cradova 2.3.0 → 3.0.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 +30 -48
- package/dist/index.d.ts +444 -373
- package/dist/index.js +477 -636
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
// lib/
|
|
2
|
-
var Init = function() {
|
|
3
|
-
if (!document.querySelector("[data-wrapper=app]")) {
|
|
4
|
-
const Wrapper = document.createElement("div");
|
|
5
|
-
Wrapper.setAttribute("data-wrapper", "app");
|
|
6
|
-
document.body.appendChild(Wrapper);
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// lib/utils/fns.ts
|
|
1
|
+
// lib/parts/fns.ts
|
|
11
2
|
var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
|
|
12
3
|
var cradovaEvent = class {
|
|
13
4
|
constructor() {
|
|
@@ -19,20 +10,10 @@ var cradovaEvent = class {
|
|
|
19
10
|
}
|
|
20
11
|
this.listeners[eventName].push(callback);
|
|
21
12
|
}
|
|
22
|
-
removeEventListener(eventName, callback) {
|
|
23
|
-
if (this.listeners[eventName]) {
|
|
24
|
-
const index = this.listeners[eventName].indexOf(callback);
|
|
25
|
-
if (index !== -1) {
|
|
26
|
-
this.listeners[eventName].splice(index, 1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
13
|
dispatchEvent(eventName, eventArgs) {
|
|
31
|
-
const eventListeners = this.listeners[eventName];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
eventListeners[i2](eventArgs);
|
|
35
|
-
}
|
|
14
|
+
const eventListeners = this.listeners[eventName] || [];
|
|
15
|
+
for (; eventListeners.length !== 0; ) {
|
|
16
|
+
eventListeners.shift()?.call(void 0, eventArgs);
|
|
36
17
|
}
|
|
37
18
|
}
|
|
38
19
|
};
|
|
@@ -43,8 +24,8 @@ function Rhoda(l) {
|
|
|
43
24
|
if (Array.isArray(ch)) {
|
|
44
25
|
fg.appendChild(Rhoda(ch));
|
|
45
26
|
} else {
|
|
46
|
-
if (ch
|
|
47
|
-
ch = ch.render();
|
|
27
|
+
if (ch instanceof Ref) {
|
|
28
|
+
ch = ch.render(void 0);
|
|
48
29
|
}
|
|
49
30
|
if (typeof ch === "function") {
|
|
50
31
|
ch = ch();
|
|
@@ -116,18 +97,21 @@ var Ref = class {
|
|
|
116
97
|
this.component = component.bind(this);
|
|
117
98
|
}
|
|
118
99
|
preRender(data2) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
100
|
+
let ihtml = this.component(data2);
|
|
101
|
+
let phtml;
|
|
102
|
+
if (typeof ihtml === "function") {
|
|
103
|
+
phtml = ihtml;
|
|
104
|
+
ihtml = phtml();
|
|
105
|
+
}
|
|
106
|
+
if (ihtml instanceof HTMLElement) {
|
|
107
|
+
this.preRendered = ihtml;
|
|
124
108
|
}
|
|
125
109
|
if (!this.preRendered) {
|
|
126
110
|
throw new Error(
|
|
127
111
|
" \u2718 Cradova err : Invalid component type for cradova Ref got - " + this.preRendered
|
|
128
112
|
);
|
|
129
113
|
}
|
|
130
|
-
this.reference._appendDomForce("
|
|
114
|
+
this.reference._appendDomForce("element", this.preRendered);
|
|
131
115
|
}
|
|
132
116
|
destroyPreRendered() {
|
|
133
117
|
this.preRendered = null;
|
|
@@ -138,11 +122,14 @@ var Ref = class {
|
|
|
138
122
|
this.hasFirstStateUpdateRun = false;
|
|
139
123
|
let element = null;
|
|
140
124
|
if (!this.preRendered) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
125
|
+
let ihtml = this.component(data2);
|
|
126
|
+
let phtml;
|
|
127
|
+
if (typeof ihtml === "function") {
|
|
128
|
+
phtml = ihtml;
|
|
129
|
+
ihtml = phtml();
|
|
130
|
+
}
|
|
131
|
+
if (ihtml instanceof HTMLElement) {
|
|
132
|
+
element = ihtml;
|
|
146
133
|
}
|
|
147
134
|
if (!element) {
|
|
148
135
|
throw new Error(
|
|
@@ -155,20 +142,19 @@ var Ref = class {
|
|
|
155
142
|
}
|
|
156
143
|
const av = async () => {
|
|
157
144
|
await this.effector.apply(this);
|
|
158
|
-
CradovaEvent.removeEventListener("cradovaAftermountEvent", av);
|
|
159
145
|
};
|
|
160
|
-
CradovaEvent.addEventListener("
|
|
146
|
+
CradovaEvent.addEventListener("onmountEvent", av);
|
|
161
147
|
this.effector();
|
|
162
148
|
this.published = true;
|
|
163
149
|
this.rendered = true;
|
|
164
150
|
if (!element) {
|
|
165
151
|
element = this.preRendered;
|
|
166
152
|
}
|
|
167
|
-
this.reference._appendDomForce("
|
|
153
|
+
this.reference._appendDomForce("element", element);
|
|
168
154
|
return element;
|
|
169
155
|
}
|
|
170
156
|
instance() {
|
|
171
|
-
return this.reference.
|
|
157
|
+
return this.reference.element;
|
|
172
158
|
}
|
|
173
159
|
_setExtra(Extra) {
|
|
174
160
|
this.Signal = Extra;
|
|
@@ -217,38 +203,36 @@ var Ref = class {
|
|
|
217
203
|
return;
|
|
218
204
|
}
|
|
219
205
|
this.published = false;
|
|
220
|
-
if (!this.reference.
|
|
206
|
+
if (!this.reference.element) {
|
|
221
207
|
return;
|
|
222
208
|
}
|
|
223
|
-
|
|
209
|
+
let ihtml = this.component(data2);
|
|
224
210
|
let element;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
211
|
+
let phtml;
|
|
212
|
+
if (typeof ihtml === "function") {
|
|
213
|
+
phtml = ihtml;
|
|
214
|
+
ihtml = phtml();
|
|
215
|
+
}
|
|
216
|
+
if (ihtml instanceof HTMLElement) {
|
|
217
|
+
element = ihtml;
|
|
229
218
|
}
|
|
230
219
|
if (!element) {
|
|
231
220
|
throw new Error(
|
|
232
221
|
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
|
|
233
222
|
);
|
|
234
223
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
);
|
|
241
|
-
} else {
|
|
242
|
-
this.reference.reference.remove();
|
|
243
|
-
}
|
|
244
|
-
this.reference._appendDomForce("reference", element);
|
|
245
|
-
} catch (e0) {
|
|
246
|
-
console.error(e0);
|
|
224
|
+
this.reference.element.insertAdjacentElement("beforebegin", element);
|
|
225
|
+
if (this.reference.element.parentElement) {
|
|
226
|
+
this.reference.element.parentElement.removeChild(this.reference.element);
|
|
227
|
+
} else {
|
|
228
|
+
this.reference.element.remove();
|
|
247
229
|
}
|
|
230
|
+
this.reference._appendDomForce("element", element);
|
|
248
231
|
this.published = true;
|
|
232
|
+
CradovaEvent.dispatchEvent("onmountEvent");
|
|
249
233
|
}
|
|
250
234
|
remove() {
|
|
251
|
-
this.reference.
|
|
235
|
+
this.reference.element.remove();
|
|
252
236
|
}
|
|
253
237
|
};
|
|
254
238
|
var frag = function(children) {
|
|
@@ -258,9 +242,6 @@ var frag = function(children) {
|
|
|
258
242
|
if (typeof a2 === "function") {
|
|
259
243
|
a2 = a2();
|
|
260
244
|
}
|
|
261
|
-
if (typeof a2 === "function") {
|
|
262
|
-
a2 = a2();
|
|
263
|
-
}
|
|
264
245
|
if (isNode(a2)) {
|
|
265
246
|
par.appendChild(a2);
|
|
266
247
|
continue;
|
|
@@ -274,158 +255,95 @@ var frag = function(children) {
|
|
|
274
255
|
}
|
|
275
256
|
return par;
|
|
276
257
|
};
|
|
277
|
-
var svgNS = (type, props, ...children) => {
|
|
278
|
-
const sc = document.createElementNS(
|
|
279
|
-
props.xmlns || "http://www.w3.org/2000/svg",
|
|
280
|
-
type
|
|
281
|
-
);
|
|
282
|
-
delete props.xmlns;
|
|
283
|
-
for (const p2 in props) {
|
|
284
|
-
sc.setAttributeNS(null, p2, props[p2]);
|
|
285
|
-
}
|
|
286
|
-
for (let ch of children) {
|
|
287
|
-
if (typeof ch === "function") {
|
|
288
|
-
ch = ch();
|
|
289
|
-
}
|
|
290
|
-
if (typeof ch === "function") {
|
|
291
|
-
ch = ch();
|
|
292
|
-
}
|
|
293
|
-
sc.appendChild(ch);
|
|
294
|
-
}
|
|
295
|
-
return sc;
|
|
296
|
-
};
|
|
297
258
|
var lazy = class {
|
|
298
259
|
constructor(cb) {
|
|
299
|
-
this.content = void 0;
|
|
300
260
|
this._cb = cb;
|
|
301
261
|
}
|
|
302
262
|
async load() {
|
|
303
|
-
|
|
304
|
-
if (typeof
|
|
305
|
-
|
|
263
|
+
let content = await this._cb();
|
|
264
|
+
if (typeof content === "function") {
|
|
265
|
+
content = await content();
|
|
306
266
|
} else {
|
|
307
|
-
|
|
267
|
+
content = await content;
|
|
268
|
+
}
|
|
269
|
+
const def = content;
|
|
270
|
+
if (def.default) {
|
|
271
|
+
this.content = def?.default;
|
|
308
272
|
}
|
|
309
|
-
this.content = this.content.default;
|
|
310
273
|
}
|
|
311
274
|
};
|
|
312
275
|
var reference = class {
|
|
313
276
|
bindAs(name) {
|
|
314
277
|
return [this, name];
|
|
315
278
|
}
|
|
316
|
-
_appendDom(name, Element) {
|
|
317
|
-
if (!Object.hasOwnProperty.call(this, name)) {
|
|
318
|
-
this[name] = Element;
|
|
319
|
-
} else {
|
|
320
|
-
if (Array.isArray(this[name])) {
|
|
321
|
-
this[name].push(Element);
|
|
322
|
-
} else {
|
|
323
|
-
this[name] = [this[name], Element];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
279
|
_appendDomForce(name, Element) {
|
|
328
280
|
this[name] = Element;
|
|
329
281
|
}
|
|
330
282
|
};
|
|
331
283
|
|
|
332
|
-
// lib/
|
|
333
|
-
function
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
344
|
-
element.style[k] = v;
|
|
345
|
-
} else {
|
|
346
|
-
throw new Error(
|
|
347
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (typeof element[key] === "function") {
|
|
354
|
-
if (key.startsWith("on")) {
|
|
355
|
-
element[key] = state[key];
|
|
356
|
-
} else {
|
|
357
|
-
element[key].apply(element);
|
|
358
|
-
}
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
if (key === "text") {
|
|
362
|
-
element.innerText = state[key];
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
if (key === "tree") {
|
|
366
|
-
element.innerHTML = "";
|
|
367
|
-
element.appendChild(frag(state[key]));
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
try {
|
|
371
|
-
if (typeof element[key] !== "undefined") {
|
|
372
|
-
element[key] = state[key];
|
|
284
|
+
// lib/parts/track.ts
|
|
285
|
+
function dispatch(element, state) {
|
|
286
|
+
if (!element) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
290
|
+
for (const key in state) {
|
|
291
|
+
if (key === "style" && typeof state[key] === "object") {
|
|
292
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
293
|
+
if (typeof element.style[k] !== "undefined" && k !== "src" && typeof v === "string") {
|
|
294
|
+
element.style[k] = v;
|
|
373
295
|
} else {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
} else {
|
|
378
|
-
element[key] = state[key];
|
|
379
|
-
}
|
|
380
|
-
if (key !== "for" && key !== "text" && key !== "class" && key !== "tabindex" && key !== "disabled" && !key.includes("aria")) {
|
|
381
|
-
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
382
|
-
}
|
|
296
|
+
throw new Error(
|
|
297
|
+
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
298
|
+
);
|
|
383
299
|
}
|
|
384
|
-
} catch (error) {
|
|
385
|
-
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
386
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
387
300
|
}
|
|
301
|
+
continue;
|
|
388
302
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
function dispatch(stateID, state) {
|
|
396
|
-
if (stateID instanceof HTMLElement) {
|
|
397
|
-
cradovaDispatchTrack([stateID], state);
|
|
398
|
-
}
|
|
399
|
-
let ele;
|
|
400
|
-
let updated = void 0;
|
|
401
|
-
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
402
|
-
for (const [id, eachState] of Object.entries(stateID)) {
|
|
403
|
-
const elements = document.querySelectorAll(
|
|
404
|
-
"[data-cra-id=" + id + "]"
|
|
405
|
-
);
|
|
406
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
407
|
-
cradovaDispatchTrack(elements, eachState);
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
if (typeof stateID === "string") {
|
|
411
|
-
const elements = document.querySelectorAll(
|
|
412
|
-
"[data-cra-id=" + stateID + "]"
|
|
413
|
-
);
|
|
414
|
-
if (elements.length) {
|
|
415
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
416
|
-
if (!state?.cradovaDispatchTrackBreak) {
|
|
417
|
-
cradovaDispatchTrack(elements, state);
|
|
303
|
+
const stateK = state;
|
|
304
|
+
if (typeof element[key] === "function") {
|
|
305
|
+
if (key.startsWith("on")) {
|
|
306
|
+
element[key] = stateK[key];
|
|
307
|
+
} else {
|
|
308
|
+
element[key].apply(element);
|
|
418
309
|
}
|
|
310
|
+
continue;
|
|
419
311
|
}
|
|
312
|
+
if (key === "text") {
|
|
313
|
+
element.innerText = stateK[key];
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (key === "tree") {
|
|
317
|
+
element.innerHTML = "";
|
|
318
|
+
element.appendChild(frag([stateK[key]]));
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (key.includes("data-")) {
|
|
322
|
+
element.setAttribute(key, stateK[key]);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
element[key] = stateK[key];
|
|
420
326
|
}
|
|
421
|
-
if (ele) {
|
|
422
|
-
cradovaDispatchTrack([ele], state);
|
|
423
|
-
}
|
|
424
327
|
}
|
|
425
|
-
|
|
328
|
+
if (typeof state === "string") {
|
|
329
|
+
element.innerText = state;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (typeof state === "function") {
|
|
333
|
+
element.appendChild(frag([state]));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (state instanceof HTMLElement) {
|
|
337
|
+
element.appendChild(state);
|
|
338
|
+
}
|
|
339
|
+
if (!(typeof state === "object" && !Array.isArray(state))) {
|
|
340
|
+
throw new Error(
|
|
341
|
+
" \u2718 Cradova err: Cradova got invalid state => \n" + String(state)
|
|
342
|
+
);
|
|
343
|
+
}
|
|
426
344
|
}
|
|
427
345
|
|
|
428
|
-
// lib/
|
|
346
|
+
// lib/parts/createSignal.ts
|
|
429
347
|
var createSignal = class {
|
|
430
348
|
constructor(initial, props) {
|
|
431
349
|
this.persistName = "";
|
|
@@ -483,35 +401,33 @@ var createSignal = class {
|
|
|
483
401
|
);
|
|
484
402
|
}
|
|
485
403
|
}
|
|
486
|
-
createAction(
|
|
487
|
-
if (typeof
|
|
488
|
-
this.actions[
|
|
404
|
+
createAction(name, action) {
|
|
405
|
+
if (typeof name === "string" && typeof action === "function") {
|
|
406
|
+
this.actions[name] = action;
|
|
489
407
|
} else {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
408
|
+
throw new Error(
|
|
409
|
+
`\u2718 Cradova err : can't create action, ${name} is not a function`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
createActions(Actions) {
|
|
414
|
+
for (const [name, action] of Object.entries(Actions)) {
|
|
415
|
+
if (typeof name === "string" && typeof action === "function") {
|
|
416
|
+
this.actions[name] = action;
|
|
498
417
|
} else {
|
|
499
|
-
throw new Error(
|
|
418
|
+
throw new Error(
|
|
419
|
+
`\u2718 Cradova err : can't create action, ${name} is not a function`
|
|
420
|
+
);
|
|
500
421
|
}
|
|
501
422
|
}
|
|
502
423
|
}
|
|
503
424
|
fireAction(key, data2) {
|
|
504
425
|
this._updateState(key, data2);
|
|
505
|
-
if (this.actions[key]
|
|
506
|
-
this.actions[key].
|
|
507
|
-
return;
|
|
426
|
+
if (typeof this.actions[key] === "function") {
|
|
427
|
+
this.actions[key].call(this, data2);
|
|
508
428
|
} else {
|
|
509
|
-
|
|
510
|
-
this.actions[key].bind(this)(data2);
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
429
|
+
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
513
430
|
}
|
|
514
|
-
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
515
431
|
}
|
|
516
432
|
bind(prop) {
|
|
517
433
|
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
@@ -527,7 +443,7 @@ var createSignal = class {
|
|
|
527
443
|
this.ref.map((ent) => {
|
|
528
444
|
if (ent._event === name) {
|
|
529
445
|
if (ent._element_property && ent._signalProperty) {
|
|
530
|
-
ent.ref
|
|
446
|
+
ent.ref?.updateState({
|
|
531
447
|
[ent._element_property]: data2[ent._signalProperty]
|
|
532
448
|
});
|
|
533
449
|
return;
|
|
@@ -587,7 +503,7 @@ var createSignal = class {
|
|
|
587
503
|
return;
|
|
588
504
|
}
|
|
589
505
|
throw new Error(
|
|
590
|
-
"\u2718 Cradova err : Invalid parameters for binding ref to
|
|
506
|
+
"\u2718 Cradova err : Invalid parameters for binding ref to Signal"
|
|
591
507
|
);
|
|
592
508
|
}
|
|
593
509
|
listen(callback) {
|
|
@@ -600,8 +516,110 @@ var createSignal = class {
|
|
|
600
516
|
}
|
|
601
517
|
};
|
|
602
518
|
|
|
603
|
-
// lib/
|
|
604
|
-
var
|
|
519
|
+
// lib/parts/Screen.ts
|
|
520
|
+
var localTree = new reference();
|
|
521
|
+
var Screen = class {
|
|
522
|
+
constructor(cradova_screen_initials) {
|
|
523
|
+
this._secondaryChildren = [];
|
|
524
|
+
this._errorHandler = null;
|
|
525
|
+
this._packed = false;
|
|
526
|
+
this._template = document.createElement("div");
|
|
527
|
+
this._persist = true;
|
|
528
|
+
this._delegatedRoutesCount = -1;
|
|
529
|
+
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
530
|
+
this._html = template2;
|
|
531
|
+
this._name = name;
|
|
532
|
+
this._transition = transition;
|
|
533
|
+
this._template.setAttribute("id", "cradova-screen-set");
|
|
534
|
+
if (renderInParallel === true) {
|
|
535
|
+
this._delegatedRoutesCount = 0;
|
|
536
|
+
} else {
|
|
537
|
+
if (typeof persist === "boolean") {
|
|
538
|
+
this._persist = persist;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
get _delegatedRoutes() {
|
|
543
|
+
if (this._delegatedRoutesCount > 100) {
|
|
544
|
+
return -1;
|
|
545
|
+
}
|
|
546
|
+
return this._delegatedRoutesCount;
|
|
547
|
+
}
|
|
548
|
+
set _delegatedRoutes(count) {
|
|
549
|
+
if (count) {
|
|
550
|
+
this._delegatedRoutesCount += 1;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
setErrorHandler(errorHandler) {
|
|
554
|
+
this._errorHandler = errorHandler;
|
|
555
|
+
}
|
|
556
|
+
async _package() {
|
|
557
|
+
if (typeof this._html === "function") {
|
|
558
|
+
let fuc = await this._html.apply(this, this._data);
|
|
559
|
+
if (typeof fuc === "function") {
|
|
560
|
+
fuc = fuc();
|
|
561
|
+
if (isNode(fuc)) {
|
|
562
|
+
this._template.innerHTML = "";
|
|
563
|
+
this._template.appendChild(fuc);
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
if (isNode(fuc)) {
|
|
567
|
+
this._template.innerHTML = "";
|
|
568
|
+
this._template.appendChild(fuc);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (this._secondaryChildren.length) {
|
|
573
|
+
this._template.appendChild(frag(this._secondaryChildren));
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
onActivate(cb) {
|
|
577
|
+
this._callBack = cb;
|
|
578
|
+
}
|
|
579
|
+
onDeactivate(cb) {
|
|
580
|
+
this._deCallBack = cb;
|
|
581
|
+
}
|
|
582
|
+
addChildren(...addOns) {
|
|
583
|
+
this._secondaryChildren.push(...addOns);
|
|
584
|
+
}
|
|
585
|
+
async _deActivate() {
|
|
586
|
+
if (this._deCallBack) {
|
|
587
|
+
await this._deCallBack();
|
|
588
|
+
}
|
|
589
|
+
if (this._transition) {
|
|
590
|
+
this._template.classList.remove(this._transition);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
async _Activate(force = false) {
|
|
594
|
+
if (!this._persist || force || !this._packed) {
|
|
595
|
+
await this._package();
|
|
596
|
+
this._packed = true;
|
|
597
|
+
}
|
|
598
|
+
if (!localTree._doc) {
|
|
599
|
+
localTree._appendDomForce(
|
|
600
|
+
"_doc",
|
|
601
|
+
document.querySelector("[data-wrapper=app]")
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
if (!localTree._doc) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-wrapper='app'> ... </div>"
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
if (this._transition) {
|
|
610
|
+
this._template.classList.add(this._transition);
|
|
611
|
+
}
|
|
612
|
+
localTree._doc.innerHTML = "";
|
|
613
|
+
localTree._doc.appendChild(this._template);
|
|
614
|
+
document.title = this._name;
|
|
615
|
+
CradovaEvent.dispatchEvent("onmountEvent");
|
|
616
|
+
if (this._callBack) {
|
|
617
|
+
await this._callBack();
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// lib/parts/Router.ts
|
|
605
623
|
var RouterBox = {};
|
|
606
624
|
RouterBox["lastNavigatedRouteController"] = null;
|
|
607
625
|
RouterBox["nextRouteController"] = null;
|
|
@@ -609,13 +627,16 @@ RouterBox["lastNavigatedRoute"] = null;
|
|
|
609
627
|
RouterBox["pageShow"] = null;
|
|
610
628
|
RouterBox["pageHide"] = null;
|
|
611
629
|
RouterBox["errorHandler"] = null;
|
|
630
|
+
RouterBox["loadingScreen"] = {};
|
|
612
631
|
RouterBox["params"] = {};
|
|
613
632
|
RouterBox["routes"] = {};
|
|
614
633
|
RouterBox["pageevents"] = [];
|
|
615
|
-
RouterBox["start_pageevents"] = function(lastR, newR) {
|
|
616
|
-
|
|
617
|
-
RouterBox["pageevents"]
|
|
618
|
-
|
|
634
|
+
RouterBox["start_pageevents"] = async function(lastR, newR) {
|
|
635
|
+
setTimeout(() => {
|
|
636
|
+
for (let ci = 0; ci < RouterBox["pageevents"].length; ci++) {
|
|
637
|
+
RouterBox["pageevents"][ci](lastR, newR);
|
|
638
|
+
}
|
|
639
|
+
}, 300);
|
|
619
640
|
};
|
|
620
641
|
var checker = (url) => {
|
|
621
642
|
if (RouterBox.routes[url]) {
|
|
@@ -628,11 +649,11 @@ var checker = (url) => {
|
|
|
628
649
|
if (!path.includes(":")) {
|
|
629
650
|
continue;
|
|
630
651
|
}
|
|
631
|
-
if (url.endsWith("/")) {
|
|
632
|
-
url = url.slice(0, path.length - 2);
|
|
633
|
-
}
|
|
634
652
|
const urlFixtures = url.split("/");
|
|
635
653
|
const pathFixtures = path.split("/");
|
|
654
|
+
if (url.endsWith("/")) {
|
|
655
|
+
urlFixtures.pop();
|
|
656
|
+
}
|
|
636
657
|
let fixturesX = 0;
|
|
637
658
|
let fixturesY = 0;
|
|
638
659
|
urlFixtures.shift();
|
|
@@ -641,11 +662,11 @@ var checker = (url) => {
|
|
|
641
662
|
const routesParams = { _path: "" };
|
|
642
663
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
643
664
|
if (pathFixtures[i2].includes(":")) {
|
|
644
|
-
fixturesY
|
|
665
|
+
fixturesY++;
|
|
645
666
|
continue;
|
|
646
667
|
}
|
|
647
|
-
if (urlFixtures[i2] === pathFixtures[i2]
|
|
648
|
-
fixturesX
|
|
668
|
+
if (urlFixtures[i2] === pathFixtures[i2]) {
|
|
669
|
+
fixturesX++;
|
|
649
670
|
}
|
|
650
671
|
}
|
|
651
672
|
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
@@ -662,97 +683,21 @@ var checker = (url) => {
|
|
|
662
683
|
return [];
|
|
663
684
|
};
|
|
664
685
|
RouterBox.route = (path, screen) => {
|
|
665
|
-
if (
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
RouterBox.routes[path] = screen;
|
|
670
|
-
return RouterBox.routes[path];
|
|
671
|
-
};
|
|
672
|
-
Router.BrowserRoutes = function(obj) {
|
|
673
|
-
for (const path in obj) {
|
|
674
|
-
let screen = obj[path];
|
|
675
|
-
if (screen.catch || typeof screen === "function") {
|
|
676
|
-
RouterBox["routes"][path] = async () => {
|
|
677
|
-
if (typeof screen === "function") {
|
|
678
|
-
screen = await screen();
|
|
679
|
-
} else {
|
|
680
|
-
screen = await screen;
|
|
681
|
-
}
|
|
682
|
-
return RouterBox.route(path, screen.default);
|
|
683
|
-
};
|
|
684
|
-
} else {
|
|
685
|
-
RouterBox.route(path, screen);
|
|
686
|
+
if (typeof screen !== "undefined") {
|
|
687
|
+
if (screen && !screen._Activate) {
|
|
688
|
+
console.error(" \u2718 Cradova err: not a valid screen ", screen);
|
|
689
|
+
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
686
690
|
}
|
|
691
|
+
return RouterBox.routes[path] = screen;
|
|
687
692
|
}
|
|
688
|
-
|
|
689
|
-
};
|
|
690
|
-
Router.delegateScreen = function(path = "/", screen) {
|
|
691
|
-
RouterBox.routes[path] = {
|
|
692
|
-
controller: async (params, force) => await screen.Activate(params, force),
|
|
693
|
-
packager: async (params) => await screen.package(params),
|
|
694
|
-
deactivate: async () => {
|
|
695
|
-
await screen.deActivate();
|
|
696
|
-
},
|
|
697
|
-
paramData: (data2) => {
|
|
698
|
-
screen.paramData = data2;
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
if (typeof screen.errorHandler === "function") {
|
|
702
|
-
RouterBox["errorHandler"][path] = screen.errorHandler;
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
Router.navigate = function(href, data2 = null, force = false) {
|
|
706
|
-
if (typeof href !== "string") {
|
|
707
|
-
throw new TypeError(
|
|
708
|
-
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
if (typeof data2 === "boolean") {
|
|
712
|
-
force = true;
|
|
713
|
-
data2 = null;
|
|
714
|
-
}
|
|
715
|
-
let route = null, params;
|
|
716
|
-
if (href.includes("://")) {
|
|
717
|
-
window.location.href = href;
|
|
718
|
-
} else {
|
|
719
|
-
const lastR = window.location.pathname;
|
|
720
|
-
if (href === lastR) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
[route, params] = checker(href);
|
|
724
|
-
if (route) {
|
|
725
|
-
RouterBox["nextRouteController"] = route;
|
|
726
|
-
RouterBox.params.params = params;
|
|
727
|
-
route._paramData = params;
|
|
728
|
-
RouterBox.params.data = data2 || null;
|
|
729
|
-
window.history.pushState({}, "", href);
|
|
730
|
-
}
|
|
731
|
-
RouterBox.router(null, force);
|
|
732
|
-
RouterBox["start_pageevents"](lastR, href);
|
|
733
|
-
}
|
|
693
|
+
return void 0;
|
|
734
694
|
};
|
|
735
|
-
RouterBox.router = async function(
|
|
695
|
+
RouterBox.router = async function(_e, _force) {
|
|
736
696
|
let url, route, params;
|
|
737
|
-
if (e) {
|
|
738
|
-
const Alink = e.target.tagName === "A" && e.target;
|
|
739
|
-
if (Alink) {
|
|
740
|
-
if (Alink.href.includes("#")) {
|
|
741
|
-
const l = Alink.href.split("#");
|
|
742
|
-
document.getElementById("#" + l[l.length - 1])?.scrollIntoView();
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
if (Alink.href.includes("javascript")) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
e.preventDefault();
|
|
749
|
-
url = new URL(Alink.href).pathname;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
697
|
if (!url) {
|
|
753
698
|
url = window.location.pathname;
|
|
754
699
|
}
|
|
755
|
-
if (url ===
|
|
700
|
+
if (url === RouterBox["lastNavigatedRoute"]) {
|
|
756
701
|
return;
|
|
757
702
|
}
|
|
758
703
|
if (RouterBox["nextRouteController"]) {
|
|
@@ -763,13 +708,19 @@ RouterBox.router = async function(e, force = false) {
|
|
|
763
708
|
}
|
|
764
709
|
if (typeof route !== "undefined") {
|
|
765
710
|
try {
|
|
766
|
-
if (
|
|
767
|
-
RouterBox.
|
|
768
|
-
|
|
769
|
-
|
|
711
|
+
if (typeof route === "function") {
|
|
712
|
+
if (RouterBox["LoadingScreen"] && RouterBox["LoadingScreen"]._Activate) {
|
|
713
|
+
await RouterBox["LoadingScreen"]._Activate();
|
|
714
|
+
}
|
|
770
715
|
route = await route();
|
|
716
|
+
if (!route) {
|
|
717
|
+
if (RouterBox["lastNavigatedRoute"]) {
|
|
718
|
+
history.pushState({}, url, RouterBox["lastNavigatedRoute"]);
|
|
719
|
+
}
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
771
722
|
}
|
|
772
|
-
if (route._delegatedRoutes !== -1
|
|
723
|
+
if (route._delegatedRoutes !== -1) {
|
|
773
724
|
route._delegatedRoutes = true;
|
|
774
725
|
route = new Screen({
|
|
775
726
|
name: route._name,
|
|
@@ -777,90 +728,152 @@ RouterBox.router = async function(e, force = false) {
|
|
|
777
728
|
});
|
|
778
729
|
RouterBox.routes[url] = route;
|
|
779
730
|
}
|
|
780
|
-
|
|
731
|
+
if (params) {
|
|
732
|
+
RouterBox.params.params = params;
|
|
733
|
+
}
|
|
734
|
+
await route._Activate(_force);
|
|
781
735
|
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
|
|
782
736
|
RouterBox["lastNavigatedRoute"] = url;
|
|
783
737
|
RouterBox["lastNavigatedRouteController"] = route;
|
|
784
738
|
} catch (error) {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
739
|
+
if (route && route["_errorHandler"]) {
|
|
740
|
+
route._errorHandler(error);
|
|
741
|
+
} else {
|
|
742
|
+
if (RouterBox["errorHandler"]) {
|
|
743
|
+
RouterBox["errorHandler"](error);
|
|
744
|
+
} else {
|
|
745
|
+
console.error(error);
|
|
746
|
+
throw new Error(
|
|
747
|
+
" \u2718 Cradova err: consider adding error boundary to the specific screen "
|
|
748
|
+
);
|
|
749
|
+
}
|
|
791
750
|
}
|
|
792
751
|
}
|
|
793
752
|
} else {
|
|
794
753
|
if (RouterBox.routes["/404"]) {
|
|
795
|
-
RouterBox.routes["/404"].
|
|
754
|
+
await RouterBox.routes["/404"]._Activate(_force);
|
|
796
755
|
}
|
|
797
756
|
}
|
|
798
757
|
};
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
758
|
+
var RouterClass = class {
|
|
759
|
+
BrowserRoutes(obj) {
|
|
760
|
+
for (const path in obj) {
|
|
761
|
+
let screen = obj[path];
|
|
762
|
+
if (typeof screen === "object" && typeof screen.then === "function" || typeof screen === "function") {
|
|
763
|
+
RouterBox["routes"][path] = async () => {
|
|
764
|
+
screen = await (typeof screen === "function" ? await screen() : await screen);
|
|
765
|
+
return RouterBox.route(path, screen?.default || screen);
|
|
766
|
+
};
|
|
767
|
+
} else {
|
|
768
|
+
RouterBox.route(path, screen);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
this._mount();
|
|
806
772
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
if (!RouterBox.routes[path]) {
|
|
810
|
-
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
811
|
-
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
773
|
+
back() {
|
|
774
|
+
history.go(-1);
|
|
812
775
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
route = await route();
|
|
776
|
+
forward() {
|
|
777
|
+
history.go(1);
|
|
816
778
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
779
|
+
navigate(href, data2 = null, force = false) {
|
|
780
|
+
if (typeof href !== "string") {
|
|
781
|
+
throw new TypeError(
|
|
782
|
+
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
let route = null, params;
|
|
786
|
+
if (href.includes("://")) {
|
|
787
|
+
window.location.href = href;
|
|
788
|
+
} else {
|
|
789
|
+
const lastR = window.location.pathname;
|
|
790
|
+
if (href === lastR) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
[route, params] = checker(href);
|
|
794
|
+
if (route) {
|
|
795
|
+
RouterBox["nextRouteController"] = route;
|
|
796
|
+
window.history.pushState({}, "", href);
|
|
797
|
+
}
|
|
798
|
+
RouterBox.params.params = params;
|
|
799
|
+
RouterBox.params.data = data2;
|
|
800
|
+
RouterBox.router(null, force);
|
|
801
|
+
RouterBox["start_pageevents"](lastR, href);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
setLoadingScreen(screen) {
|
|
805
|
+
if (screen instanceof Screen) {
|
|
806
|
+
RouterBox["LoadingScreen"] = screen;
|
|
807
|
+
} else {
|
|
808
|
+
throw new Error(
|
|
809
|
+
" \u2718 Cradova err: Loading Screen should be a cradova screen class"
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
onPageEvent(callback) {
|
|
814
|
+
if (typeof callback === "function") {
|
|
815
|
+
RouterBox["pageevents"].push(callback);
|
|
816
|
+
} else {
|
|
817
|
+
throw new Error(
|
|
818
|
+
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
async packageScreen(path, data2 = {}) {
|
|
823
|
+
if (!RouterBox.routes[path]) {
|
|
824
|
+
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
825
|
+
throw new Error(
|
|
826
|
+
" \u2718 Cradova err: cradova err: Not a defined screen path"
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
let [route, params] = checker(path);
|
|
830
|
+
if (!route._Activate && typeof route === "function") {
|
|
831
|
+
route = await route();
|
|
832
|
+
}
|
|
833
|
+
route._package(Object.assign(data2, params || {}));
|
|
834
|
+
route._packed = true;
|
|
835
|
+
}
|
|
836
|
+
getParams() {
|
|
837
|
+
return RouterBox["params"];
|
|
838
|
+
}
|
|
839
|
+
addErrorHandler(callback) {
|
|
840
|
+
if (typeof callback === "function") {
|
|
841
|
+
RouterBox["errorHandler"] = callback;
|
|
842
|
+
} else {
|
|
843
|
+
throw new Error(" \u2718 Cradova err: callback for event is not a function");
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
_mount() {
|
|
847
|
+
let doc = document.querySelector("[data-wrapper=app]");
|
|
848
|
+
if (!doc) {
|
|
849
|
+
doc = document.createElement("div");
|
|
850
|
+
doc.setAttribute("data-wrapper", "app");
|
|
851
|
+
document.body.appendChild(doc);
|
|
852
|
+
localTree._appendDomForce("doc", doc);
|
|
853
|
+
}
|
|
854
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
855
|
+
window.addEventListener("popstate", (_e) => {
|
|
856
|
+
RouterBox.router();
|
|
857
|
+
});
|
|
830
858
|
}
|
|
831
859
|
};
|
|
832
|
-
Router
|
|
833
|
-
window.addEventListener("pageshow", RouterBox.router);
|
|
834
|
-
window.addEventListener("popstate", (e) => {
|
|
835
|
-
e.preventDefault();
|
|
836
|
-
RouterBox.router();
|
|
837
|
-
});
|
|
838
|
-
};
|
|
860
|
+
var Router = new RouterClass();
|
|
839
861
|
|
|
840
|
-
// lib/
|
|
841
|
-
var makeElement = (element,
|
|
842
|
-
let
|
|
843
|
-
|
|
844
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
862
|
+
// lib/parts/elements.ts
|
|
863
|
+
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
864
|
+
let props = {}, text = null;
|
|
865
|
+
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
845
866
|
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
846
867
|
let child = ElementChildrenAndPropertyList[i2];
|
|
847
|
-
if (child
|
|
868
|
+
if (child instanceof Ref) {
|
|
848
869
|
child = child.render();
|
|
849
870
|
}
|
|
850
871
|
if (typeof child === "function") {
|
|
851
872
|
child = child();
|
|
852
|
-
if (typeof child === "function") {
|
|
853
|
-
child = child();
|
|
854
|
-
}
|
|
855
873
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
continue;
|
|
860
|
-
}
|
|
861
|
-
} catch (error) {
|
|
862
|
-
console.log(element, ElementChildrenAndPropertyList);
|
|
863
|
-
console.log(error);
|
|
874
|
+
if (isNode(child)) {
|
|
875
|
+
element.appendChild(child);
|
|
876
|
+
continue;
|
|
864
877
|
}
|
|
865
878
|
if (Array.isArray(child)) {
|
|
866
879
|
element.appendChild(Rhoda(child));
|
|
@@ -871,11 +884,7 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
871
884
|
continue;
|
|
872
885
|
}
|
|
873
886
|
if (typeof child === "object") {
|
|
874
|
-
|
|
875
|
-
props = child;
|
|
876
|
-
} else {
|
|
877
|
-
props = Object.assign(props, child);
|
|
878
|
-
}
|
|
887
|
+
props = Object.assign(props, child);
|
|
879
888
|
continue;
|
|
880
889
|
}
|
|
881
890
|
if (typeof child !== "undefined") {
|
|
@@ -889,9 +898,9 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
889
898
|
return element;
|
|
890
899
|
}
|
|
891
900
|
if (typeof props === "object" && element) {
|
|
892
|
-
for (const prop
|
|
893
|
-
if (prop === "style" && typeof
|
|
894
|
-
for (const [k, v] of Object.entries(
|
|
901
|
+
for (const [prop, value] of Object.entries(props)) {
|
|
902
|
+
if (prop === "style" && typeof value === "object") {
|
|
903
|
+
for (const [k, v] of Object.entries(value)) {
|
|
895
904
|
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
896
905
|
element.style[k] = v;
|
|
897
906
|
} else {
|
|
@@ -903,95 +912,70 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
903
912
|
continue;
|
|
904
913
|
}
|
|
905
914
|
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
906
|
-
element.style[prop] =
|
|
907
|
-
continue;
|
|
908
|
-
}
|
|
909
|
-
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
910
|
-
text = props[prop];
|
|
911
|
-
continue;
|
|
912
|
-
}
|
|
913
|
-
if (prop === "beforeMount") {
|
|
914
|
-
beforeMount = props["beforeMount"];
|
|
915
|
+
element.style[prop] = value;
|
|
915
916
|
continue;
|
|
916
917
|
}
|
|
917
|
-
if (prop === "
|
|
918
|
-
|
|
918
|
+
if (prop === "text" && typeof value === "string" && value !== "") {
|
|
919
|
+
text = value;
|
|
919
920
|
continue;
|
|
920
921
|
}
|
|
921
|
-
if (prop
|
|
922
|
-
|
|
922
|
+
if (prop === "href" && typeof value === "string") {
|
|
923
|
+
const href = value || "";
|
|
924
|
+
if (!href.includes("://")) {
|
|
925
|
+
element.addEventListener(
|
|
926
|
+
"click",
|
|
927
|
+
(e) => {
|
|
928
|
+
e.preventDefault();
|
|
929
|
+
Router.navigate(element.pathname);
|
|
930
|
+
}
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
element.setAttribute(prop, value);
|
|
923
934
|
continue;
|
|
924
935
|
}
|
|
925
|
-
if (Array.isArray(
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
936
|
+
if (Array.isArray(value)) {
|
|
937
|
+
const clas = value;
|
|
938
|
+
if (clas[0] instanceof createSignal) {
|
|
939
|
+
element["updateState"] = dispatch.bind(null, element);
|
|
940
|
+
clas[0].bindRef(element, {
|
|
941
|
+
_element_property: prop,
|
|
942
|
+
signalProperty: clas[1]
|
|
943
|
+
});
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (prop == "reference" && clas[0] instanceof reference) {
|
|
947
|
+
element["updateState"] = dispatch.bind(null, element);
|
|
948
|
+
clas[0]._appendDomForce(clas[1], element);
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
932
951
|
}
|
|
933
|
-
if (prop
|
|
934
|
-
|
|
935
|
-
|
|
952
|
+
if (prop === "onmount" && typeof props["onmount"] === "function") {
|
|
953
|
+
const ev = () => {
|
|
954
|
+
props.onmount?.apply(element);
|
|
955
|
+
props["onmount"] = void 0;
|
|
956
|
+
};
|
|
957
|
+
CradovaEvent.addEventListener("onmountEvent", ev);
|
|
936
958
|
continue;
|
|
937
959
|
}
|
|
938
|
-
if (prop
|
|
939
|
-
element.
|
|
960
|
+
if (prop.includes("data-")) {
|
|
961
|
+
element.setAttribute(prop, value);
|
|
940
962
|
continue;
|
|
941
963
|
}
|
|
942
|
-
if (prop
|
|
943
|
-
|
|
944
|
-
props["afterMount"].apply(element);
|
|
945
|
-
CradovaEvent.removeEventListener("cradovaAftermountEvent", avi);
|
|
946
|
-
};
|
|
947
|
-
CradovaEvent.addEventListener("cradovaAftermountEvent", avi);
|
|
964
|
+
if (prop.includes("aria-")) {
|
|
965
|
+
element.setAttribute(prop, value);
|
|
948
966
|
continue;
|
|
949
967
|
}
|
|
950
|
-
|
|
951
|
-
if (typeof element[prop] !== "undefined") {
|
|
952
|
-
element[prop] = props[prop];
|
|
953
|
-
} else {
|
|
954
|
-
if (prop.includes("data-")) {
|
|
955
|
-
element.setAttribute(prop, props[prop]);
|
|
956
|
-
continue;
|
|
957
|
-
}
|
|
958
|
-
element[prop] = props[prop];
|
|
959
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && prop !== "disabled" && !prop.includes("aria")) {
|
|
960
|
-
console.warn(" \u2718 Cradova err: invalid html attribute ", {
|
|
961
|
-
prop
|
|
962
|
-
});
|
|
963
|
-
} else {
|
|
964
|
-
continue;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
} catch (error) {
|
|
968
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
969
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
970
|
-
}
|
|
968
|
+
element[prop] = value;
|
|
971
969
|
}
|
|
972
970
|
}
|
|
973
971
|
if (text) {
|
|
974
972
|
element.appendChild(document.createTextNode(text));
|
|
975
973
|
}
|
|
976
|
-
if (typeof beforeMount === "function") {
|
|
977
|
-
beforeMount.apply(element);
|
|
978
|
-
}
|
|
979
|
-
if (element.tagName === "A" && window) {
|
|
980
|
-
if (element.href.includes(window.location.origin)) {
|
|
981
|
-
element.addEventListener("click", (e) => {
|
|
982
|
-
e.preventDefault();
|
|
983
|
-
Router.navigate(element.pathname);
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
974
|
return element;
|
|
988
975
|
};
|
|
989
976
|
var cra = (element_initials) => {
|
|
990
977
|
return (...initials) => {
|
|
991
|
-
return makeElement(
|
|
992
|
-
document.createElement(element_initials),
|
|
993
|
-
...initials
|
|
994
|
-
);
|
|
978
|
+
return makeElement(document.createElement(element_initials), initials);
|
|
995
979
|
};
|
|
996
980
|
};
|
|
997
981
|
var a = cra("a");
|
|
@@ -1106,7 +1090,7 @@ var val = cra("val");
|
|
|
1106
1090
|
var video = cra("video");
|
|
1107
1091
|
var wbr = cra("wbr");
|
|
1108
1092
|
|
|
1109
|
-
// lib/
|
|
1093
|
+
// lib/parts/ajax.ts
|
|
1110
1094
|
function Ajax(url, opts = {}) {
|
|
1111
1095
|
const { method, data: data2, header: header2, callbacks } = opts;
|
|
1112
1096
|
if (typeof url !== "string") {
|
|
@@ -1117,9 +1101,7 @@ function Ajax(url, opts = {}) {
|
|
|
1117
1101
|
const formData = new FormData();
|
|
1118
1102
|
if (callbacks && typeof callbacks === "object") {
|
|
1119
1103
|
for (const [k, v] of Object.entries(callbacks)) {
|
|
1120
|
-
|
|
1121
|
-
ajax[k] = v;
|
|
1122
|
-
}
|
|
1104
|
+
ajax.addEventListener(k, v);
|
|
1123
1105
|
}
|
|
1124
1106
|
}
|
|
1125
1107
|
ajax.addEventListener("load", function() {
|
|
@@ -1130,8 +1112,11 @@ function Ajax(url, opts = {}) {
|
|
|
1130
1112
|
let value = v;
|
|
1131
1113
|
if (typeof value === "object" && value && !value.name) {
|
|
1132
1114
|
value = JSON.stringify(value);
|
|
1115
|
+
formData.set(k, value);
|
|
1116
|
+
}
|
|
1117
|
+
if (typeof value === "string") {
|
|
1118
|
+
formData.set(k, value);
|
|
1133
1119
|
}
|
|
1134
|
-
formData.set(k, value);
|
|
1135
1120
|
}
|
|
1136
1121
|
}
|
|
1137
1122
|
ajax.addEventListener("error", () => {
|
|
@@ -1167,147 +1152,13 @@ function Ajax(url, opts = {}) {
|
|
|
1167
1152
|
});
|
|
1168
1153
|
}
|
|
1169
1154
|
|
|
1170
|
-
// lib/utils/Screen.ts
|
|
1171
|
-
var Screen = class {
|
|
1172
|
-
constructor(cradova_screen_initials) {
|
|
1173
|
-
this._secondaryChildren = [];
|
|
1174
|
-
this.errorHandler = null;
|
|
1175
|
-
this._packed = false;
|
|
1176
|
-
this._template = document.createElement("div");
|
|
1177
|
-
this._persist = true;
|
|
1178
|
-
this._params = null;
|
|
1179
|
-
this._delegatedRoutesCount = -1;
|
|
1180
|
-
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
1181
|
-
this._html = template2;
|
|
1182
|
-
this._name = name;
|
|
1183
|
-
this._transition = transition || "";
|
|
1184
|
-
this._template.setAttribute("id", "cradova-screen-set");
|
|
1185
|
-
if (renderInParallel === true) {
|
|
1186
|
-
this._delegatedRoutesCount = 1;
|
|
1187
|
-
} else {
|
|
1188
|
-
if (typeof persist === "boolean") {
|
|
1189
|
-
this._persist = persist;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
get _delegatedRoutes() {
|
|
1194
|
-
if (this._delegatedRoutesCount > 1e3) {
|
|
1195
|
-
return -1;
|
|
1196
|
-
}
|
|
1197
|
-
return this._delegatedRoutesCount;
|
|
1198
|
-
}
|
|
1199
|
-
set _delegatedRoutes(count) {
|
|
1200
|
-
if (count) {
|
|
1201
|
-
this._delegatedRoutesCount += 1;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
get _paramData() {
|
|
1205
|
-
return this._params;
|
|
1206
|
-
}
|
|
1207
|
-
set _paramData(params) {
|
|
1208
|
-
if (params) {
|
|
1209
|
-
this._params = params;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
setErrorHandler(errorHandler) {
|
|
1213
|
-
this.errorHandler = errorHandler;
|
|
1214
|
-
}
|
|
1215
|
-
async _package() {
|
|
1216
|
-
if (this._html.render) {
|
|
1217
|
-
this._template.innerHTML = "";
|
|
1218
|
-
this._template.appendChild(this._html.render(this._data));
|
|
1219
|
-
}
|
|
1220
|
-
if (typeof this._html === "function") {
|
|
1221
|
-
let fuc = await this._html.apply(this, this._data);
|
|
1222
|
-
if (typeof fuc === "function") {
|
|
1223
|
-
fuc = fuc();
|
|
1224
|
-
if (!isNode(fuc)) {
|
|
1225
|
-
throw new Error(
|
|
1226
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1227
|
-
);
|
|
1228
|
-
} else {
|
|
1229
|
-
if (fuc) {
|
|
1230
|
-
this._template.innerHTML = "";
|
|
1231
|
-
this._template.appendChild(fuc);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
} else {
|
|
1235
|
-
if (!isNode(fuc) && typeof fuc !== "string") {
|
|
1236
|
-
throw new Error(
|
|
1237
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1238
|
-
);
|
|
1239
|
-
} else {
|
|
1240
|
-
this._template.innerHTML = "";
|
|
1241
|
-
this._template.appendChild(fuc);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
if (!this._template.firstChild) {
|
|
1246
|
-
console.error(" \u2718 Cradova err: expected a screen but got ", this._html);
|
|
1247
|
-
throw new Error(
|
|
1248
|
-
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
if (this._secondaryChildren.length) {
|
|
1252
|
-
let i2 = 0;
|
|
1253
|
-
while (this._secondaryChildren.length - i2 !== 0) {
|
|
1254
|
-
this.template.appendChild(this._secondaryChildren[i2]);
|
|
1255
|
-
i2++;
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
onActivate(cb) {
|
|
1260
|
-
this._callBack = cb;
|
|
1261
|
-
}
|
|
1262
|
-
onDeactivate(cb) {
|
|
1263
|
-
this._deCallBack = cb;
|
|
1264
|
-
}
|
|
1265
|
-
addChild(...addOns) {
|
|
1266
|
-
this._secondaryChildren.push(frag(addOns));
|
|
1267
|
-
}
|
|
1268
|
-
async _deActivate() {
|
|
1269
|
-
if (this._deCallBack) {
|
|
1270
|
-
await this._deCallBack();
|
|
1271
|
-
}
|
|
1272
|
-
if (this._transition) {
|
|
1273
|
-
this._template.classList.remove(this._transition);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
async _Activate(force) {
|
|
1277
|
-
if (!this._persist || force) {
|
|
1278
|
-
await this._package();
|
|
1279
|
-
} else {
|
|
1280
|
-
if (!this._packed) {
|
|
1281
|
-
this._packed = true;
|
|
1282
|
-
await this._package();
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
const doc = document.querySelector("[data-wrapper=app]");
|
|
1286
|
-
if (!doc) {
|
|
1287
|
-
throw new Error(
|
|
1288
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-wrapper='app'> ... </div>"
|
|
1289
|
-
);
|
|
1290
|
-
}
|
|
1291
|
-
if (this._transition) {
|
|
1292
|
-
this._template.classList.add(this._transition);
|
|
1293
|
-
}
|
|
1294
|
-
doc.innerHTML = "";
|
|
1295
|
-
doc.appendChild(this._template);
|
|
1296
|
-
document.title = this._name;
|
|
1297
|
-
if (this._callBack) {
|
|
1298
|
-
await this._callBack();
|
|
1299
|
-
}
|
|
1300
|
-
CradovaEvent.dispatchEvent("cradovaAftermountEvent");
|
|
1301
|
-
if (window) {
|
|
1302
|
-
window.scrollTo(0, 0);
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
};
|
|
1306
|
-
|
|
1307
1155
|
// lib/index.ts
|
|
1308
1156
|
var make = function(txx) {
|
|
1309
|
-
if (
|
|
1310
|
-
|
|
1157
|
+
if (Array.isArray(txx)) {
|
|
1158
|
+
txx = txx[0];
|
|
1159
|
+
}
|
|
1160
|
+
if (typeof txx !== "string") {
|
|
1161
|
+
return [];
|
|
1311
1162
|
}
|
|
1312
1163
|
if (Array.isArray(txx)) {
|
|
1313
1164
|
txx = txx[0];
|
|
@@ -1320,36 +1171,37 @@ var make = function(txx) {
|
|
|
1320
1171
|
}
|
|
1321
1172
|
}
|
|
1322
1173
|
let tag;
|
|
1174
|
+
let teak;
|
|
1323
1175
|
if (!txx.includes("#")) {
|
|
1324
|
-
|
|
1325
|
-
tag =
|
|
1176
|
+
teak = txx.split(".");
|
|
1177
|
+
tag = teak.shift();
|
|
1326
1178
|
if (!tag) {
|
|
1327
1179
|
tag = "DIV";
|
|
1328
1180
|
}
|
|
1329
|
-
return [tag, void 0,
|
|
1181
|
+
return [tag, void 0, teak.join(" "), innerValue];
|
|
1330
1182
|
} else {
|
|
1331
1183
|
if (!txx.includes(".")) {
|
|
1332
|
-
|
|
1333
|
-
tag =
|
|
1184
|
+
teak = txx.split("#");
|
|
1185
|
+
tag = teak.shift();
|
|
1334
1186
|
if (!tag) {
|
|
1335
1187
|
tag = "DIV";
|
|
1336
1188
|
}
|
|
1337
|
-
if (
|
|
1338
|
-
|
|
1189
|
+
if (teak[0].includes(" ")) {
|
|
1190
|
+
teak = [teak[0].split(" ")[1]];
|
|
1339
1191
|
}
|
|
1340
|
-
return [tag,
|
|
1192
|
+
return [tag, teak[0], void 0, innerValue];
|
|
1341
1193
|
}
|
|
1342
1194
|
}
|
|
1343
|
-
|
|
1195
|
+
teak = txx.split(".");
|
|
1344
1196
|
const classes = [];
|
|
1345
1197
|
const IDs = [];
|
|
1346
|
-
tag = !
|
|
1198
|
+
tag = !teak[0].includes("#") && teak.shift();
|
|
1347
1199
|
if (!tag) {
|
|
1348
1200
|
tag = "DIV";
|
|
1349
1201
|
}
|
|
1350
|
-
for (let i2 = 0; i2 <
|
|
1351
|
-
if (
|
|
1352
|
-
const item =
|
|
1202
|
+
for (let i2 = 0; i2 < teak.length; i2++) {
|
|
1203
|
+
if (teak[i2].includes("#")) {
|
|
1204
|
+
const item = teak[i2].split("#");
|
|
1353
1205
|
IDs.push(item[1]);
|
|
1354
1206
|
if (i2 === 0) {
|
|
1355
1207
|
tag = item[0];
|
|
@@ -1358,47 +1210,37 @@ var make = function(txx) {
|
|
|
1358
1210
|
classes.push(item[0]);
|
|
1359
1211
|
continue;
|
|
1360
1212
|
}
|
|
1361
|
-
classes.push(
|
|
1213
|
+
classes.push(teak[i2]);
|
|
1362
1214
|
}
|
|
1363
1215
|
return [tag || "DIV", IDs[0], classes.join(" "), innerValue];
|
|
1364
1216
|
};
|
|
1365
1217
|
var _2 = (...element_initials) => {
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
if (
|
|
1375
|
-
if (
|
|
1376
|
-
props["className"] =
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
if (initials[3]) {
|
|
1389
|
-
if (props) {
|
|
1390
|
-
props["innerText"] = initials[3];
|
|
1391
|
-
} else {
|
|
1392
|
-
props = { innerText: initials[3] };
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
return makeElement(element, props, ...element_initials);
|
|
1218
|
+
const {
|
|
1219
|
+
0: tag,
|
|
1220
|
+
1: id,
|
|
1221
|
+
2: className,
|
|
1222
|
+
3: innerText
|
|
1223
|
+
} = make(element_initials[0]);
|
|
1224
|
+
let props = {};
|
|
1225
|
+
const element = tag ? document.createElement(tag) : new DocumentFragment();
|
|
1226
|
+
if (element.tagName) {
|
|
1227
|
+
if (className) {
|
|
1228
|
+
props["className"] = className;
|
|
1229
|
+
}
|
|
1230
|
+
if (id) {
|
|
1231
|
+
props["id"] = id;
|
|
1232
|
+
}
|
|
1233
|
+
if (innerText) {
|
|
1234
|
+
props["innerText"] = innerText;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
typeof tag === "string" && element_initials.shift();
|
|
1238
|
+
props && element_initials.push(props);
|
|
1239
|
+
return makeElement(element, element_initials);
|
|
1396
1240
|
};
|
|
1397
|
-
Init();
|
|
1398
1241
|
var lib_default = _2;
|
|
1399
1242
|
export {
|
|
1400
1243
|
Ajax,
|
|
1401
|
-
CradovaEvent,
|
|
1402
1244
|
Ref,
|
|
1403
1245
|
Router,
|
|
1404
1246
|
Screen,
|
|
@@ -1435,7 +1277,6 @@ export {
|
|
|
1435
1277
|
details,
|
|
1436
1278
|
dfn,
|
|
1437
1279
|
dialog,
|
|
1438
|
-
dispatch,
|
|
1439
1280
|
div,
|
|
1440
1281
|
dl,
|
|
1441
1282
|
dt,
|
|
@@ -1506,7 +1347,6 @@ export {
|
|
|
1506
1347
|
sub,
|
|
1507
1348
|
summary,
|
|
1508
1349
|
sup,
|
|
1509
|
-
svgNS,
|
|
1510
1350
|
table,
|
|
1511
1351
|
tbody,
|
|
1512
1352
|
td,
|
|
@@ -1525,4 +1365,5 @@ export {
|
|
|
1525
1365
|
video,
|
|
1526
1366
|
wbr
|
|
1527
1367
|
};
|
|
1368
|
+
//! always starts events a moment later
|
|
1528
1369
|
//! value could be a promise
|