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