@qsxy/element-plus-react 1.0.1 → 1.0.3

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 (256) hide show
  1. package/dist/Alert/Alert.d.ts +7 -0
  2. package/dist/Alert/Alert.js +98 -0
  3. package/dist/Alert/index.d.ts +2 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Alert/typings.d.ts +45 -0
  6. package/dist/Alert/typings.js +1 -0
  7. package/dist/Calendar/Calendar.js +12 -3
  8. package/dist/Calendar/Footer.js +4 -2
  9. package/dist/Calendar/QuarterPanel.d.ts +4 -0
  10. package/dist/Calendar/QuarterPanel.js +109 -0
  11. package/dist/Calendar/WeekPanel.js +1 -1
  12. package/dist/Calendar/typings.d.ts +1 -1
  13. package/dist/Card/Card.js +13 -6
  14. package/dist/Card/typings.d.ts +1 -1
  15. package/dist/Cascader/Cascader.js +1 -1
  16. package/dist/Cascader/useCascader.d.ts +0 -14
  17. package/dist/Cascader/useCascader.js +33 -32
  18. package/dist/Checkbox/Checkbox.js +3 -2
  19. package/dist/ConfigProvider/ConfigProvider.js +2 -24
  20. package/dist/ConfigProvider/ConfigProviderContext.js +1 -1
  21. package/dist/ConfigProvider/typings.d.ts +1 -1
  22. package/dist/Container/Main.d.ts +1 -1
  23. package/dist/Container/typings.d.ts +1 -1
  24. package/dist/DatePicker/DatePicker.js +38 -12
  25. package/dist/DatePicker/DateRangePicker.js +27 -9
  26. package/dist/DatePicker/main.js +1 -1
  27. package/dist/DatePicker/typings.d.ts +1 -1
  28. package/dist/DateTimePicker/DateTimePicker.js +2 -2
  29. package/dist/Dialog/Dialog.js +5 -12
  30. package/dist/Input/Input.js +190 -149
  31. package/dist/Input/InputRange.js +1 -1
  32. package/dist/Input/TextArea.js +87 -12
  33. package/dist/Input/typings.d.ts +56 -5
  34. package/dist/Input/useComposition.d.ts +23 -0
  35. package/dist/Input/useComposition.js +63 -0
  36. package/dist/Input/utils.d.ts +7 -0
  37. package/dist/Input/utils.js +95 -0
  38. package/dist/InputNumber/InputNumber.js +351 -141
  39. package/dist/InputNumber/typings.d.ts +16 -2
  40. package/dist/Loading/Loading.js +5 -2
  41. package/dist/Menu/Menu.js +25 -1
  42. package/dist/Menu/MenuItem.js +4 -2
  43. package/dist/Menu/SubMenu.js +2 -2
  44. package/dist/Menu/SubMenuCollapseTransition.js +14 -9
  45. package/dist/Menu/typings.d.ts +2 -1
  46. package/dist/Message/Message.js +51 -23
  47. package/dist/Message/index.js +8 -10
  48. package/dist/Message/typings.d.ts +8 -5
  49. package/dist/MessageBox/MessageBox.js +52 -30
  50. package/dist/MessageBox/index.d.ts +2 -1
  51. package/dist/MessageBox/index.js +4 -2
  52. package/dist/MessageBox/typings.d.ts +3 -0
  53. package/dist/Notification/Notification.js +26 -19
  54. package/dist/Select/Option.js +30 -14
  55. package/dist/Select/SelectContext.d.ts +5 -5
  56. package/dist/Select/SelectContext.js +2 -1
  57. package/dist/Select/SelectCore.d.ts +2 -2
  58. package/dist/Select/SelectCore.js +172 -449
  59. package/dist/Select/SelectDropdown.js +85 -155
  60. package/dist/Select/index.d.ts +1 -1
  61. package/dist/Select/typings.d.ts +52 -22
  62. package/dist/Select/useSelect.d.ts +128 -0
  63. package/dist/Select/useSelect.js +524 -0
  64. package/dist/Space/Space.d.ts +4 -0
  65. package/dist/Space/Space.js +128 -0
  66. package/dist/Space/SpaceItem.d.ts +7 -0
  67. package/dist/Space/SpaceItem.js +14 -0
  68. package/dist/Space/index.d.ts +3 -0
  69. package/dist/Space/index.js +2 -0
  70. package/dist/Space/typings.d.ts +26 -0
  71. package/dist/Space/typings.js +1 -0
  72. package/dist/Space/useSpace.d.ts +7 -0
  73. package/dist/Space/useSpace.js +104 -0
  74. package/dist/Statistic/Statistic.d.ts +4 -0
  75. package/dist/Statistic/Statistic.js +92 -0
  76. package/dist/Statistic/index.d.ts +2 -0
  77. package/dist/Statistic/index.js +1 -0
  78. package/dist/Statistic/typings.d.ts +28 -0
  79. package/dist/Statistic/typings.js +1 -0
  80. package/dist/Switch/Switch.js +2 -2
  81. package/dist/Table/Table.js +3 -0
  82. package/dist/Table/typings.d.ts +2 -0
  83. package/dist/Table/util.js +6 -5
  84. package/dist/Tag/Tag.js +22 -17
  85. package/dist/Tag/typings.d.ts +1 -1
  86. package/dist/Text/Text.d.ts +4 -0
  87. package/dist/Text/Text.js +84 -0
  88. package/dist/Text/index.d.ts +2 -0
  89. package/dist/Text/index.js +1 -0
  90. package/dist/Text/typings.d.ts +15 -0
  91. package/dist/Text/typings.js +1 -0
  92. package/dist/TimePicker/TimePicker.js +2 -2
  93. package/dist/Tree/CollapseTransition.d.ts +7 -0
  94. package/dist/Tree/CollapseTransition.js +60 -0
  95. package/dist/Tree/Tree.d.ts +3 -140
  96. package/dist/Tree/Tree.js +350 -77
  97. package/dist/Tree/TreeContext.d.ts +9 -0
  98. package/dist/Tree/TreeContext.js +14 -0
  99. package/dist/Tree/TreeNode.d.ts +5 -3
  100. package/dist/Tree/TreeNode.js +321 -331
  101. package/dist/Tree/TreeNodeContent.d.ts +9 -0
  102. package/dist/Tree/TreeNodeContent.js +22 -0
  103. package/dist/Tree/index.d.ts +3 -8
  104. package/dist/Tree/index.js +1 -4
  105. package/dist/Tree/model/node.d.ts +62 -0
  106. package/dist/Tree/model/node.js +601 -0
  107. package/dist/Tree/model/tree-store.d.ts +52 -0
  108. package/dist/Tree/model/tree-store.js +510 -0
  109. package/dist/Tree/model/useDragNode.d.ts +30 -0
  110. package/dist/Tree/model/useDragNode.js +293 -0
  111. package/dist/Tree/model/useKeydown.d.ts +0 -0
  112. package/dist/Tree/model/useKeydown.js +104 -0
  113. package/dist/Tree/model/useNodeExpandEventBroadcast.d.ts +15 -0
  114. package/dist/Tree/model/useNodeExpandEventBroadcast.js +54 -0
  115. package/dist/Tree/model/util.d.ts +7 -0
  116. package/dist/Tree/model/util.js +24 -0
  117. package/dist/Tree/typings.d.ts +225 -114
  118. package/dist/TreeSelect/TreeSelect.d.ts +2 -10
  119. package/dist/TreeSelect/TreeSelect.js +90 -566
  120. package/dist/TreeSelect/TreeSelectOption.d.ts +6 -0
  121. package/dist/TreeSelect/TreeSelectOption.js +62 -0
  122. package/dist/TreeSelect/cacheOptions.d.ts +9 -0
  123. package/dist/TreeSelect/cacheOptions.js +22 -0
  124. package/dist/TreeSelect/index.d.ts +0 -1
  125. package/dist/TreeSelect/typings.d.ts +11 -63
  126. package/dist/TreeSelect/useSelect.d.ts +125 -0
  127. package/dist/TreeSelect/useSelect.js +104 -0
  128. package/dist/TreeSelect/useTree.d.ts +130 -0
  129. package/dist/TreeSelect/useTree.js +285 -0
  130. package/dist/TreeSelect/utils.d.ts +10 -0
  131. package/dist/TreeSelect/utils.js +38 -0
  132. package/dist/Upload/UploadContent.js +2 -0
  133. package/dist/Upload/ajax.js +3 -0
  134. package/dist/Upload/typings.d.ts +4 -0
  135. package/dist/Util/aria.d.ts +25 -0
  136. package/dist/Util/aria.js +118 -0
  137. package/dist/Util/base.d.ts +5 -0
  138. package/dist/Util/base.js +140 -1
  139. package/dist/config/Constants.d.ts +3 -0
  140. package/dist/config/Constants.js +8 -0
  141. package/dist/hooks/index.d.ts +1 -0
  142. package/dist/hooks/index.js +1 -0
  143. package/dist/hooks/popperPropsUtils.js +1 -1
  144. package/dist/hooks/treePropsUtils.d.ts +3 -3
  145. package/dist/hooks/treePropsUtils.js +2 -2
  146. package/dist/hooks/useCalcInputWidth.d.ts +8 -0
  147. package/dist/{Tree/useUnmount.js → hooks/useCalcInputWidth.js} +23 -27
  148. package/dist/hooks/useComposition.d.ts +16 -0
  149. package/dist/hooks/useComposition.js +39 -0
  150. package/dist/hooks/useConfigProvider.d.ts +27 -0
  151. package/dist/hooks/useConfigProvider.js +78 -0
  152. package/dist/hooks/useCursor.d.ts +2 -0
  153. package/dist/hooks/useCursor.js +52 -0
  154. package/dist/hooks/useFocusController.d.ts +27 -0
  155. package/dist/hooks/useFocusController.js +72 -0
  156. package/dist/hooks/useResizeObserver.js +6 -6
  157. package/dist/index.css +1 -1
  158. package/dist/index.d.ts +18 -11
  159. package/dist/index.js +11 -5
  160. package/dist/locale/en.d.ts +15 -0
  161. package/dist/locale/en.js +15 -0
  162. package/dist/locale/zhCn.d.ts +15 -0
  163. package/dist/locale/zhCn.js +15 -0
  164. package/package.json +1 -1
  165. package/theme-chalk/alert.scss +115 -0
  166. package/theme-chalk/aside.scss +8 -8
  167. package/theme-chalk/button-group.scss +80 -80
  168. package/theme-chalk/button.scss +304 -304
  169. package/theme-chalk/calendar/date-table.scss +164 -164
  170. package/theme-chalk/calendar/index.scss +1 -0
  171. package/theme-chalk/calendar/quarter-table.scss +78 -0
  172. package/theme-chalk/checkbox.scss +34 -0
  173. package/theme-chalk/color/index.scss +20 -20
  174. package/theme-chalk/common/transition.scss +142 -142
  175. package/theme-chalk/common/var.scss +1 -1
  176. package/theme-chalk/container.scss +14 -14
  177. package/theme-chalk/dark/css-vars.scss +39 -39
  178. package/theme-chalk/dark/var.scss +225 -225
  179. package/theme-chalk/date-picker.scss +12 -12
  180. package/theme-chalk/drawer.scss +1 -0
  181. package/theme-chalk/footer.scss +12 -12
  182. package/theme-chalk/header.scss +12 -12
  183. package/theme-chalk/index.scss +4 -0
  184. package/theme-chalk/input/input-range.scss +2 -1
  185. package/theme-chalk/input/input.scss +298 -437
  186. package/theme-chalk/input/input.scss--bak +578 -0
  187. package/theme-chalk/input-number.bak +172 -0
  188. package/theme-chalk/input-number.scss +192 -172
  189. package/theme-chalk/link.scss +87 -87
  190. package/theme-chalk/main.scss +14 -14
  191. package/theme-chalk/menu.scss +353 -353
  192. package/theme-chalk/message.scss +104 -178
  193. package/theme-chalk/mixins/_button.scss +224 -224
  194. package/theme-chalk/mixins/_col.scss +33 -33
  195. package/theme-chalk/mixins/_var.scss +67 -67
  196. package/theme-chalk/mixins/config.scss +5 -5
  197. package/theme-chalk/mixins/function.scss +99 -99
  198. package/theme-chalk/mixins/mixins.scss +240 -240
  199. package/theme-chalk/mixins/utils.scss +39 -39
  200. package/theme-chalk/notification.bak +156 -0
  201. package/theme-chalk/notification.scss +109 -156
  202. package/theme-chalk/popper.scss +104 -104
  203. package/theme-chalk/radio-button.scss +169 -169
  204. package/theme-chalk/select/index.scss +222 -191
  205. package/theme-chalk/select/index.scss--bak +247 -0
  206. package/theme-chalk/select/option-group.scss +2 -2
  207. package/theme-chalk/select/option.scss +2 -2
  208. package/theme-chalk/select/select-dropdown.scss +2 -2
  209. package/theme-chalk/space.scss +20 -0
  210. package/theme-chalk/statistic.scss +35 -0
  211. package/theme-chalk/switch.scss +300 -300
  212. package/theme-chalk/tag.scss +150 -172
  213. package/theme-chalk/tag.scss--bak +203 -0
  214. package/theme-chalk/text.scss +48 -0
  215. package/theme-chalk/transition.scss +34 -4
  216. package/theme-chalk/tree-select.scss +41 -25
  217. package/theme-chalk/tree.scss +136 -0
  218. package/theme-chalk/var.scss +83 -83
  219. package/dist/Tree/DirectoryTree.d.ts +0 -15
  220. package/dist/Tree/DirectoryTree.js +0 -183
  221. package/dist/Tree/DropIndicator.d.ts +0 -8
  222. package/dist/Tree/DropIndicator.js +0 -34
  223. package/dist/Tree/Indent.d.ts +0 -9
  224. package/dist/Tree/Indent.js +0 -25
  225. package/dist/Tree/MotionTreeNode.d.ts +0 -14
  226. package/dist/Tree/MotionTreeNode.js +0 -125
  227. package/dist/Tree/NodeList.d.ts +0 -50
  228. package/dist/Tree/NodeList.js +0 -301
  229. package/dist/Tree/RCTree.d.ts +0 -248
  230. package/dist/Tree/RCTree.js +0 -1216
  231. package/dist/Tree/contextTypes.d.ts +0 -69
  232. package/dist/Tree/contextTypes.js +0 -9
  233. package/dist/Tree/typings.tsx--bak +0 -245
  234. package/dist/Tree/useUnmount.d.ts +0 -5
  235. package/dist/Tree/util.d.ts +0 -51
  236. package/dist/Tree/util.js +0 -303
  237. package/dist/Tree/utils/conductUtil.d.ts +0 -17
  238. package/dist/Tree/utils/conductUtil.js +0 -209
  239. package/dist/Tree/utils/dictUtil.d.ts +0 -13
  240. package/dist/Tree/utils/dictUtil.js +0 -75
  241. package/dist/Tree/utils/diffUtil.d.ts +0 -7
  242. package/dist/Tree/utils/diffUtil.js +0 -48
  243. package/dist/Tree/utils/dropIndicator.d.ts +0 -11
  244. package/dist/Tree/utils/dropIndicator.js +0 -36
  245. package/dist/Tree/utils/iconUtil.d.ts +0 -5
  246. package/dist/Tree/utils/iconUtil.js +0 -62
  247. package/dist/Tree/utils/keyUtil.d.ts +0 -2
  248. package/dist/Tree/utils/keyUtil.js +0 -3
  249. package/dist/Tree/utils/motion.d.ts +0 -10
  250. package/dist/Tree/utils/motion.js +0 -54
  251. package/dist/Tree/utils/pickAttrs.d.ts +0 -11
  252. package/dist/Tree/utils/pickAttrs.js +0 -51
  253. package/dist/Tree/utils/treeUtil.d.ts +0 -86
  254. package/dist/Tree/utils/treeUtil.js +0 -364
  255. package/dist/TreeSelect/Utils.d.ts +0 -3
  256. package/dist/TreeSelect/Utils.js +0 -20
