@telia-ace/widget-core 1.0.4 → 1.0.7

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 (93) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +3 -3
  3. package/{lib-esm → dist}/action-resolver.d.ts +8 -8
  4. package/{lib → dist}/component-platform/actions-controller.d.ts +40 -40
  5. package/{lib-esm → dist}/component-platform/changeset-provider.d.ts +8 -8
  6. package/{lib-esm → dist}/component-platform/component-configuration-api.d.ts +2 -2
  7. package/{lib-esm → dist}/component-platform/component-controller.d.ts +38 -38
  8. package/{lib → dist}/component-platform/component-node-collection.d.ts +18 -18
  9. package/{lib → dist}/component-platform/component-node.d.ts +63 -63
  10. package/{lib-esm → dist}/component-platform/component-platform.d.ts +54 -54
  11. package/{lib → dist}/component-platform/component-query.d.ts +16 -16
  12. package/{lib → dist}/component-platform/create-component-model.d.ts +36 -36
  13. package/{lib-esm → dist}/component-platform/custom-component-handler.d.ts +21 -21
  14. package/{lib-esm → dist}/component-platform/descriptor.d.ts +8 -8
  15. package/{lib-esm → dist}/component-platform/extend-component.d.ts +8 -8
  16. package/{lib → dist}/component-platform/index.d.ts +18 -18
  17. package/{lib-esm → dist}/component-platform/queries.d.ts +6 -6
  18. package/{lib → dist}/component-platform/state-processor.d.ts +12 -12
  19. package/{lib-esm → dist}/component-resolver.d.ts +14 -14
  20. package/{lib-esm → dist}/event-subscriber.d.ts +7 -7
  21. package/{lib → dist}/index.d.ts +8 -8
  22. package/dist/index.js +1047 -0
  23. package/dist/index.js.map +1 -0
  24. package/{lib-esm → dist}/types/configuration.d.ts +86 -86
  25. package/{lib → dist}/types/index.d.ts +2 -2
  26. package/{lib-esm → dist}/types/ui.d.ts +54 -54
  27. package/package.json +10 -10
  28. package/lib/action-resolver.d.ts +0 -8
  29. package/lib/action-resolver.js +0 -19
  30. package/lib/component-platform/actions-controller.js +0 -119
  31. package/lib/component-platform/changeset-provider.d.ts +0 -8
  32. package/lib/component-platform/changeset-provider.js +0 -2
  33. package/lib/component-platform/component-configuration-api.d.ts +0 -2
  34. package/lib/component-platform/component-configuration-api.js +0 -32
  35. package/lib/component-platform/component-controller.d.ts +0 -38
  36. package/lib/component-platform/component-controller.js +0 -119
  37. package/lib/component-platform/component-node-collection.js +0 -51
  38. package/lib/component-platform/component-node.js +0 -190
  39. package/lib/component-platform/component-platform.d.ts +0 -54
  40. package/lib/component-platform/component-platform.js +0 -220
  41. package/lib/component-platform/component-query.js +0 -35
  42. package/lib/component-platform/create-component-model.js +0 -141
  43. package/lib/component-platform/custom-component-handler.d.ts +0 -21
  44. package/lib/component-platform/custom-component-handler.js +0 -16
  45. package/lib/component-platform/descriptor.d.ts +0 -8
  46. package/lib/component-platform/descriptor.js +0 -12
  47. package/lib/component-platform/extend-component.d.ts +0 -8
  48. package/lib/component-platform/extend-component.js +0 -57
  49. package/lib/component-platform/index.js +0 -30
  50. package/lib/component-platform/queries.d.ts +0 -6
  51. package/lib/component-platform/queries.js +0 -53
  52. package/lib/component-platform/state-processor.js +0 -209
  53. package/lib/component-resolver.d.ts +0 -14
  54. package/lib/component-resolver.js +0 -49
  55. package/lib/event-subscriber.d.ts +0 -7
  56. package/lib/event-subscriber.js +0 -22
  57. package/lib/index.js +0 -41
  58. package/lib/types/configuration.d.ts +0 -86
  59. package/lib/types/configuration.js +0 -16
  60. package/lib/types/index.js +0 -18
  61. package/lib/types/ui.d.ts +0 -54
  62. package/lib/types/ui.js +0 -2
  63. package/lib-esm/action-resolver.js +0 -17
  64. package/lib-esm/component-platform/actions-controller.d.ts +0 -40
  65. package/lib-esm/component-platform/actions-controller.js +0 -116
  66. package/lib-esm/component-platform/changeset-provider.js +0 -1
  67. package/lib-esm/component-platform/component-configuration-api.js +0 -30
  68. package/lib-esm/component-platform/component-controller.js +0 -116
  69. package/lib-esm/component-platform/component-node-collection.d.ts +0 -18
  70. package/lib-esm/component-platform/component-node-collection.js +0 -48
  71. package/lib-esm/component-platform/component-node.d.ts +0 -63
  72. package/lib-esm/component-platform/component-node.js +0 -187
  73. package/lib-esm/component-platform/component-platform.js +0 -217
  74. package/lib-esm/component-platform/component-query.d.ts +0 -16
  75. package/lib-esm/component-platform/component-query.js +0 -32
  76. package/lib-esm/component-platform/create-component-model.d.ts +0 -36
  77. package/lib-esm/component-platform/create-component-model.js +0 -135
  78. package/lib-esm/component-platform/custom-component-handler.js +0 -13
  79. package/lib-esm/component-platform/descriptor.js +0 -8
  80. package/lib-esm/component-platform/extend-component.js +0 -53
  81. package/lib-esm/component-platform/index.d.ts +0 -18
  82. package/lib-esm/component-platform/index.js +0 -10
  83. package/lib-esm/component-platform/queries.js +0 -46
  84. package/lib-esm/component-platform/state-processor.d.ts +0 -12
  85. package/lib-esm/component-platform/state-processor.js +0 -205
  86. package/lib-esm/component-resolver.js +0 -47
  87. package/lib-esm/event-subscriber.js +0 -18
  88. package/lib-esm/index.d.ts +0 -8
  89. package/lib-esm/index.js +0 -5
  90. package/lib-esm/types/configuration.js +0 -13
  91. package/lib-esm/types/index.d.ts +0 -2
  92. package/lib-esm/types/index.js +0 -2
  93. package/lib-esm/types/ui.js +0 -1
