cradova 3.3.35 → 3.3.55

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
@@ -1,12 +1,12 @@
1
1
  <br/>
2
2
  <p align="center">
3
3
  <a href="https://github.com/uiedbook/cradova">
4
- <img src="cradova.png" alt="Logo" width="80" height="80">
4
+ <img src="icon.png" alt="Logo" width="80" height="80">
5
5
  </a>
6
6
 
7
- <h1 align="center">Cradova</h1>
7
+ <h1 align="center">Cradova</h1>
8
8
 
9
- <p align="center">
9
+ <p align="center">
10
10
  Build Powerful ⚡ Web Apps with Ease
11
11
  <br/>
12
12
  <br/>
@@ -21,11 +21,15 @@ Build Powerful ⚡ Web Apps with Ease
21
21
  </p>
22
22
  </p>
23
23
 
24
- ![Contributors](https://img.shields.io/github/contributors/uiedbook/cradova?color=dark-green) ![Issues](https://img.shields.io/github/issues/uiedbook/cradova) ![License](https://img.shields.io/github/license/uiedbook/cradova)
24
+ ![Contributors](https://img.shields.io/github/contributors/uiedbook/cradova?color=dark-green)
25
+ ![Issues](https://img.shields.io/github/issues/uiedbook/cradova)
26
+ ![License](https://img.shields.io/github/license/uiedbook/cradova)
25
27
  [![npm Version](https://img.shields.io/npm/v/cradova.svg)](https://www.npmjs.com/package/cradova)
26
28
  [![License](https://img.shields.io/npm/l/cradova.svg)](https://github.com/cradova/cradova.js/blob/next/LICENSE)
27
29
  [![npm Downloads](https://img.shields.io/npm/dm/cradova.svg)](https://www.npmjs.com/package/cradova)
28
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/cradova/cradova.js/blob/next/contributing.md)![Forks](https://img.shields.io/github/forks/uiedbook/cradova?style=social) ![Stargazers](https://img.shields.io/github/stars/uiedbook/cradova?style=social)
30
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/cradova/cradova.js/blob/next/contributing.md)
31
+ ![Forks](https://img.shields.io/github/forks/uiedbook/cradova?style=social)
32
+ ![Stargazers](https://img.shields.io/github/stars/uiedbook/cradova?style=social)
29
33
 
30
34
  # Cradova is 3
31
35
 
@@ -48,13 +52,13 @@ document.body.appendChild(Cradova.render());
48
52
  ## 2023 - What's New? Conditionals!
49
53
 
50
54
  ```js
51
- import { div, h1, $if, $ifelse, $case, $switch } from "cradova";
55
+ import { $case, $if, $ifelse, $switch, div, h1 } from "cradova";
52
56
 
53
57
  function Hello({ name }) {
54
58
  return div(
55
59
  $if(name === "john", h1("Hello john")),
56
60
  $if(name === "paul", h1("Goodbye paul")),
57
- $ifelse(name === "john", h1("Hello john"), h1("Hello Paul"))
61
+ $ifelse(name === "john", h1("Hello john"), h1("Hello Paul")),
58
62
  );
59
63
  }
60
64
 
@@ -66,8 +70,8 @@ function whatsAllowed({ age }) {
66
70
  age,
67
71
  $case(12, h1("too young")),
68
72
  $case(26, h1("you are welcome")),
69
- $case(52, h1("too old"))
70
- )
73
+ $case(52, h1("too old")),
74
+ ),
71
75
  );
72
76
  }
73
77
 
@@ -86,16 +90,18 @@ document.body.append(html, whatsAllowed({ age: 26 }));
86
90
 
87
91
  ## What is Cradova?
88
92
 
89
- Cradova is a web development framework for building Single Page Applications and PWAs.
93
+ Cradova is a web development framework for building Single Page Applications and
94
+ PWAs.
90
95
 
91
- Cradova follows the [VJS specification](https://github.com/uiedbook/cradova/blob/main/VJS_spec/specification.md)
96
+ Cradova follows the
97
+ [VJS specification](https://github.com/uiedbook/cradova/blob/main/VJS_spec/specification.md)
92
98
 
93
99
  ## What's the benefit?
94
100
 
95
101
  Fast and simple with and fewer abstractions and yet easily composable.
96
102
 
97
- Cradova is not built on virtual DOM or diff algorithms.
98
- Instead, State management is done in a way that is simple, easy and fast.
103
+ Cradova is not built on virtual DOM or diff algorithms. Instead, State
104
+ management is done in a way that is simple, easy and fast.
99
105
 
100
106
  ## Is this a big benefit?
101
107
 
@@ -122,7 +128,8 @@ npm i cradova
122
128
 
123
129
  ## Examples
124
130
 
125
- Some aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.
131
+ Some aspects of Cradova are not reflected in the following example. More
132
+ functionality will be entailed in future docs.
126
133
 
127
134
  ## A basic component in Cradova:
128
135
 
@@ -149,13 +156,13 @@ This a collection of basic examples that can give you some ideas
149
156
 
150
157
  ```js
151
158
  import {
159
+ br,
152
160
  button,
153
- createSignal,
154
161
  Comp,
155
- reference,
156
- h1,
157
- br,
162
+ createSignal,
158
163
  div,
164
+ h1,
165
+ reference,
159
166
  useRef,
160
167
  } from "cradova";
161
168
 
@@ -205,7 +212,7 @@ function typingExample() {
205
212
  },
206
213
  placeholder: "typing simulation",
207
214
  }),
208
- p(" no thing typed yet!", { reference: ref.bindAs("text") })
215
+ p(" no thing typed yet!", { reference: ref.bindAs("text") }),
209
216
  );
210
217
  }
211
218
 
@@ -223,15 +230,15 @@ Let's see a simple TodoList example
223
230
  ```js
224
231
  import {
225
232
  button,
233
+ Comp,
226
234
  createSignal,
227
- useState,
228
235
  div,
236
+ h1,
229
237
  input,
230
238
  main,
231
239
  p,
232
- Comp,
233
- h1,
234
240
  useRef,
241
+ useState,
235
242
  } from "../dist/index.js";
236
243
 
237
244
  function TodoList() {
@@ -271,13 +278,13 @@ function TodoList() {
271
278
  onclick() {
272
279
  todoStore.fireAction(
273
280
  "add-todo",
274
- referenceSet.current("todoInput").value
281
+ referenceSet.current("todoInput").value,
275
282
  );
276
283
  referenceSet.current("todoInput").value = "";
277
284
  },
278
- })
285
+ }),
279
286
  ),
280
- todoList.render
287
+ todoList.render,
281
288
  );
282
289
  }
283
290
 
@@ -291,7 +298,7 @@ const todoList = new Comp(function () {
291
298
  self.Signal.fireAction("remove-todo", item);
292
299
  },
293
300
  })
294
- )
301
+ ),
295
302
  );
296
303
  });
297
304
  document.body.appendChild(TodoList());
@@ -299,16 +306,14 @@ document.body.appendChild(TodoList());
299
306
 
300
307
  ## working with page and Router:
301
308
 
302
- Unlike just appending stuff to the DOM,
303
- a better to build apps is to use a routing system.
309
+ Unlike just appending stuff to the DOM, a better to build apps is to use a
310
+ routing system.
304
311
 
305
312
  Cradova Router is a module that allows you do the following:
306
313
 
307
- Create specified routes in you application
308
- help you handle navigation
309
- render a page on a route
310
- listen to Navigation changes
311
- create error boundary at page level apart from Comp level.
314
+ Create specified routes in you application help you handle navigation render a
315
+ page on a route listen to Navigation changes create error boundary at page level
316
+ apart from Comp level.
312
317
 
313
318
  let's try an example.
314
319
 
@@ -372,7 +377,8 @@ if it already exist Cradova will use it instead.
372
377
 
373
378
  Cradova will create a div with data-wrapper="app" if it doesn't exists already.
374
379
 
375
- so if you want to use your own mount point then create a div with data-wrapper="app".
380
+ so if you want to use your own mount point then create a div with
381
+ data-wrapper="app".
376
382
 
377
383
  ---
378
384
 
@@ -380,13 +386,10 @@ More info on Cradova pages
380
386
 
381
387
  ---
382
388
 
383
- Cradova pages has
384
- onActivate() and
385
- onDeactivate() methods which is also available in the
386
- component function on the this variable bound to it.
389
+ Cradova pages has onActivate() and onDeactivate() methods which is also
390
+ available in the component function on the this variable bound to it.
387
391
 
388
- this allow you manage rendering
389
- circle for each page in your app
392
+ this allow you manage rendering circle for each page in your app
390
393
 
391
394
  ---
392
395
 
@@ -402,8 +405,7 @@ Cradova Comp is a dynamic component class, which ships simple abstractions like:
402
405
  - useRef
403
406
  - preRender
404
407
 
405
- these behaviors allow you manage rendering
406
- circle for Comps in your app
408
+ these behaviors allow you manage rendering circle for Comps in your app
407
409
 
408
410
  ---
409
411
 
@@ -422,19 +424,27 @@ with ability to:
422
424
  - persist changes to localStorage
423
425
  - update a Comp and bindings automatically
424
426
 
425
- With these simple and easy abstractions, you can write datastores with so much convenience.
427
+ With these simple and easy abstractions, you can write datastores with so much
428
+ convenience.
426
429
 
427
430
  ## Documentation
428
431
 
429
- At the moment, we're in the process of creating a documentation website for Cradova, and we have limited resources. If you're interested in lending a hand, we invite you to join our community, gain firsthand experience, and contribute to the advancement of Cradova.
432
+ At the moment, we're in the process of creating a documentation website for
433
+ Cradova, and we have limited resources. If you're interested in lending a hand,
434
+ we invite you to join our community, gain firsthand experience, and contribute
435
+ to the advancement of Cradova.
430
436
 
431
437
  ## Getting Help
432
438
 
433
- To get further insights and help on Cradova, visit the [Discord](https://discord.gg/b7fvMg38) and [Telegram](https://t.me/uiedbookHQ) Community Chats.
439
+ To get further insights and help on Cradova, visit the
440
+ [Discord](https://discord.gg/b7fvMg38) and [Telegram](https://t.me/uiedbookHQ)
441
+ Community Chats.
434
442
 
435
443
  ## Contributing
436
444
 
437
- We are currently working to [set](https://github.com/uiedbook/cradova/blob/main/contributing.md) up the following:
445
+ We are currently working to
446
+ [set](https://github.com/uiedbook/cradova/blob/main/contributing.md) up the
447
+ following:
438
448
 
439
449
  - building Cradova CLI (in progress)
440
450
  - Cradova Documentation Website
@@ -443,12 +453,12 @@ We are currently working to [set](https://github.com/uiedbook/cradova/blob/main/
443
453
  - maintenance and promotion
444
454
 
445
455
  ```
446
- ██████╗ ██████╗ █████═╗ ███████╗ ███████╗ ██╗ ██╗ █████╗
447
- ██╔════╝ ██╔══██╗ ██╔═╗██║ █ ██ ██╔═════╝█ ██║ ██║ ██╔═╗██
448
- ██║ ██████╔╝ ███████║ █ ██ ██║ ██ ██║ ██║ ██████╗
449
- ██║ ██╔══██╗ ██║ ██║ █ ██ ██║ ██ ╚██╗ ██╔╝ ██║ ██╗
450
- ╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ████████ ╚███╔╝ ██║ ██║
451
- ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚══╝ ╚═╝ ╚═╝
456
+ ██████╗ ██████╗ █████═╗ ███████╗ ███████╗ ██╗ ██╗ █████╗
457
+ ██╔════╝ ██╔══██╗ ██╔═╗██║ █ ██ ██╔═════╝█ ██║ ██║ ██╔═╗██
458
+ ██║ ██████╔╝ ███████║ █ ██ ██║ ██ ██║ ██║ ██████╗
459
+ ██║ ██╔══██╗ ██║ ██║ █ ██ ██║ ██ ╚██╗ ██╔╝ ██║ ██╗
460
+ ╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ████████ ╚███╔╝ ██║ ██║
461
+ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚══╝ ╚═╝ ╚═╝
452
462
  ```
453
463
 
454
464
  ## Apache Lincenced
@@ -459,12 +469,16 @@ Join Us on [telegram](https://t.me/UiedbookHQ).
459
469
 
460
470
  ### Contribution and License Agreement
461
471
 
462
- If you contribute code to this project, you are implicitly allowing your code to be distributed under same license. You are also implicitly verifying that all code is your original work.
472
+ If you contribute code to this project, you are implicitly allowing your code to
473
+ be distributed under same license. You are also implicitly verifying that all
474
+ code is your original work.
463
475
 
464
476
  ## Supporting Cradova development
465
477
 
466
- Your Support is a good force for change anytime you do it, you can ensure Our projects, growth, Cradova, Cradova, JetPath etc, growth and improvement by making a re-occuring or fixed sponsorship
467
- to [github sponsors](https://github.com/sponsors/FridayCandour):
478
+ Your Support is a good force for change anytime you do it, you can ensure Our
479
+ projects, growth, Cradova, Cradova, JetPath etc, growth and improvement by
480
+ making a re-occuring or fixed sponsorship to
481
+ [github sponsors](https://github.com/sponsors/FridayCandour):
468
482
 
469
483
  Support via cryptos -
470
484
 
package/dist/index.js CHANGED
@@ -1,13 +1,9 @@
1
1
  // src/primitives/classes.ts
2
2
  class cradovaEvent {
3
+ static refid = 0;
3
4
  afterMount = [];
4
5
  beforeMountActive = [];
5
- async addAfterMount(callback) {
6
- this.afterMount.push(callback);
7
- }
8
- async addBeforeMountActive(callback) {
9
- this.beforeMountActive.push(callback);
10
- }
6
+ afterDeactivate = [];
11
7
  dispatchEvent(eventName) {
12
8
  const eventListeners = this[eventName];
13
9
  if (eventName.includes("Active")) {
@@ -24,6 +20,7 @@ class cradovaEvent {
24
20
  var CradovaEvent = new cradovaEvent;
25
21
 
26
22
  class Comp {
23
+ id;
27
24
  component;
28
25
  effects = [];
29
26
  effectuate = null;
@@ -37,6 +34,11 @@ class Comp {
37
34
  test;
38
35
  constructor(component) {
39
36
  this.component = component.bind(this);
37
+ cradovaEvent.refid += 1;
38
+ this.id = cradovaEvent.refid;
39
+ }
40
+ clone() {
41
+ return new Comp(this.component);
40
42
  }
41
43
  preRender() {
42
44
  this.preRendered = this.render();
@@ -62,6 +64,9 @@ class Comp {
62
64
  }
63
65
  }
64
66
  _setExtra(Extra) {
67
+ if (this.Signal) {
68
+ Extra.value = this.Signal.value;
69
+ }
65
70
  this.Signal = Extra;
66
71
  }
67
72
  _effect(fn) {
@@ -71,7 +76,10 @@ class Comp {
71
76
  }
72
77
  async effector() {
73
78
  for (let i = 0;i < this.effects.length; i++) {
74
- await this.effects[i].apply(this);
79
+ const fn = await this.effects[i].apply(this);
80
+ if (typeof fn === "function") {
81
+ CradovaEvent.afterDeactivate.push(fn);
82
+ }
75
83
  }
76
84
  this.effects = [];
77
85
  if (this.effectuate) {
@@ -88,7 +96,9 @@ class Comp {
88
96
  };
89
97
  } else {
90
98
  if (this.published) {
91
- this.activate();
99
+ setTimeout(() => {
100
+ this.activate();
101
+ });
92
102
  }
93
103
  }
94
104
  }
@@ -98,23 +108,21 @@ class Comp {
98
108
  return;
99
109
  }
100
110
  this._state_index = 0;
101
- const html = this.component();
102
- if (html instanceof HTMLElement) {
103
- const node = this.reference;
104
- if (node) {
111
+ const node = this.reference;
112
+ if (document.contains(node)) {
113
+ const html = this.component();
114
+ if (html instanceof HTMLElement) {
105
115
  node.insertAdjacentElement("beforebegin", html);
106
116
  node.remove();
117
+ this.published = true;
118
+ this.reference = html;
119
+ CradovaEvent.dispatchEvent("afterMount");
120
+ } else {
121
+ console.error(" \u2718 Cradova err : Invalid html, got - " + html);
107
122
  }
108
- this.published = true;
109
- this.reference = html;
110
- CradovaEvent.dispatchEvent("afterMount");
111
- (async () => {
112
- if (!document.contains(html)) {
113
- this.rendered = false;
114
- }
115
- })();
116
123
  } else {
117
- console.error(" \u2718 Cradova err : Invalid html, got - " + html);
124
+ this.reference = null;
125
+ this.rendered = false;
118
126
  }
119
127
  }
120
128
  }
@@ -139,7 +147,7 @@ class lazy {
139
147
  }
140
148
  }
141
149
 
142
- class createSignal {
150
+ class Signal {
143
151
  callback;
144
152
  persistName = "";
145
153
  actions = {};
@@ -162,34 +170,34 @@ class createSignal {
162
170
  }
163
171
  }
164
172
  }
165
- set(value, shouldRefRender) {
173
+ set(value, shouldCompRender) {
166
174
  if (typeof value === "function") {
167
175
  this.value = value(this.value);
168
176
  } else {
169
177
  this.value = value;
170
178
  }
171
- if (this.persistName) {
172
- localStorage.setItem(this.persistName, JSON.stringify(this.value));
173
- }
174
- if (this.comp.length && shouldRefRender !== false) {
179
+ if (this.comp.length && shouldCompRender !== false) {
175
180
  this.updateState();
176
181
  }
177
182
  if (this.callback) {
178
183
  this.callback(this.value);
179
184
  }
185
+ if (this.persistName) {
186
+ localStorage.setItem(this.persistName, JSON.stringify(this.value));
187
+ }
180
188
  }
181
- setKey(key, value, shouldRefRender) {
182
- if (typeof this.value === "object" && !Array.isArray(this.value)) {
189
+ setKey(key, value, shouldCompRender) {
190
+ if (typeof this.value === "object") {
183
191
  this.value[key] = value;
184
- if (this.persistName) {
185
- localStorage.setItem(this.persistName, JSON.stringify(this.value));
186
- }
187
- if (this.comp.length && shouldRefRender !== false) {
192
+ if (this.comp.length && shouldCompRender !== false) {
188
193
  this.updateState();
189
194
  }
190
195
  if (this.callback) {
191
196
  this.callback(this.value);
192
197
  }
198
+ if (this.persistName) {
199
+ localStorage.setItem(this.persistName, JSON.stringify(this.value));
200
+ }
193
201
  } else {
194
202
  throw new Error(`\u2718 Cradova err : can't set key ${String(key)} store.value is not an object`);
195
203
  }
@@ -238,16 +246,18 @@ class createSignal {
238
246
  ent.comp.recall();
239
247
  }
240
248
  }
241
- bindRef(comp, binding = { signalProperty: "", _element_property: "" }) {
249
+ bindComp(comp, binding) {
242
250
  if (comp instanceof Comp) {
251
+ if (this.comp.find((cmp) => cmp.comp?.id === comp.id))
252
+ return;
243
253
  comp.render = comp.render.bind(comp);
244
254
  comp._setExtra(this);
245
255
  }
246
256
  this.comp.push({
247
257
  comp,
248
- _signalProperty: binding.signalProperty,
249
- _element_property: binding._element_property,
250
- _event: binding.event
258
+ _signalProperty: binding?.signalProperty,
259
+ _element_property: binding?._element_property,
260
+ _event: binding?.event
251
261
  });
252
262
  }
253
263
  listen(callback) {
@@ -267,16 +277,12 @@ class Page {
267
277
  _callBack;
268
278
  _deCallBack;
269
279
  _dropped = false;
270
- _errorHandler = null;
271
280
  constructor(cradova_page_initials) {
272
281
  const { template, name } = cradova_page_initials;
273
282
  this._html = template;
274
283
  this._name = name || "Document";
275
284
  this._template.setAttribute("id", "page");
276
285
  }
277
- set errorHandler(errorHandler) {
278
- this._errorHandler = errorHandler;
279
- }
280
286
  onActivate(cb) {
281
287
  this._callBack = cb;
282
288
  }
@@ -316,6 +322,7 @@ class Page {
316
322
  behavior: "instant"
317
323
  });
318
324
  this._callBack && await this._callBack();
325
+ CradovaEvent.dispatchEvent("afterDeactivate");
319
326
  }
320
327
  }
321
328
 
@@ -328,7 +335,7 @@ class RouterBoxClass {
328
335
  pageHide = null;
329
336
  errorHandler;
330
337
  loadingPage = null;
331
- params = {};
338
+ pageData = { params: {} };
332
339
  routes = {};
333
340
  pageevents = [];
334
341
  paused = false;
@@ -340,16 +347,14 @@ class RouterBoxClass {
340
347
  }, 50);
341
348
  }
342
349
  route(path, page) {
343
- if (typeof page !== "undefined") {
344
- if (page && !page) {
345
- console.error(" \u2718 Cradova err: not a valid page ", page);
346
- }
347
- return this.routes[path] = page;
350
+ if (!page) {
351
+ console.error(" \u2718 Cradova err: not a valid page ", page);
348
352
  }
349
- return;
353
+ return this.routes[path] = page;
350
354
  }
351
355
  async router(_e, _force) {
352
- let url = window.location.href, route, params;
356
+ const url = window.location.href;
357
+ let route, params;
353
358
  if (this.paused) {
354
359
  window.location.hash = "paused";
355
360
  return;
@@ -375,7 +380,7 @@ class RouterBoxClass {
375
380
  }
376
381
  }
377
382
  if (params) {
378
- this.params.params = params;
383
+ this.pageData.params = params;
379
384
  }
380
385
  await route._activate();
381
386
  this.start_pageevents(url);
@@ -383,15 +388,10 @@ class RouterBoxClass {
383
388
  this.lastNavigatedRoute = url;
384
389
  this.lastNavigatedRouteController = route;
385
390
  } catch (error) {
386
- if (route && route["_errorHandler"]) {
387
- route._errorHandler(error);
391
+ if (typeof this.errorHandler === "function") {
392
+ this.errorHandler(error, url);
388
393
  } else {
389
- if (typeof this.errorHandler === "function") {
390
- this.errorHandler(error);
391
- } else {
392
- console.error(error);
393
- throw new Error(" \u2718 Cradova err: consider adding error boundary to the specific page ");
394
- }
394
+ console.error(error);
395
395
  }
396
396
  }
397
397
  } else {
@@ -415,7 +415,7 @@ class RouterBoxClass {
415
415
  params[key] = val;
416
416
  });
417
417
  if (this.routes[url]) {
418
- return [this.routes[url], { data: params, path: url }];
418
+ return [this.routes[url], params];
419
419
  }
420
420
  }
421
421
  for (const path in this.routes) {
@@ -444,7 +444,7 @@ class RouterBoxClass {
444
444
  routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
445
445
  }
446
446
  }
447
- return [this.routes[path], { param: routesParams }];
447
+ return [this.routes[path], routesParams];
448
448
  }
449
449
  }
450
450
  }
@@ -463,11 +463,11 @@ var RouterBox = new RouterBoxClass;
463
463
  class Router {
464
464
  static BrowserRoutes(obj) {
465
465
  for (const path in obj) {
466
- let page = obj[path];
466
+ const page = obj[path];
467
467
  if (typeof page === "object" && typeof page.then === "function" || typeof page === "function") {
468
468
  RouterBox.routes[path] = async () => {
469
- page = await (typeof page === "function" ? await page() : await page);
470
- return RouterBox.route(path, page?.default || page);
469
+ const pagepp = typeof page === "function" ? await page() : await page;
470
+ return RouterBox.route(path, pagepp?.default || pagepp);
471
471
  };
472
472
  } else {
473
473
  RouterBox.route(path, page);
@@ -490,7 +490,7 @@ class Router {
490
490
  window.location.replace(window.location.pathname + window.location.search);
491
491
  history.go(-1);
492
492
  }
493
- static navigate(href, data = null) {
493
+ static navigate(href, data) {
494
494
  if (typeof href !== "string") {
495
495
  console.error(" \u2718 Cradova err: href must be a defined path but got " + href + " instead");
496
496
  }
@@ -503,8 +503,8 @@ class Router {
503
503
  RouterBox.nextRouteController = route;
504
504
  window.history.pushState({}, "", href);
505
505
  }
506
- RouterBox.params.params = params;
507
- RouterBox.params.data = data;
506
+ RouterBox.pageData.params = params;
507
+ RouterBox.pageData.data = data;
508
508
  RouterBox.router(null);
509
509
  }
510
510
  }
@@ -519,11 +519,11 @@ class Router {
519
519
  if (typeof callback === "function") {
520
520
  RouterBox["pageevents"].push(callback);
521
521
  } else {
522
- throw new Error(" \u2718 Cradova err: callback for pageShow event is not a function");
522
+ throw new Error(" \u2718 Cradova err: callback for page events event is not a function");
523
523
  }
524
524
  }
525
- static get Params() {
526
- return RouterBox.params;
525
+ static get PageData() {
526
+ return RouterBox.pageData;
527
527
  }
528
528
  static addErrorHandler(callback) {
529
529
  if (typeof callback === "function") {
@@ -702,8 +702,8 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
702
702
  value[0]._append(value[1], element);
703
703
  continue;
704
704
  }
705
- if (value[0] instanceof createSignal) {
706
- value[0].bindRef(element, {
705
+ if (value[0] instanceof Signal) {
706
+ value[0].bindComp(element, {
707
707
  _element_property: prop,
708
708
  signalProperty: value[1]
709
709
  });
@@ -711,7 +711,7 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
711
711
  }
712
712
  }
713
713
  if (prop === "onmount") {
714
- CradovaEvent.addAfterMount(() => {
714
+ CradovaEvent.afterMount.push(() => {
715
715
  typeof props["onmount"] === "function" && props["onmount"].apply(element);
716
716
  });
717
717
  continue;
@@ -875,7 +875,6 @@ export {
875
875
  dialog,
876
876
  details,
877
877
  datalist,
878
- createSignal,
879
878
  cra,
880
879
  caption,
881
880
  canvas,
@@ -883,6 +882,7 @@ export {
883
882
  br,
884
883
  audio,
885
884
  a,
885
+ Signal,
886
886
  Router,
887
887
  Rhoda,
888
888
  Page,
@@ -1,38 +1,41 @@
1
- import { type CradovaPageType, type promisedPage } from "./types";
1
+ import { type browserPageType, type CradovaPageType } from "./types";
2
2
  /**
3
3
  * Cradova event
4
4
  */
5
5
  declare class cradovaEvent {
6
- afterMount: Function[];
7
- beforeMountActive: Function[];
6
+ static refid: number;
8
7
  /**
9
- * add an event to an exhaustible list of events
10
8
  * the events runs only once and removed.
11
9
  * these event are call and removed once when when a comp is rendered to the dom
12
10
  * @param callback
13
11
  */
14
- addAfterMount(callback: () => void): Promise<void>;
12
+ afterMount: Function[];
15
13
  /**
16
- * add an event to a list of events
17
14
  * the events runs many times.
18
15
  * these event are called before a comp is rendered to the dom
19
16
  * @param callback
20
17
  */
21
- addBeforeMountActive(callback: () => void): Promise<void>;
18
+ beforeMountActive: Function[];
19
+ /**
20
+ * the events runs once after comps unmounts.
21
+ * these event are called before a comp is rendered to the dom
22
+ * @param callback
23
+ */
24
+ afterDeactivate: Function[];
22
25
  /**
23
26
  * Dispatch any event
24
27
  * @param eventName
25
28
  */
26
- dispatchEvent(eventName: "beforeMountActive" | "afterMount"): void;
29
+ dispatchEvent(eventName: "beforeMountActive" | "afterMount" | "afterDeactivate"): void;
27
30
  }
28
31
  export declare const CradovaEvent: cradovaEvent;
29
32
  /**
30
33
  * Cradova Comp
31
34
  * -------
32
35
  * create dynamic components
33
- *
34
36
  */
35
37
  export declare class Comp<Prop extends Record<string, any> = any> {
38
+ id: number;
36
39
  private component;
37
40
  private effects;
38
41
  private effectuate;
@@ -40,11 +43,12 @@ export declare class Comp<Prop extends Record<string, any> = any> {
40
43
  private published;
41
44
  private preRendered;
42
45
  private reference;
43
- Signal: createSignal<any> | undefined;
46
+ Signal: Signal<Prop> | undefined;
44
47
  _state: Prop[];
45
48
  _state_index: number;
46
49
  test?: string;
47
50
  constructor(component: (this: Comp<Prop>) => HTMLElement);
51
+ clone(): Comp<Prop>;
48
52
  preRender(): void;
49
53
  /**
50
54
  * Cradova Comp
@@ -54,7 +58,7 @@ export declare class Comp<Prop extends Record<string, any> = any> {
54
58
  * @returns () => HTMLElement
55
59
  */
56
60
  render(): any;
57
- _setExtra(Extra: createSignal<any>): void;
61
+ _setExtra(Extra: Signal<any>): void;
58
62
  _effect(fn: () => Promise<void> | void): void;
59
63
  private effector;
60
64
  /**
@@ -92,7 +96,7 @@ export declare class lazy<Type> {
92
96
  * - update a cradova Comp automatically
93
97
  * @constructor initial: unknown, props: {useHistory, persist}
94
98
  */
95
- export declare class createSignal<Type extends Record<string, any>> {
99
+ export declare class Signal<Type extends Record<string, any>> {
96
100
  private callback;
97
101
  private persistName;
98
102
  private actions;
@@ -108,7 +112,7 @@ export declare class createSignal<Type extends Record<string, any>> {
108
112
  * @param value - signal value
109
113
  * @returns void
110
114
  */
111
- set(value: Type | ((value: Type) => Type), shouldRefRender?: boolean): void;
115
+ set(value: Type | ((value: Type) => Type), shouldCompRender?: boolean): void;
112
116
  /**
113
117
  * Cradova Signal
114
118
  * ----
@@ -117,7 +121,7 @@ export declare class createSignal<Type extends Record<string, any>> {
117
121
  * @param value - value of the key
118
122
  * @returns void
119
123
  */
120
- setKey<k extends keyof Type>(key: k, value: unknown, shouldRefRender?: boolean): void;
124
+ setKey<k extends keyof Type>(key: k, value: unknown, shouldCompRender?: boolean): void;
121
125
  /**
122
126
  * Cradova Signal
123
127
  * ----
@@ -159,10 +163,10 @@ export declare class createSignal<Type extends Record<string, any>> {
159
163
  *
160
164
  * @param Comp component to bind to.
161
165
  */
162
- bindRef(comp: Comp, binding?: {
166
+ bindComp(comp: Comp, binding?: {
163
167
  event?: string;
164
- signalProperty: string;
165
- _element_property: string;
168
+ signalProperty?: string;
169
+ _element_property?: string;
166
170
  }): void;
167
171
  /**
168
172
  * Cradova Signal
@@ -175,7 +179,6 @@ export declare class createSignal<Type extends Record<string, any>> {
175
179
  * Cradova Signal
176
180
  * ----
177
181
  * clear the history on local storage
178
- *
179
182
  */
180
183
  clearPersist(): void;
181
184
  }
@@ -199,12 +202,7 @@ export declare class Page {
199
202
  private _callBack;
200
203
  private _deCallBack;
201
204
  private _dropped;
202
- /**
203
- * error handler for the page
204
- */
205
- _errorHandler: ((err: unknown) => void) | null;
206
205
  constructor(cradova_page_initials: CradovaPageType);
207
- set errorHandler(errorHandler: (err: unknown) => void);
208
206
  onActivate(cb: () => Promise<void> | void): void;
209
207
  onDeactivate(cb: () => Promise<void> | void): void;
210
208
  _deActivate(): Promise<void>;
@@ -226,7 +224,7 @@ export declare class Router {
226
224
  *
227
225
  * accepts an object containing pat and page
228
226
  */
229
- static BrowserRoutes(obj: Record<string, Page | promisedPage>): void;
227
+ static BrowserRoutes(obj: Record<string, browserPageType<Page | unknown>>): void;
230
228
  /**
231
229
  Go back in Navigation history
232
230
  */
@@ -253,7 +251,7 @@ export declare class Router {
253
251
  * @param data object
254
252
  * @param force boolean
255
253
  */
256
- static navigate(href: string, data?: Record<string, unknown> | null): void;
254
+ static navigate(href: string, data?: Record<string, any>): void;
257
255
  /**
258
256
  * Cradova
259
257
  * ---
@@ -279,7 +277,10 @@ export declare class Router {
279
277
  *
280
278
  * .
281
279
  */
282
- static get Params(): any;
280
+ static get PageData(): {
281
+ params: Record<string, string>;
282
+ data?: Record<string, any>;
283
+ };
283
284
  /**
284
285
  * Cradova
285
286
  * ---
@@ -288,7 +289,7 @@ export declare class Router {
288
289
  * @param callback
289
290
  * @param path? page path
290
291
  */
291
- static addErrorHandler(callback: (err: unknown) => void): void;
292
+ static addErrorHandler(callback: (err?: unknown, pagePath?: string) => void): void;
292
293
  static _mount(): void;
293
294
  }
294
295
  export {};
@@ -28,7 +28,6 @@ export declare const makeElement: <E extends HTMLElement>(element: E & HTMLEleme
28
28
  export declare const cra: <E extends HTMLElement>(tag: string) => (...Children_and_Properties: VJS_params_TYPE<E>) => E;
29
29
  export declare function Rhoda(l: VJS_params_TYPE<HTMLElement>): DocumentFragment;
30
30
  /**
31
- *
32
31
  * @param {expression} condition
33
32
  * @param {function} elements[]
34
33
  */
@@ -52,7 +51,7 @@ export declare const frag: (children: VJS_params_TYPE<HTMLElement>) => DocumentF
52
51
  * @param Comp
53
52
  * @returns [state, setState]
54
53
  */
55
- export declare function useState<S = unknown>(newState: S, Comp: Comp): [S, (newState: S | ((preS: S) => S)) => void];
54
+ export declare function useState<S = unknown>(newState: S, Comp: Comp<any>): [S, (newState: S | ((preS: S) => S)) => void];
56
55
  /**
57
56
  * Cradova
58
57
  * ---
@@ -1,5 +1,5 @@
1
1
  import * as CSS from "csstype";
2
- import { Comp, Page, __raw_ref } from "./classes";
2
+ import { Comp, Page } from "./classes";
3
3
  type DataAttributes = {
4
4
  [key: `data-${string}`]: string;
5
5
  };
@@ -24,7 +24,7 @@ type Attributes = {
24
24
  required?: string;
25
25
  frameBorder?: string;
26
26
  placeholder?: string;
27
- reference?: __raw_ref;
27
+ reference?: [any, string];
28
28
  autocomplete?: string;
29
29
  style?: CSS.Properties;
30
30
  recall?: (P: any) => void;
@@ -67,5 +67,5 @@ export type CradovaPageType = {
67
67
  */
68
68
  template: (this: Page) => HTMLElement;
69
69
  };
70
- export type promisedPage = (() => Promise<Page>);
70
+ export type browserPageType<importType = Page> = importType | Promise<importType> | (() => Promise<importType>);
71
71
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cradova",
3
- "version": "3.3.35",
3
+ "version": "3.3.55",
4
4
  "description": "Build Powerful ⚡ Web Apps with Ease",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",