slicejs-web-framework 2.4.8 → 3.0.0
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/.worktrees/bundling-v2-precompiled-registrars/LICENSE +21 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/ContextManager/ContextManager.js +369 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +297 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Controller/Controller.js +972 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Debugger/Debugger.css +620 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Debugger/Debugger.html +73 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Debugger/Debugger.js +1548 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/EventManager/EventManager.js +338 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/EventManager/EventManagerDebugger.js +361 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Logger/Log.js +10 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Logger/Logger.js +146 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/Router/Router.js +721 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/StylesManager/StylesManager.js +78 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +84 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/Slice.js +504 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/tests/bundle-v2-runtime-contract.test.js +268 -0
- package/.worktrees/bundling-v2-precompiled-registrars/Slice/tests/router-loading-finally.test.js +68 -0
- package/.worktrees/bundling-v2-precompiled-registrars/api/index.js +286 -0
- package/.worktrees/bundling-v2-precompiled-registrars/api/middleware/securityMiddleware.js +253 -0
- package/.worktrees/bundling-v2-precompiled-registrars/package.json +37 -0
- package/.worktrees/bundling-v2-precompiled-registrars/sliceConfig.schema.json +109 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/App/index.html +22 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/App/index.js +23 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/App/style.css +40 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/HomePage/HomePage.css +201 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/HomePage/HomePage.html +37 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/HomePage/HomePage.js +210 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/Playground/Playground.css +12 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/Playground/Playground.html +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/AppComponents/Playground/Playground.js +111 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Service/FetchManager/FetchManager.js +133 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Service/IndexedDbManager/IndexedDbManager.js +141 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Button/Button.css +47 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Button/Button.html +5 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Button/Button.js +93 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Card/Card.css +68 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Card/Card.html +7 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Card/Card.js +107 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Checkbox/Checkbox.css +87 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Checkbox/Checkbox.html +8 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Checkbox/Checkbox.js +86 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/CodeVisualizer/CodeVisualizer.css +130 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/CodeVisualizer/CodeVisualizer.html +4 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/CodeVisualizer/CodeVisualizer.js +262 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Details/Details.css +70 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Details/Details.html +9 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Details/Details.js +76 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/DropDown/DropDown.css +60 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/DropDown/DropDown.html +5 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/DropDown/DropDown.js +63 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Grid/Grid.css +7 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Grid/Grid.html +1 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Grid/Grid.js +57 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/Icon.css +510 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/Icon.html +1 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/Icon.js +89 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.eot +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.json +555 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.styl +507 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.svg +1485 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.symbol.svg +1059 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.ttf +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.woff +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Icon/slc.woff2 +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Input/Input.css +91 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Input/Input.html +4 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Input/Input.js +215 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Layout/Layout.css +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Layout/Layout.html +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Layout/Layout.js +49 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Link/Link.css +8 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Link/Link.html +1 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Link/Link.js +63 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Loading/Loading.css +56 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Loading/Loading.html +83 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Loading/Loading.js +38 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/MultiRoute/MultiRoute.js +93 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Navbar/Navbar.css +115 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Navbar/Navbar.html +44 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Navbar/Navbar.js +141 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/NotFound/NotFound.css +117 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/NotFound/NotFound.html +24 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/NotFound/NotFound.js +16 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Route/Route.js +93 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Select/Select.css +84 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Select/Select.html +8 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Select/Select.js +195 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Switch/Switch.css +76 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Switch/Switch.html +8 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/Switch/Switch.js +102 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeItem/TreeItem.css +36 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeItem/TreeItem.html +1 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeItem/TreeItem.js +126 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeView/TreeView.css +8 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeView/TreeView.html +1 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/Visual/TreeView/TreeView.js +48 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Components/components.js +27 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Styles/sliceStyles.css +34 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Themes/Dark.css +42 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Themes/Light.css +31 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/Themes/Slice.css +47 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/images/Slice.js-logo.png +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/images/favicon.ico +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/images/im2/Slice.js-logo.png +0 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/routes.js +16 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/sliceConfig.json +73 -0
- package/.worktrees/bundling-v2-precompiled-registrars/src/testing.js +888 -0
- package/Slice/Components/Structural/Controller/Controller.js +51 -29
- package/Slice/Components/Structural/Router/Router.js +25 -24
- package/Slice/Slice.js +50 -46
- package/Slice/tests/bundle-v2-runtime-contract.test.js +268 -0
- package/Slice/tests/router-loading-finally.test.js +68 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
export default class StylesManager {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.componentStyles = document.createElement('style');
|
|
5
|
+
this.componentStyles.id = 'slice-component-styles';
|
|
6
|
+
document.head.appendChild(this.componentStyles);
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load global styles and initialize ThemeManager if enabled.
|
|
12
|
+
* @returns {Promise<void>}
|
|
13
|
+
*/
|
|
14
|
+
async init() {
|
|
15
|
+
const requestedStyles = Array.isArray(slice.stylesConfig.requestedStyles)
|
|
16
|
+
? slice.stylesConfig.requestedStyles
|
|
17
|
+
: [];
|
|
18
|
+
|
|
19
|
+
const styleResults = await Promise.all(
|
|
20
|
+
requestedStyles.map(async (styleName) => {
|
|
21
|
+
const styles = await slice.controller.fetchText(styleName, 'styles');
|
|
22
|
+
return { styleName, styles };
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
for (const { styleName, styles } of styleResults) {
|
|
27
|
+
this.appendComponentStyles(styles);
|
|
28
|
+
slice.logger.logInfo('StylesManager', `${styleName} styles loaded`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (slice.themeConfig.enabled) {
|
|
32
|
+
const ThemeManagerClass = slice.frameworkClasses?.ThemeManager
|
|
33
|
+
|| await slice.getClass(`${slice.paths.structuralComponentFolderPath}/StylesManager/ThemeManager/ThemeManager.js`);
|
|
34
|
+
if (!ThemeManagerClass) {
|
|
35
|
+
throw new Error('ThemeManager not available');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.themeManager = new ThemeManagerClass();
|
|
39
|
+
let theme;
|
|
40
|
+
|
|
41
|
+
if (slice.themeConfig.saveThemeLocally) {
|
|
42
|
+
theme = localStorage.getItem('sliceTheme');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!theme) {
|
|
46
|
+
theme = slice.themeConfig.defaultTheme;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (slice.themeConfig.useBrowserTheme) {
|
|
50
|
+
const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'Dark' : 'Light';
|
|
51
|
+
theme = browserTheme;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await this.themeManager.applyTheme(theme);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//add a method that will add css as text to the componentStyles element
|
|
59
|
+
/**
|
|
60
|
+
* Append raw CSS to the global component style tag.
|
|
61
|
+
* @param {string} cssText
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
appendComponentStyles(cssText) {
|
|
65
|
+
this.componentStyles.appendChild(document.createTextNode(cssText));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Register CSS for a component.
|
|
70
|
+
* @param {string} componentName
|
|
71
|
+
* @param {string} cssText
|
|
72
|
+
* @returns {void}
|
|
73
|
+
*/
|
|
74
|
+
registerComponentStyles(componentName, cssText) {
|
|
75
|
+
slice.controller.requestedStyles.add(componentName);
|
|
76
|
+
this.appendComponentStyles(cssText);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages theme CSS loading and persistence.
|
|
3
|
+
*/
|
|
4
|
+
export default class ThemeManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.themeStyles = new Map();
|
|
7
|
+
this.currentTheme = null;
|
|
8
|
+
this.themeStyle = document.createElement('style');
|
|
9
|
+
document.head.appendChild(this.themeStyle);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Apply a theme by name.
|
|
14
|
+
* @param {string} themeName
|
|
15
|
+
* @returns {Promise<void>}
|
|
16
|
+
*/
|
|
17
|
+
async applyTheme(themeName) {
|
|
18
|
+
if (!themeName) {
|
|
19
|
+
slice.logger.logError('ThemeManager', 'Invalid theme name');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!this.themeStyles.has(themeName)) {
|
|
24
|
+
await this.loadThemeCSS(themeName);
|
|
25
|
+
} else {
|
|
26
|
+
this.setThemeStyle(themeName);
|
|
27
|
+
this.saveThemeLocally(themeName, this.themeStyles.get(themeName));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Load theme CSS and cache it.
|
|
33
|
+
* @param {string} themeName
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
async loadThemeCSS(themeName) {
|
|
37
|
+
let themeContent =
|
|
38
|
+
localStorage.getItem(`sliceTheme-${themeName}`) || (await slice.controller.fetchText(themeName, 'theme'));
|
|
39
|
+
|
|
40
|
+
if (!themeContent) {
|
|
41
|
+
slice.logger.logError('ThemeManager', `Failed to load theme: ${themeName}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.themeStyles.set(themeName, themeContent);
|
|
46
|
+
this.setThemeStyle(themeName);
|
|
47
|
+
this.saveThemeLocally(themeName, themeContent);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Persist a theme in localStorage when enabled.
|
|
52
|
+
* @param {string} themeName
|
|
53
|
+
* @param {string} themeContent
|
|
54
|
+
* @returns {void}
|
|
55
|
+
*/
|
|
56
|
+
saveThemeLocally(themeName, themeContent) {
|
|
57
|
+
if (slice.themeConfig.saveThemeLocally) {
|
|
58
|
+
localStorage.setItem('sliceTheme', themeName);
|
|
59
|
+
localStorage.setItem(`sliceTheme-${themeName}`, themeContent);
|
|
60
|
+
slice.logger.logInfo('ThemeManager', `Theme ${themeName} saved locally`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clear currently applied theme styles.
|
|
66
|
+
* @returns {void}
|
|
67
|
+
*/
|
|
68
|
+
removeCurrentTheme() {
|
|
69
|
+
if (this.currentTheme) {
|
|
70
|
+
this.themeStyle.textContent = '';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Set theme style text and mark current theme.
|
|
76
|
+
* @param {string} themeName
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
setThemeStyle(themeName) {
|
|
80
|
+
this.themeStyle.textContent = this.themeStyles.get(themeName);
|
|
81
|
+
this.currentTheme = themeName;
|
|
82
|
+
slice.logger.logInfo('ThemeManager', `Theme ${themeName} applied`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,504 @@
|
|
|
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
|
+
|
|
28
|
+
// 📦 Bundle system is initialized automatically via import in index.js
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Dynamically import a module and return its default export.
|
|
33
|
+
* @param {string} module
|
|
34
|
+
* @returns {Promise<any>}
|
|
35
|
+
*/
|
|
36
|
+
async getClass(module) {
|
|
37
|
+
try {
|
|
38
|
+
const { default: myClass } = await import(module);
|
|
39
|
+
return await myClass;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
this.logger.logError('Slice', `Error loading class ${module}`, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns true when running in production mode.
|
|
47
|
+
* Reliable after init() has completed.
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
isProduction() {
|
|
51
|
+
return this._mode === 'production';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get a component instance by sliceId.
|
|
56
|
+
* @param {string} componentSliceId
|
|
57
|
+
* @returns {HTMLElement|undefined}
|
|
58
|
+
*/
|
|
59
|
+
getComponent(componentSliceId) {
|
|
60
|
+
return this.controller.activeComponents.get(componentSliceId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Build a component instance and run init.
|
|
65
|
+
* @param {string} componentName
|
|
66
|
+
* @param {Object} [props]
|
|
67
|
+
* @returns {Promise<HTMLElement|Object|null>}
|
|
68
|
+
*/
|
|
69
|
+
async build(componentName, props = {}) {
|
|
70
|
+
if (!componentName) {
|
|
71
|
+
this.logger.logError('Slice', null, `Component name is required to build a component`);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (typeof componentName !== 'string') {
|
|
76
|
+
this.logger.logError('Slice', null, `Component name must be a string`);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.controller.componentCategories.has(componentName)) {
|
|
81
|
+
this.logger.logError('Slice', null, `Component ${componentName} not found in components.js file`);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 📦 Try to load from bundles first
|
|
86
|
+
const bundleName = this.controller.getBundleForComponent(componentName);
|
|
87
|
+
if (bundleName && !this.controller.loadedBundles.has(bundleName)) {
|
|
88
|
+
await this.controller.loadBundle(bundleName);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let componentCategory = this.controller.componentCategories.get(componentName);
|
|
92
|
+
|
|
93
|
+
// 📦 Check if component is already available from loaded bundles
|
|
94
|
+
const isFromBundle = this.controller.isComponentFromBundle(componentName);
|
|
95
|
+
|
|
96
|
+
if (componentCategory === 'Structural') {
|
|
97
|
+
this.logger.logError(
|
|
98
|
+
'Slice',
|
|
99
|
+
null,
|
|
100
|
+
`Component ${componentName} is a Structural component and cannot be built`
|
|
101
|
+
);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let isVisual = slice.paths.components[componentCategory].type === 'Visual';
|
|
106
|
+
let modulePath = `${slice.paths.components[componentCategory].path}/${componentName}/${componentName}.js`;
|
|
107
|
+
|
|
108
|
+
// Load template, class, and CSS concurrently if needed
|
|
109
|
+
try {
|
|
110
|
+
// 📦 Skip individual loading if component is available from bundles
|
|
111
|
+
const loadTemplate =
|
|
112
|
+
isFromBundle || !isVisual || this.controller.templates.has(componentName)
|
|
113
|
+
? Promise.resolve(null)
|
|
114
|
+
: this.controller.fetchText(componentName, 'html', componentCategory);
|
|
115
|
+
|
|
116
|
+
const loadClass =
|
|
117
|
+
isFromBundle || this.controller.classes.has(componentName)
|
|
118
|
+
? Promise.resolve(null)
|
|
119
|
+
: this.getClass(modulePath);
|
|
120
|
+
|
|
121
|
+
const loadCSS =
|
|
122
|
+
isFromBundle || !isVisual || this.controller.requestedStyles.has(componentName)
|
|
123
|
+
? Promise.resolve(null)
|
|
124
|
+
: this.controller.fetchText(componentName, 'css', componentCategory);
|
|
125
|
+
|
|
126
|
+
const [html, ComponentClass, css] = await Promise.all([loadTemplate, loadClass, loadCSS]);
|
|
127
|
+
|
|
128
|
+
// 📦 If component is from bundle but not in cache, it should have been registered by registerBundle
|
|
129
|
+
if (isFromBundle) {
|
|
130
|
+
console.log(`📦 Using bundled component: ${componentName}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (html || html === '') {
|
|
134
|
+
const template = document.createElement('template');
|
|
135
|
+
template.innerHTML = html;
|
|
136
|
+
this.controller.templates.set(componentName, template);
|
|
137
|
+
this.logger.logInfo('Slice', `Template ${componentName} loaded`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (ComponentClass) {
|
|
141
|
+
this.controller.classes.set(componentName, ComponentClass);
|
|
142
|
+
this.logger.logInfo('Slice', `Class ${componentName} loaded`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (css) {
|
|
146
|
+
this.stylesManager.registerComponentStyles(componentName, css);
|
|
147
|
+
this.logger.logInfo('Slice', `CSS ${componentName} loaded`);
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.log(error);
|
|
151
|
+
this.logger.logError('Slice', `Error loading resources for ${componentName}`, error);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Create instance
|
|
156
|
+
try {
|
|
157
|
+
let componentIds = {};
|
|
158
|
+
if (props.id) componentIds.id = props.id;
|
|
159
|
+
if (props.sliceId) componentIds.sliceId = props.sliceId;
|
|
160
|
+
|
|
161
|
+
delete props.id;
|
|
162
|
+
delete props.sliceId;
|
|
163
|
+
|
|
164
|
+
const ComponentClass = this.controller.classes.get(componentName);
|
|
165
|
+
if (componentName === 'Loading') {
|
|
166
|
+
console.log('🔎 Build component: Loading', {
|
|
167
|
+
classType: typeof ComponentClass,
|
|
168
|
+
isFunction: typeof ComponentClass === 'function',
|
|
169
|
+
classValue: ComponentClass
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (componentName === 'InputSearchDocs' || componentName === 'MainMenu') {
|
|
173
|
+
console.log(`🔎 Build component: ${componentName}`, {
|
|
174
|
+
classType: typeof ComponentClass,
|
|
175
|
+
isFunction: typeof ComponentClass === 'function',
|
|
176
|
+
classValue: ComponentClass
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const componentInstance = new ComponentClass(props);
|
|
180
|
+
|
|
181
|
+
if (componentIds.id && isVisual) componentInstance.id = componentIds.id;
|
|
182
|
+
if (componentIds.sliceId) componentInstance.sliceId = componentIds.sliceId;
|
|
183
|
+
|
|
184
|
+
if (!this.controller.verifyComponentIds(componentInstance)) {
|
|
185
|
+
this.logger.logError('Slice', `Error registering instance ${componentName} ${componentInstance.sliceId}`);
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (componentInstance.init) await componentInstance.init();
|
|
190
|
+
|
|
191
|
+
if (slice.debuggerConfig.enabled && isVisual) {
|
|
192
|
+
this.debugger.attachDebugMode(componentInstance);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.controller.registerComponent(componentInstance);
|
|
196
|
+
if (isVisual) {
|
|
197
|
+
this.controller.registerComponentsRecursively(componentInstance);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.logger.logInfo('Slice', `Instance ${componentInstance.sliceId} created`);
|
|
201
|
+
return componentInstance;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.log(error);
|
|
204
|
+
this.logger.logError('Slice', `Error creating instance ${componentName}`, error);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Apply a theme by name.
|
|
211
|
+
* @param {string} themeName
|
|
212
|
+
* @returns {Promise<void>}
|
|
213
|
+
*/
|
|
214
|
+
async setTheme(themeName) {
|
|
215
|
+
await this.stylesManager.themeManager.applyTheme(themeName);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Current theme name.
|
|
220
|
+
* @returns {string|null}
|
|
221
|
+
*/
|
|
222
|
+
get theme() {
|
|
223
|
+
return this.stylesManager.themeManager.currentTheme;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Attach HTML template to a component instance.
|
|
228
|
+
* @param {HTMLElement} componentInstance
|
|
229
|
+
* @returns {void}
|
|
230
|
+
*/
|
|
231
|
+
attachTemplate(componentInstance) {
|
|
232
|
+
this.controller.loadTemplateToComponent(componentInstance);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function loadConfig() {
|
|
237
|
+
try {
|
|
238
|
+
const response = await fetch('/sliceConfig.json'); // 🔹 Express lo sirve desde `src/`
|
|
239
|
+
if (!response.ok) throw new Error('Error loading sliceConfig.json');
|
|
240
|
+
const json = await response.json();
|
|
241
|
+
return json;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.error(`Error loading config file: ${error.message}`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function init() {
|
|
249
|
+
const sliceConfig = await loadConfig();
|
|
250
|
+
if (!sliceConfig) {
|
|
251
|
+
//Display error message in console with colors and alert in english
|
|
252
|
+
console.error('%c⛔️ Error loading Slice configuration ⛔️', 'color: red; font-size: 20px;');
|
|
253
|
+
alert('Error loading Slice configuration');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 1+2. Fetch mode endpoint and bundle config in parallel — both are independent.
|
|
258
|
+
// In production, /slice-env.json returns 404 (catch is expected and normal).
|
|
259
|
+
// bundleConfigJson.production serves as a mode fallback when env endpoint is absent.
|
|
260
|
+
let frameworkClasses = null;
|
|
261
|
+
const [envResult, configResult] = await Promise.all([
|
|
262
|
+
fetch('/slice-env.json', { cache: 'no-store' })
|
|
263
|
+
.then(r => r.ok ? r.json() : null)
|
|
264
|
+
.catch(() => null),
|
|
265
|
+
fetch('/bundles/bundle.config.json', { cache: 'no-store' })
|
|
266
|
+
.then(r => r.ok ? r.json() : null)
|
|
267
|
+
.catch(() => null)
|
|
268
|
+
]);
|
|
269
|
+
const envMode = envResult?.mode ?? null;
|
|
270
|
+
const bundleConfigJson = configResult;
|
|
271
|
+
|
|
272
|
+
// 3. Determine canonical mode: env endpoint takes precedence, then bundle config
|
|
273
|
+
let resolvedMode;
|
|
274
|
+
if (envMode) {
|
|
275
|
+
resolvedMode = envMode;
|
|
276
|
+
} else if (bundleConfigJson?.production) {
|
|
277
|
+
resolvedMode = 'production';
|
|
278
|
+
} else {
|
|
279
|
+
resolvedMode = 'development';
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// 4. Load framework classes.
|
|
283
|
+
// In production the bundler generates slice-bundle.framework.js which
|
|
284
|
+
// sets window.SLICE_FRAMEWORK_CLASSES. In dev mode always use individual
|
|
285
|
+
// imports so the live /Slice/ source is served directly without bundles.
|
|
286
|
+
if (resolvedMode === 'production' && bundleConfigJson?.bundles?.framework?.file) {
|
|
287
|
+
try {
|
|
288
|
+
await import(`/bundles/${bundleConfigJson.bundles.framework.file}`);
|
|
289
|
+
if (window.SLICE_FRAMEWORK_CLASSES) {
|
|
290
|
+
frameworkClasses = window.SLICE_FRAMEWORK_CLASSES;
|
|
291
|
+
}
|
|
292
|
+
} catch (e) {
|
|
293
|
+
// framework bundle failed — fall through to individual imports
|
|
294
|
+
console.error('[Slice.js] framework bundle import failed:', e?.message || e);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (!frameworkClasses) {
|
|
299
|
+
try {
|
|
300
|
+
const imports = await Promise.all([
|
|
301
|
+
import('./Components/Structural/Controller/Controller.js'),
|
|
302
|
+
import('./Components/Structural/StylesManager/StylesManager.js')
|
|
303
|
+
]);
|
|
304
|
+
frameworkClasses = {
|
|
305
|
+
Controller: imports[0].default,
|
|
306
|
+
StylesManager: imports[1].default
|
|
307
|
+
};
|
|
308
|
+
} catch (e) {
|
|
309
|
+
console.error('[Slice.js] individual imports fallback failed:', e?.message || e);
|
|
310
|
+
throw e;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 5. Create Slice instance and set resolved mode
|
|
315
|
+
window.slice = new Slice(sliceConfig, frameworkClasses);
|
|
316
|
+
window.slice._mode = resolvedMode;
|
|
317
|
+
|
|
318
|
+
const createBundlingInitError = (step, error) => {
|
|
319
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
320
|
+
return new Error(`Bundling V2 initialization failed (${step}): ${detail}`, { cause: error });
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// Initialize bundles before building components.
|
|
324
|
+
// Only in production — dev mode loads each component individually from source.
|
|
325
|
+
// bundleConfigJson was already fetched above (step 2); reuse it.
|
|
326
|
+
if (resolvedMode === 'production' && bundleConfigJson) {
|
|
327
|
+
window.slice.controller.bundleConfig = bundleConfigJson;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (resolvedMode === 'production' && window.slice.controller.bundleConfig) {
|
|
331
|
+
const config = window.slice.controller.bundleConfig;
|
|
332
|
+
const criticalFile = config?.bundles?.critical?.file;
|
|
333
|
+
if (criticalFile) {
|
|
334
|
+
try {
|
|
335
|
+
await window.slice.controller.loadBundle('critical');
|
|
336
|
+
} catch (error) {
|
|
337
|
+
throw createBundlingInitError(`critical bundle "${criticalFile}"`, error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const routeBundles = config?.routeBundles || {};
|
|
342
|
+
const initialPath = window.location.pathname || '/';
|
|
343
|
+
const bundlesForRoute = routeBundles[initialPath] || [];
|
|
344
|
+
|
|
345
|
+
const loadRouteBundles = async () => {
|
|
346
|
+
for (const bundleName of bundlesForRoute) {
|
|
347
|
+
if (bundleName === 'critical') continue;
|
|
348
|
+
const bundleInfo = config?.bundles?.routes?.[bundleName];
|
|
349
|
+
if (!bundleInfo?.file) continue;
|
|
350
|
+
await window.slice.controller.loadBundle(bundleName);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const preloadRouteBundles = () => {
|
|
355
|
+
loadRouteBundles().catch((error) => {
|
|
356
|
+
const bundlingError = createBundlingInitError(
|
|
357
|
+
`idle route preload "${initialPath}"`,
|
|
358
|
+
error
|
|
359
|
+
);
|
|
360
|
+
queueMicrotask(() => {
|
|
361
|
+
throw bundlingError;
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
if (typeof requestIdleCallback === 'function') {
|
|
367
|
+
requestIdleCallback(() => preloadRouteBundles());
|
|
368
|
+
} else {
|
|
369
|
+
setTimeout(() => preloadRouteBundles(), 0);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
slice.paths.structuralComponentFolderPath = '/Slice/Components/Structural';
|
|
374
|
+
|
|
375
|
+
if (sliceConfig.logger.enabled) {
|
|
376
|
+
const LoggerModule = window.slice.frameworkClasses?.Logger
|
|
377
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Logger/Logger.js`);
|
|
378
|
+
window.slice.logger = new LoggerModule();
|
|
379
|
+
} else {
|
|
380
|
+
window.slice.logger = {
|
|
381
|
+
logError: () => {},
|
|
382
|
+
logWarning: () => {},
|
|
383
|
+
logInfo: () => {},
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (sliceConfig.debugger.enabled) {
|
|
388
|
+
const DebuggerModule = window.slice.frameworkClasses?.Debugger
|
|
389
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Debugger/Debugger.js`);
|
|
390
|
+
window.slice.debugger = new DebuggerModule();
|
|
391
|
+
await window.slice.debugger.enableDebugMode();
|
|
392
|
+
document.body.appendChild(window.slice.debugger);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (sliceConfig.events?.ui?.enabled) {
|
|
396
|
+
const EventsDebuggerModule = window.slice.frameworkClasses?.EventManagerDebugger
|
|
397
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/EventManager/EventManagerDebugger.js`);
|
|
398
|
+
window.slice.eventsDebugger = new EventsDebuggerModule();
|
|
399
|
+
await window.slice.eventsDebugger.init();
|
|
400
|
+
document.body.appendChild(window.slice.eventsDebugger);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (sliceConfig.context?.ui?.enabled) {
|
|
404
|
+
const ContextDebuggerModule = window.slice.frameworkClasses?.ContextManagerDebugger
|
|
405
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManagerDebugger.js`);
|
|
406
|
+
window.slice.contextDebugger = new ContextDebuggerModule();
|
|
407
|
+
await window.slice.contextDebugger.init();
|
|
408
|
+
document.body.appendChild(window.slice.contextDebugger);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (sliceConfig.events?.enabled) {
|
|
412
|
+
const EventManagerModule = window.slice.frameworkClasses?.EventManager
|
|
413
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/EventManager/EventManager.js`);
|
|
414
|
+
window.slice.events = new EventManagerModule();
|
|
415
|
+
if (typeof window.slice.events.init === 'function') {
|
|
416
|
+
await window.slice.events.init();
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
window.slice.events = {
|
|
420
|
+
subscribe: () => null,
|
|
421
|
+
subscribeOnce: () => null,
|
|
422
|
+
unsubscribe: () => false,
|
|
423
|
+
emit: () => {},
|
|
424
|
+
bind: () => ({
|
|
425
|
+
subscribe: () => null,
|
|
426
|
+
subscribeOnce: () => null,
|
|
427
|
+
emit: () => {},
|
|
428
|
+
}),
|
|
429
|
+
cleanupComponent: () => 0,
|
|
430
|
+
hasSubscribers: () => false,
|
|
431
|
+
subscriberCount: () => 0,
|
|
432
|
+
clear: () => {},
|
|
433
|
+
};
|
|
434
|
+
window.slice.logger.logError('Slice', 'EventManager disabled');
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (sliceConfig.context?.enabled) {
|
|
438
|
+
const ContextManagerModule = window.slice.frameworkClasses?.ContextManager
|
|
439
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/ContextManager/ContextManager.js`);
|
|
440
|
+
window.slice.context = new ContextManagerModule();
|
|
441
|
+
if (typeof window.slice.context.init === 'function') {
|
|
442
|
+
await window.slice.context.init();
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
window.slice.context = {
|
|
446
|
+
create: () => false,
|
|
447
|
+
getState: () => null,
|
|
448
|
+
setState: () => {},
|
|
449
|
+
watch: () => null,
|
|
450
|
+
has: () => false,
|
|
451
|
+
destroy: () => false,
|
|
452
|
+
list: () => [],
|
|
453
|
+
};
|
|
454
|
+
window.slice.logger.logError('Slice', 'ContextManager disabled');
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (sliceConfig.loading.enabled) {
|
|
458
|
+
const loading = await window.slice.build('Loading', {});
|
|
459
|
+
window.slice.loading = loading;
|
|
460
|
+
if (typeof loading?.start === 'function') {
|
|
461
|
+
loading.start();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const stylesInitPromise = window.slice.stylesManager.init();
|
|
466
|
+
const routesModulePromise = import(slice.paths.routesFile);
|
|
467
|
+
|
|
468
|
+
if (sliceConfig.events?.ui?.shortcut || sliceConfig.context?.ui?.shortcut) {
|
|
469
|
+
const normalize = (value) => (typeof value === 'string' ? value.toLowerCase() : '');
|
|
470
|
+
const toKey = (event) => {
|
|
471
|
+
const parts = [];
|
|
472
|
+
if (event.ctrlKey) parts.push('ctrl');
|
|
473
|
+
if (event.shiftKey) parts.push('shift');
|
|
474
|
+
if (event.altKey) parts.push('alt');
|
|
475
|
+
if (event.metaKey) parts.push('meta');
|
|
476
|
+
const key = event.key?.toLowerCase();
|
|
477
|
+
if (key && !['control', 'shift', 'alt', 'meta'].includes(key)) {
|
|
478
|
+
parts.push(key);
|
|
479
|
+
}
|
|
480
|
+
return parts.join('+');
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const handlers = {
|
|
484
|
+
[normalize(sliceConfig.events?.ui?.shortcut)]: () => window.slice.eventsDebugger?.toggle?.(),
|
|
485
|
+
[normalize(sliceConfig.context?.ui?.shortcut)]: () => window.slice.contextDebugger?.toggle?.(),
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
document.addEventListener('keydown', (event) => {
|
|
489
|
+
const key = toKey(event);
|
|
490
|
+
if (!key || !handlers[key]) return;
|
|
491
|
+
event.preventDefault();
|
|
492
|
+
handlers[key]();
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const [, routesModule] = await Promise.all([stylesInitPromise, routesModulePromise]);
|
|
497
|
+
const routes = routesModule.default;
|
|
498
|
+
const RouterModule = window.slice.frameworkClasses?.Router
|
|
499
|
+
|| await window.slice.getClass(`${slice.paths.structuralComponentFolderPath}/Router/Router.js`);
|
|
500
|
+
window.slice.router = new RouterModule(routes);
|
|
501
|
+
await window.slice.router.init();
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
await init();
|