kimu-core 0.4.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 (146) hide show
  1. package/.editorconfig +30 -0
  2. package/.gitattributes +11 -0
  3. package/.github/FUNDING.yml +8 -0
  4. package/.github/copilot-instructions.md +103 -0
  5. package/.github/kimu-copilot-instructions.md +3779 -0
  6. package/.github/workflows/deploy-demo.yml +39 -0
  7. package/AUTHORS.md +20 -0
  8. package/CHANGELOG.md +20 -0
  9. package/CODE_GUIDELINES.md +165 -0
  10. package/CODE_OF_CONDUCT.md +47 -0
  11. package/CONTRIBUTING.md +62 -0
  12. package/FUNDING.md +31 -0
  13. package/ISSUE_GUIDELINES.md +74 -0
  14. package/LICENSE +17 -0
  15. package/LICENSE.it.md +17 -0
  16. package/MPL-2.0.txt +373 -0
  17. package/NOTICE +65 -0
  18. package/README-KIMU.md +40 -0
  19. package/README.it.md +208 -0
  20. package/README.md +266 -0
  21. package/SECURITY.md +64 -0
  22. package/docs/get-started-en.md +207 -0
  23. package/docs/images/icon.svg +64 -0
  24. package/docs/images/logo_kimu.png +0 -0
  25. package/docs/index.md +29 -0
  26. package/env/dev.config.json +6 -0
  27. package/env/local.config.json +6 -0
  28. package/env/prod.config.json +6 -0
  29. package/env/staging.config.json +6 -0
  30. package/env/test.config.json +4 -0
  31. package/icon.svg +10 -0
  32. package/logo_kimu.png +0 -0
  33. package/package.json +79 -0
  34. package/public/favicon.svg +64 -0
  35. package/public/logo_kimu.svg +1 -0
  36. package/scripts/build-all-config.js +59 -0
  37. package/scripts/build-all-core.js +65 -0
  38. package/scripts/build-all-extensions.js +64 -0
  39. package/scripts/build-all-modules.js +99 -0
  40. package/scripts/build-extension.js +60 -0
  41. package/scripts/clear-kimu-build.js +31 -0
  42. package/scripts/generate-kimu-build-config.js +79 -0
  43. package/scripts/install-module.js +162 -0
  44. package/scripts/list-modules.js +109 -0
  45. package/scripts/minify-css-assets.js +82 -0
  46. package/scripts/remove-module.js +122 -0
  47. package/scripts/utils/fix-imports.js +85 -0
  48. package/src/assets/index.css +43 -0
  49. package/src/assets/kimu-style.css +84 -0
  50. package/src/assets/style.css +116 -0
  51. package/src/config/kimu-base-config.json +5 -0
  52. package/src/core/index.ts +47 -0
  53. package/src/core/kimu-app.ts +76 -0
  54. package/src/core/kimu-asset-manager.ts +167 -0
  55. package/src/core/kimu-component-element.ts +325 -0
  56. package/src/core/kimu-component.ts +33 -0
  57. package/src/core/kimu-engine.ts +188 -0
  58. package/src/core/kimu-extension-manager.ts +281 -0
  59. package/src/core/kimu-global-styles.ts +136 -0
  60. package/src/core/kimu-module-manager.ts +69 -0
  61. package/src/core/kimu-module.ts +21 -0
  62. package/src/core/kimu-path-config.ts +127 -0
  63. package/src/core/kimu-reactive.ts +196 -0
  64. package/src/core/kimu-render.ts +91 -0
  65. package/src/core/kimu-store.ts +147 -0
  66. package/src/core/kimu-types.ts +65 -0
  67. package/src/extensions/.gitkeep +0 -0
  68. package/src/extensions/extensions-manifest.json +13 -0
  69. package/src/extensions/kimu-home/component.ts +80 -0
  70. package/src/extensions/kimu-home/lang/en.json +5 -0
  71. package/src/extensions/kimu-home/lang/it.json +5 -0
  72. package/src/extensions/kimu-home/style.css +61 -0
  73. package/src/extensions/kimu-home/view.html +51 -0
  74. package/src/index.html +26 -0
  75. package/src/main.ts +68 -0
  76. package/src/modules/.gitkeep +0 -0
  77. package/src/modules/README.md +79 -0
  78. package/src/modules/i18n/README.it.md +63 -0
  79. package/src/modules/i18n/README.md +63 -0
  80. package/src/modules/i18n/kimu-global-lang.ts +26 -0
  81. package/src/modules/i18n/kimu-i18n-service.ts +108 -0
  82. package/src/modules/i18n/manifest.json +22 -0
  83. package/src/modules/i18n/module.ts +39 -0
  84. package/src/modules/modules-manifest.json +12 -0
  85. package/src/modules-repository/README.md +108 -0
  86. package/src/modules-repository/api-axios/CHANGELOG.md +48 -0
  87. package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -0
  88. package/src/modules-repository/api-axios/README.md +304 -0
  89. package/src/modules-repository/api-axios/api-axios-service.ts +355 -0
  90. package/src/modules-repository/api-axios/examples.ts +293 -0
  91. package/src/modules-repository/api-axios/index.ts +19 -0
  92. package/src/modules-repository/api-axios/interfaces.ts +71 -0
  93. package/src/modules-repository/api-axios/module.ts +41 -0
  94. package/src/modules-repository/api-core/CHANGELOG.md +42 -0
  95. package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -0
  96. package/src/modules-repository/api-core/README.md +435 -0
  97. package/src/modules-repository/api-core/api-core-service.ts +289 -0
  98. package/src/modules-repository/api-core/examples.ts +432 -0
  99. package/src/modules-repository/api-core/index.ts +8 -0
  100. package/src/modules-repository/api-core/interfaces.ts +83 -0
  101. package/src/modules-repository/api-core/module.ts +30 -0
  102. package/src/modules-repository/event-bus/README.md +273 -0
  103. package/src/modules-repository/event-bus/event-bus-service.ts +176 -0
  104. package/src/modules-repository/event-bus/module.ts +30 -0
  105. package/src/modules-repository/i18n/README.it.md +63 -0
  106. package/src/modules-repository/i18n/README.md +63 -0
  107. package/src/modules-repository/i18n/kimu-global-lang.ts +26 -0
  108. package/src/modules-repository/i18n/kimu-i18n-service.ts +108 -0
  109. package/src/modules-repository/i18n/manifest.json +22 -0
  110. package/src/modules-repository/i18n/module.ts +39 -0
  111. package/src/modules-repository/notification/README.md +423 -0
  112. package/src/modules-repository/notification/module.ts +30 -0
  113. package/src/modules-repository/notification/notification-service.ts +436 -0
  114. package/src/modules-repository/router/README.it.md +39 -0
  115. package/src/modules-repository/router/README.md +39 -0
  116. package/src/modules-repository/router/manifest.json +21 -0
  117. package/src/modules-repository/router/module.ts +23 -0
  118. package/src/modules-repository/router/router.ts +144 -0
  119. package/src/modules-repository/state/README.md +409 -0
  120. package/src/modules-repository/state/module.ts +30 -0
  121. package/src/modules-repository/state/state-service.ts +296 -0
  122. package/src/modules-repository/theme/README.md +267 -0
  123. package/src/modules-repository/theme/module.ts +30 -0
  124. package/src/modules-repository/theme/pre-build.js +40 -0
  125. package/src/modules-repository/theme/theme-service.ts +389 -0
  126. package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -0
  127. package/src/modules-repository/theme/themes/theme-cozy.css +111 -0
  128. package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -0
  129. package/src/modules-repository/theme/themes/theme-dark.css +79 -0
  130. package/src/modules-repository/theme/themes/theme-forest.css +171 -0
  131. package/src/modules-repository/theme/themes/theme-gold.css +100 -0
  132. package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -0
  133. package/src/modules-repository/theme/themes/theme-lava.css +101 -0
  134. package/src/modules-repository/theme/themes/theme-lavender.css +90 -0
  135. package/src/modules-repository/theme/themes/theme-light.css +79 -0
  136. package/src/modules-repository/theme/themes/theme-matrix.css +103 -0
  137. package/src/modules-repository/theme/themes/theme-midnight.css +81 -0
  138. package/src/modules-repository/theme/themes/theme-nord.css +94 -0
  139. package/src/modules-repository/theme/themes/theme-ocean.css +84 -0
  140. package/src/modules-repository/theme/themes/theme-retro80s.css +343 -0
  141. package/src/modules-repository/theme/themes/theme-sunset.css +62 -0
  142. package/src/modules-repository/theme/themes-config.d.ts +27 -0
  143. package/src/modules-repository/theme/themes-config.json +213 -0
  144. package/src/vite-env.d.ts +1 -0
  145. package/tsconfig.json +33 -0
  146. package/vite.config.ts +99 -0
