@telia-ace/widget-core 1.0.0 → 1.0.4

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 (29) hide show
  1. package/LICENSE.txt +5 -5
  2. package/README.md +3 -3
  3. package/lib/component-platform/component-configuration-api.d.ts +2 -0
  4. package/lib/component-platform/component-configuration-api.js +32 -0
  5. package/lib/component-platform/component-platform.d.ts +4 -0
  6. package/lib/component-platform/component-platform.js +11 -0
  7. package/lib/component-platform/create-component-model.d.ts +20 -3
  8. package/lib/component-platform/create-component-model.js +30 -15
  9. package/lib/component-platform/custom-component-handler.d.ts +21 -0
  10. package/lib/component-platform/custom-component-handler.js +16 -0
  11. package/lib/component-platform/index.d.ts +3 -1
  12. package/lib/component-platform/index.js +7 -1
  13. package/lib/index.d.ts +2 -2
  14. package/lib/index.js +3 -1
  15. package/lib/types/ui.d.ts +0 -1
  16. package/lib-esm/component-platform/component-configuration-api.d.ts +2 -0
  17. package/lib-esm/component-platform/component-configuration-api.js +30 -0
  18. package/lib-esm/component-platform/component-platform.d.ts +4 -0
  19. package/lib-esm/component-platform/component-platform.js +11 -0
  20. package/lib-esm/component-platform/create-component-model.d.ts +20 -3
  21. package/lib-esm/component-platform/create-component-model.js +27 -13
  22. package/lib-esm/component-platform/custom-component-handler.d.ts +21 -0
  23. package/lib-esm/component-platform/custom-component-handler.js +13 -0
  24. package/lib-esm/component-platform/index.d.ts +3 -1
  25. package/lib-esm/component-platform/index.js +2 -1
  26. package/lib-esm/index.d.ts +2 -2
  27. package/lib-esm/index.js +1 -1
  28. package/lib-esm/types/ui.d.ts +0 -1
  29. package/package.json +2 -2
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
- Copyright © 2021, Telia Company AB. All rights reserved.
2
-
3
- THIS PACKAGE AND CONTAINING SOFTWARE IS PART OF
4
- THE HUMANY SERVICE. BY USING THIS SOFTWARE YOU
5
- AGREE TO THE FOLLOWING TERMS AND CONDITIONS:
1
+ Copyright © 2021, Telia Company AB. All rights reserved.
2
+
3
+ THIS PACKAGE AND CONTAINING SOFTWARE IS PART OF
4
+ THE HUMANY SERVICE. BY USING THIS SOFTWARE YOU
5
+ AGREE TO THE FOLLOWING TERMS AND CONDITIONS:
6
6
  http://www.humany.com/legal
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # `@telia-ace/widget-core`
2
-
3
- Core framework for ACE widgets.
1
+ # `@telia-ace/widget-core`
2
+
3
+ Core framework for ACE widgets.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@webprovisions/platform").ConfigurationApiDefinition;
2
+ export default _default;
@@ -0,0 +1,32 @@
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
+ var platform_1 = require("@webprovisions/platform");
20
+ exports.default = (0, platform_1.createConfigurationApi)(function (builder) {
21
+ builder.createCommand('components', function (context) { return function (config) {
22
+ context.events.subscribeOnce('components:platform-created', function (event, _a) {
23
+ var platform = _a.platform;
24
+ if (config.handlers) {
25
+ config.handlers.forEach(function (_a) {
26
+ var _b = __read(_a, 2), key = _b[0], handler = _b[1];
27
+ platform.addComponentHandler(key, handler);
28
+ });
29
+ }
30
+ });
31
+ }; });
32
+ });
@@ -4,6 +4,7 @@ import { ChangesetProvider } from './changeset-provider';
4
4
  import { ChangesetOptions, ComponentNode, ComponentNodeSettings, RemoveChangeset } from './component-node';
5
5
  import { ComponentNodeCollection } from './component-node-collection';
6
6
  import { ComponentQuery } from './component-query';
7
+ import { CustomHandlerCallback } from './custom-component-handler';
7
8
  export declare type MergeOptions = {
8
9
  breakpoints?: string[];
9
10
  };
