vasille 3.0.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/lib/core/core.js +40 -24
- package/lib/core/ivalue.js +1 -2
- package/lib/index.js +20 -22
- package/lib/node/app.js +7 -7
- package/lib/node/node.js +47 -360
- package/lib/node/watch.js +5 -6
- package/lib/{binding → runner/web/binding}/attribute.js +1 -1
- package/lib/{binding → runner/web/binding}/binding.js +1 -1
- package/lib/{binding → runner/web/binding}/class.js +3 -1
- package/lib/{binding → runner/web/binding}/style.js +2 -1
- package/lib/runner/web/runner.js +165 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/value/expression.js +3 -2
- package/lib/value/pointer.js +8 -12
- package/lib/value/reference.js +2 -2
- package/lib/views/array-view.js +1 -1
- package/lib/views/base-view.js +3 -3
- package/lib/views/map-view.js +1 -1
- package/lib/views/repeat-node.js +5 -6
- package/lib/views/set-view.js +3 -3
- package/package.json +31 -25
- package/types/core/core.d.ts +14 -13
- package/types/index.d.ts +22 -24
- package/types/node/app.d.ts +8 -7
- package/types/node/node.d.ts +49 -144
- package/types/node/runner.d.ts +10 -0
- package/types/node/watch.d.ts +7 -6
- package/types/{binding → runner/web/binding}/attribute.d.ts +4 -4
- package/types/{binding → runner/web/binding}/binding.d.ts +2 -2
- package/types/runner/web/binding/class.d.ts +11 -0
- package/types/{binding → runner/web/binding}/style.d.ts +4 -4
- package/types/runner/web/runner.d.ts +42 -0
- package/types/tsconfig-types.tsbuildinfo +1 -1
- package/types/value/expression.d.ts +2 -2
- package/types/value/pointer.d.ts +1 -1
- package/types/value/reference.d.ts +1 -1
- package/types/views/array-view.d.ts +5 -5
- package/types/views/base-view.d.ts +7 -6
- package/types/views/map-view.d.ts +3 -3
- package/types/views/repeat-node.d.ts +8 -7
- package/types/views/set-view.d.ts +5 -4
- package/lib/core/config.js +0 -3
- package/lib/models/array-model.js +0 -147
- package/lib/models/listener.js +0 -66
- package/lib/models/map-model.js +0 -59
- package/lib/models/model.js +0 -1
- package/lib/models/object-model.js +0 -78
- package/lib/models/set-model.js +0 -55
- package/lib/spec/html.js +0 -1
- package/lib/spec/react.js +0 -1
- package/lib/spec/svg.js +0 -1
- package/lib/tsconfig-build.tsbuildinfo +0 -1
- package/lib/value/mirror.js +0 -42
- package/lib/views/object-view.js +0 -17
- package/lib-node/binding/attribute.js +0 -34
- package/lib-node/binding/binding.js +0 -32
- package/lib-node/binding/class.js +0 -46
- package/lib-node/binding/style.js +0 -36
- package/lib-node/core/config.js +0 -6
- package/lib-node/core/core.js +0 -101
- package/lib-node/core/destroyable.js +0 -14
- package/lib-node/core/errors.js +0 -22
- package/lib-node/core/ivalue.js +0 -19
- package/lib-node/functional/options.js +0 -2
- package/lib-node/functional/safety.js +0 -12
- package/lib-node/index.js +0 -51
- package/lib-node/models/array-model.js +0 -152
- package/lib-node/models/listener.js +0 -70
- package/lib-node/models/map-model.js +0 -63
- package/lib-node/models/model.js +0 -2
- package/lib-node/models/object-model.js +0 -82
- package/lib-node/models/set-model.js +0 -59
- package/lib-node/node/app.js +0 -34
- package/lib-node/node/node.js +0 -656
- package/lib-node/node/watch.js +0 -26
- package/lib-node/spec/html.js +0 -2
- package/lib-node/spec/react.js +0 -2
- package/lib-node/spec/svg.js +0 -2
- package/lib-node/tsconfig-build-node.tsbuildinfo +0 -1
- package/lib-node/value/expression.js +0 -65
- package/lib-node/value/mirror.js +0 -46
- package/lib-node/value/pointer.js +0 -79
- package/lib-node/value/reference.js +0 -50
- package/lib-node/views/array-view.js +0 -21
- package/lib-node/views/base-view.js +0 -31
- package/lib-node/views/map-view.js +0 -18
- package/lib-node/views/object-view.js +0 -21
- package/lib-node/views/repeat-node.js +0 -53
- package/lib-node/views/set-view.js +0 -22
- package/types/binding/class.d.ts +0 -11
- package/types/core/config.d.ts +0 -3
- package/types/functional/options.d.ts +0 -10
- package/types/models/array-model.d.ts +0 -55
- package/types/models/listener.d.ts +0 -48
- package/types/models/map-model.d.ts +0 -34
- package/types/models/model.d.ts +0 -14
- package/types/models/object-model.d.ts +0 -38
- package/types/models/set-model.d.ts +0 -33
- package/types/spec/html.d.ts +0 -975
- package/types/spec/react.d.ts +0 -4
- package/types/spec/svg.d.ts +0 -314
- package/types/value/mirror.d.ts +0 -33
- package/types/views/object-view.d.ts +0 -10
- /package/lib/{functional/options.js → node/runner.js} +0 -0
package/lib-node/node/app.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Portal = exports.App = void 0;
|
|
4
|
-
const node_1 = require("./node");
|
|
5
|
-
/**
|
|
6
|
-
* Represents a Vasille.js application
|
|
7
|
-
* @class App
|
|
8
|
-
* @extends AppNode
|
|
9
|
-
*/
|
|
10
|
-
class App extends node_1.Root {
|
|
11
|
-
/**
|
|
12
|
-
* Constructs an app node
|
|
13
|
-
* @param node {Element} The root of application
|
|
14
|
-
* @param input
|
|
15
|
-
*/
|
|
16
|
-
constructor(node, input) {
|
|
17
|
-
super(input);
|
|
18
|
-
this.node = node;
|
|
19
|
-
}
|
|
20
|
-
appendNode(node) {
|
|
21
|
-
this.node.appendChild(node);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.App = App;
|
|
25
|
-
class Portal extends node_1.Fragment {
|
|
26
|
-
constructor(input) {
|
|
27
|
-
super(input, ":portal");
|
|
28
|
-
this.node = input.node;
|
|
29
|
-
}
|
|
30
|
-
appendNode(node) {
|
|
31
|
-
this.node.appendChild(node);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.Portal = Portal;
|
package/lib-node/node/node.js
DELETED
|
@@ -1,656 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DebugNode = exports.SwitchedNode = exports.Extension = exports.Tag = exports.INode = exports.TextNode = exports.Fragment = exports.Root = void 0;
|
|
4
|
-
const core_1 = require("../core/core");
|
|
5
|
-
const ivalue_1 = require("../core/ivalue");
|
|
6
|
-
const reference_1 = require("../value/reference");
|
|
7
|
-
const expression_1 = require("../value/expression");
|
|
8
|
-
const attribute_1 = require("../binding/attribute");
|
|
9
|
-
const class_1 = require("../binding/class");
|
|
10
|
-
const style_1 = require("../binding/style");
|
|
11
|
-
const errors_1 = require("../core/errors");
|
|
12
|
-
const config_1 = require("../core/config");
|
|
13
|
-
/**
|
|
14
|
-
* This class is symbolic
|
|
15
|
-
* @extends Reactive
|
|
16
|
-
*/
|
|
17
|
-
class Root extends core_1.Reactive {
|
|
18
|
-
constructor() {
|
|
19
|
-
super(...arguments);
|
|
20
|
-
/**
|
|
21
|
-
* The children list
|
|
22
|
-
* @type Array
|
|
23
|
-
*/
|
|
24
|
-
this.children = new Set();
|
|
25
|
-
this.lastChild = undefined;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Pushes a node to children immediately
|
|
29
|
-
* @param node {Fragment} A node to push
|
|
30
|
-
* @protected
|
|
31
|
-
*/
|
|
32
|
-
pushNode(node) {
|
|
33
|
-
node.parent = this;
|
|
34
|
-
this.lastChild = node;
|
|
35
|
-
this.children.add(node);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Find the first node in the element if so exists
|
|
39
|
-
* @return {?Element}
|
|
40
|
-
* @protected
|
|
41
|
-
*/
|
|
42
|
-
findFirstChild() {
|
|
43
|
-
let first;
|
|
44
|
-
this.children.forEach(child => {
|
|
45
|
-
first = first || child.findFirstChild();
|
|
46
|
-
});
|
|
47
|
-
return first;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Defines a text fragment
|
|
51
|
-
* @param text {String | IValue} A text fragment string
|
|
52
|
-
* @param cb {function (TextNode)} Callback if previous is slot name
|
|
53
|
-
*/
|
|
54
|
-
text(text) {
|
|
55
|
-
const node = new TextNode({ text });
|
|
56
|
-
this.pushNode(node);
|
|
57
|
-
node.compose();
|
|
58
|
-
}
|
|
59
|
-
debug(text) {
|
|
60
|
-
if (config_1.config.debugUi) {
|
|
61
|
-
const node = new DebugNode({ text });
|
|
62
|
-
this.pushNode(node);
|
|
63
|
-
node.compose();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Defines a tag element
|
|
68
|
-
* @param tagName {String} the tag name
|
|
69
|
-
* @param input
|
|
70
|
-
* @param cb {function(Tag, *)} callback
|
|
71
|
-
*/
|
|
72
|
-
tag(tagName, input, cb) {
|
|
73
|
-
const tag = new Tag(input, tagName);
|
|
74
|
-
input.slot = cb || input.slot;
|
|
75
|
-
this.pushNode(tag);
|
|
76
|
-
tag.compose();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Defines a custom element
|
|
80
|
-
* @param node {Fragment} vasille element to insert
|
|
81
|
-
* @param callback {function($ : *)}
|
|
82
|
-
*/
|
|
83
|
-
create(node, callback) {
|
|
84
|
-
this.pushNode(node);
|
|
85
|
-
node.compose();
|
|
86
|
-
callback === null || callback === void 0 ? void 0 : callback(node);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Defines an if node
|
|
90
|
-
* @param cond {IValue} condition
|
|
91
|
-
* @param cb {function(Fragment)} callback to run on true
|
|
92
|
-
* @return {this}
|
|
93
|
-
*/
|
|
94
|
-
if(cond, cb) {
|
|
95
|
-
const node = new SwitchedNode();
|
|
96
|
-
this.pushNode(node);
|
|
97
|
-
node.addCase(this.case(cond, cb));
|
|
98
|
-
}
|
|
99
|
-
else(cb) {
|
|
100
|
-
if (this.lastChild instanceof SwitchedNode) {
|
|
101
|
-
this.lastChild.addCase(this.default(cb));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw (0, errors_1.userError)("wrong `else` function use", "logic-error");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
elif(cond, cb) {
|
|
108
|
-
if (this.lastChild instanceof SwitchedNode) {
|
|
109
|
-
this.lastChild.addCase(this.case(cond, cb));
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
throw (0, errors_1.userError)("wrong `elif` function use", "logic-error");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a case for switch
|
|
117
|
-
* @param cond {IValue<boolean>}
|
|
118
|
-
* @param cb {function(Fragment) : void}
|
|
119
|
-
* @return {{cond : IValue, cb : (function(Fragment) : void)}}
|
|
120
|
-
*/
|
|
121
|
-
case(cond, cb) {
|
|
122
|
-
return { cond, cb };
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* @param cb {(function(Fragment) : void)}
|
|
126
|
-
* @return {{cond : IValue, cb : (function(Fragment) : void)}}
|
|
127
|
-
*/
|
|
128
|
-
default(cb) {
|
|
129
|
-
return { cond: trueIValue, cb };
|
|
130
|
-
}
|
|
131
|
-
destroy() {
|
|
132
|
-
this.children.forEach(child => child.destroy());
|
|
133
|
-
this.children.clear();
|
|
134
|
-
this.lastChild = undefined;
|
|
135
|
-
super.destroy();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.Root = Root;
|
|
139
|
-
class Fragment extends Root {
|
|
140
|
-
constructor(input, name) {
|
|
141
|
-
super(input);
|
|
142
|
-
this.name = name;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Pushes a node to children immediately
|
|
146
|
-
* @param node {Fragment} A node to push
|
|
147
|
-
* @protected
|
|
148
|
-
*/
|
|
149
|
-
pushNode(node) {
|
|
150
|
-
if (this.lastChild) {
|
|
151
|
-
this.lastChild.next = node;
|
|
152
|
-
}
|
|
153
|
-
node.prev = this.lastChild;
|
|
154
|
-
super.pushNode(node);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Append a node to end of element
|
|
158
|
-
* @param node {Node} node to insert
|
|
159
|
-
*/
|
|
160
|
-
appendNode(node) {
|
|
161
|
-
if (this.next) {
|
|
162
|
-
this.next.insertAdjacent(node);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this.parent.appendNode(node);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Insert a node as a sibling of this
|
|
170
|
-
* @param node {Node} node to insert
|
|
171
|
-
*/
|
|
172
|
-
insertAdjacent(node) {
|
|
173
|
-
const child = this.findFirstChild();
|
|
174
|
-
if (child) {
|
|
175
|
-
const parent = child.parentElement;
|
|
176
|
-
if (parent) {
|
|
177
|
-
child.parentElement.insertBefore(node, child);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
else if (this.next) {
|
|
181
|
-
this.next.insertAdjacent(node);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
this.parent.appendNode(node);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
compose() {
|
|
188
|
-
// do nothing
|
|
189
|
-
// to override it
|
|
190
|
-
}
|
|
191
|
-
insertBefore(node) {
|
|
192
|
-
node.prev = this.prev;
|
|
193
|
-
node.next = this;
|
|
194
|
-
if (this.prev) {
|
|
195
|
-
this.prev.next = node;
|
|
196
|
-
}
|
|
197
|
-
this.prev = node;
|
|
198
|
-
}
|
|
199
|
-
insertAfter(node) {
|
|
200
|
-
node.prev = this;
|
|
201
|
-
node.next = this.next;
|
|
202
|
-
this.next = node;
|
|
203
|
-
}
|
|
204
|
-
remove() {
|
|
205
|
-
if (this.next) {
|
|
206
|
-
this.next.prev = this.prev;
|
|
207
|
-
}
|
|
208
|
-
if (this.prev) {
|
|
209
|
-
this.prev.next = this.next;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
destroy() {
|
|
213
|
-
if (this.parent.lastChild === this) {
|
|
214
|
-
this.parent.lastChild = this.prev;
|
|
215
|
-
}
|
|
216
|
-
super.destroy();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.Fragment = Fragment;
|
|
220
|
-
const trueIValue = new reference_1.Reference(true);
|
|
221
|
-
/**
|
|
222
|
-
* Represents a text node
|
|
223
|
-
* @class TextNode
|
|
224
|
-
* @extends Fragment
|
|
225
|
-
*/
|
|
226
|
-
class TextNode extends Fragment {
|
|
227
|
-
constructor(input) {
|
|
228
|
-
super(input, ":text");
|
|
229
|
-
}
|
|
230
|
-
compose() {
|
|
231
|
-
var _a, _b;
|
|
232
|
-
const text = this.input.text;
|
|
233
|
-
this.node = document.createTextNode((_b = (_a = (text instanceof ivalue_1.IValue ? text.$ : text)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "");
|
|
234
|
-
if (text instanceof ivalue_1.IValue) {
|
|
235
|
-
this.register(new expression_1.Expression((v) => {
|
|
236
|
-
var _a;
|
|
237
|
-
this.node.replaceData(0, -1, (_a = v === null || v === void 0 ? void 0 : v.toString()) !== null && _a !== void 0 ? _a : "");
|
|
238
|
-
}, text));
|
|
239
|
-
}
|
|
240
|
-
this.parent.appendNode(this.node);
|
|
241
|
-
}
|
|
242
|
-
findFirstChild() {
|
|
243
|
-
return this.node;
|
|
244
|
-
}
|
|
245
|
-
destroy() {
|
|
246
|
-
this.node.remove();
|
|
247
|
-
super.destroy();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.TextNode = TextNode;
|
|
251
|
-
/**
|
|
252
|
-
* Vasille node which can manipulate an element node
|
|
253
|
-
* @class INode
|
|
254
|
-
* @extends Fragment
|
|
255
|
-
*/
|
|
256
|
-
class INode extends Fragment {
|
|
257
|
-
constructor() {
|
|
258
|
-
super(...arguments);
|
|
259
|
-
/**
|
|
260
|
-
* Defines if node is unmounted
|
|
261
|
-
* @type {boolean}
|
|
262
|
-
*/
|
|
263
|
-
this.unmounted = false;
|
|
264
|
-
}
|
|
265
|
-
get element() {
|
|
266
|
-
return this.node;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Bind attribute value
|
|
270
|
-
* @param name {String} name of attribute
|
|
271
|
-
* @param value {IValue} value
|
|
272
|
-
*/
|
|
273
|
-
attr(name, value) {
|
|
274
|
-
this.register(new attribute_1.AttributeBinding(this, name, value));
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Set attribute value
|
|
278
|
-
* @param name {string} name of attribute
|
|
279
|
-
* @param value {string} value
|
|
280
|
-
*/
|
|
281
|
-
setAttr(name, value) {
|
|
282
|
-
if (typeof value === "boolean") {
|
|
283
|
-
if (value) {
|
|
284
|
-
this.node.setAttribute(name, "");
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else if (value !== null && value !== undefined) {
|
|
288
|
-
this.node.setAttribute(name, `${value}`);
|
|
289
|
-
}
|
|
290
|
-
return this;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Adds a CSS class
|
|
294
|
-
* @param cl {string} Class name
|
|
295
|
-
*/
|
|
296
|
-
addClass(cl) {
|
|
297
|
-
this.node.classList.add(cl);
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Adds some CSS classes
|
|
301
|
-
* @param cl {string} classes names
|
|
302
|
-
*/
|
|
303
|
-
removeClass(cl) {
|
|
304
|
-
this.node.classList.remove(cl);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Bind a CSS class
|
|
308
|
-
* @param className {IValue}
|
|
309
|
-
*/
|
|
310
|
-
bindClass(className) {
|
|
311
|
-
this.register(new class_1.DynamicalClassBinding(this, className));
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Bind a floating class name
|
|
315
|
-
* @param cond {IValue} condition
|
|
316
|
-
* @param className {string} class name
|
|
317
|
-
*/
|
|
318
|
-
floatingClass(cond, className) {
|
|
319
|
-
this.register(new class_1.StaticClassBinding(this, className, cond));
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Defines a style attribute
|
|
323
|
-
* @param name {String} name of style attribute
|
|
324
|
-
* @param value {IValue} value
|
|
325
|
-
*/
|
|
326
|
-
style(name, value) {
|
|
327
|
-
if (this.node instanceof HTMLElement) {
|
|
328
|
-
this.register(new style_1.StyleBinding(this, name, value));
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
throw (0, errors_1.userError)("style can be applied to HTML elements only", "non-html-element");
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Sets a style property value
|
|
336
|
-
* @param prop {string} Property name
|
|
337
|
-
* @param value {string} Property value
|
|
338
|
-
*/
|
|
339
|
-
setStyle(prop, value) {
|
|
340
|
-
if (this.node instanceof HTMLElement) {
|
|
341
|
-
this.node.style.setProperty(prop, (0, style_1.stringifyStyleValue)(value));
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
throw (0, errors_1.userError)("Style can be set for HTML elements only", "non-html-element");
|
|
345
|
-
}
|
|
346
|
-
return this;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Add a listener for an event
|
|
350
|
-
* @param name {string} Event name
|
|
351
|
-
* @param handler {function (Event)} Event handler
|
|
352
|
-
* @param options {Object | boolean} addEventListener options
|
|
353
|
-
*/
|
|
354
|
-
listen(name, handler, options) {
|
|
355
|
-
this.node.addEventListener(name, handler, options);
|
|
356
|
-
}
|
|
357
|
-
insertAdjacent(node) {
|
|
358
|
-
const parent = this.node.parentNode;
|
|
359
|
-
if (parent) {
|
|
360
|
-
parent.insertBefore(node, this.node);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* A v-show & ngShow alternative
|
|
365
|
-
* @param cond {IValue} show condition
|
|
366
|
-
*/
|
|
367
|
-
bindShow(cond) {
|
|
368
|
-
const node = this.node;
|
|
369
|
-
if (node instanceof HTMLElement) {
|
|
370
|
-
let lastDisplay = node.style.display;
|
|
371
|
-
const htmlNode = node;
|
|
372
|
-
this.register(new expression_1.Expression(cond => {
|
|
373
|
-
if (cond) {
|
|
374
|
-
if (htmlNode.style.display === "none") {
|
|
375
|
-
htmlNode.style.display = lastDisplay;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
if (htmlNode.style.display !== "none") {
|
|
380
|
-
lastDisplay = htmlNode.style.display;
|
|
381
|
-
htmlNode.style.display = "none";
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}, cond));
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
throw (0, errors_1.userError)("the element must be a html element", "bind-show");
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* bind HTML
|
|
392
|
-
* @param value {IValue}
|
|
393
|
-
*/
|
|
394
|
-
bindDomApi(name, value) {
|
|
395
|
-
const node = this.node;
|
|
396
|
-
if (node instanceof HTMLElement) {
|
|
397
|
-
node[name] = value.$;
|
|
398
|
-
this.watch((v) => {
|
|
399
|
-
node[name] = v;
|
|
400
|
-
}, value);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
throw (0, errors_1.userError)("HTML can be bound for HTML nodes only", "dom-error");
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
applyAttrs(attrs) {
|
|
407
|
-
for (const name in attrs) {
|
|
408
|
-
const value = attrs[name];
|
|
409
|
-
if (value instanceof ivalue_1.IValue) {
|
|
410
|
-
this.attr(name, value);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
this.setAttr(name, value);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
applyStyle(style) {
|
|
418
|
-
for (const name in style) {
|
|
419
|
-
const value = style[name];
|
|
420
|
-
if (value instanceof ivalue_1.IValue) {
|
|
421
|
-
this.style(name, value);
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
this.setStyle(name, value);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
applyBind(bind) {
|
|
429
|
-
const inode = this.node;
|
|
430
|
-
for (const k in bind) {
|
|
431
|
-
const value = bind[k];
|
|
432
|
-
if (!(value instanceof ivalue_1.IValue)) {
|
|
433
|
-
inode[k] = value;
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
this.bindDomApi(k, value);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
applyOptions(options) {
|
|
440
|
-
options.attr && this.applyAttrs(options.attr);
|
|
441
|
-
options.class &&
|
|
442
|
-
options.class.forEach(item => {
|
|
443
|
-
if (item instanceof ivalue_1.IValue) {
|
|
444
|
-
this.bindClass(item);
|
|
445
|
-
}
|
|
446
|
-
else if (typeof item == "string") {
|
|
447
|
-
this.addClass(item);
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
for (const name in item) {
|
|
451
|
-
const value = item[name];
|
|
452
|
-
if (value instanceof ivalue_1.IValue) {
|
|
453
|
-
this.floatingClass(value, name);
|
|
454
|
-
}
|
|
455
|
-
else if (value && name !== "$") {
|
|
456
|
-
this.addClass(name);
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
this.removeClass(name);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
options.style && this.applyStyle(options.style);
|
|
465
|
-
if (options.events) {
|
|
466
|
-
for (const name of Object.keys(options.events)) {
|
|
467
|
-
this.listen(name, options.events[name]);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
options.bind && this.applyBind(options.bind);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
exports.INode = INode;
|
|
474
|
-
/**
|
|
475
|
-
* Represents an Vasille.js HTML element node
|
|
476
|
-
* @class Tag
|
|
477
|
-
* @extends INode
|
|
478
|
-
*/
|
|
479
|
-
class Tag extends INode {
|
|
480
|
-
constructor(input, tagName) {
|
|
481
|
-
super(input, tagName);
|
|
482
|
-
}
|
|
483
|
-
compose() {
|
|
484
|
-
var _a, _b, _c, _d;
|
|
485
|
-
if (!this.name) {
|
|
486
|
-
throw (0, errors_1.internalError)("wrong Tag constructor call");
|
|
487
|
-
}
|
|
488
|
-
const node = document.createElement(this.name);
|
|
489
|
-
this.node = node;
|
|
490
|
-
this.applyOptions(this.input);
|
|
491
|
-
this.parent.appendNode(node);
|
|
492
|
-
(_b = (_a = this.input).callback) === null || _b === void 0 ? void 0 : _b.call(_a, this.node);
|
|
493
|
-
(_d = (_c = this.input).slot) === null || _d === void 0 ? void 0 : _d.call(_c, this);
|
|
494
|
-
}
|
|
495
|
-
findFirstChild() {
|
|
496
|
-
return this.unmounted ? undefined : this.node;
|
|
497
|
-
}
|
|
498
|
-
insertAdjacent(node) {
|
|
499
|
-
if (this.unmounted) {
|
|
500
|
-
if (this.next) {
|
|
501
|
-
this.next.insertAdjacent(node);
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
this.parent.appendNode(node);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
super.insertAdjacent(node);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
appendNode(node) {
|
|
512
|
-
this.node.appendChild(node);
|
|
513
|
-
}
|
|
514
|
-
extent(options) {
|
|
515
|
-
this.applyOptions(options);
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Mount/Unmount a node
|
|
519
|
-
* @param cond {IValue} show condition
|
|
520
|
-
*/
|
|
521
|
-
bindMount(cond) {
|
|
522
|
-
this.register(new expression_1.Expression(cond => {
|
|
523
|
-
if (cond) {
|
|
524
|
-
if (this.unmounted) {
|
|
525
|
-
this.insertAdjacent(this.node);
|
|
526
|
-
this.unmounted = false;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
if (!this.unmounted) {
|
|
531
|
-
this.node.remove();
|
|
532
|
-
this.unmounted = true;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}, cond));
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Runs GC
|
|
539
|
-
*/
|
|
540
|
-
destroy() {
|
|
541
|
-
this.node.remove();
|
|
542
|
-
super.destroy();
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
exports.Tag = Tag;
|
|
546
|
-
/**
|
|
547
|
-
* Represents a vasille extension node
|
|
548
|
-
* @class Extension
|
|
549
|
-
* @extends INode
|
|
550
|
-
*/
|
|
551
|
-
class Extension extends Fragment {
|
|
552
|
-
tag(tagName, input) {
|
|
553
|
-
var _a;
|
|
554
|
-
let parent = this.parent;
|
|
555
|
-
const target = tagName.toLowerCase();
|
|
556
|
-
while (parent instanceof Fragment && !(parent instanceof Tag)) {
|
|
557
|
-
parent = parent.parent;
|
|
558
|
-
}
|
|
559
|
-
if (parent instanceof Tag && parent.element.tagName.toLowerCase() === target) {
|
|
560
|
-
parent.extent(input);
|
|
561
|
-
(_a = input.slot) === null || _a === void 0 ? void 0 : _a.call(input, parent);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
exports.Extension = Extension;
|
|
566
|
-
/**
|
|
567
|
-
* Defines a node which can switch its children conditionally
|
|
568
|
-
*/
|
|
569
|
-
class SwitchedNode extends Fragment {
|
|
570
|
-
/**
|
|
571
|
-
* Constructs a switch node and define a sync function
|
|
572
|
-
*/
|
|
573
|
-
constructor() {
|
|
574
|
-
super({}, ":switch");
|
|
575
|
-
/**
|
|
576
|
-
* Array of possible cases
|
|
577
|
-
* @type {Array<{cond : IValue<unknown>, cb : function(Fragment)}>}
|
|
578
|
-
*/
|
|
579
|
-
this.cases = [];
|
|
580
|
-
this.sync = () => {
|
|
581
|
-
let i = 0;
|
|
582
|
-
for (; i < this.cases.length; i++) {
|
|
583
|
-
if (this.cases[i].cond.$) {
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
if (i === this.index) {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
if (this.lastChild) {
|
|
591
|
-
this.lastChild.destroy();
|
|
592
|
-
this.children.clear();
|
|
593
|
-
this.lastChild = undefined;
|
|
594
|
-
}
|
|
595
|
-
if (i !== this.cases.length) {
|
|
596
|
-
this.index = i;
|
|
597
|
-
this.createChild(this.cases[i].cb);
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
this.index = -1;
|
|
601
|
-
}
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
addCase(case_) {
|
|
605
|
-
this.cases.push(case_);
|
|
606
|
-
case_.cond.on(this.sync);
|
|
607
|
-
this.sync();
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Creates a child node
|
|
611
|
-
* @param cb {function(Fragment)} Call-back
|
|
612
|
-
*/
|
|
613
|
-
createChild(cb) {
|
|
614
|
-
const node = new Fragment({}, ":case");
|
|
615
|
-
node.parent = this;
|
|
616
|
-
this.lastChild = node;
|
|
617
|
-
this.children.add(node);
|
|
618
|
-
cb(node);
|
|
619
|
-
}
|
|
620
|
-
destroy() {
|
|
621
|
-
this.cases.forEach(c => {
|
|
622
|
-
c.cond.off(this.sync);
|
|
623
|
-
});
|
|
624
|
-
this.cases.splice(0);
|
|
625
|
-
super.destroy();
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
exports.SwitchedNode = SwitchedNode;
|
|
629
|
-
/**
|
|
630
|
-
* Represents a debug node
|
|
631
|
-
* @class DebugNode
|
|
632
|
-
* @extends Fragment
|
|
633
|
-
*/
|
|
634
|
-
class DebugNode extends Fragment {
|
|
635
|
-
constructor(input) {
|
|
636
|
-
super(input, ":debug");
|
|
637
|
-
}
|
|
638
|
-
compose() {
|
|
639
|
-
var _a, _b;
|
|
640
|
-
const text = this.input.text;
|
|
641
|
-
this.node = document.createComment((_b = (_a = text.$) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "");
|
|
642
|
-
this.register(new expression_1.Expression((v) => {
|
|
643
|
-
var _a;
|
|
644
|
-
this.node.replaceData(0, -1, (_a = v === null || v === void 0 ? void 0 : v.toString()) !== null && _a !== void 0 ? _a : "");
|
|
645
|
-
}, text));
|
|
646
|
-
this.parent.appendNode(this.node);
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* Runs garbage collector
|
|
650
|
-
*/
|
|
651
|
-
destroy() {
|
|
652
|
-
this.node.remove();
|
|
653
|
-
super.destroy();
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
exports.DebugNode = DebugNode;
|
package/lib-node/node/watch.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Watch = void 0;
|
|
4
|
-
const node_1 = require("./node");
|
|
5
|
-
/**
|
|
6
|
-
* Watch Node
|
|
7
|
-
* @class Watch
|
|
8
|
-
* @extends Fragment
|
|
9
|
-
*/
|
|
10
|
-
class Watch extends node_1.Fragment {
|
|
11
|
-
constructor(input) {
|
|
12
|
-
super(input, ":watch");
|
|
13
|
-
}
|
|
14
|
-
compose() {
|
|
15
|
-
this.watch(value => {
|
|
16
|
-
var _a, _b;
|
|
17
|
-
this.children.forEach(child => {
|
|
18
|
-
child.destroy();
|
|
19
|
-
});
|
|
20
|
-
this.children.clear();
|
|
21
|
-
this.lastChild = undefined;
|
|
22
|
-
(_b = (_a = this.input).slot) === null || _b === void 0 ? void 0 : _b.call(_a, this, value);
|
|
23
|
-
}, this.input.model);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.Watch = Watch;
|
package/lib-node/spec/html.js
DELETED