@doubao-apps/taro-runtime 0.0.18 → 0.0.19

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/api/base/index.d.ts +12 -0
  2. package/dist/api/base/index.js +13 -1
  3. package/dist/api/create-selector-query/index.d.ts +3 -0
  4. package/dist/api/create-selector-query/index.js +577 -0
  5. package/dist/api/index.d.ts +7 -3
  6. package/dist/api/index.js +7 -3
  7. package/dist/api/location/index.d.ts +10 -0
  8. package/dist/api/location/index.js +77 -0
  9. package/dist/api/map/index.js +28 -30
  10. package/dist/api/request/index.js +8 -18
  11. package/dist/api/router/index.d.ts +4 -0
  12. package/dist/api/router/index.js +4 -0
  13. package/dist/api/router/navigate-back.d.ts +5 -0
  14. package/dist/api/router/navigate-back.js +20 -0
  15. package/dist/api/{navigate/index.d.ts → router/navigate-to.d.ts} +2 -2
  16. package/dist/api/{navigate/index.js → router/navigate-to.js} +7 -7
  17. package/dist/api/router/redirect-to.d.ts +5 -0
  18. package/dist/api/router/redirect-to.js +22 -0
  19. package/dist/api/show-toast/index.d.ts +6 -0
  20. package/dist/api/show-toast/index.js +39 -0
  21. package/dist/api/storage/index.d.ts +16 -0
  22. package/dist/api/storage/index.js +55 -0
  23. package/dist/api/system/index.d.ts +12 -0
  24. package/dist/api/system/index.js +40 -10
  25. package/dist/api/utils.d.ts +21 -0
  26. package/dist/api/utils.js +65 -0
  27. package/dist/components/Image/index.d.ts +2 -1
  28. package/dist/components/Image/index.jsx +3 -2
  29. package/dist/components/Input/index.d.ts +3 -5
  30. package/dist/components/Input/index.jsx +50 -3
  31. package/dist/components/Input/map.d.ts +50 -0
  32. package/dist/components/Input/map.js +226 -0
  33. package/dist/components/Map/bridge.d.ts +32 -4
  34. package/dist/components/Map/bridge.js +224 -13
  35. package/dist/components/Map/index.jsx +78 -58
  36. package/dist/components/Map/mapping.d.ts +71 -3
  37. package/dist/components/Map/mapping.js +0 -15
  38. package/dist/components/PickerView/index.d.ts +8 -0
  39. package/dist/components/PickerView/index.jsx +47 -0
  40. package/dist/components/PickerView/map.d.ts +36 -0
  41. package/dist/components/PickerView/map.js +29 -0
  42. package/dist/components/Radio/index.d.ts +5 -0
  43. package/dist/components/Radio/index.jsx +82 -0
  44. package/dist/components/Radio/map.d.ts +38 -0
  45. package/dist/components/Radio/map.js +109 -0
  46. package/dist/components/Radio/shared.d.ts +7 -0
  47. package/dist/components/Radio/shared.js +9 -0
  48. package/dist/components/RadioGroup/context.d.ts +11 -0
  49. package/dist/components/RadioGroup/context.js +3 -0
  50. package/dist/components/RadioGroup/index.d.ts +3 -0
  51. package/dist/components/RadioGroup/index.jsx +80 -0
  52. package/dist/components/RadioGroup/map.d.ts +44 -0
  53. package/dist/components/RadioGroup/map.js +109 -0
  54. package/dist/components/WebView/index.d.ts +3 -0
  55. package/dist/components/WebView/index.jsx +24 -0
  56. package/dist/components/index.d.ts +4 -0
  57. package/dist/components/index.js +4 -0
  58. package/dist/exports/app-core.d.ts +1 -1
  59. package/dist/exports/app-core.js +1 -1
  60. package/dist/exports/view-core.d.ts +1 -1
  61. package/dist/exports/view-core.js +1 -1
  62. package/dist/internal/map-context/index.d.ts +7 -1
  63. package/package.json +1 -1
