cradova 3.1.3 → 3.1.5

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