@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/registry.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
class KupolaComponentRegistry {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.components = new Map();
|
|
4
|
+
this.lazyComponents = new Map();
|
|
5
|
+
this.loadedComponents = new Map();
|
|
6
|
+
this.instances = new Map();
|
|
7
|
+
this.observer = null;
|
|
8
|
+
this.mixins = new Map();
|
|
9
|
+
this.loadingPromises = new Map();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
register(name, componentClass) {
|
|
13
|
+
if (!(componentClass.prototype instanceof window.KupolaComponent)) {
|
|
14
|
+
throw new Error(`Component ${name} must extend KupolaComponent`);
|
|
15
|
+
}
|
|
16
|
+
this.components.set(name, componentClass);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
registerLazy(name, loader) {
|
|
20
|
+
this.lazyComponents.set(name, loader);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
unregister(name) {
|
|
24
|
+
this.components.delete(name);
|
|
25
|
+
this.lazyComponents.delete(name);
|
|
26
|
+
this.loadedComponents.delete(name);
|
|
27
|
+
this.loadingPromises.delete(name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get(name) {
|
|
31
|
+
return this.components.get(name) || this.loadedComponents.get(name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getAsync(name) {
|
|
35
|
+
const cached = this.components.get(name) || this.loadedComponents.get(name);
|
|
36
|
+
if (cached) return cached;
|
|
37
|
+
|
|
38
|
+
if (this.loadingPromises.has(name)) {
|
|
39
|
+
return this.loadingPromises.get(name);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const loader = this.lazyComponents.get(name);
|
|
43
|
+
if (!loader) {
|
|
44
|
+
throw new Error(`Component ${name} not found`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const loadingPromise = (async () => {
|
|
48
|
+
try {
|
|
49
|
+
const result = await loader();
|
|
50
|
+
const componentClass = result.default || result;
|
|
51
|
+
if (!(componentClass.prototype instanceof window.KupolaComponent)) {
|
|
52
|
+
throw new Error(`Component ${name} must extend KupolaComponent`);
|
|
53
|
+
}
|
|
54
|
+
this.loadedComponents.set(name, componentClass);
|
|
55
|
+
return componentClass;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
this.loadingPromises.delete(name);
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
|
|
62
|
+
this.loadingPromises.set(name, loadingPromise);
|
|
63
|
+
return loadingPromise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
defineMixin(name, mixin) {
|
|
67
|
+
this.mixins.set(name, mixin);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
useMixin(componentClass, ...mixinNames) {
|
|
71
|
+
mixinNames.forEach(name => {
|
|
72
|
+
const mixin = this.mixins.get(name);
|
|
73
|
+
if (mixin && window.applyMixin) {
|
|
74
|
+
window.applyMixin(componentClass, mixin);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async bootstrap(root = document) {
|
|
80
|
+
await this._upgradeElements(root);
|
|
81
|
+
this._startObserver(root);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async _upgradeElements(root) {
|
|
85
|
+
const elements = root.querySelectorAll('[data-component]');
|
|
86
|
+
const promises = [];
|
|
87
|
+
elements.forEach(element => {
|
|
88
|
+
promises.push(this._upgradeElement(element));
|
|
89
|
+
});
|
|
90
|
+
await Promise.all(promises);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async _upgradeElement(element) {
|
|
94
|
+
if (element.__kupolaInstance || element.__kupolaUpgrading) return;
|
|
95
|
+
|
|
96
|
+
element.__kupolaUpgrading = true;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const componentName = element.getAttribute('data-component');
|
|
100
|
+
|
|
101
|
+
if (window.kupolaInitializer && componentName) {
|
|
102
|
+
const initializer = window.kupolaInitializer.get(componentName);
|
|
103
|
+
if (initializer) {
|
|
104
|
+
try {
|
|
105
|
+
await initializer(element);
|
|
106
|
+
return;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.warn(`[KupolaComponentRegistry] Initializer for "${componentName}" failed, trying component class:`, e);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let ComponentClass = this.components.get(componentName);
|
|
114
|
+
|
|
115
|
+
if (!ComponentClass) {
|
|
116
|
+
try {
|
|
117
|
+
ComponentClass = await this.getAsync(componentName);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error(`Failed to load component ${componentName}:`, e);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!element.isConnected) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const mixinNames = element.getAttribute('data-mixins');
|
|
129
|
+
const componentClass = ComponentClass;
|
|
130
|
+
if (mixinNames && window.applyMixin) {
|
|
131
|
+
mixinNames.split(',').forEach(name => {
|
|
132
|
+
const mixin = this.mixins.get(name.trim());
|
|
133
|
+
if (mixin) {
|
|
134
|
+
window.applyMixin(componentClass, mixin);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const instance = new componentClass(element);
|
|
140
|
+
element.__kupolaInstance = instance;
|
|
141
|
+
this.instances.set(element, instance);
|
|
142
|
+
instance.mount();
|
|
143
|
+
} finally {
|
|
144
|
+
element.__kupolaUpgrading = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_startObserver(root) {
|
|
149
|
+
if (this.observer) return;
|
|
150
|
+
|
|
151
|
+
this.observer = new MutationObserver((mutations) => {
|
|
152
|
+
mutations.forEach(mutation => {
|
|
153
|
+
mutation.addedNodes.forEach(node => {
|
|
154
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
155
|
+
if (node.hasAttribute('data-component')) {
|
|
156
|
+
this._upgradeElement(node).catch(e => console.error(e));
|
|
157
|
+
}
|
|
158
|
+
this._upgradeElements(node).catch(e => console.error(e));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
mutation.removedNodes.forEach(node => {
|
|
163
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
164
|
+
const instance = this.instances.get(node);
|
|
165
|
+
if (instance) {
|
|
166
|
+
instance.unmount();
|
|
167
|
+
this.instances.delete(node);
|
|
168
|
+
}
|
|
169
|
+
node.querySelectorAll('[data-component]').forEach(child => {
|
|
170
|
+
const childInstance = this.instances.get(child);
|
|
171
|
+
if (childInstance) {
|
|
172
|
+
childInstance.unmount();
|
|
173
|
+
this.instances.delete(child);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
this.observer.observe(root, {
|
|
182
|
+
childList: true,
|
|
183
|
+
subtree: true
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
destroy() {
|
|
188
|
+
if (this.observer) {
|
|
189
|
+
this.observer.disconnect();
|
|
190
|
+
this.observer = null;
|
|
191
|
+
}
|
|
192
|
+
this.instances.forEach(instance => {
|
|
193
|
+
instance.unmount();
|
|
194
|
+
});
|
|
195
|
+
this.instances.clear();
|
|
196
|
+
this.components.clear();
|
|
197
|
+
this.mixins.clear();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
202
|
+
module.exports = { KupolaComponentRegistry };
|
|
203
|
+
} else {
|
|
204
|
+
window.KupolaComponentRegistry = KupolaComponentRegistry;
|
|
205
|
+
}
|
package/js/router.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
class KupolaRouter {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.mode = options.mode || 'hash';
|
|
4
|
+
this.routes = options.routes || [];
|
|
5
|
+
this.base = options.base || '';
|
|
6
|
+
this.currentRoute = null;
|
|
7
|
+
this.beforeEachHandlers = [];
|
|
8
|
+
this.afterEachHandlers = [];
|
|
9
|
+
this.isStarted = false;
|
|
10
|
+
this.animationClass = 'fade';
|
|
11
|
+
this.componentCache = new Map();
|
|
12
|
+
this._routeHandler = () => this._handleRoute();
|
|
13
|
+
|
|
14
|
+
this._setupRoutes();
|
|
15
|
+
this._bindEvents();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_setupRoutes() {
|
|
19
|
+
this.routeMap = new Map();
|
|
20
|
+
this._registerRoutes(this.routes, '');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_registerRoutes(routes, parentPath) {
|
|
24
|
+
routes.forEach(route => {
|
|
25
|
+
const fullPath = route.path.startsWith('/')
|
|
26
|
+
? route.path
|
|
27
|
+
: parentPath + (parentPath && !route.path.startsWith('/') ? '/' : '') + route.path;
|
|
28
|
+
const pathRegex = this._pathToRegex(fullPath);
|
|
29
|
+
this.routeMap.set(fullPath, { ...route, regex: pathRegex, parentPath });
|
|
30
|
+
|
|
31
|
+
if (route.children && route.children.length > 0) {
|
|
32
|
+
this._registerRoutes(route.children, fullPath);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_pathToRegex(path) {
|
|
38
|
+
const regexStr = path
|
|
39
|
+
.replace(/:(\w+)/g, '([^/]+)')
|
|
40
|
+
.replace(/\*/g, '.*');
|
|
41
|
+
return new RegExp(`^${regexStr}$`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_bindEvents() {
|
|
45
|
+
if (this.mode === 'hash') {
|
|
46
|
+
window.addEventListener('hashchange', this._routeHandler);
|
|
47
|
+
} else {
|
|
48
|
+
window.addEventListener('popstate', this._routeHandler);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_handleRoute() {
|
|
53
|
+
const path = this._getCurrentPath();
|
|
54
|
+
this.navigate(path);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_getCurrentPath() {
|
|
58
|
+
if (this.mode === 'hash') {
|
|
59
|
+
return location.hash.slice(1) || '/';
|
|
60
|
+
}
|
|
61
|
+
return location.pathname.replace(this.base, '') || '/';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async navigate(path, replace = false) {
|
|
65
|
+
const route = this._matchRoute(path);
|
|
66
|
+
if (!route) return;
|
|
67
|
+
|
|
68
|
+
const from = this.currentRoute;
|
|
69
|
+
|
|
70
|
+
for (const handler of this.beforeEachHandlers) {
|
|
71
|
+
const result = await handler(route, from);
|
|
72
|
+
if (result === false) return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.currentRoute = route;
|
|
76
|
+
this._updateURL(path, replace);
|
|
77
|
+
await this._renderRoute(route);
|
|
78
|
+
|
|
79
|
+
for (const handler of this.afterEachHandlers) {
|
|
80
|
+
handler(route);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_matchRoute(path) {
|
|
85
|
+
for (const [, route] of this.routeMap) {
|
|
86
|
+
const match = path.match(route.regex);
|
|
87
|
+
if (match) {
|
|
88
|
+
const params = {};
|
|
89
|
+
const paramNames = route.path.match(/:(\w+)/g) || [];
|
|
90
|
+
paramNames.forEach((name, index) => {
|
|
91
|
+
params[name.slice(1)] = match[index + 1];
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const query = this._parseQuery();
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
...route,
|
|
98
|
+
params,
|
|
99
|
+
query,
|
|
100
|
+
fullPath: path
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_parseQuery() {
|
|
108
|
+
const search = location.search.slice(1);
|
|
109
|
+
const params = {};
|
|
110
|
+
if (search) {
|
|
111
|
+
search.split('&').forEach(pair => {
|
|
112
|
+
const [key, value] = pair.split('=');
|
|
113
|
+
params[key] = decodeURIComponent(value || '');
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return params;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_updateURL(path, replace) {
|
|
120
|
+
if (this.mode === 'hash') {
|
|
121
|
+
const url = `#${path}`;
|
|
122
|
+
if (replace) {
|
|
123
|
+
location.replace(url);
|
|
124
|
+
} else {
|
|
125
|
+
location.hash = path;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
const url = this.base + path + location.search;
|
|
129
|
+
if (replace) {
|
|
130
|
+
history.replaceState({}, '', url);
|
|
131
|
+
} else {
|
|
132
|
+
history.pushState({}, '', url);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async _renderRoute(route) {
|
|
138
|
+
if (route.parentPath && route.parentPath !== '') {
|
|
139
|
+
await this._renderNestedRoute(route);
|
|
140
|
+
} else {
|
|
141
|
+
await this._renderRootRoute(route);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async _renderRootRoute(route) {
|
|
146
|
+
const container = document.querySelector('[data-router-view]');
|
|
147
|
+
if (!container || !route.component) return;
|
|
148
|
+
|
|
149
|
+
this._cleanupContainerComponents(container);
|
|
150
|
+
|
|
151
|
+
container.classList.add('router-view-leave');
|
|
152
|
+
container.classList.remove('router-view-enter');
|
|
153
|
+
|
|
154
|
+
await this._waitForAnimation(container);
|
|
155
|
+
|
|
156
|
+
const componentName = await this._resolveComponent(route.component);
|
|
157
|
+
if (!componentName) return;
|
|
158
|
+
|
|
159
|
+
const componentElement = document.createElement('div');
|
|
160
|
+
componentElement.setAttribute('data-component', componentName);
|
|
161
|
+
componentElement.classList.add('router-view-enter');
|
|
162
|
+
|
|
163
|
+
Object.keys(route.params).forEach(key => {
|
|
164
|
+
componentElement.setAttribute(`data-prop-${key}`, route.params[key]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
container.innerHTML = '';
|
|
168
|
+
container.appendChild(componentElement);
|
|
169
|
+
|
|
170
|
+
if (window.kupolaRegistry) {
|
|
171
|
+
await window.kupolaRegistry.bootstrap(container);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
container.classList.remove('router-view-leave');
|
|
176
|
+
componentElement.classList.remove('router-view-enter');
|
|
177
|
+
}, 10);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async _renderNestedRoute(route) {
|
|
181
|
+
const parentRoute = this.routeMap.get(route.parentPath);
|
|
182
|
+
if (!parentRoute) return;
|
|
183
|
+
|
|
184
|
+
const rootContainer = document.querySelector('[data-router-view]');
|
|
185
|
+
if (!rootContainer) return;
|
|
186
|
+
|
|
187
|
+
const existingParent = document.querySelector(`[data-component="${parentRoute.component}"]`);
|
|
188
|
+
|
|
189
|
+
if (!existingParent) {
|
|
190
|
+
this._cleanupContainerComponents(rootContainer);
|
|
191
|
+
|
|
192
|
+
rootContainer.classList.add('router-view-leave');
|
|
193
|
+
rootContainer.classList.remove('router-view-enter');
|
|
194
|
+
|
|
195
|
+
await this._waitForAnimation(rootContainer);
|
|
196
|
+
|
|
197
|
+
const parentName = await this._resolveComponent(parentRoute.component);
|
|
198
|
+
if (!parentName) return;
|
|
199
|
+
|
|
200
|
+
const parentElement = document.createElement('div');
|
|
201
|
+
parentElement.setAttribute('data-component', parentName);
|
|
202
|
+
|
|
203
|
+
rootContainer.innerHTML = '';
|
|
204
|
+
rootContainer.appendChild(parentElement);
|
|
205
|
+
|
|
206
|
+
if (window.kupolaRegistry) {
|
|
207
|
+
await window.kupolaRegistry.bootstrap(rootContainer);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
rootContainer.classList.remove('router-view-leave');
|
|
212
|
+
}, 50);
|
|
213
|
+
|
|
214
|
+
await this._renderChildComponent(route);
|
|
215
|
+
} else {
|
|
216
|
+
await this._renderChildComponent(route);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async _renderChildComponent(route) {
|
|
221
|
+
const parentElement = document.querySelector(`[data-component="${this._getParentComponent(route.parentPath)}"]`);
|
|
222
|
+
if (!parentElement) return;
|
|
223
|
+
|
|
224
|
+
const container = parentElement.querySelector('[data-router-view]');
|
|
225
|
+
if (!container || !route.component) return;
|
|
226
|
+
|
|
227
|
+
const componentName = await this._resolveComponent(route.component);
|
|
228
|
+
if (!componentName) return;
|
|
229
|
+
|
|
230
|
+
const componentElement = document.createElement('div');
|
|
231
|
+
componentElement.setAttribute('data-component', componentName);
|
|
232
|
+
componentElement.classList.add('router-view-enter');
|
|
233
|
+
|
|
234
|
+
Object.keys(route.params).forEach(key => {
|
|
235
|
+
componentElement.setAttribute(`data-prop-${key}`, route.params[key]);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
container.innerHTML = '';
|
|
239
|
+
container.appendChild(componentElement);
|
|
240
|
+
|
|
241
|
+
if (window.kupolaRegistry) {
|
|
242
|
+
await window.kupolaRegistry.bootstrap(container);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
componentElement.classList.remove('router-view-enter');
|
|
247
|
+
}, 10);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async _resolveComponent(component) {
|
|
251
|
+
if (typeof component === 'function') {
|
|
252
|
+
const cacheKey = component.toString();
|
|
253
|
+
if (this.componentCache.has(cacheKey)) {
|
|
254
|
+
return this.componentCache.get(cacheKey);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
const result = await component();
|
|
259
|
+
const componentClass = result.default || result;
|
|
260
|
+
|
|
261
|
+
const componentName = `lazy-${Math.random().toString(36).substr(2, 9)}`;
|
|
262
|
+
|
|
263
|
+
if (window.kupolaRegistry) {
|
|
264
|
+
window.kupolaRegistry.register(componentName, componentClass);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
this.componentCache.set(cacheKey, componentName);
|
|
268
|
+
return componentName;
|
|
269
|
+
} catch (e) {
|
|
270
|
+
console.error('Failed to load lazy component:', e);
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (typeof component === 'string' && component.startsWith('lazy:')) {
|
|
276
|
+
const componentName = component.slice(5);
|
|
277
|
+
if (window.kupolaRegistry) {
|
|
278
|
+
try {
|
|
279
|
+
await window.kupolaRegistry.getAsync(componentName);
|
|
280
|
+
} catch (e) {
|
|
281
|
+
console.error(`Failed to load lazy component ${componentName}:`, e);
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return componentName;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return component;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
_getParentComponent(parentPath) {
|
|
292
|
+
for (const [path, route] of this.routeMap) {
|
|
293
|
+
if (path === parentPath) {
|
|
294
|
+
return route.component;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setAnimation(name) {
|
|
301
|
+
this.animationClass = name;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
push(path) {
|
|
305
|
+
this.navigate(path, false);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
replace(path) {
|
|
309
|
+
this.navigate(path, true);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
go(delta) {
|
|
313
|
+
history.go(delta);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
back() {
|
|
317
|
+
history.back();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
forward() {
|
|
321
|
+
history.forward();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
beforeEach(handler) {
|
|
325
|
+
this.beforeEachHandlers.push(handler);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
afterEach(handler) {
|
|
329
|
+
this.afterEachHandlers.push(handler);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
_waitForAnimation(element) {
|
|
333
|
+
return new Promise(resolve => {
|
|
334
|
+
const transitionDuration = this._getTransitionDuration(element);
|
|
335
|
+
if (transitionDuration > 0) {
|
|
336
|
+
const cleanup = () => {
|
|
337
|
+
element.removeEventListener('transitionend', cleanup);
|
|
338
|
+
element.removeEventListener('animationend', cleanup);
|
|
339
|
+
resolve();
|
|
340
|
+
};
|
|
341
|
+
element.addEventListener('transitionend', cleanup);
|
|
342
|
+
element.addEventListener('animationend', cleanup);
|
|
343
|
+
setTimeout(cleanup, transitionDuration + 100);
|
|
344
|
+
} else {
|
|
345
|
+
resolve();
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
_getTransitionDuration(element) {
|
|
351
|
+
const style = window.getComputedStyle(element);
|
|
352
|
+
const transitionDuration = parseFloat(style.transitionDuration) || 0;
|
|
353
|
+
const animationDuration = parseFloat(style.animationDuration) || 0;
|
|
354
|
+
return Math.max(transitionDuration, animationDuration) * 1000;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
_cleanupContainerComponents(container) {
|
|
358
|
+
const components = container.querySelectorAll('[data-component]');
|
|
359
|
+
components.forEach(element => {
|
|
360
|
+
const instance = element.__kupolaInstance;
|
|
361
|
+
if (instance && typeof instance.unmount === 'function') {
|
|
362
|
+
instance.unmount().catch(e => console.error(`Error unmounting component:`, e));
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
if (window.kupolaInitializer) {
|
|
367
|
+
const allElements = container.querySelectorAll('[data-component], [data-dropdown], [data-select], [data-datepicker], [data-timepicker], [data-slider], [data-carousel], [data-drawer], [data-modal], [data-dialog], [data-color-picker], [data-calendar], [data-slide-captcha], [data-heatmap]');
|
|
368
|
+
allElements.forEach(element => {
|
|
369
|
+
window.kupolaInitializer.cleanup(element);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
destroy() {
|
|
375
|
+
if (this.mode === 'hash') {
|
|
376
|
+
window.removeEventListener('hashchange', this._routeHandler);
|
|
377
|
+
} else {
|
|
378
|
+
window.removeEventListener('popstate', this._routeHandler);
|
|
379
|
+
}
|
|
380
|
+
this.routes = [];
|
|
381
|
+
this.routeMap.clear();
|
|
382
|
+
this.beforeEachHandlers = [];
|
|
383
|
+
this.afterEachHandlers = [];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function createRouter(options) {
|
|
388
|
+
return new KupolaRouter(options);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
392
|
+
module.exports = { KupolaRouter, createRouter };
|
|
393
|
+
} else {
|
|
394
|
+
window.KupolaRouter = KupolaRouter;
|
|
395
|
+
window.createRouter = createRouter;
|
|
396
|
+
}
|