@@ -0,0 +1,7 @@
1
+ import type { ReactElement } from '@byted-doubao-apps/framework';
2
+ export declare const RUNTIME_RADIO_MARK: unique symbol;
3
+ export declare function markRuntimeRadio<T extends object>(component: T): T;
4
+ export declare function isRuntimeRadioElement(element: ReactElement | {
5
+ type?: unknown;
6
+ }): boolean;
7
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1,9 @@
1
+ export const RUNTIME_RADIO_MARK = Symbol.for('doubao.taro.runtime.radio');
2
+ export function markRuntimeRadio(component) {
3
+ component[RUNTIME_RADIO_MARK] = true;
4
+ return component;
5
+ }
6
+ export function isRuntimeRadioElement(element) {
7
+ return Boolean(element.type?.[RUNTIME_RADIO_MARK]);
8
+ }
9
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,11 @@
1
+ export type RadioGroupOnChangeHandler = () => void;
2
+ export type RegisterRadioOnChange = (value: string, handler: RadioGroupOnChangeHandler) => () => void;
3
+ export type RadioGroupRuntimeContextValue = {
4
+ groupId: string;
5
+ selectedValue: string | null;
6
+ disabled: boolean;
7
+ selectValue: (value: string) => void;
8
+ registerRadioOnChange: RegisterRadioOnChange;
9
+ };
10
+ export declare const RadioGroupRuntimeContext: import("react").Context<RadioGroupRuntimeContextValue | null>;
11
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { createContext } from '@byted-doubao-apps/framework';
2
+ export const RadioGroupRuntimeContext = createContext(null);
3
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,3 @@
1
+ import type { RadioGroupProps as TaroRadioGroupProps } from '@tarojs/components';
2
+ export declare function RadioGroup(props: TaroRadioGroupProps): any;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,80 @@
1
+ import { useCallback, useMemo, useRef, useState } from '@byted-doubao-apps/framework';
2
+ import { warnUnsupported } from '../base/warn-unsupported.js';
3
+ import { RadioGroupRuntimeContext } from './context.js';
4
+ import { mapRadioGroupProps, resolveCheckedRadioSelection, resolveGroupSelectedValue, shouldDispatchGroupChange, toRadioGroupChangeEvent } from './map.js';
5
+ export function RadioGroup(props) {
6
+ const { children, onChange, ...nonEventProps } = props;
7
+ const { mapped, unsupported, groupId, resolvedDisabled } = mapRadioGroupProps(nonEventProps);
8
+ const checkedSelection = resolveCheckedRadioSelection(children);
9
+ const { hasCheckedRadio, selectedValue: checkedValue, missingValueCount } = checkedSelection;
10
+ warnUnsupported('RadioGroup', unsupported);
11
+ warnCheckedRadioValueMissing(missingValueCount);
12
+ const [uncontrolledValue, setUncontrolledValue] = useState(checkedValue);
13
+ const radioChangeHandlersRef = useRef(new Map());
14
+ const selectedValue = resolveGroupSelectedValue(hasCheckedRadio, checkedValue, uncontrolledValue);
15
+ const registerRadioOnChange = useCallback((value, handler) => {
16
+ const handlerMap = radioChangeHandlersRef.current;
17
+ const bucket = handlerMap.get(value) ?? new Set();
18
+ bucket.add(handler);
19
+ handlerMap.set(value, bucket);
20
+ return () => {
21
+ const current = handlerMap.get(value);
22
+ if (!current) {
23
+ return;
24
+ }
25
+ current.delete(handler);
26
+ if (current.size === 0) {
27
+ handlerMap.delete(value);
28
+ }
29
+ };
30
+ }, []);
31
+ const triggerRadioChange = useCallback((value) => {
32
+ const handlers = radioChangeHandlersRef.current.get(value);
33
+ if (!handlers) {
34
+ return;
35
+ }
36
+ handlers.forEach((handler) => {
37
+ handler();
38
+ });
39
+ }, []);
40
+ const selectValue = useCallback((nextValue) => {
41
+ if (resolvedDisabled || !shouldDispatchGroupChange(selectedValue, nextValue)) {
42
+ return;
43
+ }
44
+ if (!hasCheckedRadio) {
45
+ setUncontrolledValue(nextValue);
46
+ }
47
+ onChange?.(toRadioGroupChangeEvent({ value: nextValue }, 'change', groupId));
48
+ triggerRadioChange(nextValue);
49
+ }, [groupId, hasCheckedRadio, onChange, resolvedDisabled, selectedValue, triggerRadioChange]);
50
+ const contextValue = useMemo(() => ({
51
+ groupId,
52
+ selectedValue,
53
+ disabled: resolvedDisabled,
54
+ selectValue,
55
+ registerRadioOnChange
56
+ }), [groupId, registerRadioOnChange, resolvedDisabled, selectValue, selectedValue]);
57
+ const lynxGroupProps = {
58
+ disabled: resolvedDisabled,
59
+ onValueChange: selectValue,
60
+ ...(selectedValue !== null ? { value: selectedValue } : {})
61
+ };
62
+ return (<RadioGroupRuntimeContext.Provider value={contextValue}>
63
+ <view {...mapped}>
64
+ <radio-group {...lynxGroupProps}>{children}</radio-group>
65
+ </view>
66
+ </RadioGroupRuntimeContext.Provider>);
67
+ }
68
+ let hasWarnedCheckedRadioValueMissing = false;
69
+ function warnCheckedRadioValueMissing(missingValueCount) {
70
+ if (missingValueCount === 0 || isProduction() || hasWarnedCheckedRadioValueMissing) {
71
+ return;
72
+ }
73
+ hasWarnedCheckedRadioValueMissing = true;
74
+ // eslint-disable-next-line no-console
75
+ console.warn('[components-taro] Radio with checked=true inside RadioGroup requires a string value.');
76
+ }
77
+ function isProduction() {
78
+ return (globalThis.process?.env?.NODE_ENV === 'production');
79
+ }
80
+ //# sourceMappingURL=index.jsx.map
@@ -0,0 +1,44 @@
1
+ import type { ReactNode } from '@byted-doubao-apps/framework';
2
+ import type { RadioGroupProps as TaroRadioGroupProps } from '@tarojs/components';
3
+ export type MappableTaroRadioGroupProps = Omit<TaroRadioGroupProps, 'children' | 'onChange'> & {
4
+ disabled?: boolean;
5
+ };
6
+ type CommonEvent<T = unknown> = {
7
+ type: string;
8
+ timeStamp: number;
9
+ target: {
10
+ id: string;
11
+ tagName: string;
12
+ dataset: Record<string, unknown>;
13
+ };
14
+ currentTarget: {
15
+ id: string;
16
+ tagName: string;
17
+ dataset: Record<string, unknown>;
18
+ };
19
+ detail: T;
20
+ preventDefault: () => void;
21
+ stopPropagation: () => void;
22
+ };
23
+ type MapRadioGroupPropsResult = {
24
+ mapped: Record<string, unknown>;
25
+ unsupported: string[];
26
+ groupId: string;
27
+ resolvedDisabled: boolean;
28
+ };
29
+ type CheckedRadioSelection = {
30
+ hasCheckedRadio: boolean;
31
+ selectedValue: string | null;
32
+ missingValueCount: number;
33
+ };
34
+ export declare function mapRadioGroupProps(props: MappableTaroRadioGroupProps): MapRadioGroupPropsResult;
35
+ export declare function resolveCheckedRadioSelection(children: ReactNode): CheckedRadioSelection;
36
+ export declare function resolveGroupSelectedValue(hasCheckedRadio: boolean, checkedValue: string | null, uncontrolledValue: string | null): string | null;
37
+ export declare function shouldDispatchGroupChange(currentValue: string | null, nextValue: string): boolean;
38
+ export declare function toRadioGroupChangeEvent(detail: {
39
+ value: string;
40
+ }, type: string, groupId: string): CommonEvent<{
41
+ value: string;
42
+ }>;
43
+ export {};
44
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1,109 @@
1
+ import { BASE_PROP_MAP } from '../base/prop-map.js';
2
+ import { isRuntimeRadioElement } from '../Radio/shared.js';
3
+ const RADIO_GROUP_PROP_MAP = {
4
+ name: null
5
+ };
6
+ export function mapRadioGroupProps(props) {
7
+ const { disabled, ...rest } = props;
8
+ const mapped = {};
9
+ const unsupported = [];
10
+ Object.entries(rest).forEach(([key, value]) => {
11
+ const target = RADIO_GROUP_PROP_MAP[key] ?? BASE_PROP_MAP[key];
12
+ if (target) {
13
+ mapped[target] = value;
14
+ return;
15
+ }
16
+ unsupported.push(key);
17
+ });
18
+ const resolvedDisabled = resolveBooleanProp(disabled, 'disabled', unsupported) ?? false;
19
+ return {
20
+ mapped,
21
+ unsupported: dedupe(unsupported),
22
+ groupId: resolveGroupId(mapped.id),
23
+ resolvedDisabled
24
+ };
25
+ }
26
+ export function resolveCheckedRadioSelection(children) {
27
+ const result = {
28
+ hasCheckedRadio: false,
29
+ selectedValue: null,
30
+ missingValueCount: 0
31
+ };
32
+ visitNode(children, result);
33
+ return result;
34
+ }
35
+ export function resolveGroupSelectedValue(hasCheckedRadio, checkedValue, uncontrolledValue) {
36
+ return hasCheckedRadio ? checkedValue : uncontrolledValue;
37
+ }
38
+ export function shouldDispatchGroupChange(currentValue, nextValue) {
39
+ return currentValue !== nextValue;
40
+ }
41
+ export function toRadioGroupChangeEvent(detail, type, groupId) {
42
+ return {
43
+ type,
44
+ timeStamp: Date.now(),
45
+ target: {
46
+ id: groupId,
47
+ tagName: 'radio-group',
48
+ dataset: {}
49
+ },
50
+ currentTarget: {
51
+ id: groupId,
52
+ tagName: 'radio-group',
53
+ dataset: {}
54
+ },
55
+ detail,
56
+ preventDefault: () => { },
57
+ stopPropagation: () => { }
58
+ };
59
+ }
60
+ function visitNode(node, result) {
61
+ if (node === null || node === undefined || typeof node === 'boolean') {
62
+ return;
63
+ }
64
+ if (Array.isArray(node)) {
65
+ node.forEach((child) => visitNode(child, result));
66
+ return;
67
+ }
68
+ if (!isReactElement(node)) {
69
+ return;
70
+ }
71
+ const element = node;
72
+ const props = element.props ?? {};
73
+ if (isRuntimeRadioElement(element) && props.checked === true) {
74
+ result.hasCheckedRadio = true;
75
+ if (typeof props.value === 'string') {
76
+ if (result.selectedValue === null) {
77
+ result.selectedValue = props.value;
78
+ }
79
+ }
80
+ else {
81
+ result.missingValueCount += 1;
82
+ }
83
+ }
84
+ if (props.children !== undefined) {
85
+ visitNode(props.children, result);
86
+ }
87
+ }
88
+ function resolveBooleanProp(value, propName, unsupported) {
89
+ if (value === undefined) {
90
+ return undefined;
91
+ }
92
+ if (typeof value === 'boolean') {
93
+ return value;
94
+ }
95
+ unsupported.push(propName);
96
+ return undefined;
97
+ }
98
+ function resolveGroupId(id) {
99
+ return typeof id === 'string' && id.length > 0 ? id : 'radio-group';
100
+ }
101
+ function dedupe(values) {
102
+ return Array.from(new Set(values));
103
+ }
104
+ function isReactElement(value) {
105
+ return (typeof value === 'object' &&
106
+ value !== null &&
107
+ value.$$typeof === Symbol.for('react.element'));
108
+ }
109
+ //# sourceMappingURL=map.js.map
@@ -0,0 +1,3 @@
1
+ import type { WebViewProps } from '@tarojs/components';
2
+ export declare function WebView(props: WebViewProps): any;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,24 @@
1
+ function toCommonEvent(detail, type) {
2
+ return {
3
+ type,
4
+ timeStamp: Date.now(),
5
+ target: {
6
+ id: '',
7
+ tagName: 'web-view',
8
+ dataset: {}
9
+ },
10
+ currentTarget: {
11
+ id: '',
12
+ tagName: 'web-view',
13
+ dataset: {}
14
+ },
15
+ detail,
16
+ preventDefault: () => { },
17
+ stopPropagation: () => { }
18
+ };
19
+ }
20
+ export function WebView(props) {
21
+ const { src, onLoad, onError, onMessage } = props;
22
+ return (<web-view src={src} onLoad={() => onLoad?.(toCommonEvent({ src }, 'load'))} onError={(e) => onError?.(toCommonEvent({ src, errorMsg: e.errorMsg, errorCode: e.errorCode }, 'error'))} onMessage={(e) => onMessage?.(toCommonEvent({ data: [e.msg] }, 'message'))}/>);
23
+ }
24
+ //# sourceMappingURL=index.jsx.map
@@ -4,7 +4,11 @@ export * from './Text/index.jsx';
4
4
  export * from './Image/index.jsx';
