@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
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
class KupolaLifecycle {
|
|
2
|
+
constructor(scope = 'app') {
|
|
3
|
+
this.scope = scope;
|
|
4
|
+
this.hooks = new Map();
|
|
5
|
+
this.state = 'created';
|
|
6
|
+
this.stateHistory = ['created'];
|
|
7
|
+
this.transitions = new Map([
|
|
8
|
+
['created', ['bootstrapped', 'destroyed']],
|
|
9
|
+
['bootstrapped', ['mounted', 'destroyed']],
|
|
10
|
+
['mounted', ['updated', 'unmounted', 'destroyed']],
|
|
11
|
+
['updated', ['updated', 'unmounted', 'destroyed']],
|
|
12
|
+
['unmounted', ['mounted', 'destroyed']],
|
|
13
|
+
['destroyed', []]
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
this.phaseStateMap = {
|
|
17
|
+
'bootstrap': { from: 'created', to: 'bootstrapped' },
|
|
18
|
+
'mount': { from: ['bootstrapped', 'unmounted'], to: 'mounted' },
|
|
19
|
+
'update': { from: ['mounted', 'updated'], to: 'updated' },
|
|
20
|
+
'unmount': { from: ['mounted', 'updated'], to: 'unmounted' },
|
|
21
|
+
'destroy': { from: ['bootstrapped', 'mounted', 'updated', 'unmounted'], to: 'destroyed' }
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.basePhases = ['bootstrap', 'mount', 'update', 'unmount', 'destroy'];
|
|
25
|
+
this.allPhases = ['error', 'errorBoundary'];
|
|
26
|
+
|
|
27
|
+
this.basePhases.forEach(phase => {
|
|
28
|
+
this.allPhases.push(`before${phase.charAt(0).toUpperCase() + phase.slice(1)}`);
|
|
29
|
+
this.allPhases.push(phase);
|
|
30
|
+
this.allPhases.push(`after${phase.charAt(0).toUpperCase() + phase.slice(1)}`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.allPhases.forEach(phase => {
|
|
34
|
+
this.hooks.set(phase, []);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.pendingHooks = new Set();
|
|
38
|
+
this.trace = [];
|
|
39
|
+
this.errorHandler = null;
|
|
40
|
+
this.errorBoundary = null;
|
|
41
|
+
this.lastError = null;
|
|
42
|
+
this.errorCount = 0;
|
|
43
|
+
this.maxErrors = 10;
|
|
44
|
+
this._onErrorCallback = null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_validateTransition(nextState) {
|
|
48
|
+
const allowed = this.transitions.get(this.state);
|
|
49
|
+
if (!allowed || !allowed.includes(nextState)) {
|
|
50
|
+
throw new Error(`Invalid state transition: ${this.state} -> ${nextState}`);
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_updateState(nextState) {
|
|
56
|
+
this._validateTransition(nextState);
|
|
57
|
+
this.state = nextState;
|
|
58
|
+
this.stateHistory.push(nextState);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_resetResolved(phase) {
|
|
62
|
+
const handlers = this.hooks.get(phase);
|
|
63
|
+
if (handlers) {
|
|
64
|
+
handlers.forEach(hook => {
|
|
65
|
+
hook.resolved = false;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
on(phase, handler, options = {}) {
|
|
71
|
+
if (!this.allPhases.includes(phase)) {
|
|
72
|
+
throw new Error(`Unknown lifecycle phase: ${phase}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hooks = this.hooks.get(phase);
|
|
76
|
+
hooks.push({
|
|
77
|
+
handler,
|
|
78
|
+
priority: options.priority || 0,
|
|
79
|
+
depends: options.depends || [],
|
|
80
|
+
name: options.name || handler.name || `anonymous_${hooks.length}`
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
hooks.sort((a, b) => b.priority - a.priority);
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
const index = hooks.findIndex(h => h.handler === handler);
|
|
87
|
+
if (index > -1) {
|
|
88
|
+
hooks.splice(index, 1);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async _resolveDepends(depends, phase) {
|
|
94
|
+
if (!depends || depends.length === 0) return;
|
|
95
|
+
|
|
96
|
+
for (const depName of depends) {
|
|
97
|
+
const phaseHooks = this.hooks.get(phase);
|
|
98
|
+
const depHook = phaseHooks.find(h => h.name === depName);
|
|
99
|
+
if (depHook && !depHook.resolved) {
|
|
100
|
+
await depHook.handler();
|
|
101
|
+
depHook.resolved = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async emit(phase, ...args) {
|
|
107
|
+
if (this.state === 'destroyed' && phase !== 'error') return;
|
|
108
|
+
|
|
109
|
+
const handlers = this.hooks.get(phase);
|
|
110
|
+
if (!handlers || handlers.length === 0) return;
|
|
111
|
+
|
|
112
|
+
const emitId = `${phase}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
113
|
+
this.pendingHooks.add(emitId);
|
|
114
|
+
|
|
115
|
+
const startTime = performance.now();
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
for (const hook of handlers) {
|
|
119
|
+
await this._resolveDepends(hook.depends, phase);
|
|
120
|
+
|
|
121
|
+
const hookStartTime = performance.now();
|
|
122
|
+
let hookResult, hookError;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
hookResult = hook.handler(...args);
|
|
126
|
+
if (hookResult instanceof Promise) {
|
|
127
|
+
await hookResult;
|
|
128
|
+
}
|
|
129
|
+
hook.resolved = true;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
hookError = error;
|
|
132
|
+
console.error(`[KupolaLifecycle] Error in ${phase} hook "${hook.name}":`, error);
|
|
133
|
+
|
|
134
|
+
if (phase !== 'error') {
|
|
135
|
+
await this._handleError({ phase, hook: hook.name, error, args });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const hookDuration = performance.now() - hookStartTime;
|
|
140
|
+
|
|
141
|
+
this.trace.push({
|
|
142
|
+
emitId,
|
|
143
|
+
phase,
|
|
144
|
+
hookName: hook.name,
|
|
145
|
+
duration: hookDuration,
|
|
146
|
+
status: hookError ? 'error' : 'success',
|
|
147
|
+
error: hookError ? hookError.message : null,
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const totalDuration = performance.now() - startTime;
|
|
153
|
+
console.debug(`[KupolaLifecycle] ${phase} completed in ${totalDuration.toFixed(2)}ms (${this.scope})`);
|
|
154
|
+
} finally {
|
|
155
|
+
this.pendingHooks.delete(emitId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async runPhase(phase, ...args) {
|
|
160
|
+
if (!this.basePhases.includes(phase)) {
|
|
161
|
+
throw new Error(`Unknown base phase: ${phase}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const stateMap = this.phaseStateMap[phase];
|
|
165
|
+
if (stateMap) {
|
|
166
|
+
if (Array.isArray(stateMap.from)) {
|
|
167
|
+
if (!stateMap.from.includes(this.state)) {
|
|
168
|
+
throw new Error(`Cannot ${phase} from state ${this.state}, expected one of: ${stateMap.from.join(', ')}`);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (this.state !== stateMap.from) {
|
|
172
|
+
throw new Error(`Cannot ${phase} from state ${this.state}, expected ${stateMap.from}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const beforePhase = `before${phase.charAt(0).toUpperCase() + phase.slice(1)}`;
|
|
178
|
+
const afterPhase = `after${phase.charAt(0).toUpperCase() + phase.slice(1)}`;
|
|
179
|
+
|
|
180
|
+
this._resetResolved(beforePhase);
|
|
181
|
+
this._resetResolved(phase);
|
|
182
|
+
this._resetResolved(afterPhase);
|
|
183
|
+
|
|
184
|
+
if (this.allPhases.includes(beforePhase)) {
|
|
185
|
+
await this.emit(beforePhase, ...args);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
await this.emit(phase, ...args);
|
|
189
|
+
|
|
190
|
+
if (stateMap) {
|
|
191
|
+
this._updateState(stateMap.to);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.allPhases.includes(afterPhase)) {
|
|
195
|
+
await this.emit(afterPhase, ...args);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async bootstrap(...args) {
|
|
200
|
+
await this.runPhase('bootstrap', ...args);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async _waitForDOMReady() {
|
|
204
|
+
return new Promise((resolve) => {
|
|
205
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
206
|
+
resolve();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const onReady = () => {
|
|
211
|
+
document.removeEventListener('DOMContentLoaded', onReady);
|
|
212
|
+
window.removeEventListener('load', onReady);
|
|
213
|
+
resolve();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
document.addEventListener('DOMContentLoaded', onReady);
|
|
217
|
+
window.addEventListener('load', onReady);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async mount(...args) {
|
|
222
|
+
await this.runPhase('mount', ...args);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async mountWithDOMReady(...args) {
|
|
226
|
+
await this._waitForDOMReady();
|
|
227
|
+
await this.runPhase('mount', ...args);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async update(...args) {
|
|
231
|
+
await this.runPhase('update', ...args);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async unmount(...args) {
|
|
235
|
+
await this.runPhase('unmount', ...args);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async destroy(...args) {
|
|
239
|
+
await this.runPhase('destroy', ...args);
|
|
240
|
+
|
|
241
|
+
this.hooks.forEach(handlers => {
|
|
242
|
+
handlers.length = 0;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
getPhaseHandlers(phase) {
|
|
247
|
+
return this.hooks.get(phase) || [];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
hasHandlers(phase) {
|
|
251
|
+
const handlers = this.hooks.get(phase);
|
|
252
|
+
return handlers && handlers.length > 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
getTrace() {
|
|
256
|
+
return [...this.trace];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
clearTrace() {
|
|
260
|
+
this.trace = [];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
getState() {
|
|
264
|
+
return this.state;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
getStateHistory() {
|
|
268
|
+
return [...this.stateHistory];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
isInState(targetState) {
|
|
272
|
+
return this.state === targetState;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
onError(handler) {
|
|
276
|
+
this._onErrorCallback = handler;
|
|
277
|
+
return this.on('error', handler);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
setErrorBoundary(boundary) {
|
|
281
|
+
this.errorBoundary = boundary;
|
|
282
|
+
return this.on('errorBoundary', (errorInfo) => {
|
|
283
|
+
if (typeof boundary === 'function') {
|
|
284
|
+
return boundary(errorInfo);
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
setMaxErrors(max) {
|
|
291
|
+
this.maxErrors = max;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
getErrorCount() {
|
|
295
|
+
return this.errorCount;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
getLastError() {
|
|
299
|
+
return this.lastError;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
resetErrorCount() {
|
|
303
|
+
this.errorCount = 0;
|
|
304
|
+
this.lastError = null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async _handleError(errorInfo) {
|
|
308
|
+
this.errorCount++;
|
|
309
|
+
this.lastError = errorInfo.error;
|
|
310
|
+
|
|
311
|
+
if (this.errorCount >= this.maxErrors) {
|
|
312
|
+
console.error(`[KupolaLifecycle] Error limit reached (${this.maxErrors}), stopping error handling`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
await this.emit('error', errorInfo);
|
|
317
|
+
|
|
318
|
+
if (typeof this._onErrorCallback === 'function') {
|
|
319
|
+
try {
|
|
320
|
+
await this._onErrorCallback(errorInfo);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error('[KupolaLifecycle] Error in onError callback:', e);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const boundaryHandlers = this.hooks.get('errorBoundary');
|
|
327
|
+
if (boundaryHandlers && boundaryHandlers.length > 0) {
|
|
328
|
+
for (const hook of boundaryHandlers) {
|
|
329
|
+
try {
|
|
330
|
+
const result = hook.handler(errorInfo);
|
|
331
|
+
if (result instanceof Promise) {
|
|
332
|
+
await result;
|
|
333
|
+
}
|
|
334
|
+
if (result === 'handled') {
|
|
335
|
+
console.debug(`[KupolaLifecycle] Error handled by errorBoundary hook "${hook.name}"`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
} catch (e) {
|
|
339
|
+
console.error(`[KupolaLifecycle] Error in errorBoundary hook "${hook.name}":`, e);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
console.error(`[KupolaLifecycle] Unhandled error in ${errorInfo.phase}:`, errorInfo.error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
class KupolaPluginManager {
|
|
349
|
+
constructor() {
|
|
350
|
+
this.plugins = new Map();
|
|
351
|
+
this.enabledPlugins = new Set();
|
|
352
|
+
this.pluginHooks = new Map();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
register(name, plugin) {
|
|
356
|
+
if (this.plugins.has(name)) {
|
|
357
|
+
console.warn(`Plugin ${name} already registered, overriding`);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
this.plugins.set(name, {
|
|
361
|
+
...plugin,
|
|
362
|
+
name,
|
|
363
|
+
enabled: false,
|
|
364
|
+
instance: null,
|
|
365
|
+
lifecycle: new KupolaLifecycle(`plugin:${name}`)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async enable(name) {
|
|
370
|
+
const plugin = this.plugins.get(name);
|
|
371
|
+
if (!plugin) {
|
|
372
|
+
throw new Error(`Plugin ${name} not found`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (plugin.enabled) return;
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
await plugin.lifecycle.bootstrap();
|
|
379
|
+
|
|
380
|
+
if (plugin.install) {
|
|
381
|
+
plugin.instance = await plugin.install();
|
|
382
|
+
}
|
|
383
|
+
plugin.enabled = true;
|
|
384
|
+
this.enabledPlugins.add(name);
|
|
385
|
+
|
|
386
|
+
await plugin.lifecycle.mount();
|
|
387
|
+
|
|
388
|
+
if (plugin.hooks) {
|
|
389
|
+
this._registerPluginHooks(name, plugin.hooks);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
console.log(`Plugin ${name} enabled`);
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error(`Failed to enable plugin ${name}:`, error);
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async disable(name) {
|
|
400
|
+
const plugin = this.plugins.get(name);
|
|
401
|
+
if (!plugin || !plugin.enabled) return;
|
|
402
|
+
|
|
403
|
+
try {
|
|
404
|
+
await plugin.lifecycle.unmount();
|
|
405
|
+
|
|
406
|
+
if (plugin.uninstall) {
|
|
407
|
+
await plugin.uninstall(plugin.instance);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (plugin.hooks) {
|
|
411
|
+
this._unregisterPluginHooks(name);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
plugin.enabled = false;
|
|
415
|
+
this.enabledPlugins.delete(name);
|
|
416
|
+
plugin.instance = null;
|
|
417
|
+
|
|
418
|
+
await plugin.lifecycle.destroy();
|
|
419
|
+
|
|
420
|
+
console.log(`Plugin ${name} disabled`);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
console.error(`Failed to disable plugin ${name}:`, error);
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
get(name) {
|
|
428
|
+
const plugin = this.plugins.get(name);
|
|
429
|
+
return plugin?.instance || null;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
getAll() {
|
|
433
|
+
const result = {};
|
|
434
|
+
this.plugins.forEach((plugin, name) => {
|
|
435
|
+
result[name] = {
|
|
436
|
+
name: plugin.name,
|
|
437
|
+
enabled: plugin.enabled,
|
|
438
|
+
instance: plugin.instance,
|
|
439
|
+
state: plugin.lifecycle.getState()
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
return result;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
getEnabled() {
|
|
446
|
+
const result = {};
|
|
447
|
+
this.enabledPlugins.forEach(name => {
|
|
448
|
+
const plugin = this.plugins.get(name);
|
|
449
|
+
if (plugin) {
|
|
450
|
+
result[name] = plugin.instance;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async enableAll() {
|
|
457
|
+
const promises = [];
|
|
458
|
+
this.plugins.forEach((_, name) => {
|
|
459
|
+
promises.push(this.enable(name));
|
|
460
|
+
});
|
|
461
|
+
await Promise.all(promises);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async disableAll() {
|
|
465
|
+
const promises = [];
|
|
466
|
+
this.enabledPlugins.forEach(name => {
|
|
467
|
+
promises.push(this.disable(name));
|
|
468
|
+
});
|
|
469
|
+
await Promise.all(promises);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
_registerPluginHooks(pluginName, hooks) {
|
|
473
|
+
if (!this.pluginHooks.has(pluginName)) {
|
|
474
|
+
this.pluginHooks.set(pluginName, []);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const pluginHooks = this.pluginHooks.get(pluginName);
|
|
478
|
+
|
|
479
|
+
Object.keys(hooks).forEach(phase => {
|
|
480
|
+
const unsubscribe = window.kupolaLifecycle?.on(phase, hooks[phase], { name: `${pluginName}:${phase}` });
|
|
481
|
+
if (unsubscribe) {
|
|
482
|
+
pluginHooks.push({ phase, unsubscribe });
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
_unregisterPluginHooks(pluginName) {
|
|
488
|
+
const pluginHooks = this.pluginHooks.get(pluginName);
|
|
489
|
+
if (!pluginHooks) return;
|
|
490
|
+
|
|
491
|
+
pluginHooks.forEach(({ unsubscribe }) => {
|
|
492
|
+
if (unsubscribe) unsubscribe();
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
this.pluginHooks.delete(pluginName);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const kupolaLifecycle = new KupolaLifecycle('app');
|
|
500
|
+
const kupolaPluginManager = new KupolaPluginManager();
|
|
501
|
+
|
|
502
|
+
function createLifecycle(scope = 'app') {
|
|
503
|
+
return new KupolaLifecycle(scope);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
window.KupolaLifecycle = KupolaLifecycle;
|
|
507
|
+
window.KupolaPluginManager = KupolaPluginManager;
|
|
508
|
+
window.kupolaLifecycle = kupolaLifecycle;
|
|
509
|
+
window.kupolaPluginManager = kupolaPluginManager;
|
|
510
|
+
window.createLifecycle = createLifecycle;
|
package/js/message.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const Message = {
|
|
2
|
+
normal: function(message, options = {}) {
|
|
3
|
+
this.show(message, 'normal', options);
|
|
4
|
+
},
|
|
5
|
+
success: function(message, options = {}) {
|
|
6
|
+
this.show(message, 'success', options);
|
|
7
|
+
},
|
|
8
|
+
error: function(message, options = {}) {
|
|
9
|
+
this.show(message, 'error', options);
|
|
10
|
+
},
|
|
11
|
+
warning: function(message, options = {}) {
|
|
12
|
+
this.show(message, 'warning', options);
|
|
13
|
+
},
|
|
14
|
+
info: function(message, options = {}) {
|
|
15
|
+
this.show(message, 'info', options);
|
|
16
|
+
},
|
|
17
|
+
show: function(message, type = 'normal', options = {}) {
|
|
18
|
+
const { duration = 3000 } = options;
|
|
19
|
+
|
|
20
|
+
const msg = document.createElement('div');
|
|
21
|
+
msg.className = `ds-message__item ds-message__item--${type}`;
|
|
22
|
+
|
|
23
|
+
const icons = {
|
|
24
|
+
normal: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
|
|
25
|
+
success: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>',
|
|
26
|
+
error: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
|
|
27
|
+
warning: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
|
|
28
|
+
info: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
msg.innerHTML = `
|
|
32
|
+
<div class="ds-message__icon ds-message__icon--${type}">${icons[type]}</div>
|
|
33
|
+
<div class="ds-message__content"></div>
|
|
34
|
+
`;
|
|
35
|
+
msg.querySelector('.ds-message__content').textContent = message;
|
|
36
|
+
|
|
37
|
+
let container = document.querySelector('.ds-message');
|
|
38
|
+
if (!container) {
|
|
39
|
+
container = document.createElement('div');
|
|
40
|
+
container.className = 'ds-message';
|
|
41
|
+
document.body.appendChild(container);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
container.appendChild(msg);
|
|
45
|
+
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
msg.classList.add('is-visible');
|
|
48
|
+
}, 10);
|
|
49
|
+
|
|
50
|
+
if (duration > 0) {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
msg.classList.remove('is-visible');
|
|
53
|
+
msg.classList.add('is-exiting');
|
|
54
|
+
setTimeout(() => msg.remove(), 300);
|
|
55
|
+
}, duration);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function initMessages() {}
|