@decido/shell-vscode-core 1.0.0 → 4.0.2

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 (256) hide show
  1. package/README.md +31 -0
  2. package/package.json +14 -13
  3. package/.turbo/turbo-build.log +0 -13
  4. package/dist/appState.d.ts +0 -23
  5. package/dist/appState.d.ts.map +0 -1
  6. package/dist/appState.js +0 -138
  7. package/dist/core/AIService.d.ts +0 -33
  8. package/dist/core/AIService.d.ts.map +0 -1
  9. package/dist/core/AIService.js +0 -73
  10. package/dist/core/ApiService.d.ts +0 -34
  11. package/dist/core/ApiService.d.ts.map +0 -1
  12. package/dist/core/ApiService.js +0 -32
  13. package/dist/core/AuthService.d.ts +0 -31
  14. package/dist/core/AuthService.d.ts.map +0 -1
  15. package/dist/core/AuthService.js +0 -56
  16. package/dist/core/BaseService.d.ts +0 -29
  17. package/dist/core/BaseService.d.ts.map +0 -1
  18. package/dist/core/BaseService.js +0 -33
  19. package/dist/core/CalendarService.d.ts +0 -15
  20. package/dist/core/CalendarService.d.ts.map +0 -1
  21. package/dist/core/CalendarService.js +0 -32
  22. package/dist/core/CommandService.d.ts +0 -25
  23. package/dist/core/CommandService.d.ts.map +0 -1
  24. package/dist/core/CommandService.js +0 -52
  25. package/dist/core/DebugPanelService.d.ts +0 -12
  26. package/dist/core/DebugPanelService.d.ts.map +0 -1
  27. package/dist/core/DebugPanelService.js +0 -29
  28. package/dist/core/DebugService.d.ts +0 -57
  29. package/dist/core/DebugService.d.ts.map +0 -1
  30. package/dist/core/DebugService.js +0 -134
  31. package/dist/core/EventBus.d.ts +0 -32
  32. package/dist/core/EventBus.d.ts.map +0 -1
  33. package/dist/core/EventBus.js +0 -51
  34. package/dist/core/EventHandler.d.ts +0 -3
  35. package/dist/core/EventHandler.d.ts.map +0 -1
  36. package/dist/core/EventHandler.js +0 -82
  37. package/dist/core/GamificationService.d.ts +0 -19
  38. package/dist/core/GamificationService.d.ts.map +0 -1
  39. package/dist/core/GamificationService.js +0 -102
  40. package/dist/core/HookService.d.ts +0 -34
  41. package/dist/core/HookService.d.ts.map +0 -1
  42. package/dist/core/HookService.js +0 -64
  43. package/dist/core/LayoutService.d.ts +0 -61
  44. package/dist/core/LayoutService.d.ts.map +0 -1
  45. package/dist/core/LayoutService.js +0 -223
  46. package/dist/core/ModalService.d.ts +0 -21
  47. package/dist/core/ModalService.d.ts.map +0 -1
  48. package/dist/core/ModalService.js +0 -71
  49. package/dist/core/NotificationService.d.ts +0 -7
  50. package/dist/core/NotificationService.d.ts.map +0 -1
  51. package/dist/core/NotificationService.js +0 -42
  52. package/dist/core/RouterService.d.ts +0 -13
  53. package/dist/core/RouterService.d.ts.map +0 -1
  54. package/dist/core/RouterService.js +0 -54
  55. package/dist/core/ServiceContainer.d.ts +0 -18
  56. package/dist/core/ServiceContainer.d.ts.map +0 -1
  57. package/dist/core/ServiceContainer.js +0 -27
  58. package/dist/core/ShortcutService.d.ts +0 -17
  59. package/dist/core/ShortcutService.d.ts.map +0 -1
  60. package/dist/core/ShortcutService.js +0 -37
  61. package/dist/core/StorageService.d.ts +0 -36
  62. package/dist/core/StorageService.d.ts.map +0 -1
  63. package/dist/core/StorageService.js +0 -101
  64. package/dist/core/ThemeService.d.ts +0 -12
  65. package/dist/core/ThemeService.d.ts.map +0 -1
  66. package/dist/core/ThemeService.js +0 -60
  67. package/dist/core/WebSocketService.d.ts +0 -16
  68. package/dist/core/WebSocketService.d.ts.map +0 -1
  69. package/dist/core/WebSocketService.js +0 -22
  70. package/dist/core/api.d.ts +0 -70
  71. package/dist/core/api.d.ts.map +0 -1
  72. package/dist/core/api.js +0 -1
  73. package/dist/core/app/ModuleManager copy.d.ts +0 -23
  74. package/dist/core/app/ModuleManager copy.js +0 -52
  75. package/dist/core/app/ModuleManager.d.ts +0 -60
  76. package/dist/core/app/ModuleManager.d.ts.map +0 -1
  77. package/dist/core/app/ModuleManager.js +0 -217
  78. package/dist/core/app/apiFactory.d.ts +0 -4
  79. package/dist/core/app/apiFactory.d.ts.map +0 -1
  80. package/dist/core/app/apiFactory.js +0 -120
  81. package/dist/core/app/commandManager.d.ts +0 -3
  82. package/dist/core/app/commandManager.d.ts.map +0 -1
  83. package/dist/core/app/commandManager.js +0 -195
  84. package/dist/core/app/moduleLoader.d.ts +0 -11
  85. package/dist/core/app/moduleLoader.d.ts.map +0 -1
  86. package/dist/core/app/moduleLoader.js +0 -30
  87. package/dist/core/app/routeManager.d.ts +0 -2
  88. package/dist/core/app/routeManager.d.ts.map +0 -1
  89. package/dist/core/app/routeManager.js +0 -7
  90. package/dist/core/index.d.ts +0 -16
  91. package/dist/core/index.d.ts.map +0 -1
  92. package/dist/core/index.js +0 -15
  93. package/dist/core/layout/dragDropManager.d.ts +0 -8
  94. package/dist/core/layout/dragDropManager.d.ts.map +0 -1
  95. package/dist/core/layout/dragDropManager.js +0 -8
  96. package/dist/core/layout/paneManager.d.ts +0 -7
  97. package/dist/core/layout/paneManager.d.ts.map +0 -1
  98. package/dist/core/layout/paneManager.js +0 -7
  99. package/dist/core/layout/renderer.d.ts +0 -8
  100. package/dist/core/layout/renderer.d.ts.map +0 -1
  101. package/dist/core/layout/renderer.js +0 -8
  102. package/dist/core/layout/resizeManager.d.ts +0 -5
  103. package/dist/core/layout/resizeManager.d.ts.map +0 -1
  104. package/dist/core/layout/resizeManager.js +0 -5
  105. package/dist/core/signals.d.ts +0 -20
  106. package/dist/core/signals.d.ts.map +0 -1
  107. package/dist/core/signals.js +0 -66
  108. package/dist/core/uiState.d.ts +0 -9
  109. package/dist/core/uiState.d.ts.map +0 -1
  110. package/dist/core/uiState.js +0 -11
  111. package/dist/index.d.ts +0 -17
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js +0 -15
  114. package/dist/lib/local-db.d.ts +0 -43
  115. package/dist/lib/local-db.d.ts.map +0 -1
  116. package/dist/lib/local-db.js +0 -23
  117. package/dist/lib/sync-service.d.ts +0 -7
  118. package/dist/lib/sync-service.d.ts.map +0 -1
  119. package/dist/lib/sync-service.js +0 -41
  120. package/dist/platform/ILayoutService.d.ts +0 -63
  121. package/dist/platform/ILayoutService.d.ts.map +0 -1
  122. package/dist/platform/ILayoutService.js +0 -1
  123. package/dist/platform/IRenderer.d.ts +0 -16
  124. package/dist/platform/IRenderer.d.ts.map +0 -1
  125. package/dist/platform/IRenderer.js +0 -1
  126. package/dist/platform/ServiceRegistry.d.ts +0 -43
  127. package/dist/platform/ServiceRegistry.d.ts.map +0 -1
  128. package/dist/platform/ServiceRegistry.js +0 -2
  129. package/dist/platform/extensionPoints.d.ts +0 -70
  130. package/dist/platform/extensionPoints.d.ts.map +0 -1
  131. package/dist/platform/extensionPoints.js +0 -22
  132. package/dist/platform/index.d.ts +0 -5
  133. package/dist/platform/index.d.ts.map +0 -1
  134. package/dist/platform/index.js +0 -4
  135. package/dist/stores/editorStore.d.ts +0 -5
  136. package/dist/stores/editorStore.d.ts.map +0 -1
  137. package/dist/stores/editorStore.js +0 -4
  138. package/dist/stores/gamificationStore.d.ts +0 -3
  139. package/dist/stores/gamificationStore.d.ts.map +0 -1
  140. package/dist/stores/gamificationStore.js +0 -2
  141. package/dist/stores/historyStore.d.ts +0 -12
  142. package/dist/stores/historyStore.d.ts.map +0 -1
  143. package/dist/stores/historyStore.js +0 -6
  144. package/dist/stores/workspaceStore.d.ts +0 -13
  145. package/dist/stores/workspaceStore.d.ts.map +0 -1
  146. package/dist/stores/workspaceStore.js +0 -6
  147. package/dist/types/app.d.ts +0 -31
  148. package/dist/types/app.d.ts.map +0 -1
  149. package/dist/types/app.js +0 -1
  150. package/dist/types/debug.d.ts +0 -68
  151. package/dist/types/debug.d.ts.map +0 -1
  152. package/dist/types/debug.js +0 -1
  153. package/dist/types/entities.d.ts +0 -42
  154. package/dist/types/entities.js +0 -2
  155. package/dist/types/index.d.ts +0 -3
  156. package/dist/types/index.d.ts.map +0 -1
  157. package/dist/types/index.js +0 -3
  158. package/dist/types/modules.d.ts +0 -66
  159. package/dist/types/modules.js +0 -2
  160. package/dist/types/platform.d.ts +0 -95
  161. package/dist/types/platform.d.ts.map +0 -1
  162. package/dist/types/platform.js +0 -2
  163. package/dist/ui/Palette.d.ts +0 -38
  164. package/dist/ui/Palette.d.ts.map +0 -1
  165. package/dist/ui/Palette.js +0 -144
  166. package/dist/ui/debug-panel/dragAndResize.d.ts +0 -6
  167. package/dist/ui/debug-panel/dragAndResize.d.ts.map +0 -1
  168. package/dist/ui/debug-panel/dragAndResize.js +0 -140
  169. package/dist/ui/debug-panel/eventBinder.d.ts +0 -5
  170. package/dist/ui/debug-panel/eventBinder.d.ts.map +0 -1
  171. package/dist/ui/debug-panel/eventBinder.js +0 -120
  172. package/dist/ui/debug-panel/layoutManager.d.ts +0 -16
  173. package/dist/ui/debug-panel/layoutManager.d.ts.map +0 -1
  174. package/dist/ui/debug-panel/layoutManager.js +0 -73
  175. package/dist/ui/debug-panel/main.d.ts +0 -12
  176. package/dist/ui/debug-panel/main.d.ts.map +0 -1
  177. package/dist/ui/debug-panel/main.js +0 -42
  178. package/dist/ui/debug-panel/panelManager.d.ts +0 -17
  179. package/dist/ui/debug-panel/panelManager.d.ts.map +0 -1
  180. package/dist/ui/debug-panel/panelManager.js +0 -123
  181. package/dist/ui/debug-panel/renderer.d.ts +0 -4
  182. package/dist/ui/debug-panel/renderer.d.ts.map +0 -1
  183. package/dist/ui/debug-panel/renderer.js +0 -181
  184. package/dist/ui/debug-panel/services.d.ts +0 -4
  185. package/dist/ui/debug-panel/services.d.ts.map +0 -1
  186. package/dist/ui/debug-panel/services.js +0 -134
  187. package/dist/ui/debug-panel/settings.d.ts +0 -5
  188. package/dist/ui/debug-panel/settings.d.ts.map +0 -1
  189. package/dist/ui/debug-panel/settings.js +0 -35
  190. package/dist/ui/debug-panel/state.d.ts +0 -128
  191. package/dist/ui/debug-panel/state.d.ts.map +0 -1
  192. package/dist/ui/debug-panel/state.js +0 -42
  193. package/dist/ui/debug-panel/stateEditor.d.ts +0 -9
  194. package/dist/ui/debug-panel/stateEditor.d.ts.map +0 -1
  195. package/dist/ui/debug-panel/stateEditor.js +0 -158
  196. package/dist/ui/debug-panel/types.d.ts +0 -68
  197. package/dist/ui/debug-panel/types.d.ts.map +0 -1
  198. package/dist/ui/debug-panel/types.js +0 -1
  199. package/dist/ui/debug-panel/ui.d.ts +0 -10
  200. package/dist/ui/debug-panel/ui.d.ts.map +0 -1
  201. package/dist/ui/debug-panel/ui.js +0 -199
  202. package/dist/ui/debug-panel/utils.d.ts +0 -16
  203. package/dist/ui/debug-panel/utils.d.ts.map +0 -1
  204. package/dist/ui/debug-panel/utils.js +0 -104
  205. package/dist/utils.d.ts +0 -22
  206. package/dist/utils.d.ts.map +0 -1
  207. package/dist/utils.js +0 -58
  208. package/src/appState.ts +0 -167
  209. package/src/core/AIService.ts +0 -109
  210. package/src/core/ApiService.ts +0 -40
  211. package/src/core/AuthService.ts +0 -85
  212. package/src/core/BaseService.ts +0 -47
  213. package/src/core/CalendarService.ts +0 -44
  214. package/src/core/CommandService.ts +0 -69
  215. package/src/core/DebugPanelService.ts +0 -38
  216. package/src/core/DebugService.ts +0 -181
  217. package/src/core/EventBus.ts +0 -60
  218. package/src/core/EventHandler.ts +0 -97
  219. package/src/core/GamificationService.ts +0 -120
  220. package/src/core/HookService.ts +0 -86
  221. package/src/core/ModalService.ts +0 -97
  222. package/src/core/NotificationService.ts +0 -53
  223. package/src/core/RouterService.ts +0 -68
  224. package/src/core/ServiceContainer.ts +0 -31
  225. package/src/core/ShortcutService.ts +0 -49
  226. package/src/core/StorageService.ts +0 -123
  227. package/src/core/ThemeService.ts +0 -71
  228. package/src/core/WebSocketService.ts +0 -32
  229. package/src/core/api.ts +0 -78
  230. package/src/core/app/ModuleManager.ts +0 -273
  231. package/src/core/app/apiFactory.ts +0 -130
  232. package/src/core/app/commandManager.ts +0 -218
  233. package/src/core/app/moduleLoader.ts +0 -39
  234. package/src/core/app/routeManager.ts +0 -8
  235. package/src/core/index.ts +0 -15
  236. package/src/core/signals.ts +0 -84
  237. package/src/core/uiState.ts +0 -13
  238. package/src/index.ts +0 -18
  239. package/src/lib/local-db.ts +0 -65
  240. package/src/lib/sync-service.ts +0 -44
  241. package/src/platform/ILayoutService.ts +0 -77
  242. package/src/platform/IRenderer.ts +0 -16
  243. package/src/platform/ServiceRegistry.ts +0 -53
  244. package/src/platform/extensionPoints.ts +0 -202
  245. package/src/platform/index.ts +0 -4
  246. package/src/stores/editorStore.ts +0 -6
  247. package/src/stores/gamificationStore.ts +0 -4
  248. package/src/stores/historyStore.ts +0 -14
  249. package/src/stores/workspaceStore.ts +0 -8
  250. package/src/types/app.ts +0 -36
  251. package/src/types/debug.ts +0 -69
  252. package/src/types/index.ts +0 -3
  253. package/src/types/platform.ts +0 -112
  254. package/src/ui/Palette.ts +0 -161
  255. package/src/utils.ts +0 -63
  256. package/tsconfig.json +0 -23
