slicejs-web-framework 3.3.7 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/opencode.json +14 -13
- package/Slice/Components/Structural/ContextManager/ContextManager.js +420 -423
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +421 -420
- package/Slice/Components/Structural/Controller/Controller.js +1198 -1199
- package/Slice/Components/Structural/Debugger/Debugger.js +1504 -1497
- package/Slice/Components/Structural/EventManager/EventManager.js +334 -338
- package/Slice/Components/Structural/Logger/Logger.js +200 -145
- package/Slice/Components/Structural/Router/Router.js +775 -760
- package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +106 -106
- package/Slice/Slice.js +618 -619
- package/Slice/tests/build-singleton.test.js +244 -244
- package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -728
- package/Slice/tests/context-patch-use.test.js +95 -95
- package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
- package/Slice/tests/public-env-typed-accessors.test.js +66 -66
- package/api/index.js +281 -286
- package/api/utils/publicEnvResolver.js +123 -117
- package/package.json +44 -44
package/Slice/Slice.js
CHANGED
|
@@ -1,619 +1,618 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Main Slice.js runtime.
|
|
4
|
-
*/
|
|
5
|
-
export default class Slice {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Object} sliceConfig
|
|
8
|
-
*/
|
|
9
|
-
constructor(sliceConfig, frameworkClasses = null) {
|
|
10
|
-
this.frameworkClasses = frameworkClasses;
|
|
11
|
-
const ControllerClass = frameworkClasses?.Controller;
|
|
12
|
-
const StylesManagerClass = frameworkClasses?.StylesManager;
|
|
13
|
-
|
|
14
|
-
this.controller = ControllerClass ? new ControllerClass() : null;
|
|
15
|
-
this.stylesManager = StylesManagerClass ? new StylesManagerClass() : null;
|
|
16
|
-
this.paths = sliceConfig.paths;
|
|
17
|
-
this.themeConfig = sliceConfig.themeManager;
|
|
18
|
-
this.stylesConfig = sliceConfig.stylesManager;
|
|
19
|
-
this.loggerConfig = sliceConfig.logger;
|
|
20
|
-
this.debuggerConfig = sliceConfig.debugger;
|
|
21
|
-
this.loadingConfig = sliceConfig.loading;
|
|
22
|
-
this.eventsConfig = sliceConfig.events;
|
|
23
|
-
|
|
24
|
-
// Default to production until init() resolves the actual mode.
|
|
25
|
-
// Safe to call isProduction() before init() completes.
|
|
26
|
-
this._mode = 'production';
|
|
27
|
-
this._publicEnv = {};
|
|
28
|
-
|
|
29
|
-
// 📦 Bundle system is initialized automatically via import in index.js
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Dynamically import a module and return its default export.
|
|
34
|
-
* @param {string} module
|
|
35
|
-
* @returns {Promise<any>}
|
|
36
|
-
*/
|
|
37
|
-
async getClass(module) {
|
|
38
|
-
try {
|
|
39
|
-
const { default: myClass } = await import(module);
|
|
40
|
-
return await myClass;
|
|
41
|
-
} catch (error) {
|
|
42
|
-
this.logger.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
* slice.env.
|
|
86
|
-
* slice.env.
|
|
87
|
-
* slice.env.
|
|
88
|
-
* slice.env.
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* `
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* the
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @param {
|
|
144
|
-
* @param {
|
|
145
|
-
* @
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* @param {
|
|
180
|
-
* @
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.controller.
|
|
256
|
-
this.logger.logInfo('Slice', `
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
this.
|
|
261
|
-
this.logger.logInfo('Slice', `
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
delete props.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
this.
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
this.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
window.slice.events =
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
window.slice.context =
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
};
|
|
569
|
-
window.slice.
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
const
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
await init();
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Main Slice.js runtime.
|
|
4
|
+
*/
|
|
5
|
+
export default class Slice {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} sliceConfig
|
|
8
|
+
*/
|
|
9
|
+
constructor(sliceConfig, frameworkClasses = null) {
|
|
10
|
+
this.frameworkClasses = frameworkClasses;
|
|
11
|
+
const ControllerClass = frameworkClasses?.Controller;
|
|
12
|
+
const StylesManagerClass = frameworkClasses?.StylesManager;
|
|
13
|
+
|
|
14
|
+
this.controller = ControllerClass ? new ControllerClass() : null;
|
|
15
|
+
this.stylesManager = StylesManagerClass ? new StylesManagerClass() : null;
|
|
16
|
+
this.paths = sliceConfig.paths;
|
|
17
|
+
this.themeConfig = sliceConfig.themeManager;
|
|
18
|
+
this.stylesConfig = sliceConfig.stylesManager;
|
|
19
|
+
this.loggerConfig = sliceConfig.logger;
|
|
20
|
+
this.debuggerConfig = sliceConfig.debugger;
|
|
21
|
+
this.loadingConfig = sliceConfig.loading;
|
|
22
|
+
this.eventsConfig = sliceConfig.events;
|
|
23
|
+
|
|
24
|
+
// Default to production until init() resolves the actual mode.
|
|
25
|
+
// Safe to call isProduction() before init() completes.
|
|
26
|
+
this._mode = 'production';
|
|
27
|
+
this._publicEnv = {};
|
|
28
|
+
|
|
29
|
+
// 📦 Bundle system is initialized automatically via import in index.js
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Dynamically import a module and return its default export.
|
|
34
|
+
* @param {string} module
|
|
35
|
+
* @returns {Promise<any>}
|
|
36
|
+
*/
|
|
37
|
+
async getClass(module) {
|
|
38
|
+
try {
|
|
39
|
+
const { default: myClass } = await import(module);
|
|
40
|
+
return await myClass;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.logger.error('Slice', `Error loading class ${module}`, error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns true when running in production mode.
|
|
49
|
+
* Reliable after init() has completed.
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
isProduction() {
|
|
53
|
+
return this._mode === 'production';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setPublicEnv(envPayload = {}) {
|
|
57
|
+
const normalized = {};
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(envPayload || {})) {
|
|
60
|
+
if (!key.startsWith('SLICE_PUBLIC_')) continue;
|
|
61
|
+
normalized[key] = String(value ?? '');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this._publicEnv = normalized;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getEnv(name, fallbackValue = undefined) {
|
|
68
|
+
if (!name || typeof name !== 'string') {
|
|
69
|
+
return fallbackValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (Object.prototype.hasOwnProperty.call(this._publicEnv, name)) {
|
|
73
|
+
return this._publicEnv[name];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return fallbackValue;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getPublicEnv() {
|
|
80
|
+
return { ...this._publicEnv };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Typed accessors over the public env, so callers stop re-parsing strings.
|
|
85
|
+
* slice.env.get('SLICE_PUBLIC_API_URL', '')
|
|
86
|
+
* slice.env.bool('SLICE_PUBLIC_AUTH_ENABLED') // '1'|'true'|'yes'|'on' → true
|
|
87
|
+
* slice.env.int('SLICE_PUBLIC_TIMEOUT', 5000)
|
|
88
|
+
* slice.env.list('SLICE_PUBLIC_MODELS') // 'a, b' → ['a','b']
|
|
89
|
+
* slice.env.has('X') / slice.env.all()
|
|
90
|
+
* @returns {{ get: Function, has: Function, all: Function, bool: Function, int: Function, list: Function }}
|
|
91
|
+
*/
|
|
92
|
+
get env() {
|
|
93
|
+
const read = (name) =>
|
|
94
|
+
Object.prototype.hasOwnProperty.call(this._publicEnv, name) ? this._publicEnv[name] : undefined;
|
|
95
|
+
const present = (v) => v !== undefined && String(v).trim() !== '';
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
get: (name, fallback = undefined) => this.getEnv(name, fallback),
|
|
99
|
+
has: (name) => Object.prototype.hasOwnProperty.call(this._publicEnv, name),
|
|
100
|
+
all: () => this.getPublicEnv(),
|
|
101
|
+
bool: (name, fallback = false) => {
|
|
102
|
+
const v = read(name);
|
|
103
|
+
return present(v) ? ['1', 'true', 'yes', 'on'].includes(String(v).trim().toLowerCase()) : fallback;
|
|
104
|
+
},
|
|
105
|
+
int: (name, fallback = 0) => {
|
|
106
|
+
const v = read(name);
|
|
107
|
+
const n = parseInt(v, 10);
|
|
108
|
+
return Number.isNaN(n) ? fallback : n;
|
|
109
|
+
},
|
|
110
|
+
list: (name, fallback = []) => {
|
|
111
|
+
const v = read(name);
|
|
112
|
+
if (!present(v)) return fallback;
|
|
113
|
+
return String(v)
|
|
114
|
+
.split(',')
|
|
115
|
+
.map((s) => s.trim())
|
|
116
|
+
.filter(Boolean);
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get a component instance by sliceId.
|
|
123
|
+
* @param {string} componentSliceId
|
|
124
|
+
* @returns {HTMLElement|undefined}
|
|
125
|
+
*/
|
|
126
|
+
getComponent(componentSliceId) {
|
|
127
|
+
return this.controller.activeComponents.get(componentSliceId);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build a component instance and run init.
|
|
132
|
+
*
|
|
133
|
+
* Pass `{ singleton: true }` to get-or-create one shared instance keyed by
|
|
134
|
+
* `sliceId` (defaults to `componentName`). Concurrent singleton builds of the
|
|
135
|
+
* same id share a single in-flight build, so they never race on a duplicate
|
|
136
|
+
* sliceId. Singletons are only supported for Service components — for app-wide
|
|
137
|
+
* UI build a Provider Service that manages the Visual (see ToastProvider /
|
|
138
|
+
* ToolTipProvider), because a DOM node can only live in one place.
|
|
139
|
+
*
|
|
140
|
+
* Note: `props` only apply on the first (creating) call; later calls return
|
|
141
|
+
* the existing instance and ignore them.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} componentName
|
|
144
|
+
* @param {Object} [props]
|
|
145
|
+
* @param {boolean} [props.singleton] Reuse a single instance per sliceId.
|
|
146
|
+
* @returns {Promise<HTMLElement|Object|null>}
|
|
147
|
+
*/
|
|
148
|
+
async build(componentName, props = {}) {
|
|
149
|
+
if (!props || props.singleton !== true) {
|
|
150
|
+
return this._build(componentName, props);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const { singleton, ...rest } = props;
|
|
154
|
+
const sliceId = rest.sliceId || componentName;
|
|
155
|
+
|
|
156
|
+
// Singletons are allowed for any category whose *type* is 'Service' — not
|
|
157
|
+
// only the built-in 'Service' category. Custom categories declared in
|
|
158
|
+
// sliceConfig with `"type": "Service"` (e.g. AppServices) are services too.
|
|
159
|
+
const category = this.controller.componentCategories.get(componentName);
|
|
160
|
+
const categoryType = slice.paths?.components?.[category]?.type;
|
|
161
|
+
if (categoryType !== 'Service') {
|
|
162
|
+
this.logger.logError(
|
|
163
|
+
'Slice',
|
|
164
|
+
`singleton:true is only supported for Service-type components ('${componentName}' is in category '${category || 'unknown'}', type '${categoryType || 'unknown'}'). ` +
|
|
165
|
+
`For app-wide UI build a Provider Service that manages the Visual (see ToastProvider/ToolTipProvider).`
|
|
166
|
+
);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return this.controller.getOrCreate(sliceId, () =>
|
|
171
|
+
this._build(componentName, { ...rest, sliceId })
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Internal build: load resources, construct, run init, register. Always
|
|
177
|
+
* creates a new instance. Public `build` delegates here (and wraps it with
|
|
178
|
+
* get-or-create when `singleton:true`).
|
|
179
|
+
* @param {string} componentName
|
|
180
|
+
* @param {Object} [props]
|
|
181
|
+
* @returns {Promise<HTMLElement|Object|null>}
|
|
182
|
+
*/
|
|
183
|
+
async _build(componentName, props = {}) {
|
|
184
|
+
if (!componentName) {
|
|
185
|
+
this.logger.error('Slice', 'Component name is required to build a component');
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (typeof componentName !== 'string') {
|
|
190
|
+
this.logger.error('Slice', 'Component name must be a string');
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 📦 Try to load from bundles first
|
|
195
|
+
const bundleName = this.controller.getBundleForComponent(componentName);
|
|
196
|
+
if (bundleName && !this.controller.loadedBundles.has(bundleName)) {
|
|
197
|
+
await this.controller.loadBundle(bundleName);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!this.controller.componentCategories.has(componentName) && !this.controller.classes.has(componentName)) {
|
|
201
|
+
this.logger.error('Slice', `Component ${componentName} not found in components.js file`);
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let componentCategory = this.controller.componentCategories.get(componentName);
|
|
206
|
+
if (!componentCategory && this.controller.classes.has(componentName)) {
|
|
207
|
+
componentCategory = 'AppComponents';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 📦 Check if component is already available from loaded bundles
|
|
211
|
+
const isFromBundle = this.controller.isComponentFromBundle(componentName);
|
|
212
|
+
|
|
213
|
+
if (componentCategory === 'Structural') {
|
|
214
|
+
this.logger.error('Slice', `Component ${componentName} is a Structural component and cannot be built`);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let isVisual = slice.paths.components[componentCategory]?.type === 'Visual';
|
|
219
|
+
let modulePath = `${slice.paths.components[componentCategory].path}/${componentName}/${componentName}.js`;
|
|
220
|
+
const isJsOnlyVisualComponent = isVisual && (componentName === 'MultiRoute' || componentName === 'Route');
|
|
221
|
+
|
|
222
|
+
// Load template, class, and CSS concurrently if needed
|
|
223
|
+
try {
|
|
224
|
+
// 📦 Skip individual loading if component is available from bundles
|
|
225
|
+
const loadTemplate =
|
|
226
|
+
isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.templates.has(componentName)
|
|
227
|
+
? Promise.resolve(null)
|
|
228
|
+
: this.controller.fetchText(componentName, 'html', componentCategory);
|
|
229
|
+
|
|
230
|
+
const loadClass =
|
|
231
|
+
isFromBundle || this.controller.classes.has(componentName)
|
|
232
|
+
? Promise.resolve(null)
|
|
233
|
+
: this.getClass(modulePath);
|
|
234
|
+
|
|
235
|
+
const loadCSS =
|
|
236
|
+
isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.requestedStyles.has(componentName)
|
|
237
|
+
? Promise.resolve(null)
|
|
238
|
+
: this.controller.fetchText(componentName, 'css', componentCategory);
|
|
239
|
+
|
|
240
|
+
const [html, ComponentClass, css] = await Promise.all([loadTemplate, loadClass, loadCSS]);
|
|
241
|
+
|
|
242
|
+
// 📦 If component is from bundle but not in cache, it should have been registered by registerBundle
|
|
243
|
+
if (isFromBundle) {
|
|
244
|
+
this.logger.logInfo('Slice', `📦 Using bundled component: ${componentName}`);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (html || html === '') {
|
|
248
|
+
const template = document.createElement('template');
|
|
249
|
+
template.innerHTML = html;
|
|
250
|
+
this.controller.templates.set(componentName, template);
|
|
251
|
+
this.logger.logInfo('Slice', `Template ${componentName} loaded`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (ComponentClass) {
|
|
255
|
+
this.controller.classes.set(componentName, ComponentClass);
|
|
256
|
+
this.logger.logInfo('Slice', `Class ${componentName} loaded`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (css) {
|
|
260
|
+
this.stylesManager.registerComponentStyles(componentName, css);
|
|
261
|
+
this.logger.logInfo('Slice', `CSS ${componentName} loaded`);
|
|
262
|
+
}
|
|
263
|
+
} catch (error) {
|
|
264
|
+
this.logger.logError('Slice', `Error loading resources for ${componentName}`, error);
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Create instance
|
|
269
|
+
try {
|
|
270
|
+
let componentIds = {};
|
|
271
|
+
if (props.id) componentIds.id = props.id;
|
|
272
|
+
if (props.sliceId) componentIds.sliceId = props.sliceId;
|
|
273
|
+
|
|
274
|
+
delete props.id;
|
|
275
|
+
delete props.sliceId;
|
|
276
|
+
// `singleton` is a build directive (handled in the public build()
|
|
277
|
+
// wrapper). Strip it here too so it is consistently reserved and never
|
|
278
|
+
// leaks into a component's props on the non-singleton path.
|
|
279
|
+
delete props.singleton;
|
|
280
|
+
|
|
281
|
+
const ComponentClass = this.controller.classes.get(componentName);
|
|
282
|
+
this.logger.logInfo(
|
|
283
|
+
'Slice',
|
|
284
|
+
`🔎 Build component: ${componentName} (classType: ${typeof ComponentClass}, isFunction: ${typeof ComponentClass === 'function'})`
|
|
285
|
+
);
|
|
286
|
+
const componentInstance = new ComponentClass(props);
|
|
287
|
+
|
|
288
|
+
if (componentIds.id && isVisual) componentInstance.id = componentIds.id;
|
|
289
|
+
if (componentIds.sliceId) componentInstance.sliceId = componentIds.sliceId;
|
|
290
|
+
|
|
291
|
+
if (!this.controller.verifyComponentIds(componentInstance)) {
|
|
292
|
+
this.logger.logError('Slice', `Error registering instance ${componentName} ${componentInstance.sliceId}`);
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (componentInstance.init) await componentInstance.init();
|
|
297
|
+
|
|
298
|
+
if (slice.debuggerConfig.enabled && isVisual) {
|
|
299
|
+
this.debugger.attachDebugMode(componentInstance);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this.controller.registerComponent(componentInstance);
|
|
303
|
+
if (isVisual) {
|
|
304
|
+
this.controller.registerComponentsRecursively(componentInstance);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
this.logger.logInfo('Slice', `Instance ${componentInstance.sliceId} created`);
|
|
308
|
+
return componentInstance;
|
|
309
|
+
} catch (error) {
|
|
310
|
+
this.logger.logError('Slice', `Error creating instance ${componentName}`, error);
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Apply a theme by name.
|
|
317
|
+
* @param {string} themeName
|
|
318
|
+
* @returns {Promise<void>}
|
|
319
|
+
*/
|
|
320
|
+
async setTheme(themeName) {
|
|
321
|
+
await this.stylesManager.themeManager.applyTheme(themeName);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Current theme name.
|
|
326
|
+
* @returns {string|null}
|
|
327
|
+
*/
|
|
328
|
+
get theme() {
|
|
329
|
+
return this.stylesManager.themeManager.currentTheme;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Attach HTML template to a component instance.
|
|
334
|
+
* @param {HTMLElement} componentInstance
|
|
335
|
+
* @returns {void}
|
|
336
|
+
*/
|
|
337
|
+
attachTemplate(componentInstance) {
|
|
338
|
+
this.controller.loadTemplateToComponent(componentInstance);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function loadConfig() {
|
|
343
|
+
try {
|
|
344
|
+
const response = await fetch('/sliceConfig.json');
|
|
345
|
+
if (!response.ok) throw new Error('Error loading sliceConfig.json');
|
|
346
|
+
const json = await response.json();
|
|
347
|
+
return json;
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.error('Error loading config file:', error);
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function init() {
|
|
355
|
+
const sliceConfig = await loadConfig();
|
|
356
|
+
if (!sliceConfig) {
|
|
357
|
+
console.error('%c\u26A0\uFE0F Error loading Slice configuration', 'color: red; font-size: 20px;');
|
|
358
|
+
alert('Error loading Slice configuration');
|
|
359
|
+
throw new Error('Slice initialization failed: unable to load sliceConfig.json');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 1+2. Fetch mode endpoint and bundle config in parallel — both are independent.
|
|
363
|
+
// In production, /slice-env.json returns 404 (catch is expected and normal).
|
|
364
|
+
// bundleConfigJson.production serves as a mode fallback when env endpoint is absent.
|
|
365
|
+
let frameworkClasses = null;
|
|
366
|
+
const [envResult, configResult] = await Promise.all([
|
|
367
|
+
fetch('/slice-env.json', { cache: 'no-store' })
|
|
368
|
+
.then(r => r.ok ? r.json() : null)
|
|
369
|
+
.catch(error => { console.error('[Slice.js] Error fetching /slice-env.json:', error); return null; }),
|
|
370
|
+
fetch('/bundles/bundle.config.json', { cache: 'no-store' })
|
|
371
|
+
.then(r => r.ok ? r.json() : null)
|
|
372
|
+
.catch(error => { console.error('[Slice.js] Error fetching bundle.config.json:', error); return null; })
|
|
373
|
+
]);
|
|
374
|
+
const envMode = envResult?.mode ?? null;
|
|
375
|
+
const bundleConfigJson = configResult;
|
|
376
|
+
|
|
377
|
+
// 3. Determine canonical mode: env endpoint takes precedence, then bundle config
|
|
378
|
+
let resolvedMode;
|
|
379
|
+
if (envMode) {
|
|
380
|
+
resolvedMode = envMode;
|
|
381
|
+
} else if (bundleConfigJson?.production) {
|
|
382
|
+
resolvedMode = 'production';
|
|
383
|
+
} else {
|
|
384
|
+
resolvedMode = 'development';
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 4. Load framework classes.
|
|
388
|
+
// In production the bundler generates slice-bundle.framework.js which
|
|
389
|
+
// sets window.SLICE_FRAMEWORK_CLASSES. In dev mode always use individual
|
|
390
|
+
// imports so the live /Slice/ source is served directly without bundles.
|
|
391
|
+
if (resolvedMode === 'production' && bundleConfigJson?.bundles?.framework?.file) {
|
|
392
|
+
try {
|
|
393
|
+
await import(`/bundles/${bundleConfigJson.bundles.framework.file}`);
|
|
394
|
+
if (window.SLICE_FRAMEWORK_CLASSES) {
|
|
395
|
+
frameworkClasses = window.SLICE_FRAMEWORK_CLASSES;
|
|
396
|
+
}
|
|
397
|
+
} catch (e) {
|
|
398
|
+
console.error('[Slice.js] framework bundle import failed, falling through to individual imports:', e);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (!frameworkClasses) {
|
|
403
|
+
try {
|
|
404
|
+
const imports = await Promise.all([
|
|
405
|
+
import('./Components/Structural/Controller/Controller.js'),
|
|
406
|
+
import('./Components/Structural/StylesManager/StylesManager.js')
|
|
407
|
+
]);
|
|
408
|
+
frameworkClasses = {
|
|
409
|
+
Controller: imports[0].default,
|
|
410
|
+
StylesManager: imports[1].default
|
|
411
|
+
};
|
|
412
|
+
} catch (e) {
|
|
413
|
+
console.error('[Slice.js] individual imports fallback failed:', e);
|
|
414
|
+
throw e;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// 5. Create Slice instance and set resolved mode
|
|
419
|
+
window.slice = new Slice(sliceConfig, frameworkClasses);
|
|
420
|
+
window.slice._mode = resolvedMode;
|
|
421
|
+
window.slice.setPublicEnv(envResult?.env || {});
|
|
422
|
+
|
|
423
|
+
const createBundlingInitError = (step, error) => {
|
|
424
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
425
|
+
return new Error(`Bundling V2 initialization failed (${step}): ${detail}`, { cause: error });
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// Initialize bundles before building components.
|
|
429
|
+
// Only in production — dev mode loads each component individually from source.
|
|
430
|
+
// bundleConfigJson was already fetched above (step 2); reuse it.
|
|
431
|
+
if (resolvedMode === 'production' && bundleConfigJson) {
|
|
432
|
+
window.slice.controller.bundleConfig = bundleConfigJson;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (resolvedMode === 'production' && window.slice.controller.bundleConfig) {
|
|
436
|
+
const config = window.slice.controller.bundleConfig;
|
|
437
|
+
if (!window.__SLICE_SHARED_DEPS__ || typeof window.__SLICE_SHARED_DEPS__ !== 'object') {
|
|
438
|
+
window.__SLICE_SHARED_DEPS__ = {};
|
|
439
|
+
}
|
|
440
|
+
const criticalFile = config?.bundles?.critical?.file;
|
|
441
|
+
if (criticalFile) {
|
|
442
|
+
try {
|
|
443
|
+
await window.slice.controller.loadBundle('critical');
|
|
444
|
+
} catch (error) {
|
|
445
|
+
throw createBundlingInitError(`critical bundle "${criticalFile}"`, error);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const routeBundles = config?.routeBundles || {};
|
|
450
|
+
const initialPath = window.location.pathname || '/';
|
|
451
|
+
const bundlesForRoute = routeBundles[initialPath] || [];
|
|
452
|
+
|
|
453
|
+
const loadRouteBundles = async () => {
|
|
454
|
+
for (const bundleName of bundlesForRoute) {
|
|
455
|
+
if (bundleName === 'critical') continue;
|
|
456
|
+
const bundleInfo = config?.bundles?.routes?.[bundleName];
|
|
457
|
+
if (!bundleInfo?.file) continue;
|
|
458
|
+
await window.slice.controller.loadBundle(bundleName);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const preloadRouteBundles = () => {
|
|
463
|
+
loadRouteBundles().catch((error) => {
|
|
464
|
+
window.slice?.logger?.error('Slice', `Idle route preload failed for "${initialPath}"`, error);
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const safePreload = () => {
|
|
469
|
+
try {
|
|
470
|
+
preloadRouteBundles();
|
|
471
|
+
} catch (error) {
|
|
472
|
+
window.slice?.logger?.error('Slice', 'Error in route preload callback', error);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
if (typeof requestIdleCallback === 'function') {
|
|
477
|
+
requestIdleCallback(() => safePreload());
|
|
478
|
+
} else {
|
|
479
|
+
setTimeout(() => safePreload(), 0);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
slice.paths.structuralComponentFolderPath = '/Slice/Components/Structural';
|
|
484
|
+
|
|
485
|
+
if (sliceConfig.logger.enabled) {
|
|
486
|
+
const LoggerModule = window.slice.frameworkClasses?.Logger
|
|
487
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Logger/Logger.js`);
|
|
488
|
+
window.slice.logger = new LoggerModule();
|
|
489
|
+
} else {
|
|
490
|
+
const noop = () => {};
|
|
491
|
+
window.slice.logger = {
|
|
492
|
+
error: noop, warn: noop, info: noop, debug: noop,
|
|
493
|
+
logError: noop, logWarning: noop, logInfo: noop,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (sliceConfig.debugger.enabled) {
|
|
498
|
+
const DebuggerModule = window.slice.frameworkClasses?.Debugger
|
|
499
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Debugger/Debugger.js`);
|
|
500
|
+
window.slice.debugger = new DebuggerModule();
|
|
501
|
+
await window.slice.debugger.enableDebugMode();
|
|
502
|
+
document.body.appendChild(window.slice.debugger);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (sliceConfig.events?.ui?.enabled) {
|
|
506
|
+
const EventsDebuggerModule = window.slice.frameworkClasses?.EventManagerDebugger
|
|
507
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/EventManager/EventManagerDebugger.js`);
|
|
508
|
+
window.slice.eventsDebugger = new EventsDebuggerModule();
|
|
509
|
+
await window.slice.eventsDebugger.init();
|
|
510
|
+
document.body.appendChild(window.slice.eventsDebugger);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (sliceConfig.context?.ui?.enabled) {
|
|
514
|
+
const ContextDebuggerModule = window.slice.frameworkClasses?.ContextManagerDebugger
|
|
515
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManagerDebugger.js`);
|
|
516
|
+
window.slice.contextDebugger = new ContextDebuggerModule();
|
|
517
|
+
await window.slice.contextDebugger.init();
|
|
518
|
+
document.body.appendChild(window.slice.contextDebugger);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (sliceConfig.events?.enabled) {
|
|
522
|
+
const EventManagerModule = window.slice.frameworkClasses?.EventManager
|
|
523
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/EventManager/EventManager.js`);
|
|
524
|
+
window.slice.events = new EventManagerModule();
|
|
525
|
+
if (typeof window.slice.events.init === 'function') {
|
|
526
|
+
await window.slice.events.init();
|
|
527
|
+
}
|
|
528
|
+
} else {
|
|
529
|
+
window.slice.events = {
|
|
530
|
+
subscribe: () => null,
|
|
531
|
+
subscribeOnce: () => null,
|
|
532
|
+
unsubscribe: () => false,
|
|
533
|
+
emit: () => {},
|
|
534
|
+
bind: () => ({
|
|
535
|
+
subscribe: () => null,
|
|
536
|
+
subscribeOnce: () => null,
|
|
537
|
+
emit: () => {},
|
|
538
|
+
}),
|
|
539
|
+
cleanupComponent: () => 0,
|
|
540
|
+
hasSubscribers: () => false,
|
|
541
|
+
subscriberCount: () => 0,
|
|
542
|
+
clear: () => {},
|
|
543
|
+
};
|
|
544
|
+
window.slice.logger.logError('Slice', 'EventManager disabled');
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (sliceConfig.context?.enabled) {
|
|
548
|
+
const ContextManagerModule = window.slice.frameworkClasses?.ContextManager
|
|
549
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManager.js`);
|
|
550
|
+
window.slice.context = new ContextManagerModule();
|
|
551
|
+
if (typeof window.slice.context.init === 'function') {
|
|
552
|
+
await window.slice.context.init();
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
window.slice.context = {
|
|
556
|
+
create: () => false,
|
|
557
|
+
getState: () => null,
|
|
558
|
+
setState: () => {},
|
|
559
|
+
watch: () => null,
|
|
560
|
+
has: () => false,
|
|
561
|
+
destroy: () => false,
|
|
562
|
+
list: () => [],
|
|
563
|
+
};
|
|
564
|
+
window.slice.logger.logError('Slice', 'ContextManager disabled');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (sliceConfig.loading.enabled) {
|
|
568
|
+
const loading = await window.slice.build('Loading', {});
|
|
569
|
+
window.slice.loading = loading;
|
|
570
|
+
if (typeof loading?.start === 'function') {
|
|
571
|
+
loading.start();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const stylesInitPromise = window.slice.stylesManager.init();
|
|
576
|
+
const routesModulePromise = import(slice.paths.routesFile);
|
|
577
|
+
|
|
578
|
+
if (sliceConfig.events?.ui?.shortcut || sliceConfig.context?.ui?.shortcut) {
|
|
579
|
+
const normalize = (value) => (typeof value === 'string' ? value.toLowerCase() : '');
|
|
580
|
+
const toKey = (event) => {
|
|
581
|
+
const parts = [];
|
|
582
|
+
if (event.ctrlKey) parts.push('ctrl');
|
|
583
|
+
if (event.shiftKey) parts.push('shift');
|
|
584
|
+
if (event.altKey) parts.push('alt');
|
|
585
|
+
if (event.metaKey) parts.push('meta');
|
|
586
|
+
const key = event.key?.toLowerCase();
|
|
587
|
+
if (key && !['control', 'shift', 'alt', 'meta'].includes(key)) {
|
|
588
|
+
parts.push(key);
|
|
589
|
+
}
|
|
590
|
+
return parts.join('+');
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const handlers = {
|
|
594
|
+
[normalize(sliceConfig.events?.ui?.shortcut)]: () => window.slice.eventsDebugger?.toggle?.(),
|
|
595
|
+
[normalize(sliceConfig.context?.ui?.shortcut)]: () => window.slice.contextDebugger?.toggle?.(),
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
document.addEventListener('keydown', (event) => {
|
|
599
|
+
const key = toKey(event);
|
|
600
|
+
if (!key || !handlers[key]) return;
|
|
601
|
+
event.preventDefault();
|
|
602
|
+
handlers[key]();
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const [, routesModule] = await Promise.all([stylesInitPromise, routesModulePromise]);
|
|
607
|
+
const routes = routesModule.default;
|
|
608
|
+
const RouterModule = window.slice.frameworkClasses?.Router
|
|
609
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Router/Router.js`);
|
|
610
|
+
window.slice.router = new RouterModule(routes);
|
|
611
|
+
await window.slice.router.init();
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
try {
|
|
615
|
+
await init();
|
|
616
|
+
} catch (initError) {
|
|
617
|
+
console.error('[Slice.js] Initialization failed:', initError);
|
|
618
|
+
}
|