@telia-ace/widget-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +3 -0
  3. package/lib/action-resolver.d.ts +8 -0
  4. package/lib/action-resolver.js +19 -0
  5. package/lib/component-platform/actions-controller.d.ts +40 -0
  6. package/lib/component-platform/actions-controller.js +119 -0
  7. package/lib/component-platform/changeset-provider.d.ts +8 -0
  8. package/lib/component-platform/changeset-provider.js +2 -0
  9. package/lib/component-platform/component-controller.d.ts +38 -0
  10. package/lib/component-platform/component-controller.js +119 -0
  11. package/lib/component-platform/component-node-collection.d.ts +18 -0
  12. package/lib/component-platform/component-node-collection.js +51 -0
  13. package/lib/component-platform/component-node.d.ts +63 -0
  14. package/lib/component-platform/component-node.js +190 -0
  15. package/lib/component-platform/component-platform.d.ts +50 -0
  16. package/lib/component-platform/component-platform.js +209 -0
  17. package/lib/component-platform/component-query.d.ts +16 -0
  18. package/lib/component-platform/component-query.js +35 -0
  19. package/lib/component-platform/create-component-model.d.ts +19 -0
  20. package/lib/component-platform/create-component-model.js +126 -0
  21. package/lib/component-platform/descriptor.d.ts +8 -0
  22. package/lib/component-platform/descriptor.js +12 -0
  23. package/lib/component-platform/extend-component.d.ts +8 -0
  24. package/lib/component-platform/extend-component.js +57 -0
  25. package/lib/component-platform/index.d.ts +16 -0
  26. package/lib/component-platform/index.js +24 -0
  27. package/lib/component-platform/queries.d.ts +6 -0
  28. package/lib/component-platform/queries.js +53 -0
  29. package/lib/component-platform/state-processor.d.ts +12 -0
  30. package/lib/component-platform/state-processor.js +209 -0
  31. package/lib/component-resolver.d.ts +14 -0
  32. package/lib/component-resolver.js +49 -0
  33. package/lib/event-subscriber.d.ts +7 -0
  34. package/lib/event-subscriber.js +22 -0
  35. package/lib/index.d.ts +8 -0
  36. package/lib/index.js +39 -0
  37. package/lib/types/configuration.d.ts +86 -0
  38. package/lib/types/configuration.js +16 -0
  39. package/lib/types/index.d.ts +2 -0
  40. package/lib/types/index.js +18 -0
  41. package/lib/types/ui.d.ts +55 -0
  42. package/lib/types/ui.js +2 -0
  43. package/lib-esm/action-resolver.d.ts +8 -0
  44. package/lib-esm/action-resolver.js +17 -0
  45. package/lib-esm/component-platform/actions-controller.d.ts +40 -0
  46. package/lib-esm/component-platform/actions-controller.js +116 -0
  47. package/lib-esm/component-platform/changeset-provider.d.ts +8 -0
  48. package/lib-esm/component-platform/changeset-provider.js +1 -0
  49. package/lib-esm/component-platform/component-controller.d.ts +38 -0
  50. package/lib-esm/component-platform/component-controller.js +116 -0
  51. package/lib-esm/component-platform/component-node-collection.d.ts +18 -0
  52. package/lib-esm/component-platform/component-node-collection.js +48 -0
  53. package/lib-esm/component-platform/component-node.d.ts +63 -0
  54. package/lib-esm/component-platform/component-node.js +187 -0
  55. package/lib-esm/component-platform/component-platform.d.ts +50 -0
  56. package/lib-esm/component-platform/component-platform.js +206 -0
  57. package/lib-esm/component-platform/component-query.d.ts +16 -0
  58. package/lib-esm/component-platform/component-query.js +32 -0
  59. package/lib-esm/component-platform/create-component-model.d.ts +19 -0
  60. package/lib-esm/component-platform/create-component-model.js +121 -0
  61. package/lib-esm/component-platform/descriptor.d.ts +8 -0
  62. package/lib-esm/component-platform/descriptor.js +8 -0
  63. package/lib-esm/component-platform/extend-component.d.ts +8 -0
  64. package/lib-esm/component-platform/extend-component.js +53 -0
  65. package/lib-esm/component-platform/index.d.ts +16 -0
  66. package/lib-esm/component-platform/index.js +9 -0
  67. package/lib-esm/component-platform/queries.d.ts +6 -0
  68. package/lib-esm/component-platform/queries.js +46 -0
  69. package/lib-esm/component-platform/state-processor.d.ts +12 -0
  70. package/lib-esm/component-platform/state-processor.js +205 -0
  71. package/lib-esm/component-resolver.d.ts +14 -0
  72. package/lib-esm/component-resolver.js +47 -0
  73. package/lib-esm/event-subscriber.d.ts +7 -0
  74. package/lib-esm/event-subscriber.js +18 -0
  75. package/lib-esm/index.d.ts +8 -0
  76. package/lib-esm/index.js +5 -0
  77. package/lib-esm/types/configuration.d.ts +86 -0
  78. package/lib-esm/types/configuration.js +13 -0
  79. package/lib-esm/types/index.d.ts +2 -0
  80. package/lib-esm/types/index.js +2 -0
  81. package/lib-esm/types/ui.d.ts +55 -0
  82. package/lib-esm/types/ui.js +1 -0
  83. package/package.json +33 -0
