cradova 1.2.0 → 1.4.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/dist/index.d.ts CHANGED
@@ -1,56 +1,82 @@
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
+ */
9
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
+ * re-renders the screen -
27
+ *
28
+ * first level call will only be called once
29
+ * lower level calls will be continuously called
30
+ * @param data .
31
+ *
32
+ * *
33
+ */
34
+
35
+ updateState(data: unknown): void;
36
+ };
37
+
38
+ type CradovaElementType = Record<string, any>;
39
+
10
40
  type RefType = {
11
41
  /**
12
42
  * Cradova Ref
13
43
  * ---
14
44
  * returns html with cradova reference
15
45
  * @param data
16
- * @returns html
46
+ * @returns HTMLElement
17
47
  */
18
- render: (data: any) => () => HTMLElement;
48
+ render(data?: any): () => any;
19
49
  /**
20
50
  * Cradova Ref
21
51
  * ---
22
- * runs on every state update
23
- *
52
+ * checks if element is in the dom and returns it.
53
+ * @param data
54
+ * @return HTMLElement
24
55
  */
25
- r: (data: any) => () => HTMLElement;
56
+ instance(): HTMLElement | null;
26
57
  /**
27
58
  * Cradova Ref
28
59
  * ---
29
- * runs on every state update
30
- *
60
+ * update ref component with new data and update the dom.
61
+ * @param data
62
+ * @returns void
31
63
  */
32
- onStateUpdate: (callback: () => void) => void;
64
+ updateState(data: any): void;
33
65
  /**
34
66
  * Cradova Ref
35
67
  * ---
36
- * update ref component with new data and update the dom.
68
+ * remove element from the dom
37
69
  * @param data
38
- * @returns void
70
+ * @returns () => HTMLElement
39
71
  */
40
- updateState: (data: any) => any;
72
+ remove(): void;
41
73
  /**
42
74
  * Cradova Ref
43
75
  * ---
44
- * update ref component with new data and update the dom.
45
- * @param data
46
- * @returns void
76
+ * runs once on render
77
+ *
47
78
  */
48
- u: (data: any) => any;
49
- };
50
- type RouterRouteObject = {
51
- controller: (params: object, force?: boolean) => any;
52
- deactivate: (params: object) => any;
53
- packager: (params: any) => void;
79
+ effect(fn: (data: unknown) => Promise<void> | void): void;
54
80
  };
55
81
  /**
56
82
  * Cradova Router
@@ -58,65 +84,76 @@ declare module "cradova" {
58
84
  * Facilitates navigation within the application and initializes
59
85
  * page views based on the matched routes.
60
86
  */
