@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.
- package/LICENSE.txt +6 -0
- package/README.md +3 -0
- package/lib/action-resolver.d.ts +8 -0
- package/lib/action-resolver.js +19 -0
- package/lib/component-platform/actions-controller.d.ts +40 -0
- package/lib/component-platform/actions-controller.js +119 -0
- package/lib/component-platform/changeset-provider.d.ts +8 -0
- package/lib/component-platform/changeset-provider.js +2 -0
- package/lib/component-platform/component-controller.d.ts +38 -0
- package/lib/component-platform/component-controller.js +119 -0
- package/lib/component-platform/component-node-collection.d.ts +18 -0
- package/lib/component-platform/component-node-collection.js +51 -0
- package/lib/component-platform/component-node.d.ts +63 -0
- package/lib/component-platform/component-node.js +190 -0
- package/lib/component-platform/component-platform.d.ts +50 -0
- package/lib/component-platform/component-platform.js +209 -0
- package/lib/component-platform/component-query.d.ts +16 -0
- package/lib/component-platform/component-query.js +35 -0
- package/lib/component-platform/create-component-model.d.ts +19 -0
- package/lib/component-platform/create-component-model.js +126 -0
- package/lib/component-platform/descriptor.d.ts +8 -0
- package/lib/component-platform/descriptor.js +12 -0
- package/lib/component-platform/extend-component.d.ts +8 -0
- package/lib/component-platform/extend-component.js +57 -0
- package/lib/component-platform/index.d.ts +16 -0
- package/lib/component-platform/index.js +24 -0
- package/lib/component-platform/queries.d.ts +6 -0
- package/lib/component-platform/queries.js +53 -0
- package/lib/component-platform/state-processor.d.ts +12 -0
- package/lib/component-platform/state-processor.js +209 -0
- package/lib/component-resolver.d.ts +14 -0
- package/lib/component-resolver.js +49 -0
- package/lib/event-subscriber.d.ts +7 -0
- package/lib/event-subscriber.js +22 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +39 -0
- package/lib/types/configuration.d.ts +86 -0
- package/lib/types/configuration.js +16 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +18 -0
- package/lib/types/ui.d.ts +55 -0
- package/lib/types/ui.js +2 -0
- package/lib-esm/action-resolver.d.ts +8 -0
- package/lib-esm/action-resolver.js +17 -0
- package/lib-esm/component-platform/actions-controller.d.ts +40 -0
- package/lib-esm/component-platform/actions-controller.js +116 -0
- package/lib-esm/component-platform/changeset-provider.d.ts +8 -0
- package/lib-esm/component-platform/changeset-provider.js +1 -0
- package/lib-esm/component-platform/component-controller.d.ts +38 -0
- package/lib-esm/component-platform/component-controller.js +116 -0
- package/lib-esm/component-platform/component-node-collection.d.ts +18 -0
- package/lib-esm/component-platform/component-node-collection.js +48 -0
- package/lib-esm/component-platform/component-node.d.ts +63 -0
- package/lib-esm/component-platform/component-node.js +187 -0
- package/lib-esm/component-platform/component-platform.d.ts +50 -0
- package/lib-esm/component-platform/component-platform.js +206 -0
- package/lib-esm/component-platform/component-query.d.ts +16 -0
- package/lib-esm/component-platform/component-query.js +32 -0
- package/lib-esm/component-platform/create-component-model.d.ts +19 -0
- package/lib-esm/component-platform/create-component-model.js +121 -0
- package/lib-esm/component-platform/descriptor.d.ts +8 -0
- package/lib-esm/component-platform/descriptor.js +8 -0
- package/lib-esm/component-platform/extend-component.d.ts +8 -0
- package/lib-esm/component-platform/extend-component.js +53 -0
- package/lib-esm/component-platform/index.d.ts +16 -0
- package/lib-esm/component-platform/index.js +9 -0
- package/lib-esm/component-platform/queries.d.ts +6 -0
- package/lib-esm/component-platform/queries.js +46 -0
- package/lib-esm/component-platform/state-processor.d.ts +12 -0
- package/lib-esm/component-platform/state-processor.js +205 -0
- package/lib-esm/component-resolver.d.ts +14 -0
- package/lib-esm/component-resolver.js +47 -0
- package/lib-esm/event-subscriber.d.ts +7 -0
- package/lib-esm/event-subscriber.js +18 -0
- package/lib-esm/index.d.ts +8 -0
- package/lib-esm/index.js +5 -0
- package/lib-esm/types/configuration.d.ts +86 -0
- package/lib-esm/types/configuration.js +13 -0
- package/lib-esm/types/index.d.ts +2 -0
- package/lib-esm/types/index.js +2 -0
- package/lib-esm/types/ui.d.ts +55 -0
- package/lib-esm/types/ui.js +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { ActionsController } from './actions-controller';
|
|
2
|
+
export type { WatchActionDelegate } from './actions-controller';
|
|
3
|
+
export type { ChangesetProvider } from './changeset-provider';
|
|
4
|
+
export { AbstractComponentController, ComponentNodeController } from './component-controller';
|
|
5
|
+
export { ComponentNode } from './component-node';
|
|
6
|
+
export type { ChangesetOptions, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, Size, } from './component-node';
|
|
7
|
+
export { ComponentPlatform } from './component-platform';
|
|
8
|
+
export type { SwitchMap } from './component-platform';
|
|
9
|
+
export { ComponentQuery } from './component-query';
|
|
10
|
+
export type { ComponentQueryRule } from './component-query';
|
|
11
|
+
export { createComponentModel } from './create-component-model';
|
|
12
|
+
export { asDescriptor } from './descriptor';
|
|
13
|
+
export type { ComponentDescriptor } from './descriptor';
|
|
14
|
+
export { extendComponent } from './extend-component';
|
|
15
|
+
export type { ExtendComponentHandler, ExtendComponentOptions } from './extend-component';
|
|
16
|
+
export { findComponent, findVisibleComponents, traverseComponents } from './queries';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ActionsController } from './actions-controller';
|
|
2
|
+
export { AbstractComponentController, ComponentNodeController } from './component-controller';
|
|
3
|
+
export { ComponentNode } from './component-node';
|
|
4
|
+
export { ComponentPlatform } from './component-platform';
|
|
5
|
+
export { ComponentQuery } from './component-query';
|
|
6
|
+
export { createComponentModel } from './create-component-model';
|
|
7
|
+
export { asDescriptor } from './descriptor';
|
|
8
|
+
export { extendComponent } from './extend-component';
|
|
9
|
+
export { findComponent, findVisibleComponents, traverseComponents } from './queries';
|
|
@@ -0,0 +1,6 @@
|
|
|
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[];
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
var calculateNodeIndex = function (node) {
|
|
27
|
+
var currentNode = node;
|
|
28
|
+
var index = 0;
|
|
29
|
+
while (currentNode.parent) {
|
|
30
|
+
index = index + 1;
|
|
31
|
+
currentNode = currentNode.parent;
|
|
32
|
+
}
|
|
33
|
+
return index;
|
|
34
|
+
};
|
|
35
|
+
var sortQueue = function (queue) {
|
|
36
|
+
var mapped = queue.map(function (_a) {
|
|
37
|
+
var _b = __read(_a, 2), node = _b[0], options = _b[1];
|
|
38
|
+
return [calculateNodeIndex(node), node, options];
|
|
39
|
+
});
|
|
40
|
+
return mapped
|
|
41
|
+
.sort(function (_a, _b) {
|
|
42
|
+
var _c = __read(_a, 1), a = _c[0];
|
|
43
|
+
var _d = __read(_b, 1), b = _d[0];
|
|
44
|
+
return a - b;
|
|
45
|
+
})
|
|
46
|
+
.map(function (_a) {
|
|
47
|
+
var _b = __read(_a, 3), node = _b[1], options = _b[2];
|
|
48
|
+
return [node, options];
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var isObject = function (item) {
|
|
52
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
53
|
+
};
|
|
54
|
+
var mergeDeep = function (target) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
var sources = [];
|
|
57
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
58
|
+
sources[_i - 1] = arguments[_i];
|
|
59
|
+
}
|
|
60
|
+
if (!sources.length)
|
|
61
|
+
return target;
|
|
62
|
+
var source = sources.shift();
|
|
63
|
+
if (isObject(target) && isObject(source)) {
|
|
64
|
+
for (var key in source) {
|
|
65
|
+
if (isObject(source[key])) {
|
|
66
|
+
if (!target[key])
|
|
67
|
+
Object.assign(target, (_a = {}, _a[key] = {}, _a));
|
|
68
|
+
mergeDeep(target[key], source[key]);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return mergeDeep.apply(void 0, __spreadArray([target], __read(sources), false));
|
|
76
|
+
};
|
|
77
|
+
var matchesBreakpoint = function (b1, b2) {
|
|
78
|
+
if (!b1 || b1 === 'all') {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return b1.some(function (b1) { return b2.indexOf(b1) > -1; });
|
|
82
|
+
};
|
|
83
|
+
export var createStateProcessor = function (platform, callback) {
|
|
84
|
+
var nodeQueue = [];
|
|
85
|
+
var optionsQueue = [];
|
|
86
|
+
var timeout;
|
|
87
|
+
var flush = function () {
|
|
88
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
89
|
+
console.time('state-processor.flush');
|
|
90
|
+
}
|
|
91
|
+
var processHistory = new Map();
|
|
92
|
+
var sortedQueue = sortQueue(nodeQueue.map(function (node, i) { return [node, optionsQueue[i]]; }));
|
|
93
|
+
var processNode = function (node, options) {
|
|
94
|
+
var _a;
|
|
95
|
+
var history = processHistory.get(node) || {};
|
|
96
|
+
// todo: this doesnt take overrides into account
|
|
97
|
+
var processContext = options.context && !history.context;
|
|
98
|
+
var processProperties = options.properties && !history.properties;
|
|
99
|
+
var processLayout = options.layout && !history.layout;
|
|
100
|
+
processHistory.set(node, {
|
|
101
|
+
context: history.context || processContext,
|
|
102
|
+
properties: history.properties || processProperties,
|
|
103
|
+
layout: history.layout || processLayout,
|
|
104
|
+
});
|
|
105
|
+
if (processProperties) {
|
|
106
|
+
node.attributes.properties = {};
|
|
107
|
+
}
|
|
108
|
+
if (processLayout) {
|
|
109
|
+
node.attributes.layout = {};
|
|
110
|
+
}
|
|
111
|
+
if (processContext) {
|
|
112
|
+
node.attributes.context = mergeDeep({}, (_a = node.parent) === null || _a === void 0 ? void 0 : _a.attributes.context);
|
|
113
|
+
}
|
|
114
|
+
var propertyResolvers = [];
|
|
115
|
+
var layoutResolvers = [];
|
|
116
|
+
var contextResolvers = [];
|
|
117
|
+
node.changesets.forEach(function (changeset) {
|
|
118
|
+
var _a = __read(changeset, 2), change = _a[0], options = _a[1];
|
|
119
|
+
if (matchesBreakpoint(options.breakpoints, platform.breakpoints)) {
|
|
120
|
+
if (processProperties) {
|
|
121
|
+
if (typeof change.properties === 'function') {
|
|
122
|
+
propertyResolvers.push(change.properties);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
mergeDeep(node.attributes.properties, change.properties);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (processLayout) {
|
|
129
|
+
if (typeof change.layout === 'function') {
|
|
130
|
+
layoutResolvers.push(change.layout);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
mergeDeep(node.attributes.layout, change.layout);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (processContext) {
|
|
137
|
+
if (typeof change.context === 'function') {
|
|
138
|
+
contextResolvers.push(change.context);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
mergeDeep(node.attributes.context, change.context);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
propertyResolvers.forEach(function (resolver) {
|
|
147
|
+
mergeDeep(node.attributes.properties, resolver(node.attributes.properties));
|
|
148
|
+
});
|
|
149
|
+
layoutResolvers.forEach(function (resolver) {
|
|
150
|
+
mergeDeep(node.attributes.layout, resolver(node.attributes.layout));
|
|
151
|
+
});
|
|
152
|
+
contextResolvers.forEach(function (resolver) {
|
|
153
|
+
mergeDeep(node.attributes.context, resolver(node.attributes.context));
|
|
154
|
+
});
|
|
155
|
+
if (processContext || options.recursive) {
|
|
156
|
+
var branch = platform.getBranch(node);
|
|
157
|
+
var childOptions_1 = options.recursive
|
|
158
|
+
? options
|
|
159
|
+
: {
|
|
160
|
+
context: !!processContext,
|
|
161
|
+
};
|
|
162
|
+
node.getChildren(branch).forEach(function (child) {
|
|
163
|
+
processNode(child, childOptions_1);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
168
|
+
console.timeEnd('state-processor.flush');
|
|
169
|
+
}
|
|
170
|
+
sortedQueue.forEach(function (_a) {
|
|
171
|
+
var _b = __read(_a, 2), node = _b[0], options = _b[1];
|
|
172
|
+
processNode(node, options);
|
|
173
|
+
});
|
|
174
|
+
nodeQueue = [];
|
|
175
|
+
optionsQueue = [];
|
|
176
|
+
callback(processHistory);
|
|
177
|
+
};
|
|
178
|
+
var schedule = function () {
|
|
179
|
+
clearTimeout(timeout);
|
|
180
|
+
timeout = setTimeout(flush, 0);
|
|
181
|
+
};
|
|
182
|
+
return function (node, options) {
|
|
183
|
+
var index = nodeQueue.indexOf(node);
|
|
184
|
+
if (index > -1) {
|
|
185
|
+
// if node already exist in queue, update its options
|
|
186
|
+
var summary = optionsQueue[index];
|
|
187
|
+
if (options.context) {
|
|
188
|
+
summary.context = true;
|
|
189
|
+
}
|
|
190
|
+
if (options.properties) {
|
|
191
|
+
summary.properties = true;
|
|
192
|
+
}
|
|
193
|
+
if (options.layout) {
|
|
194
|
+
summary.layout = true;
|
|
195
|
+
}
|
|
196
|
+
if (options.recursive) {
|
|
197
|
+
summary.recursive = true;
|
|
198
|
+
}
|
|
199
|
+
return schedule();
|
|
200
|
+
}
|
|
201
|
+
nodeQueue.push(node);
|
|
202
|
+
optionsQueue.push(options);
|
|
203
|
+
return schedule();
|
|
204
|
+
};
|
|
205
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger } from '@telia-ace/widget-utilities';
|
|
2
|
+
import { Container, EventManager, EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
3
|
+
export declare type ReactComponent = any | null;
|
|
4
|
+
export default class ComponentResolver {
|
|
5
|
+
aliases: Map<string, string>;
|
|
6
|
+
components: Map<string, any>;
|
|
7
|
+
events: EventManager;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
constructor(container: Container);
|
|
10
|
+
getComponent(key: string): ReactComponent;
|
|
11
|
+
registerComponent(key: string, component: ReactComponent): EventSubscriptionCancellation;
|
|
12
|
+
registerResolver(key: string, fn: (component: ReactComponent) => void): EventSubscriptionCancellation;
|
|
13
|
+
registerAlias(alias: string, key: string): EventSubscriptionCancellation;
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Logger } from '@telia-ace/widget-utilities';
|
|
2
|
+
var ComponentResolver = /** @class */ (function () {
|
|
3
|
+
function ComponentResolver(container) {
|
|
4
|
+
this.aliases = new Map();
|
|
5
|
+
this.components = new Map();
|
|
6
|
+
this.logger = new Logger();
|
|
7
|
+
var events = container.get('$widget').events;
|
|
8
|
+
this.events = events;
|
|
9
|
+
}
|
|
10
|
+
ComponentResolver.prototype.getComponent = function (key) {
|
|
11
|
+
var alias = this.aliases.get(key);
|
|
12
|
+
var component = this.components.get(alias || key) || null;
|
|
13
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
+
if (!component) {
|
|
15
|
+
this.logger.warn(alias || key, "Unable to resolve component: \"".concat(alias || key, "\". You most likely forgot to register the required plugin for: ").concat(alias || key, "."));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return component;
|
|
19
|
+
};
|
|
20
|
+
ComponentResolver.prototype.registerComponent = function (key, component) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
this.components.set(key, component);
|
|
23
|
+
this.events.dispatch('component-resolver:resolve', key);
|
|
24
|
+
return function () {
|
|
25
|
+
_this.components.delete(key);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
ComponentResolver.prototype.registerResolver = function (key, fn) {
|
|
29
|
+
var _this = this;
|
|
30
|
+
return this.events.subscribe('component-resolver:resolve', function (e, data) {
|
|
31
|
+
if (data === key) {
|
|
32
|
+
var component = _this.getComponent(key);
|
|
33
|
+
fn(component);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
ComponentResolver.prototype.registerAlias = function (alias, key) {
|
|
38
|
+
var _this = this;
|
|
39
|
+
this.aliases.set(alias, key);
|
|
40
|
+
this.events.dispatch('component-resolver:resolve', alias);
|
|
41
|
+
return function () {
|
|
42
|
+
_this.aliases.delete(alias);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
return ComponentResolver;
|
|
46
|
+
}());
|
|
47
|
+
export default ComponentResolver;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventListener, EventManager, EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
2
|
+
export declare type SubscribeDelegate = (type: string, listener: EventListener) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Creates s subscriber for the specified `EventManager` and provides a single cancellation
|
|
5
|
+
* function for all registered subscriptions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createEventSubscriber: (events: EventManager) => [SubscribeDelegate, EventSubscriptionCancellation];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates s subscriber for the specified `EventManager` and provides a single cancellation
|
|
3
|
+
* function for all registered subscriptions.
|
|
4
|
+
*/
|
|
5
|
+
export var createEventSubscriber = function (events) {
|
|
6
|
+
var subs = [];
|
|
7
|
+
var subscribe = function (type, listener) {
|
|
8
|
+
subs.push(events.subscribe(type, listener));
|
|
9
|
+
};
|
|
10
|
+
return [
|
|
11
|
+
subscribe,
|
|
12
|
+
function () {
|
|
13
|
+
subs.forEach(function (sub) {
|
|
14
|
+
sub();
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as ActionResolver } from './action-resolver';
|
|
2
|
+
export { ActionsController, asDescriptor, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
|
|
3
|
+
export type { ChangesetOptions, ChangesetProvider, ComponentDescriptor, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, ComponentQueryRule, ExtendComponentHandler, ExtendComponentOptions, Size, SwitchMap, WatchActionDelegate, } from './component-platform';
|
|
4
|
+
export { default as ComponentResolver } from './component-resolver';
|
|
5
|
+
export type { ReactComponent } from './component-resolver';
|
|
6
|
+
export { createEventSubscriber } from './event-subscriber';
|
|
7
|
+
export type { SubscribeDelegate } from './event-subscriber';
|
|
8
|
+
export * from './types';
|
package/lib-esm/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as ActionResolver } from './action-resolver';
|
|
2
|
+
export { ActionsController, asDescriptor, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
|
|
3
|
+
export { default as ComponentResolver } from './component-resolver';
|
|
4
|
+
export { createEventSubscriber } from './event-subscriber';
|
|
5
|
+
export * from './types';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ComponentNodeLayout } from '../component-platform';
|
|
2
|
+
export declare type ComponentSettings = {
|
|
3
|
+
type: string;
|
|
4
|
+
context?: Context;
|
|
5
|
+
properties?: Properties;
|
|
6
|
+
layout?: ComponentNodeLayout;
|
|
7
|
+
tags?: string[];
|
|
8
|
+
children?: ComponentReference[];
|
|
9
|
+
};
|
|
10
|
+
declare enum HistoryMode {
|
|
11
|
+
scopedHash = "scopedHash",
|
|
12
|
+
hash = "hash",
|
|
13
|
+
browser = "browser",
|
|
14
|
+
memory = "memory"
|
|
15
|
+
}
|
|
16
|
+
export declare type RoutingSettings = {
|
|
17
|
+
initialPath: string;
|
|
18
|
+
mode: HistoryMode;
|
|
19
|
+
basePath?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare type ComponentReference = string | [string, ...ComponentReferenceOverride[]];
|
|
22
|
+
export declare type Properties = {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
export declare type Context = {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
export declare type ViewDefinition = {
|
|
29
|
+
path: string | string[];
|
|
30
|
+
entry: ComponentReference;
|
|
31
|
+
};
|
|
32
|
+
export declare type Breakpoints = 'all' | string[];
|
|
33
|
+
export declare type ComponentReferenceOverride = {
|
|
34
|
+
breakpoints?: Breakpoints;
|
|
35
|
+
size?: number | 'full' | 'none';
|
|
36
|
+
indent?: number;
|
|
37
|
+
tags?: string[];
|
|
38
|
+
context?: Context;
|
|
39
|
+
properties?: Properties;
|
|
40
|
+
};
|
|
41
|
+
export declare type ComponentDefinitionMap = {
|
|
42
|
+
[name: string]: ComponentSettings;
|
|
43
|
+
};
|
|
44
|
+
export declare type WidgetSettings = {
|
|
45
|
+
data: {
|
|
46
|
+
projection: string;
|
|
47
|
+
site?: 'current' | 'referrer';
|
|
48
|
+
forceHttps?: boolean;
|
|
49
|
+
};
|
|
50
|
+
components: ComponentDefinitionMap;
|
|
51
|
+
entry: ComponentReference;
|
|
52
|
+
breakpoints: {
|
|
53
|
+
[name: string]: string;
|
|
54
|
+
};
|
|
55
|
+
routing: RoutingSettings;
|
|
56
|
+
views: {
|
|
57
|
+
[name: string]: ViewDefinition;
|
|
58
|
+
};
|
|
59
|
+
integrationResources: {
|
|
60
|
+
path: string;
|
|
61
|
+
mediaQueriesSupported: boolean;
|
|
62
|
+
}[];
|
|
63
|
+
trigger?: {
|
|
64
|
+
symbol?: Symbol;
|
|
65
|
+
label?: string;
|
|
66
|
+
action?: string;
|
|
67
|
+
};
|
|
68
|
+
activate?: boolean | null;
|
|
69
|
+
plugins?: {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export declare type MinMax = {
|
|
74
|
+
min: string;
|
|
75
|
+
max: string;
|
|
76
|
+
};
|
|
77
|
+
declare type Symbol = {
|
|
78
|
+
type: 'Uri' | 'Svg' | 'FontAwesome' | 'Text' | string;
|
|
79
|
+
content: string;
|
|
80
|
+
};
|
|
81
|
+
export declare enum WidgetRenderState {
|
|
82
|
+
open = "open",
|
|
83
|
+
closed = "closed",
|
|
84
|
+
hidden = "hidden"
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var HistoryMode;
|
|
2
|
+
(function (HistoryMode) {
|
|
3
|
+
HistoryMode["scopedHash"] = "scopedHash";
|
|
4
|
+
HistoryMode["hash"] = "hash";
|
|
5
|
+
HistoryMode["browser"] = "browser";
|
|
6
|
+
HistoryMode["memory"] = "memory";
|
|
7
|
+
})(HistoryMode || (HistoryMode = {}));
|
|
8
|
+
export var WidgetRenderState;
|
|
9
|
+
(function (WidgetRenderState) {
|
|
10
|
+
WidgetRenderState["open"] = "open";
|
|
11
|
+
WidgetRenderState["closed"] = "closed";
|
|
12
|
+
WidgetRenderState["hidden"] = "hidden";
|
|
13
|
+
})(WidgetRenderState || (WidgetRenderState = {}));
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type Theme = {
|
|
3
|
+
gap: string;
|
|
4
|
+
accessibility: {
|
|
5
|
+
isTabbing: boolean;
|
|
6
|
+
border: string;
|
|
7
|
+
colors: {
|
|
8
|
+
inactiveText: string;
|
|
9
|
+
activeText: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
border: string;
|
|
13
|
+
borderRadius: string;
|
|
14
|
+
boxShadow: string;
|
|
15
|
+
inputBorder: string;
|
|
16
|
+
colors: {
|
|
17
|
+
warning: string;
|
|
18
|
+
accent: string;
|
|
19
|
+
link: string;
|
|
20
|
+
primary: string;
|
|
21
|
+
text: string;
|
|
22
|
+
textLight: string;
|
|
23
|
+
};
|
|
24
|
+
fonts: {
|
|
25
|
+
type: string;
|
|
26
|
+
base: string;
|
|
27
|
+
small: string;
|
|
28
|
+
normal: string;
|
|
29
|
+
medium: string;
|
|
30
|
+
large: string;
|
|
31
|
+
huge: string;
|
|
32
|
+
};
|
|
33
|
+
sizes: {
|
|
34
|
+
cardinal: number;
|
|
35
|
+
small: string;
|
|
36
|
+
normal: string;
|
|
37
|
+
medium: string;
|
|
38
|
+
large: string;
|
|
39
|
+
};
|
|
40
|
+
typographyVariantMapping?: {
|
|
41
|
+
h1: 'h1';
|
|
42
|
+
h2: 'h2';
|
|
43
|
+
h3: 'h3';
|
|
44
|
+
h4: 'h4';
|
|
45
|
+
h5: 'h5';
|
|
46
|
+
h6: 'h6';
|
|
47
|
+
p: 'p';
|
|
48
|
+
span: 'span';
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export declare type ModeWrapper = React.FC<{
|
|
52
|
+
className: string;
|
|
53
|
+
route: string;
|
|
54
|
+
isTabbing: boolean;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/widget-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Core framework for ACE widgets.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"author": "Telia Company AB",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"telia"
|
|
9
|
+
],
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"module": "lib-esm/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"LICENSE.txt",
|
|
14
|
+
"README.md",
|
|
15
|
+
"lib/",
|
|
16
|
+
"lib-esm/"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "cleandir lib && cleandir lib-esm",
|
|
23
|
+
"compile": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && node scripts/print-version.js"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"typings": "lib/index.d.ts",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@telia-ace/widget-utilities": "^1.0.1",
|
|
29
|
+
"@webprovisions/bootstrapping": "^1.0.12",
|
|
30
|
+
"@webprovisions/platform": "^1.1.2"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "a45fde2bae0981a2a791a2362f2ecaf53430570b"
|
|
33
|
+
}
|