@zat-design/sisyphus-react 4.0.6 → 4.0.9
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/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProDrawerForm/components/ProDrawer/index.js +2 -2
- package/es/ProEditTable/index.js +1 -1
- package/es/ProEnum/index.js +1 -1
- package/es/ProForm/components/base/Input/index.js +75 -17
- package/es/ProForm/components/combination/FormList/components/BlockFields.js +2 -2
- package/es/ProForm/components/combination/Group/style/index.less +4 -2
- package/es/ProForm/components/combination/Group/utils/index.d.ts +23 -23
- package/es/ProForm/components/render/ChangedWrapper.js +1 -3
- package/es/ProForm/style/index.less +18 -0
- package/es/ProIcon/index.js +204 -98
- package/es/ProIcon/propsTypes.d.ts +17 -11
- package/es/ProLayout/components/ProCollapse/index.js +1 -1
- package/es/ProLayout/components/ProFooter/index.js +1 -1
- package/es/ProLayout/components/ProHeader/index.js +2 -6
- package/es/ProLayout/index.js +1 -2
- package/es/ProSelect/index.js +1 -1
- package/es/ProStep/components/Step/index.js +1 -1
- package/es/ProStep/style/index.less +4 -2
- package/es/ProTable/components/RenderColumn/index.js +1 -1
- package/es/ProTable/components/RenderTabs/index.js +9 -3
- package/es/ProThemeTools/component/ProTools/index.js +109 -90
- package/es/ProThemeTools/context/ThemeContext.d.ts +10 -0
- package/es/ProThemeTools/context/ThemeContext.js +28 -0
- package/es/ProThemeTools/index.js +37 -12
- package/es/ProThemeTools/utils/index.d.ts +9 -1
- package/es/ProThemeTools/utils/index.js +84 -5
- package/es/ProTreeModal/components/Trigger.js +34 -13
- package/es/ProTreeModal/index.js +6 -0
- package/es/ProTreeModal/style/index.less +41 -0
- package/es/ProUpload/components/ImageRender.js +1 -1
- package/es/ProViewer/index.js +2 -3
- package/es/style/theme/antd.less +0 -9
- package/es/style/theme/base.less +1 -1
- package/es/style/variables.less +1 -0
- package/lib/ProDrawerForm/components/ProDrawer/index.js +1 -1
- package/lib/ProEditTable/index.js +1 -1
- package/lib/ProEnum/index.js +1 -1
- package/lib/ProForm/components/base/Input/index.js +73 -16
- package/lib/ProForm/components/combination/FormList/components/BlockFields.js +2 -2
- package/lib/ProForm/components/combination/Group/style/index.less +4 -2
- package/lib/ProForm/components/combination/Group/utils/index.d.ts +23 -23
- package/lib/ProForm/components/render/ChangedWrapper.js +1 -3
- package/lib/ProForm/style/index.less +18 -0
- package/lib/ProIcon/index.js +205 -99
- package/lib/ProIcon/propsTypes.d.ts +17 -11
- package/lib/ProLayout/components/ProCollapse/index.js +1 -1
- package/lib/ProLayout/components/ProFooter/index.js +1 -1
- package/lib/ProLayout/components/ProHeader/index.js +3 -6
- package/lib/ProLayout/index.js +1 -2
- package/lib/ProSelect/index.js +1 -1
- package/lib/ProStep/components/Step/index.js +1 -1
- package/lib/ProStep/style/index.less +4 -2
- package/lib/ProTable/components/RenderColumn/index.js +1 -1
- package/lib/ProTable/components/RenderTabs/index.js +9 -3
- package/lib/ProThemeTools/component/ProTools/index.js +109 -91
- package/lib/ProThemeTools/context/ThemeContext.d.ts +10 -0
- package/lib/ProThemeTools/context/ThemeContext.js +31 -2
- package/lib/ProThemeTools/index.js +35 -10
- package/lib/ProThemeTools/utils/index.d.ts +9 -1
- package/lib/ProThemeTools/utils/index.js +86 -6
- package/lib/ProTreeModal/components/Trigger.js +34 -13
- package/lib/ProTreeModal/index.js +6 -0
- package/lib/ProTreeModal/style/index.less +41 -0
- package/lib/ProUpload/components/ImageRender.js +1 -1
- package/lib/ProViewer/index.js +3 -3
- package/lib/style/theme/antd.less +0 -9
- package/lib/style/theme/base.less +1 -1
- package/lib/style/variables.less +1 -0
- package/package.json +14 -14
|
@@ -24,7 +24,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
24
24
|
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; }
|
|
25
25
|
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; }
|
|
26
26
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
27
|
-
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); }
|
|
27
|
+
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); } // 导入语句
|
|
28
28
|
var connect = function connect(Component) {
|
|
29
29
|
var ComponentWrapper = function ComponentWrapper(props) {
|
|
30
30
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({}, props));
|
|
@@ -40,9 +40,12 @@ var ProTools = _ref => {
|
|
|
40
40
|
state = _ref.state,
|
|
41
41
|
tableBorder = _ref.tableBorder,
|
|
42
42
|
tableStripe = _ref.tableStripe;
|
|
43
|
+
// Props 和基础 Hooks
|
|
43
44
|
var _useProConfig = (0, _ProConfigProvider.useProConfig)(),
|
|
44
45
|
config = _useProConfig.state,
|
|
45
46
|
dispatch = _useProConfig.dispatch;
|
|
47
|
+
|
|
48
|
+
// 状态和 Refs
|
|
46
49
|
var _useState = (0, _react.useState)([{
|
|
47
50
|
color: '#006AFF',
|
|
48
51
|
active: true
|
|
@@ -62,19 +65,112 @@ var ProTools = _ref => {
|
|
|
62
65
|
_useState2 = _slicedToArray(_useState, 2),
|
|
63
66
|
active = _useState2[0],
|
|
64
67
|
setActive = _useState2[1];
|
|
68
|
+
|
|
69
|
+
// 事件处理函数
|
|
70
|
+
var handleThemeColorClick = item => {
|
|
71
|
+
var array = active.map(activeItem => {
|
|
72
|
+
activeItem.active = false;
|
|
73
|
+
return {
|
|
74
|
+
color: activeItem.color,
|
|
75
|
+
active: item.color === activeItem.color
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
setActive(array);
|
|
79
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
80
|
+
zauiBrand: item.color
|
|
81
|
+
}));
|
|
82
|
+
(0, _index.setThemes)({
|
|
83
|
+
'zaui-brand': item.color
|
|
84
|
+
});
|
|
85
|
+
dispatch({
|
|
86
|
+
type: 'set',
|
|
87
|
+
payload: {
|
|
88
|
+
theme: {
|
|
89
|
+
primaryColor: item.color,
|
|
90
|
+
qiankunPrimaryColor: item.color
|
|
91
|
+
},
|
|
92
|
+
forms: {}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
var handleLayoutChange = value => {
|
|
97
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
98
|
+
zauiSize: value
|
|
99
|
+
}));
|
|
100
|
+
(0, _index.setThemes)({
|
|
101
|
+
'zaui-size': value
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
var handleFormAlignChange = value => {
|
|
105
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
106
|
+
zauiFormAlign: value
|
|
107
|
+
}));
|
|
108
|
+
(0, _index.setThemes)({
|
|
109
|
+
'zaui-form-align': value
|
|
110
|
+
});
|
|
111
|
+
dispatch({
|
|
112
|
+
type: 'setWithLocal',
|
|
113
|
+
payload: {
|
|
114
|
+
ProForm: {
|
|
115
|
+
labelAlign: value
|
|
116
|
+
},
|
|
117
|
+
forms: {}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
var handleTableBorderClick = value => {
|
|
122
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
123
|
+
zauiTableBorder: value
|
|
124
|
+
}));
|
|
125
|
+
(0, _index.setThemes)({
|
|
126
|
+
'zaui-table-border': value
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
var handleTableStripeClick = value => {
|
|
130
|
+
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
131
|
+
zauiStripe: value
|
|
132
|
+
}));
|
|
133
|
+
(0, _index.setThemes)({
|
|
134
|
+
'zaui-stripe': value,
|
|
135
|
+
'zaui-table-strip-bg': value ? '#fafafa' : '#ffffff'
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
var handleResetClick = () => {
|
|
139
|
+
setActive([{
|
|
140
|
+
color: '#006AFF',
|
|
141
|
+
active: true
|
|
142
|
+
}, {
|
|
143
|
+
color: '#00BC70',
|
|
144
|
+
active: false
|
|
145
|
+
}, {
|
|
146
|
+
color: '#FF8C16',
|
|
147
|
+
active: false
|
|
148
|
+
}, {
|
|
149
|
+
color: '#A00F20',
|
|
150
|
+
active: false
|
|
151
|
+
}]);
|
|
152
|
+
onReset();
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// 所有 useEffect 集中放置
|
|
65
156
|
(0, _react.useEffect)(() => {
|
|
157
|
+
var _document$documentEle;
|
|
158
|
+
// 检查 CSS 变量是否已被 setThemes 设置(优先级高于缓存)
|
|
159
|
+
var existingZauiBrand = (_document$documentEle = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.trim();
|
|
66
160
|
var themeConfig = localStorage.getItem('themeConfig');
|
|
67
161
|
var curThemeConfig = themeConfig ? JSON.parse(themeConfig) : {};
|
|
68
162
|
var _ref2 = curThemeConfig.data || {},
|
|
69
163
|
_ref2$zauiBrand = _ref2.zauiBrand,
|
|
70
164
|
zauiBrand = _ref2$zauiBrand === void 0 ? '#006AFF' : _ref2$zauiBrand;
|
|
71
|
-
|
|
72
|
-
|
|
165
|
+
|
|
166
|
+
// 优先使用 CSS 变量的值
|
|
167
|
+
var finalZauiBrand = existingZauiBrand || zauiBrand;
|
|
168
|
+
if (finalZauiBrand) {
|
|
73
169
|
var newArray = active.map(activeItem => {
|
|
74
170
|
activeItem.active = false;
|
|
75
171
|
return {
|
|
76
172
|
color: activeItem.color,
|
|
77
|
-
active: activeItem.color ===
|
|
173
|
+
active: activeItem.color === finalZauiBrand.toLocaleUpperCase()
|
|
78
174
|
};
|
|
79
175
|
});
|
|
80
176
|
setActive(newArray);
|
|
@@ -82,8 +178,8 @@ var ProTools = _ref => {
|
|
|
82
178
|
type: 'set',
|
|
83
179
|
payload: {
|
|
84
180
|
theme: {
|
|
85
|
-
primaryColor:
|
|
86
|
-
qiankunPrimaryColor:
|
|
181
|
+
primaryColor: finalZauiBrand,
|
|
182
|
+
qiankunPrimaryColor: finalZauiBrand
|
|
87
183
|
},
|
|
88
184
|
forms: {}
|
|
89
185
|
}
|
|
@@ -92,7 +188,7 @@ var ProTools = _ref => {
|
|
|
92
188
|
}, []);
|
|
93
189
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(NewDrawer, {
|
|
94
190
|
className: "pro-theme-prd-tools-drawer",
|
|
95
|
-
|
|
191
|
+
size: 400,
|
|
96
192
|
title: `${_locale.default.ProThemeTools.title}`,
|
|
97
193
|
placement: "right",
|
|
98
194
|
onClose: onClose,
|
|
@@ -113,32 +209,7 @@ var ProTools = _ref => {
|
|
|
113
209
|
children: active.map((item, index) => {
|
|
114
210
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
115
211
|
className: item.active ? 'active' : '',
|
|
116
|
-
onClick: () =>
|
|
117
|
-
var array = active.map(activeItem => {
|
|
118
|
-
activeItem.active = false;
|
|
119
|
-
return {
|
|
120
|
-
color: activeItem.color,
|
|
121
|
-
active: item.color === activeItem.color
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
setActive(array);
|
|
125
|
-
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
126
|
-
zauiBrand: item.color
|
|
127
|
-
}));
|
|
128
|
-
(0, _index.setThemes)({
|
|
129
|
-
'zaui-brand': item.color
|
|
130
|
-
});
|
|
131
|
-
dispatch({
|
|
132
|
-
type: 'set',
|
|
133
|
-
payload: {
|
|
134
|
-
theme: {
|
|
135
|
-
primaryColor: item.color,
|
|
136
|
-
qiankunPrimaryColor: item.color
|
|
137
|
-
},
|
|
138
|
-
forms: {}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
},
|
|
212
|
+
onClick: () => handleThemeColorClick(item),
|
|
142
213
|
children: item.active ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.CheckOutlined, {}) : null
|
|
143
214
|
}, item.color);
|
|
144
215
|
})
|
|
@@ -154,14 +225,7 @@ var ProTools = _ref => {
|
|
|
154
225
|
className: "pro-theme-tools-item",
|
|
155
226
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Radio.Group, {
|
|
156
227
|
value: state.zauiSize,
|
|
157
|
-
onChange: e =>
|
|
158
|
-
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
159
|
-
zauiSize: e.target.value
|
|
160
|
-
}));
|
|
161
|
-
(0, _index.setThemes)({
|
|
162
|
-
'zaui-size': e.target.value
|
|
163
|
-
});
|
|
164
|
-
},
|
|
228
|
+
onChange: e => handleLayoutChange(e.target.value),
|
|
165
229
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Radio.Button, {
|
|
166
230
|
value: 0.5,
|
|
167
231
|
children: `${_locale.default.ProThemeTools.layoutMode[0]}`
|
|
@@ -185,23 +249,7 @@ var ProTools = _ref => {
|
|
|
185
249
|
className: "pro-theme-tools-item",
|
|
186
250
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Radio.Group, {
|
|
187
251
|
value: state.zauiFormAlign,
|
|
188
|
-
onChange: e =>
|
|
189
|
-
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
190
|
-
zauiFormAlign: e.target.value
|
|
191
|
-
}));
|
|
192
|
-
(0, _index.setThemes)({
|
|
193
|
-
'zaui-form-align': e.target.value
|
|
194
|
-
});
|
|
195
|
-
dispatch({
|
|
196
|
-
type: 'setWithLocal',
|
|
197
|
-
payload: {
|
|
198
|
-
ProForm: {
|
|
199
|
-
labelAlign: e.target.value
|
|
200
|
-
},
|
|
201
|
-
forms: {}
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
},
|
|
252
|
+
onChange: e => handleFormAlignChange(e.target.value),
|
|
205
253
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Radio.Button, {
|
|
206
254
|
value: "left",
|
|
207
255
|
children: `${_locale.default.ProThemeTools.flex[0]}`
|
|
@@ -224,14 +272,7 @@ var ProTools = _ref => {
|
|
|
224
272
|
checkedChildren: `${_locale.default.ProThemeTools.switchText[0]}`,
|
|
225
273
|
unCheckedChildren: `${_locale.default.ProThemeTools.switchText[1]}`,
|
|
226
274
|
checked: state.zauiTableBorder,
|
|
227
|
-
onClick:
|
|
228
|
-
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
229
|
-
zauiTableBorder: value
|
|
230
|
-
}));
|
|
231
|
-
(0, _index.setThemes)({
|
|
232
|
-
'zaui-table-border': value
|
|
233
|
-
});
|
|
234
|
-
}
|
|
275
|
+
onClick: handleTableBorderClick
|
|
235
276
|
})
|
|
236
277
|
})]
|
|
237
278
|
}), tableStripe && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -247,35 +288,12 @@ var ProTools = _ref => {
|
|
|
247
288
|
checkedChildren: `${_locale.default.ProThemeTools.switchText[0]}`,
|
|
248
289
|
unCheckedChildren: `${_locale.default.ProThemeTools.switchText[1]}`,
|
|
249
290
|
checked: state.zauiStripe,
|
|
250
|
-
onClick:
|
|
251
|
-
setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
252
|
-
zauiStripe: value
|
|
253
|
-
}));
|
|
254
|
-
(0, _index.setThemes)({
|
|
255
|
-
'zaui-stripe': value,
|
|
256
|
-
'zaui-table-strip-bg': value ? '#fafafa' : '#ffffff'
|
|
257
|
-
});
|
|
258
|
-
}
|
|
291
|
+
onClick: handleTableStripeClick
|
|
259
292
|
})
|
|
260
293
|
})]
|
|
261
294
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Button, {
|
|
262
295
|
className: "copy-btn",
|
|
263
|
-
onClick:
|
|
264
|
-
setActive([{
|
|
265
|
-
color: '#006AFF',
|
|
266
|
-
active: true
|
|
267
|
-
}, {
|
|
268
|
-
color: '#00BC70',
|
|
269
|
-
active: false
|
|
270
|
-
}, {
|
|
271
|
-
color: '#FF8C16',
|
|
272
|
-
active: false
|
|
273
|
-
}, {
|
|
274
|
-
color: '#A00F20',
|
|
275
|
-
active: false
|
|
276
|
-
}]);
|
|
277
|
-
onReset();
|
|
278
|
-
},
|
|
296
|
+
onClick: handleResetClick,
|
|
279
297
|
children: `${_locale.default.ProThemeTools.reset}`
|
|
280
298
|
})]
|
|
281
299
|
});
|
|
@@ -23,6 +23,16 @@ interface ThemeContextType {
|
|
|
23
23
|
loadFromCache: (cacheState: ThemeStateType) => void;
|
|
24
24
|
}
|
|
25
25
|
declare const defaultThemeConfig: LocalThemeConfigType;
|
|
26
|
+
export declare const registerThemeUpdaters: (updaters: {
|
|
27
|
+
updateAntdConfig: (config: AntdThemeConfigType) => void;
|
|
28
|
+
updateCssVariables: (variables: Record<string, any>) => void;
|
|
29
|
+
updateLocalConfig: (config: Partial<LocalThemeConfigType>) => void;
|
|
30
|
+
}) => void;
|
|
31
|
+
export declare const getThemeUpdaters: () => {
|
|
32
|
+
updateAntdConfig: (config: AntdThemeConfigType) => void;
|
|
33
|
+
updateCssVariables: (variables: Record<string, any>) => void;
|
|
34
|
+
updateLocalConfig: (config: Partial<LocalThemeConfigType>) => void;
|
|
35
|
+
};
|
|
26
36
|
interface ThemeProviderProps {
|
|
27
37
|
children: ReactNode;
|
|
28
38
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useTheme = exports.defaultThemeConfig = exports.ThemeProvider = void 0;
|
|
6
|
+
exports.useTheme = exports.registerThemeUpdaters = exports.getThemeUpdaters = exports.defaultThemeConfig = exports.ThemeProvider = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -84,8 +84,28 @@ function themeReducer(state, action) {
|
|
|
84
84
|
// 创建 Context
|
|
85
85
|
var ThemeContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
86
86
|
|
|
87
|
-
//
|
|
87
|
+
// 全局更新函数注册机制,用于 setThemes 静态方法更新 Context
|
|
88
|
+
var globalUpdateAntdConfig = null;
|
|
89
|
+
var globalUpdateCssVariables = null;
|
|
90
|
+
var globalUpdateLocalConfig = null;
|
|
91
|
+
|
|
92
|
+
// 注册全局更新函数(由 ThemeProvider 调用)
|
|
93
|
+
var registerThemeUpdaters = updaters => {
|
|
94
|
+
globalUpdateAntdConfig = updaters.updateAntdConfig;
|
|
95
|
+
globalUpdateCssVariables = updaters.updateCssVariables;
|
|
96
|
+
globalUpdateLocalConfig = updaters.updateLocalConfig;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// 获取全局更新函数(供 setThemes 使用)
|
|
100
|
+
exports.registerThemeUpdaters = registerThemeUpdaters;
|
|
101
|
+
var getThemeUpdaters = () => ({
|
|
102
|
+
updateAntdConfig: globalUpdateAntdConfig,
|
|
103
|
+
updateCssVariables: globalUpdateCssVariables,
|
|
104
|
+
updateLocalConfig: globalUpdateLocalConfig
|
|
105
|
+
});
|
|
88
106
|
|
|
107
|
+
// Provider 组件
|
|
108
|
+
exports.getThemeUpdaters = getThemeUpdaters;
|
|
89
109
|
var ThemeProvider = _ref => {
|
|
90
110
|
var children = _ref.children;
|
|
91
111
|
var _useReducer = (0, _react.useReducer)(themeReducer, initialState),
|
|
@@ -121,6 +141,15 @@ var ThemeProvider = _ref => {
|
|
|
121
141
|
payload: cacheState
|
|
122
142
|
});
|
|
123
143
|
}, []);
|
|
144
|
+
|
|
145
|
+
// 注册全局更新函数,供 setThemes 静态方法使用
|
|
146
|
+
_react.default.useEffect(() => {
|
|
147
|
+
registerThemeUpdaters({
|
|
148
|
+
updateAntdConfig,
|
|
149
|
+
updateCssVariables,
|
|
150
|
+
updateLocalConfig
|
|
151
|
+
});
|
|
152
|
+
}, [updateAntdConfig, updateCssVariables, updateLocalConfig]);
|
|
124
153
|
var contextValue = {
|
|
125
154
|
state,
|
|
126
155
|
updateLocalConfig,
|
|
@@ -30,6 +30,7 @@ var _ThemeContext = require("./context/ThemeContext");
|
|
|
30
30
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
31
31
|
var _excluded = ["size", "className", "cacheTime", "color", "mode", "iconFollowTheme", "prefixCls", "tableBorder", "tableStripe", "theme", "onChange"];
|
|
32
32
|
/* eslint-disable prefer-const */
|
|
33
|
+
// 导入语句
|
|
33
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
35
|
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; }
|
|
35
36
|
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; }
|
|
@@ -90,6 +91,7 @@ var ProThemeTools = _ref => {
|
|
|
90
91
|
theme = _ref$theme === void 0 ? {} : _ref$theme,
|
|
91
92
|
onChange = _ref.onChange,
|
|
92
93
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
94
|
+
// Props 和基础 Hooks
|
|
93
95
|
var _useToggle = (0, _ahooks.useToggle)(false),
|
|
94
96
|
_useToggle2 = _slicedToArray(_useToggle, 2),
|
|
95
97
|
visible = _useToggle2[0],
|
|
@@ -98,16 +100,25 @@ var ProThemeTools = _ref => {
|
|
|
98
100
|
updateLocalConfig = _useTheme.updateLocalConfig,
|
|
99
101
|
updateAntdConfig = _useTheme.updateAntdConfig,
|
|
100
102
|
updateCssVariables = _useTheme.updateCssVariables;
|
|
103
|
+
|
|
104
|
+
// 状态和 Refs
|
|
101
105
|
var _useState = (0, _react.useState)(_objectSpread(_objectSpread({}, defaultThemeConfig), (0, _index.getMapHumpCase)(theme))),
|
|
102
106
|
_useState2 = _slicedToArray(_useState, 2),
|
|
103
107
|
state = _useState2[0],
|
|
104
108
|
setState = _useState2[1];
|
|
105
109
|
var previousState = (0, _ahooks.usePrevious)(state);
|
|
110
|
+
|
|
111
|
+
// 配置和计算值
|
|
106
112
|
var zauiBrand = state.zauiBrand,
|
|
107
113
|
zauiStripe = state.zauiStripe,
|
|
108
114
|
zauiTableBorder = state.zauiTableBorder;
|
|
115
|
+
var cls = (0, _classnames.default)({
|
|
116
|
+
'pro-theme-tools': true,
|
|
117
|
+
'pro-theme-tools-follow': iconFollowTheme,
|
|
118
|
+
[className]: className
|
|
119
|
+
});
|
|
109
120
|
|
|
110
|
-
//
|
|
121
|
+
// 事件处理函数
|
|
111
122
|
var onReset = () => {
|
|
112
123
|
var resetConfig = _objectSpread(_objectSpread({}, state), defaultThemeConfig);
|
|
113
124
|
setState(resetConfig);
|
|
@@ -139,8 +150,6 @@ var ProThemeTools = _ref => {
|
|
|
139
150
|
(0, _index.setThemes)(cssVars);
|
|
140
151
|
updateCssVariables(cssVars);
|
|
141
152
|
};
|
|
142
|
-
|
|
143
|
-
// 复制
|
|
144
153
|
var onCopy = () => {
|
|
145
154
|
var data = JSON.stringify((0, _index.getMapKebabCase)(state, '@'));
|
|
146
155
|
var input = document.createElement('input');
|
|
@@ -154,8 +163,17 @@ var ProThemeTools = _ref => {
|
|
|
154
163
|
document.body.removeChild(input);
|
|
155
164
|
};
|
|
156
165
|
|
|
166
|
+
// 所有 useEffect 集中放置
|
|
167
|
+
// 注册全局更新函数,供 setThemes 静态方法使用
|
|
168
|
+
(0, _react.useEffect)(() => {
|
|
169
|
+
(0, _index.setThemeUpdatersGetter)(() => (0, _ThemeContext.getThemeUpdaters)());
|
|
170
|
+
}, []);
|
|
171
|
+
|
|
157
172
|
// 首次从缓存中读取主题配置
|
|
158
173
|
(0, _react.useEffect)(() => {
|
|
174
|
+
var _document$documentEle;
|
|
175
|
+
// 检查 CSS 变量是否已被 setThemes 设置(优先级高于缓存)
|
|
176
|
+
var existingZauiBrand = (_document$documentEle = document.documentElement.style.getPropertyValue('--zaui-brand')) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.trim();
|
|
159
177
|
var themeConfig = localStorage.getItem('themeConfig');
|
|
160
178
|
var curThemeConfig = themeConfig ? JSON.parse(themeConfig) : {};
|
|
161
179
|
var startTime = curThemeConfig === null || curThemeConfig === void 0 ? void 0 : curThemeConfig.startTime;
|
|
@@ -165,6 +183,11 @@ var ProThemeTools = _ref => {
|
|
|
165
183
|
var _localThemeConfig;
|
|
166
184
|
var localThemeConfig;
|
|
167
185
|
localThemeConfig = curThemeConfig.data;
|
|
186
|
+
|
|
187
|
+
// 如果 CSS 变量已被 setThemes 设置,优先使用 CSS 变量的值
|
|
188
|
+
if (existingZauiBrand && existingZauiBrand !== localThemeConfig.zauiBrand) {
|
|
189
|
+
localThemeConfig.zauiBrand = existingZauiBrand;
|
|
190
|
+
}
|
|
168
191
|
var cssVariables = Object.fromEntries(Object.entries(localThemeConfig).map(item => [`${(0, _index.getKebabCase)(item === null || item === void 0 ? void 0 : item[0])}`, ['zauiSize'].includes(item === null || item === void 0 ? void 0 : item[0]) || typeof (item === null || item === void 0 ? void 0 : item[1]) !== 'number' ? item === null || item === void 0 ? void 0 : item[1] : `${item === null || item === void 0 ? void 0 : item[1]}px` // zauiSize取数字
|
|
169
192
|
]));
|
|
170
193
|
setState(_objectSpread(_objectSpread({}, state), localThemeConfig));
|
|
@@ -180,13 +203,20 @@ var ProThemeTools = _ref => {
|
|
|
180
203
|
});
|
|
181
204
|
updateAntdConfig(antdConfig);
|
|
182
205
|
} else {
|
|
183
|
-
|
|
206
|
+
// 如果 CSS 变量已被 setThemes 设置,优先使用 CSS 变量的值
|
|
207
|
+
var finalZauiBrand = state === null || state === void 0 ? void 0 : state.zauiBrand;
|
|
208
|
+
if (existingZauiBrand && existingZauiBrand !== (state === null || state === void 0 ? void 0 : state.zauiBrand)) {
|
|
209
|
+
finalZauiBrand = existingZauiBrand;
|
|
210
|
+
}
|
|
211
|
+
var cssVars = (0, _index.getMapKebabCase)(_objectSpread(_objectSpread({}, state), {}, {
|
|
212
|
+
zauiBrand: finalZauiBrand
|
|
213
|
+
}));
|
|
184
214
|
(0, _index.setThemes)(cssVars);
|
|
185
215
|
updateCssVariables(cssVars);
|
|
186
216
|
|
|
187
217
|
// 更新 antd 主题
|
|
188
218
|
var _antdConfig = (0, _index.getAntd5ThemeConfig)({
|
|
189
|
-
'zaui-brand':
|
|
219
|
+
'zaui-brand': finalZauiBrand
|
|
190
220
|
});
|
|
191
221
|
updateAntdConfig(_antdConfig);
|
|
192
222
|
}
|
|
@@ -247,11 +277,6 @@ var ProThemeTools = _ref => {
|
|
|
247
277
|
onChange === null || onChange === void 0 || onChange(state);
|
|
248
278
|
}
|
|
249
279
|
}, [state]);
|
|
250
|
-
var cls = (0, _classnames.default)({
|
|
251
|
-
'pro-theme-tools': true,
|
|
252
|
-
'pro-theme-tools-follow': iconFollowTheme,
|
|
253
|
-
[className]: className
|
|
254
|
-
});
|
|
255
280
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, props), {}, {
|
|
256
281
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
257
282
|
className: cls,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export interface ThemesProps {
|
|
2
2
|
[key: string]: any;
|
|
3
3
|
}
|
|
4
|
+
declare let getThemeUpdaters: (() => {
|
|
5
|
+
updateAntdConfig: ((config: any) => void) | null;
|
|
6
|
+
updateCssVariables: ((variables: Record<string, any>) => void) | null;
|
|
7
|
+
updateLocalConfig: ((config: any) => void) | null;
|
|
8
|
+
}) | null;
|
|
9
|
+
export declare const setThemeUpdatersGetter: (getter: typeof getThemeUpdaters) => void;
|
|
4
10
|
/**
|
|
5
11
|
* 将 kebab-case 的主题配置转换为 antd5 的 token 格式
|
|
6
12
|
* @param themes kebab-case 格式的主题配置
|
|
@@ -11,7 +17,8 @@ export declare const convertToAntd5Tokens: (themes: ThemesProps, themeMapping?:
|
|
|
11
17
|
};
|
|
12
18
|
/**
|
|
13
19
|
* 设置主题变量 - antd5 兼容版本
|
|
14
|
-
*
|
|
20
|
+
* 设置 CSS 变量,并同步更新 Context 的 antdConfig
|
|
21
|
+
* @param themes 主题配置对象,会自动过滤掉 antdConfig
|
|
15
22
|
*/
|
|
16
23
|
export declare const setThemes: (themes: ThemesProps) => boolean;
|
|
17
24
|
/**
|
|
@@ -39,3 +46,4 @@ export declare const setTableNoStripe: (stripe: boolean, prefixCls?: string) =>
|
|
|
39
46
|
* @param border boolean
|
|
40
47
|
*/
|
|
41
48
|
export declare const setTableBorder: (border: boolean) => void;
|
|
49
|
+
export {};
|
|
@@ -3,13 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setThemes = exports.setTableNoStripe = exports.setTableBorder = exports.getMapKebabCase = exports.getMapHumpCase = exports.getKebabCase = exports.getAntd5ThemeConfig = exports.convertToAntd5Tokens = void 0;
|
|
6
|
+
exports.setThemes = exports.setThemeUpdatersGetter = exports.setTableNoStripe = exports.setTableBorder = exports.getMapKebabCase = exports.getMapHumpCase = exports.getKebabCase = exports.getAntd5ThemeConfig = exports.convertToAntd5Tokens = void 0;
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
13
|
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; }
|
|
8
14
|
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; }
|
|
9
15
|
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; }
|
|
10
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
11
17
|
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); }
|
|
18
|
+
// 动态导入 getThemeUpdaters,避免循环依赖
|
|
19
|
+
var getThemeUpdaters = null;
|
|
20
|
+
|
|
21
|
+
// 设置 getThemeUpdaters 函数(由 index.tsx 调用)
|
|
22
|
+
var setThemeUpdatersGetter = getter => {
|
|
23
|
+
getThemeUpdaters = getter;
|
|
24
|
+
};
|
|
25
|
+
|
|
12
26
|
/** antd5 主题配置 mapping */
|
|
27
|
+
exports.setThemeUpdatersGetter = setThemeUpdatersGetter;
|
|
13
28
|
var antd5ConfigMapping = {
|
|
14
29
|
'zaui-brand': 'colorPrimary'
|
|
15
30
|
// 可以根据需要添加更多映射
|
|
@@ -37,7 +52,8 @@ var convertToAntd5Tokens = (themes, themeMapping) => {
|
|
|
37
52
|
|
|
38
53
|
/**
|
|
39
54
|
* 设置主题变量 - antd5 兼容版本
|
|
40
|
-
*
|
|
55
|
+
* 设置 CSS 变量,并同步更新 Context 的 antdConfig
|
|
56
|
+
* @param themes 主题配置对象,会自动过滤掉 antdConfig
|
|
41
57
|
*/
|
|
42
58
|
exports.convertToAntd5Tokens = convertToAntd5Tokens;
|
|
43
59
|
var setThemes = themes => {
|
|
@@ -45,11 +61,75 @@ var setThemes = themes => {
|
|
|
45
61
|
return false;
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
//
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
// 过滤掉 antdConfig,它只用于 Ant Design ConfigProvider,不应作为 CSS 变量
|
|
65
|
+
var filteredThemes = Object.entries(themes).filter(_ref => {
|
|
66
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
67
|
+
key = _ref2[0];
|
|
68
|
+
return key !== 'antdConfig';
|
|
52
69
|
});
|
|
70
|
+
if (!filteredThemes.length) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 设置 CSS 变量
|
|
75
|
+
filteredThemes.forEach(_ref3 => {
|
|
76
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
77
|
+
key = _ref4[0],
|
|
78
|
+
value = _ref4[1];
|
|
79
|
+
// 确保值是字符串或数字,对象类型不应作为 CSS 变量
|
|
80
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
81
|
+
var cssVarName = `--${key}`;
|
|
82
|
+
var cssVarValue = String(value);
|
|
83
|
+
document.documentElement.style.setProperty(cssVarName, cssVarValue);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 同步更新 Context(如果已注册)
|
|
88
|
+
if (getThemeUpdaters) {
|
|
89
|
+
var updaters = getThemeUpdaters();
|
|
90
|
+
|
|
91
|
+
// 更新 CSS 变量到 Context
|
|
92
|
+
if (updaters.updateCssVariables) {
|
|
93
|
+
updaters.updateCssVariables(filteredThemes.reduce((acc, _ref5) => {
|
|
94
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
95
|
+
key = _ref6[0],
|
|
96
|
+
value = _ref6[1];
|
|
97
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
98
|
+
acc[key] = value;
|
|
99
|
+
}
|
|
100
|
+
return acc;
|
|
101
|
+
}, {}));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 如果设置了 zaui-brand,同步更新 antdConfig
|
|
105
|
+
var zauiBrand = themes['zaui-brand'];
|
|
106
|
+
if (zauiBrand && typeof zauiBrand === 'string' && updaters.updateAntdConfig) {
|
|
107
|
+
var antdConfig = convertToAntd5Tokens({
|
|
108
|
+
'zaui-brand': zauiBrand
|
|
109
|
+
});
|
|
110
|
+
updaters.updateAntdConfig(antdConfig);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 更新本地配置(将 kebab-case 转换为驼峰格式)
|
|
114
|
+
if (updaters.updateLocalConfig) {
|
|
115
|
+
var localConfig = {};
|
|
116
|
+
filteredThemes.forEach(_ref7 => {
|
|
117
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
118
|
+
key = _ref8[0],
|
|
119
|
+
value = _ref8[1];
|
|
120
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
121
|
+
// 将 kebab-case 转换为驼峰格式
|
|
122
|
+
var camelKey = key.replace(/-(\w)/g, (_, letter) => letter.toUpperCase());
|
|
123
|
+
if (camelKey === 'zauiBrand') {
|
|
124
|
+
localConfig.zauiBrand = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (Object.keys(localConfig).length > 0) {
|
|
129
|
+
updaters.updateLocalConfig(localConfig);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
53
133
|
return true;
|
|
54
134
|
};
|
|
55
135
|
|