cradova 2.1.0 → 2.1.2

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 +647 -59
  2. package/dist/index.js +1540 -382
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,59 +1,647 @@
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 _;
1
+ declare module "cradova" {
2
+ /**
3
+ *
4
+ * Cradova Ajax
5
+ * ------------------
6
+ * your new axios alternative
7
+ * supports files upload
8
+ * @param url string
9
+ * @param {{method: string;data;header;callbacks;}} opts
10
+ * @returns any
11
+ */
12
+ export function Ajax(
13
+ url: string | URL,
14
+ opts?:
15
+ | {
16
+ method?: "GET" | "POST";
17
+ data?: Record<string, any>;
18
+ header?: {
19
+ "content-type": string;
20
+ } & Record<string, any>;
21
+ callbacks?: Record<string, (arg: any) => void>;
22
+ }
23
+ | any
24
+ ): Promise<unknown>;
25
+
26
+ /**
27
+ * Cradova Signal
28
+ * ----
29
+ * create stateful data store.
30
+ * ability to:
31
+ * - create a store
32
+ * - create actions and fire them
33
+ * - bind a Ref or RefList
34
+ * - listen to changes
35
+ * - persist changes to localStorage
36
+ * - set keys instead of all values
37
+ * - update a cradova Ref/RefList automatically
38
+ * @constructor initial: any, props: {useHistory, persist}
39
+ */
40
+ export class createSignal<Type> {
41
+ private callback;
42
+ private persistName;
43
+ private actions;
44
+ private ref;
45
+ private path;
46
+ value: Type;
47
+ constructor(
48
+ initial: Type,
49
+ props?: {
50
+ persistName?: string | undefined;
51
+ }
52
+ );
53
+ /**
54
+ * Cradova Signal
55
+ * ----
56
+ * set signal value
57
+ * @param value - signal value
58
+ * @returns void
59
+ */
60
+ set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
61
+ /**
62
+ * Cradova Signal
63
+ * ----
64
+ * set a key value if it's an object
65
+ * @param key - key of the key
66
+ * @param value - value of the key
67
+ * @returns void
68
+ */
69
+ setKey<k extends keyof Type>(
70
+ key: k,
71
+ value: any,
72
+ shouldRefRender?: boolean
73
+ ): void;
74
+ /**
75
+ * Cradova Signal
76
+ * ----
77
+ * set a key to signal an action
78
+ * @param key - key of the action
79
+ * @param action function to execute
80
+ */
81
+ createAction(
82
+ key: string | Record<string, (data?: Type) => void>,
83
+ action?: (data?: Type) => void
84
+ ): void;
85
+ /**
86
+ * Cradova Signal
87
+ * ----
88
+ * fires an action if available
89
+ * @param key - string key of the action
90
+ * @param data - data for the action
91
+ */
92
+ fireAction(key: string, data?: Type): void;
93
+ /**
94
+ * Cradova Signal
95
+ * ----
96
+ * set a auto - rendering component for this store
97
+ *
98
+ * @param Ref component to bind to.
99
+ * @param path a property in the object to send to attached ref
100
+ */
101
+ bindRef(Ref: any, path?: string): void;
102
+ /**
103
+ * Cradova Signal
104
+ * ----
105
+ * set a update listener on value changes
106
+ * @param callback
107
+ */
108
+ listen(callback: (a: any) => void): void;
109
+ /**
110
+ * Cradova Signal
111
+ * ----
112
+ * clear the history on local storage
113
+ *
114
+ *
115
+ * .
116
+ */
117
+ clearPersist(): void;
118
+ }
119
+
120
+ type stateType =
121
+ | Partial<HTMLElement>
122
+ | {
123
+ class?: string;
124
+ text?: string;
125
+ style?: Partial<CSSStyleDeclaration>;
126
+ tree?: Function | HTMLElement;
127
+ remove?: boolean;
128
+ };
129
+ type stateID = string;
130
+ /**
131
+ * Send a new state to specified element with stateID
132
+ *
133
+ * @param stateID
134
+ * @param state
135
+ * @returns element(s)
136
+ */
137
+ export function dispatch(
138
+ stateID: stateID | Record<stateID, stateType>,
139
+ state?: stateType
140
+ ): any;
141
+
142
+ type ElementType<T> = (
143
+ ...VJS: (
144
+ | string
145
+ | undefined
146
+ | Partial<T>
147
+ | HTMLElement
148
+ | (() => HTMLElement)
149
+ | {
150
+ style?: Partial<CSSStyleDeclaration>;
151
+ beforeMount?: () => void;
152
+ afterMount?: () => void;
153
+ text?: string;
154
+ stateID?: string;
155
+ shouldUpdate?: boolean;
156
+ }
157
+ )[]
158
+ ) => T;
159
+
160
+ /**
161
+ * Cradova Router
162
+ * ---
163
+ * Facilitates navigation within the application and initializes
164
+ * page views based on the matched routes.
165
+ */
166
+ type RouterType = {
167
+ /**
168
+ * Registers a route.
169
+ *
170
+ * @param {string} path Route path.
171
+ * @param {any} screen the cradova document tree for the route.
172
+ */
173
+ route: (path: string, screen: Screen) => void;
174
+ /**
175
+ * get a screen ready before time.
176
+ *
177
+ * @param {string} path Route path.
178
+ * @param {any} data data for the screen.
179
+ */
180
+ packageScreen: (path: string, data?: any) => Promise<void>;
181
+ onPageShow: (callback: () => void) => void;
182
+ onPageHide: (callback: () => void) => void;
183
+ /**
184
+ * Cradova Router
185
+ * ------
186
+ *
187
+ * return last set router params
188
+ *
189
+ * .
190
+ */
191
+ getParams: <D>() => { data: D | unknown; params: any };
192
+ /**
193
+ * Cradova Router
194
+ * ------
195
+ *
196
+ * Navigates to a designated screen in your app
197
+ */
198
+ navigate: (
199
+ href: string,
200
+ data?: Record<string, any> | null,
201
+ force?: boolean
202
+ ) => void;
203
+
204
+ /**
205
+ * Cradova
206
+ * ---
207
+ * Error Handler for your app
208
+ *
209
+ * @param callback
210
+ * @param path? page path
211
+ */
212
+
213
+ addErrorHandler: (callback: (error: string) => void, path?: string) => void;
214
+ };
215
+
216
+ /**
217
+ * Cradova Router
218
+ * ---
219
+ * Facilitates navigation within the application and initializes
220
+ * page views based on the matched routes.
221
+ */
222
+ export const Router: RouterType;
223
+
224
+ /**
225
+ *
226
+ */
227
+ type CradovaScreenType = {
228
+ /**
229
+ * Cradova screen
230
+ * ---
231
+ * title of the page
232
+ * @param data
233
+ * @returns void
234
+ *
235
+ *
236
+ * .
237
+ */
238
+ name: string;
239
+ /**
240
+ * Cradova screen
241
+ * ---
242
+ * The component for the screen
243
+ * @param data
244
+ * @returns void
245
+ *
246
+ *
247
+ * .
248
+ */
249
+ template: Function | HTMLElement;
250
+ /**
251
+ * Cradova screen
252
+ * ---
253
+ * Screen transition from the screen class
254
+ * @param data
255
+ * @returns void
256
+ *
257
+ *
258
+ * .
259
+ */
260
+ transition?: string;
261
+ /**
262
+ * Cradova screen
263
+ * ---
264
+ * gets called when the the screen is displayed
265
+ * @param data
266
+ * @returns void
267
+ *
268
+ *
269
+ * .
270
+ */
271
+ /**
272
+ * Cradova screen
273
+ * ---
274
+ * Should this screen be cached after first render?
275
+ * @param data
276
+ * @returns void
277
+ *
278
+ *
279
+ * .
280
+ */
281
+ persist?: boolean;
282
+ };
283
+
284
+ /**
285
+ * Cradova Screen
286
+ * ---
287
+ * create instances of manageable pages and scaffolds
288
+ * @param name
289
+ * @param template
290
+ * @param transitions
291
+ */
292
+ export class Screen {
293
+ /**
294
+ * this should be a cradova screen component
295
+ */
296
+ private html;
297
+ /**
298
+ * this is the name of the screen that appears as the title
299
+ */
300
+ private name;
301
+ private packed;
302
+ private secondaryChildren;
303
+ /**
304
+ * used internally
305
+ */
306
+ private template;
307
+ private callBack;
308
+ private deCallBack;
309
+ errorHandler: (() => void) | null;
310
+ /**
311
+ * this tells cradova to persist state on the screen or not
312
+ * persisting is better
313
+ */
314
+ private persist;
315
+ private data;
316
+ constructor(cradova_screen_initials: CradovaScreenType);
317
+ setErrorHandler(errorHandler: () => void): void;
318
+ package(): Promise<void>;
319
+ onActivate(cb: () => Promise<void> | void): void;
320
+ onDeactivate(cb: () => Promise<void> | void): void;
321
+ addChild(...addOns: any[]): void;
322
+ deActivate(): void;
323
+ Activate(force?: boolean): Promise<void>;
324
+ }
325
+
326
+ /**
327
+ * Cradova simpleStore
328
+ * ----
329
+ * create stateful data store.
330
+ * ability to:
331
+ * - create a store
332
+ * - set keys instead of all values
333
+ * - able to update state on any element as a property value
334
+ * @constructor initial: any, Ref/RefList/RefElement: any
335
+ */
336
+ export class $<Type extends Record<string, unknown>> {
337
+ private ref;
338
+ value: Type;
339
+ constructor(initial: Type);
340
+ /**
341
+ * Cradova simpleStore
342
+ * ----
343
+ * set simpleStore value
344
+ * @param value - simpleStore value
345
+ * @returns void
346
+ */
347
+ set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
348
+ /**
349
+ * Cradova
350
+ * ---
351
+ * is used to bind store data to any element
352
+ *
353
+ * @param prop
354
+ * @returns something
355
+ */
356
+ bind(prop: string): (string | this)[];
357
+ private updateState;
358
+ /**
359
+ * Cradova simpleStore
360
+ * ----
361
+ * set a key value if it's an object
362
+ * @param name - name of the key
363
+ * @param value - value of the key
364
+ * @returns void
365
+ */
366
+ setKey<k extends keyof Type>(
367
+ name: k,
368
+ value: any,
369
+ shouldRefRender?: boolean
370
+ ): void;
371
+ /**
372
+ * Cradova simpleStore
373
+ * ----
374
+ * set a auto - rendering component for this store
375
+ *
376
+ * @param Ref component to bind to.
377
+ * @param path a property in the object to send to attached ref
378
+ */
379
+ bindRef(ref: any, key: string, prop: string): void;
380
+ }
381
+
382
+ export const a: ElementType<HTMLAnchorElement>;
383
+ export const abbr: ElementType<HTMLElement>;
384
+ export const address: ElementType<HTMLElement>;
385
+ export const area: ElementType<HTMLAreaElement>;
386
+ export const article: ElementType<HTMLElement>;
387
+ export const aside: ElementType<HTMLElement>;
388
+ export const audio: ElementType<HTMLAudioElement>;
389
+ export const b: ElementType<HTMLElement>;
390
+ export const base: ElementType<HTMLBaseElement>;
391
+ export const bdi: ElementType<HTMLElement>;
392
+ export const bdo: ElementType<HTMLElement>;
393
+ export const blockquote: ElementType<HTMLElement>;
394
+ export const body: ElementType<HTMLBodyElement>;
395
+ export const br: ElementType<HTMLBRElement>;
396
+ export const button: ElementType<HTMLButtonElement>;
397
+ export const canvas: ElementType<HTMLCanvasElement>;
398
+ export const caption: ElementType<HTMLTableCaptionElement>;
399
+ export const cite: ElementType<HTMLElement>;
400
+ export const code: ElementType<HTMLElement>;
401
+ export const col: ElementType<HTMLTableColElement>;
402
+ export const colgroup: ElementType<HTMLElement>;
403
+ export const data: ElementType<HTMLDataElement>;
404
+ export const datalist: ElementType<HTMLDataListElement>;
405
+ export const dd: ElementType<HTMLElement>;
406
+ export const del: ElementType<HTMLElement>;
407
+ export const details: ElementType<HTMLDetailsElement>;
408
+ export const dfn: ElementType<HTMLElement>;
409
+ export const dialog: ElementType<HTMLDialogElement>;
410
+ export const div: ElementType<HTMLDivElement>;
411
+ export const dl: ElementType<HTMLElement>;
412
+ export const dt: ElementType<HTMLElement>;
413
+ export const em: ElementType<HTMLElement>;
414
+ export const embed: ElementType<HTMLEmbedElement>;
415
+ export const fieldset: ElementType<HTMLFieldSetElement>;
416
+ export const figcaption: ElementType<HTMLElement>;
417
+ export const figure: ElementType<HTMLElement>;
418
+ export const footer: ElementType<HTMLElement>;
419
+ export const form: ElementType<HTMLFormElement>;
420
+ export const h1: ElementType<HTMLHeadingElement>;
421
+ export const h2: ElementType<HTMLHeadingElement>;
422
+ export const h3: ElementType<HTMLHeadingElement>;
423
+ export const h4: ElementType<HTMLHeadingElement>;
424
+ export const h5: ElementType<HTMLHeadingElement>;
425
+ export const h6: ElementType<HTMLHeadingElement>;
426
+ export const head: ElementType<HTMLHeadElement>;
427
+ export const header: ElementType<HTMLElement>;
428
+ export const hr: ElementType<HTMLHRElement>;
429
+ export const html: ElementType<HTMLHtmlElement>;
430
+ export const i: ElementType<HTMLElement>;
431
+ export const iframe: ElementType<HTMLIFrameElement>;
432
+ export const img: ElementType<HTMLImageElement>;
433
+ export const input: ElementType<HTMLInputElement>;
434
+ export const ins: ElementType<HTMLElement>;
435
+ export const kbd: ElementType<HTMLElement>;
436
+ export const label: ElementType<HTMLLabelElement>;
437
+ export const legend: ElementType<HTMLLegendElement>;
438
+ export const li: ElementType<HTMLLIElement>;
439
+ export const link: ElementType<HTMLLinkElement>;
440
+ export const main: ElementType<HTMLElement>;
441
+ export const map: ElementType<HTMLMapElement>;
442
+ export const mark: ElementType<HTMLElement>;
443
+ export const math: ElementType<HTMLElement>;
444
+ export const menu: ElementType<HTMLMenuElement>;
445
+ export const meta: ElementType<HTMLMetaElement>;
446
+ export const meter: ElementType<HTMLMeterElement>;
447
+ export const nav: ElementType<HTMLElement>;
448
+ export const noscript: ElementType<HTMLElement>;
449
+ export const object: ElementType<HTMLObjectElement>;
450
+ export const ol: ElementType<HTMLOListElement>;
451
+ export const optgroup: ElementType<HTMLOptGroupElement>;
452
+ export const option: ElementType<HTMLOptionElement>;
453
+ export const output: ElementType<HTMLOutputElement>;
454
+ export const p: ElementType<HTMLParagraphElement>;
455
+ export const picture: ElementType<HTMLPictureElement>;
456
+ export const portal: ElementType<HTMLElement>;
457
+ export const pre: ElementType<HTMLPreElement>;
458
+ export const progress: ElementType<HTMLProgressElement>;
459
+ export const q: ElementType<HTMLQuoteElement>;
460
+ export const rp: ElementType<HTMLElement>;
461
+ export const rt: ElementType<HTMLElement>;
462
+ export const ruby: ElementType<HTMLElement>;
463
+ export const s: ElementType<HTMLElement>;
464
+ export const samp: ElementType<HTMLElement>;
465
+ export const script: ElementType<HTMLScriptElement>;
466
+ export const section: ElementType<HTMLElement>;
467
+ export const select: ElementType<HTMLSelectElement>;
468
+ export const slot: ElementType<HTMLSlotElement>;
469
+ export const small: ElementType<HTMLElement>;
470
+ export const source: ElementType<HTMLSourceElement>;
471
+ export const span: ElementType<HTMLSpanElement>;
472
+ export const strong: ElementType<HTMLElement>;
473
+ export const style: ElementType<HTMLStyleElement>;
474
+ export const sub: ElementType<HTMLElement>;
475
+ export const summary: ElementType<HTMLElement>;
476
+ export const sup: ElementType<HTMLElement>;
477
+ export const table: ElementType<HTMLTableElement>;
478
+ export const tbody: ElementType<HTMLTableColElement>;
479
+ export const td: ElementType<HTMLTableCellElement>;
480
+ export const template: ElementType<HTMLTemplateElement>;
481
+ export const textarea: ElementType<HTMLTextAreaElement>;
482
+ export const tfoot: ElementType<HTMLElement>;
483
+ export const th: ElementType<HTMLTableSectionElement>;
484
+ export const thead: ElementType<HTMLTableSectionElement>;
485
+ export const time: ElementType<HTMLTimeElement>;
486
+ export const title: ElementType<HTMLTitleElement>;
487
+ export const tr: ElementType<HTMLTableRowElement>;
488
+ export const track: ElementType<HTMLTrackElement>;
489
+ export const u: ElementType<HTMLElement>;
490
+ export const ul: ElementType<HTMLUListElement>;
491
+ export const val: ElementType<HTMLElement>;
492
+ export const video: ElementType<HTMLVideoElement>;
493
+ export const wbr: ElementType<HTMLElement>;
494
+
495
+ /**
496
+ * Cradova afterMount event
497
+ */
498
+ export let cradovaAftermountEvent: CustomEvent<unknown>;
499
+ /**
500
+ Write CSS styles in Javascript
501
+ @example
502
+
503
+ css("#container",
504
+ {
505
+ height: "100%",
506
+ height: "100%",
507
+ background-color: "#ff9800"
508
+ })
509
+
510
+ css(".btn:hover",
511
+ {
512
+ height: "100%",
513
+ height: "100%",
514
+ background-color: "#ff9800"
515
+ })
516
+
517
+ */
518
+ export function css(
519
+ identifier: string,
520
+ properties?: Record<string, string>
521
+ ): void;
522
+ /**
523
+ *
524
+ * @param {expression} condition
525
+ * @param {function} callback
526
+ */
527
+ export function assert(condition: any, ...elements: any): undefined | any;
528
+
529
+ export function loop(
530
+ datalist: any[],
531
+ component: (value: any, index?: number, array?: any[]) => HTMLElement
532
+ ): any;
533
+
534
+ export function svgNS(
535
+ type: string,
536
+ props: Record<string, any>,
537
+ ...children: any
538
+ ): HTMLElement;
539
+
540
+ export function assertOr(
541
+ condition: boolean,
542
+ ifTrue: () => any,
543
+ ifFalse: () => any
544
+ ): () => any;
545
+ /**
546
+ * Cradova Ref
547
+ * -------
548
+ * create dynamic components
549
+ */
550
+ type RefProps<D> = D | any;
551
+ export class Ref<D> {
552
+ private component;
553
+ private stateID;
554
+ private effects;
555
+ private effectuate;
556
+ private rendered;
557
+ private published;
558
+ private hasFirstStateUpdateRun;
559
+ private preRendered;
560
+ stash: D | undefined;
561
+ constructor(component: (data?: RefProps<D>) => any);
562
+ preRender(data?: RefProps<D>): void;
563
+ destroyPreRendered(): void;
564
+ /**
565
+ * Cradova Ref
566
+ * ---
567
+ * returns html with cradova reference
568
+ * @param data
569
+ * @returns () => HTMLElement
570
+ */
571
+ render(data?: D, stash?: boolean): HTMLElement;
572
+ instance(): any;
573
+ /**
574
+ * Cradova Ref
575
+ * ---
576
+ * runs on first state update
577
+ *
578
+ */
579
+ effect(fn: () => Promise<unknown>): void;
580
+ private effector;
581
+ /**
582
+ * Cradova Ref
583
+ * ---
584
+ * update ref component with new data and update the dom.
585
+ * @param data
586
+ * @returns void
587
+ *
588
+ *
589
+ * .
590
+ */
591
+ updateState(data: D, stash?: boolean): void;
592
+ private Activate;
593
+ remove(): void;
594
+ }
595
+
596
+ /**
597
+ * Cradova
598
+ * ---
599
+ * Creates new cradova HTML element
600
+ * @example
601
+ * // using template
602
+ * const p = _("p");
603
+ * _("p.class");
604
+ * _("p#id");
605
+ * _("p.class#id");
606
+ * _("p.foo.bar#poo.loo");
607
+ *
608
+ * // using inline props
609
+ *
610
+ * _("p",{
611
+ * text: "am a p tag",
612
+ * style: {
613
+ * color: "blue"
614
+ * }
615
+ * })
616
+ * // or no style props it works!
617
+ * _("p",{
618
+ * text: "am a p tag",
619
+ * color: "blue"
620
+ * })
621
+ *
622
+ * // props and children
623
+ * _("p", // template first
624
+ * // property next if wanted
625
+ * {style: {color: "brown"}, // optional
626
+ * // the rest should be children or text
627
+ * _("span", " am a span tag text like so"),
628
+ * ...
629
+ * )
630
+ *
631
+ * // list of children
632
+ * _("p",
633
+ * // all children goes after
634
+ * _("span",
635
+ * {
636
+ * text:" am a span tag like so",
637
+ * color: "brown",
638
+ * }),
639
+ * ...
640
+ * )
641
+ *
642
+ * @param {...any[]} element_initials
643
+ * @returns function - cradova element
644
+ */
645
+ const _: any;
646
+ export default _;
647
+ }