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