@ringcentral/spring-base 1.12.0 → 1.13.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/config.js +32 -12
- package/contexts.js +42 -24
- package/hooks.js +1630 -613
- package/index.js +15 -17
- package/liveAnnouncer.js +303 -1
- package/package.json +2 -2
- package/src/hooks/useButton/useButton.d.ts +1 -1
- package/typings.js +7 -0
- package/utils.js +835 -81
- package/chunks/index.js +0 -234
- package/chunks/twMerge.js +0 -503
package/config.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// TODO: refactor config
|
|
2
|
+
/* oxlint-disable no-console */ const SPRING_WARNING_IGNORE_KEY = '__SPRING_WARNING_IGNORE__';
|
|
3
|
+
// * use that way to avoid that code be exist in production code base
|
|
4
|
+
/**
|
|
5
|
+
* config global setting
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* configure({
|
|
9
|
+
* warning: false
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
* ## WARNING related method and only work in `development mode`
|
|
13
|
+
*
|
|
14
|
+
* `WARNING_IGNORE`: only work in `development mode`
|
|
15
|
+
* `WARNING_FUNCTION` only work in `development mode`
|
|
16
|
+
*/ let rcConfiguration = {};
|
|
3
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
4
18
|
class RcConfig {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
constructor(){
|
|
20
|
+
this._WARNING_IGNORE = false;
|
|
21
|
+
this._WARNING_FUNCTION = (message, options)=>{
|
|
22
|
+
console[options?.level || 'warn'](message);
|
|
23
|
+
};
|
|
10
24
|
if (typeof window !== 'undefined') {
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
// SSR support
|
|
26
|
+
// * get value once when init
|
|
27
|
+
this._WARNING_IGNORE = window?.localStorage?.getItem(SPRING_WARNING_IGNORE_KEY) === 'true';
|
|
28
|
+
// * also provide user to set variable from window
|
|
13
29
|
window.__SPRING__ = this;
|
|
14
30
|
}
|
|
15
31
|
}
|
|
@@ -28,8 +44,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
28
44
|
set WARNING_FUNCTION(func) {
|
|
29
45
|
if (typeof func === 'function') {
|
|
30
46
|
this._WARNING_FUNCTION = func;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
47
|
+
} else {
|
|
33
48
|
console.warn('[Spring] config warningFunction is not a function.');
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -39,7 +54,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
39
54
|
}
|
|
40
55
|
rcConfiguration = new RcConfig();
|
|
41
56
|
}
|
|
42
|
-
|
|
57
|
+
/**
|
|
58
|
+
* set config with Spring
|
|
59
|
+
*
|
|
60
|
+
* ## WARNING method only work in `development mode`
|
|
61
|
+
*/ const configure = (options)=>{
|
|
43
62
|
if (process.env.NODE_ENV !== 'production') {
|
|
44
63
|
const { warning, warningFunction } = options;
|
|
45
64
|
if (warning !== undefined) {
|
|
@@ -51,4 +70,5 @@ const configure = (options) => {
|
|
|
51
70
|
}
|
|
52
71
|
};
|
|
53
72
|
|
|
73
|
+
|
|
54
74
|
export { configure, rcConfiguration };
|
package/contexts.js
CHANGED
|
@@ -1,70 +1,88 @@
|
|
|
1
|
-
import { createContext, useContext } from
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
const WindowContext = createContext({
|
|
4
|
-
document: typeof window !== 'undefined'
|
|
5
|
-
? window.document
|
|
6
|
-
: globalThis.window?.document
|
|
7
|
-
? globalThis.window.document
|
|
8
|
-
: undefined,
|
|
6
|
+
document: typeof window !== 'undefined' ? window.document : globalThis.window?.document ? globalThis.window.document : undefined,
|
|
9
7
|
globalThis: globalThis,
|
|
10
|
-
externalWindow: typeof window !== 'undefined' ? window : globalThis.window
|
|
8
|
+
externalWindow: typeof window !== 'undefined' ? window : globalThis.window
|
|
11
9
|
});
|
|
12
|
-
const useWindowContext = ()
|
|
10
|
+
const useWindowContext = ()=>useContext(WindowContext);
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/** small to large */ const breakpointList = [
|
|
14
|
+
'xs',
|
|
15
|
+
'sm',
|
|
16
|
+
'md',
|
|
17
|
+
'lg',
|
|
18
|
+
'xl'
|
|
19
|
+
];
|
|
13
20
|
|
|
14
|
-
const breakpointList = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
15
21
|
|
|
16
22
|
const matchCache = new Map();
|
|
17
|
-
const getMatchGroups = (breakpoint)
|
|
23
|
+
const getMatchGroups = (breakpoint)=>{
|
|
18
24
|
const ltMatchGroup = [];
|
|
19
25
|
const gtMatchGroup = [];
|
|
20
26
|
if (breakpoint === null) {
|
|
21
|
-
for
|
|
27
|
+
for(let i = 0; i < breakpointList.length; i++){
|
|
22
28
|
ltMatchGroup.push(`lt-${breakpointList[i]}`);
|
|
23
29
|
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
30
|
+
} else {
|
|
26
31
|
const bpIndex = breakpointList.indexOf(breakpoint);
|
|
27
|
-
for
|
|
32
|
+
for(let i = 0; i < bpIndex; i++){
|
|
28
33
|
gtMatchGroup.unshift(`gt-${breakpointList[i]}`);
|
|
29
34
|
}
|
|
30
|
-
for
|
|
35
|
+
for(let i = bpIndex + 1; i < breakpointList.length; i++){
|
|
31
36
|
ltMatchGroup.push(`lt-${breakpointList[i]}`);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
ltMatchGroup,
|
|
41
|
+
gtMatchGroup
|
|
42
|
+
};
|
|
35
43
|
};
|
|
36
|
-
const getMatchMap = ({ ltMatchGroup, gtMatchGroup }, matchBP)
|
|
44
|
+
const getMatchMap = ({ ltMatchGroup, gtMatchGroup }, matchBP)=>{
|
|
37
45
|
const matchMap = {};
|
|
38
|
-
if (matchBP !== null)
|
|
39
|
-
|
|
40
|
-
for (const ltBP of ltMatchGroup) {
|
|
46
|
+
if (matchBP !== null) matchMap[matchBP] = true;
|
|
47
|
+
for (const ltBP of ltMatchGroup){
|
|
41
48
|
const [, bp] = ltBP.split('-');
|
|
42
49
|
matchMap[`lt${bp.toUpperCase()}`] = true;
|
|
43
50
|
matchMap[ltBP] = true;
|
|
44
51
|
}
|
|
45
|
-
for (const gtBP of gtMatchGroup)
|
|
52
|
+
for (const gtBP of gtMatchGroup){
|
|
46
53
|
const [, bp] = gtBP.split('-');
|
|
47
54
|
matchMap[`gt${bp.toUpperCase()}`] = true;
|
|
48
55
|
matchMap[gtBP] = true;
|
|
49
56
|
}
|
|
50
57
|
return matchMap;
|
|
51
58
|
};
|
|
52
|
-
const getMatchDetail = (breakpoint)
|
|
59
|
+
const getMatchDetail = (breakpoint)=>{
|
|
53
60
|
if (!matchCache.has(breakpoint)) {
|
|
54
61
|
const matchGroups = getMatchGroups(breakpoint);
|
|
55
62
|
const matchMap = getMatchMap(matchGroups, breakpoint);
|
|
56
63
|
matchCache.set(breakpoint, {
|
|
57
64
|
...matchGroups,
|
|
58
65
|
matchBP: breakpoint,
|
|
59
|
-
matchMap
|
|
66
|
+
matchMap
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
return matchCache.get(breakpoint);
|
|
63
70
|
};
|
|
64
71
|
|
|
72
|
+
|
|
73
|
+
|
|
65
74
|
const RcResponsiveContext = createContext(undefined);
|
|
66
|
-
const useResponsiveContext = ()
|
|
75
|
+
const useResponsiveContext = ()=>{
|
|
67
76
|
return useContext(RcResponsiveContext);
|
|
68
77
|
};
|
|
69
78
|
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
70
88
|
export { RcResponsiveContext, WindowContext, breakpointList, getMatchDetail, useResponsiveContext, useWindowContext };
|