cradova 1.1.1 → 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 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
- cradova.js supports various versions of IE11, Firefox ESR, and Firefox,
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
- but extra speed, ease and security.
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
- Happy coding.
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 HelloMessage({ name }) {
102
- return _("div", "Hello " + name);
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(HelloMessage("friday"));
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
- // which will rerender this screen when done
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: "home page", // page title
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
- import _, { dispatch, Ref } from "cradova";
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
- stateID: "bar",
143
- text: "hello ____" + (name || ""),
172
+ shouldUpdate: true,
173
+ text: "hello " + (name || "no name"),
144
174
  onclick() {
145
- const name = prompt();
146
- dispatch("bar", { text: "hello " + name });
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 ____" + (name || ""),
184
+ text: "hello" + (name || "no name"),
155
185
  onclick() {
156
186
  const name = prompt();
157
- self.updateState({ text: "hello " + name });
187
+ self.updateState({ name });
158
188
  },
159
189
  });
160
190
  });
161
191
 
162
192
  function Home() {
163
- return _(
164
- "div",
165
- { id: "foo", class: "bar" },
166
- HelloMessage,
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
- # How to Sponsor
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 [OpenCollective](https://opencollective.com/cradova). Invoices can be obtained via GitHub's payment system. Both monthly-recurring sponsorships and one-time donations are accepted. Recurring sponsorships will be entitled to logo placements in Tiers.
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 CradovaScreenType = {
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
- effect?: (fn: () => any) => void;
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
- onStateUpdate: (callback: () => void) => void;
61
+ effect(fn: (data: unknown) => Promise<void> | void): void;
33
62
  /**
34
63
  * Cradova Ref
35
64
  * ---
@@ -67,15 +96,6 @@ declare module "cradova" {
67
96
  * @param {any} screen the cradova document tree for the route.
68
97
  */
69
98
  route: (path: string, screen: CradovaScreenType) => void;
70
- routes: Record<string, RouterRouteObject>;
71
- lastNavigatedRoute: string | null;
72
- lastNavigatedRouteController: RouterRouteObject | null;
73
- nextRouteController: RouterRouteObject | null;
74
- params: Record<string, any>;
75
- /**
76
- * n/a
77
- */
78
- router: (e: any, force?: boolean) => void;
79
99
  /**
80
100
  * get a screen ready before time.
81
101
  *
@@ -83,8 +103,6 @@ declare module "cradova" {
83
103
  * @param {any} data data for the screen.
84
104
  */
85
105
  packageScreen: (path: string, data?: any) => void;
86
- pageShow: ((path: string) => void) | null;
87
- pageHide: ((path: string) => void) | null;
88
106
  onPageShow: (callback: () => void) => void;
89
107
  onPageHide: (callback: () => void) => void;
90
108
  /**
@@ -102,32 +120,14 @@ declare module "cradova" {
102
120
  | Record<string, any>;
103
121
 
104
122
  /**
123
+ * Cradova Screen
124
+ * ---
125
+ * create instances of manageable pages and scaffolds
105
126
  * @param name
106
127
  * @param template
107
128
  * @param transitions
108
129
  */
109
130
  export class Screen {
110
- /**
111
- * this should be a cradova screen component
112
- */
113
- private html;
114
- /**
115
- * this is the name of the screen that appears as the title
116
- */
117
- name: string;
118
- private packed;
119
- secondaryChildren: Array<any>;
120
- /**
121
- * used internally
122
- */
123
- private template;
124
- /**
125
- * this a set of two class names
126
- * one for the entry transition
127
- * and one for the exit transition
128
- */
129
- private transition;
130
- private callBack;
131
131
  static SCALE_IN: string;
132
132
  static SCALE_OUT: string;
133
133
  static CIRCLE_IN: string;
@@ -139,15 +139,21 @@ declare module "cradova" {
139
139
  static SLIDE_LEFT: string;
140
140
  static SLIDE_RIGHT: string;
141
141
  /**
142
- * this tells cradova to persist state on the screen or not
143
- * persisting is better
142
+ * Cradova Screen
143
+ * ---
144
+ * create instances of manageable pages and scaffolds
145
+ * @param name
146
+ * @param template
147
+ * @param transitions
148
+ */
149
+ constructor(cradova_screen_initials: CradovaScreenTyping);
150
+ /**
151
+ * Cradova Screen
152
+ * ---
153
+ * runs once after first render
154
+ *
144
155
  */
145
- persist: boolean;
146
- rendered: boolean;
147
- effects: (() => unknown | Promise<unknown>)[];
148
- constructor(cradova_screen_initials: CradovaScreenType);
149
- effect(fn: () => unknown | Promise<unknown>): void;
150
- effector(): Promise<void>;
156
+ effect(fn: () => void | Promise<void>): void;
151
157
  package(data?: any): Promise<void>;
152
158
  onActivate(cb: (data: any) => void): void;
153
159
  addChild(...addOns: any[]): void;
@@ -198,7 +204,7 @@ declare module "cradova" {
198
204
  * - update a cradova Ref/RefList automatically
199
205
  * @constructor initial: any, props: {useHistory, persist}
200
206
  */
201
- export class Signal {
207
+ export class createSignal {
202
208
  private callback;
203
209
  private persistName;
204
210
  private actions;
@@ -333,7 +339,7 @@ declare module "cradova" {
333
339
  export class simpleStore {
334
340
  private ref;
335
341
  value: any;
336
- constructor(initial: unknown, ref: RefType);
342
+ constructor(initial: unknown);
337
343
  /**
338
344
  * Cradova simpleStore
339
345
  * ----
@@ -359,7 +365,17 @@ declare module "cradova" {
359
365
  * @param Ref component to bind to.
360
366
  * @param path a property in the object to send to attached ref
361
367
  */
362
- 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;
363
379
  }
364
380
 
365
381
  /**
@@ -452,7 +468,7 @@ css(".btn:hover",
452
468
  */
453
469
  export function css(
454
470
  identifier: string,
455
- properties: Record<string, string>
471
+ properties?: Record<string, string>
456
472
  ): void;
457
473
  /**
458
474
  Write animation value in javascript
@@ -521,11 +537,8 @@ _.animate("polarization",
521
537
  private component;
522
538
  private stateID;
523
539
  private parentElement;
524
- private datas;
525
540
  constructor(component: (...data: any) => any);
526
- stale(datas: any): void;
527
541
  r(d?: any): any;
528
- u(d?: any): void;
529
542
  render(datas?: any): any;
530
543
  updateState(datas: any[]): void;
531
544
  remove(): void;
@@ -542,11 +555,8 @@ _.animate("polarization",
542
555
  private component;
543
556
  private stateID;
544
557
  private upcb;
545
- private data;
546
558
  constructor(component: (...data: any) => any);
547
- stale(data: any): void;
548
559
  r(d?: any): () => any;
549
- u(d?: any): void;
550
560
  /**
551
561
  * Cradova Ref
552
562
  * ---
@@ -557,13 +567,6 @@ _.animate("polarization",
557
567
  render(data?: any): () => any;
558
568
  instance(): any;
559
569
  i(): any;
560
- /**
561
- * Cradova Ref
562
- * ---
563
- * runs on every state update
564
- *
565
- */
566
- onStateUpdate(cb: any): void;
567
570
  /**
568
571
  * Cradova Ref
569
572
  * ---
@@ -573,6 +576,13 @@ _.animate("polarization",
573
576
  */
574
577
  updateState(data: any): void;
575
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;
576
586
  }
577
587
  /**
578
588
  * Document fragment
@@ -581,77 +591,57 @@ _.animate("polarization",
581
591
  */
582
592
  type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
583
593
  export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
594
+
584
595
  /**
596
+ * Cradova
597
+ * ---
585
598
  * Creates new cradova HTML element
586
599
  * @example
587
- * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
588
- * using inline props
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
+ *
589
609
  * _("p",{
590
610
  * text: "am a p tag",
591
611
  * style: {
592
612
  * color: "blue"
593
613
  * }
594
- * )
595
- * adding children
596
- * _("p",
597
- * _("span",{text:" am a span tag like so",
598
- * {style: {color: "brown"}
599
- * })
600
- * )
601
- *
602
- * props and children
603
- * _("p",
604
- * // props first
605
- * {
606
- * text: "am a p tag",
607
- * style: {
608
- * color: "blue"
609
- * },
610
- * // all children goes after
611
- * _("span",{text:" am a span tag like so",
612
- * {style: {color: "brown"}
613
614
  * })
614
- * )
615
- *
616
- * @param {...any} element_initials
617
- * @returns function - cradova element
618
- */
619
-
620
- /**
621
- * Creates new cradova HTML element
622
- * @example
623
- * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
624
- * using inline props
615
+ * // or no style props it works!
625
616
  * _("p",{
626
617
  * text: "am a p tag",
627
- * style: {
628
618
  * color: "blue"
629
- * }
630
- * )
631
- * adding children
632
- * _("p",
633
- * _("span",{text:" am a span tag like so",
634
- * {style: {color: "brown"}
635
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
+ * ...
636
628
  * )
637
629
  *
638
- * props and children
630
+ * // list of children
639
631
  * _("p",
640
- * // props first
641
- * {
642
- * text: "am a p tag",
643
- * style: {
644
- * color: "blue"
645
- * },
646
632
  * // all children goes after
647
- * _("span",{text:" am a span tag like so",
648
- * {style: {color: "brown"}
649
- * })
633
+ * _("span",
634
+ * {
635
+ * text:" am a span tag like so",
636
+ * color: "brown",
637
+ * }),
638
+ * ...
650
639
  * )
651
640
  *
652
- * @param {...any} element_initials
641
+ * @param {...any[]} element_initials
653
642
  * @returns function - cradova element
654
643
  */
644
+
655
645
  const _: any;
656
646
  export default _;
657
647
  }