@rc-component/util 1.0.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 (159) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +303 -0
  3. package/es/Children/toArray.d.ts +5 -0
  4. package/es/Children/toArray.js +19 -0
  5. package/es/Dom/canUseDom.d.ts +1 -0
  6. package/es/Dom/canUseDom.js +3 -0
  7. package/es/Dom/contains.d.ts +1 -0
  8. package/es/Dom/contains.js +20 -0
  9. package/es/Dom/dynamicCSS.d.ts +25 -0
  10. package/es/Dom/dynamicCSS.js +153 -0
  11. package/es/Dom/findDOMNode.d.ts +12 -0
  12. package/es/Dom/findDOMNode.js +36 -0
  13. package/es/Dom/focus.d.ts +8 -0
  14. package/es/Dom/focus.js +87 -0
  15. package/es/Dom/isVisible.d.ts +2 -0
  16. package/es/Dom/isVisible.js +27 -0
  17. package/es/Dom/scrollLocker.d.ts +12 -0
  18. package/es/Dom/scrollLocker.js +135 -0
  19. package/es/Dom/shadow.d.ts +8 -0
  20. package/es/Dom/shadow.js +18 -0
  21. package/es/Dom/styleChecker.d.ts +2 -0
  22. package/es/Dom/styleChecker.js +26 -0
  23. package/es/KeyCode.d.ts +436 -0
  24. package/es/KeyCode.js +538 -0
  25. package/es/Portal.d.ts +9 -0
  26. package/es/Portal.js +44 -0
  27. package/es/PortalWrapper.d.ts +51 -0
  28. package/es/PortalWrapper.js +217 -0
  29. package/es/React/isFragment.d.ts +4 -0
  30. package/es/React/isFragment.js +18 -0
  31. package/es/React/render.d.ts +13 -0
  32. package/es/React/render.js +114 -0
  33. package/es/composeProps.d.ts +2 -0
  34. package/es/composeProps.js +24 -0
  35. package/es/getScrollBarSize.d.ts +7 -0
  36. package/es/getScrollBarSize.js +76 -0
  37. package/es/hooks/useEffect.d.ts +2 -0
  38. package/es/hooks/useEffect.js +14 -0
  39. package/es/hooks/useEvent.d.ts +2 -0
  40. package/es/hooks/useEvent.js +16 -0
  41. package/es/hooks/useId.d.ts +4 -0
  42. package/es/hooks/useId.js +69 -0
  43. package/es/hooks/useLayoutEffect.d.ts +4 -0
  44. package/es/hooks/useLayoutEffect.js +30 -0
  45. package/es/hooks/useMemo.d.ts +1 -0
  46. package/es/hooks/useMemo.js +9 -0
  47. package/es/hooks/useMergedState.d.ts +12 -0
  48. package/es/hooks/useMergedState.js +68 -0
  49. package/es/hooks/useMobile.d.ts +6 -0
  50. package/es/hooks/useMobile.js +25 -0
  51. package/es/hooks/useState.d.ts +14 -0
  52. package/es/hooks/useState.js +32 -0
  53. package/es/hooks/useSyncState.d.ts +9 -0
  54. package/es/hooks/useSyncState.js +29 -0
  55. package/es/index.d.ts +6 -0
  56. package/es/index.js +6 -0
  57. package/es/isEqual.d.ts +9 -0
  58. package/es/isEqual.js +55 -0
  59. package/es/isMobile.d.ts +2 -0
  60. package/es/isMobile.js +7 -0
  61. package/es/omit.d.ts +1 -0
  62. package/es/omit.js +9 -0
  63. package/es/pickAttrs.d.ts +11 -0
  64. package/es/pickAttrs.js +51 -0
  65. package/es/proxyObject.d.ts +4 -0
  66. package/es/proxyObject.js +19 -0
  67. package/es/raf.d.ts +6 -0
  68. package/es/raf.js +54 -0
  69. package/es/ref.d.ts +19 -0
  70. package/es/ref.js +89 -0
  71. package/es/setStyle.d.ts +12 -0
  72. package/es/setStyle.js +26 -0
  73. package/es/test/domHook.d.ts +8 -0
  74. package/es/test/domHook.js +64 -0
  75. package/es/utils/get.d.ts +1 -0
  76. package/es/utils/get.js +10 -0
  77. package/es/utils/set.d.ts +6 -0
  78. package/es/utils/set.js +93 -0
  79. package/es/warning.d.ts +32 -0
  80. package/es/warning.js +68 -0
  81. package/lib/Children/toArray.d.ts +5 -0
  82. package/lib/Children/toArray.js +26 -0
  83. package/lib/Dom/canUseDom.d.ts +1 -0
  84. package/lib/Dom/canUseDom.js +9 -0
  85. package/lib/Dom/contains.d.ts +1 -0
  86. package/lib/Dom/contains.js +26 -0
  87. package/lib/Dom/dynamicCSS.d.ts +25 -0
  88. package/lib/Dom/dynamicCSS.js +163 -0
  89. package/lib/Dom/findDOMNode.d.ts +12 -0
  90. package/lib/Dom/findDOMNode.js +45 -0
  91. package/lib/Dom/focus.d.ts +8 -0
  92. package/lib/Dom/focus.js +98 -0
  93. package/lib/Dom/isVisible.d.ts +2 -0
  94. package/lib/Dom/isVisible.js +33 -0
  95. package/lib/Dom/scrollLocker.d.ts +12 -0
  96. package/lib/Dom/scrollLocker.js +141 -0
  97. package/lib/Dom/shadow.d.ts +8 -0
  98. package/lib/Dom/shadow.js +25 -0
  99. package/lib/Dom/styleChecker.d.ts +2 -0
  100. package/lib/Dom/styleChecker.js +33 -0
  101. package/lib/KeyCode.d.ts +436 -0
  102. package/lib/KeyCode.js +544 -0
  103. package/lib/Portal.d.ts +9 -0
  104. package/lib/Portal.js +51 -0
  105. package/lib/PortalWrapper.d.ts +51 -0
  106. package/lib/PortalWrapper.js +226 -0
  107. package/lib/React/isFragment.d.ts +4 -0
  108. package/lib/React/isFragment.js +24 -0
  109. package/lib/React/render.d.ts +13 -0
  110. package/lib/React/render.js +125 -0
  111. package/lib/composeProps.d.ts +2 -0
  112. package/lib/composeProps.js +30 -0
  113. package/lib/getScrollBarSize.d.ts +7 -0
  114. package/lib/getScrollBarSize.js +84 -0
  115. package/lib/hooks/useEffect.d.ts +2 -0
  116. package/lib/hooks/useEffect.js +22 -0
  117. package/lib/hooks/useEvent.d.ts +2 -0
  118. package/lib/hooks/useEvent.js +26 -0
  119. package/lib/hooks/useId.d.ts +4 -0
  120. package/lib/hooks/useId.js +78 -0
  121. package/lib/hooks/useLayoutEffect.d.ts +4 -0
  122. package/lib/hooks/useLayoutEffect.js +39 -0
  123. package/lib/hooks/useMemo.d.ts +1 -0
  124. package/lib/hooks/useMemo.js +18 -0
  125. package/lib/hooks/useMergedState.d.ts +12 -0
  126. package/lib/hooks/useMergedState.js +75 -0
  127. package/lib/hooks/useMobile.d.ts +6 -0
  128. package/lib/hooks/useMobile.js +31 -0
  129. package/lib/hooks/useState.d.ts +14 -0
  130. package/lib/hooks/useState.js +41 -0
  131. package/lib/hooks/useSyncState.d.ts +9 -0
  132. package/lib/hooks/useSyncState.js +39 -0
  133. package/lib/index.d.ts +6 -0
  134. package/lib/index.js +60 -0
  135. package/lib/isEqual.d.ts +9 -0
  136. package/lib/isEqual.js +61 -0
  137. package/lib/isMobile.d.ts +2 -0
  138. package/lib/isMobile.js +13 -0
  139. package/lib/omit.d.ts +1 -0
  140. package/lib/omit.js +15 -0
  141. package/lib/pickAttrs.d.ts +11 -0
  142. package/lib/pickAttrs.js +57 -0
  143. package/lib/proxyObject.d.ts +4 -0
  144. package/lib/proxyObject.js +25 -0
  145. package/lib/raf.d.ts +6 -0
  146. package/lib/raf.js +60 -0
  147. package/lib/ref.d.ts +19 -0
  148. package/lib/ref.js +96 -0
  149. package/lib/setStyle.d.ts +12 -0
  150. package/lib/setStyle.js +32 -0
  151. package/lib/test/domHook.d.ts +8 -0
  152. package/lib/test/domHook.js +71 -0
  153. package/lib/utils/get.d.ts +1 -0
  154. package/lib/utils/get.js +16 -0
  155. package/lib/utils/set.d.ts +6 -0
  156. package/lib/utils/set.js +101 -0
  157. package/lib/warning.d.ts +32 -0
  158. package/lib/warning.js +81 -0
  159. package/package.json +76 -0
