antd-mobile 5.11.2 → 5.12.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/2x/cjs/components/calendar/calendar.d.ts +4 -0
- package/2x/cjs/components/calendar/calendar.js +13 -9
- package/2x/cjs/components/capsule-tabs/capsule-tabs.css +1 -0
- package/2x/cjs/components/cascade-picker/cascade-picker.d.ts +6 -3
- package/2x/cjs/components/cascade-picker/cascade-picker.js +8 -4
- package/2x/cjs/components/cascade-picker/index.d.ts +4 -2
- package/2x/cjs/components/date-picker/date-picker.d.ts +18 -4
- package/2x/cjs/components/date-picker/date-picker.js +5 -6
- package/2x/cjs/components/date-picker/index.d.ts +15 -2
- package/2x/cjs/components/dialog/dialog.js +2 -2
- package/2x/cjs/components/form/form-item.d.ts +2 -1
- package/2x/cjs/components/form/form-item.js +21 -4
- package/2x/cjs/components/form/utils.d.ts +1 -0
- package/2x/cjs/components/form/utils.js +20 -0
- package/2x/cjs/components/image-uploader/image-uploader.js +1 -2
- package/2x/cjs/components/input/input.d.ts +2 -2
- package/2x/cjs/components/input/input.js +1 -0
- package/2x/cjs/components/jumbo-tabs/jumbo-tabs.css +1 -0
- package/2x/cjs/components/list/list.css +1 -0
- package/2x/cjs/components/mask/mask.js +1 -1
- package/2x/cjs/components/modal/modal.js +2 -2
- package/2x/cjs/components/picker/index.d.ts +44 -3
- package/2x/cjs/components/picker/picker.d.ts +32 -2
- package/2x/cjs/components/picker/picker.js +43 -16
- package/2x/cjs/components/popup/popup.js +1 -1
- package/2x/cjs/components/swipe-action/swipe-action.js +1 -1
- package/2x/cjs/components/tabs/tabs.css +1 -0
- package/2x/cjs/components/text-area/text-area.d.ts +2 -2
- package/2x/cjs/components/text-area/text-area.js +4 -1
- package/2x/cjs/components/toast/methods.js +3 -7
- package/2x/cjs/utils/render-to-body.js +3 -6
- package/2x/cjs/utils/render.d.ts +9 -0
- package/2x/cjs/utils/render.js +80 -0
- package/2x/cjs/utils/use-drag-and-pinch.d.ts +1 -1
- package/2x/cjs/utils/use-props-value.d.ts +1 -1
- package/2x/es/components/calendar/calendar.d.ts +4 -0
- package/2x/es/components/calendar/calendar.js +13 -9
- package/2x/es/components/capsule-tabs/capsule-tabs.css +1 -0
- package/2x/es/components/cascade-picker/cascade-picker.d.ts +6 -3
- package/2x/es/components/cascade-picker/cascade-picker.js +4 -3
- package/2x/es/components/cascade-picker/index.d.ts +4 -2
- package/2x/es/components/date-picker/date-picker.d.ts +18 -4
- package/2x/es/components/date-picker/date-picker.js +6 -5
- package/2x/es/components/date-picker/index.d.ts +15 -2
- package/2x/es/components/dialog/dialog.js +2 -2
- package/2x/es/components/form/form-item.d.ts +2 -1
- package/2x/es/components/form/form-item.js +23 -4
- package/2x/es/components/form/utils.d.ts +1 -0
- package/2x/es/components/form/utils.js +17 -0
- package/2x/es/components/image-uploader/image-uploader.js +1 -2
- package/2x/es/components/input/input.d.ts +2 -2
- package/2x/es/components/input/input.js +1 -0
- package/2x/es/components/jumbo-tabs/jumbo-tabs.css +1 -0
- package/2x/es/components/list/list.css +1 -0
- package/2x/es/components/mask/mask.js +1 -1
- package/2x/es/components/modal/modal.js +2 -2
- package/2x/es/components/picker/index.d.ts +44 -3
- package/2x/es/components/picker/picker.d.ts +32 -2
- package/2x/es/components/picker/picker.js +42 -17
- package/2x/es/components/popup/popup.js +1 -1
- package/2x/es/components/swipe-action/swipe-action.js +1 -1
- package/2x/es/components/tabs/tabs.css +1 -0
- package/2x/es/components/text-area/text-area.d.ts +2 -2
- package/2x/es/components/text-area/text-area.js +4 -2
- package/2x/es/components/toast/methods.js +3 -3
- package/2x/es/utils/render-to-body.js +3 -3
- package/2x/es/utils/render.d.ts +9 -0
- package/2x/es/utils/render.js +65 -0
- package/2x/es/utils/use-drag-and-pinch.d.ts +1 -1
- package/2x/es/utils/use-props-value.d.ts +1 -1
- package/2x/package.json +8 -8
- package/bundle/antd-mobile.cjs.js +5041 -4302
- package/bundle/antd-mobile.es.js +5043 -4304
- package/bundle/style.css +4 -0
- package/cjs/components/calendar/calendar.d.ts +4 -0
- package/cjs/components/calendar/calendar.js +13 -9
- package/cjs/components/capsule-tabs/capsule-tabs.css +1 -0
- package/cjs/components/cascade-picker/cascade-picker.d.ts +6 -3
- package/cjs/components/cascade-picker/cascade-picker.js +8 -4
- package/cjs/components/cascade-picker/index.d.ts +4 -2
- package/cjs/components/date-picker/date-picker.d.ts +18 -4
- package/cjs/components/date-picker/date-picker.js +5 -6
- package/cjs/components/date-picker/index.d.ts +15 -2
- package/cjs/components/dialog/dialog.js +2 -2
- package/cjs/components/form/form-item.d.ts +2 -1
- package/cjs/components/form/form-item.js +21 -4
- package/cjs/components/form/utils.d.ts +1 -0
- package/cjs/components/form/utils.js +20 -0
- package/cjs/components/image-uploader/image-uploader.js +1 -2
- package/cjs/components/input/input.d.ts +2 -2
- package/cjs/components/input/input.js +1 -0
- package/cjs/components/jumbo-tabs/jumbo-tabs.css +1 -0
- package/cjs/components/list/list.css +1 -0
- package/cjs/components/mask/mask.js +1 -1
- package/cjs/components/modal/modal.js +2 -2
- package/cjs/components/picker/index.d.ts +44 -3
- package/cjs/components/picker/picker.d.ts +32 -2
- package/cjs/components/picker/picker.js +43 -16
- package/cjs/components/popup/popup.js +1 -1
- package/cjs/components/swipe-action/swipe-action.js +1 -1
- package/cjs/components/tabs/tabs.css +1 -0
- package/cjs/components/text-area/text-area.d.ts +2 -2
- package/cjs/components/text-area/text-area.js +4 -1
- package/cjs/components/toast/methods.js +3 -7
- package/cjs/utils/render-to-body.js +3 -6
- package/cjs/utils/render.d.ts +9 -0
- package/cjs/utils/render.js +80 -0
- package/cjs/utils/use-drag-and-pinch.d.ts +1 -1
- package/cjs/utils/use-props-value.d.ts +1 -1
- package/es/components/calendar/calendar.d.ts +4 -0
- package/es/components/calendar/calendar.js +13 -9
- package/es/components/capsule-tabs/capsule-tabs.css +1 -0
- package/es/components/cascade-picker/cascade-picker.d.ts +6 -3
- package/es/components/cascade-picker/cascade-picker.js +4 -3
- package/es/components/cascade-picker/index.d.ts +4 -2
- package/es/components/date-picker/date-picker.d.ts +18 -4
- package/es/components/date-picker/date-picker.js +6 -5
- package/es/components/date-picker/index.d.ts +15 -2
- package/es/components/dialog/dialog.js +2 -2
- package/es/components/form/form-item.d.ts +2 -1
- package/es/components/form/form-item.js +23 -4
- package/es/components/form/utils.d.ts +1 -0
- package/es/components/form/utils.js +17 -0
- package/es/components/image-uploader/image-uploader.js +1 -2
- package/es/components/input/input.d.ts +2 -2
- package/es/components/input/input.js +1 -0
- package/es/components/jumbo-tabs/jumbo-tabs.css +1 -0
- package/es/components/list/list.css +1 -0
- package/es/components/mask/mask.js +1 -1
- package/es/components/modal/modal.js +2 -2
- package/es/components/picker/index.d.ts +44 -3
- package/es/components/picker/picker.d.ts +32 -2
- package/es/components/picker/picker.js +42 -17
- package/es/components/popup/popup.js +1 -1
- package/es/components/swipe-action/swipe-action.js +1 -1
- package/es/components/tabs/tabs.css +1 -0
- package/es/components/text-area/text-area.d.ts +2 -2
- package/es/components/text-area/text-area.js +4 -2
- package/es/components/toast/methods.js +3 -3
- package/es/utils/render-to-body.js +3 -3
- package/es/utils/render.d.ts +9 -0
- package/es/utils/render.js +65 -0
- package/es/utils/use-drag-and-pinch.d.ts +1 -1
- package/es/utils/use-props-value.d.ts +1 -1
- package/package.json +8 -8
- package/umd/antd-mobile.js +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { useContext, useCallback, useState } from 'react';
|
|
2
|
+
import React, { useContext, useCallback, useState, useRef } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { Field } from 'rc-field-form';
|
|
5
5
|
import FieldContext from 'rc-field-form/lib/FieldContext';
|
|
6
6
|
import { devWarning } from '../../utils/dev-log';
|
|
7
7
|
import { FormContext, NoStyleItemContext } from './context';
|
|
8
|
-
import { toArray } from './utils';
|
|
8
|
+
import { toArray, isSafeSetRefComponent } from './utils';
|
|
9
9
|
import List from '../list';
|
|
10
10
|
import Popover from '../popover';
|
|
11
11
|
import { QuestionCircleOutline } from 'antd-mobile-icons';
|
|
@@ -147,7 +147,8 @@ export const FormItem = props => {
|
|
|
147
147
|
validateTrigger: contextValidateTrigger
|
|
148
148
|
} = useContext(FieldContext);
|
|
149
149
|
const mergedValidateTrigger = undefinedFallback(validateTrigger, contextValidateTrigger, trigger);
|
|
150
|
-
const
|
|
150
|
+
const widgetRef = useRef(null);
|
|
151
|
+
const updateRef = useRef(0);
|
|
151
152
|
updateRef.current += 1;
|
|
152
153
|
const [subMetas, setSubMetas] = useState({});
|
|
153
154
|
const onSubMetaChange = useCallback((subMeta, namePath) => {
|
|
@@ -209,7 +210,7 @@ export const FormItem = props => {
|
|
|
209
210
|
htmlFor: fieldId,
|
|
210
211
|
errors: errors,
|
|
211
212
|
warnings: warnings,
|
|
212
|
-
onClick: onClick,
|
|
213
|
+
onClick: onClick && (e => onClick(e, widgetRef)),
|
|
213
214
|
hidden: hidden,
|
|
214
215
|
layout: layout,
|
|
215
216
|
childElementPosition: childElementPosition,
|
|
@@ -286,6 +287,24 @@ export const FormItem = props => {
|
|
|
286
287
|
|
|
287
288
|
const childProps = Object.assign(Object.assign({}, children.props), control);
|
|
288
289
|
|
|
290
|
+
if (isSafeSetRefComponent(children)) {
|
|
291
|
+
childProps.ref = instance => {
|
|
292
|
+
const originRef = children.ref;
|
|
293
|
+
|
|
294
|
+
if (originRef) {
|
|
295
|
+
if (typeof originRef === 'function') {
|
|
296
|
+
originRef(instance);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if ('current' in originRef) {
|
|
300
|
+
originRef.current = instance;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
widgetRef.current = instance;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
289
308
|
if (!childProps.id) {
|
|
290
309
|
childProps.id = fieldId;
|
|
291
310
|
} // We should keep user origin event handler
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import { isMemo, isFragment } from 'react-is';
|
|
1
2
|
export function toArray(candidate) {
|
|
2
3
|
if (candidate === undefined || candidate === false) return [];
|
|
3
4
|
return Array.isArray(candidate) ? candidate : [candidate];
|
|
5
|
+
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
6
|
+
|
|
7
|
+
function shouldConstruct(Component) {
|
|
8
|
+
const prototype = Component.prototype;
|
|
9
|
+
return !!(prototype && prototype.isReactComponent);
|
|
10
|
+
} // https://github.com/facebook/react/blob/ce13860281f833de8a3296b7a3dad9caced102e9/packages/react-reconciler/src/ReactFiber.new.js#L225
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function isSimpleFunctionComponent(type) {
|
|
14
|
+
return typeof type === 'function' && !shouldConstruct(type) && type.defaultProps === undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isSafeSetRefComponent(component) {
|
|
18
|
+
if (isFragment(component)) return false;
|
|
19
|
+
if (isMemo(component)) return isSafeSetRefComponent(component.type);
|
|
20
|
+
return !isSimpleFunctionComponent(component.type);
|
|
4
21
|
}
|
|
@@ -65,6 +65,7 @@ export const ImageUploader = p => {
|
|
|
65
65
|
} = e.target;
|
|
66
66
|
if (!rawFiles) return;
|
|
67
67
|
let files = [].slice.call(rawFiles);
|
|
68
|
+
e.target.value = ''; // HACK: fix the same file doesn't trigger onChange
|
|
68
69
|
|
|
69
70
|
if (props.beforeUpload) {
|
|
70
71
|
const postFiles = files.map(file => {
|
|
@@ -94,8 +95,6 @@ export const ImageUploader = p => {
|
|
|
94
95
|
file
|
|
95
96
|
}));
|
|
96
97
|
setTasks(prev => [...prev, ...newTasks]);
|
|
97
|
-
e.target.value = ''; // HACK: fix the same file doesn't trigger onChange
|
|
98
|
-
|
|
99
98
|
yield Promise.all(newTasks.map(currentTask => __awaiter(this, void 0, void 0, function* () {
|
|
100
99
|
try {
|
|
101
100
|
const result = yield props.upload(currentTask.file);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
declare type NativeInputProps = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
4
|
-
export declare type InputProps = Pick<NativeInputProps, 'maxLength' | 'minLength' | 'autoComplete' | 'autoFocus' | 'pattern' | 'inputMode' | 'type' | 'onFocus' | 'onBlur' | 'autoCapitalize' | 'autoCorrect' | 'onKeyDown' | 'onKeyUp' | 'onCompositionStart' | 'onCompositionEnd' | 'onClick'> & {
|
|
4
|
+
export declare type InputProps = Pick<NativeInputProps, 'maxLength' | 'minLength' | 'autoComplete' | 'autoFocus' | 'pattern' | 'inputMode' | 'type' | 'name' | 'onFocus' | 'onBlur' | 'autoCapitalize' | 'autoCorrect' | 'onKeyDown' | 'onKeyUp' | 'onCompositionStart' | 'onCompositionEnd' | 'onClick'> & {
|
|
5
5
|
value?: string;
|
|
6
6
|
defaultValue?: string;
|
|
7
7
|
onChange?: (val: string) => void;
|
|
@@ -23,7 +23,7 @@ export declare type InputRef = {
|
|
|
23
23
|
blur: () => void;
|
|
24
24
|
nativeElement: HTMLInputElement | null;
|
|
25
25
|
};
|
|
26
|
-
export declare const Input: React.ForwardRefExoticComponent<Pick<NativeInputProps, "pattern" | "onClick" | "type" | "onCompositionEnd" | "onCompositionStart" | "onFocus" | "onBlur" | "onKeyDown" | "onKeyUp" | "autoCapitalize" | "autoCorrect" | "inputMode" | "autoComplete" | "autoFocus" | "maxLength" | "minLength"> & {
|
|
26
|
+
export declare const Input: React.ForwardRefExoticComponent<Pick<NativeInputProps, "pattern" | "onClick" | "name" | "type" | "onCompositionEnd" | "onCompositionStart" | "onFocus" | "onBlur" | "onKeyDown" | "onKeyUp" | "autoCapitalize" | "autoCorrect" | "inputMode" | "autoComplete" | "autoFocus" | "maxLength" | "minLength"> & {
|
|
27
27
|
value?: string | undefined;
|
|
28
28
|
defaultValue?: string | undefined;
|
|
29
29
|
onChange?: ((val: string) => void) | undefined;
|
|
@@ -116,6 +116,7 @@ export const Input = forwardRef((p, ref) => {
|
|
|
116
116
|
pattern: props.pattern,
|
|
117
117
|
inputMode: props.inputMode,
|
|
118
118
|
type: props.type,
|
|
119
|
+
name: props.name,
|
|
119
120
|
autoCapitalize: props.autoCapitalize,
|
|
120
121
|
autoCorrect: props.autoCorrect,
|
|
121
122
|
onKeyDown: handleKeydown,
|
|
@@ -92,7 +92,7 @@ export const Modal = p => {
|
|
|
92
92
|
const node = withStopPropagation(props.stopPropagation, withNativeProps(props, React.createElement("div", {
|
|
93
93
|
className: cls(),
|
|
94
94
|
style: {
|
|
95
|
-
display: active ?
|
|
95
|
+
display: active ? undefined : 'none'
|
|
96
96
|
}
|
|
97
97
|
}, React.createElement(Mask, {
|
|
98
98
|
visible: props.visible,
|
|
@@ -103,7 +103,7 @@ export const Modal = p => {
|
|
|
103
103
|
}), React.createElement("div", {
|
|
104
104
|
className: cls('wrap'),
|
|
105
105
|
style: {
|
|
106
|
-
pointerEvents: props.visible ?
|
|
106
|
+
pointerEvents: props.visible ? undefined : 'none'
|
|
107
107
|
}
|
|
108
108
|
}, React.createElement(animated.div, {
|
|
109
109
|
style: style
|
|
@@ -1,9 +1,50 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import './picker.less';
|
|
3
2
|
import { prompt } from './prompt';
|
|
4
|
-
export type { PickerProps } from './picker';
|
|
3
|
+
export type { PickerProps, PickerRef, PickerActions } from './picker';
|
|
5
4
|
export type { PickerValue, PickerColumnItem, PickerColumn, PickerValueExtend, } from '../picker-view';
|
|
6
|
-
declare const _default: import("react").NamedExoticComponent<
|
|
5
|
+
declare const _default: import("react").NamedExoticComponent<{
|
|
6
|
+
columns: import("../picker-view").PickerColumn[] | ((value: import("../picker-view").PickerValue[]) => import("../picker-view").PickerColumn[]);
|
|
7
|
+
value?: import("../picker-view").PickerValue[] | undefined;
|
|
8
|
+
defaultValue?: import("../picker-view").PickerValue[] | undefined;
|
|
9
|
+
onSelect?: ((value: import("../picker-view").PickerValue[], extend: import("../picker-view").PickerValueExtend) => void) | undefined;
|
|
10
|
+
onConfirm?: ((value: import("../picker-view").PickerValue[], extend: import("../picker-view").PickerValueExtend) => void) | undefined;
|
|
11
|
+
onCancel?: (() => void) | undefined;
|
|
12
|
+
onClose?: (() => void) | undefined;
|
|
13
|
+
closeOnMaskClick?: boolean | undefined;
|
|
14
|
+
visible?: boolean | undefined;
|
|
15
|
+
title?: import("react").ReactNode;
|
|
16
|
+
confirmText?: import("react").ReactNode;
|
|
17
|
+
cancelText?: import("react").ReactNode;
|
|
18
|
+
children?: ((items: (import("../picker-view").PickerColumnItem | null)[], actions: import("./picker").PickerActions) => import("react").ReactNode) | undefined;
|
|
19
|
+
renderLabel?: ((item: import("../picker-view").PickerColumnItem) => import("react").ReactNode) | undefined;
|
|
20
|
+
mouseWheel?: boolean | undefined;
|
|
21
|
+
popupClassName?: string | undefined;
|
|
22
|
+
popupStyle?: import("react").CSSProperties | undefined;
|
|
23
|
+
forceRender?: boolean | undefined;
|
|
24
|
+
destroyOnClose?: boolean | undefined;
|
|
25
|
+
} & Pick<import("../popup").PopupProps, "onClick" | "getContainer" | "afterShow" | "afterClose" | "stopPropagation"> & import("../../utils/native-props").NativeProps<"--item-height" | "--header-button-font-size" | "--title-font-size" | "--item-font-size"> & import("react").RefAttributes<import("./picker").PickerActions>> & {
|
|
26
|
+
readonly type: import("react").ForwardRefExoticComponent<{
|
|
27
|
+
columns: import("../picker-view").PickerColumn[] | ((value: import("../picker-view").PickerValue[]) => import("../picker-view").PickerColumn[]);
|
|
28
|
+
value?: import("../picker-view").PickerValue[] | undefined;
|
|
29
|
+
defaultValue?: import("../picker-view").PickerValue[] | undefined;
|
|
30
|
+
onSelect?: ((value: import("../picker-view").PickerValue[], extend: import("../picker-view").PickerValueExtend) => void) | undefined;
|
|
31
|
+
onConfirm?: ((value: import("../picker-view").PickerValue[], extend: import("../picker-view").PickerValueExtend) => void) | undefined;
|
|
32
|
+
onCancel?: (() => void) | undefined;
|
|
33
|
+
onClose?: (() => void) | undefined;
|
|
34
|
+
closeOnMaskClick?: boolean | undefined;
|
|
35
|
+
visible?: boolean | undefined;
|
|
36
|
+
title?: import("react").ReactNode;
|
|
37
|
+
confirmText?: import("react").ReactNode;
|
|
38
|
+
cancelText?: import("react").ReactNode;
|
|
39
|
+
children?: ((items: (import("../picker-view").PickerColumnItem | null)[], actions: import("./picker").PickerActions) => import("react").ReactNode) | undefined;
|
|
40
|
+
renderLabel?: ((item: import("../picker-view").PickerColumnItem) => import("react").ReactNode) | undefined;
|
|
41
|
+
mouseWheel?: boolean | undefined;
|
|
42
|
+
popupClassName?: string | undefined;
|
|
43
|
+
popupStyle?: import("react").CSSProperties | undefined;
|
|
44
|
+
forceRender?: boolean | undefined;
|
|
45
|
+
destroyOnClose?: boolean | undefined;
|
|
46
|
+
} & Pick<import("../popup").PopupProps, "onClick" | "getContainer" | "afterShow" | "afterClose" | "stopPropagation"> & import("../../utils/native-props").NativeProps<"--item-height" | "--header-button-font-size" | "--title-font-size" | "--item-font-size"> & import("react").RefAttributes<import("./picker").PickerActions>>;
|
|
47
|
+
} & {
|
|
7
48
|
prompt: typeof prompt;
|
|
8
49
|
};
|
|
9
50
|
export default _default;
|
|
@@ -2,6 +2,12 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import { PopupProps } from '../popup';
|
|
3
3
|
import { NativeProps } from '../../utils/native-props';
|
|
4
4
|
import { PickerColumn, PickerColumnItem, PickerValue, PickerValueExtend } from './index';
|
|
5
|
+
export declare type PickerActions = {
|
|
6
|
+
open: () => void;
|
|
7
|
+
close: () => void;
|
|
8
|
+
toggle: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare type PickerRef = PickerActions;
|
|
5
11
|
export declare type PickerProps = {
|
|
6
12
|
columns: PickerColumn[] | ((value: PickerValue[]) => PickerColumn[]);
|
|
7
13
|
value?: PickerValue[];
|
|
@@ -15,8 +21,32 @@ export declare type PickerProps = {
|
|
|
15
21
|
title?: ReactNode;
|
|
16
22
|
confirmText?: ReactNode;
|
|
17
23
|
cancelText?: ReactNode;
|
|
18
|
-
children?: (items: (PickerColumnItem | null)[]) => ReactNode;
|
|
24
|
+
children?: (items: (PickerColumnItem | null)[], actions: PickerActions) => ReactNode;
|
|
19
25
|
renderLabel?: (item: PickerColumnItem) => ReactNode;
|
|
20
26
|
mouseWheel?: boolean;
|
|
27
|
+
popupClassName?: string;
|
|
28
|
+
popupStyle?: React.CSSProperties;
|
|
29
|
+
forceRender?: boolean;
|
|
30
|
+
destroyOnClose?: boolean;
|
|
21
31
|
} & Pick<PopupProps, 'getContainer' | 'afterShow' | 'afterClose' | 'onClick' | 'stopPropagation'> & NativeProps<'--header-button-font-size' | '--title-font-size' | '--item-font-size' | '--item-height'>;
|
|
22
|
-
export declare const Picker: React.
|
|
32
|
+
export declare const Picker: React.MemoExoticComponent<React.ForwardRefExoticComponent<{
|
|
33
|
+
columns: PickerColumn[] | ((value: PickerValue[]) => PickerColumn[]);
|
|
34
|
+
value?: PickerValue[] | undefined;
|
|
35
|
+
defaultValue?: PickerValue[] | undefined;
|
|
36
|
+
onSelect?: ((value: PickerValue[], extend: PickerValueExtend) => void) | undefined;
|
|
37
|
+
onConfirm?: ((value: PickerValue[], extend: PickerValueExtend) => void) | undefined;
|
|
38
|
+
onCancel?: (() => void) | undefined;
|
|
39
|
+
onClose?: (() => void) | undefined;
|
|
40
|
+
closeOnMaskClick?: boolean | undefined;
|
|
41
|
+
visible?: boolean | undefined;
|
|
42
|
+
title?: ReactNode;
|
|
43
|
+
confirmText?: ReactNode;
|
|
44
|
+
cancelText?: ReactNode;
|
|
45
|
+
children?: ((items: (PickerColumnItem | null)[], actions: PickerActions) => ReactNode) | undefined;
|
|
46
|
+
renderLabel?: ((item: PickerColumnItem) => ReactNode) | undefined;
|
|
47
|
+
mouseWheel?: boolean | undefined;
|
|
48
|
+
popupClassName?: string | undefined;
|
|
49
|
+
popupStyle?: React.CSSProperties | undefined;
|
|
50
|
+
forceRender?: boolean | undefined;
|
|
51
|
+
destroyOnClose?: boolean | undefined;
|
|
52
|
+
} & Pick<PopupProps, "onClick" | "getContainer" | "afterShow" | "afterClose" | "stopPropagation"> & NativeProps<"--item-height" | "--header-button-font-size" | "--title-font-size" | "--item-font-size"> & React.RefAttributes<PickerActions>>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React, { useState, useEffect, memo } from 'react';
|
|
1
|
+
import React, { useState, useEffect, forwardRef, useImperativeHandle, memo } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
2
3
|
import Popup from '../popup';
|
|
3
4
|
import { mergeProps } from '../../utils/with-default-props';
|
|
4
5
|
import { withNativeProps } from '../../utils/native-props';
|
|
@@ -9,13 +10,14 @@ import { useConfig } from '../config-provider';
|
|
|
9
10
|
import { useMemoizedFn } from 'ahooks';
|
|
10
11
|
import SafeArea from '../safe-area';
|
|
11
12
|
import { defaultRenderLabel } from './picker-utils';
|
|
13
|
+
import { useShouldRender } from '../../utils/should-render';
|
|
12
14
|
const classPrefix = `adm-picker`;
|
|
13
15
|
const defaultProps = {
|
|
14
16
|
defaultValue: [],
|
|
15
17
|
closeOnMaskClick: true,
|
|
16
18
|
renderLabel: defaultRenderLabel
|
|
17
19
|
};
|
|
18
|
-
export const Picker = memo(p => {
|
|
20
|
+
export const Picker = memo(forwardRef((p, ref) => {
|
|
19
21
|
var _a;
|
|
20
22
|
|
|
21
23
|
const {
|
|
@@ -25,6 +27,29 @@ export const Picker = memo(p => {
|
|
|
25
27
|
confirmText: locale.common.confirm,
|
|
26
28
|
cancelText: locale.common.cancel
|
|
27
29
|
}, p);
|
|
30
|
+
const [visible, setVisible] = usePropsValue({
|
|
31
|
+
value: props.visible,
|
|
32
|
+
defaultValue: false,
|
|
33
|
+
onChange: v => {
|
|
34
|
+
var _a;
|
|
35
|
+
|
|
36
|
+
if (v === false) {
|
|
37
|
+
(_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const actions = {
|
|
42
|
+
toggle: () => {
|
|
43
|
+
setVisible(v => !v);
|
|
44
|
+
},
|
|
45
|
+
open: () => {
|
|
46
|
+
setVisible(true);
|
|
47
|
+
},
|
|
48
|
+
close: () => {
|
|
49
|
+
setVisible(false);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
useImperativeHandle(ref, () => actions);
|
|
28
53
|
const [value, setValue] = usePropsValue(Object.assign(Object.assign({}, props), {
|
|
29
54
|
onChange: val => {
|
|
30
55
|
var _a;
|
|
@@ -39,9 +64,9 @@ export const Picker = memo(p => {
|
|
|
39
64
|
if (innerValue !== value) {
|
|
40
65
|
setInnerValue(value);
|
|
41
66
|
}
|
|
42
|
-
}, [
|
|
67
|
+
}, [visible]);
|
|
43
68
|
useEffect(() => {
|
|
44
|
-
if (!
|
|
69
|
+
if (!visible) {
|
|
45
70
|
setInnerValue(value);
|
|
46
71
|
}
|
|
47
72
|
}, [value]);
|
|
@@ -50,10 +75,11 @@ export const Picker = memo(p => {
|
|
|
50
75
|
|
|
51
76
|
setInnerValue(val);
|
|
52
77
|
|
|
53
|
-
if (
|
|
78
|
+
if (visible) {
|
|
54
79
|
(_a = props.onSelect) === null || _a === void 0 ? void 0 : _a.call(props, val, ext);
|
|
55
80
|
}
|
|
56
81
|
});
|
|
82
|
+
const shouldRender = useShouldRender(visible, props.forceRender, props.destroyOnClose);
|
|
57
83
|
const pickerElement = withNativeProps(props, React.createElement("div", {
|
|
58
84
|
className: classPrefix
|
|
59
85
|
}, React.createElement("div", {
|
|
@@ -61,20 +87,18 @@ export const Picker = memo(p => {
|
|
|
61
87
|
}, React.createElement("a", {
|
|
62
88
|
className: `${classPrefix}-header-button`,
|
|
63
89
|
onClick: () => {
|
|
64
|
-
var _a
|
|
90
|
+
var _a;
|
|
65
91
|
|
|
66
92
|
(_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
67
|
-
(
|
|
93
|
+
setVisible(false);
|
|
68
94
|
}
|
|
69
95
|
}, props.cancelText), React.createElement("div", {
|
|
70
96
|
className: `${classPrefix}-header-title`
|
|
71
97
|
}, props.title), React.createElement("a", {
|
|
72
98
|
className: `${classPrefix}-header-button`,
|
|
73
99
|
onClick: () => {
|
|
74
|
-
var _a;
|
|
75
|
-
|
|
76
100
|
setValue(innerValue);
|
|
77
|
-
(
|
|
101
|
+
setVisible(false);
|
|
78
102
|
}
|
|
79
103
|
}, props.confirmText)), React.createElement("div", {
|
|
80
104
|
className: `${classPrefix}-body`
|
|
@@ -86,15 +110,16 @@ export const Picker = memo(p => {
|
|
|
86
110
|
onChange: onChange
|
|
87
111
|
}))));
|
|
88
112
|
const popupElement = React.createElement(Popup, {
|
|
89
|
-
|
|
90
|
-
|
|
113
|
+
style: props.popupStyle,
|
|
114
|
+
className: classNames(`${classPrefix}-popup`, props.popupClassName),
|
|
115
|
+
visible: visible,
|
|
91
116
|
position: 'bottom',
|
|
92
117
|
onMaskClick: () => {
|
|
93
|
-
var _a
|
|
118
|
+
var _a;
|
|
94
119
|
|
|
95
120
|
if (!props.closeOnMaskClick) return;
|
|
96
121
|
(_a = props.onCancel) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
97
|
-
(
|
|
122
|
+
setVisible(false);
|
|
98
123
|
},
|
|
99
124
|
getContainer: props.getContainer,
|
|
100
125
|
destroyOnClose: true,
|
|
@@ -103,9 +128,9 @@ export const Picker = memo(p => {
|
|
|
103
128
|
onClick: props.onClick,
|
|
104
129
|
forceRender: true,
|
|
105
130
|
stopPropagation: props.stopPropagation
|
|
106
|
-
}, pickerElement, React.createElement(SafeArea, {
|
|
131
|
+
}, shouldRender && pickerElement, React.createElement(SafeArea, {
|
|
107
132
|
position: 'bottom'
|
|
108
133
|
}));
|
|
109
|
-
return React.createElement(React.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props, extend.items));
|
|
110
|
-
});
|
|
134
|
+
return React.createElement(React.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props, extend.items, actions));
|
|
135
|
+
}));
|
|
111
136
|
Picker.displayName = 'Picker';
|
|
@@ -185,7 +185,7 @@ export const SwipeAction = forwardRef((p, ref) => {
|
|
|
185
185
|
}
|
|
186
186
|
}, React.createElement(animated.div, {
|
|
187
187
|
style: {
|
|
188
|
-
pointerEvents: x.to(v => v !== 0 && x.goal !== 0 ? 'none' : '
|
|
188
|
+
pointerEvents: x.to(v => v !== 0 && x.goal !== 0 ? 'none' : 'auto')
|
|
189
189
|
}
|
|
190
190
|
}, props.children)), withStopPropagation(props.stopPropagation, React.createElement("div", {
|
|
191
191
|
className: 'adm-swipe-action-actions adm-swipe-action-actions-right',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { NativeProps } from '../../utils/native-props';
|
|
4
|
-
export declare type TextAreaProps = Pick<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, 'autoComplete' | 'autoFocus' | 'disabled' | 'readOnly' | 'onFocus' | 'onBlur' | 'onCompositionStart' | 'onCompositionEnd' | 'onClick'> & {
|
|
4
|
+
export declare type TextAreaProps = Pick<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, 'autoComplete' | 'autoFocus' | 'disabled' | 'readOnly' | 'name' | 'onFocus' | 'onBlur' | 'onCompositionStart' | 'onCompositionEnd' | 'onClick'> & {
|
|
5
5
|
onChange?: (val: string) => void;
|
|
6
6
|
value?: string;
|
|
7
7
|
defaultValue?: string;
|
|
@@ -20,7 +20,7 @@ export declare type TextAreaRef = {
|
|
|
20
20
|
focus: () => void;
|
|
21
21
|
blur: () => void;
|
|
22
22
|
};
|
|
23
|
-
export declare const TextArea: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "onClick" | "disabled" | "onCompositionEnd" | "onCompositionStart" | "onFocus" | "onBlur" | "autoComplete" | "autoFocus" | "readOnly"> & {
|
|
23
|
+
export declare const TextArea: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "onClick" | "disabled" | "name" | "onCompositionEnd" | "onCompositionStart" | "onFocus" | "onBlur" | "autoComplete" | "autoFocus" | "readOnly"> & {
|
|
24
24
|
onChange?: ((val: string) => void) | undefined;
|
|
25
25
|
value?: string | undefined;
|
|
26
26
|
defaultValue?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
|
2
|
+
import { useIsomorphicLayoutEffect } from 'ahooks';
|
|
2
3
|
import { withNativeProps } from '../../utils/native-props';
|
|
3
4
|
import { usePropsValue } from '../../utils/use-props-value';
|
|
4
5
|
import { mergeProps } from '../../utils/with-default-props';
|
|
@@ -41,7 +42,7 @@ export const TextArea = forwardRef((p, ref) => {
|
|
|
41
42
|
(_a = nativeTextAreaRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
42
43
|
}
|
|
43
44
|
}));
|
|
44
|
-
|
|
45
|
+
useIsomorphicLayoutEffect(() => {
|
|
45
46
|
if (!autoSize) return;
|
|
46
47
|
const textArea = nativeTextAreaRef.current;
|
|
47
48
|
if (!textArea) return;
|
|
@@ -114,6 +115,7 @@ export const TextArea = forwardRef((p, ref) => {
|
|
|
114
115
|
autoFocus: props.autoFocus,
|
|
115
116
|
disabled: props.disabled,
|
|
116
117
|
readOnly: props.readOnly,
|
|
118
|
+
name: props.name,
|
|
117
119
|
onFocus: props.onFocus,
|
|
118
120
|
onBlur: props.onBlur,
|
|
119
121
|
onClick: props.onClick
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
|
|
2
2
|
import { resolveContainer } from '../../utils/get-container';
|
|
3
|
-
import ReactDOM from 'react-dom';
|
|
4
3
|
import { InternalToast } from './toast';
|
|
5
4
|
import { mergeProps } from '../../utils/with-default-props';
|
|
5
|
+
import { render, unmount as reactUnmount } from '../../utils/render';
|
|
6
6
|
const containers = [];
|
|
7
7
|
|
|
8
8
|
function unmount(container) {
|
|
9
|
-
const unmountResult =
|
|
9
|
+
const unmountResult = reactUnmount(container);
|
|
10
10
|
|
|
11
11
|
if (unmountResult && container.parentNode) {
|
|
12
12
|
container.parentNode.removeChild(container);
|
|
@@ -64,7 +64,7 @@ export function show(p) {
|
|
|
64
64
|
}));
|
|
65
65
|
});
|
|
66
66
|
const ref = createRef();
|
|
67
|
-
|
|
67
|
+
render(React.createElement(TempToast, {
|
|
68
68
|
ref: ref
|
|
69
69
|
}), container);
|
|
70
70
|
return {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { render, unmount as reactUnmount } from './render';
|
|
2
2
|
export function renderToBody(element) {
|
|
3
3
|
const container = document.createElement('div');
|
|
4
4
|
document.body.appendChild(container);
|
|
5
5
|
|
|
6
6
|
function unmount() {
|
|
7
|
-
const unmountResult =
|
|
7
|
+
const unmountResult = reactUnmount(container);
|
|
8
8
|
|
|
9
9
|
if (unmountResult && container.parentNode) {
|
|
10
10
|
container.parentNode.removeChild(container);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
render(element, container);
|
|
15
15
|
return unmount;
|
|
16
16
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import type { Root } from 'react-dom/client';
|
|
3
|
+
declare const MARK = "__antd_mobile_root__";
|
|
4
|
+
declare type ContainerType = (Element | DocumentFragment) & {
|
|
5
|
+
[MARK]?: Root;
|
|
6
|
+
};
|
|
7
|
+
export declare function render(node: ReactElement, container: ContainerType): void;
|
|
8
|
+
export declare function unmount(container: ContainerType): boolean | Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import * as ReactDOM from 'react-dom'; // Let compiler not to search module usage
|
|
3
|
+
|
|
4
|
+
const fullClone = Object.assign({}, ReactDOM);
|
|
5
|
+
const {
|
|
6
|
+
version,
|
|
7
|
+
render: reactRender,
|
|
8
|
+
unmountComponentAtNode
|
|
9
|
+
} = fullClone;
|
|
10
|
+
let createRoot;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const mainVersion = Number((version || '').split('.')[0]);
|
|
14
|
+
|
|
15
|
+
if (mainVersion >= 18) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
+
createRoot = require('react-dom/client').createRoot;
|
|
18
|
+
}
|
|
19
|
+
} catch (e) {// Do nothing;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const MARK = '__antd_mobile_root__';
|
|
23
|
+
|
|
24
|
+
function legacyRender(node, container) {
|
|
25
|
+
reactRender(node, container);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function concurrentRender(node, container) {
|
|
29
|
+
const root = container[MARK] || createRoot(container);
|
|
30
|
+
root.render(node);
|
|
31
|
+
container[MARK] = root;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function render(node, container) {
|
|
35
|
+
if (createRoot) {
|
|
36
|
+
concurrentRender(node, container);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
legacyRender(node, container);
|
|
41
|
+
} // ========================== Unmount =========================
|
|
42
|
+
|
|
43
|
+
function legacyUnmount(container) {
|
|
44
|
+
return unmountComponentAtNode(container);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function concurrentUnmount(container) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
// Delay to unmount to avoid React 18 sync warning
|
|
50
|
+
return Promise.resolve().then(() => {
|
|
51
|
+
var _a;
|
|
52
|
+
|
|
53
|
+
(_a = container[MARK]) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
54
|
+
delete container[MARK];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function unmount(container) {
|
|
60
|
+
if (createRoot) {
|
|
61
|
+
return concurrentUnmount(container);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return legacyUnmount(container);
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useDragAndPinch: <Config extends import("@use-gesture/react").UserGestureConfig = import("@use-gesture/react").UserGestureConfig>(_handlers: Partial<import("@use-gesture/react").NativeHandlers<import("@use-gesture/react").EventTypes> & import("@use-gesture/react").UserHandlers<import("@use-gesture/react").EventTypes>>, _config?:
|
|
1
|
+
export declare const useDragAndPinch: <Config extends import("@use-gesture/react").UserGestureConfig = import("@use-gesture/react").UserGestureConfig>(_handlers: Partial<import("@use-gesture/react").NativeHandlers<import("@use-gesture/react").EventTypes> & import("@use-gesture/react").UserHandlers<import("@use-gesture/react").EventTypes>>, _config?: Config | undefined) => Config["target"] extends object ? void : (...args: any[]) => import("@use-gesture/react").ReactDOMAttributes;
|
|
@@ -4,5 +4,5 @@ declare type Options<T> = {
|
|
|
4
4
|
defaultValue: T;
|
|
5
5
|
onChange?: (v: T) => void;
|
|
6
6
|
};
|
|
7
|
-
export declare function usePropsValue<T>(options: Options<T>): readonly [T, (
|
|
7
|
+
export declare function usePropsValue<T>(options: Options<T>): readonly [T, (v: SetStateAction<T>) => void];
|
|
8
8
|
export {};
|