slicejs-web-framework 3.0.0 → 3.1.1

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 (118) hide show
  1. package/.worktrees/public-env-browser-exposure/LICENSE +21 -0
  2. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/ContextManager/ContextManager.js +369 -0
  3. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +297 -0
  4. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Controller/Controller.js +972 -0
  5. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Debugger/Debugger.css +620 -0
  6. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Debugger/Debugger.html +73 -0
  7. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Debugger/Debugger.js +1548 -0
  8. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/EventManager/EventManager.js +338 -0
  9. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/EventManager/EventManagerDebugger.js +361 -0
  10. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Logger/Log.js +10 -0
  11. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Logger/Logger.js +146 -0
  12. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/Router/Router.js +721 -0
  13. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/StylesManager/StylesManager.js +78 -0
  14. package/.worktrees/public-env-browser-exposure/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +84 -0
  15. package/.worktrees/public-env-browser-exposure/Slice/Slice.js +533 -0
  16. package/.worktrees/public-env-browser-exposure/Slice/tests/bundle-v2-runtime-contract.test.js +268 -0
  17. package/.worktrees/public-env-browser-exposure/Slice/tests/public-env-runtime-accessors.test.js +44 -0
  18. package/.worktrees/public-env-browser-exposure/Slice/tests/router-loading-finally.test.js +68 -0
  19. package/.worktrees/public-env-browser-exposure/api/index.js +286 -0
  20. package/.worktrees/public-env-browser-exposure/api/middleware/securityMiddleware.js +253 -0
  21. package/.worktrees/public-env-browser-exposure/api/tests/public-env-resolver.test.js +193 -0
  22. package/.worktrees/public-env-browser-exposure/api/utils/publicEnvResolver.js +117 -0
  23. package/.worktrees/public-env-browser-exposure/package.json +37 -0
  24. package/.worktrees/public-env-browser-exposure/sliceConfig.schema.json +109 -0
  25. package/.worktrees/public-env-browser-exposure/src/App/index.html +22 -0
  26. package/.worktrees/public-env-browser-exposure/src/App/index.js +23 -0
  27. package/.worktrees/public-env-browser-exposure/src/App/style.css +40 -0
  28. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/HomePage/HomePage.css +201 -0
  29. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/HomePage/HomePage.html +37 -0
  30. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/HomePage/HomePage.js +210 -0
  31. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/Playground/Playground.css +12 -0
  32. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/Playground/Playground.html +0 -0
  33. package/.worktrees/public-env-browser-exposure/src/Components/AppComponents/Playground/Playground.js +111 -0
  34. package/.worktrees/public-env-browser-exposure/src/Components/Service/FetchManager/FetchManager.js +133 -0
  35. package/.worktrees/public-env-browser-exposure/src/Components/Service/IndexedDbManager/IndexedDbManager.js +141 -0
  36. package/.worktrees/public-env-browser-exposure/src/Components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
  37. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Button/Button.css +47 -0
  38. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Button/Button.html +5 -0
  39. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Button/Button.js +93 -0
  40. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Card/Card.css +68 -0
  41. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Card/Card.html +7 -0
  42. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Card/Card.js +107 -0
  43. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Checkbox/Checkbox.css +87 -0
  44. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Checkbox/Checkbox.html +8 -0
  45. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Checkbox/Checkbox.js +86 -0
  46. package/.worktrees/public-env-browser-exposure/src/Components/Visual/CodeVisualizer/CodeVisualizer.css +130 -0
  47. package/.worktrees/public-env-browser-exposure/src/Components/Visual/CodeVisualizer/CodeVisualizer.html +4 -0
  48. package/.worktrees/public-env-browser-exposure/src/Components/Visual/CodeVisualizer/CodeVisualizer.js +262 -0
  49. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Details/Details.css +70 -0
  50. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Details/Details.html +9 -0
  51. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Details/Details.js +76 -0
  52. package/.worktrees/public-env-browser-exposure/src/Components/Visual/DropDown/DropDown.css +60 -0
  53. package/.worktrees/public-env-browser-exposure/src/Components/Visual/DropDown/DropDown.html +5 -0
  54. package/.worktrees/public-env-browser-exposure/src/Components/Visual/DropDown/DropDown.js +63 -0
  55. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Grid/Grid.css +7 -0
  56. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Grid/Grid.html +1 -0
  57. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Grid/Grid.js +57 -0
  58. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/Icon.css +510 -0
  59. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/Icon.html +1 -0
  60. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/Icon.js +89 -0
  61. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.eot +0 -0
  62. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.json +555 -0
  63. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.styl +507 -0
  64. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.svg +1485 -0
  65. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.symbol.svg +1059 -0
  66. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.ttf +0 -0
  67. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.woff +0 -0
  68. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Icon/slc.woff2 +0 -0
  69. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Input/Input.css +91 -0
  70. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Input/Input.html +4 -0
  71. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Input/Input.js +215 -0
  72. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Layout/Layout.css +0 -0
  73. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Layout/Layout.html +0 -0
  74. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Layout/Layout.js +49 -0
  75. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Link/Link.css +8 -0
  76. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Link/Link.html +1 -0
  77. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Link/Link.js +63 -0
  78. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Loading/Loading.css +56 -0
  79. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Loading/Loading.html +83 -0
  80. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Loading/Loading.js +38 -0
  81. package/.worktrees/public-env-browser-exposure/src/Components/Visual/MultiRoute/MultiRoute.js +93 -0
  82. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Navbar/Navbar.css +115 -0
  83. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Navbar/Navbar.html +44 -0
  84. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Navbar/Navbar.js +141 -0
  85. package/.worktrees/public-env-browser-exposure/src/Components/Visual/NotFound/NotFound.css +117 -0
  86. package/.worktrees/public-env-browser-exposure/src/Components/Visual/NotFound/NotFound.html +24 -0
  87. package/.worktrees/public-env-browser-exposure/src/Components/Visual/NotFound/NotFound.js +16 -0
  88. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Route/Route.js +93 -0
  89. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Select/Select.css +84 -0
  90. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Select/Select.html +8 -0
  91. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Select/Select.js +195 -0
  92. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Switch/Switch.css +76 -0
  93. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Switch/Switch.html +8 -0
  94. package/.worktrees/public-env-browser-exposure/src/Components/Visual/Switch/Switch.js +102 -0
  95. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeItem/TreeItem.css +36 -0
  96. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeItem/TreeItem.html +1 -0
  97. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeItem/TreeItem.js +126 -0
  98. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeView/TreeView.css +8 -0
  99. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeView/TreeView.html +1 -0
  100. package/.worktrees/public-env-browser-exposure/src/Components/Visual/TreeView/TreeView.js +48 -0
  101. package/.worktrees/public-env-browser-exposure/src/Components/components.js +27 -0
  102. package/.worktrees/public-env-browser-exposure/src/Styles/sliceStyles.css +34 -0
  103. package/.worktrees/public-env-browser-exposure/src/Themes/Dark.css +42 -0
  104. package/.worktrees/public-env-browser-exposure/src/Themes/Light.css +31 -0
  105. package/.worktrees/public-env-browser-exposure/src/Themes/Slice.css +47 -0
  106. package/.worktrees/public-env-browser-exposure/src/images/Slice.js-logo.png +0 -0
  107. package/.worktrees/public-env-browser-exposure/src/images/favicon.ico +0 -0
  108. package/.worktrees/public-env-browser-exposure/src/images/im2/Slice.js-logo.png +0 -0
  109. package/.worktrees/public-env-browser-exposure/src/routes.js +16 -0
  110. package/.worktrees/public-env-browser-exposure/src/sliceConfig.json +73 -0
  111. package/.worktrees/public-env-browser-exposure/src/testing.js +888 -0
  112. package/Slice/Slice.js +38 -8
  113. package/Slice/tests/build-js-only-visual-components.test.js +129 -0
  114. package/Slice/tests/public-env-runtime-accessors.test.js +44 -0
  115. package/api/index.js +12 -12
  116. package/api/tests/public-env-resolver.test.js +193 -0
  117. package/api/utils/publicEnvResolver.js +117 -0
  118. package/package.json +1 -1
