@telia-ace/widget-core 1.0.4 → 1.0.5
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/{lib-esm → dist}/action-resolver.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/actions-controller.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/changeset-provider.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-configuration-api.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-controller.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-node-collection.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-node.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-platform.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/component-query.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/create-component-model.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/custom-component-handler.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/descriptor.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/extend-component.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/index.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/queries.d.ts +0 -0
- package/{lib-esm → dist}/component-platform/state-processor.d.ts +0 -0
- package/{lib-esm → dist}/component-resolver.d.ts +0 -0
- package/{lib-esm → dist}/event-subscriber.d.ts +0 -0
- package/{lib-esm → dist}/index.d.ts +0 -0
- package/dist/index.js +1047 -0
- package/dist/index.js.map +1 -0
- package/{lib-esm → dist}/types/configuration.d.ts +0 -0
- package/{lib-esm → dist}/types/index.d.ts +0 -0
- package/{lib-esm → dist}/types/ui.d.ts +0 -0
- package/package.json +9 -9
- package/lib/action-resolver.d.ts +0 -8
- package/lib/action-resolver.js +0 -19
- package/lib/component-platform/actions-controller.d.ts +0 -40
- package/lib/component-platform/actions-controller.js +0 -119
- package/lib/component-platform/changeset-provider.d.ts +0 -8
- package/lib/component-platform/changeset-provider.js +0 -2
- package/lib/component-platform/component-configuration-api.d.ts +0 -2
- package/lib/component-platform/component-configuration-api.js +0 -32
- package/lib/component-platform/component-controller.d.ts +0 -38
- package/lib/component-platform/component-controller.js +0 -119
- package/lib/component-platform/component-node-collection.d.ts +0 -18
- package/lib/component-platform/component-node-collection.js +0 -51
- package/lib/component-platform/component-node.d.ts +0 -63
- package/lib/component-platform/component-node.js +0 -190
- package/lib/component-platform/component-platform.d.ts +0 -54
- package/lib/component-platform/component-platform.js +0 -220
- package/lib/component-platform/component-query.d.ts +0 -16
- package/lib/component-platform/component-query.js +0 -35
- package/lib/component-platform/create-component-model.d.ts +0 -36
- package/lib/component-platform/create-component-model.js +0 -141
- package/lib/component-platform/custom-component-handler.d.ts +0 -21
- package/lib/component-platform/custom-component-handler.js +0 -16
- package/lib/component-platform/descriptor.d.ts +0 -8
- package/lib/component-platform/descriptor.js +0 -12
- package/lib/component-platform/extend-component.d.ts +0 -8
- package/lib/component-platform/extend-component.js +0 -57
- package/lib/component-platform/index.d.ts +0 -18
- package/lib/component-platform/index.js +0 -30
- package/lib/component-platform/queries.d.ts +0 -6
- package/lib/component-platform/queries.js +0 -53
- package/lib/component-platform/state-processor.d.ts +0 -12
- package/lib/component-platform/state-processor.js +0 -209
- package/lib/component-resolver.d.ts +0 -14
- package/lib/component-resolver.js +0 -49
- package/lib/event-subscriber.d.ts +0 -7
- package/lib/event-subscriber.js +0 -22
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -41
- package/lib/types/configuration.d.ts +0 -86
- package/lib/types/configuration.js +0 -16
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -18
- package/lib/types/ui.d.ts +0 -54
- package/lib/types/ui.js +0 -2
- package/lib-esm/action-resolver.js +0 -17
- package/lib-esm/component-platform/actions-controller.js +0 -116
- package/lib-esm/component-platform/changeset-provider.js +0 -1
- package/lib-esm/component-platform/component-configuration-api.js +0 -30
- package/lib-esm/component-platform/component-controller.js +0 -116
- package/lib-esm/component-platform/component-node-collection.js +0 -48
- package/lib-esm/component-platform/component-node.js +0 -187
- package/lib-esm/component-platform/component-platform.js +0 -217
- package/lib-esm/component-platform/component-query.js +0 -32
- package/lib-esm/component-platform/create-component-model.js +0 -135
- package/lib-esm/component-platform/custom-component-handler.js +0 -13
- package/lib-esm/component-platform/descriptor.js +0 -8
- package/lib-esm/component-platform/extend-component.js +0 -53
- package/lib-esm/component-platform/index.js +0 -10
- package/lib-esm/component-platform/queries.js +0 -46
- package/lib-esm/component-platform/state-processor.js +0 -205
- package/lib-esm/component-resolver.js +0 -47
- package/lib-esm/event-subscriber.js +0 -18
- package/lib-esm/index.js +0 -5
- package/lib-esm/types/configuration.js +0 -13
- package/lib-esm/types/index.js +0 -2
- package/lib-esm/types/ui.js +0 -1
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { ComponentNodeController } from './component-controller';
|
|
13
|
-
var executeActionListeners = function (listeners, data, controller) {
|
|
14
|
-
var stack = listeners.concat();
|
|
15
|
-
var dispatch = function (data, globalOptions, controller) {
|
|
16
|
-
var cancelled = true;
|
|
17
|
-
if (stack.length) {
|
|
18
|
-
var handler = stack.shift();
|
|
19
|
-
var next = function (data, options) {
|
|
20
|
-
cancelled = false;
|
|
21
|
-
return dispatch(data, Object.assign({}, globalOptions, options), controller);
|
|
22
|
-
};
|
|
23
|
-
return Promise.resolve(handler(data, next, controller)).then(function (result) { return (__assign(__assign({}, result), { cancelled: cancelled })); });
|
|
24
|
-
}
|
|
25
|
-
return Promise.resolve({ data: data, cancelled: false, options: globalOptions });
|
|
26
|
-
};
|
|
27
|
-
return dispatch(data, {}, controller);
|
|
28
|
-
};
|
|
29
|
-
var ActionsController = /** @class */ (function () {
|
|
30
|
-
function ActionsController(platform, target, ns) {
|
|
31
|
-
this.platform = platform;
|
|
32
|
-
this.target = target;
|
|
33
|
-
this.ns = ns;
|
|
34
|
-
this.subscriptions = [];
|
|
35
|
-
this.create = this.create.bind(this);
|
|
36
|
-
}
|
|
37
|
-
ActionsController.prototype.create = function (key, fn) {
|
|
38
|
-
var _this = this;
|
|
39
|
-
if (fn === void 0) { fn = function () { }; }
|
|
40
|
-
var handler = {
|
|
41
|
-
key: key,
|
|
42
|
-
fn: fn,
|
|
43
|
-
target: this.target,
|
|
44
|
-
ns: this.ns,
|
|
45
|
-
};
|
|
46
|
-
this.platform.actionsState.handlers.push(handler);
|
|
47
|
-
var subscription = function () {
|
|
48
|
-
var index = _this.platform.actionsState.handlers.indexOf(handler);
|
|
49
|
-
if (index > -1) {
|
|
50
|
-
_this.platform.actionsState.handlers.splice(index, 1);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
this.subscriptions.push(subscription);
|
|
54
|
-
return subscription;
|
|
55
|
-
};
|
|
56
|
-
ActionsController.prototype.dispatch = function (key, data) {
|
|
57
|
-
var _this = this;
|
|
58
|
-
var instances = this.platform.nodes.all.concat(this.platform.nodes.detached);
|
|
59
|
-
var output = {};
|
|
60
|
-
// handlers matching the specified pattern.
|
|
61
|
-
var handlers = this.platform.actionsState.handlers.filter(function (handler) { return handler.key === key && (!handler.ns || !_this.ns || handler.ns === _this.ns); });
|
|
62
|
-
return Promise.all(handlers.map(function (handler) {
|
|
63
|
-
// select all matching instances for this particular
|
|
64
|
-
// handler (a handler can be mapped to many instances)
|
|
65
|
-
var matchedInstances = instances.filter(function (instance) { return handler.target.match(instance) && _this.target.match(instance); });
|
|
66
|
-
// execute watchers for each matched instance
|
|
67
|
-
var watchers = _this.platform.actionsState.watchers
|
|
68
|
-
.filter(function (watcher) {
|
|
69
|
-
return (watcher.key === key &&
|
|
70
|
-
(!watcher.ns || !_this.ns || watcher.ns === _this.ns) &&
|
|
71
|
-
matchedInstances.some(function (instance) { return watcher.target.match(instance); }));
|
|
72
|
-
})
|
|
73
|
-
.map(function (watcher) { return watcher.fn; });
|
|
74
|
-
// execute watchers and handler for each instance
|
|
75
|
-
return Promise.all(matchedInstances.map(function (node) {
|
|
76
|
-
var controller = new ComponentNodeController(_this.platform, node, _this.ns);
|
|
77
|
-
return executeActionListeners(watchers, data, controller).then(function (input) {
|
|
78
|
-
var _a = input.data, data = _a === void 0 ? {} : _a, options = input.options, cancelled = input.cancelled;
|
|
79
|
-
return Promise.resolve(cancelled ? {} : handler.fn(data, options, controller)).then(function (handlerResponse) {
|
|
80
|
-
output[node.id] = handlerResponse;
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}));
|
|
84
|
-
})).then(function () { return output; });
|
|
85
|
-
};
|
|
86
|
-
ActionsController.prototype.watch = function (key, fn) {
|
|
87
|
-
var _this = this;
|
|
88
|
-
var parsedKey = key;
|
|
89
|
-
var parsedNs = this.ns;
|
|
90
|
-
var sections = key.split('.');
|
|
91
|
-
if (sections.length > 1) {
|
|
92
|
-
parsedNs = sections[0];
|
|
93
|
-
parsedKey = sections.splice(1).join('.');
|
|
94
|
-
}
|
|
95
|
-
var watcher = {
|
|
96
|
-
fn: fn,
|
|
97
|
-
target: this.target,
|
|
98
|
-
key: parsedKey,
|
|
99
|
-
ns: parsedNs,
|
|
100
|
-
};
|
|
101
|
-
this.platform.actionsState.watchers.push(watcher);
|
|
102
|
-
var subscription = function () {
|
|
103
|
-
var index = _this.platform.actionsState.watchers.indexOf(watcher);
|
|
104
|
-
if (index > -1) {
|
|
105
|
-
_this.platform.actionsState.watchers.splice(index, 1);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
this.subscriptions.push(subscription);
|
|
109
|
-
return subscription;
|
|
110
|
-
};
|
|
111
|
-
ActionsController.prototype.dispose = function () {
|
|
112
|
-
this.subscriptions.forEach(function (unsubscribe) { return unsubscribe(); });
|
|
113
|
-
};
|
|
114
|
-
return ActionsController;
|
|
115
|
-
}());
|
|
116
|
-
export { ActionsController };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
import { createConfigurationApi } from '@webprovisions/platform';
|
|
18
|
-
export default createConfigurationApi(function (builder) {
|
|
19
|
-
builder.createCommand('components', function (context) { return function (config) {
|
|
20
|
-
context.events.subscribeOnce('components:platform-created', function (event, _a) {
|
|
21
|
-
var platform = _a.platform;
|
|
22
|
-
if (config.handlers) {
|
|
23
|
-
config.handlers.forEach(function (_a) {
|
|
24
|
-
var _b = __read(_a, 2), key = _b[0], handler = _b[1];
|
|
25
|
-
platform.addComponentHandler(key, handler);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}; });
|
|
30
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
import { createEventSubscriber } from '../event-subscriber';
|
|
18
|
-
import { ActionsController } from './actions-controller';
|
|
19
|
-
import { ComponentQuery } from './component-query';
|
|
20
|
-
var ComponentNodeController = /** @class */ (function () {
|
|
21
|
-
function ComponentNodeController(platform, node, ns) {
|
|
22
|
-
this.platform = platform;
|
|
23
|
-
this.node = node;
|
|
24
|
-
this.actions = new ActionsController(platform, new ComponentQuery(platform).withId(node.id), ns);
|
|
25
|
-
var _a = __read(createEventSubscriber(this.platform.events), 2), subscribe = _a[0], unsubscribe = _a[1];
|
|
26
|
-
this.subscribe = subscribe;
|
|
27
|
-
this.unsubscribe = unsubscribe;
|
|
28
|
-
}
|
|
29
|
-
ComponentNodeController.prototype.properties = function (updated) {
|
|
30
|
-
if (updated) {
|
|
31
|
-
this.node.touchProperties(function (properties) { return updated(properties); });
|
|
32
|
-
}
|
|
33
|
-
return this.node.attributes.properties;
|
|
34
|
-
};
|
|
35
|
-
ComponentNodeController.prototype.context = function (updated) {
|
|
36
|
-
var _this = this;
|
|
37
|
-
if (updated) {
|
|
38
|
-
this.subscribe('components:context-changed', function (event, _a) {
|
|
39
|
-
var node = _a.node;
|
|
40
|
-
if (node === _this.node) {
|
|
41
|
-
updated(_this.node.attributes.context);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return this.node.attributes.context;
|
|
46
|
-
};
|
|
47
|
-
ComponentNodeController.prototype.layout = function (updated) {
|
|
48
|
-
var _this = this;
|
|
49
|
-
if (updated) {
|
|
50
|
-
this.subscribe('components:layout-changed', function (event, _a) {
|
|
51
|
-
var node = _a.node;
|
|
52
|
-
if (node === _this.node) {
|
|
53
|
-
updated(_this.node.attributes.layout);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return this.node.attributes.layout;
|
|
58
|
-
};
|
|
59
|
-
ComponentNodeController.prototype.writeProperties = function (properties, options) {
|
|
60
|
-
this.node.writeProperties(properties, options);
|
|
61
|
-
};
|
|
62
|
-
ComponentNodeController.prototype.writeContext = function (context, options) {
|
|
63
|
-
this.node.writeProperties(context, options);
|
|
64
|
-
};
|
|
65
|
-
ComponentNodeController.prototype.writeLayout = function (layout, options) {
|
|
66
|
-
this.node.writeLayout(layout, options);
|
|
67
|
-
};
|
|
68
|
-
ComponentNodeController.prototype.dispose = function () {
|
|
69
|
-
this.unsubscribe();
|
|
70
|
-
this.actions.dispose();
|
|
71
|
-
};
|
|
72
|
-
return ComponentNodeController;
|
|
73
|
-
}());
|
|
74
|
-
export { ComponentNodeController };
|
|
75
|
-
var AbstractComponentController = /** @class */ (function () {
|
|
76
|
-
function AbstractComponentController(platform, target, clearOnDispose) {
|
|
77
|
-
if (clearOnDispose === void 0) { clearOnDispose = true; }
|
|
78
|
-
this.platform = platform;
|
|
79
|
-
this.target = target;
|
|
80
|
-
this.clearOnDispose = clearOnDispose;
|
|
81
|
-
this.removes = [];
|
|
82
|
-
this.actions = new ActionsController(this.platform, this.target);
|
|
83
|
-
}
|
|
84
|
-
AbstractComponentController.prototype.writeProperties = function (properties, options) {
|
|
85
|
-
this.removes.push(this.platform.write({
|
|
86
|
-
options: options,
|
|
87
|
-
attributes: { properties: properties },
|
|
88
|
-
target: this.target,
|
|
89
|
-
removable: this.clearOnDispose,
|
|
90
|
-
}));
|
|
91
|
-
};
|
|
92
|
-
AbstractComponentController.prototype.writeContext = function (context, options) {
|
|
93
|
-
this.removes.push(this.platform.write({
|
|
94
|
-
options: options,
|
|
95
|
-
attributes: { context: context },
|
|
96
|
-
target: this.target,
|
|
97
|
-
removable: this.clearOnDispose,
|
|
98
|
-
}));
|
|
99
|
-
};
|
|
100
|
-
AbstractComponentController.prototype.writeLayout = function (layout, options) {
|
|
101
|
-
this.removes.push(this.platform.write({
|
|
102
|
-
options: options,
|
|
103
|
-
attributes: { layout: layout },
|
|
104
|
-
target: this.target,
|
|
105
|
-
removable: this.clearOnDispose,
|
|
106
|
-
}));
|
|
107
|
-
};
|
|
108
|
-
AbstractComponentController.prototype.dispose = function () {
|
|
109
|
-
this.removes.forEach(function (remove) {
|
|
110
|
-
remove();
|
|
111
|
-
});
|
|
112
|
-
this.actions.dispose();
|
|
113
|
-
};
|
|
114
|
-
return AbstractComponentController;
|
|
115
|
-
}());
|
|
116
|
-
export { AbstractComponentController };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { findComponent, findVisibleComponents, traverseComponents } from './queries';
|
|
2
|
-
var ComponentNodeCollection = /** @class */ (function () {
|
|
3
|
-
function ComponentNodeCollection(root, switches, events) {
|
|
4
|
-
var _this = this;
|
|
5
|
-
this.root = root;
|
|
6
|
-
this.switches = switches;
|
|
7
|
-
this.all = [];
|
|
8
|
-
this.visible = [];
|
|
9
|
-
this.detached = [];
|
|
10
|
-
events.subscribe('components:node-appended', function (event, data) {
|
|
11
|
-
_this.all.push(data.node);
|
|
12
|
-
_this.visible = findVisibleComponents(root, switches);
|
|
13
|
-
});
|
|
14
|
-
events.subscribe('components:node-removed', function (event, data) {
|
|
15
|
-
var indexToRemove = _this.all.indexOf(data.node);
|
|
16
|
-
if (indexToRemove > -1) {
|
|
17
|
-
_this.all.splice(indexToRemove, 1);
|
|
18
|
-
}
|
|
19
|
-
indexToRemove = _this.visible.indexOf(data.node);
|
|
20
|
-
if (indexToRemove > -1) {
|
|
21
|
-
_this.visible.splice(indexToRemove, 1);
|
|
22
|
-
}
|
|
23
|
-
_this.visible = findVisibleComponents(root, switches);
|
|
24
|
-
});
|
|
25
|
-
events.subscribe('components:node-switched', function (event, data) {
|
|
26
|
-
_this.visible = findVisibleComponents(root, switches);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
ComponentNodeCollection.prototype.query = function (query) {
|
|
30
|
-
if (query === void 0) { query = {}; }
|
|
31
|
-
var nodes = [];
|
|
32
|
-
traverseComponents(this.root, this.switches, function (node) {
|
|
33
|
-
var match = Object.keys(query).every(function (member) {
|
|
34
|
-
return query[member] === node[member];
|
|
35
|
-
});
|
|
36
|
-
if (match) {
|
|
37
|
-
nodes.push(node);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return nodes;
|
|
41
|
-
};
|
|
42
|
-
ComponentNodeCollection.prototype.get = function (id) {
|
|
43
|
-
return (findComponent(this.root, this.switches, function (node) { return node.id === id; }) ||
|
|
44
|
-
this.detached.find(function (node) { return node.id === id; }));
|
|
45
|
-
};
|
|
46
|
-
return ComponentNodeCollection;
|
|
47
|
-
}());
|
|
48
|
-
export { ComponentNodeCollection };
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { Logger, uuid } from '@telia-ace/widget-utilities';
|
|
2
|
-
var ComponentNode = /** @class */ (function () {
|
|
3
|
-
function ComponentNode(events, type) {
|
|
4
|
-
this.events = events;
|
|
5
|
-
this.tags = [];
|
|
6
|
-
this.children = {};
|
|
7
|
-
this.changesets = [];
|
|
8
|
-
this.mountCount = 0;
|
|
9
|
-
this.id = uuid();
|
|
10
|
-
this.type = type;
|
|
11
|
-
this.attributes = {
|
|
12
|
-
context: {},
|
|
13
|
-
properties: {},
|
|
14
|
-
layout: {},
|
|
15
|
-
tags: [],
|
|
16
|
-
};
|
|
17
|
-
// write default attributes
|
|
18
|
-
this.writeLayout({ size: 'full', indent: 0 });
|
|
19
|
-
}
|
|
20
|
-
ComponentNode.prototype.mount = function (viewOutletContainer, element) {
|
|
21
|
-
var _this = this;
|
|
22
|
-
var mountedNodes = viewOutletContainer.get('mounted-nodes');
|
|
23
|
-
if (!mountedNodes) {
|
|
24
|
-
mountedNodes = new Map();
|
|
25
|
-
viewOutletContainer.register('mounted-nodes', mountedNodes);
|
|
26
|
-
}
|
|
27
|
-
if (mountedNodes.has(this)) {
|
|
28
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
-
Logger.error('Trying to mount an already mounted component node.', this);
|
|
30
|
-
}
|
|
31
|
-
return function () { };
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Dispatched when a node is mounted in a component.
|
|
35
|
-
* This happens once for every `ViewOutlet`.
|
|
36
|
-
*/
|
|
37
|
-
this.events.dispatch('components:node-mounted', { node: this });
|
|
38
|
-
if (this.mountCount === 0) {
|
|
39
|
-
this.mountCount = this.mountCount + 1;
|
|
40
|
-
/**
|
|
41
|
-
* Dispatched when a node is mounted in a component the first time.
|
|
42
|
-
*/
|
|
43
|
-
this.events.dispatch('components:node-enter', { node: this });
|
|
44
|
-
}
|
|
45
|
-
return function () {
|
|
46
|
-
mountedNodes.delete(_this);
|
|
47
|
-
_this.events.dispatch('components:node-unmounted', { node: _this });
|
|
48
|
-
_this.mountCount = _this.mountCount - 1;
|
|
49
|
-
if (_this.mountCount === 0) {
|
|
50
|
-
_this.events.dispatch('components:node-exit', { node: _this });
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
ComponentNode.prototype.appendChild = function (node, branch) {
|
|
55
|
-
if (branch === void 0) { branch = 'default'; }
|
|
56
|
-
if (node.parent) {
|
|
57
|
-
if (node.parent === this) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
node.parent.removeChild(node);
|
|
61
|
-
}
|
|
62
|
-
node.parent = this;
|
|
63
|
-
if (!this.children[branch]) {
|
|
64
|
-
this.children[branch] = [];
|
|
65
|
-
}
|
|
66
|
-
this.children[branch].push(node);
|
|
67
|
-
this.events.dispatch('components:node-appended', { node: node });
|
|
68
|
-
};
|
|
69
|
-
ComponentNode.prototype.prependChild = function (node, branch) {
|
|
70
|
-
if (branch === void 0) { branch = 'default'; }
|
|
71
|
-
if (node.parent) {
|
|
72
|
-
if (node.parent === this) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
node.parent.removeChild(node);
|
|
76
|
-
}
|
|
77
|
-
node.parent = this;
|
|
78
|
-
if (!this.children[branch]) {
|
|
79
|
-
this.children[branch] = [];
|
|
80
|
-
}
|
|
81
|
-
this.children[branch].unshift(node);
|
|
82
|
-
this.events.dispatch('components:node-appended', { node: node });
|
|
83
|
-
};
|
|
84
|
-
ComponentNode.prototype.touchProperties = function (properties, options, removable) {
|
|
85
|
-
var _this = this;
|
|
86
|
-
if (options === void 0) { options = {}; }
|
|
87
|
-
var attributes = { properties: properties };
|
|
88
|
-
var changeset = [attributes, options];
|
|
89
|
-
this.changesets.push(changeset);
|
|
90
|
-
this.events.dispatch('components:set-properties', { node: this });
|
|
91
|
-
return function () {
|
|
92
|
-
if (removable) {
|
|
93
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
94
|
-
if (indexToRemove > -1) {
|
|
95
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
96
|
-
_this.events.dispatch('components:set-properties', { node: _this });
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
ComponentNode.prototype.writeProperties = function (properties, options, removable) {
|
|
102
|
-
var _this = this;
|
|
103
|
-
if (options === void 0) { options = {}; }
|
|
104
|
-
var attributes = { properties: properties };
|
|
105
|
-
var changeset = [attributes, options];
|
|
106
|
-
this.changesets.push(changeset);
|
|
107
|
-
this.events.dispatch('components:set-properties', { node: this });
|
|
108
|
-
return function () {
|
|
109
|
-
if (removable) {
|
|
110
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
111
|
-
if (indexToRemove > -1) {
|
|
112
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
113
|
-
_this.events.dispatch('components:set-properties', { node: _this });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
ComponentNode.prototype.writeLayout = function (layout, options, removable) {
|
|
119
|
-
var _this = this;
|
|
120
|
-
if (options === void 0) { options = {}; }
|
|
121
|
-
var attributes = { layout: layout };
|
|
122
|
-
var changeset = [attributes, options];
|
|
123
|
-
this.changesets.push(changeset);
|
|
124
|
-
this.events.dispatch('components:set-layout', { node: this });
|
|
125
|
-
return function () {
|
|
126
|
-
if (!removable) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
130
|
-
if (indexToRemove > -1) {
|
|
131
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
132
|
-
_this.events.dispatch('components:set-layout', { node: _this });
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
ComponentNode.prototype.writeContext = function (context, options, removable) {
|
|
137
|
-
var _this = this;
|
|
138
|
-
if (options === void 0) { options = {}; }
|
|
139
|
-
var attributes = { context: context };
|
|
140
|
-
var changeset = [attributes, options];
|
|
141
|
-
this.changesets.push(changeset);
|
|
142
|
-
this.events.dispatch('components:set-context', { node: this });
|
|
143
|
-
return function () {
|
|
144
|
-
if (!removable) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
148
|
-
if (indexToRemove > -1) {
|
|
149
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
150
|
-
_this.events.dispatch('components:set-context', { node: _this });
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
ComponentNode.prototype.getChildren = function (branch) {
|
|
155
|
-
if (branch === void 0) { branch = 'default'; }
|
|
156
|
-
var children = this.children[branch] || [];
|
|
157
|
-
return children.reduce(function (acc, node, i) {
|
|
158
|
-
var _a = node.attributes.layout.order, index = _a === void 0 ? i : _a;
|
|
159
|
-
if (!acc[index]) {
|
|
160
|
-
acc[index] = node;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
acc.splice(index, 0, node);
|
|
164
|
-
}
|
|
165
|
-
return acc;
|
|
166
|
-
}, Array(children.length));
|
|
167
|
-
};
|
|
168
|
-
ComponentNode.prototype.remove = function () {
|
|
169
|
-
if (this.parent) {
|
|
170
|
-
this.parent.removeChild(this);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
ComponentNode.prototype.removeChild = function (node) {
|
|
174
|
-
var _this = this;
|
|
175
|
-
Object.keys(this.children).forEach(function (branch) {
|
|
176
|
-
var children = _this.children[branch];
|
|
177
|
-
var indexToRemove = children.indexOf(node);
|
|
178
|
-
if (indexToRemove > -1) {
|
|
179
|
-
children.splice(indexToRemove, 1);
|
|
180
|
-
_this.events.dispatch('components:node-removed', { node: node, parentNode: _this });
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
delete node.parent;
|
|
184
|
-
};
|
|
185
|
-
return ComponentNode;
|
|
186
|
-
}());
|
|
187
|
-
export { ComponentNode };
|