@vef-framework/shared 1.0.122 → 1.0.123
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/cjs/color.cjs +11 -0
- package/cjs/constants.cjs +39 -0
- package/cjs/context.cjs +36 -0
- package/cjs/dom.cjs +23 -0
- package/cjs/error.cjs +30 -0
- package/cjs/event.cjs +11 -0
- package/cjs/expression.cjs +27 -0
- package/cjs/function.cjs +16 -0
- package/cjs/icons.cjs +136 -0
- package/cjs/id.cjs +14 -0
- package/cjs/index.cjs +317 -0
- package/cjs/json.cjs +18 -0
- package/cjs/lib.cjs +232 -0
- package/cjs/message.cjs +303 -0
- package/cjs/path.cjs +40 -0
- package/cjs/pinyin.cjs +33 -0
- package/cjs/security.cjs +27 -0
- package/cjs/store.cjs +105 -0
- package/cjs/styles.cjs +55 -0
- package/cjs/temporal.cjs +27 -0
- package/cjs/theme-variables.cjs +354 -0
- package/cjs/types.cjs +4 -0
- package/cjs/utils.cjs +117 -0
- package/cjs/validation.cjs +189 -0
- package/cjs/yaml.cjs +11 -0
- package/esm/color.js +9 -0
- package/esm/constants.js +31 -0
- package/esm/context.js +34 -0
- package/esm/dom.js +21 -0
- package/esm/error.js +28 -0
- package/esm/event.js +9 -0
- package/esm/expression.js +23 -0
- package/esm/function.js +14 -0
- package/esm/icons.js +129 -0
- package/esm/id.js +12 -0
- package/esm/index.js +32 -0
- package/esm/json.js +16 -0
- package/esm/lib.js +21 -0
- package/esm/message.js +282 -0
- package/esm/path.js +33 -0
- package/esm/pinyin.js +30 -0
- package/esm/security.js +24 -0
- package/esm/store.js +100 -0
- package/esm/styles.js +51 -0
- package/esm/temporal.js +23 -0
- package/esm/theme-variables.js +352 -0
- package/esm/types.js +2 -0
- package/esm/utils.js +109 -0
- package/esm/validation.js +151 -0
- package/esm/yaml.js +9 -0
- package/package.json +11 -10
- package/es/color.js +0 -1
- package/es/constants.js +0 -1
- package/es/context.js +0 -1
- package/es/dom.js +0 -1
- package/es/error.js +0 -1
- package/es/event.js +0 -1
- package/es/expression.js +0 -1
- package/es/function.js +0 -1
- package/es/icons.js +0 -1
- package/es/id.js +0 -1
- package/es/index.js +0 -1
- package/es/json.js +0 -1
- package/es/lib.js +0 -1
- package/es/message.js +0 -1
- package/es/path.js +0 -1
- package/es/pinyin.js +0 -1
- package/es/security.js +0 -1
- package/es/store.js +0 -1
- package/es/styles.js +0 -1
- package/es/temporal.js +0 -1
- package/es/theme-variables.js +0 -1
- package/es/utils.js +0 -1
- package/es/validation.js +0 -1
- package/es/yaml.js +0 -1
- package/lib/color.cjs +0 -1
- package/lib/constants.cjs +0 -1
- package/lib/context.cjs +0 -1
- package/lib/dom.cjs +0 -1
- package/lib/error.cjs +0 -1
- package/lib/event.cjs +0 -1
- package/lib/expression.cjs +0 -1
- package/lib/function.cjs +0 -1
- package/lib/icons.cjs +0 -1
- package/lib/id.cjs +0 -1
- package/lib/index.cjs +0 -1
- package/lib/json.cjs +0 -1
- package/lib/lib.cjs +0 -1
- package/lib/message.cjs +0 -1
- package/lib/path.cjs +0 -1
- package/lib/pinyin.cjs +0 -1
- package/lib/security.cjs +0 -1
- package/lib/store.cjs +0 -1
- package/lib/styles.cjs +0 -1
- package/lib/temporal.cjs +0 -1
- package/lib/theme-variables.cjs +0 -1
- package/lib/types.cjs +0 -1
- package/lib/utils.cjs +0 -1
- package/lib/validation.cjs +0 -1
- package/lib/yaml.cjs +0 -1
package/esm/message.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import Icon from '@ant-design/icons';
|
|
3
|
+
import { Modal, message, notification } from 'antd';
|
|
4
|
+
import { createElement } from 'react';
|
|
5
|
+
import { IconCheck, IconTickCircle, IconInfoCircle, IconAlertTriangle, IconAlertCircle } from './icons.js';
|
|
6
|
+
import './lib.js';
|
|
7
|
+
import { isFunction } from 'radashi';
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
const {
|
|
11
|
+
confirm,
|
|
12
|
+
info,
|
|
13
|
+
success,
|
|
14
|
+
warning,
|
|
15
|
+
error
|
|
16
|
+
} = Modal;
|
|
17
|
+
const checkIcon = createElement(Icon, {
|
|
18
|
+
component: IconCheck
|
|
19
|
+
});
|
|
20
|
+
const successIcon = createElement(Icon, {
|
|
21
|
+
component: IconTickCircle
|
|
22
|
+
});
|
|
23
|
+
const infoIcon = createElement(Icon, {
|
|
24
|
+
component: IconInfoCircle
|
|
25
|
+
});
|
|
26
|
+
const warningIcon = createElement(Icon, {
|
|
27
|
+
component: IconAlertTriangle
|
|
28
|
+
});
|
|
29
|
+
const errorIcon = createElement(Icon, {
|
|
30
|
+
component: IconAlertCircle
|
|
31
|
+
});
|
|
32
|
+
const notificationSuccessIcon = createElement(Icon, {
|
|
33
|
+
className: "vef-notification-notice-icon vef-notification-notice-icon-success",
|
|
34
|
+
component: IconTickCircle
|
|
35
|
+
});
|
|
36
|
+
const notificationInfoIcon = createElement(Icon, {
|
|
37
|
+
className: "vef-notification-notice-icon vef-notification-notice-icon-info",
|
|
38
|
+
component: IconInfoCircle
|
|
39
|
+
});
|
|
40
|
+
const notificationWarningIcon = createElement(Icon, {
|
|
41
|
+
className: "vef-notification-notice-icon vef-notification-notice-icon-warning",
|
|
42
|
+
component: IconAlertTriangle
|
|
43
|
+
});
|
|
44
|
+
const notificationErrorIcon = createElement(Icon, {
|
|
45
|
+
className: "vef-notification-notice-icon vef-notification-notice-icon-error",
|
|
46
|
+
component: IconAlertCircle
|
|
47
|
+
});
|
|
48
|
+
function showSuccessMessage(content) {
|
|
49
|
+
message.open({
|
|
50
|
+
type: "success",
|
|
51
|
+
content,
|
|
52
|
+
duration: 2,
|
|
53
|
+
icon: successIcon
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function showInfoMessage(content) {
|
|
57
|
+
message.open({
|
|
58
|
+
type: "info",
|
|
59
|
+
content,
|
|
60
|
+
duration: 3,
|
|
61
|
+
icon: infoIcon
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function showWarningMessage(content) {
|
|
65
|
+
message.open({
|
|
66
|
+
type: "warning",
|
|
67
|
+
content,
|
|
68
|
+
duration: 3,
|
|
69
|
+
icon: warningIcon
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function showErrorMessage(content) {
|
|
73
|
+
message.open({
|
|
74
|
+
type: "error",
|
|
75
|
+
content,
|
|
76
|
+
duration: 4,
|
|
77
|
+
icon: errorIcon
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function showLoadingMessage(content) {
|
|
81
|
+
const close = message.open({
|
|
82
|
+
type: "loading",
|
|
83
|
+
content,
|
|
84
|
+
duration: 0
|
|
85
|
+
});
|
|
86
|
+
return () => close();
|
|
87
|
+
}
|
|
88
|
+
const defaultMessageTitle = "提示";
|
|
89
|
+
function showSuccessNotification(titleOrContent, content, buttons) {
|
|
90
|
+
const argsLength = arguments.length;
|
|
91
|
+
if (argsLength < 1) {
|
|
92
|
+
throw new Error("showSuccessNotification requires at least one argument");
|
|
93
|
+
}
|
|
94
|
+
const titleToUse = argsLength > 1 ? titleOrContent : defaultMessageTitle;
|
|
95
|
+
const contentToUse = argsLength > 1 ? content : titleOrContent;
|
|
96
|
+
const buttonsToUse = argsLength === 3 ? buttons : void 0;
|
|
97
|
+
notification.open({
|
|
98
|
+
type: "success",
|
|
99
|
+
message: titleToUse,
|
|
100
|
+
description: contentToUse,
|
|
101
|
+
duration: 4,
|
|
102
|
+
closable: true,
|
|
103
|
+
btn: buttonsToUse,
|
|
104
|
+
icon: notificationSuccessIcon
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function showInfoNotification(titleOrContent, content, buttons) {
|
|
108
|
+
const argsLength = arguments.length;
|
|
109
|
+
if (argsLength < 1) {
|
|
110
|
+
throw new Error("showInfoNotification requires at least one argument");
|
|
111
|
+
}
|
|
112
|
+
const titleToUse = argsLength > 1 ? titleOrContent : defaultMessageTitle;
|
|
113
|
+
const contentToUse = argsLength > 1 ? content : titleOrContent;
|
|
114
|
+
const buttonsToUse = argsLength === 3 ? buttons : void 0;
|
|
115
|
+
notification.open({
|
|
116
|
+
type: "info",
|
|
117
|
+
message: titleToUse,
|
|
118
|
+
description: contentToUse,
|
|
119
|
+
duration: 5,
|
|
120
|
+
closable: true,
|
|
121
|
+
btn: buttonsToUse,
|
|
122
|
+
icon: notificationInfoIcon
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function showWarningNotification(titleOrContent, content, buttons) {
|
|
126
|
+
const argsLength = arguments.length;
|
|
127
|
+
if (argsLength < 1) {
|
|
128
|
+
throw new Error("showWarningNotification requires at least one argument");
|
|
129
|
+
}
|
|
130
|
+
const titleToUse = argsLength > 1 ? titleOrContent : defaultMessageTitle;
|
|
131
|
+
const contentToUse = argsLength > 1 ? content : titleOrContent;
|
|
132
|
+
const buttonsToUse = argsLength === 3 ? buttons : void 0;
|
|
133
|
+
notification.open({
|
|
134
|
+
type: "warning",
|
|
135
|
+
message: titleToUse,
|
|
136
|
+
description: contentToUse,
|
|
137
|
+
duration: 6,
|
|
138
|
+
closable: true,
|
|
139
|
+
btn: buttonsToUse,
|
|
140
|
+
icon: notificationWarningIcon
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function showErrorNotification(titleOrContent, content, buttons) {
|
|
144
|
+
const argsLength = arguments.length;
|
|
145
|
+
if (argsLength < 1) {
|
|
146
|
+
throw new Error("showErrorNotification requires at least one argument");
|
|
147
|
+
}
|
|
148
|
+
const titleToUse = argsLength > 1 ? titleOrContent : defaultMessageTitle;
|
|
149
|
+
const contentToUse = argsLength > 1 ? content : titleOrContent;
|
|
150
|
+
const buttonsToUse = argsLength === 3 ? buttons : void 0;
|
|
151
|
+
notification.open({
|
|
152
|
+
type: "error",
|
|
153
|
+
message: titleToUse,
|
|
154
|
+
description: contentToUse,
|
|
155
|
+
duration: 10,
|
|
156
|
+
closable: true,
|
|
157
|
+
btn: buttonsToUse,
|
|
158
|
+
icon: notificationErrorIcon
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const cancelButtonProps = {
|
|
162
|
+
color: "default",
|
|
163
|
+
variant: "text"
|
|
164
|
+
};
|
|
165
|
+
const okButtonProps = {
|
|
166
|
+
icon: checkIcon
|
|
167
|
+
};
|
|
168
|
+
function showConfirmation(title, content, onOk, options) {
|
|
169
|
+
const argsLength = arguments.length;
|
|
170
|
+
if (argsLength < 2) {
|
|
171
|
+
throw new Error("showConfirmation requires at least two arguments");
|
|
172
|
+
}
|
|
173
|
+
const titleToUse = argsLength > 2 ? title : "提示";
|
|
174
|
+
const contentToUse = argsLength === 2 ? title : content;
|
|
175
|
+
const onOkToUse = argsLength === 2 ? content : onOk;
|
|
176
|
+
const {
|
|
177
|
+
okText,
|
|
178
|
+
cancelText,
|
|
179
|
+
onCancel,
|
|
180
|
+
onAfterOpen,
|
|
181
|
+
onAfterClose
|
|
182
|
+
} = options ?? {};
|
|
183
|
+
const { destroy } = confirm({
|
|
184
|
+
title: titleToUse,
|
|
185
|
+
content: contentToUse,
|
|
186
|
+
cancelButtonProps,
|
|
187
|
+
okButtonProps,
|
|
188
|
+
centered: true,
|
|
189
|
+
onOk: onOkToUse,
|
|
190
|
+
okText,
|
|
191
|
+
cancelText,
|
|
192
|
+
onCancel,
|
|
193
|
+
afterOpenChange: isFunction(onAfterOpen) || isFunction(onAfterClose) ? (open) => {
|
|
194
|
+
if (open) {
|
|
195
|
+
onAfterOpen?.();
|
|
196
|
+
} else {
|
|
197
|
+
onAfterClose?.();
|
|
198
|
+
}
|
|
199
|
+
} : void 0
|
|
200
|
+
});
|
|
201
|
+
return destroy;
|
|
202
|
+
}
|
|
203
|
+
const alertFnMap = {
|
|
204
|
+
success,
|
|
205
|
+
info,
|
|
206
|
+
warning,
|
|
207
|
+
error
|
|
208
|
+
};
|
|
209
|
+
const alertIconMap = {
|
|
210
|
+
success: successIcon,
|
|
211
|
+
info: infoIcon,
|
|
212
|
+
warning: warningIcon,
|
|
213
|
+
error: errorIcon
|
|
214
|
+
};
|
|
215
|
+
const defaultOkText = "👍🏻 好的,知道了";
|
|
216
|
+
function showAlert(type, content, title = defaultMessageTitle, onOk, options) {
|
|
217
|
+
const {
|
|
218
|
+
okText = defaultOkText,
|
|
219
|
+
onCancel,
|
|
220
|
+
onAfterOpen,
|
|
221
|
+
onAfterClose
|
|
222
|
+
} = options ?? {};
|
|
223
|
+
const { destroy } = alertFnMap[type]({
|
|
224
|
+
title,
|
|
225
|
+
content,
|
|
226
|
+
icon: alertIconMap[type],
|
|
227
|
+
centered: true,
|
|
228
|
+
onOk,
|
|
229
|
+
okText,
|
|
230
|
+
onCancel,
|
|
231
|
+
afterOpenChange: isFunction(onAfterOpen) || isFunction(onAfterClose) ? (open) => {
|
|
232
|
+
if (open) {
|
|
233
|
+
onAfterOpen?.();
|
|
234
|
+
} else {
|
|
235
|
+
onAfterClose?.();
|
|
236
|
+
}
|
|
237
|
+
} : void 0
|
|
238
|
+
});
|
|
239
|
+
return destroy;
|
|
240
|
+
}
|
|
241
|
+
function showSuccessAlert(title, content, onOk, options) {
|
|
242
|
+
const argsLength = arguments.length;
|
|
243
|
+
if (argsLength < 1) {
|
|
244
|
+
throw new Error("showSuccessAlert requires at least one argument");
|
|
245
|
+
}
|
|
246
|
+
const titleToUse = argsLength === 1 || isFunction(content) ? void 0 : title;
|
|
247
|
+
const contentToUse = argsLength === 1 || isFunction(content) ? title : content;
|
|
248
|
+
const onOkToUse = argsLength === 2 || isFunction(content) ? content : onOk;
|
|
249
|
+
return showAlert("success", contentToUse, titleToUse, onOkToUse, options);
|
|
250
|
+
}
|
|
251
|
+
function showInfoAlert(title, content, onOk, options) {
|
|
252
|
+
const argsLength = arguments.length;
|
|
253
|
+
if (argsLength < 1) {
|
|
254
|
+
throw new Error("showInfoAlert requires at least one argument");
|
|
255
|
+
}
|
|
256
|
+
const titleToUse = argsLength === 1 || isFunction(content) ? void 0 : title;
|
|
257
|
+
const contentToUse = argsLength === 1 || isFunction(content) ? title : content;
|
|
258
|
+
const onOkToUse = argsLength === 2 || isFunction(content) ? content : onOk;
|
|
259
|
+
return showAlert("info", contentToUse, titleToUse, onOkToUse, options);
|
|
260
|
+
}
|
|
261
|
+
function showWarningAlert(title, content, onOk, options) {
|
|
262
|
+
const argsLength = arguments.length;
|
|
263
|
+
if (argsLength < 1) {
|
|
264
|
+
throw new Error("showWarningAlert requires at least one argument");
|
|
265
|
+
}
|
|
266
|
+
const titleToUse = argsLength === 1 || isFunction(content) ? void 0 : title;
|
|
267
|
+
const contentToUse = argsLength === 1 || isFunction(content) ? title : content;
|
|
268
|
+
const onOkToUse = argsLength === 2 || isFunction(content) ? content : onOk;
|
|
269
|
+
return showAlert("warning", contentToUse, titleToUse, onOkToUse, options);
|
|
270
|
+
}
|
|
271
|
+
function showErrorAlert(title, content, onOk, options) {
|
|
272
|
+
const argsLength = arguments.length;
|
|
273
|
+
if (argsLength < 1) {
|
|
274
|
+
throw new Error("showErrorAlert requires at least one argument");
|
|
275
|
+
}
|
|
276
|
+
const titleToUse = argsLength === 1 || isFunction(content) ? void 0 : title;
|
|
277
|
+
const contentToUse = argsLength === 1 || isFunction(content) ? title : content;
|
|
278
|
+
const onOkToUse = argsLength === 2 || isFunction(content) ? content : onOk;
|
|
279
|
+
return showAlert("error", contentToUse, titleToUse, onOkToUse, options);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { checkIcon, defaultMessageTitle, errorIcon, infoIcon, showConfirmation, showErrorAlert, showErrorMessage, showErrorNotification, showInfoAlert, showInfoMessage, showInfoNotification, showLoadingMessage, showSuccessAlert, showSuccessMessage, showSuccessNotification, showWarningAlert, showWarningMessage, showWarningNotification, successIcon, warningIcon };
|
package/esm/path.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import path from 'path-browserify';
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
const {
|
|
6
|
+
basename,
|
|
7
|
+
dirname,
|
|
8
|
+
extname,
|
|
9
|
+
isAbsolute,
|
|
10
|
+
join,
|
|
11
|
+
normalize
|
|
12
|
+
} = path;
|
|
13
|
+
function extractBaseName(path2, keepExt = true) {
|
|
14
|
+
const ext = keepExt ? void 0 : extname(path2);
|
|
15
|
+
return basename(path2, ext);
|
|
16
|
+
}
|
|
17
|
+
function extractExtName(path2) {
|
|
18
|
+
return extname(path2);
|
|
19
|
+
}
|
|
20
|
+
function extractDirName(path2) {
|
|
21
|
+
return dirname(path2);
|
|
22
|
+
}
|
|
23
|
+
function joinPaths(...paths) {
|
|
24
|
+
return join(...paths);
|
|
25
|
+
}
|
|
26
|
+
function isAbsolutePath(path2) {
|
|
27
|
+
return isAbsolute(path2);
|
|
28
|
+
}
|
|
29
|
+
function normalizePath(path2) {
|
|
30
|
+
return normalize(path2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { extractBaseName, extractDirName, extractExtName, isAbsolutePath, joinPaths, normalizePath };
|
package/esm/pinyin.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { pinyin } from 'pinyin-pro';
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
function parsePinyin(text) {
|
|
6
|
+
return pinyin(
|
|
7
|
+
text,
|
|
8
|
+
{
|
|
9
|
+
pattern: "pinyin",
|
|
10
|
+
toneType: "none",
|
|
11
|
+
type: "array",
|
|
12
|
+
mode: "normal",
|
|
13
|
+
nonZh: "consecutive"
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function parsePinyinFirstLetter(text) {
|
|
18
|
+
return pinyin(
|
|
19
|
+
text,
|
|
20
|
+
{
|
|
21
|
+
pattern: "first",
|
|
22
|
+
toneType: "none",
|
|
23
|
+
type: "array",
|
|
24
|
+
mode: "normal",
|
|
25
|
+
nonZh: "consecutive"
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { parsePinyin, parsePinyinFirstLetter };
|
package/esm/security.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import JSEncrypt from 'jsencrypt';
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
function encryptRsa(value, publicKey) {
|
|
6
|
+
const rsa = new JSEncrypt();
|
|
7
|
+
rsa.setPublicKey(publicKey);
|
|
8
|
+
const encrypted = rsa.encrypt(value);
|
|
9
|
+
if (!encrypted) {
|
|
10
|
+
throw new Error(`Failed to encrypt value [${value}] using RSA`);
|
|
11
|
+
}
|
|
12
|
+
return encrypted;
|
|
13
|
+
}
|
|
14
|
+
function decryptRsa(value, privateKey) {
|
|
15
|
+
const rsa = new JSEncrypt();
|
|
16
|
+
rsa.setPrivateKey(privateKey);
|
|
17
|
+
const decrypted = rsa.decrypt(value);
|
|
18
|
+
if (!decrypted) {
|
|
19
|
+
throw new Error(`Failed to decrypt value [${value}] using RSA`);
|
|
20
|
+
}
|
|
21
|
+
return decrypted;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { decryptRsa, encryptRsa };
|
package/esm/store.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { createContext, useState, useRef, useEffect, createElement, useContext } from 'react';
|
|
3
|
+
import { createJSONStorage, persist, subscribeWithSelector } from 'zustand/middleware';
|
|
4
|
+
import { createWithEqualityFn, useStoreWithEqualityFn } from 'zustand/traditional';
|
|
5
|
+
import { createStore as createStore$1 } from 'zustand/vanilla';
|
|
6
|
+
import './lib.js';
|
|
7
|
+
import { constantCase } from './utils.js';
|
|
8
|
+
import { isNullish } from 'radashi';
|
|
9
|
+
import { shallow } from 'zustand/shallow';
|
|
10
|
+
|
|
11
|
+
"use strict";
|
|
12
|
+
function createStorageProxy(storage) {
|
|
13
|
+
const delegate = createJSONStorage(() => storage === "local" ? localStorage : sessionStorage);
|
|
14
|
+
return {
|
|
15
|
+
getItem: delegate.getItem,
|
|
16
|
+
setItem(name, value) {
|
|
17
|
+
if (isNullish(value.state)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
delegate.setItem(name, value);
|
|
21
|
+
},
|
|
22
|
+
removeItem: delegate.removeItem
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createStore(stateCreator, persistenceOptions) {
|
|
26
|
+
const name = persistenceOptions?.name ?? "UNKNOWN";
|
|
27
|
+
const storage = persistenceOptions?.storage ?? "local";
|
|
28
|
+
const selector = persistenceOptions ? persistenceOptions.selector : () => null;
|
|
29
|
+
const storageInstance = createStorageProxy(storage);
|
|
30
|
+
return createWithEqualityFn(
|
|
31
|
+
persist(
|
|
32
|
+
subscribeWithSelector(stateCreator),
|
|
33
|
+
{
|
|
34
|
+
name: `__VEF_STORE__${constantCase(name)}__`,
|
|
35
|
+
storage: storageInstance,
|
|
36
|
+
version: 1,
|
|
37
|
+
partialize: selector
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
shallow
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function createUnboundStore(stateCreator) {
|
|
44
|
+
return createStore$1(
|
|
45
|
+
subscribeWithSelector(stateCreator)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function useUnboundStore(store, selector, equalityFn) {
|
|
49
|
+
return useStoreWithEqualityFn(
|
|
50
|
+
store,
|
|
51
|
+
selector,
|
|
52
|
+
equalityFn ?? shallow
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function createComponentStore(name, getStateCreator) {
|
|
56
|
+
const StoreContext = createContext(null);
|
|
57
|
+
const StoreProvider = ({ initialState, children }) => {
|
|
58
|
+
const [store] = useState(() => {
|
|
59
|
+
const creator = getStateCreator(initialState);
|
|
60
|
+
return createUnboundStore(creator);
|
|
61
|
+
});
|
|
62
|
+
const isMounted = useRef(false);
|
|
63
|
+
useEffect(() => () => {
|
|
64
|
+
isMounted.current = false;
|
|
65
|
+
}, []);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!isMounted.current) {
|
|
68
|
+
isMounted.current = true;
|
|
69
|
+
}
|
|
70
|
+
if (initialState) {
|
|
71
|
+
store.setState({
|
|
72
|
+
...initialState
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, [initialState, store]);
|
|
76
|
+
return createElement(
|
|
77
|
+
StoreContext.Provider,
|
|
78
|
+
{ value: store },
|
|
79
|
+
children
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const useStoreApi = () => {
|
|
83
|
+
const store = useContext(StoreContext);
|
|
84
|
+
if (!store) {
|
|
85
|
+
throw new Error(`${name}Store can be used only inside ${name}StoreProvider`);
|
|
86
|
+
}
|
|
87
|
+
return store;
|
|
88
|
+
};
|
|
89
|
+
const useStore = (selector) => useUnboundStore(
|
|
90
|
+
useStoreApi(),
|
|
91
|
+
selector
|
|
92
|
+
);
|
|
93
|
+
return {
|
|
94
|
+
StoreProvider,
|
|
95
|
+
useStore,
|
|
96
|
+
useStoreApi
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { createComponentStore, createStore, createUnboundStore, useUnboundStore };
|
package/esm/styles.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { css } from '@emotion/react';
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
const breakpointWidths = {
|
|
6
|
+
xs: 0,
|
|
7
|
+
sm: 576,
|
|
8
|
+
md: 768,
|
|
9
|
+
lg: 992,
|
|
10
|
+
xl: 1200,
|
|
11
|
+
xxl: 1400
|
|
12
|
+
};
|
|
13
|
+
const breakpoints = [
|
|
14
|
+
"xs",
|
|
15
|
+
"sm",
|
|
16
|
+
"md",
|
|
17
|
+
"lg",
|
|
18
|
+
"xl",
|
|
19
|
+
"xxl"
|
|
20
|
+
];
|
|
21
|
+
const bmq = Object.keys(breakpointWidths).reduce(
|
|
22
|
+
(acc, label) => {
|
|
23
|
+
acc[label] = `@media (min-width: ${breakpointWidths[label]}px)`;
|
|
24
|
+
return acc;
|
|
25
|
+
},
|
|
26
|
+
{}
|
|
27
|
+
);
|
|
28
|
+
const styles = {
|
|
29
|
+
// Flex center style
|
|
30
|
+
flexCenter: css({
|
|
31
|
+
display: "flex",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
alignItems: "center"
|
|
34
|
+
}),
|
|
35
|
+
// Full height style
|
|
36
|
+
fullHeight: css({
|
|
37
|
+
height: "100%"
|
|
38
|
+
}),
|
|
39
|
+
// Full width style
|
|
40
|
+
fullWidth: css({
|
|
41
|
+
width: "100%"
|
|
42
|
+
}),
|
|
43
|
+
// Scrollbar style
|
|
44
|
+
scrollbar: css({
|
|
45
|
+
scrollbarWidth: "thin",
|
|
46
|
+
scrollbarColor: "rgba(0, 0, 0, 0.3) transparent",
|
|
47
|
+
scrollbarGutter: "stable"
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { bmq, breakpoints, styles };
|
package/esm/temporal.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { tz } from '@date-fns/tz';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
|
+
import { zhCN } from 'date-fns/locale';
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
function getNowDate() {
|
|
8
|
+
return /* @__PURE__ */ new Date();
|
|
9
|
+
}
|
|
10
|
+
function getNowDateString() {
|
|
11
|
+
return format(getNowDate(), "yyyy-MM-dd", {
|
|
12
|
+
locale: zhCN,
|
|
13
|
+
in: tz("Asia/Shanghai")
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function getTodayString() {
|
|
17
|
+
return format(getNowDate(), "PPPPpp", {
|
|
18
|
+
locale: zhCN,
|
|
19
|
+
in: tz("Asia/Shanghai")
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getNowDate, getNowDateString, getTodayString };
|