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