5
5
  export * from './CoverImage/index.js';
6
6
  export * from './Input/index.jsx';
7
+ export * from './Radio/index.jsx';
8
+ export * from './RadioGroup/index.jsx';
7
9
  export * from './ScrollView/index.jsx';
8
10
  export * from './Map/index.jsx';
11
+ export * from './WebView/index.jsx';
9
12
  export { Button, Slider, Swiper, SwiperItem, TextArea } from '@byted-doubao-apps/components';
13
+ export * from './PickerView/index.jsx';
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -4,7 +4,11 @@ export * from './Text/index.jsx';
4
4
  export * from './Image/index.jsx';
5
5
  export * from './CoverImage/index.js';
6
6
  export * from './Input/index.jsx';
7
+ export * from './Radio/index.jsx';
8
+ export * from './RadioGroup/index.jsx';
7
9
  export * from './ScrollView/index.jsx';
8
10
  export * from './Map/index.jsx';
11
+ export * from './WebView/index.jsx';
9
12
  export { Button, Slider, Swiper, SwiperItem, TextArea } from '@byted-doubao-apps/components';
13
+ export * from './PickerView/index.jsx';
10
14
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
1
  export { useError, useLaunch, usePageNotFound, useDidHide, useDidShow } from '../hooks/lifecycle/app.js';
