@nano-app/frontend 0.3.1 → 0.3.3
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/bin/generate-stores.mjs +128 -0
- package/dist/auto-register.d.ts +6 -0
- package/dist/auto-register.js +9 -0
- package/dist/auto-register.mjs +310 -0
- package/dist/auto-register.ts +336 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +12 -2
- package/dist/state/RenderManager.d.ts +47 -0
- package/dist/state/RenderManager.js +78 -0
- package/dist/store/{ApiClient.d.ts → ApiStore.d.ts} +4 -3
- package/dist/store/{ApiClient.js → ApiStore.js} +10 -10
- package/dist/store/AppStore.d.ts +25 -0
- package/dist/store/AppStore.js +59 -0
- package/dist/store/RenderManager.d.ts +47 -0
- package/dist/store/RenderManager.js +78 -0
- package/dist/store/StateManager.d.ts +4 -0
- package/dist/store/StateManager.js +10 -0
- package/dist/store/StoreManager.d.ts +8 -9
- package/dist/store/StoreManager.js +14 -28
- package/dist/store/stores.d.ts +6 -0
- package/dist/store/stores.js +9 -0
- package/dist/ui/Controller.d.ts +13 -14
- package/dist/ui/Controller.js +41 -8
- package/dist/ui/createComponent.d.ts +17 -4
- package/dist/ui/createComponent.js +25 -18
- package/dist/utils/pathUtils.d.ts +14 -0
- package/dist/utils/pathUtils.js +43 -0
- package/package.json +8 -6
- package/dist/api/ApiClient.d.ts +0 -16
- package/dist/api/ApiClient.js +0 -69
- package/dist/api/QueryBuilder.d.ts +0 -8
- package/dist/api/QueryBuilder.js +0 -51
- package/dist/components/Controller.d.ts +0 -16
- package/dist/components/Controller.js +0 -29
- package/dist/config/index.d.ts +0 -21
- package/dist/config/index.js +0 -10
- package/dist/hooks/useComponent.d.ts +0 -8
- package/dist/hooks/useComponent.js +0 -10
- package/dist/plugin/index.d.ts +0 -11
- package/dist/plugin/index.js +0 -134
- package/dist/store/StoreClient.d.ts +0 -11
- package/dist/store/StoreClient.js +0 -40
- package/dist/store/bootstrapApp.d.ts +0 -19
- package/dist/store/bootstrapApp.js +0 -25
- package/dist/store/setStores.d.ts +0 -8
- package/dist/store/setStores.js +0 -23
- package/dist/types/api.d.ts +0 -7
- package/dist/types/api.js +0 -2
- package/dist/ui/Component.d.ts +0 -4
- package/dist/ui/Component.js +0 -49
- package/dist/ui/StoreProvider.d.ts +0 -18
- package/dist/ui/StoreProvider.js +0 -62
- package/dist/ui/defineController.d.ts +0 -23
- package/dist/ui/defineController.js +0 -14
- package/dist/ui/defineView.d.ts +0 -3
- package/dist/ui/defineView.js +0 -44
- package/dist/ui/definers.d.ts +0 -1
- package/dist/ui/definers.js +0 -59
- package/dist/ui/useComponent.d.ts +0 -2
- package/dist/ui/useComponent.js +0 -9
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// Auto-generado por @nano-app
|
|
2
|
+
// No editar manualmente.
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
"name": "api",
|
|
6
|
+
"type": "api",
|
|
7
|
+
"path": "/api",
|
|
8
|
+
"data": {
|
|
9
|
+
"busy": true,
|
|
10
|
+
"refresh": false,
|
|
11
|
+
"DefaultItems": [],
|
|
12
|
+
"UserStatusItems": [
|
|
13
|
+
{
|
|
14
|
+
"key": "SUSPENDED",
|
|
15
|
+
"text": "Suspendido"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"key": "PENDING",
|
|
19
|
+
"text": "Pendiente"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"key": "ACTIVE",
|
|
23
|
+
"text": "Activo"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "app",
|
|
30
|
+
"type": "app",
|
|
31
|
+
"data": {
|
|
32
|
+
"isRegister": false,
|
|
33
|
+
"navbar": {
|
|
34
|
+
"tabs": [],
|
|
35
|
+
"selectedTabKey": "home",
|
|
36
|
+
"selectedTab": {},
|
|
37
|
+
"isMenuOpen": false
|
|
38
|
+
},
|
|
39
|
+
"form": {
|
|
40
|
+
"data": {},
|
|
41
|
+
"validate": []
|
|
42
|
+
},
|
|
43
|
+
"drawer": {
|
|
44
|
+
"isOpen": false,
|
|
45
|
+
"formType": "",
|
|
46
|
+
"title": ""
|
|
47
|
+
},
|
|
48
|
+
"totales": {},
|
|
49
|
+
"config": {
|
|
50
|
+
"theme": "dark"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "const",
|
|
56
|
+
"type": "app",
|
|
57
|
+
"data": {
|
|
58
|
+
"alias": "42974117.prex",
|
|
59
|
+
"stepSkipTop": 20,
|
|
60
|
+
"tabs": [
|
|
61
|
+
{
|
|
62
|
+
"key": "home",
|
|
63
|
+
"href": "/",
|
|
64
|
+
"label": "Home",
|
|
65
|
+
"minRole": 1
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"key": "resumen",
|
|
69
|
+
"href": "/resumen",
|
|
70
|
+
"label": "Resumen",
|
|
71
|
+
"minRole": 2
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"key": "admin",
|
|
75
|
+
"href": "/admin",
|
|
76
|
+
"label": "Administración",
|
|
77
|
+
"minRole": 3
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"key": "uli",
|
|
81
|
+
"href": "/",
|
|
82
|
+
"label": "Uli :v",
|
|
83
|
+
"minRole": 1
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"key": "luka",
|
|
87
|
+
"href": "/",
|
|
88
|
+
"label": "Lucas :v",
|
|
89
|
+
"minRole": 1
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"initialForms": {
|
|
93
|
+
"User": {
|
|
94
|
+
"rolId": 1,
|
|
95
|
+
"status": "PENDING"
|
|
96
|
+
},
|
|
97
|
+
"Collection": {
|
|
98
|
+
"total_months": 1,
|
|
99
|
+
"start_date": "2026-03-01T00:00:00.000Z"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"tableColumns": {
|
|
103
|
+
"Users": [
|
|
104
|
+
"name",
|
|
105
|
+
"phone",
|
|
106
|
+
"mail",
|
|
107
|
+
"pending",
|
|
108
|
+
"favor",
|
|
109
|
+
"rol.name",
|
|
110
|
+
"status"
|
|
111
|
+
],
|
|
112
|
+
"Collections": [
|
|
113
|
+
"user.name",
|
|
114
|
+
"price",
|
|
115
|
+
"description",
|
|
116
|
+
"start_date",
|
|
117
|
+
"total_months",
|
|
118
|
+
"subscription.description"
|
|
119
|
+
],
|
|
120
|
+
"Subscriptions": [
|
|
121
|
+
"description",
|
|
122
|
+
"price"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"formField": {
|
|
126
|
+
"pay": [
|
|
127
|
+
{
|
|
128
|
+
"fieldName": "total",
|
|
129
|
+
"valueType": "price",
|
|
130
|
+
"isRequired": true
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"login": [
|
|
134
|
+
{
|
|
135
|
+
"fieldName": "mail",
|
|
136
|
+
"inputType": "email",
|
|
137
|
+
"isRequired": true
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"fieldName": "password",
|
|
141
|
+
"inputType": "password",
|
|
142
|
+
"isRequired": true
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"register": [
|
|
146
|
+
{
|
|
147
|
+
"fieldName": "name",
|
|
148
|
+
"isRequired": true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"fieldName": "phone",
|
|
152
|
+
"isRequired": true
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"fieldName": "mail",
|
|
156
|
+
"inputType": "email",
|
|
157
|
+
"isRequired": true
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"fieldName": "password",
|
|
161
|
+
"inputType": "password",
|
|
162
|
+
"isRequired": true
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"fieldName": "confirmPassword",
|
|
166
|
+
"inputType": "password",
|
|
167
|
+
"isRequired": true
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"Users": [
|
|
171
|
+
{
|
|
172
|
+
"fieldName": "name",
|
|
173
|
+
"isRequired": true
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"fieldName": "mail",
|
|
177
|
+
"inputType": "email",
|
|
178
|
+
"isRequired": true
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"fieldName": "rolId",
|
|
182
|
+
"valueType": "number",
|
|
183
|
+
"isRequired": true,
|
|
184
|
+
"inputType": "select",
|
|
185
|
+
"select": {
|
|
186
|
+
"items": "/Roles",
|
|
187
|
+
"itemKey": "id",
|
|
188
|
+
"showValues": [
|
|
189
|
+
"name"
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"fieldName": "status",
|
|
195
|
+
"inputType": "select",
|
|
196
|
+
"isRequired": true,
|
|
197
|
+
"select": {
|
|
198
|
+
"items": "/UserStatusItems",
|
|
199
|
+
"itemKey": "key",
|
|
200
|
+
"showValues": [
|
|
201
|
+
"text"
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"fieldName": "pending",
|
|
207
|
+
"valueType": "price"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"fieldName": "favor",
|
|
211
|
+
"valueType": "price"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"Collections": [
|
|
215
|
+
{
|
|
216
|
+
"fieldName": "userId",
|
|
217
|
+
"valueType": "number",
|
|
218
|
+
"inputType": "select",
|
|
219
|
+
"isRequired": true,
|
|
220
|
+
"select": {
|
|
221
|
+
"items": "Users",
|
|
222
|
+
"itemKey": "id",
|
|
223
|
+
"showValues": [
|
|
224
|
+
"name"
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"fieldName": "price",
|
|
230
|
+
"valueType": "price",
|
|
231
|
+
"isRequired": true
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"fieldName": "description",
|
|
235
|
+
"isRequired": true
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"fieldName": "total_months",
|
|
239
|
+
"valueType": "number",
|
|
240
|
+
"isRequired": true
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"fieldName": "start_date",
|
|
244
|
+
"valueType": "date",
|
|
245
|
+
"inputType": "date",
|
|
246
|
+
"isRequired": true
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"fieldName": "subscriptionId",
|
|
250
|
+
"valueType": "number",
|
|
251
|
+
"inputType": "select",
|
|
252
|
+
"select": {
|
|
253
|
+
"items": "Subscriptions",
|
|
254
|
+
"itemKey": "id",
|
|
255
|
+
"showValues": [
|
|
256
|
+
"description"
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
"Subscriptions": [
|
|
262
|
+
{
|
|
263
|
+
"fieldName": "description",
|
|
264
|
+
"isRequired": true
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"fieldName": "price",
|
|
268
|
+
"valueType": "price",
|
|
269
|
+
"isRequired": true
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
"expandFields": {
|
|
274
|
+
"Users": "rol",
|
|
275
|
+
"Collections": "user,subscription"
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "i18n",
|
|
281
|
+
"type": "app",
|
|
282
|
+
"data": {
|
|
283
|
+
"login": {
|
|
284
|
+
"header": (isRegister) => isRegister ? "REGISTRARSE" : "INICIAR SESIÓN",
|
|
285
|
+
"footer": (isRegister) => isRegister ? "o iniciar sesión" : "o registrarse",
|
|
286
|
+
"buttonText": (isRegister) => isRegister ? "Crear" : "Ingresar"
|
|
287
|
+
},
|
|
288
|
+
"create": (entity) => `Crear ${entity}`,
|
|
289
|
+
"edit": (entity) => `Editar ${entity}`,
|
|
290
|
+
"mapping": {
|
|
291
|
+
"name": "Nombre",
|
|
292
|
+
"phone": "Teléfono",
|
|
293
|
+
"mail": "Mail",
|
|
294
|
+
"pending": "Pendiente",
|
|
295
|
+
"favor": "A favor",
|
|
296
|
+
"rolId": "Rol",
|
|
297
|
+
"rol.name": "Rol",
|
|
298
|
+
"status": "Estado",
|
|
299
|
+
"password": "Contraseña",
|
|
300
|
+
"confirmPassword": "Repetir contraseña",
|
|
301
|
+
"user.name": "Usuario",
|
|
302
|
+
"userId": "Usuario",
|
|
303
|
+
"price": "Precio",
|
|
304
|
+
"description": "Descripción",
|
|
305
|
+
"start_date": "Fecha de inicio",
|
|
306
|
+
"total_months": "Meses totales",
|
|
307
|
+
"subscription.description": "Subscripción",
|
|
308
|
+
"subscriptionId": "Subscripción",
|
|
309
|
+
"last_pay": "Último pago",
|
|
310
|
+
"first_month": "Mes de inicio",
|
|
311
|
+
"current_month": "Último mes pagado",
|
|
312
|
+
"payed_months": "Meses pagados",
|
|
313
|
+
"actions": "Acciones",
|
|
314
|
+
"created_at": "Creado",
|
|
315
|
+
"Users": "Usuarios",
|
|
316
|
+
"Collections": "Cuotas",
|
|
317
|
+
"Subscriptions": "Subscripciones",
|
|
318
|
+
"total": "TOTAL"
|
|
319
|
+
},
|
|
320
|
+
"months": {
|
|
321
|
+
"1": "Enero",
|
|
322
|
+
"2": "Febrero",
|
|
323
|
+
"3": "Marzo",
|
|
324
|
+
"4": "Abril",
|
|
325
|
+
"5": "Mayo",
|
|
326
|
+
"6": "Junio",
|
|
327
|
+
"7": "Julio",
|
|
328
|
+
"8": "Agosto",
|
|
329
|
+
"9": "Septiembre",
|
|
330
|
+
"10": "Octubre",
|
|
331
|
+
"11": "Noviembre",
|
|
332
|
+
"12": "Diciembre"
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./store/
|
|
2
|
-
export * from "./store/
|
|
1
|
+
export * from "./store/ApiStore";
|
|
2
|
+
export * from "./store/AppStore";
|
|
3
3
|
export * from "./store/StoreManager";
|
|
4
|
+
export * from "./store/RenderManager";
|
|
4
5
|
export * from "./ui/Controller";
|
|
5
6
|
export * from "./ui/createComponent";
|
|
6
7
|
export * from "./utils/QueryBuilder";
|
package/dist/index.js
CHANGED
|
@@ -13,12 +13,22 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./store/
|
|
20
|
+
const StoreManager_1 = __importDefault(require("./store/StoreManager"));
|
|
21
|
+
__exportStar(require("./store/ApiStore"), exports);
|
|
22
|
+
__exportStar(require("./store/AppStore"), exports);
|
|
19
23
|
__exportStar(require("./store/StoreManager"), exports);
|
|
24
|
+
__exportStar(require("./store/RenderManager"), exports);
|
|
20
25
|
__exportStar(require("./ui/Controller"), exports);
|
|
21
26
|
__exportStar(require("./ui/createComponent"), exports);
|
|
22
27
|
__exportStar(require("./utils/QueryBuilder"), exports);
|
|
23
28
|
__exportStar(require("./utils/Toast"), exports);
|
|
24
29
|
__exportStar(require("./utils/TokenHelper"), exports);
|
|
30
|
+
// Inicializa los stores si existen
|
|
31
|
+
try {
|
|
32
|
+
StoreManager_1.default.init(require('./auto-register.mjs').default);
|
|
33
|
+
}
|
|
34
|
+
catch (e) { }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type ComponentId = symbol;
|
|
2
|
+
/**
|
|
3
|
+
{
|
|
4
|
+
store1: {
|
|
5
|
+
path1: {
|
|
6
|
+
component1: true,
|
|
7
|
+
component2: true,
|
|
8
|
+
},
|
|
9
|
+
path2: {
|
|
10
|
+
component1: true,
|
|
11
|
+
},
|
|
12
|
+
path3: {
|
|
13
|
+
component1: true,
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
*/
|
|
18
|
+
export declare class RenderManager {
|
|
19
|
+
private dependenciesMap;
|
|
20
|
+
private hooksMap;
|
|
21
|
+
/**
|
|
22
|
+
* Registra un hook de re-render para un componente
|
|
23
|
+
* @param componentId - El id del componente
|
|
24
|
+
* @param hook - El hook de re-render
|
|
25
|
+
*/
|
|
26
|
+
register(componentId: ComponentId, hook: () => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Agrega una dependencia de path a un componente
|
|
29
|
+
* @param componentId - El id del componente
|
|
30
|
+
* @param path - El path del estado
|
|
31
|
+
* @param storeName - El nombre del store
|
|
32
|
+
*/
|
|
33
|
+
dependsOn(componentId: ComponentId, path: string, storeName: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Actualiza los componentes que dependen de este path
|
|
36
|
+
* @param path - El path del estado
|
|
37
|
+
* @param storeName - El nombre del store
|
|
38
|
+
*/
|
|
39
|
+
refresh(path: string, storeName: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Elimina un componente del manager
|
|
42
|
+
* @param componentId - El id del componente
|
|
43
|
+
*/
|
|
44
|
+
unregister(componentId: ComponentId): void;
|
|
45
|
+
}
|
|
46
|
+
declare const _default: RenderManager;
|
|
47
|
+
export default _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RenderManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
{
|
|
6
|
+
store1: {
|
|
7
|
+
path1: {
|
|
8
|
+
component1: true,
|
|
9
|
+
component2: true,
|
|
10
|
+
},
|
|
11
|
+
path2: {
|
|
12
|
+
component1: true,
|
|
13
|
+
},
|
|
14
|
+
path3: {
|
|
15
|
+
component1: true,
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
*/
|
|
20
|
+
class RenderManager {
|
|
21
|
+
dependenciesMap = new Map();
|
|
22
|
+
hooksMap = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* Registra un hook de re-render para un componente
|
|
25
|
+
* @param componentId - El id del componente
|
|
26
|
+
* @param hook - El hook de re-render
|
|
27
|
+
*/
|
|
28
|
+
register(componentId, hook) {
|
|
29
|
+
this.hooksMap.set(componentId, hook);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Agrega una dependencia de path a un componente
|
|
33
|
+
* @param componentId - El id del componente
|
|
34
|
+
* @param path - El path del estado
|
|
35
|
+
* @param storeName - El nombre del store
|
|
36
|
+
*/
|
|
37
|
+
dependsOn(componentId, path, storeName) {
|
|
38
|
+
// Si no existe el store, crea un nuevo mapa
|
|
39
|
+
if (!this.dependenciesMap.has(storeName)) {
|
|
40
|
+
this.dependenciesMap.set(storeName, new Map());
|
|
41
|
+
}
|
|
42
|
+
// Si no existe el path, crea un nuevo conjunto
|
|
43
|
+
if (!this.dependenciesMap.get(storeName)?.has(path)) {
|
|
44
|
+
this.dependenciesMap.get(storeName)?.set(path, new Set());
|
|
45
|
+
}
|
|
46
|
+
// Agrega el componente al conjunto de dependencias
|
|
47
|
+
this.dependenciesMap.get(storeName)?.get(path)?.add(componentId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Actualiza los componentes que dependen de este path
|
|
51
|
+
* @param path - El path del estado
|
|
52
|
+
* @param storeName - El nombre del store
|
|
53
|
+
*/
|
|
54
|
+
refresh(path, storeName) {
|
|
55
|
+
// Obtiene los componentes que dependen de este path
|
|
56
|
+
const components = this.dependenciesMap.get(storeName)?.get(path);
|
|
57
|
+
// Si hay componentes que dependen de este path, actualiza cada uno
|
|
58
|
+
if (components) {
|
|
59
|
+
components.forEach((componentId) => {
|
|
60
|
+
this.hooksMap.get(componentId)?.();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Elimina un componente del manager
|
|
66
|
+
* @param componentId - El id del componente
|
|
67
|
+
*/
|
|
68
|
+
unregister(componentId) {
|
|
69
|
+
this.hooksMap.delete(componentId);
|
|
70
|
+
this.dependenciesMap.forEach((store) => {
|
|
71
|
+
store.forEach((path) => {
|
|
72
|
+
path.delete(componentId);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.RenderManager = RenderManager;
|
|
78
|
+
exports.default = new RenderManager();
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ApiResponse } from "@nano-app/backend";
|
|
2
|
-
import {
|
|
2
|
+
import { AppStore, StoreData } from "./AppStore";
|
|
3
3
|
export type ApiRequest = (query: string, body?: unknown) => Promise<ApiResponse>;
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class ApiStore extends AppStore {
|
|
5
5
|
private baseUrl;
|
|
6
|
-
|
|
6
|
+
private busyCount;
|
|
7
|
+
constructor(initialData?: StoreData, storeName?: string, baseUrl?: string);
|
|
7
8
|
create: ApiRequest;
|
|
8
9
|
read: ApiRequest;
|
|
9
10
|
update: ApiRequest;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.ApiStore = void 0;
|
|
4
|
+
const AppStore_1 = require("./AppStore");
|
|
5
5
|
const QueryBuilder_1 = require("../utils/QueryBuilder");
|
|
6
6
|
const TokenHelper_1 = require("../utils/TokenHelper");
|
|
7
7
|
const Toast_1 = require("../utils/Toast");
|
|
8
|
-
class
|
|
8
|
+
class ApiStore extends AppStore_1.AppStore {
|
|
9
9
|
baseUrl;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
busyCount = 0;
|
|
11
|
+
constructor(initialData = {}, storeName = "", baseUrl = "/api") {
|
|
12
|
+
super({}, storeName);
|
|
12
13
|
this.baseUrl = baseUrl;
|
|
13
14
|
}
|
|
14
15
|
create = (entity, body) => this.request("POST", entity, body);
|
|
@@ -22,7 +23,7 @@ class ApiClient extends StoreClient_1.StoreClient {
|
|
|
22
23
|
delete = (entity, id) => this.request("DELETE", entity, id);
|
|
23
24
|
async request(method, path, body) {
|
|
24
25
|
let oResponse = { result: null, success: false, message: "", warning: false };
|
|
25
|
-
this.
|
|
26
|
+
this.busyCount++;
|
|
26
27
|
this.set("/busy", true);
|
|
27
28
|
try {
|
|
28
29
|
oResponse = await fetch(`${this.baseUrl}${path}`, {
|
|
@@ -40,12 +41,11 @@ class ApiClient extends StoreClient_1.StoreClient {
|
|
|
40
41
|
console.error(error);
|
|
41
42
|
}
|
|
42
43
|
finally {
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
if (remaining < 1)
|
|
44
|
+
this.busyCount--;
|
|
45
|
+
if (this.busyCount < 1)
|
|
46
46
|
this.set("/busy", false);
|
|
47
47
|
}
|
|
48
48
|
return oResponse;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
exports.
|
|
51
|
+
exports.ApiStore = ApiStore;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type StoreData = Record<string, any>;
|
|
2
|
+
export declare class AppStore {
|
|
3
|
+
protected name: string;
|
|
4
|
+
private state;
|
|
5
|
+
constructor(initialData?: StoreData, name?: string);
|
|
6
|
+
/**
|
|
7
|
+
* Gestiona el estado de la store
|
|
8
|
+
* @param path - El path del estado
|
|
9
|
+
* @param value - El valor a asignar
|
|
10
|
+
* @returns El valor del estado
|
|
11
|
+
*/
|
|
12
|
+
private manageState;
|
|
13
|
+
/**
|
|
14
|
+
* Obtiene el valor del estado
|
|
15
|
+
* @param path - El path del estado
|
|
16
|
+
* @returns El valor del estado
|
|
17
|
+
*/
|
|
18
|
+
get(path: string): any;
|
|
19
|
+
/**
|
|
20
|
+
* Asigna un valor al estado
|
|
21
|
+
* @param path - El path del estado
|
|
22
|
+
* @param value - El valor a asignar
|
|
23
|
+
*/
|
|
24
|
+
set(path: string, value: any): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AppStore = void 0;
|
|
7
|
+
const RenderManager_1 = __importDefault(require("./RenderManager"));
|
|
8
|
+
class AppStore {
|
|
9
|
+
name;
|
|
10
|
+
state;
|
|
11
|
+
constructor(initialData = {}, name = "app") {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.state = initialData;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gestiona el estado de la store
|
|
17
|
+
* @param path - El path del estado
|
|
18
|
+
* @param value - El valor a asignar
|
|
19
|
+
* @returns El valor del estado
|
|
20
|
+
*/
|
|
21
|
+
manageState(path, value) {
|
|
22
|
+
// Divide el path en segmentos y obtiene el ultimo segmento
|
|
23
|
+
const segments = path.split("/").filter(Boolean);
|
|
24
|
+
if (segments.length === 0)
|
|
25
|
+
return this.state;
|
|
26
|
+
const last = segments.pop();
|
|
27
|
+
// Recorre los segmentos y crea el objeto si no existe
|
|
28
|
+
let current = this.state;
|
|
29
|
+
for (const seg of segments) {
|
|
30
|
+
if (current[seg] == null)
|
|
31
|
+
current[seg] = {};
|
|
32
|
+
current = current[seg];
|
|
33
|
+
}
|
|
34
|
+
// Si se proporciona un valor, lo asigna al ultimo segmento
|
|
35
|
+
if (arguments.length >= 2) {
|
|
36
|
+
current[last] = value;
|
|
37
|
+
}
|
|
38
|
+
// Retorna el valor del ultimo segmento
|
|
39
|
+
return current[last];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Obtiene el valor del estado
|
|
43
|
+
* @param path - El path del estado
|
|
44
|
+
* @returns El valor del estado
|
|
45
|
+
*/
|
|
46
|
+
get(path) {
|
|
47
|
+
return this.manageState(path);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Asigna un valor al estado
|
|
51
|
+
* @param path - El path del estado
|
|
52
|
+
* @param value - El valor a asignar
|
|
53
|
+
*/
|
|
54
|
+
set(path, value) {
|
|
55
|
+
RenderManager_1.default.refresh(path, this.name);
|
|
56
|
+
this.manageState(path, value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.AppStore = AppStore;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type ComponentId = symbol;
|
|
2
|
+
/**
|
|
3
|
+
{
|
|
4
|
+
store1: {
|
|
5
|
+
path1: {
|
|
6
|
+
component1: true,
|
|
7
|
+
component2: true,
|
|
8
|
+
},
|
|
9
|
+
path2: {
|
|
10
|
+
component1: true,
|
|
11
|
+
},
|
|
12
|
+
path3: {
|
|
13
|
+
component1: true,
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
*/
|
|
18
|
+
export declare class RenderManager {
|
|
19
|
+
private dependenciesMap;
|
|
20
|
+
private hooksMap;
|
|
21
|
+
/**
|
|
22
|
+
* Registra un hook de re-render para un componente
|
|
23
|
+
* @param componentId - El id del componente
|
|
24
|
+
* @param hook - El hook de re-render
|
|
25
|
+
*/
|
|
26
|
+
register(componentId: ComponentId, hook: () => void): void;
|
|
27
|
+
/**
|
|
28
|
+
* Agrega una dependencia de path a un componente
|
|
29
|
+
* @param componentId - El id del componente
|
|
30
|
+
* @param path - El path del estado
|
|
31
|
+
* @param storeName - El nombre del store
|
|
32
|
+
*/
|
|
33
|
+
dependsOn(componentId: ComponentId, path: string, storeName: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Actualiza los componentes que dependen de este path
|
|
36
|
+
* @param path - El path del estado
|
|
37
|
+
* @param storeName - El nombre del store
|
|
38
|
+
*/
|
|
39
|
+
refresh(path: string, storeName: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Elimina un componente del manager
|
|
42
|
+
* @param componentId - El id del componente
|
|
43
|
+
*/
|
|
44
|
+
unregister(componentId: ComponentId): void;
|
|
45
|
+
}
|
|
46
|
+
declare const _default: RenderManager;
|
|
47
|
+
export default _default;
|