cradova 1.1.0 → 1.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +297 -224
  2. package/dist/index.js +816 -560
  3. package/package.json +18 -31
package/dist/index.d.ts CHANGED
@@ -1,21 +1,177 @@
1
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
+ };
2
55
  /**
3
- * swipe
56
+ * Cradova Router
4
57
  * ---
5
- * Now you can detect swipes the best way possible
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
+ /**
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 {
99
+ /**
100
+ * this should be a cradova screen component
101
+ */
102
+ private html;
103
+ /**
104
+ * this is the name of the screen that appears as the title
105
+ */
106
+ name: string;
107
+ private packed;
108
+ secondaryChildren: Array<any>;
109
+ /**
110
+ * used internally
111
+ */
112
+ private template;
113
+ /**
114
+ * this a set of two class names
115
+ * one for the entry transition
116
+ * and one for the exit transition
117
+ */
118
+ private transition;
119
+ private callBack;
120
+ static SCALE_IN: string;
121
+ static SCALE_OUT: string;
122
+ static CIRCLE_IN: string;
123
+ static CIRCLE_OUT: string;
124
+ static FADE_OUT: string;
125
+ static FADE_IN: string;
126
+ static SLIDE_UP: string;
127
+ static SLIDE_DOWN: string;
128
+ static SLIDE_LEFT: string;
129
+ static SLIDE_RIGHT: string;
130
+ /**
131
+ * this tells cradova to persist state on the screen or not
132
+ * persisting is better
133
+ */
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>;
140
+ package(data?: any): Promise<void>;
141
+ onActivate(cb: (data: any) => void): void;
142
+ addChild(...addOns: any[]): void;
143
+ deActivate(): void;
144
+ Activate(data?: any, force?: boolean): Promise<void>;
145
+ }
146
+
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>;
153
+ }
154
+
155
+ /**
156
+ * Cradova Router
157
+ * ---
158
+ * Facilitates navigation within the application and initializes
159
+ * page views based on the matched routes.
160
+ */
161
+ export const Router: RouterType;
162
+
163
+ /**
164
+ * Send a new state to specified element with stateID
6
165
  *
7
- * @param callback
8
- * @param touching?
9
- * @param element?
166
+ * @param stateID
167
+ * @param state
168
+ * @returns element(s)
10
169
  */
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
- };
170
+ export function dispatch(
171
+ stateID: string | Record<string, any>,
172
+ state?: Record<string, any>
173
+ ): any;
174
+
19
175
  /**
20
176
  * Cradova Signal
21
177
  * ----
@@ -32,6 +188,14 @@ declare module "cradova" {
32
188
  * @constructor initial: any, props: {useHistory, persist}
33
189
  */
