cradova 2.1.2 → 2.2.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 +9 -4
- package/dist/index.d.ts +247 -342
- package/dist/index.js +703 -751
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,12 +7,114 @@ var Init = function() {
|
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
// lib/utils/track.ts
|
|
11
|
+
function cradovaDispatchTrack(nodes, state) {
|
|
12
|
+
for (let i2 = 0; i2 < nodes.length; i2++) {
|
|
13
|
+
const element = nodes[i2];
|
|
14
|
+
if (!element) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
18
|
+
for (const key in state) {
|
|
19
|
+
if (key === "style") {
|
|
20
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
21
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
22
|
+
element.style[k] = v;
|
|
23
|
+
} else {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (typeof element[key] === "function") {
|
|
32
|
+
if (key.startsWith("on")) {
|
|
33
|
+
element[key] = state[key];
|
|
34
|
+
} else {
|
|
35
|
+
element[key].apply(element);
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (key === "text") {
|
|
40
|
+
element.innerText = state[key];
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (key === "remove") {
|
|
44
|
+
if (element.parentElement) {
|
|
45
|
+
element.parentElement?.removeChild(element);
|
|
46
|
+
} else {
|
|
47
|
+
element.remove();
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (key.includes("$")) {
|
|
52
|
+
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (key === "tree") {
|
|
56
|
+
element.innerHTML = "";
|
|
57
|
+
element.appendChild(frag(state[key]));
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
if (typeof element[key] !== "undefined") {
|
|
62
|
+
element[key] = state[key];
|
|
63
|
+
} else {
|
|
64
|
+
element[key] = state[key];
|
|
65
|
+
if (key !== "for" && key !== "text" && key !== "class" && key !== "tabindex" && key !== "disabled" && !key.includes("aria")) {
|
|
66
|
+
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
71
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function dispatch(stateID, state) {
|
|
80
|
+
let ele;
|
|
81
|
+
if (stateID instanceof HTMLElement) {
|
|
82
|
+
ele = stateID;
|
|
83
|
+
}
|
|
84
|
+
let updated = void 0;
|
|
85
|
+
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
86
|
+
for (const [id, eachState] of Object.entries(stateID)) {
|
|
87
|
+
const elements = document.querySelectorAll(
|
|
88
|
+
"[data-cra-id=" + id + "]"
|
|
89
|
+
);
|
|
90
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
91
|
+
cradovaDispatchTrack(elements, eachState);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (typeof stateID === "string") {
|
|
95
|
+
const elements = document.querySelectorAll(
|
|
96
|
+
"[data-cra-id=" + stateID + "]"
|
|
97
|
+
);
|
|
98
|
+
if (elements.length) {
|
|
99
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
100
|
+
if (!state?.cradovaDispatchTrackBreak) {
|
|
101
|
+
cradovaDispatchTrack(elements, state);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (ele) {
|
|
106
|
+
cradovaDispatchTrack([ele], state);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return updated;
|
|
110
|
+
}
|
|
111
|
+
|
|
10
112
|
// lib/utils/fns.ts
|
|
11
113
|
var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
|
|
12
114
|
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
13
115
|
function uuid() {
|
|
14
116
|
let t = Date.now ? +Date.now() : +new Date();
|
|
15
|
-
return "cradova-id-
|
|
117
|
+
return "cradova-id-xxxxxx".replace(/[x]/g, function(e) {
|
|
16
118
|
const r = (t + 16 * Math.random()) % 16 | 0;
|
|
17
119
|
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
18
120
|
});
|
|
@@ -160,12 +262,10 @@ var Ref = class {
|
|
|
160
262
|
await this.effector.apply(this);
|
|
161
263
|
window.removeEventListener("cradova-aftermount", av);
|
|
162
264
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.effector();
|
|
168
|
-
}
|
|
265
|
+
window.addEventListener("cradova-aftermount", av);
|
|
266
|
+
this.published = true;
|
|
267
|
+
this.rendered = true;
|
|
268
|
+
this.effector();
|
|
169
269
|
if (!element) {
|
|
170
270
|
element = this.preRendered;
|
|
171
271
|
}
|
|
@@ -183,14 +283,13 @@ var Ref = class {
|
|
|
183
283
|
}
|
|
184
284
|
async effector() {
|
|
185
285
|
if (!this.rendered) {
|
|
186
|
-
for (
|
|
187
|
-
await
|
|
286
|
+
for (let i2 = 0; i2 < this.effects.length; i2++) {
|
|
287
|
+
await this.effects[i2].apply(this);
|
|
188
288
|
}
|
|
189
289
|
}
|
|
190
290
|
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
191
291
|
await this.effectuate();
|
|
192
292
|
}
|
|
193
|
-
this.rendered = true;
|
|
194
293
|
this.hasFirstStateUpdateRun = true;
|
|
195
294
|
}
|
|
196
295
|
updateState(data2, stash) {
|
|
@@ -206,9 +305,11 @@ var Ref = class {
|
|
|
206
305
|
}
|
|
207
306
|
this.effectuate = updateState.bind(this, data2);
|
|
208
307
|
} else {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
308
|
+
if (this.published) {
|
|
309
|
+
(async () => {
|
|
310
|
+
await this.Activate(data2);
|
|
311
|
+
})();
|
|
312
|
+
}
|
|
212
313
|
}
|
|
213
314
|
if (stash) {
|
|
214
315
|
this.stash = data2;
|
|
@@ -218,6 +319,7 @@ var Ref = class {
|
|
|
218
319
|
if (!data2) {
|
|
219
320
|
return;
|
|
220
321
|
}
|
|
322
|
+
this.published = false;
|
|
221
323
|
const guy = dispatch(this.stateID, {
|
|
222
324
|
cradovaDispatchTrackBreak: true
|
|
223
325
|
});
|
|
@@ -242,6 +344,7 @@ var Ref = class {
|
|
|
242
344
|
} catch (e0) {
|
|
243
345
|
console.error(e0);
|
|
244
346
|
}
|
|
347
|
+
this.published = true;
|
|
245
348
|
}
|
|
246
349
|
remove() {
|
|
247
350
|
dispatch(this.stateID, { remove: true });
|
|
@@ -253,15 +356,21 @@ var frag = function(children) {
|
|
|
253
356
|
let a2 = children[i2];
|
|
254
357
|
if (typeof a2 === "function") {
|
|
255
358
|
a2 = a2();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
359
|
+
}
|
|
360
|
+
if (typeof a2 === "function") {
|
|
361
|
+
a2 = a2();
|
|
362
|
+
}
|
|
363
|
+
if (isNode(a2)) {
|
|
364
|
+
par.appendChild(a2);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (a2 instanceof String) {
|
|
368
|
+
par.appendChild(document.createTextNode(a2));
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
{
|
|
372
|
+
console.error(" \u2718 Cradova err: wrong element type" + a2);
|
|
373
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
265
374
|
}
|
|
266
375
|
}
|
|
267
376
|
return par;
|
|
@@ -286,123 +395,43 @@ var svgNS = (type, props, ...children) => {
|
|
|
286
395
|
}
|
|
287
396
|
return sc;
|
|
288
397
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
for (const key in state) {
|
|
299
|
-
if (key === "style") {
|
|
300
|
-
for (const [k, v] of Object.entries(state[key])) {
|
|
301
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
302
|
-
element.style[k] = v;
|
|
303
|
-
} else {
|
|
304
|
-
throw new Error(
|
|
305
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
312
|
-
element.style[key] = state[key];
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
if (typeof element[key] === "function") {
|
|
316
|
-
element[key].apply(element);
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
if (key === "text") {
|
|
320
|
-
element.innerText = state[key];
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
324
|
-
const classes = state[key].split(" ");
|
|
325
|
-
for (let i3 = 0; i3 < classes.length; i3++) {
|
|
326
|
-
if (classes[i3]) {
|
|
327
|
-
element.classList.add(classes[i3]);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (key === "remove") {
|
|
333
|
-
if (element.parentElement) {
|
|
334
|
-
element.parentElement?.removeChild(element);
|
|
335
|
-
} else {
|
|
336
|
-
element.remove();
|
|
337
|
-
}
|
|
338
|
-
continue;
|
|
339
|
-
}
|
|
340
|
-
if (key.includes("$")) {
|
|
341
|
-
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
342
|
-
continue;
|
|
343
|
-
}
|
|
344
|
-
if (key === "tree") {
|
|
345
|
-
element.innerHTML = "";
|
|
346
|
-
element.appendChild(frag(state[key]));
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
try {
|
|
350
|
-
if (typeof element[key] !== "undefined") {
|
|
351
|
-
element[key] = state[key];
|
|
352
|
-
} else {
|
|
353
|
-
element[key] = state[key];
|
|
354
|
-
if (key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
355
|
-
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
} catch (error) {
|
|
359
|
-
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
360
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
398
|
+
var lazy = class {
|
|
399
|
+
constructor(cb) {
|
|
400
|
+
this.content = void 0;
|
|
401
|
+
this._cb = cb;
|
|
402
|
+
}
|
|
403
|
+
async load() {
|
|
404
|
+
this.content = await this._cb();
|
|
405
|
+
if (typeof this.content === "function") {
|
|
406
|
+
this.content = await this.content;
|
|
363
407
|
} else {
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function dispatch(stateID, state) {
|
|
369
|
-
let ele;
|
|
370
|
-
if (stateID instanceof HTMLElement) {
|
|
371
|
-
ele = stateID;
|
|
372
|
-
}
|
|
373
|
-
let updated = void 0;
|
|
374
|
-
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
375
|
-
for (const [id, eachState] of Object.entries(stateID)) {
|
|
376
|
-
const elements = document.querySelectorAll(
|
|
377
|
-
"[data-cra-id=" + id + "]"
|
|
378
|
-
);
|
|
379
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
380
|
-
cradovaDispatchTrack(elements, eachState);
|
|
381
|
-
}
|
|
382
|
-
} else {
|
|
383
|
-
if (typeof stateID === "string") {
|
|
384
|
-
const elements = document.querySelectorAll(
|
|
385
|
-
"[data-cra-id=" + stateID + "]"
|
|
386
|
-
);
|
|
387
|
-
if (elements.length) {
|
|
388
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
389
|
-
if (!state?.cradovaDispatchTrackBreak) {
|
|
390
|
-
cradovaDispatchTrack(elements, state);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (ele) {
|
|
395
|
-
cradovaDispatchTrack([ele], state);
|
|
408
|
+
this.content = await this.content;
|
|
396
409
|
}
|
|
410
|
+
this.content = this.content.default;
|
|
397
411
|
}
|
|
398
|
-
|
|
399
|
-
}
|
|
412
|
+
};
|
|
400
413
|
|
|
401
|
-
// lib/utils/
|
|
402
|
-
var
|
|
403
|
-
constructor(initial) {
|
|
414
|
+
// lib/utils/createSignal.ts
|
|
415
|
+
var createSignal = class {
|
|
416
|
+
constructor(initial, props) {
|
|
417
|
+
this.persistName = "";
|
|
418
|
+
this.actions = {};
|
|
404
419
|
this.ref = [];
|
|
405
420
|
this.value = initial;
|
|
421
|
+
if (props && props.persistName) {
|
|
422
|
+
this.persistName = props.persistName;
|
|
423
|
+
const key = localStorage.getItem(props.persistName);
|
|
424
|
+
if (key && key !== "undefined") {
|
|
425
|
+
this.value = JSON.parse(key);
|
|
426
|
+
}
|
|
427
|
+
if (typeof initial === "object") {
|
|
428
|
+
for (const key2 in initial) {
|
|
429
|
+
if (!Object.prototype.hasOwnProperty.call(this.value, key2)) {
|
|
430
|
+
this.value[key2] = initial[key2];
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
406
435
|
}
|
|
407
436
|
set(value, shouldRefRender) {
|
|
408
437
|
if (typeof value === "function") {
|
|
@@ -410,166 +439,24 @@ var simpleStore = class {
|
|
|
410
439
|
} else {
|
|
411
440
|
this.value = value;
|
|
412
441
|
}
|
|
413
|
-
if (this.
|
|
414
|
-
this.
|
|
442
|
+
if (this.persistName) {
|
|
443
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
415
444
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
419
|
-
return [this, prop];
|
|
420
|
-
} else {
|
|
421
|
-
throw new Error(
|
|
422
|
-
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
423
|
-
);
|
|
445
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
446
|
+
this._updateState();
|
|
424
447
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (name) {
|
|
428
|
-
const entry = this.ref.find((ent) => ent.prop === name);
|
|
429
|
-
if (entry) {
|
|
430
|
-
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
431
|
-
}
|
|
432
|
-
} else {
|
|
433
|
-
for (let i2 = 0; i2 < this.ref.length; i2++) {
|
|
434
|
-
const entry = this.ref[i2];
|
|
435
|
-
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
436
|
-
}
|
|
448
|
+
if (this.callback) {
|
|
449
|
+
this.callback(this.value);
|
|
437
450
|
}
|
|
438
451
|
}
|
|
439
|
-
setKey(
|
|
452
|
+
setKey(key, value, shouldRefRender) {
|
|
440
453
|
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
this.value[name] = value;
|
|
454
|
+
this.value[key] = value;
|
|
455
|
+
if (this.persistName) {
|
|
456
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
445
457
|
}
|
|
446
458
|
if (this.ref.length && shouldRefRender !== false) {
|
|
447
|
-
this.
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
_bindRef(ref, key, prop) {
|
|
452
|
-
if (ref && ref.updateState && prop) {
|
|
453
|
-
this.ref.push({ prop, ref, key });
|
|
454
|
-
if (ref.reader) {
|
|
455
|
-
ref.render = ref.render.bind(ref, this.value);
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
throw new Error(
|
|
459
|
-
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
// lib/utils/ajax.ts
|
|
466
|
-
function Ajax(url, opts = {}) {
|
|
467
|
-
const { method, data: data2, header: header2, callbacks } = opts;
|
|
468
|
-
if (typeof url !== "string") {
|
|
469
|
-
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
470
|
-
}
|
|
471
|
-
return new Promise(function(resolve) {
|
|
472
|
-
const ajax = new XMLHttpRequest();
|
|
473
|
-
const formData = new FormData();
|
|
474
|
-
if (callbacks && typeof callbacks === "object") {
|
|
475
|
-
for (const [k, v] of Object.entries(callbacks)) {
|
|
476
|
-
if (typeof v === "function" && ajax[k]) {
|
|
477
|
-
ajax[k] = v;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
ajax.addEventListener("load", function() {
|
|
482
|
-
resolve(ajax.response);
|
|
483
|
-
});
|
|
484
|
-
if (data2 && typeof data2 === "object") {
|
|
485
|
-
for (const [k, v] of Object.entries(data2)) {
|
|
486
|
-
let value = v;
|
|
487
|
-
if (typeof value === "object" && value && !value.name) {
|
|
488
|
-
value = JSON.stringify(value);
|
|
489
|
-
}
|
|
490
|
-
formData.set(k, value);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
ajax.addEventListener("error", () => {
|
|
494
|
-
console.error(
|
|
495
|
-
"\u2718 Cradova Ajax err : ",
|
|
496
|
-
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
497
|
-
);
|
|
498
|
-
if (!navigator.onLine) {
|
|
499
|
-
resolve(
|
|
500
|
-
JSON.stringify({
|
|
501
|
-
message: `the device is offline!`
|
|
502
|
-
})
|
|
503
|
-
);
|
|
504
|
-
} else {
|
|
505
|
-
resolve(
|
|
506
|
-
JSON.stringify({
|
|
507
|
-
message: `problem with the action, please try again!`
|
|
508
|
-
})
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
if (!method) {
|
|
513
|
-
ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
|
|
514
|
-
} else {
|
|
515
|
-
ajax.open(method, url, true);
|
|
516
|
-
}
|
|
517
|
-
if (header2 && typeof header2 === "object") {
|
|
518
|
-
Object.keys(header2).forEach(function(key) {
|
|
519
|
-
ajax.setRequestHeader(key, header2[key]);
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
ajax.send(formData);
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// lib/utils/createSignal.ts
|
|
527
|
-
var createSignal = class {
|
|
528
|
-
constructor(initial, props) {
|
|
529
|
-
this.persistName = "";
|
|
530
|
-
this.actions = {};
|
|
531
|
-
this.path = null;
|
|
532
|
-
this.value = initial;
|
|
533
|
-
if (props && props.persistName) {
|
|
534
|
-
this.persistName = props.persistName;
|
|
535
|
-
const key = localStorage.getItem(props.persistName);
|
|
536
|
-
if (key && key !== "undefined") {
|
|
537
|
-
this.value = JSON.parse(key);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
set(value, shouldRefRender) {
|
|
542
|
-
if (typeof value === "function") {
|
|
543
|
-
this.value = value(this.value);
|
|
544
|
-
} else {
|
|
545
|
-
this.value = value;
|
|
546
|
-
}
|
|
547
|
-
if (this.persistName) {
|
|
548
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
549
|
-
}
|
|
550
|
-
if (this.ref && shouldRefRender !== false) {
|
|
551
|
-
if (this.path) {
|
|
552
|
-
this.ref.updateState(this.value[this.path]);
|
|
553
|
-
} else {
|
|
554
|
-
this.ref.updateState(this.value);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (this.callback) {
|
|
558
|
-
this.callback(this.value);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
setKey(key, value, shouldRefRender) {
|
|
562
|
-
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
563
|
-
this.value[key] = value;
|
|
564
|
-
if (this.persistName) {
|
|
565
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
566
|
-
}
|
|
567
|
-
if (this.ref && shouldRefRender !== false) {
|
|
568
|
-
if (this.path) {
|
|
569
|
-
this.ref.updateState(this.value[this.path]);
|
|
570
|
-
} else {
|
|
571
|
-
this.ref.updateState(this.value);
|
|
572
|
-
}
|
|
459
|
+
this._updateState();
|
|
573
460
|
}
|
|
574
461
|
if (this.callback) {
|
|
575
462
|
this.callback(this.value);
|
|
@@ -583,7 +470,7 @@ var createSignal = class {
|
|
|
583
470
|
}
|
|
584
471
|
}
|
|
585
472
|
createAction(key, action) {
|
|
586
|
-
if (typeof key === "string"
|
|
473
|
+
if (typeof key === "string") {
|
|
587
474
|
this.actions[key] = action;
|
|
588
475
|
} else {
|
|
589
476
|
if (typeof key === "object" && !action) {
|
|
@@ -600,27 +487,88 @@ var createSignal = class {
|
|
|
600
487
|
}
|
|
601
488
|
}
|
|
602
489
|
fireAction(key, data2) {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
490
|
+
if (this.actions[key].updateState) {
|
|
491
|
+
this.actions[key].updateState(this, data2);
|
|
492
|
+
this._updateState(key, data2);
|
|
493
|
+
return;
|
|
494
|
+
} else {
|
|
495
|
+
if (typeof this.actions[key] === "function") {
|
|
496
|
+
this.actions[key](this, data2);
|
|
497
|
+
this._updateState(key, data2);
|
|
498
|
+
return;
|
|
606
499
|
}
|
|
607
|
-
} catch (_e) {
|
|
608
|
-
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
609
500
|
}
|
|
610
|
-
|
|
501
|
+
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
611
502
|
}
|
|
612
|
-
|
|
613
|
-
if (
|
|
614
|
-
this
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
503
|
+
bind(prop) {
|
|
504
|
+
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
505
|
+
return [this, prop];
|
|
506
|
+
} else {
|
|
507
|
+
throw new Error(
|
|
508
|
+
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
_updateState(name, data2) {
|
|
513
|
+
if (name && data2) {
|
|
514
|
+
this.ref.map((ent) => {
|
|
515
|
+
if (ent._event === name) {
|
|
516
|
+
if (ent._element_property && ent._signalProperty) {
|
|
517
|
+
ent.ref.updateState({
|
|
518
|
+
[ent._element_property]: data2[ent._signalProperty]
|
|
519
|
+
});
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (ent._element_property) {
|
|
523
|
+
ent.ref.updateState({
|
|
524
|
+
[ent._element_property]: data2
|
|
525
|
+
});
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (ent._signalProperty) {
|
|
529
|
+
ent.ref.updateState(data2[ent._signalProperty]);
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
});
|
|
621
534
|
} else {
|
|
622
|
-
|
|
535
|
+
for (let i2 = 0; i2 < this.ref.length; i2++) {
|
|
536
|
+
const ent = this.ref[i2];
|
|
537
|
+
if (ent._element_property && ent._signalProperty) {
|
|
538
|
+
ent.ref.updateState({
|
|
539
|
+
[ent._element_property]: this.value[ent._signalProperty]
|
|
540
|
+
});
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (ent._element_property) {
|
|
544
|
+
ent.ref.updateState({
|
|
545
|
+
[ent._element_property]: this.value
|
|
546
|
+
});
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
if (ent._signalProperty) {
|
|
550
|
+
ent.ref.updateState(this.value[ent._signalProperty]);
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
bindRef(ref, binding) {
|
|
557
|
+
if (ref.render) {
|
|
558
|
+
ref.render = ref.render.bind(ref, this.value);
|
|
559
|
+
}
|
|
560
|
+
if (ref && ref.updateState) {
|
|
561
|
+
this.ref.push({
|
|
562
|
+
ref,
|
|
563
|
+
_signalProperty: binding.signalProperty,
|
|
564
|
+
_element_property: binding._element_property,
|
|
565
|
+
_event: binding.event
|
|
566
|
+
});
|
|
567
|
+
return;
|
|
623
568
|
}
|
|
569
|
+
throw new Error(
|
|
570
|
+
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
571
|
+
);
|
|
624
572
|
}
|
|
625
573
|
listen(callback) {
|
|
626
574
|
this.callback = callback;
|
|
@@ -640,63 +588,88 @@ RouterBox["nextRouteController"] = null;
|
|
|
640
588
|
RouterBox["lastNavigatedRoute"] = null;
|
|
641
589
|
RouterBox["pageShow"] = null;
|
|
642
590
|
RouterBox["pageHide"] = null;
|
|
643
|
-
RouterBox["errorHandler"] =
|
|
591
|
+
RouterBox["errorHandler"] = null;
|
|
644
592
|
RouterBox["params"] = {};
|
|
645
593
|
RouterBox["routes"] = {};
|
|
646
594
|
var checker = (url) => {
|
|
647
595
|
if (RouterBox.routes[url]) {
|
|
648
596
|
return [RouterBox.routes[url], { path: url }];
|
|
649
597
|
}
|
|
598
|
+
if (RouterBox.routes[url + "/"]) {
|
|
599
|
+
return [RouterBox.routes[url], { path: url }];
|
|
600
|
+
}
|
|
650
601
|
for (const path in RouterBox.routes) {
|
|
651
602
|
if (!path.includes(":")) {
|
|
652
603
|
continue;
|
|
653
604
|
}
|
|
605
|
+
if (url.endsWith("/")) {
|
|
606
|
+
url = url.slice(0, path.length - 2);
|
|
607
|
+
}
|
|
654
608
|
const urlFixtures = url.split("/");
|
|
655
609
|
const pathFixtures = path.split("/");
|
|
610
|
+
let fixturesX = 0;
|
|
611
|
+
let fixturesY = 0;
|
|
612
|
+
urlFixtures.shift();
|
|
613
|
+
pathFixtures.shift();
|
|
656
614
|
if (pathFixtures.length === urlFixtures.length) {
|
|
657
|
-
|
|
658
|
-
pathFixtures.shift();
|
|
659
|
-
let isIt = true;
|
|
660
|
-
const routesParams = {};
|
|
615
|
+
const routesParams = { _path: "" };
|
|
661
616
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
} else {
|
|
666
|
-
if (pathFixtures[i2].includes(":")) {
|
|
667
|
-
continue;
|
|
668
|
-
}
|
|
669
|
-
isIt = false;
|
|
617
|
+
if (pathFixtures[i2].includes(":")) {
|
|
618
|
+
fixturesY += 1;
|
|
619
|
+
continue;
|
|
670
620
|
}
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
" \u2718 Cradova err: cradova router doesn't allow paths with multiple names"
|
|
674
|
-
);
|
|
621
|
+
if (urlFixtures[i2] === pathFixtures[i2] && pathFixtures.indexOf(urlFixtures[i2]) === pathFixtures.lastIndexOf(urlFixtures[i2])) {
|
|
622
|
+
fixturesX += 1;
|
|
675
623
|
}
|
|
676
624
|
}
|
|
677
|
-
if (
|
|
625
|
+
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
678
626
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
679
627
|
if (pathFixtures[i2].includes(":")) {
|
|
680
628
|
routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
|
|
681
629
|
}
|
|
682
630
|
}
|
|
683
|
-
routesParams.
|
|
631
|
+
routesParams._path = path;
|
|
684
632
|
return [RouterBox.routes[path], routesParams];
|
|
685
633
|
}
|
|
686
634
|
}
|
|
687
635
|
}
|
|
688
636
|
return [];
|
|
689
637
|
};
|
|
690
|
-
|
|
691
|
-
if (!screen
|
|
638
|
+
RouterBox.route = (path, screen) => {
|
|
639
|
+
if (!screen || !screen._Activate) {
|
|
692
640
|
console.error(" \u2718 Cradova err: not a valid screen ", screen);
|
|
693
641
|
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
694
642
|
}
|
|
643
|
+
RouterBox.routes[path] = screen;
|
|
644
|
+
return RouterBox.routes[path];
|
|
645
|
+
};
|
|
646
|
+
Router.BrowserRoutes = function(obj) {
|
|
647
|
+
for (const path in obj) {
|
|
648
|
+
let screen = obj[path];
|
|
649
|
+
if (screen.catch || typeof screen === "function") {
|
|
650
|
+
RouterBox["routes"][path] = async () => {
|
|
651
|
+
if (typeof screen === "function") {
|
|
652
|
+
screen = await screen();
|
|
653
|
+
} else {
|
|
654
|
+
screen = await screen;
|
|
655
|
+
}
|
|
656
|
+
return RouterBox.route(path, screen.default);
|
|
657
|
+
};
|
|
658
|
+
} else {
|
|
659
|
+
RouterBox.route(path, screen);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
Router.mount();
|
|
663
|
+
};
|
|
664
|
+
Router.delegateScreen = function(path = "/", screen) {
|
|
695
665
|
RouterBox.routes[path] = {
|
|
696
|
-
controller: (params, force) => screen.Activate(params, force),
|
|
666
|
+
controller: async (params, force) => await screen.Activate(params, force),
|
|
697
667
|
packager: async (params) => await screen.package(params),
|
|
698
|
-
deactivate: () => {
|
|
699
|
-
screen.deActivate();
|
|
668
|
+
deactivate: async () => {
|
|
669
|
+
await screen.deActivate();
|
|
670
|
+
},
|
|
671
|
+
paramData: (data2) => {
|
|
672
|
+
screen.paramData = data2;
|
|
700
673
|
}
|
|
701
674
|
};
|
|
702
675
|
if (typeof screen.errorHandler === "function") {
|
|
@@ -724,28 +697,31 @@ Router.navigate = function(href, data2 = null, force = false) {
|
|
|
724
697
|
if (route) {
|
|
725
698
|
RouterBox["nextRouteController"] = route;
|
|
726
699
|
RouterBox.params.params = params;
|
|
700
|
+
route._paramData = params;
|
|
727
701
|
RouterBox.params.data = data2 || null;
|
|
728
702
|
link2 = href;
|
|
729
703
|
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
730
704
|
window.history.pushState({}, "", link2);
|
|
731
705
|
}
|
|
732
|
-
(
|
|
733
|
-
await RouterBox.router(null, force);
|
|
734
|
-
})();
|
|
706
|
+
RouterBox.router(null, force);
|
|
735
707
|
}
|
|
736
708
|
};
|
|
737
709
|
RouterBox.router = async function(e, force = false) {
|
|
738
710
|
let url, route, params;
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
if (Alink
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
711
|
+
if (e) {
|
|
712
|
+
const Alink = e.target.tagName === "A" && e.target;
|
|
713
|
+
if (Alink) {
|
|
714
|
+
if (Alink.href.includes("#")) {
|
|
715
|
+
const l = Alink.href.split("#");
|
|
716
|
+
document.getElementById("#" + l[l.length - 1])?.scrollIntoView();
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (Alink.href.includes("javascript")) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
e.preventDefault();
|
|
723
|
+
url = new URL(Alink.href).pathname;
|
|
746
724
|
}
|
|
747
|
-
e.preventDefault();
|
|
748
|
-
url = new URL(Alink.href).pathname;
|
|
749
725
|
}
|
|
750
726
|
if (!url) {
|
|
751
727
|
url = window.location.pathname;
|
|
@@ -759,26 +735,29 @@ RouterBox.router = async function(e, force = false) {
|
|
|
759
735
|
} else {
|
|
760
736
|
[route, params] = checker(url);
|
|
761
737
|
}
|
|
762
|
-
if (route) {
|
|
738
|
+
if (typeof route !== "undefined") {
|
|
763
739
|
try {
|
|
764
740
|
if (params) {
|
|
765
741
|
RouterBox.params.params = params;
|
|
766
742
|
}
|
|
767
|
-
|
|
768
|
-
|
|
743
|
+
if (!route._Activate && typeof route === "function") {
|
|
744
|
+
route = await route();
|
|
745
|
+
}
|
|
746
|
+
if (route._delegatedRoutes !== -1 && route._delegatedRoutes !== 1) {
|
|
747
|
+
route._delegatedRoutes = true;
|
|
748
|
+
route = new Screen({
|
|
749
|
+
name: route._name,
|
|
750
|
+
template: route._html
|
|
751
|
+
});
|
|
752
|
+
RouterBox.routes[url] = route;
|
|
753
|
+
}
|
|
754
|
+
await route._Activate(force);
|
|
755
|
+
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
|
|
769
756
|
RouterBox["lastNavigatedRoute"] = url;
|
|
770
757
|
RouterBox["lastNavigatedRouteController"] = route;
|
|
771
758
|
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
772
|
-
for (const a2 of document.querySelectorAll("a")) {
|
|
773
|
-
if (a2.href.includes(window.location.origin)) {
|
|
774
|
-
a2.addEventListener("click", (e2) => {
|
|
775
|
-
e2.preventDefault();
|
|
776
|
-
Router.navigate(a2.pathname);
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
759
|
} catch (error) {
|
|
781
|
-
const errorHandler = RouterBox.
|
|
760
|
+
const errorHandler = RouterBox.routes[RouterBox.params.params.path].errorHandler || RouterBox.errorHandler;
|
|
782
761
|
if (errorHandler) {
|
|
783
762
|
errorHandler(error);
|
|
784
763
|
}
|
|
@@ -818,265 +797,174 @@ Router.packageScreen = async function(path, data2) {
|
|
|
818
797
|
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
819
798
|
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
820
799
|
}
|
|
821
|
-
|
|
800
|
+
const [route, params] = checker(path);
|
|
801
|
+
if (!route._Activate && typeof route._Activate === "function") {
|
|
802
|
+
route._Activate = await route._Activate();
|
|
803
|
+
}
|
|
804
|
+
route._Activate._package(Object.assign(data2, params || {}));
|
|
805
|
+
route._packed = true;
|
|
822
806
|
};
|
|
823
807
|
Router.getParams = function() {
|
|
824
808
|
return RouterBox["params"];
|
|
825
809
|
};
|
|
826
|
-
Router["addErrorHandler"] = function(callback
|
|
810
|
+
Router["addErrorHandler"] = function(callback) {
|
|
827
811
|
if (typeof callback === "function") {
|
|
828
|
-
RouterBox["errorHandler"]
|
|
812
|
+
RouterBox["errorHandler"] = callback;
|
|
829
813
|
} else {
|
|
830
814
|
throw new Error(
|
|
831
815
|
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
832
816
|
);
|
|
833
817
|
}
|
|
834
818
|
};
|
|
835
|
-
|
|
836
|
-
window.addEventListener("
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
819
|
+
Router.mount = () => {
|
|
820
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
821
|
+
window.addEventListener("popstate", (e) => {
|
|
822
|
+
e.preventDefault();
|
|
823
|
+
RouterBox.router();
|
|
824
|
+
});
|
|
825
|
+
};
|
|
840
826
|
|
|
841
|
-
// lib/utils/
|
|
842
|
-
var
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
827
|
+
// lib/utils/tags.ts
|
|
828
|
+
var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
829
|
+
let beforeMount = null;
|
|
830
|
+
let props = null, text = null;
|
|
831
|
+
if (ElementChildrenAndPropertyList.length) {
|
|
832
|
+
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
833
|
+
let child = ElementChildrenAndPropertyList[i2];
|
|
834
|
+
if (typeof child === "function") {
|
|
835
|
+
child = child();
|
|
836
|
+
if (typeof child === "function") {
|
|
837
|
+
child = child();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (isNode(child)) {
|
|
841
|
+
element.appendChild(child);
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
if (Array.isArray(child)) {
|
|
845
|
+
element.appendChild(Rhoda(child));
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
849
|
+
text = child;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
if (typeof child === "object") {
|
|
853
|
+
if (!props) {
|
|
854
|
+
props = child;
|
|
855
|
+
} else {
|
|
856
|
+
props = Object.assign(props, child);
|
|
857
|
+
}
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (typeof child !== "undefined") {
|
|
861
|
+
console.error(" \u2718 Cradova err: got", { child });
|
|
862
|
+
throw new Error(
|
|
863
|
+
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
864
|
+
);
|
|
865
|
+
}
|
|
860
866
|
}
|
|
867
|
+
} else {
|
|
868
|
+
return element;
|
|
861
869
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
873
|
-
);
|
|
874
|
-
} else {
|
|
875
|
-
if (fuc) {
|
|
876
|
-
this.template.innerHTML = "";
|
|
877
|
-
this.template.appendChild(fuc);
|
|
870
|
+
if (typeof props === "object" && element) {
|
|
871
|
+
for (const prop in props) {
|
|
872
|
+
if (prop === "style" && typeof props[prop] === "object") {
|
|
873
|
+
for (const [k, v] of Object.entries(props[prop])) {
|
|
874
|
+
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
875
|
+
element.style[k] = v;
|
|
876
|
+
} else {
|
|
877
|
+
throw new Error(
|
|
878
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
879
|
+
);
|
|
878
880
|
}
|
|
879
881
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
885
|
+
element.style[prop] = props[prop];
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
889
|
+
text = props[prop];
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
if (prop === "beforeMount") {
|
|
893
|
+
beforeMount = props["beforeMount"];
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
if (prop === "stateID") {
|
|
897
|
+
element.setAttribute("data-cra-id", props[prop]);
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
if (prop.includes("$")) {
|
|
901
|
+
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (Array.isArray(props[prop]) && props[prop][0] instanceof createSignal) {
|
|
905
|
+
element.updateState = dispatch.bind(null, element);
|
|
906
|
+
props[prop][0].bindRef(element, {
|
|
907
|
+
_element_property: prop,
|
|
908
|
+
signalProperty: props[prop][1]
|
|
909
|
+
});
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
913
|
+
element.updateState = dispatch.bind(void 0, element);
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
917
|
+
const av = () => {
|
|
918
|
+
props["afterMount"].apply(element);
|
|
919
|
+
window.removeEventListener("cradova-aftermount", av);
|
|
920
|
+
};
|
|
921
|
+
window.addEventListener("cradova-aftermount", av);
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
try {
|
|
925
|
+
if (typeof element[prop] !== "undefined") {
|
|
926
|
+
element[prop] = props[prop];
|
|
885
927
|
} else {
|
|
886
|
-
|
|
887
|
-
|
|
928
|
+
if (prop.includes("data-")) {
|
|
929
|
+
element.setAttribute(prop, props[prop]);
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
element[prop] = props[prop];
|
|
933
|
+
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && prop !== "disabled" && !prop.includes("aria")) {
|
|
934
|
+
console.warn(" \u2718 Cradova err: invalid html attribute ", {
|
|
935
|
+
prop
|
|
936
|
+
});
|
|
937
|
+
} else {
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
888
940
|
}
|
|
941
|
+
} catch (error) {
|
|
942
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
943
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
889
944
|
}
|
|
890
945
|
}
|
|
891
|
-
if (!this.template.firstChild) {
|
|
892
|
-
throw new Error(
|
|
893
|
-
" \u2718 Cradova err: no screen is rendered, may have been past wrongly."
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
if (this.secondaryChildren.length) {
|
|
897
|
-
for (const child of this.secondaryChildren) {
|
|
898
|
-
this.template.appendChild(child);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
onActivate(cb) {
|
|
903
|
-
this.callBack = cb;
|
|
904
946
|
}
|
|
905
|
-
|
|
906
|
-
|
|
947
|
+
if (text) {
|
|
948
|
+
element.appendChild(document.createTextNode(text));
|
|
907
949
|
}
|
|
908
|
-
|
|
909
|
-
|
|
950
|
+
if (typeof beforeMount === "function") {
|
|
951
|
+
beforeMount.apply(element);
|
|
910
952
|
}
|
|
911
|
-
|
|
912
|
-
if (
|
|
913
|
-
|
|
953
|
+
if (element.tagName === "A") {
|
|
954
|
+
if (element.href.includes(window.location.origin)) {
|
|
955
|
+
element.addEventListener("click", (e) => {
|
|
956
|
+
e.preventDefault();
|
|
957
|
+
Router.navigate(element.pathname);
|
|
958
|
+
});
|
|
914
959
|
}
|
|
915
960
|
}
|
|
916
|
-
|
|
917
|
-
if (!this.persist) {
|
|
918
|
-
await this.package();
|
|
919
|
-
this.packed = true;
|
|
920
|
-
} else {
|
|
921
|
-
if (!this.packed) {
|
|
922
|
-
await this.package();
|
|
923
|
-
this.packed = true;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
if (this.persist && force) {
|
|
927
|
-
await this.package();
|
|
928
|
-
this.packed = true;
|
|
929
|
-
}
|
|
930
|
-
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
931
|
-
if (!doc) {
|
|
932
|
-
throw new Error(
|
|
933
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
doc.innerHTML = "";
|
|
937
|
-
doc.appendChild(this.template);
|
|
938
|
-
document.title = this.name;
|
|
939
|
-
if (!this.persist) {
|
|
940
|
-
this.packed = false;
|
|
941
|
-
}
|
|
942
|
-
if (this.callBack) {
|
|
943
|
-
await this.callBack();
|
|
944
|
-
}
|
|
945
|
-
window.dispatchEvent(cradovaAftermountEvent);
|
|
946
|
-
window.scrollTo(0, 0);
|
|
947
|
-
}
|
|
961
|
+
return element;
|
|
948
962
|
};
|
|
949
|
-
|
|
950
|
-
// lib/utils/tags.ts
|
|
951
963
|
var cra = (element_initials) => {
|
|
952
|
-
return (
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
element = document.createElement(element_initials);
|
|
957
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
958
|
-
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
959
|
-
let child = ElementChildrenAndPropertyList[i2];
|
|
960
|
-
if (typeof child === "function") {
|
|
961
|
-
child = child();
|
|
962
|
-
if (typeof child === "function") {
|
|
963
|
-
child = child();
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
if (isNode(child)) {
|
|
967
|
-
element.appendChild(child);
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
if (Array.isArray(child)) {
|
|
971
|
-
element.appendChild(Rhoda(child));
|
|
972
|
-
continue;
|
|
973
|
-
}
|
|
974
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
975
|
-
text = child;
|
|
976
|
-
continue;
|
|
977
|
-
}
|
|
978
|
-
if (typeof child === "object") {
|
|
979
|
-
if (!props) {
|
|
980
|
-
props = child;
|
|
981
|
-
} else {
|
|
982
|
-
props = Object.assign(props, child);
|
|
983
|
-
}
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
986
|
-
if (typeof child !== "undefined") {
|
|
987
|
-
console.error(" \u2718 Cradova err: got", { child });
|
|
988
|
-
throw new Error(
|
|
989
|
-
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
if (typeof props === "object" && element) {
|
|
995
|
-
for (const prop in props) {
|
|
996
|
-
if (prop === "style" && typeof props[prop] === "object") {
|
|
997
|
-
for (const [k, v] of Object.entries(props[prop])) {
|
|
998
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
999
|
-
element.style[k] = v;
|
|
1000
|
-
} else {
|
|
1001
|
-
throw new Error(
|
|
1002
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
continue;
|
|
1007
|
-
}
|
|
1008
|
-
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1009
|
-
element.style[prop] = props[prop];
|
|
1010
|
-
continue;
|
|
1011
|
-
}
|
|
1012
|
-
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1013
|
-
text = props[prop];
|
|
1014
|
-
continue;
|
|
1015
|
-
}
|
|
1016
|
-
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1017
|
-
element.classList.add(props[prop]);
|
|
1018
|
-
continue;
|
|
1019
|
-
}
|
|
1020
|
-
if (prop === "beforeMount") {
|
|
1021
|
-
beforeMount = props["beforeMount"];
|
|
1022
|
-
continue;
|
|
1023
|
-
}
|
|
1024
|
-
if (prop === "stateID") {
|
|
1025
|
-
element.setAttribute("data-cra-id", props[prop]);
|
|
1026
|
-
continue;
|
|
1027
|
-
}
|
|
1028
|
-
if (prop.includes("$")) {
|
|
1029
|
-
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1030
|
-
continue;
|
|
1031
|
-
}
|
|
1032
|
-
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1033
|
-
element.updateState = dispatch.bind(null, element);
|
|
1034
|
-
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1035
|
-
continue;
|
|
1036
|
-
}
|
|
1037
|
-
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1038
|
-
element.updateState = dispatch.bind(null, element);
|
|
1039
|
-
continue;
|
|
1040
|
-
}
|
|
1041
|
-
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1042
|
-
const av = () => {
|
|
1043
|
-
props["afterMount"].apply(element);
|
|
1044
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
1045
|
-
};
|
|
1046
|
-
window.addEventListener("cradova-aftermount", av);
|
|
1047
|
-
continue;
|
|
1048
|
-
}
|
|
1049
|
-
try {
|
|
1050
|
-
if (typeof element[prop] !== "undefined") {
|
|
1051
|
-
element[prop] = props[prop];
|
|
1052
|
-
} else {
|
|
1053
|
-
if (prop.includes("data-")) {
|
|
1054
|
-
element.setAttribute(prop, props[prop]);
|
|
1055
|
-
continue;
|
|
1056
|
-
}
|
|
1057
|
-
element[prop] = props[prop];
|
|
1058
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1059
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1060
|
-
prop
|
|
1061
|
-
});
|
|
1062
|
-
} else {
|
|
1063
|
-
continue;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
} catch (error) {
|
|
1067
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1068
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
if (text) {
|
|
1073
|
-
element.appendChild(document.createTextNode(text));
|
|
1074
|
-
}
|
|
1075
|
-
if (typeof beforeMount === "function") {
|
|
1076
|
-
beforeMount.apply(element);
|
|
1077
|
-
}
|
|
1078
|
-
return element;
|
|
1079
|
-
};
|
|
964
|
+
return makeElement.bind(
|
|
965
|
+
void 0,
|
|
966
|
+
document.createElement(element_initials)
|
|
967
|
+
);
|
|
1080
968
|
};
|
|
1081
969
|
var a = cra("a");
|
|
1082
970
|
var abbr = cra("abbr");
|
|
@@ -1191,6 +1079,203 @@ var val = cra("val");
|
|
|
1191
1079
|
var video = cra("video");
|
|
1192
1080
|
var wbr = cra("wbr");
|
|
1193
1081
|
|
|
1082
|
+
// lib/utils/ajax.ts
|
|
1083
|
+
function Ajax(url, opts = {}) {
|
|
1084
|
+
const { method, data: data2, header: header2, callbacks } = opts;
|
|
1085
|
+
if (typeof url !== "string") {
|
|
1086
|
+
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
1087
|
+
}
|
|
1088
|
+
return new Promise(function(resolve) {
|
|
1089
|
+
const ajax = new XMLHttpRequest();
|
|
1090
|
+
const formData = new FormData();
|
|
1091
|
+
if (callbacks && typeof callbacks === "object") {
|
|
1092
|
+
for (const [k, v] of Object.entries(callbacks)) {
|
|
1093
|
+
if (typeof v === "function" && ajax[k]) {
|
|
1094
|
+
ajax[k] = v;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
ajax.addEventListener("load", function() {
|
|
1099
|
+
resolve(ajax.response);
|
|
1100
|
+
});
|
|
1101
|
+
if (data2 && typeof data2 === "object") {
|
|
1102
|
+
for (const [k, v] of Object.entries(data2)) {
|
|
1103
|
+
let value = v;
|
|
1104
|
+
if (typeof value === "object" && value && !value.name) {
|
|
1105
|
+
value = JSON.stringify(value);
|
|
1106
|
+
}
|
|
1107
|
+
formData.set(k, value);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
ajax.addEventListener("error", () => {
|
|
1111
|
+
console.error(
|
|
1112
|
+
"\u2718 Cradova Ajax err : ",
|
|
1113
|
+
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
1114
|
+
);
|
|
1115
|
+
if (!navigator.onLine) {
|
|
1116
|
+
resolve(
|
|
1117
|
+
JSON.stringify({
|
|
1118
|
+
message: `this device is offline!`
|
|
1119
|
+
})
|
|
1120
|
+
);
|
|
1121
|
+
} else {
|
|
1122
|
+
resolve(
|
|
1123
|
+
JSON.stringify({
|
|
1124
|
+
message: `problem with the action, please try again!`
|
|
1125
|
+
})
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
if (!method) {
|
|
1130
|
+
ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
|
|
1131
|
+
} else {
|
|
1132
|
+
ajax.open(method, url, true);
|
|
1133
|
+
}
|
|
1134
|
+
if (header2 && typeof header2 === "object") {
|
|
1135
|
+
Object.keys(header2).forEach(function(key) {
|
|
1136
|
+
ajax.setRequestHeader(key, header2[key]);
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
ajax.send(formData);
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
// lib/utils/Screen.ts
|
|
1144
|
+
var Screen = class {
|
|
1145
|
+
constructor(cradova_screen_initials) {
|
|
1146
|
+
this._secondaryChildren = [];
|
|
1147
|
+
this.errorHandler = null;
|
|
1148
|
+
this._packed = false;
|
|
1149
|
+
this._template = document.createElement("div");
|
|
1150
|
+
this._persist = true;
|
|
1151
|
+
this._params = null;
|
|
1152
|
+
this._delegatedRoutesCount = -1;
|
|
1153
|
+
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
1154
|
+
if (typeof template2 !== "function") {
|
|
1155
|
+
console.error(" \u2718 Cradova err: expected a screen but got ", template2);
|
|
1156
|
+
throw new Error(
|
|
1157
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
this._html = template2;
|
|
1161
|
+
this._name = name;
|
|
1162
|
+
this._transition = transition || "";
|
|
1163
|
+
this._template.setAttribute("id", "cradova-screen-set");
|
|
1164
|
+
if (renderInParallel === true) {
|
|
1165
|
+
this._delegatedRoutesCount = 1;
|
|
1166
|
+
} else {
|
|
1167
|
+
if (typeof persist === "boolean") {
|
|
1168
|
+
this._persist = persist;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
get _delegatedRoutes() {
|
|
1173
|
+
if (this._delegatedRoutesCount > 1e3) {
|
|
1174
|
+
return -1;
|
|
1175
|
+
}
|
|
1176
|
+
return this._delegatedRoutesCount;
|
|
1177
|
+
}
|
|
1178
|
+
set _delegatedRoutes(count) {
|
|
1179
|
+
if (count) {
|
|
1180
|
+
this._delegatedRoutesCount += 1;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
get _paramData() {
|
|
1184
|
+
return this._params;
|
|
1185
|
+
}
|
|
1186
|
+
set _paramData(params) {
|
|
1187
|
+
if (params) {
|
|
1188
|
+
this._params = params;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
setErrorHandler(errorHandler) {
|
|
1192
|
+
this.errorHandler = errorHandler;
|
|
1193
|
+
}
|
|
1194
|
+
async _package() {
|
|
1195
|
+
if (typeof this._html === "function") {
|
|
1196
|
+
let fuc = await this._html.apply(this, this._data);
|
|
1197
|
+
if (typeof fuc === "function") {
|
|
1198
|
+
fuc = fuc();
|
|
1199
|
+
if (!isNode(fuc)) {
|
|
1200
|
+
throw new Error(
|
|
1201
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1202
|
+
);
|
|
1203
|
+
} else {
|
|
1204
|
+
if (fuc) {
|
|
1205
|
+
this._template.innerHTML = "";
|
|
1206
|
+
this._template.appendChild(fuc);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
} else {
|
|
1210
|
+
if (!isNode(fuc) && typeof fuc !== "string") {
|
|
1211
|
+
throw new Error(
|
|
1212
|
+
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1213
|
+
);
|
|
1214
|
+
} else {
|
|
1215
|
+
this._template.innerHTML = "";
|
|
1216
|
+
this._template.appendChild(fuc);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
if (!this._template.firstChild) {
|
|
1221
|
+
throw new Error(
|
|
1222
|
+
" \u2718 Cradova err: no screen is rendered, may have been past wrongly."
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
if (this._secondaryChildren.length) {
|
|
1226
|
+
let i2 = 0;
|
|
1227
|
+
while (this._secondaryChildren.length - i2 !== 0) {
|
|
1228
|
+
this.template.appendChild(this._secondaryChildren[i2]);
|
|
1229
|
+
i2++;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
onActivate(cb) {
|
|
1234
|
+
this._callBack = cb;
|
|
1235
|
+
}
|
|
1236
|
+
onDeactivate(cb) {
|
|
1237
|
+
this._deCallBack = cb;
|
|
1238
|
+
}
|
|
1239
|
+
addChild(...addOns) {
|
|
1240
|
+
this._secondaryChildren.push(frag(addOns));
|
|
1241
|
+
}
|
|
1242
|
+
async _deActivate() {
|
|
1243
|
+
if (this._deCallBack) {
|
|
1244
|
+
await this._deCallBack();
|
|
1245
|
+
}
|
|
1246
|
+
if (this._transition) {
|
|
1247
|
+
this._template.classList.remove(this._transition);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
async _Activate(force) {
|
|
1251
|
+
if (!this._persist || force) {
|
|
1252
|
+
await this._package();
|
|
1253
|
+
} else {
|
|
1254
|
+
if (!this._packed) {
|
|
1255
|
+
this._packed = true;
|
|
1256
|
+
await this._package();
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
1260
|
+
if (!doc) {
|
|
1261
|
+
throw new Error(
|
|
1262
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
|
|
1263
|
+
);
|
|
1264
|
+
}
|
|
1265
|
+
if (this._transition) {
|
|
1266
|
+
this._template.classList.add(this._transition);
|
|
1267
|
+
}
|
|
1268
|
+
doc.innerHTML = "";
|
|
1269
|
+
doc.appendChild(this._template);
|
|
1270
|
+
document.title = this._name;
|
|
1271
|
+
if (this._callBack) {
|
|
1272
|
+
await this._callBack();
|
|
1273
|
+
}
|
|
1274
|
+
window.dispatchEvent(cradovaAftermountEvent);
|
|
1275
|
+
window.scrollTo(0, 0);
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1194
1279
|
// lib/index.ts
|
|
1195
1280
|
var make = function(txx) {
|
|
1196
1281
|
if (!txx) {
|
|
@@ -1260,183 +1345,47 @@ var make = function(txx) {
|
|
|
1260
1345
|
const className = classes && classes.join(" ");
|
|
1261
1346
|
return { tag, className, ID, innerValue };
|
|
1262
1347
|
};
|
|
1263
|
-
var
|
|
1264
|
-
if (
|
|
1265
|
-
return frag(element_initials);
|
|
1266
|
-
}
|
|
1267
|
-
if (element_initials.raw) {
|
|
1348
|
+
var _2 = (...element_initials) => {
|
|
1349
|
+
if (element_initials[0].raw) {
|
|
1268
1350
|
element_initials[0] = element_initials["raw"][0];
|
|
1269
1351
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
firstLevelChildren = element_initials.splice(1);
|
|
1273
|
-
}
|
|
1274
|
-
if (typeof element_initials !== "object") {
|
|
1275
|
-
element_initials = [element_initials];
|
|
1352
|
+
if (typeof element_initials[0] !== "string") {
|
|
1353
|
+
return frag(element_initials);
|
|
1276
1354
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
);
|
|
1290
|
-
}
|
|
1291
|
-
if (initials.className) {
|
|
1292
|
-
if (props) {
|
|
1293
|
-
props["className"] = initials.className.trim();
|
|
1294
|
-
} else {
|
|
1295
|
-
props = { className: initials.className.trim() };
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
if (initials.ID) {
|
|
1299
|
-
if (props) {
|
|
1300
|
-
props["id"] = initials.ID.trim();
|
|
1301
|
-
} else {
|
|
1302
|
-
props = { id: initials.ID.trim() };
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
if (initials.innerValue) {
|
|
1306
|
-
if (props) {
|
|
1307
|
-
props["innerText"] = initials.innerValue;
|
|
1308
|
-
} else {
|
|
1309
|
-
props = { innerText: initials.innerValue };
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
1313
|
-
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
1314
|
-
let child = ElementChildrenAndPropertyList[i2];
|
|
1315
|
-
if (typeof child === "function") {
|
|
1316
|
-
child = child();
|
|
1317
|
-
}
|
|
1318
|
-
if (typeof child === "function") {
|
|
1319
|
-
child = child();
|
|
1320
|
-
}
|
|
1321
|
-
if (isNode(child)) {
|
|
1322
|
-
element.appendChild(child);
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
if (Array.isArray(child)) {
|
|
1326
|
-
element.appendChild(Rhoda(child));
|
|
1327
|
-
continue;
|
|
1328
|
-
}
|
|
1329
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
1330
|
-
text = child;
|
|
1331
|
-
continue;
|
|
1332
|
-
}
|
|
1333
|
-
if (typeof child === "object") {
|
|
1334
|
-
if (!props) {
|
|
1335
|
-
props = child;
|
|
1336
|
-
} else {
|
|
1337
|
-
props = Object.assign(props, child);
|
|
1338
|
-
}
|
|
1339
|
-
continue;
|
|
1340
|
-
}
|
|
1341
|
-
if (typeof child !== "undefined") {
|
|
1342
|
-
console.error(" \u2718 Cradova err: got", { child });
|
|
1343
|
-
throw new Error(
|
|
1344
|
-
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
1345
|
-
);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
if (typeof props === "object" && element) {
|
|
1350
|
-
for (const prop in props) {
|
|
1351
|
-
if (prop === "style" && typeof props[prop] === "object") {
|
|
1352
|
-
for (const [k, v] of Object.entries(props[prop])) {
|
|
1353
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
1354
|
-
element.style[k] = v;
|
|
1355
|
-
} else {
|
|
1356
|
-
throw new Error(
|
|
1357
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
continue;
|
|
1362
|
-
}
|
|
1363
|
-
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1364
|
-
element.style[prop] = props[prop];
|
|
1365
|
-
continue;
|
|
1366
|
-
}
|
|
1367
|
-
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1368
|
-
text = props[prop];
|
|
1369
|
-
continue;
|
|
1370
|
-
}
|
|
1371
|
-
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1372
|
-
element.classList.add(props[prop]);
|
|
1373
|
-
continue;
|
|
1374
|
-
}
|
|
1375
|
-
if (prop === "beforeMount") {
|
|
1376
|
-
beforeMount = props["beforeMount"];
|
|
1377
|
-
continue;
|
|
1378
|
-
}
|
|
1379
|
-
if (prop === "stateID") {
|
|
1380
|
-
element.setAttribute("data-cra-id", props[prop]);
|
|
1381
|
-
continue;
|
|
1382
|
-
}
|
|
1383
|
-
if (prop.includes("$")) {
|
|
1384
|
-
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1385
|
-
continue;
|
|
1386
|
-
}
|
|
1387
|
-
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1388
|
-
element.updateState = dispatch.bind(null, element);
|
|
1389
|
-
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1390
|
-
continue;
|
|
1391
|
-
}
|
|
1392
|
-
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1393
|
-
element.updateState = dispatch.bind(null, element);
|
|
1394
|
-
continue;
|
|
1395
|
-
}
|
|
1396
|
-
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1397
|
-
const av = () => {
|
|
1398
|
-
props["afterMount"].apply(element);
|
|
1399
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
1400
|
-
};
|
|
1401
|
-
window.addEventListener("cradova-aftermount", av);
|
|
1402
|
-
continue;
|
|
1403
|
-
}
|
|
1404
|
-
try {
|
|
1405
|
-
if (typeof element[prop] !== "undefined") {
|
|
1406
|
-
element[prop] = props[prop];
|
|
1407
|
-
} else {
|
|
1408
|
-
if (prop.includes("data-")) {
|
|
1409
|
-
element.setAttribute(prop, props[prop]);
|
|
1410
|
-
continue;
|
|
1411
|
-
}
|
|
1412
|
-
element[prop] = props[prop];
|
|
1413
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1414
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1415
|
-
prop
|
|
1416
|
-
});
|
|
1417
|
-
} else {
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
} catch (error) {
|
|
1422
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1423
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1355
|
+
const initials = make(element_initials.shift());
|
|
1356
|
+
let props = void 0;
|
|
1357
|
+
let element;
|
|
1358
|
+
try {
|
|
1359
|
+
element = document.createElement(initials.tag.trim());
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
throw new TypeError(" \u2718 Cradova err: invalid tag given " + initials.tag);
|
|
1362
|
+
}
|
|
1363
|
+
if (initials.className) {
|
|
1364
|
+
if (props) {
|
|
1365
|
+
props["className"] = initials.className.trim();
|
|
1366
|
+
} else {
|
|
1367
|
+
props = { className: initials.className.trim() };
|
|
1426
1368
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1369
|
+
}
|
|
1370
|
+
if (initials.ID) {
|
|
1371
|
+
if (props) {
|
|
1372
|
+
props["id"] = initials.ID.trim();
|
|
1373
|
+
} else {
|
|
1374
|
+
props = { id: initials.ID.trim() };
|
|
1429
1375
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1376
|
+
}
|
|
1377
|
+
if (initials.innerValue) {
|
|
1378
|
+
if (props) {
|
|
1379
|
+
props["innerText"] = initials.innerValue;
|
|
1380
|
+
} else {
|
|
1381
|
+
props = { innerText: initials.innerValue };
|
|
1432
1382
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1383
|
+
}
|
|
1384
|
+
return makeElement(element, props, ...element_initials);
|
|
1435
1385
|
};
|
|
1436
1386
|
Init();
|
|
1437
|
-
var lib_default =
|
|
1387
|
+
var lib_default = _2;
|
|
1438
1388
|
export {
|
|
1439
|
-
simpleStore as $,
|
|
1440
1389
|
Ajax,
|
|
1441
1390
|
Ref,
|
|
1442
1391
|
Router,
|
|
@@ -1503,11 +1452,13 @@ export {
|
|
|
1503
1452
|
ins,
|
|
1504
1453
|
kbd,
|
|
1505
1454
|
label,
|
|
1455
|
+
lazy,
|
|
1506
1456
|
legend,
|
|
1507
1457
|
li,
|
|
1508
1458
|
link,
|
|
1509
1459
|
loop,
|
|
1510
1460
|
main,
|
|
1461
|
+
makeElement,
|
|
1511
1462
|
map,
|
|
1512
1463
|
mark,
|
|
1513
1464
|
math,
|
|
@@ -1563,3 +1514,4 @@ export {
|
|
|
1563
1514
|
video,
|
|
1564
1515
|
wbr
|
|
1565
1516
|
};
|
|
1517
|
+
//! value could be a promise
|