cradova 2.1.2 → 2.2.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
@@ -41,7 +41,7 @@
41
41
 
42
42
  Cradova is a JavaScript framework for building Single Page Applications and PWAs.
43
43
 
44
- It's small, fast and provides state management, routing and a rest API utility out of the box.
44
+ It's a fast and simple framework, it provides state management, routing system and a rest API utility out of the box.
45
45
 
46
46
  Cradova follows the [VJS specification](https://github.com/fridaycandour/cradova/blob/main/spec.md)
47
47
 
@@ -49,12 +49,17 @@ Cradova follows the [VJS specification](https://github.com/fridaycandour/cradova
49
49
 
50
50
  Cradova is aimed to be fast and simple with and fewer abstractions and yet easily composable.
51
51
 
52
- We don't use visual DOM or diff algorithms to manage the DOM.
52
+ Cradova does't rely on visual DOM or diff algorithms to manage the DOM, instead, State management is done more elegantly with a simple predictive model, manually and easily with all the speed.
53
53
 
54
- State management is done more elegantly with the predictive model, manually and easily with all the speed.
54
+ ### is this a big benefit?
55
+
56
+ Yes!
57
+ see for yourself.
55
58
 
56
59
  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.
57
60
 
61
+ [current version changes](https://github.com/fridaycandour/cradova/blob/main/CHANGELOG.md#v220)
62
+
58
63
  ## Installation
59
64
 
60
65
  ### CDN sources
@@ -192,7 +197,7 @@ function counter() {
192
197
  function dataCounter() {
193
198
  return _("h1| 0", {
194
199
  shouldUpdate: true,
195
- $num: "0", // data-num
200
+ "data-num": "0",
196
201
  onclick() {
197
202
  const num = Number(this.getAttribute("data-num")) + 1;
198
203
  this.updateState({ text: num, $num: num });
package/dist/index.d.ts CHANGED
@@ -1,144 +1,4 @@
1
1
  declare module "cradova" {
2
- /**
3
- *
4
- * Cradova Ajax
5
- * ------------------
6
- * your new axios alternative
7
- * supports files upload
8
- * @param url string
9
- * @param {{method: string;data;header;callbacks;}} opts
10
- * @returns any
11
- */
12
- export function Ajax(
13
- url: string | URL,
14
- opts?:
15
- | {
16
- method?: "GET" | "POST";
17
- data?: Record<string, any>;
18
- header?: {
19
- "content-type": string;
20
- } & Record<string, any>;
21
- callbacks?: Record<string, (arg: any) => void>;
22
- }
23
- | any
24
- ): Promise<unknown>;
25
-
26
- /**
27
- * Cradova Signal
28
- * ----
29
- * create stateful data store.
30
- * ability to:
31
- * - create a store
32
- * - create actions and fire them
33
- * - bind a Ref or RefList
34
- * - listen to changes
35
- * - persist changes to localStorage
36
- * - set keys instead of all values
37
- * - update a cradova Ref/RefList automatically
38
- * @constructor initial: any, props: {useHistory, persist}
39
- */
40
- export class createSignal<Type> {
41
- private callback;
42
- private persistName;
43
- private actions;
44
- private ref;
45
- private path;
46
- value: Type;
47
- constructor(
48
- initial: Type,
49
- props?: {
50
- persistName?: string | undefined;
51
- }
52
- );
53
- /**
54
- * Cradova Signal
55
- * ----
56
- * set signal value
57
- * @param value - signal value
58
- * @returns void
59
- */
60
- set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
61
- /**
62
- * Cradova Signal
63
- * ----
64
- * set a key value if it's an object
65
- * @param key - key of the key
66
- * @param value - value of the key
67
- * @returns void
68
- */
69
- setKey<k extends keyof Type>(
70
- key: k,
71
- value: any,
72
- shouldRefRender?: boolean
73
- ): void;
74
- /**
75
- * Cradova Signal
76
- * ----
77
- * set a key to signal an action
78
- * @param key - key of the action
79
- * @param action function to execute
80
- */
81
- createAction(
82
- key: string | Record<string, (data?: Type) => void>,
83
- action?: (data?: Type) => void
84
- ): void;
85
- /**
86
- * Cradova Signal
87
- * ----
88
- * fires an action if available
89
- * @param key - string key of the action
90
- * @param data - data for the action
91
- */
92
- fireAction(key: string, data?: Type): void;
93
- /**
94
- * Cradova Signal
95
- * ----
96
- * set a auto - rendering component for this store
97
- *
98
- * @param Ref component to bind to.
99
- * @param path a property in the object to send to attached ref
100
- */
101
- bindRef(Ref: any, path?: string): void;
102
- /**
103
- * Cradova Signal
104
- * ----
105
- * set a update listener on value changes
106
- * @param callback
107
- */
108
- listen(callback: (a: any) => void): void;
109
- /**
110
- * Cradova Signal
111
- * ----
112
- * clear the history on local storage
113
- *
114
- *
115
- * .
116
- */
117
- clearPersist(): void;
118
- }
119
-
120
- type stateType =
121
- | Partial<HTMLElement>
122
- | {
123
- class?: string;
124
- text?: string;
125
- style?: Partial<CSSStyleDeclaration>;
126
- tree?: Function | HTMLElement;
127
- remove?: boolean;
128
- };
129
- type stateID = string;
130
- /**
131
- * Send a new state to specified element with stateID
132
- *
133
- * @param stateID
134
- * @param state
135
- * @returns element(s)
136
- */
137
- export function dispatch(
138
- stateID: stateID | Record<stateID, stateType>,
139
- state?: stateType
140
- ): any;
141
-
142
2
  type ElementType<T> = (
143
3
  ...VJS: (
144
4
  | string
@@ -153,74 +13,10 @@ declare module "cradova" {
153
13
  text?: string;
154
14
  stateID?: string;
155
15
  shouldUpdate?: boolean;
16
+ assert?: any;
156
17
  }
157
18
  )[]
158
19
  ) => T;
159
-
160
- /**
161
- * Cradova Router
162
- * ---
163
- * Facilitates navigation within the application and initializes
164
- * page views based on the matched routes.
165
- */
166
- type RouterType = {
167
- /**
168
- * Registers a route.
169
- *
170
- * @param {string} path Route path.
171
- * @param {any} screen the cradova document tree for the route.
172
- */
173
- route: (path: string, screen: Screen) => void;
174
- /**
175
- * get a screen ready before time.
176
- *
177
- * @param {string} path Route path.
178
- * @param {any} data data for the screen.
179
- */
180
- packageScreen: (path: string, data?: any) => Promise<void>;
181
- onPageShow: (callback: () => void) => void;
182
- onPageHide: (callback: () => void) => void;
183
- /**
184
- * Cradova Router
185
- * ------
186
- *
187
- * return last set router params
188
- *
189
- * .
190
- */
191
- getParams: <D>() => { data: D | unknown; params: any };
192
- /**
193
- * Cradova Router
194
- * ------
195
- *
196
- * Navigates to a designated screen in your app
197
- */
198
- navigate: (
199
- href: string,
200
- data?: Record<string, any> | null,
201
- force?: boolean
202
- ) => void;
203
-
204
- /**
205
- * Cradova
206
- * ---
207
- * Error Handler for your app
208
- *
209
- * @param callback
210
- * @param path? page path
211
- */
212
-
213
- addErrorHandler: (callback: (error: string) => void, path?: string) => void;
214
- };
215
-
216
- /**
217
- * Cradova Router
218
- * ---
219
- * Facilitates navigation within the application and initializes
220
- * page views based on the matched routes.
221
- */
222
- export const Router: RouterType;
223
-
224
20
  /**
225
21
  *
226
22
  */
@@ -229,13 +25,19 @@ declare module "cradova" {
229
25
  * Cradova screen
230
26
  * ---
231
27
  * title of the page
232
- * @param data
233
- * @returns void
234
28
  *
235
29
  *
236
30
  * .
237
31
  */
238
32
  name: string;
33
+ /**
34
+ * Cradova screen
35
+ * ---
36
+ * a css className to add to screen when rendering it
37
+ * Usually for adding css transitions
38
+ * .
39
+ */
40
+ transition?: string;
239
41
  /**
240
42
  * Cradova screen
241
43
  * ---
@@ -250,20 +52,19 @@ declare module "cradova" {
250
52
  /**
251
53
  * Cradova screen
252
54
  * ---
253
- * Screen transition from the screen class
254
- * @param data
255
- * @returns void
55
+ * Allows this screen render in parallel for unique routes
56
+ *
57
+ * limit is 1000
58
+ *
256
59
  *
257
60
  *
258
61
  * .
259
62
  */
260
- transition?: string;
63
+ renderInParallel?: boolean;
261
64
  /**
262
65
  * Cradova screen
263
66
  * ---
264
67
  * gets called when the the screen is displayed
265
- * @param data
266
- * @returns void
267
68
  *
268
69
  *
269
70
  * .
@@ -272,113 +73,17 @@ declare module "cradova" {
272
73
  * Cradova screen
273
74
  * ---
274
75
  * Should this screen be cached after first render?
275
- * @param data
276
- * @returns void
277
- *
76
+ * you can use Route.navigate(url, null, true) to force later
278
77
  *
279
78
  * .
280
79
  */
281
80
  persist?: boolean;
282
81
  };
283
82
 
284
- /**
285
- * Cradova Screen
286
- * ---
287
- * create instances of manageable pages and scaffolds
288
- * @param name
289
- * @param template
290
- * @param transitions
291
- */
292
- export class Screen {
293
- /**
294
- * this should be a cradova screen component
295
- */
296
- private html;
297
- /**
298
- * this is the name of the screen that appears as the title
299
- */
300
- private name;
301
- private packed;
302
- private secondaryChildren;
303
- /**
304
- * used internally
305
- */
306
- private template;
307
- private callBack;
308
- private deCallBack;
309
- errorHandler: (() => void) | null;
310
- /**
311
- * this tells cradova to persist state on the screen or not
312
- * persisting is better
313
- */
314
- private persist;
315
- private data;
316
- constructor(cradova_screen_initials: CradovaScreenType);
317
- setErrorHandler(errorHandler: () => void): void;
318
- package(): Promise<void>;
319
- onActivate(cb: () => Promise<void> | void): void;
320
- onDeactivate(cb: () => Promise<void> | void): void;
321
- addChild(...addOns: any[]): void;
322
- deActivate(): void;
323
- Activate(force?: boolean): Promise<void>;
324
- }
325
-
326
- /**
327
- * Cradova simpleStore
328
- * ----
329
- * create stateful data store.
330
- * ability to:
331
- * - create a store
332
- * - set keys instead of all values
333
- * - able to update state on any element as a property value
334
- * @constructor initial: any, Ref/RefList/RefElement: any
335
- */
336
- export class $<Type extends Record<string, unknown>> {
337
- private ref;
338
- value: Type;
339
- constructor(initial: Type);
340
- /**
341
- * Cradova simpleStore
342
- * ----
343
- * set simpleStore value
344
- * @param value - simpleStore value
345
- * @returns void
346
- */
347
- set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
348
- /**
349
- * Cradova
350
- * ---
351
- * is used to bind store data to any element
352
- *
353
- * @param prop
354
- * @returns something
355
- */
356
- bind(prop: string): (string | this)[];
357
- private updateState;
358
- /**
359
- * Cradova simpleStore
360
- * ----
361
- * set a key value if it's an object
362
- * @param name - name of the key
363
- * @param value - value of the key
364
- * @returns void
365
- */
366
- setKey<k extends keyof Type>(
367
- name: k,
368
- value: any,
369
- shouldRefRender?: boolean
370
- ): void;
371
- /**
372
- * Cradova simpleStore
373
- * ----
374
- * set a auto - rendering component for this store
375
- *
376
- * @param Ref component to bind to.
377
- * @param path a property in the object to send to attached ref
378
- */
379
- bindRef(ref: any, key: string, prop: string): void;
380
- }
381
-
83
+ export const makeElement: (
84
+ element: Record<string, any>,
85
+ ...ElementChildrenAndPropertyList: ElementType<HTMLElement>[]
86
+ ) => Record<string, any>;
382
87
  export const a: ElementType<HTMLAnchorElement>;
383
88
  export const abbr: ElementType<HTMLElement>;
384
89
  export const address: ElementType<HTMLElement>;
@@ -492,6 +197,30 @@ declare module "cradova" {
492
197
  export const video: ElementType<HTMLVideoElement>;
493
198
  export const wbr: ElementType<HTMLElement>;
494
199
 
200
+ /**
201
+ *
202
+ * Cradova Ajax
203
+ * ------------------
204
+ * your new axios alternative
205
+ * supports files upload
206
+ * @param url string
207
+ * @param {{method: string;data;header;callbacks;}} opts
208
+ * @returns any
209
+ */
210
+ export function Ajax(
211
+ url: string | URL,
212
+ opts?:
213
+ | {
214
+ method?: "GET" | "POST";
215
+ data?: Record<string, any>;
216
+ header?: {
217
+ "content-type": string;
218
+ } & Record<string, any>;
219
+ callbacks?: Record<string, (arg: any) => void>;
220
+ }
221
+ | any
222
+ ): Promise<unknown>;
223
+
495
224
  /**
496
225
  * Cradova afterMount event
497
226
  */
@@ -522,21 +251,13 @@ css(".btn:hover",
522
251
  /**
523
252
  *
524
253
  * @param {expression} condition
525
- * @param {function} callback
254
+ * @param {function} elements[]
526
255
  */
527
- export function assert(condition: any, ...elements: any): undefined | any;
528
-
256
+ export function assert(condition: any, ...elements: any): any;
529
257
  export function loop(
530
258
  datalist: any[],
531
- component: (value: any, index?: number, array?: any[]) => HTMLElement
532
- ): any;
533
-
534
- export function svgNS(
535
- type: string,
536
- props: Record<string, any>,
537
- ...children: any
538
- ): HTMLElement;
539
-
259
+ component: (value: any, index?: number, array?: any[]) => any
260
+ ): HTMLElement | undefined;
540
261
  export function assertOr(
541
262
  condition: boolean,
542
263
  ifTrue: () => any,
@@ -592,6 +313,206 @@ css(".btn:hover",
592
313
  private Activate;
593
314
  remove(): void;
594
315
  }
316
+ export const svgNS: (
317
+ type: string,
318
+ props: Record<string, any>,
319
+ ...children: any
320
+ ) => HTMLElement;
321
+ export class lazy {
322
+ content: any;
323
+ private _cb;
324
+ constructor(cb: () => Promise<any>);
325
+ load(): Promise<void>;
326
+ }
327
+
328
+ /**
329
+ * Cradova Signal
330
+ * ----
331
+ * create stateful data store.
332
+ * ability to:
333
+ * - create store
334
+ * - create actions and fire them
335
+ * - bind a Ref
336
+ * - listen to changes
337
+ * - persist changes to localStorage
338
+ * - set keys instead of all values
339
+ * - update a cradova Ref and bindings automatically
340
+ * @constructor initial: any, props: {useHistory, persist}
341
+ */
342
+
343
+ export class createSignal<Type extends Record<string, any>> {
344
+ private callback;
345
+ private persistName;
346
+ private actions;
347
+ private ref;
348
+ value: Type;
349
+ constructor(
350
+ initial: Type,
351
+ props?: {
352
+ persistName?: string | undefined;
353
+ }
354
+ );
355
+ /**
356
+ * Cradova Signal
357
+ * ----
358
+ * set signal value
359
+ * @param value - signal value
360
+ * @returns void
361
+ */
362
+ set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
363
+ /**
364
+ * Cradova Signal
365
+ * ----
366
+ * set a key value if it's an object
367
+ * @param key - key of the key
368
+ * @param value - value of the key
369
+ * @returns void
370
+ */
371
+ setKey<k extends keyof Type>(
372
+ key: k,
373
+ value: any,
374
+ shouldRefRender?: boolean
375
+ ): void;
376
+ /**
377
+ * Cradova Signal
378
+ * ----
379
+ * set a key to signal an action
380
+ * @param key - key of the action
381
+ * @param action function to execute
382
+ */
383
+ createAction(
384
+ key: string | Record<string, (data?: Type) => void>,
385
+ action?: ((data?: Type) => void) | Ref<unknown>
386
+ ): void;
387
+ /**
388
+ * Cradova Signal
389
+ * ----
390
+ * fires an action if available
391
+ * @param key - string key of the action
392
+ * @param data - data for the action
393
+ */
394
+ fireAction(key: string, data?: Type): void;
395
+ /**
396
+ * Cradova
397
+ * ---
398
+ * is used to bind store data to an element
399
+ *
400
+ * @param prop
401
+ * @returns something
402
+ */
403
+ bind(prop: string): (string | this)[];
404
+ private _updateState;
405
+ /**
406
+ * Cradova Signal
407
+ * ----
408
+ * set a auto - rendering component for this store
409
+ *
410
+ * @param Ref component to bind to.
411
+ * @param path a property in the object to send to attached ref
412
+ */
413
+ bindRef(
414
+ ref: any,
415
+ binding: {
416
+ event?: string;
417
+ signalProperty: string;
418
+ _element_property: string;
419
+ }
420
+ ): void;
421
+ /**
422
+ * Cradova Signal
423
+ * ----
424
+ * set a update listener on value changes
425
+ * @param callback
426
+ */
427
+ listen(callback: (a: any) => void): void;
428
+ /**
429
+ * Cradova Signal
430
+ * ----
431
+ * clear the history on local storage
432
+ *
433
+ *
434
+ * .
435
+ */
436
+ clearPersist(): void;
437
+ }
438
+
439
+ type stateType =
440
+ | Partial<HTMLElement>
441
+ | {
442
+ class?: string;
443
+ text?: string;
444
+ style?: Partial<CSSStyleDeclaration>;
445
+ tree?: Function | HTMLElement;
446
+ remove?: boolean;
447
+ };
448
+ type stateID = string;
449
+ /**
450
+ * Send a new state to specified element with stateID
451
+ *
452
+ * @param stateID
453
+ * @param state
454
+ * @returns element(s)
455
+ */
456
+ export function dispatch(
457
+ stateID: stateID | Record<stateID, stateType>,
458
+ state?: stateType
459
+ ): any;
460
+
461
+ /**
462
+ * Cradova Router
463
+ * ---
464
+ * Facilitates navigation within the application and initializes
465
+ * page views based on the matched routes.
466
+ */
467
+ export const Router: Record<string, any>;
468
+
469
+ /**
470
+ * Cradova Screen
471
+ * ---
472
+ * create instances of manageable pages and scaffolds
473
+ * @param name
474
+ * @param template
475
+ * @param transitions
476
+ */
477
+ export class Screen {
478
+ /**
479
+ * this should be a cradova screen component
480
+ */
481
+ _html: Function;
482
+ /**
483
+ * this is a set of added html to the screen
484
+ */
485
+ _secondaryChildren: Array<Node>;
486
+ /**
487
+ * error handler for the screen
488
+ */
489
+ errorHandler: (() => void) | null;
490
+ /**
491
+ * used internally
492
+ */
493
+ _name: string;
494
+ private _packed;
495
+ private _template;
496
+ private _callBack;
497
+ private _deCallBack;
498
+ private _persist;
499
+ private _data;
500
+ _params: Record<string, any> | null;
501
+ private _delegatedRoutesCount;
502
+ private _transition;
503
+ constructor(cradova_screen_initials: CradovaScreenType);
504
+ get _delegatedRoutes(): boolean;
505
+ set _delegatedRoutes(count: boolean);
506
+ get _paramData(): typeof this._params;
507
+ set _paramData(params: typeof this._params);
508
+ setErrorHandler(errorHandler: () => void): void;
509
+ _package(): Promise<void>;
510
+ onActivate(cb: () => Promise<void> | void): void;
511
+ onDeactivate(cb: () => Promise<void> | void): void;
512
+ addChild(...addOns: any[]): void;
513
+ _deActivate(): Promise<void>;
514
+ _Activate(force?: boolean): Promise<void>;
515
+ }
595
516
 
596
517
  /**
597
518
  * Cradova
@@ -613,11 +534,6 @@ css(".btn:hover",
613
534
  * color: "blue"
614
535
  * }
615
536
  * })
616
- * // or no style props it works!
617
- * _("p",{
618
- * text: "am a p tag",
619
- * color: "blue"
620
- * })
621
537
  *
622
538
  * // props and children
623
539
  * _("p", // template first
@@ -628,17 +544,6 @@ css(".btn:hover",
628
544
  * ...
629
545
  * )
630
546
  *
631
- * // list of children
632
- * _("p",
633
- * // all children goes after
634
- * _("span",
635
- * {
636
- * text:" am a span tag like so",
637
- * color: "brown",
638
- * }),
639
- * ...
640
- * )
641
- *
642
547
  * @param {...any[]} element_initials
643
548
  * @returns function - cradova element
644
549
  */