cradova 3.3.58 → 3.4.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/dist/index.js +34 -134
- package/dist/primitives/classes.d.ts +8 -79
- package/dist/primitives/functions.d.ts +3 -3
- package/dist/primitives/types.d.ts +1 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ class Comp {
|
|
|
28
28
|
published = false;
|
|
29
29
|
preRendered = null;
|
|
30
30
|
reference = null;
|
|
31
|
-
|
|
31
|
+
subData = null;
|
|
32
32
|
_state = [];
|
|
33
33
|
_state_index = 0;
|
|
34
34
|
test;
|
|
@@ -60,12 +60,6 @@ class Comp {
|
|
|
60
60
|
return this.preRendered;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
_setExtra(Extra) {
|
|
64
|
-
if (this.Signal) {
|
|
65
|
-
Extra.value = this.Signal.value;
|
|
66
|
-
}
|
|
67
|
-
this.Signal = Extra;
|
|
68
|
-
}
|
|
69
63
|
_effect(fn) {
|
|
70
64
|
if (!this.rendered) {
|
|
71
65
|
this.effects.push(fn.bind(this));
|
|
@@ -124,145 +118,55 @@ class Comp {
|
|
|
124
118
|
}
|
|
125
119
|
}
|
|
126
120
|
|
|
127
|
-
class lazy {
|
|
128
|
-
content;
|
|
129
|
-
_cb;
|
|
130
|
-
constructor(cb) {
|
|
131
|
-
this._cb = cb;
|
|
132
|
-
}
|
|
133
|
-
async load() {
|
|
134
|
-
let content = await this._cb();
|
|
135
|
-
if (typeof content === "function") {
|
|
136
|
-
content = await content();
|
|
137
|
-
} else {
|
|
138
|
-
content = await content;
|
|
139
|
-
}
|
|
140
|
-
const def = content;
|
|
141
|
-
if (def.default) {
|
|
142
|
-
this.content = def?.default;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
121
|
class Signal {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
comp = [];
|
|
152
|
-
value;
|
|
122
|
+
pn;
|
|
123
|
+
subs;
|
|
124
|
+
pipe;
|
|
153
125
|
constructor(initial, props) {
|
|
154
|
-
this.
|
|
126
|
+
this.pipe = initial;
|
|
127
|
+
this.subs = {};
|
|
155
128
|
if (props && props.persistName) {
|
|
156
|
-
this.
|
|
129
|
+
this.pn = props.persistName;
|
|
157
130
|
const key = localStorage.getItem(props.persistName);
|
|
158
131
|
if (key && key !== "undefined") {
|
|
159
|
-
this.
|
|
132
|
+
this.pipe = JSON.parse(key);
|
|
160
133
|
}
|
|
161
134
|
if (typeof initial === "object") {
|
|
162
135
|
for (const key2 in initial) {
|
|
163
|
-
if (!Object.prototype.hasOwnProperty.call(this.
|
|
164
|
-
this.
|
|
136
|
+
if (!Object.prototype.hasOwnProperty.call(this.pipe, key2)) {
|
|
137
|
+
this.pipe[key2] = initial[key2];
|
|
165
138
|
}
|
|
166
139
|
}
|
|
167
140
|
}
|
|
168
141
|
}
|
|
169
142
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.updateState();
|
|
178
|
-
}
|
|
179
|
-
if (this.callback) {
|
|
180
|
-
this.callback(this.value);
|
|
143
|
+
publish(eventName, data) {
|
|
144
|
+
this.pipe[eventName] = data;
|
|
145
|
+
const subs = this.subs[eventName] || [];
|
|
146
|
+
for (let i = 0;i < subs.length; i++) {
|
|
147
|
+
const comp = subs[i];
|
|
148
|
+
comp.subData = data;
|
|
149
|
+
comp.recall();
|
|
181
150
|
}
|
|
182
|
-
if (this.
|
|
183
|
-
localStorage.setItem(this.
|
|
151
|
+
if (this.pn) {
|
|
152
|
+
localStorage.setItem(this.pn, JSON.stringify(this.pipe));
|
|
184
153
|
}
|
|
185
154
|
}
|
|
186
|
-
|
|
187
|
-
if (
|
|
188
|
-
this.
|
|
189
|
-
|
|
190
|
-
this.updateState();
|
|
191
|
-
}
|
|
192
|
-
if (this.callback) {
|
|
193
|
-
this.callback(this.value);
|
|
194
|
-
}
|
|
195
|
-
if (this.persistName) {
|
|
196
|
-
localStorage.setItem(this.persistName, JSON.stringify(this.value));
|
|
155
|
+
subscribe(eventName, comp) {
|
|
156
|
+
if (comp instanceof Comp) {
|
|
157
|
+
if (this.subs[eventName]?.find((cmp) => cmp.id === comp.id)) {
|
|
158
|
+
return;
|
|
197
159
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
createAction(name, action) {
|
|
203
|
-
if (typeof name === "string" && typeof action === "function") {
|
|
204
|
-
this.actions[name] = action.bind(this);
|
|
205
|
-
} else {
|
|
206
|
-
throw new Error(`\u2718 Cradova err : can't create action ${name}, check values`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
createActions(Actions) {
|
|
210
|
-
for (const [name, action] of Object.entries(Actions)) {
|
|
211
|
-
if (typeof name === "string" && typeof action === "function") {
|
|
212
|
-
this.actions[name] = action;
|
|
160
|
+
if (!this.subs[eventName]) {
|
|
161
|
+
this.subs[eventName] = [comp];
|
|
213
162
|
} else {
|
|
214
|
-
|
|
163
|
+
this.subs[eventName].push(comp);
|
|
215
164
|
}
|
|
216
165
|
}
|
|
217
166
|
}
|
|
218
|
-
fireAction(key) {
|
|
219
|
-
if (typeof this.actions[key] === "function") {
|
|
220
|
-
this.updateState(key);
|
|
221
|
-
return this.actions[key].call(this);
|
|
222
|
-
} else {
|
|
223
|
-
throw Error("\u2718 Cradova err : action " + key + " does not exist!");
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
bind(prop) {
|
|
227
|
-
if (typeof this.value === "object" && typeof this.value[prop] !== "undefined") {
|
|
228
|
-
return [this, prop];
|
|
229
|
-
} else {
|
|
230
|
-
throw new Error("\u2718 Cradova err : can't bind an unavailable property! " + prop);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
updateState(name) {
|
|
234
|
-
for (let i = 0;i < this.comp.length; i++) {
|
|
235
|
-
const ent = this.comp[i];
|
|
236
|
-
if (ent._event && ent._event === name) {
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
if (ent._element_property && ent._signalProperty) {
|
|
240
|
-
ent.comp[ent._element_property] = this.value[ent._signalProperty];
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
ent.comp.recall();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
bindComp(comp, binding) {
|
|
247
|
-
if (comp instanceof Comp) {
|
|
248
|
-
if (this.comp.find((cmp) => cmp.comp?.id === comp.id))
|
|
249
|
-
return;
|
|
250
|
-
comp.render = comp.render.bind(comp);
|
|
251
|
-
comp._setExtra(this);
|
|
252
|
-
}
|
|
253
|
-
this.comp.push({
|
|
254
|
-
comp,
|
|
255
|
-
_signalProperty: binding?.signalProperty,
|
|
256
|
-
_element_property: binding?._element_property,
|
|
257
|
-
_event: binding?.event
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
listen(callback) {
|
|
261
|
-
this.callback = callback;
|
|
262
|
-
}
|
|
263
167
|
clearPersist() {
|
|
264
|
-
if (this.
|
|
265
|
-
localStorage.removeItem(this.
|
|
168
|
+
if (this.pn) {
|
|
169
|
+
localStorage.removeItem(this.pn);
|
|
266
170
|
}
|
|
267
171
|
}
|
|
268
172
|
}
|
|
@@ -634,8 +538,12 @@ class __raw_ref {
|
|
|
634
538
|
bindAs(name) {
|
|
635
539
|
return [this, name];
|
|
636
540
|
}
|
|
637
|
-
|
|
638
|
-
|
|
541
|
+
elem(name) {
|
|
542
|
+
const elem = this.tree[name];
|
|
543
|
+
if (document.contains(elem)) {
|
|
544
|
+
return elem;
|
|
545
|
+
}
|
|
546
|
+
this.tree[name] = undefined;
|
|
639
547
|
}
|
|
640
548
|
swap(name1, name2) {
|
|
641
549
|
[this.tree[name1], this.tree[name2]] = [this.tree[name2], this.tree[name1]];
|
|
@@ -702,13 +610,6 @@ var makeElement = (element, ElementChildrenAndPropertyList) => {
|
|
|
702
610
|
value[0]._append(value[1], element);
|
|
703
611
|
continue;
|
|
704
612
|
}
|
|
705
|
-
if (value[0] instanceof Signal) {
|
|
706
|
-
value[0].bindComp(element, {
|
|
707
|
-
_element_property: prop,
|
|
708
|
-
signalProperty: value[1]
|
|
709
|
-
});
|
|
710
|
-
continue;
|
|
711
|
-
}
|
|
712
613
|
}
|
|
713
614
|
if (prop === "onmount") {
|
|
714
615
|
CradovaEvent.afterMount.push(() => {
|
|
@@ -853,7 +754,6 @@ export {
|
|
|
853
754
|
main,
|
|
854
755
|
loop,
|
|
855
756
|
li,
|
|
856
|
-
lazy,
|
|
857
757
|
label,
|
|
858
758
|
input,
|
|
859
759
|
img,
|
|
@@ -43,7 +43,7 @@ export declare class Comp<Prop extends Record<string, any> = any> {
|
|
|
43
43
|
private published;
|
|
44
44
|
private preRendered;
|
|
45
45
|
private reference;
|
|
46
|
-
|
|
46
|
+
subData: Prop | null;
|
|
47
47
|
_state: Prop[];
|
|
48
48
|
_state_index: number;
|
|
49
49
|
test?: string;
|
|
@@ -57,7 +57,6 @@ export declare class Comp<Prop extends Record<string, any> = any> {
|
|
|
57
57
|
* @returns () => HTMLElement
|
|
58
58
|
*/
|
|
59
59
|
render(): any;
|
|
60
|
-
_setExtra(Extra: Signal<any>): void;
|
|
61
60
|
_effect(fn: () => Promise<void> | void): void;
|
|
62
61
|
private effector;
|
|
63
62
|
/**
|
|
@@ -70,73 +69,24 @@ export declare class Comp<Prop extends Record<string, any> = any> {
|
|
|
70
69
|
recall(): void;
|
|
71
70
|
private activate;
|
|
72
71
|
}
|
|
73
|
-
/**
|
|
74
|
-
* cradova
|
|
75
|
-
* ---
|
|
76
|
-
* lazy load a file
|
|
77
|
-
*/
|
|
78
|
-
export declare class lazy<Type> {
|
|
79
|
-
content: Type | undefined;
|
|
80
|
-
private _cb;
|
|
81
|
-
constructor(cb: () => Promise<unknown>);
|
|
82
|
-
load(): Promise<void>;
|
|
83
|
-
}
|
|
84
72
|
/**
|
|
85
73
|
* Cradova Signal
|
|
86
74
|
* ----
|
|
87
75
|
* Create stateful data store.
|
|
88
76
|
* Features:
|
|
89
77
|
* - create a store
|
|
90
|
-
* -
|
|
91
|
-
* - bind a Comp and elements
|
|
92
|
-
* - listen to updates
|
|
78
|
+
* - subscribe components to events
|
|
93
79
|
* - set object keys instead of all values
|
|
94
80
|
* - persist changes to localStorage
|
|
95
|
-
* - update a cradova Comp automatically
|
|
96
81
|
* @constructor initial: unknown, props: {useHistory, persist}
|
|
97
82
|
*/
|
|
98
83
|
export declare class Signal<Type extends Record<string, any>> {
|
|
99
|
-
private
|
|
100
|
-
private
|
|
101
|
-
|
|
102
|
-
private comp;
|
|
103
|
-
value: Type;
|
|
84
|
+
private pn?;
|
|
85
|
+
private subs?;
|
|
86
|
+
pipe: Type;
|
|
104
87
|
constructor(initial: Type, props?: {
|
|
105
88
|
persistName?: string | undefined;
|
|
106
89
|
});
|
|
107
|
-
/**
|
|
108
|
-
* Cradova Signal
|
|
109
|
-
* ----
|
|
110
|
-
* set signal value
|
|
111
|
-
* @param value - signal value
|
|
112
|
-
* @returns void
|
|
113
|
-
*/
|
|
114
|
-
set(value: Type | ((value: Type) => Type), shouldCompRender?: boolean): void;
|
|
115
|
-
/**
|
|
116
|
-
* Cradova Signal
|
|
117
|
-
* ----
|
|
118
|
-
* set a key value if it's an object
|
|
119
|
-
* @param key - key of the key
|
|
120
|
-
* @param value - value of the key
|
|
121
|
-
* @returns void
|
|
122
|
-
*/
|
|
123
|
-
setKey<k extends keyof Type>(key: k, value: unknown, shouldCompRender?: boolean): void;
|
|
124
|
-
/**
|
|
125
|
-
* Cradova Signal
|
|
126
|
-
* ----
|
|
127
|
-
* set a key to signal an action
|
|
128
|
-
* @param name - name of the action
|
|
129
|
-
* @param action function to execute
|
|
130
|
-
*/
|
|
131
|
-
createAction(name: string, action: (data?: unknown) => void): void;
|
|
132
|
-
/**
|
|
133
|
-
* Cradova Signal
|
|
134
|
-
* ----
|
|
135
|
-
* creates man y actions at a time
|
|
136
|
-
* @param name - name of the action
|
|
137
|
-
* @param action function to execute
|
|
138
|
-
*/
|
|
139
|
-
createActions(Actions: Record<string, (data?: unknown) => void>): void;
|
|
140
90
|
/**
|
|
141
91
|
* Cradova Signal
|
|
142
92
|
* ----
|
|
@@ -144,36 +94,15 @@ export declare class Signal<Type extends Record<string, any>> {
|
|
|
144
94
|
* @param key - string key of the action
|
|
145
95
|
* @param data - data for the action
|
|
146
96
|
*/
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Cradova
|
|
150
|
-
* ---
|
|
151
|
-
* is used to bind signal data to elements and Comps
|
|
152
|
-
*
|
|
153
|
-
* @param prop
|
|
154
|
-
* @returns something
|
|
155
|
-
*/
|
|
156
|
-
bind(prop: string): any;
|
|
157
|
-
private updateState;
|
|
97
|
+
publish<T extends keyof Type>(eventName: T, data: Type[T]): void;
|
|
158
98
|
/**
|
|
159
99
|
* Cradova Signal
|
|
160
100
|
* ----
|
|
161
|
-
*
|
|
101
|
+
* subscribe to an event
|
|
162
102
|
*
|
|
163
103
|
* @param Comp component to bind to.
|
|
164
104
|
*/
|
|
165
|
-
|
|
166
|
-
event?: string;
|
|
167
|
-
signalProperty?: string;
|
|
168
|
-
_element_property?: string;
|
|
169
|
-
}): void;
|
|
170
|
-
/**
|
|
171
|
-
* Cradova Signal
|
|
172
|
-
* ----
|
|
173
|
-
* set a update listener on value changes
|
|
174
|
-
* @param callback
|
|
175
|
-
*/
|
|
176
|
-
listen(callback: (a: Type) => void): void;
|
|
105
|
+
subscribe<T extends keyof Type>(eventName: T, comp: Comp): void;
|
|
177
106
|
/**
|
|
178
107
|
* Cradova Signal
|
|
179
108
|
* ----
|
|
@@ -16,7 +16,7 @@ declare class __raw_ref {
|
|
|
16
16
|
* Retrieve a referenced DOM element.
|
|
17
17
|
* @param name - The name of the referenced DOM element.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
elem<ElementType extends HTMLElement = HTMLElement>(name: string): ElementType | undefined;
|
|
20
20
|
/**
|
|
21
21
|
* Swap referenced DOM element.
|
|
22
22
|
*/
|
|
@@ -35,9 +35,9 @@ export declare function Rhoda(l: VJS_params_TYPE<HTMLElement>): DocumentFragment
|
|
|
35
35
|
* @param {expression} condition
|
|
36
36
|
* @param {function} elements[]
|
|
37
37
|
*/
|
|
38
|
-
export declare function $if<E>(condition: any, ...elements: VJS_params_TYPE<E>): any;
|
|
38
|
+
export declare function $if<E extends HTMLElement>(condition: any, ...elements: VJS_params_TYPE<E>): any;
|
|
39
39
|
export declare function $ifelse(condition: any, ifTrue: any, ifFalse?: any): any;
|
|
40
|
-
export declare function $case<E = HTMLElement>(value: any, ...elements: VJS_params_TYPE<E>): (key: any) => VJS_params_TYPE<E> | undefined;
|
|
40
|
+
export declare function $case<E extends HTMLElement = HTMLElement>(value: any, ...elements: VJS_params_TYPE<E>): (key: any) => VJS_params_TYPE<E> | undefined;
|
|
41
41
|
export declare function $switch(key: unknown, ...cases: ((key: any) => any)[]): any;
|
|
42
42
|
type LoopData<Type> = Type[];
|
|
43
43
|
export declare function loop<Type>(datalist: LoopData<Type>, component: (value: Type, index?: number, array?: LoopData<Type>) => HTMLElement | DocumentFragment | undefined): HTMLElement[] | undefined;
|
|
@@ -30,9 +30,7 @@ type Attributes = {
|
|
|
30
30
|
recall?: (P: any) => void;
|
|
31
31
|
onmount?: (this: HTMLElement & Attributes) => void;
|
|
32
32
|
};
|
|
33
|
-
export type VJS_params_TYPE<E
|
|
34
|
-
[K in keyof HTMLElementEventMap]?: (this: E, e: HTMLElementEventMap[K]) => void;
|
|
35
|
-
} | Partial<DataAttributes> | Partial<AriaAttributes> | CSS.Properties<string | number>)[];
|
|
33
|
+
export type VJS_params_TYPE<E extends HTMLElement> = (Comp | Comp[] | string | undefined | HTMLElement | HTMLElement[] | DocumentFragment | DocumentFragment[] | Attributes | (() => HTMLElement) | Partial<Attributes> | Partial<E> | Record<string, (this: E) => void> | Partial<DataAttributes> | Partial<AriaAttributes> | CSS.Properties<string | number>)[];
|
|
36
34
|
export interface RouterRouteObject {
|
|
37
35
|
_html: ((this: Page, data?: unknown) => HTMLElement | DocumentFragment) | HTMLElement | DocumentFragment;
|
|
38
36
|
_delegatedRoutes: number | boolean;
|