34
190
  export class createSignal {
191
+ private callback;
192
+ private persistName;
193
+ private actions;
194
+ private useHistory;
195
+ private history;
196
+ private ref;
197
+ private index;
198
+ private path;
35
199
  value: any;
36
200
  constructor(
37
201
  initial: unknown,
@@ -143,156 +307,94 @@ declare module "cradova" {
143
307
  */
144
308
  clearPersist(): void;
145
309
  }
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;
310
+
311
+ /**
312
+ * Cradova simpleStore
313
+ * ----
314
+ * create stateful data store.
315
+ * ability to:
316
+ * - create a store
317
+ * - set keys instead of all values
318
+ * - update a cradova Ref/RefList/RefElement automatically
319
+ * @constructor initial: any, Ref/RefList/RefElement: any
320
+ */
321
+
322
+ export class simpleStore {
323
+ private ref;
324
+ value: any;
325
+ constructor(initial: unknown, ref?: RefType);
170
326
  /**
171
- * Cradova Ref
172
- * ---
173
- * runs on every state update
174
- *
327
+ * Cradova simpleStore
328
+ * ----
329
+ * set simpleStore value
330
+ * @param value - simpleStore value
331
+ * @returns void
175
332
  */
176
- onStateUpdate: (callback: () => void) => void;
333
+ set(value: unknown, shouldRefRender?: boolean): void;
177
334
  /**
178
- * Cradova Ref
179
- * ---
180
- * update ref component with new data and update the dom.
181
- * @param data
335
+ * Cradova simpleStore
336
+ * ----
337
+ * set a key value if it's an object
338
+ * @param name - name of the key
339
+ * @param value - value of the key
182
340
  * @returns void
183
341
  */
184
- updateState: (data: any) => any;
342
+ setKey(name: string, value: any, shouldRefRender?: boolean): void;
185
343
  /**
186
- * Cradova Ref
187
- * ---
188
- * update ref component with new data and update the dom.
189
- * @param data
190
- * @returns void
344
+ * Cradova simpleStore
345
+ * ----
346
+ * set a auto - rendering component for this store
347
+ *
348
+ * @param Ref component to bind to.
349
+ * @param path a property in the object to send to attached ref
191
350
  */
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
- };
351
+ bindRef(Ref: any): void;
352
+ }
353
+
199
354
  /**
200
- * Cradova Router
201
- * ---
202
- * Facilitates navigation within the application and initializes
203
- * page views based on the matched routes.
355
+ *
356
+ * Cradova Ajax
357
+ * ------------------
358
+ * your new axios alternative
359
+ * supports files upload
360
+ * @param url string
361
+ * @param {{method: string;data;header;callbacks;}} opts
362
+ * @returns any
204
363
  */
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>;
364
+ export function Ajax(
365
+ url: string | URL,
366
+ opts?:
367
+ | {
368
+ method?: string;
369
+ data?: Record<string, any>;
370
+ header?: Record<string, any>;
371
+ callbacks?: Record<string, (arg: any) => void>;
372
+ }
373
+ | any
374
+ ): Promise<unknown>;
375
+
247
376
  /**
248
- * Cradova Router
377
+ * swipe
249
378
  * ---
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
379
+ * Now you can detect swipes the best way possible
380
+ *
381
+ * @param callback
382
+ * @param touching?
383
+ * @param element?
258
384
  */
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
- }
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
+ export function loadCradovaUICss(seconds?: number): void;
395
+
396
+ export function IsElementInView(element: HTMLElement): boolean;
397
+
296
398
  export const controls: () => void;
297
399
  export function uuid(): string;
298
400
  export function PromptBeforeLeave(callback?: (e: any) => void): void;
@@ -378,10 +480,13 @@ _.animate("polarization",
378
480
  ifTrue: () => any,
379
481
  ifFalse: () => any
380
482
  ): () => any;
381
- /**
483
+ /** @deprecated
484
+ *
382
485
  * Create element and get a callback to update their state
383
486
  * no need to manage stateIDs
384
487
  * ----------------------------------------------------------------
488
+ * please use element.updateState(state) instead in listeners and mount events
489
+ * ---
385
490
  *
386
491
  * @param element_initials
387
492
  * @param props
@@ -405,6 +510,10 @@ _.animate("polarization",
405
510
  exist(): void;
406
511
  };
407
512
  export class RefList {
513
+ private component;
514
+ private stateID;
515
+ private parentElement;
516
+ private datas;
408
517
  constructor(component: (...data: any) => any);
409
518
  stale(datas: any): void;
410
519
  r(d?: any): any;
@@ -422,6 +531,10 @@ _.animate("polarization",
422
531
  *
423
532
  */
424
533
  export class Ref {
534
+ private component;
535
+ private stateID;
536
+ private upcb;
537
+ private data;
425
538
  constructor(component: (...data: any) => any);
426
539
  stale(data: any): void;
427
540
  r(d?: any): () => any;
@@ -461,81 +574,41 @@ _.animate("polarization",
461
574
  type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
462
575
  export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
463
576
  /**
464
- * Send a new state to specified element with stateID
577
+ * Creates new cradova HTML element
578
+ * @example
579
+ * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
580
+ * using inline props
581
+ * _("p",{
582
+ * text: "am a p tag",
583
+ * style: {
584
+ * color: "blue"
585
+ * }
586
+ * )
587
+ * adding children
588
+ * _("p",
589
+ * _("span",{text:" am a span tag like so",
590
+ * {style: {color: "brown"}
591
+ * })
592
+ * )
465
593
  *
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
- /**
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
+ * )
475
607
  *
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
608
+ * @param {...any} element_initials
609
+ * @returns function - cradova element
483
610
  */
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
- };
611
+
539
612
  /**
540
613
  * Creates new cradova HTML element
541
614
  * @example