cradova 1.4.1 → 1.5.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/README.md +58 -28
- package/dist/index.d.ts +41 -53
- package/dist/index.js +65 -138
- package/dist/types.ts +12 -115
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div style="display: flex; align-items:center; justify-content: space-around; width: 100%;">
|
|
2
|
+
<h1 style="border: none"> Cradova</h1>
|
|
3
|
+
<a><img src="cradova.png" alt="cradova logo" width="100" height="100"></a>
|
|
4
|
+
</div>
|
|
5
|
+
<br>
|
|
6
|
+
<hr>
|
|
7
|
+
<br>
|
|
8
|
+
<br>
|
|
2
9
|
|
|
3
|
-
# Cradova.js
|
|
4
10
|
[](https://www.npmjs.com/package/cradova)
|
|
5
11
|
[](https://github.com/cradova/cradova.js/blob/next/LICENSE)
|
|
6
12
|
[](https://www.npmjs.com/package/cradova)
|
|
@@ -8,28 +14,33 @@
|
|
|
8
14
|
[](https://opencollective.com/cradova)
|
|
9
15
|
[](https://github.com/cradova/cradova.js/blob/next/contributing.md)
|
|
10
16
|
|
|
11
|
-
|
|
12
17
|
## Contents
|
|
13
18
|
|
|
14
|
-
- [What is Cradova](#what-is-
|
|
15
|
-
- [Why
|
|
19
|
+
- [What is Cradova](#what-is-cradova)
|
|
20
|
+
- [Why Cradova?](#whats-the-benefit)
|
|
16
21
|
- [Installation](#installation)
|
|
17
22
|
- [Examples](#examples)
|
|
18
23
|
- [Documentation](#documentation)
|
|
19
24
|
- [Getting Help](#getting-help)
|
|
20
25
|
- [Contributing](#contributing)
|
|
21
26
|
|
|
22
|
-
## What is
|
|
27
|
+
## What is Cradova?
|
|
23
28
|
|
|
24
29
|
Cradova is a JavaScript framework for building Single Page Applications and PWAs.
|
|
25
30
|
|
|
26
|
-
It's small, fast and provides state management, routing and
|
|
31
|
+
It's small, fast and provides state management, routing and a rest API utility out of the box.
|
|
32
|
+
|
|
33
|
+
Cradova follows the [VJS specification](https://github.com/fridaycandour/cradova/blob/main/spec.md)
|
|
27
34
|
|
|
28
35
|
## What's the benefit?
|
|
29
|
-
We aim to be fast and simple with and no hidden abstractions whatsoever.
|
|
30
|
-
We don't use visual DOM or any diff algorithms to manage the DOM.
|
|
31
36
|
|
|
32
|
-
Cradova
|
|
37
|
+
Cradova is aimed to be fast and simple with and fewer abstractions and yet easily composable.
|
|
38
|
+
|
|
39
|
+
We don't use visual DOM or diff algorithms to manage the DOM.
|
|
40
|
+
|
|
41
|
+
State management is done more elegantly with the predictive model, manually and easily with all the speed.
|
|
42
|
+
|
|
43
|
+
Cradova has been used on a couple of projects in production and we will update this page to reflect our progress as we keep improving.
|
|
33
44
|
|
|
34
45
|
## Installation
|
|
35
46
|
|
|
@@ -51,36 +62,38 @@ Cradova has been used in production and we will update this README to reflect ou
|
|
|
51
62
|
npm i cradova
|
|
52
63
|
```
|
|
53
64
|
|
|
54
|
-
|
|
55
65
|
## Examples
|
|
66
|
+
|
|
56
67
|
Many aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.
|
|
57
68
|
|
|
58
69
|
Here's an example of create a basic component in Cradova:
|
|
59
70
|
|
|
60
71
|
```js
|
|
61
|
-
import _
|
|
72
|
+
import _ from "cradova";
|
|
62
73
|
|
|
63
74
|
function Hello(name) {
|
|
64
75
|
return _("h1", "Hello " + name);
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
// document fragment empty cradova call _()
|
|
79
|
+
|
|
80
|
+
const html = _(Hello("peter"), Hello("joe"));
|
|
81
|
+
|
|
71
82
|
document.body.append(html);
|
|
72
83
|
```
|
|
73
84
|
|
|
74
85
|
## Using Screen
|
|
86
|
+
|
|
75
87
|
```js
|
|
76
88
|
import _, { Screen, Router } from "cradova";
|
|
77
89
|
|
|
78
90
|
function HelloMessage(name) {
|
|
79
91
|
// an effect run once after screen renders
|
|
80
92
|
this.effect(() => {
|
|
81
|
-
|
|
93
|
+
const name = new Promise((res) => {
|
|
82
94
|
res("friday");
|
|
83
95
|
});
|
|
96
|
+
this.updateState(await name)
|
|
84
97
|
});
|
|
85
98
|
// effects can be used to make api calls needed for the page
|
|
86
99
|
return _("div", "Hello " + name);
|
|
@@ -129,10 +142,21 @@ function counter() {
|
|
|
129
142
|
});
|
|
130
143
|
}
|
|
131
144
|
|
|
132
|
-
function
|
|
145
|
+
function dataCounter() {
|
|
146
|
+
return _("h1| 0", {
|
|
147
|
+
shouldUpdate: true,
|
|
148
|
+
$num: "0", // data-num
|
|
149
|
+
onclick() {
|
|
150
|
+
const num = Number(this.getAttribute("data-num")) + 1;
|
|
151
|
+
this.updateState({ text: num, $num: num });
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function HelloMessage(name = "no name") {
|
|
133
157
|
return _("div.foo#bar", {
|
|
134
158
|
shouldUpdate: true,
|
|
135
|
-
text: "hello " +
|
|
159
|
+
text: "hello " + name,
|
|
136
160
|
onclick() {
|
|
137
161
|
const name = prompt("what are your names");
|
|
138
162
|
this.updateState({ text: "hello " + name });
|
|
@@ -140,13 +164,13 @@ function HelloMessage(name) {
|
|
|
140
164
|
});
|
|
141
165
|
}
|
|
142
166
|
|
|
143
|
-
const nameRef = new Ref(function (
|
|
167
|
+
const nameRef = new Ref(function ( name ) {
|
|
144
168
|
const self = this;
|
|
145
169
|
return _("div.foo#bar", {
|
|
146
170
|
text: "hello" + (name || "no name"),
|
|
147
171
|
onclick() {
|
|
148
172
|
const name = prompt();
|
|
149
|
-
self.updateState(
|
|
173
|
+
self.updateState(name);
|
|
150
174
|
},
|
|
151
175
|
});
|
|
152
176
|
});
|
|
@@ -154,8 +178,9 @@ const nameRef = new Ref(function ({ name }) {
|
|
|
154
178
|
function Home() {
|
|
155
179
|
return _("div.foo#bar",
|
|
156
180
|
counter,
|
|
181
|
+
dataCounter,
|
|
157
182
|
HelloMessage,
|
|
158
|
-
nameRef.render(
|
|
183
|
+
nameRef.render( "no name" )
|
|
159
184
|
);
|
|
160
185
|
}
|
|
161
186
|
|
|
@@ -169,22 +194,27 @@ Router.route("/", home);
|
|
|
169
194
|
```
|
|
170
195
|
|
|
171
196
|
## Documentation
|
|
197
|
+
|
|
172
198
|
We are currently building cradova's documentation and we have only a few hands, if you're interested in helping you can join the community, learn first hand, and support cradova's progress.
|
|
173
199
|
|
|
174
200
|
## Getting Help
|
|
201
|
+
|
|
175
202
|
To get further insights and help on Cradova, visit our new [Telegram Community Chat](https://t.me/cradovaframework).
|
|
176
203
|
|
|
177
204
|
## Contributing
|
|
178
|
-
We are currently working to set up:
|
|
179
205
|
|
|
206
|
+
We are currently working to [set](https://github.com/fridaycandour/cradova/blob/main/contributing.md) up the following:
|
|
207
|
+
|
|
208
|
+
- building cradova CLI (in progress)
|
|
180
209
|
- Cradova Documentation Website
|
|
181
210
|
- UI component libraries for cradova
|
|
182
211
|
- Sample projects
|
|
183
212
|
- maintenance and promotion
|
|
184
|
-
- building cradova CLI
|
|
185
|
-
|
|
186
213
|
|
|
187
214
|
## Sponsor
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
215
|
+
|
|
216
|
+
Your support is appreciated and needed to advance Cradova for more performance and improvements.
|
|
217
|
+
|
|
218
|
+
Sponsorships can be done via [Patreon](https://www.patreon.com/FridayCandour) and [KO-FI](https://www.ko-fi.com/fridaycandour).
|
|
219
|
+
|
|
220
|
+
Both monthly-recurring sponsorships and one-time donations are accepted.
|
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ declare module "cradova" {
|
|
|
35
35
|
updateState(data: unknown): void;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
type
|
|
39
|
-
|
|
40
|
-
type RefType = {
|
|
38
|
+
export type RefType<D> = {
|
|
41
39
|
/**
|
|
42
40
|
* Cradova Ref
|
|
43
41
|
* ---
|
|
@@ -45,7 +43,7 @@ declare module "cradova" {
|
|
|
45
43
|
* @param data
|
|
46
44
|
* @returns HTMLElement
|
|
47
45
|
*/
|
|
48
|
-
render(data?:
|
|
46
|
+
render(data?: D): () => any;
|
|
49
47
|
/**
|
|
50
48
|
* Cradova Ref
|
|
51
49
|
* ---
|
|
@@ -61,7 +59,7 @@ declare module "cradova" {
|
|
|
61
59
|
* @param data
|
|
62
60
|
* @returns void
|
|
63
61
|
*/
|
|
64
|
-
updateState(data:
|
|
62
|
+
updateState(data: D, stash?: boolean): void;
|
|
65
63
|
/**
|
|
66
64
|
* Cradova Ref
|
|
67
65
|
* ---
|
|
@@ -77,7 +75,15 @@ declare module "cradova" {
|
|
|
77
75
|
*
|
|
78
76
|
*/
|
|
79
77
|
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
78
|
+
/**
|
|
79
|
+
* Cradova Ref
|
|
80
|
+
* ---
|
|
81
|
+
* returns last set stashed Ref data
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
stash: D;
|
|
80
85
|
};
|
|
86
|
+
|
|
81
87
|
/**
|
|
82
88
|
* Cradova Router
|
|
83
89
|
* ---
|
|
@@ -235,7 +241,7 @@ declare module "cradova" {
|
|
|
235
241
|
* - update a cradova Ref automatically
|
|
236
242
|
* @constructor initial: any, props: {useHistory, persist}
|
|
237
243
|
*/
|
|
238
|
-
export class createSignal {
|
|
244
|
+
export class createSignal<Type> {
|
|
239
245
|
private callback;
|
|
240
246
|
private persistName;
|
|
241
247
|
private actions;
|
|
@@ -246,7 +252,7 @@ declare module "cradova" {
|
|
|
246
252
|
private path;
|
|
247
253
|
value: any;
|
|
248
254
|
constructor(
|
|
249
|
-
initial:
|
|
255
|
+
initial: Type,
|
|
250
256
|
props?: {
|
|
251
257
|
useHistory?: boolean;
|
|
252
258
|
persistName?: string | undefined;
|
|
@@ -259,46 +265,21 @@ declare module "cradova" {
|
|
|
259
265
|
* @param value - signal value
|
|
260
266
|
* @returns void
|
|
261
267
|
*/
|
|
262
|
-
set(value:
|
|
268
|
+
set(value: Type, shouldRefRender?: boolean): void;
|
|
263
269
|
/**
|
|
264
270
|
* Cradova Signal
|
|
265
271
|
* ----
|
|
266
272
|
* set a key value if it's an object
|
|
267
273
|
* @param name - name of the key
|
|
268
274
|
* @param value - value of the key
|
|
275
|
+
* @param shouldRefRender? boolean
|
|
269
276
|
* @returns void
|
|
277
|
+
*
|
|
278
|
+
*
|
|
279
|
+
* .
|
|
280
|
+
*
|
|
270
281
|
*/
|
|
271
|
-
setKey(name: string, value:
|
|
272
|
-
/**
|
|
273
|
-
* Cradova Signal
|
|
274
|
-
* ----
|
|
275
|
-
* set a prop value inside an object prop of the store
|
|
276
|
-
* @param key - a prop of the store - object value
|
|
277
|
-
* @param name - prop of the key object
|
|
278
|
-
* @param value - value of the name
|
|
279
|
-
* @returns void
|
|
280
|
-
*/
|
|
281
|
-
setPath(
|
|
282
|
-
key: string,
|
|
283
|
-
name: string,
|
|
284
|
-
value: any,
|
|
285
|
-
shouldRefRender?: boolean
|
|
286
|
-
): void;
|
|
287
|
-
/**
|
|
288
|
-
* Cradova Signal
|
|
289
|
-
* ----
|
|
290
|
-
* set a prop value inside an array prop of the store
|
|
291
|
-
* @param key - a prop of the store - object value
|
|
292
|
-
* @param index - index of the key object
|
|
293
|
-
* @param value - value of the index
|
|
294
|
-
* @returns void
|
|
295
|
-
*/
|
|
296
|
-
setIndex(
|
|
297
|
-
key: string,
|
|
298
|
-
index: number,
|
|
299
|
-
value: any,
|
|
300
|
-
shouldRefRender?: boolean
|
|
301
|
-
): void;
|
|
282
|
+
setKey(name: string, value: unknown, shouldRefRender?: boolean): void;
|
|
302
283
|
/**
|
|
303
284
|
* Cradova Signal
|
|
304
285
|
* ----
|
|
@@ -307,8 +288,8 @@ declare module "cradova" {
|
|
|
307
288
|
* @param action function to execute
|
|
308
289
|
*/
|
|
309
290
|
createAction(
|
|
310
|
-
name: string | Record<string, (self?:
|
|
311
|
-
action?: (self?:
|
|
291
|
+
name: string | Record<string, (self?: this, data?: Type) => void>,
|
|
292
|
+
action?: (self?: this, data?: any) => void
|
|
312
293
|
): void;
|
|
313
294
|
/**
|
|
314
295
|
* Cradova Signal
|
|
@@ -317,7 +298,7 @@ declare module "cradova" {
|
|
|
317
298
|
* @param name - string name of the action
|
|
318
299
|
* @param data - data for the action
|
|
319
300
|
*/
|
|
320
|
-
fireAction(name: string, data?:
|
|
301
|
+
fireAction(name: string, data?: Type): void;
|
|
321
302
|
/**
|
|
322
303
|
* Cradova Signal
|
|
323
304
|
* ----
|
|
@@ -347,7 +328,7 @@ declare module "cradova" {
|
|
|
347
328
|
* set a update listener on value changes
|
|
348
329
|
* @param callback
|
|
349
330
|
*/
|
|
350
|
-
listen(callback: (
|
|
331
|
+
listen(callback: (data: Type) => void): void;
|
|
351
332
|
/**
|
|
352
333
|
* Cradova Signal
|
|
353
334
|
* ----
|
|
@@ -367,10 +348,10 @@ declare module "cradova" {
|
|
|
367
348
|
* @constructor initial: any, Ref: any
|
|
368
349
|
*/
|
|
369
350
|
|
|
370
|
-
export class
|
|
351
|
+
export class $<Type> {
|
|
371
352
|
private ref;
|
|
372
353
|
value: any;
|
|
373
|
-
constructor(initial:
|
|
354
|
+
constructor(initial: Type);
|
|
374
355
|
/**
|
|
375
356
|
* Cradova simpleStore
|
|
376
357
|
* ----
|
|
@@ -378,7 +359,7 @@ declare module "cradova" {
|
|
|
378
359
|
* @param value - simpleStore value
|
|
379
360
|
* @returns void
|
|
380
361
|
*/
|
|
381
|
-
set(value:
|
|
362
|
+
set(value: Type, shouldRefRender?: boolean): void;
|
|
382
363
|
/**
|
|
383
364
|
* Cradova simpleStore
|
|
384
365
|
* ----
|
|
@@ -387,7 +368,7 @@ declare module "cradova" {
|
|
|
387
368
|
* @param value - value of the key
|
|
388
369
|
* @returns void
|
|
389
370
|
*/
|
|
390
|
-
setKey(name: string, value:
|
|
371
|
+
setKey(name: string, value: unknown, shouldRefRender?: boolean): void;
|
|
391
372
|
/**
|
|
392
373
|
* Cradova simpleStore
|
|
393
374
|
* ---
|
|
@@ -414,9 +395,9 @@ declare module "cradova" {
|
|
|
414
395
|
url: string | URL,
|
|
415
396
|
opts?:
|
|
416
397
|
| {
|
|
417
|
-
method?:
|
|
398
|
+
method?: "GET" | "POST";
|
|
418
399
|
data?: Record<string, any>;
|
|
419
|
-
header?: Record<string, any>;
|
|
400
|
+
header?: { "content-type": string } & Record<string, any>;
|
|
420
401
|
callbacks?: Record<string, (arg: any) => void>;
|
|
421
402
|
}
|
|
422
403
|
| any
|
|
@@ -480,8 +461,8 @@ css(".btn:hover",
|
|
|
480
461
|
* create dynamic components
|
|
481
462
|
*
|
|
482
463
|
*/
|
|
483
|
-
export class Ref {
|
|
484
|
-
constructor(component: (
|
|
464
|
+
export class Ref<D> {
|
|
465
|
+
constructor(component: (data: D) => any);
|
|
485
466
|
/**
|
|
486
467
|
* Cradova Ref
|
|
487
468
|
* ---
|
|
@@ -489,7 +470,7 @@ css(".btn:hover",
|
|
|
489
470
|
* @param data
|
|
490
471
|
* @returns HTMLElement
|
|
491
472
|
*/
|
|
492
|
-
render(data?:
|
|
473
|
+
render(data?: D, stash?: boolean): () => any;
|
|
493
474
|
/**
|
|
494
475
|
* Cradova Ref
|
|
495
476
|
* ---
|
|
@@ -505,7 +486,7 @@ css(".btn:hover",
|
|
|
505
486
|
* @param data
|
|
506
487
|
* @returns void
|
|
507
488
|
*/
|
|
508
|
-
updateState(data:
|
|
489
|
+
updateState(data: D, stashed?: boolean): void;
|
|
509
490
|
/**
|
|
510
491
|
* Cradova Ref
|
|
511
492
|
* ---
|
|
@@ -521,6 +502,13 @@ css(".btn:hover",
|
|
|
521
502
|
*
|
|
522
503
|
*/
|
|
523
504
|
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
505
|
+
/**
|
|
506
|
+
* Cradova Ref
|
|
507
|
+
* ---
|
|
508
|
+
* returns last set stashed Ref data
|
|
509
|
+
*
|
|
510
|
+
*/
|
|
511
|
+
stash: D;
|
|
524
512
|
}
|
|
525
513
|
|
|
526
514
|
/**
|
package/dist/index.js
CHANGED
|
@@ -89,7 +89,6 @@ var createSignal = class {
|
|
|
89
89
|
this.history = [];
|
|
90
90
|
this.index = 0;
|
|
91
91
|
this.path = null;
|
|
92
|
-
this.value = null;
|
|
93
92
|
this.value = initial;
|
|
94
93
|
if (props && props.persistName) {
|
|
95
94
|
this.persistName = props.persistName;
|
|
@@ -125,7 +124,7 @@ var createSignal = class {
|
|
|
125
124
|
if (!this.useHistory)
|
|
126
125
|
return;
|
|
127
126
|
this.index += 1;
|
|
128
|
-
this.history.push(value);
|
|
127
|
+
this.history.push(this.value);
|
|
129
128
|
}
|
|
130
129
|
setKey(name, value, shouldRefRender) {
|
|
131
130
|
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
@@ -147,37 +146,13 @@ var createSignal = class {
|
|
|
147
146
|
return;
|
|
148
147
|
this.history.push(this.value);
|
|
149
148
|
this.index += 1;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
setPath(key, name, value, shouldRefRender) {
|
|
153
|
-
if (this.value[key]) {
|
|
154
|
-
this.value[key][name] = value;
|
|
155
|
-
} else {
|
|
156
|
-
this.value[key] = { [name]: [value] };
|
|
157
|
-
}
|
|
158
|
-
if (this.ref && shouldRefRender !== false) {
|
|
159
|
-
if (this.path) {
|
|
160
|
-
this.ref.updateState(this.value[this.path]);
|
|
161
|
-
} else {
|
|
162
|
-
this.ref.updateState(this.value);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
setIndex(key, index, value, shouldRefRender) {
|
|
167
|
-
if (Array.isArray(this.value[key])) {
|
|
168
|
-
this.value[key][index] = value;
|
|
169
149
|
} else {
|
|
170
150
|
throw new Error(
|
|
171
|
-
|
|
151
|
+
`\u2718 Cradova err : can't set key ${String(
|
|
152
|
+
name
|
|
153
|
+
)} . store value is not a javascript object`
|
|
172
154
|
);
|
|
173
155
|
}
|
|
174
|
-
if (this.ref && shouldRefRender !== false) {
|
|
175
|
-
if (this.path) {
|
|
176
|
-
this.ref.updateState(this.value[this.path]);
|
|
177
|
-
} else {
|
|
178
|
-
this.ref.updateState(this.value);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
156
|
}
|
|
182
157
|
createAction(name, action) {
|
|
183
158
|
if (typeof name === "string" && typeof action === "function") {
|
|
@@ -240,7 +215,7 @@ var createSignal = class {
|
|
|
240
215
|
}
|
|
241
216
|
clearPersist() {
|
|
242
217
|
if (this.persistName) {
|
|
243
|
-
localStorage.
|
|
218
|
+
localStorage.removeItem(this.persistName);
|
|
244
219
|
}
|
|
245
220
|
}
|
|
246
221
|
};
|
|
@@ -274,7 +249,7 @@ function css(identifier, properties) {
|
|
|
274
249
|
}
|
|
275
250
|
styTag = document.createElement("style");
|
|
276
251
|
styTag.textContent = identifier;
|
|
277
|
-
document.head.
|
|
252
|
+
document.head.appendChild(styTag);
|
|
278
253
|
return;
|
|
279
254
|
}
|
|
280
255
|
if (!properties) {
|
|
@@ -302,7 +277,7 @@ function css(identifier, properties) {
|
|
|
302
277
|
`;
|
|
303
278
|
totalStyle += styS + style + styE;
|
|
304
279
|
styleTag.innerHTML = totalStyle;
|
|
305
|
-
document.head.
|
|
280
|
+
document.head.appendChild(styleTag);
|
|
306
281
|
}
|
|
307
282
|
function assert(condition, ...callback) {
|
|
308
283
|
if (condition) {
|
|
@@ -326,34 +301,20 @@ ls.retrieve = (name) => {
|
|
|
326
301
|
ls.remove = (name) => {
|
|
327
302
|
localStorage.removeItem(name);
|
|
328
303
|
};
|
|
329
|
-
ls.getKey = (index) => {
|
|
330
|
-
return window.localStorage.key(index);
|
|
331
|
-
};
|
|
332
|
-
ls.clear = () => {
|
|
333
|
-
localStorage.clear();
|
|
334
|
-
};
|
|
335
|
-
function fullScreen(e) {
|
|
336
|
-
return {
|
|
337
|
-
set() {
|
|
338
|
-
e.requestFullscreen().catch((err2) => {
|
|
339
|
-
throw err2;
|
|
340
|
-
});
|
|
341
|
-
},
|
|
342
|
-
exist() {
|
|
343
|
-
document.exitFullscreen();
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
304
|
var Ref = class {
|
|
348
305
|
constructor(component) {
|
|
349
306
|
this.stateID = uuid();
|
|
350
|
-
this.rendered = false;
|
|
351
307
|
this.effects = [];
|
|
352
308
|
this.effectuate = null;
|
|
309
|
+
this.rendered = false;
|
|
310
|
+
this.published = false;
|
|
353
311
|
this.hasFirstStateUpdateRun = false;
|
|
312
|
+
this.testName = null;
|
|
354
313
|
this.component = component.bind(this);
|
|
355
314
|
}
|
|
356
|
-
render(data) {
|
|
315
|
+
render(data, stash) {
|
|
316
|
+
this.rendered = false;
|
|
317
|
+
this.hasFirstStateUpdateRun = false;
|
|
357
318
|
const chtml = this.component(data);
|
|
358
319
|
if (typeof chtml !== "function") {
|
|
359
320
|
throw new Error(
|
|
@@ -368,17 +329,25 @@ var Ref = class {
|
|
|
368
329
|
\x1B[35m Exception: ref only a function that returns cradova element or cradova element tree. \x1B[35m
|
|
369
330
|
|
|
370
331
|
to track and debug this element add a
|
|
371
|
-
beforeMount or afterMount
|
|
332
|
+
beforeMount or afterMount property to the element
|
|
372
333
|
`
|
|
373
334
|
],
|
|
374
335
|
`Cradova can't render component make sure it's a valid component`
|
|
375
336
|
);
|
|
376
337
|
}
|
|
377
|
-
|
|
378
|
-
this.
|
|
338
|
+
if (stash) {
|
|
339
|
+
this.stash = data;
|
|
340
|
+
}
|
|
341
|
+
const av = () => __async(this, null, function* () {
|
|
342
|
+
yield this.effector.apply(this);
|
|
379
343
|
window.removeEventListener("cradova-aftermount", av);
|
|
380
|
-
};
|
|
381
|
-
|
|
344
|
+
});
|
|
345
|
+
if (!this.published) {
|
|
346
|
+
this.published = true;
|
|
347
|
+
window.addEventListener("cradova-aftermount", av);
|
|
348
|
+
} else {
|
|
349
|
+
this.effector();
|
|
350
|
+
}
|
|
382
351
|
return () => element;
|
|
383
352
|
}
|
|
384
353
|
instance() {
|
|
@@ -387,39 +356,32 @@ var Ref = class {
|
|
|
387
356
|
});
|
|
388
357
|
}
|
|
389
358
|
effect(fn) {
|
|
390
|
-
if (this.rendered) {
|
|
391
|
-
|
|
359
|
+
if (!this.rendered) {
|
|
360
|
+
this.effects.push(fn.bind(this));
|
|
392
361
|
}
|
|
393
|
-
fn = fn.bind(this);
|
|
394
|
-
this.effects.push(
|
|
395
|
-
new Promise((res, rej) => __async(this, null, function* () {
|
|
396
|
-
try {
|
|
397
|
-
yield fn();
|
|
398
|
-
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
399
|
-
this.hasFirstStateUpdateRun = true;
|
|
400
|
-
yield this.effectuate();
|
|
401
|
-
}
|
|
402
|
-
res(void 0);
|
|
403
|
-
} catch (error) {
|
|
404
|
-
rej(error);
|
|
405
|
-
}
|
|
406
|
-
}))
|
|
407
|
-
);
|
|
408
362
|
}
|
|
409
363
|
effector() {
|
|
410
364
|
return __async(this, null, function* () {
|
|
411
|
-
|
|
365
|
+
if (!this.rendered) {
|
|
366
|
+
for (const effect of this.effects) {
|
|
367
|
+
yield effect.apply(this);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
371
|
+
yield this.effectuate();
|
|
372
|
+
}
|
|
412
373
|
this.rendered = true;
|
|
413
374
|
this.hasFirstStateUpdateRun = true;
|
|
414
375
|
});
|
|
415
376
|
}
|
|
416
|
-
updateState(data) {
|
|
377
|
+
updateState(data, stash) {
|
|
417
378
|
if (!this.rendered) {
|
|
418
|
-
this.rendered = true;
|
|
419
379
|
function updateState(data2) {
|
|
420
380
|
return __async(this, null, function* () {
|
|
421
|
-
if (this.
|
|
381
|
+
if (this.rendered) {
|
|
422
382
|
yield this.Activate(data2);
|
|
383
|
+
this.rendered = true;
|
|
384
|
+
this.hasFirstStateUpdateRun = true;
|
|
423
385
|
} else {
|
|
424
386
|
setTimeout(updateState.bind(this, data2), 4);
|
|
425
387
|
}
|
|
@@ -429,7 +391,10 @@ var Ref = class {
|
|
|
429
391
|
} else {
|
|
430
392
|
(() => __async(this, null, function* () {
|
|
431
393
|
yield this.Activate(data);
|
|
432
|
-
}))
|
|
394
|
+
}))();
|
|
395
|
+
}
|
|
396
|
+
if (stash) {
|
|
397
|
+
this.stash = data;
|
|
433
398
|
}
|
|
434
399
|
}
|
|
435
400
|
Activate(data) {
|
|
@@ -473,7 +438,7 @@ var Ref = class {
|
|
|
473
438
|
dispatch(this.stateID, { remove: true });
|
|
474
439
|
}
|
|
475
440
|
};
|
|
476
|
-
var frag = function(
|
|
441
|
+
var frag = function(children) {
|
|
477
442
|
const par = document.createDocumentFragment();
|
|
478
443
|
for (let i = 0; i < children.length; i++) {
|
|
479
444
|
if (typeof children[i] === "function") {
|
|
@@ -481,7 +446,7 @@ var frag = function(...children) {
|
|
|
481
446
|
if (typeof a === "function") {
|
|
482
447
|
const b = a();
|
|
483
448
|
if (b instanceof HTMLElement) {
|
|
484
|
-
par.
|
|
449
|
+
par.appendChild(b);
|
|
485
450
|
} else {
|
|
486
451
|
if (!(b instanceof HTMLElement)) {
|
|
487
452
|
console.error(" \u2718 Cradova err: wrong element type" + b);
|
|
@@ -490,7 +455,7 @@ var frag = function(...children) {
|
|
|
490
455
|
}
|
|
491
456
|
} else {
|
|
492
457
|
if (a instanceof HTMLElement) {
|
|
493
|
-
par.
|
|
458
|
+
par.appendChild(a);
|
|
494
459
|
} else {
|
|
495
460
|
if (!(a instanceof HTMLElement)) {
|
|
496
461
|
console.error(" \u2718 Cradova err: wrong element type" + a);
|
|
@@ -533,21 +498,13 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
533
498
|
continue;
|
|
534
499
|
}
|
|
535
500
|
if (typeof element[key] === "function") {
|
|
536
|
-
element[key](element);
|
|
501
|
+
element[key].apply(element);
|
|
537
502
|
continue;
|
|
538
503
|
}
|
|
539
504
|
if (key === "text") {
|
|
540
505
|
element.innerText = state[key];
|
|
541
506
|
continue;
|
|
542
507
|
}
|
|
543
|
-
if (key === "fullscreen") {
|
|
544
|
-
if (state[key]) {
|
|
545
|
-
fullScreen(element).set();
|
|
546
|
-
} else {
|
|
547
|
-
fullScreen(element).exist();
|
|
548
|
-
}
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
508
|
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
552
509
|
const classes = state[key].split(" ");
|
|
553
510
|
for (let i2 = 0; i2 < classes.length; i2++) {
|
|
@@ -557,14 +514,6 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
557
514
|
}
|
|
558
515
|
continue;
|
|
559
516
|
}
|
|
560
|
-
if (key === "toggleclass" && state[key] !== "") {
|
|
561
|
-
element.classList.toggle(state[key]);
|
|
562
|
-
continue;
|
|
563
|
-
}
|
|
564
|
-
if (key === "removeclass" && state[key] !== "") {
|
|
565
|
-
element.classList.remove(state[key]);
|
|
566
|
-
continue;
|
|
567
|
-
}
|
|
568
517
|
if (key === "remove") {
|
|
569
518
|
if (element.parentElement) {
|
|
570
519
|
(_a = element.parentElement) == null ? void 0 : _a.removeChild(element);
|
|
@@ -578,31 +527,8 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
578
527
|
continue;
|
|
579
528
|
}
|
|
580
529
|
if (key === "tree") {
|
|
581
|
-
if (typeof state[key] === "function") {
|
|
582
|
-
state[key] = state[key]();
|
|
583
|
-
} else {
|
|
584
|
-
throw new TypeError(
|
|
585
|
-
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
if (typeof state[key] === "function") {
|
|
589
|
-
state[key] = state[key]();
|
|
590
|
-
}
|
|
591
|
-
if (Array.isArray(state[key])) {
|
|
592
|
-
throw new TypeError(
|
|
593
|
-
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
if (!(state[key] instanceof HTMLElement)) {
|
|
597
|
-
console.error(
|
|
598
|
-
" \u2718 Cradova err: wrong element type: can't update tree using " + state[key]
|
|
599
|
-
);
|
|
600
|
-
throw new TypeError(
|
|
601
|
-
" \u2718 Cradova err: invalid tree element type, should be a single parent cradova element tree"
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
530
|
element.innerHTML = "";
|
|
605
|
-
element.appendChild(state[key]);
|
|
531
|
+
element.appendChild(frag(state[key]));
|
|
606
532
|
continue;
|
|
607
533
|
}
|
|
608
534
|
try {
|
|
@@ -1005,7 +931,7 @@ RouterBox.router = function(e, force = false) {
|
|
|
1005
931
|
}
|
|
1006
932
|
});
|
|
1007
933
|
} catch (error) {
|
|
1008
|
-
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
934
|
+
const errorHandler = RouterBox.errorHandler[params && params.path || "all"];
|
|
1009
935
|
if (errorHandler) {
|
|
1010
936
|
errorHandler(error);
|
|
1011
937
|
}
|
|
@@ -1014,7 +940,7 @@ RouterBox.router = function(e, force = false) {
|
|
|
1014
940
|
if (RouterBox.routes["/404"]) {
|
|
1015
941
|
RouterBox.routes["/404"].controller(RouterBox.params);
|
|
1016
942
|
} else {
|
|
1017
|
-
const errorHandler = RouterBox.errorHandler[params.path || "all"];
|
|
943
|
+
const errorHandler = RouterBox.errorHandler[params && params.path || "all"];
|
|
1018
944
|
if (errorHandler) {
|
|
1019
945
|
errorHandler(
|
|
1020
946
|
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
@@ -1100,7 +1026,7 @@ var Screen = class {
|
|
|
1100
1026
|
}
|
|
1101
1027
|
effect(fn) {
|
|
1102
1028
|
if (!this.rendered) {
|
|
1103
|
-
this.effects.push(fn);
|
|
1029
|
+
this.effects.push(fn.bind(this));
|
|
1104
1030
|
}
|
|
1105
1031
|
}
|
|
1106
1032
|
effector() {
|
|
@@ -1111,21 +1037,21 @@ var Screen = class {
|
|
|
1111
1037
|
}
|
|
1112
1038
|
}
|
|
1113
1039
|
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
1114
|
-
this.hasFirstStateUpdateRun = true;
|
|
1115
1040
|
yield this.effectuate();
|
|
1116
1041
|
}
|
|
1042
|
+
this.hasFirstStateUpdateRun = true;
|
|
1117
1043
|
this.rendered = true;
|
|
1118
1044
|
});
|
|
1119
1045
|
}
|
|
1120
1046
|
updateState(data) {
|
|
1121
1047
|
if (!this.rendered) {
|
|
1122
|
-
function
|
|
1048
|
+
function effectuate(data2) {
|
|
1123
1049
|
return __async(this, null, function* () {
|
|
1124
1050
|
this.data = data2;
|
|
1125
1051
|
yield this.Activate(true);
|
|
1126
1052
|
});
|
|
1127
1053
|
}
|
|
1128
|
-
this.effectuate =
|
|
1054
|
+
this.effectuate = effectuate.bind(this, data);
|
|
1129
1055
|
} else {
|
|
1130
1056
|
(() => __async(this, null, function* () {
|
|
1131
1057
|
this.data = data;
|
|
@@ -1158,7 +1084,9 @@ var Screen = class {
|
|
|
1158
1084
|
);
|
|
1159
1085
|
}
|
|
1160
1086
|
if (this.secondaryChildren.length) {
|
|
1161
|
-
|
|
1087
|
+
for (const child of this.secondaryChildren) {
|
|
1088
|
+
this.template.appendChild(child);
|
|
1089
|
+
}
|
|
1162
1090
|
}
|
|
1163
1091
|
});
|
|
1164
1092
|
}
|
|
@@ -1166,9 +1094,11 @@ var Screen = class {
|
|
|
1166
1094
|
this.callBack = cb;
|
|
1167
1095
|
}
|
|
1168
1096
|
addChild(...addOns) {
|
|
1169
|
-
this.secondaryChildren.push(frag(
|
|
1097
|
+
this.secondaryChildren.push(frag(addOns));
|
|
1170
1098
|
}
|
|
1171
1099
|
deActivate() {
|
|
1100
|
+
this.rendered = false;
|
|
1101
|
+
this.hasFirstStateUpdateRun = false;
|
|
1172
1102
|
if (this.transition) {
|
|
1173
1103
|
this.template.classList.remove("CRADOVA-UI-" + this.transition);
|
|
1174
1104
|
}
|
|
@@ -1227,7 +1157,6 @@ Screen.SLIDE_RIGHT = "SLIDE-RIGHT";
|
|
|
1227
1157
|
var simpleStore = class {
|
|
1228
1158
|
constructor(initial) {
|
|
1229
1159
|
this.ref = [];
|
|
1230
|
-
this.value = null;
|
|
1231
1160
|
this.value = initial;
|
|
1232
1161
|
}
|
|
1233
1162
|
set(value, shouldRefRender) {
|
|
@@ -1295,7 +1224,7 @@ var Init = function() {
|
|
|
1295
1224
|
}
|
|
1296
1225
|
const Wrapper = document.createElement("div");
|
|
1297
1226
|
Wrapper.setAttribute("data-cra-id", "cradova-app-wrapper");
|
|
1298
|
-
document.body.
|
|
1227
|
+
document.body.appendChild(Wrapper);
|
|
1299
1228
|
};
|
|
1300
1229
|
|
|
1301
1230
|
// lib/index.ts
|
|
@@ -1368,13 +1297,12 @@ var make = function(txx) {
|
|
|
1368
1297
|
return { tag, className, ID, innerValue };
|
|
1369
1298
|
};
|
|
1370
1299
|
var _ = (...element_initials) => {
|
|
1300
|
+
if (typeof element_initials[0] !== "string") {
|
|
1301
|
+
return frag(element_initials);
|
|
1302
|
+
}
|
|
1371
1303
|
if (element_initials[0].raw) {
|
|
1372
1304
|
element_initials[0] = element_initials[0]["raw"][0];
|
|
1373
1305
|
}
|
|
1374
|
-
if (typeof element_initials[0] !== "string") {
|
|
1375
|
-
console.error(" \u2718 Cradova err: NO TEMPLATE STRING PROVIDED");
|
|
1376
|
-
return () => " \u2718 NO TEMPLATE STRING PROVIDED";
|
|
1377
|
-
}
|
|
1378
1306
|
let beforeMount = null, firstLevelChildren = [];
|
|
1379
1307
|
if (element_initials.length > 1) {
|
|
1380
1308
|
firstLevelChildren = element_initials.splice(1);
|
|
@@ -1580,7 +1508,6 @@ export {
|
|
|
1580
1508
|
css,
|
|
1581
1509
|
lib_default as default,
|
|
1582
1510
|
dispatch,
|
|
1583
|
-
frag,
|
|
1584
1511
|
loadCradovaUICss,
|
|
1585
1512
|
ls
|
|
1586
1513
|
};
|
package/dist/types.ts
CHANGED
|
@@ -45,77 +45,6 @@ export type CradovaHTMLElementType = (
|
|
|
45
45
|
| ((...element_initials: any[]) => HTMLElement | undefined);
|
|
46
46
|
|
|
47
47
|
export type CradovaScreenType = {
|
|
48
|
-
/**
|
|
49
|
-
* Cradova screen
|
|
50
|
-
* ---
|
|
51
|
-
* title of the page
|
|
52
|
-
* @param data
|
|
53
|
-
* @returns void
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* .
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
name: string;
|
|
60
|
-
/**
|
|
61
|
-
* Cradova screen
|
|
62
|
-
* ---
|
|
63
|
-
* The component for the screen
|
|
64
|
-
* @param data
|
|
65
|
-
* @returns void
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* .
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
template: Function | HTMLElement;
|
|
72
|
-
/**
|
|
73
|
-
* Cradova screen
|
|
74
|
-
* ---
|
|
75
|
-
* Screen transition from the screen class
|
|
76
|
-
* @param data
|
|
77
|
-
* @returns void
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* .
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
transition?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Cradova screen
|
|
86
|
-
* ---
|
|
87
|
-
* gets called when the the screen is displayed
|
|
88
|
-
* @param data
|
|
89
|
-
* @returns void
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* .
|
|
93
|
-
*
|
|
94
|
-
*/
|
|
95
|
-
onActivate: (fn: (data: any) => void) => Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* Cradova screen
|
|
98
|
-
* ---
|
|
99
|
-
* Should this screen be cached after first render?
|
|
100
|
-
* @param data
|
|
101
|
-
* @returns void
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* .
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
persist?: boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Cradova screen
|
|
110
|
-
* ---
|
|
111
|
-
* run once on first render and update the screen immediately.
|
|
112
|
-
* @param fn () => void
|
|
113
|
-
* @returns void
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* .
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
48
|
effect(fn: () => void | Promise<void>): void;
|
|
120
49
|
/**
|
|
121
50
|
* Cradova Screen
|
|
@@ -128,11 +57,10 @@ export type CradovaScreenType = {
|
|
|
128
57
|
*
|
|
129
58
|
* *
|
|
130
59
|
*/
|
|
131
|
-
|
|
132
|
-
updateState(data: unknown): void;
|
|
60
|
+
updateState(data: unknown, stash?: unknown): void;
|
|
133
61
|
};
|
|
134
62
|
|
|
135
|
-
export type RefType = {
|
|
63
|
+
export type RefType<D> = {
|
|
136
64
|
/**
|
|
137
65
|
* Cradova Ref
|
|
138
66
|
* ---
|
|
@@ -140,7 +68,7 @@ export type RefType = {
|
|
|
140
68
|
* @param data
|
|
141
69
|
* @returns HTMLElement
|
|
142
70
|
*/
|
|
143
|
-
render(data?:
|
|
71
|
+
render(data?: D): () => any;
|
|
144
72
|
/**
|
|
145
73
|
* Cradova Ref
|
|
146
74
|
* ---
|
|
@@ -156,7 +84,7 @@ export type RefType = {
|
|
|
156
84
|
* @param data
|
|
157
85
|
* @returns void
|
|
158
86
|
*/
|
|
159
|
-
updateState(data:
|
|
87
|
+
updateState(data: D, stash?: boolean): void;
|
|
160
88
|
/**
|
|
161
89
|
* Cradova Ref
|
|
162
90
|
* ---
|
|
@@ -172,6 +100,13 @@ export type RefType = {
|
|
|
172
100
|
*
|
|
173
101
|
*/
|
|
174
102
|
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
103
|
+
/**
|
|
104
|
+
* Cradova Ref
|
|
105
|
+
* ---
|
|
106
|
+
* returns last set stashed Ref data
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
stash: D;
|
|
175
110
|
};
|
|
176
111
|
|
|
177
112
|
/**
|
|
@@ -219,6 +154,7 @@ export type SignalType = {
|
|
|
219
154
|
* set a key value if it's an object
|
|
220
155
|
* @param name - name of the key
|
|
221
156
|
* @param value - value of the key
|
|
157
|
+
* @param shouldRefRender? boolean
|
|
222
158
|
* @returns void
|
|
223
159
|
*
|
|
224
160
|
*
|
|
@@ -227,45 +163,6 @@ export type SignalType = {
|
|
|
227
163
|
*/
|
|
228
164
|
|
|
229
165
|
setKey: (name: string, value: any, shouldRefRender?: boolean) => void;
|
|
230
|
-
/**
|
|
231
|
-
* Cradova Signal
|
|
232
|
-
* ----
|
|
233
|
-
* set a prop value inside an object prop of the store
|
|
234
|
-
* @param key - a prop of the store - object value
|
|
235
|
-
* @param name - prop of the key object
|
|
236
|
-
* @param value - value of the name
|
|
237
|
-
* @returns void
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* .
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
setPath: (
|
|
245
|
-
key: string,
|
|
246
|
-
name: string,
|
|
247
|
-
value: any,
|
|
248
|
-
shouldRefRender?: boolean
|
|
249
|
-
) => void;
|
|
250
|
-
/**
|
|
251
|
-
* Cradova Signal
|
|
252
|
-
* ----
|
|
253
|
-
* set a prop value inside an array prop of the store
|
|
254
|
-
* @param key - a prop of the store - object value
|
|
255
|
-
* @param index - index of the key object
|
|
256
|
-
* @param value - value of the index
|
|
257
|
-
* @returns void
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* .
|
|
261
|
-
*
|
|
262
|
-
*/
|
|
263
|
-
setIndex: (
|
|
264
|
-
key: string,
|
|
265
|
-
index: number,
|
|
266
|
-
value: any,
|
|
267
|
-
shouldRefRender?: boolean
|
|
268
|
-
) => void;
|
|
269
166
|
/**
|
|
270
167
|
* Cradova Signal
|
|
271
168
|
* ----
|