slicejs-cli 1.0.53 → 1.0.55
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/commands/createComponent/createComponent.js +7 -4
- package/commands/listComponents/listComponents.js +63 -30
- package/package.json +1 -1
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Provider/TestProvider/TestProvider.js +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/FetchManager/FetchManager.js +0 -134
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/IndexedDbManager/IndexedDbManager.js +0 -138
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/LocalStorageManager/LocalStorageManager.js +0 -45
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/Translator/Translator.js +0 -59
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/Translator/messages.json +0 -50
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Controller/Controller.js +0 -106
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Debugger/Debugger.css +0 -95
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Debugger/Debugger.html +0 -10
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Debugger/Debugger.js +0 -250
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Logger/Log.js +0 -10
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/Logger/Logger.js +0 -112
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/StylesManager/CustomStylesManager/CustomStylesManager.js +0 -52
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/StylesManager/StylesManager.js +0 -42
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +0 -25
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Button/Button.css +0 -44
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Button/Button.html +0 -5
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Button/Button.js +0 -39
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Card/Card.css +0 -63
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Card/Card.html +0 -7
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Card/Card.js +0 -110
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Checkbox/Checkbox.css +0 -87
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Checkbox/Checkbox.html +0 -8
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Checkbox/Checkbox.js +0 -87
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/CodeValidator/CodeValidator.css +0 -97
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/CodeValidator/CodeValidator.html +0 -18
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/CodeValidator/CodeValidator.js +0 -86
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/Icon.css +0 -505
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/Icon.html +0 -1
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/Icon.js +0 -95
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.eot +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.json +0 -550
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.styl +0 -502
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.svg +0 -1470
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.symbol.svg +0 -1035
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.ttf +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.woff +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Icon/slc.woff2 +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Input/Input.css +0 -87
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Input/Input.html +0 -4
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Input/Input.js +0 -210
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Loading/Loading.css +0 -56
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Loading/Loading.html +0 -83
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Loading/Loading.js +0 -39
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Navbar/Navbar.css +0 -30
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Navbar/Navbar.html +0 -6
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Navbar/Navbar.js +0 -39
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Select/Select.css +0 -91
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Select/Select.html +0 -8
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Select/Select.js +0 -210
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Switch/Switch.css +0 -76
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Switch/Switch.html +0 -8
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Switch/Switch.js +0 -109
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/TestComponent/TestComponent.css +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/TestComponent/TestComponent.html +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/TestComponent/TestComponent.js +0 -0
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester/Tester.css +0 -34
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester/Tester.html +0 -7
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester/Tester.js +0 -33
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester2/Tester2.css +0 -34
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester2/Tester2.html +0 -43
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/Tester2/Tester2.js +0 -39
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/ToastAlert/ToastAlert.css +0 -110
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/ToastAlert/ToastAlert.html +0 -12
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/ToastAlert/ToastAlert.js +0 -65
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/complexNavbar/complexNavbar.css +0 -163
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/complexNavbar/complexNavbar.html +0 -15
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/complexNavbar/complexNavbar.js +0 -48
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/imageCarousel/img-carousel.css +0 -56
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/imageCarousel/img-carousel.html +0 -6
- package/PROJECT_TEMPLATES/Basic/Slice/Components/Visual/imageCarousel/img-carousel.js +0 -119
- package/PROJECT_TEMPLATES/Basic/Slice/Components/components.js +0 -23
- package/PROJECT_TEMPLATES/Basic/Slice/Slice.js +0 -194
- package/PROJECT_TEMPLATES/Basic/Slice/Styles/Custom/custom.css +0 -23
- package/PROJECT_TEMPLATES/Basic/Slice/Styles/sliceStyles.css +0 -10
- package/PROJECT_TEMPLATES/Basic/Slice/Themes/Dark.css +0 -38
- package/PROJECT_TEMPLATES/Basic/Slice/Themes/Light.css +0 -31
- package/PROJECT_TEMPLATES/Basic/Slice/Themes/Slice.css +0 -30
- package/PROJECT_TEMPLATES/Basic/Slice/package.json +0 -12
- package/PROJECT_TEMPLATES/Basic/Slice/sliceConfig.json +0 -32
- package/PROJECT_TEMPLATES/Basic/src/Views/LandingPage/index.html +0 -14
- package/PROJECT_TEMPLATES/Basic/src/Views/LandingPage/index.js +0 -395
- package/PROJECT_TEMPLATES/Basic/src/Views/LandingPage/style.css +0 -0
|
@@ -7,7 +7,7 @@ import Validations from '../Validations.js';
|
|
|
7
7
|
import Print from '../Print.js';
|
|
8
8
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
9
9
|
|
|
10
|
-
function createComponent(componentName, category, properties) {
|
|
10
|
+
function createComponent(componentName, category, properties, methods) {
|
|
11
11
|
|
|
12
12
|
if (!componentName) {
|
|
13
13
|
Print.error('Component name is required');
|
|
@@ -38,7 +38,7 @@ function createComponent(componentName, category, properties) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if(category==='Service'){
|
|
41
|
-
template = componentTemplates.service(className,
|
|
41
|
+
template = componentTemplates.service(className, methods);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
//RUTA PARA CUANDO SE COLOQUE DE USUARIO
|
|
@@ -63,8 +63,11 @@ function createComponent(componentName, category, properties) {
|
|
|
63
63
|
|
|
64
64
|
// Escribir el código del componente en el archivo
|
|
65
65
|
fs.writeFileSync(componentPath, template);
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
|
|
67
|
+
if(category==='Visual'){
|
|
68
|
+
fs.writeFileSync(`${componentDir}/${className}.css`, '');
|
|
69
|
+
fs.writeFileSync(`${componentDir}/${className}.html`, `<div>${componentName}</div>`);
|
|
70
|
+
}
|
|
68
71
|
|
|
69
72
|
Print.success(`Component '${componentName}' created successfully.`);
|
|
70
73
|
return true;
|
|
@@ -1,45 +1,78 @@
|
|
|
1
|
-
|
|
2
1
|
import fs from 'fs';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import { fileURLToPath } from 'url';
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
4
|
import Print from '../Print.js';
|
|
7
|
-
export default function listComponents() {
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Carga la configuración desde sliceConfig.json
|
|
10
|
+
* @returns {object} - Objeto de configuración
|
|
11
|
+
*/
|
|
12
|
+
const loadConfig = () => {
|
|
13
|
+
try {
|
|
14
|
+
const configPath = path.join(__dirname, '../../../../Slice/sliceConfig.json');
|
|
15
|
+
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
16
|
+
return JSON.parse(rawData);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(`Error cargando configuración: ${error.message}`);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Lista los archivos en una carpeta dada, filtrando solo los archivos .js
|
|
25
|
+
* @param {string} folderPath - Ruta de la carpeta a leer
|
|
26
|
+
* @returns {string[]} - Lista de archivos encontrados
|
|
27
|
+
*/
|
|
28
|
+
const listComponents = (folderPath) => {
|
|
29
|
+
try {
|
|
30
|
+
const result = fs.readdirSync(folderPath)
|
|
31
|
+
console.log(`Leyendo carpeta ${folderPath}: ${result.length} archivos encontrados`);
|
|
32
|
+
return result;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(`Error leyendo carpeta ${folderPath}: ${error.message}`);
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Obtiene los componentes dinámicamente desde sliceConfig.json
|
|
41
|
+
* @returns {object} - Mapeo de componentes con su categoría
|
|
42
|
+
*/
|
|
43
|
+
const getComponents = () => {
|
|
44
|
+
const config = loadConfig();
|
|
45
|
+
if (!config) return {};
|
|
46
|
+
|
|
47
|
+
const isProduction = config.production.enabled===true;
|
|
48
|
+
const folderSuffix = isProduction ? 'dist' : 'src';
|
|
49
|
+
|
|
50
|
+
const componentPaths = config.paths?.components || {}; // Obtiene dinámicamente las rutas de los componentes
|
|
51
|
+
let allComponents = new Map();
|
|
12
52
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
53
|
+
Object.entries(componentPaths).forEach(([category, { path: folderPath }]) => {
|
|
54
|
+
const fullPath = path.join(__dirname, `../../../../${folderSuffix}`, folderPath);
|
|
55
|
+
const files = listComponents(fullPath);
|
|
16
56
|
|
|
17
57
|
|
|
18
|
-
|
|
58
|
+
files.forEach(file => {
|
|
59
|
+
const componentName = path.basename(file, '.js');
|
|
60
|
+
allComponents.set(componentName, category);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
19
63
|
|
|
20
|
-
visualComponents.forEach(component => {
|
|
21
|
-
componentMap.set(component, "Visual");
|
|
22
|
-
});
|
|
23
64
|
|
|
24
|
-
services.forEach(component => {
|
|
25
|
-
componentMap.set(component, "Service");
|
|
26
|
-
});
|
|
27
65
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
66
|
+
return Object.fromEntries(allComponents);
|
|
67
|
+
};
|
|
31
68
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
69
|
+
// Obtener componentes dinámicamente
|
|
70
|
+
const components = getComponents();
|
|
35
71
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
72
|
+
// Ruta donde se generará components.js
|
|
73
|
+
const outputPath = path.join(__dirname, '../../../../Slice/Components/components.js');
|
|
39
74
|
|
|
40
|
-
|
|
41
|
-
|
|
75
|
+
// Generar archivo components.js con los componentes detectados
|
|
76
|
+
fs.writeFileSync(outputPath, `const components = ${JSON.stringify(components, null, 2)}; export default components;`);
|
|
42
77
|
|
|
43
|
-
|
|
44
|
-
Print.success('Components list updated');
|
|
45
|
-
}
|
|
78
|
+
Print.success('Lista de componentes actualizada dinámicamente');
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
export default class FetchManager {
|
|
2
|
-
constructor(props) {
|
|
3
|
-
const { baseUrl, timeout } = props;
|
|
4
|
-
if (baseUrl !== undefined) {
|
|
5
|
-
this.baseUrl = baseUrl;
|
|
6
|
-
}
|
|
7
|
-
this.methods = ["GET", "POST", "PUT", "DELETE"];
|
|
8
|
-
this.lastRequest = null;
|
|
9
|
-
this.cacheEnabled = false;
|
|
10
|
-
this.defaultHeaders = {};
|
|
11
|
-
timeout ? (this.timeout = timeout) : (this.timeout = 10000);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async request(
|
|
15
|
-
method,
|
|
16
|
-
data,
|
|
17
|
-
endpoint,
|
|
18
|
-
onRequestSuccess,
|
|
19
|
-
onRequestError,
|
|
20
|
-
refetchOnError = false,
|
|
21
|
-
requestOptions = {}
|
|
22
|
-
) {
|
|
23
|
-
if (!this.methods.includes(method)) throw new Error("Invalid method");
|
|
24
|
-
if (data && typeof data !== "object")
|
|
25
|
-
throw new Error("Invalid data, not JSON");
|
|
26
|
-
const controller = new AbortController();
|
|
27
|
-
|
|
28
|
-
let options;
|
|
29
|
-
if (method !== "GET") {
|
|
30
|
-
options = {
|
|
31
|
-
method: method,
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
...this.defaultHeaders,
|
|
35
|
-
...requestOptions.headers,
|
|
36
|
-
},
|
|
37
|
-
signal: controller.signal,
|
|
38
|
-
};
|
|
39
|
-
} else {
|
|
40
|
-
options = {
|
|
41
|
-
method: method,
|
|
42
|
-
headers: {
|
|
43
|
-
...this.defaultHeaders,
|
|
44
|
-
...requestOptions.headers,
|
|
45
|
-
},
|
|
46
|
-
signal: controller.signal,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (data) {
|
|
51
|
-
options.body = JSON.stringify(data);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let loading;
|
|
55
|
-
if (!slice.controller.getComponent("Loading")) {
|
|
56
|
-
loading = await slice.build("Loading", { sliceId: "Loading" });
|
|
57
|
-
} else {
|
|
58
|
-
loading = slice.controller.getComponent("Loading");
|
|
59
|
-
}
|
|
60
|
-
loading.start();
|
|
61
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout || 10000);
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
let response;
|
|
65
|
-
|
|
66
|
-
// Check if cache is enabled and a cached response exists
|
|
67
|
-
if (this.cacheEnabled && this.lastRequest && this.lastRequest.endpoint === endpoint) {
|
|
68
|
-
return this.lastRequest.response;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (this.baseUrl !== undefined) {
|
|
72
|
-
response = await fetch(this.baseUrl + endpoint, options);
|
|
73
|
-
} else {
|
|
74
|
-
response = await fetch(endpoint, options);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (response.ok) {
|
|
78
|
-
if (typeof onRequestSuccess === "function") {
|
|
79
|
-
onRequestSuccess(data, response);
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
if (typeof onRequestError === "function") {
|
|
83
|
-
onRequestError(data, response);
|
|
84
|
-
}
|
|
85
|
-
if (refetchOnError) {
|
|
86
|
-
// Retry the request in case of error
|
|
87
|
-
return await this.request(
|
|
88
|
-
method,
|
|
89
|
-
data,
|
|
90
|
-
endpoint,
|
|
91
|
-
onRequestSuccess,
|
|
92
|
-
onRequestError,
|
|
93
|
-
refetchOnError,
|
|
94
|
-
requestOptions
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let output = await response.json();
|
|
100
|
-
loading.stop();
|
|
101
|
-
|
|
102
|
-
// Cache the response if cache is enabled
|
|
103
|
-
if (this.cacheEnabled) {
|
|
104
|
-
this.lastRequest = { data, response, endpoint };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return output;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
if (error.message === "Failed to fetch") {
|
|
110
|
-
slice.logger.logError("Se perdió la conexión a internet");
|
|
111
|
-
} else {
|
|
112
|
-
console.error("Error al realizar la solicitud:", error);
|
|
113
|
-
}
|
|
114
|
-
loading.stop();
|
|
115
|
-
throw error;
|
|
116
|
-
} finally {
|
|
117
|
-
clearTimeout(timeoutId);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Enable or disable caching of responses
|
|
122
|
-
enableCache() {
|
|
123
|
-
this.cacheEnabled = true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
disableCache() {
|
|
127
|
-
this.cacheEnabled = false;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Set default headers for all requests
|
|
131
|
-
setDefaultHeaders(headers) {
|
|
132
|
-
this.defaultHeaders = headers;
|
|
133
|
-
}
|
|
134
|
-
}
|
package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/IndexedDbManager/IndexedDbManager.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
export default class IndexedDbManager {
|
|
2
|
-
constructor(databaseName, storeName) {
|
|
3
|
-
this.databaseName = databaseName;
|
|
4
|
-
this.storeName = storeName;
|
|
5
|
-
this.db = null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async openDatabase() {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const request = indexedDB.open(this.databaseName);
|
|
11
|
-
|
|
12
|
-
request.onupgradeneeded = (event) => {
|
|
13
|
-
const db = event.target.result;
|
|
14
|
-
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
15
|
-
db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
request.onsuccess = (event) => {
|
|
20
|
-
this.db = event.target.result;
|
|
21
|
-
resolve(this.db);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
request.onerror = (event) => {
|
|
25
|
-
reject(new Error(`Error opening IndexedDB: ${event.target.error}`));
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
closeDatabase() {
|
|
31
|
-
if (this.db) {
|
|
32
|
-
this.db.close();
|
|
33
|
-
this.db = null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async addItem(item) {
|
|
38
|
-
const db = await this.openDatabase();
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
41
|
-
const store = transaction.objectStore(this.storeName);
|
|
42
|
-
const request = store.add(item);
|
|
43
|
-
|
|
44
|
-
request.onsuccess = () => {
|
|
45
|
-
resolve(request.result);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
request.onerror = (event) => {
|
|
49
|
-
reject(new Error(`Error adding item to IndexedDB: ${event.target.error}`));
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async updateItem(item) {
|
|
55
|
-
const db = await this.openDatabase();
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
58
|
-
const store = transaction.objectStore(this.storeName);
|
|
59
|
-
const request = store.put(item);
|
|
60
|
-
|
|
61
|
-
request.onsuccess = () => {
|
|
62
|
-
resolve(request.result);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
request.onerror = (event) => {
|
|
66
|
-
reject(new Error(`Error updating item in IndexedDB: ${event.target.error}`));
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async getItem(id) {
|
|
72
|
-
const db = await this.openDatabase();
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
const transaction = db.transaction([this.storeName], 'readonly');
|
|
75
|
-
const store = transaction.objectStore(this.storeName);
|
|
76
|
-
const request = store.get(id);
|
|
77
|
-
|
|
78
|
-
request.onsuccess = () => {
|
|
79
|
-
resolve(request.result);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
request.onerror = (event) => {
|
|
83
|
-
reject(new Error(`Error getting item from IndexedDB: ${event.target.error}`));
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async deleteItem(id) {
|
|
89
|
-
const db = await this.openDatabase();
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
92
|
-
const store = transaction.objectStore(this.storeName);
|
|
93
|
-
const request = store.delete(id);
|
|
94
|
-
|
|
95
|
-
request.onsuccess = () => {
|
|
96
|
-
resolve();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
request.onerror = (event) => {
|
|
100
|
-
reject(new Error(`Error deleting item from IndexedDB: ${event.target.error}`));
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async getAllItems() {
|
|
106
|
-
const db = await this.openDatabase();
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
const transaction = db.transaction([this.storeName], 'readonly');
|
|
109
|
-
const store = transaction.objectStore(this.storeName);
|
|
110
|
-
const request = store.getAll();
|
|
111
|
-
|
|
112
|
-
request.onsuccess = () => {
|
|
113
|
-
resolve(request.result);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
request.onerror = (event) => {
|
|
117
|
-
reject(new Error(`Error getting items from IndexedDB: ${event.target.error}`));
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async clearItems() {
|
|
123
|
-
const db = await this.openDatabase();
|
|
124
|
-
return new Promise((resolve, reject) => {
|
|
125
|
-
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
126
|
-
const store = transaction.objectStore(this.storeName);
|
|
127
|
-
const request = store.clear();
|
|
128
|
-
|
|
129
|
-
request.onsuccess = () => {
|
|
130
|
-
resolve();
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
request.onerror = (event) => {
|
|
134
|
-
reject(new Error(`Error clearing items in IndexedDB: ${event.target.error}`));
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
package/PROJECT_TEMPLATES/Basic/Slice/Components/Service/LocalStorageManager/LocalStorageManager.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export default class LocalStorageManager {
|
|
2
|
-
constructor() {
|
|
3
|
-
// No se necesitan propiedades en este caso
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
getItem(key) {
|
|
7
|
-
try {
|
|
8
|
-
const item = localStorage.getItem(key);
|
|
9
|
-
return item ? JSON.parse(item) : null;
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error(`Error getting item from localStorage: ${error.message}`);
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
setItem(key, value) {
|
|
17
|
-
try {
|
|
18
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
19
|
-
return true;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error(`Error setting item in localStorage: ${error.message}`);
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
removeItem(key) {
|
|
27
|
-
try {
|
|
28
|
-
localStorage.removeItem(key);
|
|
29
|
-
return true;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error(`Error removing item from localStorage: ${error.message}`);
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
clear() {
|
|
37
|
-
try {
|
|
38
|
-
localStorage.clear();
|
|
39
|
-
return true;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
console.error(`Error clearing localStorage: ${error.message}`);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import messages from "./messages.json" assert { type: "json" };
|
|
2
|
-
|
|
3
|
-
export default class Translator {
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
this.messages=messages;
|
|
7
|
-
this.currentLanguage = 'en';
|
|
8
|
-
|
|
9
|
-
if(slice.translator){
|
|
10
|
-
throw new Error("Translator already initialized")
|
|
11
|
-
}else{
|
|
12
|
-
slice.translator = this;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
changeLanguage(newLanguage) {
|
|
18
|
-
this.currentLanguage = newLanguage;
|
|
19
|
-
return this.setPropertiesForComponents();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setPropertiesForComponents() {
|
|
25
|
-
try {
|
|
26
|
-
const currentLanguageMessages = this.messages[this.currentLanguage];
|
|
27
|
-
|
|
28
|
-
for (const componentName in currentLanguageMessages) {
|
|
29
|
-
const component = slice.controller.activeComponents.get(componentName);
|
|
30
|
-
const translations = currentLanguageMessages[componentName];
|
|
31
|
-
if (component) {
|
|
32
|
-
for (const prop in translations) {
|
|
33
|
-
component[prop] = translations[prop];
|
|
34
|
-
}
|
|
35
|
-
}else {
|
|
36
|
-
console.error(`Component ${componentName} not found`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return true
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.log(error)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
setMessages(messagesObject){
|
|
49
|
-
this.messages=messagesObject;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"en": {
|
|
3
|
-
"myInput": {
|
|
4
|
-
"placeholder": "Type here"
|
|
5
|
-
},
|
|
6
|
-
"cardYoutube": {
|
|
7
|
-
"title": "Youtube in English",
|
|
8
|
-
"text": "Youtube is a video sharing platform. You can watch videos, upload your own videos and comment on videos."
|
|
9
|
-
},
|
|
10
|
-
"cardGoogle": {
|
|
11
|
-
"title": "Google in English",
|
|
12
|
-
"text": "Google is a search engine. You can search for information, images, videos and much more."
|
|
13
|
-
},
|
|
14
|
-
"cardFacebook": {
|
|
15
|
-
"title": "Facebook in English",
|
|
16
|
-
"text": "Facebook is a social network. You can share photos, videos, statuses and chat with your friends."
|
|
17
|
-
},
|
|
18
|
-
"cardTwitter": {
|
|
19
|
-
"title": "Twitter in English",
|
|
20
|
-
"text": "Twitter is a social network. You can share tweets, follow other people and stay informed."
|
|
21
|
-
},
|
|
22
|
-
"buttonLanguage": {
|
|
23
|
-
"value": "Change language"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"es": {
|
|
27
|
-
"myInput": {
|
|
28
|
-
"placeholder": "Escribe aquí"
|
|
29
|
-
},
|
|
30
|
-
"cardYoutube": {
|
|
31
|
-
"title": "Youtube en Español",
|
|
32
|
-
"text": "Youtube es una plataforma de intercambio de videos. Puedes ver videos, subir tus propios videos y comentar en videos."
|
|
33
|
-
},
|
|
34
|
-
"cardGoogle": {
|
|
35
|
-
"title": "Google en Español",
|
|
36
|
-
"text": "Google es un motor de búsqueda. Puedes buscar información, imágenes, videos y mucho más."
|
|
37
|
-
},
|
|
38
|
-
"cardFacebook": {
|
|
39
|
-
"title": "Facebook en Español",
|
|
40
|
-
"text": "Facebook es una red social. Puedes compartir fotos, videos, estados y chatear con tus amigos."
|
|
41
|
-
},
|
|
42
|
-
"cardTwitter": {
|
|
43
|
-
"title": "Twitter en Español",
|
|
44
|
-
"text": "Twitter es una red social. Puedes compartir tweets, seguir a otras personas y mantenerte informado."
|
|
45
|
-
},
|
|
46
|
-
"buttonLanguage": {
|
|
47
|
-
"value": "Cambiar idioma"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import components from "../../components.js";
|
|
2
|
-
|
|
3
|
-
export default class Controller {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.componentCategories = new Map(Object.entries(components));
|
|
6
|
-
this.templates = new Map();
|
|
7
|
-
this.classes = new Map();
|
|
8
|
-
this.requestedStyles = new Set();
|
|
9
|
-
this.activeComponents = new Map();
|
|
10
|
-
this.idCounter = 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
registerComponent(component) {
|
|
14
|
-
const htmlId = component.id;
|
|
15
|
-
|
|
16
|
-
if (htmlId && htmlId.trim() !== "") {
|
|
17
|
-
if (this.activeComponents.has(htmlId)) {
|
|
18
|
-
slice.logger.logError(
|
|
19
|
-
"Controller",
|
|
20
|
-
`A component with the same html id attribute is already registered: ${htmlId}`
|
|
21
|
-
);
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let sliceId = component.sliceId;
|
|
27
|
-
|
|
28
|
-
if (sliceId && sliceId.trim() !== "") {
|
|
29
|
-
if (this.activeComponents.has(sliceId)) {
|
|
30
|
-
slice.logger.logError(
|
|
31
|
-
"Controller",
|
|
32
|
-
`A component with the same slice id attribute is already registered: ${sliceId}`
|
|
33
|
-
);
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
sliceId = `${component.constructor.name[0].toLowerCase()}${component.constructor.name.slice(1)}-${this.idCounter}`;
|
|
38
|
-
component.sliceId = sliceId;
|
|
39
|
-
this.idCounter++;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.activeComponents.set(sliceId, component);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getComponent(id) {
|
|
47
|
-
return this.activeComponents.get(id);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//Attach template to component
|
|
51
|
-
loadTemplateToComponent(component) {
|
|
52
|
-
const className = component.constructor.name;
|
|
53
|
-
const template = this.templates.get(className);
|
|
54
|
-
|
|
55
|
-
if (!template) {
|
|
56
|
-
console.error(`Template not found for component: ${className}`);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
component.innerHTML = template.innerHTML;
|
|
61
|
-
return component;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getComponentCategory(componentName) {
|
|
65
|
-
return this.componentCategories.get(componentName);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async fetchText(componentName, fileType) {
|
|
69
|
-
const componentCategory = this.getComponentCategory(componentName);
|
|
70
|
-
|
|
71
|
-
let path;
|
|
72
|
-
|
|
73
|
-
if (fileType === "css") {
|
|
74
|
-
path = `Slice/${slice.paths.components}/${componentCategory}/${componentName}/${componentName}.css`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (fileType === "html") {
|
|
78
|
-
path = `Slice/${slice.paths.components}/${componentCategory}/${componentName}/${componentName}.html`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (fileType === "theme") {
|
|
82
|
-
path = `Slice/${slice.paths.themes}/${componentName}.css`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (fileType === "styles") {
|
|
86
|
-
path = `Slice/${slice.paths.styles}/${componentName}.css`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const response = await fetch(path);
|
|
90
|
-
const html = await response.text();
|
|
91
|
-
return html;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
setComponentProps(component, props) {
|
|
95
|
-
for (const prop in props) {
|
|
96
|
-
component[`_${prop}`] = null;
|
|
97
|
-
component[prop] = props[prop];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
destroyComponent(component) {
|
|
102
|
-
const sliceId = component.sliceId;
|
|
103
|
-
this.activeComponents.delete(sliceId);
|
|
104
|
-
component.remove();
|
|
105
|
-
}
|
|
106
|
-
}
|