package/dist/Util/base.js CHANGED
@@ -5,6 +5,8 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
5
5
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
6
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
7
7
  import is_empty from 'lodash/isEmpty';
8
+ import isNil from 'lodash/isNil';
9
+ import noop from 'lodash/noop';
8
10
 
9
11
  /**
10
12
  * 判断对象是否为空
@@ -130,6 +132,12 @@ export var isNumber = function isNumber(val) {
130
132
  export var isString = function isString(val) {
131
133
  return typeof val === 'string';
132
134
  };
135
+ export var isFunction = function isFunction(val) {
136
+ return typeof val === 'function';
137
+ };
138
+ export var isPropAbsent = function isPropAbsent(prop) {
139
+ return isNil(prop);
140
+ };
133
141
  export var isStringNumber = function isStringNumber(val) {
134
142
  if (!isString(val)) {
135
143
  return false;
@@ -165,4 +173,135 @@ export function mergeDefaultProps() {
165
173
  }
166
174
  }
167
175
  return props;
168
- }
176
+ }
177
+ var isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
178
+ function isNative(Ctor) {
179
+ return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
180
+ }
181
+ // 上面三行与核心代码关系不大,了解即可
182
+ // noop 表示一个无操作空函数,用作函数默认值,防止传入 undefined 导致报错
183
+ // handleError 错误处理函数
184
+ // isIE, isIOS, isNative 环境判断函数,
185
+ // isNative 判断某个属性或方法是否原生支持,如果不支持或通过第三方实现支持都会返回 false
186
+
187
+ export var isUsingMicroTask = false; // 标记 nextTick 最终是否以微任务执行
188
+
189
+ var callbacks = []; // 存放调用 nextTick 时传入的回调函数
190
+ var pending = false; // 标记是否已经向任务队列中添加了一个任务,如果已经添加了就不能再添加了
191
+ // 当向任务队列中添加了任务时,将 pending 置为 true,当任务被执行时将 pending 置为 false
192
+ //
193
+
194
+ // 声明 nextTick 函数,接收一个回调函数和一个执行上下文作为参数
195
+ // 回调的 this 自动绑定到调用它的实例上
196
+ export function nextTick(cb, ctx) {
197
+ var _resolve;
198
+ // 将传入的回调函数存放到数组中,后面会遍历执行其中的回调
199
+ callbacks.push(function () {
200
+ if (cb) {
201
+ // 对传入的回调进行 try catch 错误捕获
202
+ try {
203
+ cb.call(ctx);
204
+ } catch (e) {
205
+ // 进行统一的错误处理
206
+ // handleError(e, ctx, 'nextTick');
207
+ }
208
+ } else if (_resolve) {
209
+ _resolve(ctx);
210
+ }
211
+ });
212
+
213
+ // 如果当前没有在 pending 的回调,
214
+ // 就执行 timeFunc 函数选择当前环境优先支持的异步方法
215
+ if (!pending) {
216
+ pending = true;
217
+ timerFunc();
218
+ }
219
+
220
+ // 如果没有传入回调,并且当前环境支持 promise,就返回一个 promise
221
+ // 在返回的这个 promise.then 中 DOM 已经更新好了,
222
+ if (!cb && typeof Promise !== 'undefined') {
223
+ return new Promise(function (resolve) {
224
+ _resolve = resolve;
225
+ });
226
+ }
227
+ }
228
+
229
+ // 判断当前环境优先支持的异步方法,优先选择微任务
230
+ // 优先级:Promise---> MutationObserver---> setImmediate---> setTimeout
231
+ // setTimeout 可能产生一个 4ms 的延迟,而 setImmediate 会在主线程执行完后立刻执行
232
+ // setImmediate 在 IE10 和 node 中支持
233
+
234
+ // 当在同一轮事件循环中多次调用 nextTick 时 ,timerFunc 只会执行一次
235
+
236
+ var timerFunc;
237
+ // 判断当前环境是否原生支持 promise
238
+ if (typeof Promise !== 'undefined' && isNative(Promise)) {
239
+ // 支持 promise
240
+ var p = Promise.resolve();
241
+ timerFunc = function timerFunc() {
242
+ // 用 promise.then 把 flushCallbacks 函数包裹成一个异步微任务
243
+ p.then(flushCallbacks);
244
+ if (isIOS) {
245
+ setTimeout(noop);
246
+ }
247
+ // 这里的 setTimeout 是用来强制刷新微任务队列的
248
+ // 因为在 ios 下 promise.then 后面没有宏任务的话,微任务队列不会刷新
249
+ };
250
+ // 标记当前 nextTick 使用的微任务
251
+ isUsingMicroTask = true;
252
+
253
+ // 如果不支持 promise,就判断是否支持 MutationObserver
254
+ // 不是IE环境,并且原生支持 MutationObserver,那也是一个微任务
255
+ } else if (typeof MutationObserver !== 'undefined' && (isNative(MutationObserver) || MutationObserver.toString() === '[object MutationObserverConstructor]')) {
256
+ var counter = 1;
257
+ // new 一个 MutationObserver 类
258
+ var observer = new MutationObserver(flushCallbacks);
259
+ // 创建一个文本节点
260
+ var textNode = document.createTextNode(String(counter));
261
+ // 监听这个文本节点,当数据发生变化就执行 flushCallbacks
262
+ observer.observe(textNode, {
263
+ characterData: true
264
+ });
265
+ timerFunc = function timerFunc() {
266
+ counter = (counter + 1) % 2;
267
+ textNode.data = String(counter); // 数据更新
268
+ };
269
+ isUsingMicroTask = true; // 标记当前 nextTick 使用的微任务
270
+
271
+ // 判断当前环境是否原生支持 setImmediate
272
+ } else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) {
273
+ timerFunc = function timerFunc() {
274
+ setImmediate(flushCallbacks);
275
+ };
276
+ } else {
277
+ // 以上三种都不支持就选择 setTimeout
278
+ timerFunc = function timerFunc() {
279
+ setTimeout(flushCallbacks, 0);
280
+ };
281
+ }
282
+
283
+ // 如果多次调用 nextTick,会依次执行上面的方法,将 nextTick 的回调放在 callbacks 数组中
284
+ // 最后通过 flushCallbacks 函数遍历 callbacks 数组的拷贝并执行其中的回调
285
+ function flushCallbacks() {
286
+ pending = false;
287
+ var copies = callbacks.slice(0); // 拷贝一份 callbacks
288
+ callbacks.length = 0; // 清空 callbacks
289
+ for (var i = 0; i < copies.length; i++) {
290
+ // 遍历执行传入的回调
291
+ copies[i]();
292
+ }
293
+ }
294
+
295
+ // 为什么要拷贝一份 callbacks
296
+
297
+ // 用 callbacks.slice(0) 将 callbacks 拷贝出来一份,
298
+ // 是因为考虑到在 nextTick 回调中可能还会调用 nextTick 的情况,
299
+ // 如果在 nextTick 回调中又调用了一次 nextTick,则又会向 callbacks 中添加回调,
300
+ // 而 nextTick 回调中的 nextTick 应该放在下一轮执行,
301
+ // 否则就可能出现一直循环的情况,
302
+ // 所以需要将 callbacks 复制一份出来然后清空,再遍历备份列表执行回调
303
+
304
+ export var escapeStringRegexp = function escapeStringRegexp() {
305
+ var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
306
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
307
+ };
@@ -1,9 +1,12 @@
1
+ import { IconName } from '../Icon';
1
2
  export declare const TypeMap: {
3
+ primary: string;
2
4
  success: string;
3
5
  info: string;
4
6
  warning: string;
5
7
  error: string;
6
8
  };
9
+ export declare const TypeComponentsMap: Record<string, IconName>;
7
10
  export declare const EVENT_CODE: {
8
11
  tab: string;
9
12
  enter: string;
@@ -1,9 +1,17 @@
1
1
  export var TypeMap = {
2
+ primary: 'primary',
2
3
  success: 'success',
3
4
  info: 'info',
4
5
  warning: 'warning',
5
6
  error: 'error'
6
7
  };
8
+ export var TypeComponentsMap = {
9
+ primary: 'info-circle',
10
+ success: 'circle-check',
11
+ info: 'info-circle',
12
+ warning: 'circle-exclamation',
13
+ error: 'circle-xmark'
14
+ };
7
15
  export var EVENT_CODE = {
8
16
  tab: 'Tab',
9
17
  enter: 'Enter',
@@ -9,5 +9,6 @@ export { default as prefix } from './prefix';
9
9
  export { partitionTreePropsUtils } from './treePropsUtils';
10
10
  export { default as useChildrenInstance } from './useChildrenInstance';
11
11
  export * from './useCommonProps';
12
+ export { useConfigProvider } from './useConfigProvider';
12
13
  export { useForceUpdate } from './useForceUpdate';
13
14
  export { default as useUpdateEffect } from './useUpdateEffect';
@@ -11,5 +11,6 @@ export { default as prefix } from "./prefix";
11
11
  export { partitionTreePropsUtils } from "./treePropsUtils";
12
12
  export { default as useChildrenInstance } from "./useChildrenInstance";
13
13
  export * from "./useCommonProps";
14
+ export { useConfigProvider } from "./useConfigProvider";
14
15
  export { useForceUpdate } from "./useForceUpdate";
15
16
  export { default as useUpdateEffect } from "./useUpdateEffect";
@@ -1,7 +1,7 @@
1
1
  import forEach from 'lodash/forEach';
2
2
  import includes from 'lodash/includes';
3
3
  // @ts-ignore
4
- export var popperAllProps = ['popperInstRef', 'offset', 'placement', 'arrowOffset', 'showArrow', 'popperClass', 'popperStyle', 'name', 'display', 'unmountOnExit', 'transitionAppear', 'duration', 'gpuAcceleration', 'strategy', 'appendToBody', 'appendTo', 'popperOptions', 'fallbackPlacements'];
4
+ export var popperAllProps = ['popperInstRef', 'offset', 'placement', 'arrowOffset', 'showArrow', 'popperClass', 'popperStyle', 'name', 'display', 'unmountOnExit', 'transitionAppear', 'duration', 'gpuAcceleration', 'strategy', 'appendToBody', 'appendTo', 'popperOptions', 'fallbackPlacements', 'effect'];
5
5
 
6
6
  /**
7
7
  * Returns an array of objects consisting of: props of html input element and rest.
@@ -1,15 +1,15 @@
1
- import { DirectoryTreeProps } from '../Tree';
1
+ import { TreeProps } from '../Tree';
2
2
  export declare const treeAllProps: string[];
3
3
  /**
4
4
  * Returns an array of objects consisting of: props of html input element and rest.
5
5
  * @author Parker
6
6
  * @CreateTime 2022/4/8 17:46:40
7
7
  * @LastEditor Parker
8
- * @ModifyTime 2022/4/21 10:06:19
8
+ * @ModifyTime 2026/2/7 14:37:37
9
9
  * @param {object} props A ReactElement props object
10
10
  * @param {Object} [options={}]
11
11
  * @param {Array} [options.htmlProps] An array of html input props
12
12
  * @param {boolean} [options.includeAria] Includes all input props that starts with "aria-"
13
13
  * @returns {[{}, {}]} An array of objects
14
14
  */
