cradova 3.3.20 → 3.3.54
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 +303 -367
- package/dist/primitives/classes.d.ts +28 -52
- package/dist/primitives/functions.d.ts +26 -7
- package/dist/primitives/types.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,253 +1,41 @@
|
|
|
1
|
-
// src/primitives/functions.ts
|
|
2
|
-
function Rhoda(l) {
|
|
3
|
-
const fg = new DocumentFragment;
|
|
4
|
-
for (let ch of l) {
|
|
5
|
-
if (Array.isArray(ch)) {
|
|
6
|
-
fg.appendChild(Rhoda(ch));
|
|
7
|
-
} else {
|
|
8
|
-
if (ch instanceof Comp) {
|
|
9
|
-
ch = ch.render();
|
|
10
|
-
}
|
|
11
|
-
if (typeof ch === "function") {
|
|
12
|
-
ch = ch();
|
|
13
|
-
if (typeof ch === "function") {
|
|
14
|
-
ch = ch();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (ch instanceof HTMLElement || ch instanceof DocumentFragment) {
|
|
18
|
-
fg.appendChild(ch);
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
if (typeof ch === "string") {
|
|
22
|
-
fg.appendChild(document.createTextNode(ch));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return fg;
|
|
27
|
-
}
|
|
28
|
-
function $if(condition, ...elements) {
|
|
29
|
-
if (condition) {
|
|
30
|
-
return elements;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function $ifelse(condition, ifTrue, ifFalse) {
|
|
34
|
-
if (condition) {
|
|
35
|
-
return ifTrue;
|
|
36
|
-
}
|
|
37
|
-
return ifFalse;
|
|
38
|
-
}
|
|
39
|
-
function $case(value, ...elements) {
|
|
40
|
-
return (key) => {
|
|
41
|
-
if (key === value) {
|
|
42
|
-
return elements;
|
|
43
|
-
}
|
|
44
|
-
return;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function $switch(key, ...cases) {
|
|
48
|
-
let elements;
|
|
49
|
-
if (cases.length) {
|
|
50
|
-
for (let i = 0;i < cases.length; i++) {
|
|
51
|
-
elements = cases[i](key);
|
|
52
|
-
if (elements) {
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return elements;
|
|
58
|
-
}
|
|
59
|
-
function loop(datalist, component) {
|
|
60
|
-
return Array.isArray(datalist) ? datalist.map(component) : undefined;
|
|
61
|
-
}
|
|
62
|
-
function useState(newState, Comp2) {
|
|
63
|
-
Comp2._state_index += 1;
|
|
64
|
-
const idx = Comp2._state_index;
|
|
65
|
-
if (idx >= Comp2._state.length) {
|
|
66
|
-
Comp2._state[idx] = newState;
|
|
67
|
-
}
|
|
68
|
-
function setState(newState2) {
|
|
69
|
-
Comp2._state[idx] = newState2;
|
|
70
|
-
Comp2.recall();
|
|
71
|
-
}
|
|
72
|
-
return [Comp2._state[idx], setState];
|
|
73
|
-
}
|
|
74
|
-
function useEffect(effect, Comp2) {
|
|
75
|
-
Comp2._effect(effect);
|
|
76
|
-
}
|
|
77
|
-
function useRef() {
|
|
78
|
-
return new __raw_ref;
|
|
79
|
-
}
|
|
80
|
-
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
81
|
-
const props = {};
|
|
82
|
-
let text = undefined;
|
|
83
|
-
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
84
|
-
for (let i = 0;i < ElementChildrenAndPropertyList.length; i++) {
|
|
85
|
-
let child = ElementChildrenAndPropertyList[i];
|
|
86
|
-
if (typeof child === "function") {
|
|
87
|
-
child = child();
|
|
88
|
-
}
|
|
89
|
-
if (child instanceof Comp) {
|
|
90
|
-
child = child.render();
|
|
91
|
-
}
|
|
92
|
-
if (child instanceof HTMLElement || child instanceof DocumentFragment) {
|
|
93
|
-
element.appendChild(child);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(child)) {
|
|
97
|
-
element.appendChild(Rhoda(child));
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (typeof child === "string") {
|
|
101
|
-
text = child;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (typeof child === "object") {
|
|
105
|
-
Object.assign(props, child);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
return element;
|
|
111
|
-
}
|
|
112
|
-
if (typeof props === "object" && element) {
|
|
113
|
-
for (const [prop, value] of Object.entries(props)) {
|
|
114
|
-
if (prop === "style" && typeof value === "object") {
|
|
115
|
-
Object.assign(element.style, value);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (prop === "href") {
|
|
119
|
-
const href = value || "";
|
|
120
|
-
if (!href.includes("://")) {
|
|
121
|
-
element.addEventListener("click", (e) => {
|
|
122
|
-
e.preventDefault();
|
|
123
|
-
Router.navigate(element.href);
|
|
124
|
-
if (href.includes("#")) {
|
|
125
|
-
const l = href.split("#").at(-1);
|
|
126
|
-
document.getElementById("#" + l)?.scrollIntoView();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
element.setAttribute(prop, value);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (Array.isArray(value)) {
|
|
134
|
-
if (prop == "reference" && value[0] instanceof __raw_ref) {
|
|
135
|
-
value[0]._appendDomForce(value[1], element);
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
if (value[0] instanceof createSignal) {
|
|
139
|
-
value[0].bindRef(element, {
|
|
140
|
-
_element_property: prop,
|
|
141
|
-
signalProperty: value[1]
|
|
142
|
-
});
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (prop === "onmount" && typeof props["onmount"] === "function") {
|
|
147
|
-
const ev = () => {
|
|
148
|
-
props["onmount"]?.apply(element);
|
|
149
|
-
props["onmount"] = undefined;
|
|
150
|
-
};
|
|
151
|
-
CradovaEvent.addAfterMount(ev);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (prop.includes("data-")) {
|
|
155
|
-
element.setAttribute(prop, value);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (prop.includes("aria-")) {
|
|
159
|
-
element.setAttribute(prop, value);
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
element[prop] = value;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (text !== undefined) {
|
|
166
|
-
element.appendChild(document.createTextNode(text));
|
|
167
|
-
}
|
|
168
|
-
return element;
|
|
169
|
-
};
|
|
170
|
-
var cra = (tag) => {
|
|
171
|
-
return (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
|
|
172
|
-
};
|
|
173
|
-
var SNRU = {
|
|
174
|
-
snru: "",
|
|
175
|
-
memo_SNRU() {
|
|
176
|
-
let key = 0;
|
|
177
|
-
const url = window.location.href;
|
|
178
|
-
for (let i = 0;i < url.length; i++) {
|
|
179
|
-
key += url.charCodeAt(i);
|
|
180
|
-
}
|
|
181
|
-
this.snru = key.toString();
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var frag = function(children) {
|
|
185
|
-
const par = document.createDocumentFragment();
|
|
186
|
-
for (let i = 0;i < children.length; i++) {
|
|
187
|
-
let html = children[i];
|
|
188
|
-
if (typeof html === "function") {
|
|
189
|
-
html = html();
|
|
190
|
-
}
|
|
191
|
-
if (html instanceof HTMLElement || html instanceof DocumentFragment) {
|
|
192
|
-
par.appendChild(html);
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
if (html instanceof String) {
|
|
196
|
-
par.appendChild(document.createTextNode(html));
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
console.error(" \u2718 Cradova err: wrong element type" + html);
|
|
200
|
-
}
|
|
201
|
-
return par;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
1
|
// src/primitives/classes.ts
|
|
205
2
|
class cradovaEvent {
|
|
3
|
+
static refid = 0;
|
|
206
4
|
afterMount = [];
|
|
207
5
|
beforeMountActive = [];
|
|
208
|
-
|
|
209
|
-
if (!this.addAfterMount) {
|
|
210
|
-
this.afterMount = [];
|
|
211
|
-
}
|
|
212
|
-
this.afterMount.push(callback);
|
|
213
|
-
}
|
|
214
|
-
async addBeforeMountActive(callback) {
|
|
215
|
-
if (!this.beforeMountActive) {
|
|
216
|
-
this.beforeMountActive = [];
|
|
217
|
-
}
|
|
218
|
-
this.beforeMountActive.push(callback);
|
|
219
|
-
}
|
|
6
|
+
afterDeactivate = [];
|
|
220
7
|
dispatchEvent(eventName) {
|
|
221
|
-
const eventListeners = this[eventName]
|
|
222
|
-
|
|
223
|
-
|
|
8
|
+
const eventListeners = this[eventName];
|
|
9
|
+
if (eventName.includes("Active")) {
|
|
10
|
+
for (let i = 0;i < eventListeners.length; i++) {
|
|
224
11
|
eventListeners[i]();
|
|
225
|
-
} else {
|
|
226
|
-
eventListeners.shift()();
|
|
227
12
|
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
while (eventListeners.length !== 0) {
|
|
16
|
+
eventListeners.shift()();
|
|
228
17
|
}
|
|
229
18
|
}
|
|
230
19
|
}
|
|
231
20
|
var CradovaEvent = new cradovaEvent;
|
|
232
21
|
|
|
233
22
|
class Comp {
|
|
23
|
+
id;
|
|
234
24
|
component;
|
|
235
25
|
effects = [];
|
|
236
26
|
effectuate = null;
|
|
237
27
|
rendered = false;
|
|
238
28
|
published = false;
|
|
239
29
|
preRendered = null;
|
|
240
|
-
reference =
|
|
30
|
+
reference = null;
|
|
241
31
|
Signal;
|
|
242
32
|
_state = [];
|
|
243
33
|
_state_index = 0;
|
|
244
34
|
test;
|
|
245
35
|
constructor(component) {
|
|
246
36
|
this.component = component.bind(this);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
this._state = [];
|
|
250
|
-
});
|
|
37
|
+
cradovaEvent.refid += 1;
|
|
38
|
+
this.id = cradovaEvent.refid;
|
|
251
39
|
}
|
|
252
40
|
preRender() {
|
|
253
41
|
this.preRendered = this.render();
|
|
@@ -256,9 +44,11 @@ class Comp {
|
|
|
256
44
|
this.effects = [];
|
|
257
45
|
this.rendered = false;
|
|
258
46
|
if (!this.preRendered) {
|
|
47
|
+
this._state_index = 0;
|
|
48
|
+
this._state = [];
|
|
259
49
|
const html = this.component();
|
|
260
|
-
if (html instanceof HTMLElement
|
|
261
|
-
this.reference
|
|
50
|
+
if (html instanceof HTMLElement) {
|
|
51
|
+
this.reference = html;
|
|
262
52
|
this.effector.apply(this);
|
|
263
53
|
this.rendered = true;
|
|
264
54
|
this.published = true;
|
|
@@ -271,6 +61,9 @@ class Comp {
|
|
|
271
61
|
}
|
|
272
62
|
}
|
|
273
63
|
_setExtra(Extra) {
|
|
64
|
+
if (this.Signal) {
|
|
65
|
+
Extra.value = this.Signal.value;
|
|
66
|
+
}
|
|
274
67
|
this.Signal = Extra;
|
|
275
68
|
}
|
|
276
69
|
_effect(fn) {
|
|
@@ -280,7 +73,10 @@ class Comp {
|
|
|
280
73
|
}
|
|
281
74
|
async effector() {
|
|
282
75
|
for (let i = 0;i < this.effects.length; i++) {
|
|
283
|
-
await this.effects[i].apply(this);
|
|
76
|
+
const fn = await this.effects[i].apply(this);
|
|
77
|
+
if (typeof fn === "function") {
|
|
78
|
+
CradovaEvent.afterDeactivate.push(fn);
|
|
79
|
+
}
|
|
284
80
|
}
|
|
285
81
|
this.effects = [];
|
|
286
82
|
if (this.effectuate) {
|
|
@@ -297,33 +93,33 @@ class Comp {
|
|
|
297
93
|
};
|
|
298
94
|
} else {
|
|
299
95
|
if (this.published) {
|
|
300
|
-
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
this.activate();
|
|
98
|
+
});
|
|
301
99
|
}
|
|
302
100
|
}
|
|
303
101
|
}
|
|
304
102
|
async activate() {
|
|
305
|
-
this._state_index = 0;
|
|
306
103
|
this.published = false;
|
|
307
104
|
if (!this.rendered) {
|
|
308
105
|
return;
|
|
309
106
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
107
|
+
this._state_index = 0;
|
|
108
|
+
const node = this.reference;
|
|
109
|
+
if (document.contains(node)) {
|
|
110
|
+
const html = this.component();
|
|
111
|
+
if (html instanceof HTMLElement) {
|
|
314
112
|
node.insertAdjacentElement("beforebegin", html);
|
|
315
113
|
node.remove();
|
|
114
|
+
this.published = true;
|
|
115
|
+
this.reference = html;
|
|
116
|
+
CradovaEvent.dispatchEvent("afterMount");
|
|
117
|
+
} else {
|
|
118
|
+
console.error(" \u2718 Cradova err : Invalid html, got - " + html);
|
|
316
119
|
}
|
|
317
|
-
this.published = true;
|
|
318
|
-
this.reference._appendDomForce("html", html);
|
|
319
|
-
CradovaEvent.dispatchEvent("afterMount");
|
|
320
|
-
(async () => {
|
|
321
|
-
if (!document.contains(html)) {
|
|
322
|
-
this.rendered = false;
|
|
323
|
-
}
|
|
324
|
-
})();
|
|
325
120
|
} else {
|
|
326
|
-
|
|
121
|
+
this.reference = null;
|
|
122
|
+
this.rendered = false;
|
|
327
123
|
}
|
|
328
124
|
}
|
|
329
125
|
}
|
|
@@ -348,33 +144,7 @@ class lazy {
|
|
|
348
144
|
}
|
|
349
145
|
}
|
|
350
146
|
|
|
351
|
-
class
|
|
352
|
-
tree = {};
|
|
353
|
-
globalTree = {};
|
|
354
|
-
bindAs(name) {
|
|
355
|
-
return [this, name];
|
|
356
|
-
}
|
|
357
|
-
current(name) {
|
|
358
|
-
if (this.tree[SNRU.snru]) {
|
|
359
|
-
return this.tree[SNRU.snru][name];
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
_appendDomForce(name, Element) {
|
|
364
|
-
if (this.tree[SNRU.snru]) {
|
|
365
|
-
this.tree[SNRU.snru][name] = Element;
|
|
366
|
-
} else {
|
|
367
|
-
this.tree[SNRU.snru] = {};
|
|
368
|
-
this.tree[SNRU.snru][name] = Element;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
_appendDomForceGlobal(name, Element) {
|
|
372
|
-
this.globalTree[name] = Element;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
var localTree = new __raw_ref;
|
|
376
|
-
|
|
377
|
-
class createSignal {
|
|
147
|
+
class Signal {
|
|
378
148
|
callback;
|
|
379
149
|
persistName = "";
|
|
380
150
|
actions = {};
|
|
@@ -397,34 +167,34 @@ class createSignal {
|
|
|
397
167
|
}
|
|
398
168
|
}
|
|
399
169
|
}
|
|
400
|
-
set(value,
|
|
170
|
+
set(value, shouldCompRender) {
|
|
401
171
|
if (typeof value === "function") {
|
|
402
172
|
this.value = value(this.value);
|
|
403
173
|
} else {
|
|
404
174
|
this.value = value;
|
|
405
175
|
}
|
|
406
|
-
if (this.
|
|
407
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
408
|
-
}
|
|
409
|
-
if (this.comp.length && shouldRefRender !== false) {
|
|
176
|
+
if (this.comp.length && shouldCompRender !== false) {
|
|
410
177
|
this.updateState();
|
|
411
178
|
}
|
|
412
179
|
if (this.callback) {
|
|
413
180
|
this.callback(this.value);
|
|
414
181
|
}
|
|
182
|
+
if (this.persistName) {
|
|
183
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
184
|
+
}
|
|
415
185
|
}
|
|
416
|
-
setKey(key, value,
|
|
417
|
-
if (typeof this.value === "object"
|
|
186
|
+
setKey(key, value, shouldCompRender) {
|
|
187
|
+
if (typeof this.value === "object") {
|
|
418
188
|
this.value[key] = value;
|
|
419
|
-
if (this.
|
|
420
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
421
|
-
}
|
|
422
|
-
if (this.comp.length && shouldRefRender !== false) {
|
|
189
|
+
if (this.comp.length && shouldCompRender !== false) {
|
|
423
190
|
this.updateState();
|
|
424
191
|
}
|
|
425
192
|
if (this.callback) {
|
|
426
193
|
this.callback(this.value);
|
|
427
194
|
}
|
|
195
|
+
if (this.persistName) {
|
|
196
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
197
|
+
}
|
|
428
198
|
} else {
|
|
429
199
|
throw new Error(`\u2718 Cradova err : can't set key ${String(key)} store.value is not an object`);
|
|
430
200
|
}
|
|
@@ -445,10 +215,10 @@ class createSignal {
|
|
|
445
215
|
}
|
|
446
216
|
}
|
|
447
217
|
}
|
|
448
|
-
fireAction(key
|
|
218
|
+
fireAction(key) {
|
|
449
219
|
if (typeof this.actions[key] === "function") {
|
|
450
|
-
this.updateState(key
|
|
451
|
-
return this.actions[key].call(this
|
|
220
|
+
this.updateState(key);
|
|
221
|
+
return this.actions[key].call(this);
|
|
452
222
|
} else {
|
|
453
223
|
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
454
224
|
}
|
|
@@ -460,54 +230,31 @@ class createSignal {
|
|
|
460
230
|
throw new Error("\u2718 Cradova err : can't bind an unavailable property! " + prop);
|
|
461
231
|
}
|
|
462
232
|
}
|
|
463
|
-
updateState(name
|
|
464
|
-
|
|
465
|
-
this.comp
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
ent.comp.recall();
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
if (ent._element_property) {
|
|
472
|
-
ent.comp.recall();
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
if (ent._signalProperty) {
|
|
476
|
-
ent.comp.recall();
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
} else {
|
|
482
|
-
for (let i = 0;i < this.comp.length; i++) {
|
|
483
|
-
const ent = this.comp[i];
|
|
484
|
-
if (ent._element_property && ent._signalProperty) {
|
|
485
|
-
ent.comp.recall();
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
if (ent._element_property) {
|
|
489
|
-
ent.comp.recall();
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
if (ent._signalProperty) {
|
|
493
|
-
ent.comp.recall();
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
if (!ent._element_property && !ent._signalProperty) {
|
|
497
|
-
ent.comp.recall();
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
233
|
+
updateState(name) {
|
|
234
|
+
for (let i = 0;i < this.comp.length; i++) {
|
|
235
|
+
const ent = this.comp[i];
|
|
236
|
+
if (ent._event && ent._event === name) {
|
|
237
|
+
continue;
|
|
500
238
|
}
|
|
239
|
+
if (ent._element_property && ent._signalProperty) {
|
|
240
|
+
ent.comp[ent._element_property] = this.value[ent._signalProperty];
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
ent.comp.recall();
|
|
501
244
|
}
|
|
502
245
|
}
|
|
503
|
-
|
|
504
|
-
comp
|
|
505
|
-
|
|
246
|
+
bindComp(comp, binding) {
|
|
247
|
+
if (comp instanceof Comp) {
|
|
248
|
+
if (this.comp.find((cmp) => cmp.comp?.id === comp.id))
|
|
249
|
+
return;
|
|
250
|
+
comp.render = comp.render.bind(comp);
|
|
251
|
+
comp._setExtra(this);
|
|
252
|
+
}
|
|
506
253
|
this.comp.push({
|
|
507
254
|
comp,
|
|
508
|
-
_signalProperty: binding
|
|
509
|
-
_element_property: binding
|
|
510
|
-
_event: binding
|
|
255
|
+
_signalProperty: binding?.signalProperty,
|
|
256
|
+
_element_property: binding?._element_property,
|
|
257
|
+
_event: binding?.event
|
|
511
258
|
});
|
|
512
259
|
}
|
|
513
260
|
listen(callback) {
|
|
@@ -527,16 +274,12 @@ class Page {
|
|
|
527
274
|
_callBack;
|
|
528
275
|
_deCallBack;
|
|
529
276
|
_dropped = false;
|
|
530
|
-
_errorHandler = null;
|
|
531
277
|
constructor(cradova_page_initials) {
|
|
532
278
|
const { template, name } = cradova_page_initials;
|
|
533
279
|
this._html = template;
|
|
534
280
|
this._name = name || "Document";
|
|
535
281
|
this._template.setAttribute("id", "page");
|
|
536
282
|
}
|
|
537
|
-
set errorHandler(errorHandler) {
|
|
538
|
-
this._errorHandler = errorHandler;
|
|
539
|
-
}
|
|
540
283
|
onActivate(cb) {
|
|
541
284
|
this._callBack = cb;
|
|
542
285
|
}
|
|
@@ -558,7 +301,6 @@ class Page {
|
|
|
558
301
|
history.go(-1);
|
|
559
302
|
return;
|
|
560
303
|
}
|
|
561
|
-
SNRU.memo_SNRU();
|
|
562
304
|
let html = this._html.apply(this);
|
|
563
305
|
if (html instanceof HTMLElement) {
|
|
564
306
|
this._template.innerHTML = "";
|
|
@@ -567,9 +309,9 @@ class Page {
|
|
|
567
309
|
throw new Error(` \u2718 Cradova err: template function for the page returned ${html} instead of html`);
|
|
568
310
|
}
|
|
569
311
|
document.title = this._name;
|
|
570
|
-
|
|
312
|
+
RouterBox.doc.innerHTML = "";
|
|
571
313
|
CradovaEvent.dispatchEvent("beforeMountActive");
|
|
572
|
-
|
|
314
|
+
RouterBox.doc.appendChild(this._template);
|
|
573
315
|
CradovaEvent.dispatchEvent("afterMount");
|
|
574
316
|
window.scrollTo({
|
|
575
317
|
top: 0,
|
|
@@ -577,10 +319,12 @@ class Page {
|
|
|
577
319
|
behavior: "instant"
|
|
578
320
|
});
|
|
579
321
|
this._callBack && await this._callBack();
|
|
322
|
+
CradovaEvent.dispatchEvent("afterDeactivate");
|
|
580
323
|
}
|
|
581
324
|
}
|
|
582
325
|
|
|
583
326
|
class RouterBoxClass {
|
|
327
|
+
doc = null;
|
|
584
328
|
lastNavigatedRouteController;
|
|
585
329
|
nextRouteController;
|
|
586
330
|
lastNavigatedRoute;
|
|
@@ -588,7 +332,7 @@ class RouterBoxClass {
|
|
|
588
332
|
pageHide = null;
|
|
589
333
|
errorHandler;
|
|
590
334
|
loadingPage = null;
|
|
591
|
-
|
|
335
|
+
pageData = { params: {} };
|
|
592
336
|
routes = {};
|
|
593
337
|
pageevents = [];
|
|
594
338
|
paused = false;
|
|
@@ -600,16 +344,14 @@ class RouterBoxClass {
|
|
|
600
344
|
}, 50);
|
|
601
345
|
}
|
|
602
346
|
route(path, page) {
|
|
603
|
-
if (
|
|
604
|
-
|
|
605
|
-
console.error(" \u2718 Cradova err: not a valid page ", page);
|
|
606
|
-
}
|
|
607
|
-
return this.routes[path] = page;
|
|
347
|
+
if (!page) {
|
|
348
|
+
console.error(" \u2718 Cradova err: not a valid page ", page);
|
|
608
349
|
}
|
|
609
|
-
return;
|
|
350
|
+
return this.routes[path] = page;
|
|
610
351
|
}
|
|
611
352
|
async router(_e, _force) {
|
|
612
|
-
|
|
353
|
+
const url = window.location.href;
|
|
354
|
+
let route, params;
|
|
613
355
|
if (this.paused) {
|
|
614
356
|
window.location.hash = "paused";
|
|
615
357
|
return;
|
|
@@ -635,7 +377,7 @@ class RouterBoxClass {
|
|
|
635
377
|
}
|
|
636
378
|
}
|
|
637
379
|
if (params) {
|
|
638
|
-
this.
|
|
380
|
+
this.pageData.params = params;
|
|
639
381
|
}
|
|
640
382
|
await route._activate();
|
|
641
383
|
this.start_pageevents(url);
|
|
@@ -643,15 +385,10 @@ class RouterBoxClass {
|
|
|
643
385
|
this.lastNavigatedRoute = url;
|
|
644
386
|
this.lastNavigatedRouteController = route;
|
|
645
387
|
} catch (error) {
|
|
646
|
-
if (
|
|
647
|
-
|
|
388
|
+
if (typeof this.errorHandler === "function") {
|
|
389
|
+
this.errorHandler(error, url);
|
|
648
390
|
} else {
|
|
649
|
-
|
|
650
|
-
this.errorHandler(error);
|
|
651
|
-
} else {
|
|
652
|
-
console.error(error);
|
|
653
|
-
throw new Error(" \u2718 Cradova err: consider adding error boundary to the specific page ");
|
|
654
|
-
}
|
|
391
|
+
console.error(error);
|
|
655
392
|
}
|
|
656
393
|
}
|
|
657
394
|
} else {
|
|
@@ -675,7 +412,7 @@ class RouterBoxClass {
|
|
|
675
412
|
params[key] = val;
|
|
676
413
|
});
|
|
677
414
|
if (this.routes[url]) {
|
|
678
|
-
return [this.routes[url],
|
|
415
|
+
return [this.routes[url], params];
|
|
679
416
|
}
|
|
680
417
|
}
|
|
681
418
|
for (const path in this.routes) {
|
|
@@ -704,7 +441,7 @@ class RouterBoxClass {
|
|
|
704
441
|
routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
|
|
705
442
|
}
|
|
706
443
|
}
|
|
707
|
-
return [this.routes[path],
|
|
444
|
+
return [this.routes[path], routesParams];
|
|
708
445
|
}
|
|
709
446
|
}
|
|
710
447
|
}
|
|
@@ -723,11 +460,11 @@ var RouterBox = new RouterBoxClass;
|
|
|
723
460
|
class Router {
|
|
724
461
|
static BrowserRoutes(obj) {
|
|
725
462
|
for (const path in obj) {
|
|
726
|
-
|
|
463
|
+
const page = obj[path];
|
|
727
464
|
if (typeof page === "object" && typeof page.then === "function" || typeof page === "function") {
|
|
728
465
|
RouterBox.routes[path] = async () => {
|
|
729
|
-
|
|
730
|
-
return RouterBox.route(path,
|
|
466
|
+
const pagepp = typeof page === "function" ? await page() : await page;
|
|
467
|
+
return RouterBox.route(path, pagepp?.default || pagepp);
|
|
731
468
|
};
|
|
732
469
|
} else {
|
|
733
470
|
RouterBox.route(path, page);
|
|
@@ -750,7 +487,7 @@ class Router {
|
|
|
750
487
|
window.location.replace(window.location.pathname + window.location.search);
|
|
751
488
|
history.go(-1);
|
|
752
489
|
}
|
|
753
|
-
static navigate(href, data
|
|
490
|
+
static navigate(href, data) {
|
|
754
491
|
if (typeof href !== "string") {
|
|
755
492
|
console.error(" \u2718 Cradova err: href must be a defined path but got " + href + " instead");
|
|
756
493
|
}
|
|
@@ -763,8 +500,8 @@ class Router {
|
|
|
763
500
|
RouterBox.nextRouteController = route;
|
|
764
501
|
window.history.pushState({}, "", href);
|
|
765
502
|
}
|
|
766
|
-
RouterBox.
|
|
767
|
-
RouterBox.
|
|
503
|
+
RouterBox.pageData.params = params;
|
|
504
|
+
RouterBox.pageData.data = data;
|
|
768
505
|
RouterBox.router(null);
|
|
769
506
|
}
|
|
770
507
|
}
|
|
@@ -779,11 +516,11 @@ class Router {
|
|
|
779
516
|
if (typeof callback === "function") {
|
|
780
517
|
RouterBox["pageevents"].push(callback);
|
|
781
518
|
} else {
|
|
782
|
-
throw new Error(" \u2718 Cradova err: callback for
|
|
519
|
+
throw new Error(" \u2718 Cradova err: callback for page events event is not a function");
|
|
783
520
|
}
|
|
784
521
|
}
|
|
785
|
-
static get
|
|
786
|
-
return RouterBox.
|
|
522
|
+
static get PageData() {
|
|
523
|
+
return RouterBox.pageData;
|
|
787
524
|
}
|
|
788
525
|
static addErrorHandler(callback) {
|
|
789
526
|
if (typeof callback === "function") {
|
|
@@ -798,9 +535,9 @@ class Router {
|
|
|
798
535
|
doc = document.createElement("div");
|
|
799
536
|
doc.setAttribute("data-wrapper", "app");
|
|
800
537
|
document.body.appendChild(doc);
|
|
801
|
-
|
|
538
|
+
RouterBox.doc = doc;
|
|
802
539
|
} else {
|
|
803
|
-
|
|
540
|
+
RouterBox.doc = doc;
|
|
804
541
|
}
|
|
805
542
|
window.addEventListener("pageshow", () => RouterBox.router());
|
|
806
543
|
window.addEventListener("popstate", (_e) => {
|
|
@@ -809,6 +546,207 @@ class Router {
|
|
|
809
546
|
});
|
|
810
547
|
}
|
|
811
548
|
}
|
|
549
|
+
// src/primitives/functions.ts
|
|
550
|
+
function Rhoda(l) {
|
|
551
|
+
const fg = new DocumentFragment;
|
|
552
|
+
for (let ch of l) {
|
|
553
|
+
if (Array.isArray(ch)) {
|
|
554
|
+
fg.appendChild(Rhoda(ch));
|
|
555
|
+
} else {
|
|
556
|
+
if (ch instanceof Comp) {
|
|
557
|
+
ch = ch.render();
|
|
558
|
+
}
|
|
559
|
+
if (typeof ch === "function") {
|
|
560
|
+
ch = ch();
|
|
561
|
+
if (typeof ch === "function") {
|
|
562
|
+
ch = ch();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (ch instanceof HTMLElement || ch instanceof DocumentFragment) {
|
|
566
|
+
fg.appendChild(ch);
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (typeof ch === "string") {
|
|
570
|
+
fg.appendChild(document.createTextNode(ch));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return fg;
|
|
575
|
+
}
|
|
576
|
+
function $if(condition, ...elements) {
|
|
577
|
+
if (condition) {
|
|
578
|
+
return elements;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function $ifelse(condition, ifTrue, ifFalse) {
|
|
582
|
+
if (condition) {
|
|
583
|
+
return ifTrue;
|
|
584
|
+
}
|
|
585
|
+
return ifFalse;
|
|
586
|
+
}
|
|
587
|
+
function $case(value, ...elements) {
|
|
588
|
+
return (key) => {
|
|
589
|
+
if (key === value) {
|
|
590
|
+
return elements;
|
|
591
|
+
}
|
|
592
|
+
return;
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function $switch(key, ...cases) {
|
|
596
|
+
let elements;
|
|
597
|
+
if (cases.length) {
|
|
598
|
+
for (let i = 0;i < cases.length; i++) {
|
|
599
|
+
elements = cases[i](key);
|
|
600
|
+
if (elements) {
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return elements;
|
|
606
|
+
}
|
|
607
|
+
function loop(datalist, component) {
|
|
608
|
+
return Array.isArray(datalist) ? datalist.map(component) : undefined;
|
|
609
|
+
}
|
|
610
|
+
function useState(newState, Comp2) {
|
|
611
|
+
Comp2._state_index += 1;
|
|
612
|
+
const idx = Comp2._state_index;
|
|
613
|
+
if (idx >= Comp2._state.length) {
|
|
614
|
+
Comp2._state[idx] = newState;
|
|
615
|
+
}
|
|
616
|
+
function setState(newState2) {
|
|
617
|
+
if (typeof newState2 === "function") {
|
|
618
|
+
newState2 = newState2(Comp2._state[idx]);
|
|
619
|
+
}
|
|
620
|
+
Comp2._state[idx] = newState2;
|
|
621
|
+
Comp2.recall();
|
|
622
|
+
}
|
|
623
|
+
return [Comp2._state[idx], setState];
|
|
624
|
+
}
|
|
625
|
+
function useEffect(effect, Comp2) {
|
|
626
|
+
Comp2._effect(effect);
|
|
627
|
+
}
|
|
628
|
+
function useRef() {
|
|
629
|
+
return new __raw_ref;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
class __raw_ref {
|
|
633
|
+
tree = {};
|
|
634
|
+
bindAs(name) {
|
|
635
|
+
return [this, name];
|
|
636
|
+
}
|
|
637
|
+
current(name) {
|
|
638
|
+
return this.tree[name];
|
|
639
|
+
}
|
|
640
|
+
_append(name, Element) {
|
|
641
|
+
this.tree[name] = Element;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
645
|
+
const props = {};
|
|
646
|
+
let text = undefined;
|
|
647
|
+
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
648
|
+
for (let i = 0;i < ElementChildrenAndPropertyList.length; i++) {
|
|
649
|
+
let child = ElementChildrenAndPropertyList[i];
|
|
650
|
+
if (typeof child === "function") {
|
|
651
|
+
child = child();
|
|
652
|
+
}
|
|
653
|
+
if (child instanceof Comp) {
|
|
654
|
+
child = child.render();
|
|
655
|
+
}
|
|
656
|
+
if (child instanceof HTMLElement || child instanceof DocumentFragment) {
|
|
657
|
+
element.appendChild(child);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (Array.isArray(child)) {
|
|
661
|
+
element.appendChild(Rhoda(child));
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (typeof child === "string") {
|
|
665
|
+
text = child;
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
if (typeof child === "object") {
|
|
669
|
+
Object.assign(props, child);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
return element;
|
|
675
|
+
}
|
|
676
|
+
if (typeof props === "object" && element) {
|
|
677
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
678
|
+
if (prop === "style" && typeof value === "object") {
|
|
679
|
+
Object.assign(element.style, value);
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (prop === "href") {
|
|
683
|
+
const href = value || "";
|
|
684
|
+
if (!href.includes("://")) {
|
|
685
|
+
element.addEventListener("click", (e) => {
|
|
686
|
+
e.preventDefault();
|
|
687
|
+
Router.navigate(element.href);
|
|
688
|
+
if (href.includes("#")) {
|
|
689
|
+
const l = href.split("#").at(-1);
|
|
690
|
+
document.getElementById("#" + l)?.scrollIntoView();
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
element.setAttribute(prop, value);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
if (Array.isArray(value)) {
|
|
698
|
+
if (prop == "reference" && value[0] instanceof __raw_ref) {
|
|
699
|
+
value[0]._append(value[1], element);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (value[0] instanceof Signal) {
|
|
703
|
+
value[0].bindComp(element, {
|
|
704
|
+
_element_property: prop,
|
|
705
|
+
signalProperty: value[1]
|
|
706
|
+
});
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (prop === "onmount") {
|
|
711
|
+
CradovaEvent.afterMount.push(() => {
|
|
712
|
+
typeof props["onmount"] === "function" && props["onmount"].apply(element);
|
|
713
|
+
});
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
if (prop.includes("data-") || prop.includes("aria-")) {
|
|
717
|
+
element.setAttribute(prop, value);
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
element[prop] = value;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if (text !== undefined) {
|
|
724
|
+
element.appendChild(document.createTextNode(text));
|
|
725
|
+
}
|
|
726
|
+
return element;
|
|
727
|
+
};
|
|
728
|
+
var cra = (tag) => {
|
|
729
|
+
return (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
|
|
730
|
+
};
|
|
731
|
+
var frag = function(children) {
|
|
732
|
+
const par = document.createDocumentFragment();
|
|
733
|
+
for (let i = 0;i < children.length; i++) {
|
|
734
|
+
let html = children[i];
|
|
735
|
+
if (typeof html === "function") {
|
|
736
|
+
html = html();
|
|
737
|
+
}
|
|
738
|
+
if (html instanceof HTMLElement || html instanceof DocumentFragment) {
|
|
739
|
+
par.appendChild(html);
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
if (html instanceof String) {
|
|
743
|
+
par.appendChild(document.createTextNode(html));
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
console.error(" \u2718 Cradova err: wrong element type" + html);
|
|
747
|
+
}
|
|
748
|
+
return par;
|
|
749
|
+
};
|
|
812
750
|
// src/primitives/dom-objects.ts
|
|
813
751
|
var a = cra("a");
|
|
814
752
|
var audio = cra("audio");
|
|
@@ -934,7 +872,6 @@ export {
|
|
|
934
872
|
dialog,
|
|
935
873
|
details,
|
|
936
874
|
datalist,
|
|
937
|
-
createSignal,
|
|
938
875
|
cra,
|
|
939
876
|
caption,
|
|
940
877
|
canvas,
|
|
@@ -942,8 +879,7 @@ export {
|
|
|
942
879
|
br,
|
|
943
880
|
audio,
|
|
944
881
|
a,
|
|
945
|
-
|
|
946
|
-
SNRU,
|
|
882
|
+
Signal,
|
|
947
883
|
Router,
|
|
948
884
|
Rhoda,
|
|
949
885
|
Page,
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import { type CradovaPageType, type
|
|
1
|
+
import { type CradovaPageType, type browserPageType } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Cradova event
|
|
4
4
|
*/
|
|
5
5
|
declare class cradovaEvent {
|
|
6
|
-
|
|
7
|
-
private beforeMountActive;
|
|
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
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -33,6 +36,7 @@ export declare const CradovaEvent: cradovaEvent;
|
|
|
33
36
|
*
|
|
34
37
|
*/
|
|
35
38
|
export declare class Comp<Prop extends Record<string, any> = any> {
|
|
39
|
+
id: number;
|
|
36
40
|
private component;
|
|
37
41
|
private effects;
|
|
38
42
|
private effectuate;
|
|
@@ -40,7 +44,7 @@ export declare class Comp<Prop extends Record<string, any> = any> {
|
|
|
40
44
|
private published;
|
|
41
45
|
private preRendered;
|
|
42
46
|
private reference;
|
|
43
|
-
Signal:
|
|
47
|
+
Signal: Signal<Prop> | undefined;
|
|
44
48
|
_state: Prop[];
|
|
45
49
|
_state_index: number;
|
|
46
50
|
test?: string;
|
|
@@ -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:
|
|
61
|
+
_setExtra(Extra: Signal<any>): void;
|
|
58
62
|
_effect(fn: () => Promise<void> | void): void;
|
|
59
63
|
private effector;
|
|
60
64
|
/**
|
|
@@ -78,32 +82,6 @@ export declare class lazy<Type> {
|
|
|
78
82
|
constructor(cb: () => Promise<unknown>);
|
|
79
83
|
load(): Promise<void>;
|
|
80
84
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Cradova
|
|
83
|
-
* ---
|
|
84
|
-
* make reference to dom elements
|
|
85
|
-
*/
|
|
86
|
-
export declare class __raw_ref {
|
|
87
|
-
tree: Record<string, any>;
|
|
88
|
-
globalTree: Record<string, HTMLElement>;
|
|
89
|
-
/**
|
|
90
|
-
* Bind a DOM element to a reference name.
|
|
91
|
-
* @param name - The name to reference the DOM element by.
|
|
92
|
-
*/
|
|
93
|
-
bindAs(name: string): __raw_ref;
|
|
94
|
-
/**
|
|
95
|
-
* Retrieve a referenced DOM element.
|
|
96
|
-
* @param name - The name of the referenced DOM element.
|
|
97
|
-
*/
|
|
98
|
-
current<ElementType extends HTMLElement = HTMLElement>(name: string): ElementType;
|
|
99
|
-
/**
|
|
100
|
-
* Append a DOM element to the reference, overwriting any existing reference.
|
|
101
|
-
* @param name - The name to reference the DOM element by.
|
|
102
|
-
* @param element - The DOM element to reference.
|
|
103
|
-
*/
|
|
104
|
-
_appendDomForce(name: string, Element: HTMLElement): void;
|
|
105
|
-
_appendDomForceGlobal(name: string, Element: HTMLElement): void;
|
|
106
|
-
}
|
|
107
85
|
/**
|
|
108
86
|
* Cradova Signal
|
|
109
87
|
* ----
|
|
@@ -118,7 +96,7 @@ export declare class __raw_ref {
|
|
|
118
96
|
* - update a cradova Comp automatically
|
|
119
97
|
* @constructor initial: unknown, props: {useHistory, persist}
|
|
120
98
|
*/
|
|
121
|
-
export declare class
|
|
99
|
+
export declare class Signal<Type extends Record<string, any>> {
|
|
122
100
|
private callback;
|
|
123
101
|
private persistName;
|
|
124
102
|
private actions;
|
|
@@ -134,7 +112,7 @@ export declare class createSignal<Type extends Record<string, any>> {
|
|
|
134
112
|
* @param value - signal value
|
|
135
113
|
* @returns void
|
|
136
114
|
*/
|
|
137
|
-
set(value: Type | ((value: Type) => Type),
|
|
115
|
+
set(value: Type | ((value: Type) => Type), shouldCompRender?: boolean): void;
|
|
138
116
|
/**
|
|
139
117
|
* Cradova Signal
|
|
140
118
|
* ----
|
|
@@ -143,7 +121,7 @@ export declare class createSignal<Type extends Record<string, any>> {
|
|
|
143
121
|
* @param value - value of the key
|
|
144
122
|
* @returns void
|
|
145
123
|
*/
|
|
146
|
-
setKey<k extends keyof Type>(key: k, value: unknown,
|
|
124
|
+
setKey<k extends keyof Type>(key: k, value: unknown, shouldCompRender?: boolean): void;
|
|
147
125
|
/**
|
|
148
126
|
* Cradova Signal
|
|
149
127
|
* ----
|
|
@@ -167,7 +145,7 @@ export declare class createSignal<Type extends Record<string, any>> {
|
|
|
167
145
|
* @param key - string key of the action
|
|
168
146
|
* @param data - data for the action
|
|
169
147
|
*/
|
|
170
|
-
fireAction(key: string
|
|
148
|
+
fireAction(key: string): void;
|
|
171
149
|
/**
|
|
172
150
|
* Cradova
|
|
173
151
|
* ---
|
|
@@ -185,10 +163,10 @@ export declare class createSignal<Type extends Record<string, any>> {
|
|
|
185
163
|
*
|
|
186
164
|
* @param Comp component to bind to.
|
|
187
165
|
*/
|
|
188
|
-
|
|
166
|
+
bindComp(comp: Comp, binding?: {
|
|
189
167
|
event?: string;
|
|
190
|
-
signalProperty
|
|
191
|
-
_element_property
|
|
168
|
+
signalProperty?: string;
|
|
169
|
+
_element_property?: string;
|
|
192
170
|
}): void;
|
|
193
171
|
/**
|
|
194
172
|
* Cradova Signal
|
|
@@ -225,12 +203,7 @@ export declare class Page {
|
|
|
225
203
|
private _callBack;
|
|
226
204
|
private _deCallBack;
|
|
227
205
|
private _dropped;
|
|
228
|
-
/**
|
|
229
|
-
* error handler for the page
|
|
230
|
-
*/
|
|
231
|
-
_errorHandler: ((err: unknown) => void) | null;
|
|
232
206
|
constructor(cradova_page_initials: CradovaPageType);
|
|
233
|
-
set errorHandler(errorHandler: (err: unknown) => void);
|
|
234
207
|
onActivate(cb: () => Promise<void> | void): void;
|
|
235
208
|
onDeactivate(cb: () => Promise<void> | void): void;
|
|
236
209
|
_deActivate(): Promise<void>;
|
|
@@ -252,7 +225,7 @@ export declare class Router {
|
|
|
252
225
|
*
|
|
253
226
|
* accepts an object containing pat and page
|
|
254
227
|
*/
|
|
255
|
-
static BrowserRoutes(obj: Record<string, Page |
|
|
228
|
+
static BrowserRoutes(obj: Record<string, browserPageType<Page | unknown>>): void;
|
|
256
229
|
/**
|
|
257
230
|
Go back in Navigation history
|
|
258
231
|
*/
|
|
@@ -279,7 +252,7 @@ export declare class Router {
|
|
|
279
252
|
* @param data object
|
|
280
253
|
* @param force boolean
|
|
281
254
|
*/
|
|
282
|
-
static navigate(href: string, data?: Record<string,
|
|
255
|
+
static navigate(href: string, data?: Record<string, any>): void;
|
|
283
256
|
/**
|
|
284
257
|
* Cradova
|
|
285
258
|
* ---
|
|
@@ -305,7 +278,10 @@ export declare class Router {
|
|
|
305
278
|
*
|
|
306
279
|
* .
|
|
307
280
|
*/
|
|
308
|
-
static get
|
|
281
|
+
static get PageData(): {
|
|
282
|
+
params: Record<string, string>;
|
|
283
|
+
data?: Record<string, any> | undefined;
|
|
284
|
+
};
|
|
309
285
|
/**
|
|
310
286
|
* Cradova
|
|
311
287
|
* ---
|
|
@@ -314,7 +290,7 @@ export declare class Router {
|
|
|
314
290
|
* @param callback
|
|
315
291
|
* @param path? page path
|
|
316
292
|
*/
|
|
317
|
-
static addErrorHandler(callback: (err
|
|
293
|
+
static addErrorHandler(callback: (err?: unknown, pagePath?: string) => void): void;
|
|
318
294
|
static _mount(): void;
|
|
319
295
|
}
|
|
320
296
|
export {};
|
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { type VJS_params_TYPE } from "./types";
|
|
2
|
-
import { Comp
|
|
2
|
+
import { Comp } from "./classes";
|
|
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
|
+
current<ElementType extends HTMLElement = HTMLElement>(name: string): ElementType | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Append a DOM element to the reference, overwriting any existing reference.
|
|
22
|
+
* @param name - The name to reference the DOM element by.
|
|
23
|
+
* @param element - The DOM element to reference.
|
|
24
|
+
*/
|
|
25
|
+
_append(name: string, Element: HTMLElement): void;
|
|
26
|
+
}
|
|
3
27
|
export declare const makeElement: <E extends HTMLElement>(element: E & HTMLElement, ElementChildrenAndPropertyList: VJS_params_TYPE<E>) => E;
|
|
4
28
|
export declare const cra: <E extends HTMLElement>(tag: string) => (...Children_and_Properties: VJS_params_TYPE<E>) => E;
|
|
5
29
|
export declare function Rhoda(l: VJS_params_TYPE<HTMLElement>): DocumentFragment;
|
|
@@ -14,11 +38,6 @@ export declare function $case<E = HTMLElement>(value: any, ...elements: VJS_para
|
|
|
14
38
|
export declare function $switch(key: unknown, ...cases: ((key: any) => any)[]): any;
|
|
15
39
|
type LoopData<Type> = Type[];
|
|
16
40
|
export declare function loop<Type>(datalist: LoopData<Type>, component: (value: Type, index?: number, array?: LoopData<Type>) => HTMLElement | DocumentFragment | undefined): HTMLElement[] | undefined;
|
|
17
|
-
/** Calculate a simple numerical representation of the URL */
|
|
18
|
-
export declare const SNRU: {
|
|
19
|
-
snru: string;
|
|
20
|
-
memo_SNRU(): void;
|
|
21
|
-
};
|
|
22
41
|
/**
|
|
23
42
|
* Document fragment
|
|
24
43
|
* @param children
|
|
@@ -33,7 +52,7 @@ export declare const frag: (children: VJS_params_TYPE<HTMLElement>) => DocumentF
|
|
|
33
52
|
* @param Comp
|
|
34
53
|
* @returns [state, setState]
|
|
35
54
|
*/
|
|
36
|
-
export declare function useState<S = unknown>(newState: S, Comp: Comp): [S, (newState: S) => void];
|
|
55
|
+
export declare function useState<S = unknown>(newState: S, Comp: Comp<any>): [S, (newState: S | ((preS: S) => S)) => void];
|
|
37
56
|
/**
|
|
38
57
|
* Cradova
|
|
39
58
|
* ---
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CSS from "csstype";
|
|
2
|
-
import { Comp, Page
|
|
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?:
|
|
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
|
|
70
|
+
export type browserPageType<importType = Page> = importType | Promise<importType> | (() => Promise<importType>);
|
|
71
71
|
export {};
|