cradova 2.1.1 → 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 +246 -345
- package/dist/index.js +738 -827
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,16 +7,147 @@ 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
|
});
|
|
19
121
|
}
|
|
122
|
+
function Rhoda(l) {
|
|
123
|
+
const fg = new DocumentFragment();
|
|
124
|
+
for (let ch of l) {
|
|
125
|
+
if (Array.isArray(ch)) {
|
|
126
|
+
fg.appendChild(Rhoda(ch));
|
|
127
|
+
} else {
|
|
128
|
+
if (typeof ch === "function") {
|
|
129
|
+
ch = ch();
|
|
130
|
+
}
|
|
131
|
+
if (typeof ch === "function") {
|
|
132
|
+
ch = ch();
|
|
133
|
+
}
|
|
134
|
+
if (typeof ch === "string" || typeof ch === "number") {
|
|
135
|
+
fg.appendChild(document.createTextNode(ch));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (isNode(ch)) {
|
|
139
|
+
fg.appendChild(ch);
|
|
140
|
+
} else {
|
|
141
|
+
if (typeof ch !== "undefined") {
|
|
142
|
+
throw new Error(
|
|
143
|
+
" \u2718 Cradova err: invalid child type: " + ch + " (" + typeof ch + ")"
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return fg;
|
|
150
|
+
}
|
|
20
151
|
function css(identifier, properties) {
|
|
21
152
|
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
22
153
|
let styTag = document.querySelector("style");
|
|
@@ -57,14 +188,19 @@ function css(identifier, properties) {
|
|
|
57
188
|
styleTag.innerHTML = totalStyle;
|
|
58
189
|
document.head.appendChild(styleTag);
|
|
59
190
|
}
|
|
60
|
-
function assert(condition, ...
|
|
191
|
+
function assert(condition, ...elements) {
|
|
61
192
|
if (condition) {
|
|
62
|
-
return
|
|
193
|
+
return elements;
|
|
63
194
|
}
|
|
64
|
-
return
|
|
195
|
+
return void 0;
|
|
65
196
|
}
|
|
66
197
|
function loop(datalist2, component) {
|
|
67
|
-
|
|
198
|
+
if (typeof component !== "function") {
|
|
199
|
+
throw new Error(
|
|
200
|
+
" \u2718 Cradova err : Invalid component type, must be a function that returns html "
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return Array.isArray(datalist2) ? datalist2.map(component) : void 0;
|
|
68
204
|
}
|
|
69
205
|
function assertOr(condition, ifTrue, ifFalse) {
|
|
70
206
|
if (condition) {
|
|
@@ -126,12 +262,10 @@ var Ref = class {
|
|
|
126
262
|
await this.effector.apply(this);
|
|
127
263
|
window.removeEventListener("cradova-aftermount", av);
|
|
128
264
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.effector();
|
|
134
|
-
}
|
|
265
|
+
window.addEventListener("cradova-aftermount", av);
|
|
266
|
+
this.published = true;
|
|
267
|
+
this.rendered = true;
|
|
268
|
+
this.effector();
|
|
135
269
|
if (!element) {
|
|
136
270
|
element = this.preRendered;
|
|
137
271
|
}
|
|
@@ -149,14 +283,13 @@ var Ref = class {
|
|
|
149
283
|
}
|
|
150
284
|
async effector() {
|
|
151
285
|
if (!this.rendered) {
|
|
152
|
-
for (
|
|
153
|
-
await
|
|
286
|
+
for (let i2 = 0; i2 < this.effects.length; i2++) {
|
|
287
|
+
await this.effects[i2].apply(this);
|
|
154
288
|
}
|
|
155
289
|
}
|
|
156
290
|
if (!this.hasFirstStateUpdateRun && this.effectuate) {
|
|
157
291
|
await this.effectuate();
|
|
158
292
|
}
|
|
159
|
-
this.rendered = true;
|
|
160
293
|
this.hasFirstStateUpdateRun = true;
|
|
161
294
|
}
|
|
162
295
|
updateState(data2, stash) {
|
|
@@ -172,9 +305,11 @@ var Ref = class {
|
|
|
172
305
|
}
|
|
173
306
|
this.effectuate = updateState.bind(this, data2);
|
|
174
307
|
} else {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
308
|
+
if (this.published) {
|
|
309
|
+
(async () => {
|
|
310
|
+
await this.Activate(data2);
|
|
311
|
+
})();
|
|
312
|
+
}
|
|
178
313
|
}
|
|
179
314
|
if (stash) {
|
|
180
315
|
this.stash = data2;
|
|
@@ -184,6 +319,7 @@ var Ref = class {
|
|
|
184
319
|
if (!data2) {
|
|
185
320
|
return;
|
|
186
321
|
}
|
|
322
|
+
this.published = false;
|
|
187
323
|
const guy = dispatch(this.stateID, {
|
|
188
324
|
cradovaDispatchTrackBreak: true
|
|
189
325
|
});
|
|
@@ -208,6 +344,7 @@ var Ref = class {
|
|
|
208
344
|
} catch (e0) {
|
|
209
345
|
console.error(e0);
|
|
210
346
|
}
|
|
347
|
+
this.published = true;
|
|
211
348
|
}
|
|
212
349
|
remove() {
|
|
213
350
|
dispatch(this.stateID, { remove: true });
|
|
@@ -219,15 +356,21 @@ var frag = function(children) {
|
|
|
219
356
|
let a2 = children[i2];
|
|
220
357
|
if (typeof a2 === "function") {
|
|
221
358
|
a2 = a2();
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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");
|
|
231
374
|
}
|
|
232
375
|
}
|
|
233
376
|
return par;
|
|
@@ -252,123 +395,43 @@ var svgNS = (type, props, ...children) => {
|
|
|
252
395
|
}
|
|
253
396
|
return sc;
|
|
254
397
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
for (const key in state) {
|
|
265
|
-
if (key === "style") {
|
|
266
|
-
for (const [k, v] of Object.entries(state[key])) {
|
|
267
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
268
|
-
element.style[k] = v;
|
|
269
|
-
} else {
|
|
270
|
-
throw new Error(
|
|
271
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
if (typeof element.style[key] !== "undefined" && key !== "src") {
|
|
278
|
-
element.style[key] = state[key];
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (typeof element[key] === "function") {
|
|
282
|
-
element[key].apply(element);
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (key === "text") {
|
|
286
|
-
element.innerText = state[key];
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
290
|
-
const classes = state[key].split(" ");
|
|
291
|
-
for (let i3 = 0; i3 < classes.length; i3++) {
|
|
292
|
-
if (classes[i3]) {
|
|
293
|
-
element.classList.add(classes[i3]);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
if (key === "remove") {
|
|
299
|
-
if (element.parentElement) {
|
|
300
|
-
element.parentElement?.removeChild(element);
|
|
301
|
-
} else {
|
|
302
|
-
element.remove();
|
|
303
|
-
}
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (key.includes("$")) {
|
|
307
|
-
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
if (key === "tree") {
|
|
311
|
-
element.innerHTML = "";
|
|
312
|
-
element.appendChild(frag(state[key]));
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
if (typeof element[key] !== "undefined") {
|
|
317
|
-
element[key] = state[key];
|
|
318
|
-
} else {
|
|
319
|
-
element[key] = state[key];
|
|
320
|
-
if (key !== "for" && key !== "text" && key !== "class" && !key.includes("aria")) {
|
|
321
|
-
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
} catch (error) {
|
|
325
|
-
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
326
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
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;
|
|
329
407
|
} else {
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function dispatch(stateID, state) {
|
|
335
|
-
let ele;
|
|
336
|
-
if (stateID instanceof HTMLElement) {
|
|
337
|
-
ele = stateID;
|
|
338
|
-
}
|
|
339
|
-
let updated = void 0;
|
|
340
|
-
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
341
|
-
for (const [id, eachState] of Object.entries(stateID)) {
|
|
342
|
-
const elements = document.querySelectorAll(
|
|
343
|
-
"[data-cra-id=" + id + "]"
|
|
344
|
-
);
|
|
345
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
346
|
-
cradovaDispatchTrack(elements, eachState);
|
|
347
|
-
}
|
|
348
|
-
} else {
|
|
349
|
-
if (typeof stateID === "string") {
|
|
350
|
-
const elements = document.querySelectorAll(
|
|
351
|
-
"[data-cra-id=" + stateID + "]"
|
|
352
|
-
);
|
|
353
|
-
if (elements.length) {
|
|
354
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
355
|
-
if (!state?.cradovaDispatchTrackBreak) {
|
|
356
|
-
cradovaDispatchTrack(elements, state);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (ele) {
|
|
361
|
-
cradovaDispatchTrack([ele], state);
|
|
408
|
+
this.content = await this.content;
|
|
362
409
|
}
|
|
410
|
+
this.content = this.content.default;
|
|
363
411
|
}
|
|
364
|
-
|
|
365
|
-
}
|
|
412
|
+
};
|
|
366
413
|
|
|
367
|
-
// lib/utils/
|
|
368
|
-
var
|
|
369
|
-
constructor(initial) {
|
|
414
|
+
// lib/utils/createSignal.ts
|
|
415
|
+
var createSignal = class {
|
|
416
|
+
constructor(initial, props) {
|
|
417
|
+
this.persistName = "";
|
|
418
|
+
this.actions = {};
|
|
370
419
|
this.ref = [];
|
|
371
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
|
+
}
|
|
372
435
|
}
|
|
373
436
|
set(value, shouldRefRender) {
|
|
374
437
|
if (typeof value === "function") {
|
|
@@ -376,152 +439,14 @@ var simpleStore = class {
|
|
|
376
439
|
} else {
|
|
377
440
|
this.value = value;
|
|
378
441
|
}
|
|
442
|
+
if (this.persistName) {
|
|
443
|
+
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
444
|
+
}
|
|
379
445
|
if (this.ref.length && shouldRefRender !== false) {
|
|
380
|
-
this.
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
385
|
-
return [this, prop];
|
|
386
|
-
} else {
|
|
387
|
-
throw new Error(
|
|
388
|
-
"\u2718 Cradova err : can't bind an unavailable property! " + prop
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
updateState(name) {
|
|
393
|
-
if (name) {
|
|
394
|
-
const entry = this.ref.find((ent) => ent.prop === name);
|
|
395
|
-
if (entry) {
|
|
396
|
-
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
for (let i2 = 0; i2 < this.ref.length; i2++) {
|
|
400
|
-
const entry = this.ref[i2];
|
|
401
|
-
entry.ref.updateState({ [entry.key]: this.value[entry.prop] });
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
setKey(name, value, shouldRefRender) {
|
|
406
|
-
if (typeof this.value === "object" && !Array.isArray(this.value)) {
|
|
407
|
-
if (typeof value === "function") {
|
|
408
|
-
this.value[name] = value(this.value);
|
|
409
|
-
} else {
|
|
410
|
-
this.value[name] = value;
|
|
411
|
-
}
|
|
412
|
-
if (this.ref.length && shouldRefRender !== false) {
|
|
413
|
-
this.updateState(name);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
_bindRef(ref, key, prop) {
|
|
418
|
-
if (ref && ref.updateState && prop) {
|
|
419
|
-
this.ref.push({ prop, ref, key });
|
|
420
|
-
if (ref.reader) {
|
|
421
|
-
ref.render = ref.render.bind(ref, this.value);
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
throw new Error(
|
|
425
|
-
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
// lib/utils/ajax.ts
|
|
432
|
-
function Ajax(url, opts = {}) {
|
|
433
|
-
const { method, data: data2, header: header2, callbacks } = opts;
|
|
434
|
-
if (typeof url !== "string") {
|
|
435
|
-
throw new Error("\u2718 Cradova err : Ajax invalid url " + url);
|
|
436
|
-
}
|
|
437
|
-
return new Promise(function(resolve) {
|
|
438
|
-
const ajax = new XMLHttpRequest();
|
|
439
|
-
const formData = new FormData();
|
|
440
|
-
if (callbacks && typeof callbacks === "object") {
|
|
441
|
-
for (const [k, v] of Object.entries(callbacks)) {
|
|
442
|
-
if (typeof v === "function" && ajax[k]) {
|
|
443
|
-
ajax[k] = v;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
ajax.addEventListener("load", function() {
|
|
448
|
-
resolve(ajax.response);
|
|
449
|
-
});
|
|
450
|
-
if (data2 && typeof data2 === "object") {
|
|
451
|
-
for (const [k, v] of Object.entries(data2)) {
|
|
452
|
-
let value = v;
|
|
453
|
-
if (typeof value === "object" && value && !value.name) {
|
|
454
|
-
value = JSON.stringify(value);
|
|
455
|
-
}
|
|
456
|
-
formData.set(k, value);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
ajax.addEventListener("error", () => {
|
|
460
|
-
console.error(
|
|
461
|
-
"\u2718 Cradova Ajax err : ",
|
|
462
|
-
ajax.response || "ERR_INTERNET_DISCONNECTED"
|
|
463
|
-
);
|
|
464
|
-
if (!navigator.onLine) {
|
|
465
|
-
resolve(
|
|
466
|
-
JSON.stringify({
|
|
467
|
-
message: `the device is offline!`
|
|
468
|
-
})
|
|
469
|
-
);
|
|
470
|
-
} else {
|
|
471
|
-
resolve(
|
|
472
|
-
JSON.stringify({
|
|
473
|
-
message: `problem with the action, please try again!`
|
|
474
|
-
})
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
if (!method) {
|
|
479
|
-
ajax.open(data2 && typeof data2 === "object" ? "POST" : "GET", url, true);
|
|
480
|
-
} else {
|
|
481
|
-
ajax.open(method, url, true);
|
|
482
|
-
}
|
|
483
|
-
if (header2 && typeof header2 === "object") {
|
|
484
|
-
Object.keys(header2).forEach(function(key) {
|
|
485
|
-
ajax.setRequestHeader(key, header2[key]);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
ajax.send(formData);
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// lib/utils/createSignal.ts
|
|
493
|
-
var createSignal = class {
|
|
494
|
-
constructor(initial, props) {
|
|
495
|
-
this.persistName = "";
|
|
496
|
-
this.actions = {};
|
|
497
|
-
this.path = null;
|
|
498
|
-
this.value = initial;
|
|
499
|
-
if (props && props.persistName) {
|
|
500
|
-
this.persistName = props.persistName;
|
|
501
|
-
const key = localStorage.getItem(props.persistName);
|
|
502
|
-
if (key && key !== "undefined") {
|
|
503
|
-
this.value = JSON.parse(key);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
set(value, shouldRefRender) {
|
|
508
|
-
if (typeof value === "function") {
|
|
509
|
-
this.value = value(this.value);
|
|
510
|
-
} else {
|
|
511
|
-
this.value = value;
|
|
512
|
-
}
|
|
513
|
-
if (this.persistName) {
|
|
514
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
515
|
-
}
|
|
516
|
-
if (this.ref && shouldRefRender !== false) {
|
|
517
|
-
if (this.path) {
|
|
518
|
-
this.ref.updateState(this.value[this.path]);
|
|
519
|
-
} else {
|
|
520
|
-
this.ref.updateState(this.value);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
if (this.callback) {
|
|
524
|
-
this.callback(this.value);
|
|
446
|
+
this._updateState();
|
|
447
|
+
}
|
|
448
|
+
if (this.callback) {
|
|
449
|
+
this.callback(this.value);
|
|
525
450
|
}
|
|
526
451
|
}
|
|
527
452
|
setKey(key, value, shouldRefRender) {
|
|
@@ -530,12 +455,8 @@ var createSignal = class {
|
|
|
530
455
|
if (this.persistName) {
|
|
531
456
|
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
532
457
|
}
|
|
533
|
-
if (this.ref && shouldRefRender !== false) {
|
|
534
|
-
|
|
535
|
-
this.ref.updateState(this.value[this.path]);
|
|
536
|
-
} else {
|
|
537
|
-
this.ref.updateState(this.value);
|
|
538
|
-
}
|
|
458
|
+
if (this.ref.length && shouldRefRender !== false) {
|
|
459
|
+
this._updateState();
|
|
539
460
|
}
|
|
540
461
|
if (this.callback) {
|
|
541
462
|
this.callback(this.value);
|
|
@@ -549,7 +470,7 @@ var createSignal = class {
|
|
|
549
470
|
}
|
|
550
471
|
}
|
|
551
472
|
createAction(key, action) {
|
|
552
|
-
if (typeof key === "string"
|
|
473
|
+
if (typeof key === "string") {
|
|
553
474
|
this.actions[key] = action;
|
|
554
475
|
} else {
|
|
555
476
|
if (typeof key === "object" && !action) {
|
|
@@ -566,27 +487,88 @@ var createSignal = class {
|
|
|
566
487
|
}
|
|
567
488
|
}
|
|
568
489
|
fireAction(key, data2) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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;
|
|
572
499
|
}
|
|
573
|
-
} catch (_e) {
|
|
574
|
-
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
575
500
|
}
|
|
576
|
-
|
|
501
|
+
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
577
502
|
}
|
|
578
|
-
|
|
579
|
-
if (
|
|
580
|
-
this
|
|
581
|
-
if (typeof path === "string") {
|
|
582
|
-
this.path = path;
|
|
583
|
-
Ref2.render = Ref2.render.bind(Ref2, this.value[path]);
|
|
584
|
-
} else {
|
|
585
|
-
Ref2.render = Ref2.render.bind(Ref2, this.value);
|
|
586
|
-
}
|
|
503
|
+
bind(prop) {
|
|
504
|
+
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
505
|
+
return [this, prop];
|
|
587
506
|
} else {
|
|
588
|
-
throw new Error(
|
|
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
|
+
});
|
|
534
|
+
} else {
|
|
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;
|
|
589
568
|
}
|
|
569
|
+
throw new Error(
|
|
570
|
+
"\u2718 Cradova err : Invalid parameters for binding ref to simple store"
|
|
571
|
+
);
|
|
590
572
|
}
|
|
591
573
|
listen(callback) {
|
|
592
574
|
this.callback = callback;
|
|
@@ -606,63 +588,88 @@ RouterBox["nextRouteController"] = null;
|
|
|
606
588
|
RouterBox["lastNavigatedRoute"] = null;
|
|
607
589
|
RouterBox["pageShow"] = null;
|
|
608
590
|
RouterBox["pageHide"] = null;
|
|
609
|
-
RouterBox["errorHandler"] =
|
|
591
|
+
RouterBox["errorHandler"] = null;
|
|
610
592
|
RouterBox["params"] = {};
|
|
611
593
|
RouterBox["routes"] = {};
|
|
612
594
|
var checker = (url) => {
|
|
613
595
|
if (RouterBox.routes[url]) {
|
|
614
596
|
return [RouterBox.routes[url], { path: url }];
|
|
615
597
|
}
|
|
598
|
+
if (RouterBox.routes[url + "/"]) {
|
|
599
|
+
return [RouterBox.routes[url], { path: url }];
|
|
600
|
+
}
|
|
616
601
|
for (const path in RouterBox.routes) {
|
|
617
602
|
if (!path.includes(":")) {
|
|
618
603
|
continue;
|
|
619
604
|
}
|
|
605
|
+
if (url.endsWith("/")) {
|
|
606
|
+
url = url.slice(0, path.length - 2);
|
|
607
|
+
}
|
|
620
608
|
const urlFixtures = url.split("/");
|
|
621
609
|
const pathFixtures = path.split("/");
|
|
610
|
+
let fixturesX = 0;
|
|
611
|
+
let fixturesY = 0;
|
|
612
|
+
urlFixtures.shift();
|
|
613
|
+
pathFixtures.shift();
|
|
622
614
|
if (pathFixtures.length === urlFixtures.length) {
|
|
623
|
-
|
|
624
|
-
pathFixtures.shift();
|
|
625
|
-
let isIt = true;
|
|
626
|
-
const routesParams = {};
|
|
615
|
+
const routesParams = { _path: "" };
|
|
627
616
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
628
|
-
if (
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
} else {
|
|
632
|
-
if (pathFixtures[i2].includes(":")) {
|
|
633
|
-
continue;
|
|
634
|
-
}
|
|
635
|
-
isIt = false;
|
|
617
|
+
if (pathFixtures[i2].includes(":")) {
|
|
618
|
+
fixturesY += 1;
|
|
619
|
+
continue;
|
|
636
620
|
}
|
|
637
|
-
if (
|
|
638
|
-
|
|
639
|
-
" \u2718 Cradova err: cradova router doesn't allow paths with multiple names"
|
|
640
|
-
);
|
|
621
|
+
if (urlFixtures[i2] === pathFixtures[i2] && pathFixtures.indexOf(urlFixtures[i2]) === pathFixtures.lastIndexOf(urlFixtures[i2])) {
|
|
622
|
+
fixturesX += 1;
|
|
641
623
|
}
|
|
642
624
|
}
|
|
643
|
-
if (
|
|
625
|
+
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
644
626
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
645
627
|
if (pathFixtures[i2].includes(":")) {
|
|
646
628
|
routesParams[pathFixtures[i2].split(":")[1]] = urlFixtures[i2];
|
|
647
629
|
}
|
|
648
630
|
}
|
|
649
|
-
routesParams.
|
|
631
|
+
routesParams._path = path;
|
|
650
632
|
return [RouterBox.routes[path], routesParams];
|
|
651
633
|
}
|
|
652
634
|
}
|
|
653
635
|
}
|
|
654
636
|
return [];
|
|
655
637
|
};
|
|
656
|
-
|
|
657
|
-
if (!screen
|
|
638
|
+
RouterBox.route = (path, screen) => {
|
|
639
|
+
if (!screen || !screen._Activate) {
|
|
658
640
|
console.error(" \u2718 Cradova err: not a valid screen ", screen);
|
|
659
641
|
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
660
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) {
|
|
661
665
|
RouterBox.routes[path] = {
|
|
662
|
-
controller: (params, force) => screen.Activate(params, force),
|
|
666
|
+
controller: async (params, force) => await screen.Activate(params, force),
|
|
663
667
|
packager: async (params) => await screen.package(params),
|
|
664
|
-
deactivate: () => {
|
|
665
|
-
screen.deActivate();
|
|
668
|
+
deactivate: async () => {
|
|
669
|
+
await screen.deActivate();
|
|
670
|
+
},
|
|
671
|
+
paramData: (data2) => {
|
|
672
|
+
screen.paramData = data2;
|
|
666
673
|
}
|
|
667
674
|
};
|
|
668
675
|
if (typeof screen.errorHandler === "function") {
|
|
@@ -690,28 +697,31 @@ Router.navigate = function(href, data2 = null, force = false) {
|
|
|
690
697
|
if (route) {
|
|
691
698
|
RouterBox["nextRouteController"] = route;
|
|
692
699
|
RouterBox.params.params = params;
|
|
700
|
+
route._paramData = params;
|
|
693
701
|
RouterBox.params.data = data2 || null;
|
|
694
702
|
link2 = href;
|
|
695
703
|
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
696
704
|
window.history.pushState({}, "", link2);
|
|
697
705
|
}
|
|
698
|
-
(
|
|
699
|
-
await RouterBox.router(null, force);
|
|
700
|
-
})();
|
|
706
|
+
RouterBox.router(null, force);
|
|
701
707
|
}
|
|
702
708
|
};
|
|
703
709
|
RouterBox.router = async function(e, force = false) {
|
|
704
710
|
let url, route, params;
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (Alink
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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;
|
|
712
724
|
}
|
|
713
|
-
e.preventDefault();
|
|
714
|
-
url = new URL(Alink.href).pathname;
|
|
715
725
|
}
|
|
716
726
|
if (!url) {
|
|
717
727
|
url = window.location.pathname;
|
|
@@ -725,26 +735,29 @@ RouterBox.router = async function(e, force = false) {
|
|
|
725
735
|
} else {
|
|
726
736
|
[route, params] = checker(url);
|
|
727
737
|
}
|
|
728
|
-
if (route) {
|
|
738
|
+
if (typeof route !== "undefined") {
|
|
729
739
|
try {
|
|
730
740
|
if (params) {
|
|
731
741
|
RouterBox.params.params = params;
|
|
732
742
|
}
|
|
733
|
-
|
|
734
|
-
|
|
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();
|
|
735
756
|
RouterBox["lastNavigatedRoute"] = url;
|
|
736
757
|
RouterBox["lastNavigatedRouteController"] = route;
|
|
737
758
|
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
738
|
-
for (const a2 of document.querySelectorAll("a")) {
|
|
739
|
-
if (a2.href.includes(window.location.origin)) {
|
|
740
|
-
a2.addEventListener("click", (e2) => {
|
|
741
|
-
e2.preventDefault();
|
|
742
|
-
Router.navigate(a2.pathname);
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
759
|
} catch (error) {
|
|
747
|
-
const errorHandler = RouterBox.
|
|
760
|
+
const errorHandler = RouterBox.routes[RouterBox.params.params.path].errorHandler || RouterBox.errorHandler;
|
|
748
761
|
if (errorHandler) {
|
|
749
762
|
errorHandler(error);
|
|
750
763
|
}
|
|
@@ -784,300 +797,174 @@ Router.packageScreen = async function(path, data2) {
|
|
|
784
797
|
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
785
798
|
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
786
799
|
}
|
|
787
|
-
|
|
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;
|
|
788
806
|
};
|
|
789
807
|
Router.getParams = function() {
|
|
790
808
|
return RouterBox["params"];
|
|
791
809
|
};
|
|
792
|
-
Router["addErrorHandler"] = function(callback
|
|
810
|
+
Router["addErrorHandler"] = function(callback) {
|
|
793
811
|
if (typeof callback === "function") {
|
|
794
|
-
RouterBox["errorHandler"]
|
|
812
|
+
RouterBox["errorHandler"] = callback;
|
|
795
813
|
} else {
|
|
796
814
|
throw new Error(
|
|
797
815
|
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
798
816
|
);
|
|
799
817
|
}
|
|
800
818
|
};
|
|
801
|
-
|
|
802
|
-
window.addEventListener("
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
819
|
+
Router.mount = () => {
|
|
820
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
821
|
+
window.addEventListener("popstate", (e) => {
|
|
822
|
+
e.preventDefault();
|
|
823
|
+
RouterBox.router();
|
|
824
|
+
});
|
|
825
|
+
};
|
|
806
826
|
|
|
807
|
-
// lib/utils/
|
|
808
|
-
var
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
this.html = template2.bind(this);
|
|
822
|
-
this.name = name;
|
|
823
|
-
this.template.setAttribute("id", "cradova-screen-set");
|
|
824
|
-
if (typeof persist === "boolean") {
|
|
825
|
-
this.persist = persist;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
setErrorHandler(errorHandler) {
|
|
829
|
-
this.errorHandler = errorHandler;
|
|
830
|
-
}
|
|
831
|
-
async package() {
|
|
832
|
-
if (typeof this.html === "function") {
|
|
833
|
-
let fuc = await this.html(this.data);
|
|
834
|
-
if (typeof fuc === "function") {
|
|
835
|
-
fuc = fuc();
|
|
836
|
-
if (fuc && !isNode(fuc) && typeof fuc !== "string") {
|
|
837
|
-
throw new Error(
|
|
838
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
839
|
-
);
|
|
840
|
-
} else {
|
|
841
|
-
if (fuc) {
|
|
842
|
-
this.template.innerHTML = "";
|
|
843
|
-
this.template.appendChild(fuc);
|
|
844
|
-
}
|
|
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();
|
|
845
838
|
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
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;
|
|
851
855
|
} else {
|
|
852
|
-
|
|
853
|
-
this.template.appendChild(fuc);
|
|
856
|
+
props = Object.assign(props, child);
|
|
854
857
|
}
|
|
858
|
+
continue;
|
|
855
859
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
if (this.secondaryChildren.length) {
|
|
863
|
-
for (const child of this.secondaryChildren) {
|
|
864
|
-
this.template.appendChild(child);
|
|
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
865
|
}
|
|
866
866
|
}
|
|
867
|
+
} else {
|
|
868
|
+
return element;
|
|
867
869
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
async Activate(force) {
|
|
883
|
-
if (!this.persist) {
|
|
884
|
-
await this.package();
|
|
885
|
-
this.packed = true;
|
|
886
|
-
} else {
|
|
887
|
-
if (!this.packed) {
|
|
888
|
-
await this.package();
|
|
889
|
-
this.packed = true;
|
|
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
|
+
);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
continue;
|
|
890
883
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
this.packed = true;
|
|
895
|
-
}
|
|
896
|
-
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
897
|
-
if (!doc) {
|
|
898
|
-
throw new Error(
|
|
899
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-cra-id='cradova-app-wrapper'> ... </div>"
|
|
900
|
-
);
|
|
901
|
-
}
|
|
902
|
-
doc.innerHTML = "";
|
|
903
|
-
doc.appendChild(this.template);
|
|
904
|
-
document.title = this.name;
|
|
905
|
-
if (!this.persist) {
|
|
906
|
-
this.packed = false;
|
|
907
|
-
}
|
|
908
|
-
if (this.callBack) {
|
|
909
|
-
await this.callBack();
|
|
910
|
-
}
|
|
911
|
-
window.dispatchEvent(cradovaAftermountEvent);
|
|
912
|
-
window.scrollTo(0, 0);
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
// lib/utils/tags.ts
|
|
917
|
-
var cra = (element_initials) => {
|
|
918
|
-
return (...ElementChildrenAndPropertyList) => {
|
|
919
|
-
let beforeMount = null;
|
|
920
|
-
let props = null, text = null;
|
|
921
|
-
let element;
|
|
922
|
-
element = document.createElement(element_initials);
|
|
923
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
924
|
-
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
925
|
-
let child = ElementChildrenAndPropertyList[i2];
|
|
926
|
-
if (typeof child === "function") {
|
|
927
|
-
child = child();
|
|
928
|
-
if (typeof child === "function") {
|
|
929
|
-
child = child();
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
if (isNode(child)) {
|
|
933
|
-
element.appendChild(child);
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
if (Array.isArray(child)) {
|
|
937
|
-
let rload2 = function(l) {
|
|
938
|
-
const fg = new DocumentFragment();
|
|
939
|
-
for (let ch of l) {
|
|
940
|
-
if (Array.isArray(ch)) {
|
|
941
|
-
fg.appendChild(rload2(ch));
|
|
942
|
-
} else {
|
|
943
|
-
if (typeof ch === "function") {
|
|
944
|
-
ch = ch();
|
|
945
|
-
}
|
|
946
|
-
if (typeof ch === "function") {
|
|
947
|
-
ch = ch();
|
|
948
|
-
}
|
|
949
|
-
fg.appendChild(ch);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
return fg;
|
|
953
|
-
};
|
|
954
|
-
var rload = rload2;
|
|
955
|
-
const arrCXLength = child.length;
|
|
956
|
-
for (let p2 = 0; p2 < arrCXLength; p2++) {
|
|
957
|
-
let childly = child[p2];
|
|
958
|
-
if (typeof childly === "function") {
|
|
959
|
-
childly = childly();
|
|
960
|
-
}
|
|
961
|
-
if (typeof childly === "function") {
|
|
962
|
-
childly = childly();
|
|
963
|
-
}
|
|
964
|
-
if (Array.isArray(childly)) {
|
|
965
|
-
childly = rload2(childly);
|
|
966
|
-
}
|
|
967
|
-
if (isNode(childly)) {
|
|
968
|
-
element.appendChild(childly);
|
|
969
|
-
} else {
|
|
970
|
-
throw new Error(
|
|
971
|
-
" \u2718 Cradova err: invalid child type: " + childly + " (" + typeof childly + ")"
|
|
972
|
-
);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
continue;
|
|
976
|
-
}
|
|
977
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
978
|
-
text = child;
|
|
979
|
-
continue;
|
|
980
|
-
}
|
|
981
|
-
if (typeof child === "object" && !Array.isArray(child)) {
|
|
982
|
-
if (!props) {
|
|
983
|
-
props = child;
|
|
984
|
-
} else {
|
|
985
|
-
props = Object.assign(props, child);
|
|
986
|
-
}
|
|
987
|
-
continue;
|
|
988
|
-
}
|
|
989
|
-
console.error(" \u2718 Cradova err: got", { child });
|
|
990
|
-
throw new Error(
|
|
991
|
-
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
992
|
-
);
|
|
884
|
+
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
885
|
+
element.style[prop] = props[prop];
|
|
886
|
+
continue;
|
|
993
887
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
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];
|
|
927
|
+
} else {
|
|
928
|
+
if (prop.includes("data-")) {
|
|
929
|
+
element.setAttribute(prop, props[prop]);
|
|
930
|
+
continue;
|
|
1006
931
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1014
|
-
text = props[prop];
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1018
|
-
element.classList.add(props[prop]);
|
|
1019
|
-
continue;
|
|
1020
|
-
}
|
|
1021
|
-
if (prop === "beforeMount") {
|
|
1022
|
-
beforeMount = props["beforeMount"];
|
|
1023
|
-
continue;
|
|
1024
|
-
}
|
|
1025
|
-
if (prop === "stateID") {
|
|
1026
|
-
element.setAttribute("data-cra-id", props[prop]);
|
|
1027
|
-
continue;
|
|
1028
|
-
}
|
|
1029
|
-
if (prop.includes("$")) {
|
|
1030
|
-
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1031
|
-
continue;
|
|
1032
|
-
}
|
|
1033
|
-
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1034
|
-
element.updateState = dispatch.bind(null, element);
|
|
1035
|
-
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1036
|
-
continue;
|
|
1037
|
-
}
|
|
1038
|
-
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1039
|
-
element.updateState = dispatch.bind(null, element);
|
|
1040
|
-
continue;
|
|
1041
|
-
}
|
|
1042
|
-
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1043
|
-
const av = () => {
|
|
1044
|
-
props["afterMount"].apply(element);
|
|
1045
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
1046
|
-
};
|
|
1047
|
-
window.addEventListener("cradova-aftermount", av);
|
|
1048
|
-
continue;
|
|
1049
|
-
}
|
|
1050
|
-
try {
|
|
1051
|
-
if (typeof element[prop] !== "undefined") {
|
|
1052
|
-
element[prop] = props[prop];
|
|
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
|
+
});
|
|
1053
937
|
} else {
|
|
1054
|
-
|
|
1055
|
-
element.setAttribute(prop, props[prop]);
|
|
1056
|
-
continue;
|
|
1057
|
-
}
|
|
1058
|
-
element[prop] = props[prop];
|
|
1059
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1060
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1061
|
-
prop
|
|
1062
|
-
});
|
|
1063
|
-
} else {
|
|
1064
|
-
continue;
|
|
1065
|
-
}
|
|
938
|
+
continue;
|
|
1066
939
|
}
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1069
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
1070
940
|
}
|
|
941
|
+
} catch (error) {
|
|
942
|
+
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
943
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
1071
944
|
}
|
|
1072
945
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
946
|
+
}
|
|
947
|
+
if (text) {
|
|
948
|
+
element.appendChild(document.createTextNode(text));
|
|
949
|
+
}
|
|
950
|
+
if (typeof beforeMount === "function") {
|
|
951
|
+
beforeMount.apply(element);
|
|
952
|
+
}
|
|
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
|
+
});
|
|
1078
959
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
960
|
+
}
|
|
961
|
+
return element;
|
|
962
|
+
};
|
|
963
|
+
var cra = (element_initials) => {
|
|
964
|
+
return makeElement.bind(
|
|
965
|
+
void 0,
|
|
966
|
+
document.createElement(element_initials)
|
|
967
|
+
);
|
|
1081
968
|
};
|
|
1082
969
|
var a = cra("a");
|
|
1083
970
|
var abbr = cra("abbr");
|
|
@@ -1192,6 +1079,203 @@ var val = cra("val");
|
|
|
1192
1079
|
var video = cra("video");
|
|
1193
1080
|
var wbr = cra("wbr");
|
|
1194
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
|
+
|
|
1195
1279
|
// lib/index.ts
|
|
1196
1280
|
var make = function(txx) {
|
|
1197
1281
|
if (!txx) {
|
|
@@ -1261,223 +1345,47 @@ var make = function(txx) {
|
|
|
1261
1345
|
const className = classes && classes.join(" ");
|
|
1262
1346
|
return { tag, className, ID, innerValue };
|
|
1263
1347
|
};
|
|
1264
|
-
var
|
|
1265
|
-
if (
|
|
1266
|
-
return frag(element_initials);
|
|
1267
|
-
}
|
|
1268
|
-
if (element_initials.raw) {
|
|
1348
|
+
var _2 = (...element_initials) => {
|
|
1349
|
+
if (element_initials[0].raw) {
|
|
1269
1350
|
element_initials[0] = element_initials["raw"][0];
|
|
1270
1351
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
firstLevelChildren = element_initials.splice(1);
|
|
1274
|
-
}
|
|
1275
|
-
if (typeof element_initials !== "object") {
|
|
1276
|
-
element_initials = [element_initials];
|
|
1352
|
+
if (typeof element_initials[0] !== "string") {
|
|
1353
|
+
return frag(element_initials);
|
|
1277
1354
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
);
|
|
1291
|
-
}
|
|
1292
|
-
if (initials.className) {
|
|
1293
|
-
if (props) {
|
|
1294
|
-
props["className"] = initials.className.trim();
|
|
1295
|
-
} else {
|
|
1296
|
-
props = { className: initials.className.trim() };
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
if (initials.ID) {
|
|
1300
|
-
if (props) {
|
|
1301
|
-
props["id"] = initials.ID.trim();
|
|
1302
|
-
} else {
|
|
1303
|
-
props = { id: initials.ID.trim() };
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
if (initials.innerValue) {
|
|
1307
|
-
if (props) {
|
|
1308
|
-
props["innerText"] = initials.innerValue;
|
|
1309
|
-
} else {
|
|
1310
|
-
props = { innerText: initials.innerValue };
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
1314
|
-
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
1315
|
-
let child = ElementChildrenAndPropertyList[i2];
|
|
1316
|
-
if (typeof child === "function") {
|
|
1317
|
-
child = child();
|
|
1318
|
-
if (typeof child === "function") {
|
|
1319
|
-
child = child();
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
if (isNode(child)) {
|
|
1323
|
-
element.appendChild(child);
|
|
1324
|
-
continue;
|
|
1325
|
-
}
|
|
1326
|
-
if (Array.isArray(child)) {
|
|
1327
|
-
let rload2 = function(l) {
|
|
1328
|
-
const fg = new DocumentFragment();
|
|
1329
|
-
for (let ch of l) {
|
|
1330
|
-
if (Array.isArray(ch)) {
|
|
1331
|
-
fg.appendChild(rload2(ch));
|
|
1332
|
-
} else {
|
|
1333
|
-
if (typeof ch === "function") {
|
|
1334
|
-
ch = ch();
|
|
1335
|
-
}
|
|
1336
|
-
if (typeof ch === "function") {
|
|
1337
|
-
ch = ch();
|
|
1338
|
-
}
|
|
1339
|
-
fg.appendChild(ch);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
return fg;
|
|
1343
|
-
};
|
|
1344
|
-
var rload = rload2;
|
|
1345
|
-
const arrCXLength = child.length;
|
|
1346
|
-
for (let p2 = 0; p2 < arrCXLength; p2++) {
|
|
1347
|
-
let childly = child[p2];
|
|
1348
|
-
if (typeof childly === "function") {
|
|
1349
|
-
childly = childly();
|
|
1350
|
-
}
|
|
1351
|
-
if (typeof childly === "function") {
|
|
1352
|
-
childly = childly();
|
|
1353
|
-
}
|
|
1354
|
-
if (Array.isArray(childly)) {
|
|
1355
|
-
childly = rload2(childly);
|
|
1356
|
-
}
|
|
1357
|
-
if (isNode(childly)) {
|
|
1358
|
-
element.appendChild(childly);
|
|
1359
|
-
} else {
|
|
1360
|
-
console.log(childly);
|
|
1361
|
-
if (typeof childly !== "undefined") {
|
|
1362
|
-
throw new Error(
|
|
1363
|
-
" \u2718 Cradova err: invalid child type: " + childly + " (" + typeof childly + ")"
|
|
1364
|
-
);
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
continue;
|
|
1369
|
-
}
|
|
1370
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
1371
|
-
text = child;
|
|
1372
|
-
continue;
|
|
1373
|
-
}
|
|
1374
|
-
if (typeof child === "object" && !Array.isArray(child)) {
|
|
1375
|
-
if (!props) {
|
|
1376
|
-
props = child;
|
|
1377
|
-
} else {
|
|
1378
|
-
props = Object.assign(props, child);
|
|
1379
|
-
}
|
|
1380
|
-
continue;
|
|
1381
|
-
}
|
|
1382
|
-
if (typeof child !== "undefined") {
|
|
1383
|
-
console.error(" \u2718 Cradova err: got", { child });
|
|
1384
|
-
throw new Error(
|
|
1385
|
-
" \u2718 Cradova err: invalid child type: (" + typeof child + ")"
|
|
1386
|
-
);
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
if (typeof props === "object" && element) {
|
|
1391
|
-
for (const prop in props) {
|
|
1392
|
-
if (prop === "style" && typeof props[prop] === "object") {
|
|
1393
|
-
for (const [k, v] of Object.entries(props[prop])) {
|
|
1394
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
1395
|
-
element.style[k] = v;
|
|
1396
|
-
} else {
|
|
1397
|
-
throw new Error(
|
|
1398
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
1399
|
-
);
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
continue;
|
|
1403
|
-
}
|
|
1404
|
-
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
1405
|
-
element.style[prop] = props[prop];
|
|
1406
|
-
continue;
|
|
1407
|
-
}
|
|
1408
|
-
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1409
|
-
text = props[prop];
|
|
1410
|
-
continue;
|
|
1411
|
-
}
|
|
1412
|
-
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1413
|
-
element.classList.add(props[prop]);
|
|
1414
|
-
continue;
|
|
1415
|
-
}
|
|
1416
|
-
if (prop === "beforeMount") {
|
|
1417
|
-
beforeMount = props["beforeMount"];
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
if (prop === "stateID") {
|
|
1421
|
-
element.setAttribute("data-cra-id", props[prop]);
|
|
1422
|
-
continue;
|
|
1423
|
-
}
|
|
1424
|
-
if (prop.includes("$")) {
|
|
1425
|
-
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1426
|
-
continue;
|
|
1427
|
-
}
|
|
1428
|
-
if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
|
|
1429
|
-
element.updateState = dispatch.bind(null, element);
|
|
1430
|
-
props[prop][0]._bindRef(element, prop, props[prop][1]);
|
|
1431
|
-
continue;
|
|
1432
|
-
}
|
|
1433
|
-
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1434
|
-
element.updateState = dispatch.bind(null, element);
|
|
1435
|
-
continue;
|
|
1436
|
-
}
|
|
1437
|
-
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
1438
|
-
const av = () => {
|
|
1439
|
-
props["afterMount"].apply(element);
|
|
1440
|
-
window.removeEventListener("cradova-aftermount", av);
|
|
1441
|
-
};
|
|
1442
|
-
window.addEventListener("cradova-aftermount", av);
|
|
1443
|
-
continue;
|
|
1444
|
-
}
|
|
1445
|
-
try {
|
|
1446
|
-
if (typeof element[prop] !== "undefined") {
|
|
1447
|
-
element[prop] = props[prop];
|
|
1448
|
-
} else {
|
|
1449
|
-
if (prop.includes("data-")) {
|
|
1450
|
-
element.setAttribute(prop, props[prop]);
|
|
1451
|
-
continue;
|
|
1452
|
-
}
|
|
1453
|
-
element[prop] = props[prop];
|
|
1454
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
|
|
1455
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", {
|
|
1456
|
-
prop
|
|
1457
|
-
});
|
|
1458
|
-
} else {
|
|
1459
|
-
continue;
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
} catch (error) {
|
|
1463
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
1464
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
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() };
|
|
1467
1368
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1369
|
+
}
|
|
1370
|
+
if (initials.ID) {
|
|
1371
|
+
if (props) {
|
|
1372
|
+
props["id"] = initials.ID.trim();
|
|
1373
|
+
} else {
|
|
1374
|
+
props = { id: initials.ID.trim() };
|
|
1470
1375
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1376
|
+
}
|
|
1377
|
+
if (initials.innerValue) {
|
|
1378
|
+
if (props) {
|
|
1379
|
+
props["innerText"] = initials.innerValue;
|
|
1380
|
+
} else {
|
|
1381
|
+
props = { innerText: initials.innerValue };
|
|
1473
1382
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1383
|
+
}
|
|
1384
|
+
return makeElement(element, props, ...element_initials);
|
|
1476
1385
|
};
|
|
1477
1386
|
Init();
|
|
1478
|
-
var lib_default =
|
|
1387
|
+
var lib_default = _2;
|
|
1479
1388
|
export {
|
|
1480
|
-
simpleStore as $,
|
|
1481
1389
|
Ajax,
|
|
1482
1390
|
Ref,
|
|
1483
1391
|
Router,
|
|
@@ -1544,11 +1452,13 @@ export {
|
|
|
1544
1452
|
ins,
|
|
1545
1453
|
kbd,
|
|
1546
1454
|
label,
|
|
1455
|
+
lazy,
|
|
1547
1456
|
legend,
|
|
1548
1457
|
li,
|
|
1549
1458
|
link,
|
|
1550
1459
|
loop,
|
|
1551
1460
|
main,
|
|
1461
|
+
makeElement,
|
|
1552
1462
|
map,
|
|
1553
1463
|
mark,
|
|
1554
1464
|
math,
|
|
@@ -1604,3 +1514,4 @@ export {
|
|
|
1604
1514
|
video,
|
|
1605
1515
|
wbr
|
|
1606
1516
|
};
|
|
1517
|
+
//! value could be a promise
|