@ringcentral/spring-base 1.7.0 → 1.9.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/chunks/twMerge.js +0 -133
- package/config.js +0 -24
- package/contexts.js +0 -1
- package/hooks.js +61 -642
- package/index.js +3 -2
- package/package.json +1 -1
- package/src/config.d.ts +1 -26
- package/src/contexts/ResponsiveContext/breakpointList.d.ts +0 -1
- package/src/contexts/ResponsiveContext/types.d.ts +0 -11
- package/src/hooks/index.d.ts +2 -0
- package/src/hooks/useA11yKeyEvent/useA11yKeyEvent.d.ts +0 -17
- package/src/hooks/useActive/useActive.d.ts +4 -10
- package/src/hooks/useAnnouncer/useAnnouncer.d.ts +0 -10
- package/src/hooks/useAriaHideOutside/useAriaHideOutside.d.ts +0 -4
- package/src/hooks/useAudio/useAudio.d.ts +0 -20
- package/src/hooks/useBodyScrollLock/useBodyScrollLock.d.ts +0 -19
- package/src/hooks/useButton/index.d.ts +1 -0
- package/src/hooks/useButton/useButton.d.ts +2 -0
- package/src/hooks/useChange/useChange.d.ts +0 -10
- package/src/hooks/useClickAway/useClickAway.d.ts +0 -10
- package/src/hooks/useDebounce/useDebounce.d.ts +0 -6
- package/src/hooks/useEventListener/useEventListener.d.ts +0 -20
- package/src/hooks/useEver/useEver.d.ts +0 -12
- package/src/hooks/useFocusVisible/useFocusVisible.d.ts +0 -6
- package/src/hooks/useFontLoaded/useFontLoaded.d.ts +0 -12
- package/src/hooks/useForceUpdate/useForceUpdate.d.ts +0 -4
- package/src/hooks/useForkRef/useForkRef.d.ts +0 -17
- package/src/hooks/useGlobalListener/createGlobalListener.d.ts +0 -37
- package/src/hooks/useGlobalListener/useGlobalListener.d.ts +0 -5
- package/src/hooks/useHiddenTabindex/useHiddenTabindex.d.ts +0 -4
- package/src/hooks/useHover/useHover.d.ts +0 -3
- package/src/hooks/useId/useId.d.ts +0 -14
- package/src/hooks/useImgLoaded/useImgLoaded.d.ts +0 -14
- package/src/hooks/useInterval/useInterval.d.ts +0 -37
- package/src/hooks/useKeyDownOnce/useKeyDownOnce.d.ts +0 -6
- package/src/hooks/useKeyboardMoveFocus/moveIndexInTwoDimension.d.ts +0 -11
- package/src/hooks/useKeyboardMoveFocus/useKeyboardMoveFocus.d.ts +0 -33
- package/src/hooks/useKeyboardMoveFocus/useOnlyOneFocusable.d.ts +0 -6
- package/src/hooks/useLongPress/useLongPress.d.ts +0 -16
- package/src/hooks/useMountState/useMountState.d.ts +0 -14
- package/src/hooks/useOnLayoutReRender/useOnLayoutReRender.d.ts +0 -3
- package/src/hooks/useOnReRender/useOnReRender.d.ts +0 -3
- package/src/hooks/useOverflow/useOverflow.d.ts +0 -3
- package/src/hooks/usePrevious/usePrevious.d.ts +0 -6
- package/src/hooks/useRefState/useRefState.d.ts +0 -19
- package/src/hooks/useResizeObserver/useResizeObserver.d.ts +0 -15
- package/src/hooks/useResponsiveMatch/useResponsiveMatch.d.ts +0 -4
- package/src/hooks/useResultRef/useResultRef.d.ts +0 -8
- package/src/hooks/useRetry/useRetry.d.ts +2 -25
- package/src/hooks/useSleep/useSleep.d.ts +0 -17
- package/src/hooks/useTabOut/useTabOut.d.ts +0 -3
- package/src/hooks/useTestRunnerDetection.d.ts +0 -6
- package/src/hooks/useThrottle/useThrottle.d.ts +0 -6
- package/src/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +2 -41
- package/src/hooks/useVirtuosoExternalWindow/index.d.ts +1 -0
- package/src/hooks/useVirtuosoExternalWindow/useVirtuosoExternalWindow.d.ts +5 -0
- package/src/typings/BaseColor.d.ts +0 -1
- package/src/typings/ComponentTypes.d.ts +4 -30
- package/src/typings/OverridableTypes.d.ts +0 -29
- package/src/typings/UnitMap.d.ts +0 -15
- package/src/utils/ariaHideOutside.d.ts +0 -8
- package/src/utils/checkDefaultPrevented.d.ts +0 -1
- package/src/utils/classes/useClasses.d.ts +0 -29
- package/src/utils/combineProps.d.ts +0 -88
- package/src/utils/getRefElement.d.ts +0 -3
- package/src/utils/isWebKit154.d.ts +0 -8
- package/src/utils/omit.d.ts +0 -1
- package/src/utils/outerSize.d.ts +0 -4
- package/src/utils/pick.d.ts +0 -1
- package/src/utils/preloadImg.d.ts +0 -1
- package/src/utils/removeClassName.d.ts +0 -28
- package/src/utils/runKeyHandler.d.ts +0 -8
- package/src/utils/selectionHandler.d.ts +0 -8
- package/src/utils/twMerge.d.ts +0 -3
- package/utils.js +0 -99
|
@@ -1,35 +1,7 @@
|
|
|
1
1
|
import { RefOrElementOrCallback } from './getRefElement';
|
|
2
2
|
declare type RemoveClassNameOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* make replace also scan child nodes
|
|
5
|
-
*
|
|
6
|
-
* @default false
|
|
7
|
-
*/
|
|
8
3
|
scanChildren?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* is that should fullMatch class name
|
|
11
|
-
*
|
|
12
|
-
* @default false
|
|
13
|
-
*/
|
|
14
4
|
fullMatch?: boolean;
|
|
15
5
|
};
|
|
16
|
-
/**
|
|
17
|
-
* remove className from element, default will not scan child nodes, if you want to scan child nodes, set `scanChildren` to `true`.
|
|
18
|
-
*
|
|
19
|
-
* @param target target element reference or element or callback
|
|
20
|
-
* @param removeClass className to remove, default will use class `includes` to check, if you want to use full match, set `fullMatch` to `true`
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```js
|
|
24
|
-
* elm => <div class="abc bcd efg abc-def"></div>
|
|
25
|
-
*
|
|
26
|
-
* removeClassName(elmRef, 'bcd');
|
|
27
|
-
*
|
|
28
|
-
* elm => <div class="abc efg abc-def"></div>
|
|
29
|
-
*
|
|
30
|
-
* removeClassName(elmRef, 'abc');
|
|
31
|
-
* elm => <div class="efg"></div>
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
6
|
export declare function removeClassName(target: RefOrElementOrCallback, removeClass: string, { scanChildren, fullMatch }?: RemoveClassNameOptions): void;
|
|
35
7
|
export {};
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { KeyboardEvent } from 'react';
|
|
2
2
|
declare type KeyHandlers = Record<KeyboardEvent['key'], () => void>;
|
|
3
|
-
/**
|
|
4
|
-
* Executes the corresponding key handler function based on the provided keyboard event.
|
|
5
|
-
* If a handler is found for the pressed key, it will be invoked.
|
|
6
|
-
* Additionally, it prevents any side effects caused by the event, such as page scrolling.
|
|
7
|
-
*
|
|
8
|
-
* @param e - The keyboard event.
|
|
9
|
-
* @param keyHandlers - An object containing key-handler mappings.
|
|
10
|
-
*/
|
|
11
3
|
export declare const runKeyHandler: (e: KeyboardEvent<unknown>, keyHandlers: KeyHandlers) => void;
|
|
12
4
|
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { RefOrElementOrCallback } from './getRefElement';
|
|
2
|
-
/**
|
|
3
|
-
* get current input element selection position and is that selectRange state
|
|
4
|
-
*/
|
|
5
2
|
export declare function getSelectionPosition<T extends HTMLInputElement | HTMLTextAreaElement>(sourceTarget: RefOrElementOrCallback<T>): {
|
|
6
3
|
isSelectRange: boolean;
|
|
7
4
|
position: {
|
|
@@ -9,15 +6,10 @@ export declare function getSelectionPosition<T extends HTMLInputElement | HTMLTe
|
|
|
9
6
|
end: number;
|
|
10
7
|
};
|
|
11
8
|
};
|
|
12
|
-
/**
|
|
13
|
-
* set input element selection position position,
|
|
14
|
-
* if you need scroll that into view set `scrollIntoView` as true
|
|
15
|
-
*/
|
|
16
9
|
export declare function setSelectionPosition<T extends HTMLInputElement | HTMLTextAreaElement>(target: RefOrElementOrCallback<T>, options: {
|
|
17
10
|
start: number | null;
|
|
18
11
|
end: number | null;
|
|
19
12
|
direction?: 'forward' | 'backward' | 'none' | undefined;
|
|
20
13
|
scrollIntoView?: boolean;
|
|
21
14
|
}): void;
|
|
22
|
-
/** clean whole selection */
|
|
23
15
|
export declare function clearWindowSelection(): void;
|
package/src/utils/twMerge.d.ts
CHANGED
package/utils.js
CHANGED
|
@@ -17,10 +17,6 @@ const a11yKeyboard = {
|
|
|
17
17
|
Tab: 'Tab',
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
// It should to be noted that this function isn't equivalent to `text-transform: capitalize`.
|
|
21
|
-
//
|
|
22
|
-
// A strict capitalization should uppercase the first letter of each word in the sentence.
|
|
23
|
-
// We only handle the first word.
|
|
24
20
|
function capitalize(string) {
|
|
25
21
|
if (typeof string !== 'string') {
|
|
26
22
|
throw new Error('SPRING: `capitalize(string)` expects a string argument.');
|
|
@@ -28,7 +24,6 @@ function capitalize(string) {
|
|
|
28
24
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
/** check is that event preventDefault */
|
|
32
27
|
const checkDefaultPrevented = (fc) => {
|
|
33
28
|
return (e, ...args) => {
|
|
34
29
|
if (e.defaultPrevented)
|
|
@@ -60,47 +55,11 @@ const globalStateClasses = {
|
|
|
60
55
|
dragged: 'sui-dragged',
|
|
61
56
|
};
|
|
62
57
|
|
|
63
|
-
/**
|
|
64
|
-
* simple camel case for better performance, because this is a very open execution function, below is the benchmark of lodash camelCase vs simpleCamelCase and regex camelCase.
|
|
65
|
-
*
|
|
66
|
-
* https://www.measurethat.net/Benchmarks/Show/31672/0/regex-vs-javascript-camelcase-long
|
|
67
|
-
*
|
|
68
|
-
* https://www.measurethat.net/Benchmarks/Show/12906/0/lodash-camelcase-vs-javascript-camelcase-long
|
|
69
|
-
*/
|
|
70
58
|
const simpleCamelCase = (str) => str
|
|
71
59
|
.split('-')
|
|
72
60
|
.map((item, index) => index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item)
|
|
73
61
|
.join('');
|
|
74
62
|
const DEFAULT_PREFIX = 'sui-';
|
|
75
|
-
/**
|
|
76
|
-
* Custom hook for generating CSS classes based on input parameters.
|
|
77
|
-
*
|
|
78
|
-
* pick class from object with prefix of object like `sui-${prefix}-${key}`
|
|
79
|
-
*
|
|
80
|
-
* `className` will be apply to the `cls('root')` class.
|
|
81
|
-
*
|
|
82
|
-
* camelCase will be used for the key in the inputClasses object.
|
|
83
|
-
*
|
|
84
|
-
* and apply to kebabCase in the class name.
|
|
85
|
-
*
|
|
86
|
-
* ```tsx
|
|
87
|
-
* type BaseButtonClasses =
|
|
88
|
-
* | 'root'
|
|
89
|
-
* | 'content'
|
|
90
|
-
* | 'start-slot';
|
|
91
|
-
*
|
|
92
|
-
* const cls = useClasses<BaseButtonClasses>('button', {
|
|
93
|
-
* root: 'custom-button-root',
|
|
94
|
-
* content: 'custom-button-content',
|
|
95
|
-
* startSlot: 'custom-button-start-slot',
|
|
96
|
-
* }, 'custom-root-class');
|
|
97
|
-
*
|
|
98
|
-
* <button className={cls('root')}>Button</button> // 'sui-button-root custom-button-root custom-root-class'
|
|
99
|
-
* <button className={cls('content')}>Button</button> // 'sui-button-content custom-button-content'
|
|
100
|
-
*
|
|
101
|
-
* <button className={cls('start-slot')}>Button</button> // 'sui-button-start-slot custom-button-start-slot'
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
63
|
const useClasses = (prefix, inputClasses, className) => {
|
|
105
64
|
return useCallback((...classValues) => {
|
|
106
65
|
const classList = [];
|
|
@@ -116,7 +75,6 @@ const useClasses = (prefix, inputClasses, className) => {
|
|
|
116
75
|
classList.push(`${DEFAULT_PREFIX}${prefix}-${classValue}`);
|
|
117
76
|
}
|
|
118
77
|
if (hasCustomClasses) {
|
|
119
|
-
// add selected class to map for use in inputClasses
|
|
120
78
|
selectedMap.set(simpleCamelCase(classValue), 1);
|
|
121
79
|
}
|
|
122
80
|
};
|
|
@@ -146,14 +104,12 @@ const useClasses = (prefix, inputClasses, className) => {
|
|
|
146
104
|
}
|
|
147
105
|
});
|
|
148
106
|
if (isRoot && className) {
|
|
149
|
-
// add root class and className
|
|
150
107
|
classList.push(className);
|
|
151
108
|
}
|
|
152
109
|
return classList.join(' ');
|
|
153
110
|
}, [className, inputClasses, prefix]);
|
|
154
111
|
};
|
|
155
112
|
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
113
|
const getTitle = (text) => {
|
|
158
114
|
return typeof text === 'string' ? text : undefined;
|
|
159
115
|
};
|
|
@@ -164,33 +120,18 @@ const isSuiElement = (element, suiNames) => {
|
|
|
164
120
|
};
|
|
165
121
|
|
|
166
122
|
function isUrl(url) {
|
|
167
|
-
// eslint-disable-next-line no-useless-escape
|
|
168
123
|
const exp = /(\b(https?):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
|
|
169
124
|
return url.match(exp);
|
|
170
125
|
}
|
|
171
126
|
|
|
172
|
-
// * this whole file should be remove after webkit154 issue be fixed
|
|
173
|
-
/**
|
|
174
|
-
* Conditionally apply a workaround for the CSS transition bug in Safari 15.4 / WebKit browsers.
|
|
175
|
-
* Remove this workaround once the WebKit bug fix is released.
|
|
176
|
-
*
|
|
177
|
-
* follow up:
|
|
178
|
-
* https://github.com/mui/material-ui/pull/31975/files
|
|
179
|
-
* https://github.com/mui/material-ui/pull/32202/files
|
|
180
|
-
*/
|
|
181
127
|
const isWebKit154 = typeof navigator !== 'undefined' &&
|
|
182
128
|
/^((?!chrome|android).)*(safari|mobile)/i.test(navigator.userAgent) &&
|
|
183
129
|
/(os |version\/)15(.|_)[4-9]/i.test(navigator.userAgent);
|
|
184
130
|
|
|
185
|
-
/** enhance lodash type */
|
|
186
131
|
const omit = (classes, keys) => {
|
|
187
132
|
return lodashOmit(classes, keys);
|
|
188
133
|
};
|
|
189
134
|
|
|
190
|
-
/**
|
|
191
|
-
* get that full height and margin with margin
|
|
192
|
-
* that will ignore transform animation
|
|
193
|
-
*/
|
|
194
135
|
function outerSize(el) {
|
|
195
136
|
const style = getComputedStyle(el);
|
|
196
137
|
return {
|
|
@@ -207,12 +148,10 @@ function outerSize(el) {
|
|
|
207
148
|
};
|
|
208
149
|
}
|
|
209
150
|
|
|
210
|
-
/** enhance lodash type */
|
|
211
151
|
const pick = (classes, keys) => {
|
|
212
152
|
return lodashPick(classes, keys);
|
|
213
153
|
};
|
|
214
154
|
|
|
215
|
-
/** preload image file */
|
|
216
155
|
function preloadImg(url) {
|
|
217
156
|
return new Promise((resolve, reject) => {
|
|
218
157
|
const img = new Image();
|
|
@@ -230,24 +169,6 @@ function preloadImg(url) {
|
|
|
230
169
|
});
|
|
231
170
|
}
|
|
232
171
|
|
|
233
|
-
/**
|
|
234
|
-
* remove className from element, default will not scan child nodes, if you want to scan child nodes, set `scanChildren` to `true`.
|
|
235
|
-
*
|
|
236
|
-
* @param target target element reference or element or callback
|
|
237
|
-
* @param removeClass className to remove, default will use class `includes` to check, if you want to use full match, set `fullMatch` to `true`
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```js
|
|
241
|
-
* elm => <div class="abc bcd efg abc-def"></div>
|
|
242
|
-
*
|
|
243
|
-
* removeClassName(elmRef, 'bcd');
|
|
244
|
-
*
|
|
245
|
-
* elm => <div class="abc efg abc-def"></div>
|
|
246
|
-
*
|
|
247
|
-
* removeClassName(elmRef, 'abc');
|
|
248
|
-
* elm => <div class="efg"></div>
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
172
|
function removeClassName(target, removeClass, { scanChildren = false, fullMatch = false } = {}) {
|
|
252
173
|
const elm = getRefElement(target);
|
|
253
174
|
if (!elm)
|
|
@@ -272,26 +193,14 @@ function cleanClass(elm, removeClass, fullMatch) {
|
|
|
272
193
|
.join(' ');
|
|
273
194
|
}
|
|
274
195
|
|
|
275
|
-
/**
|
|
276
|
-
* Executes the corresponding key handler function based on the provided keyboard event.
|
|
277
|
-
* If a handler is found for the pressed key, it will be invoked.
|
|
278
|
-
* Additionally, it prevents any side effects caused by the event, such as page scrolling.
|
|
279
|
-
*
|
|
280
|
-
* @param e - The keyboard event.
|
|
281
|
-
* @param keyHandlers - An object containing key-handler mappings.
|
|
282
|
-
*/
|
|
283
196
|
const runKeyHandler = (e, keyHandlers) => {
|
|
284
197
|
const handler = keyHandlers[e.key];
|
|
285
198
|
if (handler) {
|
|
286
199
|
handler();
|
|
287
|
-
// if event was handled prevent other side effects (e.g. page scroll)
|
|
288
200
|
e.preventDefault();
|
|
289
201
|
}
|
|
290
202
|
};
|
|
291
203
|
|
|
292
|
-
/**
|
|
293
|
-
* get current input element selection position and is that selectRange state
|
|
294
|
-
*/
|
|
295
204
|
function getSelectionPosition(sourceTarget) {
|
|
296
205
|
const input = getRefElement(sourceTarget);
|
|
297
206
|
const currentPosition = input?.selectionStart;
|
|
@@ -302,14 +211,9 @@ function getSelectionPosition(sourceTarget) {
|
|
|
302
211
|
position: { start: currentPosition || 0, end: currentPositionEnd || 0 },
|
|
303
212
|
};
|
|
304
213
|
}
|
|
305
|
-
/**
|
|
306
|
-
* set input element selection position position,
|
|
307
|
-
* if you need scroll that into view set `scrollIntoView` as true
|
|
308
|
-
*/
|
|
309
214
|
function setSelectionPosition(target, options) {
|
|
310
215
|
const elm = getRefElement(target);
|
|
311
216
|
if (elm && options.start !== null && options.end !== null) {
|
|
312
|
-
// * use blur and refocus to refocus position into view
|
|
313
217
|
if (options.scrollIntoView)
|
|
314
218
|
elm.blur();
|
|
315
219
|
elm.setSelectionRange(options.start, options.end, options.direction);
|
|
@@ -317,14 +221,11 @@ function setSelectionPosition(target, options) {
|
|
|
317
221
|
elm.focus();
|
|
318
222
|
}
|
|
319
223
|
}
|
|
320
|
-
/** clean whole selection */
|
|
321
224
|
function clearWindowSelection() {
|
|
322
225
|
if (window?.getSelection) {
|
|
323
226
|
const selection = window.getSelection();
|
|
324
227
|
if (selection) {
|
|
325
|
-
// Chrome
|
|
326
228
|
selection.empty?.();
|
|
327
|
-
// Firefox
|
|
328
229
|
selection.removeAllRanges?.();
|
|
329
230
|
}
|
|
330
231
|
}
|