antd-mobile 5.5.1 → 5.6.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.
Files changed (123) hide show
  1. package/2x/cjs/components/action-sheet/action-sheet.d.ts +5 -5
  2. package/2x/cjs/components/action-sheet/action-sheet.js +6 -46
  3. package/2x/cjs/components/action-sheet/index.d.ts +1 -1
  4. package/2x/cjs/components/badge/badge.js +1 -1
  5. package/2x/cjs/components/cascader-view/cascader-view.js +7 -0
  6. package/2x/cjs/components/checkbox/checkbox.js +4 -20
  7. package/2x/cjs/components/checkbox/native-input.d.ts +10 -0
  8. package/2x/cjs/components/checkbox/native-input.js +42 -0
  9. package/2x/cjs/components/dialog/index.d.ts +1 -1
  10. package/2x/cjs/components/dialog/show.d.ts +2 -4
  11. package/2x/cjs/components/dialog/show.js +9 -47
  12. package/2x/cjs/components/dot-loading/dot-loading.js +1 -2
  13. package/2x/cjs/components/error-block/error-block.js +4 -2
  14. package/2x/cjs/components/floating-bubble/floating-bubble.css +2 -1
  15. package/2x/cjs/components/floating-bubble/floating-bubble.d.ts +1 -1
  16. package/2x/cjs/components/image-viewer/index.d.ts +1 -1
  17. package/2x/cjs/components/image-viewer/methods.d.ts +3 -4
  18. package/2x/cjs/components/image-viewer/methods.js +41 -56
  19. package/2x/cjs/components/modal/index.d.ts +1 -1
  20. package/2x/cjs/components/modal/show.d.ts +2 -4
  21. package/2x/cjs/components/modal/show.js +9 -47
  22. package/2x/cjs/components/popover/popover.js +1 -0
  23. package/2x/cjs/components/popover/temp-floating-ui.min.js +1 -430
  24. package/2x/cjs/components/radio/radio.js +4 -20
  25. package/2x/cjs/components/search-bar/search-bar.d.ts +1 -1
  26. package/2x/cjs/components/tab-bar/tab-bar.d.ts +1 -1
  27. package/2x/cjs/components/tab-bar/tab-bar.js +1 -1
  28. package/2x/cjs/components/tree-select/tree-select.js +2 -2
  29. package/2x/cjs/utils/render-imperatively.d.ts +10 -0
  30. package/2x/cjs/utils/render-imperatively.js +58 -0
  31. package/2x/es/components/action-sheet/action-sheet.d.ts +5 -5
  32. package/2x/es/components/action-sheet/action-sheet.js +5 -41
  33. package/2x/es/components/action-sheet/index.d.ts +1 -1
  34. package/2x/es/components/badge/badge.js +1 -1
  35. package/2x/es/components/cascader-view/cascader-view.js +7 -0
  36. package/2x/es/components/checkbox/checkbox.js +4 -21
  37. package/2x/es/components/checkbox/native-input.d.ts +10 -0
  38. package/2x/es/components/checkbox/native-input.js +28 -0
  39. package/2x/es/components/dialog/index.d.ts +1 -1
  40. package/2x/es/components/dialog/show.d.ts +2 -4
  41. package/2x/es/components/dialog/show.js +8 -44
  42. package/2x/es/components/dot-loading/dot-loading.js +1 -2
  43. package/2x/es/components/error-block/error-block.js +4 -2
  44. package/2x/es/components/floating-bubble/floating-bubble.css +2 -1
  45. package/2x/es/components/floating-bubble/floating-bubble.d.ts +1 -1
  46. package/2x/es/components/image-viewer/index.d.ts +1 -1
  47. package/2x/es/components/image-viewer/methods.d.ts +3 -4
  48. package/2x/es/components/image-viewer/methods.js +38 -57
  49. package/2x/es/components/modal/index.d.ts +1 -1
  50. package/2x/es/components/modal/show.d.ts +2 -4
  51. package/2x/es/components/modal/show.js +8 -44
  52. package/2x/es/components/popover/popover.js +1 -0
  53. package/2x/es/components/popover/temp-floating-ui.min.js +1 -430
  54. package/2x/es/components/radio/radio.js +4 -21
  55. package/2x/es/components/search-bar/search-bar.d.ts +1 -1
  56. package/2x/es/components/tab-bar/tab-bar.d.ts +1 -1
  57. package/2x/es/components/tab-bar/tab-bar.js +1 -1
  58. package/2x/es/components/tree-select/tree-select.js +2 -2
  59. package/2x/es/utils/render-imperatively.d.ts +10 -0
  60. package/2x/es/utils/render-imperatively.js +45 -0
  61. package/2x/package.json +2 -3
  62. package/cjs/components/action-sheet/action-sheet.d.ts +5 -5
  63. package/cjs/components/action-sheet/action-sheet.js +6 -46
  64. package/cjs/components/action-sheet/index.d.ts +1 -1
  65. package/cjs/components/badge/badge.js +1 -1
  66. package/cjs/components/cascader-view/cascader-view.js +7 -0
  67. package/cjs/components/checkbox/checkbox.js +4 -20
  68. package/cjs/components/checkbox/native-input.d.ts +10 -0
  69. package/cjs/components/checkbox/native-input.js +42 -0
  70. package/cjs/components/dialog/index.d.ts +1 -1
  71. package/cjs/components/dialog/show.d.ts +2 -4
  72. package/cjs/components/dialog/show.js +9 -47
  73. package/cjs/components/dot-loading/dot-loading.js +1 -2
  74. package/cjs/components/error-block/error-block.js +4 -2
  75. package/cjs/components/floating-bubble/floating-bubble.css +2 -1
  76. package/cjs/components/floating-bubble/floating-bubble.d.ts +1 -1
  77. package/cjs/components/image-viewer/index.d.ts +1 -1
  78. package/cjs/components/image-viewer/methods.d.ts +3 -4
  79. package/cjs/components/image-viewer/methods.js +41 -56
  80. package/cjs/components/modal/index.d.ts +1 -1
  81. package/cjs/components/modal/show.d.ts +2 -4
  82. package/cjs/components/modal/show.js +9 -47
  83. package/cjs/components/popover/popover.js +1 -0
  84. package/cjs/components/popover/temp-floating-ui.min.js +1 -430
  85. package/cjs/components/radio/radio.js +4 -20
  86. package/cjs/components/search-bar/search-bar.d.ts +1 -1
  87. package/cjs/components/tab-bar/tab-bar.d.ts +1 -1
  88. package/cjs/components/tab-bar/tab-bar.js +1 -1
  89. package/cjs/components/tree-select/tree-select.js +2 -2
  90. package/cjs/utils/render-imperatively.d.ts +10 -0
  91. package/cjs/utils/render-imperatively.js +58 -0
  92. package/es/components/action-sheet/action-sheet.d.ts +5 -5
  93. package/es/components/action-sheet/action-sheet.js +5 -41
  94. package/es/components/action-sheet/index.d.ts +1 -1
  95. package/es/components/badge/badge.js +1 -1
  96. package/es/components/cascader-view/cascader-view.js +7 -0
  97. package/es/components/checkbox/checkbox.js +4 -21
  98. package/es/components/checkbox/native-input.d.ts +10 -0
  99. package/es/components/checkbox/native-input.js +28 -0
  100. package/es/components/dialog/index.d.ts +1 -1
  101. package/es/components/dialog/show.d.ts +2 -4
  102. package/es/components/dialog/show.js +8 -44
  103. package/es/components/dot-loading/dot-loading.js +1 -2
  104. package/es/components/error-block/error-block.js +4 -2
  105. package/es/components/floating-bubble/floating-bubble.css +2 -1
  106. package/es/components/floating-bubble/floating-bubble.d.ts +1 -1
  107. package/es/components/image-viewer/index.d.ts +1 -1
  108. package/es/components/image-viewer/methods.d.ts +3 -4
  109. package/es/components/image-viewer/methods.js +38 -57
  110. package/es/components/modal/index.d.ts +1 -1
  111. package/es/components/modal/show.d.ts +2 -4
  112. package/es/components/modal/show.js +8 -44
  113. package/es/components/popover/popover.js +1 -0
  114. package/es/components/popover/temp-floating-ui.min.js +1 -430
  115. package/es/components/radio/radio.js +4 -21
  116. package/es/components/search-bar/search-bar.d.ts +1 -1
  117. package/es/components/tab-bar/tab-bar.d.ts +1 -1
  118. package/es/components/tab-bar/tab-bar.js +1 -1
  119. package/es/components/tree-select/tree-select.js +2 -2
  120. package/es/utils/render-imperatively.d.ts +10 -0
  121. package/es/utils/render-imperatively.js +45 -0
  122. package/package.json +2 -3
  123. package/umd/antd-mobile.js +1 -1
