@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/collapse.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
class Collapse {
|
|
2
|
+
constructor(element) {
|
|
3
|
+
this.element = element;
|
|
4
|
+
this.headers = [];
|
|
5
|
+
this._listeners = [];
|
|
6
|
+
this._init();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
_init() {
|
|
10
|
+
const headers = this.element.querySelectorAll('.ds-collapse__header');
|
|
11
|
+
|
|
12
|
+
headers.forEach(header => {
|
|
13
|
+
const item = header.closest('.ds-collapse__item');
|
|
14
|
+
const content = header.nextElementSibling;
|
|
15
|
+
|
|
16
|
+
if (!item || !content || !content.classList.contains('ds-collapse__content')) return;
|
|
17
|
+
|
|
18
|
+
const isActive = item.classList.contains('is-active');
|
|
19
|
+
content.style.height = isActive ? content.scrollHeight + 'px' : '0';
|
|
20
|
+
|
|
21
|
+
const clickHandler = () => {
|
|
22
|
+
const isExpanded = content.style.height !== '0px';
|
|
23
|
+
|
|
24
|
+
if (isExpanded) {
|
|
25
|
+
content.style.height = '0';
|
|
26
|
+
item.classList.remove('is-active');
|
|
27
|
+
} else {
|
|
28
|
+
content.style.height = content.scrollHeight + 'px';
|
|
29
|
+
item.classList.add('is-active');
|
|
30
|
+
|
|
31
|
+
const transitionHandler = function onTransitionEnd() {
|
|
32
|
+
content.removeEventListener('transitionend', transitionHandler);
|
|
33
|
+
content.style.height = '';
|
|
34
|
+
};
|
|
35
|
+
content.addEventListener('transitionend', transitionHandler);
|
|
36
|
+
this._listeners.push({ el: content, event: 'transitionend', handler: transitionHandler });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
header.addEventListener('click', clickHandler);
|
|
41
|
+
this.headers.push({ header, item, content, clickHandler });
|
|
42
|
+
this._listeners.push({ el: header, event: 'click', handler: clickHandler });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
destroy() {
|
|
47
|
+
this._listeners.forEach(({ el, event, handler }) => {
|
|
48
|
+
el.removeEventListener(event, handler);
|
|
49
|
+
});
|
|
50
|
+
this._listeners = null;
|
|
51
|
+
this.headers = null;
|
|
52
|
+
this.element = null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toggle(index) {
|
|
56
|
+
const headerInfo = this.headers[index];
|
|
57
|
+
if (headerInfo) {
|
|
58
|
+
headerInfo.clickHandler();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
expand(index) {
|
|
63
|
+
const headerInfo = this.headers[index];
|
|
64
|
+
if (headerInfo && !headerInfo.item.classList.contains('is-active')) {
|
|
65
|
+
headerInfo.clickHandler();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
collapse(index) {
|
|
70
|
+
const headerInfo = this.headers[index];
|
|
71
|
+
if (headerInfo && headerInfo.item.classList.contains('is-active')) {
|
|
72
|
+
headerInfo.clickHandler();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
expandAll() {
|
|
77
|
+
this.headers.forEach((headerInfo, index) => {
|
|
78
|
+
if (!headerInfo.item.classList.contains('is-active')) {
|
|
79
|
+
this.toggle(index);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
collapseAll() {
|
|
85
|
+
this.headers.forEach((headerInfo, index) => {
|
|
86
|
+
if (headerInfo.item.classList.contains('is-active')) {
|
|
87
|
+
this.toggle(index);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function initCollapse(element) {
|
|
94
|
+
if (element.__kupolaInitialized) return;
|
|
95
|
+
|
|
96
|
+
const collapse = new Collapse(element);
|
|
97
|
+
element.__kupolaInstance = collapse;
|
|
98
|
+
element.__kupolaInitialized = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function cleanupCollapse(element) {
|
|
102
|
+
if (!element.__kupolaInitialized || !element.__kupolaInstance) return;
|
|
103
|
+
|
|
104
|
+
const collapse = element.__kupolaInstance;
|
|
105
|
+
collapse.destroy();
|
|
106
|
+
|
|
107
|
+
element.__kupolaInstance = null;
|
|
108
|
+
element.__kupolaInitialized = false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function initCollapses() {
|
|
112
|
+
document.querySelectorAll('.ds-collapse').forEach(collapse => {
|
|
113
|
+
initCollapse(collapse);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
118
|
+
module.exports = { Collapse, initCollapses, initCollapse, cleanupCollapse };
|
|
119
|
+
} else {
|
|
120
|
+
window.Collapse = Collapse;
|
|
121
|
+
window.initCollapse = initCollapse;
|
|
122
|
+
window.cleanupCollapse = cleanupCollapse;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (window.kupolaInitializer) {
|
|
126
|
+
window.kupolaInitializer.register('collapse', initCollapse, cleanupCollapse);
|
|
127
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
class ColorPicker {
|
|
2
|
+
constructor(element) {
|
|
3
|
+
this.element = element;
|
|
4
|
+
this.trigger = element.querySelector('.ds-color-picker__trigger');
|
|
5
|
+
this.panel = element.querySelector('.ds-color-picker__panel');
|
|
6
|
+
this.valueSpan = element.querySelector('.ds-color-picker__value');
|
|
7
|
+
this.customInput = element.querySelector('.ds-color-picker__input');
|
|
8
|
+
this.scope = `colorpicker-${Math.random().toString(36).substr(2, 9)}`;
|
|
9
|
+
|
|
10
|
+
this._triggerClickHandler = null;
|
|
11
|
+
this._documentClickHandler = null;
|
|
12
|
+
this._documentClickListener = null;
|
|
13
|
+
this._colorClickHandler = null;
|
|
14
|
+
this._inputInputHandler = null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init() {
|
|
18
|
+
if (!this.trigger || !this.panel) return;
|
|
19
|
+
if (this.element.__kupolaInitialized) return;
|
|
20
|
+
|
|
21
|
+
this._triggerClickHandler = (e) => {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
this.togglePanel();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this._colorClickHandler = (e) => {
|
|
27
|
+
const colorBtn = e.currentTarget;
|
|
28
|
+
const color = colorBtn.getAttribute('data-color');
|
|
29
|
+
this.updateColor(color);
|
|
30
|
+
this.hidePanel();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
this._inputInputHandler = (e) => {
|
|
34
|
+
this.updateColor(e.target.value);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this._documentClickHandler = (e) => {
|
|
38
|
+
if (!this.element.contains(e.target)) {
|
|
39
|
+
this.hidePanel();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.trigger.addEventListener('click', this._triggerClickHandler);
|
|
44
|
+
|
|
45
|
+
this.panel.querySelectorAll('.ds-color-picker__color').forEach(colorBtn => {
|
|
46
|
+
colorBtn.addEventListener('click', this._colorClickHandler);
|
|
47
|
+
colorBtn._colorPickerColorHandler = this._colorClickHandler;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (this.customInput) {
|
|
51
|
+
this.customInput.addEventListener('input', this._inputInputHandler);
|
|
52
|
+
this.customInput._colorPickerInputHandler = this._inputInputHandler;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (window.globalEvents) {
|
|
56
|
+
this._documentClickListener = window.globalEvents.on(document, 'click', this._documentClickHandler, { scope: this.scope });
|
|
57
|
+
} else {
|
|
58
|
+
document.addEventListener('click', this._documentClickHandler);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.element.__kupolaInitialized = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
togglePanel() {
|
|
65
|
+
this.panel.classList.toggle('is-visible');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
hidePanel() {
|
|
69
|
+
this.panel.classList.remove('is-visible');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
updateColor(color) {
|
|
73
|
+
this.trigger.style.backgroundColor = color;
|
|
74
|
+
if (this.valueSpan) {
|
|
75
|
+
this.valueSpan.textContent = color.toUpperCase();
|
|
76
|
+
}
|
|
77
|
+
if (this.customInput) {
|
|
78
|
+
this.customInput.value = color;
|
|
79
|
+
}
|
|
80
|
+
this.element.dispatchEvent(new CustomEvent('colorchange', { detail: { color } }));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
destroy() {
|
|
84
|
+
if (!this.element.__kupolaInitialized) return;
|
|
85
|
+
|
|
86
|
+
if (this.trigger && this._triggerClickHandler) {
|
|
87
|
+
this.trigger.removeEventListener('click', this._triggerClickHandler);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.panel) {
|
|
91
|
+
this.panel.querySelectorAll('.ds-color-picker__color').forEach(colorBtn => {
|
|
92
|
+
if (colorBtn._colorPickerColorHandler) {
|
|
93
|
+
colorBtn.removeEventListener('click', colorBtn._colorPickerColorHandler);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (this.customInput && this._inputInputHandler) {
|
|
99
|
+
this.customInput.removeEventListener('input', this._inputInputHandler);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (this._documentClickListener && this._documentClickListener.unsubscribe) {
|
|
103
|
+
this._documentClickListener.unsubscribe();
|
|
104
|
+
} else if (this._documentClickHandler) {
|
|
105
|
+
document.removeEventListener('click', this._documentClickHandler);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this._documentClickHandler = null;
|
|
109
|
+
this._documentClickListener = null;
|
|
110
|
+
this._triggerClickHandler = null;
|
|
111
|
+
this._colorClickHandler = null;
|
|
112
|
+
this._inputInputHandler = null;
|
|
113
|
+
this.element.__kupolaInitialized = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function initColorPicker(element) {
|
|
118
|
+
const picker = new ColorPicker(element);
|
|
119
|
+
picker.init();
|
|
120
|
+
element._kupolaColorPicker = picker;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function initColorPickers(root = document) {
|
|
124
|
+
root.querySelectorAll('.ds-color-picker').forEach(picker => {
|
|
125
|
+
initColorPicker(picker);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function cleanupColorPicker(picker) {
|
|
130
|
+
if (picker._kupolaColorPicker) {
|
|
131
|
+
picker._kupolaColorPicker.destroy();
|
|
132
|
+
picker._kupolaColorPicker = null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function cleanupAllColorPickers() {
|
|
137
|
+
document.querySelectorAll('.ds-color-picker').forEach(picker => {
|
|
138
|
+
cleanupColorPicker(picker);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (window.kupolaInitializer) {
|
|
143
|
+
window.kupolaInitializer.register('color-picker', initColorPicker, cleanupColorPicker);
|
|
144
|
+
}
|
package/js/component.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
class KupolaComponent {
|
|
2
|
+
constructor(element) {
|
|
3
|
+
this.element = element;
|
|
4
|
+
this.isMounted = false;
|
|
5
|
+
this.isDestroyed = false;
|
|
6
|
+
this.props = this._parseProps();
|
|
7
|
+
this.state = {};
|
|
8
|
+
this.slots = this._parseSlots();
|
|
9
|
+
this._eventListeners = {};
|
|
10
|
+
this._appliedMixins = [];
|
|
11
|
+
this.lifecycle = window.KupolaLifecycle
|
|
12
|
+
? new window.KupolaLifecycle()
|
|
13
|
+
: {
|
|
14
|
+
on: () => () => {},
|
|
15
|
+
emit: () => {},
|
|
16
|
+
bootstrap: () => {},
|
|
17
|
+
mount: () => {},
|
|
18
|
+
update: () => {},
|
|
19
|
+
unmount: () => {},
|
|
20
|
+
destroy: () => {},
|
|
21
|
+
state: 'created'
|
|
22
|
+
};
|
|
23
|
+
this.setupContext = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_parseProps() {
|
|
27
|
+
const props = {};
|
|
28
|
+
for (const attr of this.element.attributes) {
|
|
29
|
+
if (attr.name.startsWith('data-prop-')) {
|
|
30
|
+
const name = attr.name.replace('data-prop-', '');
|
|
31
|
+
let value = attr.value;
|
|
32
|
+
try {
|
|
33
|
+
value = JSON.parse(value);
|
|
34
|
+
} catch (e) {}
|
|
35
|
+
props[name] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return props;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_parseSlots() {
|
|
42
|
+
const slots = {};
|
|
43
|
+
const slotElements = this.element.querySelectorAll('[data-slot]');
|
|
44
|
+
|
|
45
|
+
slotElements.forEach(slotEl => {
|
|
46
|
+
const slotName = slotEl.getAttribute('data-slot') || 'default';
|
|
47
|
+
slots[slotName] = slotEl.innerHTML.trim();
|
|
48
|
+
slotEl.remove();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!slots.default && this.element.children.length > 0) {
|
|
52
|
+
slots.default = this.element.innerHTML.trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return slots;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
$slot(name = 'default') {
|
|
59
|
+
return this.slots[name] || '';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
$emit(eventName, data) {
|
|
63
|
+
const handlers = this._eventListeners[eventName] || [];
|
|
64
|
+
handlers.forEach(handler => {
|
|
65
|
+
try {
|
|
66
|
+
handler(data);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(`Error in event handler for ${eventName}:`, e);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (this.element) {
|
|
73
|
+
const customEvent = new CustomEvent(`kupola:${eventName}`, {
|
|
74
|
+
detail: data,
|
|
75
|
+
bubbles: true,
|
|
76
|
+
cancelable: true
|
|
77
|
+
});
|
|
78
|
+
this.element.dispatchEvent(customEvent);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
$on(eventName, handler) {
|
|
83
|
+
if (!this._eventListeners[eventName]) {
|
|
84
|
+
this._eventListeners[eventName] = [];
|
|
85
|
+
}
|
|
86
|
+
this._eventListeners[eventName].push(handler);
|
|
87
|
+
return handler;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
$off(eventName, handler) {
|
|
91
|
+
if (this._eventListeners[eventName]) {
|
|
92
|
+
this._eventListeners[eventName] = this._eventListeners[eventName].filter(cb => cb !== handler);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async setProps(newProps) {
|
|
97
|
+
try {
|
|
98
|
+
this.props = { ...this.props, ...newProps };
|
|
99
|
+
await this.lifecycle.update();
|
|
100
|
+
this.setupContext?._executeUpdated();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(`[KupolaComponent] Error in setProps for "${this.constructor.name}":`, error);
|
|
103
|
+
|
|
104
|
+
if (this.lifecycle && typeof this.lifecycle._handleError === 'function') {
|
|
105
|
+
await this.lifecycle._handleError({ phase: 'update', hook: 'setProps', error, args: [newProps] });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async setState(newState) {
|
|
111
|
+
try {
|
|
112
|
+
this.state = { ...this.state, ...newState };
|
|
113
|
+
await this.lifecycle.update();
|
|
114
|
+
this.setupContext?._executeUpdated();
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error(`[KupolaComponent] Error in setState for "${this.constructor.name}":`, error);
|
|
117
|
+
|
|
118
|
+
if (this.lifecycle && typeof this.lifecycle._handleError === 'function') {
|
|
119
|
+
await this.lifecycle._handleError({ phase: 'update', hook: 'setState', error, args: [newState] });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async mount() {
|
|
125
|
+
if (this.isMounted || this.isDestroyed) return;
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
this._bindLifecycleHooks();
|
|
129
|
+
|
|
130
|
+
await this.lifecycle.bootstrap();
|
|
131
|
+
|
|
132
|
+
if (window._setCurrentSetupContext && window.SetupContext) {
|
|
133
|
+
this.setupContext = new window.SetupContext(this);
|
|
134
|
+
window._setCurrentSetupContext(this.setupContext);
|
|
135
|
+
|
|
136
|
+
if (typeof this.setup === 'function') {
|
|
137
|
+
const result = this.setup();
|
|
138
|
+
if (result instanceof Promise) {
|
|
139
|
+
await result;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.isMounted = true;
|
|
145
|
+
await this.lifecycle.mount();
|
|
146
|
+
|
|
147
|
+
this.setupContext?._executeMounted();
|
|
148
|
+
|
|
149
|
+
if (window._clearSetupContext) {
|
|
150
|
+
window._clearSetupContext();
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error(`[KupolaComponent] Error mounting component "${this.constructor.name}":`, error);
|
|
154
|
+
|
|
155
|
+
if (this.lifecycle && typeof this.lifecycle._handleError === 'function') {
|
|
156
|
+
await this.lifecycle._handleError({ phase: 'mount', hook: 'component', error, args: [] });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (typeof this.renderError === 'function') {
|
|
160
|
+
try {
|
|
161
|
+
this.renderError(error);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.error(`[KupolaComponent] Error in renderError for "${this.constructor.name}":`, e);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
this.element.innerHTML = `
|
|
167
|
+
<div style="padding: 16px; background: #fee2e2; border: 1px solid #fecaca; border-radius: 8px; color: #991b1b;">
|
|
168
|
+
<div style="font-weight: bold; margin-bottom: 8px;">Component Error</div>
|
|
169
|
+
<div style="font-size: 12px; white-space: pre-wrap;">${error.message}</div>
|
|
170
|
+
</div>
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_bindLifecycleHooks() {
|
|
177
|
+
if (this._hooksBound) return;
|
|
178
|
+
|
|
179
|
+
const hookMap = {
|
|
180
|
+
beforeMount: 'beforeMount',
|
|
181
|
+
render: ['mount', 'update'],
|
|
182
|
+
afterMount: 'afterMount',
|
|
183
|
+
updated: 'afterUpdate',
|
|
184
|
+
beforeUnmount: 'beforeUnmount',
|
|
185
|
+
afterUnmount: 'afterUnmount',
|
|
186
|
+
renderError: 'errorBoundary'
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
let proto = Object.getPrototypeOf(this);
|
|
190
|
+
const registeredHooks = new Set();
|
|
191
|
+
|
|
192
|
+
while (proto && proto.constructor !== Object && proto.constructor !== KupolaComponent) {
|
|
193
|
+
for (const [methodName, lifecyclePhase] of Object.entries(hookMap)) {
|
|
194
|
+
if (registeredHooks.has(methodName)) continue;
|
|
195
|
+
|
|
196
|
+
if (proto.hasOwnProperty(methodName)) {
|
|
197
|
+
if (Array.isArray(lifecyclePhase)) {
|
|
198
|
+
lifecyclePhase.forEach(phase => {
|
|
199
|
+
if (methodName === 'render') {
|
|
200
|
+
this.lifecycle.on(phase, () => this.render?.());
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
} else if (methodName === 'renderError') {
|
|
204
|
+
this.lifecycle.on(lifecyclePhase, (errorInfo) => {
|
|
205
|
+
this.renderError(errorInfo.error);
|
|
206
|
+
return 'handled';
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
this.lifecycle.on(lifecyclePhase, () => this[methodName]?.());
|
|
210
|
+
}
|
|
211
|
+
registeredHooks.add(methodName);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
proto = Object.getPrototypeOf(proto);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this._hooksBound = true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async unmount() {
|
|
221
|
+
if (!this.isMounted || this.isDestroyed) return;
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
this.setupContext?._executeUnmounted();
|
|
225
|
+
|
|
226
|
+
await this.lifecycle.unmount();
|
|
227
|
+
this.isMounted = false;
|
|
228
|
+
this.isDestroyed = true;
|
|
229
|
+
await this.lifecycle.destroy();
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error(`[KupolaComponent] Error unmounting component "${this.constructor.name}":`, error);
|
|
232
|
+
|
|
233
|
+
if (this.lifecycle && typeof this.lifecycle._handleError === 'function') {
|
|
234
|
+
await this.lifecycle._handleError({ phase: 'unmount', hook: 'component', error, args: [] });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.isMounted = false;
|
|
238
|
+
this.isDestroyed = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
beforeMount() {}
|
|
243
|
+
afterMount() {}
|
|
244
|
+
beforeUnmount() {}
|
|
245
|
+
afterUnmount() {}
|
|
246
|
+
render() {}
|
|
247
|
+
renderError(error) {}
|
|
248
|
+
updated() {}
|
|
249
|
+
setup() {}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function applyMixin(componentClass, mixin) {
|
|
253
|
+
Object.keys(mixin).forEach(key => {
|
|
254
|
+
if (key === 'constructor') return;
|
|
255
|
+
if (typeof mixin[key] === 'function') {
|
|
256
|
+
const original = componentClass.prototype[key];
|
|
257
|
+
if (original) {
|
|
258
|
+
componentClass.prototype[key] = function(...args) {
|
|
259
|
+
mixin[key].apply(this, args);
|
|
260
|
+
return original.apply(this, args);
|
|
261
|
+
};
|
|
262
|
+
} else {
|
|
263
|
+
componentClass.prototype[key] = mixin[key];
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
componentClass.prototype[key] = mixin[key];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
272
|
+
module.exports = { KupolaComponent, applyMixin };
|
|
273
|
+
} else {
|
|
274
|
+
window.KupolaComponent = KupolaComponent;
|
|
275
|
+
window.applyMixin = applyMixin;
|
|
276
|
+
}
|