cradova 2.2.2 → 2.3.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 +276 -110
- package/dist/index.js +302 -298
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,135 +1,56 @@
|
|
|
1
1
|
// lib/utils/init.ts
|
|
2
2
|
var Init = function() {
|
|
3
|
-
if (!document.querySelector("[data-
|
|
3
|
+
if (!document.querySelector("[data-wrapper=app]")) {
|
|
4
4
|
const Wrapper = document.createElement("div");
|
|
5
|
-
Wrapper.setAttribute("data-
|
|
5
|
+
Wrapper.setAttribute("data-wrapper", "app");
|
|
6
6
|
document.body.appendChild(Wrapper);
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
// lib/utils/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
// lib/utils/fns.ts
|
|
11
|
+
var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
|
|
12
|
+
var cradovaEvent = class {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.listeners = {};
|
|
15
|
+
}
|
|
16
|
+
addEventListener(eventName, callback) {
|
|
17
|
+
if (!this.listeners[eventName]) {
|
|
18
|
+
this.listeners[eventName] = [];
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error(
|
|
25
|
-
"\u2718 Cradova err : " + k + " is not a valid css style property"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (typeof element[key] === "function") {
|
|
32
|
-
if (key.startsWith("on")) {
|
|
33
|
-
element[key] = state[key];
|
|
34
|
-
} else {
|
|
35
|
-
element[key].apply(element);
|
|
36
|
-
}
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (key === "text") {
|
|
40
|
-
element.innerText = state[key];
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (key === "remove") {
|
|
44
|
-
if (element.parentElement) {
|
|
45
|
-
element.parentElement?.removeChild(element);
|
|
46
|
-
} else {
|
|
47
|
-
element.remove();
|
|
48
|
-
}
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (key.includes("$")) {
|
|
52
|
-
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (key === "tree") {
|
|
56
|
-
element.innerHTML = "";
|
|
57
|
-
element.appendChild(frag(state[key]));
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
if (typeof element[key] !== "undefined") {
|
|
62
|
-
element[key] = state[key];
|
|
63
|
-
} else {
|
|
64
|
-
element[key] = state[key];
|
|
65
|
-
if (key !== "for" && key !== "text" && key !== "class" && key !== "tabindex" && key !== "disabled" && !key.includes("aria")) {
|
|
66
|
-
console.error(" \u2718 Cradova err: invalid html attribute " + key);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
71
|
-
console.error(" \u2718 Cradova err: ", error);
|
|
72
|
-
}
|
|
20
|
+
this.listeners[eventName].push(callback);
|
|
21
|
+
}
|
|
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);
|
|
73
27
|
}
|
|
74
|
-
} else {
|
|
75
|
-
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
76
28
|
}
|
|
77
29
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
let updated = void 0;
|
|
85
|
-
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
86
|
-
for (const [id, eachState] of Object.entries(stateID)) {
|
|
87
|
-
const elements = document.querySelectorAll(
|
|
88
|
-
"[data-cra-id=" + id + "]"
|
|
89
|
-
);
|
|
90
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
91
|
-
cradovaDispatchTrack(elements, eachState);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
if (typeof stateID === "string") {
|
|
95
|
-
const elements = document.querySelectorAll(
|
|
96
|
-
"[data-cra-id=" + stateID + "]"
|
|
97
|
-
);
|
|
98
|
-
if (elements.length) {
|
|
99
|
-
updated = elements.length === 1 ? elements[0] : elements;
|
|
100
|
-
if (!state?.cradovaDispatchTrackBreak) {
|
|
101
|
-
cradovaDispatchTrack(elements, state);
|
|
102
|
-
}
|
|
30
|
+
dispatchEvent(eventName, eventArgs) {
|
|
31
|
+
const eventListeners = this.listeners[eventName];
|
|
32
|
+
if (eventListeners) {
|
|
33
|
+
for (let i2 = 0; i2 < eventListeners.length; i2++) {
|
|
34
|
+
eventListeners[i2](eventArgs);
|
|
103
35
|
}
|
|
104
36
|
}
|
|
105
|
-
if (ele) {
|
|
106
|
-
cradovaDispatchTrack([ele], state);
|
|
107
|
-
}
|
|
108
37
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// lib/utils/fns.ts
|
|
113
|
-
var isNode = (node) => typeof node === "object" && typeof node.nodeType === "number";
|
|
114
|
-
var cradovaAftermountEvent = new CustomEvent("cradova-aftermount");
|
|
115
|
-
function uuid() {
|
|
116
|
-
let t = Date.now ? +Date.now() : +new Date();
|
|
117
|
-
return "cradova-id-xxxxxx".replace(/[x]/g, function(e) {
|
|
118
|
-
const r = (t + 16 * Math.random()) % 16 | 0;
|
|
119
|
-
return ("x" === e ? r : 7 & r | 8).toString(16);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
38
|
+
};
|
|
39
|
+
var CradovaEvent = new cradovaEvent();
|
|
122
40
|
function Rhoda(l) {
|
|
123
41
|
const fg = new DocumentFragment();
|
|
124
42
|
for (let ch of l) {
|
|
125
43
|
if (Array.isArray(ch)) {
|
|
126
44
|
fg.appendChild(Rhoda(ch));
|
|
127
45
|
} else {
|
|
128
|
-
if (
|
|
129
|
-
ch = ch();
|
|
46
|
+
if (ch?.render) {
|
|
47
|
+
ch = ch.render();
|
|
130
48
|
}
|
|
131
49
|
if (typeof ch === "function") {
|
|
132
50
|
ch = ch();
|
|
51
|
+
if (typeof ch === "function") {
|
|
52
|
+
ch = ch();
|
|
53
|
+
}
|
|
133
54
|
}
|
|
134
55
|
if (typeof ch === "string" || typeof ch === "number") {
|
|
135
56
|
fg.appendChild(document.createTextNode(ch));
|
|
@@ -148,45 +69,20 @@ function Rhoda(l) {
|
|
|
148
69
|
}
|
|
149
70
|
return fg;
|
|
150
71
|
}
|
|
151
|
-
function css(identifier
|
|
152
|
-
if (
|
|
72
|
+
function css(identifier) {
|
|
73
|
+
if (Array.isArray(identifier)) {
|
|
74
|
+
identifier = identifier[0];
|
|
75
|
+
}
|
|
76
|
+
if (typeof identifier === "string") {
|
|
153
77
|
let styTag = document.querySelector("style");
|
|
154
78
|
if (styTag !== null) {
|
|
155
|
-
identifier
|
|
156
|
-
styTag.textContent = identifier;
|
|
79
|
+
styTag.textContent = identifier + styTag.textContent;
|
|
157
80
|
return;
|
|
158
81
|
}
|
|
159
82
|
styTag = document.createElement("style");
|
|
160
83
|
styTag.textContent = identifier;
|
|
161
84
|
document.head.appendChild(styTag);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (!properties) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const styS = "" + identifier + `{
|
|
168
|
-
`;
|
|
169
|
-
const styE = `}
|
|
170
|
-
`;
|
|
171
|
-
let style2 = "", totalStyle = "";
|
|
172
|
-
for (const [k, v] of Object.entries(properties)) {
|
|
173
|
-
style2 += "" + k + ": " + v + `;
|
|
174
|
-
`;
|
|
175
|
-
}
|
|
176
|
-
let styleTag = document.querySelector("style");
|
|
177
|
-
if (styleTag !== null) {
|
|
178
|
-
totalStyle += styleTag.innerHTML;
|
|
179
|
-
totalStyle += styS + style2 + styE;
|
|
180
|
-
styleTag.innerHTML = totalStyle;
|
|
181
|
-
return;
|
|
182
85
|
}
|
|
183
|
-
styleTag = document.createElement("style");
|
|
184
|
-
totalStyle += styleTag.innerHTML + `
|
|
185
|
-
|
|
186
|
-
`;
|
|
187
|
-
totalStyle += styS + style2 + styE;
|
|
188
|
-
styleTag.innerHTML = totalStyle;
|
|
189
|
-
document.head.appendChild(styleTag);
|
|
190
86
|
}
|
|
191
87
|
function assert(condition, ...elements) {
|
|
192
88
|
if (condition) {
|
|
@@ -210,28 +106,28 @@ function assertOr(condition, ifTrue, ifFalse) {
|
|
|
210
106
|
}
|
|
211
107
|
var Ref = class {
|
|
212
108
|
constructor(component) {
|
|
213
|
-
this.stateID = uuid();
|
|
214
109
|
this.effects = [];
|
|
215
110
|
this.effectuate = null;
|
|
216
111
|
this.rendered = false;
|
|
217
112
|
this.published = false;
|
|
218
113
|
this.hasFirstStateUpdateRun = false;
|
|
219
114
|
this.preRendered = null;
|
|
115
|
+
this.reference = new reference();
|
|
220
116
|
this.component = component.bind(this);
|
|
221
117
|
}
|
|
222
118
|
preRender(data2) {
|
|
223
119
|
const chtml = this.component(data2);
|
|
224
120
|
if (chtml instanceof HTMLElement) {
|
|
225
|
-
chtml.setAttribute("data-cra-id", this.stateID);
|
|
226
121
|
this.preRendered = chtml;
|
|
227
122
|
} else {
|
|
228
|
-
this.preRendered = chtml(
|
|
123
|
+
this.preRendered = chtml();
|
|
229
124
|
}
|
|
230
|
-
if (
|
|
125
|
+
if (!this.preRendered) {
|
|
231
126
|
throw new Error(
|
|
232
|
-
" \u2718 Cradova err : Invalid component type for cradova Ref
|
|
127
|
+
" \u2718 Cradova err : Invalid component type for cradova Ref got - " + this.preRendered
|
|
233
128
|
);
|
|
234
129
|
}
|
|
130
|
+
this.reference._appendDomForce("reference", this.preRendered);
|
|
235
131
|
}
|
|
236
132
|
destroyPreRendered() {
|
|
237
133
|
this.preRendered = null;
|
|
@@ -244,12 +140,11 @@ var Ref = class {
|
|
|
244
140
|
if (!this.preRendered) {
|
|
245
141
|
const chtml = this.component(data2);
|
|
246
142
|
if (chtml instanceof HTMLElement) {
|
|
247
|
-
chtml.setAttribute("data-cra-id", this.stateID);
|
|
248
143
|
element = chtml;
|
|
249
144
|
} else {
|
|
250
|
-
element = chtml(
|
|
145
|
+
element = chtml();
|
|
251
146
|
}
|
|
252
|
-
if (
|
|
147
|
+
if (!element) {
|
|
253
148
|
throw new Error(
|
|
254
149
|
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
|
|
255
150
|
);
|
|
@@ -260,21 +155,23 @@ var Ref = class {
|
|
|
260
155
|
}
|
|
261
156
|
const av = async () => {
|
|
262
157
|
await this.effector.apply(this);
|
|
263
|
-
|
|
158
|
+
CradovaEvent.removeEventListener("cradovaAftermountEvent", av);
|
|
264
159
|
};
|
|
265
|
-
|
|
160
|
+
CradovaEvent.addEventListener("cradovaAftermountEvent", av);
|
|
266
161
|
this.effector();
|
|
267
162
|
this.published = true;
|
|
268
163
|
this.rendered = true;
|
|
269
164
|
if (!element) {
|
|
270
165
|
element = this.preRendered;
|
|
271
166
|
}
|
|
167
|
+
this.reference._appendDomForce("reference", element);
|
|
272
168
|
return element;
|
|
273
169
|
}
|
|
274
170
|
instance() {
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
171
|
+
return this.reference.reference;
|
|
172
|
+
}
|
|
173
|
+
_setExtra(Extra) {
|
|
174
|
+
this.Signal = Extra;
|
|
278
175
|
}
|
|
279
176
|
effect(fn) {
|
|
280
177
|
if (!this.rendered) {
|
|
@@ -320,34 +217,38 @@ var Ref = class {
|
|
|
320
217
|
return;
|
|
321
218
|
}
|
|
322
219
|
this.published = false;
|
|
323
|
-
|
|
324
|
-
cradovaDispatchTrackBreak: true
|
|
325
|
-
});
|
|
326
|
-
if (!guy) {
|
|
220
|
+
if (!this.reference.reference) {
|
|
327
221
|
return;
|
|
328
222
|
}
|
|
329
223
|
const chtml = this.component(data2);
|
|
330
224
|
let element;
|
|
331
225
|
if (chtml instanceof HTMLElement) {
|
|
332
|
-
chtml.setAttribute("data-cra-id", this.stateID);
|
|
333
226
|
element = chtml;
|
|
334
227
|
} else {
|
|
335
|
-
element = chtml(
|
|
228
|
+
element = chtml();
|
|
229
|
+
}
|
|
230
|
+
if (!element) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
" \u2718 Cradova err : Invalid component type for cradova Ref, got - " + element
|
|
233
|
+
);
|
|
336
234
|
}
|
|
337
235
|
try {
|
|
338
|
-
|
|
339
|
-
if (
|
|
340
|
-
|
|
236
|
+
this.reference.reference.insertAdjacentElement("beforebegin", element);
|
|
237
|
+
if (this.reference.reference.parentElement) {
|
|
238
|
+
this.reference.reference.parentElement.removeChild(
|
|
239
|
+
this.reference.reference
|
|
240
|
+
);
|
|
341
241
|
} else {
|
|
342
|
-
|
|
242
|
+
this.reference.reference.remove();
|
|
343
243
|
}
|
|
244
|
+
this.reference._appendDomForce("reference", element);
|
|
344
245
|
} catch (e0) {
|
|
345
246
|
console.error(e0);
|
|
346
247
|
}
|
|
347
248
|
this.published = true;
|
|
348
249
|
}
|
|
349
250
|
remove() {
|
|
350
|
-
|
|
251
|
+
this.reference.reference.remove();
|
|
351
252
|
}
|
|
352
253
|
};
|
|
353
254
|
var frag = function(children) {
|
|
@@ -368,10 +269,8 @@ var frag = function(children) {
|
|
|
368
269
|
par.appendChild(document.createTextNode(a2));
|
|
369
270
|
continue;
|
|
370
271
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
374
|
-
}
|
|
272
|
+
console.error(" \u2718 Cradova err: wrong element type" + a2);
|
|
273
|
+
throw new TypeError(" \u2718 Cradova err: invalid element");
|
|
375
274
|
}
|
|
376
275
|
return par;
|
|
377
276
|
};
|
|
@@ -410,6 +309,121 @@ var lazy = class {
|
|
|
410
309
|
this.content = this.content.default;
|
|
411
310
|
}
|
|
412
311
|
};
|
|
312
|
+
var reference = class {
|
|
313
|
+
bindAs(name) {
|
|
314
|
+
return [this, name];
|
|
315
|
+
}
|
|
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
|
+
_appendDomForce(name, Element) {
|
|
328
|
+
this[name] = Element;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// lib/utils/track.ts
|
|
333
|
+
function cradovaDispatchTrack(nodes, state) {
|
|
334
|
+
for (let i2 = 0; i2 < nodes.length; i2++) {
|
|
335
|
+
const element = nodes[i2];
|
|
336
|
+
if (!element) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
340
|
+
for (const key in state) {
|
|
341
|
+
if (key === "style") {
|
|
342
|
+
for (const [k, v] of Object.entries(state[key])) {
|
|
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];
|
|
373
|
+
} else {
|
|
374
|
+
if (key.includes("data-")) {
|
|
375
|
+
element.setAttribute(key, state[key]);
|
|
376
|
+
continue;
|
|
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
|
+
}
|
|
383
|
+
}
|
|
384
|
+
} catch (error) {
|
|
385
|
+
console.error(" \u2718 Cradova err: Cradova got ", state);
|
|
386
|
+
console.error(" \u2718 Cradova err: ", error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
console.log(nodes, state);
|
|
391
|
+
throw new TypeError(" \u2718 Cradova err: invalid state object" + state);
|
|
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);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (ele) {
|
|
422
|
+
cradovaDispatchTrack([ele], state);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return updated;
|
|
426
|
+
}
|
|
413
427
|
|
|
414
428
|
// lib/utils/createSignal.ts
|
|
415
429
|
var createSignal = class {
|
|
@@ -474,9 +488,9 @@ var createSignal = class {
|
|
|
474
488
|
this.actions[key] = action;
|
|
475
489
|
} else {
|
|
476
490
|
if (typeof key === "object" && !action) {
|
|
477
|
-
for (const [nam,
|
|
478
|
-
if (typeof nam === "string" && typeof
|
|
479
|
-
this.actions[nam] =
|
|
491
|
+
for (const [nam, act] of Object.entries(key)) {
|
|
492
|
+
if (typeof nam === "string" && typeof action === "function") {
|
|
493
|
+
this.actions[nam] = act;
|
|
480
494
|
} else {
|
|
481
495
|
throw new Error(`\u2718 Cradova err : can't create action ${nam}`);
|
|
482
496
|
}
|
|
@@ -487,14 +501,13 @@ var createSignal = class {
|
|
|
487
501
|
}
|
|
488
502
|
}
|
|
489
503
|
fireAction(key, data2) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
this.
|
|
504
|
+
this._updateState(key, data2);
|
|
505
|
+
if (this.actions[key] && this.actions[key].updateState) {
|
|
506
|
+
this.actions[key].updateState(data2);
|
|
493
507
|
return;
|
|
494
508
|
} else {
|
|
495
509
|
if (typeof this.actions[key] === "function") {
|
|
496
|
-
this.actions[key](this
|
|
497
|
-
this._updateState(key, data2);
|
|
510
|
+
this.actions[key].bind(this)(data2);
|
|
498
511
|
return;
|
|
499
512
|
}
|
|
500
513
|
}
|
|
@@ -550,13 +563,20 @@ var createSignal = class {
|
|
|
550
563
|
ent.ref.updateState(this.value[ent._signalProperty]);
|
|
551
564
|
continue;
|
|
552
565
|
}
|
|
566
|
+
if (!ent._element_property && !ent._signalProperty) {
|
|
567
|
+
ent.ref.updateState(this.value);
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
553
570
|
}
|
|
554
571
|
}
|
|
555
572
|
}
|
|
556
|
-
bindRef(ref, binding) {
|
|
573
|
+
bindRef(ref, binding = { signalProperty: "", _element_property: "" }) {
|
|
557
574
|
if (ref.render) {
|
|
558
575
|
ref.render = ref.render.bind(ref, this.value);
|
|
559
576
|
}
|
|
577
|
+
if (ref._setExtra) {
|
|
578
|
+
ref._setExtra(this);
|
|
579
|
+
}
|
|
560
580
|
if (ref && ref.updateState) {
|
|
561
581
|
this.ref.push({
|
|
562
582
|
ref,
|
|
@@ -591,6 +611,12 @@ RouterBox["pageHide"] = null;
|
|
|
591
611
|
RouterBox["errorHandler"] = null;
|
|
592
612
|
RouterBox["params"] = {};
|
|
593
613
|
RouterBox["routes"] = {};
|
|
614
|
+
RouterBox["pageevents"] = [];
|
|
615
|
+
RouterBox["start_pageevents"] = function(lastR, newR) {
|
|
616
|
+
for (let ci = 0; ci < RouterBox["pageevents"].length; ci++) {
|
|
617
|
+
RouterBox["pageevents"][ci](lastR, newR);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
594
620
|
var checker = (url) => {
|
|
595
621
|
if (RouterBox.routes[url]) {
|
|
596
622
|
return [RouterBox.routes[url], { path: url }];
|
|
@@ -686,11 +712,12 @@ Router.navigate = function(href, data2 = null, force = false) {
|
|
|
686
712
|
force = true;
|
|
687
713
|
data2 = null;
|
|
688
714
|
}
|
|
689
|
-
let route = null, params
|
|
715
|
+
let route = null, params;
|
|
690
716
|
if (href.includes("://")) {
|
|
691
717
|
window.location.href = href;
|
|
692
718
|
} else {
|
|
693
|
-
|
|
719
|
+
const lastR = window.location.pathname;
|
|
720
|
+
if (href === lastR) {
|
|
694
721
|
return;
|
|
695
722
|
}
|
|
696
723
|
[route, params] = checker(href);
|
|
@@ -699,11 +726,10 @@ Router.navigate = function(href, data2 = null, force = false) {
|
|
|
699
726
|
RouterBox.params.params = params;
|
|
700
727
|
route._paramData = params;
|
|
701
728
|
RouterBox.params.data = data2 || null;
|
|
702
|
-
|
|
703
|
-
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
704
|
-
window.history.pushState({}, "", link2);
|
|
729
|
+
window.history.pushState({}, "", href);
|
|
705
730
|
}
|
|
706
731
|
RouterBox.router(null, force);
|
|
732
|
+
RouterBox["start_pageevents"](lastR, href);
|
|
707
733
|
}
|
|
708
734
|
};
|
|
709
735
|
RouterBox.router = async function(e, force = false) {
|
|
@@ -755,9 +781,11 @@ RouterBox.router = async function(e, force = false) {
|
|
|
755
781
|
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"]._deActivate();
|
|
756
782
|
RouterBox["lastNavigatedRoute"] = url;
|
|
757
783
|
RouterBox["lastNavigatedRouteController"] = route;
|
|
758
|
-
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
759
784
|
} catch (error) {
|
|
760
|
-
|
|
785
|
+
let errorHandler;
|
|
786
|
+
if (RouterBox.routes[RouterBox.params.params._path]) {
|
|
787
|
+
errorHandler = RouterBox.routes[RouterBox.params.params._path].errorHandler || RouterBox.errorHandler;
|
|
788
|
+
}
|
|
761
789
|
if (errorHandler) {
|
|
762
790
|
errorHandler(error);
|
|
763
791
|
}
|
|
@@ -765,34 +793,19 @@ RouterBox.router = async function(e, force = false) {
|
|
|
765
793
|
} else {
|
|
766
794
|
if (RouterBox.routes["/404"]) {
|
|
767
795
|
RouterBox.routes["/404"].controller();
|
|
768
|
-
} else {
|
|
769
|
-
if (Object.keys(RouterBox.routes).length > 0) {
|
|
770
|
-
console.error(
|
|
771
|
-
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
796
|
}
|
|
775
797
|
}
|
|
776
798
|
};
|
|
777
|
-
Router["
|
|
799
|
+
Router["onPageEvent"] = function(callback) {
|
|
778
800
|
if (typeof callback === "function") {
|
|
779
|
-
RouterBox["
|
|
801
|
+
RouterBox["pageevents"].push(callback);
|
|
780
802
|
} else {
|
|
781
803
|
throw new Error(
|
|
782
804
|
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
783
805
|
);
|
|
784
806
|
}
|
|
785
807
|
};
|
|
786
|
-
Router
|
|
787
|
-
if (typeof callback === "function") {
|
|
788
|
-
RouterBox["pageHide"] = callback;
|
|
789
|
-
} else {
|
|
790
|
-
throw new Error(
|
|
791
|
-
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
Router.packageScreen = async function(path, data2) {
|
|
808
|
+
Router.packageScreen = async function(path, data2 = {}) {
|
|
796
809
|
if (!RouterBox.routes[path]) {
|
|
797
810
|
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
798
811
|
throw new Error(" \u2718 Cradova err: cradova err: Not a defined screen path");
|
|
@@ -824,13 +837,16 @@ Router.mount = () => {
|
|
|
824
837
|
});
|
|
825
838
|
};
|
|
826
839
|
|
|
827
|
-
// lib/utils/
|
|
840
|
+
// lib/utils/elements.ts
|
|
828
841
|
var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
829
842
|
let beforeMount = null;
|
|
830
843
|
let props = null, text = null;
|
|
831
844
|
if (ElementChildrenAndPropertyList.length) {
|
|
832
845
|
for (let i2 = 0; i2 < ElementChildrenAndPropertyList.length; i2++) {
|
|
833
846
|
let child = ElementChildrenAndPropertyList[i2];
|
|
847
|
+
if (child?.render) {
|
|
848
|
+
child = child.render();
|
|
849
|
+
}
|
|
834
850
|
if (typeof child === "function") {
|
|
835
851
|
child = child();
|
|
836
852
|
if (typeof child === "function") {
|
|
@@ -914,16 +930,21 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
914
930
|
});
|
|
915
931
|
continue;
|
|
916
932
|
}
|
|
933
|
+
if (prop == "reference" && Array.isArray(props[prop]) && props[prop][0] instanceof reference) {
|
|
934
|
+
element.updateState = dispatch.bind(null, element);
|
|
935
|
+
props[prop][0]._appendDom(props[prop][1], element);
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
917
938
|
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
918
939
|
element.updateState = dispatch.bind(void 0, element);
|
|
919
940
|
continue;
|
|
920
941
|
}
|
|
921
942
|
if (prop === "afterMount" && typeof props["afterMount"] === "function") {
|
|
922
|
-
const
|
|
943
|
+
const avi = () => {
|
|
923
944
|
props["afterMount"].apply(element);
|
|
924
|
-
|
|
945
|
+
CradovaEvent.removeEventListener("cradovaAftermountEvent", avi);
|
|
925
946
|
};
|
|
926
|
-
|
|
947
|
+
CradovaEvent.addEventListener("cradovaAftermountEvent", avi);
|
|
927
948
|
continue;
|
|
928
949
|
}
|
|
929
950
|
try {
|
|
@@ -955,7 +976,7 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
955
976
|
if (typeof beforeMount === "function") {
|
|
956
977
|
beforeMount.apply(element);
|
|
957
978
|
}
|
|
958
|
-
if (element.tagName === "A") {
|
|
979
|
+
if (element.tagName === "A" && window) {
|
|
959
980
|
if (element.href.includes(window.location.origin)) {
|
|
960
981
|
element.addEventListener("click", (e) => {
|
|
961
982
|
e.preventDefault();
|
|
@@ -966,10 +987,10 @@ var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|
|
|
966
987
|
return element;
|
|
967
988
|
};
|
|
968
989
|
var cra = (element_initials) => {
|
|
969
|
-
return (...
|
|
990
|
+
return (...initials) => {
|
|
970
991
|
return makeElement(
|
|
971
992
|
document.createElement(element_initials),
|
|
972
|
-
...
|
|
993
|
+
...initials
|
|
973
994
|
);
|
|
974
995
|
};
|
|
975
996
|
};
|
|
@@ -1039,7 +1060,6 @@ var menu = cra("menu");
|
|
|
1039
1060
|
var meta = cra("meta");
|
|
1040
1061
|
var meter = cra("meter");
|
|
1041
1062
|
var nav = cra("nav");
|
|
1042
|
-
var noscript = cra("noscript");
|
|
1043
1063
|
var object = cra("object");
|
|
1044
1064
|
var ol = cra("ol");
|
|
1045
1065
|
var optgroup = cra("optgroup");
|
|
@@ -1158,12 +1178,6 @@ var Screen = class {
|
|
|
1158
1178
|
this._params = null;
|
|
1159
1179
|
this._delegatedRoutesCount = -1;
|
|
1160
1180
|
const { template: template2, name, persist, renderInParallel, transition } = cradova_screen_initials;
|
|
1161
|
-
if (typeof template2 !== "function") {
|
|
1162
|
-
console.error(" \u2718 Cradova err: expected a screen but got ", template2);
|
|
1163
|
-
throw new Error(
|
|
1164
|
-
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
1181
|
this._html = template2;
|
|
1168
1182
|
this._name = name;
|
|
1169
1183
|
this._transition = transition || "";
|
|
@@ -1199,6 +1213,10 @@ var Screen = class {
|
|
|
1199
1213
|
this.errorHandler = errorHandler;
|
|
1200
1214
|
}
|
|
1201
1215
|
async _package() {
|
|
1216
|
+
if (this._html.render) {
|
|
1217
|
+
this._template.innerHTML = "";
|
|
1218
|
+
this._template.appendChild(this._html.render(this._data));
|
|
1219
|
+
}
|
|
1202
1220
|
if (typeof this._html === "function") {
|
|
1203
1221
|
let fuc = await this._html.apply(this, this._data);
|
|
1204
1222
|
if (typeof fuc === "function") {
|
|
@@ -1225,8 +1243,9 @@ var Screen = class {
|
|
|
1225
1243
|
}
|
|
1226
1244
|
}
|
|
1227
1245
|
if (!this._template.firstChild) {
|
|
1246
|
+
console.error(" \u2718 Cradova err: expected a screen but got ", this._html);
|
|
1228
1247
|
throw new Error(
|
|
1229
|
-
" \u2718 Cradova err:
|
|
1248
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
1230
1249
|
);
|
|
1231
1250
|
}
|
|
1232
1251
|
if (this._secondaryChildren.length) {
|
|
@@ -1263,10 +1282,10 @@ var Screen = class {
|
|
|
1263
1282
|
await this._package();
|
|
1264
1283
|
}
|
|
1265
1284
|
}
|
|
1266
|
-
const doc = document.querySelector("[data-
|
|
1285
|
+
const doc = document.querySelector("[data-wrapper=app]");
|
|
1267
1286
|
if (!doc) {
|
|
1268
1287
|
throw new Error(
|
|
1269
|
-
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-
|
|
1288
|
+
" \u2718 Cradova err: Unable to render, cannot find cradova root <div data-wrapper='app'> ... </div>"
|
|
1270
1289
|
);
|
|
1271
1290
|
}
|
|
1272
1291
|
if (this._transition) {
|
|
@@ -1278,114 +1297,99 @@ var Screen = class {
|
|
|
1278
1297
|
if (this._callBack) {
|
|
1279
1298
|
await this._callBack();
|
|
1280
1299
|
}
|
|
1281
|
-
|
|
1282
|
-
window
|
|
1300
|
+
CradovaEvent.dispatchEvent("cradovaAftermountEvent");
|
|
1301
|
+
if (window) {
|
|
1302
|
+
window.scrollTo(0, 0);
|
|
1303
|
+
}
|
|
1283
1304
|
}
|
|
1284
1305
|
};
|
|
1285
1306
|
|
|
1286
1307
|
// lib/index.ts
|
|
1287
1308
|
var make = function(txx) {
|
|
1288
|
-
if (!txx) {
|
|
1289
|
-
return
|
|
1290
|
-
|
|
1291
|
-
|
|
1309
|
+
if (!txx.length) {
|
|
1310
|
+
return ["DIV"];
|
|
1311
|
+
}
|
|
1312
|
+
if (Array.isArray(txx)) {
|
|
1313
|
+
txx = txx[0];
|
|
1292
1314
|
}
|
|
1293
|
-
let tag;
|
|
1294
1315
|
let innerValue = "";
|
|
1295
1316
|
if (txx.includes("|")) {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
}
|
|
1300
|
-
const itemsPurifier = () => {
|
|
1301
|
-
if (!txx.includes("#")) {
|
|
1302
|
-
txx = txx.split(".");
|
|
1303
|
-
tag = txx[0];
|
|
1304
|
-
if (tag) {
|
|
1305
|
-
txx.shift();
|
|
1306
|
-
} else {
|
|
1307
|
-
tag = "div";
|
|
1308
|
-
}
|
|
1309
|
-
return [txx, []];
|
|
1310
|
-
} else {
|
|
1311
|
-
if (!txx.includes(".")) {
|
|
1312
|
-
txx = txx.split("#");
|
|
1313
|
-
tag = txx[0];
|
|
1314
|
-
if (tag) {
|
|
1315
|
-
txx.shift();
|
|
1316
|
-
} else {
|
|
1317
|
-
tag = "div";
|
|
1318
|
-
}
|
|
1319
|
-
if (txx[0].includes(" ")) {
|
|
1320
|
-
txx = [txx[0].split(" ")[1]];
|
|
1321
|
-
}
|
|
1322
|
-
return [[], txx];
|
|
1323
|
-
}
|
|
1317
|
+
[txx, innerValue] = txx.split("|");
|
|
1318
|
+
if (!txx) {
|
|
1319
|
+
return ["P", void 0, void 0, innerValue];
|
|
1324
1320
|
}
|
|
1321
|
+
}
|
|
1322
|
+
let tag;
|
|
1323
|
+
if (!txx.includes("#")) {
|
|
1325
1324
|
txx = txx.split(".");
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1325
|
+
tag = txx.shift();
|
|
1326
|
+
if (!tag) {
|
|
1327
|
+
tag = "DIV";
|
|
1328
|
+
}
|
|
1329
|
+
return [tag, void 0, txx.join(" "), innerValue];
|
|
1330
|
+
} else {
|
|
1331
|
+
if (!txx.includes(".")) {
|
|
1332
|
+
txx = txx.split("#");
|
|
1333
|
+
tag = txx.shift();
|
|
1334
|
+
if (!tag) {
|
|
1335
|
+
tag = "DIV";
|
|
1336
|
+
}
|
|
1337
|
+
if (txx[0].includes(" ")) {
|
|
1338
|
+
txx = [txx[0].split(" ")[1]];
|
|
1339
|
+
}
|
|
1340
|
+
return [tag, txx[0], void 0, innerValue];
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
txx = txx.split(".");
|
|
1344
|
+
const classes = [];
|
|
1345
|
+
const IDs = [];
|
|
1346
|
+
tag = !txx[0].includes("#") && txx.shift();
|
|
1347
|
+
if (!tag) {
|
|
1348
|
+
tag = "DIV";
|
|
1349
|
+
}
|
|
1350
|
+
for (let i2 = 0; i2 < txx.length; i2++) {
|
|
1351
|
+
if (txx[i2].includes("#")) {
|
|
1352
|
+
const item = txx[i2].split("#");
|
|
1353
|
+
IDs.push(item[1]);
|
|
1354
|
+
if (i2 === 0) {
|
|
1355
|
+
tag = item[0];
|
|
1341
1356
|
continue;
|
|
1342
1357
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
if (!tag) {
|
|
1346
|
-
tag = "div";
|
|
1358
|
+
classes.push(item[0]);
|
|
1359
|
+
continue;
|
|
1347
1360
|
}
|
|
1348
|
-
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
const ID = ids && ids[0];
|
|
1352
|
-
const className = classes && classes.join(" ");
|
|
1353
|
-
return { tag, className, ID, innerValue };
|
|
1361
|
+
classes.push(txx[i2]);
|
|
1362
|
+
}
|
|
1363
|
+
return [tag || "DIV", IDs[0], classes.join(" "), innerValue];
|
|
1354
1364
|
};
|
|
1355
1365
|
var _2 = (...element_initials) => {
|
|
1356
|
-
if (element_initials[0].raw) {
|
|
1357
|
-
element_initials[0] = element_initials["raw"][0];
|
|
1358
|
-
}
|
|
1359
|
-
if (typeof element_initials[0] !== "string") {
|
|
1360
|
-
return frag(element_initials);
|
|
1361
|
-
}
|
|
1362
1366
|
const initials = make(element_initials.shift());
|
|
1363
1367
|
let props = void 0;
|
|
1364
1368
|
let element;
|
|
1365
1369
|
try {
|
|
1366
|
-
element = document.createElement(initials
|
|
1370
|
+
element = document.createElement(initials[0]);
|
|
1367
1371
|
} catch (error) {
|
|
1368
|
-
throw new TypeError(" \u2718 Cradova err: invalid tag given " + initials
|
|
1372
|
+
throw new TypeError(" \u2718 Cradova err: invalid tag given " + initials[0]);
|
|
1369
1373
|
}
|
|
1370
|
-
if (initials
|
|
1374
|
+
if (initials[2]) {
|
|
1371
1375
|
if (props) {
|
|
1372
|
-
props["className"] = initials
|
|
1376
|
+
props["className"] = initials[2];
|
|
1373
1377
|
} else {
|
|
1374
|
-
props = { className: initials
|
|
1378
|
+
props = { className: initials[2] };
|
|
1375
1379
|
}
|
|
1376
1380
|
}
|
|
1377
|
-
if (initials
|
|
1381
|
+
if (initials[1]) {
|
|
1378
1382
|
if (props) {
|
|
1379
|
-
props["id"] = initials
|
|
1383
|
+
props["id"] = initials[1];
|
|
1380
1384
|
} else {
|
|
1381
|
-
props = { id: initials
|
|
1385
|
+
props = { id: initials[1] };
|
|
1382
1386
|
}
|
|
1383
1387
|
}
|
|
1384
|
-
if (initials
|
|
1388
|
+
if (initials[3]) {
|
|
1385
1389
|
if (props) {
|
|
1386
|
-
props["innerText"] = initials
|
|
1390
|
+
props["innerText"] = initials[3];
|
|
1387
1391
|
} else {
|
|
1388
|
-
props = { innerText: initials
|
|
1392
|
+
props = { innerText: initials[3] };
|
|
1389
1393
|
}
|
|
1390
1394
|
}
|
|
1391
1395
|
return makeElement(element, props, ...element_initials);
|
|
@@ -1394,6 +1398,7 @@ Init();
|
|
|
1394
1398
|
var lib_default = _2;
|
|
1395
1399
|
export {
|
|
1396
1400
|
Ajax,
|
|
1401
|
+
CradovaEvent,
|
|
1397
1402
|
Ref,
|
|
1398
1403
|
Router,
|
|
1399
1404
|
Screen,
|
|
@@ -1420,7 +1425,6 @@ export {
|
|
|
1420
1425
|
code,
|
|
1421
1426
|
col,
|
|
1422
1427
|
colgroup,
|
|
1423
|
-
cradovaAftermountEvent,
|
|
1424
1428
|
createSignal,
|
|
1425
1429
|
css,
|
|
1426
1430
|
data,
|
|
@@ -1473,7 +1477,6 @@ export {
|
|
|
1473
1477
|
meta,
|
|
1474
1478
|
meter,
|
|
1475
1479
|
nav,
|
|
1476
|
-
noscript,
|
|
1477
1480
|
object,
|
|
1478
1481
|
ol,
|
|
1479
1482
|
optgroup,
|
|
@@ -1485,6 +1488,7 @@ export {
|
|
|
1485
1488
|
pre,
|
|
1486
1489
|
progress,
|
|
1487
1490
|
q,
|
|
1491
|
+
reference,
|
|
1488
1492
|
rp,
|
|
1489
1493
|
rt,
|
|
1490
1494
|
ruby,
|