@tendaui/react 1.1.1

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 (244) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/es/_chunks/dep-0QH2Ee4R.js +34 -0
  4. package/es/_chunks/dep-0QH2Ee4R.js.map +1 -0
  5. package/es/_chunks/dep-B7HmDtze.js +199 -0
  6. package/es/_chunks/dep-B7HmDtze.js.map +1 -0
  7. package/es/_chunks/dep-BH5n5r1M.js +55 -0
  8. package/es/_chunks/dep-BH5n5r1M.js.map +1 -0
  9. package/es/_chunks/dep-BP0-apUT.js +9 -0
  10. package/es/_chunks/dep-BP0-apUT.js.map +1 -0
  11. package/es/_chunks/dep-C1XcmShP.js +18 -0
  12. package/es/_chunks/dep-C1XcmShP.js.map +1 -0
  13. package/es/_chunks/dep-C36au4Ip.js +104 -0
  14. package/es/_chunks/dep-C36au4Ip.js.map +1 -0
  15. package/es/_chunks/dep-CgyDw_YI.js +20 -0
  16. package/es/_chunks/dep-CgyDw_YI.js.map +1 -0
  17. package/es/_chunks/dep-CoIiHOgo.js +162 -0
  18. package/es/_chunks/dep-CoIiHOgo.js.map +1 -0
  19. package/es/_chunks/dep-Cwish4GD.js +29 -0
  20. package/es/_chunks/dep-Cwish4GD.js.map +1 -0
  21. package/es/_chunks/dep-CzLhKWCf.js +56 -0
  22. package/es/_chunks/dep-CzLhKWCf.js.map +1 -0
  23. package/es/_chunks/dep-D-UKOauR.js +12 -0
  24. package/es/_chunks/dep-D-UKOauR.js.map +1 -0
  25. package/es/_chunks/dep-D6YxJv-F.js +31 -0
  26. package/es/_chunks/dep-D6YxJv-F.js.map +1 -0
  27. package/es/_chunks/dep-D7LanWes.js +171 -0
  28. package/es/_chunks/dep-D7LanWes.js.map +1 -0
  29. package/es/_chunks/dep-D8jki30S.js +31 -0
  30. package/es/_chunks/dep-D8jki30S.js.map +1 -0
  31. package/es/_chunks/dep-DB5wmwh1.js +48 -0
  32. package/es/_chunks/dep-DB5wmwh1.js.map +1 -0
  33. package/es/_chunks/dep-DGvfel3I.js +16 -0
  34. package/es/_chunks/dep-DGvfel3I.js.map +1 -0
  35. package/es/_chunks/dep-DHWwZ2Nj.js +139 -0
  36. package/es/_chunks/dep-DHWwZ2Nj.js.map +1 -0
  37. package/es/_chunks/dep-DN7d1SzH.js +24 -0
  38. package/es/_chunks/dep-DN7d1SzH.js.map +1 -0
  39. package/es/_chunks/dep-DZ_0EvBk.js +440 -0
  40. package/es/_chunks/dep-DZ_0EvBk.js.map +1 -0
  41. package/es/_chunks/dep-Dk2xX8lh.js +691 -0
  42. package/es/_chunks/dep-Dk2xX8lh.js.map +1 -0
  43. package/es/_chunks/dep-DwWrhxkd.js +26 -0
  44. package/es/_chunks/dep-DwWrhxkd.js.map +1 -0
  45. package/es/_chunks/dep-EcrDKDlu.js +1677 -0
  46. package/es/_chunks/dep-EcrDKDlu.js.map +1 -0
  47. package/es/_chunks/dep-PPA-yoAy.js +16 -0
  48. package/es/_chunks/dep-PPA-yoAy.js.map +1 -0
  49. package/es/_chunks/dep-U1T8CQY9.js +4 -0
  50. package/es/_chunks/dep-U1T8CQY9.js.map +1 -0
  51. package/es/_chunks/dep-bWaVq_y3.js +14 -0
  52. package/es/_chunks/dep-bWaVq_y3.js.map +1 -0
  53. package/es/_chunks/dep-u1x3x6MJ.js +9 -0
  54. package/es/_chunks/dep-u1x3x6MJ.js.map +1 -0
  55. package/es/alert/Alert.js +153 -0
  56. package/es/alert/Alert.js.map +1 -0
  57. package/es/alert/index.js +23 -0
  58. package/es/alert/index.js.map +1 -0
  59. package/es/alert/style/css.js +1 -0
  60. package/es/alert/style/index.css +172 -0
  61. package/es/alert/style/index.js +2 -0
  62. package/es/alert/style/index.js.map +1 -0
  63. package/es/badge/Badge.js +81 -0
  64. package/es/badge/Badge.js.map +1 -0
  65. package/es/badge/index.js +15 -0
  66. package/es/badge/index.js.map +1 -0
  67. package/es/badge/style/css.js +1 -0
  68. package/es/badge/style/index.css +60 -0
  69. package/es/badge/style/index.js +2 -0
  70. package/es/badge/style/index.js.map +1 -0
  71. package/es/button/Button.js +94 -0
  72. package/es/button/Button.js.map +1 -0
  73. package/es/button/index.js +28 -0
  74. package/es/button/index.js.map +1 -0
  75. package/es/button/style/css.js +1 -0
  76. package/es/button/style/index.css +1206 -0
  77. package/es/button/style/index.js +2 -0
  78. package/es/button/style/index.js.map +1 -0
  79. package/es/checkbox/Checkbox.js +17 -0
  80. package/es/checkbox/Checkbox.js.map +1 -0
  81. package/es/checkbox/CheckboxGroup.js +17 -0
  82. package/es/checkbox/CheckboxGroup.js.map +1 -0
  83. package/es/checkbox/index.js +22 -0
  84. package/es/checkbox/index.js.map +1 -0
  85. package/es/checkbox/style/css.js +1 -0
  86. package/es/checkbox/style/index.css +151 -0
  87. package/es/checkbox/style/index.js +2 -0
  88. package/es/checkbox/style/index.js.map +1 -0
  89. package/es/common/Check.js +101 -0
  90. package/es/common/Check.js.map +1 -0
  91. package/es/common/FakeArrow.js +28 -0
  92. package/es/common/FakeArrow.js.map +1 -0
  93. package/es/common/PluginContainer.js +19 -0
  94. package/es/common/PluginContainer.js.map +1 -0
  95. package/es/common/Portal.js +53 -0
  96. package/es/common/Portal.js.map +1 -0
  97. package/es/config-provider/ConfigContext.js +17 -0
  98. package/es/config-provider/ConfigContext.js.map +1 -0
  99. package/es/config-provider/ConfigProvider.js +45 -0
  100. package/es/config-provider/ConfigProvider.js.map +1 -0
  101. package/es/config-provider/index.js +12 -0
  102. package/es/config-provider/index.js.map +1 -0
  103. package/es/dialog/Dialog.js +575 -0
  104. package/es/dialog/Dialog.js.map +1 -0
  105. package/es/dialog/DialogCard.js +28 -0
  106. package/es/dialog/DialogCard.js.map +1 -0
  107. package/es/dialog/index.js +44 -0
  108. package/es/dialog/index.js.map +1 -0
  109. package/es/dialog/plugin.js +199 -0
  110. package/es/dialog/plugin.js.map +1 -0
  111. package/es/dialog/style/css.js +1 -0
  112. package/es/dialog/style/index.css +510 -0
  113. package/es/dialog/style/index.js +2 -0
  114. package/es/dialog/style/index.js.map +1 -0
  115. package/es/form/Form.js +190 -0
  116. package/es/form/Form.js.map +1 -0
  117. package/es/form/FormContext.js +38 -0
  118. package/es/form/FormContext.js.map +1 -0
  119. package/es/form/FormItem.js +39 -0
  120. package/es/form/FormItem.js.map +1 -0
  121. package/es/form/FormList.js +306 -0
  122. package/es/form/FormList.js.map +1 -0
  123. package/es/form/hooks/useFormItemStyle.js +10 -0
  124. package/es/form/hooks/useFormItemStyle.js.map +1 -0
  125. package/es/form/hooks/useInstance.js +326 -0
  126. package/es/form/hooks/useInstance.js.map +1 -0
  127. package/es/form/index.js +47 -0
  128. package/es/form/index.js.map +1 -0
  129. package/es/form/style/css.js +1 -0
  130. package/es/form/style/index.css +296 -0
  131. package/es/form/style/index.js +2 -0
  132. package/es/form/style/index.js.map +1 -0
  133. package/es/form/utils/index.js +75 -0
  134. package/es/form/utils/index.js.map +1 -0
  135. package/es/hooks/useDragSorter.js +137 -0
  136. package/es/hooks/useDragSorter.js.map +1 -0
  137. package/es/index.js +103 -0
  138. package/es/index.js.map +1 -0
  139. package/es/input/Input.js +375 -0
  140. package/es/input/Input.js.map +1 -0
  141. package/es/input/InputGroup.js +23 -0
  142. package/es/input/InputGroup.js.map +1 -0
  143. package/es/input/index.js +23 -0
  144. package/es/input/index.js.map +1 -0
  145. package/es/input/style/css.js +1 -0
  146. package/es/input/style/index.css +450 -0
  147. package/es/input/style/index.js +2 -0
  148. package/es/input/style/index.js.map +1 -0
  149. package/es/loading/Gradient.js +86 -0
  150. package/es/loading/Gradient.js.map +1 -0
  151. package/es/loading/Loading.js +147 -0
  152. package/es/loading/Loading.js.map +1 -0
  153. package/es/loading/index.js +24 -0
  154. package/es/loading/index.js.map +1 -0
  155. package/es/loading/style/css.js +1 -0
  156. package/es/loading/style/index.css +191 -0
  157. package/es/loading/style/index.js +2 -0
  158. package/es/loading/style/index.js.map +1 -0
  159. package/es/myform/index.js +2 -0
  160. package/es/myform/index.js.map +1 -0
  161. package/es/notification/NotifyContainer.js +78 -0
  162. package/es/notification/NotifyContainer.js.map +1 -0
  163. package/es/notification/NotifyContext.js +149 -0
  164. package/es/notification/NotifyContext.js.map +1 -0
  165. package/es/notification/NotifyItem.js +150 -0
  166. package/es/notification/NotifyItem.js.map +1 -0
  167. package/es/notification/index.js +32 -0
  168. package/es/notification/index.js.map +1 -0
  169. package/es/notification/style/css.js +1 -0
  170. package/es/notification/style/index.css +142 -0
  171. package/es/notification/style/index.js +2 -0
  172. package/es/notification/style/index.js.map +1 -0
  173. package/es/popup/Popup.js +790 -0
  174. package/es/popup/Popup.js.map +1 -0
  175. package/es/popup/index.js +28 -0
  176. package/es/popup/index.js.map +1 -0
  177. package/es/popup/style/css.js +1 -0
  178. package/es/popup/style/index.css +186 -0
  179. package/es/popup/style/index.js +2 -0
  180. package/es/popup/style/index.js.map +1 -0
  181. package/es/portal/Portal.js +48 -0
  182. package/es/portal/Portal.js.map +1 -0
  183. package/es/portal/index.js +7 -0
  184. package/es/portal/index.js.map +1 -0
  185. package/es/select/Option.js +118 -0
  186. package/es/select/Option.js.map +1 -0
  187. package/es/select/OptionGroup.js +9 -0
  188. package/es/select/OptionGroup.js.map +1 -0
  189. package/es/select/PopupContent.js +16 -0
  190. package/es/select/PopupContent.js.map +1 -0
  191. package/es/select/Select.js +709 -0
  192. package/es/select/Select.js.map +1 -0
  193. package/es/select/index.js +66 -0
  194. package/es/select/index.js.map +1 -0
  195. package/es/select/style/css.js +1 -0
  196. package/es/select/style/index.css +437 -0
  197. package/es/select/style/index.js +2 -0
  198. package/es/select/style/index.js.map +1 -0
  199. package/es/select-input/SelectInput.js +202 -0
  200. package/es/select-input/SelectInput.js.map +1 -0
  201. package/es/select-input/hook/useMultiple.js +118 -0
  202. package/es/select-input/hook/useMultiple.js.map +1 -0
  203. package/es/select-input/hook/useSingle.js +105 -0
  204. package/es/select-input/hook/useSingle.js.map +1 -0
  205. package/es/select-input/index.js +51 -0
  206. package/es/select-input/index.js.map +1 -0
  207. package/es/select-input/style/css.js +1 -0
  208. package/es/select-input/style/index.css +0 -0
  209. package/es/select-input/style/index.js +2 -0
  210. package/es/select-input/style/index.js.map +1 -0
  211. package/es/space/index.js +2 -0
  212. package/es/space/index.js.map +1 -0
  213. package/es/style/index.css +490 -0
  214. package/es/style/index.js +2 -0
  215. package/es/style/index.js.map +1 -0
  216. package/es/switch/Switch.js +174 -0
  217. package/es/switch/Switch.js.map +1 -0
  218. package/es/switch/index.js +28 -0
  219. package/es/switch/index.js.map +1 -0
  220. package/es/switch/style/css.js +1 -0
  221. package/es/switch/style/index.css +239 -0
  222. package/es/switch/style/index.js +2 -0
  223. package/es/switch/style/index.js.map +1 -0
  224. package/es/tag/Tag.js +1312 -0
  225. package/es/tag/Tag.js.map +1 -0
  226. package/es/tag/index.js +21 -0
  227. package/es/tag/index.js.map +1 -0
  228. package/es/tag/style/css.js +1 -0
  229. package/es/tag/style/index.css +236 -0
  230. package/es/tag/style/index.js +2 -0
  231. package/es/tag/style/index.js.map +1 -0
  232. package/es/tag-input/TagInput.js +360 -0
  233. package/es/tag-input/TagInput.js.map +1 -0
  234. package/es/tag-input/hooks/useTagList.js +167 -0
  235. package/es/tag-input/hooks/useTagList.js.map +1 -0
  236. package/es/tag-input/index.js +35 -0
  237. package/es/tag-input/index.js.map +1 -0
  238. package/es/tag-input/style/css.js +1 -0
  239. package/es/tag-input/style/index.css +223 -0
  240. package/es/tag-input/style/index.js +2 -0
  241. package/es/tag-input/style/index.js.map +1 -0
  242. package/es/tag-input/useTagList.js +167 -0
  243. package/es/tag-input/useTagList.js.map +1 -0
  244. package/package.json +59 -0
