cradova 3.1.0 → 3.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.
@@ -0,0 +1,635 @@
1
+ /*
2
+ ============================================================================="
3
+ ██████╗ ██████╗ █████═╗ ███████╗ ███████╗ ██╗ ██╗ █████╗
4
+ ██╔════╝ ██╔══██╗ ██╔═╗██║ █ ██ ██╔═════╝█ ██║ ██║ ██╔═╗██
5
+ ██║ ██████╔╝ ███████║ █ ██ ██║ ██ ██║ ██║ ██████╗
6
+ ██║ ██╔══██╗ ██║ ██║ █ ██ ██║ ██ ╚██╗ ██╔╝ ██║ ██╗
7
+ ╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ████████ ╚███╔╝ ██║ ██║
8
+ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚══╝ ╚═╝ ╚═╝
9
+ =============================================================================
10
+ Cradova FrameWork
11
+ @version 3.0.0
12
+ License: Apache V2
13
+ Copyright 2022 Friday Candour.
14
+ Repository - https://github.com/fridaycandour/cradova
15
+ =============================================================================
16
+ */
17
+
18
+ declare module "cradova" {
19
+ /**
20
+ * Cradova Signal
21
+ * ----
22
+ * Create stateful data store.
23
+ * Features:
24
+ * - create a store
25
+ * - create actions and fire them
26
+ * - bind a Ref and elements
27
+ * - listen to updates
28
+ * - set object keys instead of all values
29
+ * - persist changes to localStorage
30
+ * - update a cradova Ref automatically
31
+ * @constructor initial: unknown, props: {useHistory, persist}
32
+ */
33
+ export class createSignal<Type extends Record<string, unknown>> {
34
+ private callback;
35
+ private persistName;
36
+ private actions;
37
+ private ref;
38
+ value: Type;
39
+ constructor(
40
+ initial: Type,
41
+ props?: {
42
+ persistName?: string | undefined;
43
+ }
44
+ );
45
+ /**
46
+ * Cradova Signal
47
+ * ----
48
+ * set signal value
49
+ * @param value - signal value
50
+ * @returns void
51
+ */
52
+ set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
53
+ /**
54
+ * Cradova Signal
55
+ * ----
56
+ * set a key value if it's an object
57
+ * @param key - key of the key
58
+ * @param value - value of the key
59
+ * @returns void
60
+ */
61
+ setKey<k extends keyof Type>(
62
+ key: k,
63
+ value: unknown,
64
+ shouldRefRender?: boolean
65
+ ): void;
66
+ /**
67
+ * Cradova Signal
68
+ * ----
69
+ * set a key to signal an action
70
+ * @param name - name of the action
71
+ * @param action function to execute
72
+ */
73
+ createAction(name: string, action: (data?: unknown) => void): void;
74
+ /**
75
+ * Cradova Signal
76
+ * ----
77
+ * creates man y actions at a time
78
+ * @param name - name of the action
79
+ * @param action function to execute
80
+ */
81
+ createActions(Actions: Record<string, (data?: unknown) => void>): void;
82
+ /**
83
+ * Cradova Signal
84
+ * ----
85
+ * fires an action if available
86
+ * @param key - string key of the action
87
+ * @param data - data for the action
88
+ */
89
+ fireAction(key: string, data?: Type): Type;
90
+ /**
91
+ * Cradova
92
+ * ---
93
+ * is used to bind signal data to elements and Refs
94
+ *
95
+ * @param prop
96
+ * @returns something
97
+ */
98
+ bind(prop: string): any;
99
+ private _updateState;
100
+ /**
101
+ * Cradova Signal
102
+ * ----
103
+ * set a auto - rendering component for this store
104
+ *
105
+ * @param Ref component to bind to.
106
+ * @param path a property in the object to send to attached ref
107
+ */
108
+ bindRef(
109
+ ref: Partial<Ref<unknown>>,
110
+ binding?: {
111
+ event?: string;
112
+ signalProperty: string;
113
+ _element_property: string;
114
+ }
115
+ ): void;
116
+ /**
117
+ * Cradova Signal
118
+ * ----
119
+ * set a update listener on value changes
120
+ * @param callback
121
+ */
122
+ listen(callback: (a: Type) => void): void;
123
+ /**
124
+ * Cradova Signal
125
+ * ----
126
+ * clear the history on local storage
127
+ *
128
+ */
129
+ clearPersist(): void;
130
+ }
131
+
132
+ export function css(identifier: string | TemplateStringsArray): void;
133
+ /**
134
+ *
135
+ * @param {expression} condition
136
+ * @param {function} elements[]
137
+ */
138
+ export function assert<Type>(
139
+ condition: boolean,
140
+ ...elements: VJS_Child_TYPE<Type | HTMLElement>[]
141
+ ): HTMLElement[];
142
+ type LoopData<Type> = Type[];
143
+ export function loop<Type>(
144
+ datalist: LoopData<Type>,
145
+ component: (
146
+ value: Type,
147
+ index?: number,
148
+ array?: LoopData<Type>
149
+ ) => HTMLElement | DocumentFragment | undefined
150
+ ): HTMLElement[] | undefined;
151
+ export function assertOr<Type>(
152
+ condition: boolean,
153
+ ifTrue: VJS_Child_TYPE<Type | HTMLElement>,
154
+ ifFalse: VJS_Child_TYPE<Type | HTMLElement>
155
+ ): HTMLElement;
156
+ /**
157
+ * Cradova Ref
158
+ * -------
159
+ * create dynamic components
160
+ */
161
+ export class Ref<D> {
162
+ private component;
163
+ private effects;
164
+ private effectuate;
165
+ private rendered;
166
+ private published;
167
+ private preRendered;
168
+ private reference;
169
+ Signal: createSignal<any> | undefined;
170
+ _state: D[];
171
+ _state_track: {
172
+ [x: number]: boolean;
173
+ };
174
+ _state_index: number;
175
+ stash: D | undefined;
176
+ constructor(
177
+ component: (this: Ref<D>, data: D) => HTMLElement | DocumentFragment
178
+ );
179
+ preRender(data?: D): void;
180
+ destroyPreRendered(): void;
181
+ /**
182
+ * Cradova Ref
183
+ * ---
184
+ * returns html with cradova reference
185
+ * @param data
186
+ * @returns () => HTMLElement
187
+ */
188
+ render(data?: D, stash?: boolean): HTMLElement | DocumentFragment;
189
+ instance(): Record<string, any>;
190
+ _setExtra(Extra: createSignal<any>): void;
191
+ _roll_state(data: D, idx: number, get?: boolean): D;
192
+ _effect(fn: () => Promise<void> | void): void;
193
+ private effector;
194
+ /**
195
+ * Cradova Ref
196
+ * ---
197
+ * update ref component with new data and update the dom.
198
+ * @param data
199
+ * @returns
200
+ */
201
+ updateState(data?: D, stash?: boolean): void;
202
+ private Activate;
203
+ }
204
+ /**
205
+ * cradova
206
+ * ---
207
+ * lazy load a file
208
+ */
209
+ export class lazy<Type> {
210
+ content: Type | undefined;
211
+ private _cb;
212
+ constructor(cb: () => Promise<unknown>);
213
+ load(): Promise<void>;
214
+ }
215
+ /**
216
+ * Cradova
217
+ * ---
218
+ * make reference to dom elements
219
+ */
220
+ export class reference {
221
+ [x: string]: Record<string, any>;
222
+ bindAs(name: string): reference;
223
+ _appendDomForce(name: string, Element: HTMLElement): void;
224
+ }
225
+ /**
226
+ * Cradova
227
+ * ---
228
+ * Allows functional components to manage state by providing a state value and a function to update it.
229
+ * @param initialValue
230
+ * @param ActiveRef
231
+ * @returns [state, setState]
232
+ */
233
+ export function useState<S>(
234
+ initialValue: S,
235
+ ActiveRef: Ref<S>
236
+ ): [S, (newState: S) => void];
237
+ /**
238
+ * Cradova
239
+ * ---
240
+ Allows side effects to be performed in functional components (Refs), such as fetching data or subscribing to events.
241
+ * @param effect
242
+ * @returns
243
+ */
244
+ export function useEffect(effect: () => void, ActiveRef: Ref<unknown>): void;
245
+ /**
246
+ * Cradova
247
+ * ---
248
+ Returns a mutable reference object of dom elements that persists across component renders.
249
+ * @returns reference
250
+ */
251
+ export function useRef(): Record<string, HTMLElement | undefined>;
252
+
253
+ /**
254
+ * Cradova Screen
255
+ * ---
256
+ * create instances of manageable pages and scaffolds
257
+ * @param name
258
+ * @param template
259
+ * @param transitions
260
+ */
261
+ export class Screen {
262
+ /**
263
+ * this should be a cradova screen component
264
+ */
265
+ _html:
266
+ | ((this: Screen, data?: unknown) => HTMLElement | DocumentFragment)
267
+ | HTMLElement
268
+ | DocumentFragment;
269
+ /**
270
+ * this is a set of added html to the screen
271
+ */
272
+ _secondaryChildren: VJSType<HTMLElement>[];
273
+ /**
274
+ * error handler for the screen
275
+ */
276
+ _errorHandler: ((err: unknown) => void) | null;
277
+ /**
278
+ * used internally
279
+ */
280
+ _name: string;
281
+ private _packed;
282
+ private _template;
283
+ private _callBack;
284
+ private _deCallBack;
285
+ private _persist;
286
+ private _delegatedRoutesCount;
287
+ private _transition;
288
+ constructor(cradova_screen_initials: CradovaScreenType);
289
+ get _delegatedRoutes(): boolean;
290
+ set _delegatedRoutes(count: boolean);
291
+ setErrorHandler(errorHandler: (err: unknown) => void): void;
292
+ _package(): Promise<void>;
293
+ onActivate(cb: () => Promise<void> | void): void;
294
+ onDeactivate(cb: () => Promise<void> | void): void;
295
+ addChildren(...addOns: VJSType<HTMLElement>[]): void;
296
+ _deActivate(): Promise<void>;
297
+ _Activate(force?: boolean): Promise<void>;
298
+ }
299
+
300
+ type DataAttributes = {
301
+ [key: `data-${string}`]: string;
302
+ };
303
+ type AriaAttributes = {
304
+ [key: `aria-${string}`]: string;
305
+ };
306
+ type VJSType<T> = (
307
+ ...VJS: (
308
+ | undefined
309
+ | string
310
+ | HTMLElement
311
+ | HTMLElement[]
312
+ | DocumentFragment
313
+ | DocumentFragment[]
314
+ | TemplateStringsArray
315
+ | Partial<T>
316
+ | (() => HTMLElement)
317
+ | Partial<DataAttributes>
318
+ | Partial<AriaAttributes>
319
+ | Partial<CSSStyleDeclaration>
320
+ | {
321
+ style?: Partial<CSSStyleDeclaration>;
322
+ onmount?: (this: T) => void;
323
+ reference?: reference;
324
+ }
325
+ )[]
326
+ ) => T;
327
+ type VJS_params_TYPE<T> = (
328
+ | undefined
329
+ | string
330
+ | HTMLElement
331
+ | HTMLElement[]
332
+ | DocumentFragment
333
+ | DocumentFragment[]
334
+ | TemplateStringsArray
335
+ | Partial<T>
336
+ | (() => HTMLElement)
337
+ | Partial<DataAttributes>
338
+ | Partial<AriaAttributes>
339
+ | Partial<CSSStyleDeclaration>
340
+ | {
341
+ style?: Partial<CSSStyleDeclaration>;
342
+ src?: string;
343
+ href?: string;
344
+ placeholder?: string;
345
+ type?: string;
346
+ action?: string;
347
+ name?: string;
348
+ alt?: string;
349
+ for?: string;
350
+ method?: string;
351
+ rows?: string;
352
+ value?: string;
353
+ target?: string;
354
+ rel?: string;
355
+ required?: string;
356
+ frameBorder?: string;
357
+ onmount?: (this: T) => void;
358
+ reference?: reference;
359
+ }
360
+ )[];
361
+ type VJS_Child_TYPE<T> = undefined | string | T | (() => T);
362
+ type CradovaScreenType<T = unknown> = {
363
+ /**
364
+ * Cradova screen
365
+ * ---
366
+ * title of the page
367
+ * .
368
+ */
369
+ name: string;
370
+ /**
371
+ * Cradova screen
372
+ * ---
373
+ * a css className to add to screen when rendering it
374
+ * Usually for adding css transitions
375
+ * .
376
+ */
377
+ transition?: string;
378
+ /**
379
+ * Cradova screen
380
+ * ---
381
+ * The component for the screen
382
+ * @param data
383
+ * @returns void
384
+ * .
385
+ */
386
+ template:
387
+ | ((this: Screen, data?: T | unknown) => HTMLElement | DocumentFragment)
388
+ | HTMLElement
389
+ | DocumentFragment;
390
+ /**
391
+ * Cradova screen
392
+ * ---
393
+ * Allows this screen render in parallel for unique routes
394
+ *
395
+ * limit is 1000
396
+ *
397
+ * .
398
+ */
399
+ renderInParallel?: boolean;
400
+ /**
401
+ * Cradova screen
402
+ * ---
403
+ * Should this screen be cached after first render?
404
+ * you can use Route.navigate(url, null, true) to force later
405
+ *
406
+ * .
407
+ */
408
+ persist?: boolean;
409
+ };
410
+
411
+ export const makeElement: <E extends HTMLElement>(
412
+ element: E & HTMLElement,
413
+ ElementChildrenAndPropertyList: VJS_params_TYPE<E>
414
+ ) => E;
415
+ export const a: VJSType<HTMLAnchorElement>;
416
+ export const area: VJSType<HTMLAreaElement>;
417
+ export const article: VJSType<HTMLElement>;
418
+ export const aside: VJSType<HTMLElement>;
419
+ export const audio: VJSType<HTMLAudioElement>;
420
+ export const b: VJSType<HTMLElement>;
421
+ export const base: VJSType<HTMLBaseElement>;
422
+ export const blockquote: VJSType<HTMLElement>;
423
+ export const br: VJSType<HTMLBRElement>;
424
+ export const button: VJSType<HTMLButtonElement>;
425
+ export const canvas: VJSType<HTMLCanvasElement>;
426
+ export const caption: VJSType<HTMLTableCaptionElement>;
427
+ export const code: VJSType<HTMLElement>;
428
+ export const col: VJSType<HTMLTableColElement>;
429
+ export const colgroup: VJSType<HTMLOptGroupElement>;
430
+ export const data: VJSType<HTMLDataElement>;
431
+ export const datalist: VJSType<HTMLDataListElement>;
432
+ export const details: VJSType<HTMLDetailsElement>;
433
+ export const dialog: VJSType<HTMLDialogElement>;
434
+ export const div: VJSType<HTMLDivElement>;
435
+ export const em: VJSType<HTMLElement>;
436
+ export const embed: VJSType<HTMLEmbedElement>;
437
+ export const figure: VJSType<HTMLElement>;
438
+ export const footer: VJSType<HTMLElement>;
439
+ export const form: VJSType<HTMLFormElement>;
440
+ export const h1: VJSType<HTMLHeadingElement>;
441
+ export const h2: VJSType<HTMLHeadingElement>;
442
+ export const h3: VJSType<HTMLHeadingElement>;
443
+ export const h4: VJSType<HTMLHeadingElement>;
444
+ export const h5: VJSType<HTMLHeadingElement>;
445
+ export const h6: VJSType<HTMLHeadingElement>;
446
+ export const head: VJSType<HTMLHeadElement>;
447
+ export const header: VJSType<HTMLHeadElement>;
448
+ export const hr: VJSType<HTMLHRElement>;
449
+ export const i: VJSType<HTMLLIElement>;
450
+ export const iframe: VJSType<HTMLIFrameElement>;
451
+ export const img: VJSType<HTMLImageElement>;
452
+ export const input: VJSType<HTMLInputElement>;
453
+ export const label: VJSType<HTMLLabelElement>;
454
+ export const legend: VJSType<HTMLLegendElement>;
455
+ export const li: VJSType<HTMLLIElement>;
456
+ export const link: VJSType<HTMLLinkElement>;
457
+ export const main: VJSType<HTMLElement>;
458
+ export const menu: VJSType<HTMLMenuElement>;
459
+ export const nav: VJSType<HTMLElement>;
460
+ export const object: VJSType<HTMLObjectElement>;
461
+ export const ol: VJSType<HTMLOListElement>;
462
+ export const optgroup: VJSType<HTMLOptGroupElement>;
463
+ export const option: VJSType<HTMLOptionElement>;
464
+ export const p: VJSType<HTMLParagraphElement>;
465
+ export const pre: VJSType<HTMLPreElement>;
466
+ export const progress: VJSType<HTMLProgressElement>;
467
+ export const q: VJSType<HTMLQuoteElement>;
468
+ export const section: VJSType<HTMLElement>;
469
+ export const select: VJSType<HTMLSelectElement>;
470
+ export const source: VJSType<HTMLSourceElement>;
471
+ export const span: VJSType<HTMLSpanElement>;
472
+ export const strong: VJSType<HTMLElement>;
473
+ export const summary: VJSType<HTMLElement>;
474
+ export const table: VJSType<HTMLTableElement>;
475
+ export const tbody: VJSType<HTMLTableColElement>;
476
+ export const td: VJSType<HTMLTableCellElement>;
477
+ export const template: VJSType<HTMLTemplateElement>;
478
+ export const textarea: VJSType<HTMLTextAreaElement>;
479
+ export const th: VJSType<HTMLTableSectionElement>;
480
+ export const title: VJSType<HTMLTitleElement>;
481
+ export const tr: VJSType<HTMLTableRowElement>;
482
+ export const track: VJSType<HTMLTrackElement>;
483
+ export const u: VJSType<HTMLUListElement>;
484
+ export const ul: VJSType<HTMLUListElement>;
485
+ export const video: VJSType<HTMLVideoElement>;
486
+
487
+ /** cradova router
488
+ * ---
489
+ * Registers a route.
490
+ *
491
+ * @param {string} path Route path.
492
+ * @param screen the cradova document tree for the route.
493
+ */
494
+ export class RouterClass {
495
+ /** cradova router
496
+ * ---
497
+ * Registers a route.
498
+ *
499
+ * accepts an object containing
500
+ *
501
+ * @param {string} path Route path.
502
+ * @param screen the cradova screen.
503
+ */
504
+ BrowserRoutes(obj: Record<string, any>): void;
505
+ /**
506
+ Go back in Navigation history
507
+ */
508
+ back(): void;
509
+ /**
510
+ Go forward in Navigation history
511
+ */
512
+ forward(): void;
513
+ /**
514
+ * Cradova Router
515
+ * ------
516
+ *
517
+ * Navigates to a designated screen in your app
518
+ *
519
+ * @param href string
520
+ * @param data object
521
+ * @param force boolean
522
+ */
523
+ navigate(
524
+ href: string,
525
+ data?: Record<string, unknown> | null,
526
+ force?: boolean
527
+ ): void;
528
+ /**
529
+ * Cradova
530
+ * ---
531
+ * Loading screen for your app
532
+ *
533
+ * lazy loaded loading use
534
+ *
535
+ * @param screen
536
+ */
537
+ setLoadingScreen(screen: Screen): void;
538
+ /** cradova router
539
+ * ---
540
+ * Listen for navigation events
541
+ *
542
+ * @param callback () => void
543
+ */
544
+ onPageEvent(callback: () => void): void;
545
+ /** cradova router
546
+ * ---
547
+ * get a screen ready before time.
548
+ *
549
+ * @param {string} path Route path.
550
+ * @param data data for the screen.
551
+ */
552
+ packageScreen(path: string, data?: Record<string, unknown>): Promise<void>;
553
+ /**
554
+ * Cradova Router
555
+ * ------
556
+ *
557
+ * return last set router params
558
+ *
559
+ * .
560
+ */
561
+ getParams(): any;
562
+ /**
563
+ * Cradova
564
+ * ---
565
+ * Error Handler for your app
566
+ *
567
+ * @param callback
568
+ * @param path? page path
569
+ */
570
+ addErrorHandler(callback: (err: unknown) => void): void;
571
+ _mount(): void;
572
+ }
573
+ export const Router: RouterClass;
574
+
575
+ /**
576
+ *
577
+ * Cradova Ajax
578
+ * ------------------
579
+ * your new axios alternative
580
+ * supports files upload
581
+ * @param url string
582
+ * @param {{method: string;data;header;callbacks;}} opts
583
+ * @returns unknown
584
+ */
585
+ export function Ajax(
586
+ url: string | URL,
587
+ opts?: {
588
+ method?: "GET" | "POST";
589
+ data?: Record<string, unknown>;
590
+ header?: {
591
+ "content-type"?: string;
592
+ } & Record<string, string>;
593
+ callbacks?: Record<string, (arg: Function) => void>;
594
+ }
595
+ ): Promise<string>;
596
+
597
+ type TemplateType = <E extends HTMLElement>(
598
+ ...element_initials: VJS_params_TYPE<E | HTMLElement>
599
+ ) => E | HTMLElement | DocumentFragment;
600
+ /**
601
+ * Cradova
602
+ * ---
603
+ * Creates new cradova HTML element
604
+ * @example
605
+ * // using template
606
+ * const p = _("p");
607
+ * _("p.class");
608
+ * _("p#id");
609
+ * _("p.class#id");
610
+ * _("p.foo.bar#poo.loo");
611
+ *
612
+ * // using inline props
613
+ *
614
+ * _("p",{
615
+ * text: "am a p tag",
616
+ * style: {
617
+ * color: "blue"
618
+ * }
619
+ * })
620
+ *
621
+ * // props and children
622
+ * _("p", // template first
623
+ * // property next if wanted
624
+ * {style: {color: "brown"}, // optional
625
+ * // the rest should be children or text
626
+ * _("span", " am a span tag text like so"),
627
+ * ...
628
+ * )
629
+ *
630
+ * @param element_initials
631
+ * @returns function - cradova element
632
+ */
633
+ const _: TemplateType;
634
+ export default _;
635
+ }