cradova 3.5.7 → 3.6.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 +64 -33
- package/dist/index.js +816 -1
- package/dist/primitives/classes.d.ts +44 -57
- package/dist/primitives/dom-objects.d.ts +4 -2
- package/dist/primitives/func.d.ts +8 -0
- package/dist/primitives/functions.d.ts +15 -35
- package/dist/primitives/types.d.ts +16 -3
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<br/>
|
|
2
2
|
<p align="center">
|
|
3
3
|
<a href="https://github.com/uiedbook/cradova">
|
|
4
|
-
<img src="icon.png" alt="Logo" width="80" height="80">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/Uiedbook/cradova/main/icon.png" alt="Logo" width="80" height="80">
|
|
5
5
|
</a>
|
|
6
6
|
|
|
7
7
|
<h1 align="center">Cradova</h1>
|
|
@@ -33,8 +33,14 @@ Build Powerful ⚡ Web Apps with Ease
|
|
|
33
33
|
|
|
34
34
|
# Cradova is 3
|
|
35
35
|
|
|
36
|
+
## 2025 - What's New? Function as reactive components
|
|
37
|
+
|
|
38
|
+
this can't be better anywhere XD
|
|
39
|
+
|
|
36
40
|
```js
|
|
37
|
-
|
|
41
|
+
// functional components
|
|
42
|
+
|
|
43
|
+
const Cradova = function () {
|
|
38
44
|
const [year, setYear] = useState(3, this);
|
|
39
45
|
|
|
40
46
|
return h1("Cradova is " + year + " yrs old in ", {
|
|
@@ -44,9 +50,37 @@ const Cradova = new Comp(function () {
|
|
|
44
50
|
});
|
|
45
51
|
},
|
|
46
52
|
});
|
|
47
|
-
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// NOTE: all cradova elements returns html elements
|
|
56
|
+
|
|
57
|
+
// converts to html and append to the Dom
|
|
58
|
+
document.body.appendChild(div(Cradova));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 2024 - What's New? Signals pub/sub
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { Signal, getSignal, $if, $ifelse, div, h1 } from "cradova";
|
|
65
|
+
|
|
66
|
+
const signal = new Signal({ name: "john" });
|
|
67
|
+
|
|
68
|
+
function Hello() {
|
|
69
|
+
const name = getSignal("name", this).name;
|
|
70
|
+
return div(
|
|
71
|
+
$if(name === "john", h1("Hello john")),
|
|
72
|
+
$if(name === "paul", h1("Goodbye paul")),
|
|
73
|
+
$ifelse(name === "john", h1("Hello john"), h1("Hello Paul"))
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
signal.bind("name", this);
|
|
78
|
+
const html = div(Hello);
|
|
79
|
+
document.body.append(html);
|
|
48
80
|
|
|
49
|
-
|
|
81
|
+
setInterval(() => {
|
|
82
|
+
signal.publish("name", "paul");
|
|
83
|
+
}, 5000);
|
|
50
84
|
```
|
|
51
85
|
|
|
52
86
|
## 2023 - What's New? Conditionals
|
|
@@ -78,6 +112,20 @@ function whatsAllowed({ age }) {
|
|
|
78
112
|
document.body.append(html, whatsAllowed({ age: 26 }));
|
|
79
113
|
```
|
|
80
114
|
|
|
115
|
+
## 2023 - What's New? Router
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
Router.BrowserRoutes({
|
|
119
|
+
"/home": home,
|
|
120
|
+
});
|
|
121
|
+
// creates these routes
|
|
122
|
+
Router.navigate("/home", data);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 2021 - first version
|
|
126
|
+
|
|
127
|
+
...
|
|
128
|
+
|
|
81
129
|
# Contents
|
|
82
130
|
|
|
83
131
|
- [What is Cradova](#what-is-cradova)
|
|
@@ -158,7 +206,7 @@ This a collection of basic examples that can give you some ideas
|
|
|
158
206
|
import {
|
|
159
207
|
br,
|
|
160
208
|
button,
|
|
161
|
-
|
|
209
|
+
Function,
|
|
162
210
|
createSignal,
|
|
163
211
|
div,
|
|
164
212
|
h1,
|
|
@@ -206,7 +254,7 @@ Let's see a simple TodoList example
|
|
|
206
254
|
```js
|
|
207
255
|
import {
|
|
208
256
|
button,
|
|
209
|
-
|
|
257
|
+
Function,
|
|
210
258
|
createSignal,
|
|
211
259
|
div,
|
|
212
260
|
h1,
|
|
@@ -237,7 +285,7 @@ const removeTodo = function (todo: string) {
|
|
|
237
285
|
function TodoList() {
|
|
238
286
|
// can be used to hold multiple references
|
|
239
287
|
const referenceSet = useRef();
|
|
240
|
-
// bind
|
|
288
|
+
// bind Function to Signal
|
|
241
289
|
todoStore.subscribe("todo", todoList);
|
|
242
290
|
// vjs
|
|
243
291
|
return main(
|
|
@@ -260,8 +308,8 @@ function TodoList() {
|
|
|
260
308
|
);
|
|
261
309
|
}
|
|
262
310
|
|
|
263
|
-
const todoList =
|
|
264
|
-
const data = this.
|
|
311
|
+
const todoList = function () {
|
|
312
|
+
const data = this.pipes.get("todo");
|
|
265
313
|
return div(
|
|
266
314
|
data.map((item: any) =>
|
|
267
315
|
p(item, {
|
|
@@ -272,7 +320,7 @@ const todoList = new Comp(function () {
|
|
|
272
320
|
})
|
|
273
321
|
)
|
|
274
322
|
);
|
|
275
|
-
}
|
|
323
|
+
};
|
|
276
324
|
document.body.appendChild(TodoList());
|
|
277
325
|
```
|
|
278
326
|
|
|
@@ -285,29 +333,12 @@ Cradova Router is a module that allows you do the following:
|
|
|
285
333
|
|
|
286
334
|
Create specified routes in you application help you handle navigation render a
|
|
287
335
|
page on a route listen to Navigation changes create error boundary at page level
|
|
288
|
-
apart from
|
|
336
|
+
apart from Function level.
|
|
289
337
|
|
|
290
338
|
let's try an example.
|
|
291
339
|
|
|
292
340
|
```js
|
|
293
|
-
import { Page, Router } from "cradova";
|
|
294
|
-
|
|
295
|
-
// Comp can be used as page template this way
|
|
296
|
-
|
|
297
|
-
const template = new Comp(function (name) {
|
|
298
|
-
// an effect run once after page renders
|
|
299
|
-
const self = this;
|
|
300
|
-
self.effect(() => {
|
|
301
|
-
const name = new Promise((res) => {
|
|
302
|
-
res("john doe");
|
|
303
|
-
});
|
|
304
|
-
setTimeout(async () => {
|
|
305
|
-
self.recall(await name);
|
|
306
|
-
}, 1000);
|
|
307
|
-
});
|
|
308
|
-
// effects can be used to make api calls needed for the page
|
|
309
|
-
return div(name ? ">>>>>>>> Hello " + name : " loading...");
|
|
310
|
-
});
|
|
341
|
+
import { Page, Router, useEffect } from "cradova";
|
|
311
342
|
|
|
312
343
|
const home = new Page({
|
|
313
344
|
name: "home page", // page title
|
|
@@ -365,11 +396,11 @@ this allow you manage rendering circle for each page in your app
|
|
|
365
396
|
|
|
366
397
|
---
|
|
367
398
|
|
|
368
|
-
More info on Cradova
|
|
399
|
+
More info on Cradova Function
|
|
369
400
|
|
|
370
401
|
---
|
|
371
402
|
|
|
372
|
-
Cradova
|
|
403
|
+
Cradova Function is a dynamic component class, which ships simple abstractions like:
|
|
373
404
|
|
|
374
405
|
- Signal
|
|
375
406
|
- useEffect
|
|
@@ -377,7 +408,7 @@ Cradova Comp is a dynamic component class, which ships simple abstractions like:
|
|
|
377
408
|
- useRef
|
|
378
409
|
- preRender
|
|
379
410
|
|
|
380
|
-
these behaviors allow you manage rendering circle for
|
|
411
|
+
these behaviors allow you manage rendering circle for Functions in your app
|
|
381
412
|
|
|
382
413
|
---
|
|
383
414
|
|
|
@@ -391,7 +422,7 @@ with ability to:
|
|
|
391
422
|
|
|
392
423
|
- create store
|
|
393
424
|
- create actions and fire them
|
|
394
|
-
- bind a
|
|
425
|
+
- bind a Function
|
|
395
426
|
- listen to changes
|
|
396
427
|
- persist changes to localStorage
|
|
397
428
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1,816 @@
|
|
|
1
|
-
class U{static compId=0;afterMount=[];beforeMountActive=[];afterDeactivate=[];dispatchEvent(H){let L=this[H];if(H.includes("Active")){for(let T=0;T<L.length;T++)L[T]();return}while(L.length!==0)L.shift()()}}var J=new U;class G{id=0;component;effects=[];effectuate=null;rendered=!1;published=!1;preRendered=null;reference=null;subData=null;_state=[];_state_index=0;constructor(H){this.component=H.bind(this)}preRender(H){this.preRendered=this.render(H)}render(H){if(U.compId+=1,this.id=U.compId,this.effects=[],this.rendered=!1,!this.preRendered){this._state_index=0,this._state=[];let L=this.component(H);if(L instanceof HTMLElement)this.reference=L,this.effector.apply(this),this.rendered=!0,this.published=!0;else console.error(" ✘ Cradova err : Invalid html content, got - "+L);return L}else return this.preRendered}_effect(H){if(!this.rendered)this.effects.push(H.bind(this))}async effector(){for(let H=0;H<this.effects.length;H++){let L=await this.effects[H].apply(this);if(typeof L==="function")J.afterDeactivate.push(L)}if(this.effects=[],this.effectuate)this.effectuate(),this.effectuate=null}recall(H){if(!this.rendered)this.effectuate=()=>{if(this.published)this.activate(H)};else if(this.published)setTimeout(()=>{this.activate(H)})}async activate(H){if(this.published=!1,!this.rendered)return;this._state_index=0;let L=this.reference;if(document.contains(L)){let T=this.component(H);if(T instanceof HTMLElement)L.insertAdjacentElement("beforebegin",T),L.remove(),this.published=!0,this.reference=T,J.dispatchEvent("afterMount");else console.error(" ✘ Cradova err : Invalid html, got - "+T)}else this.reference=null,this.rendered=!1}}class Z{pn;subs;pipe;constructor(H,L){if(this.pipe=H,this.subs={},L&&L.persistName){this.pn=L.persistName;let T=localStorage.getItem(L.persistName);if(T&&T!=="undefined")this.pipe=JSON.parse(T);if(typeof H==="object"){for(let M in H)if(!Object.prototype.hasOwnProperty.call(this.pipe,M))this.pipe[M]=H[M]}}}publish(H,L){this.pipe[H]=L;let T=this.subs[H]||[];for(let M=0;M<T.length;M++){let E=T[M];E.subData=L,E.recall()}if(this.pn)localStorage.setItem(this.pn,JSON.stringify(this.pipe))}subscribe(H,L){if(L instanceof G){if(this.subs[H]?.find((T)=>T.id===L.id))return;if(!this.subs[H])this.subs[H]=[L];else this.subs[H].push(L);if(this.pipe[H])L.subData=this.pipe[H]}}clearPersist(){if(this.pn)localStorage.removeItem(this.pn)}}class q{_name;_html;_template=document.createElement("div");_dropped=!1;_snapshot;_snapshot_html;_deCB;constructor(H){let{template:L,name:T}=H;this._html=L,this._name=T||document.title,this._template.setAttribute("id","page"),this._snapshot=H.snapshotIsolation||!1}async _takeSnapShot(){if(A.doc.dataset.snapshot==="true")return;try{let H=await fetch(location.href);if(!H.ok)throw new Error("Failed to fetch the page");let L=await H.text(),M=new DOMParser().parseFromString(L,"text/html");M.title=this._name;let E=M.querySelector('[data-wrapper="app"]');if(E)E.setAttribute("data-snapshot","true"),E.innerHTML=this._snapshot_html;else{console.error("Wrapper or template is not found");return}let I=M.documentElement.outerHTML;await fetch(`${location.origin}`,{body:I,method:"POST",headers:{"Content-Type":"text/html","cradova-snapshot":location.href.slice(location.origin.length)}})}catch(H){console.error("Snapshot error:",H)}this._snapshot_html=void 0}set onDeactivate(H){this._deCB=H}drop(H){if(typeof H==="boolean"){this._dropped=H;return}else return this._dropped}async _activate(){if(this._dropped){history.go(-1);return}let H=this._html.apply(this);if(H instanceof HTMLElement)this._template.innerHTML="",this._template.appendChild(H);else throw new Error(` ✘ Cradova err: template function for the page returned ${H} instead of html`);if(document.title=this._name,A.doc.innerHTML="",J.dispatchEvent("beforeMountActive"),this._snapshot)this._snapshot_html=this._template.outerHTML;if(A.doc.appendChild(this._template),J.dispatchEvent("afterMount"),window.scrollTo({top:0,left:0,behavior:"instant"}),J.dispatchEvent("afterDeactivate"),this._snapshot)this._takeSnapShot()}}class Q{doc=null;lastNavigatedRouteController;nextRouteController;lastNavigatedRoute;pageShow=null;pageHide=null;errorHandler;loadingPage=null;pageData={params:{}};routes={};paused=!1;route(H,L){if(!L)console.error(" ✘ Cradova err: not a valid page ",L);return this.routes[H]=L}async router(H,L){let T=window.location.href,M,E;if(this.paused){window.location.hash="paused";return}if(this.nextRouteController)M=this.nextRouteController,this.nextRouteController=void 0;else[M,E]=this.checker(T);if(typeof M!=="undefined")try{if(typeof M==="function"){if(this.loadingPage instanceof q)await this.loadingPage._activate();if(M=await M(),M?.default)M=M.default;if(!M){if(this.lastNavigatedRoute)history.pushState({},T,this.lastNavigatedRoute);return}}if(E)this.pageData.params=E;await M._activate(),this.lastNavigatedRouteController&&this.lastNavigatedRouteController._deCB?.(),this.lastNavigatedRoute=T,this.lastNavigatedRouteController=M}catch(I){if(typeof this.errorHandler==="function")this.errorHandler(I,T);else console.error(I)}else if(this.routes["*"])await this.routes["*"]._activate()}checker(H){if(H[0]!=="/")H=H.slice(H.indexOf("/",8));if(this.routes[H])return[this.routes[H],{path:H}];if(H.includes("?")){let L,T={};if([H,L]=H.split("?"),new URLSearchParams(L).forEach((M,E)=>{T[E]=M}),this.routes[H])return[this.routes[H],T]}for(let L in this.routes){if(L.includes(":")){let T=H.split("/"),M=L.split("/");if(H.endsWith("/"))T.pop();let E=0,I=0;if(M.length===T.length){for(let D=0;D<M.length;D++){if(M[D].includes(":")){I++;continue}if(T[D]===M[D])E++}if(E+I===M.length){let D={};for(let O=0;O<M.length;O++)if(M[O].includes(":"))D[M[O].split(":")[1]]=T[O];return[this.routes[L],D]}}}if(L.includes("*")){let T=L.slice(0,-1);if(H.startsWith(T))return[this.routes[L],{extraPath:H.slice(T.length)}]}}return[]}}var A=new Q;class Y{static BrowserRoutes(H){for(let L in H){let T=H[L];if(typeof T==="object"&&typeof T.then==="function"||typeof T==="function")A.routes[L]=async()=>{let M=typeof T==="function"?await T():await T;return A.route(L,M)};else A.route(L,T)}Y._mount()}static pauseNavigation(){A.paused=!0,window.location.hash="paused"}static resumeNavigation(){A.paused=!1,window.location.replace(window.location.pathname+window.location.search),history.go(-1)}static navigate(H,L){if(typeof H!=="string")console.error(" ✘ Cradova err: href must be a defined path but got "+H+" instead");let T=null,M;if(H.includes("."))window.location.href=H;else{if([T,M]=A.checker(H),T)A.nextRouteController=T,window.history.pushState({},"",H);A.pageData.params=M,A.pageData.data=L,A.router(null)}}static setLoadingPage(H){if(H instanceof q)A.loadingPage=H;else throw new Error(" ✘ Cradova err: Loading Page should be a cradova page class")}static get PageData(){return A.pageData}static addErrorHandler(H){if(typeof H==="function")A.errorHandler=H;else throw new Error(" ✘ Cradova err: callback for error event is not a function")}static _mount(){let H=document.querySelector("[data-wrapper=app]");if(H)A.doc=H;else throw new Error(`✘ Cradova err: please add '<div data-wrapper="app"></div>' to the body of your index.html file `);window.addEventListener("pageshow",()=>A.router()),window.addEventListener("popstate",(L)=>{L.preventDefault(),A.router()})}}class z{tree={};bindAs(H){return[this,H]}elem(H){let L=this.tree[H];if(document.contains(L))return L;this.tree[H]=void 0}swap(H,L){[this.tree[H],this.tree[L]]=[this.tree[L],this.tree[H]]}_append(H,L){this.tree[H]=L}}var K=(H,L)=>{let T={},M=void 0;if(L.length!==0)for(let E=0;E<L.length;E++){let I=L[E];if(typeof I==="function")I=I();if(I instanceof G)I=I.render();if(I instanceof HTMLElement||I instanceof DocumentFragment){H.appendChild(I);continue}if(Array.isArray(I)){H.appendChild(S(I));continue}if(typeof I==="string"){M=I;continue}if(typeof I==="object"){Object.assign(T,I);continue}}else return H;if(typeof T==="object"&&H)for(let[E,I]of Object.entries(T)){if(E==="style"&&typeof I==="object"){Object.assign(H.style,I);continue}if(E==="href"){let D=I||"";if(!D.includes("://"))H.addEventListener("click",(O)=>{if(O.preventDefault(),Y.navigate(H.href),D.includes("#")){let W=D.split("#").at(-1);document.getElementById("#"+W)?.scrollIntoView()}});H.setAttribute(E,I);continue}if(E==="onmount"){J.afterMount.push(()=>{typeof T.onmount==="function"&&T.onmount.apply(H)});continue}if(E.includes("data-")||E.includes("aria-")){H.setAttribute(E,I);continue}if(Array.isArray(I)){if(E=="ref"&&I[0]instanceof z){I[0]._append(I[1],H);continue}}H[E]=I}if(M!==void 0)H.appendChild(document.createTextNode(M));return H},V=(H)=>{return(...L)=>K(document.createElement(H),L)};function S(H){let L=new DocumentFragment;for(let T of H)if(Array.isArray(T))L.appendChild(S(T));else{if(T instanceof G)T=T.render();if(typeof T==="function"){if(T=T(),typeof T==="function")T=T()}if(T instanceof HTMLElement||T instanceof DocumentFragment){L.appendChild(T);continue}if(typeof T==="string")L.appendChild(document.createTextNode(T))}return L}function x(H,...L){if(H)return L}function j(H,L,T){if(H)return L;return T}function y(H,...L){return(T)=>{if(T===H)return L;return}}function g(H,...L){let T;if(L.length){for(let M=0;M<L.length;M++)if(T=L[M](H),T)break}return T}function b(H,L){return Array.isArray(H)?H.map(L):void 0}var F=function(H){let L=document.createDocumentFragment();for(let T=0;T<H.length;T++){let M=H[T];if(typeof M==="function")M=M();if(M instanceof HTMLElement||M instanceof DocumentFragment){L.appendChild(M);continue}if(M instanceof String){L.appendChild(document.createTextNode(M));continue}console.error(" ✘ Cradova err: wrong element type"+M)}return L};function w(H,L){L._state_index+=1;let T=L._state_index;if(T>=L._state.length)L._state[T]=H;function M(E){if(typeof E==="function")E=E(L._state[T]);L._state[T]=E,L.recall()}return[L._state[T],M]}function _(H,L){L._effect(H)}function P(){return new z}var N=V("a"),B=V("audio"),c=V("button"),f=V("canvas"),R=V("div"),C=V("footer"),s=V("form"),v=V("h1"),d=V("h2"),i=V("h3"),o=V("h4"),h=V("h5"),u=V("h6"),m=V("header"),t=V("i"),p=V("iframe"),l=V("img"),r=V("input"),a=V("label"),e=V("li"),HH=V("main"),LH=V("nav"),TH=V("ol"),MH=V("optgroup"),EH=V("option"),IH=V("p"),VH=V("section"),AH=V("select"),DH=V("source"),OH=V("span"),JH=V("textarea"),GH=V("ul"),UH=V("video"),YH=(H,L)=>{let T=document.createElement("span");return T.innerHTML=H,K(T,L||[])},qH=(H)=>{let L=document.createElement("div");if(Array.isArray(H))L.innerHTML=H[0];else if(typeof H==="string")L.innerHTML=H;let T=new DocumentFragment;return T.append(...Array.from(L.children)),T};export{UH as video,w as useState,P as useRef,_ as useEffect,GH as ul,JH as textarea,YH as svg,OH as span,DH as source,AH as select,VH as section,qH as raw,IH as p,EH as option,MH as optgroup,TH as ol,LH as nav,K as makeElement,HH as main,b as loop,e as li,a as label,r as input,l as img,p as iframe,t as i,m as header,u as h6,h as h5,o as h4,i as h3,d as h2,v as h1,F as frag,s as form,C as footer,R as div,V as cra,f as canvas,c as button,B as audio,N as a,Z as Signal,Y as Router,S as Rhoda,q as Page,J as CradovaEvent,G as Comp,g as $switch,j as $ifelse,x as $if,y as $case};
|
|
1
|
+
// src/primitives/functions.ts
|
|
2
|
+
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
3
|
+
const props = {};
|
|
4
|
+
let text = undefined;
|
|
5
|
+
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
6
|
+
for (let i = 0;i < ElementChildrenAndPropertyList.length; i++) {
|
|
7
|
+
let child = ElementChildrenAndPropertyList[i];
|
|
8
|
+
if (typeof child === "function") {
|
|
9
|
+
child = isArrowFunc(child) ? child() : toFunc(child);
|
|
10
|
+
}
|
|
11
|
+
if (child instanceof HTMLElement || child instanceof DocumentFragment) {
|
|
12
|
+
element.appendChild(child);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(child)) {
|
|
16
|
+
element.appendChild(unroll_child_list(child));
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (typeof child === "string") {
|
|
20
|
+
text = child;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (typeof child === "object") {
|
|
24
|
+
Object.assign(props, child);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return element;
|
|
30
|
+
}
|
|
31
|
+
if (typeof props === "object" && element) {
|
|
32
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
33
|
+
if (prop === "style" && typeof value === "object") {
|
|
34
|
+
Object.assign(element.style, value);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (prop === "href") {
|
|
38
|
+
const href = value || "";
|
|
39
|
+
if (!href.includes("://")) {
|
|
40
|
+
element.addEventListener("click", (e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
Router.navigate(element.href);
|
|
43
|
+
if (href.includes("#")) {
|
|
44
|
+
const l = href.split("#").at(-1);
|
|
45
|
+
document.getElementById("#" + l)?.scrollIntoView();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
element.setAttribute(prop, value);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (prop === "onmount") {
|
|
53
|
+
CradovaEvent.after_comp_is_mounted.push(() => {
|
|
54
|
+
typeof props["onmount"] === "function" && props["onmount"].apply(element);
|
|
55
|
+
});
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (prop.includes("data-") || prop.includes("aria-")) {
|
|
59
|
+
element.setAttribute(prop, value);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
if (prop == "reference" && value[0] instanceof __raw_ref) {
|
|
64
|
+
value[0]._append(value[1], element);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
element[prop] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (text !== undefined) {
|
|
72
|
+
element.appendChild(document.createTextNode(text));
|
|
73
|
+
}
|
|
74
|
+
return element;
|
|
75
|
+
};
|
|
76
|
+
var cra = (tag) => {
|
|
77
|
+
return (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
|
|
78
|
+
};
|
|
79
|
+
function unroll_child_list(l) {
|
|
80
|
+
const fg = new DocumentFragment;
|
|
81
|
+
for (let ch of l) {
|
|
82
|
+
if (Array.isArray(ch)) {
|
|
83
|
+
fg.appendChild(unroll_child_list(ch));
|
|
84
|
+
} else {
|
|
85
|
+
if (typeof ch === "function") {
|
|
86
|
+
ch = isArrowFunc(ch) ? ch() : toFunc(ch);
|
|
87
|
+
if (typeof ch === "function") {
|
|
88
|
+
ch = isArrowFunc(ch) ? ch() : toFunc(ch);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (ch instanceof HTMLElement || ch instanceof DocumentFragment) {
|
|
92
|
+
fg.appendChild(ch);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (typeof ch === "string") {
|
|
96
|
+
fg.appendChild(document.createTextNode(ch));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return fg;
|
|
101
|
+
}
|
|
102
|
+
function $if(condition, ...elements) {
|
|
103
|
+
if (condition) {
|
|
104
|
+
return elements;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function $ifelse(condition, ifTrue, ifFalse) {
|
|
108
|
+
if (condition) {
|
|
109
|
+
return ifTrue;
|
|
110
|
+
}
|
|
111
|
+
return ifFalse;
|
|
112
|
+
}
|
|
113
|
+
function $case(value, ...elements) {
|
|
114
|
+
return (key) => {
|
|
115
|
+
if (key === value) {
|
|
116
|
+
return elements;
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function $switch(key, ...cases) {
|
|
122
|
+
let elements;
|
|
123
|
+
if (cases.length) {
|
|
124
|
+
for (let i = 0;i < cases.length; i++) {
|
|
125
|
+
elements = cases[i](key);
|
|
126
|
+
if (elements) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return elements;
|
|
132
|
+
}
|
|
133
|
+
function loop(datalist, component) {
|
|
134
|
+
return Array.isArray(datalist) ? datalist.map(component) : undefined;
|
|
135
|
+
}
|
|
136
|
+
var frag = function(children) {
|
|
137
|
+
const par = document.createDocumentFragment();
|
|
138
|
+
for (let i = 0;i < children.length; i++) {
|
|
139
|
+
let html = children[i];
|
|
140
|
+
if (typeof html === "function") {
|
|
141
|
+
html = html();
|
|
142
|
+
}
|
|
143
|
+
if (html instanceof HTMLElement || html instanceof DocumentFragment) {
|
|
144
|
+
par.appendChild(html);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (html instanceof String) {
|
|
148
|
+
par.appendChild(document.createTextNode(html));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
console.error(" ✘ Cradova err: wrong element type" + html);
|
|
152
|
+
}
|
|
153
|
+
return par;
|
|
154
|
+
};
|
|
155
|
+
function useState(newState, self) {
|
|
156
|
+
if (typeof self !== "function")
|
|
157
|
+
return null;
|
|
158
|
+
const Func = self;
|
|
159
|
+
Func._state_index += 1;
|
|
160
|
+
const idx = Func._state_index;
|
|
161
|
+
if (idx >= Func._state.length) {
|
|
162
|
+
Func._state[idx] = newState;
|
|
163
|
+
}
|
|
164
|
+
function setState(newState2) {
|
|
165
|
+
if (typeof newState2 === "function") {
|
|
166
|
+
newState2 = newState2(Func._state[idx]);
|
|
167
|
+
}
|
|
168
|
+
Func._state[idx] = newState2;
|
|
169
|
+
funcManager.recall(Func);
|
|
170
|
+
}
|
|
171
|
+
return [Func._state[idx], setState];
|
|
172
|
+
}
|
|
173
|
+
function useEffect(effect, self) {
|
|
174
|
+
funcManager._effect(self, effect);
|
|
175
|
+
if (typeof self !== "function")
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function useRef() {
|
|
179
|
+
return new __raw_ref;
|
|
180
|
+
}
|
|
181
|
+
var getSignal = (func, name) => {
|
|
182
|
+
return func.pipes.get(name);
|
|
183
|
+
};
|
|
184
|
+
var sendSignal = (func, name, data) => {
|
|
185
|
+
const signal = func.signals.get(name);
|
|
186
|
+
if (signal) {
|
|
187
|
+
signal.publish(name, data);
|
|
188
|
+
} else {
|
|
189
|
+
console.error(" ✘ Cradova err : Invalid signal name " + name);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var isArrowFunc = (fn) => !fn.hasOwnProperty("prototype");
|
|
193
|
+
var toFunc = (func) => {
|
|
194
|
+
if (func.id)
|
|
195
|
+
return funcManager.render(func);
|
|
196
|
+
cradovaEvent.compId += 1;
|
|
197
|
+
func.id = cradovaEvent.compId;
|
|
198
|
+
func.effects = [];
|
|
199
|
+
func.rendered = false;
|
|
200
|
+
func.published = false;
|
|
201
|
+
func.preRendered = null;
|
|
202
|
+
func.reference = null;
|
|
203
|
+
func.signals = new Map;
|
|
204
|
+
func.pipes = new Map;
|
|
205
|
+
func._state = [];
|
|
206
|
+
func._state_index = 0;
|
|
207
|
+
func.effectuate = null;
|
|
208
|
+
return funcManager.render(func);
|
|
209
|
+
};
|
|
210
|
+
var funcManager = {
|
|
211
|
+
render(func) {
|
|
212
|
+
cradovaEvent.compId += 1;
|
|
213
|
+
func.id = cradovaEvent.compId;
|
|
214
|
+
func.effects = [];
|
|
215
|
+
func.rendered = false;
|
|
216
|
+
func._state_index = 0;
|
|
217
|
+
func._state = [];
|
|
218
|
+
const html = func.apply(func);
|
|
219
|
+
if (html instanceof HTMLElement) {
|
|
220
|
+
func.reference = html;
|
|
221
|
+
this.effector(func);
|
|
222
|
+
func.rendered = true;
|
|
223
|
+
func.published = true;
|
|
224
|
+
} else {
|
|
225
|
+
console.error(" ✘ Cradova err : Invalid html content, got - " + html);
|
|
226
|
+
}
|
|
227
|
+
return html;
|
|
228
|
+
},
|
|
229
|
+
_effect(func, fn) {
|
|
230
|
+
if (!func.rendered) {
|
|
231
|
+
func.effects.push(fn);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
async effector(func) {
|
|
235
|
+
for (let i = 0;i < func.effects.length; i++) {
|
|
236
|
+
const fn = await func.effects[i].apply(func);
|
|
237
|
+
if (typeof fn === "function") {
|
|
238
|
+
CradovaEvent.after_page_is_killed.push(fn);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
func.effects = [];
|
|
242
|
+
if (func.effectuate) {
|
|
243
|
+
func.effectuate();
|
|
244
|
+
func.effectuate = null;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
recall(func) {
|
|
248
|
+
if (!func.rendered) {
|
|
249
|
+
func.effectuate = () => {
|
|
250
|
+
if (func.published) {
|
|
251
|
+
this.activate(func);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
} else {
|
|
255
|
+
if (func.published) {
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
this.activate(func);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
async activate(func) {
|
|
263
|
+
func.published = false;
|
|
264
|
+
if (!func.rendered) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
func._state_index = 0;
|
|
268
|
+
const node = func.reference;
|
|
269
|
+
if (document.contains(node)) {
|
|
270
|
+
const html = func.apply(func);
|
|
271
|
+
if (html instanceof HTMLElement) {
|
|
272
|
+
node.insertAdjacentElement("beforebegin", html);
|
|
273
|
+
node.remove();
|
|
274
|
+
func.published = true;
|
|
275
|
+
func.reference = html;
|
|
276
|
+
CradovaEvent.dispatchEvent("after_comp_is_mounted");
|
|
277
|
+
} else {
|
|
278
|
+
console.error(" ✘ Cradova err : Invalid html, got - " + html);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
func.reference = null;
|
|
282
|
+
func.rendered = false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/primitives/dom-objects.ts
|
|
288
|
+
var a = cra("a");
|
|
289
|
+
var audio = cra("audio");
|
|
290
|
+
var button = cra("button");
|
|
291
|
+
var canvas = cra("canvas");
|
|
292
|
+
var div = cra("div");
|
|
293
|
+
var footer = cra("footer");
|
|
294
|
+
var form = cra("form");
|
|
295
|
+
var h1 = cra("h1");
|
|
296
|
+
var h2 = cra("h2");
|
|
297
|
+
var h3 = cra("h3");
|
|
298
|
+
var h4 = cra("h4");
|
|
299
|
+
var h5 = cra("h5");
|
|
300
|
+
var h6 = cra("h6");
|
|
301
|
+
var header = cra("header");
|
|
302
|
+
var i = cra("i");
|
|
303
|
+
var iframe = cra("iframe");
|
|
304
|
+
var img = cra("img");
|
|
305
|
+
var input = cra("input");
|
|
306
|
+
var label = cra("label");
|
|
307
|
+
var li = cra("li");
|
|
308
|
+
var main = cra("main");
|
|
309
|
+
var nav = cra("nav");
|
|
310
|
+
var ol = cra("ol");
|
|
311
|
+
var option = cra("option");
|
|
312
|
+
var p = cra("p");
|
|
313
|
+
var section = cra("section");
|
|
314
|
+
var select = cra("select");
|
|
315
|
+
var span = cra("span");
|
|
316
|
+
var textarea = cra("textarea");
|
|
317
|
+
var ul = cra("ul");
|
|
318
|
+
var video = cra("video");
|
|
319
|
+
var tbody = cra("table");
|
|
320
|
+
var table = cra("tbody");
|
|
321
|
+
var td = cra("td");
|
|
322
|
+
var tr = cra("tr");
|
|
323
|
+
var svg = (svg2, properties) => {
|
|
324
|
+
const span2 = document.createElement("span");
|
|
325
|
+
span2.innerHTML = svg2;
|
|
326
|
+
return makeElement(span2, properties || []);
|
|
327
|
+
};
|
|
328
|
+
var raw = (html) => {
|
|
329
|
+
const div2 = document.createElement("div");
|
|
330
|
+
if (Array.isArray(html)) {
|
|
331
|
+
div2.innerHTML = html[0];
|
|
332
|
+
} else {
|
|
333
|
+
if (typeof html === "string") {
|
|
334
|
+
div2.innerHTML = html;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const df = new DocumentFragment;
|
|
338
|
+
df.append(...Array.from(div2.children));
|
|
339
|
+
return df;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// src/primitives/classes.ts
|
|
343
|
+
class cradovaEvent {
|
|
344
|
+
static compId = 0;
|
|
345
|
+
after_comp_is_mounted = [];
|
|
346
|
+
after_page_is_killed = [];
|
|
347
|
+
dispatchEvent(eventName) {
|
|
348
|
+
const eventListeners = this[eventName];
|
|
349
|
+
if (eventName.includes("Active")) {
|
|
350
|
+
for (let i2 = 0;i2 < eventListeners.length; i2++) {
|
|
351
|
+
eventListeners[i2]();
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
while (eventListeners.length !== 0) {
|
|
356
|
+
eventListeners.shift()();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
var CradovaEvent = new cradovaEvent;
|
|
361
|
+
|
|
362
|
+
class Signal {
|
|
363
|
+
pn;
|
|
364
|
+
subs;
|
|
365
|
+
pipe;
|
|
366
|
+
constructor(initial, props) {
|
|
367
|
+
this.pipe = initial;
|
|
368
|
+
this.subs = {};
|
|
369
|
+
if (props && props.persistName) {
|
|
370
|
+
this.pn = props.persistName;
|
|
371
|
+
const key = localStorage.getItem(props.persistName);
|
|
372
|
+
if (key && key !== "undefined") {
|
|
373
|
+
this.pipe = JSON.parse(key);
|
|
374
|
+
}
|
|
375
|
+
if (typeof initial === "object") {
|
|
376
|
+
for (const key2 in initial) {
|
|
377
|
+
if (!Object.prototype.hasOwnProperty.call(this.pipe, key2)) {
|
|
378
|
+
this.pipe[key2] = initial[key2];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
publish(eventName, data) {
|
|
385
|
+
this.pipe[eventName] = data;
|
|
386
|
+
const subs = this.subs[eventName] || [];
|
|
387
|
+
for (let i2 = 0;i2 < subs.length; i2++) {
|
|
388
|
+
const c = subs[i2];
|
|
389
|
+
c.pipes.set(eventName, this.pipe[eventName]);
|
|
390
|
+
funcManager.recall(c);
|
|
391
|
+
}
|
|
392
|
+
if (this.pn) {
|
|
393
|
+
localStorage.setItem(this.pn, JSON.stringify(this.pipe));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
publishObject(events) {
|
|
397
|
+
const s = new Map;
|
|
398
|
+
for (const [eventName, data] of Object.entries(events)) {
|
|
399
|
+
this.pipe[eventName] = data;
|
|
400
|
+
const subs = this.subs[eventName] || [];
|
|
401
|
+
for (let i2 = 0;i2 < subs.length; i2++) {
|
|
402
|
+
const c = subs[i2];
|
|
403
|
+
c.pipes.set(eventName, this.pipe[eventName]);
|
|
404
|
+
s.set(c.id, c);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
for (const [_, c] of s) {
|
|
408
|
+
c.recall();
|
|
409
|
+
}
|
|
410
|
+
if (this.pn) {
|
|
411
|
+
localStorage.setItem(this.pn, JSON.stringify(this.pipe));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
subscribe(eventName, comp) {
|
|
415
|
+
if (typeof Function === "function") {
|
|
416
|
+
if (Array.isArray(eventName)) {
|
|
417
|
+
for (let i2 = 0;i2 < eventName.length; i2++) {
|
|
418
|
+
const event = eventName[i2];
|
|
419
|
+
if (this.pipe[event]) {
|
|
420
|
+
comp.pipes.set(event, this.pipe[event]);
|
|
421
|
+
comp.signals.set(event, this);
|
|
422
|
+
} else {
|
|
423
|
+
console.error(` ✘ Cradova err: ${event} is not a valid event for this Signal`);
|
|
424
|
+
}
|
|
425
|
+
if (this.subs[event]?.find((cmp) => cmp.id === comp.id)) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (!this.subs[event]) {
|
|
429
|
+
this.subs[event] = [comp];
|
|
430
|
+
} else {
|
|
431
|
+
this.subs[event].push(comp);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (this.pipe[eventName]) {
|
|
437
|
+
comp.pipes.set(eventName, this.pipe[eventName]);
|
|
438
|
+
comp.signals.set(eventName, this);
|
|
439
|
+
} else {
|
|
440
|
+
console.error(` ✘ Cradova err: ${eventName} is not a valid event for this Signal`);
|
|
441
|
+
}
|
|
442
|
+
if (this.subs[eventName]?.find((cmp) => cmp.id === comp.id)) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (!this.subs[eventName]) {
|
|
446
|
+
this.subs[eventName] = [comp];
|
|
447
|
+
} else {
|
|
448
|
+
this.subs[eventName].push(comp);
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
console.error(` ✘ Cradova err: ${comp} is not a valid component`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
clearPersist() {
|
|
455
|
+
if (this.pn) {
|
|
456
|
+
localStorage.removeItem(this.pn);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
class Page {
|
|
462
|
+
_name;
|
|
463
|
+
_html;
|
|
464
|
+
_template;
|
|
465
|
+
_dropped = false;
|
|
466
|
+
_snapshot;
|
|
467
|
+
_snapshot_html;
|
|
468
|
+
_deCB;
|
|
469
|
+
constructor(pageParams) {
|
|
470
|
+
const { template, name } = pageParams;
|
|
471
|
+
if (typeof template !== "function") {
|
|
472
|
+
throw new Error(` ✘ Cradova err: template function for the page is not a function`);
|
|
473
|
+
}
|
|
474
|
+
this._html = template;
|
|
475
|
+
this._name = name || document.title;
|
|
476
|
+
this._snapshot = pageParams.snapshotIsolation || false;
|
|
477
|
+
}
|
|
478
|
+
async _takeSnapShot() {
|
|
479
|
+
if (RouterBox.doc.dataset["snapshot"] === "true")
|
|
480
|
+
return;
|
|
481
|
+
try {
|
|
482
|
+
const response = await fetch(location.href);
|
|
483
|
+
if (!response.ok)
|
|
484
|
+
throw new Error("Failed to fetch the page");
|
|
485
|
+
const html = await response.text();
|
|
486
|
+
const parser = new DOMParser;
|
|
487
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
488
|
+
doc.title = this._name;
|
|
489
|
+
const wrapper = doc.querySelector('[data-wrapper="app"]');
|
|
490
|
+
if (wrapper) {
|
|
491
|
+
wrapper.setAttribute("data-snapshot", "true");
|
|
492
|
+
wrapper.innerHTML = this._snapshot_html;
|
|
493
|
+
} else {
|
|
494
|
+
console.error("Wrapper or template is not found");
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const snapshot = doc.documentElement.outerHTML;
|
|
498
|
+
await fetch(location.origin, {
|
|
499
|
+
body: snapshot,
|
|
500
|
+
method: "POST",
|
|
501
|
+
headers: {
|
|
502
|
+
"Content-Type": "text/html",
|
|
503
|
+
"cradova-snapshot": location.href.slice(location.origin.length)
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
} catch (error) {
|
|
507
|
+
console.error("Snapshot error:", error);
|
|
508
|
+
}
|
|
509
|
+
this._snapshot_html = undefined;
|
|
510
|
+
}
|
|
511
|
+
set onDeactivate(cb) {
|
|
512
|
+
this._deCB = cb;
|
|
513
|
+
}
|
|
514
|
+
drop(state) {
|
|
515
|
+
if (typeof state === "boolean") {
|
|
516
|
+
this._dropped = state;
|
|
517
|
+
return;
|
|
518
|
+
} else
|
|
519
|
+
return this._dropped;
|
|
520
|
+
}
|
|
521
|
+
async _activate() {
|
|
522
|
+
if (this._dropped) {
|
|
523
|
+
history.go(-1);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (this._name)
|
|
527
|
+
document.title = this._name;
|
|
528
|
+
this._template = div({ id: "page" }, this._html);
|
|
529
|
+
RouterBox.doc.innerHTML = "";
|
|
530
|
+
if (this._snapshot)
|
|
531
|
+
this._snapshot_html = this._template.outerHTML;
|
|
532
|
+
RouterBox.doc.appendChild(this._template);
|
|
533
|
+
CradovaEvent.dispatchEvent("after_comp_is_mounted");
|
|
534
|
+
window.scrollTo({
|
|
535
|
+
top: 0,
|
|
536
|
+
left: 0,
|
|
537
|
+
behavior: "instant"
|
|
538
|
+
});
|
|
539
|
+
CradovaEvent.dispatchEvent("after_page_is_killed");
|
|
540
|
+
if (this._snapshot)
|
|
541
|
+
this._takeSnapShot();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
class RouterBoxClass {
|
|
546
|
+
doc = null;
|
|
547
|
+
lastNavigatedRouteController;
|
|
548
|
+
nextRouteController;
|
|
549
|
+
lastNavigatedRoute;
|
|
550
|
+
pageShow = null;
|
|
551
|
+
pageHide = null;
|
|
552
|
+
errorHandler;
|
|
553
|
+
loadingPage = null;
|
|
554
|
+
pageData = { params: {} };
|
|
555
|
+
routes = {};
|
|
556
|
+
paused = false;
|
|
557
|
+
route(path, page) {
|
|
558
|
+
if (!page) {
|
|
559
|
+
console.error(" ✘ Cradova err: not a valid page ", page);
|
|
560
|
+
}
|
|
561
|
+
return this.routes[path] = page;
|
|
562
|
+
}
|
|
563
|
+
async router(_e, _force) {
|
|
564
|
+
const url = window.location.href;
|
|
565
|
+
let route, params;
|
|
566
|
+
if (this.paused) {
|
|
567
|
+
window.location.hash = "paused";
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (this.nextRouteController) {
|
|
571
|
+
route = this.nextRouteController;
|
|
572
|
+
this.nextRouteController = undefined;
|
|
573
|
+
} else {
|
|
574
|
+
[route, params] = this.checker(url);
|
|
575
|
+
}
|
|
576
|
+
if (typeof route !== "undefined") {
|
|
577
|
+
try {
|
|
578
|
+
if (typeof route === "function") {
|
|
579
|
+
if (this.loadingPage instanceof Page) {
|
|
580
|
+
await this.loadingPage._activate();
|
|
581
|
+
}
|
|
582
|
+
route = await route();
|
|
583
|
+
}
|
|
584
|
+
if (route?.default)
|
|
585
|
+
route = route.default;
|
|
586
|
+
if (!route) {
|
|
587
|
+
if (this.lastNavigatedRoute) {
|
|
588
|
+
history.pushState({}, url, this.lastNavigatedRoute);
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (params) {
|
|
593
|
+
this.pageData.params = params;
|
|
594
|
+
}
|
|
595
|
+
await route._activate();
|
|
596
|
+
this.lastNavigatedRouteController && this.lastNavigatedRouteController._deCB?.();
|
|
597
|
+
this.lastNavigatedRoute = url;
|
|
598
|
+
this.lastNavigatedRouteController = route;
|
|
599
|
+
} catch (error) {
|
|
600
|
+
if (typeof this.errorHandler === "function") {
|
|
601
|
+
this.errorHandler(error, url);
|
|
602
|
+
} else {
|
|
603
|
+
console.error(error);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
} else {
|
|
607
|
+
if (this.routes["*"]) {
|
|
608
|
+
await this.routes["*"]._activate();
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
checker(url) {
|
|
613
|
+
if (url[0] !== "/") {
|
|
614
|
+
url = url.slice(url.indexOf("/", 8));
|
|
615
|
+
}
|
|
616
|
+
if (this.routes[url]) {
|
|
617
|
+
return [this.routes[url], { path: url }];
|
|
618
|
+
}
|
|
619
|
+
if (url.includes("?")) {
|
|
620
|
+
let search;
|
|
621
|
+
const params = {};
|
|
622
|
+
[url, search] = url.split("?");
|
|
623
|
+
new URLSearchParams(search).forEach((val, key) => {
|
|
624
|
+
params[key] = val;
|
|
625
|
+
});
|
|
626
|
+
if (this.routes[url]) {
|
|
627
|
+
return [this.routes[url], params];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const path in this.routes) {
|
|
631
|
+
if (path.includes(":")) {
|
|
632
|
+
const urlFixtures = url.split("/");
|
|
633
|
+
const pathFixtures = path.split("/");
|
|
634
|
+
if (url.endsWith("/")) {
|
|
635
|
+
urlFixtures.pop();
|
|
636
|
+
}
|
|
637
|
+
let fixturesX = 0;
|
|
638
|
+
let fixturesY = 0;
|
|
639
|
+
if (pathFixtures.length === urlFixtures.length) {
|
|
640
|
+
for (let i2 = 0;i2 < pathFixtures.length; i2++) {
|
|
641
|
+
if (pathFixtures[i2].includes(":")) {
|
|
642
|
+
fixturesY++;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (urlFixtures[i2] === pathFixtures[i2]) {
|
|
646
|
+
fixturesX++;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
650
|
+
const routesParams = {};
|
|
651
|
+
for (let i2 = 0;i2 < pathFixtures.length; i2++) {
|
|
652
|
+
if (pathFixtures[i2].includes(":")) {
|
|
653
|
+
routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return [this.routes[path], routesParams];
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (path.includes("*")) {
|
|
661
|
+
const p2 = path.slice(0, -1);
|
|
662
|
+
if (url.startsWith(p2)) {
|
|
663
|
+
return [this.routes[path], { extraPath: url.slice(p2.length) }];
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return [];
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
var RouterBox = new RouterBoxClass;
|
|
671
|
+
|
|
672
|
+
class Router {
|
|
673
|
+
static BrowserRoutes(obj) {
|
|
674
|
+
for (const path in obj) {
|
|
675
|
+
const page = obj[path];
|
|
676
|
+
if (typeof page === "object" && typeof page.then === "function" || typeof page === "function") {
|
|
677
|
+
RouterBox.routes[path] = async () => {
|
|
678
|
+
const paged = typeof page === "function" ? await page() : await page;
|
|
679
|
+
return RouterBox.route(path, paged);
|
|
680
|
+
};
|
|
681
|
+
} else {
|
|
682
|
+
RouterBox.route(path, page);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
Router._mount();
|
|
686
|
+
}
|
|
687
|
+
static pauseNavigation() {
|
|
688
|
+
RouterBox["paused"] = true;
|
|
689
|
+
window.location.hash = "paused";
|
|
690
|
+
}
|
|
691
|
+
static resumeNavigation() {
|
|
692
|
+
RouterBox["paused"] = false;
|
|
693
|
+
window.location.replace(window.location.pathname + window.location.search);
|
|
694
|
+
history.go(-1);
|
|
695
|
+
}
|
|
696
|
+
static navigate(href, data) {
|
|
697
|
+
if (typeof href !== "string") {
|
|
698
|
+
console.error(" ✘ Cradova err: href must be a defined path but got " + href + " instead");
|
|
699
|
+
}
|
|
700
|
+
let route = null, params;
|
|
701
|
+
if (href.includes(".")) {
|
|
702
|
+
window.location.href = href;
|
|
703
|
+
} else {
|
|
704
|
+
[route, params] = RouterBox.checker(href);
|
|
705
|
+
if (route) {
|
|
706
|
+
RouterBox.nextRouteController = route;
|
|
707
|
+
window.history.pushState({}, "", href);
|
|
708
|
+
}
|
|
709
|
+
RouterBox.pageData.params = params;
|
|
710
|
+
RouterBox.pageData.data = data;
|
|
711
|
+
RouterBox.router(null);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
static setLoadingPage(page) {
|
|
715
|
+
if (page instanceof Page) {
|
|
716
|
+
RouterBox.loadingPage = page;
|
|
717
|
+
} else {
|
|
718
|
+
throw new Error(" ✘ Cradova err: Loading Page should be a cradova page class");
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
static get PageData() {
|
|
722
|
+
return RouterBox.pageData;
|
|
723
|
+
}
|
|
724
|
+
static addErrorHandler(callback) {
|
|
725
|
+
if (typeof callback === "function") {
|
|
726
|
+
RouterBox["errorHandler"] = callback;
|
|
727
|
+
} else {
|
|
728
|
+
throw new Error(" ✘ Cradova err: callback for error event is not a function");
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
static _mount() {
|
|
732
|
+
let doc = document.querySelector("[data-wrapper=app]");
|
|
733
|
+
if (doc) {
|
|
734
|
+
RouterBox.doc = doc;
|
|
735
|
+
} else {
|
|
736
|
+
throw new Error(`✘ Cradova err: please add '<div data-wrapper="app"></div>' to the body of your index.html file `);
|
|
737
|
+
}
|
|
738
|
+
window.addEventListener("pageshow", () => RouterBox.router());
|
|
739
|
+
window.addEventListener("popstate", (_e) => {
|
|
740
|
+
_e.preventDefault();
|
|
741
|
+
RouterBox.router();
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
class __raw_ref {
|
|
747
|
+
tree = {};
|
|
748
|
+
bindAs(name) {
|
|
749
|
+
return [this, name];
|
|
750
|
+
}
|
|
751
|
+
elem(name) {
|
|
752
|
+
return this.tree[name];
|
|
753
|
+
}
|
|
754
|
+
_append(name, Element) {
|
|
755
|
+
this.tree[name] = Element;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
export {
|
|
759
|
+
video,
|
|
760
|
+
useState,
|
|
761
|
+
useRef,
|
|
762
|
+
useEffect,
|
|
763
|
+
ul,
|
|
764
|
+
tr,
|
|
765
|
+
textarea,
|
|
766
|
+
td,
|
|
767
|
+
tbody,
|
|
768
|
+
table,
|
|
769
|
+
svg,
|
|
770
|
+
span,
|
|
771
|
+
sendSignal,
|
|
772
|
+
select,
|
|
773
|
+
section,
|
|
774
|
+
raw,
|
|
775
|
+
p,
|
|
776
|
+
option,
|
|
777
|
+
ol,
|
|
778
|
+
nav,
|
|
779
|
+
makeElement,
|
|
780
|
+
main,
|
|
781
|
+
loop,
|
|
782
|
+
li,
|
|
783
|
+
label,
|
|
784
|
+
input,
|
|
785
|
+
img,
|
|
786
|
+
iframe,
|
|
787
|
+
i,
|
|
788
|
+
header,
|
|
789
|
+
h6,
|
|
790
|
+
h5,
|
|
791
|
+
h4,
|
|
792
|
+
h3,
|
|
793
|
+
h2,
|
|
794
|
+
h1,
|
|
795
|
+
getSignal,
|
|
796
|
+
funcManager,
|
|
797
|
+
frag,
|
|
798
|
+
form,
|
|
799
|
+
footer,
|
|
800
|
+
div,
|
|
801
|
+
cradovaEvent,
|
|
802
|
+
cra,
|
|
803
|
+
canvas,
|
|
804
|
+
button,
|
|
805
|
+
audio,
|
|
806
|
+
a,
|
|
807
|
+
__raw_ref,
|
|
808
|
+
Signal,
|
|
809
|
+
Router,
|
|
810
|
+
Page,
|
|
811
|
+
CradovaEvent,
|
|
812
|
+
$switch,
|
|
813
|
+
$ifelse,
|
|
814
|
+
$if,
|
|
815
|
+
$case
|
|
816
|
+
};
|
|
@@ -1,73 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { browserPageType, CradovaPageType } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Cradova event
|
|
4
4
|
*/
|
|
5
|
-
declare class cradovaEvent {
|
|
5
|
+
export declare class cradovaEvent {
|
|
6
6
|
static compId: number;
|
|
7
7
|
/**
|
|
8
|
-
* the events runs only once and removed
|
|
9
|
-
* these event are call and removed once when when a
|
|
8
|
+
* the events runs only once and removed to avoid duplication when added on the next rendering
|
|
9
|
+
* these event are call and removed once when when a Function is rendered to the dom
|
|
10
10
|
* @param callback
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* the events runs many times.
|
|
15
|
-
* these event are called before a comp is rendered to the dom
|
|
16
|
-
* @param callback
|
|
17
|
-
*/
|
|
18
|
-
beforeMountActive: Function[];
|
|
12
|
+
after_comp_is_mounted: Function[];
|
|
19
13
|
/**
|
|
20
14
|
* the events runs once after comps unmounts.
|
|
21
|
-
* these event are called before a
|
|
15
|
+
* these event are called before a Function is rendered to the dom
|
|
22
16
|
* @param callback
|
|
23
17
|
*/
|
|
24
|
-
|
|
18
|
+
after_page_is_killed: Function[];
|
|
25
19
|
/**
|
|
26
20
|
* Dispatch any event
|
|
27
21
|
* @param eventName
|
|
28
22
|
*/
|
|
29
|
-
dispatchEvent(eventName: "
|
|
23
|
+
dispatchEvent(eventName: "after_comp_is_mounted" | "after_page_is_killed"): void;
|
|
30
24
|
}
|
|
31
25
|
export declare const CradovaEvent: cradovaEvent;
|
|
32
|
-
/**
|
|
33
|
-
* Cradova Comp
|
|
34
|
-
* -------
|
|
35
|
-
* create dynamic components
|
|
36
|
-
*/
|
|
37
|
-
export declare class Comp<Props extends Record<string, any> = any> {
|
|
38
|
-
id: number;
|
|
39
|
-
private component;
|
|
40
|
-
private effects;
|
|
41
|
-
private effectuate;
|
|
42
|
-
private rendered;
|
|
43
|
-
private published;
|
|
44
|
-
private preRendered;
|
|
45
|
-
private reference;
|
|
46
|
-
subData: Props | null;
|
|
47
|
-
_state: Props[];
|
|
48
|
-
_state_index: number;
|
|
49
|
-
constructor(component: (this: Comp<Props>, data?: Props) => HTMLElement);
|
|
50
|
-
preRender(props: Props): void;
|
|
51
|
-
/**
|
|
52
|
-
* Cradova Comp
|
|
53
|
-
* ---
|
|
54
|
-
* returns html with cradova reference
|
|
55
|
-
* @param data
|
|
56
|
-
* @returns () => HTMLElement
|
|
57
|
-
*/
|
|
58
|
-
render(props?: Props): HTMLElement;
|
|
59
|
-
_effect(fn: () => Promise<void> | void): void;
|
|
60
|
-
private effector;
|
|
61
|
-
/**
|
|
62
|
-
* Cradova Comp
|
|
63
|
-
* ---
|
|
64
|
-
* update comp component with new data and update the dom.
|
|
65
|
-
* @param data
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
recall(props?: Props): void;
|
|
69
|
-
private activate;
|
|
70
|
-
}
|
|
71
26
|
/**
|
|
72
27
|
* Cradova Signal
|
|
73
28
|
* ----
|
|
@@ -93,14 +48,23 @@ export declare class Signal<Type extends Record<string, any>> {
|
|
|
93
48
|
* @param data - data for the action
|
|
94
49
|
*/
|
|
95
50
|
publish<T extends keyof Type>(eventName: T, data: Type[T]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Cradova Signal
|
|
53
|
+
* ----
|
|
54
|
+
* fires an action if available
|
|
55
|
+
* @param key - string key of the action
|
|
56
|
+
* @param data - data for the action
|
|
57
|
+
*/
|
|
58
|
+
publishObject<T extends keyof Type>(events: Record<T, Type[T]>): void;
|
|
96
59
|
/**
|
|
97
60
|
* Cradova Signal
|
|
98
61
|
* ----
|
|
99
62
|
* subscribe to an event
|
|
100
63
|
*
|
|
101
|
-
* @param
|
|
64
|
+
* @param name of event.
|
|
65
|
+
* @param Func component to bind to.
|
|
102
66
|
*/
|
|
103
|
-
subscribe<T extends keyof Type>(eventName: T, comp:
|
|
67
|
+
subscribe<T extends keyof Type>(eventName: T | T[], comp: any): void;
|
|
104
68
|
/**
|
|
105
69
|
* Cradova Signal
|
|
106
70
|
* ----
|
|
@@ -124,7 +88,7 @@ export declare class Page {
|
|
|
124
88
|
* this should be a cradova page component
|
|
125
89
|
*/
|
|
126
90
|
_html: (this: Page) => HTMLElement;
|
|
127
|
-
|
|
91
|
+
_template?: HTMLElement;
|
|
128
92
|
private _dropped;
|
|
129
93
|
private _snapshot;
|
|
130
94
|
private _snapshot_html?;
|
|
@@ -203,4 +167,27 @@ export declare class Router {
|
|
|
203
167
|
static addErrorHandler(callback: (err?: unknown, pagePath?: string) => void): void;
|
|
204
168
|
static _mount(): void;
|
|
205
169
|
}
|
|
206
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Cradova
|
|
172
|
+
* ---
|
|
173
|
+
* make reference to dom elements
|
|
174
|
+
*/
|
|
175
|
+
export declare class __raw_ref {
|
|
176
|
+
tree: Record<string, any>;
|
|
177
|
+
/**
|
|
178
|
+
* Bind a DOM element to a reference name.
|
|
179
|
+
* @param name - The name to reference the DOM element by.
|
|
180
|
+
*/
|
|
181
|
+
bindAs(name: string): __raw_ref;
|
|
182
|
+
/**
|
|
183
|
+
* Retrieve a referenced DOM element.
|
|
184
|
+
* @param name - The name of the referenced DOM element.
|
|
185
|
+
*/
|
|
186
|
+
elem<ElementType extends HTMLElement = HTMLElement>(name: string): ElementType | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Append a DOM element to the reference, overwriting any existing reference.
|
|
189
|
+
* @param name - The name to reference the DOM element by.
|
|
190
|
+
* @param element - The DOM element to reference.
|
|
191
|
+
*/
|
|
192
|
+
_append(name: string, Element: HTMLElement): void;
|
|
193
|
+
}
|
|
@@ -22,15 +22,17 @@ export declare const li: (...Children_and_Properties: VJS_params_TYPE<HTMLLIElem
|
|
|
22
22
|
export declare const main: (...Children_and_Properties: VJS_params_TYPE<HTMLElement>) => HTMLElement;
|
|
23
23
|
export declare const nav: (...Children_and_Properties: VJS_params_TYPE<HTMLElement>) => HTMLElement;
|
|
24
24
|
export declare const ol: (...Children_and_Properties: VJS_params_TYPE<HTMLOListElement>) => HTMLOListElement;
|
|
25
|
-
export declare const optgroup: (...Children_and_Properties: VJS_params_TYPE<HTMLOptGroupElement>) => HTMLOptGroupElement;
|
|
26
25
|
export declare const option: (...Children_and_Properties: VJS_params_TYPE<HTMLOptionElement>) => HTMLOptionElement;
|
|
27
26
|
export declare const p: (...Children_and_Properties: VJS_params_TYPE<HTMLParagraphElement>) => HTMLParagraphElement;
|
|
28
27
|
export declare const section: (...Children_and_Properties: VJS_params_TYPE<HTMLElement>) => HTMLElement;
|
|
29
28
|
export declare const select: (...Children_and_Properties: VJS_params_TYPE<HTMLSelectElement>) => HTMLSelectElement;
|
|
30
|
-
export declare const source: (...Children_and_Properties: VJS_params_TYPE<HTMLSourceElement>) => HTMLSourceElement;
|
|
31
29
|
export declare const span: (...Children_and_Properties: VJS_params_TYPE<HTMLSpanElement>) => HTMLSpanElement;
|
|
32
30
|
export declare const textarea: (...Children_and_Properties: VJS_params_TYPE<HTMLTextAreaElement>) => HTMLTextAreaElement;
|
|
33
31
|
export declare const ul: (...Children_and_Properties: VJS_params_TYPE<HTMLUListElement>) => HTMLUListElement;
|
|
34
32
|
export declare const video: (...Children_and_Properties: VJS_params_TYPE<HTMLVideoElement>) => HTMLVideoElement;
|
|
33
|
+
export declare const tbody: (...Children_and_Properties: VJS_params_TYPE<HTMLTableElement>) => HTMLTableElement;
|
|
34
|
+
export declare const table: (...Children_and_Properties: VJS_params_TYPE<HTMLTableSectionElement>) => HTMLTableSectionElement;
|
|
35
|
+
export declare const td: (...Children_and_Properties: VJS_params_TYPE<HTMLTableCellElement>) => HTMLTableCellElement;
|
|
36
|
+
export declare const tr: (...Children_and_Properties: VJS_params_TYPE<HTMLTableColElement>) => HTMLTableColElement;
|
|
35
37
|
export declare const svg: (svg: string, properties?: VJS_params_TYPE<HTMLSpanElement>) => HTMLSpanElement;
|
|
36
38
|
export declare const raw: (html: string | TemplateStringsArray) => DocumentFragment;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CradovaFunc } from "./types";
|
|
2
|
+
export declare const funcManager: {
|
|
3
|
+
render(func: CradovaFunc): HTMLElement;
|
|
4
|
+
_effect(func: CradovaFunc, fn: () => Promise<void> | void): void;
|
|
5
|
+
effector(func: CradovaFunc): Promise<void>;
|
|
6
|
+
recall(func: CradovaFunc): void;
|
|
7
|
+
activate(func: CradovaFunc): Promise<void>;
|
|
8
|
+
};
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
4
|
-
* Cradova
|
|
5
|
-
* ---
|
|
6
|
-
* make reference to dom elements
|
|
7
|
-
*/
|
|
8
|
-
declare class __raw_ref {
|
|
9
|
-
tree: Record<string, any>;
|
|
10
|
-
/**
|
|
11
|
-
* Bind a DOM element to a reference name.
|
|
12
|
-
* @param name - The name to reference the DOM element by.
|
|
13
|
-
*/
|
|
14
|
-
bindAs(name: string): __raw_ref;
|
|
15
|
-
/**
|
|
16
|
-
* Retrieve a referenced DOM element.
|
|
17
|
-
* @param name - The name of the referenced DOM element.
|
|
18
|
-
*/
|
|
19
|
-
elem<ElementType extends HTMLElement = HTMLElement>(name: string): ElementType | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Swap referenced DOM element.
|
|
22
|
-
*/
|
|
23
|
-
swap(name1: string, name2: string): void;
|
|
24
|
-
/**
|
|
25
|
-
* Append a DOM element to the reference, overwriting any existing reference.
|
|
26
|
-
* @param name - The name to reference the DOM element by.
|
|
27
|
-
* @param element - The DOM element to reference.
|
|
28
|
-
*/
|
|
29
|
-
_append(name: string, Element: HTMLElement): void;
|
|
30
|
-
}
|
|
1
|
+
import type { VJS_params_TYPE, CradovaFunc } from "./types.js";
|
|
2
|
+
import { __raw_ref } from "./classes.js";
|
|
31
3
|
export declare const makeElement: <E extends HTMLElement>(element: E & HTMLElement, ElementChildrenAndPropertyList: VJS_params_TYPE<E>) => E;
|
|
32
4
|
export declare const cra: <E extends HTMLElement>(tag: string) => (...Children_and_Properties: VJS_params_TYPE<E>) => E;
|
|
33
|
-
export declare function Rhoda(l: VJS_params_TYPE<HTMLElement>): DocumentFragment;
|
|
34
5
|
/**
|
|
35
6
|
* @param {expression} condition
|
|
36
7
|
* @param {function} elements[]
|
|
@@ -52,18 +23,18 @@ export declare const frag: (children: VJS_params_TYPE<HTMLElement>) => DocumentF
|
|
|
52
23
|
* ---
|
|
53
24
|
* Allows functional components to manage state by providing a state value and a function to update it.
|
|
54
25
|
* @param initialValue
|
|
55
|
-
* @param
|
|
26
|
+
* @param Func
|
|
56
27
|
* @returns [state, setState]
|
|
57
28
|
*/
|
|
58
|
-
export declare function useState<S = unknown>(newState: S,
|
|
29
|
+
export declare function useState<S = unknown>(newState: S, self: any): [S, (newState: S | ((preS: S) => S)) => void];
|
|
59
30
|
/**
|
|
60
31
|
* Cradova
|
|
61
32
|
* ---
|
|
62
|
-
Allows side effects to be performed in functional components
|
|
33
|
+
Allows side effects to be performed in functional components, such as fetching data or subscribing to events.
|
|
63
34
|
* @param effect
|
|
64
35
|
* @returns
|
|
65
36
|
*/
|
|
66
|
-
export declare function useEffect(effect: () => void,
|
|
37
|
+
export declare function useEffect(effect: () => void, self: any): any;
|
|
67
38
|
/**
|
|
68
39
|
* Cradova
|
|
69
40
|
* ---
|
|
@@ -71,4 +42,13 @@ Returns a mutable reference object of dom elements.
|
|
|
71
42
|
* @returns reference
|
|
72
43
|
*/
|
|
73
44
|
export declare function useRef(): __raw_ref;
|
|
45
|
+
export declare const getSignal: (func: CradovaFunc, name: string) => any;
|
|
46
|
+
export declare const sendSignal: (func: CradovaFunc, name: string, data: any) => void;
|
|
47
|
+
export declare const funcManager: {
|
|
48
|
+
render(func: CradovaFunc): HTMLElement;
|
|
49
|
+
_effect(func: CradovaFunc, fn: () => Promise<void> | void): void;
|
|
50
|
+
effector(func: CradovaFunc): Promise<void>;
|
|
51
|
+
recall(func: CradovaFunc): void;
|
|
52
|
+
activate(func: CradovaFunc): Promise<void>;
|
|
53
|
+
};
|
|
74
54
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CSS from "csstype";
|
|
2
|
-
import {
|
|
2
|
+
import { __raw_ref, Page, Signal } from "./classes.js";
|
|
3
3
|
type DataAttributes = {
|
|
4
4
|
[key: `data-${string}`]: string;
|
|
5
5
|
};
|
|
@@ -24,13 +24,13 @@ type Attributes = {
|
|
|
24
24
|
required?: string;
|
|
25
25
|
frameBorder?: string;
|
|
26
26
|
placeholder?: string;
|
|
27
|
-
ref?:
|
|
27
|
+
ref?: __raw_ref;
|
|
28
28
|
autocomplete?: string;
|
|
29
29
|
style?: CSS.Properties;
|
|
30
30
|
recall?: (P: any) => void;
|
|
31
31
|
onmount?: (this: HTMLElement & Attributes) => void;
|
|
32
32
|
};
|
|
33
|
-
export type VJS_params_TYPE<E extends HTMLElement> = (
|
|
33
|
+
export type VJS_params_TYPE<E extends HTMLElement> = (string | undefined | HTMLElement | HTMLElement[] | DocumentFragment | DocumentFragment[] | Attributes | Partial<Attributes> | (() => HTMLElement) | Partial<E> | Record<string, (this: E) => void> | Partial<DataAttributes> | Partial<AriaAttributes> | CSS.Properties<string | number>)[];
|
|
34
34
|
export interface RouterRouteObject {
|
|
35
35
|
_html: ((this: Page, data?: unknown) => HTMLElement | DocumentFragment) | HTMLElement | DocumentFragment;
|
|
36
36
|
_delegatedRoutes: number | boolean;
|
|
@@ -78,4 +78,17 @@ export type CradovaPageType = {
|
|
|
78
78
|
snapshotIsolation?: boolean;
|
|
79
79
|
};
|
|
80
80
|
export type browserPageType<importType = Page> = importType | Promise<importType> | (() => Promise<importType>);
|
|
81
|
+
export type CradovaFunc = {
|
|
82
|
+
(): HTMLElement;
|
|
83
|
+
id?: number;
|
|
84
|
+
rendered: boolean;
|
|
85
|
+
published: boolean;
|
|
86
|
+
reference: HTMLElement | null;
|
|
87
|
+
signals: Map<string, Signal<any>>;
|
|
88
|
+
pipes: Map<string, any>;
|
|
89
|
+
_state: unknown[];
|
|
90
|
+
_state_index: number;
|
|
91
|
+
effects: (() => Promise<void> | void)[];
|
|
92
|
+
effectuate: ((this: any) => void) | null;
|
|
93
|
+
};
|
|
81
94
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cradova",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Build Powerful ⚡ Web Apps with Ease",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"PWA",
|
|
22
22
|
"webapp",
|
|
23
23
|
"SPA",
|
|
24
|
-
"Comps",
|
|
25
24
|
"Signal",
|
|
26
25
|
"VJS",
|
|
27
26
|
"vjs specification",
|