cradova 2.3.0 → 2.3.1
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 +19 -38
- package/dist/index.d.ts +90 -41
- package/dist/index.js +91 -100
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ Undoubtedly, this provides a significant advantage. You can experience it firsth
|
|
|
58
58
|
|
|
59
59
|
Cradova has already been utilized in multiple production projects, and we will continuously update this page to showcase our advancements as we keep improving.
|
|
60
60
|
|
|
61
|
-
[current version changes](https://github.com/fridaycandour/cradova/blob/main/CHANGELOG.md#
|
|
61
|
+
[current version changes](https://github.com/fridaycandour/cradova/blob/main/CHANGELOG.md#v230)
|
|
62
62
|
|
|
63
63
|
## Installation
|
|
64
64
|
|
|
@@ -109,42 +109,7 @@ this a collection of basic examples
|
|
|
109
109
|
you can choose any that best suite what problem you want to solve
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
|
-
import _, {
|
|
113
|
-
button,
|
|
114
|
-
createSignal,
|
|
115
|
-
Ref,
|
|
116
|
-
reference,
|
|
117
|
-
h1,
|
|
118
|
-
br,
|
|
119
|
-
div,
|
|
120
|
-
} from "../dist/index.js";
|
|
121
|
-
|
|
122
|
-
function Hello(name) {
|
|
123
|
-
return h1("Hello " + name, {
|
|
124
|
-
className: "title",
|
|
125
|
-
style: {
|
|
126
|
-
color: "grey",
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const html = div(Hello("peter"), Hello("joe"));
|
|
132
|
-
|
|
133
|
-
// reference (not state)
|
|
134
|
-
|
|
135
|
-
function typingExample() {
|
|
136
|
-
const re = new reference();
|
|
137
|
-
return _(
|
|
138
|
-
"div",
|
|
139
|
-
input({
|
|
140
|
-
oninput() {
|
|
141
|
-
re.text.innerText = this.value;
|
|
142
|
-
},
|
|
143
|
-
placeholder: "typing simulation",
|
|
144
|
-
}),
|
|
145
|
-
p(" no thing typed yet!", { reference: re.bindAs("text") })
|
|
146
|
-
);
|
|
147
|
-
}
|
|
112
|
+
import _, { button, createSignal, Ref, reference, h1, br, div } from "cradova";
|
|
148
113
|
|
|
149
114
|
// setting shouldUpdate to true
|
|
150
115
|
// gives you this.updateState binding
|
|
@@ -203,6 +168,22 @@ const nameRef = new Ref(function (name) {
|
|
|
203
168
|
});
|
|
204
169
|
});
|
|
205
170
|
|
|
171
|
+
// reference (not state)
|
|
172
|
+
|
|
173
|
+
function typingExample() {
|
|
174
|
+
const re = new reference();
|
|
175
|
+
return _(
|
|
176
|
+
"div",
|
|
177
|
+
input({
|
|
178
|
+
oninput() {
|
|
179
|
+
re.text.innerText = this.value;
|
|
180
|
+
},
|
|
181
|
+
placeholder: "typing simulation",
|
|
182
|
+
}),
|
|
183
|
+
p(" no thing typed yet!", { reference: re.bindAs("text") })
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
206
187
|
function App() {
|
|
207
188
|
return div(counter, dataCounter, HelloMessage, br, nameRef);
|
|
208
189
|
}
|
|
@@ -227,7 +208,7 @@ import _, {
|
|
|
227
208
|
p,
|
|
228
209
|
Ref,
|
|
229
210
|
reference,
|
|
230
|
-
} from "
|
|
211
|
+
} from "cradova";
|
|
231
212
|
|
|
232
213
|
function TodoList() {
|
|
233
214
|
// can be used to hold multiple references
|
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ declare module "cradova" {
|
|
|
11
11
|
beforeMount?: () => void;
|
|
12
12
|
afterMount?: () => void;
|
|
13
13
|
text?: string;
|
|
14
|
+
reference?: any;
|
|
14
15
|
stateID?: string;
|
|
15
16
|
shouldUpdate?: boolean;
|
|
16
|
-
assert?: any;
|
|
17
17
|
}
|
|
18
18
|
)[]
|
|
19
19
|
) => T;
|
|
@@ -80,10 +80,6 @@ declare module "cradova" {
|
|
|
80
80
|
persist?: boolean;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
export const makeElement: (
|
|
84
|
-
element: Record<string, any>,
|
|
85
|
-
...ElementChildrenAndPropertyList: ElementType<HTMLElement>[]
|
|
86
|
-
) => Record<string, any>;
|
|
87
83
|
export const a: ElementType<HTMLAnchorElement>;
|
|
88
84
|
export const abbr: ElementType<HTMLElement>;
|
|
89
85
|
export const address: ElementType<HTMLElement>;
|
|
@@ -150,7 +146,6 @@ declare module "cradova" {
|
|
|
150
146
|
export const meta: ElementType<HTMLMetaElement>;
|
|
151
147
|
export const meter: ElementType<HTMLMeterElement>;
|
|
152
148
|
export const nav: ElementType<HTMLElement>;
|
|
153
|
-
export const noscript: ElementType<HTMLElement>;
|
|
154
149
|
export const object: ElementType<HTMLObjectElement>;
|
|
155
150
|
export const ol: ElementType<HTMLOListElement>;
|
|
156
151
|
export const optgroup: ElementType<HTMLOptGroupElement>;
|
|
@@ -222,32 +217,16 @@ declare module "cradova" {
|
|
|
222
217
|
): Promise<unknown>;
|
|
223
218
|
|
|
224
219
|
/**
|
|
225
|
-
* Cradova
|
|
220
|
+
* Cradova event
|
|
226
221
|
*/
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
height: "100%",
|
|
236
|
-
background-color: "#ff9800"
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
css(".btn:hover",
|
|
240
|
-
{
|
|
241
|
-
height: "100%",
|
|
242
|
-
height: "100%",
|
|
243
|
-
background-color: "#ff9800"
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
*/
|
|
247
|
-
export function css(
|
|
248
|
-
identifier: string,
|
|
249
|
-
properties?: Record<string, string>
|
|
250
|
-
): void;
|
|
222
|
+
export class cradovaEvent {
|
|
223
|
+
private listeners;
|
|
224
|
+
addEventListener(eventName: string, callback: any): void;
|
|
225
|
+
removeEventListener(eventName: string, callback: any): void;
|
|
226
|
+
dispatchEvent(eventName: string, eventArgs?: any): void;
|
|
227
|
+
}
|
|
228
|
+
export const CradovaEvent: cradovaEvent;
|
|
229
|
+
export function css(identifier: string | TemplateStringsArray): void;
|
|
251
230
|
/**
|
|
252
231
|
*
|
|
253
232
|
* @param {expression} condition
|
|
@@ -271,13 +250,14 @@ css(".btn:hover",
|
|
|
271
250
|
type RefProps<D> = D | any;
|
|
272
251
|
export class Ref<D> {
|
|
273
252
|
private component;
|
|
274
|
-
private stateID;
|
|
275
253
|
private effects;
|
|
276
254
|
private effectuate;
|
|
277
255
|
private rendered;
|
|
278
256
|
private published;
|
|
279
257
|
private hasFirstStateUpdateRun;
|
|
280
258
|
private preRendered;
|
|
259
|
+
private reference;
|
|
260
|
+
Signal: createSignal<any> | undefined;
|
|
281
261
|
stash: D | undefined;
|
|
282
262
|
constructor(component: (data?: RefProps<D>) => any);
|
|
283
263
|
preRender(data?: RefProps<D>): void;
|
|
@@ -290,7 +270,8 @@ css(".btn:hover",
|
|
|
290
270
|
* @returns () => HTMLElement
|
|
291
271
|
*/
|
|
292
272
|
render(data?: D, stash?: boolean): HTMLElement;
|
|
293
|
-
instance(): any
|
|
273
|
+
instance(): Record<string, any>;
|
|
274
|
+
_setExtra(Extra: createSignal<any>): void;
|
|
294
275
|
/**
|
|
295
276
|
* Cradova Ref
|
|
296
277
|
* ---
|
|
@@ -324,6 +305,12 @@ css(".btn:hover",
|
|
|
324
305
|
constructor(cb: () => Promise<any>);
|
|
325
306
|
load(): Promise<void>;
|
|
326
307
|
}
|
|
308
|
+
export class reference {
|
|
309
|
+
[x: string]: Record<string, any>;
|
|
310
|
+
bindAs(name: string): any;
|
|
311
|
+
_appendDom(name: string, Element: any): void;
|
|
312
|
+
_appendDomForce(name: string, Element: any): void;
|
|
313
|
+
}
|
|
327
314
|
|
|
328
315
|
/**
|
|
329
316
|
* Cradova Signal
|
|
@@ -391,11 +378,11 @@ css(".btn:hover",
|
|
|
391
378
|
* @param key - string key of the action
|
|
392
379
|
* @param data - data for the action
|
|
393
380
|
*/
|
|
394
|
-
fireAction(key: string, data?:
|
|
381
|
+
fireAction(key: string, data?: unknown): void;
|
|
395
382
|
/**
|
|
396
383
|
* Cradova
|
|
397
384
|
* ---
|
|
398
|
-
* is used to bind store data to
|
|
385
|
+
* is used to bind store data to any element
|
|
399
386
|
*
|
|
400
387
|
* @param prop
|
|
401
388
|
* @returns something
|
|
@@ -412,7 +399,7 @@ css(".btn:hover",
|
|
|
412
399
|
*/
|
|
413
400
|
bindRef(
|
|
414
401
|
ref: any,
|
|
415
|
-
binding
|
|
402
|
+
binding?: {
|
|
416
403
|
event?: string;
|
|
417
404
|
signalProperty: string;
|
|
418
405
|
_element_property: string;
|
|
@@ -458,13 +445,75 @@ css(".btn:hover",
|
|
|
458
445
|
state?: stateType
|
|
459
446
|
): any;
|
|
460
447
|
|
|
461
|
-
/**
|
|
462
|
-
* Cradova Router
|
|
448
|
+
/** cradova router
|
|
463
449
|
* ---
|
|
464
|
-
*
|
|
465
|
-
*
|
|
450
|
+
* Registers a route.
|
|
451
|
+
*
|
|
452
|
+
* @param {string} path Route path.
|
|
453
|
+
* @param {any} screen the cradova document tree for the route.
|
|
466
454
|
*/
|
|
467
|
-
|
|
455
|
+
class RouterClass {
|
|
456
|
+
/** cradova router
|
|
457
|
+
* ---
|
|
458
|
+
* Registers a route.
|
|
459
|
+
*
|
|
460
|
+
* accepts an object containing
|
|
461
|
+
*
|
|
462
|
+
* @param {string} path Route path.
|
|
463
|
+
* @param {any} screen the cradova screen.
|
|
464
|
+
*/
|
|
465
|
+
BrowserRoutes(obj: Record<string, any>): void;
|
|
466
|
+
/**
|
|
467
|
+
* Cradova Router
|
|
468
|
+
* ------
|
|
469
|
+
*
|
|
470
|
+
* Navigates to a designated screen in your app
|
|
471
|
+
*
|
|
472
|
+
* @param href string
|
|
473
|
+
* @param data object
|
|
474
|
+
* @param force boolean
|
|
475
|
+
*/
|
|
476
|
+
navigate(
|
|
477
|
+
href: string,
|
|
478
|
+
data?: Record<string, any> | null,
|
|
479
|
+
force?: boolean
|
|
480
|
+
): void;
|
|
481
|
+
/** cradova router
|
|
482
|
+
* ---
|
|
483
|
+
* Listen for navigation events
|
|
484
|
+
*
|
|
485
|
+
* @param callback () => void
|
|
486
|
+
*/
|
|
487
|
+
onPageEvent(callback: () => void): void;
|
|
488
|
+
/** cradova router
|
|
489
|
+
* ---
|
|
490
|
+
* get a screen ready before time.
|
|
491
|
+
*
|
|
492
|
+
* @param {string} path Route path.
|
|
493
|
+
* @param {any} data data for the screen.
|
|
494
|
+
*/
|
|
495
|
+
packageScreen(path: string, data?: any): Promise<void>;
|
|
496
|
+
/**
|
|
497
|
+
* Cradova Router
|
|
498
|
+
* ------
|
|
499
|
+
*
|
|
500
|
+
* return last set router params
|
|
501
|
+
*
|
|
502
|
+
* .
|
|
503
|
+
*/
|
|
504
|
+
getParams: () => any;
|
|
505
|
+
/**
|
|
506
|
+
* Cradova
|
|
507
|
+
* ---
|
|
508
|
+
* Error Handler for your app
|
|
509
|
+
*
|
|
510
|
+
* @param callback
|
|
511
|
+
* @param path? page path
|
|
512
|
+
*/
|
|
513
|
+
addErrorHandler(callback: () => void): void;
|
|
514
|
+
_mount(): void;
|
|
515
|
+
}
|
|
516
|
+
export const Router: RouterClass;
|
|
468
517
|
|
|
469
518
|
/**
|
|
470
519
|
* Cradova Screen
|
package/dist/index.js
CHANGED
|
@@ -601,7 +601,6 @@ var createSignal = class {
|
|
|
601
601
|
};
|
|
602
602
|
|
|
603
603
|
// lib/utils/Router.ts
|
|
604
|
-
var Router = {};
|
|
605
604
|
var RouterBox = {};
|
|
606
605
|
RouterBox["lastNavigatedRouteController"] = null;
|
|
607
606
|
RouterBox["nextRouteController"] = null;
|
|
@@ -669,69 +668,6 @@ RouterBox.route = (path, screen) => {
|
|
|
669
668
|
RouterBox.routes[path] = screen;
|
|
670
669
|
return RouterBox.routes[path];
|
|
671
670
|
};
|
|
672
|
-
Router.BrowserRoutes = function(obj) {
|
|
673
|
-
for (const path in obj) {
|
|
674
|
-
let screen = obj[path];
|
|
675
|
-
if (screen.catch || typeof screen === "function") {
|
|
676
|
-
RouterBox["routes"][path] = async () => {
|
|
677
|
-
if (typeof screen === "function") {
|
|
678
|
-
screen = await screen();
|
|
679
|
-
} else {
|
|
680
|
-
screen = await screen;
|
|
681
|
-
}
|
|
682
|
-
return RouterBox.route(path, screen.default);
|
|
683
|
-
};
|
|
684
|
-
} else {
|
|
685
|
-
RouterBox.route(path, screen);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
Router.mount();
|
|
689
|
-
};
|
|
690
|
-
Router.delegateScreen = function(path = "/", screen) {
|
|
691
|
-
RouterBox.routes[path] = {
|
|
692
|
-
controller: async (params, force) => await screen.Activate(params, force),
|
|
693
|
-
packager: async (params) => await screen.package(params),
|
|
694
|
-
deactivate: async () => {
|
|
695
|
-
await screen.deActivate();
|
|
696
|
-
},
|
|
697
|
-
paramData: (data2) => {
|
|
698
|
-
screen.paramData = data2;
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
if (typeof screen.errorHandler === "function") {
|
|
702
|
-
RouterBox["errorHandler"][path] = screen.errorHandler;
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
Router.navigate = function(href, data2 = null, force = false) {
|
|
706
|
-
if (typeof href !== "string") {
|
|
707
|
-
throw new TypeError(
|
|
708
|
-
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
if (typeof data2 === "boolean") {
|
|
712
|
-
force = true;
|
|
713
|
-
data2 = null;
|
|
714
|
-
}
|
|
715
|
-
let route = null, params;
|
|
716
|
-
if (href.includes("://")) {
|
|
717
|
-
window.location.href = href;
|
|
718
|
-
} else {
|
|
719
|
-
const lastR = window.location.pathname;
|
|
720
|
-
if (href === lastR) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
[route, params] = checker(href);
|
|
724
|
-
if (route) {
|
|
725
|
-
RouterBox["nextRouteController"] = route;
|
|
726
|
-
RouterBox.params.params = params;
|
|
727
|
-
route._paramData = params;
|
|
728
|
-
RouterBox.params.data = data2 || null;
|
|
729
|
-
window.history.pushState({}, "", href);
|
|
730
|
-
}
|
|
731
|
-
RouterBox.router(null, force);
|
|
732
|
-
RouterBox["start_pageevents"](lastR, href);
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
671
|
RouterBox.router = async function(e, force = false) {
|
|
736
672
|
let url, route, params;
|
|
737
673
|
if (e) {
|
|
@@ -752,7 +688,7 @@ RouterBox.router = async function(e, force = false) {
|
|
|
752
688
|
if (!url) {
|
|
753
689
|
url = window.location.pathname;
|
|
754
690
|
}
|
|
755
|
-
if (url ===
|
|
691
|
+
if (url === RouterBox["lastNavigatedRoute"]) {
|
|
756
692
|
return;
|
|
757
693
|
}
|
|
758
694
|
if (RouterBox["nextRouteController"]) {
|
|
@@ -796,46 +732,101 @@ RouterBox.router = async function(e, force = false) {
|
|
|
796
732
|
}
|
|
797
733
|
}
|
|
798
734
|
};
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
805
|
-
);
|
|
735
|
+
var RouterClass = class {
|
|
736
|
+
constructor() {
|
|
737
|
+
this.getParams = function() {
|
|
738
|
+
return RouterBox["params"];
|
|
739
|
+
};
|
|
806
740
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
741
|
+
BrowserRoutes(obj) {
|
|
742
|
+
for (const path in obj) {
|
|
743
|
+
let screen = obj[path];
|
|
744
|
+
if (screen.catch || typeof screen === "function") {
|
|
745
|
+
RouterBox["routes"][path] = async () => {
|
|
746
|
+
if (typeof screen === "function") {
|
|
747
|
+
screen = await screen();
|
|
748
|
+
} else {
|
|
749
|
+
screen = await screen;
|
|
750
|
+
}
|
|
751
|
+
return RouterBox.route(path, screen.default);
|
|
752
|
+
};
|
|
753
|
+
} else {
|
|
754
|
+
RouterBox.route(path, screen);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
this._mount();
|
|
758
|
+
}
|
|
759
|
+
navigate(href, data2 = null, force = false) {
|
|
760
|
+
if (typeof href !== "string") {
|
|
761
|
+
throw new TypeError(
|
|
762
|
+
" \u2718 Cradova err: href must be a defined path but got " + href + " instead"
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
if (typeof data2 === "boolean") {
|
|
766
|
+
force = true;
|
|
767
|
+
data2 = null;
|
|
768
|
+
}
|
|
769
|
+
let route = null, params;
|
|
770
|
+
if (href.includes("://")) {
|
|
771
|
+
window.location.href = href;
|
|
772
|
+
} else {
|
|
773
|
+
const lastR = window.location.pathname;
|
|
774
|
+
if (href === lastR) {
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
[route, params] = checker(href);
|
|
778
|
+
if (route) {
|
|
779
|
+
RouterBox["nextRouteController"] = route;
|
|
780
|
+
RouterBox.params.params = params;
|
|
781
|
+
route._paramData = params;
|
|
782
|
+
RouterBox.params.data = data2 || null;
|
|
783
|
+
window.history.pushState({}, "", href);
|
|
784
|
+
}
|
|
785
|
+
RouterBox.router(null, force);
|
|
786
|
+
RouterBox["start_pageevents"](lastR, href);
|
|
787
|
+
}
|
|
812
788
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
789
|
+
onPageEvent(callback) {
|
|
790
|
+
if (typeof callback === "function") {
|
|
791
|
+
RouterBox["pageevents"].push(callback);
|
|
792
|
+
} else {
|
|
793
|
+
throw new Error(
|
|
794
|
+
" \u2718 Cradova err: callback for pageShow event is not a function"
|
|
795
|
+
);
|
|
796
|
+
}
|
|
816
797
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
798
|
+
async packageScreen(path, data2 = {}) {
|
|
799
|
+
if (!RouterBox.routes[path]) {
|
|
800
|
+
console.error(" \u2718 Cradova err: no screen with path " + path);
|
|
801
|
+
throw new Error(
|
|
802
|
+
" \u2718 Cradova err: cradova err: Not a defined screen path"
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
let [route, params] = checker(path);
|
|
806
|
+
if (!route._Activate && typeof route === "function") {
|
|
807
|
+
route = await route();
|
|
808
|
+
}
|
|
809
|
+
route._package(Object.assign(data2, params || {}));
|
|
810
|
+
route._packed = true;
|
|
811
|
+
}
|
|
812
|
+
addErrorHandler(callback) {
|
|
813
|
+
if (typeof callback === "function") {
|
|
814
|
+
RouterBox["errorHandler"] = callback;
|
|
815
|
+
} else {
|
|
816
|
+
throw new Error(
|
|
817
|
+
" \u2718 Cradova err: callback for ever event event is not a function"
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
_mount() {
|
|
822
|
+
window.addEventListener("pageshow", RouterBox.router);
|
|
823
|
+
window.addEventListener("popstate", (e) => {
|
|
824
|
+
e.preventDefault();
|
|
825
|
+
RouterBox.router();
|
|
826
|
+
});
|
|
830
827
|
}
|
|
831
828
|
};
|
|
832
|
-
Router
|
|
833
|
-
window.addEventListener("pageshow", RouterBox.router);
|
|
834
|
-
window.addEventListener("popstate", (e) => {
|
|
835
|
-
e.preventDefault();
|
|
836
|
-
RouterBox.router();
|
|
837
|
-
});
|
|
838
|
-
};
|
|
829
|
+
var Router = new RouterClass();
|
|
839
830
|
|
|
840
831
|
// lib/utils/elements.ts
|
|
841
832
|
var makeElement = (element, ...ElementChildrenAndPropertyList) => {
|