61
- type RouterType =
62
- | {
63
- /**
64
- * Registers a route.
65
- *
66
- * @param {string} path Route path.
67
- * @param {any} screen the cradova document tree for the route.
68
- */
69
- route: (path: string, screen: CradovaScreenType) => void;
70
- /**
71
- * get a screen ready before time.
72
- *
73
- * @param {string} path Route path.
74
- * @param {any} data data for the screen.
75
- */
76
- packageScreen: (path: string, data?: any) => void;
77
- onPageShow: (callback: () => void) => void;
78
- onPageHide: (callback: () => void) => void;
79
- /**
80
- * Cradova Router
81
- * ------
82
- *
83
- * Navigates to a designated screen in your app
84
- */
85
- navigate: (
86
- href: string,
87
- data?: Record<string, any> | null,
88
- force?: boolean
89
- ) => void;
90
- }
91
- | Record<string, any>;
92
-
93
- /**
94
- * @param name
95
- * @param template
96
- * @param transitions
97
- */
98
- export class Screen {
87
+ type RouterType = {
99
88
  /**
100
- * this should be a cradova screen component
89
+ * Registers a route.
90
+ *
91
+ * @param {string} path Route path.
92
+ * @param {any} screen the cradova document tree for the route.
101
93
  */
102
- private html;
94
+ route: (path: string, screen: CradovaScreenType) => void;
103
95
  /**
104
- * this is the name of the screen that appears as the title
96
+ * get a screen ready before time.
97
+ *
98
+ * @param {string} path Route path.
99
+ * @param {any} data data for the screen.
105
100
  */
106
- name: string;
107
- private packed;
108
- secondaryChildren: Array<any>;
101
+ packageScreen: (path: string, data?: any) => void;
102
+ onPageShow: (callback: () => void) => void;
103
+ onPageHide: (callback: () => void) => void;
104
+ /**
105
+ * Cradova Router
106
+ * ------
107
+ *
108
+ * return last set router params
109
+ *
110
+ * .
111
+ */
112
+ getParams: () => unknown;
109
113
  /**
110
- * used internally
114
+ * Cradova Router
115
+ * ------
116
+ *
117
+ * Navigates to a designated screen in your app
111
118
  */
112
- private template;
119
+ navigate: (
120
+ href: string,
121
+ data?: Record<string, any> | null,
122
+ force?: boolean
123
+ ) => void;
124
+
113
125
  /**
114
- * this a set of two class names
115
- * one for the entry transition
116
- * and one for the exit transition
126
+ * Cradova
127
+ * ---
128
+ * Error Handler for your app
129
+ *
130
+ * @param callback
131
+ * @param path? page path
117
132
  */
118
- private transition;
119
- private callBack;
133
+
134
+ addErrorHandler: (callback: (error: string) => void, path?: string) => void;
135
+ };
136
+
137
+ /**
138
+ * Cradova
139
+ * ---
140
+ * Cradova afterMount event
141
+ *
142
+ * dispatch this manually if you are not using a cradova screen object
143
+ *
144
+ */
145
+
146
+ export const cradovaAftermountEvent: CustomEvent<string>;
147
+
148
+ /**
149
+ * Cradova Screen
150
+ * ---
151
+ * create instances of manageable pages
152
+ * @param name
153
+ * @param template
154
+ * @param transitions
155
+ */
156
+ export class Screen {
120
157
  static SCALE_IN: string;
121
158
  static SCALE_OUT: string;
122
159
  static CIRCLE_IN: string;
@@ -128,28 +165,39 @@ declare module "cradova" {
128
165
  static SLIDE_LEFT: string;
129
166
  static SLIDE_RIGHT: string;
130
167
  /**
131
- * this tells cradova to persist state on the screen or not
132
- * persisting is better
168
+ * Cradova Screen
169
+ * ---
170
+ * create instances of manageable pages
171
+ * @param name
172
+ * @param template
173
+ * @param transitions
174
+ */
175
+ constructor(cradova_screen_initials: CradovaScreenTyping);
176
+ /**
177
+ * Cradova Screen
178
+ * ---
179
+ * runs once after first render
180
+ *
133
181
  */
134
- persist: boolean;
135
- rendered: boolean;
136
- effects: (() => unknown | Promise<unknown>)[];
137
- constructor(cradova_screen_initials: CradovaScreenType);
138
- effect(fn: () => unknown | Promise<unknown>): void;
139
- effector(): Promise<void>;
182
+ effect(fn: () => void | Promise<void>): void;
140
183
  package(data?: any): Promise<void>;
141
184
  onActivate(cb: (data: any) => void): void;
142
185
  addChild(...addOns: any[]): void;
143
186
  deActivate(): void;
144
187
  Activate(data?: any, force?: boolean): Promise<void>;
145
- }
188
+ /**
189
+ * Cradova Screen
190
+ * ---
191
+ * re-renders the screen -
192
+ *
193
+ * first level call will only be called once
194
+ * lower level calls will be continuously called
195
+ * @param data .
196
+ *
197
+ * *
198
+ */
146
199
 
147
- export class Scaffold {
148
- private history;
149
- private Scaffolds;
150
- push(label: string, data?: unknown, force?: boolean): Promise<void>;
151
- pop(data?: unknown, force?: boolean): Promise<void>;
152
- addScaffolds(scaffolds: Record<string, CradovaScreenType>): Promise<void>;
200
+ updateState(data: unknown): void;
153
201
  }
154
202
 
155
203
  /**
@@ -179,12 +227,12 @@ declare module "cradova" {
179
227
  * ability to:
180
228
  * - create a store
181
229
  * - create actions and fire them
182
- * - bind a Ref or RefList
230
+ * - bind a Ref
183
231
  * - listen to changes
184
232
  * - persist changes to localStorage
185
233
  * - go back and forward in value history
186
234
  * - set keys instead of all values
187
- * - update a cradova Ref/RefList automatically
235
+ * - update a cradova Ref automatically
188
236
  * @constructor initial: any, props: {useHistory, persist}
189
237
  */
190
238
  export class createSignal {
@@ -315,14 +363,14 @@ declare module "cradova" {
315
363
  * ability to:
316
364
  * - create a store
317
365
  * - set keys instead of all values
318
- * - update a cradova Ref/RefList/RefElement automatically
319
- * @constructor initial: any, Ref/RefList/RefElement: any
366
+ * - update a cradova Ref automatically
367
+ * @constructor initial: any, Ref: any
320
368
  */
321
369
 
322
- export class simpleStore {
370
+ export class $ {
323
371
  private ref;
324
372
  value: any;
325
- constructor(initial: unknown, ref?: RefType);
373
+ constructor(initial: unknown);
326
374
  /**
327
375
  * Cradova simpleStore
328
376
  * ----
@@ -342,13 +390,14 @@ declare module "cradova" {
342
390
  setKey(name: string, value: any, shouldRefRender?: boolean): void;
343
391
  /**
344
392
  * Cradova simpleStore
345
- * ----
346
- * set a auto - rendering component for this store
393
+ * ---
394
+ * is used to bind store data to any element
347
395
  *
348
- * @param Ref component to bind to.
349
- * @param path a property in the object to send to attached ref
396
+ * @param prop
397
+ * @returns something
350
398
  */
351
- bindRef(Ref: any): void;
399
+
400
+ bind(prop: string): void;
352
401
  }
353
402
 
354
403
  /**
@@ -373,53 +422,9 @@ declare module "cradova" {
373
422
  | any
374
423
  ): Promise<unknown>;
375
424
 
376
- /**
377
- * swipe
378
- * ---
379
- * Now you can detect swipes the best way possible
380
- *
381
- * @param callback
382
- * @param touching?
383
- * @param element?
384
- */
385
- export function swipe(
386
- callback: (swipe_data: Record<string, number>) => void,
387
- touching?: boolean,
388
- element?: HTMLElement
389
- ): {
390
- start(): void;
391
- stop(): void;
392
- };
393
-
394
425
  export function loadCradovaUICss(seconds?: number): void;
395
-
396
- export function IsElementInView(element: HTMLElement): boolean;
397
-
398
- export const controls: () => void;
399
426
  export function uuid(): string;
400
- export function PromptBeforeLeave(callback?: (e: any) => void): void;
401
- /**
402
- Write CSS media in javascript
403
427
 
404
- @example
405
-
406
- _.media("min-width: 790px",
407
- ["#container",
408
- {
409
- width: "100%",
410
- height: "100%",
411
- "background-color": "#0000"
412
- }],
413
-
414
- ["#header",
415
- {
416
- width: "100%",
417
- height: "20%",
418
- "background-color": "#fff"
419
- }]
420
- )
421
- */
422
- export function media(value: string, ...properties: any[]): void;
423
428
  /**
424
429
  Write CSS styles in Javascript
425
430
  @example
@@ -441,32 +446,9 @@ css(".btn:hover",
441
446
  */
442
447
  export function css(
443
448
  identifier: string,
444
- properties: Record<string, string>
449
+ properties?: Record<string, string>
445
450
  ): void;
446
451
  /**
447
- Write animation value in javascript
448
-
449
- @example
450
-
451
- _.animate("polarization",
452
- ["from",
453
- {
454
- transform: "scale3D(2)" ,
455
- height: "10%",
456
- "background-color": "#0000"
457
- }],
458
-
459
- ["to",
460
- {
461
- transform: "scale3D(1)" ,
462
- height: "100%",
463
- "background-color": "#ff9800"
464
- }]
465
- )
466
-
467
- */
468
- export function animate(identifier: string, ...properties: any[]): void;
469
- /**
470
452
  *
471
453
  * @param {expression} condition
472
454
  * @param {function} callback
@@ -480,50 +462,18 @@ _.animate("polarization",
480
462
  ifTrue: () => any,
481
463
  ifFalse: () => any
482
464
  ): () => any;
483
- /** @deprecated
484
- *
465
+ /**
485
466
  * Create element and get a callback to update their state
486
467
  * no need to manage stateIDs
487
468
  * ----------------------------------------------------------------
488
- * please use element.updateState(state) instead in listeners and mount events
489
- * ---
490
469
  *
491
470
  * @param element_initials
492
471
  * @param props
493
472
  * @returns
494
473
  */
495
- export function RefElement(
496
- element_initials?: string,
497
- props?: any,
498
- ...other: any
499
- ): {
500
- render(data?: any): any;
501
- r(data?: any): any;
502
- instance(): any;
503
- i(): any;
504
- updateState(state: Record<string, any>): void;
505
- u(state: Record<string, any>): void;
506
- };
474
+
507
475
  export const ls: Record<string, Function>;
508
- export function fullScreen(e: Element): {
509
- set(): void;
510
- exist(): void;
511
- };
512
- export class RefList {
513
- private component;
514
- private stateID;
515
- private parentElement;
516
- private datas;
517
- constructor(component: (...data: any) => any);
518
- stale(datas: any): void;
519
- r(d?: any): any;
520
- u(d?: any): void;
521
- render(datas?: any): any;
522
- updateState(datas: any[]): void;
523
- remove(): void;
524
- instance(): any;
525
- i(): any;
526
- }
476
+
527
477
  /**
528
478
  * Cradova Ref
529
479
  * -------
@@ -531,31 +481,23 @@ _.animate("polarization",
531
481
  *
532
482
  */
533
483
  export class Ref {
534
- private component;
535
- private stateID;
536
- private upcb;
537
- private data;
538
484
  constructor(component: (...data: any) => any);
539
- stale(data: any): void;
540
- r(d?: any): () => any;
541
- u(d?: any): void;
542
485
  /**
543
486
  * Cradova Ref
544
487
  * ---
545
488
  * returns html with cradova reference
546
489
  * @param data
547
- * @returns () => HTMLElement
490
+ * @returns HTMLElement
548
491
  */
549
492
  render(data?: any): () => any;
550
- instance(): any;
551
- i(): any;
552
493
  /**
553
494
  * Cradova Ref
554
495
  * ---
555
- * runs on every state update
556
- *
496
+ * checks if element is in the dom and returns it.
497
+ * @param data
498
+ * @return HTMLElement
557
499
  */
558
- onStateUpdate(cb: any): void;
500
+ instance(): HTMLElement | null;
559
501
  /**
560
502
  * Cradova Ref
561
503
  * ---
@@ -564,86 +506,73 @@ _.animate("polarization",
564
506
  * @returns void
565
507
  */
566
508
  updateState(data: any): void;
509
+ /**
510
+ * Cradova Ref
511
+ * ---
512
+ * remove element from the dom
513
+ * @param data
514
+ * @returns () => HTMLElement
515
+ */
567
516
  remove(): void;
517
+ /**
518
+ * Cradova Ref
519
+ * ---
520
+ * runs once on render
521
+ *
522
+ */
523
+ effect(fn: (data: unknown) => Promise<void> | void): void;
568
524
  }
525
+
569
526
  /**
570
- * Document fragment
571
- * @param children
572
- * @returns
573
- */
574
- type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
575
- export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
576
- /**
527
+ * Cradova
528
+ * ---
577
529
  * Creates new cradova HTML element
578
530
  * @example
579
- * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
580
- * using inline props
531
+ * // using template
532
+ * const p = _("p");
533
+ * _("p.class");
534
+ * _("p#id");
535
+ * _("p.class#id");
536
+ * _("p.foo.bar#poo.loo");
537
+ *
538
+ * // using inline props
539
+ *
581
540
  * _("p",{
582
541
  * text: "am a p tag",
583
542
  * style: {
584
543
  * color: "blue"
585
544
  * }
586
- * )
587
- * adding children
588
- * _("p",
589
- * _("span",{text:" am a span tag like so",
590
- * {style: {color: "brown"}
591
545
  * })
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
546
+ * // or no style props it works!
617
547
  * _("p",{
618
548
  * text: "am a p tag",
619
- * style: {
620
549
  * color: "blue"
621
- * }
622
- * )
623
- * adding children
624
- * _("p",
625
- * _("span",{text:" am a span tag like so",
626
- * {style: {color: "brown"}
627
550
  * })
551
+ *
552
+ * // props and children
553
+ * _("p", // template first
554
+ * // property next if wanted
555
+ * {style: {color: "brown"}, // optional
556
+ * // the rest should be children or text
557
+ * _("span", " am a span tag text like so"),
558
+ * ...
628
559
  * )
629
560
  *
630
- * props and children
561
+ * // list of children
631
562
  * _("p",
632
- * // props first
633
- * {
634
- * text: "am a p tag",
635
- * style: {
636
- * color: "blue"
637
- * },
638
563
  * // all children goes after
639
- * _("span",{text:" am a span tag like so",
640
- * {style: {color: "brown"}
641
- * })
564
+ * _("span",
565
+ * {
566
+ * text:" am a span tag like so",
567
+ * color: "brown",
568
+ * }),
569
+ * ...
642
570
  * )
643
571
  *
644
- * @param {...any} element_initials
572
+ * @param {...any[]} element_initials
645
573
  * @returns function - cradova element
646
574
  */
575
+
647
576
  const _: any;
648
577
  export default _;
649
578
  }