cradova 2.3.1 → 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 +12 -11
- package/dist/index.d.ts +381 -359
- package/dist/index.js +411 -561
- 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,7 +516,110 @@ var createSignal = class {
|
|
|
600
516
|
}
|
|
601
517
|
};
|
|
602
518
|
|
|
603
|
-
// lib/
|
|
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
|
|
604
623
|
var RouterBox = {};
|
|
605
624
|
RouterBox["lastNavigatedRouteController"] = null;
|
|
606
625
|
RouterBox["nextRouteController"] = null;
|
|
@@ -608,13 +627,16 @@ RouterBox["lastNavigatedRoute"] = null;
|
|
|
608
627
|
RouterBox["pageShow"] = null;
|
|
609
628
|
RouterBox["pageHide"] = null;
|
|
610
629
|
RouterBox["errorHandler"] = null;
|
|
630
|
+
RouterBox["loadingScreen"] = {};
|
|
611
631
|
RouterBox["params"] = {};
|
|
612
632
|
RouterBox["routes"] = {};
|
|
613
633
|
RouterBox["pageevents"] = [];
|
|
614
|
-
RouterBox["start_pageevents"] = function(lastR, newR) {
|
|
615
|
-
|
|
616
|
-
RouterBox["pageevents"]
|
|
617
|
-
|
|
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);
|
|
618
640
|
};
|
|
619
641
|
var checker = (url) => {
|
|
620
642
|
if (RouterBox.routes[url]) {
|
|
@@ -627,11 +649,11 @@ var checker = (url) => {
|
|
|
627
649
|
if (!path.includes(":")) {
|
|
628
650
|
continue;
|
|
629
651
|
}
|
|
630
|
-
if (url.endsWith("/")) {
|
|
631
|
-
url = url.slice(0, path.length - 2);
|
|
632
|
-
}
|
|
633
652
|
const urlFixtures = url.split("/");
|
|
634
653
|
const pathFixtures = path.split("/");
|
|
654
|
+
if (url.endsWith("/")) {
|
|
655
|
+
urlFixtures.pop();
|
|
656
|
+
}
|
|
635
657
|
let fixturesX = 0;
|
|
636
658
|
let fixturesY = 0;
|
|
637
659
|
urlFixtures.shift();
|
|
@@ -640,11 +662,11 @@ var checker = (url) => {
|
|
|
640
662
|
const routesParams = { _path: "" };
|
|
641
663
|
for (let i2 = 0; i2 < pathFixtures.length; i2++) {
|
|
642
664
|
if (pathFixtures[i2].includes(":")) {
|
|
643
|
-
fixturesY
|
|
665
|
+
fixturesY++;
|
|
644
666
|
continue;
|
|
645
667
|
}
|
|
646
|
-
if (urlFixtures[i2] === pathFixtures[i2]
|
|
647
|
-
fixturesX
|
|
668
|
+
if (urlFixtures[i2] === pathFixtures[i2]) {
|
|
669
|
+
fixturesX++;
|
|
648
670
|
}
|
|
649
671
|
}
|
|
650
672
|
if (fixturesX + fixturesY === pathFixtures.length) {
|
|
@@ -661,30 +683,17 @@ var checker = (url) => {
|
|
|
661
683
|
return [];
|
|
662
684
|
};
|
|
663
685
|
RouterBox.route = (path, screen) => {
|
|
664
|
-
if (
|
|
665
|
-
|
|
666
|
-
|
|
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");
|
|
690
|
+
}
|
|
691
|
+
return RouterBox.routes[path] = screen;
|
|
667
692
|
}
|
|
668
|
-
|
|
669
|
-
return RouterBox.routes[path];
|
|
693
|
+
return void 0;
|
|
670
694
|
};
|
|
671
|
-
RouterBox.router = async function(
|
|
695
|
+
RouterBox.router = async function(_e, _force) {
|
|
672
696
|
let url, route, params;
|
|
673
|
-
if (e) {
|
|
674
|
-
const Alink = e.target.tagName === "A" && e.target;
|
|
675
|
-
if (Alink) {
|
|
676
|
-
if (Alink.href.includes("#")) {
|
|
677
|
-
const l = Alink.href.split("#");
|
|
678
|
-
document.getElementById("#" + l[l.length - 1])?.scrollIntoView();
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
if (Alink.href.includes("javascript")) {
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
e.preventDefault();
|
|
685
|
-
url = new URL(Alink.href).pathname;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
697
|
if (!url) {
|
|
689
698
|
url = window.location.pathname;
|
|
690
699
|
}
|
|
@@ -699,13 +708,19 @@ RouterBox.router = async function(e, force = false) {
|
|
|
699
708
|
}
|
|
700
709
|
if (typeof route !== "undefined") {
|
|
701
710
|
try {
|
|
702
|
-
if (
|
|
703
|
-
RouterBox.
|
|
704
|
-
|
|
705
|
-
|
|
711
|
+
if (typeof route === "function") {
|
|
712
|
+
if (RouterBox["LoadingScreen"] && RouterBox["LoadingScreen"]._Activate) {
|
|
713
|
+
await RouterBox["LoadingScreen"]._Activate();
|
|
714
|
+
}
|
|
706
715
|
route = await route();
|
|
716
|
+
if (!route) {
|
|
717
|
+
if (RouterBox["lastNavigatedRoute"]) {
|
|
718
|
+
history.pushState({}, url, RouterBox["lastNavigatedRoute"]);
|
|
719
|
+
}
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
707
722
|
}
|
|
708
|
-
if (route._delegatedRoutes !== -1
|
|
723
|
+
if (route._delegatedRoutes !== -1) {
|
|
709
724
|
route._delegatedRoutes = true;
|
|
710
725
|
route = new Screen({
|
|
711
726
|
name: route._name,
|
|
@@ -713,42 +728,41 @@ RouterBox.router = async function(e, force = false) {
|
|
|
713
728
|
});
|
|
714
729
|
RouterBox.routes[url] = route;
|
|
715
730
|
}
|
|
716
|
-
|
|
731
|
+
if (params) {
|
|
732
|
+
RouterBox.params.params = params;
|
|
733
|
+
}
|
|
734
|
+
await route._Activate(_force);
|
|
717
735
|
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
|
|
718
736
|
RouterBox["lastNavigatedRoute"] = url;
|
|
719
737
|
RouterBox["lastNavigatedRouteController"] = route;
|
|
720
738
|
} catch (error) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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
|
+
}
|
|
727
750
|
}
|
|
728
751
|
}
|
|
729
752
|
} else {
|
|
730
753
|
if (RouterBox.routes["/404"]) {
|
|
731
|
-
RouterBox.routes["/404"].
|
|
754
|
+
await RouterBox.routes["/404"]._Activate(_force);
|
|
732
755
|
}
|
|
733
756
|
}
|
|
734
757
|
};
|
|
735
758
|
var RouterClass = class {
|
|
736
|
-
constructor() {
|
|
737
|
-
this.getParams = function() {
|
|
738
|
-
return RouterBox["params"];
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
759
|
BrowserRoutes(obj) {
|
|
742
760
|
for (const path in obj) {
|
|
743
761
|
let screen = obj[path];
|
|
744
|
-
if (screen.
|
|
762
|
+
if (typeof screen === "object" && typeof screen.then === "function" || typeof screen === "function") {
|
|
745
763
|
RouterBox["routes"][path] = async () => {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
} else {
|
|
749
|
-
screen = await screen;
|
|
750
|
-
}
|
|
751
|
-
return RouterBox.route(path, screen.default);
|
|
764
|
+
screen = await (typeof screen === "function" ? await screen() : await screen);
|
|
765
|
+
return RouterBox.route(path, screen?.default || screen);
|
|
752
766
|
};
|
|
753
767
|
} else {
|
|
754
768
|
RouterBox.route(path, screen);
|
|
@@ -756,16 +770,18 @@ var RouterClass = class {
|
|
|
756
770
|
}
|
|
757
771
|
this._mount();
|
|
758
772
|
}
|
|
773
|
+
back() {
|
|
774
|
+
history.go(-1);
|
|
775
|
+
}
|
|
776
|
+
forward() {
|
|
777
|
+
history.go(1);
|
|
778
|
+
}
|
|
759
779
|
navigate(href, data2 = null, force = false) {
|
|
760
780
|
if (typeof href !== "string") {
|
|
761
781
|
throw new TypeError(
|
|
762
782
|
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
763
783
|
);
|
|
764
784
|
}
|
|
765
|
-
if (typeof data2 === "boolean") {
|
|
766
|
-
force = true;
|
|
767
|
-
data2 = null;
|
|
768
|
-
}
|
|
769
785
|
let route = null, params;
|
|
770
786
|
if (href.includes("://")) {
|
|
771
787
|
window.location.href = href;
|
|
@@ -777,15 +793,23 @@ var RouterClass = class {
|
|
|
777
793
|
[route, params] = checker(href);
|
|
778
794
|
if (route) {
|
|
779
795
|
RouterBox["nextRouteController"] = route;
|
|
780
|
-
RouterBox.params.params = params;
|
|
781
|
-
route._paramData = params;
|
|
782
|
-
RouterBox.params.data = data2 || null;
|
|
783
796
|
window.history.pushState({}, "", href);
|
|
784
797
|
}
|
|
798
|
+
RouterBox.params.params = params;
|
|
799
|
+
RouterBox.params.data = data2;
|
|
785
800
|
RouterBox.router(null, force);
|
|
786
801
|
RouterBox["start_pageevents"](lastR, href);
|
|
787
802
|
}
|
|
788
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
|
+
}
|
|
789
813
|
onPageEvent(callback) {
|
|
790
814
|
if (typeof callback === "function") {
|
|
791
815
|
RouterBox["pageevents"].push(callback);
|
|
@@ -809,49 +833,47 @@ var RouterClass = class {
|
|
|
809
833
|
route._package(Object.assign(data2, params || {}));
|
|
810
834
|
route._packed = true;
|
|
811
835
|
}
|
|
836
|
+
getParams() {
|
|
837
|
+
return RouterBox["params"];
|
|
838
|
+
}
|
|
812
839
|
addErrorHandler(callback) {
|
|
813
840
|
if (typeof callback === "function") {
|
|
814
841
|
RouterBox["errorHandler"] = callback;
|
|
815
842
|
} else {
|
|
816
|
-
throw new Error(
|
|
817
|
-
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
818
|
-
);
|
|
843
|
+
throw new Error(" \u2718 Cradova err: callback for event is not a function");
|
|
819
844
|
}
|
|
820
845
|
}
|
|
821
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
|
+
}
|
|
822
854
|
window.addEventListener("pageshow", RouterBox.router);
|
|
823
|
-
window.addEventListener("popstate", (
|
|
824
|
-
e.preventDefault();
|
|
855
|
+
window.addEventListener("popstate", (_e) => {
|
|
825
856
|
RouterBox.router();
|
|
826
857
|
});
|
|
827
858
|
}
|
|
828
859
|
};
|
|
829
860
|
var Router = new RouterClass();
|
|
830
861
|
|
|
831
|
-
// lib/
|
|
832
|
-
var makeElement = (element,
|
|
833
|
-
let
|
|
834
|
-
|
|
835
|
-
if (ElementChildrenAndPropertyList.length) {
|
|
862
|
+
// lib/parts/elements.ts
|
|
863
|
+
var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
864
|
+
let props = {}, text = null;
|
|
865
|
+
if (ElementChildrenAndPropertyList.length !== 0) {
|
|
836
866
|
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
837
867
|
let child = ElementChildrenAndPropertyList[i2];
|
|
838
|
-
if (child
|
|
868
|
+
if (child instanceof Ref) {
|
|
839
869
|
child = child.render();
|
|
840
870
|
}
|
|
841
871
|
if (typeof child === "function") {
|
|
842
872
|
child = child();
|
|
843
|
-
if (typeof child === "function") {
|
|
844
|
-
child = child();
|
|
845
|
-
}
|
|
846
873
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
} catch (error) {
|
|
853
|
-
console.log(element, ElementChildrenAndPropertyList);
|
|
854
|
-
console.log(error);
|
|
874
|
+
if (isNode(child)) {
|
|
875
|
+
element.appendChild(child);
|
|
876
|
+
continue;
|
|
855
877
|
}
|
|
856
878
|
if (Array.isArray(child)) {
|
|
857
879
|
element.appendChild(Rhoda(child));
|
|
@@ -862,11 +884,7 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
862
884
|
continue;
|
|
863
885
|
}
|
|
864
886
|
if (typeof child === "object") {
|
|
865
|
-
|
|
866
|
-
props = child;
|
|
867
|
-
} else {
|
|
868
|
-
props = Object.assign(props, child);
|
|
869
|
-
}
|
|
887
|
+
props = Object.assign(props, child);
|
|
870
888
|
continue;
|
|
871
889
|
}
|
|
872
890
|
if (typeof child !== "undefined") {
|
|
@@ -880,9 +898,9 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
880
898
|
return element;
|
|
881
899
|
}
|
|
882
900
|
if (typeof props === "object" && element) {
|
|
883
|
-
for (const prop
|
|
884
|
-
if (prop === "style" && typeof
|
|
885
|
-
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)) {
|
|
886
904
|
if (typeof element.style[k] !== "undefined" && k !== "src") {
|
|
887
905
|
element.style[k] = v;
|
|
888
906
|
} else {
|
|
@@ -894,95 +912,70 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
894
912
|
continue;
|
|
895
913
|
}
|
|
896
914
|
if (typeof element.style[prop] !== "undefined" && prop !== "src") {
|
|
897
|
-
element.style[prop] =
|
|
915
|
+
element.style[prop] = value;
|
|
898
916
|
continue;
|
|
899
917
|
}
|
|
900
|
-
if (prop === "text" && typeof
|
|
901
|
-
text =
|
|
918
|
+
if (prop === "text" && typeof value === "string" && value !== "") {
|
|
919
|
+
text = value;
|
|
902
920
|
continue;
|
|
903
921
|
}
|
|
904
|
-
if (prop === "
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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);
|
|
914
934
|
continue;
|
|
915
935
|
}
|
|
916
|
-
if (Array.isArray(
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
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
|
+
}
|
|
923
951
|
}
|
|
924
|
-
if (prop
|
|
925
|
-
|
|
926
|
-
|
|
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);
|
|
927
958
|
continue;
|
|
928
959
|
}
|
|
929
|
-
if (prop
|
|
930
|
-
element.
|
|
960
|
+
if (prop.includes("data-")) {
|
|
961
|
+
element.setAttribute(prop, value);
|
|
931
962
|
continue;
|
|
932
963
|
}
|
|
933
|
-
if (prop
|
|
934
|
-
|
|
935
|
-
props["afterMount"].apply(element);
|
|
936
|
-
CradovaEvent.removeEventListener("cradovaAftermountEvent", avi);
|
|
937
|
-
};
|
|
938
|
-
CradovaEvent.addEventListener("cradovaAftermountEvent", avi);
|
|
964
|
+
if (prop.includes("aria-")) {
|
|
965
|
+
element.setAttribute(prop, value);
|
|
939
966
|
continue;
|
|
940
967
|
}
|
|
941
|
-
|
|
942
|
-
if (typeof element[prop] !== "undefined") {
|
|
943
|
-
element[prop] = props[prop];
|
|
944
|
-
} else {
|
|
945
|
-
if (prop.includes("data-")) {
|
|
946
|
-
element.setAttribute(prop, props[prop]);
|
|
947
|
-
continue;
|
|
948
|
-
}
|
|
949
|
-
element[prop] = props[prop];
|
|
950
|
-
if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && prop !== "disabled" && !prop.includes("aria")) {
|
|
951
|
-
console.warn(" \u2718 Cradova err: invalid html attribute ", {
|
|
952
|
-
prop
|
|
953
|
-
});
|
|
954
|
-
} else {
|
|
955
|
-
continue;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
} catch (error) {
|
|
959
|
-
console.error(" \u2718 Cradova err: invalid html attribute ", { props });
|
|
960
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
961
|
-
}
|
|
968
|
+
element[prop] = value;
|
|
962
969
|
}
|
|
963
970
|
}
|
|
964
971
|
if (text) {
|
|
965
972
|
element.appendChild(document.createTextNode(text));
|
|
966
973
|
}
|
|
967
|
-
if (typeof beforeMount === "function") {
|
|
968
|
-
beforeMount.apply(element);
|
|
969
|
-
}
|
|
970
|
-
if (element.tagName === "A" && window) {
|
|
971
|
-
if (element.href.includes(window.location.origin)) {
|
|
972
|
-
element.addEventListener("click", (e) => {
|
|
973
|
-
e.preventDefault();
|
|
974
|
-
Router.navigate(element.pathname);
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
974
|
return element;
|
|
979
975
|
};
|
|
980
976
|
var cra = (element_initials) => {
|
|
981
977
|
return (...initials) => {
|
|
982
|
-
return makeElement(
|
|
983
|
-
document.createElement(element_initials),
|
|
984
|
-
...initials
|
|
985
|
-
);
|
|
978
|
+
return makeElement(document.createElement(element_initials), initials);
|
|
986
979
|
};
|
|
987
980
|
};
|
|
988
981
|
var a = cra("a");
|
|
@@ -1097,7 +1090,7 @@ var val = cra("val");
|
|
|
1097
1090
|
var video = cra("video");
|
|
1098
1091
|
var wbr = cra("wbr");
|
|
1099
1092
|
|
|
1100
|
-
// lib/
|
|
1093
|
+
// lib/parts/ajax.ts
|
|
1101
1094
|
function Ajax(url, opts = {}) {
|
|
1102
1095
|
const { method, data: data2, header: header2, callbacks } = opts;
|
|
1103
1096
|
if (typeof url !== "string") {
|
|
@@ -1108,9 +1101,7 @@ function Ajax(url, opts = {}) {
|
|
|
1108
1101
|
const formData = new FormData();
|
|
1109
1102
|
if (callbacks && typeof callbacks === "object") {
|
|
1110
1103
|
for (const [k, v] of Object.entries(callbacks)) {
|
|
1111
|
-
|
|
1112
|
-
ajax[k] = v;
|
|
1113
|
-
}
|
|
1104
|
+
ajax.addEventListener(k, v);
|
|
1114
1105
|
}
|
|
1115
1106
|
}
|
|
1116
1107
|
ajax.addEventListener("load", function() {
|
|
@@ -1121,8 +1112,11 @@ function Ajax(url, opts = {}) {
|
|
|
1121
1112
|
let value = v;
|
|
1122
1113
|
if (typeof value === "object" && value && !value.name) {
|
|
1123
1114
|
value = JSON.stringify(value);
|
|
1115
|
+
formData.set(k, value);
|
|
1116
|
+
}
|
|
1117
|
+
if (typeof value === "string") {
|
|
1118
|
+
formData.set(k, value);
|
|
1124
1119
|
}
|
|
1125
|
-
formData.set(k, value);
|
|
1126
1120
|
}
|
|
1127
1121
|
}
|
|
1128
1122
|
ajax.addEventListener("error", () => {
|
|
@@ -1158,147 +1152,13 @@ function Ajax(url, opts = {}) {
|
|
|
1158
1152
|
});
|
|
1159
1153
|
}
|
|
1160
1154
|
|
|
1161
|
-
// lib/utils/Screen.ts
|
|
1162
|
-
var Screen = class {
|
|
1163
|
-
constructor(cradova_screen_initials) {
|
|
1164
|
-
this._secondaryChildren = [];
|
|
1165
|
-
this.errorHandler = null;
|
|
1166
|
-
this._packed = false;
|
|
1167
|
-
this._template = document.createElement("div");
|
|
1168
|
-
this._persist = true;
|
|
1169
|
-
this._params = null;
|
|
1170
|
-
this._delegatedRoutesCount = -1;
|
|
1171
|
-
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
1172
|
-
this._html = template2;
|
|
1173
|
-
this._name = name;
|
|
1174
|
-
this._transition = transition || "";
|
|
1175
|
-
this._template.setAttribute("id", "cradova-screen-set");
|
|
1176
|
-
if (renderInParallel === true) {
|
|
1177
|
-
this._delegatedRoutesCount = 1;
|
|
1178
|
-
} else {
|
|
1179
|
-
if (typeof persist === "boolean") {
|
|
1180
|
-
this._persist = persist;
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
get _delegatedRoutes() {
|
|
1185
|
-
if (this._delegatedRoutesCount > 1e3) {
|
|
1186
|
-
return -1;
|
|
1187
|
-
}
|
|
1188
|
-
return this._delegatedRoutesCount;
|
|
1189
|
-
}
|
|
1190
|
-
set _delegatedRoutes(count) {
|
|
1191
|
-
if (count) {
|
|
1192
|
-
this._delegatedRoutesCount += 1;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
get _paramData() {
|
|
1196
|
-
return this._params;
|
|
1197
|
-
}
|
|
1198
|
-
set _paramData(params) {
|
|
1199
|
-
if (params) {
|
|
1200
|
-
this._params = params;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
setErrorHandler(errorHandler) {
|
|
1204
|
-
this.errorHandler = errorHandler;
|
|
1205
|
-
}
|
|
1206
|
-
async _package() {
|
|
1207
|
-
if (this._html.render) {
|
|
1208
|
-
this._template.innerHTML = "";
|
|
1209
|
-
this._template.appendChild(this._html.render(this._data));
|
|
1210
|
-
}
|
|
1211
|
-
if (typeof this._html === "function") {
|
|
1212
|
-
let fuc = await this._html.apply(this, this._data);
|
|
1213
|
-
if (typeof fuc === "function") {
|
|
1214
|
-
fuc = fuc();
|
|
1215
|
-
if (!isNode(fuc)) {
|
|
1216
|
-
throw new Error(
|
|
1217
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1218
|
-
);
|
|
1219
|
-
} else {
|
|
1220
|
-
if (fuc) {
|
|
1221
|
-
this._template.innerHTML = "";
|
|
1222
|
-
this._template.appendChild(fuc);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
} else {
|
|
1226
|
-
if (!isNode(fuc) && typeof fuc !== "string") {
|
|
1227
|
-
throw new Error(
|
|
1228
|
-
" \u2718 Cradova err: only parent with descendants is valid"
|
|
1229
|
-
);
|
|
1230
|
-
} else {
|
|
1231
|
-
this._template.innerHTML = "";
|
|
1232
|
-
this._template.appendChild(fuc);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
if (!this._template.firstChild) {
|
|
1237
|
-
console.error(" \u2718 Cradova err: expected a screen but got ", this._html);
|
|
1238
|
-
throw new Error(
|
|
1239
|
-
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1240
|
-
);
|
|
1241
|
-
}
|
|
1242
|
-
if (this._secondaryChildren.length) {
|
|
1243
|
-
let i2 = 0;
|
|
1244
|
-
while (this._secondaryChildren.length - i2 !== 0) {
|
|
1245
|
-
this.template.appendChild(this._secondaryChildren[i2]);
|
|
1246
|
-
i2++;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
onActivate(cb) {
|
|
1251
|
-
this._callBack = cb;
|
|
1252
|
-
}
|
|
1253
|
-
onDeactivate(cb) {
|
|
1254
|
-
this._deCallBack = cb;
|
|
1255
|
-
}
|
|
1256
|
-
addChild(...addOns) {
|
|
1257
|
-
this._secondaryChildren.push(frag(addOns));
|
|
1258
|
-
}
|
|
1259
|
-
async _deActivate() {
|
|
1260
|
-
if (this._deCallBack) {
|
|
1261
|
-
await this._deCallBack();
|
|
1262
|
-
}
|
|
1263
|
-
if (this._transition) {
|
|
1264
|
-
this._template.classList.remove(this._transition);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
async _Activate(force) {
|
|
1268
|
-
if (!this._persist || force) {
|
|
1269
|
-
await this._package();
|
|
1270
|
-
} else {
|
|
1271
|
-
if (!this._packed) {
|
|
1272
|
-
this._packed = true;
|
|
1273
|
-
await this._package();
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
const doc = document.querySelector("[data-wrapper=app]");
|
|
1277
|
-
if (!doc) {
|
|
1278
|
-
throw new Error(
|
|
1279
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-wrapper='app'> ... </div>"
|
|
1280
|
-
);
|
|
1281
|
-
}
|
|
1282
|
-
if (this._transition) {
|
|
1283
|
-
this._template.classList.add(this._transition);
|
|
1284
|
-
}
|
|
1285
|
-
doc.innerHTML = "";
|
|
1286
|
-
doc.appendChild(this._template);
|
|
1287
|
-
document.title = this._name;
|
|
1288
|
-
if (this._callBack) {
|
|
1289
|
-
await this._callBack();
|
|
1290
|
-
}
|
|
1291
|
-
CradovaEvent.dispatchEvent("cradovaAftermountEvent");
|
|
1292
|
-
if (window) {
|
|
1293
|
-
window.scrollTo(0, 0);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
};
|
|
1297
|
-
|
|
1298
1155
|
// lib/index.ts
|
|
1299
1156
|
var make = function(txx) {
|
|
1300
|
-
if (
|
|
1301
|
-
|
|
1157
|
+
if (Array.isArray(txx)) {
|
|
1158
|
+
txx = txx[0];
|
|
1159
|
+
}
|
|
1160
|
+
if (typeof txx !== "string") {
|
|
1161
|
+
return [];
|
|
1302
1162
|
}
|
|
1303
1163
|
if (Array.isArray(txx)) {
|
|
1304
1164
|
txx = txx[0];
|
|
@@ -1311,36 +1171,37 @@ var make = function(txx) {
|
|
|
1311
1171
|
}
|
|
1312
1172
|
}
|
|
1313
1173
|
let tag;
|
|
1174
|
+
let teak;
|
|
1314
1175
|
if (!txx.includes("#")) {
|
|
1315
|
-
|
|
1316
|
-
tag =
|
|
1176
|
+
teak = txx.split(".");
|
|
1177
|
+
tag = teak.shift();
|
|
1317
1178
|
if (!tag) {
|
|
1318
1179
|
tag = "DIV";
|
|
1319
1180
|
}
|
|
1320
|
-
return [tag, void 0,
|
|
1181
|
+
return [tag, void 0, teak.join(" "), innerValue];
|
|
1321
1182
|
} else {
|
|
1322
1183
|
if (!txx.includes(".")) {
|
|
1323
|
-
|
|
1324
|
-
tag =
|
|
1184
|
+
teak = txx.split("#");
|
|
1185
|
+
tag = teak.shift();
|
|
1325
1186
|
if (!tag) {
|
|
1326
1187
|
tag = "DIV";
|
|
1327
1188
|
}
|
|
1328
|
-
if (
|
|
1329
|
-
|
|
1189
|
+
if (teak[0].includes(" ")) {
|
|
1190
|
+
teak = [teak[0].split(" ")[1]];
|
|
1330
1191
|
}
|
|
1331
|
-
return [tag,
|
|
1192
|
+
return [tag, teak[0], void 0, innerValue];
|
|
1332
1193
|
}
|
|
1333
1194
|
}
|
|
1334
|
-
|
|
1195
|
+
teak = txx.split(".");
|
|
1335
1196
|
const classes = [];
|
|
1336
1197
|
const IDs = [];
|
|
1337
|
-
tag = !
|
|
1198
|
+
tag = !teak[0].includes("#") && teak.shift();
|
|
1338
1199
|
if (!tag) {
|
|
1339
1200
|
tag = "DIV";
|
|
1340
1201
|
}
|
|
1341
|
-
for (let i2 = 0; i2 <
|
|
1342
|
-
if (
|
|
1343
|
-
const item =
|
|
1202
|
+
for (let i2 = 0; i2 < teak.length; i2++) {
|
|
1203
|
+
if (teak[i2].includes("#")) {
|
|
1204
|
+
const item = teak[i2].split("#");
|
|
1344
1205
|
IDs.push(item[1]);
|
|
1345
1206
|
if (i2 === 0) {
|
|
1346
1207
|
tag = item[0];
|
|
@@ -1349,47 +1210,37 @@ var make = function(txx) {
|
|
|
1349
1210
|
classes.push(item[0]);
|
|
1350
1211
|
continue;
|
|
1351
1212
|
}
|
|
1352
|
-
classes.push(
|
|
1213
|
+
classes.push(teak[i2]);
|
|
1353
1214
|
}
|
|
1354
1215
|
return [tag || "DIV", IDs[0], classes.join(" "), innerValue];
|
|
1355
1216
|
};
|
|
1356
1217
|
var _2 = (...element_initials) => {
|
|
1357
|
-
const
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (
|
|
1366
|
-
if (
|
|
1367
|
-
props["className"] =
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (initials[3]) {
|
|
1380
|
-
if (props) {
|
|
1381
|
-
props["innerText"] = initials[3];
|
|
1382
|
-
} else {
|
|
1383
|
-
props = { innerText: initials[3] };
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
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);
|
|
1387
1240
|
};
|
|
1388
|
-
Init();
|
|
1389
1241
|
var lib_default = _2;
|
|
1390
1242
|
export {
|
|
1391
1243
|
Ajax,
|
|
1392
|
-
CradovaEvent,
|
|
1393
1244
|
Ref,
|
|
1394
1245
|
Router,
|
|
1395
1246
|
Screen,
|
|
@@ -1426,7 +1277,6 @@ export {
|
|
|
1426
1277
|
details,
|
|
1427
1278
|
dfn,
|
|
1428
1279
|
dialog,
|
|
1429
|
-
dispatch,
|
|
1430
1280
|
div,
|
|
1431
1281
|
dl,
|
|
1432
1282
|
dt,
|
|
@@ -1497,7 +1347,6 @@ export {
|
|
|
1497
1347
|
sub,
|
|
1498
1348
|
summary,
|
|
1499
1349
|
sup,
|
|
1500
|
-
svgNS,
|
|
1501
1350
|
table,
|
|
1502
1351
|
tbody,
|
|
1503
1352
|
td,
|
|
@@ -1516,4 +1365,5 @@ export {
|
|
|
1516
1365
|
video,
|
|
1517
1366
|
wbr
|
|
1518
1367
|
};
|
|
1368
|
+
//! always starts events a moment later
|
|
1519
1369
|
//! value could be a promise
|