@lowdefy/client 5.0.0 → 5.1.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/dist/useDarkMode.js +66 -3
- package/package.json +8 -8
package/dist/useDarkMode.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { useCallback, useEffect, useState } from 'react';
|
|
15
|
+
*/ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
16
16
|
import { theme as antdTheme } from 'antd';
|
|
17
17
|
const algorithmMap = {
|
|
18
18
|
default: antdTheme.defaultAlgorithm,
|
|
@@ -52,7 +52,23 @@ function resolveIsDark({ configDarkMode, userPreference, systemIsDark }) {
|
|
|
52
52
|
// userPreference is 'system' — follow OS
|
|
53
53
|
return systemIsDark;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function mergeComponents(shared, mode) {
|
|
56
|
+
if (!shared && !mode) return undefined;
|
|
57
|
+
const keys = new Set([
|
|
58
|
+
...Object.keys(shared ?? {}),
|
|
59
|
+
...Object.keys(mode ?? {})
|
|
60
|
+
]);
|
|
61
|
+
const merged = {};
|
|
62
|
+
keys.forEach((name)=>{
|
|
63
|
+
merged[name] = {
|
|
64
|
+
...(shared ?? {})[name] ?? {},
|
|
65
|
+
...(mode ?? {})[name] ?? {}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
return merged;
|
|
69
|
+
}
|
|
70
|
+
function useDarkMode({ antd, configDarkMode }) {
|
|
71
|
+
const baseAlgorithm = antd?.algorithm;
|
|
56
72
|
const cleanAlgorithm = stripDarkFromAlgorithm(baseAlgorithm);
|
|
57
73
|
const [userPreference, setUserPreference] = useState(()=>{
|
|
58
74
|
return window.localStorage?.getItem('lowdefy_darkMode') ?? 'system';
|
|
@@ -79,6 +95,53 @@ function useDarkMode({ baseAlgorithm, configDarkMode }) {
|
|
|
79
95
|
systemIsDark
|
|
80
96
|
});
|
|
81
97
|
window.__lowdefy_isDark = isDark;
|
|
82
|
-
|
|
98
|
+
const sharedToken = antd?.token;
|
|
99
|
+
const lightToken = antd?.lightToken;
|
|
100
|
+
const darkToken = antd?.darkToken;
|
|
101
|
+
const sharedComponents = antd?.components;
|
|
102
|
+
const lightComponents = antd?.lightComponents;
|
|
103
|
+
const darkComponents = antd?.darkComponents;
|
|
104
|
+
const token = useMemo(()=>{
|
|
105
|
+
const modeToken = isDark ? darkToken : lightToken;
|
|
106
|
+
if (!sharedToken && !modeToken) return undefined;
|
|
107
|
+
return {
|
|
108
|
+
...sharedToken ?? {},
|
|
109
|
+
...modeToken ?? {}
|
|
110
|
+
};
|
|
111
|
+
}, [
|
|
112
|
+
isDark,
|
|
113
|
+
sharedToken,
|
|
114
|
+
lightToken,
|
|
115
|
+
darkToken
|
|
116
|
+
]);
|
|
117
|
+
const components = useMemo(()=>mergeComponents(sharedComponents, isDark ? darkComponents : lightComponents), [
|
|
118
|
+
isDark,
|
|
119
|
+
sharedComponents,
|
|
120
|
+
lightComponents,
|
|
121
|
+
darkComponents
|
|
122
|
+
]);
|
|
123
|
+
// Keep the <html> background in sync with the resolved mode. The _document.js
|
|
124
|
+
// inline script sets an initial background before hydration; this effect takes
|
|
125
|
+
// over once React is active and updates on every dark/light toggle.
|
|
126
|
+
const darkBg = darkToken?.colorBgLayout;
|
|
127
|
+
const lightBg = lightToken?.colorBgLayout;
|
|
128
|
+
useEffect(()=>{
|
|
129
|
+
if (isDark) {
|
|
130
|
+
document.documentElement.style.backgroundColor = darkBg ?? '#000';
|
|
131
|
+
} else if (lightBg) {
|
|
132
|
+
document.documentElement.style.backgroundColor = lightBg;
|
|
133
|
+
} else {
|
|
134
|
+
document.documentElement.style.removeProperty('background-color');
|
|
135
|
+
}
|
|
136
|
+
}, [
|
|
137
|
+
isDark,
|
|
138
|
+
darkBg,
|
|
139
|
+
lightBg
|
|
140
|
+
]);
|
|
141
|
+
return {
|
|
142
|
+
algorithm: resolveAlgorithm(mergeAlgorithm(cleanAlgorithm, isDark)),
|
|
143
|
+
token,
|
|
144
|
+
components
|
|
145
|
+
};
|
|
83
146
|
}
|
|
84
147
|
export default useDarkMode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/client",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy Client",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@ant-design/icons": "6.1.0",
|
|
37
37
|
"antd": "6.3.1",
|
|
38
|
-
"@lowdefy/block-utils": "5.
|
|
39
|
-
"@lowdefy/engine": "5.
|
|
40
|
-
"@lowdefy/errors": "5.
|
|
41
|
-
"@lowdefy/helpers": "5.
|
|
42
|
-
"@lowdefy/layout": "5.
|
|
43
|
-
"@lowdefy/logger": "5.
|
|
38
|
+
"@lowdefy/block-utils": "5.1.0",
|
|
39
|
+
"@lowdefy/engine": "5.1.0",
|
|
40
|
+
"@lowdefy/errors": "5.1.0",
|
|
41
|
+
"@lowdefy/helpers": "5.1.0",
|
|
42
|
+
"@lowdefy/layout": "5.1.0",
|
|
43
|
+
"@lowdefy/logger": "5.1.0",
|
|
44
44
|
"react": "18.2.0",
|
|
45
45
|
"react-dom": "18.2.0",
|
|
46
46
|
"tinykeys": "^3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@jest/globals": "28.1.3",
|
|
50
|
-
"@lowdefy/jest-yaml-transform": "5.
|
|
50
|
+
"@lowdefy/jest-yaml-transform": "5.1.0",
|
|
51
51
|
"@swc/cli": "0.8.0",
|
|
52
52
|
"@swc/core": "1.15.18",
|
|
53
53
|
"@swc/jest": "0.2.39",
|