@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,190 @@
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;
@@ -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,209 @@
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;
@@ -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,35 @@
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;
@@ -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,126 @@
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.createComponentModel = exports.normalizeReference = void 0;
20
+ var widget_utilities_1 = require("@telia-ace/widget-utilities");
21
+ var normalizeReference = function (reference) {
22
+ if (Array.isArray(reference)) {
23
+ var _a = __read(reference), definitionId = _a[0], overrides = _a.slice(1);
24
+ return {
25
+ definitionId: definitionId,
26
+ overrides: overrides,
27
+ };
28
+ }
29
+ return {
30
+ definitionId: reference,
31
+ overrides: [],
32
+ };
33
+ };
34
+ exports.normalizeReference = normalizeReference;
35
+ var createChildren = function (platform, node, references, definitions, views, branch) {
36
+ references.forEach(function (ref) {
37
+ var childRef = (0, exports.normalizeReference)(ref);
38
+ if (childRef.definitionId === 'view') {
39
+ var viewNode_1 = platform.createNode('view');
40
+ viewNode_1.name = 'view';
41
+ Object.keys(views).forEach(function (key) {
42
+ var viewDef = views[key];
43
+ createChildren(platform, viewNode_1, [viewDef.entry], definitions, views, key);
44
+ });
45
+ node.appendChild(viewNode_1);
46
+ childRef.overrides.forEach(function (override) {
47
+ if (override.properties) {
48
+ viewNode_1.writeProperties(override.properties, {
49
+ breakpoints: override.breakpoints,
50
+ });
51
+ }
52
+ if (override.context) {
53
+ viewNode_1.writeContext(override.context, { breakpoints: override.breakpoints });
54
+ }
55
+ if (override.layout) {
56
+ viewNode_1.writeLayout(override.layout, { breakpoints: override.breakpoints });
57
+ }
58
+ });
59
+ }
60
+ else {
61
+ var childDef = definitions[childRef.definitionId];
62
+ if (process.env.NODE_ENV !== 'production') {
63
+ if (!childDef) {
64
+ widget_utilities_1.Logger.error("No definition found for component type '".concat(childRef.definitionId, "'."));
65
+ return;
66
+ }
67
+ }
68
+ var childNode_1 = platform.createNode(childDef.type);
69
+ childNode_1.name = childRef.definitionId;
70
+ childNode_1.tags = childDef.tags || [];
71
+ if (childDef.properties) {
72
+ childNode_1.writeProperties(childDef.properties);
73
+ }
74
+ if (childDef.context) {
75
+ childNode_1.writeContext(childDef.context);
76
+ }
77
+ if (childDef.layout) {
78
+ childNode_1.writeLayout(childDef.layout);
79
+ }
80
+ node.appendChild(childNode_1, branch);
81
+ childRef.overrides.forEach(function (override) {
82
+ var options = { breakpoints: override.breakpoints };
83
+ if (override.properties) {
84
+ childNode_1.writeProperties(override.properties, options);
85
+ }
86
+ if (override.context) {
87
+ childNode_1.writeContext(override.context, options);
88
+ }
89
+ if (override.layout) {
90
+ childNode_1.writeLayout(override.layout, options);
91
+ }
92
+ });
93
+ if (childDef.children) {
94
+ createChildren(platform, childNode_1, childDef.children, definitions, views);
95
+ }
96
+ }
97
+ });
98
+ };
99
+ var createComponentModel = function (platform, settings) {
100
+ var entry = settings.entry, components = settings.components, breakpoints = settings.breakpoints, views = settings.views;
101
+ var subscriptions = [];
102
+ Object.keys(breakpoints).forEach(function (name) {
103
+ var query = breakpoints[name];
104
+ var list = window.matchMedia(query);
105
+ if (list.matches) {
106
+ platform.breakpoints.push(name);
107
+ }
108
+ var listener = function (event) {
109
+ if (event.matches) {
110
+ platform.addBreakpoint(name);
111
+ }
112
+ else {
113
+ platform.removeBreakpoint(name);
114
+ }
115
+ };
116
+ list.addListener(listener);
117
+ subscriptions.push(function () { return list.removeListener(listener); });
118
+ });
119
+ createChildren(platform, platform.nodes.root, [entry], components, views);
120
+ return function () {
121
+ return subscriptions.forEach(function (sub) {
122
+ sub();
123
+ });
124
+ };
125
+ };
126
+ exports.createComponentModel = createComponentModel;
@@ -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,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asDescriptor = void 0;
4
+ var asDescriptor = function (node, branch) {
5
+ return {
6
+ id: node.id,
7
+ type: node.type,
8
+ name: node.name,
9
+ branch: branch || 'default',
10
+ };
11
+ };
12
+ exports.asDescriptor = asDescriptor;
@@ -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>;