cradova 3.1.5 → 3.1.8

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