@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.
- package/LICENSE +22 -0
- package/README.md +303 -0
- package/es/Children/toArray.d.ts +5 -0
- package/es/Children/toArray.js +19 -0
- package/es/Dom/canUseDom.d.ts +1 -0
- package/es/Dom/canUseDom.js +3 -0
- package/es/Dom/contains.d.ts +1 -0
- package/es/Dom/contains.js +20 -0
- package/es/Dom/dynamicCSS.d.ts +25 -0
- package/es/Dom/dynamicCSS.js +153 -0
- package/es/Dom/findDOMNode.d.ts +12 -0
- package/es/Dom/findDOMNode.js +36 -0
- package/es/Dom/focus.d.ts +8 -0
- package/es/Dom/focus.js +87 -0
- package/es/Dom/isVisible.d.ts +2 -0
- package/es/Dom/isVisible.js +27 -0
- package/es/Dom/scrollLocker.d.ts +12 -0
- package/es/Dom/scrollLocker.js +135 -0
- package/es/Dom/shadow.d.ts +8 -0
- package/es/Dom/shadow.js +18 -0
- package/es/Dom/styleChecker.d.ts +2 -0
- package/es/Dom/styleChecker.js +26 -0
- package/es/KeyCode.d.ts +436 -0
- package/es/KeyCode.js +538 -0
- package/es/Portal.d.ts +9 -0
- package/es/Portal.js +44 -0
- package/es/PortalWrapper.d.ts +51 -0
- package/es/PortalWrapper.js +217 -0
- package/es/React/isFragment.d.ts +4 -0
- package/es/React/isFragment.js +18 -0
- package/es/React/render.d.ts +13 -0
- package/es/React/render.js +114 -0
- package/es/composeProps.d.ts +2 -0
- package/es/composeProps.js +24 -0
- package/es/getScrollBarSize.d.ts +7 -0
- package/es/getScrollBarSize.js +76 -0
- package/es/hooks/useEffect.d.ts +2 -0
- package/es/hooks/useEffect.js +14 -0
- package/es/hooks/useEvent.d.ts +2 -0
- package/es/hooks/useEvent.js +16 -0
- package/es/hooks/useId.d.ts +4 -0
- package/es/hooks/useId.js +69 -0
- package/es/hooks/useLayoutEffect.d.ts +4 -0
- package/es/hooks/useLayoutEffect.js +30 -0
- package/es/hooks/useMemo.d.ts +1 -0
- package/es/hooks/useMemo.js +9 -0
- package/es/hooks/useMergedState.d.ts +12 -0
- package/es/hooks/useMergedState.js +68 -0
- package/es/hooks/useMobile.d.ts +6 -0
- package/es/hooks/useMobile.js +25 -0
- package/es/hooks/useState.d.ts +14 -0
- package/es/hooks/useState.js +32 -0
- package/es/hooks/useSyncState.d.ts +9 -0
- package/es/hooks/useSyncState.js +29 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/isEqual.d.ts +9 -0
- package/es/isEqual.js +55 -0
- package/es/isMobile.d.ts +2 -0
- package/es/isMobile.js +7 -0
- package/es/omit.d.ts +1 -0
- package/es/omit.js +9 -0
- package/es/pickAttrs.d.ts +11 -0
- package/es/pickAttrs.js +51 -0
- package/es/proxyObject.d.ts +4 -0
- package/es/proxyObject.js +19 -0
- package/es/raf.d.ts +6 -0
- package/es/raf.js +54 -0
- package/es/ref.d.ts +19 -0
- package/es/ref.js +89 -0
- package/es/setStyle.d.ts +12 -0
- package/es/setStyle.js +26 -0
- package/es/test/domHook.d.ts +8 -0
- package/es/test/domHook.js +64 -0
- package/es/utils/get.d.ts +1 -0
- package/es/utils/get.js +10 -0
- package/es/utils/set.d.ts +6 -0
- package/es/utils/set.js +93 -0
- package/es/warning.d.ts +32 -0
- package/es/warning.js +68 -0
- package/lib/Children/toArray.d.ts +5 -0
- package/lib/Children/toArray.js +26 -0
- package/lib/Dom/canUseDom.d.ts +1 -0
- package/lib/Dom/canUseDom.js +9 -0
- package/lib/Dom/contains.d.ts +1 -0
- package/lib/Dom/contains.js +26 -0
- package/lib/Dom/dynamicCSS.d.ts +25 -0
- package/lib/Dom/dynamicCSS.js +163 -0
- package/lib/Dom/findDOMNode.d.ts +12 -0
- package/lib/Dom/findDOMNode.js +45 -0
- package/lib/Dom/focus.d.ts +8 -0
- package/lib/Dom/focus.js +98 -0
- package/lib/Dom/isVisible.d.ts +2 -0
- package/lib/Dom/isVisible.js +33 -0
- package/lib/Dom/scrollLocker.d.ts +12 -0
- package/lib/Dom/scrollLocker.js +141 -0
- package/lib/Dom/shadow.d.ts +8 -0
- package/lib/Dom/shadow.js +25 -0
- package/lib/Dom/styleChecker.d.ts +2 -0
- package/lib/Dom/styleChecker.js +33 -0
- package/lib/KeyCode.d.ts +436 -0
- package/lib/KeyCode.js +544 -0
- package/lib/Portal.d.ts +9 -0
- package/lib/Portal.js +51 -0
- package/lib/PortalWrapper.d.ts +51 -0
- package/lib/PortalWrapper.js +226 -0
- package/lib/React/isFragment.d.ts +4 -0
- package/lib/React/isFragment.js +24 -0
- package/lib/React/render.d.ts +13 -0
- package/lib/React/render.js +125 -0
- package/lib/composeProps.d.ts +2 -0
- package/lib/composeProps.js +30 -0
- package/lib/getScrollBarSize.d.ts +7 -0
- package/lib/getScrollBarSize.js +84 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +22 -0
- package/lib/hooks/useEvent.d.ts +2 -0
- package/lib/hooks/useEvent.js +26 -0
- package/lib/hooks/useId.d.ts +4 -0
- package/lib/hooks/useId.js +78 -0
- package/lib/hooks/useLayoutEffect.d.ts +4 -0
- package/lib/hooks/useLayoutEffect.js +39 -0
- package/lib/hooks/useMemo.d.ts +1 -0
- package/lib/hooks/useMemo.js +18 -0
- package/lib/hooks/useMergedState.d.ts +12 -0
- package/lib/hooks/useMergedState.js +75 -0
- package/lib/hooks/useMobile.d.ts +6 -0
- package/lib/hooks/useMobile.js +31 -0
- package/lib/hooks/useState.d.ts +14 -0
- package/lib/hooks/useState.js +41 -0
- package/lib/hooks/useSyncState.d.ts +9 -0
- package/lib/hooks/useSyncState.js +39 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +60 -0
- package/lib/isEqual.d.ts +9 -0
- package/lib/isEqual.js +61 -0
- package/lib/isMobile.d.ts +2 -0
- package/lib/isMobile.js +13 -0
- package/lib/omit.d.ts +1 -0
- package/lib/omit.js +15 -0
- package/lib/pickAttrs.d.ts +11 -0
- package/lib/pickAttrs.js +57 -0
- package/lib/proxyObject.d.ts +4 -0
- package/lib/proxyObject.js +25 -0
- package/lib/raf.d.ts +6 -0
- package/lib/raf.js +60 -0
- package/lib/ref.d.ts +19 -0
- package/lib/ref.js +96 -0
- package/lib/setStyle.d.ts +12 -0
- package/lib/setStyle.js +32 -0
- package/lib/test/domHook.d.ts +8 -0
- package/lib/test/domHook.js +71 -0
- package/lib/utils/get.d.ts +1 -0
- package/lib/utils/get.js +16 -0
- package/lib/utils/set.d.ts +6 -0
- package/lib/utils/set.js +101 -0
- package/lib/warning.d.ts +32 -0
- package/lib/warning.js +81 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-present yiminghe
|
|
4
|
+
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# rc-util
|
|
2
|
+
|
|
3
|
+
Common Utils For React Component.
|
|
4
|
+
|
|
5
|
+
[![NPM version][npm-image]][npm-url]
|
|
6
|
+
[![npm download][download-image]][download-url]
|
|
7
|
+
[![build status][github-actions-image]][github-actions-url]
|
|
8
|
+
[![Codecov][codecov-image]][codecov-url]
|
|
9
|
+
[![bundle size][bundlephobia-image]][bundlephobia-url]
|
|
10
|
+
[![dumi][dumi-image]][dumi-url]
|
|
11
|
+
|
|
12
|
+
[npm-image]: http://img.shields.io/npm/v/rc-util.svg?style=flat-square
|
|
13
|
+
[npm-url]: http://npmjs.org/package/rc-util
|
|
14
|
+
[travis-image]: https://img.shields.io/travis/react-component/util/master?style=flat-square
|
|
15
|
+
[travis-url]: https://travis-ci.com/react-component/util
|
|
16
|
+
[github-actions-image]: https://github.com/react-component/util/workflows/CI/badge.svg
|
|
17
|
+
[github-actions-url]: https://github.com/react-component/util/actions
|
|
18
|
+
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/util/master.svg?style=flat-square
|
|
19
|
+
[codecov-url]: https://app.codecov.io/gh/react-component/util
|
|
20
|
+
[david-url]: https://david-dm.org/react-component/util
|
|
21
|
+
[david-image]: https://david-dm.org/react-component/util/status.svg?style=flat-square
|
|
22
|
+
[david-dev-url]: https://david-dm.org/react-component/util?type=dev
|
|
23
|
+
[david-dev-image]: https://david-dm.org/react-component/util/dev-status.svg?style=flat-square
|
|
24
|
+
[download-image]: https://img.shields.io/npm/dm/rc-util.svg?style=flat-square
|
|
25
|
+
[download-url]: https://npmjs.org/package/rc-util
|
|
26
|
+
[bundlephobia-url]: https://bundlephobia.com/package/rc-util
|
|
27
|
+
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-util
|
|
28
|
+
[dumi-url]: https://github.com/umijs/dumi
|
|
29
|
+
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
[](https://npmjs.org/package/rc-util)
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### createChainedFunction
|
|
38
|
+
|
|
39
|
+
> (...functions): Function
|
|
40
|
+
|
|
41
|
+
Create a function which will call all the functions with it's arguments from left to right.
|
|
42
|
+
|
|
43
|
+
```jsx|pure
|
|
44
|
+
import createChainedFunction from 'rc-util/lib/createChainedFunction';
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### deprecated
|
|
48
|
+
|
|
49
|
+
> (prop: string, instead: string, component: string): void
|
|
50
|
+
|
|
51
|
+
Log an error message to warn developers that `prop` is deprecated.
|
|
52
|
+
|
|
53
|
+
```jsx|pure
|
|
54
|
+
import deprecated from 'rc-util/lib/deprecated';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### getContainerRenderMixin
|
|
58
|
+
|
|
59
|
+
> (config: Object): Object
|
|
60
|
+
|
|
61
|
+
To generate a mixin which will render specific component into specific container automatically.
|
|
62
|
+
|
|
63
|
+
```jsx|pure
|
|
64
|
+
import getContainerRenderMixin from 'rc-util/lib/getContainerRenderMixin';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Fields in `config` and their meanings.
|
|
68
|
+
|
|
69
|
+
| Field | Type | Description | Default |
|
|
70
|
+
| ------------- | ---------------------------- | -------------------------------------------------------------------------- | ------- |
|
|
71
|
+
| autoMount | boolean | Whether to render component into container automatically | true |
|
|
72
|
+
| autoDestroy | boolean | Whether to remove container automatically while the component is unmounted | true |
|
|
73
|
+
| isVisible | (instance): boolean | A function to get current visibility of the component | - |
|
|
74
|
+
| isForceRender | (instance): boolean | A function to determine whether to render popup even it's not visible | - |
|
|
75
|
+
| getComponent | (instance, extra): ReactNode | A function to get the component which will be rendered into container | - |
|
|
76
|
+
| getContainer | (instance): HTMLElement | A function to get the container | |
|
|
77
|
+
|
|
78
|
+
### Portal
|
|
79
|
+
|
|
80
|
+
Render children to the specific container;
|
|
81
|
+
|
|
82
|
+
```jsx|pure
|
|
83
|
+
import Portal from 'rc-util/lib/Portal';
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Props:
|
|
87
|
+
|
|
88
|
+
| Prop | Type | Description | Default |
|
|
89
|
+
| ------------ | --------------- | ------------------------------- | ------- |
|
|
90
|
+
| children | ReactChildren | Content render to the container | - |
|
|
91
|
+
| getContainer | (): HTMLElement | A function to get the container | - |
|
|
92
|
+
|
|
93
|
+
### getScrollBarSize
|
|
94
|
+
|
|
95
|
+
> (fresh?: boolean): number
|
|
96
|
+
|
|
97
|
+
Get the width of scrollbar.
|
|
98
|
+
|
|
99
|
+
```jsx|pure
|
|
100
|
+
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### guid
|
|
104
|
+
|
|
105
|
+
> (): string
|
|
106
|
+
|
|
107
|
+
To generate a global unique id across current application.
|
|
108
|
+
|
|
109
|
+
```jsx|pure
|
|
110
|
+
import guid from 'rc-util/lib/guid';
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### pickAttrs
|
|
114
|
+
|
|
115
|
+
> (props: Object): Object
|
|
116
|
+
|
|
117
|
+
Pick valid HTML attributes and events from props.
|
|
118
|
+
|
|
119
|
+
```jsx|pure
|
|
120
|
+
import pickAttrs from 'rc-util/lib/pickAttrs';
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### warn
|
|
124
|
+
|
|
125
|
+
> (msg: string): void
|
|
126
|
+
|
|
127
|
+
A shallow wrapper of `console.warn`.
|
|
128
|
+
|
|
129
|
+
```jsx|pure
|
|
130
|
+
import warn from 'rc-util/lib/warn';
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### warning
|
|
134
|
+
|
|
135
|
+
> (valid: boolean, msg: string): void
|
|
136
|
+
|
|
137
|
+
A shallow wrapper of [warning](https://github.com/BerkeleyTrue/warning), but only warning once for the same message.
|
|
138
|
+
|
|
139
|
+
```jsx|pure
|
|
140
|
+
import warning, { noteOnce } from 'rc-util/lib/warning';
|
|
141
|
+
|
|
142
|
+
warning(false, '[antd Component] test hello world');
|
|
143
|
+
|
|
144
|
+
// Low level note
|
|
145
|
+
noteOnce(false, '[antd Component] test hello world');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Children
|
|
149
|
+
|
|
150
|
+
A collection of functions to operate React elements' children.
|
|
151
|
+
|
|
152
|
+
#### Children/mapSelf
|
|
153
|
+
|
|
154
|
+
> (children): children
|
|
155
|
+
|
|
156
|
+
Return a shallow copy of children.
|
|
157
|
+
|
|
158
|
+
```jsx|pure
|
|
159
|
+
import mapSelf from 'rc-util/lib/Children/mapSelf';
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Children/toArray
|
|
163
|
+
|
|
164
|
+
> (children: ReactNode[]): ReactNode[]
|
|
165
|
+
|
|
166
|
+
Convert children into an array.
|
|
167
|
+
|
|
168
|
+
```jsx|pure
|
|
169
|
+
import toArray from 'rc-util/lib/Children/toArray';
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Dom
|
|
173
|
+
|
|
174
|
+
A collection of functions to operate DOM elements.
|
|
175
|
+
|
|
176
|
+
#### Dom/addEventlistener
|
|
177
|
+
|
|
178
|
+
> (target: ReactNode, eventType: string, listener: Function): { remove: Function }
|
|
179
|
+
|
|
180
|
+
A shallow wrapper of [add-dom-event-listener](https://github.com/yiminghe/add-dom-event-listener).
|
|
181
|
+
|
|
182
|
+
```jsx|pure
|
|
183
|
+
import addEventlistener from 'rc-util/lib/Dom/addEventlistener';
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Dom/canUseDom
|
|
187
|
+
|
|
188
|
+
> (): boolean
|
|
189
|
+
|
|
190
|
+
Check if DOM is available.
|
|
191
|
+
|
|
192
|
+
```jsx|pure
|
|
193
|
+
import canUseDom from 'rc-util/lib/Dom/canUseDom';
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Dom/class
|
|
197
|
+
|
|
198
|
+
A collection of functions to operate DOM nodes' class name.
|
|
199
|
+
|
|
200
|
+
- `hasClass(node: HTMLElement, className: string): boolean`
|
|
201
|
+
- `addClass(node: HTMLElement, className: string): void`
|
|
202
|
+
- `removeClass(node: HTMLElement, className: string): void`
|
|
203
|
+
|
|
204
|
+
```jsx|pure
|
|
205
|
+
import cssClass from 'rc-util/lib/Dom/class;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Dom/contains
|
|
209
|
+
|
|
210
|
+
> (root: HTMLElement, node: HTMLElement): boolean
|
|
211
|
+
|
|
212
|
+
Check if node is equal to root or in the subtree of root.
|
|
213
|
+
|
|
214
|
+
```jsx|pure
|
|
215
|
+
import contains from 'rc-util/lib/Dom/contains';
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Dom/css
|
|
219
|
+
|
|
220
|
+
A collection of functions to get or set css styles.
|
|
221
|
+
|
|
222
|
+
- `get(node: HTMLElement, name?: string): any`
|
|
223
|
+
- `set(node: HTMLElement, name?: string, value: any) | set(node, object)`
|
|
224
|
+
- `getOuterWidth(el: HTMLElement): number`
|
|
225
|
+
- `getOuterHeight(el: HTMLElement): number`
|
|
226
|
+
- `getDocSize(): { width: number, height: number }`
|
|
227
|
+
- `getClientSize(): { width: number, height: number }`
|
|
228
|
+
- `getScroll(): { scrollLeft: number, scrollTop: number }`
|
|
229
|
+
- `getOffset(node: HTMLElement): { left: number, top: number }`
|
|
230
|
+
|
|
231
|
+
```jsx|pure
|
|
232
|
+
import css from 'rc-util/lib/Dom/css';
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Dom/focus
|
|
236
|
+
|
|
237
|
+
A collection of functions to operate focus status of DOM node.
|
|
238
|
+
|
|
239
|
+
- `saveLastFocusNode(): void`
|
|
240
|
+
- `clearLastFocusNode(): void`
|
|
241
|
+
- `backLastFocusNode(): void`
|
|
242
|
+
- `getFocusNodeList(node: HTMLElement): HTMLElement[]` get a list of focusable nodes from the subtree of node.
|
|
243
|
+
- `limitTabRange(node: HTMLElement, e: Event): void`
|
|
244
|
+
|
|
245
|
+
```jsx|pure
|
|
246
|
+
import focus from 'rc-util/lib/Dom/focus';
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Dom/support
|
|
250
|
+
|
|
251
|
+
> { animation: boolean | Object, transition: boolean | Object }
|
|
252
|
+
|
|
253
|
+
A flag to tell whether current environment supports `animationend` or `transitionend`.
|
|
254
|
+
|
|
255
|
+
```jsx|pure
|
|
256
|
+
import support from 'rc-util/lib/Dom/support';
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### KeyCode
|
|
260
|
+
|
|
261
|
+
> Enum
|
|
262
|
+
|
|
263
|
+
Enum of KeyCode, please check the [definition](https://github.com/react-component/util/blob/master/src/KeyCode.ts) of it.
|
|
264
|
+
|
|
265
|
+
```jsx|pure
|
|
266
|
+
import KeyCode from 'rc-util/lib/KeyCode';
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### KeyCode.isTextModifyingKeyEvent
|
|
270
|
+
|
|
271
|
+
> (e: Event): boolean
|
|
272
|
+
|
|
273
|
+
Whether text and modified key is entered at the same time.
|
|
274
|
+
|
|
275
|
+
#### KeyCode.isCharacterKey
|
|
276
|
+
|
|
277
|
+
> (keyCode: KeyCode): boolean
|
|
278
|
+
|
|
279
|
+
Whether character is entered.
|
|
280
|
+
|
|
281
|
+
### ScrollLocker
|
|
282
|
+
|
|
283
|
+
> ScrollLocker<{lock: (options: {container: HTMLElement}) => void, unLock: () => void}>
|
|
284
|
+
|
|
285
|
+
improve shake when page scroll bar hidden.
|
|
286
|
+
|
|
287
|
+
`ScrollLocker` change body style, and add a class `ant-scrolling-effect` when called, so if you page look abnormal, please check this;
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
import ScrollLocker from 'rc-util/lib/Dom/scrollLocker';
|
|
291
|
+
|
|
292
|
+
const scrollLocker = new ScrollLocker();
|
|
293
|
+
|
|
294
|
+
// lock
|
|
295
|
+
scrollLocker.lock()
|
|
296
|
+
|
|
297
|
+
// unLock
|
|
298
|
+
scrollLocker.unLock()
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
[MIT](/LICENSE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import isFragment from "../React/isFragment";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export default function toArray(children) {
|
|
4
|
+
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5
|
+
var ret = [];
|
|
6
|
+
React.Children.forEach(children, function (child) {
|
|
7
|
+
if ((child === undefined || child === null) && !option.keepEmpty) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(child)) {
|
|
11
|
+
ret = ret.concat(toArray(child));
|
|
12
|
+
} else if (isFragment(child) && child.props) {
|
|
13
|
+
ret = ret.concat(toArray(child.props.children, option));
|
|
14
|
+
} else {
|
|
15
|
+
ret.push(child);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return ret;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function canUseDom(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function contains(root: Node | null | undefined, n?: Node): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default function contains(root, n) {
|
|
2
|
+
if (!root) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Use native if support
|
|
7
|
+
if (root.contains) {
|
|
8
|
+
return root.contains(n);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// `document.contains` not support with IE11
|
|
12
|
+
var node = n;
|
|
13
|
+
while (node) {
|
|
14
|
+
if (node === root) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
node = node.parentNode;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type ContainerType = Element | ShadowRoot;
|
|
2
|
+
export type Prepend = boolean | 'queue';
|
|
3
|
+
export type AppendType = 'prependQueue' | 'append' | 'prepend';
|
|
4
|
+
interface Options {
|
|
5
|
+
attachTo?: ContainerType;
|
|
6
|
+
csp?: {
|
|
7
|
+
nonce?: string;
|
|
8
|
+
};
|
|
9
|
+
prepend?: Prepend;
|
|
10
|
+
/**
|
|
11
|
+
* Config the `priority` of `prependQueue`. Default is `0`.
|
|
12
|
+
* It's useful if you need to insert style before other style.
|
|
13
|
+
*/
|
|
14
|
+
priority?: number;
|
|
15
|
+
mark?: string;
|
|
16
|
+
styles?: HTMLElement[];
|
|
17
|
+
}
|
|
18
|
+
export declare function injectCSS(css: string, option?: Options): HTMLStyleElement;
|
|
19
|
+
export declare function removeCSS(key: string, option?: Options): void;
|
|
20
|
+
/**
|
|
21
|
+
* manually clear container cache to avoid global cache in unit testes
|
|
22
|
+
*/
|
|
23
|
+
export declare function clearContainerCache(): void;
|
|
24
|
+
export declare function updateCSS(css: string, key: string, originOption?: Options): HTMLElement;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
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 canUseDom from "./canUseDom";
|
|
8
|
+
import contains from "./contains";
|
|
9
|
+
var APPEND_ORDER = 'data-rc-order';
|
|
10
|
+
var APPEND_PRIORITY = 'data-rc-priority';
|
|
11
|
+
var MARK_KEY = "rc-util-key";
|
|
12
|
+
var containerCache = new Map();
|
|
13
|
+
function getMark() {
|
|
14
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
15
|
+
mark = _ref.mark;
|
|
16
|
+
if (mark) {
|
|
17
|
+
return mark.startsWith('data-') ? mark : "data-".concat(mark);
|
|
18
|
+
}
|
|
19
|
+
return MARK_KEY;
|
|
20
|
+
}
|
|
21
|
+
function getContainer(option) {
|
|
22
|
+
if (option.attachTo) {
|
|
23
|
+
return option.attachTo;
|
|
24
|
+
}
|
|
25
|
+
var head = document.querySelector('head');
|
|
26
|
+
return head || document.body;
|
|
27
|
+
}
|
|
28
|
+
function getOrder(prepend) {
|
|
29
|
+
if (prepend === 'queue') {
|
|
30
|
+
return 'prependQueue';
|
|
31
|
+
}
|
|
32
|
+
return prepend ? 'prepend' : 'append';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Find style which inject by rc-util
|
|
37
|
+
*/
|
|
38
|
+
function findStyles(container) {
|
|
39
|
+
return Array.from((containerCache.get(container) || container).children).filter(function (node) {
|
|
40
|
+
return node.tagName === 'STYLE';
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function injectCSS(css) {
|
|
44
|
+
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
45
|
+
if (!canUseDom()) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var csp = option.csp,
|
|
49
|
+
prepend = option.prepend,
|
|
50
|
+
_option$priority = option.priority,
|
|
51
|
+
priority = _option$priority === void 0 ? 0 : _option$priority;
|
|
52
|
+
var mergedOrder = getOrder(prepend);
|
|
53
|
+
var isPrependQueue = mergedOrder === 'prependQueue';
|
|
54
|
+
var styleNode = document.createElement('style');
|
|
55
|
+
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
56
|
+
if (isPrependQueue && priority) {
|
|
57
|
+
styleNode.setAttribute(APPEND_PRIORITY, "".concat(priority));
|
|
58
|
+
}
|
|
59
|
+
if (csp !== null && csp !== void 0 && csp.nonce) {
|
|
60
|
+
styleNode.nonce = csp === null || csp === void 0 ? void 0 : csp.nonce;
|
|
61
|
+
}
|
|
62
|
+
styleNode.innerHTML = css;
|
|
63
|
+
var container = getContainer(option);
|
|
64
|
+
var firstChild = container.firstChild;
|
|
65
|
+
if (prepend) {
|
|
66
|
+
// If is queue `prepend`, it will prepend first style and then append rest style
|
|
67
|
+
if (isPrependQueue) {
|
|
68
|
+
var existStyle = (option.styles || findStyles(container)).filter(function (node) {
|
|
69
|
+
// Ignore style which not injected by rc-util with prepend
|
|
70
|
+
if (!['prepend', 'prependQueue'].includes(node.getAttribute(APPEND_ORDER))) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Ignore style which priority less then new style
|
|
75
|
+
var nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
76
|
+
return priority >= nodePriority;
|
|
77
|
+
});
|
|
78
|
+
if (existStyle.length) {
|
|
79
|
+
container.insertBefore(styleNode, existStyle[existStyle.length - 1].nextSibling);
|
|
80
|
+
return styleNode;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Use `insertBefore` as `prepend`
|
|
85
|
+
container.insertBefore(styleNode, firstChild);
|
|
86
|
+
} else {
|
|
87
|
+
container.appendChild(styleNode);
|
|
88
|
+
}
|
|
89
|
+
return styleNode;
|
|
90
|
+
}
|
|
91
|
+
function findExistNode(key) {
|
|
92
|
+
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
93
|
+
var container = getContainer(option);
|
|
94
|
+
return (option.styles || findStyles(container)).find(function (node) {
|
|
95
|
+
return node.getAttribute(getMark(option)) === key;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function removeCSS(key) {
|
|
99
|
+
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
100
|
+
var existNode = findExistNode(key, option);
|
|
101
|
+
if (existNode) {
|
|
102
|
+
var container = getContainer(option);
|
|
103
|
+
container.removeChild(existNode);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* qiankun will inject `appendChild` to insert into other
|
|
109
|
+
*/
|
|
110
|
+
function syncRealContainer(container, option) {
|
|
111
|
+
var cachedRealContainer = containerCache.get(container);
|
|
112
|
+
|
|
113
|
+
// Find real container when not cached or cached container removed
|
|
114
|
+
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
115
|
+
var placeholderStyle = injectCSS('', option);
|
|
116
|
+
var parentNode = placeholderStyle.parentNode;
|
|
117
|
+
containerCache.set(container, parentNode);
|
|
118
|
+
container.removeChild(placeholderStyle);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* manually clear container cache to avoid global cache in unit testes
|
|
124
|
+
*/
|
|
125
|
+
export function clearContainerCache() {
|
|
126
|
+
containerCache.clear();
|
|
127
|
+
}
|
|
128
|
+
export function updateCSS(css, key) {
|
|
129
|
+
var originOption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
130
|
+
var container = getContainer(originOption);
|
|
131
|
+
var styles = findStyles(container);
|
|
132
|
+
var option = _objectSpread(_objectSpread({}, originOption), {}, {
|
|
133
|
+
styles: styles
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Sync real parent
|
|
137
|
+
syncRealContainer(container, option);
|
|
138
|
+
var existNode = findExistNode(key, option);
|
|
139
|
+
if (existNode) {
|
|
140
|
+
var _option$csp, _option$csp2;
|
|
141
|
+
if ((_option$csp = option.csp) !== null && _option$csp !== void 0 && _option$csp.nonce && existNode.nonce !== ((_option$csp2 = option.csp) === null || _option$csp2 === void 0 ? void 0 : _option$csp2.nonce)) {
|
|
142
|
+
var _option$csp3;
|
|
143
|
+
existNode.nonce = (_option$csp3 = option.csp) === null || _option$csp3 === void 0 ? void 0 : _option$csp3.nonce;
|
|
144
|
+
}
|
|
145
|
+
if (existNode.innerHTML !== css) {
|
|
146
|
+
existNode.innerHTML = css;
|
|
147
|
+
}
|
|
148
|
+
return existNode;
|
|
149
|
+
}
|
|
150
|
+
var newNode = injectCSS(css, option);
|
|
151
|
+
newNode.setAttribute(getMark(option), key);
|
|
152
|
+
return newNode;
|
|
153
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function isDOM(node: any): node is HTMLElement | SVGElement;
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a DOM node via a ref, and does not invoke `findDOMNode`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getDOM(node: any): HTMLElement | SVGElement | null;
|
|
7
|
+
/**
|
|
8
|
+
* Return if a node is a DOM node. Else will return by `findDOMNode`
|
|
9
|
+
*/
|
|
10
|
+
export default function findDOMNode<T = Element | Text>(node: React.ReactInstance | HTMLElement | SVGElement | {
|
|
11
|
+
nativeElement: T;
|
|
12
|
+
}): T;
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
export function isDOM(node) {
|
|
5
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
6
|
+
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
|
|
7
|
+
return node instanceof HTMLElement || node instanceof SVGElement;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves a DOM node via a ref, and does not invoke `findDOMNode`.
|
|
12
|
+
*/
|
|
13
|
+
export function getDOM(node) {
|
|
14
|
+
if (node && _typeof(node) === 'object' && isDOM(node.nativeElement)) {
|
|
15
|
+
return node.nativeElement;
|
|
16
|
+
}
|
|
17
|
+
if (isDOM(node)) {
|
|
18
|
+
return node;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return if a node is a DOM node. Else will return by `findDOMNode`
|
|
25
|
+
*/
|
|
26
|
+
export default function findDOMNode(node) {
|
|
27
|
+
var domNode = getDOM(node);
|
|
28
|
+
if (domNode) {
|
|
29
|
+
return domNode;
|
|
30
|
+
}
|
|
31
|
+
if (node instanceof React.Component) {
|
|
32
|
+
var _ReactDOM$findDOMNode;
|
|
33
|
+
return (_ReactDOM$findDOMNode = ReactDOM.findDOMNode) === null || _ReactDOM$findDOMNode === void 0 ? void 0 : _ReactDOM$findDOMNode.call(ReactDOM, node);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function getFocusNodeList(node: HTMLElement, includePositive?: boolean): HTMLElement[];
|
|
2
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
3
|
+
export declare function saveLastFocusNode(): void;
|
|
4
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
5
|
+
export declare function clearLastFocusNode(): void;
|
|
6
|
+
/** @deprecated Do not use since this may failed when used in async */
|
|
7
|
+
export declare function backLastFocusNode(): void;
|
|
8
|
+
export declare function limitTabRange(node: HTMLElement, e: KeyboardEvent): void;
|