2
- export { request, getEnv, getSystemSetting, getAppAuthorizeSetting, getDeviceInfo, getAppBaseInfo, getWindowInfo } from './common.js';
2
+ export * from './common.js';
3
3
  //# sourceMappingURL=app-core.d.ts.map
@@ -1,3 +1,3 @@
1
1
  export { useError, useLaunch, usePageNotFound, useDidHide, useDidShow } from '../hooks/lifecycle/app.js';
2
- export { request, getEnv, getSystemSetting, getAppAuthorizeSetting, getDeviceInfo, getAppBaseInfo, getWindowInfo } from './common.js';
2
+ export * from './common.js';
3
3
  //# sourceMappingURL=app-core.js.map
@@ -1,3 +1,3 @@
1
- export { request, getEnv, getSystemSetting, getAppAuthorizeSetting, getDeviceInfo, getAppBaseInfo, getWindowInfo, createMapContext } from './common.js';
1
+ export * from './common.js';
2
2
  export { useCreated as useLoad, useMounted as useReady, useShow as useDidShow, useHide as useDidHide, useError, useDestroy as useUnload } from '@byted-doubao-apps/framework';
3
3
  //# sourceMappingURL=view-core.d.ts.map
@@ -1,3 +1,3 @@
1
- export { request, getEnv, getSystemSetting, getAppAuthorizeSetting, getDeviceInfo, getAppBaseInfo, getWindowInfo, createMapContext } from './common.js';
1
+ export * from './common.js';
2
2
  export { useCreated as useLoad, useMounted as useReady, useShow as useDidShow, useHide as useDidHide, useError, useDestroy as useUnload } from '@byted-doubao-apps/framework';