@@ -0,0 +1,187 @@
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 };
@@ -0,0 +1,50 @@
1
+ import { Container, EventManager, Widget } from '@webprovisions/platform';
2
+ import { ActionsController, ActionsState } from './actions-controller';
3
+ import { ChangesetProvider } from './changeset-provider';
4
+ import { ChangesetOptions, ComponentNode, ComponentNodeSettings, RemoveChangeset } from './component-node';
5
+ import { ComponentNodeCollection } from './component-node-collection';
6
+ import { ComponentQuery } from './component-query';
7
+ export declare type MergeOptions = {
8
+ breakpoints?: string[];
9
+ };
10
+ export declare type SwitchMap = {
11
+ [id: string]: string;
12
+ };
13
+ export declare type ChangesetData = {
14
+ key?: string;
15
+ target: ComponentQuery;
16
+ attributes: Partial<ComponentNodeSettings>;
17
+ options?: ChangesetOptions;
18
+ removable?: boolean;
19
+ provider?: string;
20
+ };
21
+ export declare class ComponentPlatform {
22
+ private providers;
23
+ events: EventManager;
24
+ breakpoints: string[];
25
+ nodes: ComponentNodeCollection;
26
+ actionsState: ActionsState;
27
+ private switches;
28
+ private changesets;
29
+ private subscriptions;
30
+ private processNode;
31
+ constructor(widget: Widget, providers?: {
32
+ [key: string]: ChangesetProvider;
33
+ });
34
+ static getInstance(container: Container): Promise<ComponentPlatform>;
35
+ addBreakpoint(name: string): void;
36
+ removeBreakpoint(name: string): void;
37
+ setSwitch(node: ComponentNode, branch: string): void;
38
+ getBranch(node: ComponentNode): string | undefined;
39
+ /**
40
+ * Creates a `ComponentNode` of the specified type.
41
+ * @param type Type of node.
42
+ */
43
+ createNode(type: string, options?: {
44
+ detached?: boolean;
45
+ }): ComponentNode;
46
+ components(): ComponentQuery;
47
+ actions(target: ComponentQuery, ns: string): ActionsController;
48
+ write(data: ChangesetData): RemoveChangeset;
49
+ dispose(): void;
50
+ }
@@ -0,0 +1,206 @@
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 { uuid } from '@telia-ace/widget-utilities';
18
+ import { ActionsController } from './actions-controller';
19
+ import { ComponentNode, } from './component-node';
20
+ import { ComponentNodeCollection } from './component-node-collection';
21
+ import { ComponentQuery } from './component-query';
22
+ import { createStateProcessor } from './state-processor';
23
+ var ComponentPlatform = /** @class */ (function () {
24
+ function ComponentPlatform(widget, providers) {
25
+ if (providers === void 0) { providers = {}; }
26
+ var _this = this;
27
+ this.providers = providers;
28
+ this.breakpoints = [];
29
+ // internal
30
+ this.actionsState = { handlers: [], watchers: [] };
31
+ this.switches = {};
32
+ this.changesets = [];
33
+ this.subscriptions = [];
34
+ this.events = widget.events.createChild(this);
35
+ var root = new ComponentNode(this.events, 'root');
36
+ root.name = "root-".concat(widget.name);
37
+ this.nodes = new ComponentNodeCollection(root, this.switches, this.events);
38
+ var processNode = (this.processNode = createStateProcessor(this, function (report) {
39
+ var nodes = Array.from(report.keys());
40
+ if (process.env.NODE_ENV !== 'production') {
41
+ 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"); })));
42
+ }
43
+ nodes.forEach(function (node) {
44
+ var options = report.get(node);
45
+ if (node.parent && node.parent.type === 'root') {
46
+ _this.events.dispatch('components:root-children-changed', { node: node });
47
+ }
48
+ if (options === null || options === void 0 ? void 0 : options.context) {
49
+ _this.events.dispatch('components:context-changed', { node: node });
50
+ }
51
+ if (options === null || options === void 0 ? void 0 : options.properties) {
52
+ _this.events.dispatch('components:properties-changed', { node: node });
53
+ }
54
+ if (options === null || options === void 0 ? void 0 : options.layout) {
55
+ _this.events.dispatch('components:layout-changed', { node: node });
56
+ }
57
+ });
58
+ _this.events.dispatch('components:component-model-initialized', {}, { bubbles: true });
59
+ }));
60
+ Promise.all(Object.keys(providers).map(function (key) {
61
+ var provider = providers[key];
62
+ return provider.load(_this);
63
+ }));
64
+ this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
65
+ var node = data.node;
66
+ _this.changesets.forEach(function (record) {
67
+ var changeset = record.changeset, target = record.target, removes = record.removes;
68
+ var _a = __read(changeset, 2), change = _a[0], options = _a[1];
69
+ if (target.match(data.node)) {
70
+ if (change.properties) {
71
+ removes.push(node.writeProperties(change.properties, options));
72
+ }
73
+ if (change.context) {
74
+ removes.push(node.writeContext(change.context, options));
75
+ }
76
+ if (change.layout) {
77
+ removes.push(node.writeLayout(change.layout, options));
78
+ }
79
+ }
80
+ });
81
+ }));
82
+ this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
83
+ processNode(data.node, { properties: true, context: true });
84
+ }));
85
+ this.subscriptions.push(this.events.subscribe('components:set-properties', function (event, data) {
86
+ processNode(data.node, { properties: true });
87
+ }));
88
+ this.subscriptions.push(this.events.subscribe('components:set-context', function (event, data) {
89
+ processNode(data.node, { properties: true, context: true });
90
+ }));
91
+ this.subscriptions.push(this.events.subscribe('components:set-indent', function (event, data) {
92
+ processNode(data.node, { layout: true });
93
+ }));
94
+ this.subscriptions.push(this.events.subscribe('components:set-layout', function (event, data) {
95
+ processNode(data.node, { layout: true });
96
+ }));
97
+ this.subscriptions.push(this.events.subscribe('components:node-switched', function (event, _a) {
98
+ var node = _a.node, branch = _a.branch;
99
+ processNode(node, {
100
+ layout: true,
101
+ recursive: true,
102
+ properties: true,
103
+ context: true,
104
+ });
105
+ }));
106
+ this.subscriptions.push(this.events.subscribe('components:node-removed', function (event, _a) {
107
+ var parentNode = _a.parentNode;
108
+ processNode(parentNode, { properties: true });
109
+ }));
110
+ }
111
+ ComponentPlatform.getInstance = function (container) {
112
+ return container.getAsync('components');
113
+ };
114
+ ComponentPlatform.prototype.addBreakpoint = function (name) {
115
+ if (this.breakpoints.indexOf(name) === -1) {
116
+ this.breakpoints.push(name);
117
+ this.processNode(this.nodes.root, {
118
+ context: true,
119
+ properties: true,
120
+ layout: true,
121
+ recursive: true,
122
+ });
123
+ }
124
+ };
125
+ ComponentPlatform.prototype.removeBreakpoint = function (name) {
126
+ var indexToRemove = this.breakpoints.indexOf(name);
127
+ if (indexToRemove > -1) {
128
+ this.breakpoints.splice(indexToRemove, 1);
129
+ this.processNode(this.nodes.root, {
130
+ context: true,
131
+ properties: true,
132
+ layout: true,
133
+ recursive: true,
134
+ });
135
+ }
136
+ };
137
+ ComponentPlatform.prototype.setSwitch = function (node, branch) {
138
+ this.switches[node.id] = branch;
139
+ this.events.dispatch('components:node-switched', { node: node, branch: branch });
140
+ };
141
+ ComponentPlatform.prototype.getBranch = function (node) {
142
+ return this.switches[node.id];
143
+ };
144
+ /**
145
+ * Creates a `ComponentNode` of the specified type.
146
+ * @param type Type of node.
147
+ */
148
+ ComponentPlatform.prototype.createNode = function (type, options) {
149
+ if (options === void 0) { options = {}; }
150
+ var node = new ComponentNode(this.events, type);
151
+ if (options.detached) {
152
+ this.nodes.detached.push(node);
153
+ }
154
+ return node;
155
+ };
156
+ ComponentPlatform.prototype.components = function () {
157
+ return new ComponentQuery(this);
158
+ };
159
+ ComponentPlatform.prototype.actions = function (target, ns) {
160
+ return new ActionsController(this, target, ns);
161
+ };
162
+ ComponentPlatform.prototype.write = function (data) {
163
+ var _this = this;
164
+ var providerName = data.provider, target = data.target, attributes = data.attributes, _a = data.options, options = _a === void 0 ? {} : _a, removable = data.removable;
165
+ var key = data.key || uuid();
166
+ var changeset = [attributes, options];
167
+ var record = { changeset: changeset, target: target, removes: [] };
168
+ if (providerName) {
169
+ var provider_1 = this.providers[providerName];
170
+ provider_1.write(key, target, attributes, options);
171
+ record.removes.push(function () {
172
+ provider_1.remove(key);
173
+ });
174
+ }
175
+ this.changesets.push(record);
176
+ this.nodes.all.forEach(function (node) {
177
+ if (target.match(node)) {
178
+ var remove = function () { };
179
+ if (attributes.properties) {
180
+ remove = node.writeProperties(attributes.properties, options, removable);
181
+ }
182
+ if (attributes.context) {
183
+ remove = node.writeContext(attributes.context, options, removable);
184
+ }
185
+ if (attributes.layout) {
186
+ remove = node.writeContext(attributes.layout, options, removable);
187
+ }
188
+ record.removes.push(remove);
189
+ }
190
+ });
191
+ return function () {
192
+ if (removable) {
193
+ record.removes.forEach(function (remove) { return remove(); });
194
+ var indexToRemove = _this.changesets.indexOf(record);
195
+ if (indexToRemove > -1) {
196
+ _this.changesets.splice(indexToRemove, 1);
197
+ }
198
+ }
199
+ };
200
+ };
201
+ ComponentPlatform.prototype.dispose = function () {
202
+ this.subscriptions.forEach(function (sub) { return sub(); });
203
+ };
204
+ return ComponentPlatform;
205
+ }());
206
+ export { ComponentPlatform };
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,32 @@
1
+ import { AbstractComponentController } from './component-controller';
2
+ var ComponentQuery = /** @class */ (function () {
3
+ function ComponentQuery(platform, rules) {
4
+ if (rules === void 0) { rules = []; }
5
+ this.platform = platform;
6
+ this.rules = rules;
7
+ }
8
+ ComponentQuery.prototype.match = function (node) {
9
+ return this.rules.every(function (rule) {
10
+ if (rule.id && rule.id !== node.id) {
11
+ return false;
12
+ }
13
+ if (rule.type && rule.type !== node.type) {
14
+ return false;
15
+ }
16
+ return true;
17
+ });
18
+ };
19
+ ComponentQuery.prototype.ofType = function (type) {
20
+ this.rules.push({ type: type });
21
+ return this;
22
+ };
23
+ ComponentQuery.prototype.withId = function (id) {
24
+ this.rules.push({ id: id });
25
+ return this;
26
+ };
27
+ ComponentQuery.prototype.select = function () {
28
+ return new AbstractComponentController(this.platform, this);
29
+ };
30
+ return ComponentQuery;
31
+ }());
32
+ export { ComponentQuery };
@@ -0,0 +1,19 @@
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 {};
@@ -0,0 +1,121 @@
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 { Logger } from '@telia-ace/widget-utilities';
18
+ export var normalizeReference = function (reference) {
19
+ if (Array.isArray(reference)) {
20
+ var _a = __read(reference), definitionId = _a[0], overrides = _a.slice(1);
21
+ return {
22
+ definitionId: definitionId,
23
+ overrides: overrides,
24
+ };
25
+ }
26
+ return {
27
+ definitionId: reference,
28
+ overrides: [],
29
+ };
30
+ };
31
+ var createChildren = function (platform, node, references, definitions, views, branch) {
32
+ references.forEach(function (ref) {
33
+ var childRef = normalizeReference(ref);
34
+ if (childRef.definitionId === 'view') {
35
+ var viewNode_1 = platform.createNode('view');
36
+ viewNode_1.name = 'view';
37
+ Object.keys(views).forEach(function (key) {
38
+ var viewDef = views[key];
39
+ createChildren(platform, viewNode_1, [viewDef.entry], definitions, views, key);
40
+ });
41
+ node.appendChild(viewNode_1);
42
+ childRef.overrides.forEach(function (override) {
43
+ if (override.properties) {
44
+ viewNode_1.writeProperties(override.properties, {
45
+ breakpoints: override.breakpoints,
46
+ });
47
+ }
48
+ if (override.context) {
49
+ viewNode_1.writeContext(override.context, { breakpoints: override.breakpoints });
50
+ }
51
+ if (override.layout) {
52
+ viewNode_1.writeLayout(override.layout, { breakpoints: override.breakpoints });
53
+ }
54
+ });
55
+ }
56
+ else {
57
+ var childDef = definitions[childRef.definitionId];
58
+ if (process.env.NODE_ENV !== 'production') {
59
+ if (!childDef) {
60
+ Logger.error("No definition found for component type '".concat(childRef.definitionId, "'."));
61
+ return;
62
+ }
63
+ }
64
+ var childNode_1 = platform.createNode(childDef.type);
65
+ childNode_1.name = childRef.definitionId;
66
+ childNode_1.tags = childDef.tags || [];
67
+ if (childDef.properties) {
68
+ childNode_1.writeProperties(childDef.properties);
69
+ }
70
+ if (childDef.context) {
71
+ childNode_1.writeContext(childDef.context);
72
+ }
73
+ if (childDef.layout) {
74
+ childNode_1.writeLayout(childDef.layout);
75
+ }
76
+ node.appendChild(childNode_1, branch);
77
+ childRef.overrides.forEach(function (override) {
78
+ var options = { breakpoints: override.breakpoints };
79
+ if (override.properties) {
80
+ childNode_1.writeProperties(override.properties, options);
81
+ }
82
+ if (override.context) {
83
+ childNode_1.writeContext(override.context, options);
84
+ }
85
+ if (override.layout) {
86
+ childNode_1.writeLayout(override.layout, options);
87
+ }
88
+ });
89
+ if (childDef.children) {
90
+ createChildren(platform, childNode_1, childDef.children, definitions, views);
91
+ }
92
+ }
93
+ });
94
+ };
95
+ export var createComponentModel = function (platform, settings) {
96
+ var entry = settings.entry, components = settings.components, breakpoints = settings.breakpoints, views = settings.views;
97
+ var subscriptions = [];
98
+ Object.keys(breakpoints).forEach(function (name) {
99
+ var query = breakpoints[name];
100
+ var list = window.matchMedia(query);
101
+ if (list.matches) {
102
+ platform.breakpoints.push(name);
103
+ }
104
+ var listener = function (event) {
105
+ if (event.matches) {
106
+ platform.addBreakpoint(name);
107
+ }
108
+ else {
109
+ platform.removeBreakpoint(name);
110
+ }
111
+ };
112
+ list.addListener(listener);
113
+ subscriptions.push(function () { return list.removeListener(listener); });
114
+ });
115
+ createChildren(platform, platform.nodes.root, [entry], components, views);
116
+ return function () {
117
+ return subscriptions.forEach(function (sub) {
118
+ sub();
119
+ });
120
+ };
121
+ };
@@ -0,0 +1,8 @@
1
+ import { ComponentNode } from './component-node';
2
+ export declare type ComponentDescriptor = {
3
+ id: string;
4
+ type?: string;
5
+ name?: string;
6
+ branch: string;
7
+ };
8
+ export declare const asDescriptor: (node: ComponentNode, branch?: string | undefined) => ComponentDescriptor;
@@ -0,0 +1,8 @@
1
+ export var asDescriptor = function (node, branch) {
2
+ return {
3
+ id: node.id,
4
+ type: node.type,
5
+ name: node.name,
6
+ branch: branch || 'default',
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ import { ComponentNodeController } from './component-controller';
3
+ import { ComponentQuery } from './component-query';
4
+ export declare type ExtendComponentHandler = (controller: ComponentNodeController) => any;
5
+ export declare type ExtendComponentOptions = {
6
+ reuseController?: boolean;
7
+ };
8
+ export declare const extendComponent: (container: Container, typeOrQuery: string | ComponentQuery, handler: ExtendComponentHandler, ns?: string, options?: ExtendComponentOptions) => Promise<void>;