@@ -1,11 +1,11 @@
1
- import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
1
+ import React from 'react';
2
2
  import { withNativeProps } from '../../utils/native-props';
3
3
  import { mergeProps } from '../../utils/with-default-props';
4
4
  import classNames from 'classnames';
5
5
  import Popup from '../popup';
6
6
  import Button from '../button';
7
- import { renderToBody } from '../../utils/render-to-body';
8
7
  import SafeArea from '../safe-area';
8
+ import { renderImperatively } from '../../utils/render-imperatively';
9
9
  const classPrefix = `adm-action-sheet`;
10
10
  const defaultProps = {
11
11
  visible: false,
@@ -29,7 +29,8 @@ export const ActionSheet = p => {
29
29
  }
30
30
  },
31
31
  afterClose: props.afterClose,
32
- className: `${classPrefix}-popup`,
32
+ className: classNames(`${classPrefix}-popup`, props.popupClassName),
33
+ style: props.popupStyle,
33
34
  getContainer: props.getContainer
34
35
  }, withNativeProps(props, React.createElement("div", {
35
36
  className: classPrefix
@@ -83,42 +84,5 @@ export const ActionSheet = p => {
83
84
  }))));
84
85
  };
85
86
  export function showActionSheet(props) {
86
- const Wrapper = forwardRef((_, ref) => {
87
- const [visible, setVisible] = useState(false);
88
- useEffect(() => {
89
- setVisible(true);
90
- }, []);
91
-
92
- function handleClose() {
93
- var _a;
94
-
95
- (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
96
- setVisible(false);
97
- }
98
-
99
- useImperativeHandle(ref, () => ({
100
- close: handleClose
101
- }));
102
- return React.createElement(ActionSheet, Object.assign({}, props, {
103
- visible: visible,
104
- onClose: handleClose,
105
- afterClose: () => {
106
- var _a;
107
-
108
- (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
109
- unmount();
110
- }
111
- }));
112
- });
113
- const ref = createRef();
114
- const unmount = renderToBody(React.createElement(Wrapper, {
115
- ref: ref
116
- }));
117
- return {
118
- close: () => {
119
- var _a;
120
-
121
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
122
- }
123
- };
87
+ return renderImperatively(React.createElement(ActionSheet, Object.assign({}, props)));
124
88
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import './action-sheet.less';
3
3
  import { showActionSheet } from './action-sheet';
4
- export type { Action, ActionSheetProps, ActionSheetRef } from './action-sheet';
4
+ export type { Action, ActionSheetProps, ActionSheetShowHandler, } from './action-sheet';
5
5
  declare const _default: import("react").FC<import("./action-sheet").ActionSheetProps> & {
6
6
  show: typeof showActionSheet;
7
7
  };
@@ -11,7 +11,7 @@ export const Badge = props => {
11
11
  } = props;
12
12
  const isDot = content === dot;
13
13
  const badgeCls = classNames(classPrefix, !!children && `${classPrefix}-fixed`, isDot && `${classPrefix}-dot`, props.bordered && `${classPrefix}-bordered`);
14
- const element = content ? withNativeProps(props, React.createElement("div", {
14
+ const element = content || content === 0 ? withNativeProps(props, React.createElement("div", {
15
15
  className: badgeCls,
16
16
  style: {
17
17
  '--color': color
@@ -61,6 +61,13 @@ export const CascaderView = p => {
61
61
  useEffect(() => {
62
62
  setTabActiveKey(levels.length - 1);
63
63
  }, [value]);
64
+ useEffect(() => {
65
+ const max = levels.length - 1;
66
+
67
+ if (tabActiveKey > max) {
68
+ setTabActiveKey(max);
69
+ }
70
+ }, [tabActiveKey, levels]);
64
71
 
65
72
  const onItemSelect = (selectValue, depth) => {
66
73
  const next = value.slice(0, depth);
@@ -1,4 +1,4 @@
1
- import React, { useContext, useEffect, useRef } from 'react';
1
+ import React, { useContext } from 'react';
2
2
  import { withNativeProps } from '../../utils/native-props';
3
3
  import classNames from 'classnames';
4
4
  import { CheckboxGroupContext } from './group-context';
@@ -8,6 +8,7 @@ import { devWarning } from '../../utils/dev-log';
8
8
  import { CheckIcon } from './check-icon';
9
9
  import { IndeterminateIcon } from './indeterminate-icon';
10
10
  import { isDev } from '../../utils/is-dev';
11
+ import { NativeInput } from './native-input';
11
12
  const classPrefix = `adm-checkbox`;
12
13
  const defaultProps = {
13
14
  defaultChecked: false,
@@ -66,35 +67,17 @@ export const Checkbox = p => {
66
67
  }, props.indeterminate ? React.createElement(IndeterminateIcon, null) : checked && React.createElement(CheckIcon, null));
67
68
  };
68
69
 
69
- const inputRef = useRef(null);
70
- const labelRef = useRef(null);
71
- useEffect(() => {
72
- var _a;
73
-
74
- (_a = labelRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('click', e => {
75
- if (e.target !== inputRef.current) {
76
- e.stopPropagation();
77
- e.stopImmediatePropagation();
78
- }
79
- }, {
80
- capture: false
81
- });
82
- }, []);
83
70
  return withNativeProps(props, React.createElement("label", {
84
- ref: labelRef,
85
71
  className: classNames(classPrefix, {
86
72
  [`${classPrefix}-checked`]: checked && !props.indeterminate,
87
73
  [`${classPrefix}-indeterminate`]: props.indeterminate,
88
74
  [`${classPrefix}-disabled`]: disabled,
89
75
  [`${classPrefix}-block`]: props.block
90
76
  })
91
- }, React.createElement("input", {
92
- ref: inputRef,
77
+ }, React.createElement(NativeInput, {
93
78
  type: 'checkbox',
94
79
  checked: checked,
95
- onChange: e => {
96
- setChecked(e.target.checked);
97
- },
80
+ onChange: setChecked,
98
81
  disabled: disabled,
99
82
  id: props.id
100
83
  }), renderIcon(), props.children && React.createElement("div", {
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+ interface Props {
3
+ type: 'checkbox' | 'radio';
4
+ checked: boolean;
5
+ onChange: (checked: boolean) => void;
6
+ disabled?: boolean;
7
+ id?: string;
8
+ }
9
+ export declare const NativeInput: FC<Props>;
10
+ export {};
@@ -0,0 +1,28 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ export const NativeInput = props => {
3
+ const inputRef = useRef(null);
4
+ useEffect(() => {
5
+ if (props.disabled) return;
6
+ if (!inputRef.current) return;
7
+ const input = inputRef.current;
8
+
9
+ function handleClick(e) {
10
+ e.stopPropagation();
11
+ e.stopImmediatePropagation();
12
+ props.onChange(input.checked);
13
+ }
14
+
15
+ input.addEventListener('click', handleClick);
16
+ return () => {
17
+ input.removeEventListener('click', handleClick);
18
+ };
19
+ }, [props.disabled, props.onChange]);
20
+ return React.createElement("input", {
21
+ ref: inputRef,
22
+ type: 'checkbox',
23
+ checked: props.checked,
24
+ onChange: () => {},
25
+ disabled: props.disabled,
26
+ id: props.id
27
+ });
28
+ };
@@ -6,7 +6,7 @@ import { confirm } from './confirm';
6
6
  import { clear } from './clear';
7
7
  export type { DialogProps } from './dialog';
8
8
  export type { Action } from './dialog-action-button';
9
- export type { DialogShowProps, DialogShowRef } from './show';
9
+ export type { DialogShowProps, DialogShowHandler } from './show';
10
10
  export type { DialogAlertProps } from './alert';
11
11
  export type { DialogConfirmProps } from './confirm';
12
12
  declare const _default: import("react").FC<import("./dialog").DialogProps> & {
@@ -1,9 +1,7 @@
1
1
  import { DialogProps } from './dialog';
2
2
  export declare type DialogShowProps = Omit<DialogProps, 'visible'>;
3
- export declare type DialogShowRef = {
3
+ export declare type DialogShowHandler = {
4
4
  close: () => void;
5
5
  };
6
6
  export declare const closeFnSet: Set<() => void>;
7
- export declare function show(props: DialogShowProps): {
8
- close: () => void;
9
- };
7
+ export declare function show(props: DialogShowProps): DialogShowHandler;
@@ -1,52 +1,16 @@
1
- import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
2
- import { renderToBody } from '../../utils/render-to-body';
1
+ import React from 'react';
3
2
  import { Dialog } from './dialog';
3
+ import { renderImperatively } from '../../utils/render-imperatively';
4
4
  export const closeFnSet = new Set();
5
5
  export function show(props) {
6
- const Wrapper = forwardRef((_, ref) => {
7
- const [visible, setVisible] = useState(false);
8
- useEffect(() => {
9
- setVisible(true);
10
- }, []);
11
-
12
- function handleClose() {
13
- var _a;
14
-
15
- (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
16
- setVisible(false);
17
- }
18
-
19
- useImperativeHandle(ref, () => ({
20
- close: handleClose
21
- }));
22
-
23
- function handleAfterClose() {
6
+ const handler = renderImperatively(React.createElement(Dialog, Object.assign({}, props, {
7
+ afterClose: () => {
24
8
  var _a;
25
9
 
10
+ closeFnSet.delete(handler.close);
26
11
  (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
27
- unmount();
28
- closeFnSet.delete(close);
29
12
  }
30
-
31
- return React.createElement(Dialog, Object.assign({}, props, {
32
- visible: visible,
33
- onClose: handleClose,
34
- afterClose: handleAfterClose
35
- }));
36
- });
37
- const ref = createRef();
38
- const unmount = renderToBody(React.createElement(Wrapper, {
39
- ref: ref
40
- }));
41
-
42
- const close = () => {
43
- var _a;
44
-
45
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
46
- };
47
-
48
- closeFnSet.add(close);
49
- return {
50
- close
51
- };
13
+ })));
14
+ closeFnSet.add(handler.close);
15
+ return handler;
52
16
  }
@@ -53,7 +53,6 @@ export const DotLoading = memo(p => {
53
53
  begin: `${i * 0.2}s`,
54
54
  repeatCount: 'indefinite',
55
55
  values: '16; 6; 26; 16; 16',
56
- keyTimes: '0; 0.1; 0.3; 0.4; 1',
57
- id: 'circ-anim'
56
+ keyTimes: '0; 0.1; 0.3; 0.4; 1'
58
57
  }))))))))));
59
58
  });
@@ -18,13 +18,15 @@ export const ErrorBlock = p => {
18
18
  const des = 'description' in props ? props.description : contentPack.description;
19
19
  const title = 'title' in props ? props.title : contentPack.title;
20
20
  let imageNode = React.createElement("img", {
21
- src: icon
21
+ src: icon,
22
+ alt: 'error block image'
22
23
  });
23
24
 
24
25
  if (props.image) {
25
26
  if (typeof props.image === 'string') {
26
27
  imageNode = React.createElement("img", {
27
- src: props.image
28
+ src: props.image,
29
+ alt: 'error block image'
28
30
  });
29
31
  } else {
30
32
  imageNode = props.image;
@@ -7,6 +7,7 @@
7
7
  --edge-distance: 0;
8
8
  --size: 96px;
9
9
  --border-radius: 50%;
10
+ --background: var(--adm-color-primary);
10
11
  }
11
12
 
12
13
  .adm-floating-bubble-boundary-outer {
@@ -43,7 +44,7 @@
43
44
  transition: opacity ease 0.15s;
44
45
  user-select: none;
45
46
  touch-action: none;
46
- background: var(--adm-color-primary);
47
+ background: var(--background);
47
48
  color: var(--adm-color-white);
48
49
  border-radius: var(--border-radius);
49
50
  z-index: var(--z-index);
@@ -4,5 +4,5 @@ export declare type FloatingBubbleProps = {
4
4
  onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
5
5
  axis?: 'x' | 'y' | 'xy' | 'lock';
6
6
  magnetic?: 'x' | 'y';
7
- } & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius'>;
7
+ } & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius' | '--background'>;
8
8
  export declare const FloatingBubble: FC<FloatingBubbleProps>;
@@ -2,7 +2,7 @@
2
2
  import './image-viewer.less';
3
3
  import { showMultiImageViewer, showImageViewer, clearImageViewer } from './methods';
4
4
  export type { ImageViewerProps, MultiImageViewerProps, MultiImageViewerRef, } from './image-viewer';
5
- export type { ImageViewerHandler } from './methods';
5
+ export type { ImageViewerShowHandler } from './methods';
6
6
  declare const _default: import("react").FC<import("./image-viewer").ImageViewerProps> & {
7
7
  Multi: import("react").ForwardRefExoticComponent<Omit<import("./image-viewer").ImageViewerProps, "image"> & {
8
8
  images?: string[] | undefined;
@@ -1,11 +1,10 @@
1
1
  import { ImageViewerProps, MultiImageViewerProps } from './image-viewer';
2
- export declare type ImageViewerHandler = {
3
- close: () => void;
4
- };
5
- export declare function showImageViewer(props: Omit<ImageViewerProps, 'visible'>): {
2
+ export declare type ImageViewerShowHandler = {
6
3
  close: () => void;
7
4
  };
5
+ export declare function showImageViewer(props: Omit<ImageViewerProps, 'visible'>): ImageViewerShowHandler;
8
6
  export declare function showMultiImageViewer(props: Omit<MultiImageViewerProps, 'visible'>): {
9
7
  close: () => void;
10
8
  };
11
9
  export declare function clearImageViewer(): void;
10
+ export declare const getH: () => void;
@@ -1,49 +1,18 @@
1
- import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
1
+ import React, { createRef, forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
2
  import { renderToBody } from '../../utils/render-to-body';
3
3
  import { ImageViewer, MultiImageViewer } from './image-viewer';
4
- import { useUnmountedRef } from 'ahooks';
4
+ import { renderImperatively } from '../../utils/render-imperatively';
5
5
  const handlerSet = new Set();
6
6
  export function showImageViewer(props) {
7
7
  clearImageViewer();
8
- const Wrapper = forwardRef((_, ref) => {
9
- const [visible, setVisible] = useState(false);
10
- useEffect(() => {
11
- setVisible(true);
12
- }, []);
13
- const isUnmountedRef = useUnmountedRef();
14
- useImperativeHandle(ref, () => ({
15
- close: () => {
16
- if (isUnmountedRef.current) return;
17
- setVisible(false);
18
- }
19
- }));
20
- return React.createElement(ImageViewer, Object.assign({}, props, {
21
- visible: visible,
22
- onClose: () => {
23
- var _a;
24
-
25
- (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
26
- setVisible(false);
27
- },
28
- afterClose: () => {
29
- var _a;
30
-
31
- (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
32
- unmount();
33
- }
34
- }));
35
- });
36
- const ref = createRef();
37
- const unmount = renderToBody(React.createElement(Wrapper, {
38
- ref: ref
39
- }));
40
- const handler = {
41
- close: () => {
8
+ const handler = renderImperatively(React.createElement(ImageViewer, Object.assign({}, props, {
9
+ afterClose: () => {
42
10
  var _a;
43
11
 
44
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
12
+ handlerSet.delete(handler);
13
+ (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
45
14
  }
46
- };
15
+ })));
47
16
  handlerSet.add(handler);
48
17
  return handler;
49
18
  }
@@ -51,30 +20,39 @@ export function showMultiImageViewer(props) {
51
20
  clearImageViewer();
52
21
  const Wrapper = forwardRef((_, ref) => {
53
22
  const [visible, setVisible] = useState(false);
23
+ const closedRef = useRef(false);
54
24
  useEffect(() => {
55
- setVisible(true);
25
+ if (!closedRef.current) {
26
+ setVisible(true);
27
+ } else {
28
+ handleAfterClose();
29
+ }
56
30
  }, []);
57
- const isUnmountedRef = useUnmountedRef();
31
+
32
+ function handleClose() {
33
+ var _a;
34
+
35
+ closedRef.current = true;
36
+ (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
37
+ setVisible(false);
38
+ }
39
+
58
40
  useImperativeHandle(ref, () => ({
59
- close: () => {
60
- if (isUnmountedRef.current) return;
61
- setVisible(false);
62
- }
41
+ close: handleClose
63
42
  }));
64
- return React.createElement(MultiImageViewer, Object.assign({}, props, {
65
- visible: visible,
66
- onClose: () => {
67
- var _a;
68
43
 
69
- (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
70
- setVisible(false);
71
- },
72
- afterClose: () => {
73
- var _a;
44
+ function handleAfterClose() {
45
+ var _a;
74
46
 
75
- (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
76
- unmount();
77
- }
47
+ (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
48
+ unmount();
49
+ handlerSet.delete(handler);
50
+ }
51
+
52
+ return React.createElement(MultiImageViewer, Object.assign({}, props, {
53
+ visible: visible,
54
+ onClose: handleClose,
55
+ afterClose: handleAfterClose
78
56
  }));
79
57
  });
80
58
  const ref = createRef();
@@ -96,4 +74,7 @@ export function clearImageViewer() {
96
74
  handler.close();
97
75
  });
98
76
  handlerSet.clear();
99
- }
77
+ }
78
+ export const getH = () => {
79
+ console.log(handlerSet);
80
+ };
@@ -6,7 +6,7 @@ import { confirm } from './confirm';
6
6
  import { clear } from './clear';
7
7
  export type { ModalProps } from './modal';
8
8
  export type { Action } from './modal-action-button';
9
- export type { ModalShowProps, ModalShowRef } from './show';
9
+ export type { ModalShowProps, ModalShowHandler } from './show';
10
10
  export type { ModalAlertProps } from './alert';
11
11
  export type { ModalConfirmProps } from './confirm';
12
12
  declare const _default: import("react").FC<import("./modal").ModalProps> & {
@@ -1,9 +1,7 @@
1
1
  import { ModalProps } from './modal';
2
2
  export declare type ModalShowProps = Omit<ModalProps, 'visible'>;
3
- export declare type ModalShowRef = {
3
+ export declare type ModalShowHandler = {
4
4
  close: () => void;
5
5
  };
6
6
  export declare const closeFnSet: Set<() => void>;
7
- export declare function show(props: ModalShowProps): {
8
- close: () => void;
9
- };
7
+ export declare function show(props: ModalShowProps): ModalShowHandler;
@@ -1,52 +1,16 @@
1
- import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
2
- import { renderToBody } from '../../utils/render-to-body';
1
+ import React from 'react';
3
2
  import { Modal } from './modal';
3
+ import { renderImperatively } from '../../utils/render-imperatively';
4
4
  export const closeFnSet = new Set();
5
5
  export function show(props) {
6
- const Wrapper = forwardRef((_, ref) => {
7
- const [visible, setVisible] = useState(false);
8
- useEffect(() => {
9
- setVisible(true);
10
- }, []);
11
-
12
- function handleClose() {
13
- var _a;
14
-
15
- (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
16
- setVisible(false);
17
- }
18
-
19
- useImperativeHandle(ref, () => ({
20
- close: handleClose
21
- }));
22
-
23
- function handleAfterClose() {
6
+ const handler = renderImperatively(React.createElement(Modal, Object.assign({}, props, {
7
+ afterClose: () => {
24
8
  var _a;
25
9
 
10
+ closeFnSet.delete(handler.close);
26
11
  (_a = props.afterClose) === null || _a === void 0 ? void 0 : _a.call(props);
27
- unmount();
28
- closeFnSet.delete(close);
29
12
  }
30
-
31
- return React.createElement(Modal, Object.assign({}, props, {
32
- visible: visible,
33
- onClose: handleClose,
34
- afterClose: handleAfterClose
35
- }));
36
- });
37
- const ref = createRef();
38
- const unmount = renderToBody(React.createElement(Wrapper, {
39
- ref: ref
40
- }));
41
-
42
- const close = () => {
43
- var _a;
44
-
45
- (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
46
- };
47
-
48
- closeFnSet.add(close);
49
- return {
50
- close
51
- };
13
+ })));
14
+ closeFnSet.add(handler.close);
15
+ return handler;
52
16
  }
@@ -121,6 +121,7 @@ export const Popover = forwardRef((p, ref) => {
121
121
  if (!props.trigger) return;
122
122
 
123
123
  function handleClick() {
124
+ console.log('handleClick');
124
125
  setVisible(v => !v);
125
126
  }
126
127