package/es/KeyCode.js ADDED
@@ -0,0 +1,538 @@
1
+ /**
2
+ * @ignore
3
+ * some key-codes definition and utils from closure-library
4
+ * @author yiminghe@gmail.com
5
+ */
6
+
7
+ var KeyCode = {
8
+ /**
9
+ * MAC_ENTER
10
+ */
11
+ MAC_ENTER: 3,
12
+ /**
13
+ * BACKSPACE
14
+ */
15
+ BACKSPACE: 8,
16
+ /**
17
+ * TAB
18
+ */
19
+ TAB: 9,
20
+ /**
21
+ * NUMLOCK on FF/Safari Mac
22
+ */
23
+ NUM_CENTER: 12,
24
+ // NUMLOCK on FF/Safari Mac
25
+ /**
26
+ * ENTER
27
+ */
28
+ ENTER: 13,
29
+ /**
30
+ * SHIFT
31
+ */
32
+ SHIFT: 16,
33
+ /**
34
+ * CTRL
35
+ */
36
+ CTRL: 17,
37
+ /**
38
+ * ALT
39
+ */
40
+ ALT: 18,
41
+ /**
42
+ * PAUSE
43
+ */
44
+ PAUSE: 19,
45
+ /**
46
+ * CAPS_LOCK
47
+ */
48
+ CAPS_LOCK: 20,
49
+ /**
50
+ * ESC
51
+ */
52
+ ESC: 27,
53
+ /**
54
+ * SPACE
55
+ */
56
+ SPACE: 32,
57
+ /**
58
+ * PAGE_UP
59
+ */
60
+ PAGE_UP: 33,
61
+ // also NUM_NORTH_EAST
62
+ /**
63
+ * PAGE_DOWN
64
+ */
65
+ PAGE_DOWN: 34,
66
+ // also NUM_SOUTH_EAST
67
+ /**
68
+ * END
69
+ */
70
+ END: 35,
71
+ // also NUM_SOUTH_WEST
72
+ /**
73
+ * HOME
74
+ */
75
+ HOME: 36,
76
+ // also NUM_NORTH_WEST
77
+ /**
78
+ * LEFT
79
+ */
80
+ LEFT: 37,
81
+ // also NUM_WEST
82
+ /**
83
+ * UP
84
+ */
85
+ UP: 38,
86
+ // also NUM_NORTH
87
+ /**
88
+ * RIGHT
89
+ */
90
+ RIGHT: 39,
91
+ // also NUM_EAST
92
+ /**
93
+ * DOWN
94
+ */
95
+ DOWN: 40,
96
+ // also NUM_SOUTH
97
+ /**
98
+ * PRINT_SCREEN
99
+ */
100
+ PRINT_SCREEN: 44,
101
+ /**
102
+ * INSERT
103
+ */
104
+ INSERT: 45,
105
+ // also NUM_INSERT
106
+ /**
107
+ * DELETE
108
+ */
109
+ DELETE: 46,
110
+ // also NUM_DELETE
111
+ /**
112
+ * ZERO
113
+ */
114
+ ZERO: 48,
115
+ /**
116
+ * ONE
117
+ */
118
+ ONE: 49,
119
+ /**
120
+ * TWO
121
+ */
122
+ TWO: 50,
123
+ /**
124
+ * THREE
125
+ */
126
+ THREE: 51,
127
+ /**
128
+ * FOUR
129
+ */
130
+ FOUR: 52,
131
+ /**
132
+ * FIVE
133
+ */
134
+ FIVE: 53,
135
+ /**
136
+ * SIX
137
+ */
138
+ SIX: 54,
139
+ /**
140
+ * SEVEN
141
+ */
142
+ SEVEN: 55,
143
+ /**
144
+ * EIGHT
145
+ */
146
+ EIGHT: 56,
147
+ /**
148
+ * NINE
149
+ */
150
+ NINE: 57,
151
+ /**
152
+ * QUESTION_MARK
153
+ */
154
+ QUESTION_MARK: 63,
155
+ // needs localization
156
+ /**
157
+ * A
158
+ */
159
+ A: 65,
160
+ /**
161
+ * B
162
+ */
163
+ B: 66,
164
+ /**
165
+ * C
166
+ */
167
+ C: 67,
168
+ /**
169
+ * D
170
+ */
171
+ D: 68,
172
+ /**
173
+ * E
174
+ */
175
+ E: 69,
176
+ /**
177
+ * F
178
+ */
179
+ F: 70,
180
+ /**
181
+ * G
182
+ */
183
+ G: 71,
184
+ /**
185
+ * H
186
+ */
187
+ H: 72,
188
+ /**
189
+ * I
190
+ */
191
+ I: 73,
192
+ /**
193
+ * J
194
+ */
195
+ J: 74,
196
+ /**
197
+ * K
198
+ */
199
+ K: 75,
200
+ /**
201
+ * L
202
+ */
203
+ L: 76,
204
+ /**
205
+ * M
206
+ */
207
+ M: 77,
208
+ /**
209
+ * N
210
+ */
211
+ N: 78,
212
+ /**
213
+ * O
214
+ */
215
+ O: 79,
216
+ /**
217
+ * P
218
+ */
219
+ P: 80,
220
+ /**
221
+ * Q
222
+ */
223
+ Q: 81,
224
+ /**
225
+ * R
226
+ */
227
+ R: 82,
228
+ /**
229
+ * S
230
+ */
231
+ S: 83,
232
+ /**
233
+ * T
234
+ */
235
+ T: 84,
236
+ /**
237
+ * U
238
+ */
239
+ U: 85,
240
+ /**
241
+ * V
242
+ */
243
+ V: 86,
244
+ /**
245
+ * W
246
+ */
247
+ W: 87,
248
+ /**
249
+ * X
250
+ */
251
+ X: 88,
252
+ /**
253
+ * Y
254
+ */
255
+ Y: 89,
256
+ /**
257
+ * Z
258
+ */
259
+ Z: 90,
260
+ /**
261
+ * META
262
+ */
263
+ META: 91,
264
+ // WIN_KEY_LEFT
265
+ /**
266
+ * WIN_KEY_RIGHT
267
+ */
268
+ WIN_KEY_RIGHT: 92,
269
+ /**
270
+ * CONTEXT_MENU
271
+ */
272
+ CONTEXT_MENU: 93,
273
+ /**
274
+ * NUM_ZERO
275
+ */
276
+ NUM_ZERO: 96,
277
+ /**
278
+ * NUM_ONE
279
+ */
280
+ NUM_ONE: 97,
281
+ /**
282
+ * NUM_TWO
283
+ */
284
+ NUM_TWO: 98,
285
+ /**
286
+ * NUM_THREE
287
+ */
288
+ NUM_THREE: 99,
289
+ /**
290
+ * NUM_FOUR
291
+ */
292
+ NUM_FOUR: 100,
293
+ /**
294
+ * NUM_FIVE
295
+ */
296
+ NUM_FIVE: 101,
297
+ /**
298
+ * NUM_SIX
299
+ */
300
+ NUM_SIX: 102,
301
+ /**
302
+ * NUM_SEVEN
303
+ */
304
+ NUM_SEVEN: 103,
305
+ /**
306
+ * NUM_EIGHT
307
+ */
308
+ NUM_EIGHT: 104,
309
+ /**
310
+ * NUM_NINE
311
+ */
312
+ NUM_NINE: 105,
313
+ /**
314
+ * NUM_MULTIPLY
315
+ */
316
+ NUM_MULTIPLY: 106,
317
+ /**
318
+ * NUM_PLUS
319
+ */
320
+ NUM_PLUS: 107,
321
+ /**
322
+ * NUM_MINUS
323
+ */
324
+ NUM_MINUS: 109,
325
+ /**
326
+ * NUM_PERIOD
327
+ */
328
+ NUM_PERIOD: 110,
329
+ /**
330
+ * NUM_DIVISION
331
+ */
332
+ NUM_DIVISION: 111,
333
+ /**
334
+ * F1
335
+ */
336
+ F1: 112,
337
+ /**
338
+ * F2
339
+ */
340
+ F2: 113,
341
+ /**
342
+ * F3
343
+ */
344
+ F3: 114,
345
+ /**
346
+ * F4
347
+ */
348
+ F4: 115,
349
+ /**
350
+ * F5
351
+ */
352
+ F5: 116,
353
+ /**
354
+ * F6
355
+ */
356
+ F6: 117,
357
+ /**
358
+ * F7
359
+ */
360
+ F7: 118,
361
+ /**
362
+ * F8
363
+ */
364
+ F8: 119,
365
+ /**
366
+ * F9
367
+ */
368
+ F9: 120,
369
+ /**
370
+ * F10
371
+ */
372
+ F10: 121,
373
+ /**
374
+ * F11
375
+ */
376
+ F11: 122,
377
+ /**
378
+ * F12
379
+ */
380
+ F12: 123,
381
+ /**
382
+ * NUMLOCK
383
+ */
384
+ NUMLOCK: 144,
385
+ /**
386
+ * SEMICOLON
387
+ */
388
+ SEMICOLON: 186,
389
+ // needs localization
390
+ /**
391
+ * DASH
392
+ */
393
+ DASH: 189,
394
+ // needs localization
395
+ /**
396
+ * EQUALS
397
+ */
398
+ EQUALS: 187,
399
+ // needs localization
400
+ /**
401
+ * COMMA
402
+ */
403
+ COMMA: 188,
404
+ // needs localization
405
+ /**
406
+ * PERIOD
407
+ */
408
+ PERIOD: 190,
409
+ // needs localization
410
+ /**
411
+ * SLASH
412
+ */
413
+ SLASH: 191,
414
+ // needs localization
415
+ /**
416
+ * APOSTROPHE
417
+ */
418
+ APOSTROPHE: 192,
419
+ // needs localization
420
+ /**
421
+ * SINGLE_QUOTE
422
+ */
423
+ SINGLE_QUOTE: 222,
424
+ // needs localization
425
+ /**
426
+ * OPEN_SQUARE_BRACKET
427
+ */
428
+ OPEN_SQUARE_BRACKET: 219,
429
+ // needs localization
430
+ /**
431
+ * BACKSLASH
432
+ */
433
+ BACKSLASH: 220,
434
+ // needs localization
435
+ /**
436
+ * CLOSE_SQUARE_BRACKET
437
+ */
438
+ CLOSE_SQUARE_BRACKET: 221,
439
+ // needs localization
440
+ /**
441
+ * WIN_KEY
442
+ */
443
+ WIN_KEY: 224,
444
+ /**
445
+ * MAC_FF_META
446
+ */
447
+ MAC_FF_META: 224,
448
+ // Firefox (Gecko) fires this for the meta key instead of 91
449
+ /**
450
+ * WIN_IME
451
+ */
452
+ WIN_IME: 229,
453
+ // ======================== Function ========================
454
+ /**
455
+ * whether text and modified key is entered at the same time.
456
+ */
457
+ isTextModifyingKeyEvent: function isTextModifyingKeyEvent(e) {
458
+ var keyCode = e.keyCode;
459
+ if (e.altKey && !e.ctrlKey || e.metaKey ||
460
+ // Function keys don't generate text
461
+ keyCode >= KeyCode.F1 && keyCode <= KeyCode.F12) {
462
+ return false;
463
+ }
464
+
465
+ // The following keys are quite harmless, even in combination with
466
+ // CTRL, ALT or SHIFT.
467
+ switch (keyCode) {
468
+ case KeyCode.ALT:
469
+ case KeyCode.CAPS_LOCK:
470
+ case KeyCode.CONTEXT_MENU:
471
+ case KeyCode.CTRL:
472
+ case KeyCode.DOWN:
473
+ case KeyCode.END:
474
+ case KeyCode.ESC:
475
+ case KeyCode.HOME:
476
+ case KeyCode.INSERT:
477
+ case KeyCode.LEFT:
478
+ case KeyCode.MAC_FF_META:
479
+ case KeyCode.META:
480
+ case KeyCode.NUMLOCK:
481
+ case KeyCode.NUM_CENTER:
482
+ case KeyCode.PAGE_DOWN:
483
+ case KeyCode.PAGE_UP:
484
+ case KeyCode.PAUSE:
485
+ case KeyCode.PRINT_SCREEN:
486
+ case KeyCode.RIGHT:
487
+ case KeyCode.SHIFT:
488
+ case KeyCode.UP:
489
+ case KeyCode.WIN_KEY:
490
+ case KeyCode.WIN_KEY_RIGHT:
491
+ return false;
492
+ default:
493
+ return true;
494
+ }
495
+ },
496
+ /**
497
+ * whether character is entered.
498
+ */
499
+ isCharacterKey: function isCharacterKey(keyCode) {
500
+ if (keyCode >= KeyCode.ZERO && keyCode <= KeyCode.NINE) {
501
+ return true;
502
+ }
503
+ if (keyCode >= KeyCode.NUM_ZERO && keyCode <= KeyCode.NUM_MULTIPLY) {
504
+ return true;
505
+ }
506
+ if (keyCode >= KeyCode.A && keyCode <= KeyCode.Z) {
507
+ return true;
508
+ }
509
+
510
+ // Safari sends zero key code for non-latin characters.
511
+ if (window.navigator.userAgent.indexOf('WebKit') !== -1 && keyCode === 0) {
512
+ return true;
513
+ }
514
+ switch (keyCode) {
515
+ case KeyCode.SPACE:
516
+ case KeyCode.QUESTION_MARK:
517
+ case KeyCode.NUM_PLUS:
518
+ case KeyCode.NUM_MINUS:
519
+ case KeyCode.NUM_PERIOD:
520
+ case KeyCode.NUM_DIVISION:
521
+ case KeyCode.SEMICOLON:
522
+ case KeyCode.DASH:
523
+ case KeyCode.EQUALS:
524
+ case KeyCode.COMMA:
525
+ case KeyCode.PERIOD:
526
+ case KeyCode.SLASH:
527
+ case KeyCode.APOSTROPHE:
528
+ case KeyCode.SINGLE_QUOTE:
529
+ case KeyCode.OPEN_SQUARE_BRACKET:
530
+ case KeyCode.BACKSLASH:
531
+ case KeyCode.CLOSE_SQUARE_BRACKET:
532
+ return true;
533
+ default:
534
+ return false;
535
+ }
536
+ }
537
+ };
538
+ export default KeyCode;
package/es/Portal.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type * as React from 'react';
2
+ export type PortalRef = {};
3
+ export interface PortalProps {
4
+ didUpdate?: (prevProps: PortalProps) => void;
5
+ getContainer: () => HTMLElement;
6
+ children?: React.ReactNode;
7
+ }
8
+ declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<PortalRef>>;
9
+ export default Portal;
package/es/Portal.js ADDED
@@ -0,0 +1,44 @@
1
+ import { useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import canUseDom from "./Dom/canUseDom";
4
+ var Portal = /*#__PURE__*/forwardRef(function (props, ref) {
5
+ var didUpdate = props.didUpdate,
6
+ getContainer = props.getContainer,
7
+ children = props.children;
8
+ var parentRef = useRef();
9
+ var containerRef = useRef();
10
+
11
+ // Ref return nothing, only for wrapper check exist
12
+ useImperativeHandle(ref, function () {
13
+ return {};
14
+ });
15
+
16
+ // Create container in client side with sync to avoid useEffect not get ref
17
+ var initRef = useRef(false);
18
+ if (!initRef.current && canUseDom()) {
19
+ containerRef.current = getContainer();
20
+ parentRef.current = containerRef.current.parentNode;
21
+ initRef.current = true;
22
+ }
23
+
24
+ // [Legacy] Used by `rc-trigger`
25
+ useEffect(function () {
26
+ didUpdate === null || didUpdate === void 0 || didUpdate(props);
27
+ });
28
+ useEffect(function () {
29
+ // Restore container to original place
30
+ // React 18 StrictMode will unmount first and mount back for effect test:
31
+ // https://reactjs.org/blog/2022/03/29/react-v18.html#new-strict-mode-behaviors
32
+ if (containerRef.current.parentNode === null && parentRef.current !== null) {
33
+ parentRef.current.appendChild(containerRef.current);
34
+ }
35
+ return function () {
36
+ var _containerRef$current;
37
+ // [Legacy] This should not be handle by Portal but parent PortalWrapper instead.
38
+ // Since some component use `Portal` directly, we have to keep the logic here.
39
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 || (_containerRef$current = _containerRef$current.parentNode) === null || _containerRef$current === void 0 || _containerRef$current.removeChild(containerRef.current);
40
+ };
41
+ }, []);
42
+ return containerRef.current ? /*#__PURE__*/ReactDOM.createPortal(children, containerRef.current) : null;
43
+ });
44
+ export default Portal;
@@ -0,0 +1,51 @@
1
+ import * as React from 'react';
2
+ import type { PortalRef } from './Portal';
3
+ import ScrollLocker from './Dom/scrollLocker';
4
+ /** @private Test usage only */
5
+ export declare function getOpenCount(): number;
6
+ export type GetContainer = string | HTMLElement | (() => HTMLElement);
7
+ export interface PortalWrapperProps {
8
+ visible?: boolean;
9
+ getContainer?: GetContainer;
10
+ wrapperClassName?: string;
11
+ forceRender?: boolean;
12
+ children: (info: {
13
+ getOpenCount: () => number;
14
+ getContainer: () => HTMLElement;
15
+ switchScrollingEffect: () => void;
16
+ scrollLocker: ScrollLocker;
17
+ ref?: (c: any) => void;
18
+ }) => React.ReactNode;
19
+ }
20
+ declare class PortalWrapper extends React.Component<PortalWrapperProps> {
21
+ container?: HTMLElement;
22
+ componentRef: React.RefObject<PortalRef>;
23
+ rafId?: number;
24
+ scrollLocker: ScrollLocker;
25
+ constructor(props: PortalWrapperProps);
26
+ renderComponent?: (info: {
27
+ afterClose: (...params: any[]) => void;
28
+ onClose: (...params: any[]) => void;
29
+ visible: boolean;
30
+ }) => void;
31
+ componentDidMount(): void;
32
+ componentDidUpdate(prevProps: PortalWrapperProps): void;
33
+ updateScrollLocker: (prevProps?: Partial<PortalWrapperProps>) => void;
34
+ updateOpenCount: (prevProps?: Partial<PortalWrapperProps>) => void;
35
+ componentWillUnmount(): void;
36
+ attachToParent: (force?: boolean) => boolean;
37
+ getContainer: () => HTMLElement;
38
+ setWrapperClassName: () => void;
39
+ removeCurrentContainer: () => void;
40
+ /**
41
+ * Enhance ./switchScrollingEffect
42
+ * 1. Simulate document body scroll bar with
43
+ * 2. Record body has overflow style and recover when all of PortalWrapper invisible
44
+ * 3. Disable body scroll when PortalWrapper has open
45
+ *
46
+ * @memberof PortalWrapper
47
+ */
48
+ switchScrollingEffect: () => void;
49
+ render(): any;
50
+ }
51
+ export default PortalWrapper;