slicejs-web-framework 2.3.1 ā 2.3.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.
- package/Slice/Components/Structural/ContextManager/ContextManager.js +369 -361
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +258 -0
- package/Slice/Components/Structural/Controller/Controller.js +944 -925
- package/Slice/Components/Structural/Debugger/Debugger.js +1547 -1347
- package/Slice/Components/Structural/EventManager/EventManager.js +338 -329
- package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +238 -0
- package/Slice/Components/Structural/Logger/Logger.js +146 -104
- package/Slice/Components/Structural/Router/Router.js +720 -598
- package/Slice/Components/Structural/StylesManager/StylesManager.js +64 -49
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +84 -56
- package/Slice/Slice.js +383 -297
- package/package.json +1 -1
package/Slice/Slice.js
CHANGED
|
@@ -1,297 +1,383 @@
|
|
|
1
|
-
import Controller from './Components/Structural/Controller/Controller.js';
|
|
2
|
-
import StylesManager from './Components/Structural/StylesManager/StylesManager.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
this.logger.logError(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
await
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
await init();
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
1
|
+
import Controller from './Components/Structural/Controller/Controller.js';
|
|
2
|
+
import StylesManager from './Components/Structural/StylesManager/StylesManager.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Main Slice.js runtime.
|
|
6
|
+
*/
|
|
7
|
+
export default class Slice {
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} sliceConfig
|
|
10
|
+
*/
|
|
11
|
+
constructor(sliceConfig) {
|
|
12
|
+
this.controller = new Controller();
|
|
13
|
+
this.stylesManager = new StylesManager();
|
|
14
|
+
this.paths = sliceConfig.paths;
|
|
15
|
+
this.themeConfig = sliceConfig.themeManager;
|
|
16
|
+
this.stylesConfig = sliceConfig.stylesManager;
|
|
17
|
+
this.loggerConfig = sliceConfig.logger;
|
|
18
|
+
this.debuggerConfig = sliceConfig.debugger;
|
|
19
|
+
this.loadingConfig = sliceConfig.loading;
|
|
20
|
+
this.eventsConfig = sliceConfig.events;
|
|
21
|
+
|
|
22
|
+
// š¦ Bundle system is initialized automatically via import in index.js
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Dynamically import a module and return its default export.
|
|
27
|
+
* @param {string} module
|
|
28
|
+
* @returns {Promise<any>}
|
|
29
|
+
*/
|
|
30
|
+
async getClass(module) {
|
|
31
|
+
try {
|
|
32
|
+
const { default: myClass } = await import(module);
|
|
33
|
+
return await myClass;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
this.logger.logError('Slice', `Error loading class ${module}`, error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Flag for production behavior (override in builds).
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
isProduction() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get a component instance by sliceId.
|
|
49
|
+
* @param {string} componentSliceId
|
|
50
|
+
* @returns {HTMLElement|undefined}
|
|
51
|
+
*/
|
|
52
|
+
getComponent(componentSliceId) {
|
|
53
|
+
return this.controller.activeComponents.get(componentSliceId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Build a component instance and run init.
|
|
58
|
+
* @param {string} componentName
|
|
59
|
+
* @param {Object} [props]
|
|
60
|
+
* @returns {Promise<HTMLElement|Object|null>}
|
|
61
|
+
*/
|
|
62
|
+
async build(componentName, props = {}) {
|
|
63
|
+
if (!componentName) {
|
|
64
|
+
this.logger.logError('Slice', null, `Component name is required to build a component`);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof componentName !== 'string') {
|
|
69
|
+
this.logger.logError('Slice', null, `Component name must be a string`);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!this.controller.componentCategories.has(componentName)) {
|
|
74
|
+
this.logger.logError('Slice', null, `Component ${componentName} not found in components.js file`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// š¦ Try to load from bundles first
|
|
79
|
+
const bundleName = this.controller.getBundleForComponent(componentName);
|
|
80
|
+
if (bundleName && !this.controller.loadedBundles.has(bundleName)) {
|
|
81
|
+
await this.controller.loadBundle(bundleName);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let componentCategory = this.controller.componentCategories.get(componentName);
|
|
85
|
+
|
|
86
|
+
// š¦ Check if component is already available from loaded bundles
|
|
87
|
+
const isFromBundle = this.controller.isComponentFromBundle(componentName);
|
|
88
|
+
|
|
89
|
+
if (componentCategory === 'Structural') {
|
|
90
|
+
this.logger.logError(
|
|
91
|
+
'Slice',
|
|
92
|
+
null,
|
|
93
|
+
`Component ${componentName} is a Structural component and cannot be built`
|
|
94
|
+
);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let isVisual = slice.paths.components[componentCategory].type === 'Visual';
|
|
99
|
+
let modulePath = `${slice.paths.components[componentCategory].path}/${componentName}/${componentName}.js`;
|
|
100
|
+
|
|
101
|
+
// Load template, class, and CSS concurrently if needed
|
|
102
|
+
try {
|
|
103
|
+
// š¦ Skip individual loading if component is available from bundles
|
|
104
|
+
const loadTemplate =
|
|
105
|
+
isFromBundle || !isVisual || this.controller.templates.has(componentName)
|
|
106
|
+
? Promise.resolve(null)
|
|
107
|
+
: this.controller.fetchText(componentName, 'html', componentCategory);
|
|
108
|
+
|
|
109
|
+
const loadClass =
|
|
110
|
+
isFromBundle || this.controller.classes.has(componentName)
|
|
111
|
+
? Promise.resolve(null)
|
|
112
|
+
: this.getClass(modulePath);
|
|
113
|
+
|
|
114
|
+
const loadCSS =
|
|
115
|
+
isFromBundle || !isVisual || this.controller.requestedStyles.has(componentName)
|
|
116
|
+
? Promise.resolve(null)
|
|
117
|
+
: this.controller.fetchText(componentName, 'css', componentCategory);
|
|
118
|
+
|
|
119
|
+
const [html, ComponentClass, css] = await Promise.all([loadTemplate, loadClass, loadCSS]);
|
|
120
|
+
|
|
121
|
+
// š¦ If component is from bundle but not in cache, it should have been registered by registerBundle
|
|
122
|
+
if (isFromBundle) {
|
|
123
|
+
console.log(`š¦ Using bundled component: ${componentName}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (html || html === '') {
|
|
127
|
+
const template = document.createElement('template');
|
|
128
|
+
template.innerHTML = html;
|
|
129
|
+
this.controller.templates.set(componentName, template);
|
|
130
|
+
this.logger.logInfo('Slice', `Template ${componentName} loaded`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (ComponentClass) {
|
|
134
|
+
this.controller.classes.set(componentName, ComponentClass);
|
|
135
|
+
this.logger.logInfo('Slice', `Class ${componentName} loaded`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (css) {
|
|
139
|
+
this.stylesManager.registerComponentStyles(componentName, css);
|
|
140
|
+
this.logger.logInfo('Slice', `CSS ${componentName} loaded`);
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.log(error);
|
|
144
|
+
this.logger.logError('Slice', `Error loading resources for ${componentName}`, error);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Create instance
|
|
149
|
+
try {
|
|
150
|
+
let componentIds = {};
|
|
151
|
+
if (props.id) componentIds.id = props.id;
|
|
152
|
+
if (props.sliceId) componentIds.sliceId = props.sliceId;
|
|
153
|
+
|
|
154
|
+
delete props.id;
|
|
155
|
+
delete props.sliceId;
|
|
156
|
+
|
|
157
|
+
const ComponentClass = this.controller.classes.get(componentName);
|
|
158
|
+
const componentInstance = new ComponentClass(props);
|
|
159
|
+
|
|
160
|
+
if (componentIds.id && isVisual) componentInstance.id = componentIds.id;
|
|
161
|
+
if (componentIds.sliceId) componentInstance.sliceId = componentIds.sliceId;
|
|
162
|
+
|
|
163
|
+
if (!this.controller.verifyComponentIds(componentInstance)) {
|
|
164
|
+
this.logger.logError('Slice', `Error registering instance ${componentName} ${componentInstance.sliceId}`);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (componentInstance.init) await componentInstance.init();
|
|
169
|
+
|
|
170
|
+
if (slice.debuggerConfig.enabled && isVisual) {
|
|
171
|
+
this.debugger.attachDebugMode(componentInstance);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.controller.registerComponent(componentInstance);
|
|
175
|
+
if (isVisual) {
|
|
176
|
+
this.controller.registerComponentsRecursively(componentInstance);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
this.logger.logInfo('Slice', `Instance ${componentInstance.sliceId} created`);
|
|
180
|
+
return componentInstance;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.log(error);
|
|
183
|
+
this.logger.logError('Slice', `Error creating instance ${componentName}`, error);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Apply a theme by name.
|
|
190
|
+
* @param {string} themeName
|
|
191
|
+
* @returns {Promise<void>}
|
|
192
|
+
*/
|
|
193
|
+
async setTheme(themeName) {
|
|
194
|
+
await this.stylesManager.themeManager.applyTheme(themeName);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Current theme name.
|
|
199
|
+
* @returns {string|null}
|
|
200
|
+
*/
|
|
201
|
+
get theme() {
|
|
202
|
+
return this.stylesManager.themeManager.currentTheme;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Attach HTML template to a component instance.
|
|
207
|
+
* @param {HTMLElement} componentInstance
|
|
208
|
+
* @returns {void}
|
|
209
|
+
*/
|
|
210
|
+
attachTemplate(componentInstance) {
|
|
211
|
+
this.controller.loadTemplateToComponent(componentInstance);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function loadConfig() {
|
|
216
|
+
try {
|
|
217
|
+
const response = await fetch('/sliceConfig.json'); // š¹ Express lo sirve desde `src/`
|
|
218
|
+
if (!response.ok) throw new Error('Error loading sliceConfig.json');
|
|
219
|
+
const json = await response.json();
|
|
220
|
+
console.log(json);
|
|
221
|
+
return json;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error(`Error loading config file: ${error.message}`);
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function init() {
|
|
229
|
+
const sliceConfig = await loadConfig();
|
|
230
|
+
if (!sliceConfig) {
|
|
231
|
+
//Display error message in console with colors and alert in english
|
|
232
|
+
console.error('%cāļø Error loading Slice configuration āļø', 'color: red; font-size: 20px;');
|
|
233
|
+
alert('Error loading Slice configuration');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
window.slice = new Slice(sliceConfig);
|
|
238
|
+
|
|
239
|
+
slice.paths.structuralComponentFolderPath = '/Slice/Components/Structural';
|
|
240
|
+
|
|
241
|
+
if (sliceConfig.logger.enabled) {
|
|
242
|
+
const LoggerModule = await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Logger/Logger.js`);
|
|
243
|
+
window.slice.logger = new LoggerModule();
|
|
244
|
+
} else {
|
|
245
|
+
window.slice.logger = {
|
|
246
|
+
logError: () => {},
|
|
247
|
+
logWarning: () => {},
|
|
248
|
+
logInfo: () => {},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (sliceConfig.debugger.enabled) {
|
|
253
|
+
const DebuggerModule = await window.slice.getClass(
|
|
254
|
+
`${slice.paths.structuralComponentFolderPath}/Debugger/Debugger.js`
|
|
255
|
+
);
|
|
256
|
+
window.slice.debugger = new DebuggerModule();
|
|
257
|
+
await window.slice.debugger.enableDebugMode();
|
|
258
|
+
document.body.appendChild(window.slice.debugger);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (sliceConfig.events?.ui?.enabled) {
|
|
262
|
+
const EventsDebuggerModule = await window.slice.getClass(
|
|
263
|
+
`${slice.paths.structuralComponentFolderPath}/EventManager/EventManagerDebugger.js`
|
|
264
|
+
);
|
|
265
|
+
window.slice.eventsDebugger = new EventsDebuggerModule();
|
|
266
|
+
await window.slice.eventsDebugger.init();
|
|
267
|
+
document.body.appendChild(window.slice.eventsDebugger);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (sliceConfig.context?.ui?.enabled) {
|
|
271
|
+
const ContextDebuggerModule = await window.slice.getClass(
|
|
272
|
+
`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManagerDebugger.js`
|
|
273
|
+
);
|
|
274
|
+
window.slice.contextDebugger = new ContextDebuggerModule();
|
|
275
|
+
await window.slice.contextDebugger.init();
|
|
276
|
+
document.body.appendChild(window.slice.contextDebugger);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (sliceConfig.events?.enabled) {
|
|
280
|
+
const EventManagerModule = await window.slice.getClass(
|
|
281
|
+
`${slice.paths.structuralComponentFolderPath}/EventManager/EventManager.js`
|
|
282
|
+
);
|
|
283
|
+
window.slice.events = new EventManagerModule();
|
|
284
|
+
if (typeof window.slice.events.init === 'function') {
|
|
285
|
+
await window.slice.events.init();
|
|
286
|
+
}
|
|
287
|
+
window.slice.logger.logError('Slice', 'EventManager enabled');
|
|
288
|
+
} else {
|
|
289
|
+
window.slice.events = {
|
|
290
|
+
subscribe: () => null,
|
|
291
|
+
subscribeOnce: () => null,
|
|
292
|
+
unsubscribe: () => false,
|
|
293
|
+
emit: () => {},
|
|
294
|
+
bind: () => ({
|
|
295
|
+
subscribe: () => null,
|
|
296
|
+
subscribeOnce: () => null,
|
|
297
|
+
emit: () => {},
|
|
298
|
+
}),
|
|
299
|
+
cleanupComponent: () => 0,
|
|
300
|
+
hasSubscribers: () => false,
|
|
301
|
+
subscriberCount: () => 0,
|
|
302
|
+
clear: () => {},
|
|
303
|
+
};
|
|
304
|
+
window.slice.logger.logError('Slice', 'EventManager disabled');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (sliceConfig.context?.enabled) {
|
|
308
|
+
const ContextManagerModule = await window.slice.getClass(
|
|
309
|
+
`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManager.js`
|
|
310
|
+
);
|
|
311
|
+
window.slice.context = new ContextManagerModule();
|
|
312
|
+
if (typeof window.slice.context.init === 'function') {
|
|
313
|
+
await window.slice.context.init();
|
|
314
|
+
}
|
|
315
|
+
window.slice.logger.logError('Slice', 'ContextManager enabled');
|
|
316
|
+
} else {
|
|
317
|
+
window.slice.context = {
|
|
318
|
+
create: () => false,
|
|
319
|
+
getState: () => null,
|
|
320
|
+
setState: () => {},
|
|
321
|
+
watch: () => null,
|
|
322
|
+
has: () => false,
|
|
323
|
+
destroy: () => false,
|
|
324
|
+
list: () => [],
|
|
325
|
+
};
|
|
326
|
+
window.slice.logger.logError('Slice', 'ContextManager disabled');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (sliceConfig.loading.enabled) {
|
|
330
|
+
const loading = await window.slice.build('Loading', {});
|
|
331
|
+
window.slice.loading = loading;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
await window.slice.stylesManager.init();
|
|
335
|
+
|
|
336
|
+
if (sliceConfig.events?.ui?.shortcut || sliceConfig.context?.ui?.shortcut) {
|
|
337
|
+
const normalize = (value) => (typeof value === 'string' ? value.toLowerCase() : '');
|
|
338
|
+
const toKey = (event) => {
|
|
339
|
+
const parts = [];
|
|
340
|
+
if (event.ctrlKey) parts.push('ctrl');
|
|
341
|
+
if (event.shiftKey) parts.push('shift');
|
|
342
|
+
if (event.altKey) parts.push('alt');
|
|
343
|
+
if (event.metaKey) parts.push('meta');
|
|
344
|
+
const key = event.key?.toLowerCase();
|
|
345
|
+
if (key && !['control', 'shift', 'alt', 'meta'].includes(key)) {
|
|
346
|
+
parts.push(key);
|
|
347
|
+
}
|
|
348
|
+
return parts.join('+');
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const handlers = {
|
|
352
|
+
[normalize(sliceConfig.events?.ui?.shortcut)]: () => window.slice.eventsDebugger?.toggle?.(),
|
|
353
|
+
[normalize(sliceConfig.context?.ui?.shortcut)]: () => window.slice.contextDebugger?.toggle?.(),
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
document.addEventListener('keydown', (event) => {
|
|
357
|
+
const key = toKey(event);
|
|
358
|
+
if (!key || !handlers[key]) return;
|
|
359
|
+
event.preventDefault();
|
|
360
|
+
handlers[key]();
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const routesModule = await import(slice.paths.routesFile);
|
|
365
|
+
const routes = routesModule.default;
|
|
366
|
+
const RouterModule = await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Router/Router.js`);
|
|
367
|
+
window.slice.router = new RouterModule(routes);
|
|
368
|
+
await window.slice.router.init();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
await init();
|
|
372
|
+
|
|
373
|
+
// Initialize bundles if available
|
|
374
|
+
try {
|
|
375
|
+
const { initializeBundles } = await import('/bundles/bundle.config.js');
|
|
376
|
+
if (initializeBundles) {
|
|
377
|
+
await initializeBundles(window.slice);
|
|
378
|
+
console.log('š¦ Bundles initialized automatically');
|
|
379
|
+
}
|
|
380
|
+
} catch (error) {
|
|
381
|
+
// Bundles not available, continue with individual component loading
|
|
382
|
+
console.log('š Using individual component loading (no bundles found)');
|
|
383
|
+
}
|