@kupola/kupola 1.2.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/CHANGELOG.md +130 -0
- package/INTEGRATION.md +440 -0
- package/PROJECT_SUMMARY.md +312 -0
- package/README.md +286 -0
- package/SKILL.md +572 -0
- package/css/accessibility.css +119 -0
- package/css/animations.css +224 -0
- package/css/brand-themes.css +300 -0
- package/css/colors_and_type.css +441 -0
- package/css/components-ext.css +4165 -0
- package/css/components.css +1483 -0
- package/css/kupola.css +12 -0
- package/css/responsive.css +697 -0
- package/css/scaffold.css +145 -0
- package/css/states.css +316 -0
- package/css/theme-dark.css +296 -0
- package/css/theme-light.css +296 -0
- package/css/utilities.css +171 -0
- package/dist/css/kupola.css +12 -0
- package/dist/icons/icons/activity.svg +3 -0
- package/dist/icons/icons/alert-circle.svg +1 -0
- package/dist/icons/icons/alert-triangle.svg +1 -0
- package/dist/icons/icons/alert.d27e24.svg +1 -0
- package/dist/icons/icons/alert.svg +1 -0
- package/dist/icons/icons/apple.svg +1 -0
- package/dist/icons/icons/arrow-down.svg +1 -0
- package/dist/icons/icons/arrow-expand.svg +1 -0
- package/dist/icons/icons/arrow-left.svg +1 -0
- package/dist/icons/icons/arrow-minimize.svg +1 -0
- package/dist/icons/icons/arrow-right-to-line.svg +1 -0
- package/dist/icons/icons/arrow-right.svg +1 -0
- package/dist/icons/icons/arrow-up-right.svg +1 -0
- package/dist/icons/icons/arrow-up.0c0c0d.svg +1 -0
- package/dist/icons/icons/arrow-up.svg +1 -0
- package/dist/icons/icons/at.svg +1 -0
- package/dist/icons/icons/atom.0c0c0d.svg +1 -0
- package/dist/icons/icons/atom.svg +1 -0
- package/dist/icons/icons/bar-chart-2.svg +1 -0
- package/dist/icons/icons/bar.svg +1 -0
- package/dist/icons/icons/bell.svg +1 -0
- package/dist/icons/icons/box.svg +1 -0
- package/dist/icons/icons/bug.svg +1 -0
- package/dist/icons/icons/button.svg +1 -0
- package/dist/icons/icons/calendar.svg +1 -0
- package/dist/icons/icons/check-circle.33c192.svg +1 -0
- package/dist/icons/icons/check-circle.svg +1 -0
- package/dist/icons/icons/check-square.svg +4 -0
- package/dist/icons/icons/check.d1d3db.svg +1 -0
- package/dist/icons/icons/check.svg +1 -0
- package/dist/icons/icons/chevron-down.svg +1 -0
- package/dist/icons/icons/chevron-left.svg +1 -0
- package/dist/icons/icons/chevron-right.svg +1 -0
- package/dist/icons/icons/chevron-up.svg +1 -0
- package/dist/icons/icons/circle.svg +1 -0
- package/dist/icons/icons/clock.svg +1 -0
- package/dist/icons/icons/cmd.svg +1 -0
- package/dist/icons/icons/code.svg +1 -0
- package/dist/icons/icons/columns.svg +1 -0
- package/dist/icons/icons/copy.svg +1 -0
- package/dist/icons/icons/cpu.svg +1 -0
- package/dist/icons/icons/dashboard.0c0c0d.svg +1 -0
- package/dist/icons/icons/dashboard.svg +1 -0
- package/dist/icons/icons/dollar.svg +1 -0
- package/dist/icons/icons/download.svg +1 -0
- package/dist/icons/icons/edit.svg +1 -0
- package/dist/icons/icons/extensions.svg +1 -0
- package/dist/icons/icons/external.svg +1 -0
- package/dist/icons/icons/eye.svg +1 -0
- package/dist/icons/icons/file-text.svg +1 -0
- package/dist/icons/icons/file.svg +1 -0
- package/dist/icons/icons/files.svg +1 -0
- package/dist/icons/icons/filter.svg +1 -0
- package/dist/icons/icons/folder-open.svg +4 -0
- package/dist/icons/icons/folder.svg +1 -0
- package/dist/icons/icons/gear.svg +1 -0
- package/dist/icons/icons/git.svg +1 -0
- package/dist/icons/icons/github.svg +1 -0
- package/dist/icons/icons/globe.svg +1 -0
- package/dist/icons/icons/grid-2x2.svg +1 -0
- package/dist/icons/icons/hash.svg +1 -0
- package/dist/icons/icons/heart.svg +1 -0
- package/dist/icons/icons/help-circle.svg +5 -0
- package/dist/icons/icons/help.svg +1 -0
- package/dist/icons/icons/home.svg +1 -0
- package/dist/icons/icons/icons.svg +153 -0
- package/dist/icons/icons/image.svg +1 -0
- package/dist/icons/icons/info-circle.svg +1 -0
- package/dist/icons/icons/info-square.svg +1 -0
- package/dist/icons/icons/info.387bff.svg +1 -0
- package/dist/icons/icons/info.svg +1 -0
- package/dist/icons/icons/input.svg +1 -0
- package/dist/icons/icons/key.svg +1 -0
- package/dist/icons/icons/layers.svg +1 -0
- package/dist/icons/icons/layout-grid.svg +6 -0
- package/dist/icons/icons/layout.svg +1 -0
- package/dist/icons/icons/link.svg +1 -0
- package/dist/icons/icons/list.svg +1 -0
- package/dist/icons/icons/lock.svg +1 -0
- package/dist/icons/icons/log-out.svg +1 -0
- package/dist/icons/icons/logo.svg +1 -0
- package/dist/icons/icons/mail.svg +1 -0
- package/dist/icons/icons/menu.svg +1 -0
- package/dist/icons/icons/message-circle.svg +1 -0
- package/dist/icons/icons/message-plus.svg +1 -0
- package/dist/icons/icons/message-square.svg +1 -0
- package/dist/icons/icons/mic.svg +1 -0
- package/dist/icons/icons/minus.svg +1 -0
- package/dist/icons/icons/moon.svg +1 -0
- package/dist/icons/icons/more-h.svg +1 -0
- package/dist/icons/icons/mouse.svg +1 -0
- package/dist/icons/icons/palette.svg +1 -0
- package/dist/icons/icons/panel-bottom.svg +1 -0
- package/dist/icons/icons/pause.svg +1 -0
- package/dist/icons/icons/play.svg +1 -0
- package/dist/icons/icons/plug.svg +1 -0
- package/dist/icons/icons/plus.0c0c0d.svg +1 -0
- package/dist/icons/icons/plus.svg +1 -0
- package/dist/icons/icons/refresh.svg +1 -0
- package/dist/icons/icons/ruler.svg +1 -0
- package/dist/icons/icons/scroll-text.svg +1 -0
- package/dist/icons/icons/search-menu.svg +1 -0
- package/dist/icons/icons/search.svg +1 -0
- package/dist/icons/icons/send.0c0c0d.svg +1 -0
- package/dist/icons/icons/send.svg +1 -0
- package/dist/icons/icons/settings.0c0c0d.svg +1 -0
- package/dist/icons/icons/settings.svg +1 -0
- package/dist/icons/icons/shield.svg +1 -0
- package/dist/icons/icons/sidebar-left.svg +1 -0
- package/dist/icons/icons/sidebar-right.svg +1 -0
- package/dist/icons/icons/sliders.svg +1 -0
- package/dist/icons/icons/sparkles.32f08c.svg +1 -0
- package/dist/icons/icons/sparkles.svg +1 -0
- package/dist/icons/icons/square.svg +1 -0
- package/dist/icons/icons/star.svg +1 -0
- package/dist/icons/icons/sun.svg +1 -0
- package/dist/icons/icons/table.svg +1 -0
- package/dist/icons/icons/terminal.svg +1 -0
- package/dist/icons/icons/trash.svg +1 -0
- package/dist/icons/icons/trending-down.svg +1 -0
- package/dist/icons/icons/trending-up.svg +1 -0
- package/dist/icons/icons/type.svg +1 -0
- package/dist/icons/icons/upload.svg +1 -0
- package/dist/icons/icons/user-circle.svg +1 -0
- package/dist/icons/icons/user-plus.svg +6 -0
- package/dist/icons/icons/user.svg +1 -0
- package/dist/icons/icons/users.svg +1 -0
- package/dist/icons/icons/warning.svg +1 -0
- package/dist/icons/icons/wrench.svg +1 -0
- package/dist/icons/icons/x-circle.svg +1 -0
- package/dist/icons/icons/x.svg +1 -0
- package/dist/icons/icons/zap.0c0c0d.svg +1 -0
- package/dist/icons/icons/zap.svg +1 -0
- package/dist/kupola.cjs.js +258 -0
- package/dist/kupola.cjs.js.map +1 -0
- package/dist/kupola.esm.js +7640 -0
- package/dist/kupola.esm.js.map +1 -0
- package/dist/kupola.umd.js +258 -0
- package/dist/kupola.umd.js.map +1 -0
- package/dist/types/kupola.d.ts +1359 -0
- package/dist/utils/utils/Kupola.cs +77 -0
- package/dist/utils/utils/Kupola.java +104 -0
- package/dist/utils/utils/kupola.go +120 -0
- package/dist/utils/utils/kupola.js +63 -0
- package/dist/utils/utils/kupola.py +1392 -0
- package/dist/utils/utils/kupola.rb +69 -0
- package/icons/activity.svg +3 -0
- package/icons/alert-circle.svg +1 -0
- package/icons/alert-triangle.svg +1 -0
- package/icons/alert.d27e24.svg +1 -0
- package/icons/alert.svg +1 -0
- package/icons/apple.svg +1 -0
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-expand.svg +1 -0
- package/icons/arrow-left.svg +1 -0
- package/icons/arrow-minimize.svg +1 -0
- package/icons/arrow-right-to-line.svg +1 -0
- package/icons/arrow-right.svg +1 -0
- package/icons/arrow-up-right.svg +1 -0
- package/icons/arrow-up.0c0c0d.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/at.svg +1 -0
- package/icons/atom.0c0c0d.svg +1 -0
- package/icons/atom.svg +1 -0
- package/icons/bar-chart-2.svg +1 -0
- package/icons/bar.svg +1 -0
- package/icons/bell.svg +1 -0
- package/icons/box.svg +1 -0
- package/icons/bug.svg +1 -0
- package/icons/button.svg +1 -0
- package/icons/calendar.svg +1 -0
- package/icons/check-circle.33c192.svg +1 -0
- package/icons/check-circle.svg +1 -0
- package/icons/check-square.svg +4 -0
- package/icons/check.d1d3db.svg +1 -0
- package/icons/check.svg +1 -0
- package/icons/chevron-down.svg +1 -0
- package/icons/chevron-left.svg +1 -0
- package/icons/chevron-right.svg +1 -0
- package/icons/chevron-up.svg +1 -0
- package/icons/circle.svg +1 -0
- package/icons/clock.svg +1 -0
- package/icons/cmd.svg +1 -0
- package/icons/code.svg +1 -0
- package/icons/columns.svg +1 -0
- package/icons/copy.svg +1 -0
- package/icons/cpu.svg +1 -0
- package/icons/dashboard.0c0c0d.svg +1 -0
- package/icons/dashboard.svg +1 -0
- package/icons/dollar.svg +1 -0
- package/icons/download.svg +1 -0
- package/icons/edit.svg +1 -0
- package/icons/extensions.svg +1 -0
- package/icons/external.svg +1 -0
- package/icons/eye.svg +1 -0
- package/icons/file-text.svg +1 -0
- package/icons/file.svg +1 -0
- package/icons/files.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/folder-open.svg +4 -0
- package/icons/folder.svg +1 -0
- package/icons/gear.svg +1 -0
- package/icons/git.svg +1 -0
- package/icons/github.svg +1 -0
- package/icons/globe.svg +1 -0
- package/icons/grid-2x2.svg +1 -0
- package/icons/hash.svg +1 -0
- package/icons/heart.svg +1 -0
- package/icons/help-circle.svg +5 -0
- package/icons/help.svg +1 -0
- package/icons/home.svg +1 -0
- package/icons/icons.svg +153 -0
- package/icons/image.svg +1 -0
- package/icons/info-circle.svg +1 -0
- package/icons/info-square.svg +1 -0
- package/icons/info.387bff.svg +1 -0
- package/icons/info.svg +1 -0
- package/icons/input.svg +1 -0
- package/icons/key.svg +1 -0
- package/icons/layers.svg +1 -0
- package/icons/layout-grid.svg +6 -0
- package/icons/layout.svg +1 -0
- package/icons/link.svg +1 -0
- package/icons/list.svg +1 -0
- package/icons/lock.svg +1 -0
- package/icons/log-out.svg +1 -0
- package/icons/logo.svg +1 -0
- package/icons/mail.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/message-circle.svg +1 -0
- package/icons/message-plus.svg +1 -0
- package/icons/message-square.svg +1 -0
- package/icons/mic.svg +1 -0
- package/icons/minus.svg +1 -0
- package/icons/moon.svg +1 -0
- package/icons/more-h.svg +1 -0
- package/icons/mouse.svg +1 -0
- package/icons/palette.svg +1 -0
- package/icons/panel-bottom.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/plug.svg +1 -0
- package/icons/plus.0c0c0d.svg +1 -0
- package/icons/plus.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/ruler.svg +1 -0
- package/icons/scroll-text.svg +1 -0
- package/icons/search-menu.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/send.0c0c0d.svg +1 -0
- package/icons/send.svg +1 -0
- package/icons/settings.0c0c0d.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/shield.svg +1 -0
- package/icons/sidebar-left.svg +1 -0
- package/icons/sidebar-right.svg +1 -0
- package/icons/sliders.svg +1 -0
- package/icons/sparkles.32f08c.svg +1 -0
- package/icons/sparkles.svg +1 -0
- package/icons/square.svg +1 -0
- package/icons/star.svg +1 -0
- package/icons/sun.svg +1 -0
- package/icons/table.svg +1 -0
- package/icons/terminal.svg +1 -0
- package/icons/trash.svg +1 -0
- package/icons/trending-down.svg +1 -0
- package/icons/trending-up.svg +1 -0
- package/icons/type.svg +1 -0
- package/icons/upload.svg +1 -0
- package/icons/user-circle.svg +1 -0
- package/icons/user-plus.svg +6 -0
- package/icons/user.svg +1 -0
- package/icons/users.svg +1 -0
- package/icons/warning.svg +1 -0
- package/icons/wrench.svg +1 -0
- package/icons/x-circle.svg +1 -0
- package/icons/x.svg +1 -0
- package/icons/zap.0c0c0d.svg +1 -0
- package/icons/zap.svg +1 -0
- package/js/calendar.js +184 -0
- package/js/carousel.js +173 -0
- package/js/collapse.js +127 -0
- package/js/color-picker.js +144 -0
- package/js/component.js +276 -0
- package/js/composition-api.js +458 -0
- package/js/countdown.js +144 -0
- package/js/data-bind.js +1286 -0
- package/js/datepicker.js +270 -0
- package/js/dialog.js +131 -0
- package/js/drawer.js +118 -0
- package/js/dropdown.js +122 -0
- package/js/dynamic-tags.js +156 -0
- package/js/error-handler.js +181 -0
- package/js/fileupload.js +392 -0
- package/js/form.js +291 -0
- package/js/global-events.js +203 -0
- package/js/heatmap.js +405 -0
- package/js/http.js +419 -0
- package/js/i18n.js +228 -0
- package/js/icons.js +165 -0
- package/js/image-preview.js +218 -0
- package/js/initializer.js +162 -0
- package/js/kupola-core.js +66 -0
- package/js/kupola-devtools.js +598 -0
- package/js/kupola-lifecycle.js +510 -0
- package/js/message.js +60 -0
- package/js/modal.js +191 -0
- package/js/notification.js +73 -0
- package/js/numberinput.js +146 -0
- package/js/performance.js +250 -0
- package/js/registry.js +205 -0
- package/js/router.js +396 -0
- package/js/security.js +189 -0
- package/js/select.js +143 -0
- package/js/slide-captcha.js +504 -0
- package/js/slider.js +94 -0
- package/js/statcard.js +219 -0
- package/js/tag.js +83 -0
- package/js/test-utils.js +251 -0
- package/js/theme.js +363 -0
- package/js/timepicker.js +238 -0
- package/js/tooltip.js +122 -0
- package/js/utils.js +1458 -0
- package/js/validation.js +553 -0
- package/js/virtual-list.js +593 -0
- package/package.json +105 -0
- package/templates/base.html +30 -0
- package/templates/base_dashboard.html +99 -0
- package/types/kupola.d.ts +1359 -0
- package/utils/Kupola.cs +77 -0
- package/utils/Kupola.java +104 -0
- package/utils/kupola.go +120 -0
- package/utils/kupola.js +63 -0
- package/utils/kupola.py +1392 -0
- package/utils/kupola.rb +69 -0
package/js/http.js
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
class KupolaHttp {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.baseURL = options.baseURL || '';
|
|
4
|
+
this.timeout = options.timeout || 30000;
|
|
5
|
+
this.headers = options.headers || {};
|
|
6
|
+
this.cache = new Map();
|
|
7
|
+
this.cacheTTL = options.cacheTTL || 60000;
|
|
8
|
+
this.maxRetries = options.maxRetries || 0;
|
|
9
|
+
this.retryDelay = options.retryDelay || 1000;
|
|
10
|
+
this.activeRequests = new Map();
|
|
11
|
+
this.withCredentials = options.withCredentials || false;
|
|
12
|
+
|
|
13
|
+
this._useAxios = typeof axios !== 'undefined';
|
|
14
|
+
if (this._useAxios) {
|
|
15
|
+
this._initAxios(options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (options.interceptors) {
|
|
19
|
+
this.interceptors = options.interceptors;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_initAxios(options) {
|
|
24
|
+
this.axios = axios.create({
|
|
25
|
+
baseURL: this.baseURL,
|
|
26
|
+
timeout: this.timeout,
|
|
27
|
+
headers: this.headers
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.axios.defaults.withCredentials = options.withCredentials || false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_generateCacheKey(config) {
|
|
34
|
+
const { url, method = 'GET', params = {}, data = null } = config;
|
|
35
|
+
const query = params ? new URLSearchParams(params).toString() : '';
|
|
36
|
+
const dataKey = data ? JSON.stringify(data) : '';
|
|
37
|
+
return `${method}:${url}:${query}:${dataKey}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_getCache(key) {
|
|
41
|
+
const cached = this.cache.get(key);
|
|
42
|
+
if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
|
|
43
|
+
return cached.data;
|
|
44
|
+
}
|
|
45
|
+
this.cache.delete(key);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_setCache(key, data) {
|
|
50
|
+
this.cache.set(key, { data, timestamp: Date.now() });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async _requestWithRetry(config, retryCount = 0) {
|
|
54
|
+
try {
|
|
55
|
+
return await this._request(config);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (retryCount < this.maxRetries) {
|
|
58
|
+
await new Promise(resolve => setTimeout(resolve, this.retryDelay * Math.pow(2, retryCount)));
|
|
59
|
+
return this._requestWithRetry(config, retryCount + 1);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async _request(config) {
|
|
66
|
+
const {
|
|
67
|
+
url,
|
|
68
|
+
method = 'GET',
|
|
69
|
+
headers = {},
|
|
70
|
+
params = {},
|
|
71
|
+
data = null,
|
|
72
|
+
timeout = this.timeout,
|
|
73
|
+
cache = false
|
|
74
|
+
} = config;
|
|
75
|
+
|
|
76
|
+
const cacheKey = this._generateCacheKey({ url, method, params, data });
|
|
77
|
+
|
|
78
|
+
if (cache && method === 'GET') {
|
|
79
|
+
const cached = this._getCache(cacheKey);
|
|
80
|
+
if (cached) {
|
|
81
|
+
return cached;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
this.activeRequests.set(cacheKey, controller);
|
|
87
|
+
|
|
88
|
+
const requestHeaders = { ...this.headers, ...headers };
|
|
89
|
+
|
|
90
|
+
if (!requestHeaders['Content-Type'] && data && !(data instanceof FormData)) {
|
|
91
|
+
requestHeaders['Content-Type'] = 'application/json';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let requestConfig = {
|
|
95
|
+
url: this.baseURL ? new URL(url, this.baseURL).toString() : url,
|
|
96
|
+
method,
|
|
97
|
+
headers: requestHeaders,
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
credentials: this.withCredentials ? 'include' : 'same-origin'
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (Object.keys(params).length > 0) {
|
|
103
|
+
const urlObj = new URL(requestConfig.url);
|
|
104
|
+
Object.keys(params).forEach(key => {
|
|
105
|
+
urlObj.searchParams.append(key, params[key]);
|
|
106
|
+
});
|
|
107
|
+
requestConfig.url = urlObj.toString();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (data !== null) {
|
|
111
|
+
requestConfig.body = data instanceof FormData ? data : JSON.stringify(data);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (this.interceptors && this.interceptors.request) {
|
|
115
|
+
try {
|
|
116
|
+
const intercepted = await this.interceptors.request(requestConfig);
|
|
117
|
+
if (intercepted) requestConfig = intercepted;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
this.activeRequests.delete(cacheKey);
|
|
120
|
+
if (this.interceptors.requestError) {
|
|
121
|
+
return this.interceptors.requestError(error);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
let response;
|
|
129
|
+
if (this._useAxios) {
|
|
130
|
+
const axiosConfig = {
|
|
131
|
+
url: requestConfig.url.replace(this.baseURL, ''),
|
|
132
|
+
method: requestConfig.method,
|
|
133
|
+
headers: requestConfig.headers,
|
|
134
|
+
signal: requestConfig.signal,
|
|
135
|
+
timeout
|
|
136
|
+
};
|
|
137
|
+
if (data !== null) axiosConfig.data = data;
|
|
138
|
+
if (params && Object.keys(params).length > 0) axiosConfig.params = params;
|
|
139
|
+
|
|
140
|
+
response = await this.axios(axiosConfig);
|
|
141
|
+
} else {
|
|
142
|
+
response = await this._fetchWithTimeout(requestConfig, timeout);
|
|
143
|
+
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
const error = new Error(`HTTP error! status: ${response.status}`);
|
|
146
|
+
error.status = response.status;
|
|
147
|
+
error.statusText = response.statusText;
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const result = {
|
|
153
|
+
data: this._useAxios ? response.data : await this._parseResponse(response),
|
|
154
|
+
status: this._useAxios ? response.status : response.status,
|
|
155
|
+
statusText: this._useAxios ? response.statusText : response.statusText,
|
|
156
|
+
headers: this._useAxios ? response.headers : this._parseHeaders(response.headers),
|
|
157
|
+
config: requestConfig
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if (this.interceptors && this.interceptors.response) {
|
|
161
|
+
return this.interceptors.response(result);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (cache && method === 'GET') {
|
|
165
|
+
this._setCache(cacheKey, result);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return result;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error.name === 'AbortError' || (this._useAxios && error.code === 'ERR_CANCELED')) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
if (this.interceptors && this.interceptors.responseError) {
|
|
174
|
+
return this.interceptors.responseError(error);
|
|
175
|
+
}
|
|
176
|
+
throw error;
|
|
177
|
+
} finally {
|
|
178
|
+
this.activeRequests.delete(cacheKey);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async _fetchWithTimeout(config, timeout) {
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
const signal = controller.signal;
|
|
185
|
+
|
|
186
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
187
|
+
const timerId = setTimeout(() => {
|
|
188
|
+
controller.abort();
|
|
189
|
+
reject(new Error('Request timeout'));
|
|
190
|
+
}, timeout);
|
|
191
|
+
|
|
192
|
+
signal.addEventListener('abort', () => {
|
|
193
|
+
clearTimeout(timerId);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const fetchPromise = fetch({ ...config, signal });
|
|
198
|
+
|
|
199
|
+
return Promise.race([fetchPromise, timeoutPromise]);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async _parseResponse(response) {
|
|
203
|
+
const contentType = response.headers.get('content-type');
|
|
204
|
+
if (contentType && contentType.includes('application/json')) {
|
|
205
|
+
return response.json();
|
|
206
|
+
}
|
|
207
|
+
return response.text();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_parseHeaders(headers) {
|
|
211
|
+
const result = {};
|
|
212
|
+
headers.forEach((value, key) => {
|
|
213
|
+
result[key] = value;
|
|
214
|
+
});
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
cancelRequest(url, params = {}, method = 'GET', data = null) {
|
|
219
|
+
const cacheKey = this._generateCacheKey({ url, method, params, data });
|
|
220
|
+
if (this.activeRequests.has(cacheKey)) {
|
|
221
|
+
this.activeRequests.get(cacheKey).abort();
|
|
222
|
+
this.activeRequests.delete(cacheKey);
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
cancelAllRequests() {
|
|
229
|
+
this.activeRequests.forEach((controller) => {
|
|
230
|
+
controller.abort();
|
|
231
|
+
});
|
|
232
|
+
this.activeRequests.clear();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
clearCache() {
|
|
236
|
+
this.cache.clear();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
clearCacheByUrl(url) {
|
|
240
|
+
this.cache.forEach((_, key) => {
|
|
241
|
+
if (key.startsWith(`GET:${url}`)) {
|
|
242
|
+
this.cache.delete(key);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
get(url, config = {}) {
|
|
248
|
+
const useCache = config.cache ?? true;
|
|
249
|
+
const useRetry = config.retry ?? this.maxRetries > 0;
|
|
250
|
+
|
|
251
|
+
const requestConfig = { ...config, url, method: 'GET', cache: useCache };
|
|
252
|
+
|
|
253
|
+
if (useRetry) {
|
|
254
|
+
return this._requestWithRetry(requestConfig);
|
|
255
|
+
}
|
|
256
|
+
return this._request(requestConfig);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
post(url, data = null, config = {}) {
|
|
260
|
+
const useRetry = config.retry ?? this.maxRetries > 0;
|
|
261
|
+
const requestConfig = { ...config, url, method: 'POST', data, cache: false };
|
|
262
|
+
|
|
263
|
+
if (useRetry) {
|
|
264
|
+
return this._requestWithRetry(requestConfig);
|
|
265
|
+
}
|
|
266
|
+
return this._request(requestConfig);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async uploadFile(url, file, options = {}) {
|
|
270
|
+
const {
|
|
271
|
+
chunkSize = 2 * 1024 * 1024,
|
|
272
|
+
onProgress,
|
|
273
|
+
headers = {},
|
|
274
|
+
parallel = false
|
|
275
|
+
} = options;
|
|
276
|
+
|
|
277
|
+
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
278
|
+
let uploadedChunks = 0;
|
|
279
|
+
let progress = 0;
|
|
280
|
+
|
|
281
|
+
const fileId = this._generateFileId(file);
|
|
282
|
+
|
|
283
|
+
if (parallel) {
|
|
284
|
+
const promises = [];
|
|
285
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
286
|
+
const promise = this._uploadChunk(url, file, i, totalChunks, chunkSize, fileId, headers)
|
|
287
|
+
.then(() => {
|
|
288
|
+
uploadedChunks++;
|
|
289
|
+
progress = Math.round((uploadedChunks / totalChunks) * 100);
|
|
290
|
+
|
|
291
|
+
if (onProgress) {
|
|
292
|
+
onProgress({
|
|
293
|
+
progress,
|
|
294
|
+
uploaded: uploadedChunks * chunkSize,
|
|
295
|
+
total: file.size,
|
|
296
|
+
currentChunk: uploadedChunks,
|
|
297
|
+
totalChunks
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
promises.push(promise);
|
|
302
|
+
}
|
|
303
|
+
await Promise.all(promises);
|
|
304
|
+
return this._completeUpload(url, fileId, totalChunks, file.name);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
308
|
+
await this._uploadChunk(url, file, i, totalChunks, chunkSize, fileId, headers);
|
|
309
|
+
|
|
310
|
+
uploadedChunks++;
|
|
311
|
+
progress = Math.round((uploadedChunks / totalChunks) * 100);
|
|
312
|
+
|
|
313
|
+
if (onProgress) {
|
|
314
|
+
onProgress({
|
|
315
|
+
progress,
|
|
316
|
+
uploaded: uploadedChunks * chunkSize,
|
|
317
|
+
total: file.size,
|
|
318
|
+
currentChunk: i + 1,
|
|
319
|
+
totalChunks
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return this._completeUpload(url, fileId, totalChunks, file.name);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async _uploadChunk(url, file, chunkIndex, totalChunks, chunkSize, fileId, headers) {
|
|
328
|
+
const start = chunkIndex * chunkSize;
|
|
329
|
+
const end = Math.min(start + chunkSize, file.size);
|
|
330
|
+
const chunk = file.slice(start, end);
|
|
331
|
+
|
|
332
|
+
const formData = new FormData();
|
|
333
|
+
formData.append('chunk', chunk);
|
|
334
|
+
formData.append('chunkIndex', chunkIndex);
|
|
335
|
+
formData.append('totalChunks', totalChunks);
|
|
336
|
+
formData.append('fileId', fileId);
|
|
337
|
+
formData.append('fileName', file.name);
|
|
338
|
+
formData.append('fileSize', file.size);
|
|
339
|
+
|
|
340
|
+
return this.post(`${url}/chunk`, formData, { headers });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async _completeUpload(url, fileId, totalChunks, fileName) {
|
|
344
|
+
return this.post(`${url}/complete`, { fileId, totalChunks, fileName });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
_generateFileId(file) {
|
|
348
|
+
const hash = `${file.name}-${file.size}-${file.lastModified}`;
|
|
349
|
+
let result = 0;
|
|
350
|
+
for (let i = 0; i < hash.length; i++) {
|
|
351
|
+
result = ((result << 5) - result) + hash.charCodeAt(i);
|
|
352
|
+
result |= 0;
|
|
353
|
+
}
|
|
354
|
+
return Math.abs(result).toString(36) + Date.now().toString(36);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
put(url, data = null, config = {}) {
|
|
358
|
+
const useRetry = config.retry ?? this.maxRetries > 0;
|
|
359
|
+
const requestConfig = { ...config, url, method: 'PUT', data, cache: false };
|
|
360
|
+
|
|
361
|
+
if (useRetry) {
|
|
362
|
+
return this._requestWithRetry(requestConfig);
|
|
363
|
+
}
|
|
364
|
+
return this._request(requestConfig);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
delete(url, config = {}) {
|
|
368
|
+
const useRetry = config.retry ?? this.maxRetries > 0;
|
|
369
|
+
const requestConfig = { ...config, url, method: 'DELETE', cache: false };
|
|
370
|
+
|
|
371
|
+
if (useRetry) {
|
|
372
|
+
return this._requestWithRetry(requestConfig);
|
|
373
|
+
}
|
|
374
|
+
return this._request(requestConfig);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
patch(url, data = null, config = {}) {
|
|
378
|
+
const useRetry = config.retry ?? this.maxRetries > 0;
|
|
379
|
+
const requestConfig = { ...config, url, method: 'PATCH', data, cache: false };
|
|
380
|
+
|
|
381
|
+
if (useRetry) {
|
|
382
|
+
return this._requestWithRetry(requestConfig);
|
|
383
|
+
}
|
|
384
|
+
return this._request(requestConfig);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
setHeader(name, value) {
|
|
388
|
+
this.headers[name] = value;
|
|
389
|
+
if (this.axios) {
|
|
390
|
+
this.axios.defaults.headers.common[name] = value;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
setToken(token, type = 'Bearer') {
|
|
395
|
+
this.headers['Authorization'] = `${type} ${token}`;
|
|
396
|
+
if (this.axios) {
|
|
397
|
+
this.axios.defaults.headers.common['Authorization'] = `${type} ${token}`;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
setCacheTTL(ttl) {
|
|
402
|
+
this.cacheTTL = ttl;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
setMaxRetries(retries) {
|
|
406
|
+
this.maxRetries = retries;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function createHttp(options) {
|
|
411
|
+
return new KupolaHttp(options);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
415
|
+
module.exports = { KupolaHttp, createHttp };
|
|
416
|
+
} else {
|
|
417
|
+
window.KupolaHttp = KupolaHttp;
|
|
418
|
+
window.createHttp = createHttp;
|
|
419
|
+
}
|
package/js/i18n.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
class KupolaI18n {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.locales = options.locales || {};
|
|
4
|
+
this.currentLocale = options.defaultLocale || 'zh-CN';
|
|
5
|
+
this.fallbackLocale = options.fallbackLocale || 'zh-CN';
|
|
6
|
+
this.delimiter = options.delimiter || '.';
|
|
7
|
+
this.missingHandler = options.missingHandler || ((key) => {
|
|
8
|
+
console.warn(`Missing translation: ${key}`);
|
|
9
|
+
return key;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
this._initFromDOM();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_initFromDOM() {
|
|
16
|
+
const scriptTags = document.querySelectorAll('script[type="application/json"][data-kupola-i18n]');
|
|
17
|
+
scriptTags.forEach(script => {
|
|
18
|
+
const locale = script.dataset.kupolaI18n;
|
|
19
|
+
if (locale) {
|
|
20
|
+
try {
|
|
21
|
+
const data = JSON.parse(script.textContent);
|
|
22
|
+
this.addLocale(locale, data);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.error('Failed to parse i18n data:', e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const htmlLang = document.documentElement.lang;
|
|
30
|
+
if (htmlLang && this.locales[htmlLang]) {
|
|
31
|
+
this.currentLocale = htmlLang;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
addLocale(locale, data) {
|
|
36
|
+
if (!this.locales[locale]) {
|
|
37
|
+
this.locales[locale] = {};
|
|
38
|
+
}
|
|
39
|
+
this._mergeDeep(this.locales[locale], data);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_mergeDeep(target, source) {
|
|
43
|
+
for (const key of Object.keys(source)) {
|
|
44
|
+
if (source[key] instanceof Object && key in target) {
|
|
45
|
+
this._mergeDeep(target[key], source[key]);
|
|
46
|
+
} else {
|
|
47
|
+
target[key] = source[key];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setLocale(locale) {
|
|
53
|
+
if (this.locales[locale]) {
|
|
54
|
+
this.currentLocale = locale;
|
|
55
|
+
document.documentElement.lang = locale;
|
|
56
|
+
this._emitChange();
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getLocale() {
|
|
63
|
+
return this.currentLocale;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
t(key, params = {}) {
|
|
67
|
+
let value = this._getTranslation(key, this.currentLocale);
|
|
68
|
+
|
|
69
|
+
if (!value) {
|
|
70
|
+
value = this._getTranslation(key, this.fallbackLocale);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!value) {
|
|
74
|
+
return this.missingHandler(key);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this._interpolate(value, params);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_getTranslation(key, locale) {
|
|
81
|
+
if (!this.locales[locale]) return null;
|
|
82
|
+
|
|
83
|
+
const keys = key.split(this.delimiter);
|
|
84
|
+
let value = this.locales[locale];
|
|
85
|
+
|
|
86
|
+
for (const k of keys) {
|
|
87
|
+
if (value && typeof value === 'object' && k in value) {
|
|
88
|
+
value = value[k];
|
|
89
|
+
} else {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return typeof value === 'string' ? value : null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_interpolate(str, params) {
|
|
98
|
+
return str.replace(/\{(\w+)\}/g, (match, key) => {
|
|
99
|
+
return params[key] !== undefined ? params[key] : match;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
n(key, count, params = {}) {
|
|
104
|
+
const value = this.t(key, { ...params, count });
|
|
105
|
+
|
|
106
|
+
if (!value) return value;
|
|
107
|
+
|
|
108
|
+
const parts = value.split('|');
|
|
109
|
+
|
|
110
|
+
if (parts.length === 1) {
|
|
111
|
+
return value.replace('{count}', count);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (parts.length === 2) {
|
|
115
|
+
return count === 1 ? parts[0] : parts[1];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (parts.length >= 3) {
|
|
119
|
+
if (count === 0) return parts[0];
|
|
120
|
+
if (count === 1) return parts[1];
|
|
121
|
+
return parts[2];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_emitChange() {
|
|
128
|
+
const event = new CustomEvent('kupola:i18n:change', {
|
|
129
|
+
detail: { locale: this.currentLocale },
|
|
130
|
+
bubbles: true
|
|
131
|
+
});
|
|
132
|
+
document.dispatchEvent(event);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async loadLocale(locale, url) {
|
|
136
|
+
try {
|
|
137
|
+
const response = await fetch(url);
|
|
138
|
+
const data = await response.json();
|
|
139
|
+
this.addLocale(locale, data);
|
|
140
|
+
return true;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('Failed to load locale:', error);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getAvailableLocales() {
|
|
148
|
+
return Object.keys(this.locales);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
hasLocale(locale) {
|
|
152
|
+
return !!this.locales[locale];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
formatDate(date, options = {}) {
|
|
156
|
+
const locale = options.locale || this.currentLocale;
|
|
157
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
158
|
+
|
|
159
|
+
return new Intl.DateTimeFormat(locale, options).format(dateObj);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
formatNumber(number, options = {}) {
|
|
163
|
+
const locale = options.locale || this.currentLocale;
|
|
164
|
+
|
|
165
|
+
return new Intl.NumberFormat(locale, options).format(number);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
formatCurrency(number, currency, options = {}) {
|
|
169
|
+
const locale = options.locale || this.currentLocale;
|
|
170
|
+
|
|
171
|
+
return new Intl.NumberFormat(locale, {
|
|
172
|
+
style: 'currency',
|
|
173
|
+
currency,
|
|
174
|
+
...options
|
|
175
|
+
}).format(number);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
formatRelativeTime(value, unit, options = {}) {
|
|
179
|
+
const locale = options.locale || this.currentLocale;
|
|
180
|
+
|
|
181
|
+
return new Intl.RelativeTimeFormat(locale, options).format(value, unit);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const kupolaI18n = new KupolaI18n();
|
|
186
|
+
|
|
187
|
+
function createI18n(options) {
|
|
188
|
+
return new KupolaI18n(options);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function t(key, params = {}) {
|
|
192
|
+
return kupolaI18n.t(key, params);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function n(key, count, params = {}) {
|
|
196
|
+
return kupolaI18n.n(key, count, params);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function setLocale(locale) {
|
|
200
|
+
return kupolaI18n.setLocale(locale);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getLocale() {
|
|
204
|
+
return kupolaI18n.getLocale();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function formatDate(date, options = {}) {
|
|
208
|
+
return kupolaI18n.formatDate(date, options);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function formatNumber(number, options = {}) {
|
|
212
|
+
return kupolaI18n.formatNumber(number, options);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function formatCurrency(number, currency, options = {}) {
|
|
216
|
+
return kupolaI18n.formatCurrency(number, currency, options);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
window.KupolaI18n = KupolaI18n;
|
|
220
|
+
window.kupolaI18n = kupolaI18n;
|
|
221
|
+
window.createI18n = createI18n;
|
|
222
|
+
window.t = t;
|
|
223
|
+
window.n = n;
|
|
224
|
+
window.setLocale = setLocale;
|
|
225
|
+
window.getLocale = getLocale;
|
|
226
|
+
window.formatDate = formatDate;
|
|
227
|
+
window.formatNumber = formatNumber;
|
|
228
|
+
window.formatCurrency = formatCurrency;
|