3
3
  //# sourceMappingURL=view-core.js.map
@@ -1,4 +1,5 @@
1
1
  import type { MapRef } from '@byted-doubao-apps/components';
2
+ import type { MapProps } from '@tarojs/components';
2
3
  export interface MapPoint {
3
4
  latitude: number;
4
5
  longitude: number;
@@ -7,7 +8,11 @@ export interface MapBounds {
7
8
  northeast: MapPoint;
8
9
  southwest: MapPoint;
9
10
  }
10
- export type MapController = Pick<MapRef, 'getCenter' | 'setCenter' | 'getScale' | 'getBound' | 'fitPoints' | 'setAnchor'>;
11
+ type BaseMapController = Pick<MapRef, 'getCenter' | 'setCenter' | 'getScale' | 'getBound' | 'fitPoints' | 'setAnchor'>;
12
+ export interface MapController extends BaseMapController {
13
+ addMarkers: (markers: MapProps.marker[], clear?: boolean) => void;
14
+ removeMarkers: (markerIds: number[]) => void;
15
+ }
11
16
  export declare const MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD: {
12
17
  readonly getCenterLocation: "getCenter";
13
18
  readonly moveToLocation: "setCenter";
@@ -19,4 +24,5 @@ export declare const MAP_CONTEXT_METHOD_TO_COMPONENT_METHOD: {
19
24
  export declare function registerMapController(mapId: string, controller: MapController): void;
20
25
  export declare function unregisterMapController(mapId: string, controller?: MapController): void;
21
26
  export declare function getMapController(mapId: string): MapController | undefined;
27
+ export {};
22
28
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "access": "public",
38
38
  "registry": "https://registry.npmjs.org/"
39
39
  },
40
- "version": "0.0.18",
40
+ "version": "0.0.19",
41
41
  "scripts": {
42
42
  "dev": "npm run build -- -w",
43
43
  "build": "rimraf dist bundle && tsc -p tsconfig.build.json",