valyrian.js 7.2.8 → 7.2.10
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 +7 -0
- package/dist/dataset/index.mjs +10 -4
- package/dist/dataset/index.mjs.map +7 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +7 -0
- package/dist/hooks/index.mjs.map +7 -0
- 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 +7 -0
- 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 +7 -0
- package/dist/node/index.js +7 -0
- package/dist/node/index.js.map +7 -0
- package/dist/node/index.mjs +6 -0
- package/dist/node/index.mjs.map +7 -0
- 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 +7 -0
- package/dist/proxy-signal/index.mjs.map +7 -0
- package/dist/request/index.js +1 -0
- package/dist/request/index.js.map +7 -0
- package/dist/request/index.mjs.map +7 -0
- 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 +7 -0
- package/dist/router/index.mjs +4 -3
- package/dist/router/index.mjs.map +7 -0
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +3 -2
- package/dist/signal/index.js.map +7 -0
- package/dist/signal/index.mjs +2 -2
- package/dist/signal/index.mjs.map +7 -0
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +7 -0
- package/dist/store/index.mjs.map +7 -0
- 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 +7 -0
- package/dist/sw/index.mjs.map +7 -0
- 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/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/dist/dataset/index.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export declare class DataSet<T> implements DataSetInterface<T> {
|
|
|
17
17
|
setVnodeAndHandler(vnode: VnodeWithDom, handler: DataSetHandler<T>): void;
|
|
18
18
|
reset(data: T[]): void;
|
|
19
19
|
add(...data: T[]): void;
|
|
20
|
-
delete(index:
|
|
21
|
-
update(index:
|
|
20
|
+
delete(index: number): void;
|
|
21
|
+
update(index: number, item: Partial<T>): void;
|
|
22
22
|
}
|
|
23
23
|
export {};
|
|
24
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/dataset/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAwD,MAAM,aAAa,CAAC;AAEjH,UAAU,gBAAgB,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAE3B,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAE5B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAA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;;IAQpD,IAAI,IAAI,IAQO,CAAC,EAAE,CAFjB;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAEjB;gBAqBW,IAAI,GAAE,CAAC,EAAO,EAAE,YAAY,UAAO;IAK/C,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAMlE,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE;IA2Cf,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;IA4BhB,MAAM,CAAC,KAAK,EAAE,MAAM;IAcpB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;CAgBvC"}
|
package/dist/dataset/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -40,9 +41,9 @@ function deepFreeze(obj) {
|
|
|
40
41
|
return obj;
|
|
41
42
|
}
|
|
42
43
|
var DataSet = class {
|
|
43
|
-
#vnode;
|
|
44
|
+
#vnode = null;
|
|
44
45
|
// eslint-disable-next-line no-unused-vars
|
|
45
|
-
#handler;
|
|
46
|
+
#handler = null;
|
|
46
47
|
#data = [];
|
|
47
48
|
#isFrozen = false;
|
|
48
49
|
#dataProxy = null;
|
|
@@ -84,6 +85,9 @@ var DataSet = class {
|
|
|
84
85
|
}
|
|
85
86
|
reset(data) {
|
|
86
87
|
this.#setData(data);
|
|
88
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
87
91
|
let vnode = this.#vnode;
|
|
88
92
|
let handler = this.#handler;
|
|
89
93
|
if (data.length === 0) {
|
|
@@ -123,6 +127,9 @@ var DataSet = class {
|
|
|
123
127
|
} else {
|
|
124
128
|
this.#data.push(...data);
|
|
125
129
|
}
|
|
130
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
126
133
|
let vnode = this.#vnode;
|
|
127
134
|
let handler = this.#handler;
|
|
128
135
|
for (let i = 0, ii = oldLength, l = data.length; i < l; i++, ii++) {
|
|
@@ -137,7 +144,7 @@ var DataSet = class {
|
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
146
|
delete(index) {
|
|
140
|
-
if (this.#data) {
|
|
147
|
+
if (this.#data && this.#vnode) {
|
|
141
148
|
let child = this.#vnode.children[index];
|
|
142
149
|
if (this.#isFrozen) {
|
|
143
150
|
this.#setData(this.data.filter((_, i) => i !== index));
|
|
@@ -149,7 +156,7 @@ var DataSet = class {
|
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
update(index, item) {
|
|
152
|
-
if (this.#data) {
|
|
159
|
+
if (this.#data && this.#vnode && this.#handler) {
|
|
153
160
|
let child = this.#vnode.children[index];
|
|
154
161
|
if (this.#isFrozen) {
|
|
155
162
|
this.#setData(this.#data.map((d, i) => i === index ? { ...d, ...item } : d));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../lib/dataset/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { VnodeInterface, VnodeWithDom, createDomElement, directive, patch, updateAttributes } from \"valyrian.js\";\n\ninterface DataSetInterface<T> {\n data: T[];\n // eslint-disable-next-line no-unused-vars\n reset: (data: T[]) => void;\n // eslint-disable-next-line no-unused-vars\n add: (...data: T[]) => void;\n // eslint-disable-next-line no-unused-vars\n update: (index: number, data: T) => void;\n // eslint-disable-next-line no-unused-vars\n delete: (index: number) => void;\n}\ninterface DataSetHandler<T> {\n // eslint-disable-next-line no-unused-vars\n (data: T, index: number): VnodeInterface;\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n let props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nexport class DataSet<T> implements DataSetInterface<T> {\n #vnode: VnodeWithDom | null = null;\n // eslint-disable-next-line no-unused-vars\n #handler: DataSetHandler<T> | null = null;\n #data: T[] = [];\n #isFrozen = false;\n #dataProxy: T[] | null = null;\n\n get data() {\n if (this.#dataProxy === null) {\n throw new Error(\"DataSet is not initialized\");\n }\n\n return this.#dataProxy;\n }\n\n set data(data: T[]) {\n throw new Error(\"You need to use the reset method to set the data\");\n }\n\n #setData(data: T[]) {\n if (this.#isFrozen) {\n this.#data = deepFreeze([...data]);\n } else {\n this.#data = data;\n }\n this.#dataProxy = new Proxy(this.#data as T[], {\n set: () => {\n throw new Error(\"You need to use the add, update or delete methods to change the data\");\n },\n get(target: any, prop: string) {\n return target[prop];\n },\n deleteProperty: () => {\n throw new Error(\"You need to use the add, update or delete methods to change the data\");\n }\n }) as T[];\n }\n\n constructor(data: T[] = [], shouldFreeze = true) {\n this.#isFrozen = shouldFreeze;\n this.#setData(data);\n }\n\n setVnodeAndHandler(vnode: VnodeWithDom, handler: DataSetHandler<T>) {\n this.#vnode = vnode;\n this.#handler = handler;\n this.reset(this.#data);\n }\n\n reset(data: T[]) {\n this.#setData(data);\n if (this.#vnode === null || this.#handler === null) {\n return;\n }\n\n let vnode = this.#vnode;\n let handler = this.#handler;\n\n if (data.length === 0) {\n vnode.children = [];\n vnode.dom.textContent = \"\";\n return;\n }\n\n let childrenLength = vnode.children.length;\n for (let i = 0, l = data.length; i < l; i++) {\n let child = handler(this.data[i], i);\n\n if (i < childrenLength) {\n let oldChild = vnode.children[i];\n child.isSVG = oldChild.isSVG;\n child.dom = oldChild.dom;\n updateAttributes(child as VnodeWithDom, oldChild);\n vnode.children[i] = child;\n patch(child as VnodeWithDom, oldChild);\n continue;\n }\n\n child.isSVG = vnode.isSVG || child.tag === \"svg\";\n child.dom = createDomElement(child.tag as string, child.isSVG);\n vnode.dom.appendChild(child.dom);\n updateAttributes(child as VnodeWithDom);\n vnode.children.push(child);\n patch(child as VnodeWithDom);\n }\n\n for (let i = data.length; i < childrenLength; i++) {\n vnode.dom.removeChild(vnode.children[i].dom);\n }\n vnode.children.length = data.length;\n }\n\n add(...data: T[]) {\n if (this.#data) {\n let oldLength = this.#data.length;\n if (this.#isFrozen) {\n this.#setData([...this.#data, ...data]);\n } else {\n this.#data.push(...data);\n }\n\n if (this.#vnode === null || this.#handler === null) {\n return;\n }\n\n let vnode = this.#vnode;\n let handler = this.#handler;\n\n for (let i = 0, ii = oldLength, l = data.length; i < l; i++, ii++) {\n let child = handler(this.#data[i], ii);\n child.isSVG = vnode.isSVG || child.tag === \"svg\";\n child.dom = createDomElement(child.tag as string, child.isSVG);\n vnode.dom.appendChild(child.dom);\n updateAttributes(child as VnodeWithDom);\n vnode.children.push(child);\n patch(child as VnodeWithDom);\n }\n }\n }\n\n delete(index: number) {\n if (this.#data && this.#vnode) {\n let child = this.#vnode.children[index];\n if (this.#isFrozen) {\n this.#setData(this.data.filter((_, i) => i !== index));\n } else {\n this.#data.splice(index, 1);\n }\n\n this.#vnode.dom.removeChild(child.dom);\n this.#vnode.children.splice(index, 1);\n }\n }\n\n update(index: number, item: Partial<T>) {\n if (this.#data && this.#vnode && this.#handler) {\n let child = this.#vnode.children[index];\n if (this.#isFrozen) {\n this.#setData(this.#data.map((d, i) => (i === index ? { ...d, ...item } : d)));\n } else {\n this.#data[index] = { ...this.#data[index], ...item };\n }\n let newChild = this.#handler(this.#data[index], index);\n newChild.isSVG = this.#vnode.isSVG || newChild.tag === \"svg\";\n newChild.dom = child.dom;\n this.#vnode.children[index] = newChild;\n updateAttributes(newChild as VnodeWithDom, child);\n patch(newChild as VnodeWithDom, child);\n }\n }\n}\n\ndirective(\"with-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,OAAO,CAAC;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,OAAO,OAAe,MAAkB;AACtC,QAAI,KAAK,SAAS,KAAK,UAAU,KAAK,UAAU;AAC9C,UAAI,QAAQ,KAAK,OAAO,SAAS,KAAK;AACtC,UAAI,KAAK,WAAW;AAClB,aAAK,SAAS,KAAK,MAAM,IAAI,CAAC,GAAG,MAAO,MAAM,QAAQ,EAAE,GAAG,GAAG,GAAG,KAAK,IAAI,CAAE,CAAC;AAAA,MAC/E,OAAO;AACL,aAAK,MAAM,KAAK,IAAI,EAAE,GAAG,KAAK,MAAM,KAAK,GAAG,GAAG,KAAK;AAAA,MACtD;AACA,UAAI,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK,GAAG,KAAK;AACrD,eAAS,QAAQ,KAAK,OAAO,SAAS,SAAS,QAAQ;AACvD,eAAS,MAAM,MAAM;AACrB,WAAK,OAAO,SAAS,KAAK,IAAI;AAC9B,4CAAiB,UAA0B,KAAK;AAChD,iCAAM,UAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AACF;AAAA,IAEA,2BAAU,gBAAgB,CAAC,SAAS,UAAU;AAC5C,UAAQ,mBAAmB,OAAuB,MAAM,SAAS,CAAC,CAAC;AACnE,SAAO;AACT,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/dataset/index.mjs
CHANGED
|
@@ -17,9 +17,9 @@ function deepFreeze(obj) {
|
|
|
17
17
|
return obj;
|
|
18
18
|
}
|
|
19
19
|
var DataSet = class {
|
|
20
|
-
#vnode;
|
|
20
|
+
#vnode = null;
|
|
21
21
|
// eslint-disable-next-line no-unused-vars
|
|
22
|
-
#handler;
|
|
22
|
+
#handler = null;
|
|
23
23
|
#data = [];
|
|
24
24
|
#isFrozen = false;
|
|
25
25
|
#dataProxy = null;
|
|
@@ -61,6 +61,9 @@ var DataSet = class {
|
|
|
61
61
|
}
|
|
62
62
|
reset(data) {
|
|
63
63
|
this.#setData(data);
|
|
64
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
64
67
|
let vnode = this.#vnode;
|
|
65
68
|
let handler = this.#handler;
|
|
66
69
|
if (data.length === 0) {
|
|
@@ -100,6 +103,9 @@ var DataSet = class {
|
|
|
100
103
|
} else {
|
|
101
104
|
this.#data.push(...data);
|
|
102
105
|
}
|
|
106
|
+
if (this.#vnode === null || this.#handler === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
103
109
|
let vnode = this.#vnode;
|
|
104
110
|
let handler = this.#handler;
|
|
105
111
|
for (let i = 0, ii = oldLength, l = data.length; i < l; i++, ii++) {
|
|
@@ -114,7 +120,7 @@ var DataSet = class {
|
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
delete(index) {
|
|
117
|
-
if (this.#data) {
|
|
123
|
+
if (this.#data && this.#vnode) {
|
|
118
124
|
let child = this.#vnode.children[index];
|
|
119
125
|
if (this.#isFrozen) {
|
|
120
126
|
this.#setData(this.data.filter((_, i) => i !== index));
|
|
@@ -126,7 +132,7 @@ var DataSet = class {
|
|
|
126
132
|
}
|
|
127
133
|
}
|
|
128
134
|
update(index, item) {
|
|
129
|
-
if (this.#data) {
|
|
135
|
+
if (this.#data && this.#vnode && this.#handler) {
|
|
130
136
|
let child = this.#vnode.children[index];
|
|
131
137
|
if (this.#isFrozen) {
|
|
132
138
|
this.#setData(this.#data.map((d, i) => i === index ? { ...d, ...item } : d));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../lib/dataset/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { VnodeInterface, VnodeWithDom, createDomElement, directive, patch, updateAttributes } from \"valyrian.js\";\n\ninterface DataSetInterface<T> {\n data: T[];\n // eslint-disable-next-line no-unused-vars\n reset: (data: T[]) => void;\n // eslint-disable-next-line no-unused-vars\n add: (...data: T[]) => void;\n // eslint-disable-next-line no-unused-vars\n update: (index: number, data: T) => void;\n // eslint-disable-next-line no-unused-vars\n delete: (index: number) => void;\n}\ninterface DataSetHandler<T> {\n // eslint-disable-next-line no-unused-vars\n (data: T, index: number): VnodeInterface;\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n let props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nexport class DataSet<T> implements DataSetInterface<T> {\n #vnode: VnodeWithDom | null = null;\n // eslint-disable-next-line no-unused-vars\n #handler: DataSetHandler<T> | null = null;\n #data: T[] = [];\n #isFrozen = false;\n #dataProxy: T[] | null = null;\n\n get data() {\n if (this.#dataProxy === null) {\n throw new Error(\"DataSet is not initialized\");\n }\n\n return this.#dataProxy;\n }\n\n set data(data: T[]) {\n throw new Error(\"You need to use the reset method to set the data\");\n }\n\n #setData(data: T[]) {\n if (this.#isFrozen) {\n this.#data = deepFreeze([...data]);\n } else {\n this.#data = data;\n }\n this.#dataProxy = new Proxy(this.#data as T[], {\n set: () => {\n throw new Error(\"You need to use the add, update or delete methods to change the data\");\n },\n get(target: any, prop: string) {\n return target[prop];\n },\n deleteProperty: () => {\n throw new Error(\"You need to use the add, update or delete methods to change the data\");\n }\n }) as T[];\n }\n\n constructor(data: T[] = [], shouldFreeze = true) {\n this.#isFrozen = shouldFreeze;\n this.#setData(data);\n }\n\n setVnodeAndHandler(vnode: VnodeWithDom, handler: DataSetHandler<T>) {\n this.#vnode = vnode;\n this.#handler = handler;\n this.reset(this.#data);\n }\n\n reset(data: T[]) {\n this.#setData(data);\n if (this.#vnode === null || this.#handler === null) {\n return;\n }\n\n let vnode = this.#vnode;\n let handler = this.#handler;\n\n if (data.length === 0) {\n vnode.children = [];\n vnode.dom.textContent = \"\";\n return;\n }\n\n let childrenLength = vnode.children.length;\n for (let i = 0, l = data.length; i < l; i++) {\n let child = handler(this.data[i], i);\n\n if (i < childrenLength) {\n let oldChild = vnode.children[i];\n child.isSVG = oldChild.isSVG;\n child.dom = oldChild.dom;\n updateAttributes(child as VnodeWithDom, oldChild);\n vnode.children[i] = child;\n patch(child as VnodeWithDom, oldChild);\n continue;\n }\n\n child.isSVG = vnode.isSVG || child.tag === \"svg\";\n child.dom = createDomElement(child.tag as string, child.isSVG);\n vnode.dom.appendChild(child.dom);\n updateAttributes(child as VnodeWithDom);\n vnode.children.push(child);\n patch(child as VnodeWithDom);\n }\n\n for (let i = data.length; i < childrenLength; i++) {\n vnode.dom.removeChild(vnode.children[i].dom);\n }\n vnode.children.length = data.length;\n }\n\n add(...data: T[]) {\n if (this.#data) {\n let oldLength = this.#data.length;\n if (this.#isFrozen) {\n this.#setData([...this.#data, ...data]);\n } else {\n this.#data.push(...data);\n }\n\n if (this.#vnode === null || this.#handler === null) {\n return;\n }\n\n let vnode = this.#vnode;\n let handler = this.#handler;\n\n for (let i = 0, ii = oldLength, l = data.length; i < l; i++, ii++) {\n let child = handler(this.#data[i], ii);\n child.isSVG = vnode.isSVG || child.tag === \"svg\";\n child.dom = createDomElement(child.tag as string, child.isSVG);\n vnode.dom.appendChild(child.dom);\n updateAttributes(child as VnodeWithDom);\n vnode.children.push(child);\n patch(child as VnodeWithDom);\n }\n }\n }\n\n delete(index: number) {\n if (this.#data && this.#vnode) {\n let child = this.#vnode.children[index];\n if (this.#isFrozen) {\n this.#setData(this.data.filter((_, i) => i !== index));\n } else {\n this.#data.splice(index, 1);\n }\n\n this.#vnode.dom.removeChild(child.dom);\n this.#vnode.children.splice(index, 1);\n }\n }\n\n update(index: number, item: Partial<T>) {\n if (this.#data && this.#vnode && this.#handler) {\n let child = this.#vnode.children[index];\n if (this.#isFrozen) {\n this.#setData(this.#data.map((d, i) => (i === index ? { ...d, ...item } : d)));\n } else {\n this.#data[index] = { ...this.#data[index], ...item };\n }\n let newChild = this.#handler(this.#data[index], index);\n newChild.isSVG = this.#vnode.isSVG || newChild.tag === \"svg\";\n newChild.dom = child.dom;\n this.#vnode.children[index] = newChild;\n updateAttributes(newChild as VnodeWithDom, child);\n patch(newChild as VnodeWithDom, child);\n }\n }\n}\n\ndirective(\"with-dataset\", (dataSet, vnode) => {\n dataSet.setVnodeAndHandler(vnode as VnodeWithDom, vnode.children[0]);\n return false;\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAuC,kBAAkB,WAAW,OAAO,wBAAwB;AAkBnG,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,UAAI,QAAQ,QAAQ,QAAQ,GAAG;AAC/B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,mBAAW,IAAI,MAAM,CAAC,CAAC,CAAC;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;AAEO,IAAM,UAAN,MAAgD;AAAA,EACrD,SAA8B;AAAA;AAAA,EAE9B,WAAqC;AAAA,EACrC,QAAa,CAAC;AAAA,EACd,YAAY;AAAA,EACZ,aAAyB;AAAA,EAEzB,IAAI,OAAO;AACT,QAAI,KAAK,eAAe,MAAM;AAC5B,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,KAAK,MAAW;AAClB,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAAA,EAEA,SAAS,MAAW;AAClB,QAAI,KAAK,WAAW;AAClB,WAAK,QAAQ,W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GAAG,MAAM,MAAM,KAAK,CAAC;AAAA,MACvD,OAAO;AACL,aAAK,MAAM,OAAO,OAAO,CAAC;AAAA,MAC5B;AAEA,WAAK,OAAO,IAAI,YAAY,MAAM,GAAG;AACrC,WAAK,OAAO,SAAS,OAAO,OAAO,CAAC;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,OAAO,OAAe,MAAkB;AACtC,QAAI,KAAK,SAAS,KAAK,UAAU,KAAK,UAAU;AAC9C,UAAI,QAAQ,KAAK,OAAO,SAAS,KAAK;AACtC,UAAI,KAAK,WAAW;AAClB,aAAK,SAAS,KAAK,MAAM,IAAI,CAAC,GAAG,MAAO,MAAM,QAAQ,EAAE,GAAG,GAAG,GAAG,KAAK,IAAI,CAAE,CAAC;AAAA,MAC/E,OAAO;AACL,aAAK,MAAM,KAAK,IAAI,EAAE,GAAG,KAAK,MAAM,KAAK,GAAG,GAAG,KAAK;AAAA,MACtD;AACA,UAAI,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK,GAAG,KAAK;AACrD,eAAS,QAAQ,KAAK,OAAO,SAAS,SAAS,QAAQ;AACvD,eAAS,MAAM,MAAM;AACrB,WAAK,OAAO,SAAS,KAAK,IAAI;AAC9B,uBAAiB,UAA0B,KAAK;AAChD,YAAM,UAA0B,KAAK;AAAA,IACvC;AAAA,EACF;AACF;AAEA,UAAU,gBAAgB,CAAC,SAAS,UAAU;AAC5C,UAAQ,mBAAmB,OAAuB,MAAM,SAAS,CAAC,CAAC;AACnE,SAAO;AACT,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../lib/hooks/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { Component, POJOComponent, VnodeWithDom, current, directive, onCleanup, onUnmount, update } from \"valyrian.js\";\n\ninterface CurrentOnPatch {\n component: Component | POJOComponent;\n vnode: VnodeWithDom;\n oldVnode: VnodeWithDom;\n}\n\nexport type Hook = any;\n\nexport interface HookDefinition {\n // eslint-disable-next-line no-unused-vars\n onCreate: (...args: any[]) => any;\n // eslint-disable-next-line no-unused-vars\n onUpdate?: (hook: Hook, ...args: any[]) => any;\n // eslint-disable-next-line no-unused-vars\n onCleanup?: (hook: Hook) => any;\n // eslint-disable-next-line no-unused-vars\n onRemove?: (hook: Hook) => any;\n // eslint-disable-next-line no-unused-vars\n returnValue?: (hook: Hook) => any;\n}\n\nexport interface CreateHook {\n // eslint-disable-next-line no-unused-vars\n (HookDefinition: HookDefinition): (...args: any[]) => any;\n}\n\nexport const createHook = function createHook({\n onCreate,\n onUpdate: onUpdateHook,\n onCleanup: onCleanupHook,\n onRemove,\n returnValue\n}: HookDefinition): Hook {\n return (...args: any[]) => {\n let { component, vnode } = current as CurrentOnPatch;\n\n let hook: any = null;\n\n if (vnode) {\n // Init the components array for the current vnode\n if (!vnode.components) {\n vnode.components = [];\n }\n\n if (vnode.components.indexOf(component) === -1) {\n vnode.hook_calls = -1;\n vnode.components.push(component);\n if (!component.hooks) {\n component.hooks = [];\n onUnmount(() => Reflect.deleteProperty(component, \"hooks\"));\n }\n }\n\n hook = component.hooks[++vnode.hook_calls];\n }\n\n // If the hook doesn't exist, create it\n if (!hook) {\n // create a new hook\n hook = onCreate(...args);\n\n if (vnode) {\n // Add the hook to the component\n component.hooks.push(hook);\n }\n\n // if we have a onRemove hook, add it to the onUnmount set\n if (onRemove) {\n // Add the hook to the onRemove array\n onUnmount(() => onRemove(hook));\n }\n } else {\n if (onUpdateHook) {\n onUpdateHook(hook, ...args);\n }\n }\n\n // If we have an onCleanup function, add it to the cleanup set\n if (onCleanupHook) {\n // Add the hook to the onCleanup set\n onCleanup(() => onCleanupHook(hook));\n }\n\n // If we have a returnValue function, call it and return the result instead of the hook\n if (returnValue) {\n return returnValue(hook);\n }\n\n // Return the hook\n return hook;\n };\n} as unknown as CreateHook;\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\n// Use state hook\nexport const useState = createHook({\n onCreate: (value) => {\n function get() {\n return value;\n }\n get.value = value;\n get.toJSON = get.valueOf = get;\n get.toString = () => `${value}`;\n\n function set(newValue: any) {\n // Prevent default event if it exists\n if (current.event) {\n current.event.preventDefault();\n }\n\n if (value !== newValue) {\n value = newValue;\n get.value = newValue;\n delayedUpdate();\n }\n }\n\n return [get, set];\n }\n});\n\n// Effect hook\nexport const useEffect = createHook({\n onCreate: (effect: Function, changes: any[]) => {\n let hook: {\n effect: Function;\n prev: any[];\n onRemove?: Function;\n onCleanup?: Function;\n } = { effect, prev: [] };\n // on unmount\n if (changes === null) {\n hook.onRemove = effect;\n return hook;\n }\n\n // on create\n hook.prev = changes;\n hook.onCleanup = hook.effect();\n return hook;\n },\n onUpdate: (hook, effect, changes) => {\n // on update\n if (typeof changes === \"undefined\") {\n hook.prev = changes;\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n hook.onCleanup = hook.effect();\n return;\n }\n\n // on update if there are changes\n if (Array.isArray(changes)) {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.prev[i]) {\n hook.prev = changes;\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n hook.onCleanup = hook.effect();\n return;\n }\n }\n }\n },\n onRemove: (hook) => {\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n if (typeof hook.onRemove === \"function\") {\n hook.onRemove();\n }\n }\n});\n\nexport const useRef = createHook({\n onCreate: (initialValue) => {\n directive(\"ref\", (ref, vnode) => {\n ref.current = vnode.dom;\n });\n return { current: initialValue };\n }\n});\n\nexport const useCallback = createHook({\n onCreate: (callback, changes) => {\n callback();\n return { callback, changes };\n },\n onUpdate: (hook, callback, changes) => {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.changes[i]) {\n hook.changes = changes;\n hook.callback();\n return;\n }\n }\n }\n});\n\nexport const useMemo = createHook({\n onCreate: (callback, changes) => {\n return { callback, changes, value: callback() };\n },\n onUpdate: (hook, callback, changes) => {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.changes[i]) {\n hook.changes = changes;\n hook.value = callback();\n return;\n }\n }\n },\n returnValue: (hook) => {\n return hook.value;\n }\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAyG;AA4BlG,IAAM,aAAa,SAASA,YAAW;AAAA,EAC5C;AAAA,EACA,UAAU;AAAA,EACV,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAyB;AACvB,SAAO,IAAI,SAAgB;AACzB,QAAI,EAAE,WAAW,MAAM,IAAI;AAE3B,QAAI,OAAY;AAEhB,QAAI,OAAO;AAET,UAAI,CAAC,MAAM,YAAY;AACrB,cAAM,aAAa,CAAC;AAAA,MACtB;AAEA,UAAI,MAAM,WAAW,QAAQ,SAAS,MAAM,IAAI;AAC9C,cAAM,aAAa;AACnB,cAAM,WAAW,KAAK,SAAS;AAC/B,YAAI,CAAC,UAAU,OAAO;AACpB,oBAAU,QAAQ,CAAC;AACnB,yCAAU,MAAM,QAAQ,eAAe,WAAW,OAAO,CAAC;AAAA,QAC5D;AAAA,MACF;AAEA,aAAO,UAAU,MAAM,EAAE,MAAM,UAAU;AAAA,IAC3C;AAGA,QAAI,CAAC,MAAM;AAET,aAAO,SAAS,GAAG,IAAI;AAEvB,UAAI,OAAO;AAET,kBAAU,MAAM,KAAK,IAAI;AAAA,MAC3B;AAGA,UAAI,UAAU;AAEZ,uCAAU,MAAM,SAAS,IAAI,CAAC;AAAA,MAChC;AAAA,IACF,OAAO;AACL,UAAI,cAAc;AAChB,qBAAa,MAAM,GAAG,IAAI;AAAA,MAC5B;AAAA,IACF;AAGA,QAAI,eAAe;AAEjB,qCAAU,MAAM,cAAc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AAAA,IACF;AAAA,EACF;AAAA,EACA,aAAa,CAAC,SAAS;AACrB,WAAO,KAAK;AAAA,EACd;AACF,CAAC;",
|
|
6
|
+
"names": ["createHook"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../lib/hooks/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { Component, POJOComponent, VnodeWithDom, current, directive, onCleanup, onUnmount, update } from \"valyrian.js\";\n\ninterface CurrentOnPatch {\n component: Component | POJOComponent;\n vnode: VnodeWithDom;\n oldVnode: VnodeWithDom;\n}\n\nexport type Hook = any;\n\nexport interface HookDefinition {\n // eslint-disable-next-line no-unused-vars\n onCreate: (...args: any[]) => any;\n // eslint-disable-next-line no-unused-vars\n onUpdate?: (hook: Hook, ...args: any[]) => any;\n // eslint-disable-next-line no-unused-vars\n onCleanup?: (hook: Hook) => any;\n // eslint-disable-next-line no-unused-vars\n onRemove?: (hook: Hook) => any;\n // eslint-disable-next-line no-unused-vars\n returnValue?: (hook: Hook) => any;\n}\n\nexport interface CreateHook {\n // eslint-disable-next-line no-unused-vars\n (HookDefinition: HookDefinition): (...args: any[]) => any;\n}\n\nexport const createHook = function createHook({\n onCreate,\n onUpdate: onUpdateHook,\n onCleanup: onCleanupHook,\n onRemove,\n returnValue\n}: HookDefinition): Hook {\n return (...args: any[]) => {\n let { component, vnode } = current as CurrentOnPatch;\n\n let hook: any = null;\n\n if (vnode) {\n // Init the components array for the current vnode\n if (!vnode.components) {\n vnode.components = [];\n }\n\n if (vnode.components.indexOf(component) === -1) {\n vnode.hook_calls = -1;\n vnode.components.push(component);\n if (!component.hooks) {\n component.hooks = [];\n onUnmount(() => Reflect.deleteProperty(component, \"hooks\"));\n }\n }\n\n hook = component.hooks[++vnode.hook_calls];\n }\n\n // If the hook doesn't exist, create it\n if (!hook) {\n // create a new hook\n hook = onCreate(...args);\n\n if (vnode) {\n // Add the hook to the component\n component.hooks.push(hook);\n }\n\n // if we have a onRemove hook, add it to the onUnmount set\n if (onRemove) {\n // Add the hook to the onRemove array\n onUnmount(() => onRemove(hook));\n }\n } else {\n if (onUpdateHook) {\n onUpdateHook(hook, ...args);\n }\n }\n\n // If we have an onCleanup function, add it to the cleanup set\n if (onCleanupHook) {\n // Add the hook to the onCleanup set\n onCleanup(() => onCleanupHook(hook));\n }\n\n // If we have a returnValue function, call it and return the result instead of the hook\n if (returnValue) {\n return returnValue(hook);\n }\n\n // Return the hook\n return hook;\n };\n} as unknown as CreateHook;\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\n// Use state hook\nexport const useState = createHook({\n onCreate: (value) => {\n function get() {\n return value;\n }\n get.value = value;\n get.toJSON = get.valueOf = get;\n get.toString = () => `${value}`;\n\n function set(newValue: any) {\n // Prevent default event if it exists\n if (current.event) {\n current.event.preventDefault();\n }\n\n if (value !== newValue) {\n value = newValue;\n get.value = newValue;\n delayedUpdate();\n }\n }\n\n return [get, set];\n }\n});\n\n// Effect hook\nexport const useEffect = createHook({\n onCreate: (effect: Function, changes: any[]) => {\n let hook: {\n effect: Function;\n prev: any[];\n onRemove?: Function;\n onCleanup?: Function;\n } = { effect, prev: [] };\n // on unmount\n if (changes === null) {\n hook.onRemove = effect;\n return hook;\n }\n\n // on create\n hook.prev = changes;\n hook.onCleanup = hook.effect();\n return hook;\n },\n onUpdate: (hook, effect, changes) => {\n // on update\n if (typeof changes === \"undefined\") {\n hook.prev = changes;\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n hook.onCleanup = hook.effect();\n return;\n }\n\n // on update if there are changes\n if (Array.isArray(changes)) {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.prev[i]) {\n hook.prev = changes;\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n hook.onCleanup = hook.effect();\n return;\n }\n }\n }\n },\n onRemove: (hook) => {\n if (typeof hook.onCleanup === \"function\") {\n hook.onCleanup();\n }\n if (typeof hook.onRemove === \"function\") {\n hook.onRemove();\n }\n }\n});\n\nexport const useRef = createHook({\n onCreate: (initialValue) => {\n directive(\"ref\", (ref, vnode) => {\n ref.current = vnode.dom;\n });\n return { current: initialValue };\n }\n});\n\nexport const useCallback = createHook({\n onCreate: (callback, changes) => {\n callback();\n return { callback, changes };\n },\n onUpdate: (hook, callback, changes) => {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.changes[i]) {\n hook.changes = changes;\n hook.callback();\n return;\n }\n }\n }\n});\n\nexport const useMemo = createHook({\n onCreate: (callback, changes) => {\n return { callback, changes, value: callback() };\n },\n onUpdate: (hook, callback, changes) => {\n for (let i = 0, l = changes.length; i < l; i++) {\n if (changes[i] !== hook.changes[i]) {\n hook.changes = changes;\n hook.value = callback();\n return;\n }\n }\n },\n returnValue: (hook) => {\n return hook.value;\n }\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAiD,SAAS,WAAW,WAAW,WAAW,cAAc;AA4BlG,IAAM,aAAa,SAASA,YAAW;AAAA,EAC5C;AAAA,EACA,UAAU;AAAA,EACV,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAyB;AACvB,SAAO,IAAI,SAAgB;AACzB,QAAI,EAAE,WAAW,MAAM,IAAI;AAE3B,QAAI,OAAY;AAEhB,QAAI,OAAO;AAET,UAAI,CAAC,MAAM,YAAY;AACrB,cAAM,aAAa,CAAC;AAAA,MACtB;AAEA,UAAI,MAAM,WAAW,QAAQ,SAAS,MAAM,IAAI;AAC9C,cAAM,aAAa;AACnB,cAAM,WAAW,KAAK,SAAS;AAC/B,YAAI,CAAC,UAAU,OAAO;AACpB,oBAAU,QAAQ,CAAC;AACnB,oBAAU,MAAM,QAAQ,eAAe,WAAW,OAAO,CAAC;AAAA,QAC5D;AAAA,MACF;AAEA,aAAO,UAAU,MAAM,EAAE,MAAM,UAAU;AAAA,IAC3C;AAGA,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,UAAU,CAAC,UAAU,YAAY;AAC/B,WAAO,EAAE,UAAU,SAAS,OAAO,SAAS,EAAE;AAAA,EAChD;AAAA,EACA,UAAU,CAAC,MAAM,UAAU,YAAY;AACrC,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAAI,GAAG,KAAK;AAC9C,UAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,GAAG;AAClC,aAAK,UAAU;AACf,aAAK,QAAQ,SAAS;AACtB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,aAAa,CAAC,SAAS;AACrB,WAAO,KAAK;AAAA,EACd;AACF,CAAC;",
|
|
6
|
+
"names": ["createHook"]
|
|
7
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
interface DefaultRecord extends Record<string | number | symbol, any> {
|
|
2
|
+
}
|
|
3
|
+
export interface VnodeProperties extends DefaultRecord {
|
|
2
4
|
key?: string | number;
|
|
3
5
|
state?: any;
|
|
4
|
-
[key: string | number | symbol]: any;
|
|
5
6
|
}
|
|
6
|
-
export interface DomElement extends Element {
|
|
7
|
-
[key: string]: any;
|
|
7
|
+
export interface DomElement extends Element, DefaultRecord {
|
|
8
8
|
}
|
|
9
|
-
export interface VnodeInterface {
|
|
9
|
+
export interface VnodeInterface extends DefaultRecord {
|
|
10
10
|
new (tag: string | Component | POJOComponent, props: VnodeProperties, children: Children): VnodeInterface;
|
|
11
11
|
tag: string | Component | POJOComponent;
|
|
12
12
|
props: VnodeProperties;
|
|
@@ -14,20 +14,17 @@ export interface VnodeInterface {
|
|
|
14
14
|
isSVG?: boolean;
|
|
15
15
|
dom?: DomElement;
|
|
16
16
|
processed?: boolean;
|
|
17
|
-
[key: string | number | symbol]: any;
|
|
18
17
|
}
|
|
19
18
|
export interface VnodeWithDom extends VnodeInterface {
|
|
20
19
|
dom: DomElement;
|
|
21
20
|
}
|
|
22
|
-
export interface Component {
|
|
21
|
+
export interface Component extends DefaultRecord {
|
|
23
22
|
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
24
|
-
[key: string]: any;
|
|
25
23
|
}
|
|
26
|
-
export interface POJOComponent {
|
|
24
|
+
export interface POJOComponent extends DefaultRecord {
|
|
27
25
|
view: Component;
|
|
28
26
|
props?: VnodeProperties | null;
|
|
29
27
|
children?: any[];
|
|
30
|
-
[key: string]: any;
|
|
31
28
|
}
|
|
32
29
|
export interface VnodeComponentInterface extends VnodeInterface {
|
|
33
30
|
tag: Component | POJOComponent;
|
|
@@ -39,11 +36,9 @@ export interface Children extends Array<VnodeInterface | VnodeComponentInterface
|
|
|
39
36
|
export interface Directive {
|
|
40
37
|
(value: any, vnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean;
|
|
41
38
|
}
|
|
42
|
-
export interface Directives {
|
|
43
|
-
[key: string]: Directive;
|
|
39
|
+
export interface Directives extends Record<string, Directive> {
|
|
44
40
|
}
|
|
45
|
-
export interface ReservedProps {
|
|
46
|
-
[key: string]: true;
|
|
41
|
+
export interface ReservedProps extends Record<string, true> {
|
|
47
42
|
}
|
|
48
43
|
export interface Current {
|
|
49
44
|
component: Component | POJOComponent | null;
|
|
@@ -58,17 +53,17 @@ export interface V {
|
|
|
58
53
|
export declare let isNodeJs: boolean;
|
|
59
54
|
export declare function createDomElement(tag: string, isSVG?: boolean): DomElement;
|
|
60
55
|
export declare const Vnode: VnodeInterface;
|
|
61
|
-
export declare function isComponent(component:
|
|
56
|
+
export declare function isComponent(component: unknown): component is Component;
|
|
62
57
|
export declare const isVnode: (object?: unknown | VnodeInterface) => object is VnodeInterface;
|
|
63
58
|
export declare const isVnodeComponent: (object?: unknown | VnodeComponentInterface) => object is VnodeComponentInterface;
|
|
64
59
|
export declare function domToVnode(dom: any): VnodeWithDom;
|
|
65
|
-
export declare function trust(htmlString: string):
|
|
60
|
+
export declare function trust(htmlString: string): unknown[];
|
|
66
61
|
export declare const current: Current;
|
|
67
62
|
export declare const reservedProps: Record<string, true>;
|
|
68
|
-
export declare function onMount(callback:
|
|
69
|
-
export declare function onUpdate(callback:
|
|
70
|
-
export declare function onCleanup(callback:
|
|
71
|
-
export declare function onUnmount(callback:
|
|
63
|
+
export declare function onMount(callback: Function): void;
|
|
64
|
+
export declare function onUpdate(callback: Function): void;
|
|
65
|
+
export declare function onCleanup(callback: Function): void;
|
|
66
|
+
export declare function onUnmount(callback: Function): void;
|
|
72
67
|
export declare const directives: Directives;
|
|
73
68
|
export declare function directive(name: string, directive: Directive): void;
|
|
74
69
|
export declare function setAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
@@ -77,6 +72,7 @@ export declare function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom):
|
|
|
77
72
|
export declare function update(): void | string;
|
|
78
73
|
export declare function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
|
|
79
74
|
export declare function unmount(): string | void;
|
|
80
|
-
export declare function mount(dom:
|
|
75
|
+
export declare function mount(dom: string | DomElement, component: any): string | void;
|
|
81
76
|
export declare const v: V;
|
|
77
|
+
export {};
|
|
82
78
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAKA,UAAU,aAAc,SAAQ,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC;CAAG;AAGxE,MAAM,WAAW,eAAgB,SAAQ,aAAa;IAGpD,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEtB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAID,MAAM,WAAW,UAAW,SAAQ,OAAO,EAAE,aAAa;CAAG;AAI7D,MAAM,WA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AAQ,EAAE,QAAQ,QAIzC;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,QAE1C;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,QAE3C;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,QAI3C;AAoED,eAAO,MAAM,UAAU,EAAE,UAiNxB,CAAC;AAGF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,QAI3D;AA2CD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CAM5G;AAUD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CA6BtF;AAKD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CA8N3E;AAGD,wBAAgB,MAAM,IAAI,IAAI,GAAG,MAAM,CA+BtC;AAQD,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CA6BtF;AAGD,wBAAgB,OAAO,kBA4BtB;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,iBA8B7D;AAID,eAAO,MAAM,CAAC,EAAE,CAGf,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -56,7 +57,9 @@ var Vnode = function Vnode2(tag, props, children) {
|
|
|
56
57
|
this.children = children;
|
|
57
58
|
};
|
|
58
59
|
function isComponent(component) {
|
|
59
|
-
return
|
|
60
|
+
return Boolean(
|
|
61
|
+
component && (typeof component === "function" || typeof component === "object" && "view" in component)
|
|
62
|
+
);
|
|
60
63
|
}
|
|
61
64
|
var isVnode = (object) => {
|
|
62
65
|
return object instanceof Vnode;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/index.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-use-before-define */\n/* eslint-disable indent */\n/* eslint-disable sonarjs/cognitive-complexity */\n/* eslint-disable complexity */\n\ninterface DefaultRecord extends Record<string | number | symbol, any> {}\n\n// The VnodeProperties interface represents properties that can be passed to a virtual node.\nexport interface VnodeProperties extends DefaultRecord {\n // A unique key for the virtual node, which can be a string or a number.\n // This is useful for optimizing updates in a list of nodes.\n key?: string | number;\n // A state object that is associated with the virtual node.\n state?: any;\n}\n\n// The DomElement interface extends the Element interface with an index signature.\n// This allows for any additional properties to be added to DOM elements.\nexport interface DomElement extends Element, DefaultRecord {}\n\n// The VnodeInterface represents a virtual node. It has a number of optional fields,\n// including a tag, props, children, and a DOM element.\nexport interface VnodeInterface extends DefaultRecord {\n // The constructor for the virtual node. It takes a tag, props, and children as arguments.\n // The tag can be a string, a component, or a POJO component.\n // eslint-disable-next-line no-unused-vars\n new (tag: string | Component | POJOComponent, props: VnodeProperties, children: Children): VnodeInterface;\n // The tag for the virtual node. It can be a string, a component, or a POJO component.\n tag: string | Component | POJOComponent;\n // The props for the virtual node.\n props: VnodeProperties;\n // The children for the virtual node.\n children: Children;\n // A boolean indicating whether the virtual node is an SVG element.\n isSVG?: boolean;\n // The DOM element that corresponds to the virtual node.\n dom?: DomElement;\n // A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.\n processed?: boolean;\n}\n\n// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.\nexport interface VnodeWithDom extends VnodeInterface {\n dom: DomElement;\n}\n\n// The Component interface represents a function that returns a virtual node or a list of virtual nodes.\n// It can also have additional properties.\nexport interface Component extends DefaultRecord {\n // The function that returns a virtual node or a list of virtual nodes.\n // It can take props and children as arguments.\n // eslint-disable-next-line no-unused-vars\n (props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;\n}\n\n// The POJOComponent interface represents a \"plain old JavaScript object\" (POJO) component.\n// It has a view function that returns a virtual node or a list of virtual nodes,\n// as well as optional props and children.\n// It can be used also to identify class instance components.\nexport interface POJOComponent extends DefaultRecord {\n // The view function that returns a virtual node or a list of virtual nodes.\n view: Component;\n // The props for the component.\n props?: VnodeProperties | null;\n // The children for the component.\n children?: any[];\n}\n\n// The VnodeComponentInterface represents a virtual node that has a component as its tag.\n// It has props and children, just like a regular virtual node.\nexport interface VnodeComponentInterface extends VnodeInterface {\n tag: Component | POJOComponent;\n props: VnodeProperties;\n children: Children;\n}\n\n// The Children interface represents a list of virtual nodes or other values.\nexport interface Children extends Array<VnodeInterface | VnodeComponentInterface | any> {}\n\n// The Directive interface represents a function that can be applied to a virtual node.\n// It receives the value, virtual node, and old virtual node as arguments, and can return a boolean value.\n// If only the virtual node is passed, it means its the on create phase for the v-node.\n// If the old virtual node is also passed, it means its the on update phase for the v-node.\nexport interface Directive {\n // eslint-disable-next-line no-unused-vars\n (value: any, vnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean;\n}\n\n// The Directives interface is a mapping of directive names to Directive functions.\nexport interface Directives extends Record<string, Directive> {}\n\n// The ReservedProps interface is a mapping of reserved prop names to the value `true`.\n// These prop names cannot be used as custom prop names.\nexport interface ReservedProps extends Record<string, true> {}\n\n// The Current interface represents the current component and virtual node that are being processed.\nexport interface Current {\n // The current component. It can be a component, a POJO component, or null.\n component: Component | POJOComponent | null;\n // The current virtual node. It must have a DOM element associated with it.\n vnode: VnodeWithDom | null;\n // The old virtual node. It must have a DOM element associated with it.\n oldVnode?: VnodeWithDom | null;\n // The current event. It can be an event or null.\n event: Event | null;\n}\n\n// The V function is the main function for creating virtual nodes.\n// It takes a tag or component, props, and children as arguments, and returns a virtual node.\nexport interface V {\n // eslint-disable-next-line no-unused-vars, no-use-before-define\n (tagOrComponent: string | Component | POJOComponent, props: VnodeProperties | null, ...children: Children):\n | VnodeInterface\n | VnodeComponentInterface;\n // eslint-disable-next-line no-unused-vars, no-use-before-define\n fragment(_: any, ...children: Children): Children;\n}\n\n// 'textTag' is a constant string that is used to represent text nodes in the virtual DOM.\nconst textTag = \"#text\";\n\n// 'isNodeJs' is a boolean that is true if the code is running in a Node.js environment and false otherwise.\n// It is determined by checking if the 'process' global object is defined and has a 'versions' property.\nexport let isNodeJs = Boolean(typeof process !== \"undefined\" && process.versions && process.versions.node);\n\n// 'createDomElement' is a function that creates a new DOM element with the specified tag name.\n// If 'isSVG' is true, it creates an SVG element instead of a regular DOM element.\nexport function createDomElement(tag: string, isSVG: boolean = false): DomElement {\n return isSVG ? document.createElementNS(\"http://www.w3.org/2000/svg\", tag) : document.createElement(tag);\n}\n\n// 'Vnode' is a class that represents a virtual DOM node.\n// It has three properties: 'tag', 'props', and 'children'.\n// 'Vnode' is exported as an object with a type of 'VnodeInterface'.\n// The 'as unknown as VnodeInterface' is used to tell TypeScript that the 'Vnode' function has the same type as 'VnodeInterface'.\nexport const Vnode = function Vnode(this: VnodeInterface, tag: string, props: VnodeProperties, children: Children) {\n // 'this' refers to the current instance of 'Vnode'.\n this.tag = tag;\n this.props = props;\n this.children = children;\n} as unknown as VnodeInterface;\n\n// 'isComponent' is a function that returns true if the given 'component' is a valid component and false otherwise.\n// A component is either a function or an object with a 'view' function.\nexport function isComponent(component: unknown): component is Component {\n return Boolean(\n component && (typeof component === \"function\" || (typeof component === \"object\" && \"view\" in component))\n );\n}\n\n// 'isVnode' is a function that returns true if the given 'object' is a 'Vnode' instance and false otherwise.\nexport const isVnode = (object?: unknown | VnodeInterface): object is VnodeInterface => {\n // Use the 'instanceof' operator to check if 'object' is an instance of 'Vnode'.\n return object instanceof Vnode;\n};\n\n// 'isVnodeComponent' is a function that returns true if the given 'object' is a 'Vnode' instance with a 'tag' property that is a valid component.\n// It returns false otherwise.\nexport const isVnodeComponent = (object?: unknown | VnodeComponentInterface): object is VnodeComponentInterface => {\n // Check if 'object' is a 'Vnode' instance and its 'tag' property is a valid component.\n return isVnode(object) && isComponent(object.tag);\n};\n\n// 'domToVnode' is a function that converts a DOM node to a 'Vnode' instance.\nexport function domToVnode(dom: any): VnodeWithDom {\n // If the child node is a text node, create a 'Vnode' instance with the 'textTag' constant as the 'tag' property.\n // Set the 'dom' property of the 'Vnode' instance to the child DOM node.\n // Push the 'Vnode' instance to the 'children' array.\n if (dom.nodeType === 3) {\n let vnode = new Vnode(textTag, {}, [dom.nodeValue]);\n vnode.dom = dom;\n return vnode as VnodeWithDom;\n }\n\n let children: VnodeWithDom[] = [];\n // Iterate through all child nodes of 'dom'.\n for (let i = 0, l = dom.childNodes.length; i < l; i++) {\n let childDom = dom.childNodes[i];\n // If the child node is an element node, recursively call 'domToVnode' to convert it to a 'Vnode' instance.\n // Push the 'Vnode' instance to the 'children' array.\n if (childDom.nodeType === 1 || childDom.nodeType === 3) {\n children.push(domToVnode(childDom));\n }\n }\n\n let props: VnodeProperties = {};\n // Iterate through all attributes of 'dom'.\n for (let i = 0, l = dom.attributes.length; i < l; i++) {\n let attr = dom.attributes[i];\n // Add the attribute to the 'props' object, using the attribute's name as the key and its value as the value.\n props[attr.nodeName] = attr.nodeValue;\n }\n\n // Create a new 'Vnode' instance with the 'tag' property set to the lowercase version of the DOM node's tag name.\n // Set the 'props' and 'children' properties to the 'props' and 'children' arrays respectively.\n // Set the 'dom' property of the 'Vnode' instance to the DOM node.\n let vnode = new Vnode(dom.tagName.toLowerCase(), props, children);\n vnode.dom = dom;\n return vnode as VnodeWithDom;\n}\n\n// This function takes in an HTML string and creates a virtual node representation of it\n// using the `domToVnode` function. It does this by creating a new `div` element, setting\n// its `innerHTML` to the provided HTML string, and then using `map` to iterate over the\n// `childNodes` of the `div` element, passing each one to `domToVnode` to create a virtual\n// node representation of it. The resulting array of virtual nodes is then returned.\nexport function trust(htmlString: string) {\n let div = createDomElement(\"div\");\n div.innerHTML = htmlString.trim();\n\n return [].map.call(div.childNodes, (item) => domToVnode(item));\n}\n\n/* ========================================================================== */\n/* Main Component implementation */\n/* ========================================================================== */\n\n// These variables are used to store the main component, the main virtual node, and whether\n// the main component is currently mounted.\nlet mainComponent: VnodeComponentInterface | null = null;\nlet mainVnode: VnodeWithDom | null = null;\nlet isMounted = false;\n\n// This object is used to store the current virtual node and component being rendered.\nexport const current: Current = {\n vnode: null,\n oldVnode: null,\n component: null,\n event: null\n};\n\n/* Reserved props ----------------------------------------------------------- */\n// This object is used to store the names of reserved props, which are props that are reserved\n// for special purposes and should not be used as regular component props.\nexport const reservedProps: Record<string, true> = {\n key: true,\n state: true,\n \"v-keep\": true,\n\n // Built in directives\n \"v-if\": true,\n \"v-unless\": true,\n \"v-for\": true,\n \"v-show\": true,\n \"v-class\": true,\n \"v-html\": true,\n \"v-model\": true,\n \"v-create\": true,\n \"v-update\": true,\n \"v-cleanup\": true\n};\n\n/* Mounting, Updating, Cleanup and Unmounting ------------------------------- */\n// These sets are used to store callbacks for various lifecycle events: mounting, updating,\n// cleaning up, and unmounting.\nconst onCleanupSet: Set<Function> = new Set();\nconst onMountSet: Set<Function> = new Set();\nconst onUpdateSet: Set<Function> = new Set();\nconst onUnmountSet: Set<Function> = new Set();\n\n// These functions allow users to register callbacks for the corresponding lifecycle events.\nexport function onMount(callback: Function) {\n if (!isMounted) {\n onMountSet.add(callback);\n }\n}\n\nexport function onUpdate(callback: Function) {\n onUpdateSet.add(callback);\n}\n\nexport function onCleanup(callback: Function) {\n onCleanupSet.add(callback);\n}\n\nexport function onUnmount(callback: Function) {\n if (!isMounted) {\n onUnmountSet.add(callback);\n }\n}\n\n// This function is used to call all the callbacks in a given set.\nfunction callSet(set: Set<Function>) {\n for (let callback of set) {\n callback();\n }\n\n set.clear();\n}\n\n/* Event listener ----------------------------------------------------------- */\n\n// This object stores the names of event listeners that have been added\nconst eventListenerNames: Record<string, true> = {};\n\n// This function is called when an event occurs\nfunction eventListener(e: Event) {\n // Set the current event to the event that occurred so that it can be prevented if necessary\n current.event = e;\n\n // Convert the target of the event to a DOM element\n let dom = e.target as DomElement;\n\n // Create the name of the event listener by adding \"v-on\" to the event type\n let name = `v-on${e.type}`;\n\n // Keep going up the DOM tree until we find an element with an event listener\n // matching the event type\n while (dom) {\n if (dom[name]) {\n // Call the event listener function\n dom[name](e, dom);\n\n // If the default action of the event hasn't been prevented, update the DOM\n if (!e.defaultPrevented) {\n update();\n }\n return;\n }\n dom = dom.parentNode as DomElement;\n }\n\n current.event = null;\n}\n\n/* Directives --------------------------------------------------------------- */\n\n// This function creates a directive that hides an element based on a condition\nlet hideDirective = (test: boolean) => (bool: boolean, vnode: VnodeInterface, oldnode?: VnodeInterface) => {\n // If test is true, use the value of bool. Otherwise, use the opposite of bool.\n let value = test ? bool : !bool;\n\n // If the value is true, hide the element by replacing it with a text node\n if (value) {\n let newdom = document.createTextNode(\"\");\n if (oldnode && oldnode.dom && oldnode.dom.parentNode) {\n oldnode.dom.parentNode.replaceChild(newdom, oldnode.dom);\n }\n vnode.tag = \"#text\";\n vnode.children = [];\n vnode.props = {};\n vnode.dom = newdom as unknown as DomElement;\n return false;\n }\n};\n\n// This object stores all the available directives\nexport const directives: Directives = {\n // The \"v-if\" directive hides an element if the given condition is false\n \"v-if\": hideDirective(false),\n\n // The \"v-unless\" directive hides an element if the given condition is true\n \"v-unless\": hideDirective(true),\n\n // The \"v-for\" directive creates a loop and applies a callback function to each item in the loop\n \"v-for\": (set: unknown[], vnode: VnodeWithDom) => {\n let newChildren: VnodeInterface[] = [];\n let callback = vnode.children[0];\n for (let i = 0, l = set.length; i < l; i++) {\n newChildren.push(callback(set[i], i));\n }\n vnode.children = newChildren;\n },\n\n // The \"v-show\" directive shows or hides an element by setting the \"display\" style property\n \"v-show\": (bool: boolean, vnode: VnodeWithDom) => {\n (\n vnode.dom as unknown as {\n style: { display: string };\n }\n ).style.display = bool ? \"\" : \"none\";\n },\n\n // The \"v-class\" directive adds or removes class names from an element based on a condition\n \"v-class\": (classes: { [x: string]: boolean }, vnode: VnodeWithDom) => {\n // Loop through all the class names in the classes object\n for (let name in classes) {\n // Add or remove the class name from the element's class list based on the value in the classes object\n (vnode.dom as DomElement).classList.toggle(name, classes[name]);\n }\n },\n\n // The \"v-html\" directive sets the inner HTML of an element to the given HTML string\n \"v-html\": (html: string, vnode: VnodeWithDom) => {\n // Set the children of the vnode to a trusted version of the HTML string\n vnode.children = [trust(html)];\n },\n\n // The \"v-model\" directive binds the value of an input element to a model property\n \"v-model\": ([model, property, event]: any[], vnode: VnodeWithDom, oldVnode?: VnodeWithDom) => {\n let value;\n // This function updates the model property when the input element's value changes\n let handler = (e: Event) => (model[property] = (e.target as DomElement & Record<string, any>).value);\n if (vnode.tag === \"input\") {\n // If the element is an input, use the \"input\" event by default\n event = event || \"oninput\";\n // Depending on the type of input element, use a different handler function\n switch (vnode.props.type) {\n case \"checkbox\": {\n if (Array.isArray(model[property])) {\n // If the model property is an array, add or remove the value from the array when the checkbox is checked or unchecked\n handler = (e: Event) => {\n let val = (e.target as DomElement & Record<string, any>).value;\n let idx = model[property].indexOf(val);\n if (idx === -1) {\n model[property].push(val);\n } else {\n model[property].splice(idx, 1);\n }\n };\n // If the value is in the array, set the checkbox to be checked\n value = model[property].indexOf(vnode.dom.value) !== -1;\n } else if (\"value\" in vnode.props) {\n // If the input element has a \"value\" attribute, use it to determine the checked state\n handler = () => {\n if (model[property] === vnode.props.value) {\n model[property] = null;\n } else {\n model[property] = vnode.props.value;\n }\n };\n value = model[property] === vnode.props.value;\n } else {\n // If there is no \"value\" attribute, use a boolean value for the model property\n handler = () => (model[property] = !model[property]);\n value = model[property];\n }\n // Set the \"checked\" attribute on the input element\n // eslint-disable-next-line no-use-before-define\n sharedSetAttribute(\"checked\", value, vnode);\n break;\n }\n case \"radio\": {\n // If the element is a radio button, set the \"checked\" attribute based on the value of the model property\n // eslint-disable-next-line no-use-before-define\n sharedSetAttribute(\"checked\", model[property] === vnode.dom.value, vnode);\n break;\n }\n default: {\n // For all other input types, set the \"value\" attribute based on the value of the model property\n // eslint-disable-next-line no-use-before-define\n sharedSetAttribute(\"value\", model[property], vnode);\n }\n }\n } else if (vnode.tag === \"select\") {\n // If the element is a select element, use the \"click\" event by default\n event = event || \"onclick\";\n if (vnode.props.multiple) {\n // If the select element allows multiple selections, update the model property with an array of selected values\n handler = (e: Event & Record<string, any>) => {\n let val = (e.target as DomElement & Record<string, any>).value;\n if (e.ctrlKey) {\n // If the Ctrl key is pressed, add or remove the value from the array\n let idx = model[property].indexOf(val);\n if (idx === -1) {\n model[property].push(val);\n } else {\n model[property].splice(idx, 1);\n }\n } else {\n // If the Ctrl key is not pressed, set the model property to an array with the selected value\n model[property].splice(0, model[property].length);\n model[property].push(val);\n }\n };\n // Set the \"selected\" attribute on the options based on whether they are in the model property array\n vnode.children.forEach((child: VnodeInterface) => {\n if (child.tag === \"option\") {\n let value = \"value\" in child.props ? child.props.value : child.children.join(\"\").trim();\n child.props.selected = model[property].indexOf(value) !== -1;\n }\n });\n } else {\n // If the select element does not allow multiple selections, set the \"selected\" attribute on the options based on the value of the model property\n vnode.children.forEach((child: VnodeInterface) => {\n if (child.tag === \"option\") {\n let value = \"value\" in child.props ? child.props.value : child.children.join(\"\").trim();\n child.props.selected = value === model[property];\n }\n });\n }\n } else if (vnode.tag === \"textarea\") {\n // If the element is a textarea, use the \"input\" event by default\n event = event || \"oninput\";\n // Set the textarea's content to the value of the model property\n vnode.children = [model[property]];\n }\n\n // We assume that the prev handler if any will not be changed by the user across patchs\n let prevHandler = vnode.props[event];\n\n // Set the event handler on the element\n // eslint-disable-next-line no-use-before-define\n sharedSetAttribute(\n event,\n (e: Event) => {\n handler(e);\n\n // If the previous handler is defined, call it after the model has been updated\n if (prevHandler) {\n prevHandler(e);\n }\n },\n vnode,\n oldVnode\n );\n },\n\n // The \"v-create\" directive is called when a new virtual node is created.\n // The provided callback function is called with the new virtual node as an argument.\n // This directive is only called once per virtual node, when it is first created.\n // eslint-disable-next-line no-unused-vars\n \"v-create\": (callback: (vnode: VnodeWithDom) => void, vnode: VnodeWithDom, oldVnode?: VnodeWithDom) => {\n // If this is not an update, call the callback function with the new virtual node\n if (!oldVnode) {\n let cleanup = callback(vnode);\n\n // If the callback function returns a function, call it when the update is gonna be cleaned up\n if (typeof cleanup === \"function\") {\n onCleanup(cleanup);\n }\n }\n },\n\n // The \"v-update\" directive is called when an existing virtual node is updated.\n // The provided callback function is called with the new and old virtual nodes as arguments.\n // This directive is only called once per virtual node update.\n \"v-update\": (\n // eslint-disable-next-line no-unused-vars\n callback: (vnode: VnodeWithDom, oldVnode: VnodeWithDom) => void,\n vnode: VnodeWithDom,\n oldVnode?: VnodeWithDom\n ) => {\n // If this is an update, call the callback function with the new and old virtual nodes\n if (oldVnode) {\n let cleanup = callback(vnode, oldVnode);\n\n // If the callback function returns a function, call it when the update is gonna be cleaned up\n if (typeof cleanup === \"function\") {\n onCleanup(cleanup);\n }\n }\n },\n\n // The \"v-cleanup\" directive is called when the update is cleaned up.\n // The provided callback function is called with the old virtual node as an argument.\n // This directive is only called once per virtual node, when the update is cleaned up.\n \"v-cleanup\": (\n // eslint-disable-next-line no-unused-vars\n callback: (vnode: VnodeWithDom, oldVnode?: VnodeWithDom) => void,\n vnode: VnodeWithDom,\n oldVnode?: VnodeWithDom\n ) => {\n // Add the callback function to the list of cleanup functions to be called when the update is cleaned up\n onCleanup(() => callback(vnode, oldVnode));\n }\n};\n// Add a directive to the global directives object, with the key being the name\n// preceded by \"v-\". Also add the name to the global reservedProps object.\nexport function directive(name: string, directive: Directive) {\n let directiveName = `v-${name}`;\n directives[directiveName] = directive;\n reservedProps[directiveName] = true;\n}\n\n// Set an attribute on a virtual DOM node and update the actual DOM element.\n// If the attribute value is a function, add an event listener for the attribute\n// name to the DOM element represented by mainVnode.\n// If oldVnode is provided, compare the new attribute value to the old value\n// and only update the attribute if the values are different.\nfunction sharedSetAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean {\n // If the attribute value is a function, add an event listener for the attribute\n // name to the DOM element represented by mainVnode.\n if (typeof value === \"function\") {\n // Only add the event listener if it hasn't been added yet.\n if (name in eventListenerNames === false) {\n (mainVnode as VnodeWithDom).dom.addEventListener(name.slice(2), eventListener);\n eventListenerNames[name] = true;\n }\n newVnode.dom[`v-${name}`] = value;\n return;\n }\n\n // If the attribute is present on the DOM element and newVnode is not an SVG,\n // update the attribute if the value has changed.\n if (name in newVnode.dom && newVnode.isSVG === false) {\n // eslint-disable-next-line eqeqeq\n if (newVnode.dom[name] != value) {\n newVnode.dom[name] = value;\n }\n return;\n }\n\n // If oldVnode is not provided or the attribute value has changed, update the\n // attribute on the DOM element.\n if (!oldVnode || value !== oldVnode.props[name]) {\n if (value === false) {\n newVnode.dom.removeAttribute(name);\n } else {\n newVnode.dom.setAttribute(name, value);\n }\n }\n}\n\n// Set an attribute on a virtual DOM node and update the actual DOM element.\n// Skip the attribute if it is in the reservedProps object.\nexport function setAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void {\n if (name in reservedProps) {\n return;\n }\n newVnode.props[name] = value;\n sharedSetAttribute(name, value, newVnode as VnodeWithDom, oldVnode);\n}\n\n// Update the attributes on a virtual DOM node. If oldVnode is provided, remove\n// attributes from the DOM element that are not present in newVnode.props but are\n// present in oldVnode.props. Then, iterate over the attributes in newVnode.props\n// and update the DOM element with the attributes using the sharedSetAttribute\n// function. If an attribute is in the reservedProps object and has a corresponding\n// directive in the directives object, call the directive with the attribute value\n// and the two virtual DOM nodes as arguments. If the directive returns false, exit\n// the loop.\nexport function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void {\n // If oldVnode is provided, remove attributes from the DOM element that are not\n // present in newVnode.props but are present in oldVnode.props.\n if (oldVnode) {\n for (let name in oldVnode.props) {\n if (name in newVnode.props === false && name in eventListenerNames === false && name in reservedProps === false) {\n if (name in newVnode.dom && newVnode.isSVG === false) {\n newVnode.dom[name] = null;\n } else {\n newVnode.dom.removeAttribute(name);\n }\n }\n }\n }\n\n // Iterate over the attributes in newVnode.props and update the DOM element with\n // the attributes using the sharedSetAttribute function.\n for (let name in newVnode.props) {\n if (name in reservedProps) {\n // If there is a directive for the attribute, call it with the attribute value\n // and the two virtual DOM nodes as arguments. If the directive returns false,\n // exit the loop.\n if (name in directives && directives[name](newVnode.props[name], newVnode, oldVnode) === false) {\n break;\n }\n continue;\n }\n sharedSetAttribute(name, newVnode.props[name], newVnode, oldVnode);\n }\n}\n\n/* patch ------------------------------------------------------------------- */\n\n// Patch a DOM node with a new VNode tree\nexport function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void {\n // If the new tree has no children, set the text content of the parent DOM element to an empty string\n if (newVnode.children.length === 0) {\n newVnode.dom.textContent = \"\";\n return;\n }\n\n // Get the children of the new and old virtual DOM nodes\n let newTree = newVnode.children;\n let oldTree = oldVnode?.children || [];\n // Get the length of the old tree\n let oldTreeLength = oldTree.length;\n\n // If the old tree has children and the first child of the new tree is a VNode with a \"key\"\n // attribute and the first child of the old tree is a VNode with a \"key\" attribute, update\n // the DOM element in place by comparing the keys of the nodes in the trees.\n if (oldTreeLength && newTree[0] instanceof Vnode && \"key\" in newTree[0].props && \"key\" in oldTree[0].props) {\n // Get the lengths of the new and old trees\n let newTreeLength = newTree.length;\n\n // Create an object that maps keys to indices in the old tree\n let oldKeyedList: Record<string, number> = {};\n for (let i = 0; i < oldTreeLength; i++) {\n oldKeyedList[oldTree[i].props.key] = i;\n }\n\n // Create an object that maps keys to indices in the new tree\n let newKeyedList: Record<string, number> = {};\n for (let i = 0; i < newTreeLength; i++) {\n newKeyedList[newTree[i].props.key] = i;\n }\n\n // Iterate over the new tree\n for (let i = 0; i < newTreeLength; i++) {\n // Get the current new child and the corresponding old child\n let newChild = newTree[i];\n let oldChild = oldTree[oldKeyedList[newChild.props.key]];\n // Initialize a flag to determine whether to patch the child\n let shouldPatch = true;\n\n // If the old child exists, update the DOM element of the new child to match the old child's DOM element\n if (oldChild) {\n newChild.dom = oldChild.dom;\n // If the new and old children have the same \"v-keep\" attribute value, update the children of the new child to match the old child's children\n if (\"v-keep\" in newChild.props && newChild.props[\"v-keep\"] === oldChild.props[\"v-keep\"]) {\n newChild.children = oldChild.children;\n // Set the shouldPatch flag to false\n shouldPatch = false;\n } else {\n updateAttributes(newChild, oldChild);\n }\n\n // If the old child does not exist, create a new DOM element for the new child and update its attributes\n } else {\n newChild.dom = createDomElement(newChild.tag, newChild.isSVG);\n updateAttributes(newChild);\n }\n\n // If the new child's DOM element is not the i-th child of the parent DOM element, insert it\n if (!newVnode.dom.childNodes[i]) {\n newVnode.dom.appendChild(newChild.dom);\n\n // If the new child's DOM element is not the same as the i-th child of the parent DOM element, replace the i-th child with the new child's DOM element\n } else if (newVnode.dom.childNodes[i] !== newChild.dom) {\n newVnode.dom.replaceChild(newChild.dom, newVnode.dom.childNodes[i]);\n }\n\n // If the shouldPatch flag is true, recursively call the patch function on the new child, passing in the old child as the second argument\n shouldPatch && patch(newChild, oldChild);\n }\n\n // For the rest of the children, we should remove them from the DOM\n for (let i = newTreeLength; i < oldTreeLength; i++) {\n // If the i-th child of the old tree does not have a corresponding key in the new tree, remove its DOM element from the parent DOM element\n if (!newKeyedList[oldTree[i].props.key]) {\n oldTree[i].dom.parentNode && oldTree[i].dom.parentNode.removeChild(oldTree[i].dom);\n }\n }\n return;\n }\n\n // If the new tree has no children, set the text content of the parent DOM element to an empty string\n if (newTree.length === 0) {\n newVnode.dom.textContent = \"\";\n return;\n }\n\n // Set the global current object to the new and old virtual DOM nodes\n current.vnode = newVnode;\n current.oldVnode = oldVnode;\n\n // Flatten the new tree\n // Take into account that is necessary to flatten the tree before the patch process\n // to let the hooks and signals work properly\n for (let i = 0; i < newTree.length; i++) {\n let newChild = newTree[i];\n\n // If the new child is a Vnode and is not a text node\n if (newChild instanceof Vnode) {\n // If the tag of the new child is not a string, it is a component\n if (typeof newChild.tag !== \"string\") {\n // Set the current component to the tag of the new child\n current.component = newChild.tag;\n // Replace the new child with the result of calling its view or bind method, passing in the props and children as arguments\n newTree.splice(\n i--,\n 1,\n (\"view\" in newChild.tag ? newChild.tag.view.bind(newChild.tag) : newChild.tag.bind(newChild.tag))(\n newChild.props,\n ...newChild.children\n )\n );\n }\n\n continue;\n }\n\n // If the new child is an array, flatten it and continue the loop\n if (Array.isArray(newChild)) {\n newTree.splice(i--, 1, ...newChild);\n continue;\n }\n\n // If the new child is null or undefined, remove it from the new tree and continue the loop\n if (newChild === null || newChild === undefined) {\n newTree.splice(i--, 1);\n continue;\n }\n\n // If the new child is a Vnode, set the text of the Vnode to the text content of its dom property\n newTree[i] = new Vnode(textTag, {}, [newChild]);\n }\n\n // Patch the the old tree\n for (let i = 0; i < newTree.length; i++) {\n let newChild = newTree[i];\n\n if (newChild.tag === textTag) {\n // If no old child exists at the same index\n if (i >= oldTreeLength) {\n // Create a new text node for the new child\n newChild.dom = document.createTextNode(newChild.children[0]);\n // Append the new text node to the dom\n newVnode.dom.appendChild(newChild.dom);\n continue;\n }\n\n // If there is an old child at the same index\n let oldChild = oldTree[i];\n\n // If the old child is not a text node\n if (oldChild.tag !== textTag) {\n // Create a new text node for the new child\n newChild.dom = document.createTextNode(newChild.children[0]);\n // Replace the old child in the dom with the new text node\n newVnode.dom.replaceChild(newChild.dom, oldChild.dom);\n continue;\n }\n\n // If the old child is a text node\n // Set the dom property of the text Vnode to the dom property of the old child\n newChild.dom = oldChild.dom;\n // If the text content of the old child is different from the new child, update the text content of the old child\n // eslint-disable-next-line eqeqeq\n if (newChild.children[0] != oldChild.dom.textContent) {\n oldChild.dom.textContent = newChild.children[0];\n }\n continue;\n }\n\n // If the new child is not a text node\n // Set the isSVG flag for the new child if it is an SVG element or if the parent is an SVG element\n newChild.isSVG = newVnode.isSVG || newChild.tag === \"svg\";\n\n // If there is no old child at the same index\n if (i >= oldTreeLength) {\n // Create a new dom element for the new child\n newChild.dom = createDomElement(newChild.tag as string, newChild.isSVG);\n // Update the attributes of the new child\n updateAttributes(newChild as VnodeWithDom);\n // Append the new child to the dom\n newVnode.dom.appendChild(newChild.dom);\n // Recursively patch the new child\n patch(newChild as VnodeWithDom);\n continue;\n }\n\n // If there is an old child at the same index\n let oldChild = oldTree[i];\n\n // If the tag of the new child is different from the tag of the old child\n if (newChild.tag !== oldChild.tag) {\n // Create a new dom element for the new child\n newChild.dom = createDomElement(newChild.tag as string, newChild.isSVG);\n // Update the attributes of the new child\n updateAttributes(newChild as VnodeWithDom);\n // Replace the old child in the dom with the new child\n newVnode.dom.replaceChild(newChild.dom, oldChild.dom);\n // Recursively patch the new child\n patch(newChild as VnodeWithDom);\n continue;\n }\n\n // If the tag of the new child is the same as the tag of the old child\n // Set the dom property of the new child to the dom property of the old child\n newChild.dom = oldChild.dom;\n // If the v-keep prop is the same for both the new and old child, set the children of the new child to the children of the old child\n if (\"v-keep\" in newChild.props && newChild.props[\"v-keep\"] === oldChild.props[\"v-keep\"]) {\n newChild.children = oldChild.children;\n continue;\n }\n\n // Update the attributes of the new child based on the old child\n updateAttributes(newChild as VnodeWithDom, oldChild);\n // Recursively patch the new and old children\n patch(newChild as VnodeWithDom, oldChild);\n }\n\n // Remove any old children that are no longer present in the new tree\n for (let i = newTree.length; i < oldTreeLength; i++) {\n newVnode.dom.removeChild(oldTree[i].dom);\n }\n}\n\n// Update the main Vnode\nexport function update(): void | string {\n // If the main Vnode exists\n if (mainVnode) {\n // Call any cleanup functions that are registered with the onCleanupSet set\n callSet(onCleanupSet);\n // Store a reference to the old main Vnode\n let oldMainVnode = mainVnode;\n // Create a new main Vnode with the main component as its only child\n mainVnode = new Vnode(oldMainVnode.tag, oldMainVnode.props, [mainComponent]) as VnodeWithDom;\n mainVnode.dom = oldMainVnode.dom;\n mainVnode.isSVG = oldMainVnode.isSVG;\n\n // Recursively patch the new and old main Vnodes\n patch(mainVnode, oldMainVnode);\n\n // Call any update or mount functions that are registered with the onUpdateSet or onMountSet set\n callSet(isMounted ? onUpdateSet : onMountSet);\n\n // Set the isMounted flag to true\n isMounted = true;\n\n // Reset the current vnode, oldVnode, and component properties\n current.vnode = null;\n current.oldVnode = null;\n current.component = null;\n\n // If the code is running in a Node.js environment, return the inner HTML of the main Vnode's dom element\n if (isNodeJs) {\n return mainVnode.dom.innerHTML;\n }\n }\n}\n\n// Update custom Vnode\n// It is assumed that a first mount has already occurred, so,\n// the oldVnode is not null and the dom property of the oldVnode is not null\n// You need to set the dom property of the newVnode to the dom property of the oldVnode\n// The same with the isSVG property\n// Prefer this function over patch to allow for cleanup, onUpdate and onMount sets to be called\nexport function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void {\n // Call any cleanup functions that are registered with the onCleanupSet set\n callSet(onCleanupSet);\n\n // Recursively patch the new and old main Vnodes\n patch(vnode, oldVnode);\n\n // Set the oldVnode's tag, props, children, dom, and isSVG properties to the newVnode's tag, props, children, dom, and isSVG properties\n // This is necessary to allow for the oldVnode to be used as the newVnode in the next update with the normal update function\n oldVnode.tag = vnode.tag;\n oldVnode.props = { ...vnode.props };\n oldVnode.children = [...vnode.children];\n oldVnode.dom = vnode.dom;\n oldVnode.isSVG = vnode.isSVG;\n\n // Call any update or mount functions that are registered with the onUpdateSet or onMountSet set\n callSet(isMounted ? onUpdateSet : onMountSet);\n\n // Set the isMounted flag to true\n isMounted = true;\n\n // Reset the current vnode, oldVnode, and component properties\n current.vnode = null;\n current.oldVnode = null;\n current.component = null;\n\n if (isNodeJs) {\n return vnode.dom.innerHTML;\n }\n}\n\n// Unmount the main Vnode\nexport function unmount() {\n // If the main Vnode exists\n if (mainVnode) {\n // Set the main component to a null Vnode\n mainComponent = new Vnode(() => null, {}, []) as VnodeComponentInterface;\n // Update the main Vnode\n let result = update();\n // Call any unmount functions that are registered with the onUnmountSet set\n callSet(onUnmountSet);\n\n // Remove any event listeners that were added to the main Vnode's dom element\n for (let name in eventListenerNames) {\n mainVnode.dom.removeEventListener(name.slice(2).toLowerCase(), eventListener);\n Reflect.deleteProperty(eventListenerNames, name);\n }\n\n // Reset the main component and main Vnode\n mainComponent = null;\n mainVnode = null;\n // Set the isMounted flag to false\n isMounted = false;\n // Reset the current vnode, oldVnode, and component properties\n current.vnode = null;\n current.oldVnode = null;\n current.component = null;\n // Return the result of updating the main Vnode\n return result;\n }\n}\n// This function takes in a DOM element or a DOM element selector and a component to be mounted on it.\nexport function mount(dom: string | DomElement, component: any) {\n // Check if the 'dom' argument is a string. If it is, select the first element that matches the given selector.\n // Otherwise, use the 'dom' argument as the container.\n let container =\n typeof dom === \"string\"\n ? isNodeJs\n ? createDomElement(dom, dom === \"svg\")\n : document.querySelectorAll(dom)[0]\n : dom;\n\n // Check if the 'component' argument is a Vnode component or a regular component.\n // If it's a regular component, create a new Vnode component using the 'component' argument as the tag.\n // If it's not a component at all, create a new Vnode component with the 'component' argument as the rendering function.\n let vnodeComponent = isVnodeComponent(component)\n ? component\n : isComponent(component)\n ? new Vnode(component, {}, [])\n : new Vnode(() => component, {}, []);\n\n // If a main component already exists and it's not the same as the current 'vnodeComponent', unmount it.\n if (mainComponent && mainComponent.tag !== vnodeComponent.tag) {\n unmount();\n }\n\n // Set the 'vnodeComponent' as the main component.\n mainComponent = vnodeComponent as VnodeComponentInterface;\n // Convert the container element to a Vnode.\n mainVnode = domToVnode(container);\n // Update the DOM with the new component.\n return update();\n}\n\n// This is a utility function for creating Vnode objects.\n// It takes in a tag or component, and optional props and children arguments.\nexport const v: V = (tagOrComponent, props = {}, ...children) => {\n // Return a new Vnode object using the given arguments.\n return new Vnode(tagOrComponent, props || {}, children);\n};\n\n// This utility function creates a fragment Vnode.\n// It takes in a placeholder and the children arguments, returns only the children.\nv.fragment = (_: VnodeProperties, ...children: Children) => children;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;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;AAChB,gBAAY;AAEZ,gBAAY;AAEZ,YAAQ,QAAQ;AAChB,YAAQ,WAAW;AACnB,YAAQ,YAAY;AAEpB,WAAO;AAAA,EACT;AACF;AAEO,SAAS,MAAM,KAA0B,WAAgB;AAG9D,MAAI,YACF,OAAO,QAAQ,WACX,WACE,iBAAiB,KAAK,QAAQ,KAAK,IACnC,SAAS,iBAAiB,GAAG,EAAE,CAAC,IAClC;AAKN,MAAI,iBAAiB,iBAAiB,SAAS,IAC3C,YACA,YAAY,SAAS,IACrB,IAAI,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC,IAC3B,IAAI,MAAM,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;AAGrC,MAAI,iBAAiB,cAAc,QAAQ,eAAe,KAAK;AAC7D,YAAQ;AAAA,EACV;AAGA,kBAAgB;AAEhB,cAAY,WAAW,SAAS;AAEhC,SAAO,OAAO;AAChB;AAIO,IAAM,IAAO,CAAC,gBAAgB,QAAQ,CAAC,MAAM,aAAa;AAE/D,SAAO,IAAI,MAAM,gBAAgB,SAAS,CAAC,GAAG,QAAQ;AACxD;AAIA,EAAE,WAAW,CAAC,MAAuB,aAAuB;",
|
|
6
|
+
"names": ["Vnode", "vnode", "value", "directive", "oldChild"]
|
|
7
|
+
}
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e="#text",t=Boolean("undefined"!=typeof process&&process.versions&&process.versions.node);function
|
|
1
|
+
(()=>{var e="#text",t=Boolean("undefined"!=typeof process&&process.versions&&process.versions.node);function o(e,t=!1){return t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}var n=function(e,t,o){this.tag=e,this.props=t,this.children=o};function l(e){return Boolean(e&&("function"==typeof e||"object"==typeof e&&"view"in e))}var d=e=>e instanceof n,i=e=>d(e)&&l(e.tag);function r(t){if(3===t.nodeType){let o=new n(e,{},[t.nodeValue]);return o.dom=t,o}let o=[];for(let e=0,n=t.childNodes.length;e<n;e++){let n=t.childNodes[e];1!==n.nodeType&&3!==n.nodeType||o.push(r(n))}let l={};for(let e=0,o=t.attributes.length;e<o;e++){let o=t.attributes[e];l[o.nodeName]=o.nodeValue}let d=new n(t.tagName.toLowerCase(),l,o);return d.dom=t,d}function p(e){let t=o("div");return t.innerHTML=e.trim(),[].map.call(t.childNodes,e=>r(e))}var s=null,a=null,c=!1,u={vnode:null,oldVnode:null,component:null,event:null},m={key:!0,state:!0,"v-keep":!0,"v-if":!0,"v-unless":!0,"v-for":!0,"v-show":!0,"v-class":!0,"v-html":!0,"v-model":!0,"v-create":!0,"v-update":!0,"v-cleanup":!0},f=new Set,v=new Set,h=new Set,g=new Set;function y(e){f.add(e)}function w(e){for(let t of e)t();e.clear()}var V={};function k(e){u.event=e;let t=e.target,o=`v-on${e.type}`;for(;t;){if(t[o])return t[o](e,t),void(e.defaultPrevented||G());t=t.parentNode}u.event=null}var C=e=>(t,o,n)=>{if(e?t:!t){let e=document.createTextNode("");return n&&n.dom&&n.dom.parentNode&&n.dom.parentNode.replaceChild(e,n.dom),o.tag="#text",o.children=[],o.props={},o.dom=e,!1}},N={"v-if":C(!1),"v-unless":C(!0),"v-for":(e,t)=>{let o=[],n=t.children[0];for(let t=0,l=e.length;t<l;t++)o.push(n(e[t],t));t.children=o},"v-show":(e,t)=>{t.dom.style.display=e?"":"none"},"v-class":(e,t)=>{for(let o in e)t.dom.classList.toggle(o,e[o])},"v-html":(e,t)=>{t.children=[p(e)]},"v-model":([e,t,o],n,l)=>{let d,i=o=>e[t]=o.target.value;if("input"===n.tag)switch(o=o||"oninput",n.props.type){case"checkbox":Array.isArray(e[t])?(i=o=>{let n=o.target.value,l=e[t].indexOf(n);-1===l?e[t].push(n):e[t].splice(l,1)},d=-1!==e[t].indexOf(n.dom.value)):"value"in n.props?(i=()=>{e[t]===n.props.value?e[t]=null:e[t]=n.props.value},d=e[t]===n.props.value):(i=()=>e[t]=!e[t],d=e[t]),S("checked",d,n);break;case"radio":S("checked",e[t]===n.dom.value,n);break;default:S("value",e[t],n)}else"select"===n.tag?(o=o||"onclick",n.props.multiple?(i=o=>{let n=o.target.value;if(o.ctrlKey){let o=e[t].indexOf(n);-1===o?e[t].push(n):e[t].splice(o,1)}else e[t].splice(0,e[t].length),e[t].push(n)},n.children.forEach(o=>{if("option"===o.tag){let n="value"in o.props?o.props.value:o.children.join("").trim();o.props.selected=-1!==e[t].indexOf(n)}})):n.children.forEach(o=>{if("option"===o.tag){let n="value"in o.props?o.props.value:o.children.join("").trim();o.props.selected=n===e[t]}})):"textarea"===n.tag&&(o=o||"oninput",n.children=[e[t]]);let r=n.props[o];S(o,e=>{i(e),r&&r(e)},n,l)},"v-create":(e,t,o)=>{if(!o){let o=e(t);"function"==typeof o&&y(o)}},"v-update":(e,t,o)=>{if(o){let n=e(t,o);"function"==typeof n&&y(n)}},"v-cleanup":(e,t,o)=>{y(()=>e(t,o))}};function S(e,t,o,n){if("function"==typeof t)return e in V==!1&&(a.dom.addEventListener(e.slice(2),k),V[e]=!0),void(o.dom[`v-${e}`]=t);e in o.dom&&!1===o.isSVG?o.dom[e]!=t&&(o.dom[e]=t):n&&t===n.props[e]||(!1===t?o.dom.removeAttribute(e):o.dom.setAttribute(e,t))}function x(e,t){if(t)for(let o in t.props)o in e.props==!1&&o in V==!1&&o in m==!1&&(o in e.dom&&!1===e.isSVG?e.dom[o]=null:e.dom.removeAttribute(o));for(let o in e.props)if(o in m){if(o in N&&!1===N[o](e.props[o],e,t))break}else S(o,e.props[o],e,t)}function b(t,l){if(0===t.children.length)return void(t.dom.textContent="");let d=t.children,i=l?.children||[],r=i.length;if(r&&d[0]instanceof n&&"key"in d[0].props&&"key"in i[0].props){let e=d.length,n={};for(let e=0;e<r;e++)n[i[e].props.key]=e;let l={};for(let t=0;t<e;t++)l[d[t].props.key]=t;for(let l=0;l<e;l++){let e=d[l],r=i[n[e.props.key]],p=!0;r?(e.dom=r.dom,"v-keep"in e.props&&e.props["v-keep"]===r.props["v-keep"]?(e.children=r.children,p=!1):x(e,r)):(e.dom=o(e.tag,e.isSVG),x(e)),t.dom.childNodes[l]?t.dom.childNodes[l]!==e.dom&&t.dom.replaceChild(e.dom,t.dom.childNodes[l]):t.dom.appendChild(e.dom),p&&b(e,r)}for(let t=e;t<r;t++)l[i[t].props.key]||i[t].dom.parentNode&&i[t].dom.parentNode.removeChild(i[t].dom)}else if(0!==d.length){u.vnode=t,u.oldVnode=l;for(let t=0;t<d.length;t++){let o=d[t];o instanceof n?"string"!=typeof o.tag&&(u.component=o.tag,d.splice(t--,1,("view"in o.tag?o.tag.view.bind(o.tag):o.tag.bind(o.tag))(o.props,...o.children))):Array.isArray(o)?d.splice(t--,1,...o):null!=o?d[t]=new n(e,{},[o]):d.splice(t--,1)}for(let n=0;n<d.length;n++){let l=d[n];if(l.tag===e){if(n>=r){l.dom=document.createTextNode(l.children[0]),t.dom.appendChild(l.dom);continue}let o=i[n];if(o.tag!==e){l.dom=document.createTextNode(l.children[0]),t.dom.replaceChild(l.dom,o.dom);continue}l.dom=o.dom,l.children[0]!=o.dom.textContent&&(o.dom.textContent=l.children[0]);continue}if(l.isSVG=t.isSVG||"svg"===l.tag,n>=r){l.dom=o(l.tag,l.isSVG),x(l),t.dom.appendChild(l.dom),b(l);continue}let p=i[n];l.tag===p.tag?(l.dom=p.dom,"v-keep"in l.props&&l.props["v-keep"]===p.props["v-keep"]?l.children=p.children:(x(l,p),b(l,p))):(l.dom=o(l.tag,l.isSVG),x(l),t.dom.replaceChild(l.dom,p.dom),b(l))}for(let e=d.length;e<r;e++)t.dom.removeChild(i[e].dom)}else t.dom.textContent=""}function G(){if(a){w(f);let e=a;if((a=new n(e.tag,e.props,[s])).dom=e.dom,a.isSVG=e.isSVG,b(a,e),w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return a.dom.innerHTML}}function A(){if(a){s=new n(()=>null,{},[]);let e=G();w(g);for(let e in V)a.dom.removeEventListener(e.slice(2).toLowerCase(),k),Reflect.deleteProperty(V,e);return s=null,a=null,c=!1,u.vnode=null,u.oldVnode=null,u.component=null,e}}var T=(e,t={},...o)=>new n(e,t||{},o);T.fragment=(e,...t)=>t;var L={Vnode:n,createDomElement:o,current:u,directive:function(e,t){let o=`v-${e}`;N[o]=t,m[o]=!0},directives:N,domToVnode:r,isComponent:l,isNodeJs:t,isVnode:d,isVnodeComponent:i,mount:function(e,d){let p="string"==typeof e?t?o(e,"svg"===e):document.querySelectorAll(e)[0]:e,c=i(d)?d:l(d)?new n(d,{},[]):new n(()=>d,{},[]);return s&&s.tag!==c.tag&&A(),s=c,a=r(p),G()},onCleanup:y,onMount:function(e){c||v.add(e)},onUnmount:function(e){c||g.add(e)},onUpdate:function(e){h.add(e)},patch:b,reservedProps:m,setAttribute:function(e,t,o,n){e in m||(o.props[e]=t,S(e,t,o,n))},trust:p,unmount:A,update:G,updateAttributes:x,updateVnode:function(e,o){if(w(f),b(e,o),o.tag=e.tag,o.props={...e.props},o.children=[...e.children],o.dom=e.dom,o.isSVG=e.isSVG,w(c?h:v),c=!0,u.vnode=null,u.oldVnode=null,u.component=null,t)return e.dom.innerHTML},v:T};"undefined"!=typeof module?module.exports=L:self.Valyrian=L})();//# sourceMappingURL=index.min.js.map
|