cradova 1.0.10 → 1.1.1

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
@@ -74,11 +74,11 @@ Happy coding.
74
74
  ```html
75
75
  <!-- unpkg -->
76
76
 
77
- <script src="https://unpkg.com/cradova/dist/module.js"></script>
77
+ <script src="https://unpkg.com/cradova/dist/index.js"></script>
78
78
 
79
- <!-- jsdeliver -->
79
+ <!-- js deliver -->
80
80
 
81
- <script src="https://cdn.jsdelivr.net/npm/cradova/dist/module.js"></script>
81
+ <script src="https://cdn.jsdelivr.net/npm/cradova/dist/index.js"></script>
82
82
  ```
83
83
 
84
84
  ### npm
package/dist/index.d.ts CHANGED
@@ -1,46 +1,657 @@
1
- export { swipe } from "./sacho/swipe";
2
- export { Signal as createSignal } from "./scripts/createSignal";
3
- export { Router } from "./scripts/Router";
4
- export { Screen } from "./scripts/Screen";
5
- export { Scaffold } from "./scripts/Scaffold";
6
- export { dispatch } from "./scripts/track";
7
- export { Ajax } from "./scripts/ajax";
8
- export { IsElementInView } from "./scripts/utils";
9
- export { frag, fullScreen, assert, uuid, animate, controls, PromptBeforeLeave, RefElement, css, media, ls, Ref, RefList, assertOr, } from "./scripts/fns";
10
- /**
11
- * Creates new cradova HTML element
12
- * @example
13
- * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
14
- * using inline props
15
- * _("p",{
16
- * text: "am a p tag",
17
- * style: {
18
- * color: "blue"
19
- * }
20
- * )
21
- * adding children
22
- * _("p",
23
- * _("span",{text:" am a span tag like so",
24
- * {style: {color: "brown"}
25
- * })
26
- * )
27
- *
28
- * props and children
29
- * _("p",
30
- * // props first
31
- * {
32
- * text: "am a p tag",
33
- * style: {
34
- * color: "blue"
35
- * },
36
- * // all children goes after
37
- * _("span",{text:" am a span tag like so",
38
- * {style: {color: "brown"}
39
- * })
40
- * )
41
- *
42
- * @param {...any} element_initials
43
- * @returns function - cradova element
44
- */
45
- declare const _: any;
46
- export default _;
1
+ declare module "cradova" {
2
+ type CradovaScreenType = {
3
+ name: string;
4
+ template: Function | HTMLElement;
5
+ transition?: string;
6
+ callBack?: (html?: any, data?: Record<string, any>) => void;
7
+ persist?: boolean;
8
+ effect?: (fn: () => any) => void;
9
+ };
10
+ type RefType = {
11
+ /**
12
+ * Cradova Ref
13
+ * ---
14
+ * returns html with cradova reference
15
+ * @param data
16
+ * @returns html
17
+ */
18
+ render: (data: any) => () => HTMLElement;
19
+ /**
20
+ * Cradova Ref
21
+ * ---
22
+ * runs on every state update
23
+ *
24
+ */
25
+ r: (data: any) => () => HTMLElement;
26
+ /**
27
+ * Cradova Ref
28
+ * ---
29
+ * runs on every state update
30
+ *
31
+ */
32
+ onStateUpdate: (callback: () => void) => void;
33
+ /**
34
+ * Cradova Ref
35
+ * ---
36
+ * update ref component with new data and update the dom.
37
+ * @param data
38
+ * @returns void
39
+ */
40
+ updateState: (data: any) => any;
41
+ /**
42
+ * Cradova Ref
43
+ * ---
44
+ * update ref component with new data and update the dom.
45
+ * @param data
46
+ * @returns void
47
+ */
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;
54
+ };
55
+ /**
56
+ * Cradova Router
57
+ * ---
58
+ * Facilitates navigation within the application and initializes
59
+ * page views based on the matched routes.
60
+ */
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
+ 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
+ /**
80
+ * get a screen ready before time.
81
+ *
82
+ * @param {string} path Route path.
83
+ * @param {any} data data for the screen.
84
+ */
85
+ packageScreen: (path: string, data?: any) => void;
86
+ pageShow: ((path: string) => void) | null;
87
+ pageHide: ((path: string) => void) | null;
88
+ onPageShow: (callback: () => void) => void;
89
+ onPageHide: (callback: () => void) => void;
90
+ /**
91
+ * Cradova Router
92
+ * ------
93
+ *
94
+ * Navigates to a designated screen in your app
95
+ */
96
+ navigate: (
97
+ href: string,
98
+ data?: Record<string, any> | null,
99
+ force?: boolean
100
+ ) => void;
101
+ }
102
+ | Record<string, any>;
103
+
104
+ /**
105
+ * @param name
106
+ * @param template
107
+ * @param transitions
108
+ */
109
+ 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
+ static SCALE_IN: string;
132
+ static SCALE_OUT: string;
133
+ static CIRCLE_IN: string;
134
+ static CIRCLE_OUT: string;
135
+ static FADE_OUT: string;
136
+ static FADE_IN: string;
137
+ static SLIDE_UP: string;
138
+ static SLIDE_DOWN: string;
139
+ static SLIDE_LEFT: string;
140
+ static SLIDE_RIGHT: string;
141
+ /**
142
+ * this tells cradova to persist state on the screen or not
143
+ * persisting is better
144
+ */
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>;
151
+ package(data?: any): Promise<void>;
152
+ onActivate(cb: (data: any) => void): void;
153
+ addChild(...addOns: any[]): void;
154
+ deActivate(): void;
155
+ Activate(data?: any, force?: boolean): Promise<void>;
156
+ }
157
+
158
+ export class Scaffold {
159
+ private history;
160
+ private Scaffolds;
161
+ push(label: string, data?: unknown, force?: boolean): Promise<void>;
162
+ pop(data?: unknown, force?: boolean): Promise<void>;
163
+ addScaffolds(scaffolds: Record<string, CradovaScreenType>): Promise<void>;
164
+ }
165
+
166
+ /**
167
+ * Cradova Router
168
+ * ---
169
+ * Facilitates navigation within the application and initializes
170
+ * page views based on the matched routes.
171
+ */
172
+ export const Router: RouterType;
173
+
174
+ /**
175
+ * Send a new state to specified element with stateID
176
+ *
177
+ * @param stateID
178
+ * @param state
179
+ * @returns element(s)
180
+ */
181
+ export function dispatch(
182
+ stateID: string | Record<string, any>,
183
+ state?: Record<string, any>
184
+ ): any;
185
+
186
+ /**
187
+ * Cradova Signal
188
+ * ----
189
+ * create stateful data store.
190
+ * ability to:
191
+ * - create a store
192
+ * - create actions and fire them
193
+ * - bind a Ref or RefList
194
+ * - listen to changes
195
+ * - persist changes to localStorage
196
+ * - go back and forward in value history
197
+ * - set keys instead of all values
198
+ * - update a cradova Ref/RefList automatically
199
+ * @constructor initial: any, props: {useHistory, persist}
200
+ */
201
+ export class Signal {
202
+ private callback;
203
+ private persistName;
204
+ private actions;
205
+ private useHistory;
206
+ private history;
207
+ private ref;
208
+ private index;
209
+ private path;
210
+ value: any;
211
+ constructor(
212
+ initial: unknown,
213
+ props?: {
214
+ useHistory?: boolean;
215
+ persistName?: string | undefined;
216
+ }
217
+ );
218
+ /**
219
+ * Cradova Signal
220
+ * ----
221
+ * set signal value
222
+ * @param value - signal value
223
+ * @returns void
224
+ */
225
+ set(value: unknown, shouldRefRender?: boolean): void;
226
+ /**
227
+ * Cradova Signal
228
+ * ----
229
+ * set a key value if it's an object
230
+ * @param name - name of the key
231
+ * @param value - value of the key
232
+ * @returns void
233
+ */
234
+ setKey(name: string, value: any, shouldRefRender?: boolean): void;
235
+ /**
236
+ * Cradova Signal
237
+ * ----
238
+ * set a prop value inside an object prop of the store
239
+ * @param key - a prop of the store - object value
240
+ * @param name - prop of the key object
241
+ * @param value - value of the name
242
+ * @returns void
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
+ setIndex(
260
+ key: string,
261
+ index: number,
262
+ value: any,
263
+ shouldRefRender?: boolean
264
+ ): void;
265
+ /**
266
+ * Cradova Signal
267
+ * ----
268
+ * set a key to signal an action
269
+ * @param name - name of the action
270
+ * @param action function to execute
271
+ */
272
+ createAction(
273
+ name: string | Record<string, (self?: any, data?: any) => void>,
274
+ action?: (self?: any, data?: any) => void
275
+ ): void;
276
+ /**
277
+ * Cradova Signal
278
+ * ----
279
+ * fires an action if available
280
+ * @param name - string name of the action
281
+ * @param data - data for the action
282
+ */
283
+ fireAction(name: string, data?: any): void;
284
+ /**
285
+ * Cradova Signal
286
+ * ----
287
+ * set a auto - rendering component for this store
288
+ *
289
+ * @param Ref component to bind to.
290
+ * @param path a property in the object to send to attached ref
291
+ */
292
+ bindRef(Ref: any, path?: string): void;
293
+ /**
294
+ * Cradova Signal
295
+ * ----
296
+ * set signal value to a future one
297
+ * @returns void
298
+ */
299
+ forward(): void;
300
+ /**
301
+ * Cradova Signal
302
+ * ----
303
+ * set signal value to a old past one
304
+ * @returns void
305
+ */
306
+ backward(): void;
307
+ /**
308
+ * Cradova Signal
309
+ * ----
310
+ * set a update listener on value changes
311
+ * @param callback
312
+ */
313
+ listen(callback: (a: any) => void): void;
314
+ /**
315
+ * Cradova Signal
316
+ * ----
317
+ * clear the history on local storage
318
+ */
319
+ clearPersist(): void;
320
+ }
321
+
322
+ /**
323
+ * Cradova simpleStore
324
+ * ----
325
+ * create stateful data store.
326
+ * ability to:
327
+ * - create a store
328
+ * - set keys instead of all values
329
+ * - update a cradova Ref/RefList/RefElement automatically
330
+ * @constructor initial: any, Ref/RefList/RefElement: any
331
+ */
332
+
333
+ export class simpleStore {
334
+ private ref;
335
+ value: any;
336
+ constructor(initial: unknown, ref: RefType);
337
+ /**
338
+ * Cradova simpleStore
339
+ * ----
340
+ * set simpleStore value
341
+ * @param value - simpleStore value
342
+ * @returns void
343
+ */
344
+ set(value: unknown, shouldRefRender?: boolean): void;
345
+ /**
346
+ * Cradova simpleStore
347
+ * ----
348
+ * set a key value if it's an object
349
+ * @param name - name of the key
350
+ * @param value - value of the key
351
+ * @returns void
352
+ */
353
+ setKey(name: string, value: any, shouldRefRender?: boolean): void;
354
+ /**
355
+ * Cradova simpleStore
356
+ * ----
357
+ * set a auto - rendering component for this store
358
+ *
359
+ * @param Ref component to bind to.
360
+ * @param path a property in the object to send to attached ref
361
+ */
362
+ bindRef(Ref: any): void;
363
+ }
364
+
365
+ /**
366
+ *
367
+ * Cradova Ajax
368
+ * ------------------
369
+ * your new axios alternative
370
+ * supports files upload
371
+ * @param url string
372
+ * @param {{method: string;data;header;callbacks;}} opts
373
+ * @returns any
374
+ */
375
+ export function Ajax(
376
+ url: string | URL,
377
+ opts?:
378
+ | {
379
+ method?: string;
380
+ data?: Record<string, any>;
381
+ header?: Record<string, any>;
382
+ callbacks?: Record<string, (arg: any) => void>;
383
+ }
384
+ | any
385
+ ): Promise<unknown>;
386
+
387
+ /**
388
+ * swipe
389
+ * ---
390
+ * Now you can detect swipes the best way possible
391
+ *
392
+ * @param callback
393
+ * @param touching?
394
+ * @param element?
395
+ */
396
+ export function swipe(
397
+ callback: (swipe_data: Record<string, number>) => void,
398
+ touching?: boolean,
399
+ element?: HTMLElement
400
+ ): {
401
+ start(): void;
402
+ stop(): void;
403
+ };
404
+
405
+ export function loadCradovaUICss(seconds?: number): void;
406
+
407
+ export function IsElementInView(element: HTMLElement): boolean;
408
+
409
+ export const controls: () => void;
410
+ export function uuid(): string;
411
+ export function PromptBeforeLeave(callback?: (e: any) => void): void;
412
+ /**
413
+ Write CSS media in javascript
414
+
415
+ @example
416
+
417
+ _.media("min-width: 790px",
418
+ ["#container",
419
+ {
420
+ width: "100%",
421
+ height: "100%",
422
+ "background-color": "#0000"
423
+ }],
424
+
425
+ ["#header",
426
+ {
427
+ width: "100%",
428
+ height: "20%",
429
+ "background-color": "#fff"
430
+ }]
431
+ )
432
+ */
433
+ export function media(value: string, ...properties: any[]): void;
434
+ /**
435
+ Write CSS styles in Javascript
436
+ @example
437
+
438
+ css("#container",
439
+ {
440
+ height: "100%",
441
+ height: "100%",
442
+ background-color: "#ff9800"
443
+ })
444
+
445
+ css(".btn:hover",
446
+ {
447
+ height: "100%",
448
+ height: "100%",
449
+ background-color: "#ff9800"
450
+ })
451
+
452
+ */
453
+ export function css(
454
+ identifier: string,
455
+ properties: Record<string, string>
456
+ ): void;
457
+ /**
458
+ Write animation value in javascript
459
+
460
+ @example
461
+
462
+ _.animate("polarization",
463
+ ["from",
464
+ {
465
+ transform: "scale3D(2)" ,
466
+ height: "10%",
467
+ "background-color": "#0000"
468
+ }],
469
+
470
+ ["to",
471
+ {
472
+ transform: "scale3D(1)" ,
473
+ height: "100%",
474
+ "background-color": "#ff9800"
475
+ }]
476
+ )
477
+
478
+ */
479
+ export function animate(identifier: string, ...properties: any[]): void;
480
+ /**
481
+ *
482
+ * @param {expression} condition
483
+ * @param {function} callback
484
+ */
485
+ export function assert(
486
+ condition: any,
487
+ ...callback: (() => any)[]
488
+ ): "" | (() => any)[];
489
+ export function assertOr(
490
+ condition: any,
491
+ ifTrue: () => any,
492
+ ifFalse: () => any
493
+ ): () => any;
494
+ /**
495
+ * Create element and get a callback to update their state
496
+ * no need to manage stateIDs
497
+ * ----------------------------------------------------------------
498
+ *
499
+ * @param element_initials
500
+ * @param props
501
+ * @returns
502
+ */
503
+ export function RefElement(
504
+ element_initials?: string,
505
+ props?: any,
506
+ ...other: any
507
+ ): {
508
+ render(data?: any): any;
509
+ r(data?: any): any;
510
+ instance(): any;
511
+ i(): any;
512
+ updateState(state: Record<string, any>): void;
513
+ u(state: Record<string, any>): void;
514
+ };
515
+ export const ls: Record<string, Function>;
516
+ export function fullScreen(e: Element): {
517
+ set(): void;
518
+ exist(): void;
519
+ };
520
+ export class RefList {
521
+ private component;
522
+ private stateID;
523
+ private parentElement;
524
+ private datas;
525
+ constructor(component: (...data: any) => any);
526
+ stale(datas: any): void;
527
+ r(d?: any): any;
528
+ u(d?: any): void;
529
+ render(datas?: any): any;
530
+ updateState(datas: any[]): void;
531
+ remove(): void;
532
+ instance(): any;
533
+ i(): any;
534
+ }
535
+ /**
536
+ * Cradova Ref
537
+ * -------
538
+ * create dynamic components
539
+ *
540
+ */
541
+ export class Ref {
542
+ private component;
543
+ private stateID;
544
+ private upcb;
545
+ private data;
546
+ constructor(component: (...data: any) => any);
547
+ stale(data: any): void;
548
+ r(d?: any): () => any;
549
+ u(d?: any): void;
550
+ /**
551
+ * Cradova Ref
552
+ * ---
553
+ * returns html with cradova reference
554
+ * @param data
555
+ * @returns () => HTMLElement
556
+ */
557
+ render(data?: any): () => any;
558
+ instance(): any;
559
+ i(): any;
560
+ /**
561
+ * Cradova Ref
562
+ * ---
563
+ * runs on every state update
564
+ *
565
+ */
566
+ onStateUpdate(cb: any): void;
567
+ /**
568
+ * Cradova Ref
569
+ * ---
570
+ * update ref component with new data and update the dom.
571
+ * @param data
572
+ * @returns void
573
+ */
574
+ updateState(data: any): void;
575
+ remove(): void;
576
+ }
577
+ /**
578
+ * Document fragment
579
+ * @param children
580
+ * @returns
581
+ */
582
+ type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
583
+ export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
584
+ /**
585
+ * Creates new cradova HTML element
586
+ * @example
587
+ * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
588
+ * using inline props
589
+ * _("p",{
590
+ * text: "am a p tag",
591
+ * style: {
592
+ * color: "blue"
593
+ * }
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
+ * )
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
625
+ * _("p",{
626
+ * text: "am a p tag",
627
+ * style: {
628
+ * color: "blue"
629
+ * }
630
+ * )
631
+ * adding children
632
+ * _("p",
633
+ * _("span",{text:" am a span tag like so",
634
+ * {style: {color: "brown"}
635
+ * })
636
+ * )
637
+ *
638
+ * props and children
639
+ * _("p",
640
+ * // props first
641
+ * {
642
+ * text: "am a p tag",
643
+ * style: {
644
+ * color: "blue"
645
+ * },
646
+ * // all children goes after
647
+ * _("span",{text:" am a span tag like so",
648
+ * {style: {color: "brown"}
649
+ * })
650
+ * )
651
+ *
652
+ * @param {...any} element_initials
653
+ * @returns function - cradova element
654
+ */
655
+ const _: any;
656
+ export default _;
657
+ }