cradova 1.2.0 → 1.3.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 +68 -31
- package/dist/index.d.ts +102 -104
- package/dist/index.js +270 -216
- package/dist/types.ts +402 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -48,16 +48,13 @@ cradova is a JavaScript framework for building Single Page Applications and PWAs
|
|
|
48
48
|
|
|
49
49
|
It's small, fast and provides state management, routing and XHR utilities out of the box.
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
Edge, Safari, and Chrome. No polyfills required.
|
|
53
|
-
|
|
54
|
-
# why cradova?
|
|
51
|
+
# Whats the benefit?
|
|
55
52
|
|
|
56
53
|
Javascript is a powerful language.
|
|
57
54
|
our aim is not to limit what you can achieve but rather make your make them limitless.
|
|
58
55
|
|
|
59
56
|
we made Cradova to give you more power at no cost.
|
|
60
|
-
|
|
57
|
+
extra speed, ease and security.
|
|
61
58
|
|
|
62
59
|
we don't use visual DOM or diff algorithms to manage the DOM, we rather do it the natural way.
|
|
63
60
|
|
|
@@ -65,7 +62,7 @@ which is fast and simple, with all the benefits and no abstracts whatsoever.
|
|
|
65
62
|
|
|
66
63
|
cradova has been used in production and we will update this README to reflect them as ASAP.
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
It's time to change gears.
|
|
69
66
|
|
|
70
67
|
# Installation
|
|
71
68
|
|
|
@@ -89,20 +86,23 @@ npm i cradova
|
|
|
89
86
|
|
|
90
87
|
# Examples
|
|
91
88
|
|
|
92
|
-
Before you confirm these below, please know that they are many cool parts about cradova not described here but will be on a later time.
|
|
89
|
+
Before you confirm these below, please know that they are many cool parts about cradova not described here but will be on a later time. and eventually when we get a frontend hosting.
|
|
93
90
|
|
|
94
|
-
You can get deeper insights from the telegram community for the moment.
|
|
91
|
+
You can get deeper insights from the [telegram community](https://t.me/cradovaframework) for the moment.
|
|
95
92
|
|
|
96
93
|
Here's an example of create a basic component in cradova:
|
|
97
94
|
|
|
98
95
|
```js
|
|
99
96
|
import _, { frag } from "cradova";
|
|
100
97
|
|
|
101
|
-
function
|
|
102
|
-
return _("
|
|
98
|
+
function Hello(name) {
|
|
99
|
+
return _("h1", "Hello " + name);
|
|
103
100
|
}
|
|
101
|
+
|
|
102
|
+
// calling Hello returns the HTML
|
|
103
|
+
const html = Hello("peter")(); // or
|
|
104
104
|
// using frag
|
|
105
|
-
const html = frag(
|
|
105
|
+
const html = frag(Hello("peter"), Hello("joe"));
|
|
106
106
|
document.body.append(html);
|
|
107
107
|
```
|
|
108
108
|
|
|
@@ -118,59 +118,89 @@ function HelloMessage(name) {
|
|
|
118
118
|
res("friday");
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
|
-
// effects can be used to make api calls
|
|
122
|
-
|
|
123
|
-
// with the data returned
|
|
124
|
-
return _("div", "Hello" + name);
|
|
121
|
+
// effects can be used to make api calls needed for the page
|
|
122
|
+
return _("div", "Hello " + name);
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
const home = new Screen({
|
|
128
|
-
name: "
|
|
126
|
+
name: "hello page", // page title
|
|
129
127
|
template: HelloMessage,
|
|
128
|
+
...
|
|
130
129
|
});
|
|
131
130
|
|
|
132
131
|
Router.route("/", home);
|
|
132
|
+
|
|
133
|
+
// navigates to that page
|
|
134
|
+
// Router.navigate("/home");
|
|
135
|
+
// get the page ready in the background
|
|
136
|
+
// Router.packageScreen("/home");
|
|
137
|
+
|
|
133
138
|
```
|
|
134
139
|
|
|
135
140
|
# State management
|
|
136
141
|
|
|
137
142
|
```js
|
|
138
|
-
|
|
143
|
+
// we have
|
|
144
|
+
|
|
145
|
+
// dispatch - global (element) requires state ID
|
|
146
|
+
|
|
147
|
+
// element can have this.updateState when shouldUpdate is true
|
|
148
|
+
|
|
149
|
+
// Ref components (global and local)
|
|
150
|
+
|
|
151
|
+
// RefList components (global and local)
|
|
152
|
+
|
|
153
|
+
// state can be bind to a store when using createSignal or simpleStores
|
|
154
|
+
|
|
155
|
+
import _, { Ref } from "cradova";
|
|
156
|
+
|
|
157
|
+
// simple count
|
|
158
|
+
|
|
159
|
+
function counter() {
|
|
160
|
+
let num = 0;
|
|
161
|
+
return _("h1| 0", {
|
|
162
|
+
shouldUpdate: true,
|
|
163
|
+
onclick() {
|
|
164
|
+
num++;
|
|
165
|
+
this.updateState({ text: num });
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
139
169
|
|
|
140
170
|
function HelloMessage(name) {
|
|
141
171
|
return _("div.foo#bar", {
|
|
142
|
-
|
|
143
|
-
text: "hello
|
|
172
|
+
shouldUpdate: true,
|
|
173
|
+
text: "hello " + (name || "no name"),
|
|
144
174
|
onclick() {
|
|
145
|
-
const name = prompt();
|
|
146
|
-
|
|
175
|
+
const name = prompt("what are your names");
|
|
176
|
+
this.updateState({ text: "hello " + name });
|
|
147
177
|
},
|
|
148
178
|
});
|
|
149
179
|
}
|
|
150
180
|
|
|
151
|
-
const nameRef = new Ref(function (name) {
|
|
181
|
+
const nameRef = new Ref(function ({ name }) {
|
|
152
182
|
const self = this;
|
|
153
183
|
return _("div.foo#bar", {
|
|
154
|
-
text: "hello
|
|
184
|
+
text: "hello" + (name || "no name"),
|
|
155
185
|
onclick() {
|
|
156
186
|
const name = prompt();
|
|
157
|
-
self.updateState({
|
|
187
|
+
self.updateState({ name });
|
|
158
188
|
},
|
|
159
189
|
});
|
|
160
190
|
});
|
|
161
191
|
|
|
162
192
|
function Home() {
|
|
163
|
-
return _(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
nameRef.render(null)
|
|
193
|
+
return _("div.foo#bar",
|
|
194
|
+
counter,
|
|
195
|
+
HelloMessage,
|
|
196
|
+
nameRef.render({ name: "no name" })
|
|
168
197
|
);
|
|
169
198
|
}
|
|
170
199
|
|
|
171
200
|
const home = new Screen({
|
|
172
201
|
name: "home page", // page title
|
|
173
202
|
template: Home,
|
|
203
|
+
...
|
|
174
204
|
});
|
|
175
205
|
|
|
176
206
|
Router.route("/", home);
|
|
@@ -192,9 +222,16 @@ we are currently working to set up.
|
|
|
192
222
|
- UI component libraries for cradova
|
|
193
223
|
- Sample projects
|
|
194
224
|
- maintenance and promotion
|
|
225
|
+
- building cradova CLI
|
|
195
226
|
|
|
196
227
|
community [telegram](https://t.me/cradovaframework)
|
|
197
228
|
|
|
198
|
-
#
|
|
229
|
+
# Sponsor
|
|
230
|
+
|
|
231
|
+
It's a general aim to have a development tool
|
|
232
|
+
with great developer experience and speed and that what
|
|
233
|
+
cradova gives, "low abstraction with great speed".
|
|
234
|
+
|
|
235
|
+
it's measurable, to take cradova further your support is needed.
|
|
199
236
|
|
|
200
|
-
Sponsorships can be done via [
|
|
237
|
+
Sponsorships can be done via [Patreon](https://www.patreon.com/FridayCandour). Both monthly-recurring sponsorships and one-time donations are accepted. Recurring sponsorships will be entitled to logo placements in Tiers.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
declare module "cradova" {
|
|
2
|
-
type
|
|
2
|
+
type CradovaScreenTyping = {
|
|
3
3
|
name: string;
|
|
4
4
|
template: Function | HTMLElement;
|
|
5
5
|
transition?: string;
|
|
6
|
-
callBack?: (html?: any, data?: Record<string, any>) => void;
|
|
7
6
|
persist?: boolean;
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Cradova screen
|
|
9
|
+
* ---
|
|
10
|
+
* runs once after first render
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type CradovaScreenType = {
|
|
16
|
+
/**
|
|
17
|
+
* Cradova screen
|
|
18
|
+
* ---
|
|
19
|
+
* runs once after first render
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
effect?(fn: () => void | Promise<void>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Cradova screen
|
|
25
|
+
* ---
|
|
26
|
+
* runs on first render.
|
|
27
|
+
* @param data
|
|
28
|
+
* @returns void
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* .
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
updateState: (data: any) => any;
|
|
9
35
|
};
|
|
36
|
+
|
|
37
|
+
type CradovaElementType = Record<string, any>;
|
|
38
|
+
|
|
10
39
|
type RefType = {
|
|
11
40
|
/**
|
|
12
41
|
* Cradova Ref
|
|
@@ -26,10 +55,10 @@ declare module "cradova" {
|
|
|
26
55
|
/**
|
|
27
56
|
* Cradova Ref
|
|
28
57
|
* ---
|
|
29
|
-
* runs on every state update
|
|
58
|
+
* runs on render and every state update
|
|
30
59
|
*
|
|
31
60
|
*/
|
|
32
|
-
|
|
61
|
+
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
33
62
|
/**
|
|
34
63
|
* Cradova Ref
|
|
35
64
|
* ---
|
|
@@ -91,32 +120,14 @@ declare module "cradova" {
|
|
|
91
120
|
| Record<string, any>;
|
|
92
121
|
|
|
93
122
|
/**
|
|
123
|
+
* Cradova Screen
|
|
124
|
+
* ---
|
|
125
|
+
* create instances of manageable pages and scaffolds
|
|
94
126
|
* @param name
|
|
95
127
|
* @param template
|
|
96
128
|
* @param transitions
|
|
97
129
|
*/
|
|
98
130
|
export class Screen {
|
|
99
|
-
/**
|
|
100
|
-
* this should be a cradova screen component
|
|
101
|
-
*/
|
|
102
|
-
private html;
|
|
103
|
-
/**
|
|
104
|
-
* this is the name of the screen that appears as the title
|
|
105
|
-
*/
|
|
106
|
-
name: string;
|
|
107
|
-
private packed;
|
|
108
|
-
secondaryChildren: Array<any>;
|
|
109
|
-
/**
|
|
110
|
-
* used internally
|
|
111
|
-
*/
|
|
112
|
-
private template;
|
|
113
|
-
/**
|
|
114
|
-
* this a set of two class names
|
|
115
|
-
* one for the entry transition
|
|
116
|
-
* and one for the exit transition
|
|
117
|
-
*/
|
|
118
|
-
private transition;
|
|
119
|
-
private callBack;
|
|
120
131
|
static SCALE_IN: string;
|
|
121
132
|
static SCALE_OUT: string;
|
|
122
133
|
static CIRCLE_IN: string;
|
|
@@ -128,15 +139,21 @@ declare module "cradova" {
|
|
|
128
139
|
static SLIDE_LEFT: string;
|
|
129
140
|
static SLIDE_RIGHT: string;
|
|
130
141
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
142
|
+
* Cradova Screen
|
|
143
|
+
* ---
|
|
144
|
+
* create instances of manageable pages and scaffolds
|
|
145
|
+
* @param name
|
|
146
|
+
* @param template
|
|
147
|
+
* @param transitions
|
|
133
148
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
constructor(cradova_screen_initials: CradovaScreenTyping);
|
|
150
|
+
/**
|
|
151
|
+
* Cradova Screen
|
|
152
|
+
* ---
|
|
153
|
+
* runs once after first render
|
|
154
|
+
*
|
|
155
|
+
*/
|
|
156
|
+
effect(fn: () => void | Promise<void>): void;
|
|
140
157
|
package(data?: any): Promise<void>;
|
|
141
158
|
onActivate(cb: (data: any) => void): void;
|
|
142
159
|
addChild(...addOns: any[]): void;
|
|
@@ -322,7 +339,7 @@ declare module "cradova" {
|
|
|
322
339
|
export class simpleStore {
|
|
323
340
|
private ref;
|
|
324
341
|
value: any;
|
|
325
|
-
constructor(initial: unknown
|
|
342
|
+
constructor(initial: unknown);
|
|
326
343
|
/**
|
|
327
344
|
* Cradova simpleStore
|
|
328
345
|
* ----
|
|
@@ -348,7 +365,17 @@ declare module "cradova" {
|
|
|
348
365
|
* @param Ref component to bind to.
|
|
349
366
|
* @param path a property in the object to send to attached ref
|
|
350
367
|
*/
|
|
351
|
-
bindRef(Ref: any): void;
|
|
368
|
+
bindRef(Ref: any, prop?: string): void;
|
|
369
|
+
/**
|
|
370
|
+
* Cradova simpleStore
|
|
371
|
+
* ---
|
|
372
|
+
* is used to bind store data to any element
|
|
373
|
+
*
|
|
374
|
+
* @param prop
|
|
375
|
+
* @returns something
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
bind(prop: string): void;
|
|
352
379
|
}
|
|
353
380
|
|
|
354
381
|
/**
|
|
@@ -441,7 +468,7 @@ css(".btn:hover",
|
|
|
441
468
|
*/
|
|
442
469
|
export function css(
|
|
443
470
|
identifier: string,
|
|
444
|
-
properties
|
|
471
|
+
properties?: Record<string, string>
|
|
445
472
|
): void;
|
|
446
473
|
/**
|
|
447
474
|
Write animation value in javascript
|
|
@@ -480,13 +507,10 @@ _.animate("polarization",
|
|
|
480
507
|
ifTrue: () => any,
|
|
481
508
|
ifFalse: () => any
|
|
482
509
|
): () => any;
|
|
483
|
-
/**
|
|
484
|
-
*
|
|
510
|
+
/**
|
|
485
511
|
* Create element and get a callback to update their state
|
|
486
512
|
* no need to manage stateIDs
|
|
487
513
|
* ----------------------------------------------------------------
|
|
488
|
-
* please use element.updateState(state) instead in listeners and mount events
|
|
489
|
-
* ---
|
|
490
514
|
*
|
|
491
515
|
* @param element_initials
|
|
492
516
|
* @param props
|
|
@@ -513,11 +537,8 @@ _.animate("polarization",
|
|
|
513
537
|
private component;
|
|
514
538
|
private stateID;
|
|
515
539
|
private parentElement;
|
|
516
|
-
private datas;
|
|
517
540
|
constructor(component: (...data: any) => any);
|
|
518
|
-
stale(datas: any): void;
|
|
519
541
|
r(d?: any): any;
|
|
520
|
-
u(d?: any): void;
|
|
521
542
|
render(datas?: any): any;
|
|
522
543
|
updateState(datas: any[]): void;
|
|
523
544
|
remove(): void;
|
|
@@ -534,11 +555,8 @@ _.animate("polarization",
|
|
|
534
555
|
private component;
|
|
535
556
|
private stateID;
|
|
536
557
|
private upcb;
|
|
537
|
-
private data;
|
|
538
558
|
constructor(component: (...data: any) => any);
|
|
539
|
-
stale(data: any): void;
|
|
540
559
|
r(d?: any): () => any;
|
|
541
|
-
u(d?: any): void;
|
|
542
560
|
/**
|
|
543
561
|
* Cradova Ref
|
|
544
562
|
* ---
|
|
@@ -549,13 +567,6 @@ _.animate("polarization",
|
|
|
549
567
|
render(data?: any): () => any;
|
|
550
568
|
instance(): any;
|
|
551
569
|
i(): any;
|
|
552
|
-
/**
|
|
553
|
-
* Cradova Ref
|
|
554
|
-
* ---
|
|
555
|
-
* runs on every state update
|
|
556
|
-
*
|
|
557
|
-
*/
|
|
558
|
-
onStateUpdate(cb: any): void;
|
|
559
570
|
/**
|
|
560
571
|
* Cradova Ref
|
|
561
572
|
* ---
|
|
@@ -565,6 +576,13 @@ _.animate("polarization",
|
|
|
565
576
|
*/
|
|
566
577
|
updateState(data: any): void;
|
|
567
578
|
remove(): void;
|
|
579
|
+
/**
|
|
580
|
+
* Cradova Ref
|
|
581
|
+
* ---
|
|
582
|
+
* runs on render and every state update
|
|
583
|
+
*
|
|
584
|
+
*/
|
|
585
|
+
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
568
586
|
}
|
|
569
587
|
/**
|
|
570
588
|
* Document fragment
|
|
@@ -573,77 +591,57 @@ _.animate("polarization",
|
|
|
573
591
|
*/
|
|
574
592
|
type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
|
|
575
593
|
export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
|
|
594
|
+
|
|
576
595
|
/**
|
|
596
|
+
* Cradova
|
|
597
|
+
* ---
|
|
577
598
|
* Creates new cradova HTML element
|
|
578
599
|
* @example
|
|
579
|
-
*
|
|
580
|
-
*
|
|
600
|
+
* // using template
|
|
601
|
+
* const p = _("p");
|
|
602
|
+
* _("p.class");
|
|
603
|
+
* _("p#id");
|
|
604
|
+
* _("p.class#id");
|
|
605
|
+
* _("p.foo.bar#poo.loo");
|
|
606
|
+
*
|
|
607
|
+
* // using inline props
|
|
608
|
+
*
|
|
581
609
|
* _("p",{
|
|
582
610
|
* text: "am a p tag",
|
|
583
611
|
* style: {
|
|
584
612
|
* color: "blue"
|
|
585
613
|
* }
|
|
586
|
-
* )
|
|
587
|
-
* adding children
|
|
588
|
-
* _("p",
|
|
589
|
-
* _("span",{text:" am a span tag like so",
|
|
590
|
-
* {style: {color: "brown"}
|
|
591
614
|
* })
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
* props and children
|
|
595
|
-
* _("p",
|
|
596
|
-
* // props first
|
|
597
|
-
* {
|
|
598
|
-
* text: "am a p tag",
|
|
599
|
-
* style: {
|
|
600
|
-
* color: "blue"
|
|
601
|
-
* },
|
|
602
|
-
* // all children goes after
|
|
603
|
-
* _("span",{text:" am a span tag like so",
|
|
604
|
-
* {style: {color: "brown"}
|
|
605
|
-
* })
|
|
606
|
-
* )
|
|
607
|
-
*
|
|
608
|
-
* @param {...any} element_initials
|
|
609
|
-
* @returns function - cradova element
|
|
610
|
-
*/
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Creates new cradova HTML element
|
|
614
|
-
* @example
|
|
615
|
-
* _("p") // or _("p.class") or _("p#id") or _("p.class#id")
|
|
616
|
-
* using inline props
|
|
615
|
+
* // or no style props it works!
|
|
617
616
|
* _("p",{
|
|
618
617
|
* text: "am a p tag",
|
|
619
|
-
* style: {
|
|
620
618
|
* color: "blue"
|
|
621
|
-
* }
|
|
622
|
-
* )
|
|
623
|
-
* adding children
|
|
624
|
-
* _("p",
|
|
625
|
-
* _("span",{text:" am a span tag like so",
|
|
626
|
-
* {style: {color: "brown"}
|
|
627
619
|
* })
|
|
620
|
+
*
|
|
621
|
+
* // props and children
|
|
622
|
+
* _("p", // template first
|
|
623
|
+
* // property next if wanted
|
|
624
|
+
* {style: {color: "brown"}, // optional
|
|
625
|
+
* // the rest should be children or text
|
|
626
|
+
* _("span", " am a span tag text like so"),
|
|
627
|
+
* ...
|
|
628
628
|
* )
|
|
629
629
|
*
|
|
630
|
-
*
|
|
630
|
+
* // list of children
|
|
631
631
|
* _("p",
|
|
632
|
-
* // props first
|
|
633
|
-
* {
|
|
634
|
-
* text: "am a p tag",
|
|
635
|
-
* style: {
|
|
636
|
-
* color: "blue"
|
|
637
|
-
* },
|
|
638
632
|
* // all children goes after
|
|
639
|
-
* _("span",
|
|
640
|
-
*
|
|
641
|
-
*
|
|
633
|
+
* _("span",
|
|
634
|
+
* {
|
|
635
|
+
* text:" am a span tag like so",
|
|
636
|
+
* color: "brown",
|
|
637
|
+
* }),
|
|
638
|
+
* ...
|
|
642
639
|
* )
|
|
643
640
|
*
|
|
644
|
-
* @param {...any} element_initials
|
|
641
|
+
* @param {...any[]} element_initials
|
|
645
642
|
* @returns function - cradova element
|
|
646
643
|
*/
|
|
644
|
+
|
|
647
645
|
const _: any;
|
|
648
646
|
export default _;
|
|
649
647
|
}
|