@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.
Files changed (354) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/INTEGRATION.md +440 -0
  3. package/PROJECT_SUMMARY.md +312 -0
  4. package/README.md +286 -0
  5. package/SKILL.md +572 -0
  6. package/css/accessibility.css +119 -0
  7. package/css/animations.css +224 -0
  8. package/css/brand-themes.css +300 -0
  9. package/css/colors_and_type.css +441 -0
  10. package/css/components-ext.css +4165 -0
  11. package/css/components.css +1483 -0
  12. package/css/kupola.css +12 -0
  13. package/css/responsive.css +697 -0
  14. package/css/scaffold.css +145 -0
  15. package/css/states.css +316 -0
  16. package/css/theme-dark.css +296 -0
  17. package/css/theme-light.css +296 -0
  18. package/css/utilities.css +171 -0
  19. package/dist/css/kupola.css +12 -0
  20. package/dist/icons/icons/activity.svg +3 -0
  21. package/dist/icons/icons/alert-circle.svg +1 -0
  22. package/dist/icons/icons/alert-triangle.svg +1 -0
  23. package/dist/icons/icons/alert.d27e24.svg +1 -0
  24. package/dist/icons/icons/alert.svg +1 -0
  25. package/dist/icons/icons/apple.svg +1 -0
  26. package/dist/icons/icons/arrow-down.svg +1 -0
  27. package/dist/icons/icons/arrow-expand.svg +1 -0
  28. package/dist/icons/icons/arrow-left.svg +1 -0
  29. package/dist/icons/icons/arrow-minimize.svg +1 -0
  30. package/dist/icons/icons/arrow-right-to-line.svg +1 -0
  31. package/dist/icons/icons/arrow-right.svg +1 -0
  32. package/dist/icons/icons/arrow-up-right.svg +1 -0
  33. package/dist/icons/icons/arrow-up.0c0c0d.svg +1 -0
  34. package/dist/icons/icons/arrow-up.svg +1 -0
  35. package/dist/icons/icons/at.svg +1 -0
  36. package/dist/icons/icons/atom.0c0c0d.svg +1 -0
  37. package/dist/icons/icons/atom.svg +1 -0
  38. package/dist/icons/icons/bar-chart-2.svg +1 -0
  39. package/dist/icons/icons/bar.svg +1 -0
  40. package/dist/icons/icons/bell.svg +1 -0
  41. package/dist/icons/icons/box.svg +1 -0
  42. package/dist/icons/icons/bug.svg +1 -0
  43. package/dist/icons/icons/button.svg +1 -0
  44. package/dist/icons/icons/calendar.svg +1 -0
  45. package/dist/icons/icons/check-circle.33c192.svg +1 -0
  46. package/dist/icons/icons/check-circle.svg +1 -0
  47. package/dist/icons/icons/check-square.svg +4 -0
  48. package/dist/icons/icons/check.d1d3db.svg +1 -0
  49. package/dist/icons/icons/check.svg +1 -0
  50. package/dist/icons/icons/chevron-down.svg +1 -0
  51. package/dist/icons/icons/chevron-left.svg +1 -0
  52. package/dist/icons/icons/chevron-right.svg +1 -0
  53. package/dist/icons/icons/chevron-up.svg +1 -0
  54. package/dist/icons/icons/circle.svg +1 -0
  55. package/dist/icons/icons/clock.svg +1 -0
  56. package/dist/icons/icons/cmd.svg +1 -0
  57. package/dist/icons/icons/code.svg +1 -0
  58. package/dist/icons/icons/columns.svg +1 -0
  59. package/dist/icons/icons/copy.svg +1 -0
  60. package/dist/icons/icons/cpu.svg +1 -0
  61. package/dist/icons/icons/dashboard.0c0c0d.svg +1 -0
  62. package/dist/icons/icons/dashboard.svg +1 -0
  63. package/dist/icons/icons/dollar.svg +1 -0
  64. package/dist/icons/icons/download.svg +1 -0
  65. package/dist/icons/icons/edit.svg +1 -0
  66. package/dist/icons/icons/extensions.svg +1 -0
  67. package/dist/icons/icons/external.svg +1 -0
  68. package/dist/icons/icons/eye.svg +1 -0
  69. package/dist/icons/icons/file-text.svg +1 -0
  70. package/dist/icons/icons/file.svg +1 -0
  71. package/dist/icons/icons/files.svg +1 -0
  72. package/dist/icons/icons/filter.svg +1 -0
  73. package/dist/icons/icons/folder-open.svg +4 -0
  74. package/dist/icons/icons/folder.svg +1 -0
  75. package/dist/icons/icons/gear.svg +1 -0
  76. package/dist/icons/icons/git.svg +1 -0
  77. package/dist/icons/icons/github.svg +1 -0
  78. package/dist/icons/icons/globe.svg +1 -0
  79. package/dist/icons/icons/grid-2x2.svg +1 -0
  80. package/dist/icons/icons/hash.svg +1 -0
  81. package/dist/icons/icons/heart.svg +1 -0
  82. package/dist/icons/icons/help-circle.svg +5 -0
  83. package/dist/icons/icons/help.svg +1 -0
  84. package/dist/icons/icons/home.svg +1 -0
  85. package/dist/icons/icons/icons.svg +153 -0
  86. package/dist/icons/icons/image.svg +1 -0
  87. package/dist/icons/icons/info-circle.svg +1 -0
  88. package/dist/icons/icons/info-square.svg +1 -0
  89. package/dist/icons/icons/info.387bff.svg +1 -0
  90. package/dist/icons/icons/info.svg +1 -0
  91. package/dist/icons/icons/input.svg +1 -0
  92. package/dist/icons/icons/key.svg +1 -0
  93. package/dist/icons/icons/layers.svg +1 -0
  94. package/dist/icons/icons/layout-grid.svg +6 -0
  95. package/dist/icons/icons/layout.svg +1 -0
  96. package/dist/icons/icons/link.svg +1 -0
  97. package/dist/icons/icons/list.svg +1 -0
  98. package/dist/icons/icons/lock.svg +1 -0
  99. package/dist/icons/icons/log-out.svg +1 -0
  100. package/dist/icons/icons/logo.svg +1 -0
  101. package/dist/icons/icons/mail.svg +1 -0
  102. package/dist/icons/icons/menu.svg +1 -0
  103. package/dist/icons/icons/message-circle.svg +1 -0
  104. package/dist/icons/icons/message-plus.svg +1 -0
  105. package/dist/icons/icons/message-square.svg +1 -0
  106. package/dist/icons/icons/mic.svg +1 -0
  107. package/dist/icons/icons/minus.svg +1 -0
  108. package/dist/icons/icons/moon.svg +1 -0
  109. package/dist/icons/icons/more-h.svg +1 -0
  110. package/dist/icons/icons/mouse.svg +1 -0
  111. package/dist/icons/icons/palette.svg +1 -0
  112. package/dist/icons/icons/panel-bottom.svg +1 -0
  113. package/dist/icons/icons/pause.svg +1 -0
  114. package/dist/icons/icons/play.svg +1 -0
  115. package/dist/icons/icons/plug.svg +1 -0
  116. package/dist/icons/icons/plus.0c0c0d.svg +1 -0
  117. package/dist/icons/icons/plus.svg +1 -0
  118. package/dist/icons/icons/refresh.svg +1 -0
  119. package/dist/icons/icons/ruler.svg +1 -0
  120. package/dist/icons/icons/scroll-text.svg +1 -0
  121. package/dist/icons/icons/search-menu.svg +1 -0
  122. package/dist/icons/icons/search.svg +1 -0
  123. package/dist/icons/icons/send.0c0c0d.svg +1 -0
  124. package/dist/icons/icons/send.svg +1 -0
  125. package/dist/icons/icons/settings.0c0c0d.svg +1 -0
  126. package/dist/icons/icons/settings.svg +1 -0
  127. package/dist/icons/icons/shield.svg +1 -0
  128. package/dist/icons/icons/sidebar-left.svg +1 -0
  129. package/dist/icons/icons/sidebar-right.svg +1 -0
  130. package/dist/icons/icons/sliders.svg +1 -0
  131. package/dist/icons/icons/sparkles.32f08c.svg +1 -0
  132. package/dist/icons/icons/sparkles.svg +1 -0
  133. package/dist/icons/icons/square.svg +1 -0
  134. package/dist/icons/icons/star.svg +1 -0
  135. package/dist/icons/icons/sun.svg +1 -0
  136. package/dist/icons/icons/table.svg +1 -0
  137. package/dist/icons/icons/terminal.svg +1 -0
  138. package/dist/icons/icons/trash.svg +1 -0
  139. package/dist/icons/icons/trending-down.svg +1 -0
  140. package/dist/icons/icons/trending-up.svg +1 -0
  141. package/dist/icons/icons/type.svg +1 -0
  142. package/dist/icons/icons/upload.svg +1 -0
  143. package/dist/icons/icons/user-circle.svg +1 -0
  144. package/dist/icons/icons/user-plus.svg +6 -0
  145. package/dist/icons/icons/user.svg +1 -0
  146. package/dist/icons/icons/users.svg +1 -0
  147. package/dist/icons/icons/warning.svg +1 -0
  148. package/dist/icons/icons/wrench.svg +1 -0
  149. package/dist/icons/icons/x-circle.svg +1 -0
  150. package/dist/icons/icons/x.svg +1 -0
  151. package/dist/icons/icons/zap.0c0c0d.svg +1 -0
  152. package/dist/icons/icons/zap.svg +1 -0
  153. package/dist/kupola.cjs.js +258 -0
  154. package/dist/kupola.cjs.js.map +1 -0
  155. package/dist/kupola.esm.js +7640 -0
  156. package/dist/kupola.esm.js.map +1 -0
  157. package/dist/kupola.umd.js +258 -0
  158. package/dist/kupola.umd.js.map +1 -0
  159. package/dist/types/kupola.d.ts +1359 -0
  160. package/dist/utils/utils/Kupola.cs +77 -0
  161. package/dist/utils/utils/Kupola.java +104 -0
  162. package/dist/utils/utils/kupola.go +120 -0
  163. package/dist/utils/utils/kupola.js +63 -0
  164. package/dist/utils/utils/kupola.py +1392 -0
  165. package/dist/utils/utils/kupola.rb +69 -0
  166. package/icons/activity.svg +3 -0
  167. package/icons/alert-circle.svg +1 -0
  168. package/icons/alert-triangle.svg +1 -0
  169. package/icons/alert.d27e24.svg +1 -0
  170. package/icons/alert.svg +1 -0
  171. package/icons/apple.svg +1 -0
  172. package/icons/arrow-down.svg +1 -0
  173. package/icons/arrow-expand.svg +1 -0
  174. package/icons/arrow-left.svg +1 -0
  175. package/icons/arrow-minimize.svg +1 -0
  176. package/icons/arrow-right-to-line.svg +1 -0
  177. package/icons/arrow-right.svg +1 -0
  178. package/icons/arrow-up-right.svg +1 -0
  179. package/icons/arrow-up.0c0c0d.svg +1 -0
  180. package/icons/arrow-up.svg +1 -0
  181. package/icons/at.svg +1 -0
  182. package/icons/atom.0c0c0d.svg +1 -0
  183. package/icons/atom.svg +1 -0
  184. package/icons/bar-chart-2.svg +1 -0
  185. package/icons/bar.svg +1 -0
  186. package/icons/bell.svg +1 -0
  187. package/icons/box.svg +1 -0
  188. package/icons/bug.svg +1 -0
  189. package/icons/button.svg +1 -0
  190. package/icons/calendar.svg +1 -0
  191. package/icons/check-circle.33c192.svg +1 -0
  192. package/icons/check-circle.svg +1 -0
  193. package/icons/check-square.svg +4 -0
  194. package/icons/check.d1d3db.svg +1 -0
  195. package/icons/check.svg +1 -0
  196. package/icons/chevron-down.svg +1 -0
  197. package/icons/chevron-left.svg +1 -0
  198. package/icons/chevron-right.svg +1 -0
  199. package/icons/chevron-up.svg +1 -0
  200. package/icons/circle.svg +1 -0
  201. package/icons/clock.svg +1 -0
  202. package/icons/cmd.svg +1 -0
  203. package/icons/code.svg +1 -0
  204. package/icons/columns.svg +1 -0
  205. package/icons/copy.svg +1 -0
  206. package/icons/cpu.svg +1 -0
  207. package/icons/dashboard.0c0c0d.svg +1 -0
  208. package/icons/dashboard.svg +1 -0
  209. package/icons/dollar.svg +1 -0
  210. package/icons/download.svg +1 -0
  211. package/icons/edit.svg +1 -0
  212. package/icons/extensions.svg +1 -0
  213. package/icons/external.svg +1 -0
  214. package/icons/eye.svg +1 -0
  215. package/icons/file-text.svg +1 -0
  216. package/icons/file.svg +1 -0
  217. package/icons/files.svg +1 -0
  218. package/icons/filter.svg +1 -0
  219. package/icons/folder-open.svg +4 -0
  220. package/icons/folder.svg +1 -0
  221. package/icons/gear.svg +1 -0
  222. package/icons/git.svg +1 -0
  223. package/icons/github.svg +1 -0
  224. package/icons/globe.svg +1 -0
  225. package/icons/grid-2x2.svg +1 -0
  226. package/icons/hash.svg +1 -0
  227. package/icons/heart.svg +1 -0
  228. package/icons/help-circle.svg +5 -0
  229. package/icons/help.svg +1 -0
  230. package/icons/home.svg +1 -0
  231. package/icons/icons.svg +153 -0
  232. package/icons/image.svg +1 -0
  233. package/icons/info-circle.svg +1 -0
  234. package/icons/info-square.svg +1 -0
  235. package/icons/info.387bff.svg +1 -0
  236. package/icons/info.svg +1 -0
  237. package/icons/input.svg +1 -0
  238. package/icons/key.svg +1 -0
  239. package/icons/layers.svg +1 -0
  240. package/icons/layout-grid.svg +6 -0
  241. package/icons/layout.svg +1 -0
  242. package/icons/link.svg +1 -0
  243. package/icons/list.svg +1 -0
  244. package/icons/lock.svg +1 -0
  245. package/icons/log-out.svg +1 -0
  246. package/icons/logo.svg +1 -0
  247. package/icons/mail.svg +1 -0
  248. package/icons/menu.svg +1 -0
  249. package/icons/message-circle.svg +1 -0
  250. package/icons/message-plus.svg +1 -0
  251. package/icons/message-square.svg +1 -0
  252. package/icons/mic.svg +1 -0
  253. package/icons/minus.svg +1 -0
  254. package/icons/moon.svg +1 -0
  255. package/icons/more-h.svg +1 -0
  256. package/icons/mouse.svg +1 -0
  257. package/icons/palette.svg +1 -0
  258. package/icons/panel-bottom.svg +1 -0
  259. package/icons/pause.svg +1 -0
  260. package/icons/play.svg +1 -0
  261. package/icons/plug.svg +1 -0
  262. package/icons/plus.0c0c0d.svg +1 -0
  263. package/icons/plus.svg +1 -0
  264. package/icons/refresh.svg +1 -0
  265. package/icons/ruler.svg +1 -0
  266. package/icons/scroll-text.svg +1 -0
  267. package/icons/search-menu.svg +1 -0
  268. package/icons/search.svg +1 -0
  269. package/icons/send.0c0c0d.svg +1 -0
  270. package/icons/send.svg +1 -0
  271. package/icons/settings.0c0c0d.svg +1 -0
  272. package/icons/settings.svg +1 -0
  273. package/icons/shield.svg +1 -0
  274. package/icons/sidebar-left.svg +1 -0
  275. package/icons/sidebar-right.svg +1 -0
  276. package/icons/sliders.svg +1 -0
  277. package/icons/sparkles.32f08c.svg +1 -0
  278. package/icons/sparkles.svg +1 -0
  279. package/icons/square.svg +1 -0
  280. package/icons/star.svg +1 -0
  281. package/icons/sun.svg +1 -0
  282. package/icons/table.svg +1 -0
  283. package/icons/terminal.svg +1 -0
  284. package/icons/trash.svg +1 -0
  285. package/icons/trending-down.svg +1 -0
  286. package/icons/trending-up.svg +1 -0
  287. package/icons/type.svg +1 -0
  288. package/icons/upload.svg +1 -0
  289. package/icons/user-circle.svg +1 -0
  290. package/icons/user-plus.svg +6 -0
  291. package/icons/user.svg +1 -0
  292. package/icons/users.svg +1 -0
  293. package/icons/warning.svg +1 -0
  294. package/icons/wrench.svg +1 -0
  295. package/icons/x-circle.svg +1 -0
  296. package/icons/x.svg +1 -0
  297. package/icons/zap.0c0c0d.svg +1 -0
  298. package/icons/zap.svg +1 -0
  299. package/js/calendar.js +184 -0
  300. package/js/carousel.js +173 -0
  301. package/js/collapse.js +127 -0
  302. package/js/color-picker.js +144 -0
  303. package/js/component.js +276 -0
  304. package/js/composition-api.js +458 -0
  305. package/js/countdown.js +144 -0
  306. package/js/data-bind.js +1286 -0
  307. package/js/datepicker.js +270 -0
  308. package/js/dialog.js +131 -0
  309. package/js/drawer.js +118 -0
  310. package/js/dropdown.js +122 -0
  311. package/js/dynamic-tags.js +156 -0
  312. package/js/error-handler.js +181 -0
  313. package/js/fileupload.js +392 -0
  314. package/js/form.js +291 -0
  315. package/js/global-events.js +203 -0
  316. package/js/heatmap.js +405 -0
  317. package/js/http.js +419 -0
  318. package/js/i18n.js +228 -0
  319. package/js/icons.js +165 -0
  320. package/js/image-preview.js +218 -0
  321. package/js/initializer.js +162 -0
  322. package/js/kupola-core.js +66 -0
  323. package/js/kupola-devtools.js +598 -0
  324. package/js/kupola-lifecycle.js +510 -0
  325. package/js/message.js +60 -0
  326. package/js/modal.js +191 -0
  327. package/js/notification.js +73 -0
  328. package/js/numberinput.js +146 -0
  329. package/js/performance.js +250 -0
  330. package/js/registry.js +205 -0
  331. package/js/router.js +396 -0
  332. package/js/security.js +189 -0
  333. package/js/select.js +143 -0
  334. package/js/slide-captcha.js +504 -0
  335. package/js/slider.js +94 -0
  336. package/js/statcard.js +219 -0
  337. package/js/tag.js +83 -0
  338. package/js/test-utils.js +251 -0
  339. package/js/theme.js +363 -0
  340. package/js/timepicker.js +238 -0
  341. package/js/tooltip.js +122 -0
  342. package/js/utils.js +1458 -0
  343. package/js/validation.js +553 -0
  344. package/js/virtual-list.js +593 -0
  345. package/package.json +105 -0
  346. package/templates/base.html +30 -0
  347. package/templates/base_dashboard.html +99 -0
  348. package/types/kupola.d.ts +1359 -0
  349. package/utils/Kupola.cs +77 -0
  350. package/utils/Kupola.java +104 -0
  351. package/utils/kupola.go +120 -0
  352. package/utils/kupola.js +63 -0
  353. package/utils/kupola.py +1392 -0
  354. 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
+ }