@@ -0,0 +1,575 @@
1
+ import { _ as _defineProperty } from '../_chunks/dep-Cwish4GD.js';
2
+ import { _ as _slicedToArray } from '../_chunks/dep-CzLhKWCf.js';
3
+ import { _ as _objectWithoutProperties } from '../_chunks/dep-DN7d1SzH.js';
4
+ import React, { useMemo, useState, useCallback, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
5
+ import { CSSTransition } from 'react-transition-group';
6
+ import classNames from 'classnames';
7
+ import { isUndefined } from 'lodash-es';
8
+ import Portal from '../common/Portal.js';
9
+ import { u as useConfig } from '../_chunks/dep-u1x3x6MJ.js';
10
+ import { u as useDefaultProps } from '../_chunks/dep-DGvfel3I.js';
11
+ import { d as dialogDefaultProps, D as DialogCard } from '../_chunks/dep-CoIiHOgo.js';
12
+ import { _ as _typeof } from '../_chunks/dep-D-UKOauR.js';
13
+ import { _ as _toConsumableArray } from '../_chunks/dep-CgyDw_YI.js';
14
+ import { u as useIsomorphicLayoutEffect } from '../_chunks/dep-0QH2Ee4R.js';
15
+ import 'react-dom';
16
+ import '../config-provider/ConfigContext.js';
17
+ import '@tendaui/icons';
18
+ import '../button/index.js';
19
+ import '../button/Button.js';
20
+ import '../loading/index.js';
21
+ import '../loading/Loading.js';
22
+ import '../loading/Gradient.js';
23
+ import '../_chunks/dep-DHWwZ2Nj.js';
24
+ import '../_chunks/dep-PPA-yoAy.js';
25
+ import '../_chunks/dep-BH5n5r1M.js';
26
+ import '../loading/style/css.js';
27
+ import '../_chunks/dep-D6YxJv-F.js';
28
+ import '../button/style/css.js';
29
+ import '../_chunks/dep-bWaVq_y3.js';
30
+
31
+ var defaultAttach = "body";
32
+ var useAttach = function useAttach(name, attach) {
33
+ var globalConfig = useConfig();
34
+ var attachVal = useMemo(function () {
35
+ var _globalConfig$attach;
36
+ return attach || (globalConfig === null || globalConfig === void 0 || (_globalConfig$attach = globalConfig.attach) === null || _globalConfig$attach === void 0 ? void 0 : _globalConfig$attach[name]) || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.attach) || defaultAttach;
37
+ }, [name, attach, globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.attach]);
38
+ return attachVal;
39
+ };
40
+
41
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
42
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
43
+ var isFunction = function isFunction(arg) {
44
+ return typeof arg === "function";
45
+ };
46
+ var useSetState = function useSetState() {
47
+ var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
+ var _useState = useState(initialState),
49
+ _useState2 = _slicedToArray(_useState, 2),
50
+ state = _useState2[0],
51
+ setState = _useState2[1];
52
+ var setMergeState = useCallback(function (patch) {
53
+ setState(function (prevState) {
54
+ return _objectSpread$1(_objectSpread$1({}, prevState), isFunction(patch) ? patch(prevState) : patch);
55
+ });
56
+ }, []);
57
+ return [state, setMergeState];
58
+ };
59
+
60
+ var useMouseEvent = function useMouseEvent(elementRef, options) {
61
+ var _options$enabled = options.enabled,
62
+ enabled = _options$enabled === void 0 ? true : _options$enabled,
63
+ _options$enableTouch = options.enableTouch,
64
+ enableTouch = _options$enableTouch === void 0 ? true : _options$enableTouch;
65
+ var isMovingRef = useRef(false);
66
+ var normalizeEvent = function normalizeEvent(e) {
67
+ if (!enableTouch) {
68
+ return e;
69
+ }
70
+ if ("touches" in e && e.touches.length > 0) {
71
+ return e.touches[0];
72
+ }
73
+ if ("changedTouches" in e && e.changedTouches.length > 0) {
74
+ return e.changedTouches[0];
75
+ }
76
+ if ("clientX" in e && "clientY" in e) {
77
+ return e;
78
+ }
79
+ return void 0;
80
+ };
81
+ var getCoordinate = function getCoordinate(event) {
82
+ var _elementRef$current;
83
+ var rect = elementRef === null || elementRef === void 0 || (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.getBoundingClientRect();
84
+ if (!rect) {
85
+ return {
86
+ x: 0,
87
+ y: 0
88
+ };
89
+ }
90
+ var clientX = event.clientX,
91
+ clientY = event.clientY;
92
+ var left = clientX - rect.left;
93
+ var top = clientY - rect.top;
94
+ return {
95
+ x: Math.min(Math.max(0, left), rect.width),
96
+ y: Math.min(Math.max(0, top), rect.height)
97
+ };
98
+ };
99
+ var emitMouseChange = function emitMouseChange(e, handler) {
100
+ if (!handler) return;
101
+ var event = normalizeEvent(e);
102
+ if (event !== void 0) {
103
+ var coordinate = getCoordinate(event);
104
+ handler(event, {
105
+ coordinate: coordinate
106
+ });
107
+ }
108
+ };
109
+ var handleMouseMove = function handleMouseMove(e) {
110
+ if (!isMovingRef.current) return;
111
+ e.preventDefault();
112
+ emitMouseChange(e, options.onMove);
113
+ };
114
+ var _handleMouseUp = function handleMouseUp(e) {
115
+ if (!isMovingRef.current) return;
116
+ isMovingRef.current = false;
117
+ emitMouseChange(e, options.onUp);
118
+ document.removeEventListener("mouseup", _handleMouseUp);
119
+ document.removeEventListener("mousemove", handleMouseMove);
120
+ document.removeEventListener("touchend", _handleMouseUp);
121
+ document.removeEventListener("touchmove", handleMouseMove);
122
+ };
123
+ var handleMouseDown = function handleMouseDown(e) {
124
+ isMovingRef.current = true;
125
+ emitMouseChange(e, options.onDown);
126
+ document.addEventListener("mouseup", _handleMouseUp);
127
+ document.addEventListener("mousemove", handleMouseMove);
128
+ if (!enableTouch) return;
129
+ document.addEventListener("touchend", _handleMouseUp);
130
+ document.addEventListener("touchmove", handleMouseMove, {
131
+ passive: false
132
+ });
133
+ };
134
+ var handleMouseEnter = function handleMouseEnter(e) {
135
+ emitMouseChange(e, options.onEnter);
136
+ };
137
+ var handleMouseLeave = function handleMouseLeave(e) {
138
+ emitMouseChange(e, options.onLeave);
139
+ };
140
+ useEffect(function () {
141
+ var el = elementRef.current;
142
+ if (!el || !enabled) return;
143
+ el.addEventListener("mousedown", handleMouseDown);
144
+ el.addEventListener("mousemove", handleMouseMove);
145
+ el.addEventListener("mouseup", _handleMouseUp);
146
+ if (options.onEnter) {
147
+ el.addEventListener("mouseenter", handleMouseEnter);
148
+ }
149
+ if (options.onLeave) {
150
+ el.addEventListener("mouseleave", handleMouseLeave);
151
+ }
152
+ if (!enableTouch) return;
153
+ el.addEventListener("touchstart", handleMouseDown, {
154
+ passive: false
155
+ });
156
+ el.addEventListener("touchend", _handleMouseUp);
157
+ return function () {
158
+ el.removeEventListener("mousedown", handleMouseDown);
159
+ el.removeEventListener("mouseenter", handleMouseDown);
160
+ el.removeEventListener("mouseleave", handleMouseLeave);
161
+ el.removeEventListener("mousemove", handleMouseMove);
162
+ el.removeEventListener("mouseup", _handleMouseUp);
163
+ el.removeEventListener("touchstart", handleMouseDown);
164
+ el.removeEventListener("touchend", _handleMouseUp);
165
+ };
166
+ }, [elementRef.current, options, enabled]);
167
+ return {
168
+ isMoving: isMovingRef.current
169
+ };
170
+ };
171
+
172
+ var useDialogDrag = function useDialogDrag(props) {
173
+ var dialogCardRef = props.dialogCardRef,
174
+ canDraggable = props.canDraggable;
175
+ var validWindow = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object";
176
+ var screenHeight = validWindow ? window.innerHeight || document.documentElement.clientHeight : void 0;
177
+ var screenWidth = validWindow ? window.innerWidth || document.documentElement.clientWidth : void 0;
178
+ var dragOffset = useRef({
179
+ x: 0,
180
+ y: 0
181
+ });
182
+ useMouseEvent(dialogCardRef, {
183
+ enabled: canDraggable,
184
+ onDown: function onDown(e) {
185
+ if (!validWindow || screenWidth === void 0 || screenHeight === void 0 || !dialogCardRef.current) return;
186
+ var _dialogCardRef$curren = dialogCardRef.current,
187
+ offsetLeft = _dialogCardRef$curren.offsetLeft,
188
+ offsetTop = _dialogCardRef$curren.offsetTop,
189
+ offsetWidth = _dialogCardRef$curren.offsetWidth,
190
+ offsetHeight = _dialogCardRef$curren.offsetHeight,
191
+ style = _dialogCardRef$curren.style;
192
+ if (offsetWidth > screenWidth || offsetHeight > screenHeight) return;
193
+ style.cursor = "move";
194
+ dragOffset.current = {
195
+ x: e.clientX - offsetLeft,
196
+ y: e.clientY - offsetTop
197
+ };
198
+ },
199
+ onMove: function onMove(e) {
200
+ if (!validWindow || screenWidth === void 0 || screenHeight === void 0 || !dialogCardRef.current) return;
201
+ var _dialogCardRef$curren2 = dialogCardRef.current,
202
+ offsetWidth = _dialogCardRef$curren2.offsetWidth,
203
+ offsetHeight = _dialogCardRef$curren2.offsetHeight,
204
+ style = _dialogCardRef$curren2.style;
205
+ var diffX = e.clientX - dragOffset.current.x;
206
+ var diffY = e.clientY - dragOffset.current.y;
207
+ if (diffX < 0) diffX = 0;
208
+ if (diffY < 0) diffY = 0;
209
+ if (screenWidth - offsetWidth - diffX < 0) diffX = screenWidth - offsetWidth;
210
+ if (screenHeight - offsetHeight - diffY < 0) diffY = screenHeight - offsetHeight;
211
+ style.position = "absolute";
212
+ style.left = "".concat(diffX, "px");
213
+ style.top = "".concat(diffY, "px");
214
+ },
215
+ onUp: function onUp() {
216
+ if (dialogCardRef.current) dialogCardRef.current.style.cursor = "default";
217
+ }
218
+ });
219
+ };
220
+
221
+ var dialogSet = /* @__PURE__ */new Set();
222
+ var useDialogEsc = function useDialogEsc(visible, dialog) {
223
+ useEffect(function () {
224
+ if (visible) {
225
+ if (dialog !== null && dialog !== void 0 && dialog.current) {
226
+ var _dialog$current;
227
+ dialogSet.add(dialog);
228
+ dialog === null || dialog === void 0 || (_dialog$current = dialog.current) === null || _dialog$current === void 0 || _dialog$current.focus();
229
+ }
230
+ } else if (dialogSet.has(dialog)) {
231
+ var _dialogList;
232
+ dialogSet["delete"](dialog);
233
+ var dialogList = _toConsumableArray(dialogSet);
234
+ (_dialogList = dialogList[dialogList.length - 1]) === null || _dialogList === void 0 || (_dialogList = _dialogList.current) === null || _dialogList === void 0 || _dialogList.focus();
235
+ }
236
+ return function () {
237
+ dialogSet.forEach(function (item) {
238
+ if ((item === null || item === void 0 ? void 0 : item.current) === null) {
239
+ dialogSet["delete"](item);
240
+ }
241
+ });
242
+ };
243
+ }, [visible, dialog]);
244
+ };
245
+
246
+ function useDialogPosition(visible, dialogCardRef) {
247
+ var mousePosRef = useRef(null);
248
+ var getClickPosition = function getClickPosition(e) {
249
+ if (mousePosRef) {
250
+ mousePosRef.current = {
251
+ x: e.clientX,
252
+ y: e.clientY
253
+ };
254
+ setTimeout(function () {
255
+ mousePosRef.current = null;
256
+ }, 100);
257
+ }
258
+ };
259
+ useIsomorphicLayoutEffect(function () {
260
+ document.addEventListener("click", getClickPosition, true);
261
+ return function () {
262
+ document.removeEventListener("click", getClickPosition, true);
263
+ };
264
+ }, []);
265
+ useEffect(function () {
266
+ if (!visible) return;
267
+ if (mousePosRef.current && dialogCardRef.current) {
268
+ dialogCardRef.current.style.transformOrigin = "".concat(mousePosRef.current.x - dialogCardRef.current.offsetLeft, "px ").concat(mousePosRef.current.y - dialogCardRef.current.offsetTop, "px");
269
+ }
270
+ }, [visible, dialogCardRef]);
271
+ }
272
+
273
+ function getScrollbarWidth() {
274
+ var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.body;
275
+ if (container === document.body) {
276
+ return window.innerWidth - document.documentElement.clientWidth;
277
+ }
278
+ return container.offsetWidth - container.clientWidth;
279
+ }
280
+
281
+ var key = 1;
282
+ function useDialogLockStyle(_ref) {
283
+ var preventScrollThrough = _ref.preventScrollThrough,
284
+ visible = _ref.visible,
285
+ mode = _ref.mode,
286
+ showInAttachedElement = _ref.showInAttachedElement;
287
+ var lockStyleRef = useRef(null);
288
+ var timerRef = useRef(null);
289
+ var clearStyleFunc = useCallback(function () {
290
+ if (timerRef.current) {
291
+ clearTimeout(timerRef.current);
292
+ }
293
+ timerRef.current = setTimeout(function () {
294
+ var _lockStyleRef$current, _lockStyleRef$current2;
295
+ (_lockStyleRef$current = lockStyleRef.current) === null || _lockStyleRef$current === void 0 || (_lockStyleRef$current = _lockStyleRef$current.parentNode) === null || _lockStyleRef$current === void 0 || (_lockStyleRef$current2 = _lockStyleRef$current.removeChild) === null || _lockStyleRef$current2 === void 0 || _lockStyleRef$current2.call(_lockStyleRef$current, lockStyleRef.current);
296
+ }, 150);
297
+ }, []);
298
+ useIsomorphicLayoutEffect(function () {
299
+ if (typeof document === "undefined" || !visible) return;
300
+ if (!lockStyleRef.current) {
301
+ lockStyleRef.current = document.createElement("style");
302
+ }
303
+ var hasScrollBar = document.documentElement.scrollHeight > document.documentElement.clientHeight;
304
+ var scrollbarWidth = hasScrollBar ? getScrollbarWidth() : 0;
305
+ lockStyleRef.current.dataset.id = "td_dialog_".concat(+ /* @__PURE__ */new Date(), "_").concat(key += 1);
306
+ lockStyleRef.current.innerHTML = "\n html body {\n overflow-y: hidden;\n width: calc(100% - ".concat(scrollbarWidth, "px);\n }\n ");
307
+ return clearStyleFunc;
308
+ }, [visible, clearStyleFunc]);
309
+ useIsomorphicLayoutEffect(function () {
310
+ if (typeof document === "undefined") return;
311
+ if (mode !== "modal" || !preventScrollThrough || showInAttachedElement) return;
312
+ if (visible) {
313
+ if (lockStyleRef.current) document.head.appendChild(lockStyleRef.current);
314
+ } else {
315
+ clearStyleFunc();
316
+ }
317
+ }, [preventScrollThrough, visible, mode, showInAttachedElement, clearStyleFunc]);
318
+ }
319
+
320
+ function parseValueToPx(value) {
321
+ if (typeof value === "number") return "".concat(value, "px");
322
+ return value;
323
+ }
324
+
325
+ var _excluded = ["children"],
326
+ _excluded2 = ["className", "dialogClassName", "style", "width", "mode", "zIndex", "visible", "attach", "onBeforeOpen", "onBeforeClose", "onOpened", "onCancel", "onConfirm", "onClose", "onClosed", "isPlugin", "draggable", "onOverlayClick", "onEscKeydown", "closeOnEscKeydown", "confirmOnEnter", "showOverlay", "showInAttachedElement", "closeOnOverlayClick", "destroyOnClose", "preventScrollThrough", "onCloseBtnClick", "forceRender", "lazy"];
327
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
328
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
329
+ var Dialog = /*#__PURE__*/forwardRef(function (originalProps, ref) {
330
+ var props = useDefaultProps(originalProps, dialogDefaultProps);
331
+ var children = props.children,
332
+ restProps = _objectWithoutProperties(props, _excluded);
333
+ var _useConfig = useConfig(),
334
+ classPrefix = _useConfig.classPrefix;
335
+ var componentCls = "".concat(classPrefix, "-dialog");
336
+ var wrapRef = useRef(null);
337
+ var contentClickRef = useRef(false);
338
+ var dialogCardRef = useRef(null);
339
+ var dialogPosition = useRef(null);
340
+ var portalRef = useRef(null);
341
+ var maskRef = useRef(null);
342
+ var _useSetState = useSetState(_objectSpread({
343
+ isPlugin: false
344
+ }, restProps)),
345
+ _useSetState2 = _slicedToArray(_useSetState, 2),
346
+ state = _useSetState2[0],
347
+ setState = _useSetState2[1];
348
+ var className = state.className,
349
+ dialogClassName = state.dialogClassName,
350
+ style = state.style,
351
+ width = state.width,
352
+ mode = state.mode,
353
+ zIndex = state.zIndex,
354
+ visible = state.visible,
355
+ attach = state.attach,
356
+ onBeforeOpen = state.onBeforeOpen,
357
+ onBeforeClose = state.onBeforeClose,
358
+ onOpened = state.onOpened,
359
+ onCancel = state.onCancel,
360
+ onConfirm = state.onConfirm,
361
+ onClose = state.onClose,
362
+ onClosed = state.onClosed,
363
+ isPlugin = state.isPlugin,
364
+ draggable = state.draggable,
365
+ onOverlayClick = state.onOverlayClick,
366
+ onEscKeydown = state.onEscKeydown,
367
+ closeOnEscKeydown = state.closeOnEscKeydown,
368
+ confirmOnEnter = state.confirmOnEnter,
369
+ showOverlay = state.showOverlay,
370
+ showInAttachedElement = state.showInAttachedElement,
371
+ closeOnOverlayClick = state.closeOnOverlayClick,
372
+ destroyOnClose = state.destroyOnClose,
373
+ preventScrollThrough = state.preventScrollThrough,
374
+ onCloseBtnClick = state.onCloseBtnClick,
375
+ forceRender = state.forceRender,
376
+ lazy = state.lazy,
377
+ restState = _objectWithoutProperties(state, _excluded2);
378
+ var dialogAttach = useAttach("dialog", attach);
379
+ useDialogLockStyle({
380
+ preventScrollThrough: preventScrollThrough,
381
+ visible: visible,
382
+ mode: mode,
383
+ showInAttachedElement: showInAttachedElement
384
+ });
385
+ useDialogEsc(visible, wrapRef);
386
+ useDialogPosition(visible, dialogCardRef);
387
+ useDialogDrag({
388
+ dialogCardRef: dialogCardRef,
389
+ canDraggable: draggable && mode === "modeless"
390
+ });
391
+ useEffect(function () {
392
+ if (isPlugin) {
393
+ return;
394
+ }
395
+ setState(function (prevState) {
396
+ return _objectSpread(_objectSpread({}, prevState), props);
397
+ });
398
+ }, [props, setState, isPlugin]);
399
+ useImperativeHandle(ref, function () {
400
+ return {
401
+ show: function show() {
402
+ setState({
403
+ visible: true
404
+ });
405
+ },
406
+ hide: function hide() {
407
+ setState({
408
+ visible: false
409
+ });
410
+ },
411
+ setConfirmLoading: function setConfirmLoading(loading) {
412
+ setState({
413
+ confirmLoading: loading
414
+ });
415
+ },
416
+ destroy: function destroy() {
417
+ setState({
418
+ visible: false,
419
+ destroyOnClose: true
420
+ });
421
+ },
422
+ update: function update(newOptions) {
423
+ setState(function (prevState) {
424
+ return _objectSpread(_objectSpread({}, prevState), newOptions);
425
+ });
426
+ }
427
+ };
428
+ });
429
+ var onMaskClick = function onMaskClick(e) {
430
+ if (showOverlay && closeOnOverlayClick) {
431
+ if (contentClickRef.current) {
432
+ contentClickRef.current = false;
433
+ } else if (e.target === dialogPosition.current) {
434
+ onOverlayClick === null || onOverlayClick === void 0 || onOverlayClick({
435
+ e: e
436
+ });
437
+ onClose === null || onClose === void 0 || onClose({
438
+ e: e,
439
+ trigger: "overlay"
440
+ });
441
+ }
442
+ }
443
+ };
444
+ var handleCancel = function handleCancel(_ref) {
445
+ var e = _ref.e;
446
+ onCancel === null || onCancel === void 0 || onCancel({
447
+ e: e
448
+ });
449
+ onClose === null || onClose === void 0 || onClose({
450
+ e: e,
451
+ trigger: "cancel"
452
+ });
453
+ };
454
+ var handleClose = function handleClose(_ref2) {
455
+ var e = _ref2.e;
456
+ onCloseBtnClick === null || onCloseBtnClick === void 0 || onCloseBtnClick({
457
+ e: e
458
+ });
459
+ onClose === null || onClose === void 0 || onClose({
460
+ e: e,
461
+ trigger: "close-btn"
462
+ });
463
+ };
464
+ var handleKeyDown = function handleKeyDown(e) {
465
+ if (e.key === "Escape") {
466
+ e.stopPropagation();
467
+ onEscKeydown === null || onEscKeydown === void 0 || onEscKeydown({
468
+ e: e
469
+ });
470
+ if (closeOnEscKeydown) {
471
+ onClose === null || onClose === void 0 || onClose({
472
+ e: e,
473
+ trigger: "esc"
474
+ });
475
+ }
476
+ } else if (e.key === "Enter" || e.key === "NumpadEnter") {
477
+ e.stopPropagation();
478
+ if (confirmOnEnter) {
479
+ onConfirm === null || onConfirm === void 0 || onConfirm({
480
+ e: e
481
+ });
482
+ }
483
+ }
484
+ };
485
+ var onAnimateLeave = function onAnimateLeave() {
486
+ onClosed === null || onClosed === void 0 || onClosed();
487
+ if (!wrapRef.current) return;
488
+ wrapRef.current.style.display = "none";
489
+ };
490
+ var onAnimateStart = function onAnimateStart() {
491
+ if (!wrapRef.current) return;
492
+ onBeforeOpen === null || onBeforeOpen === void 0 || onBeforeOpen();
493
+ wrapRef.current.style.display = "block";
494
+ };
495
+ var onInnerAnimateStart = function onInnerAnimateStart() {
496
+ if (!dialogCardRef.current) return;
497
+ dialogCardRef.current.style.display = "block";
498
+ };
499
+ var onInnerAnimateLeave = function onInnerAnimateLeave() {
500
+ if (!dialogCardRef.current) return;
501
+ dialogCardRef.current.style.display = "none";
502
+ };
503
+ var renderMask = function renderMask() {
504
+ if (mode !== "modal") return null;
505
+ return showOverlay ? /* @__PURE__ */React.createElement(CSSTransition, {
506
+ "in": visible,
507
+ appear: true,
508
+ timeout: 300,
509
+ classNames: "".concat(componentCls, "-fade"),
510
+ mountOnEnter: true,
511
+ unmountOnExit: true,
512
+ nodeRef: maskRef
513
+ }, /* @__PURE__ */React.createElement("div", {
514
+ ref: maskRef,
515
+ className: "".concat(componentCls, "__mask")
516
+ })) : null;
517
+ };
518
+ return /* @__PURE__ */React.createElement(CSSTransition, {
519
+ "in": visible,
520
+ appear: true,
521
+ timeout: 300,
522
+ mountOnEnter: isUndefined(forceRender) ? lazy : !forceRender,
523
+ unmountOnExit: destroyOnClose,
524
+ nodeRef: portalRef,
525
+ onEnter: onAnimateStart,
526
+ onEntered: onOpened,
527
+ onExit: function onExit() {
528
+ return onBeforeClose === null || onBeforeClose === void 0 ? void 0 : onBeforeClose();
529
+ },
530
+ onExited: onAnimateLeave
531
+ }, /* @__PURE__ */React.createElement(Portal, {
532
+ attach: dialogAttach,
533
+ ref: portalRef
534
+ }, /* @__PURE__ */React.createElement("div", {
535
+ ref: wrapRef,
536
+ className: classNames(className, "".concat(componentCls, "__ctx"), "".concat(componentCls, "__").concat(mode), _defineProperty(_defineProperty({}, "".concat(componentCls, "__ctx--fixed"), !showInAttachedElement), "".concat(componentCls, "__ctx--absolute"), showInAttachedElement)),
537
+ style: {
538
+ zIndex: zIndex,
539
+ display: "none"
540
+ },
541
+ onKeyDown: handleKeyDown,
542
+ tabIndex: 0
543
+ }, renderMask(), /* @__PURE__ */React.createElement("div", {
544
+ className: "".concat(componentCls, "__wrap")
545
+ }, /* @__PURE__ */React.createElement("div", {
546
+ ref: dialogPosition,
547
+ className: classNames("".concat(componentCls, "__position"), _defineProperty(_defineProperty({}, "".concat(componentCls, "--top"), !!props.top || props.placement === "top"), "".concat(componentCls, "--center"), props.placement === "center" && !props.top)),
548
+ style: {
549
+ paddingTop: parseValueToPx(props.top)
550
+ },
551
+ onClick: onMaskClick
552
+ }, /* @__PURE__ */React.createElement(CSSTransition, {
553
+ "in": visible,
554
+ appear: true,
555
+ timeout: 300,
556
+ classNames: "".concat(componentCls, "-zoom"),
557
+ nodeRef: dialogCardRef,
558
+ onEnter: onInnerAnimateStart,
559
+ onExited: onInnerAnimateLeave
560
+ }, /* @__PURE__ */React.createElement(DialogCard, _objectSpread(_objectSpread({
561
+ ref: dialogCardRef
562
+ }, restState), {}, {
563
+ className: dialogClassName,
564
+ style: _objectSpread(_objectSpread({}, style), {}, {
565
+ width: parseValueToPx(width || (style === null || style === void 0 ? void 0 : style.width))
566
+ }),
567
+ onConfirm: onConfirm,
568
+ onCancel: handleCancel,
569
+ onCloseBtnClick: handleClose
570
+ }), children)))))));
571
+ });
572
+ Dialog.displayName = "Dialog";
573
+
574
+ export { Dialog as default };
575
+ //# sourceMappingURL=Dialog.js.map