@@ -1,220 +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 custom_component_handler_1 = require("./custom-component-handler");
26
- var state_processor_1 = require("./state-processor");
27
- var ComponentPlatform = /** @class */ (function () {
28
- function ComponentPlatform(widget, providers) {
29
- if (providers === void 0) { providers = {}; }
30
- var _this = this;
31
- this.providers = providers;
32
- this.breakpoints = [];
33
- // internal
34
- this.actionsState = { handlers: [], watchers: [] };
35
- this.switches = {};
36
- this.changesets = [];
37
- this.subscriptions = [];
38
- this.customComponentHandler = new custom_component_handler_1.CustomComponentHandler();
39
- this.events = widget.events.createChild(this);
40
- var root = new component_node_1.ComponentNode(this.events, 'root');
41
- root.name = "root-".concat(widget.name);
42
- this.nodes = new component_node_collection_1.ComponentNodeCollection(root, this.switches, this.events);
43
- var processNode = (this.processNode = (0, state_processor_1.createStateProcessor)(this, function (report) {
44
- var nodes = Array.from(report.keys());
45
- if (process.env.NODE_ENV !== 'production') {
46
- 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"); })));
47
- }
48
- nodes.forEach(function (node) {
49
- var options = report.get(node);
50
- if (node.parent && node.parent.type === 'root') {
51
- _this.events.dispatch('components:root-children-changed', { node: node });
52
- }
53
- if (options === null || options === void 0 ? void 0 : options.context) {
54
- _this.events.dispatch('components:context-changed', { node: node });
55
- }
56
- if (options === null || options === void 0 ? void 0 : options.properties) {
57
- _this.events.dispatch('components:properties-changed', { node: node });
58
- }
59
- if (options === null || options === void 0 ? void 0 : options.layout) {
60
- _this.events.dispatch('components:layout-changed', { node: node });
61
- }
62
- });
63
- _this.events.dispatch('components:component-model-initialized', {}, { bubbles: true });
64
- }));
65
- Promise.all(Object.keys(providers).map(function (key) {
66
- var provider = providers[key];
67
- return provider.load(_this);
68
- }));
69
- this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
70
- var node = data.node;
71
- _this.changesets.forEach(function (record) {
72
- var changeset = record.changeset, target = record.target, removes = record.removes;
73
- var _a = __read(changeset, 2), change = _a[0], options = _a[1];
74
- if (target.match(data.node)) {
75
- if (change.properties) {
76
- removes.push(node.writeProperties(change.properties, options));
77
- }
78
- if (change.context) {
79
- removes.push(node.writeContext(change.context, options));
80
- }
81
- if (change.layout) {
82
- removes.push(node.writeLayout(change.layout, options));
83
- }
84
- }
85
- });
86
- }));
87
- this.subscriptions.push(this.events.subscribe('components:node-appended', function (event, data) {
88
- processNode(data.node, { properties: true, context: true });
89
- }));
90
- this.subscriptions.push(this.events.subscribe('components:set-properties', function (event, data) {
91
- processNode(data.node, { properties: true });
92
- }));
93
- this.subscriptions.push(this.events.subscribe('components:set-context', function (event, data) {
94
- processNode(data.node, { properties: true, context: true });
95
- }));
96
- this.subscriptions.push(this.events.subscribe('components:set-indent', function (event, data) {
97
- processNode(data.node, { layout: true });
98
- }));
99
- this.subscriptions.push(this.events.subscribe('components:set-layout', function (event, data) {
100
- processNode(data.node, { layout: true });
101
- }));
102
- this.subscriptions.push(this.events.subscribe('components:node-switched', function (event, _a) {
103
- var node = _a.node, branch = _a.branch;
104
- processNode(node, {
105
- layout: true,
106
- recursive: true,
107
- properties: true,
108
- context: true,
109
- });
110
- }));
111
- this.subscriptions.push(this.events.subscribe('components:node-removed', function (event, _a) {
112
- var parentNode = _a.parentNode;
113
- processNode(parentNode, { properties: true });
114
- }));
115
- if (this.events.parent) {
116
- this.events.parent.dispatch('components:platform-created', { platform: this });
117
- }
118
- }
119
- ComponentPlatform.getInstance = function (container) {
120
- return container.getAsync('components');
121
- };
122
- ComponentPlatform.prototype.addBreakpoint = function (name) {
123
- if (this.breakpoints.indexOf(name) === -1) {
124
- this.breakpoints.push(name);
125
- this.processNode(this.nodes.root, {
126
- context: true,
127
- properties: true,
128
- layout: true,
129
- recursive: true,
130
- });
131
- }
132
- };
133
- ComponentPlatform.prototype.removeBreakpoint = function (name) {
134
- var indexToRemove = this.breakpoints.indexOf(name);
135
- if (indexToRemove > -1) {
136
- this.breakpoints.splice(indexToRemove, 1);
137
- this.processNode(this.nodes.root, {
138
- context: true,
139
- properties: true,
140
- layout: true,
141
- recursive: true,
142
- });
143
- }
144
- };
145
- ComponentPlatform.prototype.setSwitch = function (node, branch) {
146
- this.switches[node.id] = branch;
147
- this.events.dispatch('components:node-switched', { node: node, branch: branch });
148
- };
149
- ComponentPlatform.prototype.getBranch = function (node) {
150
- return this.switches[node.id];
151
- };
152
- /**
153
- * Creates a `ComponentNode` of the specified type.
154
- * @param type Type of node.
155
- */
156
- ComponentPlatform.prototype.createNode = function (type, options) {
157
- if (options === void 0) { options = {}; }
158
- var node = new component_node_1.ComponentNode(this.events, type);
159
- if (options.detached) {
160
- this.nodes.detached.push(node);
161
- }
162
- return node;
163
- };
164
- ComponentPlatform.prototype.components = function () {
165
- return new component_query_1.ComponentQuery(this);
166
- };
167
- ComponentPlatform.prototype.actions = function (target, ns) {
168
- return new actions_controller_1.ActionsController(this, target, ns);
169
- };
170
- ComponentPlatform.prototype.write = function (data) {
171
- var _this = this;
172
- var providerName = data.provider, target = data.target, attributes = data.attributes, _a = data.options, options = _a === void 0 ? {} : _a, removable = data.removable;
173
- var key = data.key || (0, widget_utilities_1.uuid)();
174
- var changeset = [attributes, options];
175
- var record = { changeset: changeset, target: target, removes: [] };
176
- if (providerName) {
177
- var provider_1 = this.providers[providerName];
178
- provider_1.write(key, target, attributes, options);
179
- record.removes.push(function () {
180
- provider_1.remove(key);
181
- });
182
- }
183
- this.changesets.push(record);
184
- this.nodes.all.forEach(function (node) {
185
- if (target.match(node)) {
186
- var remove = function () { };
187
- if (attributes.properties) {
188
- remove = node.writeProperties(attributes.properties, options, removable);
189
- }
190
- if (attributes.context) {
191
- remove = node.writeContext(attributes.context, options, removable);
192
- }
193
- if (attributes.layout) {
194
- remove = node.writeContext(attributes.layout, options, removable);
195
- }
196
- record.removes.push(remove);
197
- }
198
- });
199
- return function () {
200
- if (removable) {
201
- record.removes.forEach(function (remove) { return remove(); });
202
- var indexToRemove = _this.changesets.indexOf(record);
203
- if (indexToRemove > -1) {
204
- _this.changesets.splice(indexToRemove, 1);
205
- }
206
- }
207
- };
208
- };
209
- ComponentPlatform.prototype.addComponentHandler = function (definitionType, fn) {
210
- this.customComponentHandler.add(definitionType, fn);
211
- };
212
- ComponentPlatform.prototype.getComponentHandler = function (definitionType) {
213
- return this.customComponentHandler.get(definitionType);
214
- };
215
- ComponentPlatform.prototype.dispose = function () {
216
- this.subscriptions.forEach(function (sub) { return sub(); });
217
- };
218
- return ComponentPlatform;
219
- }());
220
- exports.ComponentPlatform = ComponentPlatform;
@@ -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,141 +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.createComponentModel = exports.createChildren = 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
- var childDef = definitions[childRef.definitionId];
39
- if (childRef.definitionId === 'view') {
40
- var viewNode_1 = platform.createNode('view');
41
- viewNode_1.name = 'view';
42
- Object.keys(views).forEach(function (key) {
43
- var viewDef = views[key];
44
- (0, exports.createChildren)(platform, viewNode_1, [viewDef.entry], definitions, views, key);
45
- });
46
- node.appendChild(viewNode_1);
47
- childRef.overrides.forEach(function (override) {
48
- if (override.properties) {
49
- viewNode_1.writeProperties(override.properties, {
50
- breakpoints: override.breakpoints,
51
- });
52
- }
53
- if (override.context) {
54
- viewNode_1.writeContext(override.context, { breakpoints: override.breakpoints });
55
- }
56
- if (override.layout) {
57
- viewNode_1.writeLayout(override.layout, { breakpoints: override.breakpoints });
58
- }
59
- });
60
- }
61
- else if (platform.getComponentHandler(childDef.type)) {
62
- var handle = platform.getComponentHandler(childDef.type);
63
- if (handle) {
64
- handle(childRef, {
65
- platform: platform,
66
- node: node,
67
- references: references,
68
- definitions: definitions,
69
- views: views,
70
- branch: branch,
71
- });
72
- }
73
- }
74
- else {
75
- var childDef_1 = definitions[childRef.definitionId];
76
- if (process.env.NODE_ENV !== 'production') {
77
- if (!childDef_1) {
78
- widget_utilities_1.Logger.error("No definition found for component type '".concat(childRef.definitionId, "'."));
79
- return;
80
- }
81
- }
82
- var childNode_1 = platform.createNode(childDef_1.type);
83
- childNode_1.name = childRef.definitionId;
84
- childNode_1.tags = childDef_1.tags || [];
85
- if (childDef_1.properties) {
86
- childNode_1.writeProperties(childDef_1.properties);
87
- }
88
- if (childDef_1.context) {
89
- childNode_1.writeContext(childDef_1.context);
90
- }
91
- if (childDef_1.layout) {
92
- childNode_1.writeLayout(childDef_1.layout);
93
- }
94
- node.appendChild(childNode_1, branch);
95
- childRef.overrides.forEach(function (override) {
96
- var options = { breakpoints: override.breakpoints };
97
- if (override.properties) {
98
- childNode_1.writeProperties(override.properties, options);
99
- }
100
- if (override.context) {
101
- childNode_1.writeContext(override.context, options);
102
- }
103
- if (override.layout) {
104
- childNode_1.writeLayout(override.layout, options);
105
- }
106
- });
107
- if (childDef_1.children) {
108
- (0, exports.createChildren)(platform, childNode_1, childDef_1.children, definitions, views);
109
- }
110
- }
111
- });
112
- };
113
- exports.createChildren = createChildren;
114
- var createComponentModel = function (platform, settings) {
115
- var entry = settings.entry, components = settings.components, breakpoints = settings.breakpoints, views = settings.views;
116
- var subscriptions = [];
117
- Object.keys(breakpoints).forEach(function (name) {
118
- var query = breakpoints[name];
119
- var list = window.matchMedia(query);
120
- if (list.matches) {
121
- platform.breakpoints.push(name);
122
- }
123
- var listener = function (event) {
124
- if (event.matches) {
125
- platform.addBreakpoint(name);
126
- }
127
- else {
128
- platform.removeBreakpoint(name);
129
- }
130
- };
131
- list.addListener(listener);
132
- subscriptions.push(function () { return list.removeListener(listener); });
133
- });
134
- (0, exports.createChildren)(platform, platform.nodes.root, [entry], components, views);
135
- return function () {
136
- return subscriptions.forEach(function (sub) {
137
- sub();
138
- });
139
- };
140
- };
141
- exports.createComponentModel = createComponentModel;
@@ -1,21 +0,0 @@
1
- import { ComponentReference, ComponentSettings, ViewDefinition } from '../types';
2
- import { ComponentNode } from './component-node';
3
- import { ComponentPlatform } from './component-platform';
4
- import { NormalizedComponentReference } from './create-component-model';
5
- export declare type CustomHandlerCallback = (ref: NormalizedComponentReference, options: {
6
- platform: ComponentPlatform;
7
- node: ComponentNode;
8
- references: ComponentReference[];
9
- definitions: {
10
- [name: string]: ComponentSettings;
11
- };
12
- views: {
13
- [key: string]: ViewDefinition;
14
- };
15
- branch?: string;
16
- }) => void;
17
- export declare class CustomComponentHandler {
18
- private handlers;
19
- add(name: string, fn: CustomHandlerCallback): void;
20
- get(name: string): CustomHandlerCallback | undefined;
21
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomComponentHandler = void 0;
4
- var CustomComponentHandler = /** @class */ (function () {
5
- function CustomComponentHandler() {
6
- this.handlers = new Map();
7
- }
8
- CustomComponentHandler.prototype.add = function (name, fn) {
9
- this.handlers.set(name, fn);
10
- };
11
- CustomComponentHandler.prototype.get = function (name) {
12
- return this.handlers.get(name);
13
- };
14
- return CustomComponentHandler;
15
- }());
16
- exports.CustomComponentHandler = CustomComponentHandler;
@@ -1,8 +0,0 @@
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;
@@ -1,12 +0,0 @@
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;
@@ -1,8 +0,0 @@
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>;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendComponent = void 0;
4
- var widget_utilities_1 = require("@telia-ace/widget-utilities");
5
- var component_controller_1 = require("./component-controller");
6
- var component_platform_1 = require("./component-platform");
7
- var component_query_1 = require("./component-query");
8
- var extendComponent = function (container, typeOrQuery, handler, ns, options) {
9
- if (ns === void 0) { ns = (0, widget_utilities_1.uuid)(); }
10
- if (options === void 0) { options = {}; }
11
- return container.getAsync('components').then(function (components) {
12
- var target;
13
- if (typeof typeOrQuery === 'string') {
14
- var collection = new component_query_1.ComponentQuery(components);
15
- collection.ofType(typeOrQuery);
16
- target = collection;
17
- }
18
- else {
19
- target = typeOrQuery;
20
- }
21
- var managedInstances = {};
22
- var getOrCreateController = function (node) {
23
- var existing = managedInstances[node.id];
24
- if (existing) {
25
- return Promise.resolve(existing.controller);
26
- }
27
- return component_platform_1.ComponentPlatform.getInstance(container).then(function (platform) {
28
- return new component_controller_1.ComponentNodeController(platform, node, ns);
29
- });
30
- };
31
- components.events.subscribe('components:node-enter', function (event, _a) {
32
- var node = _a.node;
33
- if (target.match(node)) {
34
- getOrCreateController(node).then(function (controller) {
35
- Promise.resolve(handler(controller)).then(function (dispose) {
36
- managedInstances[node.id] = {
37
- dispose: dispose,
38
- controller: controller,
39
- };
40
- });
41
- });
42
- }
43
- });
44
- components.events.subscribe('components:node-exit', function (event, _a) {
45
- var node = _a.node;
46
- var instance = managedInstances[node.id];
47
- if (instance) {
48
- instance.dispose && instance.dispose();
49
- if (!options.reuseController) {
50
- instance.controller.dispose();
51
- delete managedInstances[node.id];
52
- }
53
- }
54
- });
55
- });
56
- };
57
- exports.extendComponent = extendComponent;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.traverseComponents = exports.findVisibleComponents = exports.findComponent = exports.extendComponent = exports.asDescriptor = exports.createComponentModel = exports.createChildren = exports.ComponentQuery = exports.ComponentPlatform = exports.ComponentNode = exports.ComponentNodeController = exports.AbstractComponentController = exports.componentConfigurationApi = exports.ActionsController = void 0;
7
- var actions_controller_1 = require("./actions-controller");
8
- Object.defineProperty(exports, "ActionsController", { enumerable: true, get: function () { return actions_controller_1.ActionsController; } });
9
- var component_configuration_api_1 = require("./component-configuration-api");
10
- Object.defineProperty(exports, "componentConfigurationApi", { enumerable: true, get: function () { return __importDefault(component_configuration_api_1).default; } });
11
- var component_controller_1 = require("./component-controller");
12
- Object.defineProperty(exports, "AbstractComponentController", { enumerable: true, get: function () { return component_controller_1.AbstractComponentController; } });
13
- Object.defineProperty(exports, "ComponentNodeController", { enumerable: true, get: function () { return component_controller_1.ComponentNodeController; } });
14
- var component_node_1 = require("./component-node");
15
- Object.defineProperty(exports, "ComponentNode", { enumerable: true, get: function () { return component_node_1.ComponentNode; } });
16
- var component_platform_1 = require("./component-platform");
17
- Object.defineProperty(exports, "ComponentPlatform", { enumerable: true, get: function () { return component_platform_1.ComponentPlatform; } });
18
- var component_query_1 = require("./component-query");
19
- Object.defineProperty(exports, "ComponentQuery", { enumerable: true, get: function () { return component_query_1.ComponentQuery; } });
20
- var create_component_model_1 = require("./create-component-model");
21
- Object.defineProperty(exports, "createChildren", { enumerable: true, get: function () { return create_component_model_1.createChildren; } });
22
- Object.defineProperty(exports, "createComponentModel", { enumerable: true, get: function () { return create_component_model_1.createComponentModel; } });
23
- var descriptor_1 = require("./descriptor");
24
- Object.defineProperty(exports, "asDescriptor", { enumerable: true, get: function () { return descriptor_1.asDescriptor; } });
25
- var extend_component_1 = require("./extend-component");
26
- Object.defineProperty(exports, "extendComponent", { enumerable: true, get: function () { return extend_component_1.extendComponent; } });
27
- var queries_1 = require("./queries");
28
- Object.defineProperty(exports, "findComponent", { enumerable: true, get: function () { return queries_1.findComponent; } });
29
- Object.defineProperty(exports, "findVisibleComponents", { enumerable: true, get: function () { return queries_1.findVisibleComponents; } });
30
- Object.defineProperty(exports, "traverseComponents", { enumerable: true, get: function () { return queries_1.traverseComponents; } });
@@ -1,6 +0,0 @@
1
- import { ComponentNode } from './component-node';
2
- import { SwitchMap } from './component-platform';
3
- export declare const traverseComponents: (root: ComponentNode, switches: SwitchMap, fn: (node: ComponentNode) => boolean | void) => void;
4
- export declare const findVisibleComponents: (root: ComponentNode, switches: SwitchMap) => ComponentNode[];
5
- export declare const findComponent: (root: ComponentNode, switches: SwitchMap, fn: (node: ComponentNode) => boolean) => ComponentNode | undefined;
6
- export declare const getAncestors: (node: ComponentNode) => ComponentNode[];
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAncestors = exports.findComponent = exports.findVisibleComponents = exports.traverseComponents = void 0;
4
- var traverseComponentsRecursive = function (nodes, switches, fn) {
5
- for (var i = 0, y = nodes.length; i < y; i++) {
6
- if (fn(nodes[i]) === true) {
7
- break;
8
- }
9
- var branch = switches[nodes[i].id] || 'default';
10
- var children = nodes[i].getChildren(branch);
11
- traverseComponentsRecursive(children, switches, fn);
12
- }
13
- };
14
- var traverseComponents = function (root, switches, fn) {
15
- if (fn(root) !== true) {
16
- var branch = switches[root.id] || 'default';
17
- var children = root.children[branch];
18
- traverseComponentsRecursive(children, switches, fn);
19
- }
20
- };
21
- exports.traverseComponents = traverseComponents;
22
- var findVisibleComponents = function (root, switches) {
23
- var nodes = [];
24
- (0, exports.traverseComponents)(root, switches, function (node) {
25
- nodes.push(node);
26
- });
27
- return nodes;
28
- };
29
- exports.findVisibleComponents = findVisibleComponents;
30
- var findComponent = function (root, switches, fn) {
31
- var matched;
32
- (0, exports.traverseComponents)(root, switches, function (node) {
33
- if (fn(node)) {
34
- matched = node;
35
- return true;
36
- }
37
- });
38
- return matched;
39
- };
40
- exports.findComponent = findComponent;
41
- var getAncestors = function (node) {
42
- if (!node.parent) {
43
- return [];
44
- }
45
- var tree = [];
46
- var currentNode = node.parent;
47
- while (currentNode) {
48
- tree.unshift(currentNode);
49
- currentNode = currentNode.parent;
50
- }
51
- return tree;
52
- };
53
- exports.getAncestors = getAncestors;