@@ -28,6 +29,7 @@ export declare class ComponentPlatform {
28
29
  private changesets;
29
30
  private subscriptions;
30
31
  private processNode;
32
+ private customComponentHandler;
31
33
  constructor(widget: Widget, providers?: {
32
34
  [key: string]: ChangesetProvider;
33
35
  });
@@ -46,5 +48,7 @@ export declare class ComponentPlatform {
46
48
  components(): ComponentQuery;
47
49
  actions(target: ComponentQuery, ns: string): ActionsController;
48
50
  write(data: ChangesetData): RemoveChangeset;
51
+ addComponentHandler(definitionType: string, fn: CustomHandlerCallback): void;
52
+ getComponentHandler(definitionType: string): CustomHandlerCallback | undefined;
49
53
  dispose(): void;
50
54
  }
@@ -22,6 +22,7 @@ var actions_controller_1 = require("./actions-controller");
22
22
  var component_node_1 = require("./component-node");
23
23
  var component_node_collection_1 = require("./component-node-collection");
24
24
  var component_query_1 = require("./component-query");
25
+ var custom_component_handler_1 = require("./custom-component-handler");
25
26
  var state_processor_1 = require("./state-processor");
26
27
  var ComponentPlatform = /** @class */ (function () {
27
28
  function ComponentPlatform(widget, providers) {
@@ -34,6 +35,7 @@ var ComponentPlatform = /** @class */ (function () {
34
35
  this.switches = {};
35
36
  this.changesets = [];
36
37
  this.subscriptions = [];
38
+ this.customComponentHandler = new custom_component_handler_1.CustomComponentHandler();
37
39
  this.events = widget.events.createChild(this);
38
40
  var root = new component_node_1.ComponentNode(this.events, 'root');
39
41
  root.name = "root-".concat(widget.name);
@@ -110,6 +112,9 @@ var ComponentPlatform = /** @class */ (function () {
110
112
  var parentNode = _a.parentNode;
111
113
  processNode(parentNode, { properties: true });
112
114
  }));
115
+ if (this.events.parent) {
116
+ this.events.parent.dispatch('components:platform-created', { platform: this });
117
+ }
113
118
  }
114
119
  ComponentPlatform.getInstance = function (container) {
115
120
  return container.getAsync('components');
@@ -201,6 +206,12 @@ var ComponentPlatform = /** @class */ (function () {
201
206
  }
202
207
  };
203
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
+ };
204
215
  ComponentPlatform.prototype.dispose = function () {
205
216
  this.subscriptions.forEach(function (sub) { return sub(); });
206
217
  };
@@ -1,6 +1,6 @@
1
1
  import { EventSubscriptionCancellation } from '@webprovisions/platform';
2
- import { Breakpoints, WidgetSettings } from '../types';
3
- import { ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
2
+ import { Breakpoints, ComponentSettings, ViewDefinition, WidgetSettings } from '../types';
3
+ import { ComponentNode, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
4
4
  import { ComponentPlatform } from './component-platform';
5
5
  declare type ComponentReference = string | [string, ...ComponentReferenceOverride[]];
6
6
  declare type ComponentReferenceOverride = {
@@ -10,10 +10,27 @@ declare type ComponentReferenceOverride = {
10
10
  properties?: ComponentNodeProperties;
11
11
  layout?: ComponentNodeLayout;
12
12
  };
13
- declare type NormalizedComponentReference = {
13
+ export declare type NormalizedComponentReference = {
14
14
  definitionId: string;
15
15
  overrides: ComponentReferenceOverride[];
16
16
  };
17
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;
18
35
  export declare const createComponentModel: (platform: ComponentPlatform, settings: WidgetSettings) => EventSubscriptionCancellation;
19
36
  export {};
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
16
16
  return ar;
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.createComponentModel = exports.normalizeReference = void 0;
19
+ exports.createComponentModel = exports.createChildren = exports.normalizeReference = void 0;
20
20
  var widget_utilities_1 = require("@telia-ace/widget-utilities");
21
21
  var normalizeReference = function (reference) {
22
22
  if (Array.isArray(reference)) {
@@ -35,12 +35,13 @@ exports.normalizeReference = normalizeReference;
35
35
  var createChildren = function (platform, node, references, definitions, views, branch) {
36
36
  references.forEach(function (ref) {
37
37
  var childRef = (0, exports.normalizeReference)(ref);
38
+ var childDef = definitions[childRef.definitionId];
38
39
  if (childRef.definitionId === 'view') {
39
40
  var viewNode_1 = platform.createNode('view');
40
41
  viewNode_1.name = 'view';
41
42
  Object.keys(views).forEach(function (key) {
42
43
  var viewDef = views[key];
43
- createChildren(platform, viewNode_1, [viewDef.entry], definitions, views, key);
44
+ (0, exports.createChildren)(platform, viewNode_1, [viewDef.entry], definitions, views, key);
44
45
  });
45
46
  node.appendChild(viewNode_1);
46
47
  childRef.overrides.forEach(function (override) {
@@ -57,25 +58,38 @@ var createChildren = function (platform, node, references, definitions, views, b
57
58
  }
58
59
  });
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
+ }
60
74
  else {
61
- var childDef = definitions[childRef.definitionId];
75
+ var childDef_1 = definitions[childRef.definitionId];
62
76
  if (process.env.NODE_ENV !== 'production') {
63
- if (!childDef) {
77
+ if (!childDef_1) {
64
78
  widget_utilities_1.Logger.error("No definition found for component type '".concat(childRef.definitionId, "'."));
65
79
  return;
66
80
  }
67
81
  }
68
- var childNode_1 = platform.createNode(childDef.type);
82
+ var childNode_1 = platform.createNode(childDef_1.type);
69
83
  childNode_1.name = childRef.definitionId;
70
- childNode_1.tags = childDef.tags || [];
71
- if (childDef.properties) {
72
- childNode_1.writeProperties(childDef.properties);
84
+ childNode_1.tags = childDef_1.tags || [];
85
+ if (childDef_1.properties) {
86
+ childNode_1.writeProperties(childDef_1.properties);
73
87
  }
74
- if (childDef.context) {
75
- childNode_1.writeContext(childDef.context);
88
+ if (childDef_1.context) {
89
+ childNode_1.writeContext(childDef_1.context);
76
90
  }
77
- if (childDef.layout) {
78
- childNode_1.writeLayout(childDef.layout);
91
+ if (childDef_1.layout) {
92
+ childNode_1.writeLayout(childDef_1.layout);
79
93
  }
80
94
  node.appendChild(childNode_1, branch);
81
95
  childRef.overrides.forEach(function (override) {
@@ -90,12 +104,13 @@ var createChildren = function (platform, node, references, definitions, views, b
90
104
  childNode_1.writeLayout(override.layout, options);
91
105
  }
92
106
  });
93
- if (childDef.children) {
94
- createChildren(platform, childNode_1, childDef.children, definitions, views);
107
+ if (childDef_1.children) {
108
+ (0, exports.createChildren)(platform, childNode_1, childDef_1.children, definitions, views);
95
109
  }
96
110
  }
97
111
  });
98
112
  };
113
+ exports.createChildren = createChildren;
99
114
  var createComponentModel = function (platform, settings) {
100
115
  var entry = settings.entry, components = settings.components, breakpoints = settings.breakpoints, views = settings.views;
101
116
  var subscriptions = [];
@@ -116,7 +131,7 @@ var createComponentModel = function (platform, settings) {
116
131
  list.addListener(listener);
117
132
  subscriptions.push(function () { return list.removeListener(listener); });
118
133
  });
119
- createChildren(platform, platform.nodes.root, [entry], components, views);
134
+ (0, exports.createChildren)(platform, platform.nodes.root, [entry], components, views);
120
135
  return function () {
121
136
  return subscriptions.forEach(function (sub) {
122
137
  sub();
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,16 @@
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,6 +1,7 @@
1
1
  export { ActionsController } from './actions-controller';
2
2
  export type { WatchActionDelegate } from './actions-controller';
3
3
  export type { ChangesetProvider } from './changeset-provider';
4
+ export { default as componentConfigurationApi } from './component-configuration-api';
4
5
  export { AbstractComponentController, ComponentNodeController } from './component-controller';
5
6
  export { ComponentNode } from './component-node';
6
7
  export type { ChangesetOptions, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, Size, } from './component-node';
@@ -8,7 +9,8 @@ export { ComponentPlatform } from './component-platform';
8
9
  export type { SwitchMap } from './component-platform';
9
10
  export { ComponentQuery } from './component-query';
10
11
  export type { ComponentQueryRule } from './component-query';
11
- export { createComponentModel } from './create-component-model';
12
+ export { createChildren, createComponentModel } from './create-component-model';
13
+ export type { ComponentHandlerOptions, NormalizedComponentReference, } from './create-component-model';
12
14
  export { asDescriptor } from './descriptor';
13
15
  export type { ComponentDescriptor } from './descriptor';
14
16
  export { extendComponent } from './extend-component';
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseComponents = exports.findVisibleComponents = exports.findComponent = exports.extendComponent = exports.asDescriptor = exports.createComponentModel = exports.ComponentQuery = exports.ComponentPlatform = exports.ComponentNode = exports.ComponentNodeController = exports.AbstractComponentController = exports.ActionsController = void 0;
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;
4
7
  var actions_controller_1 = require("./actions-controller");
5
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; } });
6
11
  var component_controller_1 = require("./component-controller");
7
12
  Object.defineProperty(exports, "AbstractComponentController", { enumerable: true, get: function () { return component_controller_1.AbstractComponentController; } });
8
13
  Object.defineProperty(exports, "ComponentNodeController", { enumerable: true, get: function () { return component_controller_1.ComponentNodeController; } });
@@ -13,6 +18,7 @@ Object.defineProperty(exports, "ComponentPlatform", { enumerable: true, get: fun
13
18
  var component_query_1 = require("./component-query");
14
19
  Object.defineProperty(exports, "ComponentQuery", { enumerable: true, get: function () { return component_query_1.ComponentQuery; } });
15
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; } });
16
22
  Object.defineProperty(exports, "createComponentModel", { enumerable: true, get: function () { return create_component_model_1.createComponentModel; } });
17
23
  var descriptor_1 = require("./descriptor");
18
24
  Object.defineProperty(exports, "asDescriptor", { enumerable: true, get: function () { return descriptor_1.asDescriptor; } });
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
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';
2
+ export { ActionsController, asDescriptor, componentConfigurationApi, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createChildren, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
3
+ export type { ChangesetOptions, ChangesetProvider, ComponentDescriptor, ComponentHandlerOptions, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, ComponentQueryRule, ExtendComponentHandler, ExtendComponentOptions, NormalizedComponentReference, Size, SwitchMap, WatchActionDelegate, } from './component-platform';
4
4
  export { default as ComponentResolver } from './component-resolver';
5
5
  export type { ReactComponent } from './component-resolver';
6
6
  export { createEventSubscriber } from './event-subscriber';
package/lib/index.js CHANGED
@@ -17,16 +17,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.createEventSubscriber = exports.ComponentResolver = exports.traverseComponents = exports.findVisibleComponents = exports.findComponent = exports.extendComponent = exports.createComponentModel = exports.ComponentQuery = exports.ComponentPlatform = exports.ComponentNodeController = exports.ComponentNode = exports.asDescriptor = exports.ActionsController = exports.ActionResolver = void 0;
20
+ exports.createEventSubscriber = exports.ComponentResolver = exports.traverseComponents = exports.findVisibleComponents = exports.findComponent = exports.extendComponent = exports.createComponentModel = exports.createChildren = exports.ComponentQuery = exports.ComponentPlatform = exports.ComponentNodeController = exports.ComponentNode = exports.componentConfigurationApi = exports.asDescriptor = exports.ActionsController = exports.ActionResolver = void 0;
21
21
  var action_resolver_1 = require("./action-resolver");
22
22
  Object.defineProperty(exports, "ActionResolver", { enumerable: true, get: function () { return __importDefault(action_resolver_1).default; } });
23
23
  var component_platform_1 = require("./component-platform");
24
24
  Object.defineProperty(exports, "ActionsController", { enumerable: true, get: function () { return component_platform_1.ActionsController; } });
25
25
  Object.defineProperty(exports, "asDescriptor", { enumerable: true, get: function () { return component_platform_1.asDescriptor; } });
26
+ Object.defineProperty(exports, "componentConfigurationApi", { enumerable: true, get: function () { return component_platform_1.componentConfigurationApi; } });
26
27
  Object.defineProperty(exports, "ComponentNode", { enumerable: true, get: function () { return component_platform_1.ComponentNode; } });
27
28
  Object.defineProperty(exports, "ComponentNodeController", { enumerable: true, get: function () { return component_platform_1.ComponentNodeController; } });
28
29
  Object.defineProperty(exports, "ComponentPlatform", { enumerable: true, get: function () { return component_platform_1.ComponentPlatform; } });
29
30
  Object.defineProperty(exports, "ComponentQuery", { enumerable: true, get: function () { return component_platform_1.ComponentQuery; } });
31
+ Object.defineProperty(exports, "createChildren", { enumerable: true, get: function () { return component_platform_1.createChildren; } });
30
32
  Object.defineProperty(exports, "createComponentModel", { enumerable: true, get: function () { return component_platform_1.createComponentModel; } });
31
33
  Object.defineProperty(exports, "extendComponent", { enumerable: true, get: function () { return component_platform_1.extendComponent; } });
32
34
  Object.defineProperty(exports, "findComponent", { enumerable: true, get: function () { return component_platform_1.findComponent; } });
package/lib/types/ui.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare type Theme = {
3
2
  gap: string;
4
3
  accessibility: {
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@webprovisions/platform").ConfigurationApiDefinition;
2
+ export default _default;
@@ -0,0 +1,30 @@
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 { createConfigurationApi } from '@webprovisions/platform';
18
+ export default createConfigurationApi(function (builder) {
19
+ builder.createCommand('components', function (context) { return function (config) {
20
+ context.events.subscribeOnce('components:platform-created', function (event, _a) {
21
+ var platform = _a.platform;
22
+ if (config.handlers) {
23
+ config.handlers.forEach(function (_a) {
24
+ var _b = __read(_a, 2), key = _b[0], handler = _b[1];
25
+ platform.addComponentHandler(key, handler);
26
+ });
27
+ }
28
+ });
29
+ }; });
30
+ });
@@ -4,6 +4,7 @@ import { ChangesetProvider } from './changeset-provider';
4
4
  import { ChangesetOptions, ComponentNode, ComponentNodeSettings, RemoveChangeset } from './component-node';
5
5
  import { ComponentNodeCollection } from './component-node-collection';
6
6
  import { ComponentQuery } from './component-query';
7
+ import { CustomHandlerCallback } from './custom-component-handler';
7
8
  export declare type MergeOptions = {
8
9
  breakpoints?: string[];
9
10
  };
@@ -28,6 +29,7 @@ export declare class ComponentPlatform {
28
29
  private changesets;
29
30
  private subscriptions;
30
31
  private processNode;
32
+ private customComponentHandler;
31
33
  constructor(widget: Widget, providers?: {
32
34
  [key: string]: ChangesetProvider;
33
35
  });
@@ -46,5 +48,7 @@ export declare class ComponentPlatform {
46
48
  components(): ComponentQuery;
47
49
  actions(target: ComponentQuery, ns: string): ActionsController;
48
50
  write(data: ChangesetData): RemoveChangeset;
51
+ addComponentHandler(definitionType: string, fn: CustomHandlerCallback): void;
52
+ getComponentHandler(definitionType: string): CustomHandlerCallback | undefined;
49
53
  dispose(): void;
50
54
  }
@@ -19,6 +19,7 @@ import { ActionsController } from './actions-controller';
19
19
  import { ComponentNode, } from './component-node';
20
20
  import { ComponentNodeCollection } from './component-node-collection';
21
21
  import { ComponentQuery } from './component-query';
22
+ import { CustomComponentHandler } from './custom-component-handler';
22
23
  import { createStateProcessor } from './state-processor';
23
24
  var ComponentPlatform = /** @class */ (function () {
24
25
  function ComponentPlatform(widget, providers) {
@@ -31,6 +32,7 @@ var ComponentPlatform = /** @class */ (function () {
31
32
  this.switches = {};
32
33
  this.changesets = [];
33
34
  this.subscriptions = [];
35
+ this.customComponentHandler = new CustomComponentHandler();
34
36
  this.events = widget.events.createChild(this);
35
37
  var root = new ComponentNode(this.events, 'root');
36
38
  root.name = "root-".concat(widget.name);
@@ -107,6 +109,9 @@ var ComponentPlatform = /** @class */ (function () {
107
109
  var parentNode = _a.parentNode;
108
110
  processNode(parentNode, { properties: true });
109
111
  }));
112
+ if (this.events.parent) {
113
+ this.events.parent.dispatch('components:platform-created', { platform: this });
114
+ }
110
115
  }
111
116
  ComponentPlatform.getInstance = function (container) {
112
117
  return container.getAsync('components');
@@ -198,6 +203,12 @@ var ComponentPlatform = /** @class */ (function () {
198
203
  }
199
204
  };
200
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
+ };
201
212
  ComponentPlatform.prototype.dispose = function () {
202
213
  this.subscriptions.forEach(function (sub) { return sub(); });
203
214
  };
@@ -1,6 +1,6 @@
1
1
  import { EventSubscriptionCancellation } from '@webprovisions/platform';
2
- import { Breakpoints, WidgetSettings } from '../types';
3
- import { ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
2
+ import { Breakpoints, ComponentSettings, ViewDefinition, WidgetSettings } from '../types';
3
+ import { ComponentNode, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
4
4
  import { ComponentPlatform } from './component-platform';
5
5
  declare type ComponentReference = string | [string, ...ComponentReferenceOverride[]];
6
6
  declare type ComponentReferenceOverride = {
@@ -10,10 +10,27 @@ declare type ComponentReferenceOverride = {
10
10
  properties?: ComponentNodeProperties;
11
11
  layout?: ComponentNodeLayout;
12
12
  };
13
- declare type NormalizedComponentReference = {
13
+ export declare type NormalizedComponentReference = {
14
14
  definitionId: string;
15
15
  overrides: ComponentReferenceOverride[];
16
16
  };
17
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;
18
35
  export declare const createComponentModel: (platform: ComponentPlatform, settings: WidgetSettings) => EventSubscriptionCancellation;
19
36
  export {};
@@ -28,9 +28,10 @@ export var normalizeReference = function (reference) {
28
28
  overrides: [],
29
29
  };
30
30
  };
31
- var createChildren = function (platform, node, references, definitions, views, branch) {
31
+ export var createChildren = function (platform, node, references, definitions, views, branch) {
32
32
  references.forEach(function (ref) {
33
33
  var childRef = normalizeReference(ref);
34
+ var childDef = definitions[childRef.definitionId];
34
35
  if (childRef.definitionId === 'view') {
35
36
  var viewNode_1 = platform.createNode('view');
36
37
  viewNode_1.name = 'view';
@@ -53,25 +54,38 @@ var createChildren = function (platform, node, references, definitions, views, b
53
54
  }
54
55
  });
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
+ }
56
70
  else {
57
- var childDef = definitions[childRef.definitionId];
71
+ var childDef_1 = definitions[childRef.definitionId];
58
72
  if (process.env.NODE_ENV !== 'production') {
59
- if (!childDef) {
73
+ if (!childDef_1) {
60
74
  Logger.error("No definition found for component type '".concat(childRef.definitionId, "'."));
61
75
  return;
62
76
  }
63
77
  }
64
- var childNode_1 = platform.createNode(childDef.type);
78
+ var childNode_1 = platform.createNode(childDef_1.type);
65
79
  childNode_1.name = childRef.definitionId;
66
- childNode_1.tags = childDef.tags || [];
67
- if (childDef.properties) {
68
- childNode_1.writeProperties(childDef.properties);
80
+ childNode_1.tags = childDef_1.tags || [];
81
+ if (childDef_1.properties) {
82
+ childNode_1.writeProperties(childDef_1.properties);
69
83
  }
70
- if (childDef.context) {
71
- childNode_1.writeContext(childDef.context);
84
+ if (childDef_1.context) {
85
+ childNode_1.writeContext(childDef_1.context);
72
86
  }
73
- if (childDef.layout) {
74
- childNode_1.writeLayout(childDef.layout);
87
+ if (childDef_1.layout) {
88
+ childNode_1.writeLayout(childDef_1.layout);
75
89
  }
76
90
  node.appendChild(childNode_1, branch);
77
91
  childRef.overrides.forEach(function (override) {
@@ -86,8 +100,8 @@ var createChildren = function (platform, node, references, definitions, views, b
86
100
  childNode_1.writeLayout(override.layout, options);
87
101
  }
88
102
  });
89
- if (childDef.children) {
90
- createChildren(platform, childNode_1, childDef.children, definitions, views);
103
+ if (childDef_1.children) {
104
+ createChildren(platform, childNode_1, childDef_1.children, definitions, views);
91
105
  }
92
106
  }
93
107
  });
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,13 @@
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,6 +1,7 @@
1
1
  export { ActionsController } from './actions-controller';
2
2
  export type { WatchActionDelegate } from './actions-controller';
3
3
  export type { ChangesetProvider } from './changeset-provider';
4
+ export { default as componentConfigurationApi } from './component-configuration-api';
4
5
  export { AbstractComponentController, ComponentNodeController } from './component-controller';
5
6
  export { ComponentNode } from './component-node';
6
7
  export type { ChangesetOptions, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, Size, } from './component-node';
@@ -8,7 +9,8 @@ export { ComponentPlatform } from './component-platform';
8
9
  export type { SwitchMap } from './component-platform';
9
10
  export { ComponentQuery } from './component-query';
10
11
  export type { ComponentQueryRule } from './component-query';
11
- export { createComponentModel } from './create-component-model';
12
+ export { createChildren, createComponentModel } from './create-component-model';
13
+ export type { ComponentHandlerOptions, NormalizedComponentReference, } from './create-component-model';
12
14
  export { asDescriptor } from './descriptor';
13
15
  export type { ComponentDescriptor } from './descriptor';
14
16
  export { extendComponent } from './extend-component';
@@ -1,9 +1,10 @@
1
1
  export { ActionsController } from './actions-controller';
2
+ export { default as componentConfigurationApi } from './component-configuration-api';
2
3
  export { AbstractComponentController, ComponentNodeController } from './component-controller';
3
4
  export { ComponentNode } from './component-node';
4
5
  export { ComponentPlatform } from './component-platform';
5
6
  export { ComponentQuery } from './component-query';
6
- export { createComponentModel } from './create-component-model';
7
+ export { createChildren, createComponentModel } from './create-component-model';
7
8
  export { asDescriptor } from './descriptor';
8
9
  export { extendComponent } from './extend-component';
9
10
  export { findComponent, findVisibleComponents, traverseComponents } from './queries';
@@ -1,6 +1,6 @@
1
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';
2
+ export { ActionsController, asDescriptor, componentConfigurationApi, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createChildren, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
3
+ export type { ChangesetOptions, ChangesetProvider, ComponentDescriptor, ComponentHandlerOptions, ComponentNodeAttributes, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties, ComponentNodeSettings, ComponentQueryRule, ExtendComponentHandler, ExtendComponentOptions, NormalizedComponentReference, Size, SwitchMap, WatchActionDelegate, } from './component-platform';
4
4
  export { default as ComponentResolver } from './component-resolver';
5
5
  export type { ReactComponent } from './component-resolver';
6
6
  export { createEventSubscriber } from './event-subscriber';
package/lib-esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as ActionResolver } from './action-resolver';
2
- export { ActionsController, asDescriptor, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
2
+ export { ActionsController, asDescriptor, componentConfigurationApi, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, createChildren, createComponentModel, extendComponent, findComponent, findVisibleComponents, traverseComponents, } from './component-platform';
3
3
  export { default as ComponentResolver } from './component-resolver';
4
4
  export { createEventSubscriber } from './event-subscriber';
5
5
  export * from './types';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare type Theme = {
3
2
  gap: string;
4
3
  accessibility: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-core",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Core framework for ACE widgets.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
@@ -29,5 +29,5 @@
29
29
  "@webprovisions/bootstrapping": "^1.0.12",
30
30
  "@webprovisions/platform": "^1.1.2"
31
31
  },
32
- "gitHead": "a45fde2bae0981a2a791a2362f2ecaf53430570b"
32
+ "gitHead": "34cb85e421c0c4a5bd08ccd899291683a11b3cf9"
33
33
  }