vasille 2.2.2 → 2.3.2
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 +34 -28
- package/cdn/es2015.js +18 -724
- package/cdn/es5.js +687 -957
- package/flow-typed/vasille.js +14 -59
- package/lib/core/core.js +3 -3
- package/lib/index.js +5 -4
- package/lib/models/array-model.js +6 -9
- package/lib/models/object-model.js +3 -17
- package/lib/node/node.js +6 -3
- package/lib/views/object-view.js +1 -1
- package/lib-node/binding/attribute.js +35 -0
- package/lib-node/binding/binding.js +33 -0
- package/lib-node/binding/class.js +48 -0
- package/lib-node/binding/style.js +27 -0
- package/lib-node/core/core.js +243 -0
- package/lib-node/core/destroyable.js +49 -0
- package/lib-node/core/errors.js +23 -0
- package/lib-node/core/ivalue.js +63 -0
- package/lib-node/functional/options.js +2 -0
- package/lib-node/index.js +54 -0
- package/lib-node/models/array-model.js +218 -0
- package/lib-node/models/listener.js +134 -0
- package/lib-node/models/map-model.js +70 -0
- package/lib-node/models/model.js +2 -0
- package/lib-node/models/object-model.js +82 -0
- package/lib-node/models/set-model.js +66 -0
- package/lib-node/node/app.js +54 -0
- package/lib-node/node/node.js +885 -0
- package/lib-node/node/watch.js +23 -0
- package/lib-node/spec/html.js +2 -0
- package/lib-node/spec/react.js +2 -0
- package/lib-node/spec/svg.js +2 -0
- package/lib-node/value/expression.js +90 -0
- package/lib-node/value/mirror.js +60 -0
- package/lib-node/value/pointer.js +30 -0
- package/lib-node/value/reference.js +55 -0
- package/lib-node/views/array-view.js +21 -0
- package/lib-node/views/base-view.js +43 -0
- package/lib-node/views/map-view.js +18 -0
- package/lib-node/views/object-view.js +20 -0
- package/lib-node/views/repeat-node.js +71 -0
- package/lib-node/views/set-view.js +19 -0
- package/package.json +21 -17
- package/types/core/core.d.ts +4 -4
- package/types/functional/options.d.ts +2 -2
- package/types/index.d.ts +10 -7
- package/types/models/array-model.d.ts +1 -1
- package/types/models/object-model.d.ts +1 -1
- package/types/node/node.d.ts +5 -4
- package/types/node/watch.d.ts +2 -2
- package/types/views/repeat-node.d.ts +2 -2
- package/lib/core/executor.js +0 -154
- package/lib/core/signal.js +0 -50
- package/lib/core/slot.js +0 -47
- package/lib/functional/components.js +0 -17
- package/lib/functional/merge.js +0 -41
- package/lib/functional/models.js +0 -26
- package/lib/functional/reactivity.js +0 -33
- package/lib/functional/stack.js +0 -127
- package/lib/node/interceptor.js +0 -83
- package/lib/v/index.js +0 -23
- package/lib/views/repeater.js +0 -63
- package/types/functional/components.d.ts +0 -4
- package/types/functional/merge.d.ts +0 -1
- package/types/functional/models.d.ts +0 -10
- package/types/functional/reactivity.d.ts +0 -11
- package/types/functional/stack.d.ts +0 -24
- package/types/v/index.d.ts +0 -36
package/flow-typed/vasille.js
CHANGED
|
@@ -16,7 +16,7 @@ declare class Mirror<T> extends Reference<T> {
|
|
|
16
16
|
* Collection of handlers
|
|
17
17
|
* @type Set
|
|
18
18
|
*/
|
|
19
|
-
$handler;
|
|
19
|
+
$handler: any;
|
|
20
20
|
/**
|
|
21
21
|
* Ensure forward only synchronization
|
|
22
22
|
*/
|
|
@@ -91,13 +91,13 @@ declare class Reference<T> extends IValue<T> {
|
|
|
91
91
|
* The encapsulated value
|
|
92
92
|
* @type {*}
|
|
93
93
|
*/
|
|
94
|
-
$value;
|
|
94
|
+
$value: any;
|
|
95
95
|
/**
|
|
96
96
|
* Array of handlers
|
|
97
97
|
* @type {Set}
|
|
98
98
|
* @readonly
|
|
99
99
|
*/
|
|
100
|
-
$onchange;
|
|
100
|
+
$onchange: any;
|
|
101
101
|
/**
|
|
102
102
|
* @param value {any} the initial value
|
|
103
103
|
*/
|
|
@@ -165,7 +165,7 @@ declare class RepeatNodePrivate<IdT> extends INodePrivate {
|
|
|
165
165
|
constructor(): void;
|
|
166
166
|
$destroy(): void;
|
|
167
167
|
}
|
|
168
|
-
declare interface RNO<T, IdT> extends
|
|
168
|
+
declare interface RNO<T, IdT> extends FragmentOptions {
|
|
169
169
|
slot?: (node: Fragment, value: T, index: IdT) => void;
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
@@ -268,12 +268,12 @@ declare class ObjectModel<T> extends Object implements ListenableModel<string, T
|
|
|
268
268
|
* @return {ObjectModel} a pointer to this
|
|
269
269
|
*/
|
|
270
270
|
set(key: string, v: T): this;
|
|
271
|
+
get values(): Record<string, T>;
|
|
271
272
|
/**
|
|
272
273
|
* Deletes an object property
|
|
273
274
|
* @param key {string} property name
|
|
274
275
|
*/
|
|
275
276
|
delete(key: string): void;
|
|
276
|
-
proxy(): Record<string, T>;
|
|
277
277
|
enableReactivity(): void;
|
|
278
278
|
disableReactivity(): void;
|
|
279
279
|
}
|
|
@@ -325,7 +325,6 @@ declare class ArrayModel<T> extends Array<T> implements ListenableModel<T, T> {
|
|
|
325
325
|
* @param data {Array} input data
|
|
326
326
|
*/
|
|
327
327
|
constructor(data?: Array<T>): void;
|
|
328
|
-
proxy(): ArrayModel<T>;
|
|
329
328
|
/**
|
|
330
329
|
* Gets the last item of array
|
|
331
330
|
* @return {*} the last item of array
|
|
@@ -413,6 +412,7 @@ declare class ArrayModel<T> extends Array<T> implements ListenableModel<T, T> {
|
|
|
413
412
|
* @return {this}
|
|
414
413
|
*/
|
|
415
414
|
removeOne(v: T): this;
|
|
415
|
+
replace(at: number, with_: T): this;
|
|
416
416
|
enableReactivity(): void;
|
|
417
417
|
disableReactivity(): void;
|
|
418
418
|
}
|
|
@@ -550,7 +550,7 @@ declare interface ListenableModel<K, T> extends IModel {
|
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
|
|
553
|
-
declare interface WatchOptions<T> extends
|
|
553
|
+
declare interface WatchOptions<T> extends FragmentOptions {
|
|
554
554
|
model: IValue<T>;
|
|
555
555
|
slot?: (node: Fragment, value: T) => void;
|
|
556
556
|
}
|
|
@@ -637,7 +637,7 @@ declare class Fragment<T> extends Reactive {
|
|
|
637
637
|
* @param data {*} additional data
|
|
638
638
|
*/
|
|
639
639
|
preinit(app: AppNode, parent: Fragment, data?: any): void;
|
|
640
|
-
init():
|
|
640
|
+
init(): T['return'];
|
|
641
641
|
compose(input: T): void;
|
|
642
642
|
/** To be overloaded: ready event handler */
|
|
643
643
|
ready(): void;
|
|
@@ -682,7 +682,7 @@ declare class Fragment<T> extends Reactive {
|
|
|
682
682
|
* @param node {Fragment} vasille element to insert
|
|
683
683
|
* @param callback {function($ : *)}
|
|
684
684
|
*/
|
|
685
|
-
create<T>(node: T, callback?: T['input']['slot']):
|
|
685
|
+
create<T>(node: T, callback?: T['input']['slot']): T['input']['return'];
|
|
686
686
|
/**
|
|
687
687
|
* Defines an if node
|
|
688
688
|
* @param cond {IValue} condition
|
|
@@ -880,6 +880,7 @@ declare class Tag<K> extends INode<TagOptionsWithSlot<K>> {
|
|
|
880
880
|
*/
|
|
881
881
|
declare class Extension<T> extends INode<T> {
|
|
882
882
|
preinit(app: AppNode, parent: Fragment): void;
|
|
883
|
+
extend(options: T): void;
|
|
883
884
|
$destroy(): void;
|
|
884
885
|
}
|
|
885
886
|
/**
|
|
@@ -1087,56 +1088,13 @@ declare class StyleBinding extends Binding<string> {
|
|
|
1087
1088
|
}
|
|
1088
1089
|
|
|
1089
1090
|
|
|
1090
|
-
declare
|
|
1091
|
-
declare function mapModel<K, T>(map?: [K, T][]): MapModel<K, T>;
|
|
1092
|
-
declare function setModel<T>(arr?: T[]): SetModel<T>;
|
|
1093
|
-
declare function objectModel<T>(obj?: {
|
|
1094
|
-
[p: string]: T;
|
|
1095
|
-
}): ObjectModel<T>;
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
declare function ref<T>(value: T): [IValue<T>, (value: T) => void];
|
|
1099
|
-
declare function mirror<T>(value: IValue<T>): Mirror<T>;
|
|
1100
|
-
declare function forward<T>(value: IValue<T>): Mirror<T>;
|
|
1101
|
-
declare function point<T>(value: IValue<T>): Pointer<T>;
|
|
1102
|
-
declare function expr<T,Args>(func: (...args: Args) => T, ...values: KindOfIValue<Args>): IValue<T>;
|
|
1103
|
-
declare function watch<Args>(func: (...args: Args) => void, ...values: KindOfIValue<Args>): void;
|
|
1104
|
-
declare function valueOf<T>(value: IValue<T>): T;
|
|
1105
|
-
declare function setValue<T>(ref: IValue<T>, value: IValue<T> | T): void;
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
declare function app<In>(renderer: (opts: In) => In["return"]): (node: Element, opts: In) => In["return"];
|
|
1109
|
-
declare function component<In>(renderer: (opts: In) => In["return"]): (opts: In, callback?: In['slot']) => In["return"];
|
|
1110
|
-
declare function fragment<In>(renderer: (opts: In) => In["return"]): (opts: In, callback?: In['slot']) => In["return"];
|
|
1111
|
-
declare function extension<In>(renderer: (opts: In) => In["return"]): (opts: In, callback?: In['slot']) => In["return"];
|
|
1112
|
-
declare function tag<K>(name: K, opts: TagOptionsWithSlot<K>, callback?: () => void): {
|
|
1113
|
-
node: (HTMLElementTagNameMap & SVGElementTagNameMap)[K];
|
|
1114
|
-
};
|
|
1115
|
-
declare type ExtractParams = any[];
|
|
1116
|
-
declare function create<T>(node: T, callback?: (...args: ExtractParams<T['input']['slot']>) => void): T;
|
|
1117
|
-
declare var vx: {
|
|
1118
|
-
if(condition: IValue<boolean>, callback: () => void): void;
|
|
1119
|
-
else(callback: () => void): void;
|
|
1120
|
-
elif(condition: IValue<boolean>, callback: () => void): void;
|
|
1121
|
-
for<T, K>(model: ListenableModel<K, T>, callback: (value: T, index: K) => void): void;
|
|
1122
|
-
watch<T_1>(model: IValue<T_1>, callback: (value: T_1) => void): void;
|
|
1123
|
-
nextTick(callback: () => void): void;
|
|
1124
|
-
};
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
declare function text(text: string | IValue<string>): void;
|
|
1129
|
-
declare function debug(text: IValue<string>): void;
|
|
1130
|
-
declare function predefine<T>(slot: T | null | undefined, predefined: T): T;
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
declare interface Options {
|
|
1091
|
+
declare interface FragmentOptions {
|
|
1134
1092
|
"v:is"?: Record<string, IValue<any>>;
|
|
1135
1093
|
return?: any;
|
|
1136
1094
|
slot?: (node: Fragment, ...args: any[]) => void;
|
|
1137
1095
|
}
|
|
1138
1096
|
declare type AttrType<T> = IValue<T | string | null> | T | string | null | undefined;
|
|
1139
|
-
declare interface TagOptions<T> extends
|
|
1097
|
+
declare interface TagOptions<T> extends FragmentOptions {
|
|
1140
1098
|
"v:attr"?: {
|
|
1141
1099
|
[K : string]:? AttrType<AcceptedTagsSpec[T]['attrs'][K]>;
|
|
1142
1100
|
} & Record<string, AttrType<number | boolean>>;
|
|
@@ -1152,9 +1110,6 @@ declare interface TagOptions<T> extends Options {
|
|
|
1152
1110
|
}
|
|
1153
1111
|
|
|
1154
1112
|
|
|
1155
|
-
declare function merge(main: Record<string, any>, ...targets: Record<string, any>[]): void;
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
1113
|
/**
|
|
1159
1114
|
* Mark an object which can be destroyed
|
|
1160
1115
|
* @class Destroyable
|
|
@@ -1342,10 +1297,10 @@ declare class Reactive<T> extends Destroyable {
|
|
|
1342
1297
|
* @param onOn {function} on hide feedback
|
|
1343
1298
|
*/
|
|
1344
1299
|
bindAlive(cond: IValue<boolean>, onOff?: () => void, onOn?: () => void): this;
|
|
1345
|
-
init():
|
|
1300
|
+
init(): T['return'];
|
|
1346
1301
|
applyOptions(input: T): void;
|
|
1347
1302
|
applyOptionsNow(): void;
|
|
1348
|
-
compose(input: T):
|
|
1303
|
+
compose(input: T): T['return'];
|
|
1349
1304
|
composeNow(): void;
|
|
1350
1305
|
runFunctional<F>(f: F, ...args: Parameters<F>): ReturnType<F>;
|
|
1351
1306
|
runOnDestroy(func: () => void): void;
|
package/lib/core/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Destroyable } from "./destroyable.js";
|
|
2
|
-
import { wrongBinding } from "./errors";
|
|
2
|
+
import { notOverwritten, wrongBinding } from "./errors";
|
|
3
3
|
import { Expression } from "../value/expression";
|
|
4
4
|
import { Reference } from "../value/reference";
|
|
5
5
|
import { Pointer } from "../value/pointer";
|
|
@@ -204,7 +204,7 @@ export class Reactive extends Destroyable {
|
|
|
204
204
|
}
|
|
205
205
|
init() {
|
|
206
206
|
this.applyOptions(this.input);
|
|
207
|
-
this.compose(this.input);
|
|
207
|
+
return this.compose(this.input);
|
|
208
208
|
}
|
|
209
209
|
applyOptions(input) {
|
|
210
210
|
// empty
|
|
@@ -213,7 +213,7 @@ export class Reactive extends Destroyable {
|
|
|
213
213
|
this.applyOptions(this.input);
|
|
214
214
|
}
|
|
215
215
|
compose(input) {
|
|
216
|
-
|
|
216
|
+
throw notOverwritten();
|
|
217
217
|
}
|
|
218
218
|
composeNow() {
|
|
219
219
|
this.compose(this.input);
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Destroyable } from "./core/destroyable";
|
|
2
|
-
import { Reactive } from "./core/core";
|
|
2
|
+
import { current, Reactive } from "./core/core";
|
|
3
3
|
import { IValue } from "./core/ivalue";
|
|
4
4
|
import { ArrayModel } from "./models/array-model";
|
|
5
5
|
import { Listener } from "./models/listener";
|
|
6
6
|
import { MapModel } from "./models/map-model";
|
|
7
7
|
import { ObjectModel } from "./models/object-model";
|
|
8
8
|
import { SetModel } from "./models/set-model";
|
|
9
|
-
import { App, AppNode } from "./node/app";
|
|
9
|
+
import { App, AppNode, Portal } from "./node/app";
|
|
10
10
|
import { Component, Extension, Fragment, INode, Tag } from "./node/node";
|
|
11
11
|
import { Expression } from "./value/expression";
|
|
12
12
|
import { Mirror } from "./value/mirror";
|
|
@@ -18,5 +18,6 @@ import { MapView } from "./views/map-view";
|
|
|
18
18
|
import { ObjectView } from "./views/object-view";
|
|
19
19
|
import { SetView } from "./views/set-view";
|
|
20
20
|
import { Binding } from "./binding/binding";
|
|
21
|
-
import
|
|
22
|
-
|
|
21
|
+
import { userError } from "./core/errors";
|
|
22
|
+
import { Watch } from "./node/watch";
|
|
23
|
+
export { Destroyable, IValue, Reference, Mirror, Pointer, ArrayModel, MapModel, ObjectModel, SetModel, BaseView, Listener, ArrayView, MapView, ObjectView, SetView, Fragment, INode, Tag, Component, Extension, AppNode, App, Portal, Expression, Binding, Reactive, Watch, userError, current, };
|
|
@@ -19,15 +19,6 @@ export class ArrayModel extends Array {
|
|
|
19
19
|
super.push(data[i]);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
// proxy
|
|
23
|
-
proxy() {
|
|
24
|
-
return new Proxy(this, {
|
|
25
|
-
set(target, p, value) {
|
|
26
|
-
target.splice(parseInt(p), 1, value);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
22
|
/* Array members */
|
|
32
23
|
/**
|
|
33
24
|
* Gets the last item of array
|
|
@@ -208,6 +199,12 @@ export class ArrayModel extends Array {
|
|
|
208
199
|
this.removeAt(this.indexOf(v));
|
|
209
200
|
return this;
|
|
210
201
|
}
|
|
202
|
+
replace(at, with_) {
|
|
203
|
+
this.listener.emitAdded(this[at], with_);
|
|
204
|
+
this.listener.emitRemoved(this[at], this[at]);
|
|
205
|
+
this[at] = with_;
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
211
208
|
enableReactivity() {
|
|
212
209
|
this.listener.enableReactivity();
|
|
213
210
|
}
|
|
@@ -56,6 +56,9 @@ export class ObjectModel extends Object {
|
|
|
56
56
|
this.listener.emitAdded(key, this.container[key]);
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
|
+
get values() {
|
|
60
|
+
return this.container;
|
|
61
|
+
}
|
|
59
62
|
/**
|
|
60
63
|
* Deletes an object property
|
|
61
64
|
* @param key {string} property name
|
|
@@ -66,23 +69,6 @@ export class ObjectModel extends Object {
|
|
|
66
69
|
delete this.container[key];
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
|
-
proxy() {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
71
|
-
const ts = this;
|
|
72
|
-
return new Proxy(this.container, {
|
|
73
|
-
get(target, p) {
|
|
74
|
-
return ts.get(p);
|
|
75
|
-
},
|
|
76
|
-
set(target, p, value) {
|
|
77
|
-
ts.set(p, value);
|
|
78
|
-
return true;
|
|
79
|
-
},
|
|
80
|
-
deleteProperty(target, p) {
|
|
81
|
-
ts.delete(p);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
72
|
enableReactivity() {
|
|
87
73
|
this.listener.enableReactivity();
|
|
88
74
|
}
|
package/lib/node/node.js
CHANGED
|
@@ -70,11 +70,11 @@ export class Fragment extends Reactive {
|
|
|
70
70
|
$.preinit(app, parent);
|
|
71
71
|
}
|
|
72
72
|
init() {
|
|
73
|
-
super.init();
|
|
73
|
+
const ret = super.init();
|
|
74
74
|
this.ready();
|
|
75
|
+
return ret;
|
|
75
76
|
}
|
|
76
77
|
compose(input) {
|
|
77
|
-
super.compose(input);
|
|
78
78
|
input.slot && input.slot(this);
|
|
79
79
|
}
|
|
80
80
|
/** To be overloaded: ready event handler */
|
|
@@ -182,7 +182,7 @@ export class Fragment extends Reactive {
|
|
|
182
182
|
node.preinit($.app, this);
|
|
183
183
|
node.input.slot = callback || node.input.slot;
|
|
184
184
|
this.pushNode(node);
|
|
185
|
-
node.init();
|
|
185
|
+
return node.init();
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
188
|
* Defines an if node
|
|
@@ -677,6 +677,9 @@ export class Extension extends INode {
|
|
|
677
677
|
throw userError("A extension node can be encapsulated only in a tag/extension/component", "virtual-dom");
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
|
+
extend(options) {
|
|
681
|
+
this.applyOptions(options);
|
|
682
|
+
}
|
|
680
683
|
$destroy() {
|
|
681
684
|
super.$destroy();
|
|
682
685
|
}
|
package/lib/views/object-view.js
CHANGED
|
@@ -7,7 +7,7 @@ import { BaseView } from "./base-view";
|
|
|
7
7
|
export class ObjectView extends BaseView {
|
|
8
8
|
compose(input) {
|
|
9
9
|
super.compose(input);
|
|
10
|
-
const obj = input.model.
|
|
10
|
+
const obj = input.model.values;
|
|
11
11
|
for (const key in obj) {
|
|
12
12
|
this.createChild(input, key, obj[key]);
|
|
13
13
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttributeBinding = void 0;
|
|
4
|
+
const binding_1 = require("./binding");
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Attribute binding description
|
|
7
|
+
* @class AttributeBinding
|
|
8
|
+
* @extends Binding
|
|
9
|
+
*/
|
|
10
|
+
class AttributeBinding extends binding_1.Binding {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs an attribute binding description
|
|
13
|
+
* @param node {INode} the vasille node
|
|
14
|
+
* @param name {String} the name of attribute
|
|
15
|
+
* @param value {IValue} value to bind
|
|
16
|
+
*/
|
|
17
|
+
constructor(node, name, value) {
|
|
18
|
+
super(value);
|
|
19
|
+
this.init((value) => {
|
|
20
|
+
if (value) {
|
|
21
|
+
if (typeof value === 'boolean') {
|
|
22
|
+
node.node.setAttribute(name, "");
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
node.node.setAttribute(name, `${value}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
node.node.removeAttribute(name);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
this.$seal();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.AttributeBinding = AttributeBinding;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Binding = void 0;
|
|
4
|
+
const destroyable_1 = require("../core/destroyable");
|
|
5
|
+
/**
|
|
6
|
+
* Describe a common binding logic
|
|
7
|
+
* @class Binding
|
|
8
|
+
* @extends Destroyable
|
|
9
|
+
*/
|
|
10
|
+
class Binding extends destroyable_1.Destroyable {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a common binding logic
|
|
13
|
+
* @param value {IValue} the value to bind
|
|
14
|
+
*/
|
|
15
|
+
constructor(value) {
|
|
16
|
+
super();
|
|
17
|
+
this.binding = value;
|
|
18
|
+
this.$seal();
|
|
19
|
+
}
|
|
20
|
+
init(bounded) {
|
|
21
|
+
this.func = bounded;
|
|
22
|
+
this.binding.$on(this.func);
|
|
23
|
+
this.func(this.binding.$);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Just clear bindings
|
|
27
|
+
*/
|
|
28
|
+
$destroy() {
|
|
29
|
+
this.binding.$off(this.func);
|
|
30
|
+
super.$destroy();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Binding = Binding;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicalClassBinding = exports.StaticClassBinding = void 0;
|
|
4
|
+
const binding_1 = require("./binding");
|
|
5
|
+
function addClass(node, cl) {
|
|
6
|
+
node.node.classList.add(cl);
|
|
7
|
+
}
|
|
8
|
+
function removeClass(node, cl) {
|
|
9
|
+
node.node.classList.remove(cl);
|
|
10
|
+
}
|
|
11
|
+
class StaticClassBinding extends binding_1.Binding {
|
|
12
|
+
constructor(node, name, value) {
|
|
13
|
+
super(value);
|
|
14
|
+
this.current = false;
|
|
15
|
+
this.init((value) => {
|
|
16
|
+
if (value !== this.current) {
|
|
17
|
+
if (value) {
|
|
18
|
+
addClass(node, name);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
removeClass(node, name);
|
|
22
|
+
}
|
|
23
|
+
this.current = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
this.$seal();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.StaticClassBinding = StaticClassBinding;
|
|
30
|
+
class DynamicalClassBinding extends binding_1.Binding {
|
|
31
|
+
constructor(node, value) {
|
|
32
|
+
super(value);
|
|
33
|
+
this.current = "";
|
|
34
|
+
this.init((value) => {
|
|
35
|
+
if (this.current != value) {
|
|
36
|
+
if (this.current.length) {
|
|
37
|
+
removeClass(node, this.current);
|
|
38
|
+
}
|
|
39
|
+
if (value.length) {
|
|
40
|
+
addClass(node, value);
|
|
41
|
+
}
|
|
42
|
+
this.current = value;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.$seal();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.DynamicalClassBinding = DynamicalClassBinding;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StyleBinding = void 0;
|
|
4
|
+
const binding_1 = require("./binding");
|
|
5
|
+
/**
|
|
6
|
+
* Describes a style attribute binding
|
|
7
|
+
* @class StyleBinding
|
|
8
|
+
* @extends Binding
|
|
9
|
+
*/
|
|
10
|
+
class StyleBinding extends binding_1.Binding {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a style binding attribute
|
|
13
|
+
* @param node {INode} the vasille node
|
|
14
|
+
* @param name {string} the name of style property
|
|
15
|
+
* @param value {IValue} the value to bind
|
|
16
|
+
*/
|
|
17
|
+
constructor(node, name, value) {
|
|
18
|
+
super(value);
|
|
19
|
+
this.init((value) => {
|
|
20
|
+
if (node.node instanceof HTMLElement) {
|
|
21
|
+
node.node.style.setProperty(name, value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
this.$seal();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.StyleBinding = StyleBinding;
|