cradova 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -14
- package/dist/index.js +144 -88
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -67,15 +67,6 @@ declare module "cradova" {
|
|
|
67
67
|
* @param {any} screen the cradova document tree for the route.
|
|
68
68
|
*/
|
|
69
69
|
route: (path: string, screen: CradovaScreenType) => void;
|
|
70
|
-
routes: Record<string, RouterRouteObject>;
|
|
71
|
-
lastNavigatedRoute: string | null;
|
|
72
|
-
lastNavigatedRouteController: RouterRouteObject | null;
|
|
73
|
-
nextRouteController: RouterRouteObject | null;
|
|
74
|
-
params: Record<string, any>;
|
|
75
|
-
/**
|
|
76
|
-
* n/a
|
|
77
|
-
*/
|
|
78
|
-
router: (e: any, force?: boolean) => void;
|
|
79
70
|
/**
|
|
80
71
|
* get a screen ready before time.
|
|
81
72
|
*
|
|
@@ -83,8 +74,6 @@ declare module "cradova" {
|
|
|
83
74
|
* @param {any} data data for the screen.
|
|
84
75
|
*/
|
|
85
76
|
packageScreen: (path: string, data?: any) => void;
|
|
86
|
-
pageShow: ((path: string) => void) | null;
|
|
87
|
-
pageHide: ((path: string) => void) | null;
|
|
88
77
|
onPageShow: (callback: () => void) => void;
|
|
89
78
|
onPageHide: (callback: () => void) => void;
|
|
90
79
|
/**
|
|
@@ -198,7 +187,7 @@ declare module "cradova" {
|
|
|
198
187
|
* - update a cradova Ref/RefList automatically
|
|
199
188
|
* @constructor initial: any, props: {useHistory, persist}
|
|
200
189
|
*/
|
|
201
|
-
export class
|
|
190
|
+
export class createSignal {
|
|
202
191
|
private callback;
|
|
203
192
|
private persistName;
|
|
204
193
|
private actions;
|
|
@@ -333,7 +322,7 @@ declare module "cradova" {
|
|
|
333
322
|
export class simpleStore {
|
|
334
323
|
private ref;
|
|
335
324
|
value: any;
|
|
336
|
-
constructor(initial: unknown, ref
|
|
325
|
+
constructor(initial: unknown, ref?: RefType);
|
|
337
326
|
/**
|
|
338
327
|
* Cradova simpleStore
|
|
339
328
|
* ----
|
|
@@ -491,10 +480,13 @@ _.animate("polarization",
|
|
|
491
480
|
ifTrue: () => any,
|
|
492
481
|
ifFalse: () => any
|
|
493
482
|
): () => any;
|
|
494
|
-
/**
|
|
483
|
+
/** @deprecated
|
|
484
|
+
*
|
|
495
485
|
* Create element and get a callback to update their state
|
|
496
486
|
* no need to manage stateIDs
|
|
497
487
|
* ----------------------------------------------------------------
|
|
488
|
+
* please use element.updateState(state) instead in listeners and mount events
|
|
489
|
+
* ---
|
|
498
490
|
*
|
|
499
491
|
* @param element_initials
|
|
500
492
|
* @param props
|
package/dist/index.js
CHANGED
|
@@ -9,20 +9,16 @@ var Screen = class {
|
|
|
9
9
|
const { template, name, callBack, transition, persist } = cradova_screen_initials;
|
|
10
10
|
if (typeof template !== "function") {
|
|
11
11
|
throw new Error(
|
|
12
|
-
" \u2718 Cradova err:
|
|
12
|
+
" \u2718 Cradova err: only functions that returns a cradova element is valid as screen"
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
this.html = template.bind(this);
|
|
16
16
|
this.name = name;
|
|
17
|
-
this.template = document.
|
|
18
|
-
this.template.id = "cradova-screen-set";
|
|
17
|
+
this.template = document.createDocumentFragment();
|
|
19
18
|
this.callBack = callBack;
|
|
20
19
|
this.transition = transition;
|
|
21
|
-
if (typeof persist
|
|
22
|
-
this.persist =
|
|
23
|
-
}
|
|
24
|
-
if (persist === false) {
|
|
25
|
-
this.persist = false;
|
|
20
|
+
if (typeof persist === "boolean") {
|
|
21
|
+
this.persist = persist;
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
effect(fn) {
|
|
@@ -46,12 +42,15 @@ var Screen = class {
|
|
|
46
42
|
if (typeof this.html === "function") {
|
|
47
43
|
let fuc = await this.html(data);
|
|
48
44
|
if (typeof fuc === "function") {
|
|
49
|
-
fuc = fuc(
|
|
45
|
+
fuc = fuc();
|
|
50
46
|
if (!(fuc instanceof HTMLElement)) {
|
|
51
47
|
throw new Error(
|
|
52
48
|
" \u2718 Cradova err: only parent with descendants is valid"
|
|
53
49
|
);
|
|
54
50
|
} else {
|
|
51
|
+
if (this.transition) {
|
|
52
|
+
fuc.classList.add("CRADOVA-UI-" + this.transition);
|
|
53
|
+
}
|
|
55
54
|
this.template.replaceChildren(fuc);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
@@ -61,7 +60,9 @@ var Screen = class {
|
|
|
61
60
|
" \u2718 Cradova err: no screen is rendered, may have been past wrongly, try ()=> screen; in cradova Router.route(name, screen)"
|
|
62
61
|
);
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
if (this.secondaryChildren.length) {
|
|
64
|
+
this.template.append(...this.secondaryChildren);
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
onActivate(cb) {
|
|
67
68
|
this.callBack = cb;
|
|
@@ -78,6 +79,9 @@ var Screen = class {
|
|
|
78
79
|
}
|
|
79
80
|
deActivate() {
|
|
80
81
|
this.template.parentElement?.removeChild(this.template);
|
|
82
|
+
if (!this.persist) {
|
|
83
|
+
this.rendered = false;
|
|
84
|
+
}
|
|
81
85
|
}
|
|
82
86
|
async Activate(data, force) {
|
|
83
87
|
if (!this.persist) {
|
|
@@ -92,18 +96,18 @@ var Screen = class {
|
|
|
92
96
|
if (force) {
|
|
93
97
|
await this.package(data);
|
|
94
98
|
this.packed = true;
|
|
99
|
+
this.rendered = false;
|
|
95
100
|
}
|
|
96
101
|
document.title = this.name;
|
|
97
|
-
document.querySelector("[data-cra-id=cradova-app-wrapper]")
|
|
102
|
+
const doc = document.querySelector("[data-cra-id=cradova-app-wrapper]");
|
|
103
|
+
doc?.replaceChildren(this.template);
|
|
98
104
|
if (!this.persist) {
|
|
99
105
|
this.packed = false;
|
|
100
106
|
}
|
|
101
107
|
await this.effector();
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (this.transition) {
|
|
106
|
-
this.template?.classList.add("CRADOVA-UI-" + this.transition);
|
|
108
|
+
if (doc?.firstChild?.afterMount) {
|
|
109
|
+
doc?.firstChild.afterMount();
|
|
110
|
+
doc.firstChild.afterMount = void 0;
|
|
107
111
|
}
|
|
108
112
|
if (this.callBack) {
|
|
109
113
|
await this.callBack(data);
|
|
@@ -183,18 +187,19 @@ var Scaffold = class {
|
|
|
183
187
|
|
|
184
188
|
// lib/scripts/Router.ts
|
|
185
189
|
var Router = {};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
var RouterBox = {};
|
|
191
|
+
RouterBox["lastNavigatedRouteController"] = null;
|
|
192
|
+
RouterBox["nextRouteController"] = null;
|
|
193
|
+
RouterBox["lastNavigatedRoute"] = null;
|
|
194
|
+
RouterBox["pageShow"] = null;
|
|
195
|
+
RouterBox["pageHide"] = null;
|
|
196
|
+
RouterBox["params"] = {};
|
|
197
|
+
RouterBox["routes"] = {};
|
|
193
198
|
var checker = (url) => {
|
|
194
|
-
if (
|
|
195
|
-
return [
|
|
199
|
+
if (RouterBox.routes[url]) {
|
|
200
|
+
return [RouterBox.routes[url], null];
|
|
196
201
|
}
|
|
197
|
-
for (const path in
|
|
202
|
+
for (const path in RouterBox.routes) {
|
|
198
203
|
if (!path.includes(":")) {
|
|
199
204
|
continue;
|
|
200
205
|
}
|
|
@@ -227,7 +232,7 @@ var checker = (url) => {
|
|
|
227
232
|
routesParams[pathFixtures[i].split(":")[1]] = urlFixtures[i];
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
|
-
return [
|
|
235
|
+
return [RouterBox.routes[path], routesParams];
|
|
231
236
|
}
|
|
232
237
|
}
|
|
233
238
|
}
|
|
@@ -238,7 +243,7 @@ Router.route = function(path = "/", screen) {
|
|
|
238
243
|
console.error(" \u2718 Cradova err: not a valid screen " + screen);
|
|
239
244
|
throw new Error(" \u2718 Cradova err: Not a valid cradova screen component");
|
|
240
245
|
}
|
|
241
|
-
|
|
246
|
+
RouterBox.routes[path] = {
|
|
242
247
|
controller: (params, force) => screen.Activate(params, force),
|
|
243
248
|
packager: async (params) => await screen.package(params),
|
|
244
249
|
deactivate: () => {
|
|
@@ -257,7 +262,7 @@ Router.navigate = function(href, data = null, force = false) {
|
|
|
257
262
|
);
|
|
258
263
|
}
|
|
259
264
|
let route = null, params, link = null;
|
|
260
|
-
if (href.includes("
|
|
265
|
+
if (href.includes("://")) {
|
|
261
266
|
window.location.href = href;
|
|
262
267
|
} else {
|
|
263
268
|
if (href === window.location.pathname) {
|
|
@@ -265,19 +270,19 @@ Router.navigate = function(href, data = null, force = false) {
|
|
|
265
270
|
}
|
|
266
271
|
[route, params] = checker(href);
|
|
267
272
|
if (route) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
273
|
+
RouterBox["nextRouteController"] = route;
|
|
274
|
+
RouterBox.params.params = params || null;
|
|
275
|
+
RouterBox.params.data = data || null;
|
|
271
276
|
link = href;
|
|
272
|
-
|
|
277
|
+
RouterBox["pageHide"] && RouterBox["pageHide"](href + " :navigated");
|
|
273
278
|
window.history.pushState({}, "", link);
|
|
274
279
|
setTimeout(async () => {
|
|
275
|
-
await
|
|
280
|
+
await RouterBox.router(null, force);
|
|
276
281
|
}, 0);
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
284
|
};
|
|
280
|
-
|
|
285
|
+
RouterBox.router = async function(e, force = false) {
|
|
281
286
|
let Alink, url, route, params;
|
|
282
287
|
if (e && e.target.tagName) {
|
|
283
288
|
Alink = e.target;
|
|
@@ -298,22 +303,22 @@ Router.router = async function(e, force = false) {
|
|
|
298
303
|
if (url === Router["lastNavigatedRoute"]) {
|
|
299
304
|
return;
|
|
300
305
|
}
|
|
301
|
-
if (
|
|
302
|
-
route =
|
|
303
|
-
|
|
304
|
-
params =
|
|
306
|
+
if (RouterBox["nextRouteController"]) {
|
|
307
|
+
route = RouterBox["nextRouteController"];
|
|
308
|
+
RouterBox["nextRouteController"] = null;
|
|
309
|
+
params = RouterBox.params.params;
|
|
305
310
|
} else {
|
|
306
311
|
[route, params] = checker(url);
|
|
307
312
|
}
|
|
308
313
|
if (route) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
await route.controller(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
RouterBox.params.event = e;
|
|
315
|
+
RouterBox.params.params = params || null;
|
|
316
|
+
RouterBox.params.data = RouterBox.params.data || null;
|
|
317
|
+
RouterBox["lastNavigatedRouteController"] && RouterBox["lastNavigatedRouteController"].deactivate();
|
|
318
|
+
await route.controller(RouterBox.params, force);
|
|
319
|
+
RouterBox["pageShow"] && RouterBox["pageShow"](url);
|
|
320
|
+
RouterBox["lastNavigatedRoute"] = url;
|
|
321
|
+
RouterBox["lastNavigatedRouteController"] = route;
|
|
317
322
|
Array.from(window.document.querySelectorAll("a")).forEach((a) => {
|
|
318
323
|
a.addEventListener("click", (e2) => {
|
|
319
324
|
e2.preventDefault();
|
|
@@ -321,18 +326,18 @@ Router.router = async function(e, force = false) {
|
|
|
321
326
|
});
|
|
322
327
|
});
|
|
323
328
|
} else {
|
|
324
|
-
if (
|
|
325
|
-
|
|
329
|
+
if (RouterBox.routes["/404"]) {
|
|
330
|
+
RouterBox.routes["/404"].controller(RouterBox.params);
|
|
326
331
|
} else {
|
|
327
332
|
console.error(
|
|
328
|
-
" \u2718 Cradova err: route '" + url + "' does not exist and no /404 route given!"
|
|
333
|
+
" \u2718 Cradova err: route '" + url + "' does not exist and no '/404' route given!"
|
|
329
334
|
);
|
|
330
335
|
}
|
|
331
336
|
}
|
|
332
337
|
};
|
|
333
338
|
Router["onPageShow"] = function(callback) {
|
|
334
339
|
if (typeof callback === "function") {
|
|
335
|
-
|
|
340
|
+
RouterBox["pageShow"] = callback;
|
|
336
341
|
} else {
|
|
337
342
|
throw new Error(
|
|
338
343
|
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
@@ -341,7 +346,7 @@ Router["onPageShow"] = function(callback) {
|
|
|
341
346
|
};
|
|
342
347
|
Router["onPageHide"] = function(callback) {
|
|
343
348
|
if (typeof callback === "function") {
|
|
344
|
-
|
|
349
|
+
RouterBox["pageHide"] = callback;
|
|
345
350
|
} else {
|
|
346
351
|
throw new Error(
|
|
347
352
|
" \u2718 Cradova err: callback for pageHide event is not a function"
|
|
@@ -355,10 +360,10 @@ Router.packageScreen = async function(path, data) {
|
|
|
355
360
|
}
|
|
356
361
|
await Router.routes[path].packager(data);
|
|
357
362
|
};
|
|
358
|
-
window.addEventListener("pageshow",
|
|
363
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
359
364
|
window.addEventListener("popstate", (e) => {
|
|
360
365
|
e.preventDefault();
|
|
361
|
-
|
|
366
|
+
RouterBox.router(e);
|
|
362
367
|
});
|
|
363
368
|
|
|
364
369
|
// lib/scripts/fns.ts
|
|
@@ -466,7 +471,19 @@ function media(value, ...properties) {
|
|
|
466
471
|
aniStyleTag.innerHTML = totalAnimation;
|
|
467
472
|
document.head.append(aniStyleTag);
|
|
468
473
|
}
|
|
469
|
-
function css(identifier, properties) {
|
|
474
|
+
function css(identifier, properties = {}) {
|
|
475
|
+
if (typeof identifier === "string" && typeof properties === "undefined") {
|
|
476
|
+
let styTag = document.querySelector("style");
|
|
477
|
+
if (styTag !== null) {
|
|
478
|
+
identifier += styTag.textContent;
|
|
479
|
+
styTag.textContent = identifier;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
styTag = document.createElement("style");
|
|
483
|
+
styTag.textContent = identifier;
|
|
484
|
+
document.head.append(styTag);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
470
487
|
const styS = "" + identifier + `{
|
|
471
488
|
`;
|
|
472
489
|
const styE = `}
|
|
@@ -536,7 +553,7 @@ function assertOr(condition, ifTrue, ifFalse) {
|
|
|
536
553
|
}
|
|
537
554
|
function RefElement(element_initials = "div", props = {}, ...other) {
|
|
538
555
|
const stateID = uuid();
|
|
539
|
-
if (
|
|
556
|
+
if (typeof props === "object" && !Array.isArray(element_initials[1])) {
|
|
540
557
|
other = props;
|
|
541
558
|
props = { stateID };
|
|
542
559
|
} else {
|
|
@@ -754,9 +771,9 @@ var Ref = class {
|
|
|
754
771
|
cradovaDispatchTrackBreak: true
|
|
755
772
|
});
|
|
756
773
|
if (!guy) {
|
|
757
|
-
console.error(this.component);
|
|
758
774
|
throw new Error(
|
|
759
|
-
" \u2718 Cradova err: Ref is not rendered but updateState was called"
|
|
775
|
+
" \u2718 Cradova err: Ref is not rendered but updateState was called",
|
|
776
|
+
this.component
|
|
760
777
|
);
|
|
761
778
|
}
|
|
762
779
|
const chtml = this.component(data);
|
|
@@ -789,15 +806,34 @@ var Ref = class {
|
|
|
789
806
|
dispatch(this.stateID, { remove: true });
|
|
790
807
|
}
|
|
791
808
|
};
|
|
792
|
-
var frag = function(
|
|
809
|
+
var frag = function(children) {
|
|
793
810
|
const par = document.createDocumentFragment();
|
|
794
811
|
for (let i = 0; i < children.length; i++) {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
812
|
+
if (typeof children[i] === "function") {
|
|
813
|
+
const a = children[i]();
|
|
814
|
+
if (typeof a === "function") {
|
|
815
|
+
const b = a();
|
|
816
|
+
if (b instanceof HTMLElement) {
|
|
817
|
+
par.append(b);
|
|
818
|
+
} else {
|
|
819
|
+
if (!(b instanceof HTMLElement)) {
|
|
820
|
+
console.error(" \u2718 Cradova err: wrong element type" + b);
|
|
821
|
+
throw new TypeError(
|
|
822
|
+
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
} else {
|
|
827
|
+
if (a instanceof HTMLElement) {
|
|
828
|
+
par.append(a);
|
|
829
|
+
} else {
|
|
830
|
+
if (!(a instanceof HTMLElement)) {
|
|
831
|
+
console.error(" \u2718 Cradova err: wrong element type" + a);
|
|
832
|
+
throw new TypeError(
|
|
833
|
+
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
801
837
|
}
|
|
802
838
|
}
|
|
803
839
|
}
|
|
@@ -811,7 +847,7 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
811
847
|
if (!element) {
|
|
812
848
|
continue;
|
|
813
849
|
}
|
|
814
|
-
if (typeof state === "object") {
|
|
850
|
+
if (typeof state === "object" && !Array.isArray(state)) {
|
|
815
851
|
for (const key in state) {
|
|
816
852
|
if (key === "style") {
|
|
817
853
|
for (const [k, v] of Object.entries(state[key])) {
|
|
@@ -845,7 +881,7 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
845
881
|
}
|
|
846
882
|
continue;
|
|
847
883
|
}
|
|
848
|
-
if (key === "class" && typeof state[key] === "string") {
|
|
884
|
+
if (key === "class" && typeof state[key] === "string" && state[key] !== "") {
|
|
849
885
|
const classes = state[key].split(" ");
|
|
850
886
|
for (let i2 = 0; i2 < classes.length; i2++) {
|
|
851
887
|
if (classes[i2]) {
|
|
@@ -854,11 +890,11 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
854
890
|
}
|
|
855
891
|
continue;
|
|
856
892
|
}
|
|
857
|
-
if (key === "toggleclass") {
|
|
893
|
+
if (key === "toggleclass" && state[key] !== "") {
|
|
858
894
|
element.classList.toggle(state[key]);
|
|
859
895
|
continue;
|
|
860
896
|
}
|
|
861
|
-
if (key === "removeclass") {
|
|
897
|
+
if (key === "removeclass" && state[key] !== "") {
|
|
862
898
|
element.classList.remove(state[key]);
|
|
863
899
|
continue;
|
|
864
900
|
}
|
|
@@ -866,6 +902,10 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
866
902
|
element.parentElement?.removeChild(element);
|
|
867
903
|
continue;
|
|
868
904
|
}
|
|
905
|
+
if (key.includes("$")) {
|
|
906
|
+
element.setAttribute("data-" + key.split("$")[1], state[key]);
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
869
909
|
if (key === "tree") {
|
|
870
910
|
if (typeof state[key] === "function") {
|
|
871
911
|
state[key] = state[key]();
|
|
@@ -880,14 +920,13 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
880
920
|
}
|
|
881
921
|
if (!(state[key] instanceof HTMLElement)) {
|
|
882
922
|
console.error(
|
|
883
|
-
" \u2718 Cradova err: wrong element type: can't update
|
|
923
|
+
" \u2718 Cradova err: wrong element type: can't update tree using " + state[key]
|
|
884
924
|
);
|
|
885
925
|
throw new TypeError(
|
|
886
926
|
" \u2718 Cradova err: invalid element, should be a html element from cradova"
|
|
887
927
|
);
|
|
888
928
|
}
|
|
889
|
-
element.replaceChildren();
|
|
890
|
-
element.append(state[key]);
|
|
929
|
+
element.replaceChildren(state[key]);
|
|
891
930
|
continue;
|
|
892
931
|
}
|
|
893
932
|
element[key] = state[key];
|
|
@@ -896,12 +935,17 @@ function cradovaDispatchTrack(nodes, state) {
|
|
|
896
935
|
}
|
|
897
936
|
}
|
|
898
937
|
function dispatch(stateID, state) {
|
|
938
|
+
let ele;
|
|
939
|
+
if (stateID instanceof HTMLElement) {
|
|
940
|
+
ele = stateID;
|
|
941
|
+
}
|
|
899
942
|
let updated = void 0;
|
|
900
|
-
if (typeof state === "undefined" && typeof stateID === "object") {
|
|
943
|
+
if (typeof state === "undefined" && typeof stateID === "object" && !ele) {
|
|
901
944
|
for (const [id, eachState] of Object.entries(stateID)) {
|
|
902
945
|
const elements = document.querySelectorAll(
|
|
903
946
|
"[data-cra-id=" + id + "]"
|
|
904
947
|
);
|
|
948
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
905
949
|
cradovaDispatchTrack(elements, eachState);
|
|
906
950
|
}
|
|
907
951
|
} else {
|
|
@@ -910,19 +954,21 @@ function dispatch(stateID, state) {
|
|
|
910
954
|
"[data-cra-id=" + stateID + "]"
|
|
911
955
|
);
|
|
912
956
|
if (elements.length) {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
} else {
|
|
957
|
+
updated = elements.length === 1 ? elements[0] : elements;
|
|
958
|
+
if (!state?.cradovaDispatchTrackBreak) {
|
|
916
959
|
cradovaDispatchTrack(elements, state);
|
|
917
960
|
}
|
|
918
961
|
}
|
|
919
962
|
}
|
|
963
|
+
if (ele) {
|
|
964
|
+
cradovaDispatchTrack([ele], state);
|
|
965
|
+
}
|
|
920
966
|
}
|
|
921
967
|
return updated;
|
|
922
968
|
}
|
|
923
969
|
|
|
924
970
|
// lib/scripts/createSignal.ts
|
|
925
|
-
var
|
|
971
|
+
var createSignal = class {
|
|
926
972
|
constructor(initial, props) {
|
|
927
973
|
this.persistName = "";
|
|
928
974
|
this.actions = {};
|
|
@@ -1091,7 +1137,9 @@ var simpleStore = class {
|
|
|
1091
1137
|
constructor(initial, ref) {
|
|
1092
1138
|
this.value = null;
|
|
1093
1139
|
this.value = initial;
|
|
1094
|
-
|
|
1140
|
+
if (ref) {
|
|
1141
|
+
this.bindRef(ref);
|
|
1142
|
+
}
|
|
1095
1143
|
}
|
|
1096
1144
|
set(value, shouldRefRender) {
|
|
1097
1145
|
if (typeof value === "function") {
|
|
@@ -1562,7 +1610,7 @@ var make = function(txx) {
|
|
|
1562
1610
|
};
|
|
1563
1611
|
var _ = (...element_initials) => {
|
|
1564
1612
|
let firstProps, firstLevelChildren = [], beforeMount;
|
|
1565
|
-
if (
|
|
1613
|
+
if (typeof element_initials[1] === "object" && !Array.isArray(element_initials[1])) {
|
|
1566
1614
|
firstProps = element_initials[1];
|
|
1567
1615
|
if (firstProps?.beforeMount) {
|
|
1568
1616
|
beforeMount = firstProps["beforeMount"];
|
|
@@ -1572,9 +1620,7 @@ var _ = (...element_initials) => {
|
|
|
1572
1620
|
firstLevelChildren = element_initials.slice(2, element_initials.length);
|
|
1573
1621
|
}
|
|
1574
1622
|
} else {
|
|
1575
|
-
|
|
1576
|
-
firstLevelChildren = element_initials.slice(1, element_initials.length);
|
|
1577
|
-
}
|
|
1623
|
+
firstLevelChildren = element_initials.slice(1, element_initials.length);
|
|
1578
1624
|
}
|
|
1579
1625
|
if (element_initials[0].raw) {
|
|
1580
1626
|
element_initials[0] = element_initials[0]["raw"][0];
|
|
@@ -1587,7 +1633,7 @@ var _ = (...element_initials) => {
|
|
|
1587
1633
|
return (...incoming) => {
|
|
1588
1634
|
let secondLevelChildren = [], props = {}, text;
|
|
1589
1635
|
for (let i = 0; i < incoming.length; i++) {
|
|
1590
|
-
if (
|
|
1636
|
+
if (typeof incoming[i] === "object" && !Array.isArray(incoming[1])) {
|
|
1591
1637
|
props = incoming[i];
|
|
1592
1638
|
if (incoming[i].beforeMount) {
|
|
1593
1639
|
beforeMount = incoming[i]["beforeMount"];
|
|
@@ -1646,11 +1692,11 @@ var _ = (...element_initials) => {
|
|
|
1646
1692
|
element.style[prop] = props[prop];
|
|
1647
1693
|
continue;
|
|
1648
1694
|
}
|
|
1649
|
-
if (prop === "text" && typeof props[prop] === "string") {
|
|
1695
|
+
if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1650
1696
|
text = props[prop];
|
|
1651
1697
|
continue;
|
|
1652
1698
|
}
|
|
1653
|
-
if (prop === "class" && typeof props[prop] === "string") {
|
|
1699
|
+
if (prop === "class" && typeof props[prop] === "string" && props[prop] !== "") {
|
|
1654
1700
|
element.classList.add(props[prop]);
|
|
1655
1701
|
continue;
|
|
1656
1702
|
}
|
|
@@ -1667,8 +1713,19 @@ var _ = (...element_initials) => {
|
|
|
1667
1713
|
element.setAttribute("data-" + prop.split("$")[1], props[prop]);
|
|
1668
1714
|
continue;
|
|
1669
1715
|
}
|
|
1716
|
+
if (prop === "shouldUpdate" && props[prop] === true) {
|
|
1717
|
+
element.updateState = dispatch.bind(null, element);
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1670
1720
|
try {
|
|
1671
|
-
element[prop]
|
|
1721
|
+
if (typeof element[prop] !== "undefined") {
|
|
1722
|
+
element[prop] = props[prop];
|
|
1723
|
+
} else {
|
|
1724
|
+
element[prop] = props[prop];
|
|
1725
|
+
if (prop !== "afterMount" && prop !== "for" && !prop.includes("aria")) {
|
|
1726
|
+
console.error(" \u2718 Cradova err: invalid html attribute " + prop);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1672
1729
|
} catch (error) {
|
|
1673
1730
|
console.error(" \u2718 Cradova err: ", error);
|
|
1674
1731
|
}
|
|
@@ -1760,7 +1817,6 @@ export {
|
|
|
1760
1817
|
IsElementInView,
|
|
1761
1818
|
PromptBeforeLeave,
|
|
1762
1819
|
Ref,
|
|
1763
|
-
RefElement,
|
|
1764
1820
|
RefList,
|
|
1765
1821
|
Router,
|
|
1766
1822
|
Scaffold,
|
|
@@ -1769,7 +1825,7 @@ export {
|
|
|
1769
1825
|
assert,
|
|
1770
1826
|
assertOr,
|
|
1771
1827
|
controls,
|
|
1772
|
-
|
|
1828
|
+
createSignal,
|
|
1773
1829
|
css,
|
|
1774
1830
|
lib_default as default,
|
|
1775
1831
|
dispatch,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cradova",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Web framework for building web apps and PWAs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "git+https://github.com/FridayCandour/cradova.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsup lib/index.ts &&
|
|
15
|
+
"build": "tsup lib/index.ts && npm run ts && cp lib/types.ts dist/types.ts ",
|
|
16
16
|
"buildts": "tsup lib/index.ts",
|
|
17
17
|
"ts": "cp cradova.d.ts dist/index.d.ts",
|
|
18
18
|
"lint": "eslint . --fix"
|