@microsoft/fast-element 2.0.0-beta.3 → 2.0.0-beta.6
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/CHANGELOG.json +147 -0
- package/CHANGELOG.md +42 -1
- package/dist/dts/components/fast-definitions.d.ts +9 -8
- package/dist/dts/components/fast-element.d.ts +12 -24
- package/dist/dts/context.d.ts +1 -1
- package/dist/dts/di/di.d.ts +858 -0
- package/dist/dts/interfaces.d.ts +43 -7
- package/dist/dts/observation/observable.d.ts +19 -13
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/element-styles.d.ts +6 -0
- package/dist/dts/templating/binding-signal.d.ts +10 -27
- package/dist/dts/templating/binding-two-way.d.ts +16 -41
- package/dist/dts/templating/binding.d.ts +79 -118
- package/dist/dts/templating/html-directive.d.ts +28 -2
- package/dist/dts/templating/render.d.ts +277 -0
- package/dist/dts/templating/repeat.d.ts +12 -16
- package/dist/dts/templating/template.d.ts +3 -3
- package/dist/dts/templating/when.d.ts +3 -3
- package/dist/dts/testing/exports.d.ts +2 -0
- package/dist/dts/testing/fixture.d.ts +90 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/utilities.d.ts +0 -18
- package/dist/esm/components/fast-definitions.js +25 -27
- package/dist/esm/components/fast-element.js +20 -11
- package/dist/esm/context.js +5 -1
- package/dist/esm/debug.js +35 -4
- package/dist/esm/di/di.js +1351 -0
- package/dist/esm/interfaces.js +4 -0
- package/dist/esm/observation/arrays.js +303 -2
- package/dist/esm/observation/observable.js +11 -6
- package/dist/esm/platform.js +1 -1
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/element-styles.js +14 -0
- package/dist/esm/templating/binding-signal.js +56 -61
- package/dist/esm/templating/binding-two-way.js +51 -35
- package/dist/esm/templating/binding.js +137 -156
- package/dist/esm/templating/compiler.js +29 -7
- package/dist/esm/templating/html-directive.js +12 -1
- package/dist/esm/templating/render.js +392 -0
- package/dist/esm/templating/repeat.js +57 -40
- package/dist/esm/templating/template.js +8 -5
- package/dist/esm/templating/view.js +3 -1
- package/dist/esm/templating/when.js +5 -4
- package/dist/esm/testing/exports.js +2 -0
- package/dist/esm/testing/fixture.js +88 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/utilities.js +0 -95
- package/dist/fast-element.api.json +2827 -2757
- package/dist/fast-element.d.ts +215 -229
- package/dist/fast-element.debug.js +650 -256
- package/dist/fast-element.debug.min.js +1 -1
- package/dist/fast-element.js +615 -252
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +223 -234
- package/docs/api-report.md +87 -90
- package/package.json +18 -9
- package/dist/dts/hooks.d.ts +0 -20
- package/dist/dts/observation/splice-strategies.d.ts +0 -13
- package/dist/esm/hooks.js +0 -32
- package/dist/esm/observation/splice-strategies.js +0 -400
|
@@ -1,84 +1,79 @@
|
|
|
1
1
|
import { isString } from "../interfaces.js";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export class SignalBinding extends UpdateBinding {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.handlerProperty = `${this.directive.id}-h`;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Bind this behavior to the source.
|
|
15
|
-
* @param source - The source to bind to.
|
|
16
|
-
* @param context - The execution context that the binding is operating within.
|
|
17
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
18
|
-
*/
|
|
19
|
-
bind(source, context, targets) {
|
|
20
|
-
const directive = this.directive;
|
|
21
|
-
const target = targets[directive.nodeId];
|
|
22
|
-
const signal = this.getSignal(source, context);
|
|
23
|
-
const handler = (target[this.handlerProperty] = () => {
|
|
24
|
-
this.updateTarget(target, directive.targetAspect, directive.binding(source, context), source, context);
|
|
25
|
-
});
|
|
26
|
-
handler();
|
|
27
|
-
const found = signals[signal];
|
|
2
|
+
import { Binding } from "./html-directive.js";
|
|
3
|
+
const subscribers = Object.create(null);
|
|
4
|
+
export const Signal = Object.freeze({
|
|
5
|
+
subscribe(signal, subscriber) {
|
|
6
|
+
const found = subscribers[signal];
|
|
28
7
|
if (found) {
|
|
29
|
-
|
|
30
|
-
? found.
|
|
31
|
-
: (
|
|
8
|
+
found instanceof Set
|
|
9
|
+
? found.add(subscriber)
|
|
10
|
+
: (subscribers[signal] = new Set([found, subscriber]));
|
|
32
11
|
}
|
|
33
12
|
else {
|
|
34
|
-
|
|
13
|
+
subscribers[signal] = subscriber;
|
|
35
14
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
42
|
-
*/
|
|
43
|
-
unbind(source, context, targets) {
|
|
44
|
-
const signal = this.getSignal(source, context);
|
|
45
|
-
const found = signals[signal];
|
|
46
|
-
if (found && Array.isArray(found)) {
|
|
47
|
-
const directive = this.directive;
|
|
48
|
-
const target = targets[directive.nodeId];
|
|
49
|
-
const handler = target[this.handlerProperty];
|
|
50
|
-
const index = found.indexOf(handler);
|
|
51
|
-
if (index !== -1) {
|
|
52
|
-
found.splice(index, 1);
|
|
53
|
-
}
|
|
15
|
+
},
|
|
16
|
+
unsubscribe(signal, subscriber) {
|
|
17
|
+
const found = subscribers[signal];
|
|
18
|
+
if (found && found instanceof Set) {
|
|
19
|
+
found.delete(subscriber);
|
|
54
20
|
}
|
|
55
21
|
else {
|
|
56
|
-
|
|
22
|
+
subscribers[signal] = void 0;
|
|
57
23
|
}
|
|
58
|
-
}
|
|
59
|
-
getSignal(source, context) {
|
|
60
|
-
const options = this.directive.options;
|
|
61
|
-
return isString(options) ? options : options(source, context);
|
|
62
|
-
}
|
|
24
|
+
},
|
|
63
25
|
/**
|
|
64
26
|
* Sends the specified signal to signaled bindings.
|
|
65
27
|
* @param signal - The signal to send.
|
|
66
28
|
* @public
|
|
67
29
|
*/
|
|
68
|
-
|
|
69
|
-
const found =
|
|
30
|
+
send(signal) {
|
|
31
|
+
const found = subscribers[signal];
|
|
70
32
|
if (found) {
|
|
71
|
-
|
|
33
|
+
found instanceof Set
|
|
34
|
+
? found.forEach(x => x.handleChange(this, signal))
|
|
35
|
+
: found.handleChange(this, signal);
|
|
72
36
|
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
class SignalObserver {
|
|
40
|
+
constructor(dataBinding, subscriber) {
|
|
41
|
+
this.dataBinding = dataBinding;
|
|
42
|
+
this.subscriber = subscriber;
|
|
43
|
+
}
|
|
44
|
+
observe(source, context) {
|
|
45
|
+
const signal = (this.signal = this.getSignal(source, context));
|
|
46
|
+
Signal.subscribe(signal, this);
|
|
47
|
+
return this.dataBinding.evaluate(source, context);
|
|
48
|
+
}
|
|
49
|
+
dispose() {
|
|
50
|
+
Signal.unsubscribe(this.signal, this);
|
|
51
|
+
}
|
|
52
|
+
handleChange() {
|
|
53
|
+
this.subscriber.handleChange(this.dataBinding.evaluate, this);
|
|
54
|
+
}
|
|
55
|
+
getSignal(source, context) {
|
|
56
|
+
const options = this.dataBinding.options;
|
|
57
|
+
return isString(options) ? options : options(source, context);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class SignalBinding extends Binding {
|
|
61
|
+
constructor(evaluate, options) {
|
|
62
|
+
super();
|
|
63
|
+
this.evaluate = evaluate;
|
|
64
|
+
this.options = options;
|
|
65
|
+
}
|
|
66
|
+
createObserver(directive, subscriber) {
|
|
67
|
+
return new SignalObserver(this, subscriber);
|
|
73
68
|
}
|
|
74
69
|
}
|
|
75
|
-
const signalMode = BindingMode.define(SignalBinding);
|
|
76
70
|
/**
|
|
77
71
|
* Creates a signal binding configuration with the supplied options.
|
|
72
|
+
* @param binding - The binding to refresh when signaled.
|
|
78
73
|
* @param options - The signal name or a binding to use to retrieve the signal name.
|
|
79
74
|
* @returns A binding configuration.
|
|
80
75
|
* @public
|
|
81
76
|
*/
|
|
82
|
-
export
|
|
83
|
-
return
|
|
84
|
-
}
|
|
77
|
+
export function signal(binding, options) {
|
|
78
|
+
return new SignalBinding(binding, options);
|
|
79
|
+
}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import "../interfaces.js";
|
|
1
|
+
import { isString } from "../interfaces.js";
|
|
2
|
+
import { Observable, } from "../observation/observable.js";
|
|
2
3
|
import { FAST } from "../platform.js";
|
|
3
|
-
import {
|
|
4
|
+
import { Binding } from "./html-directive.js";
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
fromView: v => v,
|
|
7
|
+
};
|
|
4
8
|
let twoWaySettings = {
|
|
5
9
|
determineChangeEvent() {
|
|
6
10
|
return "change";
|
|
7
11
|
},
|
|
8
12
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @param context - The execution context that the binding is operating within.
|
|
18
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
19
|
-
*/
|
|
20
|
-
bind(source, context, targets) {
|
|
13
|
+
class TwoWayObserver {
|
|
14
|
+
constructor(directive, subscriber, dataBinding) {
|
|
15
|
+
this.directive = directive;
|
|
16
|
+
this.subscriber = subscriber;
|
|
17
|
+
this.dataBinding = dataBinding;
|
|
18
|
+
this.notifier = Observable.binding(dataBinding.evaluate, this, dataBinding.isVolatile);
|
|
19
|
+
}
|
|
20
|
+
observe(source, context) {
|
|
21
21
|
var _a;
|
|
22
|
-
super.bind(source, context, targets);
|
|
23
|
-
const directive = this.directive;
|
|
24
|
-
const target = targets[directive.nodeId];
|
|
25
22
|
if (!this.changeEvent) {
|
|
26
23
|
this.changeEvent =
|
|
27
|
-
(_a =
|
|
24
|
+
(_a = this.dataBinding.options.changeEvent) !== null && _a !== void 0 ? _a : twoWaySettings.determineChangeEvent(this.directive, this.target);
|
|
28
25
|
}
|
|
29
|
-
target.addEventListener(this.changeEvent, this);
|
|
26
|
+
this.target.addEventListener(this.changeEvent, this);
|
|
27
|
+
return this.notifier.observe(source, context);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
super.unbind(source, context, targets);
|
|
39
|
-
targets[this.directive.nodeId].removeEventListener(this.changeEvent, this);
|
|
29
|
+
dispose() {
|
|
30
|
+
this.notifier.dispose();
|
|
31
|
+
this.target.removeEventListener(this.changeEvent, this);
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
handleChange(subject, args) {
|
|
35
|
+
this.subscriber.handleChange(this.dataBinding.evaluate, this);
|
|
40
36
|
}
|
|
41
37
|
/** @internal */
|
|
42
38
|
handleEvent(event) {
|
|
43
39
|
const directive = this.directive;
|
|
44
40
|
const target = event.currentTarget;
|
|
45
|
-
const
|
|
46
|
-
const last =
|
|
41
|
+
const notifier = this.notifier;
|
|
42
|
+
const last = notifier.last; // using internal API!!!
|
|
47
43
|
if (!last) {
|
|
48
44
|
FAST.warn(1203 /* Message.twoWayBindingRequiresObservables */);
|
|
49
45
|
return;
|
|
@@ -63,7 +59,21 @@ export class TwoWayBinding extends ChangeBinding {
|
|
|
63
59
|
value = target[directive.targetAspect];
|
|
64
60
|
break;
|
|
65
61
|
}
|
|
66
|
-
last.propertySource[last.propertyName] =
|
|
62
|
+
last.propertySource[last.propertyName] = this.dataBinding.options.fromView(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class TwoWayBinding extends Binding {
|
|
66
|
+
constructor(evaluate, isVolatile, options = defaultOptions) {
|
|
67
|
+
super();
|
|
68
|
+
this.evaluate = evaluate;
|
|
69
|
+
this.isVolatile = isVolatile;
|
|
70
|
+
this.options = options;
|
|
71
|
+
if (!options.fromView) {
|
|
72
|
+
options.fromView = defaultOptions.fromView;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
createObserver(directive, subscriber) {
|
|
76
|
+
return new TwoWayObserver(directive, subscriber, this);
|
|
67
77
|
}
|
|
68
78
|
/**
|
|
69
79
|
* Configures two-way binding.
|
|
@@ -74,9 +84,15 @@ export class TwoWayBinding extends ChangeBinding {
|
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
|
-
*
|
|
87
|
+
* Creates a default binding.
|
|
88
|
+
* @param binding - The binding to refresh when changed.
|
|
89
|
+
* @param isBindingVolatile - Indicates whether the binding is volatile or not.
|
|
90
|
+
* @returns A binding configuration.
|
|
78
91
|
* @public
|
|
79
92
|
*/
|
|
80
|
-
export
|
|
81
|
-
|
|
82
|
-
}
|
|
93
|
+
export function twoWay(binding, optionsOrChangeEvent, isBindingVolatile = Observable.isVolatileBinding(binding)) {
|
|
94
|
+
if (isString(optionsOrChangeEvent)) {
|
|
95
|
+
optionsOrChangeEvent = { changeEvent: optionsOrChangeEvent };
|
|
96
|
+
}
|
|
97
|
+
return new TwoWayBinding(binding, isBindingVolatile, optionsOrChangeEvent);
|
|
98
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../interfaces.js";
|
|
1
|
+
import { isFunction } from "../interfaces.js";
|
|
2
2
|
import { ExecutionContext, Observable, } from "../observation/observable.js";
|
|
3
3
|
import { FAST } from "../platform.js";
|
|
4
4
|
import { DOM } from "./dom.js";
|
|
5
|
-
import { Aspect, HTMLDirective, } from "./html-directive.js";
|
|
6
|
-
import { Markup } from "./markup.js";
|
|
5
|
+
import { Aspect, Binding, HTMLDirective, } from "./html-directive.js";
|
|
6
|
+
import { Markup, nextId } from "./markup.js";
|
|
7
7
|
const createInnerHTMLBinding = globalThis.TrustedHTML
|
|
8
8
|
? (binding) => (s, c) => {
|
|
9
9
|
const value = binding(s, c);
|
|
@@ -13,99 +13,28 @@ const createInnerHTMLBinding = globalThis.TrustedHTML
|
|
|
13
13
|
throw FAST.error(1202 /* Message.bindingInnerHTMLRequiresTrustedTypes */);
|
|
14
14
|
}
|
|
15
15
|
: (binding) => binding;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates a binding mode based on the supplied behavior types.
|
|
23
|
-
* @param UpdateType - The base behavior type used to update aspects.
|
|
24
|
-
* @param EventType - The base behavior type used to respond to events.
|
|
25
|
-
* @returns A new binding mode.
|
|
26
|
-
*/
|
|
27
|
-
define(UpdateType, EventType = EventBinding) {
|
|
28
|
-
return Object.freeze({
|
|
29
|
-
[1]: d => new UpdateType(d, DOM.setAttribute),
|
|
30
|
-
[2]: d => new UpdateType(d, DOM.setBooleanAttribute),
|
|
31
|
-
[3]: d => new UpdateType(d, (t, a, v) => (t[a] = v)),
|
|
32
|
-
[4]: d => new (createContentBinding(UpdateType))(d, updateContentTarget),
|
|
33
|
-
[5]: d => new UpdateType(d, updateTokenListTarget),
|
|
34
|
-
[6]: d => new EventType(d),
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* Describes the configuration for a binding expression.
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export const BindingConfig = Object.freeze({
|
|
43
|
-
/**
|
|
44
|
-
* Creates a binding configuration based on the provided mode and options.
|
|
45
|
-
* @param mode - The mode to use for the configuration.
|
|
46
|
-
* @param defaultOptions - The default options to use for the configuration.
|
|
47
|
-
* @returns A new binding configuration.
|
|
48
|
-
*/
|
|
49
|
-
define(mode, defaultOptions) {
|
|
50
|
-
const config = (options) => {
|
|
51
|
-
return {
|
|
52
|
-
mode: config.mode,
|
|
53
|
-
options: Object.assign({}, defaultOptions, options),
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
config.options = defaultOptions;
|
|
57
|
-
config.mode = mode;
|
|
58
|
-
return config;
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* A base binding behavior for DOM updates.
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export class UpdateBinding {
|
|
66
|
-
/**
|
|
67
|
-
* Creates an instance of UpdateBinding.
|
|
68
|
-
* @param directive - The directive that has the configuration for this behavior.
|
|
69
|
-
* @param updateTarget - The function used to update the target with the latest value.
|
|
70
|
-
*/
|
|
71
|
-
constructor(directive, updateTarget) {
|
|
72
|
-
this.directive = directive;
|
|
73
|
-
this.updateTarget = updateTarget;
|
|
16
|
+
class OnChangeBinding extends Binding {
|
|
17
|
+
constructor(evaluate, isVolatile) {
|
|
18
|
+
super();
|
|
19
|
+
this.evaluate = evaluate;
|
|
20
|
+
this.isVolatile = isVolatile;
|
|
74
21
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* @param source - The source to bind to.
|
|
78
|
-
* @param context - The execution context that the binding is operating within.
|
|
79
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
80
|
-
*/
|
|
81
|
-
bind(source, context, targets) { }
|
|
82
|
-
/**
|
|
83
|
-
* Unbinds this behavior from the source.
|
|
84
|
-
* @param source - The source to unbind from.
|
|
85
|
-
* @param context - The execution context that the binding is operating within.
|
|
86
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
87
|
-
*/
|
|
88
|
-
unbind(source, context, targets) { }
|
|
89
|
-
/**
|
|
90
|
-
* Creates a behavior.
|
|
91
|
-
* @param targets - The targets available for behaviors to be attached to.
|
|
92
|
-
*/
|
|
93
|
-
createBehavior(targets) {
|
|
94
|
-
return this;
|
|
22
|
+
createObserver(_, subscriber) {
|
|
23
|
+
return Observable.binding(this.evaluate, subscriber, this.isVolatile);
|
|
95
24
|
}
|
|
96
25
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
26
|
+
class OneTimeBinding extends Binding {
|
|
27
|
+
constructor(evaluate) {
|
|
28
|
+
super();
|
|
29
|
+
this.evaluate = evaluate;
|
|
30
|
+
}
|
|
31
|
+
createObserver() {
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
observe(source, context) {
|
|
35
|
+
return this.evaluate(source, context);
|
|
36
|
+
}
|
|
37
|
+
dispose() { }
|
|
109
38
|
}
|
|
110
39
|
function updateContentTarget(target, aspect, value, source, context) {
|
|
111
40
|
// If there's no actual value, then this equates to the
|
|
@@ -113,7 +42,7 @@ function updateContentTarget(target, aspect, value, source, context) {
|
|
|
113
42
|
if (value === null || value === undefined) {
|
|
114
43
|
value = "";
|
|
115
44
|
}
|
|
116
|
-
// If the value has a "create" method, then it's a
|
|
45
|
+
// If the value has a "create" method, then it's a ContentTemplate.
|
|
117
46
|
if (value.create) {
|
|
118
47
|
target.textContent = "";
|
|
119
48
|
let view = target.$fastView;
|
|
@@ -199,46 +128,21 @@ function updateTokenListTarget(target, aspect, value) {
|
|
|
199
128
|
}
|
|
200
129
|
}
|
|
201
130
|
}
|
|
202
|
-
/**
|
|
203
|
-
* A binding behavior for one-time bindings.
|
|
204
|
-
* @public
|
|
205
|
-
*/
|
|
206
|
-
export class OneTimeBinding extends UpdateBinding {
|
|
207
|
-
/**
|
|
208
|
-
* Bind this behavior to the source.
|
|
209
|
-
* @param source - The source to bind to.
|
|
210
|
-
* @param context - The execution context that the binding is operating within.
|
|
211
|
-
* @param targets - The targets that behaviors in a view can attach to.
|
|
212
|
-
*/
|
|
213
|
-
bind(source, context, targets) {
|
|
214
|
-
const directive = this.directive;
|
|
215
|
-
this.updateTarget(targets[directive.nodeId], directive.targetAspect, directive.binding(source, context), source, context);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
131
|
/**
|
|
219
132
|
* A binding behavior for bindings that change.
|
|
220
133
|
* @public
|
|
221
134
|
*/
|
|
222
|
-
export class
|
|
135
|
+
export class BindingBehavior {
|
|
223
136
|
/**
|
|
224
137
|
* Creates an instance of ChangeBinding.
|
|
225
138
|
* @param directive - The directive that has the configuration for this behavior.
|
|
226
139
|
* @param updateTarget - The function used to update the target with the latest value.
|
|
227
140
|
*/
|
|
228
141
|
constructor(directive, updateTarget) {
|
|
229
|
-
|
|
230
|
-
this.
|
|
142
|
+
this.directive = directive;
|
|
143
|
+
this.updateTarget = updateTarget;
|
|
231
144
|
this.observerProperty = `${directive.id}-o`;
|
|
232
145
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Returns the binding observer used to update the node.
|
|
235
|
-
* @param target - The target node.
|
|
236
|
-
* @returns A BindingObserver.
|
|
237
|
-
*/
|
|
238
|
-
getObserver(target) {
|
|
239
|
-
var _a;
|
|
240
|
-
return ((_a = target[this.observerProperty]) !== null && _a !== void 0 ? _a : (target[this.observerProperty] = Observable.binding(this.directive.binding, this, this.isBindingVolatile)));
|
|
241
|
-
}
|
|
242
146
|
/**
|
|
243
147
|
* Bind this behavior to the source.
|
|
244
148
|
* @param source - The source to bind to.
|
|
@@ -275,12 +179,49 @@ export class ChangeBinding extends UpdateBinding {
|
|
|
275
179
|
const context = observer.context;
|
|
276
180
|
this.updateTarget(target, this.directive.targetAspect, observer.observe(source, context), source, context);
|
|
277
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns the binding observer used to update the node.
|
|
184
|
+
* @param target - The target node.
|
|
185
|
+
* @returns A BindingObserver.
|
|
186
|
+
*/
|
|
187
|
+
getObserver(target) {
|
|
188
|
+
var _a;
|
|
189
|
+
return ((_a = target[this.observerProperty]) !== null && _a !== void 0 ? _a : (target[this.observerProperty] = this.directive.dataBinding.createObserver(this.directive, this)));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates a behavior.
|
|
193
|
+
* @param targets - The targets available for behaviors to be attached to.
|
|
194
|
+
*/
|
|
195
|
+
createBehavior(targets) {
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A special binding behavior that can bind node content.
|
|
201
|
+
* @public
|
|
202
|
+
*/
|
|
203
|
+
export class ContentBehavior extends BindingBehavior {
|
|
204
|
+
/**
|
|
205
|
+
* Unbinds this behavior from the source.
|
|
206
|
+
* @param source - The source to unbind from.
|
|
207
|
+
* @param context - The execution context that the binding is operating within.
|
|
208
|
+
* @param targets - The targets that behaviors in a view can attach to.
|
|
209
|
+
*/
|
|
210
|
+
unbind(source, context, targets) {
|
|
211
|
+
super.unbind(source, context, targets);
|
|
212
|
+
const target = targets[this.directive.nodeId];
|
|
213
|
+
const view = target.$fastView;
|
|
214
|
+
if (view !== void 0 && view.isComposed) {
|
|
215
|
+
view.unbind();
|
|
216
|
+
view.needsBindOnly = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
278
219
|
}
|
|
279
220
|
/**
|
|
280
221
|
* A binding behavior for handling events.
|
|
281
222
|
* @public
|
|
282
223
|
*/
|
|
283
|
-
export class
|
|
224
|
+
export class EventBehavior {
|
|
284
225
|
/**
|
|
285
226
|
* Creates an instance of EventBinding.
|
|
286
227
|
* @param directive - The directive that has the configuration for this behavior.
|
|
@@ -301,7 +242,7 @@ export class EventBinding {
|
|
|
301
242
|
const target = targets[directive.nodeId];
|
|
302
243
|
target[this.sourceProperty] = source;
|
|
303
244
|
target[this.contextProperty] = context;
|
|
304
|
-
target.addEventListener(directive.targetAspect, this, directive.options);
|
|
245
|
+
target.addEventListener(directive.targetAspect, this, directive.dataBinding.options);
|
|
305
246
|
}
|
|
306
247
|
/**
|
|
307
248
|
* Unbinds this behavior from the source.
|
|
@@ -313,7 +254,7 @@ export class EventBinding {
|
|
|
313
254
|
const directive = this.directive;
|
|
314
255
|
const target = targets[directive.nodeId];
|
|
315
256
|
target[this.sourceProperty] = target[this.contextProperty] = null;
|
|
316
|
-
target.removeEventListener(directive.targetAspect, this, directive.options);
|
|
257
|
+
target.removeEventListener(directive.targetAspect, this, directive.dataBinding.options);
|
|
317
258
|
}
|
|
318
259
|
/**
|
|
319
260
|
* Creates a behavior.
|
|
@@ -328,25 +269,13 @@ export class EventBinding {
|
|
|
328
269
|
handleEvent(event) {
|
|
329
270
|
const target = event.currentTarget;
|
|
330
271
|
ExecutionContext.setEvent(event);
|
|
331
|
-
const result = this.directive.
|
|
272
|
+
const result = this.directive.dataBinding.evaluate(target[this.sourceProperty], target[this.contextProperty]);
|
|
332
273
|
ExecutionContext.setEvent(null);
|
|
333
274
|
if (result !== true) {
|
|
334
275
|
event.preventDefault();
|
|
335
276
|
}
|
|
336
277
|
}
|
|
337
278
|
}
|
|
338
|
-
/**
|
|
339
|
-
* The default onChange binding configuration.
|
|
340
|
-
* @public
|
|
341
|
-
*/
|
|
342
|
-
export const onChange = BindingConfig.define(BindingMode.define(ChangeBinding), {});
|
|
343
|
-
/**
|
|
344
|
-
* The default onTime binding configuration.
|
|
345
|
-
* @public
|
|
346
|
-
*/
|
|
347
|
-
export const oneTime = BindingConfig.define(BindingMode.define(OneTimeBinding), {
|
|
348
|
-
once: true,
|
|
349
|
-
});
|
|
350
279
|
/**
|
|
351
280
|
* A directive that applies bindings.
|
|
352
281
|
* @public
|
|
@@ -354,15 +283,15 @@ export const oneTime = BindingConfig.define(BindingMode.define(OneTimeBinding),
|
|
|
354
283
|
export class HTMLBindingDirective {
|
|
355
284
|
/**
|
|
356
285
|
* Creates an instance of HTMLBindingDirective.
|
|
357
|
-
* @param
|
|
358
|
-
* @param mode - The binding mode to use when applying the binding.
|
|
359
|
-
* @param options - The options to configure the binding with.
|
|
286
|
+
* @param dataBinding - The binding configuration to apply.
|
|
360
287
|
*/
|
|
361
|
-
constructor(
|
|
362
|
-
this.
|
|
363
|
-
this.mode = mode;
|
|
364
|
-
this.options = options;
|
|
288
|
+
constructor(dataBinding) {
|
|
289
|
+
this.dataBinding = dataBinding;
|
|
365
290
|
this.factory = null;
|
|
291
|
+
/**
|
|
292
|
+
* The unique id of the factory.
|
|
293
|
+
*/
|
|
294
|
+
this.id = nextId();
|
|
366
295
|
/**
|
|
367
296
|
* The type of aspect to target.
|
|
368
297
|
*/
|
|
@@ -382,24 +311,76 @@ export class HTMLBindingDirective {
|
|
|
382
311
|
createBehavior(targets) {
|
|
383
312
|
if (this.factory == null) {
|
|
384
313
|
if (this.targetAspect === "innerHTML") {
|
|
385
|
-
this.
|
|
314
|
+
this.dataBinding.evaluate = createInnerHTMLBinding(this.dataBinding.evaluate);
|
|
315
|
+
}
|
|
316
|
+
switch (this.aspectType) {
|
|
317
|
+
case 1:
|
|
318
|
+
this.factory = new BindingBehavior(this, DOM.setAttribute);
|
|
319
|
+
break;
|
|
320
|
+
case 2:
|
|
321
|
+
this.factory = new BindingBehavior(this, DOM.setBooleanAttribute);
|
|
322
|
+
break;
|
|
323
|
+
case 3:
|
|
324
|
+
this.factory = new BindingBehavior(this, (t, a, v) => (t[a] = v));
|
|
325
|
+
break;
|
|
326
|
+
case 4:
|
|
327
|
+
this.factory = new ContentBehavior(this, updateContentTarget);
|
|
328
|
+
break;
|
|
329
|
+
case 5:
|
|
330
|
+
this.factory = new BindingBehavior(this, updateTokenListTarget);
|
|
331
|
+
break;
|
|
332
|
+
case 6:
|
|
333
|
+
this.factory = new EventBehavior(this);
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
throw FAST.error(1205 /* Message.unsupportedBindingBehavior */);
|
|
386
337
|
}
|
|
387
|
-
this.factory = this.mode[this.aspectType](this);
|
|
388
338
|
}
|
|
389
339
|
return this.factory.createBehavior(targets);
|
|
390
340
|
}
|
|
391
341
|
}
|
|
392
342
|
HTMLDirective.define(HTMLBindingDirective, { aspected: true });
|
|
393
343
|
/**
|
|
394
|
-
* Creates
|
|
395
|
-
* @param binding - The binding
|
|
396
|
-
* @param
|
|
397
|
-
* @returns A binding
|
|
344
|
+
* Creates an standard binding.
|
|
345
|
+
* @param binding - The binding to refresh when changed.
|
|
346
|
+
* @param isVolatile - Indicates whether the binding is volatile or not.
|
|
347
|
+
* @returns A binding configuration.
|
|
398
348
|
* @public
|
|
399
349
|
*/
|
|
400
|
-
export function bind(binding,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
350
|
+
export function bind(binding, isVolatile = Observable.isVolatileBinding(binding)) {
|
|
351
|
+
return new OnChangeBinding(binding, isVolatile);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Creates a one time binding
|
|
355
|
+
* @param binding - The binding to refresh when signaled.
|
|
356
|
+
* @returns A binding configuration.
|
|
357
|
+
* @public
|
|
358
|
+
*/
|
|
359
|
+
export function oneTime(binding) {
|
|
360
|
+
return new OneTimeBinding(binding);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Creates an event listener binding.
|
|
364
|
+
* @param binding - The binding to invoke when the event is raised.
|
|
365
|
+
* @param options - Event listener options.
|
|
366
|
+
* @returns A binding configuration.
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
export function listener(binding, options) {
|
|
370
|
+
const config = new OnChangeBinding(binding, false);
|
|
371
|
+
config.options = options;
|
|
372
|
+
return config;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Normalizes the input value into a binding.
|
|
376
|
+
* @param value - The value to create the default binding for.
|
|
377
|
+
* @returns A binding configuration for the provided value.
|
|
378
|
+
* @public
|
|
379
|
+
*/
|
|
380
|
+
export function normalizeBinding(value) {
|
|
381
|
+
return isFunction(value)
|
|
382
|
+
? bind(value)
|
|
383
|
+
: value instanceof Binding
|
|
384
|
+
? value
|
|
385
|
+
: oneTime(() => value);
|
|
405
386
|
}
|