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