slicejs-web-framework 1.0.6 → 1.0.9
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/Router/Router.js +59 -33
- package/api/index.js +99 -0
- package/package.json +1 -1
- package/src/App/index.html +22 -0
- package/src/App/index.js +63 -0
- package/src/App/style.css +40 -0
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.css +16 -0
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.html +22 -0
- package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.js +102 -0
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.css +15 -0
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.html +38 -0
- package/src/Components/AppComponents/CardDocumentation/CardDocumentation.js +113 -0
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.css +21 -0
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.html +35 -0
- package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.js +103 -0
- package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.css +130 -0
- package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.html +4 -0
- package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.js +263 -0
- package/src/Components/AppComponents/Documentation/Documentation.css +0 -0
- package/src/Components/AppComponents/Documentation/Documentation.html +30 -0
- package/src/Components/AppComponents/Documentation/Documentation.js +75 -0
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.css +62 -0
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.html +0 -0
- package/src/Components/AppComponents/DocumentationPage/DocumentationPage.js +283 -0
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.css +41 -0
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.html +95 -0
- package/src/Components/AppComponents/InputDocumentation/InputDocumentation.js +315 -0
- package/src/Components/AppComponents/LandingMenu/LandingMenu.css +108 -0
- package/src/Components/AppComponents/LandingMenu/LandingMenu.html +16 -0
- package/src/Components/AppComponents/LandingMenu/LandingMenu.js +33 -0
- package/src/Components/AppComponents/LandingPage/LandingPage.css +14 -0
- package/src/Components/AppComponents/LandingPage/LandingPage.html +0 -0
- package/src/Components/AppComponents/LandingPage/LandingPage.js +53 -0
- package/src/Components/AppComponents/MainMenu/MainMenu.css +80 -0
- package/src/Components/AppComponents/MainMenu/MainMenu.html +39 -0
- package/src/Components/AppComponents/MainMenu/MainMenu.js +42 -0
- package/src/Components/AppComponents/MyLayout/MyLayout.css +0 -0
- package/src/Components/AppComponents/MyLayout/MyLayout.html +0 -0
- package/src/Components/AppComponents/MyLayout/MyLayout.js +13 -0
- package/src/Components/AppComponents/MyNavigation/MyNavigation.css +49 -0
- package/src/Components/AppComponents/MyNavigation/MyNavigation.html +1 -0
- package/src/Components/AppComponents/MyNavigation/MyNavigation.js +60 -0
- package/src/Components/AppComponents/Playground/Playground.css +12 -0
- package/src/Components/AppComponents/Playground/Playground.html +0 -0
- package/src/Components/AppComponents/Playground/Playground.js +126 -0
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.css +89 -0
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.html +108 -0
- package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.js +177 -0
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.css +104 -0
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.html +12 -0
- package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.js +74 -0
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.css +21 -0
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.html +35 -0
- package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.js +103 -0
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.css +122 -0
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.html +70 -0
- package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.js +86 -0
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.css +23 -0
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.html +6 -0
- package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.js +129 -0
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.css +0 -0
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.html +7 -0
- package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.js +15 -0
- package/src/Components/Service/FetchManager/FetchManager.js +133 -0
- package/src/Components/Service/IndexedDbManager/IndexedDbManager.js +141 -0
- package/src/Components/Service/Link/Link.js +26 -0
- package/src/Components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
- package/src/Components/Service/Translator/Translator.js +45 -0
- package/src/Components/Service/Translator/messages.json +58 -0
- package/src/Components/Visual/Button/Button.css +47 -0
- package/src/Components/Visual/Button/Button.html +5 -0
- package/src/Components/Visual/Button/Button.js +70 -0
- package/src/Components/Visual/Card/Card.css +68 -0
- package/src/Components/Visual/Card/Card.html +7 -0
- package/src/Components/Visual/Card/Card.js +107 -0
- package/src/Components/Visual/Checkbox/Checkbox.css +87 -0
- package/src/Components/Visual/Checkbox/Checkbox.html +8 -0
- package/src/Components/Visual/Checkbox/Checkbox.js +86 -0
- package/src/Components/Visual/Details/Details.css +70 -0
- package/src/Components/Visual/Details/Details.html +9 -0
- package/src/Components/Visual/Details/Details.js +76 -0
- package/src/Components/Visual/DropDown/DropDown.css +60 -0
- package/src/Components/Visual/DropDown/DropDown.html +5 -0
- package/src/Components/Visual/DropDown/DropDown.js +63 -0
- package/src/Components/Visual/Grid/Grid.css +7 -0
- package/src/Components/Visual/Grid/Grid.html +1 -0
- package/src/Components/Visual/Grid/Grid.js +57 -0
- package/src/Components/Visual/Icon/Icon.css +510 -0
- package/src/Components/Visual/Icon/Icon.html +1 -0
- package/src/Components/Visual/Icon/Icon.js +89 -0
- package/src/Components/Visual/Icon/slc.eot +0 -0
- package/src/Components/Visual/Icon/slc.json +555 -0
- package/src/Components/Visual/Icon/slc.styl +507 -0
- package/src/Components/Visual/Icon/slc.svg +1485 -0
- package/src/Components/Visual/Icon/slc.symbol.svg +1059 -0
- package/src/Components/Visual/Icon/slc.ttf +0 -0
- package/src/Components/Visual/Icon/slc.woff +0 -0
- package/src/Components/Visual/Icon/slc.woff2 +0 -0
- package/src/Components/Visual/Input/Input.css +91 -0
- package/src/Components/Visual/Input/Input.html +4 -0
- package/src/Components/Visual/Input/Input.js +215 -0
- package/src/Components/Visual/Layout/Layout.css +0 -0
- package/src/Components/Visual/Layout/Layout.html +0 -0
- package/src/Components/Visual/Layout/Layout.js +49 -0
- package/src/Components/Visual/Loading/Loading.css +56 -0
- package/src/Components/Visual/Loading/Loading.html +83 -0
- package/src/Components/Visual/Loading/Loading.js +38 -0
- package/src/Components/Visual/MultiRoute/MultiRoute.js +93 -0
- package/src/Components/Visual/Navbar/Navbar.css +115 -0
- package/src/Components/Visual/Navbar/Navbar.html +44 -0
- package/src/Components/Visual/Navbar/Navbar.js +141 -0
- package/src/Components/Visual/NotFound/NotFound.css +117 -0
- package/src/Components/Visual/NotFound/NotFound.html +24 -0
- package/src/Components/Visual/NotFound/NotFound.js +16 -0
- package/src/Components/Visual/Route/Route.js +93 -0
- package/src/Components/Visual/Select/Select.css +84 -0
- package/src/Components/Visual/Select/Select.html +8 -0
- package/src/Components/Visual/Select/Select.js +195 -0
- package/src/Components/Visual/Switch/Switch.css +76 -0
- package/src/Components/Visual/Switch/Switch.html +8 -0
- package/src/Components/Visual/Switch/Switch.js +102 -0
- package/src/Components/Visual/TreeItem/TreeItem.css +36 -0
- package/src/Components/Visual/TreeItem/TreeItem.html +1 -0
- package/src/Components/Visual/TreeItem/TreeItem.js +126 -0
- package/src/Components/Visual/TreeView/TreeView.css +8 -0
- package/src/Components/Visual/TreeView/TreeView.html +1 -0
- package/src/Components/Visual/TreeView/TreeView.js +48 -0
- package/src/Components/components.js +45 -0
- package/src/Styles/sliceStyles.css +34 -0
- package/src/Themes/Dark.css +42 -0
- package/src/Themes/Light.css +31 -0
- package/src/Themes/Slice.css +47 -0
- package/src/images/Slice.js-logo.png +0 -0
- package/src/images/favicon.ico +0 -0
- package/src/images/im2/Slice.js-logo.png +0 -0
- package/src/routes.js +77 -0
- package/src/sliceConfig.json +58 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
export default class Router {
|
|
3
2
|
constructor(routes) {
|
|
4
3
|
this.routes = routes;
|
|
@@ -11,16 +10,30 @@ export default class Router {
|
|
|
11
10
|
window.addEventListener('popstate', this.onRouteChange.bind(this));
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
createPathToRouteMap(routes, basePath = '') {
|
|
13
|
+
createPathToRouteMap(routes, basePath = '', parentRoute = null) {
|
|
15
14
|
const pathToRouteMap = new Map();
|
|
16
15
|
|
|
17
16
|
for (const route of routes) {
|
|
18
|
-
const fullPath = `${basePath}${route.path}`.replace(/\/+/g, '/');
|
|
19
|
-
|
|
17
|
+
const fullPath = `${basePath}${route.path}`.replace(/\/+/g, '/');
|
|
18
|
+
|
|
19
|
+
// Guardar la referencia a la ruta padre
|
|
20
|
+
const routeWithParent = {
|
|
21
|
+
...route,
|
|
22
|
+
fullPath,
|
|
23
|
+
parentPath: parentRoute ? parentRoute.fullPath : null,
|
|
24
|
+
parentRoute: parentRoute
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
pathToRouteMap.set(fullPath, routeWithParent);
|
|
20
28
|
|
|
21
29
|
// Si tiene rutas secundarias, también agregarlas al mapa
|
|
22
30
|
if (route.children) {
|
|
23
|
-
const childPathToRouteMap = this.createPathToRouteMap(
|
|
31
|
+
const childPathToRouteMap = this.createPathToRouteMap(
|
|
32
|
+
route.children,
|
|
33
|
+
fullPath,
|
|
34
|
+
routeWithParent // Pasar la ruta actual como padre
|
|
35
|
+
);
|
|
36
|
+
|
|
24
37
|
for (const [childPath, childRoute] of childPathToRouteMap.entries()) {
|
|
25
38
|
pathToRouteMap.set(childPath, childRoute);
|
|
26
39
|
}
|
|
@@ -28,7 +41,7 @@ export default class Router {
|
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
return pathToRouteMap;
|
|
31
|
-
|
|
44
|
+
}
|
|
32
45
|
|
|
33
46
|
async renderRoutesComponentsInPage() {
|
|
34
47
|
const routeContainers = document.querySelectorAll('slice-route, slice-multi-route');
|
|
@@ -41,7 +54,6 @@ export default class Router {
|
|
|
41
54
|
routerContainersFlag = true;
|
|
42
55
|
}
|
|
43
56
|
}
|
|
44
|
-
|
|
45
57
|
return routerContainersFlag;
|
|
46
58
|
}
|
|
47
59
|
|
|
@@ -66,7 +78,12 @@ export default class Router {
|
|
|
66
78
|
|
|
67
79
|
async handleRoute(route, params) {
|
|
68
80
|
const targetElement = document.querySelector('#app');
|
|
69
|
-
|
|
81
|
+
|
|
82
|
+
// Si tenemos una ruta con parentRoute, usamos el componente del padre
|
|
83
|
+
const componentName = route.parentRoute ? route.parentRoute.component : route.component;
|
|
84
|
+
const sliceId = `route-${componentName}`;
|
|
85
|
+
|
|
86
|
+
const existingComponent = slice.controller.getComponent(sliceId);
|
|
70
87
|
|
|
71
88
|
if (slice.loading) {
|
|
72
89
|
slice.loading.start();
|
|
@@ -80,9 +97,9 @@ export default class Router {
|
|
|
80
97
|
}
|
|
81
98
|
targetElement.appendChild(existingComponent);
|
|
82
99
|
} else {
|
|
83
|
-
const component = await slice.build(
|
|
100
|
+
const component = await slice.build(componentName, {
|
|
84
101
|
params,
|
|
85
|
-
sliceId:
|
|
102
|
+
sliceId: sliceId,
|
|
86
103
|
});
|
|
87
104
|
targetElement.innerHTML = '';
|
|
88
105
|
targetElement.appendChild(component);
|
|
@@ -100,7 +117,6 @@ export default class Router {
|
|
|
100
117
|
const { route, params } = this.matchRoute(path);
|
|
101
118
|
|
|
102
119
|
await this.handleRoute(route, params);
|
|
103
|
-
|
|
104
120
|
await this.renderRoutesComponentsInPage();
|
|
105
121
|
}
|
|
106
122
|
|
|
@@ -108,10 +124,19 @@ export default class Router {
|
|
|
108
124
|
// 1. Buscar coincidencia exacta en el mapa
|
|
109
125
|
const exactMatch = this.pathToRouteMap.get(path);
|
|
110
126
|
if (exactMatch) {
|
|
127
|
+
// Si es una ruta hija y tiene un padre definido, devolvemos el padre en su lugar
|
|
128
|
+
if (exactMatch.parentRoute) {
|
|
129
|
+
// Mantenemos la información de parámetros que viene de la ruta actual
|
|
130
|
+
return {
|
|
131
|
+
route: exactMatch.parentRoute,
|
|
132
|
+
params: {},
|
|
133
|
+
childRoute: exactMatch // Guardamos la referencia a la ruta hija original
|
|
134
|
+
};
|
|
135
|
+
}
|
|
111
136
|
return { route: exactMatch, params: {} };
|
|
112
137
|
}
|
|
113
138
|
|
|
114
|
-
// 2. Buscar coincidencias en rutas con parámetros
|
|
139
|
+
// 2. Buscar coincidencias en rutas con parámetros
|
|
115
140
|
for (const [routePattern, route] of this.pathToRouteMap.entries()) {
|
|
116
141
|
if (routePattern.includes('${')) {
|
|
117
142
|
const { regex, paramNames } = this.compilePathPattern(routePattern);
|
|
@@ -119,34 +144,35 @@ export default class Router {
|
|
|
119
144
|
if (match) {
|
|
120
145
|
const params = {};
|
|
121
146
|
paramNames.forEach((name, i) => {
|
|
122
|
-
params[name] = match[i + 1];
|
|
147
|
+
params[name] = match[i + 1];
|
|
123
148
|
});
|
|
149
|
+
|
|
150
|
+
// Si es una ruta hija, devolvemos el padre con los parámetros
|
|
151
|
+
if (route.parentRoute) {
|
|
152
|
+
return {
|
|
153
|
+
route: route.parentRoute,
|
|
154
|
+
params: params,
|
|
155
|
+
childRoute: route
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
124
159
|
return { route, params };
|
|
125
160
|
}
|
|
126
161
|
}
|
|
127
162
|
}
|
|
128
163
|
|
|
129
|
-
// 3. Si no hay coincidencias, retornar la ruta 404
|
|
164
|
+
// 3. Si no hay coincidencias, retornar la ruta 404
|
|
130
165
|
const notFoundRoute = this.pathToRouteMap.get('/404');
|
|
131
166
|
return { route: notFoundRoute, params: {} };
|
|
132
167
|
}
|
|
133
168
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const regexPattern = '^' + pattern.replace(/\$\{([^}]+)\}/g, (_, paramName) => {
|
|
145
|
-
paramNames.push(paramName);
|
|
146
|
-
return '([^/]+)';
|
|
147
|
-
}) + '$';
|
|
148
|
-
|
|
149
|
-
return { regex: new RegExp(regexPattern), paramNames };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}
|
|
169
|
+
compilePathPattern(pattern) {
|
|
170
|
+
const paramNames = [];
|
|
171
|
+
const regexPattern = '^' + pattern.replace(/\$\{([^}]+)\}/g, (_, paramName) => {
|
|
172
|
+
paramNames.push(paramName);
|
|
173
|
+
return '([^/]+)';
|
|
174
|
+
}) + '$';
|
|
175
|
+
|
|
176
|
+
return { regex: new RegExp(regexPattern), paramNames };
|
|
177
|
+
}
|
|
178
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
import sliceConfig from '../src/sliceConfig.json' with { type: 'json' };
|
|
10
|
+
|
|
11
|
+
let server;
|
|
12
|
+
|
|
13
|
+
const app = express();
|
|
14
|
+
const PORT = 3001;
|
|
15
|
+
|
|
16
|
+
const isProduction = sliceConfig.production === true;
|
|
17
|
+
const folderDeployed = isProduction ? 'dist' : 'src';
|
|
18
|
+
|
|
19
|
+
// Servir archivos estáticos desde la carpeta 'Slice'
|
|
20
|
+
app.use('/Slice/', express.static(path.join(__dirname, '..', 'node_modules', 'slicejs-web-framework', 'Slice')));
|
|
21
|
+
// Servir archivos estáticos desde la carpeta 'App'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
app.get('/testing1', (req, res) => {
|
|
28
|
+
res.send(` Actual route in server: __dirname: ${__dirname} __filename: ${__filename} - checking if file exists: ${path.join(__dirname, '..', 'src','App', 'index.html')}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
app.use(express.static(path.join(__dirname,'..', folderDeployed)));
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
app.get('/testing2', (req, res) => {
|
|
36
|
+
res.send(` Actual route in server: __dirname: ${__dirname} __filename: ${__filename} - checking if file exists: ${path.join(__dirname, '..', 'src','App', 'index.html')}`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if(isProduction){
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// Ruta para servir el index.html desde la carpeta 'App'
|
|
45
|
+
app.get('*', (req, res) => {
|
|
46
|
+
const filePath = path.join(__dirname, '..', 'src','App', 'index.html');
|
|
47
|
+
res.sendFile(filePath);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function startServer() {
|
|
51
|
+
server = app.listen(PORT, () => {
|
|
52
|
+
showMenu();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function showMenu() {
|
|
57
|
+
|
|
58
|
+
console.clear();
|
|
59
|
+
console.log("\n=================================");
|
|
60
|
+
console.log(" SLICE SERVER MENU ");
|
|
61
|
+
console.log("=================================\n");
|
|
62
|
+
|
|
63
|
+
const url = `http://localhost:${PORT}`;
|
|
64
|
+
console.log(`Server is running on port ${PORT}, ${url}\n`);
|
|
65
|
+
|
|
66
|
+
while (true) {
|
|
67
|
+
const { action } = await inquirer.prompt([
|
|
68
|
+
{
|
|
69
|
+
type: 'list',
|
|
70
|
+
name: 'action',
|
|
71
|
+
message: 'Select an option:',
|
|
72
|
+
choices: ['Restart Server', 'Stop Server (Exit)']
|
|
73
|
+
}
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
if (action === 'Stop Server (Exit)') {
|
|
77
|
+
console.log('\nShutting down server...');
|
|
78
|
+
server.close(() => {
|
|
79
|
+
console.log('Server stopped.');
|
|
80
|
+
process.exit(0);
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
} else if (action === 'Restart Server') {
|
|
84
|
+
console.log('\nRestarting server...');
|
|
85
|
+
server.close(() => {
|
|
86
|
+
console.log('Server stopped. Restarting...');
|
|
87
|
+
startServer();
|
|
88
|
+
});
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
startServer();
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
export default app;
|
|
98
|
+
|
|
99
|
+
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Slice - Documentation</title>
|
|
7
|
+
<link rel="icon" type="image/x-icon" href="/../../images/favicon.ico" />
|
|
8
|
+
<link rel="stylesheet" type="text/css" href="/App/style.css" />
|
|
9
|
+
|
|
10
|
+
<!-- Prism -->
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
<!-- Eliminar Prism despues-->
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
<div id="app">
|
|
19
|
+
<script src="/App/index.js" type="module"></script>
|
|
20
|
+
</div>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
package/src/App/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Slice from '/Slice/Slice.js';
|
|
2
|
+
|
|
3
|
+
const CACHE_NAME = 'slice-cache-v1';
|
|
4
|
+
const urlsToCache = [
|
|
5
|
+
// Añade aquí las rutas de los archivos que deseas almacenar
|
|
6
|
+
'./Slice/Slice.js',
|
|
7
|
+
'./Slice/Components/Structural/Logger/Logger.js',
|
|
8
|
+
'./Slice/Components/Structural/Debugger/Debugger.js',
|
|
9
|
+
'./Slice/Components/Structural/Router/Router.js',
|
|
10
|
+
'./Slice/Components/Structural/Router/routes.js',
|
|
11
|
+
'./Slice/Components/Structural/Controller/Controller.js',
|
|
12
|
+
'./Slice/Components/Structural/StylesManager/StylesManager.js',
|
|
13
|
+
'./Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
self.addEventListener('install', (event) => {
|
|
17
|
+
event.waitUntil(
|
|
18
|
+
caches.open(CACHE_NAME).then((cache) => {
|
|
19
|
+
console.log('Opened cache');
|
|
20
|
+
return cache.addAll(urlsToCache);
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
self.addEventListener('fetch', (event) => {
|
|
26
|
+
event.respondWith(
|
|
27
|
+
caches.match(event.request).then((response) => {
|
|
28
|
+
if (response) {
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
return fetch(event.request);
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
self.addEventListener('activate', (event) => {
|
|
37
|
+
const cacheWhitelist = [CACHE_NAME];
|
|
38
|
+
|
|
39
|
+
event.waitUntil(
|
|
40
|
+
caches.keys().then((cacheNames) => {
|
|
41
|
+
return Promise.all(
|
|
42
|
+
cacheNames.map((cacheName) => {
|
|
43
|
+
if (cacheWhitelist.indexOf(cacheName) === -1) {
|
|
44
|
+
return caches.delete(cacheName);
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if ('serviceWorker' in navigator) {
|
|
53
|
+
window.addEventListener('load', () => {
|
|
54
|
+
navigator.serviceWorker
|
|
55
|
+
.register('/service-worker.js')
|
|
56
|
+
.then((registration) => {
|
|
57
|
+
console.log('Service Worker registrado con éxito:', registration);
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
console.log('Error al registrar el Service Worker:', error);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* :root {
|
|
2
|
+
--docs-width: 64%;
|
|
3
|
+
}
|
|
4
|
+
slice-layout {
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
p {
|
|
10
|
+
text-align: justify;
|
|
11
|
+
}
|
|
12
|
+
h1 {
|
|
13
|
+
padding-top: 10px;
|
|
14
|
+
padding-bottom: 10px;
|
|
15
|
+
border-bottom: 1px solid var(--secondary-background-color);
|
|
16
|
+
}
|
|
17
|
+
h2 {
|
|
18
|
+
padding-top: 10px;
|
|
19
|
+
}
|
|
20
|
+
.grid-container {
|
|
21
|
+
overflow-x: auto;
|
|
22
|
+
}
|
|
23
|
+
@media only screen and (max-width: 770px) {
|
|
24
|
+
:root {
|
|
25
|
+
--docs-width: 100%;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
* {
|
|
29
|
+
font-family: var(--font-family);
|
|
30
|
+
}
|
|
31
|
+
.docs_container {
|
|
32
|
+
color: var(--font-primary-color);
|
|
33
|
+
margin-top: 100px;
|
|
34
|
+
overflow-y: scroll;
|
|
35
|
+
overflow-x: hidden;
|
|
36
|
+
width: var(--docs-width);
|
|
37
|
+
padding-left: 10px;
|
|
38
|
+
padding-right: 10px;
|
|
39
|
+
padding-bottom: 25px;
|
|
40
|
+
} */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.buttonsGrid {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
.buttons {
|
|
5
|
+
width: 100%;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: row;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
align-items: center;
|
|
10
|
+
}
|
|
11
|
+
.buttonsContainer {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
justify-content: space-evenly;
|
|
15
|
+
/* width: 100%; */
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h1 id="sliceButton">Slice Button</h1>
|
|
2
|
+
<div class="myButton">
|
|
3
|
+
<p>
|
|
4
|
+
To build a simple Slice Button you only need to use the "slice.build"
|
|
5
|
+
method, just like that you have a Slice Button that you can customize with a
|
|
6
|
+
value prop.
|
|
7
|
+
</p>
|
|
8
|
+
</div>
|
|
9
|
+
<div class="colorButton">
|
|
10
|
+
<h2 id="customization">Customization</h2>
|
|
11
|
+
<p>
|
|
12
|
+
You can also cutomize your Slice Button specifying it's background color
|
|
13
|
+
with "customColor.button" and it's font color with "customColor.label".
|
|
14
|
+
</p>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="onClick">
|
|
17
|
+
<h2 id="onClickCallback">onClickCallback</h2>
|
|
18
|
+
<p>
|
|
19
|
+
At last but not least you can add a function to your button with the prop
|
|
20
|
+
"onClickCallback".
|
|
21
|
+
</p>
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export default class ButtonDocumentation extends HTMLElement {
|
|
2
|
+
constructor(props) {
|
|
3
|
+
super();
|
|
4
|
+
slice.attachTemplate(this);
|
|
5
|
+
|
|
6
|
+
slice.controller.setComponentProps(this, props);
|
|
7
|
+
this.debuggerProps = [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async init() {
|
|
11
|
+
const grid = await slice.build('Grid', { columns: 2, rows: 1 });
|
|
12
|
+
grid.classList.add('buttonsGrid');
|
|
13
|
+
|
|
14
|
+
const simpleButton = await this.createButton(null, {});
|
|
15
|
+
const myButton = await this.createButton(
|
|
16
|
+
null,
|
|
17
|
+
{
|
|
18
|
+
value: 'Slice Button',
|
|
19
|
+
},
|
|
20
|
+
`{
|
|
21
|
+
value: "Slice Button",
|
|
22
|
+
}`
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (window.screen.width <= 770) {
|
|
26
|
+
grid.columns = 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await grid.setItem(simpleButton);
|
|
30
|
+
await grid.setItem(myButton);
|
|
31
|
+
|
|
32
|
+
this.querySelector('.myButton').appendChild(grid);
|
|
33
|
+
|
|
34
|
+
await this.createButton(
|
|
35
|
+
this.querySelector('.colorButton'),
|
|
36
|
+
{
|
|
37
|
+
value: 'Color Button',
|
|
38
|
+
customColor: { label: 'black', button: 'red' },
|
|
39
|
+
},
|
|
40
|
+
`{
|
|
41
|
+
value: "Color Button",
|
|
42
|
+
customColor: { label: "black", button: "red" },
|
|
43
|
+
}`
|
|
44
|
+
);
|
|
45
|
+
const clickButton = await this.createButton(
|
|
46
|
+
this.querySelector('.onClick'),
|
|
47
|
+
{
|
|
48
|
+
value: 'Click',
|
|
49
|
+
onClickCallback: () => {
|
|
50
|
+
if (clickButton.value === 'Click') {
|
|
51
|
+
clickButton.value = 'Clicked';
|
|
52
|
+
} else {
|
|
53
|
+
clickButton.value = 'Click';
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
`{
|
|
58
|
+
value: "Click",
|
|
59
|
+
onClickCallback: () => {
|
|
60
|
+
if (myButton.value === "Click") {
|
|
61
|
+
myButton.value = "Clicked";
|
|
62
|
+
} else {
|
|
63
|
+
myButton.value = "Click";
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async createButton(appendTo, buttonProps, codeProps) {
|
|
71
|
+
if (!codeProps) {
|
|
72
|
+
codeProps = '{}';
|
|
73
|
+
}
|
|
74
|
+
const myButton = await slice.build('Button', buttonProps);
|
|
75
|
+
|
|
76
|
+
const componentCode = await slice.build('CodeVisualizer', {
|
|
77
|
+
value: `const myButton = await slice.build("Button", ${codeProps});
|
|
78
|
+
|
|
79
|
+
`,
|
|
80
|
+
language: 'javascript',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const div = document.createElement('div');
|
|
84
|
+
const buttonDiv = document.createElement('div');
|
|
85
|
+
buttonDiv.classList.add('buttons');
|
|
86
|
+
buttonDiv.appendChild(myButton);
|
|
87
|
+
div.classList.add('buttonsContainer');
|
|
88
|
+
div.appendChild(buttonDiv);
|
|
89
|
+
div.appendChild(componentCode);
|
|
90
|
+
|
|
91
|
+
if (appendTo) {
|
|
92
|
+
appendTo.appendChild(div);
|
|
93
|
+
}
|
|
94
|
+
if (buttonProps.onClickCallback) {
|
|
95
|
+
return myButton;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return div;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
customElements.define('slice-buttondocumentation', ButtonDocumentation);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--cards-padding: 30%;
|
|
3
|
+
}
|
|
4
|
+
.cards {
|
|
5
|
+
padding-left: var(--cards-padding);
|
|
6
|
+
padding-right: var(--cards-padding);
|
|
7
|
+
margin-top: 50px;
|
|
8
|
+
margin-bottom: 50px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@media only screen and (max-width: 770px) {
|
|
12
|
+
:root {
|
|
13
|
+
--cards-padding: 20px;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<h1 id="sliceCard">Slice Card</h1>
|
|
2
|
+
<div class="sliceCard">
|
|
3
|
+
<p>
|
|
4
|
+
When building a "Card" component, by default it's created with the Slice
|
|
5
|
+
logo, and with a default title and text.
|
|
6
|
+
</p>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="myCard">
|
|
9
|
+
<h2 id="myCard">Title and Text</h2>
|
|
10
|
+
<p>
|
|
11
|
+
To build your own Slice Card with your information it's as simple as just
|
|
12
|
+
adding "title" and "text" props to your component.
|
|
13
|
+
</p>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="cardClick">
|
|
16
|
+
<h2 id="cardClick">Click Event | "isOpen" prop</h2>
|
|
17
|
+
<p>
|
|
18
|
+
The Slice Card component has an click eventListener. While the card is
|
|
19
|
+
uncovered and shows the information inside, it's cover can be clicked to
|
|
20
|
+
keep open. Changing it's "isOpen" prop to true. That same eventListener can
|
|
21
|
+
change it back to false, and cover up the card again.
|
|
22
|
+
</p>
|
|
23
|
+
</div>
|
|
24
|
+
<h1 id="customization">Customization</h1>
|
|
25
|
+
<div class="cardIcon">
|
|
26
|
+
<h2 id="icon">Icon</h2>
|
|
27
|
+
<p>
|
|
28
|
+
You can start your Slice Card customization by assignin another icon to it.
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="cardColor">
|
|
32
|
+
<h2 id="customColor">Custom Color</h2>
|
|
33
|
+
<p>
|
|
34
|
+
You can also change card color by using "customColor" props, using
|
|
35
|
+
"customColor.card" to change it's background, and "customColor.icon" to
|
|
36
|
+
change the icon's color.
|
|
37
|
+
</p>
|
|
38
|
+
</div>
|