@@ -0,0 +1,338 @@
1
+ /**
2
+ * EventManager - Sistema de eventos pub/sub para Slice.js
3
+ * Ubicación: /Slice/Components/Structural/EventManager/EventManager.js
4
+ *
5
+ * Características:
6
+ * - Suscripciones globales y vinculadas a componentes
7
+ * - Auto-limpieza cuando componentes se destruyen
8
+ * - API simple: subscribe, subscribeOnce, unsubscribe, emit
9
+ */
10
+ /**
11
+ * @typedef {Object} EventManagerBind
12
+ * @property {(eventName: string, callback: Function) => string|null} subscribe
13
+ * @property {(eventName: string, callback: Function) => string|null} subscribeOnce
14
+ * @property {(eventName: string, data?: any) => void} emit
15
+ */
16
+
17
+
18
+ export default class EventManager {
19
+ constructor() {
20
+ // Map<eventName, Map<subscriptionId, { callback, componentSliceId, once }>>
21
+ this.subscriptions = new Map();
22
+
23
+ // Map<sliceId, Set<{ eventName, subscriptionId }>> - Para auto-cleanup
24
+ this.componentSubscriptions = new Map();
25
+
26
+ // Contador para IDs únicos
27
+ this.idCounter = 0;
28
+ }
29
+
30
+ init() {
31
+ return true;
32
+ }
33
+
34
+ // ============================================
35
+ // API PRINCIPAL
36
+ // ============================================
37
+
38
+ /**
39
+ * Suscribirse a un evento
40
+ * @param {string} eventName - Nombre del evento
41
+ * @param {(data?: any) => void} callback - Funcion a ejecutar cuando se emita el evento
42
+ * @param {{ component?: HTMLElement }} [options]
43
+ * @returns {string|null} subscriptionId - ID para desuscribirse
44
+ *
45
+ * @example
46
+ * // Suscripcion global
47
+ * const id = slice.events.subscribe('user:login', (user) => {
48
+ * console.log('Usuario:', user);
49
+ * });
50
+ *
51
+ * // Suscripcion con auto-cleanup
52
+ * slice.events.subscribe('user:login', (user) => {
53
+ * this.actualizar(user);
54
+ * }, { component: this });
55
+ */
56
+ subscribe(eventName, callback, options = {}) {
57
+ if (typeof callback !== 'function') {
58
+ slice.logger.logError('EventManager', 'El callback debe ser una función');
59
+ return null;
60
+ }
61
+
62
+ const subscriptionId = `evt_${++this.idCounter}`;
63
+
64
+ // Crear Map para este evento si no existe
65
+ if (!this.subscriptions.has(eventName)) {
66
+ this.subscriptions.set(eventName, new Map());
67
+ }
68
+
69
+ // Guardar la suscripción
70
+ this.subscriptions.get(eventName).set(subscriptionId, {
71
+ callback,
72
+ componentSliceId: options.component?.sliceId || null,
73
+ once: false,
74
+ });
75
+
76
+ // Si hay componente, registrar para auto-cleanup
77
+ if (options.component?.sliceId) {
78
+ this._registerComponentSubscription(options.component.sliceId, eventName, subscriptionId);
79
+ }
80
+
81
+ slice.logger.logInfo('EventManager', `Suscrito a "${eventName}" [${subscriptionId}]`);
82
+
83
+ return subscriptionId;
84
+ }
85
+
86
+ /**
87
+ * Suscribirse a un evento una sola vez
88
+ * @param {string} eventName - Nombre del evento
89
+ * @param {(data?: any) => void} callback - Funcion a ejecutar
90
+ * @param {{ component?: HTMLElement }} [options]
91
+ * @returns {string|null} subscriptionId
92
+ *
93
+ * @example
94
+ * slice.events.subscribeOnce('app:ready', () => {
95
+ * console.log('App lista!');
96
+ * });
97
+ */
98
+ subscribeOnce(eventName, callback, options = {}) {
99
+ if (typeof callback !== 'function') {
100
+ slice.logger.logError('EventManager', 'El callback debe ser una función');
101
+ return null;
102
+ }
103
+
104
+ const subscriptionId = `evt_${++this.idCounter}`;
105
+
106
+ if (!this.subscriptions.has(eventName)) {
107
+ this.subscriptions.set(eventName, new Map());
108
+ }
109
+
110
+ this.subscriptions.get(eventName).set(subscriptionId, {
111
+ callback,
112
+ componentSliceId: options.component?.sliceId || null,
113
+ once: true,
114
+ });
115
+
116
+ if (options.component?.sliceId) {
117
+ this._registerComponentSubscription(options.component.sliceId, eventName, subscriptionId);
118
+ }
119
+
120
+ slice.logger.logInfo('EventManager', `Suscrito (once) a "${eventName}" [${subscriptionId}]`);
121
+
122
+ return subscriptionId;
123
+ }
124
+
125
+ /**
126
+ * Desuscribirse de un evento
127
+ * @param {string} eventName - Nombre del evento
128
+ * @param {string} subscriptionId - ID de la suscripcion
129
+ * @returns {boolean} true si se elimino correctamente
130
+ *
131
+ * @example
132
+ * const id = slice.events.subscribe('evento', callback);
133
+ * // Despues...
134
+ * slice.events.unsubscribe('evento', id);
135
+ */
136
+ unsubscribe(eventName, subscriptionId) {
137
+ if (!this.subscriptions.has(eventName)) {
138
+ return false;
139
+ }
140
+
141
+ const removed = this.subscriptions.get(eventName).delete(subscriptionId);
142
+
143
+ // Limpiar Map vacío
144
+ if (this.subscriptions.get(eventName).size === 0) {
145
+ this.subscriptions.delete(eventName);
146
+ }
147
+
148
+ if (removed) {
149
+ slice.logger.logInfo('EventManager', `Desuscrito de "${eventName}" [${subscriptionId}]`);
150
+ }
151
+
152
+ return removed;
153
+ }
154
+
155
+ /**
156
+ * Emitir un evento
157
+ * @param {string} eventName - Nombre del evento
158
+ * @param {any} [data] - Datos a pasar a los callbacks
159
+ * @returns {void}
160
+ *
161
+ * @example
162
+ * slice.events.emit('user:login', { id: 123, name: 'Juan' });
163
+ * slice.events.emit('cart:cleared'); // Sin datos
164
+ */
165
+ emit(eventName, data = null) {
166
+ slice.logger.logInfo('EventManager', `Emitiendo "${eventName}"`, data);
167
+
168
+ if (!this.subscriptions.has(eventName)) {
169
+ return;
170
+ }
171
+
172
+ const toRemove = [];
173
+
174
+ // Notificar a todos los suscriptores
175
+ for (const [subscriptionId, subscription] of this.subscriptions.get(eventName)) {
176
+ // Verificar que el componente aún existe (si aplica)
177
+ if (subscription.componentSliceId) {
178
+ if (!slice.controller.activeComponents.has(subscription.componentSliceId)) {
179
+ // Componente ya no existe, marcar para eliminar
180
+ toRemove.push(subscriptionId);
181
+ continue;
182
+ }
183
+ }
184
+
185
+ // Ejecutar callback
186
+ try {
187
+ subscription.callback(data);
188
+ } catch (error) {
189
+ slice.logger.logError('EventManager', `Error en callback de "${eventName}" [${subscriptionId}]`, error);
190
+ }
191
+
192
+ // Si es subscribeOnce, marcar para eliminar
193
+ if (subscription.once) {
194
+ toRemove.push(subscriptionId);
195
+ }
196
+ }
197
+
198
+ // Limpiar suscripciones marcadas
199
+ toRemove.forEach((id) => {
200
+ this.subscriptions.get(eventName).delete(id);
201
+ });
202
+
203
+ // Limpiar Map vacío
204
+ if (this.subscriptions.get(eventName).size === 0) {
205
+ this.subscriptions.delete(eventName);
206
+ }
207
+ }
208
+
209
+ // ============================================
210
+ // BIND - Vinculación a Componente
211
+ // ============================================
212
+
213
+ /**
214
+ * Vincular el EventManager a un componente para auto-cleanup
215
+ * @param {HTMLElement} component - Componente Slice con sliceId
216
+ * @returns {EventManagerBind|null} API vinculada al componente
217
+ *
218
+ * @example
219
+ * class MiComponente extends HTMLElement {
220
+ * async init() {
221
+ * this.events = slice.events.bind(this);
222
+ *
223
+ * this.events.subscribe('user:login', (user) => {
224
+ * this.actualizar(user);
225
+ * });
226
+ * }
227
+ * }
228
+ */
229
+ bind(component) {
230
+ if (!component?.sliceId) {
231
+ slice.logger.logError('EventManager', 'bind() requiere un componente Slice válido con sliceId');
232
+ return null;
233
+ }
234
+
235
+ const self = this;
236
+
237
+ return {
238
+ /**
239
+ * Suscribirse a un evento (auto-cleanup)
240
+ */
241
+ subscribe: (eventName, callback) => {
242
+ return self.subscribe(eventName, callback, { component });
243
+ },
244
+
245
+ /**
246
+ * Suscribirse una sola vez (auto-cleanup)
247
+ */
248
+ subscribeOnce: (eventName, callback) => {
249
+ return self.subscribeOnce(eventName, callback, { component });
250
+ },
251
+
252
+ /**
253
+ * Emitir un evento
254
+ */
255
+ emit: (eventName, data) => {
256
+ self.emit(eventName, data);
257
+ },
258
+ };
259
+ }
260
+
261
+ // ============================================
262
+ // AUTO-CLEANUP
263
+ // ============================================
264
+
265
+ /**
266
+ * Registrar suscripción para un componente (interno)
267
+ */
268
+ _registerComponentSubscription(sliceId, eventName, subscriptionId) {
269
+ if (!this.componentSubscriptions.has(sliceId)) {
270
+ this.componentSubscriptions.set(sliceId, new Set());
271
+ }
272
+ this.componentSubscriptions.get(sliceId).add({ eventName, subscriptionId });
273
+ }
274
+
275
+ /**
276
+ * Limpiar todas las suscripciones de un componente
277
+ * Se llama automáticamente cuando el componente se destruye
278
+ * @param {string} sliceId - ID del componente
279
+ * @returns {number} Cantidad de suscripciones eliminadas
280
+ */
281
+ cleanupComponent(sliceId) {
282
+ if (!this.componentSubscriptions.has(sliceId)) {
283
+ return 0;
284
+ }
285
+
286
+ const subscriptions = this.componentSubscriptions.get(sliceId);
287
+ let count = 0;
288
+
289
+ for (const { eventName, subscriptionId } of subscriptions) {
290
+ if (this.unsubscribe(eventName, subscriptionId)) {
291
+ count++;
292
+ }
293
+ }
294
+
295
+ this.componentSubscriptions.delete(sliceId);
296
+
297
+ if (count > 0) {
298
+ slice.logger.logInfo('EventManager', `Limpiadas ${count} suscripción(es) de ${sliceId}`);
299
+ }
300
+
301
+ return count;
302
+ }
303
+
304
+ // ============================================
305
+ // UTILIDADES
306
+ // ============================================
307
+
308
+ /**
309
+ * Verificar si hay suscriptores para un evento
310
+ * @param {string} eventName - Nombre del evento
311
+ * @returns {boolean}
312
+ */
313
+ hasSubscribers(eventName) {
314
+ return this.subscriptions.has(eventName) && this.subscriptions.get(eventName).size > 0;
315
+ }
316
+
317
+ /**
318
+ * Obtener cantidad de suscriptores para un evento
319
+ * @param {string} eventName - Nombre del evento
320
+ * @returns {number}
321
+ */
322
+ subscriberCount(eventName) {
323
+ if (!this.subscriptions.has(eventName)) {
324
+ return 0;
325
+ }
326
+ return this.subscriptions.get(eventName).size;
327
+ }
328
+
329
+ /**
330
+ * Limpiar TODAS las suscripciones (usar con cuidado)
331
+ */
332
+ clear() {
333
+ this.subscriptions.clear();
334
+ this.componentSubscriptions.clear();
335
+ this.idCounter = 0;
336
+ slice.logger.logInfo('EventManager', 'Todas las suscripciones eliminadas');
337
+ }
338
+ }
@@ -0,0 +1,361 @@
1
+ /**
2
+ * EventManager debug panel.
3
+ */
4
+ export default class EventManagerDebugger extends HTMLElement {
5
+ constructor() {
6
+ super();
7
+ this.isOpen = false;
8
+ this.filterText = '';
9
+ this.refreshInterval = null;
10
+ }
11
+
12
+ /**
13
+ * Initialize panel UI.
14
+ * @returns {Promise<void>}
15
+ */
16
+ async init() {
17
+ this.innerHTML = this.renderTemplate();
18
+ slice.stylesManager.registerComponentStyles('EventManagerDebugger', this.renderStyles());
19
+ this.cacheElements();
20
+ this.bindEvents();
21
+ this.makeDraggable();
22
+ this.renderList();
23
+ }
24
+
25
+ /**
26
+ * Toggle panel visibility.
27
+ * @returns {void}
28
+ */
29
+ toggle() {
30
+ this.isOpen = !this.isOpen;
31
+ this.container.classList.toggle('active', this.isOpen);
32
+ if (this.isOpen) {
33
+ this.renderList();
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Show panel.
39
+ * @returns {void}
40
+ */
41
+ open() {
42
+ this.isOpen = true;
43
+ this.container.classList.add('active');
44
+ this.renderList();
45
+ }
46
+
47
+ /**
48
+ * Hide panel.
49
+ * @returns {void}
50
+ */
51
+ close() {
52
+ this.isOpen = false;
53
+ this.container.classList.remove('active');
54
+ }
55
+
56
+ cacheElements() {
57
+ this.container = this.querySelector('#events-debugger');
58
+ this.header = this.querySelector('.events-header');
59
+ this.list = this.querySelector('#events-list');
60
+ this.filterInput = this.querySelector('#events-filter');
61
+ this.countLabel = this.querySelector('#events-count');
62
+ this.refreshButton = this.querySelector('#events-refresh');
63
+ this.closeButton = this.querySelector('#events-close');
64
+ }
65
+
66
+ bindEvents() {
67
+ this.refreshButton.addEventListener('click', () => this.renderList());
68
+ this.closeButton.addEventListener('click', () => this.close());
69
+ this.filterInput.addEventListener('input', (event) => {
70
+ this.filterText = event.target.value.trim().toLowerCase();
71
+ this.renderList();
72
+ });
73
+ }
74
+
75
+ makeDraggable() {
76
+ if (!this.header || !this.container) return;
77
+
78
+ let offset = { x: 0, y: 0 };
79
+ let isDragging = false;
80
+
81
+ this.header.style.cursor = 'grab';
82
+
83
+ this.header.addEventListener('mousedown', (event) => {
84
+ if (event.target.closest('.btn')) return;
85
+ isDragging = true;
86
+ offset.x = event.clientX - this.container.getBoundingClientRect().left;
87
+ offset.y = event.clientY - this.container.getBoundingClientRect().top;
88
+ this.header.style.cursor = 'grabbing';
89
+ });
90
+
91
+ document.addEventListener('mousemove', (event) => {
92
+ if (!isDragging) return;
93
+ const rect = this.container.getBoundingClientRect();
94
+ const maxX = window.innerWidth - rect.width;
95
+ const maxY = window.innerHeight - rect.height;
96
+ const x = Math.min(Math.max(event.clientX - offset.x, 0), maxX);
97
+ const y = Math.min(Math.max(event.clientY - offset.y, 0), maxY);
98
+ this.container.style.left = `${x}px`;
99
+ this.container.style.top = `${y}px`;
100
+ this.container.style.right = 'auto';
101
+ this.container.style.bottom = 'auto';
102
+ });
103
+
104
+ document.addEventListener('mouseup', () => {
105
+ if (!isDragging) return;
106
+ isDragging = false;
107
+ this.header.style.cursor = 'grab';
108
+ });
109
+ }
110
+
111
+ renderList() {
112
+ if (!slice?.events?.subscriptions) {
113
+ this.list.textContent = 'EventManager not available.';
114
+ this.countLabel.textContent = '0';
115
+ return;
116
+ }
117
+
118
+ const items = [];
119
+ slice.events.subscriptions.forEach((subs, eventName) => {
120
+ const entries = Array.from(subs.entries()).map(([id, sub]) => {
121
+ const componentSliceId = sub.componentSliceId || null;
122
+ const component = componentSliceId ? slice.controller.getComponent(componentSliceId) : null;
123
+ const componentName = component?.constructor?.name || null;
124
+ return {
125
+ id,
126
+ once: sub.once,
127
+ componentSliceId,
128
+ componentName
129
+ };
130
+ });
131
+
132
+ if (this.filterText && !eventName.toLowerCase().includes(this.filterText)) {
133
+ return;
134
+ }
135
+
136
+ items.push({ eventName, count: subs.size, entries });
137
+ });
138
+
139
+ items.sort((a, b) => a.eventName.localeCompare(b.eventName));
140
+
141
+ this.countLabel.textContent = String(items.length);
142
+ this.list.innerHTML = items.length
143
+ ? items.map((item) => {
144
+ const details = item.entries.map((entry) => {
145
+ const label = entry.componentName
146
+ ? `${entry.componentName} (${entry.componentSliceId})`
147
+ : entry.componentSliceId || 'Global';
148
+ const onceBadge = entry.once ? '<span class="badge">once</span>' : '';
149
+ return `
150
+ <div class="subscriber-row">
151
+ <div class="subscriber-name">${label}</div>
152
+ <div class="subscriber-meta">${entry.id}${onceBadge}</div>
153
+ </div>
154
+ `;
155
+ }).join('');
156
+
157
+ return `
158
+ <details class="event-row">
159
+ <summary>
160
+ <div class="event-name">${item.eventName}</div>
161
+ <div class="event-count">${item.count}</div>
162
+ </summary>
163
+ <div class="subscriber-list">
164
+ ${details || '<div class="empty">No subscribers</div>'}
165
+ </div>
166
+ </details>
167
+ `;
168
+ }).join('')
169
+ : '<div class="empty">No events</div>';
170
+ }
171
+
172
+ renderTemplate() {
173
+ return `
174
+ <div id="events-debugger">
175
+ <div class="events-header">
176
+ <div class="title">Events</div>
177
+ <div class="actions">
178
+ <button id="events-refresh" class="btn">Refresh</button>
179
+ <button id="events-close" class="btn">Close</button>
180
+ </div>
181
+ </div>
182
+ <div class="events-toolbar">
183
+ <input id="events-filter" type="text" placeholder="Filter events" />
184
+ <div class="count">Total: <span id="events-count">0</span></div>
185
+ </div>
186
+ <div class="events-list" id="events-list"></div>
187
+ </div>
188
+ `;
189
+ }
190
+
191
+ renderStyles() {
192
+ return `
193
+ #events-debugger {
194
+ position: fixed;
195
+ bottom: 20px;
196
+ right: 20px;
197
+ width: min(360px, calc(100vw - 40px));
198
+ max-height: 60vh;
199
+ background: var(--primary-background-color);
200
+ border: 1px solid var(--medium-color);
201
+ border-radius: 12px;
202
+ box-shadow: 0 16px 32px rgba(0, 0, 0, 0.15);
203
+ display: none;
204
+ flex-direction: column;
205
+ z-index: 10001;
206
+ overflow: hidden;
207
+ }
208
+
209
+ #events-debugger.active {
210
+ display: flex;
211
+ }
212
+
213
+ #events-debugger * {
214
+ box-sizing: border-box;
215
+ }
216
+
217
+ .events-header {
218
+ display: flex;
219
+ justify-content: space-between;
220
+ align-items: center;
221
+ padding: 12px 14px;
222
+ background: var(--tertiary-background-color);
223
+ border-bottom: 1px solid var(--medium-color);
224
+ user-select: none;
225
+ }
226
+
227
+ .events-header .title {
228
+ font-weight: 600;
229
+ color: var(--font-primary-color);
230
+ }
231
+
232
+ .events-header .actions {
233
+ display: flex;
234
+ gap: 8px;
235
+ }
236
+
237
+ .events-header .btn {
238
+ padding: 6px 10px;
239
+ border-radius: 6px;
240
+ border: 1px solid var(--medium-color);
241
+ background: var(--primary-background-color);
242
+ color: var(--font-primary-color);
243
+ cursor: pointer;
244
+ font-size: 12px;
245
+ }
246
+
247
+ .events-toolbar {
248
+ display: flex;
249
+ gap: 10px;
250
+ align-items: center;
251
+ padding: 10px 12px;
252
+ border-bottom: 1px solid var(--medium-color);
253
+ }
254
+
255
+ .events-toolbar input {
256
+ flex: 1;
257
+ min-width: 0;
258
+ padding: 6px 8px;
259
+ border-radius: 6px;
260
+ border: 1px solid var(--medium-color);
261
+ background: var(--primary-background-color);
262
+ color: var(--font-primary-color);
263
+ }
264
+
265
+ .events-list {
266
+ padding: 10px 12px;
267
+ overflow: auto;
268
+ display: flex;
269
+ flex-direction: column;
270
+ gap: 8px;
271
+ }
272
+
273
+ .event-row {
274
+ display: block;
275
+ padding: 8px 10px;
276
+ background: var(--tertiary-background-color);
277
+ border-radius: 6px;
278
+ border: 1px solid var(--medium-color);
279
+ }
280
+
281
+ .event-row summary {
282
+ display: flex;
283
+ align-items: center;
284
+ justify-content: space-between;
285
+ gap: 8px;
286
+ cursor: pointer;
287
+ list-style: none;
288
+ }
289
+
290
+ .event-row summary::-webkit-details-marker {
291
+ display: none;
292
+ }
293
+
294
+ .event-name {
295
+ font-family: monospace;
296
+ font-size: 12px;
297
+ color: var(--font-primary-color);
298
+ overflow: hidden;
299
+ text-overflow: ellipsis;
300
+ white-space: nowrap;
301
+ }
302
+
303
+ .event-count {
304
+ font-weight: 600;
305
+ color: var(--primary-color);
306
+ }
307
+
308
+ .subscriber-list {
309
+ margin-top: 10px;
310
+ display: flex;
311
+ flex-direction: column;
312
+ gap: 8px;
313
+ }
314
+
315
+ .subscriber-row {
316
+ display: flex;
317
+ justify-content: space-between;
318
+ gap: 8px;
319
+ padding: 6px 8px;
320
+ border-radius: 6px;
321
+ background: var(--primary-background-color);
322
+ border: 1px solid var(--medium-color);
323
+ }
324
+
325
+ .subscriber-name {
326
+ font-size: 12px;
327
+ color: var(--font-primary-color);
328
+ overflow: hidden;
329
+ text-overflow: ellipsis;
330
+ white-space: nowrap;
331
+ }
332
+
333
+ .subscriber-meta {
334
+ font-size: 11px;
335
+ color: var(--font-secondary-color);
336
+ display: flex;
337
+ align-items: center;
338
+ gap: 6px;
339
+ white-space: nowrap;
340
+ }
341
+
342
+ .badge {
343
+ padding: 2px 6px;
344
+ border-radius: 999px;
345
+ background: var(--secondary-color);
346
+ color: var(--secondary-color-contrast);
347
+ font-size: 10px;
348
+ text-transform: uppercase;
349
+ }
350
+
351
+ .empty {
352
+ color: var(--font-secondary-color);
353
+ font-size: 12px;
354
+ text-align: center;
355
+ padding: 12px 0;
356
+ }
357
+ `;
358
+ }
359
+ }
360
+
361
+ customElements.define('slice-eventmanager-debugger', EventManagerDebugger);
@@ -0,0 +1,10 @@
1
+ export default class Log {
2
+ constructor(logType, componentCategory, componentSliceId, message, error = null) {
3
+ this.logType = logType;
4
+ this.componentCategory = componentCategory;
5
+ this.componentSliceId = componentSliceId;
6
+ this.message = message;
7
+ this.error = error;
8
+ this.timestamp = new Date();
9
+ }
10
+ }