@@ -1,181 +0,0 @@
1
- import { ConsoleLog, LogLevel } from '../types/debug.js';
2
- import { IPlatformAPI } from './api';
3
- import { createSignal } from './signals';
4
-
5
- // Tipos para nuestro grafo de arquitectura
6
- type NodeType = 'app' | 'package' | 'service' | 'module' | 'ui-component';
7
- type NodeStatus = 'idle' | 'active' | 'error' | 'loaded';
8
-
9
- interface Node {
10
- id: string;
11
- label: string;
12
- type: NodeType;
13
- description: string;
14
- status: NodeStatus;
15
- metadata?: any;
16
- }
17
-
18
- interface Link {
19
- source: string;
20
- target: string;
21
- label: string;
22
- type: string;
23
- }
24
-
25
- interface ArchitectureGraph {
26
- nodes: Node[];
27
- links: Link[];
28
- lastActivatedLink?: { source: string; target: string };
29
- }
30
-
31
- interface ProbeEvent {
32
- timestamp: number;
33
- nodeId: string;
34
- status: NodeStatus;
35
- metadata?: any;
36
- }
37
-
38
- export class DebugService {
39
- public api: IPlatformAPI;
40
- public graphState = createSignal<ArchitectureGraph>({ nodes: [], links: [] });
41
- public probeLog = createSignal<ProbeEvent[]>([]);
42
- public playbackState = createSignal({ isPlaying: false, currentIndex: -1 });
43
- // --- NUEVAS SEÑALES PARA LOGS ---
44
- public consoleLogs = createSignal<ConsoleLog[]>([]);
45
- private statusTimeouts = new Map<string, number>();
46
-
47
- constructor(api: IPlatformAPI) {
48
- this.api = api;
49
- this.setupInterceptors();
50
-
51
- // Espía todos los comandos
52
- this.api.commands.spyOn((commandId) => {
53
- this.probe(`cmd:${commandId}`, 'active'); // Asume un prefijo "cmd:"
54
- });
55
- }
56
- // --- NUEVOS MÉTODOS (Movidos desde tu 'services.ts') ---
57
- private setupInterceptors(): void {
58
- this.interceptConsole();
59
- // Aquí añadiríamos interceptFetch, interceptErrors, etc.
60
- }
61
- private interceptConsole(): void {
62
- const originalConsole = { ...window.console };
63
- (['log', 'info', 'warn', 'error'] as LogLevel[]).forEach(level => {
64
- window.console[level] = (...args: any[]) => {
65
- const newLog: ConsoleLog = {
66
- id: `log_${Date.now()}`,
67
- type: level,
68
- timestamp: new Date(),
69
- message: args,
70
- stack: level === 'error' ? new Error().stack : undefined
71
- };
72
- // Actualizamos la señal de logs de la consola
73
- this.consoleLogs[1](prevLogs => [...prevLogs, newLog]);
74
-
75
- // Llamamos al método original para que la consola del navegador siga funcionando
76
- originalConsole[level](...args);
77
- };
78
- });
79
- }
80
- // --- FIN DE NUEVOS MÉTODOS ---
81
-
82
-
83
- public clearLogs(logType: 'console' /* | 'network' ... */) {
84
- if (logType === 'console') {
85
- this.consoleLogs[1]([]);
86
- }
87
- }
88
-
89
- // public async loadArchitectureGraph(path: string) {
90
- // try {
91
- // const response = await fetch(path);
92
- // const graphData = await response.json();
93
- // // Inicializa todos los nodos con estado 'idle'
94
- // graphData.nodes.forEach((node: Node) => node.status = 'idle');
95
- // this.graphState[1](graphData);
96
- // console.log('✅ Mapa de arquitectura cargado en el DebugService.');
97
- // } catch (error) {
98
- // console.error('❌ Error al cargar el mapa de arquitectura:', error);
99
- // }
100
- // }
101
- public async loadArchitectureGraph(path: string) {
102
- try {
103
- const response = await fetch(path);
104
- const graphData = await response.json();
105
- graphData.nodes.forEach((node: any) => {
106
- node.status = 'idle';
107
- // node.x = Math.random() * 800; // Reset positions
108
- // node.y = Math.random() * 500;
109
- });
110
- this.graphState[1](graphData); // Reemplaza el grafo actual
111
- this.probeLog[1]([]); // Limpia el log de reproducción
112
- this.playbackState[1]({ isPlaying: false, currentIndex: -1 });
113
- console.log(`✅ Nuevo mapa de arquitectura cargado: ${path}`);
114
- } catch (error) {
115
- console.error(`❌ Error al cargar el mapa: ${path}`, error);
116
- }
117
- }
118
-
119
- /**
120
- * El "sensor" principal de nuestro sistema de diagnóstico.
121
- * Llama a este método desde cualquier parte del código para actualizar el estado de un nodo.
122
- */
123
- public probe(nodeId: string, status: NodeStatus, metadata?: any) {
124
- // 1. Siempre registra el evento
125
- const logEntry = { timestamp: Date.now(), nodeId, status, metadata };
126
- this.probeLog[1](prevLog => [...prevLog, logEntry]);
127
-
128
- // 2. Si no estamos en reproducción, actualiza el grafo en vivo
129
- if (!this.playbackState[0]().isPlaying) {
130
- this.applyProbeToGraph(logEntry);
131
- this.playbackState[1](prev => ({ ...prev, currentIndex: this.probeLog[0]().length - 1 }));
132
- }
133
- }
134
-
135
- private applyProbeToGraph(probe: ProbeEvent) {
136
- const [getGraph, setGraph] = this.graphState;
137
- const currentGraph = getGraph();
138
- const node = currentGraph.nodes.find((n: any) => n.id === probe.nodeId);
139
-
140
- if (node) {
141
- node.status = probe.status;
142
- node.metadata = probe.metadata;
143
- setGraph({ ...currentGraph });
144
-
145
- if (probe.status === 'active') {
146
- if (this.statusTimeouts.has(probe.nodeId)) clearTimeout(this.statusTimeouts.get(probe.nodeId));
147
- const timeoutId = window.setTimeout(() => {
148
- const latestNodeState = this.probeLog[0]().filter(p => p.nodeId === probe.nodeId).pop();
149
- this.applyProbeToGraph({ ...latestNodeState!, status: 'loaded' });
150
- }, 1500);
151
- this.statusTimeouts.set(probe.nodeId, timeoutId);
152
- }
153
- }
154
- }
155
-
156
- // --- CONTROL ---
157
- public goToLogIndex(index: number) {
158
- const log = this.probeLog[0]();
159
- if (index < 0 || index >= log.length) return;
160
-
161
- this.playbackState[1](prev => ({ ...prev, currentIndex: index, isPlaying: false }));
162
-
163
- // Reconstruye el estado del grafo hasta ese punto en el tiempo
164
- const snapshot = log.slice(0, index + 1).reduce((acc, probe) => {
165
- acc[probe.nodeId] = probe;
166
- return acc;
167
- }, {} as Record<string, ProbeEvent>);
168
-
169
- const [getGraph, setGraph] = this.graphState;
170
- const currentGraph = getGraph();
171
- currentGraph.nodes.forEach((node: any) => {
172
- if (snapshot[node.id]) {
173
- node.status = snapshot[node.id].status;
174
- node.metadata = snapshot[node.id].metadata;
175
- } else {
176
- node.status = 'idle';
177
- }
178
- });
179
- setGraph({ ...currentGraph });
180
- }
181
- }
@@ -1,60 +0,0 @@
1
- // src/platform/EventBus.ts
2
- type EventHandler = (data?: any) => void;
3
- type SpyHandler = (eventName: string, data?: any) => void;
4
-
5
- export class EventBus {
6
- private events: Map<string, Set<EventHandler>>;
7
- private spy: SpyHandler | null = null;
8
-
9
- constructor() {
10
- this.events = new Map();
11
- }
12
-
13
- /**
14
- * Se suscribe a un evento.
15
- * @param eventName El nombre del evento (e.g., 'app:ready', 'view:changed').
16
- * @param handler La función a ejecutar cuando el evento se emita.
17
- */
18
- on(eventName: string, handler: EventHandler): void {
19
- if (!this.events.has(eventName)) {
20
- this.events.set(eventName, new Set());
21
- }
22
- this.events.get(eventName)!.add(handler);
23
- }
24
-
25
- /**
26
- * Se desuscribe de un evento.
27
- * @param eventName El nombre del evento.
28
- * @param handler La función a remover.
29
- */
30
- off(eventName: string, handler: EventHandler): void {
31
- const handlers = this.events.get(eventName);
32
- if (handlers) {
33
- handlers.delete(handler);
34
- }
35
- }
36
-
37
- /**
38
- * Emite un evento, llamando a todos los suscriptores.
39
- * @param eventName El nombre del evento a emitir.
40
- * @param data Datos opcionales para pasar a los manejadores.
41
- */
42
- emit(eventName: string, data?: any): void {
43
- const handlers = this.events.get(eventName);
44
- if (handlers) {
45
- handlers.forEach(handler => handler(data));
46
- }
47
- // Notificar al espía, si existe
48
- if (this.spy) {
49
- this.spy(eventName, data);
50
- }
51
- }
52
-
53
- /**
54
- * Registra una única función que recibirá TODOS los eventos emitidos.
55
- * @param handler La función espía.
56
- */
57
- spyOn(handler: SpyHandler): void {
58
- this.spy = handler;
59
- }
60
- }
@@ -1,97 +0,0 @@
1
- // /src/EventHandler.ts (CORREGIDO Y COMPLETO CON DRAG & DROP)
2
-
3
- import { IPlatformAPI } from "./api.js";
4
-
5
-
6
- export function initEventListeners(api: IPlatformAPI) {
7
- const { commands } = api;
8
-
9
- /**
10
- * MANEJADOR DE CLICS
11
- * Escucha clics en todo el cuerpo y despacha comandos si un elemento
12
- * con `data-command` es clickeado.
13
- */
14
- document.body.addEventListener('click', (e: MouseEvent) => {
15
- const commandTarget = (e.target as HTMLElement).closest('[data-command]');
16
- if (!commandTarget || commandTarget.tagName === 'FORM') return; // Ignora los formularios aquí
17
-
18
- e.preventDefault();
19
- const commandId = commandTarget.getAttribute('data-command');
20
- const commandArg = commandTarget.getAttribute('data-command-arg');
21
- // Encuentra el ID del componente de UI padre para usarlo como fuente
22
- const componentId = commandTarget.closest('[data-component-id]')?.getAttribute('data-component-id') ?? undefined;
23
- if (commandId) {
24
- commands.execute(commandId, commandArg, componentId);
25
- }
26
- });
27
-
28
- /**
29
- * MANEJADOR DE FORMULARIOS
30
- * Escucha el evento 'submit' en todo el cuerpo. Es más eficiente y seguro
31
- * que los listeners de clic en los botones de envío.
32
- */
33
- document.body.addEventListener('submit', (e: SubmitEvent) => {
34
- const form = e.target as HTMLFormElement;
35
- if (form.dataset.command) {
36
- e.preventDefault();
37
- commands.execute(form.dataset.command, new FormData(form));
38
- }
39
- });
40
-
41
- // --- MANEJO DE DRAG & DROP ---
42
- let draggedTaskId: number | null = null;
43
-
44
- // Se dispara cuando el usuario empieza a arrastrar una tarjeta
45
- document.body.addEventListener('dragstart', (e: DragEvent) => {
46
- const target = e.target as HTMLElement;
47
- if (target.classList.contains('task-card-premium')) {
48
- draggedTaskId = Number(target.dataset.taskId);
49
- // Añadimos un efecto visual al elemento arrastrado
50
- setTimeout(() => target.classList.add('dragging'), 0);
51
- }
52
- });
53
-
54
- // Se dispara continuamente mientras un elemento se arrastra SOBRE una zona válida
55
- document.body.addEventListener('dragover', (e: DragEvent) => {
56
- const column = (e.target as HTMLElement).closest('.kanban-column');
57
- if (column) {
58
- // ✅ ESTA LÍNEA ES LA CLAVE: Prevenimos el comportamiento por defecto
59
- // para permitir que se pueda "soltar" el elemento aquí.
60
- e.preventDefault();
61
-
62
- // Añadimos feedback visual a la columna
63
- document.querySelectorAll('.kanban-column').forEach(c => c.classList.remove('drag-over'));
64
- column.classList.add('drag-over');
65
- }
66
- });
67
-
68
- // Se dispara cuando un elemento arrastrado sale de una zona válida
69
- document.body.addEventListener('dragleave', (e: DragEvent) => {
70
- (e.target as HTMLElement).closest('.kanban-column')?.classList.remove('drag-over');
71
- });
72
-
73
- // Se dispara cuando el usuario suelta el elemento en una zona válida
74
- document.body.addEventListener('drop', (e: DragEvent) => {
75
- e.preventDefault();
76
- const column = (e.target as HTMLElement).closest('.kanban-column') as HTMLElement;
77
- document.querySelectorAll('.kanban-column').forEach(c => c.classList.remove('drag-over'));
78
-
79
- if (column && draggedTaskId !== null) {
80
- const newStatus = column.dataset.status;
81
- // Despachamos un comando en lugar de ejecutar la lógica aquí
82
- api.commands.execute('kanban.moveTask', { taskId: draggedTaskId, newStatus });
83
-
84
- }
85
- document.querySelectorAll('.kanban-column').forEach(c => c.classList.remove('drag-over'));
86
- draggedTaskId = null;
87
- });
88
-
89
- // Se dispara cuando la operación de arrastre termina (se suelte o se cancele)
90
- document.body.addEventListener('dragend', (e: DragEvent) => {
91
- const target = e.target as HTMLElement;
92
- if (target.classList.contains('task-card-premium')) {
93
- target.classList.remove('dragging');
94
- }
95
- draggedTaskId = null;
96
- });
97
- }
@@ -1,120 +0,0 @@
1
- // /src/core/GamificationService.ts (CORREGIDO)
2
-
3
- import { IPlatformAPI } from "./api.js";
4
-
5
- export class GamificationService {
6
- public api!: IPlatformAPI;
7
- private levelFormula = (level: number) => Math.floor(100 * Math.pow(level, 1.5));
8
-
9
- /**
10
- * Añade una cantidad de XP, gestiona subidas de nivel y devuelve el estado actualizado.
11
- * YA NO llama a checkAndUnlockAchievements para romper el bucle.
12
- */
13
- public addXP(amount: number, reason: string = 'Acción completada') {
14
- const { state, notifications } = this.api;
15
- const gamificationState = state.gamification();
16
- const newXP = gamificationState.xp + amount;
17
-
18
- const currentLevel = gamificationState.level;
19
- let newLevel = currentLevel;
20
- let leveledUp = false;
21
-
22
- let xpForNextLevel = this.levelFormula(currentLevel);
23
- while (newXP >= xpForNextLevel) {
24
- newLevel++;
25
- leveledUp = true;
26
- xpForNextLevel = this.levelFormula(newLevel);
27
- }
28
-
29
- // Actualizamos el estado una sola vez
30
- state.setGamification({ ...gamificationState, xp: newXP, level: newLevel });
31
-
32
- notifications.show('success', `+${amount} XP!`, reason);
33
- if (leveledUp) {
34
- setTimeout(() => {
35
- notifications.show('success', `¡Subiste de Nivel!`, `🚀 ¡Felicidades! Has alcanzado el Nivel ${newLevel}.`);
36
- }, 500); // Pequeño delay para que no se solapen las notificaciones
37
- }
38
- }
39
-
40
- /**
41
- * Actualiza la racha del diario. Ahora también es más simple.
42
- */
43
- public updateJournalStreak() {
44
- const { state } = this.api;
45
- const gamificationState = state.gamification();
46
- const today = new Date();
47
- const lastDate = gamificationState.lastJournalDate ? new Date(gamificationState.lastJournalDate) : null;
48
- let newStreak = gamificationState.streak;
49
-
50
- const isSameDay = (d1: Date, d2: Date) => d1.toDateString() === d2.toDateString();
51
-
52
- if (lastDate && isSameDay(today, lastDate)) return;
53
-
54
- const yesterday = new Date();
55
- yesterday.setDate(today.getDate() - 1);
56
-
57
- newStreak = (lastDate && isSameDay(yesterday, lastDate)) ? newStreak + 1 : 1;
58
-
59
- if (newStreak > gamificationState.streak) {
60
- const streakBonusXP = Math.min(newStreak * 5, 50);
61
- this.addXP(streakBonusXP, `Racha de ${newStreak} días`);
62
- }
63
-
64
- state.setGamification({
65
- ...state.gamification(),
66
- streak: newStreak,
67
- lastJournalDate: today.toISOString().slice(0, 10),
68
- });
69
- }
70
-
71
- /**
72
- * Comprueba los logros, y si desbloquea alguno, añade el XP y actualiza el estado UNA SOLA VEZ.
73
- */
74
- public checkAndUnlockAchievements() {
75
- const { state, notifications } = this.api;
76
- const gamificationState = state.gamification();
77
- // const tasks = state.tasks();
78
- // const goals = state.goals();
79
-
80
- let totalXpFromAchievements = 0;
81
- const newlyUnlockedIds: string[] = [];
82
-
83
- gamificationState.achievements.forEach(achievement => {
84
- if (gamificationState.unlockedAchievements.includes(achievement.id)) return;
85
-
86
- let conditionMet = false;
87
- switch (achievement.conditionType) {
88
- // case 'tasks_completed':
89
- // if (tasks.filter(t => t.status === 'done').length >= achievement.conditionValue) conditionMet = true;
90
- // break;
91
- // case 'goals_created':
92
- // if (goals.length >= achievement.conditionValue) conditionMet = true;
93
- // break;
94
- case 'journal_streak':
95
- if (gamificationState.streak >= achievement.conditionValue) conditionMet = true;
96
- break;
97
- case 'level':
98
- if (gamificationState.level >= achievement.conditionValue) conditionMet = true;
99
- break;
100
- }
101
-
102
- if (conditionMet) {
103
- newlyUnlockedIds.push(achievement.id);
104
- totalXpFromAchievements += achievement.reward_xp;
105
- notifications.show('success', '¡Logro Desbloqueado!', `🏆 ${achievement.title}`);
106
- }
107
- });
108
-
109
- if (newlyUnlockedIds.length > 0) {
110
- this.addXP(totalXpFromAchievements, `Recompensa por ${newlyUnlockedIds.length} logros`);
111
-
112
- // Obtenemos el estado más reciente después del addXP y añadimos los IDs
113
- const finalGamificationState = state.gamification();
114
- state.setGamification({
115
- ...finalGamificationState,
116
- unlockedAchievements: [...finalGamificationState.unlockedAchievements, ...newlyUnlockedIds]
117
- });
118
- }
119
- }
120
- }
@@ -1,86 +0,0 @@
1
- import { HookName, HookPayloads } from "../platform/extensionPoints";
2
-
3
- // Tipo genérico para el callback de un hook.
4
- type HookCallback<T> = (data: T) => void | Promise<void>;
5
-
6
- /**
7
- * Gestiona el registro y la ejecución de hooks de ciclo de vida de forma
8
- * segura, asíncrona y desacoplada.
9
- */
10
- export class HookService {
11
- private hooks = new Map<HookName, HookCallback<any>[]>();
12
-
13
- /**
14
- * Registra un callback para un hook y devuelve una función para desregistrarlo.
15
- * @param hookName El nombre del hook al que suscribirse.
16
- * @param callback La función a ejecutar cuando el hook se dispare.
17
- * @returns Una función que, al llamarla, desuscribe el callback.
18
- */
19
- public on<K extends HookName>(
20
- hookName: K,
21
- callback: HookCallback<HookPayloads[K]>
22
- ): () => void {
23
- if (!this.hooks.has(hookName)) {
24
- this.hooks.set(hookName, []);
25
- }
26
- this.hooks.get(hookName)!.push(callback);
27
-
28
- // Devolvemos una función "disposer" para una fácil limpieza.
29
- return () => this.off(hookName, callback);
30
- }
31
-
32
- /**
33
- * Alias para el método `on`.
34
- */
35
- public register<K extends HookName>(
36
- hookName: K,
37
- callback: HookCallback<HookPayloads[K]>
38
- ): () => void {
39
- return this.on(hookName, callback);
40
- }
41
-
42
- /**
43
- * Elimina un callback previamente registrado para un hook.
44
- * @param hookName El nombre del hook.
45
- * @param callbackToRemove La instancia exacta del callback a eliminar.
46
- */
47
- public off<K extends HookName>(
48
- hookName: K,
49
- callbackToRemove: HookCallback<HookPayloads[K]>
50
- ): void {
51
- const callbacks = this.hooks.get(hookName);
52
- if (!callbacks) return;
53
-
54
- const updatedCallbacks = callbacks.filter(cb => cb !== callbackToRemove);
55
-
56
- if (updatedCallbacks.length > 0) {
57
- this.hooks.set(hookName, updatedCallbacks);
58
- } else {
59
- this.hooks.delete(hookName);
60
- }
61
- }
62
-
63
- /**
64
- * Dispara un hook, ejecutando todos los callbacks registrados para él.
65
- * @param hookName El nombre del hook a disparar.
66
- * @param data Los datos a pasar a los callbacks.
67
- */
68
- public async trigger<K extends HookName>(
69
- hookName: K,
70
- data: HookPayloads[K]
71
- ): Promise<void> {
72
- const callbacks = this.hooks.get(hookName);
73
- if (!callbacks || callbacks.length === 0) return;
74
-
75
- console.log(`🪝 Disparando hook: ${hookName}`, data);
76
-
77
- // Hacemos una copia para evitar problemas si un callback desregistra a otro
78
- for (const callback of [...callbacks]) {
79
- try {
80
- await Promise.resolve(callback(data));
81
- } catch (error) {
82
- console.error(`Error en un callback del hook '${hookName}':`, error);
83
- }
84
- }
85
- }
86
- }
@@ -1,97 +0,0 @@
1
- // src/platform/ModalService.ts
2
- import { TemplateResult } from "lit-html";
3
- import { html } from "../utils.js";
4
-
5
- interface ModalOptions {
6
- title: string;
7
- content: string | HTMLElement | TemplateResult; // HTML string o un elemento del DOM
8
- size?: 'sm' | 'md' | 'lg' | 'xl';
9
- actions?: {
10
- text: string;
11
- type: 'primary' | 'secondary';
12
- onClick: (close: () => void) => void;
13
- }[];
14
- }
15
-
16
- export class ModalService {
17
- private container: HTMLElement;
18
-
19
- constructor() {
20
- this.container = document.createElement('div');
21
- this.container.id = 'modal-container';
22
- document.body.appendChild(this.container);
23
- }
24
-
25
- show(options: ModalOptions) {
26
- this.hide(); // Cierra cualquier modal existente antes de mostrar uno nuevo
27
-
28
- const modalId = `modal_${Date.now()}`;
29
-
30
- const sizeClasses = {
31
- sm: 'max-w-md',
32
- md: 'max-w-lg',
33
- lg: 'max-w-2xl',
34
- xl: 'max-w-4xl',
35
- }
36
-
37
- const modalWrapper = document.createElement('div');
38
- modalWrapper.id = modalId;
39
- modalWrapper.className = 'fixed inset-0 bg-darker/80 backdrop-blur-sm flex items-center justify-center z-50';
40
-
41
- modalWrapper.innerHTML = html`
42
- <div class="glass-premium p-8 rounded-2xl w-full ${sizeClasses[options.size || 'md']} animate-scale-in">
43
- <div class="flex justify-between items-center mb-6">
44
- <h2 class="text-2xl font-bold text-white">${options.title}</h2>
45
- <button class="text-muted-foreground hover:text-foreground text-2xl close-btn">&times;</button>
46
- </div>
47
- <div class="modal-body"></div>
48
- ${options.actions && options.actions.length > 0 ? `
49
- <div class="pt-6 border-t border-white/10 mt-6 text-right space-x-4 modal-footer">
50
- </div>
51
- ` : ''}
52
- </div>
53
- `;
54
-
55
- const closeModal = () => modalWrapper.remove();
56
-
57
- // Contenido
58
- const body = modalWrapper.querySelector('.modal-body')!;
59
- if (typeof options.content === 'string') {
60
- body.innerHTML = options.content;
61
- } else {
62
- body.appendChild(options.content as Node);
63
- }
64
-
65
- // Acciones (botones)
66
- const footer = modalWrapper.querySelector('.modal-footer');
67
- if (footer && options.actions) {
68
- options.actions.forEach(action => {
69
- const btn = document.createElement('button');
70
- btn.textContent = action.text;
71
- btn.className = action.type === 'primary' ? 'btn-premium' : 'btn-secondary'; // necesitarás .btn-secondary
72
- btn.onclick = () => action.onClick(closeModal);
73
- footer.appendChild(btn);
74
- });
75
- }
76
-
77
- modalWrapper.querySelector('.close-btn')?.addEventListener('click', closeModal);
78
- modalWrapper.addEventListener('click', (e) => {
79
- if (e.target === modalWrapper) {
80
- closeModal();
81
- }
82
- });
83
-
84
- this.container.appendChild(modalWrapper);
85
-
86
- return {
87
- close: closeModal,
88
- };
89
- }
90
-
91
- hide() {
92
- const modal = this.container.querySelector('.fixed');
93
- if (modal) {
94
- modal.remove();
95
- }
96
- }
97
- }