@telia-ace/widget-core 1.0.1 → 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/LICENSE.txt +5 -5
- package/README.md +3 -3
- 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/dist/component-platform/component-configuration-api.d.ts +2 -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 → dist}/component-platform/component-platform.d.ts +4 -0
- package/{lib-esm → dist}/component-platform/component-query.d.ts +0 -0
- package/dist/component-platform/create-component-model.d.ts +36 -0
- package/dist/component-platform/custom-component-handler.d.ts +21 -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 → dist}/component-platform/index.d.ts +3 -1
- 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/dist/index.d.ts +8 -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 -1
- 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-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.js +0 -209
- 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 -19
- package/lib/component-platform/create-component-model.js +0 -126
- 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.js +0 -24
- 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 -39
- 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 -55
- 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-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.d.ts +0 -50
- package/lib-esm/component-platform/component-platform.js +0 -206
- package/lib-esm/component-platform/component-query.js +0 -32
- package/lib-esm/component-platform/create-component-model.d.ts +0 -19
- package/lib-esm/component-platform/create-component-model.js +0 -121
- 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.d.ts +0 -16
- package/lib-esm/component-platform/index.js +0 -9
- 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.d.ts +0 -8
- 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,18 +0,0 @@
|
|
|
1
|
-
import { EventManager } from '@webprovisions/platform';
|
|
2
|
-
import { ComponentNode } from './component-node';
|
|
3
|
-
import { SwitchMap } from './component-platform';
|
|
4
|
-
export declare type QueryDescriptor = {
|
|
5
|
-
id?: string;
|
|
6
|
-
type?: string;
|
|
7
|
-
name?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class ComponentNodeCollection {
|
|
10
|
-
root: ComponentNode;
|
|
11
|
-
private switches;
|
|
12
|
-
all: ComponentNode[];
|
|
13
|
-
visible: ComponentNode[];
|
|
14
|
-
detached: ComponentNode[];
|
|
15
|
-
constructor(root: ComponentNode, switches: SwitchMap, events: EventManager);
|
|
16
|
-
query(query?: QueryDescriptor): ComponentNode[];
|
|
17
|
-
get(id: string): ComponentNode | undefined;
|
|
18
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentNodeCollection = void 0;
|
|
4
|
-
var queries_1 = require("./queries");
|
|
5
|
-
var ComponentNodeCollection = /** @class */ (function () {
|
|
6
|
-
function ComponentNodeCollection(root, switches, events) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
this.root = root;
|
|
9
|
-
this.switches = switches;
|
|
10
|
-
this.all = [];
|
|
11
|
-
this.visible = [];
|
|
12
|
-
this.detached = [];
|
|
13
|
-
events.subscribe('components:node-appended', function (event, data) {
|
|
14
|
-
_this.all.push(data.node);
|
|
15
|
-
_this.visible = (0, queries_1.findVisibleComponents)(root, switches);
|
|
16
|
-
});
|
|
17
|
-
events.subscribe('components:node-removed', function (event, data) {
|
|
18
|
-
var indexToRemove = _this.all.indexOf(data.node);
|
|
19
|
-
if (indexToRemove > -1) {
|
|
20
|
-
_this.all.splice(indexToRemove, 1);
|
|
21
|
-
}
|
|
22
|
-
indexToRemove = _this.visible.indexOf(data.node);
|
|
23
|
-
if (indexToRemove > -1) {
|
|
24
|
-
_this.visible.splice(indexToRemove, 1);
|
|
25
|
-
}
|
|
26
|
-
_this.visible = (0, queries_1.findVisibleComponents)(root, switches);
|
|
27
|
-
});
|
|
28
|
-
events.subscribe('components:node-switched', function (event, data) {
|
|
29
|
-
_this.visible = (0, queries_1.findVisibleComponents)(root, switches);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
ComponentNodeCollection.prototype.query = function (query) {
|
|
33
|
-
if (query === void 0) { query = {}; }
|
|
34
|
-
var nodes = [];
|
|
35
|
-
(0, queries_1.traverseComponents)(this.root, this.switches, function (node) {
|
|
36
|
-
var match = Object.keys(query).every(function (member) {
|
|
37
|
-
return query[member] === node[member];
|
|
38
|
-
});
|
|
39
|
-
if (match) {
|
|
40
|
-
nodes.push(node);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
return nodes;
|
|
44
|
-
};
|
|
45
|
-
ComponentNodeCollection.prototype.get = function (id) {
|
|
46
|
-
return ((0, queries_1.findComponent)(this.root, this.switches, function (node) { return node.id === id; }) ||
|
|
47
|
-
this.detached.find(function (node) { return node.id === id; }));
|
|
48
|
-
};
|
|
49
|
-
return ComponentNodeCollection;
|
|
50
|
-
}());
|
|
51
|
-
exports.ComponentNodeCollection = ComponentNodeCollection;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Container, EventManager } from '@webprovisions/platform';
|
|
2
|
-
import { Breakpoints } from '../types';
|
|
3
|
-
export declare type ComponentNodeEventData = {
|
|
4
|
-
node: ComponentNode;
|
|
5
|
-
};
|
|
6
|
-
export declare type RemoveChangeset = () => void;
|
|
7
|
-
export declare type ComponentNodeAttributes = {
|
|
8
|
-
tags: string[];
|
|
9
|
-
properties: ComponentNodeProperties;
|
|
10
|
-
context: ComponentNodeContext;
|
|
11
|
-
layout: ComponentNodeLayout;
|
|
12
|
-
};
|
|
13
|
-
export declare type ResolveComponentNodeProperties = (properties: ComponentNodeProperties) => Partial<ComponentNodeProperties> | void;
|
|
14
|
-
export declare type ResolveComponentNodeContext = (context: ComponentNodeContext) => Partial<ComponentNodeContext>;
|
|
15
|
-
export declare type ResolveComponentNodeLayout = (layout: ComponentNodeLayout) => Partial<ComponentNodeLayout>;
|
|
16
|
-
export declare type ComponentNodeSettings = {
|
|
17
|
-
tags?: string[];
|
|
18
|
-
properties?: ComponentNodeProperties | ResolveComponentNodeProperties;
|
|
19
|
-
context?: ComponentNodeContext | ResolveComponentNodeContext;
|
|
20
|
-
layout?: ComponentNodeLayout | ResolveComponentNodeLayout;
|
|
21
|
-
};
|
|
22
|
-
export declare type ComponentNodeProperties = {
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
25
|
-
export declare type ComponentNodeContext = {
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
};
|
|
28
|
-
export declare type ComponentNodeLayout = {
|
|
29
|
-
size?: Size;
|
|
30
|
-
indent?: number;
|
|
31
|
-
order?: number;
|
|
32
|
-
};
|
|
33
|
-
export declare type Size = number | 'full' | 'none';
|
|
34
|
-
export declare type UnmountComponentNode = () => void;
|
|
35
|
-
export declare type ChangesetOptions = {
|
|
36
|
-
breakpoints?: Breakpoints;
|
|
37
|
-
};
|
|
38
|
-
export declare type Changeset = [Partial<ComponentNodeSettings>, ChangesetOptions];
|
|
39
|
-
export declare class ComponentNode {
|
|
40
|
-
private events;
|
|
41
|
-
id: string;
|
|
42
|
-
type: string;
|
|
43
|
-
name?: string;
|
|
44
|
-
parent?: ComponentNode;
|
|
45
|
-
tags: string[];
|
|
46
|
-
children: {
|
|
47
|
-
[key: string]: ComponentNode[];
|
|
48
|
-
};
|
|
49
|
-
changesets: Changeset[];
|
|
50
|
-
attributes: ComponentNodeAttributes;
|
|
51
|
-
private mountCount;
|
|
52
|
-
constructor(events: EventManager, type: string);
|
|
53
|
-
mount(viewOutletContainer: Container, element?: HTMLElement): UnmountComponentNode;
|
|
54
|
-
appendChild(node: ComponentNode, branch?: string): void;
|
|
55
|
-
prependChild(node: ComponentNode, branch?: string): void;
|
|
56
|
-
touchProperties(properties: ResolveComponentNodeProperties, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
57
|
-
writeProperties(properties: Partial<ComponentNodeProperties> | ResolveComponentNodeProperties, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
58
|
-
writeLayout(layout: Partial<ComponentNodeLayout> | ResolveComponentNodeLayout, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
59
|
-
writeContext(context: Partial<ComponentNodeContext> | ResolveComponentNodeContext, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
60
|
-
getChildren(branch?: string): ComponentNode[];
|
|
61
|
-
remove(): void;
|
|
62
|
-
removeChild(node: ComponentNode): void;
|
|
63
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentNode = void 0;
|
|
4
|
-
var widget_utilities_1 = require("@telia-ace/widget-utilities");
|
|
5
|
-
var ComponentNode = /** @class */ (function () {
|
|
6
|
-
function ComponentNode(events, type) {
|
|
7
|
-
this.events = events;
|
|
8
|
-
this.tags = [];
|
|
9
|
-
this.children = {};
|
|
10
|
-
this.changesets = [];
|
|
11
|
-
this.mountCount = 0;
|
|
12
|
-
this.id = (0, widget_utilities_1.uuid)();
|
|
13
|
-
this.type = type;
|
|
14
|
-
this.attributes = {
|
|
15
|
-
context: {},
|
|
16
|
-
properties: {},
|
|
17
|
-
layout: {},
|
|
18
|
-
tags: [],
|
|
19
|
-
};
|
|
20
|
-
// write default attributes
|
|
21
|
-
this.writeLayout({ size: 'full', indent: 0 });
|
|
22
|
-
}
|
|
23
|
-
ComponentNode.prototype.mount = function (viewOutletContainer, element) {
|
|
24
|
-
var _this = this;
|
|
25
|
-
var mountedNodes = viewOutletContainer.get('mounted-nodes');
|
|
26
|
-
if (!mountedNodes) {
|
|
27
|
-
mountedNodes = new Map();
|
|
28
|
-
viewOutletContainer.register('mounted-nodes', mountedNodes);
|
|
29
|
-
}
|
|
30
|
-
if (mountedNodes.has(this)) {
|
|
31
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
32
|
-
widget_utilities_1.Logger.error('Trying to mount an already mounted component node.', this);
|
|
33
|
-
}
|
|
34
|
-
return function () { };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Dispatched when a node is mounted in a component.
|
|
38
|
-
* This happens once for every `ViewOutlet`.
|
|
39
|
-
*/
|
|
40
|
-
this.events.dispatch('components:node-mounted', { node: this });
|
|
41
|
-
if (this.mountCount === 0) {
|
|
42
|
-
this.mountCount = this.mountCount + 1;
|
|
43
|
-
/**
|
|
44
|
-
* Dispatched when a node is mounted in a component the first time.
|
|
45
|
-
*/
|
|
46
|
-
this.events.dispatch('components:node-enter', { node: this });
|
|
47
|
-
}
|
|
48
|
-
return function () {
|
|
49
|
-
mountedNodes.delete(_this);
|
|
50
|
-
_this.events.dispatch('components:node-unmounted', { node: _this });
|
|
51
|
-
_this.mountCount = _this.mountCount - 1;
|
|
52
|
-
if (_this.mountCount === 0) {
|
|
53
|
-
_this.events.dispatch('components:node-exit', { node: _this });
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
ComponentNode.prototype.appendChild = function (node, branch) {
|
|
58
|
-
if (branch === void 0) { branch = 'default'; }
|
|
59
|
-
if (node.parent) {
|
|
60
|
-
if (node.parent === this) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
node.parent.removeChild(node);
|
|
64
|
-
}
|
|
65
|
-
node.parent = this;
|
|
66
|
-
if (!this.children[branch]) {
|
|
67
|
-
this.children[branch] = [];
|
|
68
|
-
}
|
|
69
|
-
this.children[branch].push(node);
|
|
70
|
-
this.events.dispatch('components:node-appended', { node: node });
|
|
71
|
-
};
|
|
72
|
-
ComponentNode.prototype.prependChild = function (node, branch) {
|
|
73
|
-
if (branch === void 0) { branch = 'default'; }
|
|
74
|
-
if (node.parent) {
|
|
75
|
-
if (node.parent === this) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
node.parent.removeChild(node);
|
|
79
|
-
}
|
|
80
|
-
node.parent = this;
|
|
81
|
-
if (!this.children[branch]) {
|
|
82
|
-
this.children[branch] = [];
|
|
83
|
-
}
|
|
84
|
-
this.children[branch].unshift(node);
|
|
85
|
-
this.events.dispatch('components:node-appended', { node: node });
|
|
86
|
-
};
|
|
87
|
-
ComponentNode.prototype.touchProperties = function (properties, options, removable) {
|
|
88
|
-
var _this = this;
|
|
89
|
-
if (options === void 0) { options = {}; }
|
|
90
|
-
var attributes = { properties: properties };
|
|
91
|
-
var changeset = [attributes, options];
|
|
92
|
-
this.changesets.push(changeset);
|
|
93
|
-
this.events.dispatch('components:set-properties', { node: this });
|
|
94
|
-
return function () {
|
|
95
|
-
if (removable) {
|
|
96
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
97
|
-
if (indexToRemove > -1) {
|
|
98
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
99
|
-
_this.events.dispatch('components:set-properties', { node: _this });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
ComponentNode.prototype.writeProperties = function (properties, options, removable) {
|
|
105
|
-
var _this = this;
|
|
106
|
-
if (options === void 0) { options = {}; }
|
|
107
|
-
var attributes = { properties: properties };
|
|
108
|
-
var changeset = [attributes, options];
|
|
109
|
-
this.changesets.push(changeset);
|
|
110
|
-
this.events.dispatch('components:set-properties', { node: this });
|
|
111
|
-
return function () {
|
|
112
|
-
if (removable) {
|
|
113
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
114
|
-
if (indexToRemove > -1) {
|
|
115
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
116
|
-
_this.events.dispatch('components:set-properties', { node: _this });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
ComponentNode.prototype.writeLayout = function (layout, options, removable) {
|
|
122
|
-
var _this = this;
|
|
123
|
-
if (options === void 0) { options = {}; }
|
|
124
|
-
var attributes = { layout: layout };
|
|
125
|
-
var changeset = [attributes, options];
|
|
126
|
-
this.changesets.push(changeset);
|
|
127
|
-
this.events.dispatch('components:set-layout', { node: this });
|
|
128
|
-
return function () {
|
|
129
|
-
if (!removable) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
133
|
-
if (indexToRemove > -1) {
|
|
134
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
135
|
-
_this.events.dispatch('components:set-layout', { node: _this });
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
ComponentNode.prototype.writeContext = function (context, options, removable) {
|
|
140
|
-
var _this = this;
|
|
141
|
-
if (options === void 0) { options = {}; }
|
|
142
|
-
var attributes = { context: context };
|
|
143
|
-
var changeset = [attributes, options];
|
|
144
|
-
this.changesets.push(changeset);
|
|
145
|
-
this.events.dispatch('components:set-context', { node: this });
|
|
146
|
-
return function () {
|
|
147
|
-
if (!removable) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
var indexToRemove = _this.changesets.indexOf(changeset);
|
|
151
|
-
if (indexToRemove > -1) {
|
|
152
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
153
|
-
_this.events.dispatch('components:set-context', { node: _this });
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
ComponentNode.prototype.getChildren = function (branch) {
|
|
158
|
-
if (branch === void 0) { branch = 'default'; }
|
|
159
|
-
var children = this.children[branch] || [];
|
|
160
|
-
return children.reduce(function (acc, node, i) {
|
|
161
|
-
var _a = node.attributes.layout.order, index = _a === void 0 ? i : _a;
|
|
162
|
-
if (!acc[index]) {
|
|
163
|
-
acc[index] = node;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
acc.splice(index, 0, node);
|
|
167
|
-
}
|
|
168
|
-
return acc;
|
|
169
|
-
}, Array(children.length));
|
|
170
|
-
};
|
|
171
|
-
ComponentNode.prototype.remove = function () {
|
|
172
|
-
if (this.parent) {
|
|
173
|
-
this.parent.removeChild(this);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
ComponentNode.prototype.removeChild = function (node) {
|
|
177
|
-
var _this = this;
|
|
178
|
-
Object.keys(this.children).forEach(function (branch) {
|
|
179
|
-
var children = _this.children[branch];
|
|
180
|
-
var indexToRemove = children.indexOf(node);
|
|
181
|
-
if (indexToRemove > -1) {
|
|
182
|
-
children.splice(indexToRemove, 1);
|
|
183
|
-
_this.events.dispatch('components:node-removed', { node: node, parentNode: _this });
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
delete node.parent;
|
|
187
|
-
};
|
|
188
|
-
return ComponentNode;
|
|
189
|
-
}());
|
|
190
|
-
exports.ComponentNode = ComponentNode;
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.ComponentPlatform = void 0;
|
|
20
|
-
var widget_utilities_1 = require("@telia-ace/widget-utilities");
|
|
21
|
-
var actions_controller_1 = require("./actions-controller");
|
|
22
|
-
var component_node_1 = require("./component-node");
|
|
23
|
-
var component_node_collection_1 = require("./component-node-collection");
|
|
24
|
-
var component_query_1 = require("./component-query");
|
|
25
|
-
var state_processor_1 = require("./state-processor");
|
|
26
|
-
var ComponentPlatform = /** @class */ (function () {
|
|
27
|
-
function ComponentPlatform(widget, providers) {
|
|
28
|
-
if (providers === void 0) { providers = {}; }
|
|
29
|
-
var _this = this;
|
|
30
|
-
this.providers = providers;
|
|
31
|
-
this.breakpoints = [];
|
|
32
|
-
// internal
|
|
33
|
-
this.actionsState = { handlers: [], watchers: [] };
|
|
34
|
-
this.switches = {};
|
|
35
|
-
this.changesets = [];
|
|
36
|
-
this.subscriptions = [];
|
|
37
|
-
this.events = widget.events.createChild(this);
|
|
38
|
-
var root = new component_node_1.ComponentNode(this.events, 'root');
|
|
39
|
-
root.name = "root-".concat(widget.name);
|
|
40
|
-
this.nodes = new component_node_collection_1.ComponentNodeCollection(root, this.switches, this.events);
|
|
41
|
-
var processNode = (this.processNode = (0, state_processor_1.createStateProcessor)(this, function (report) {
|
|
42
|
-
var nodes = Array.from(report.keys());
|
|
43
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
-
console.info("STATE PROCESSOR: ".concat(nodes.length, " node(s) processed:\n").concat(nodes.map(function (node) { return "".concat(node.name || '<no name>', " (").concat(node.id, ")\n"); })));
|
|
45
|
-
}
|
|
46
|
-
nodes.forEach(function (node) {
|
|
47
|
-
var options = report.get(node);
|
|
48
|
-
if (node.parent && node.parent.type === 'root') {
|
|
49
|
-
_this.events.dispatch('components:root-children-changed', { node: node });
|
|
50
|
-
}
|
|
51
|
-
if (options === null || options === void 0 ? void 0 : options.context) {
|
|
52
|
-
_this.events.dispatch('components:context-changed', { node: node });
|
|
53
|
-
}
|
|
54
|
-
if (options === null || options === void 0 ? void 0 : options.properties) {
|
|
55
|
-
_this.events.dispatch('components:properties-changed', { node: node });
|
|
56
|
-
}
|
|
57
|
-
if (options === null || options === void 0 ? void 0 : options.layout) {
|
|
58
|
-
_this.events.dispatch('components:layout-changed', { node: node });
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
_this.events.dispatch('components:component-model-initialized', {}, { bubbles: true });
|
|
62
|
-
}));
|
|
63
|
-
Promise.all(Object.keys(providers).map(function (key) {
|
|
64
|
-
var provider = providers[key];
|
|
65
|
-
return provider.load(_this);
|
|
66
|
-
}));
|
|
67
|
-
this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
|
|
68
|
-
var node = data.node;
|
|
69
|
-
_this.changesets.forEach(function (record) {
|
|
70
|
-
var changeset = record.changeset, target = record.target, removes = record.removes;
|
|
71
|
-
var _a = __read(changeset, 2), change = _a[0], options = _a[1];
|
|
72
|
-
if (target.match(data.node)) {
|
|
73
|
-
if (change.properties) {
|
|
74
|
-
removes.push(node.writeProperties(change.properties, options));
|
|
75
|
-
}
|
|
76
|
-
if (change.context) {
|
|
77
|
-
removes.push(node.writeContext(change.context, options));
|
|
78
|
-
}
|
|
79
|
-
if (change.layout) {
|
|
80
|
-
removes.push(node.writeLayout(change.layout, options));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}));
|
|
85
|
-
this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
|
|
86
|
-
processNode(data.node, { properties: true, context: true });
|
|
87
|
-
}));
|
|
88
|
-
this.subscriptions.push(this.events.subscribe('components:set-properties', function (event, data) {
|
|
89
|
-
processNode(data.node, { properties: true });
|
|
90
|
-
}));
|
|
91
|
-
this.subscriptions.push(this.events.subscribe('components:set-context', function (event, data) {
|
|
92
|
-
processNode(data.node, { properties: true, context: true });
|
|
93
|
-
}));
|
|
94
|
-
this.subscriptions.push(this.events.subscribe('components:set-indent', function (event, data) {
|
|
95
|
-
processNode(data.node, { layout: true });
|
|
96
|
-
}));
|
|
97
|
-
this.subscriptions.push(this.events.subscribe('components:set-layout', function (event, data) {
|
|
98
|
-
processNode(data.node, { layout: true });
|
|
99
|
-
}));
|
|
100
|
-
this.subscriptions.push(this.events.subscribe('components:node-switched', function (event, _a) {
|
|
101
|
-
var node = _a.node, branch = _a.branch;
|
|
102
|
-
processNode(node, {
|
|
103
|
-
layout: true,
|
|
104
|
-
recursive: true,
|
|
105
|
-
properties: true,
|
|
106
|
-
context: true,
|
|
107
|
-
});
|
|
108
|
-
}));
|
|
109
|
-
this.subscriptions.push(this.events.subscribe('components:node-removed', function (event, _a) {
|
|
110
|
-
var parentNode = _a.parentNode;
|
|
111
|
-
processNode(parentNode, { properties: true });
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
114
|
-
ComponentPlatform.getInstance = function (container) {
|
|
115
|
-
return container.getAsync('components');
|
|
116
|
-
};
|
|
117
|
-
ComponentPlatform.prototype.addBreakpoint = function (name) {
|
|
118
|
-
if (this.breakpoints.indexOf(name) === -1) {
|
|
119
|
-
this.breakpoints.push(name);
|
|
120
|
-
this.processNode(this.nodes.root, {
|
|
121
|
-
context: true,
|
|
122
|
-
properties: true,
|
|
123
|
-
layout: true,
|
|
124
|
-
recursive: true,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
ComponentPlatform.prototype.removeBreakpoint = function (name) {
|
|
129
|
-
var indexToRemove = this.breakpoints.indexOf(name);
|
|
130
|
-
if (indexToRemove > -1) {
|
|
131
|
-
this.breakpoints.splice(indexToRemove, 1);
|
|
132
|
-
this.processNode(this.nodes.root, {
|
|
133
|
-
context: true,
|
|
134
|
-
properties: true,
|
|
135
|
-
layout: true,
|
|
136
|
-
recursive: true,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
ComponentPlatform.prototype.setSwitch = function (node, branch) {
|
|
141
|
-
this.switches[node.id] = branch;
|
|
142
|
-
this.events.dispatch('components:node-switched', { node: node, branch: branch });
|
|
143
|
-
};
|
|
144
|
-
ComponentPlatform.prototype.getBranch = function (node) {
|
|
145
|
-
return this.switches[node.id];
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Creates a `ComponentNode` of the specified type.
|
|
149
|
-
* @param type Type of node.
|
|
150
|
-
*/
|
|
151
|
-
ComponentPlatform.prototype.createNode = function (type, options) {
|
|
152
|
-
if (options === void 0) { options = {}; }
|
|
153
|
-
var node = new component_node_1.ComponentNode(this.events, type);
|
|
154
|
-
if (options.detached) {
|
|
155
|
-
this.nodes.detached.push(node);
|
|
156
|
-
}
|
|
157
|
-
return node;
|
|
158
|
-
};
|
|
159
|
-
ComponentPlatform.prototype.components = function () {
|
|
160
|
-
return new component_query_1.ComponentQuery(this);
|
|
161
|
-
};
|
|
162
|
-
ComponentPlatform.prototype.actions = function (target, ns) {
|
|
163
|
-
return new actions_controller_1.ActionsController(this, target, ns);
|
|
164
|
-
};
|
|
165
|
-
ComponentPlatform.prototype.write = function (data) {
|
|
166
|
-
var _this = this;
|
|
167
|
-
var providerName = data.provider, target = data.target, attributes = data.attributes, _a = data.options, options = _a === void 0 ? {} : _a, removable = data.removable;
|
|
168
|
-
var key = data.key || (0, widget_utilities_1.uuid)();
|
|
169
|
-
var changeset = [attributes, options];
|
|
170
|
-
var record = { changeset: changeset, target: target, removes: [] };
|
|
171
|
-
if (providerName) {
|
|
172
|
-
var provider_1 = this.providers[providerName];
|
|
173
|
-
provider_1.write(key, target, attributes, options);
|
|
174
|
-
record.removes.push(function () {
|
|
175
|
-
provider_1.remove(key);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
this.changesets.push(record);
|
|
179
|
-
this.nodes.all.forEach(function (node) {
|
|
180
|
-
if (target.match(node)) {
|
|
181
|
-
var remove = function () { };
|
|
182
|
-
if (attributes.properties) {
|
|
183
|
-
remove = node.writeProperties(attributes.properties, options, removable);
|
|
184
|
-
}
|
|
185
|
-
if (attributes.context) {
|
|
186
|
-
remove = node.writeContext(attributes.context, options, removable);
|
|
187
|
-
}
|
|
188
|
-
if (attributes.layout) {
|
|
189
|
-
remove = node.writeContext(attributes.layout, options, removable);
|
|
190
|
-
}
|
|
191
|
-
record.removes.push(remove);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return function () {
|
|
195
|
-
if (removable) {
|
|
196
|
-
record.removes.forEach(function (remove) { return remove(); });
|
|
197
|
-
var indexToRemove = _this.changesets.indexOf(record);
|
|
198
|
-
if (indexToRemove > -1) {
|
|
199
|
-
_this.changesets.splice(indexToRemove, 1);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
ComponentPlatform.prototype.dispose = function () {
|
|
205
|
-
this.subscriptions.forEach(function (sub) { return sub(); });
|
|
206
|
-
};
|
|
207
|
-
return ComponentPlatform;
|
|
208
|
-
}());
|
|
209
|
-
exports.ComponentPlatform = ComponentPlatform;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AbstractComponentController } from './component-controller';
|
|
2
|
-
import { ComponentNode } from './component-node';
|
|
3
|
-
import { ComponentPlatform } from './component-platform';
|
|
4
|
-
export declare type ComponentQueryRule = {
|
|
5
|
-
id?: string;
|
|
6
|
-
type?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare class ComponentQuery {
|
|
9
|
-
private platform;
|
|
10
|
-
rules: ComponentQueryRule[];
|
|
11
|
-
constructor(platform: ComponentPlatform, rules?: ComponentQueryRule[]);
|
|
12
|
-
match(node: ComponentNode): boolean;
|
|
13
|
-
ofType(type: string): ComponentQuery;
|
|
14
|
-
withId(id: string): ComponentQuery;
|
|
15
|
-
select(): AbstractComponentController;
|
|
16
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentQuery = void 0;
|
|
4
|
-
var component_controller_1 = require("./component-controller");
|
|
5
|
-
var ComponentQuery = /** @class */ (function () {
|
|
6
|
-
function ComponentQuery(platform, rules) {
|
|
7
|
-
if (rules === void 0) { rules = []; }
|
|
8
|
-
this.platform = platform;
|
|
9
|
-
this.rules = rules;
|
|
10
|
-
}
|
|
11
|
-
ComponentQuery.prototype.match = function (node) {
|
|
12
|
-
return this.rules.every(function (rule) {
|
|
13
|
-
if (rule.id && rule.id !== node.id) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (rule.type && rule.type !== node.type) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
ComponentQuery.prototype.ofType = function (type) {
|
|
23
|
-
this.rules.push({ type: type });
|
|
24
|
-
return this;
|
|
25
|
-
};
|
|
26
|
-
ComponentQuery.prototype.withId = function (id) {
|
|
27
|
-
this.rules.push({ id: id });
|
|
28
|
-
return this;
|
|
29
|
-
};
|
|
30
|
-
ComponentQuery.prototype.select = function () {
|
|
31
|
-
return new component_controller_1.AbstractComponentController(this.platform, this);
|
|
32
|
-
};
|
|
33
|
-
return ComponentQuery;
|
|
34
|
-
}());
|
|
35
|
-
exports.ComponentQuery = ComponentQuery;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
2
|
-
import { Breakpoints, WidgetSettings } from '../types';
|
|
3
|
-
import { ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
|
|
4
|
-
import { ComponentPlatform } from './component-platform';
|
|
5
|
-
declare type ComponentReference = string | [string, ...ComponentReferenceOverride[]];
|
|
6
|
-
declare type ComponentReferenceOverride = {
|
|
7
|
-
breakpoints?: Breakpoints;
|
|
8
|
-
tags?: string[];
|
|
9
|
-
context?: ComponentNodeContext;
|
|
10
|
-
properties?: ComponentNodeProperties;
|
|
11
|
-
layout?: ComponentNodeLayout;
|
|
12
|
-
};
|
|
13
|
-
declare type NormalizedComponentReference = {
|
|
14
|
-
definitionId: string;
|
|
15
|
-
overrides: ComponentReferenceOverride[];
|
|
16
|
-
};
|
|
17
|
-
export declare const normalizeReference: (reference: ComponentReference) => NormalizedComponentReference;
|
|
18
|
-
export declare const createComponentModel: (platform: ComponentPlatform, settings: WidgetSettings) => EventSubscriptionCancellation;
|
|
19
|
-
export {};
|