valyrian.js 7.2.9 → 7.2.11
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/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +11 -4
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +10 -4
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +2 -2
- package/dist/hooks/index.mjs.map +2 -2
- package/dist/index.d.ts +17 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +2 -2
- package/dist/node/index.js +22 -11
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +21 -11
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/inline.d.ts +2 -2
- package/dist/node/utils/inline.d.ts.map +1 -1
- package/dist/node/utils/tree-adapter.d.ts +3 -3
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +1 -0
- package/dist/proxy-signal/index.js.map +1 -1
- package/dist/request/index.js +1 -0
- package/dist/request/index.js.map +1 -1
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +5 -3
- package/dist/router/index.js.map +3 -3
- package/dist/router/index.mjs +4 -3
- package/dist/router/index.mjs.map +3 -3
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +3 -2
- package/dist/signal/index.js.map +2 -2
- package/dist/signal/index.mjs +2 -2
- package/dist/signal/index.mjs.map +2 -2
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/sw/index.d.ts +1 -1
- package/dist/sw/index.d.ts.map +1 -1
- package/dist/sw/index.js +1 -0
- package/dist/sw/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/lib/dataset/index.ts +15 -7
- package/lib/hooks/index.ts +2 -2
- package/lib/index.d.ts +0 -0
- package/lib/index.ts +22 -31
- package/lib/interfaces.ts.bak +141 -0
- package/lib/node/utils/inline.ts +17 -2
- package/lib/node/utils/tree-adapter.ts +15 -11
- package/lib/router/index.ts +16 -4
- package/lib/signal/index.ts +5 -5
- package/package.json +1 -1
- package/tsconfig.json +22 -8
- package/dist/interfaces.d.ts +0 -96
- package/dist/interfaces.d.ts.map +0 -1
- package/lib/interfaces.ts +0 -98
package/lib/dataset/index.ts
CHANGED
|
@@ -35,9 +35,9 @@ function deepFreeze(obj: any) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export class DataSet<T> implements DataSetInterface<T> {
|
|
38
|
-
#vnode: VnodeWithDom;
|
|
38
|
+
#vnode: VnodeWithDom | null = null;
|
|
39
39
|
// eslint-disable-next-line no-unused-vars
|
|
40
|
-
#handler: DataSetHandler<T
|
|
40
|
+
#handler: DataSetHandler<T> | null = null;
|
|
41
41
|
#data: T[] = [];
|
|
42
42
|
#isFrozen = false;
|
|
43
43
|
#dataProxy: T[] | null = null;
|
|
@@ -64,7 +64,7 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
64
64
|
set: () => {
|
|
65
65
|
throw new Error("You need to use the add, update or delete methods to change the data");
|
|
66
66
|
},
|
|
67
|
-
get(target, prop) {
|
|
67
|
+
get(target: any, prop: string) {
|
|
68
68
|
return target[prop];
|
|
69
69
|
},
|
|
70
70
|
deleteProperty: () => {
|
|
@@ -86,6 +86,10 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
86
86
|
|
|
87
87
|
reset(data: T[]) {
|
|
88
88
|
this.#setData(data);
|
|
89
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
89
93
|
let vnode = this.#vnode;
|
|
90
94
|
let handler = this.#handler;
|
|
91
95
|
|
|
@@ -132,6 +136,10 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
132
136
|
this.#data.push(...data);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
135
143
|
let vnode = this.#vnode;
|
|
136
144
|
let handler = this.#handler;
|
|
137
145
|
|
|
@@ -147,8 +155,8 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
delete(index) {
|
|
151
|
-
if (this.#data) {
|
|
158
|
+
delete(index: number) {
|
|
159
|
+
if (this.#data && this.#vnode) {
|
|
152
160
|
let child = this.#vnode.children[index];
|
|
153
161
|
if (this.#isFrozen) {
|
|
154
162
|
this.#setData(this.data.filter((_, i) => i !== index));
|
|
@@ -161,8 +169,8 @@ export class DataSet<T> implements DataSetInterface<T> {
|
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
|
|
164
|
-
update(index, item: Partial<T>) {
|
|
165
|
-
if (this.#data) {
|
|
172
|
+
update(index: number, item: Partial<T>) {
|
|
173
|
+
if (this.#data && this.#vnode && this.#handler) {
|
|
166
174
|
let child = this.#vnode.children[index];
|
|
167
175
|
if (this.#isFrozen) {
|
|
168
176
|
this.#setData(this.#data.map((d, i) => (i === index ? { ...d, ...item } : d)));
|
package/lib/hooks/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const createHook = function createHook({
|
|
|
36
36
|
return (...args: any[]) => {
|
|
37
37
|
let { component, vnode } = current as CurrentOnPatch;
|
|
38
38
|
|
|
39
|
-
let hook = null;
|
|
39
|
+
let hook: any = null;
|
|
40
40
|
|
|
41
41
|
if (vnode) {
|
|
42
42
|
// Init the components array for the current vnode
|
|
@@ -109,7 +109,7 @@ export const useState = createHook({
|
|
|
109
109
|
get.toJSON = get.valueOf = get;
|
|
110
110
|
get.toString = () => `${value}`;
|
|
111
111
|
|
|
112
|
-
function set(newValue) {
|
|
112
|
+
function set(newValue: any) {
|
|
113
113
|
// Prevent default event if it exists
|
|
114
114
|
if (current.event) {
|
|
115
115
|
current.event.preventDefault();
|
package/lib/index.d.ts
ADDED
|
File without changes
|
package/lib/index.ts
CHANGED
|
@@ -3,26 +3,24 @@
|
|
|
3
3
|
/* eslint-disable sonarjs/cognitive-complexity */
|
|
4
4
|
/* eslint-disable complexity */
|
|
5
5
|
|
|
6
|
+
interface DefaultRecord extends Record<string | number | symbol, any> {}
|
|
7
|
+
|
|
6
8
|
// The VnodeProperties interface represents properties that can be passed to a virtual node.
|
|
7
|
-
export interface VnodeProperties {
|
|
9
|
+
export interface VnodeProperties extends DefaultRecord {
|
|
8
10
|
// A unique key for the virtual node, which can be a string or a number.
|
|
9
11
|
// This is useful for optimizing updates in a list of nodes.
|
|
10
12
|
key?: string | number;
|
|
11
13
|
// A state object that is associated with the virtual node.
|
|
12
14
|
state?: any;
|
|
13
|
-
// An index signature that allows for any other properties to be added.
|
|
14
|
-
[key: string | number | symbol]: any;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// The DomElement interface extends the Element interface with an index signature.
|
|
18
18
|
// This allows for any additional properties to be added to DOM elements.
|
|
19
|
-
export interface DomElement extends Element {
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}
|
|
19
|
+
export interface DomElement extends Element, DefaultRecord {}
|
|
22
20
|
|
|
23
21
|
// The VnodeInterface represents a virtual node. It has a number of optional fields,
|
|
24
22
|
// including a tag, props, children, and a DOM element.
|
|
25
|
-
export interface VnodeInterface {
|
|
23
|
+
export interface VnodeInterface extends DefaultRecord {
|
|
26
24
|
// The constructor for the virtual node. It takes a tag, props, and children as arguments.
|
|
27
25
|
// The tag can be a string, a component, or a POJO component.
|
|
28
26
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -39,8 +37,6 @@ export interface VnodeInterface {
|
|
|
39
37
|
dom?: DomElement;
|
|
40
38
|
// A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.
|
|
41
39
|
processed?: boolean;
|
|
42
|
-
// An index signature that allows for any additional properties to be added to the virtual node.
|
|
43
|
-
[key: string | number | symbol]: any;
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.
|
|
@@ -50,28 +46,24 @@ export interface VnodeWithDom extends VnodeInterface {
|
|
|
50
46
|
|
|
51
47
|
// The Component interface represents a function that returns a virtual node or a list of virtual nodes.
|
|
52
48
|
// It can also have additional properties.
|
|
53
|
-
export interface Component {
|
|
49
|
+
export interface Component extends DefaultRecord {
|
|
54
50
|
// The function that returns a virtual node or a list of virtual nodes.
|
|
55
51
|
// It can take props and children as arguments.
|
|
56
52
|
// eslint-disable-next-line no-unused-vars
|
|
57
53
|
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
58
|
-
// An index signature that allows for any additional properties to be added to the component.
|
|
59
|
-
[key: string]: any;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
// The POJOComponent interface represents a "plain old JavaScript object" (POJO) component.
|
|
63
57
|
// It has a view function that returns a virtual node or a list of virtual nodes,
|
|
64
58
|
// as well as optional props and children.
|
|
65
59
|
// It can be used also to identify class instance components.
|
|
66
|
-
export interface POJOComponent {
|
|
60
|
+
export interface POJOComponent extends DefaultRecord {
|
|
67
61
|
// The view function that returns a virtual node or a list of virtual nodes.
|
|
68
62
|
view: Component;
|
|
69
63
|
// The props for the component.
|
|
70
64
|
props?: VnodeProperties | null;
|
|
71
65
|
// The children for the component.
|
|
72
66
|
children?: any[];
|
|
73
|
-
// An index signature that allows for any additional properties to be added to the POJO component.
|
|
74
|
-
[key: string]: any;
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
// The VnodeComponentInterface represents a virtual node that has a component as its tag.
|
|
@@ -95,15 +87,11 @@ export interface Directive {
|
|
|
95
87
|
}
|
|
96
88
|
|
|
97
89
|
// The Directives interface is a mapping of directive names to Directive functions.
|
|
98
|
-
export interface Directives {
|
|
99
|
-
[key: string]: Directive;
|
|
100
|
-
}
|
|
90
|
+
export interface Directives extends Record<string, Directive> {}
|
|
101
91
|
|
|
102
92
|
// The ReservedProps interface is a mapping of reserved prop names to the value `true`.
|
|
103
93
|
// These prop names cannot be used as custom prop names.
|
|
104
|
-
export interface ReservedProps {
|
|
105
|
-
[key: string]: true;
|
|
106
|
-
}
|
|
94
|
+
export interface ReservedProps extends Record<string, true> {}
|
|
107
95
|
|
|
108
96
|
// The Current interface represents the current component and virtual node that are being processed.
|
|
109
97
|
export interface Current {
|
|
@@ -127,6 +115,7 @@ export interface V {
|
|
|
127
115
|
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
128
116
|
fragment(_: any, ...children: Children): Children;
|
|
129
117
|
}
|
|
118
|
+
|
|
130
119
|
// 'textTag' is a constant string that is used to represent text nodes in the virtual DOM.
|
|
131
120
|
const textTag = "#text";
|
|
132
121
|
|
|
@@ -153,8 +142,10 @@ export const Vnode = function Vnode(this: VnodeInterface, tag: string, props: Vn
|
|
|
153
142
|
|
|
154
143
|
// 'isComponent' is a function that returns true if the given 'component' is a valid component and false otherwise.
|
|
155
144
|
// A component is either a function or an object with a 'view' function.
|
|
156
|
-
export function isComponent(component): component is Component {
|
|
157
|
-
return
|
|
145
|
+
export function isComponent(component: unknown): component is Component {
|
|
146
|
+
return Boolean(
|
|
147
|
+
component && (typeof component === "function" || (typeof component === "object" && "view" in component))
|
|
148
|
+
);
|
|
158
149
|
}
|
|
159
150
|
|
|
160
151
|
// 'isVnode' is a function that returns true if the given 'object' is a 'Vnode' instance and false otherwise.
|
|
@@ -268,28 +259,28 @@ const onUpdateSet: Set<Function> = new Set();
|
|
|
268
259
|
const onUnmountSet: Set<Function> = new Set();
|
|
269
260
|
|
|
270
261
|
// These functions allow users to register callbacks for the corresponding lifecycle events.
|
|
271
|
-
export function onMount(callback) {
|
|
262
|
+
export function onMount(callback: Function) {
|
|
272
263
|
if (!isMounted) {
|
|
273
264
|
onMountSet.add(callback);
|
|
274
265
|
}
|
|
275
266
|
}
|
|
276
267
|
|
|
277
|
-
export function onUpdate(callback) {
|
|
268
|
+
export function onUpdate(callback: Function) {
|
|
278
269
|
onUpdateSet.add(callback);
|
|
279
270
|
}
|
|
280
271
|
|
|
281
|
-
export function onCleanup(callback) {
|
|
272
|
+
export function onCleanup(callback: Function) {
|
|
282
273
|
onCleanupSet.add(callback);
|
|
283
274
|
}
|
|
284
275
|
|
|
285
|
-
export function onUnmount(callback) {
|
|
276
|
+
export function onUnmount(callback: Function) {
|
|
286
277
|
if (!isMounted) {
|
|
287
278
|
onUnmountSet.add(callback);
|
|
288
279
|
}
|
|
289
280
|
}
|
|
290
281
|
|
|
291
282
|
// This function is used to call all the callbacks in a given set.
|
|
292
|
-
function callSet(set) {
|
|
283
|
+
function callSet(set: Set<Function>) {
|
|
293
284
|
for (let callback of set) {
|
|
294
285
|
callback();
|
|
295
286
|
}
|
|
@@ -684,13 +675,13 @@ export function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void {
|
|
|
684
675
|
let newTreeLength = newTree.length;
|
|
685
676
|
|
|
686
677
|
// Create an object that maps keys to indices in the old tree
|
|
687
|
-
let oldKeyedList:
|
|
678
|
+
let oldKeyedList: Record<string, number> = {};
|
|
688
679
|
for (let i = 0; i < oldTreeLength; i++) {
|
|
689
680
|
oldKeyedList[oldTree[i].props.key] = i;
|
|
690
681
|
}
|
|
691
682
|
|
|
692
683
|
// Create an object that maps keys to indices in the new tree
|
|
693
|
-
let newKeyedList:
|
|
684
|
+
let newKeyedList: Record<string, number> = {};
|
|
694
685
|
for (let i = 0; i < newTreeLength; i++) {
|
|
695
686
|
newKeyedList[newTree[i].props.key] = i;
|
|
696
687
|
}
|
|
@@ -989,7 +980,7 @@ export function unmount() {
|
|
|
989
980
|
}
|
|
990
981
|
}
|
|
991
982
|
// This function takes in a DOM element or a DOM element selector and a component to be mounted on it.
|
|
992
|
-
export function mount(dom, component) {
|
|
983
|
+
export function mount(dom: string | DomElement, component: any) {
|
|
993
984
|
// Check if the 'dom' argument is a string. If it is, select the first element that matches the given selector.
|
|
994
985
|
// Otherwise, use the 'dom' argument as the container.
|
|
995
986
|
let container =
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
declare module "valyrian.js" {
|
|
4
|
+
interface DefaultRecord extends Record<string | number | symbol, any> {}
|
|
5
|
+
|
|
6
|
+
// The VnodeProperties interface represents properties that can be passed to a virtual node.
|
|
7
|
+
export interface VnodeProperties extends DefaultRecord {
|
|
8
|
+
// A unique key for the virtual node, which can be a string or a number.
|
|
9
|
+
// This is useful for optimizing updates in a list of nodes.
|
|
10
|
+
key?: string | number;
|
|
11
|
+
// A state object that is associated with the virtual node.
|
|
12
|
+
state?: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The DomElement interface extends the Element interface with an index signature.
|
|
16
|
+
// This allows for any additional properties to be added to DOM elements.
|
|
17
|
+
export interface DomElement extends Element, DefaultRecord {}
|
|
18
|
+
|
|
19
|
+
// The VnodeInterface represents a virtual node. It has a number of optional fields,
|
|
20
|
+
// including a tag, props, children, and a DOM element.
|
|
21
|
+
export interface VnodeInterface extends DefaultRecord {
|
|
22
|
+
// The constructor for the virtual node. It takes a tag, props, and children as arguments.
|
|
23
|
+
// The tag can be a string, a component, or a POJO component.
|
|
24
|
+
// eslint-disable-next-line no-unused-vars
|
|
25
|
+
new (tag: string | Component | POJOComponent, props: VnodeProperties, children: Children): VnodeInterface;
|
|
26
|
+
// The tag for the virtual node. It can be a string, a component, or a POJO component.
|
|
27
|
+
tag: string | Component | POJOComponent;
|
|
28
|
+
// The props for the virtual node.
|
|
29
|
+
props: VnodeProperties;
|
|
30
|
+
// The children for the virtual node.
|
|
31
|
+
children: Children;
|
|
32
|
+
// A boolean indicating whether the virtual node is an SVG element.
|
|
33
|
+
isSVG?: boolean;
|
|
34
|
+
// The DOM element that corresponds to the virtual node.
|
|
35
|
+
dom?: DomElement;
|
|
36
|
+
// A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.
|
|
37
|
+
processed?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.
|
|
41
|
+
export interface VnodeWithDom extends VnodeInterface {
|
|
42
|
+
dom: DomElement;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The Component interface represents a function that returns a virtual node or a list of virtual nodes.
|
|
46
|
+
// It can also have additional properties.
|
|
47
|
+
export interface Component extends DefaultRecord {
|
|
48
|
+
// The function that returns a virtual node or a list of virtual nodes.
|
|
49
|
+
// It can take props and children as arguments.
|
|
50
|
+
// eslint-disable-next-line no-unused-vars
|
|
51
|
+
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The POJOComponent interface represents a "plain old JavaScript object" (POJO) component.
|
|
55
|
+
// It has a view function that returns a virtual node or a list of virtual nodes,
|
|
56
|
+
// as well as optional props and children.
|
|
57
|
+
// It can be used also to identify class instance components.
|
|
58
|
+
export interface POJOComponent extends DefaultRecord {
|
|
59
|
+
// The view function that returns a virtual node or a list of virtual nodes.
|
|
60
|
+
view: Component;
|
|
61
|
+
// The props for the component.
|
|
62
|
+
props?: VnodeProperties | null;
|
|
63
|
+
// The children for the component.
|
|
64
|
+
children?: any[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// The VnodeComponentInterface represents a virtual node that has a component as its tag.
|
|
68
|
+
// It has props and children, just like a regular virtual node.
|
|
69
|
+
export interface VnodeComponentInterface extends VnodeInterface {
|
|
70
|
+
tag: Component | POJOComponent;
|
|
71
|
+
props: VnodeProperties;
|
|
72
|
+
children: Children;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The Children interface represents a list of virtual nodes or other values.
|
|
76
|
+
export interface Children extends Array<VnodeInterface | VnodeComponentInterface | any> {}
|
|
77
|
+
|
|
78
|
+
// The Directive interface represents a function that can be applied to a virtual node.
|
|
79
|
+
// It receives the value, virtual node, and old virtual node as arguments, and can return a boolean value.
|
|
80
|
+
// If only the virtual node is passed, it means its the on create phase for the v-node.
|
|
81
|
+
// If the old virtual node is also passed, it means its the on update phase for the v-node.
|
|
82
|
+
export interface Directive {
|
|
83
|
+
// eslint-disable-next-line no-unused-vars
|
|
84
|
+
(value: any, vnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The Directives interface is a mapping of directive names to Directive functions.
|
|
88
|
+
export interface Directives extends Record<string, Directive> {}
|
|
89
|
+
|
|
90
|
+
// The ReservedProps interface is a mapping of reserved prop names to the value `true`.
|
|
91
|
+
// These prop names cannot be used as custom prop names.
|
|
92
|
+
export interface ReservedProps extends Record<string, true> {}
|
|
93
|
+
|
|
94
|
+
// The Current interface represents the current component and virtual node that are being processed.
|
|
95
|
+
export interface Current {
|
|
96
|
+
// The current component. It can be a component, a POJO component, or null.
|
|
97
|
+
component: Component | POJOComponent | null;
|
|
98
|
+
// The current virtual node. It must have a DOM element associated with it.
|
|
99
|
+
vnode: VnodeWithDom | null;
|
|
100
|
+
// The old virtual node. It must have a DOM element associated with it.
|
|
101
|
+
oldVnode?: VnodeWithDom | null;
|
|
102
|
+
// The current event. It can be an event or null.
|
|
103
|
+
event: Event | null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The V function is the main function for creating virtual nodes.
|
|
107
|
+
// It takes a tag or component, props, and children as arguments, and returns a virtual node.
|
|
108
|
+
export interface V {
|
|
109
|
+
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
110
|
+
(tagOrComponent: string | Component | POJOComponent, props: VnodeProperties | null, ...children: Children):
|
|
111
|
+
| VnodeInterface
|
|
112
|
+
| VnodeComponentInterface;
|
|
113
|
+
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
114
|
+
fragment(_: any, ...children: Children): Children;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export let isNodeJs: boolean;
|
|
118
|
+
export function createDomElement(tag: string, isSVG?: boolean): DomElement;
|
|
119
|
+
export const Vnode: VnodeInterface;
|
|
120
|
+
export function isComponent(component: any): component is Component;
|
|
121
|
+
export const isVnode: (object?: unknown | VnodeInterface) => object is VnodeInterface;
|
|
122
|
+
export const isVnodeComponent: (object?: unknown | VnodeComponentInterface) => object is VnodeComponentInterface;
|
|
123
|
+
export function domToVnode(dom: any): VnodeWithDom;
|
|
124
|
+
export function trust(htmlString: string): any;
|
|
125
|
+
export const current: Current;
|
|
126
|
+
export const reservedProps: Record<string, true>;
|
|
127
|
+
export function onMount(callback: any): void;
|
|
128
|
+
export function onUpdate(callback: any): void;
|
|
129
|
+
export function onCleanup(callback: any): void;
|
|
130
|
+
export function onUnmount(callback: any): void;
|
|
131
|
+
export const directives: Directives;
|
|
132
|
+
export function directive(name: string, directive: Directive): void;
|
|
133
|
+
export function setAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
134
|
+
export function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
135
|
+
export function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
136
|
+
export function update(): void | string;
|
|
137
|
+
export function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
|
|
138
|
+
export function unmount(): string | void;
|
|
139
|
+
export function mount(dom: any, component: any): string | void;
|
|
140
|
+
export const v: V;
|
|
141
|
+
}
|
package/lib/node/utils/inline.ts
CHANGED
|
@@ -6,7 +6,11 @@ import esbuild from "esbuild";
|
|
|
6
6
|
/* eslint-disable sonarjs/cognitive-complexity */
|
|
7
7
|
import fs from "fs";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
|
+
export async function inline(
|
|
11
|
+
file: string | { raw: string; map?: string | null; file: string },
|
|
12
|
+
options: Record<string, any> = {}
|
|
13
|
+
) {
|
|
10
14
|
if (typeof file === "string") {
|
|
11
15
|
let ext = file.split(".").pop();
|
|
12
16
|
if (ext && /(js|cjs|jsx|mjs|ts|tsx)/.test(ext)) {
|
|
@@ -69,6 +73,9 @@ export async function inline(file: string | { raw: string; map?: string | null;
|
|
|
69
73
|
};
|
|
70
74
|
|
|
71
75
|
let result = await esbuild.build(esbuildOptions);
|
|
76
|
+
if (result.outputFiles?.length !== 2) {
|
|
77
|
+
throw new Error(result.errors.join("\n"));
|
|
78
|
+
}
|
|
72
79
|
|
|
73
80
|
if (options.compact) {
|
|
74
81
|
const terser = await import("terser");
|
|
@@ -86,6 +93,10 @@ export async function inline(file: string | { raw: string; map?: string | null;
|
|
|
86
93
|
...(options.terser || {})
|
|
87
94
|
});
|
|
88
95
|
|
|
96
|
+
if (!result2.code || !result2.map) {
|
|
97
|
+
throw new Error("Unknown error");
|
|
98
|
+
}
|
|
99
|
+
|
|
89
100
|
let mapBase64 = Buffer.from(result2.map.toString()).toString("base64");
|
|
90
101
|
let suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
|
91
102
|
return { raw: result2.code, map: suffix, file };
|
|
@@ -117,7 +128,11 @@ export async function inline(file: string | { raw: string; map?: string | null;
|
|
|
117
128
|
}
|
|
118
129
|
}
|
|
119
130
|
|
|
120
|
-
inline.uncss = async function (
|
|
131
|
+
inline.uncss = async function (
|
|
132
|
+
renderedHtml: (string | Promise<string>)[],
|
|
133
|
+
css: string,
|
|
134
|
+
options: Record<string, any> = {}
|
|
135
|
+
) {
|
|
121
136
|
let html = await Promise.all(renderedHtml);
|
|
122
137
|
|
|
123
138
|
let contents = html.map((item) => {
|
|
@@ -56,26 +56,30 @@ export class Node implements Node {
|
|
|
56
56
|
constructor() {}
|
|
57
57
|
|
|
58
58
|
appendChild<T extends Node>(node: T): T {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (node) {
|
|
60
|
+
node.parentNode && node.parentNode.removeChild(node as Node);
|
|
61
|
+
this.childNodes.push(node);
|
|
62
|
+
node.parentNode = this;
|
|
63
|
+
}
|
|
62
64
|
return node;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
insertBefore<T extends Node>(node: T, child: Node | null): T {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
if (node) {
|
|
69
|
+
node.parentNode && node.parentNode.removeChild(node as Node);
|
|
70
|
+
node.parentNode = this;
|
|
71
|
+
if (child) {
|
|
72
|
+
let idx = this.childNodes.indexOf(child);
|
|
73
|
+
this.childNodes.splice(idx, 0, node);
|
|
74
|
+
} else {
|
|
75
|
+
this.childNodes.push(node);
|
|
76
|
+
}
|
|
73
77
|
}
|
|
74
78
|
return node;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
replaceChild<T extends Node>(node: Node, child: T): T {
|
|
78
|
-
if (child && child.parentNode === this) {
|
|
82
|
+
if (node && child && child.parentNode === this) {
|
|
79
83
|
this.insertBefore(node, child);
|
|
80
84
|
child.parentNode && child.parentNode.removeChild(child);
|
|
81
85
|
}
|
package/lib/router/index.ts
CHANGED
|
@@ -65,7 +65,11 @@ interface RouterInterface {
|
|
|
65
65
|
|
|
66
66
|
interface RedirectFunction {
|
|
67
67
|
// eslint-disable-next-line no-unused-vars
|
|
68
|
-
(
|
|
68
|
+
(
|
|
69
|
+
path: string,
|
|
70
|
+
parentComponent?: Component | POJOComponent | VnodeComponentInterface,
|
|
71
|
+
preventPushState?: boolean
|
|
72
|
+
): Promise<string | void>;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
function flat(array: any) {
|
|
@@ -181,7 +185,7 @@ async function searchComponent(
|
|
|
181
185
|
url: router.url,
|
|
182
186
|
path: router.path,
|
|
183
187
|
matches: router.matches,
|
|
184
|
-
redirect: (path: string, parentComponent?: Component) => {
|
|
188
|
+
redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => {
|
|
185
189
|
router.go(path, parentComponent);
|
|
186
190
|
// Return false to stop the middleware chain
|
|
187
191
|
return false;
|
|
@@ -260,7 +264,11 @@ export class Router implements RouterInterface {
|
|
|
260
264
|
return this.paths.filter((path) => path.method === "add").map((path) => path.path);
|
|
261
265
|
}
|
|
262
266
|
|
|
263
|
-
async go(
|
|
267
|
+
async go(
|
|
268
|
+
path: string,
|
|
269
|
+
parentComponent?: Component | POJOComponent | VnodeComponentInterface,
|
|
270
|
+
preventPushState = false
|
|
271
|
+
): Promise<string | void> {
|
|
264
272
|
if (!path) {
|
|
265
273
|
throw new Error("router.url.required");
|
|
266
274
|
}
|
|
@@ -312,7 +320,11 @@ export class Router implements RouterInterface {
|
|
|
312
320
|
|
|
313
321
|
let localRedirect: RedirectFunction;
|
|
314
322
|
|
|
315
|
-
export function redirect(
|
|
323
|
+
export function redirect(
|
|
324
|
+
url: string,
|
|
325
|
+
parentComponent?: Component | POJOComponent | VnodeComponentInterface,
|
|
326
|
+
preventPushState = false
|
|
327
|
+
): Promise<string | void> {
|
|
316
328
|
if (!localRedirect) {
|
|
317
329
|
throw new Error("router.redirect.not.found");
|
|
318
330
|
}
|
package/lib/signal/index.ts
CHANGED
|
@@ -22,12 +22,12 @@ export interface SignalInterface extends Array<any> {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
25
|
-
export function Signal(initialValue): SignalInterface {
|
|
25
|
+
export function Signal(initialValue: any): SignalInterface {
|
|
26
26
|
// Create a copy of the current context object
|
|
27
27
|
const { vnode, component } = { ...current };
|
|
28
28
|
|
|
29
29
|
// Check if the context object has a vnode property
|
|
30
|
-
if (vnode) {
|
|
30
|
+
if (vnode && component) {
|
|
31
31
|
// Is first call
|
|
32
32
|
if (!vnode.components) {
|
|
33
33
|
// Set the components property to an empty array
|
|
@@ -70,7 +70,7 @@ export function Signal(initialValue): SignalInterface {
|
|
|
70
70
|
const subscriptions: SubscriptionsInterface = [];
|
|
71
71
|
|
|
72
72
|
// Define a function that allows other parts of the code to subscribe to changes to the Signal's value
|
|
73
|
-
const subscribe = (callback) => {
|
|
73
|
+
const subscribe = (callback: Function) => {
|
|
74
74
|
// Add the callback function to the subscriptions array if it is not already in the array
|
|
75
75
|
if (subscriptions.indexOf(callback) === -1) {
|
|
76
76
|
subscriptions.push(callback);
|
|
@@ -127,7 +127,7 @@ export function Signal(initialValue): SignalInterface {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change
|
|
130
|
-
const set = (newValue) => {
|
|
130
|
+
const set = (newValue: any) => {
|
|
131
131
|
// If we have a current event on going, prevent the default action
|
|
132
132
|
if (current.event) {
|
|
133
133
|
current.event.preventDefault();
|
|
@@ -152,7 +152,7 @@ export function Signal(initialValue): SignalInterface {
|
|
|
152
152
|
|
|
153
153
|
// If the context object has a vnode property, add the signal to the vnode's signals array
|
|
154
154
|
// and add the subscriptions array to the vnode's subscriptions array
|
|
155
|
-
if (vnode) {
|
|
155
|
+
if (vnode && component) {
|
|
156
156
|
component.signals.push(signal);
|
|
157
157
|
}
|
|
158
158
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valyrian.js",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.11",
|
|
4
4
|
"description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
|
|
5
5
|
"repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
|
|
6
6
|
"author": "Masquerade <christian@masquerade-circus.net>",
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
"module": "
|
|
3
|
+
// enable latest features
|
|
4
|
+
"lib": ["esnext", "dom"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
|
|
6
8
|
"moduleResolution": "NodeNext",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
9
|
+
"noEmit": false,
|
|
10
|
+
"moduleDetection": "force",
|
|
11
|
+
|
|
12
|
+
"jsx": "react", // support JSX
|
|
11
13
|
"jsxFactory": "v",
|
|
12
14
|
"jsxFragmentFactory": "v.fragment",
|
|
15
|
+
"allowJs": true, // allow importing `.js` from `.ts`
|
|
16
|
+
"esModuleInterop": true, // allow default imports for CommonJS modules
|
|
17
|
+
|
|
18
|
+
// best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
"skipLibCheck": true,
|
|
22
|
+
"composite": true,
|
|
23
|
+
"downlevelIteration": true,
|
|
24
|
+
"allowSyntheticDefaultImports": true,
|
|
25
|
+
"resolveJsonModule": true,
|
|
26
|
+
|
|
13
27
|
"rootDir": "lib",
|
|
14
28
|
"paths": {
|
|
15
29
|
"node_modules/*": ["./node_modules/*"]
|
|
16
30
|
}
|
|
17
31
|
},
|
|
18
32
|
"include": ["./lib"],
|
|
19
|
-
"exclude": ["./dist
|
|
33
|
+
"exclude": ["./dist"]
|
|
20
34
|
}
|