cradova 3.3.20 → 3.3.35
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 +239 -300
- package/dist/primitives/classes.d.ts +3 -29
- package/dist/primitives/functions.d.ts +26 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,230 +1,23 @@
|
|
|
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 {
|
|
206
3
|
afterMount = [];
|
|
207
4
|
beforeMountActive = [];
|
|
208
5
|
async addAfterMount(callback) {
|
|
209
|
-
if (!this.addAfterMount) {
|
|
210
|
-
this.afterMount = [];
|
|
211
|
-
}
|
|
212
6
|
this.afterMount.push(callback);
|
|
213
7
|
}
|
|
214
8
|
async addBeforeMountActive(callback) {
|
|
215
|
-
if (!this.beforeMountActive) {
|
|
216
|
-
this.beforeMountActive = [];
|
|
217
|
-
}
|
|
218
9
|
this.beforeMountActive.push(callback);
|
|
219
10
|
}
|
|
220
11
|
dispatchEvent(eventName) {
|
|
221
|
-
const eventListeners = this[eventName]
|
|
222
|
-
|
|
223
|
-
|
|
12
|
+
const eventListeners = this[eventName];
|
|
13
|
+
if (eventName.includes("Active")) {
|
|
14
|
+
for (let i = 0;i < eventListeners.length; i++) {
|
|
224
15
|
eventListeners[i]();
|
|
225
|
-
} else {
|
|
226
|
-
eventListeners.shift()();
|
|
227
16
|
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
while (eventListeners.length !== 0) {
|
|
20
|
+
eventListeners.shift()();
|
|
228
21
|
}
|
|
229
22
|
}
|
|
230
23
|
}
|
|
@@ -237,17 +30,13 @@ class Comp {
|
|
|
237
30
|
rendered = false;
|
|
238
31
|
published = false;
|
|
239
32
|
preRendered = null;
|
|
240
|
-
reference =
|
|
33
|
+
reference = null;
|
|
241
34
|
Signal;
|
|
242
35
|
_state = [];
|
|
243
36
|
_state_index = 0;
|
|
244
37
|
test;
|
|
245
38
|
constructor(component) {
|
|
246
39
|
this.component = component.bind(this);
|
|
247
|
-
CradovaEvent.addBeforeMountActive(() => {
|
|
248
|
-
this._state_index = 0;
|
|
249
|
-
this._state = [];
|
|
250
|
-
});
|
|
251
40
|
}
|
|
252
41
|
preRender() {
|
|
253
42
|
this.preRendered = this.render();
|
|
@@ -256,9 +45,11 @@ class Comp {
|
|
|
256
45
|
this.effects = [];
|
|
257
46
|
this.rendered = false;
|
|
258
47
|
if (!this.preRendered) {
|
|
48
|
+
this._state_index = 0;
|
|
49
|
+
this._state = [];
|
|
259
50
|
const html = this.component();
|
|
260
|
-
if (html instanceof HTMLElement
|
|
261
|
-
this.reference
|
|
51
|
+
if (html instanceof HTMLElement) {
|
|
52
|
+
this.reference = html;
|
|
262
53
|
this.effector.apply(this);
|
|
263
54
|
this.rendered = true;
|
|
264
55
|
this.published = true;
|
|
@@ -302,20 +93,20 @@ class Comp {
|
|
|
302
93
|
}
|
|
303
94
|
}
|
|
304
95
|
async activate() {
|
|
305
|
-
this._state_index = 0;
|
|
306
96
|
this.published = false;
|
|
307
97
|
if (!this.rendered) {
|
|
308
98
|
return;
|
|
309
99
|
}
|
|
100
|
+
this._state_index = 0;
|
|
310
101
|
const html = this.component();
|
|
311
|
-
if (html instanceof HTMLElement
|
|
312
|
-
const node = this.reference
|
|
102
|
+
if (html instanceof HTMLElement) {
|
|
103
|
+
const node = this.reference;
|
|
313
104
|
if (node) {
|
|
314
105
|
node.insertAdjacentElement("beforebegin", html);
|
|
315
106
|
node.remove();
|
|
316
107
|
}
|
|
317
108
|
this.published = true;
|
|
318
|
-
this.reference
|
|
109
|
+
this.reference = html;
|
|
319
110
|
CradovaEvent.dispatchEvent("afterMount");
|
|
320
111
|
(async () => {
|
|
321
112
|
if (!document.contains(html)) {
|
|
@@ -348,32 +139,6 @@ class lazy {
|
|
|
348
139
|
}
|
|
349
140
|
}
|
|
350
141
|
|
|
351
|
-
class __raw_ref {
|
|
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
142
|
class createSignal {
|
|
378
143
|
callback;
|
|
379
144
|
persistName = "";
|
|
@@ -445,10 +210,10 @@ class createSignal {
|
|
|
445
210
|
}
|
|
446
211
|
}
|
|
447
212
|
}
|
|
448
|
-
fireAction(key
|
|
213
|
+
fireAction(key) {
|
|
449
214
|
if (typeof this.actions[key] === "function") {
|
|
450
|
-
this.updateState(key
|
|
451
|
-
return this.actions[key].call(this
|
|
215
|
+
this.updateState(key);
|
|
216
|
+
return this.actions[key].call(this);
|
|
452
217
|
} else {
|
|
453
218
|
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
454
219
|
}
|
|
@@ -460,49 +225,24 @@ class createSignal {
|
|
|
460
225
|
throw new Error("\u2718 Cradova err : can't bind an unavailable property! " + prop);
|
|
461
226
|
}
|
|
462
227
|
}
|
|
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
|
-
}
|
|
228
|
+
updateState(name) {
|
|
229
|
+
for (let i = 0;i < this.comp.length; i++) {
|
|
230
|
+
const ent = this.comp[i];
|
|
231
|
+
if (ent._event && ent._event === name) {
|
|
232
|
+
continue;
|
|
500
233
|
}
|
|
234
|
+
if (ent._element_property && ent._signalProperty) {
|
|
235
|
+
ent.comp[ent._element_property] = this.value[ent._signalProperty];
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
ent.comp.recall();
|
|
501
239
|
}
|
|
502
240
|
}
|
|
503
241
|
bindRef(comp, binding = { signalProperty: "", _element_property: "" }) {
|
|
504
|
-
comp
|
|
505
|
-
|
|
242
|
+
if (comp instanceof Comp) {
|
|
243
|
+
comp.render = comp.render.bind(comp);
|
|
244
|
+
comp._setExtra(this);
|
|
245
|
+
}
|
|
506
246
|
this.comp.push({
|
|
507
247
|
comp,
|
|
508
248
|
_signalProperty: binding.signalProperty,
|
|
@@ -558,7 +298,6 @@ class Page {
|
|
|
558
298
|
history.go(-1);
|
|
559
299
|
return;
|
|
560
300
|
}
|
|
561
|
-
SNRU.memo_SNRU();
|
|
562
301
|
let html = this._html.apply(this);
|
|
563
302
|
if (html instanceof HTMLElement) {
|
|
564
303
|
this._template.innerHTML = "";
|
|
@@ -567,9 +306,9 @@ class Page {
|
|
|
567
306
|
throw new Error(` \u2718 Cradova err: template function for the page returned ${html} instead of html`);
|
|
568
307
|
}
|
|
569
308
|
document.title = this._name;
|
|
570
|
-
|
|
309
|
+
RouterBox.doc.innerHTML = "";
|
|
571
310
|
CradovaEvent.dispatchEvent("beforeMountActive");
|
|
572
|
-
|
|
311
|
+
RouterBox.doc.appendChild(this._template);
|
|
573
312
|
CradovaEvent.dispatchEvent("afterMount");
|
|
574
313
|
window.scrollTo({
|
|
575
314
|
top: 0,
|
|
@@ -581,6 +320,7 @@ class Page {
|
|
|
581
320
|
}
|
|
582
321
|
|
|
583
322
|
class RouterBoxClass {
|
|
323
|
+
doc = null;
|
|
584
324
|
lastNavigatedRouteController;
|
|
585
325
|
nextRouteController;
|
|
586
326
|
lastNavigatedRoute;
|
|
@@ -798,9 +538,9 @@ class Router {
|
|
|
798
538
|
doc = document.createElement("div");
|
|
799
539
|
doc.setAttribute("data-wrapper", "app");
|
|
800
540
|
document.body.appendChild(doc);
|
|
801
|
-
|
|
541
|
+
RouterBox.doc = doc;
|
|
802
542
|
} else {
|
|
803
|
-
|
|
543
|
+
RouterBox.doc = doc;
|
|
804
544
|
}
|
|
805
545
|
window.addEventListener("pageshow", () => RouterBox.router());
|
|
806
546
|
window.addEventListener("popstate", (_e) => {
|
|
@@ -809,6 +549,207 @@ class Router {
|
|
|
809
549
|
});
|
|
810
550
|
}
|
|
811
551
|
}
|
|
552
|
+
// src/primitives/functions.ts
|
|
553
|
+
function Rhoda(l) {
|
|
554
|
+
const fg = new DocumentFragment;
|
|
555
|
+
for (let ch of l) {
|
|
556
|
+
if (Array.isArray(ch)) {
|
|
557
|
+
fg.appendChild(Rhoda(ch));
|
|
558
|
+
} else {
|
|
559
|
+
if (ch instanceof Comp) {
|
|
560
|
+
ch = ch.render();
|
|
561
|
+
}
|
|
562
|
+
if (typeof ch === "function") {
|
|
563
|
+
ch = ch();
|
|
564
|
+
if (typeof ch === "function") {
|
|
565
|
+
ch = ch();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (ch instanceof HTMLElement || ch instanceof DocumentFragment) {
|
|
569
|
+
fg.appendChild(ch);
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (typeof ch === "string") {
|
|
573
|
+
fg.appendChild(document.createTextNode(ch));
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return fg;
|
|
578
|
+
}
|
|
579
|
+
function $if(condition, ...elements) {
|
|
580
|
+
if (condition) {
|
|
581
|
+
return elements;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function $ifelse(condition, ifTrue, ifFalse) {
|
|
585
|
+
if (condition) {
|
|
586
|
+
return ifTrue;
|
|
587
|
+
}
|
|
588
|
+
return ifFalse;
|
|
589
|
+
}
|
|
590
|
+
function $case(value, ...elements) {
|
|
591
|
+
return (key) => {
|
|
592
|
+
if (key === value) {
|
|
593
|
+
return elements;
|
|
594
|
+
}
|
|
595
|
+
return;
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function $switch(key, ...cases) {
|
|
599
|
+
let elements;
|
|
600
|
+
if (cases.length) {
|
|
601
|
+
for (let i = 0;i < cases.length; i++) {
|
|
602
|
+
elements = cases[i](key);
|
|
603
|
+
if (elements) {
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return elements;
|
|
609
|
+
}
|
|
610
|
+
function loop(datalist, component) {
|
|
611
|
+
return Array.isArray(datalist) ? datalist.map(component) : undefined;
|
|
612
|
+
}
|
|
613
|
+
function useState(newState, Comp2) {
|
|
614
|
+
Comp2._state_index += 1;
|
|
615
|
+
const idx = Comp2._state_index;
|
|
616
|
+
if (idx >= Comp2._state.length) {
|
|
617
|
+
Comp2._state[idx] = newState;
|
|
618
|
+
}
|
|
619
|
+
function setState(newState2) {
|
|
620
|
+
if (typeof newState2 === "function") {
|
|
621
|
+
newState2 = newState2(Comp2._state[idx]);
|
|
622
|
+
}
|
|
623
|
+
Comp2._state[idx] = newState2;
|
|
624
|
+
Comp2.recall();
|
|
625
|
+
}
|
|
626
|
+
return [Comp2._state[idx], setState];
|
|
627
|
+
}
|
|
628
|
+
function useEffect(effect, Comp2) {
|
|
629
|
+
Comp2._effect(effect);
|
|
630
|
+
}
|
|
631
|
+
function useRef() {
|
|
632
|
+
return new __raw_ref;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
class __raw_ref {
|
|
636
|
+
tree = {};
|
|
637
|
+
bindAs(name) {
|
|
638
|
+
return [this, name];
|
|
639
|
+
}
|
|
640
|
+
current(name) {
|
|
641
|
+
return this.tree[name];
|
|
642
|
+
}
|
|
643
|
+
_append(name, Element) {
|
|
644
|
+
this.tree[name] = Element;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
648
|
+
const props = {};
|
|
649
|
+
let text = undefined;
|
|
650
|
+
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
651
|
+
for (let i = 0;i < ElementChildrenAndPropertyList.length; i++) {
|
|
652
|
+
let child = ElementChildrenAndPropertyList[i];
|
|
653
|
+
if (typeof child === "function") {
|
|
654
|
+
child = child();
|
|
655
|
+
}
|
|
656
|
+
if (child instanceof Comp) {
|
|
657
|
+
child = child.render();
|
|
658
|
+
}
|
|
659
|
+
if (child instanceof HTMLElement || child instanceof DocumentFragment) {
|
|
660
|
+
element.appendChild(child);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (Array.isArray(child)) {
|
|
664
|
+
element.appendChild(Rhoda(child));
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
if (typeof child === "string") {
|
|
668
|
+
text = child;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
if (typeof child === "object") {
|
|
672
|
+
Object.assign(props, child);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
return element;
|
|
678
|
+
}
|
|
679
|
+
if (typeof props === "object" && element) {
|
|
680
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
681
|
+
if (prop === "style" && typeof value === "object") {
|
|
682
|
+
Object.assign(element.style, value);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
if (prop === "href") {
|
|
686
|
+
const href = value || "";
|
|
687
|
+
if (!href.includes("://")) {
|
|
688
|
+
element.addEventListener("click", (e) => {
|
|
689
|
+
e.preventDefault();
|
|
690
|
+
Router.navigate(element.href);
|
|
691
|
+
if (href.includes("#")) {
|
|
692
|
+
const l = href.split("#").at(-1);
|
|
693
|
+
document.getElementById("#" + l)?.scrollIntoView();
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
element.setAttribute(prop, value);
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
if (Array.isArray(value)) {
|
|
701
|
+
if (prop == "reference" && value[0] instanceof __raw_ref) {
|
|
702
|
+
value[0]._append(value[1], element);
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (value[0] instanceof createSignal) {
|
|
706
|
+
value[0].bindRef(element, {
|
|
707
|
+
_element_property: prop,
|
|
708
|
+
signalProperty: value[1]
|
|
709
|
+
});
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (prop === "onmount") {
|
|
714
|
+
CradovaEvent.addAfterMount(() => {
|
|
715
|
+
typeof props["onmount"] === "function" && props["onmount"].apply(element);
|
|
716
|
+
});
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (prop.includes("data-") || prop.includes("aria-")) {
|
|
720
|
+
element.setAttribute(prop, value);
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
element[prop] = value;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (text !== undefined) {
|
|
727
|
+
element.appendChild(document.createTextNode(text));
|
|
728
|
+
}
|
|
729
|
+
return element;
|
|
730
|
+
};
|
|
731
|
+
var cra = (tag) => {
|
|
732
|
+
return (...Children_and_Properties) => makeElement(document.createElement(tag), Children_and_Properties);
|
|
733
|
+
};
|
|
734
|
+
var frag = function(children) {
|
|
735
|
+
const par = document.createDocumentFragment();
|
|
736
|
+
for (let i = 0;i < children.length; i++) {
|
|
737
|
+
let html = children[i];
|
|
738
|
+
if (typeof html === "function") {
|
|
739
|
+
html = html();
|
|
740
|
+
}
|
|
741
|
+
if (html instanceof HTMLElement || html instanceof DocumentFragment) {
|
|
742
|
+
par.appendChild(html);
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
if (html instanceof String) {
|
|
746
|
+
par.appendChild(document.createTextNode(html));
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
console.error(" \u2718 Cradova err: wrong element type" + html);
|
|
750
|
+
}
|
|
751
|
+
return par;
|
|
752
|
+
};
|
|
812
753
|
// src/primitives/dom-objects.ts
|
|
813
754
|
var a = cra("a");
|
|
814
755
|
var audio = cra("audio");
|
|
@@ -942,8 +883,6 @@ export {
|
|
|
942
883
|
br,
|
|
943
884
|
audio,
|
|
944
885
|
a,
|
|
945
|
-
__raw_ref,
|
|
946
|
-
SNRU,
|
|
947
886
|
Router,
|
|
948
887
|
Rhoda,
|
|
949
888
|
Page,
|
|
@@ -3,8 +3,8 @@ import { type CradovaPageType, type promisedPage } from "./types";
|
|
|
3
3
|
* Cradova event
|
|
4
4
|
*/
|
|
5
5
|
declare class cradovaEvent {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
afterMount: Function[];
|
|
7
|
+
beforeMountActive: Function[];
|
|
8
8
|
/**
|
|
9
9
|
* add an event to an exhaustible list of events
|
|
10
10
|
* the events runs only once and removed.
|
|
@@ -78,32 +78,6 @@ export declare class lazy<Type> {
|
|
|
78
78
|
constructor(cb: () => Promise<unknown>);
|
|
79
79
|
load(): Promise<void>;
|
|
80
80
|
}
|
|
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
81
|
/**
|
|
108
82
|
* Cradova Signal
|
|
109
83
|
* ----
|
|
@@ -167,7 +141,7 @@ export declare class createSignal<Type extends Record<string, any>> {
|
|
|
167
141
|
* @param key - string key of the action
|
|
168
142
|
* @param data - data for the action
|
|
169
143
|
*/
|
|
170
|
-
fireAction(key: string
|
|
144
|
+
fireAction(key: string): void;
|
|
171
145
|
/**
|
|
172
146
|
* Cradova
|
|
173
147
|
* ---
|
|
@@ -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): [S, (newState: S | ((preS: S) => S)) => void];
|
|
37
56
|
/**
|
|
38
57
|
* Cradova
|
|
39
58
|
* ---
|