15
- export declare const partitionTreePropsUtils: (props: any, options?: any) => [DirectoryTreeProps<any>, any];
15
+ export declare const partitionTreePropsUtils: (props: any, options?: any) => [TreeProps, any];
@@ -1,13 +1,13 @@
1
1
  import forEach from 'lodash/forEach';
2
2
  import includes from 'lodash/includes';
3
- export var treeAllProps = ['showLine', 'multiple', 'selectedKeys', 'filterAntTreeNode', 'showIcon', 'switcherIcon', 'children', 'blockNode', 'prefixCls', 'focusable', 'activeKey', 'tabIndex', 'treeData', 'fieldNames', 'icon', 'selectable', 'disabled', 'checkable', 'checkStrictly', 'draggable', 'defaultExpandParent', 'autoExpandParent', 'defaultExpandAll', 'defaultExpandedKeys', 'expandedKeys', 'defaultCheckedKeys', 'checkedKeys', 'defaultSelectedKeys', 'allowDrop', 'titleRender', 'dropIndicatorRender', 'onFocus', 'onBlur', 'onKeyDown', 'onContextMenu', 'onClick', 'onDoubleClick', 'onScroll', 'onExpand', 'onCheck', 'onSelect', 'onLoad', 'loadData', 'loadedKeys', 'onMouseEnter', 'onMouseLeave', 'onRightClick', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDragLeave', 'onDragEnd', 'onDrop'];
3
+ export var treeAllProps = ['data', 'emptyText', 'renderAfterExpand', 'nodeKey', 'checkStrictly', 'expandOnClickNode', 'defaultExpandAll', 'checkOnClickNode', 'checkOnClickLeaf', 'checkDescendants', 'autoExpandParent', 'defaultCheckedKeys', 'defaultExpandedKeys', 'currentNodeKey', 'renderContent', 'showCheckbox', 'draggable', 'allowDrag', 'allowDrop', 'props', 'lazy', 'highlightCurrent', 'load', 'filterNodeMethod', 'accordion', 'indent', 'icon', 'renderEmpty', 'onNodeClick', 'onNodeContextmenu', 'onCheckChange', 'onNodeExpandAll', 'onCheck', 'onCurrentChange', 'onNodeExpand', 'onNodeCollapse', 'onNodeDragStart', 'onNodeDragOver', 'onNodeDragLeave', 'onNodeDragEnter', 'onNodeDragEnd', 'onNodeDrop'];
4
4
 
5
5
  /**
6
6
  * Returns an array of objects consisting of: props of html input element and rest.
7
7
  * @author Parker
8
8
  * @CreateTime 2022/4/8 17:46:40
9
9
  * @LastEditor Parker
10
- * @ModifyTime 2022/4/21 10:06:19
10
+ * @ModifyTime 2026/2/7 14:37:37
11
11
  * @param {object} props A ReactElement props object
12
12
  * @param {Object} [options={}]
13
13
  * @param {Array} [options.htmlProps] An array of html input props
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export declare function useCalcInputWidth(): {
3
+ calculatorRef: import("react").MutableRefObject<HTMLElement>;
4
+ calculatorWidth: number;
5
+ inputStyle: {
6
+ minWidth: string;
7
+ };
8
+ };
@@ -4,31 +4,27 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
8
- import * as React from 'react';
9
-
10
- /**
11
- * Trigger only when component unmount
12
- */
13
- function useUnmount(triggerStart, triggerEnd) {
14
- var _React$useState = React.useState(false),
15
- _React$useState2 = _slicedToArray(_React$useState, 2),
16
- firstMount = _React$useState2[0],
17
- setFirstMount = _React$useState2[1];
18
- useLayoutEffect(function () {
19
- if (firstMount) {
20
- triggerStart();
21
- return function () {
22
- triggerEnd();
23
- };
24
- }
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [firstMount]);
27
- useLayoutEffect(function () {
28
- setFirstMount(true);
29
- return function () {
30
- setFirstMount(false);
7
+ import { useMemo, useRef, useState } from 'react';
8
+ import { useResizeObserver } from "./useResizeObserver";
9
+ export function useCalcInputWidth() {
10
+ var calculatorRef = useRef();
11
+ var _useState = useState(0),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ calculatorWidth = _useState2[0],
14
+ setCalculatorWidth = _useState2[1];
15
+ var inputStyle = useMemo(function () {
16
+ return {
17
+ minWidth: "".concat(Math.max(calculatorWidth, 11), "px")
31
18
  };
32
- }, []);
33
- }
34
- export default useUnmount;
19
+ }, [calculatorWidth]);
20
+ var resetCalculatorWidth = function resetCalculatorWidth() {
21
+ var _calculatorRef$curren, _calculatorRef$curren2;
22
+ setCalculatorWidth((_calculatorRef$curren = (_calculatorRef$curren2 = calculatorRef.current) === null || _calculatorRef$curren2 === void 0 ? void 0 : _calculatorRef$curren2.getBoundingClientRect().width) !== null && _calculatorRef$curren !== void 0 ? _calculatorRef$curren : 0);
23
+ };
24
+ useResizeObserver(calculatorRef, resetCalculatorWidth);
25
+ return {
26
+ calculatorRef: calculatorRef,
27
+ calculatorWidth: calculatorWidth,
28
+ inputStyle: inputStyle
29
+ };
30
+ }
@@ -0,0 +1,16 @@
1
+ import { CompositionEvent } from 'react';
2
+ interface UseCompositionOptions {
3
+ afterComposition: (event: CompositionEvent<HTMLInputElement>) => void;
4
+ compositionstart?: (evt: CompositionEvent<HTMLInputElement>) => void;
5
+ compositionupdate?: (evt: CompositionEvent<HTMLInputElement>) => void;
6
+ compositionend?: (evt: CompositionEvent<HTMLInputElement>) => void;
7
+ }
8
+ export declare function useComposition({ afterComposition, compositionstart, compositionupdate, compositionend }: UseCompositionOptions): {
9
+ isComposing: import("react").MutableRefObject<boolean>;
10
+ handleComposition: (event: CompositionEvent<HTMLInputElement>) => void;
11
+ handleCompositionStart: (event: CompositionEvent<HTMLInputElement>) => void;
12
+ handleCompositionUpdate: (event: CompositionEvent<HTMLInputElement>) => void;
13
+ handleCompositionEnd: (event: CompositionEvent<HTMLInputElement>) => void;
14
+ };
15
+ export declare const isKorean: (text: string) => boolean;
16
+ export {};
@@ -0,0 +1,39 @@
1
+ import { useRef } from 'react';
2
+ export function useComposition(_ref) {
3
+ var afterComposition = _ref.afterComposition,
4
+ compositionstart = _ref.compositionstart,
5
+ compositionupdate = _ref.compositionupdate,
6
+ compositionend = _ref.compositionend;
7
+ var isComposing = useRef(false);
8
+ var handleCompositionStart = function handleCompositionStart(event) {
9
+ compositionstart === null || compositionstart === void 0 || compositionstart(event);
10
+ isComposing.current = true;
11
+ };
12
+ var handleCompositionUpdate = function handleCompositionUpdate(event) {
13
+ var _event$target;
14
+ compositionupdate === null || compositionupdate === void 0 || compositionupdate(event);
15
+ var text = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value;
16
+ var lastCharacter = text[text.length - 1] || '';
17
+ isComposing.current = !isKorean(lastCharacter);
18
+ };
19
+ var handleCompositionEnd = function handleCompositionEnd(event) {
20
+ compositionend === null || compositionend === void 0 || compositionend(event);
21
+ if (isComposing.current) {
22
+ isComposing.current = false;
23
+ afterComposition(event);
24
+ }
25
+ };
26
+ var handleComposition = function handleComposition(event) {
27
+ event.type === 'compositionend' ? handleCompositionEnd(event) : handleCompositionUpdate(event);
28
+ };
29
+ return {
30
+ isComposing: isComposing,
31
+ handleComposition: handleComposition,
32
+ handleCompositionStart: handleCompositionStart,
33
+ handleCompositionUpdate: handleCompositionUpdate,
34
+ handleCompositionEnd: handleCompositionEnd
35
+ };
36
+ }
37
+ export var isKorean = function isKorean(text) {
38
+ return /([\uAC00-\uD7AF\u3130-\u318F])+/gi.test(text);
39
+ };
@@ -0,0 +1,27 @@
1
+ /// <reference types="react" />
2
+ import { MessageMethod } from '../Message/typings';
3
+ import { MessageBoxProps } from '../MessageBox';
4
+ import { Action, MessageBoxInputData } from '../MessageBox/typings';
5
+ export declare const useConfigProvider: () => {
6
+ ElMessage: MessageMethod;
7
+ ElMessageBox: {
8
+ (options?: MessageBoxProps): Promise<Action>;
9
+ /**
10
+ * 消息弹窗提示
11
+ * @param message 消息内容
12
+ * @param title 标题
13
+ * @param options 其他设置项
14
+ * @returns
15
+ */
16
+ alert: (message: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, title?: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | MessageBoxProps, options?: MessageBoxProps) => Promise<Action>;
17
+ /**
18
+ * 确认消息
19
+ * @param message 消息内容
20
+ * @param title 标题
21
+ * @param options 其他设置项
22
+ * @returns
23
+ */
24
+ confirm: (message: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, title?: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | MessageBoxProps, options?: MessageBoxProps) => Promise<Action>;
25
+ prompt: (message: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>, title?: string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | MessageBoxProps, options?: MessageBoxProps) => Promise<MessageBoxInputData>;
26
+ };
27
+ };
@@ -0,0 +1,78 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ 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; }
3
+ 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; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { isValidElement, useContext } from 'react';
8
+ import ConfigProviderContext from "../ConfigProvider/ConfigProviderContext";
9
+ import { Message } from "../Message";
10
+ import { MessageBox, instanceFactory } from "../MessageBox";
11
+ import { isEmpty } from "../Util";
12
+ export var useConfigProvider = function useConfigProvider() {
13
+ var _useContext = useContext(ConfigProviderContext),
14
+ messageConfig = _useContext.message,
15
+ locale = _useContext.locale;
16
+ var ElMessage = function ElMessage() {
17
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18
+ if (typeof opts === 'string' || /*#__PURE__*/isValidElement(opts)) {
19
+ opts = _objectSpread(_objectSpread({}, messageConfig), {}, {
20
+ message: opts
21
+ });
22
+ }
23
+ if (isEmpty(opts)) {
24
+ opts = _objectSpread(_objectSpread({}, messageConfig), {}, {
25
+ message: ''
26
+ });
27
+ } else {
28
+ opts = _objectSpread(_objectSpread({}, messageConfig), opts);
29
+ }
30
+ var options = opts;
31
+ Message(options);
32
+ };
33
+ ['primary', 'success', 'warning', 'info', 'error'].forEach(function (type) {
34
+ ElMessage[type] = function (options) {
35
+ if (typeof options === 'string' || /*#__PURE__*/isValidElement(options)) {
36
+ options = _objectSpread(_objectSpread({}, messageConfig), {}, {
37
+ message: options,
38
+ type: type
39
+ });
40
+ } else {
41
+ options = _objectSpread(_objectSpread(_objectSpread({}, messageConfig), options), {}, {
42
+ type: type
43
+ });
44
+ }
45
+ return Message(options);
46
+ };
47
+ });
48
+ ElMessage.closeAll = Message.closeAll;
49
+ var ElMessageBox = function ElMessageBox() {
50
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
51
+ return MessageBox(_objectSpread({
52
+ locale: locale
53
+ }, options));
54
+ };
55
+
56
+ /**
57
+ * 消息弹窗提示
58
+ * @param message 消息内容
59
+ * @param title 标题
60
+ * @param options 其他设置项
61
+ * @returns
62
+ */
63
+ ElMessageBox.alert = instanceFactory('alert', locale);
64
+
65
+ /**
66
+ * 确认消息
67
+ * @param message 消息内容
68
+ * @param title 标题
69
+ * @param options 其他设置项
70
+ * @returns
71
+ */
72
+ ElMessageBox.confirm = instanceFactory('confirm', locale);
73
+ ElMessageBox.prompt = instanceFactory('prompt', locale);
74
+ return {
75
+ ElMessage: ElMessage,
76
+ ElMessageBox: ElMessageBox
77
+ };
78
+ };
@@ -0,0 +1,2 @@
1
+ import { RefObject } from 'react';
2
+ export declare function useCursor(input: RefObject<HTMLInputElement | undefined>): [() => void, () => void];
@@ -0,0 +1,52 @@
1
+ // Keep input cursor in the correct position when we use formatter.
2
+ export function useCursor(input) {
3
+ var selectionInfo;
4
+ function recordCursor() {
5
+ if (input.current == undefined) {
6
+ return;
7
+ }
8
+ var _input$current = input.current,
9
+ selectionStart = _input$current.selectionStart,
10
+ selectionEnd = _input$current.selectionEnd,
11
+ value = _input$current.value;
12
+ if (selectionStart == null || selectionEnd == null) {
13
+ return;
14
+ }
15
+ var beforeTxt = value.slice(0, Math.max(0, selectionStart));
16
+ var afterTxt = value.slice(Math.max(0, selectionEnd));
17
+ selectionInfo = {
18
+ selectionStart: selectionStart,
19
+ selectionEnd: selectionEnd,
20
+ value: value,
21
+ beforeTxt: beforeTxt,
22
+ afterTxt: afterTxt
23
+ };
24
+ }
25
+ function setCursor() {
26
+ if (input.current == undefined || selectionInfo == undefined) {
27
+ return;
28
+ }
29
+ var value = input.current.value;
30
+ var _selectionInfo = selectionInfo,
31
+ beforeTxt = _selectionInfo.beforeTxt,
32
+ afterTxt = _selectionInfo.afterTxt,
33
+ selectionStart = _selectionInfo.selectionStart;
34
+ if (beforeTxt == undefined || afterTxt == undefined || selectionStart == undefined) {
35
+ return;
36
+ }
37
+ var startPos = value.length;
38
+ if (value.endsWith(afterTxt)) {
39
+ startPos = value.length - afterTxt.length;
40
+ } else if (value.startsWith(beforeTxt)) {
41
+ startPos = beforeTxt.length;
42
+ } else {
43
+ var beforeLastChar = beforeTxt[selectionStart - 1];
44
+ var newIndex = value.indexOf(beforeLastChar, selectionStart - 1);
45
+ if (newIndex !== -1) {
46
+ startPos = newIndex + 1;
47
+ }
48
+ }
49
+ input.current.setSelectionRange(startPos, startPos);
50
+ }
51
+ return [recordCursor, setCursor];
52
+ }
@@ -0,0 +1,27 @@
1
+ import { RefObject } from 'react';
2
+ interface UseFocusControllerOptions {
3
+ disabled?: boolean;
4
+ /**
5
+ * return true to cancel focus
6
+ * @param event FocusEvent
7
+ */
8
+ beforeFocus?: (event: FocusEvent) => boolean | undefined;
9
+ afterFocus?: () => void;
10
+ /**
11
+ * return true to cancel blur
12
+ * @param event FocusEvent
13
+ */
14
+ beforeBlur?: (event: FocusEvent) => boolean | undefined;
15
+ afterBlur?: () => void;
16
+ }
17
+ export declare function useFocusController<T extends {
18
+ focus: () => void;
19
+ }>(target: RefObject<HTMLElement | undefined>, { disabled, beforeFocus, afterFocus, beforeBlur, afterBlur }?: UseFocusControllerOptions): {
20
+ isFocused: boolean;
21
+ /** Avoid using wrapperRef and handleFocus/handleBlur together */
22
+ wrapperRef: import("react").MutableRefObject<HTMLInputElement>;
23
+ handleFocus: (event: FocusEvent) => void;
24
+ handleBlur: (event: FocusEvent) => void;
25
+ handleClick: (event: Event) => void;
26
+ };
27
+ export {};
@@ -0,0 +1,72 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import isFunction from 'lodash/isFunction';
8
+ import { useRef, useState } from 'react';
9
+ import { isFocusable } from "../Util/aria";
10
+ export function useFocusController(target) {
11
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
12
+ disabled = _ref.disabled,
13
+ beforeFocus = _ref.beforeFocus,
14
+ afterFocus = _ref.afterFocus,
15
+ beforeBlur = _ref.beforeBlur,
16
+ afterBlur = _ref.afterBlur;
17
+ var _useState = useState(false),
18
+ _useState2 = _slicedToArray(_useState, 2),
19
+ isFocused = _useState2[0],
20
+ setIsFocused = _useState2[1];
21
+ var wrapperRef = useRef(null);
22
+ var handleFocus = function handleFocus(event) {
23
+ var cancelFocus = isFunction(beforeFocus) ? beforeFocus(event) : false;
24
+ if (disabled || isFocused || cancelFocus) {
25
+ return;
26
+ }
27
+ setIsFocused(true);
28
+ // emit('focus', event);
29
+ afterFocus === null || afterFocus === void 0 || afterFocus();
30
+ };
31
+ var handleBlur = function handleBlur(event) {
32
+ var _wrapperRef$current;
33
+ var cancelBlur = isFunction(beforeBlur) ? beforeBlur(event) : false;
34
+ if (disabled || event.relatedTarget && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(event.relatedTarget) || cancelBlur) {
35
+ return;
36
+ }
37
+ setIsFocused(false);
38
+
39
+ // emit('blur', event);
40
+ afterBlur === null || afterBlur === void 0 || afterBlur();
41
+ };
42
+ var handleClick = function handleClick(event) {
43
+ var _wrapperRef$current2, _target$current;
44
+ if (disabled || isFocusable(event.target) || (_wrapperRef$current2 = wrapperRef.current) !== null && _wrapperRef$current2 !== void 0 && _wrapperRef$current2.contains(document.activeElement) && wrapperRef.current !== document.activeElement) {
45
+ return;
46
+ }
47
+ (_target$current = target.current) === null || _target$current === void 0 || _target$current.focus();
48
+ };
49
+
50
+ // useMount(() => {
51
+ // if (!wrapperRef.current) {
52
+ // return;
53
+ // }
54
+ // wrapperRef.current.addEventListener('focus', handleFocus, true);
55
+ // wrapperRef.current.addEventListener('blur', handleBlur, true);
56
+ // wrapperRef.current.addEventListener('click', handleClick, true);
57
+ // return () => {
58
+ // wrapperRef.current?.removeEventListener('focus', handleFocus, true);
59
+ // wrapperRef.current?.removeEventListener('blur', handleBlur, true);
60
+ // wrapperRef.current?.removeEventListener('click', handleClick, true);
61
+ // };
62
+ // });
63
+
64
+ return {
65
+ isFocused: isFocused,
66
+ /** Avoid using wrapperRef and handleFocus/handleBlur together */
67
+ wrapperRef: wrapperRef,
68
+ handleFocus: handleFocus,
69
+ handleBlur: handleBlur,
70
+ handleClick: handleClick
71
+ };
72
+ }