cradova 3.3.10 → 3.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -31
- package/dist/primitives/classes.d.ts +17 -3
- package/dist/primitives/functions.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -62,18 +62,18 @@ function loop(datalist, component) {
|
|
|
62
62
|
}
|
|
63
63
|
return Array.isArray(datalist) ? datalist.map(component) : undefined;
|
|
64
64
|
}
|
|
65
|
-
function useState(
|
|
65
|
+
function useState(newState, Comp2) {
|
|
66
66
|
Comp2._state_index += 1;
|
|
67
67
|
const idx = Comp2._state_index;
|
|
68
68
|
if (!Comp2._state_track[idx]) {
|
|
69
|
-
Comp2.
|
|
69
|
+
Comp2._state[idx] = newState;
|
|
70
70
|
Comp2._state_track[idx] = true;
|
|
71
71
|
}
|
|
72
|
-
function setState(
|
|
73
|
-
Comp2.
|
|
72
|
+
function setState(newState2) {
|
|
73
|
+
Comp2._state[idx] = newState2;
|
|
74
74
|
Comp2.recall();
|
|
75
75
|
}
|
|
76
|
-
return [Comp2.
|
|
76
|
+
return [Comp2._state[idx], setState];
|
|
77
77
|
}
|
|
78
78
|
function useEffect(effect, Comp2) {
|
|
79
79
|
Comp2._effect(effect);
|
|
@@ -124,7 +124,7 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
|
124
124
|
if (!href.includes("://")) {
|
|
125
125
|
element.addEventListener("click", (e) => {
|
|
126
126
|
e.preventDefault();
|
|
127
|
-
Router.navigate(element.
|
|
127
|
+
Router.navigate(element.href);
|
|
128
128
|
if (href.includes("#")) {
|
|
129
129
|
const l = href.split("#").at(-1);
|
|
130
130
|
document.getElementById("#" + l)?.scrollIntoView();
|
|
@@ -250,7 +250,9 @@ class Comp {
|
|
|
250
250
|
constructor(component) {
|
|
251
251
|
this.component = component.bind(this);
|
|
252
252
|
CradovaEvent.addBeforeMountActive(() => {
|
|
253
|
-
this.
|
|
253
|
+
this._state_index = 0;
|
|
254
|
+
this._state_track = {};
|
|
255
|
+
this._state = [];
|
|
254
256
|
});
|
|
255
257
|
}
|
|
256
258
|
preRender() {
|
|
@@ -274,21 +276,9 @@ class Comp {
|
|
|
274
276
|
return this.preRendered;
|
|
275
277
|
}
|
|
276
278
|
}
|
|
277
|
-
instance() {
|
|
278
|
-
return this.reference.current("html");
|
|
279
|
-
}
|
|
280
279
|
_setExtra(Extra) {
|
|
281
280
|
this.Signal = Extra;
|
|
282
281
|
}
|
|
283
|
-
_roll_state(data, idx, get = false) {
|
|
284
|
-
if (!get) {
|
|
285
|
-
if (idx !== 0) {
|
|
286
|
-
this._state[idx - 1] = undefined;
|
|
287
|
-
}
|
|
288
|
-
this._state[idx] = data;
|
|
289
|
-
}
|
|
290
|
-
return this._state[idx];
|
|
291
|
-
}
|
|
292
282
|
_effect(fn) {
|
|
293
283
|
if (!this.rendered) {
|
|
294
284
|
this.effects.push(fn.bind(this));
|
|
@@ -333,6 +323,11 @@ class Comp {
|
|
|
333
323
|
this.published = true;
|
|
334
324
|
this.reference._appendDomForce("html", html);
|
|
335
325
|
CradovaEvent.dispatchEvent("afterMount");
|
|
326
|
+
(async () => {
|
|
327
|
+
if (!document.contains(html)) {
|
|
328
|
+
this.rendered = false;
|
|
329
|
+
}
|
|
330
|
+
})();
|
|
336
331
|
} else {
|
|
337
332
|
console.error(" \u2718 Cradova err : Invalid html, got - " + html);
|
|
338
333
|
}
|
|
@@ -621,7 +616,7 @@ class RouterBoxClass {
|
|
|
621
616
|
return;
|
|
622
617
|
}
|
|
623
618
|
async router(_e, _force) {
|
|
624
|
-
let url = window.location.
|
|
619
|
+
let url = window.location.href, route, params;
|
|
625
620
|
if (this.paused) {
|
|
626
621
|
window.location.hash = "paused";
|
|
627
622
|
return;
|
|
@@ -682,17 +677,16 @@ class RouterBoxClass {
|
|
|
682
677
|
if (this.routes[url]) {
|
|
683
678
|
return [this.routes[url], { path: url }];
|
|
684
679
|
}
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
680
|
+
if (url.includes("?")) {
|
|
681
|
+
let search;
|
|
682
|
+
const params = {};
|
|
683
|
+
[url, search] = url.split("?");
|
|
684
|
+
new URLSearchParams(search).forEach((val, key) => {
|
|
685
|
+
params[key] = val;
|
|
686
|
+
});
|
|
687
|
+
if (this.routes[url]) {
|
|
688
|
+
return [this.routes[url], { data: params, path: url }];
|
|
693
689
|
}
|
|
694
|
-
const path = url.slice(0, url.indexOf("/?") + 2);
|
|
695
|
-
return [this.routes[path], { path, search }];
|
|
696
690
|
}
|
|
697
691
|
for (const path in this.routes) {
|
|
698
692
|
if (path.includes(":")) {
|
|
@@ -774,7 +768,7 @@ class Router {
|
|
|
774
768
|
if (href.includes(".")) {
|
|
775
769
|
window.location.href = href;
|
|
776
770
|
} else {
|
|
777
|
-
if (href === window.location.
|
|
771
|
+
if (href === window.location.href) {
|
|
778
772
|
return;
|
|
779
773
|
}
|
|
780
774
|
[route, params] = RouterBox.checker(href);
|
|
@@ -5,8 +5,24 @@ import { type CradovaPageType, type promisedPage } from "./types";
|
|
|
5
5
|
declare class cradovaEvent {
|
|
6
6
|
private afterMount;
|
|
7
7
|
private beforeMountActive;
|
|
8
|
+
/**
|
|
9
|
+
* add an event to an exhaustible list of events
|
|
10
|
+
* the events runs only once and removed.
|
|
11
|
+
* these event are call and removed once when when a comp is rendered to the dom
|
|
12
|
+
* @param callback
|
|
13
|
+
*/
|
|
8
14
|
addAfterMount(callback: () => void): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* add an event to a list of events
|
|
17
|
+
* the events runs many times.
|
|
18
|
+
* these event are called before a comp is rendered to the dom
|
|
19
|
+
* @param callback
|
|
20
|
+
*/
|
|
9
21
|
addBeforeMountActive(callback: () => void): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Dispatch any event
|
|
24
|
+
* @param eventName
|
|
25
|
+
*/
|
|
10
26
|
dispatchEvent(eventName: "beforeMountActive" | "afterMount"): void;
|
|
11
27
|
}
|
|
12
28
|
export declare const CradovaEvent: cradovaEvent;
|
|
@@ -40,9 +56,7 @@ export declare class Comp<Prop extends Record<string, any> = any> {
|
|
|
40
56
|
* @returns () => HTMLElement
|
|
41
57
|
*/
|
|
42
58
|
render(): any;
|
|
43
|
-
instance(): HTMLElement;
|
|
44
59
|
_setExtra(Extra: createSignal<any>): void;
|
|
45
|
-
_roll_state<S>(data: any, idx: number, get?: boolean): S;
|
|
46
60
|
_effect(fn: () => Promise<void> | void): void;
|
|
47
61
|
private effector;
|
|
48
62
|
/**
|
|
@@ -208,7 +222,7 @@ export declare class Page {
|
|
|
208
222
|
/**
|
|
209
223
|
* this should be a cradova page component
|
|
210
224
|
*/
|
|
211
|
-
_html: (
|
|
225
|
+
_html: (this: Page) => HTMLElement;
|
|
212
226
|
private _template;
|
|
213
227
|
private _callBack;
|
|
214
228
|
private _deCallBack;
|
|
@@ -33,7 +33,7 @@ export declare const frag: (children: VJS_params_TYPE<HTMLElement>) => DocumentF
|
|
|
33
33
|
* @param Comp
|
|
34
34
|
* @returns [state, setState]
|
|
35
35
|
*/
|
|
36
|
-
export declare function useState<S = unknown>(
|
|
36
|
+
export declare function useState<S = unknown>(newState: S, Comp: Comp): [S, (newState: S) => void];
|
|
37
37
|
/**
|
|
38
38
|
* Cradova
|
|
39
39
|
* ---
|