@@ -0,0 +1,409 @@
1
+ # State Management Module
2
+
3
+ ## Overview
4
+ The State Management module provides reactive state management for KIMU-Core applications. It allows components to share and react to state changes with a simple, observable API.
5
+
6
+ ## Features
7
+ - ✅ **Reactive state** - Automatic updates when state changes
8
+ - ✅ **Observer pattern** - Watch specific state keys for changes
9
+ - ✅ **Computed properties** - Derive values from state with caching
10
+ - ✅ **Deep change detection** - Prevents unnecessary updates
11
+ - ✅ **Multiple watchers** - Watch multiple keys at once
12
+ - ✅ **Debug mode** - Optional logging for development
13
+ - ✅ **Type-safe** - Full TypeScript support
14
+
15
+ ## Installation
16
+ The State Management module is included in KIMU-Core. No additional installation required.
17
+
18
+ ## Usage
19
+
20
+ ### Basic Example
21
+ ```typescript
22
+ import { stateService } from './modules/state/state-service';
23
+
24
+ // Set initial state
25
+ stateService.setState('counter', 0);
26
+
27
+ // Watch for changes
28
+ stateService.watch('counter', (newValue, oldValue) => {
29
+ console.log(`Counter changed from ${oldValue} to ${newValue}`);
30
+ });
31
+
32
+ // Update state
33
+ stateService.setState('counter', 1);
34
+ // Console: Counter changed from 0 to 1
35
+ ```
36
+
37
+ ### In a Component
38
+ ```typescript
39
+ import { KimuComponent } from '../core/kimu-component';
40
+ import { KimuComponentElement } from '../core/kimu-component-element';
41
+ import { stateService } from '../modules/state/state-service';
42
+
43
+ @KimuComponent({
44
+ tag: 'counter-component',
45
+ name: 'Counter Component',
46
+ // ...
47
+ })
48
+ export class CounterComponent extends KimuComponentElement {
49
+ private unwatchCounter?: () => void;
50
+
51
+ onInit() {
52
+ // Initialize state
53
+ if (!stateService.hasState('counter')) {
54
+ stateService.setState('counter', 0);
55
+ }
56
+
57
+ // Watch for changes
58
+ this.unwatchCounter = stateService.watch('counter', (newValue) => {
59
+ this.updateDisplay(newValue);
60
+ });
61
+
62
+ // Initial display
63
+ this.updateDisplay(stateService.getState('counter', 0));
64
+ }
65
+
66
+ updateDisplay(count: number) {
67
+ const display = this.$('#counter-display');
68
+ if (display) {
69
+ display.textContent = count.toString();
70
+ }
71
+ }
72
+
73
+ increment() {
74
+ const current = stateService.getState('counter', 0);
75
+ stateService.setState('counter', current + 1);
76
+ }
77
+
78
+ decrement() {
79
+ const current = stateService.getState('counter', 0);
80
+ stateService.setState('counter', current - 1);
81
+ }
82
+
83
+ // Clean up on component destroy
84
+ disconnectedCallback() {
85
+ if (this.unwatchCounter) {
86
+ this.unwatchCounter();
87
+ }
88
+ super.disconnectedCallback();
89
+ }
90
+ }
91
+ ```
92
+
93
+ ### Complex State Objects
94
+ ```typescript
95
+ // User state
96
+ interface User {
97
+ id: number;
98
+ name: string;
99
+ email: string;
100
+ preferences: {
101
+ theme: string;
102
+ language: string;
103
+ };
104
+ }
105
+
106
+ // Set initial user
107
+ stateService.setState<User>('user', {
108
+ id: 1,
109
+ name: 'John Doe',
110
+ email: 'john@example.com',
111
+ preferences: {
112
+ theme: 'dark',
113
+ language: 'en'
114
+ }
115
+ });
116
+
117
+ // Update partial state
118
+ stateService.updateState('user', {
119
+ name: 'Jane Doe'
120
+ });
121
+
122
+ // Watch for user changes
123
+ stateService.watch<User>('user', (newUser, oldUser) => {
124
+ console.log('User updated:', newUser);
125
+ });
126
+ ```
127
+
128
+ ### Computed Properties
129
+ ```typescript
130
+ // Define state
131
+ stateService.setState('firstName', 'John');
132
+ stateService.setState('lastName', 'Doe');
133
+
134
+ // Define computed property
135
+ stateService.defineComputed('fullName', () => {
136
+ const first = stateService.getState('firstName', '');
137
+ const last = stateService.getState('lastName', '');
138
+ return `${first} ${last}`;
139
+ });
140
+
141
+ // Get computed value (cached)
142
+ const fullName = stateService.getComputed('fullName');
143
+ console.log(fullName); // "John Doe"
144
+
145
+ // Update state - computed will auto-invalidate
146
+ stateService.setState('firstName', 'Jane');
147
+ console.log(stateService.getComputed('fullName')); // "Jane Doe"
148
+ ```
149
+
150
+ ### Watch Multiple Keys
151
+ ```typescript
152
+ // Watch multiple state keys at once
153
+ const unwatch = stateService.watchMultiple(
154
+ ['theme', 'language', 'fontSize'],
155
+ (key, newValue, oldValue) => {
156
+ console.log(`${key} changed:`, newValue);
157
+ updateUI();
158
+ }
159
+ );
160
+
161
+ // Unsubscribe from all
162
+ unwatch();
163
+ ```
164
+
165
+ ### Debug Mode
166
+ ```typescript
167
+ // Enable debug logging
168
+ stateService.setDebugMode(true);
169
+
170
+ stateService.setState('test', 'value');
171
+ // Console: [State] Set: test value
172
+
173
+ stateService.watch('test', () => {});
174
+ // Console: [State] Watching: test
175
+ ```
176
+
177
+ ## API Reference
178
+
179
+ ### `stateService.setState(key, value)`
180
+ Set a state value and notify observers.
181
+ - **key**: `string` - State key
182
+ - **value**: `T` - New value
183
+
184
+ ### `stateService.getState(key, defaultValue?)`
185
+ Get a state value.
186
+ - **key**: `string` - State key
187
+ - **defaultValue**: `T` (optional) - Default if key doesn't exist
188
+ - **Returns**: `T | undefined`
189
+
190
+ ### `stateService.updateState(key, updates)`
191
+ Update nested state properties (merge).
192
+ - **key**: `string` - State key
193
+ - **updates**: `Partial<T>` - Partial updates to merge
194
+
195
+ ### `stateService.deleteState(key)`
196
+ Delete a state key and notify observers.
197
+ - **key**: `string` - State key
198
+
199
+ ### `stateService.hasState(key)`
200
+ Check if a state key exists.
201
+ - **key**: `string` - State key
202
+ - **Returns**: `boolean`
203
+
204
+ ### `stateService.watch(key, listener)`
205
+ Watch for state changes.
206
+ - **key**: `string` - State key
207
+ - **listener**: `(newValue, oldValue) => void` - Callback
208
+ - **Returns**: `() => void` - Unwatch function
209
+
210
+ ### `stateService.unwatch(key, listener)`
211
+ Stop watching a state key.
212
+ - **key**: `string` - State key
213
+ - **listener**: `Function` - Listener to remove
214
+
215
+ ### `stateService.defineComputed(key, getter)`
216
+ Define a computed property.
217
+ - **key**: `string` - Computed property key
218
+ - **getter**: `() => T` - Function that computes value
219
+
220
+ ### `stateService.getComputed(key)`
221
+ Get computed property value (cached).
222
+ - **key**: `string` - Computed property key
223
+ - **Returns**: `T | undefined`
224
+
225
+ ### `stateService.watchMultiple(keys, listener)`
226
+ Watch multiple state keys.
227
+ - **keys**: `string[]` - Array of keys
228
+ - **listener**: `(key, newValue, oldValue) => void` - Callback
229
+ - **Returns**: `() => void` - Unwatch function
230
+
231
+ ### `stateService.getAll()`
232
+ Get all state as plain object.
233
+ - **Returns**: `Record<string, any>`
234
+
235
+ ### `stateService.clear()`
236
+ Clear all state and observers.
237
+
238
+ ### `stateService.reset(initialState?)`
239
+ Reset state to initial values.
240
+ - **initialState**: `Record<string, any>` (optional)
241
+
242
+ ### `stateService.setDebugMode(enabled)`
243
+ Enable or disable debug logging.
244
+ - **enabled**: `boolean`
245
+
246
+ ## Best Practices
247
+
248
+ ### 1. Initialize State Early
249
+ ```typescript
250
+ class MyComponent extends KimuComponentElement {
251
+ onInit() {
252
+ // Initialize state if not exists
253
+ if (!stateService.hasState('myData')) {
254
+ stateService.setState('myData', { items: [] });
255
+ }
256
+ }
257
+ }
258
+ ```
259
+
260
+ ### 2. Always Unwatch
261
+ ```typescript
262
+ class MyComponent extends KimuComponentElement {
263
+ private unwatchers: Array<() => void> = [];
264
+
265
+ onInit() {
266
+ this.unwatchers.push(
267
+ stateService.watch('data', this.handleDataChange.bind(this))
268
+ );
269
+ }
270
+
271
+ disconnectedCallback() {
272
+ this.unwatchers.forEach(unwatch => unwatch());
273
+ super.disconnectedCallback();
274
+ }
275
+ }
276
+ ```
277
+
278
+ ### 3. Use Type Safety
279
+ ```typescript
280
+ interface AppState {
281
+ user: User | null;
282
+ isAuthenticated: boolean;
283
+ theme: 'light' | 'dark';
284
+ }
285
+
286
+ // Type-safe state access
287
+ const user = stateService.getState<User>('user');
288
+ stateService.setState<boolean>('isAuthenticated', true);
289
+ ```
290
+
291
+ ### 4. Namespace State Keys
292
+ ```typescript
293
+ // Good
294
+ stateService.setState('user:profile', userData);
295
+ stateService.setState('app:settings', settings);
296
+ stateService.setState('cart:items', items);
297
+
298
+ // Avoid
299
+ stateService.setState('data', someData); // Too generic!
300
+ ```
301
+
302
+ ### 5. Use Computed for Derived State
303
+ ```typescript
304
+ // Define computed properties for derived values
305
+ stateService.defineComputed('cartTotal', () => {
306
+ const items = stateService.getState('cart:items', []);
307
+ return items.reduce((sum, item) => sum + item.price, 0);
308
+ });
309
+
310
+ // Get computed value (cached until state changes)
311
+ const total = stateService.getComputed('cartTotal');
312
+ ```
313
+
314
+ ## Common Use Cases
315
+
316
+ ### 1. Global User State
317
+ ```typescript
318
+ // Login
319
+ stateService.setState('user', { id: 1, name: 'John', role: 'admin' });
320
+ stateService.setState('isAuthenticated', true);
321
+
322
+ // Components react
323
+ stateService.watch('isAuthenticated', (isAuth) => {
324
+ if (isAuth) {
325
+ loadUserDashboard();
326
+ } else {
327
+ showLoginScreen();
328
+ }
329
+ });
330
+
331
+ // Logout
332
+ stateService.setState('user', null);
333
+ stateService.setState('isAuthenticated', false);
334
+ ```
335
+
336
+ ### 2. Theme Management
337
+ ```typescript
338
+ // Set theme
339
+ stateService.setState('theme', 'dark');
340
+
341
+ // All components react to theme changes
342
+ stateService.watch('theme', (theme) => {
343
+ document.body.className = `theme-${theme}`;
344
+ });
345
+ ```
346
+
347
+ ### 3. Shopping Cart
348
+ ```typescript
349
+ interface CartItem {
350
+ id: number;
351
+ name: string;
352
+ price: number;
353
+ quantity: number;
354
+ }
355
+
356
+ // Initialize cart
357
+ stateService.setState<CartItem[]>('cart', []);
358
+
359
+ // Add item
360
+ function addToCart(item: CartItem) {
361
+ const cart = stateService.getState<CartItem[]>('cart', []);
362
+ stateService.setState('cart', [...cart, item]);
363
+ }
364
+
365
+ // Watch cart changes
366
+ stateService.watch('cart', (cart) => {
367
+ updateCartIcon(cart.length);
368
+ });
369
+
370
+ // Computed total
371
+ stateService.defineComputed('cartTotal', () => {
372
+ const items = stateService.getState<CartItem[]>('cart', []);
373
+ return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
374
+ });
375
+ ```
376
+
377
+ ### 4. Form State
378
+ ```typescript
379
+ // Form state
380
+ stateService.setState('form', {
381
+ name: '',
382
+ email: '',
383
+ isValid: false,
384
+ errors: {}
385
+ });
386
+
387
+ // Update field
388
+ function updateField(field: string, value: any) {
389
+ stateService.updateState('form', { [field]: value });
390
+ }
391
+
392
+ // Validate
393
+ stateService.watch('form', (form) => {
394
+ const isValid = validateForm(form);
395
+ stateService.updateState('form', { isValid });
396
+ });
397
+ ```
398
+
399
+ ## Performance Considerations
400
+ - Deep equality check prevents unnecessary updates
401
+ - Computed properties are cached until state changes
402
+ - Watchers execute synchronously
403
+ - Always unwatch when components are destroyed to prevent memory leaks
404
+
405
+ ## License
406
+ This module is part of KIMU-Core and follows the same license (MPL-2.0).
407
+
408
+ ## Version History
409
+ - **1.0.0** - Initial release with reactive state management
@@ -0,0 +1,30 @@
1
+ /**
2
+ * State Management Module for KIMU-Core
3
+ *
4
+ * Provides reactive state management with observers.
5
+ *
6
+ * @module StateModule
7
+ */
8
+
9
+ import { KimuModule } from '../../core/kimu-module';
10
+ import { stateService } from './state-service';
11
+
12
+ /**
13
+ * StateModule - Module class for state management integration
14
+ */
15
+ export default class StateModule extends KimuModule {
16
+ constructor(name = 'state', version = '1.0.0', options?: any) {
17
+ super(name, version, options);
18
+ }
19
+
20
+ /**
21
+ * Get the state management service instance
22
+ */
23
+ getService() {
24
+ return stateService;
25
+ }
26
+ }
27
+
28
+ // Re-export for convenience
29
+ export { stateService } from './state-service';
30
+ export { StateService } from './state-service';