@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,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
|
+
}>;
|
package/lib/types/ui.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Container, EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
2
|
+
export declare type Action = (origin: string, action: string, value?: any) => void;
|
|
3
|
+
export default class ActionResolver {
|
|
4
|
+
private events;
|
|
5
|
+
constructor(container: Container);
|
|
6
|
+
action(target: string, action: string, value: any): void;
|
|
7
|
+
subscribe(origin: string, fn: Action): EventSubscriptionCancellation;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var ActionResolver = /** @class */ (function () {
|
|
2
|
+
function ActionResolver(container) {
|
|
3
|
+
var events = container.get('$widget').events;
|
|
4
|
+
this.events = events.createChild(this);
|
|
5
|
+
}
|
|
6
|
+
ActionResolver.prototype.action = function (target, action, value) {
|
|
7
|
+
this.events.dispatch('data:action', { action: action, value: value, target: target }, { bubbles: true });
|
|
8
|
+
};
|
|
9
|
+
ActionResolver.prototype.subscribe = function (origin, fn) {
|
|
10
|
+
return this.events.subscribe('data:action', function (e, _a) {
|
|
11
|
+
var action = _a.action, value = _a.value, target = _a.target;
|
|
12
|
+
return origin === target && fn(origin, action, value);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
return ActionResolver;
|
|
16
|
+
}());
|
|
17
|
+
export default ActionResolver;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EventSubscriptionCancellation } from '@webprovisions/platform';
|
|
2
|
+
import { ComponentNodeController } from './component-controller';
|
|
3
|
+
import { ComponentNode } from './component-node';
|
|
4
|
+
import { ComponentPlatform } from './component-platform';
|
|
5
|
+
import { ComponentQuery } from './component-query';
|
|
6
|
+
export declare type ActionData = any;
|
|
7
|
+
export declare type ActionHandler = (data: any, options: any, instance: ComponentNodeController) => any;
|
|
8
|
+
export declare type NextActionDelegate = (data: any, options?: any) => Promise<any>;
|
|
9
|
+
export declare type WatchActionDelegate = (input: ActionData, next: NextActionDelegate, instance: ComponentNodeController) => Promise<any> | any;
|
|
10
|
+
export declare type ActionWatcherContext = {
|
|
11
|
+
source: ComponentNode;
|
|
12
|
+
action: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type ActionsState = {
|
|
15
|
+
handlers: {
|
|
16
|
+
fn: ActionHandler;
|
|
17
|
+
key: string;
|
|
18
|
+
target: ComponentQuery;
|
|
19
|
+
ns?: string;
|
|
20
|
+
}[];
|
|
21
|
+
watchers: {
|
|
22
|
+
target: ComponentQuery;
|
|
23
|
+
fn: WatchActionDelegate;
|
|
24
|
+
key: string;
|
|
25
|
+
ns?: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
export declare class ActionsController {
|
|
29
|
+
private platform;
|
|
30
|
+
private target;
|
|
31
|
+
private ns?;
|
|
32
|
+
private subscriptions;
|
|
33
|
+
constructor(platform: ComponentPlatform, target: ComponentQuery, ns?: string | undefined);
|
|
34
|
+
create(key: string, fn?: ActionHandler): EventSubscriptionCancellation;
|
|
35
|
+
dispatch(key: string, data: any): Promise<{
|
|
36
|
+
[instanceId: string]: any;
|
|
37
|
+
}>;
|
|
38
|
+
watch(key: string, fn: WatchActionDelegate): EventSubscriptionCancellation;
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { ComponentNodeController } from './component-controller';
|
|
13
|
+
var executeActionListeners = function (listeners, data, controller) {
|
|
14
|
+
var stack = listeners.concat();
|
|
15
|
+
var dispatch = function (data, globalOptions, controller) {
|
|
16
|
+
var cancelled = true;
|
|
17
|
+
if (stack.length) {
|
|
18
|
+
var handler = stack.shift();
|
|
19
|
+
var next = function (data, options) {
|
|
20
|
+
cancelled = false;
|
|
21
|
+
return dispatch(data, Object.assign({}, globalOptions, options), controller);
|
|
22
|
+
};
|
|
23
|
+
return Promise.resolve(handler(data, next, controller)).then(function (result) { return (__assign(__assign({}, result), { cancelled: cancelled })); });
|
|
24
|
+
}
|
|
25
|
+
return Promise.resolve({ data: data, cancelled: false, options: globalOptions });
|
|
26
|
+
};
|
|
27
|
+
return dispatch(data, {}, controller);
|
|
28
|
+
};
|
|
29
|
+
var ActionsController = /** @class */ (function () {
|
|
30
|
+
function ActionsController(platform, target, ns) {
|
|
31
|
+
this.platform = platform;
|
|
32
|
+
this.target = target;
|
|
33
|
+
this.ns = ns;
|
|
34
|
+
this.subscriptions = [];
|
|
35
|
+
this.create = this.create.bind(this);
|
|
36
|
+
}
|
|
37
|
+
ActionsController.prototype.create = function (key, fn) {
|
|
38
|
+
var _this = this;
|
|
39
|
+
if (fn === void 0) { fn = function () { }; }
|
|
40
|
+
var handler = {
|
|
41
|
+
key: key,
|
|
42
|
+
fn: fn,
|
|
43
|
+
target: this.target,
|
|
44
|
+
ns: this.ns,
|
|
45
|
+
};
|
|
46
|
+
this.platform.actionsState.handlers.push(handler);
|
|
47
|
+
var subscription = function () {
|
|
48
|
+
var index = _this.platform.actionsState.handlers.indexOf(handler);
|
|
49
|
+
if (index > -1) {
|
|
50
|
+
_this.platform.actionsState.handlers.splice(index, 1);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.subscriptions.push(subscription);
|
|
54
|
+
return subscription;
|
|
55
|
+
};
|
|
56
|
+
ActionsController.prototype.dispatch = function (key, data) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
var instances = this.platform.nodes.all.concat(this.platform.nodes.detached);
|
|
59
|
+
var output = {};
|
|
60
|
+
// handlers matching the specified pattern.
|
|
61
|
+
var handlers = this.platform.actionsState.handlers.filter(function (handler) { return handler.key === key && (!handler.ns || !_this.ns || handler.ns === _this.ns); });
|
|
62
|
+
return Promise.all(handlers.map(function (handler) {
|
|
63
|
+
// select all matching instances for this particular
|
|
64
|
+
// handler (a handler can be mapped to many instances)
|
|
65
|
+
var matchedInstances = instances.filter(function (instance) { return handler.target.match(instance) && _this.target.match(instance); });
|
|
66
|
+
// execute watchers for each matched instance
|
|
67
|
+
var watchers = _this.platform.actionsState.watchers
|
|
68
|
+
.filter(function (watcher) {
|
|
69
|
+
return (watcher.key === key &&
|
|
70
|
+
(!watcher.ns || !_this.ns || watcher.ns === _this.ns) &&
|
|
71
|
+
matchedInstances.some(function (instance) { return watcher.target.match(instance); }));
|
|
72
|
+
})
|
|
73
|
+
.map(function (watcher) { return watcher.fn; });
|
|
74
|
+
// execute watchers and handler for each instance
|
|
75
|
+
return Promise.all(matchedInstances.map(function (node) {
|
|
76
|
+
var controller = new ComponentNodeController(_this.platform, node, _this.ns);
|
|
77
|
+
return executeActionListeners(watchers, data, controller).then(function (input) {
|
|
78
|
+
var _a = input.data, data = _a === void 0 ? {} : _a, options = input.options, cancelled = input.cancelled;
|
|
79
|
+
return Promise.resolve(cancelled ? {} : handler.fn(data, options, controller)).then(function (handlerResponse) {
|
|
80
|
+
output[node.id] = handlerResponse;
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}));
|
|
84
|
+
})).then(function () { return output; });
|
|
85
|
+
};
|
|
86
|
+
ActionsController.prototype.watch = function (key, fn) {
|
|
87
|
+
var _this = this;
|
|
88
|
+
var parsedKey = key;
|
|
89
|
+
var parsedNs = this.ns;
|
|
90
|
+
var sections = key.split('.');
|
|
91
|
+
if (sections.length > 1) {
|
|
92
|
+
parsedNs = sections[0];
|
|
93
|
+
parsedKey = sections.splice(1).join('.');
|
|
94
|
+
}
|
|
95
|
+
var watcher = {
|
|
96
|
+
fn: fn,
|
|
97
|
+
target: this.target,
|
|
98
|
+
key: parsedKey,
|
|
99
|
+
ns: parsedNs,
|
|
100
|
+
};
|
|
101
|
+
this.platform.actionsState.watchers.push(watcher);
|
|
102
|
+
var subscription = function () {
|
|
103
|
+
var index = _this.platform.actionsState.watchers.indexOf(watcher);
|
|
104
|
+
if (index > -1) {
|
|
105
|
+
_this.platform.actionsState.watchers.splice(index, 1);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.subscriptions.push(subscription);
|
|
109
|
+
return subscription;
|
|
110
|
+
};
|
|
111
|
+
ActionsController.prototype.dispose = function () {
|
|
112
|
+
this.subscriptions.forEach(function (unsubscribe) { return unsubscribe(); });
|
|
113
|
+
};
|
|
114
|
+
return ActionsController;
|
|
115
|
+
}());
|
|
116
|
+
export { ActionsController };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChangesetOptions, ComponentNodeSettings } from './component-node';
|
|
2
|
+
import { ComponentPlatform } from './component-platform';
|
|
3
|
+
import { ComponentQuery } from './component-query';
|
|
4
|
+
export interface ChangesetProvider {
|
|
5
|
+
write: (key: string, target: ComponentQuery, attributes: Partial<ComponentNodeSettings>, options: ChangesetOptions) => void;
|
|
6
|
+
remove: (key: string) => void;
|
|
7
|
+
load: (platform: ComponentPlatform) => Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ActionsController } from './actions-controller';
|
|
2
|
+
import { ChangesetOptions, ComponentNode, ComponentNodeContext, ComponentNodeLayout, ComponentNodeProperties } from './component-node';
|
|
3
|
+
import { ComponentPlatform } from './component-platform';
|
|
4
|
+
import { ComponentQuery } from './component-query';
|
|
5
|
+
export interface ComponentController {
|
|
6
|
+
actions: ActionsController;
|
|
7
|
+
writeProperties(properties: Partial<ComponentNodeProperties>, options: ChangesetOptions): void;
|
|
8
|
+
writeContext(context: Partial<ComponentNodeContext>, options: ChangesetOptions): void;
|
|
9
|
+
writeLayout(context: Partial<ComponentNodeLayout>, options: ChangesetOptions): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class ComponentNodeController implements ComponentController {
|
|
13
|
+
private platform;
|
|
14
|
+
node: ComponentNode;
|
|
15
|
+
actions: ActionsController;
|
|
16
|
+
private subscribe;
|
|
17
|
+
private unsubscribe;
|
|
18
|
+
constructor(platform: ComponentPlatform, node: ComponentNode, ns?: string);
|
|
19
|
+
properties<T extends ComponentNodeProperties>(updated?: (properties: T) => void | Partial<ComponentNodeProperties>): T;
|
|
20
|
+
context(updated?: (context: ComponentNodeContext) => void): ComponentNodeContext;
|
|
21
|
+
layout(updated?: (layout: ComponentNodeLayout) => void): ComponentNodeLayout;
|
|
22
|
+
writeProperties(properties: Partial<ComponentNodeProperties> | ((properties: ComponentNodeProperties) => Partial<ComponentNodeProperties>), options?: ChangesetOptions): void;
|
|
23
|
+
writeContext(context: Partial<ComponentNodeContext>, options?: ChangesetOptions): void;
|
|
24
|
+
writeLayout(layout: Partial<ComponentNodeLayout>, options?: ChangesetOptions): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class AbstractComponentController implements ComponentController {
|
|
28
|
+
private platform;
|
|
29
|
+
private target;
|
|
30
|
+
private clearOnDispose;
|
|
31
|
+
actions: ActionsController;
|
|
32
|
+
private removes;
|
|
33
|
+
constructor(platform: ComponentPlatform, target: ComponentQuery, clearOnDispose?: boolean);
|
|
34
|
+
writeProperties(properties: Partial<ComponentNodeProperties>, options?: ChangesetOptions): void;
|
|
35
|
+
writeContext(context: Partial<ComponentNodeContext>, options?: ChangesetOptions): void;
|
|
36
|
+
writeLayout(layout: Partial<ComponentNodeLayout>, options?: ChangesetOptions): void;
|
|
37
|
+
dispose(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 { createEventSubscriber } from '../event-subscriber';
|
|
18
|
+
import { ActionsController } from './actions-controller';
|
|
19
|
+
import { ComponentQuery } from './component-query';
|
|
20
|
+
var ComponentNodeController = /** @class */ (function () {
|
|
21
|
+
function ComponentNodeController(platform, node, ns) {
|
|
22
|
+
this.platform = platform;
|
|
23
|
+
this.node = node;
|
|
24
|
+
this.actions = new ActionsController(platform, new ComponentQuery(platform).withId(node.id), ns);
|
|
25
|
+
var _a = __read(createEventSubscriber(this.platform.events), 2), subscribe = _a[0], unsubscribe = _a[1];
|
|
26
|
+
this.subscribe = subscribe;
|
|
27
|
+
this.unsubscribe = unsubscribe;
|
|
28
|
+
}
|
|
29
|
+
ComponentNodeController.prototype.properties = function (updated) {
|
|
30
|
+
if (updated) {
|
|
31
|
+
this.node.touchProperties(function (properties) { return updated(properties); });
|
|
32
|
+
}
|
|
33
|
+
return this.node.attributes.properties;
|
|
34
|
+
};
|
|
35
|
+
ComponentNodeController.prototype.context = function (updated) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
if (updated) {
|
|
38
|
+
this.subscribe('components:context-changed', function (event, _a) {
|
|
39
|
+
var node = _a.node;
|
|
40
|
+
if (node === _this.node) {
|
|
41
|
+
updated(_this.node.attributes.context);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return this.node.attributes.context;
|
|
46
|
+
};
|
|
47
|
+
ComponentNodeController.prototype.layout = function (updated) {
|
|
48
|
+
var _this = this;
|
|
49
|
+
if (updated) {
|
|
50
|
+
this.subscribe('components:layout-changed', function (event, _a) {
|
|
51
|
+
var node = _a.node;
|
|
52
|
+
if (node === _this.node) {
|
|
53
|
+
updated(_this.node.attributes.layout);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return this.node.attributes.layout;
|
|
58
|
+
};
|
|
59
|
+
ComponentNodeController.prototype.writeProperties = function (properties, options) {
|
|
60
|
+
this.node.writeProperties(properties, options);
|
|
61
|
+
};
|
|
62
|
+
ComponentNodeController.prototype.writeContext = function (context, options) {
|
|
63
|
+
this.node.writeProperties(context, options);
|
|
64
|
+
};
|
|
65
|
+
ComponentNodeController.prototype.writeLayout = function (layout, options) {
|
|
66
|
+
this.node.writeLayout(layout, options);
|
|
67
|
+
};
|
|
68
|
+
ComponentNodeController.prototype.dispose = function () {
|
|
69
|
+
this.unsubscribe();
|
|
70
|
+
this.actions.dispose();
|
|
71
|
+
};
|
|
72
|
+
return ComponentNodeController;
|
|
73
|
+
}());
|
|
74
|
+
export { ComponentNodeController };
|
|
75
|
+
var AbstractComponentController = /** @class */ (function () {
|
|
76
|
+
function AbstractComponentController(platform, target, clearOnDispose) {
|
|
77
|
+
if (clearOnDispose === void 0) { clearOnDispose = true; }
|
|
78
|
+
this.platform = platform;
|
|
79
|
+
this.target = target;
|
|
80
|
+
this.clearOnDispose = clearOnDispose;
|
|
81
|
+
this.removes = [];
|
|
82
|
+
this.actions = new ActionsController(this.platform, this.target);
|
|
83
|
+
}
|
|
84
|
+
AbstractComponentController.prototype.writeProperties = function (properties, options) {
|
|
85
|
+
this.removes.push(this.platform.write({
|
|
86
|
+
options: options,
|
|
87
|
+
attributes: { properties: properties },
|
|
88
|
+
target: this.target,
|
|
89
|
+
removable: this.clearOnDispose,
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
AbstractComponentController.prototype.writeContext = function (context, options) {
|
|
93
|
+
this.removes.push(this.platform.write({
|
|
94
|
+
options: options,
|
|
95
|
+
attributes: { context: context },
|
|
96
|
+
target: this.target,
|
|
97
|
+
removable: this.clearOnDispose,
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
100
|
+
AbstractComponentController.prototype.writeLayout = function (layout, options) {
|
|
101
|
+
this.removes.push(this.platform.write({
|
|
102
|
+
options: options,
|
|
103
|
+
attributes: { layout: layout },
|
|
104
|
+
target: this.target,
|
|
105
|
+
removable: this.clearOnDispose,
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
AbstractComponentController.prototype.dispose = function () {
|
|
109
|
+
this.removes.forEach(function (remove) {
|
|
110
|
+
remove();
|
|
111
|
+
});
|
|
112
|
+
this.actions.dispose();
|
|
113
|
+
};
|
|
114
|
+
return AbstractComponentController;
|
|
115
|
+
}());
|
|
116
|
+
export { AbstractComponentController };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EventManager } from '@webprovisions/platform';
|
|
2
|
+
import { ComponentNode } from './component-node';
|
|
3
|
+
import { SwitchMap } from './component-platform';
|
|
4
|
+
export declare type QueryDescriptor = {
|
|
5
|
+
id?: string;
|
|
6
|
+
type?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ComponentNodeCollection {
|
|
10
|
+
root: ComponentNode;
|
|
11
|
+
private switches;
|
|
12
|
+
all: ComponentNode[];
|
|
13
|
+
visible: ComponentNode[];
|
|
14
|
+
detached: ComponentNode[];
|
|
15
|
+
constructor(root: ComponentNode, switches: SwitchMap, events: EventManager);
|
|
16
|
+
query(query?: QueryDescriptor): ComponentNode[];
|
|
17
|
+
get(id: string): ComponentNode | undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { findComponent, findVisibleComponents, traverseComponents } from './queries';
|
|
2
|
+
var ComponentNodeCollection = /** @class */ (function () {
|
|
3
|
+
function ComponentNodeCollection(root, switches, events) {
|
|
4
|
+
var _this = this;
|
|
5
|
+
this.root = root;
|
|
6
|
+
this.switches = switches;
|
|
7
|
+
this.all = [];
|
|
8
|
+
this.visible = [];
|
|
9
|
+
this.detached = [];
|
|
10
|
+
events.subscribe('components:node-appended', function (event, data) {
|
|
11
|
+
_this.all.push(data.node);
|
|
12
|
+
_this.visible = findVisibleComponents(root, switches);
|
|
13
|
+
});
|
|
14
|
+
events.subscribe('components:node-removed', function (event, data) {
|
|
15
|
+
var indexToRemove = _this.all.indexOf(data.node);
|
|
16
|
+
if (indexToRemove > -1) {
|
|
17
|
+
_this.all.splice(indexToRemove, 1);
|
|
18
|
+
}
|
|
19
|
+
indexToRemove = _this.visible.indexOf(data.node);
|
|
20
|
+
if (indexToRemove > -1) {
|
|
21
|
+
_this.visible.splice(indexToRemove, 1);
|
|
22
|
+
}
|
|
23
|
+
_this.visible = findVisibleComponents(root, switches);
|
|
24
|
+
});
|
|
25
|
+
events.subscribe('components:node-switched', function (event, data) {
|
|
26
|
+
_this.visible = findVisibleComponents(root, switches);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
ComponentNodeCollection.prototype.query = function (query) {
|
|
30
|
+
if (query === void 0) { query = {}; }
|
|
31
|
+
var nodes = [];
|
|
32
|
+
traverseComponents(this.root, this.switches, function (node) {
|
|
33
|
+
var match = Object.keys(query).every(function (member) {
|
|
34
|
+
return query[member] === node[member];
|
|
35
|
+
});
|
|
36
|
+
if (match) {
|
|
37
|
+
nodes.push(node);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return nodes;
|
|
41
|
+
};
|
|
42
|
+
ComponentNodeCollection.prototype.get = function (id) {
|
|
43
|
+
return (findComponent(this.root, this.switches, function (node) { return node.id === id; }) ||
|
|
44
|
+
this.detached.find(function (node) { return node.id === id; }));
|
|
45
|
+
};
|
|
46
|
+
return ComponentNodeCollection;
|
|
47
|
+
}());
|
|
48
|
+
export { ComponentNodeCollection };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Container, EventManager } from '@webprovisions/platform';
|
|
2
|
+
import { Breakpoints } from '../types';
|
|
3
|
+
export declare type ComponentNodeEventData = {
|
|
4
|
+
node: ComponentNode;
|
|
5
|
+
};
|
|
6
|
+
export declare type RemoveChangeset = () => void;
|
|
7
|
+
export declare type ComponentNodeAttributes = {
|
|
8
|
+
tags: string[];
|
|
9
|
+
properties: ComponentNodeProperties;
|
|
10
|
+
context: ComponentNodeContext;
|
|
11
|
+
layout: ComponentNodeLayout;
|
|
12
|
+
};
|
|
13
|
+
export declare type ResolveComponentNodeProperties = (properties: ComponentNodeProperties) => Partial<ComponentNodeProperties> | void;
|
|
14
|
+
export declare type ResolveComponentNodeContext = (context: ComponentNodeContext) => Partial<ComponentNodeContext>;
|
|
15
|
+
export declare type ResolveComponentNodeLayout = (layout: ComponentNodeLayout) => Partial<ComponentNodeLayout>;
|
|
16
|
+
export declare type ComponentNodeSettings = {
|
|
17
|
+
tags?: string[];
|
|
18
|
+
properties?: ComponentNodeProperties | ResolveComponentNodeProperties;
|
|
19
|
+
context?: ComponentNodeContext | ResolveComponentNodeContext;
|
|
20
|
+
layout?: ComponentNodeLayout | ResolveComponentNodeLayout;
|
|
21
|
+
};
|
|
22
|
+
export declare type ComponentNodeProperties = {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
export declare type ComponentNodeContext = {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
export declare type ComponentNodeLayout = {
|
|
29
|
+
size?: Size;
|
|
30
|
+
indent?: number;
|
|
31
|
+
order?: number;
|
|
32
|
+
};
|
|
33
|
+
export declare type Size = number | 'full' | 'none';
|
|
34
|
+
export declare type UnmountComponentNode = () => void;
|
|
35
|
+
export declare type ChangesetOptions = {
|
|
36
|
+
breakpoints?: Breakpoints;
|
|
37
|
+
};
|
|
38
|
+
export declare type Changeset = [Partial<ComponentNodeSettings>, ChangesetOptions];
|
|
39
|
+
export declare class ComponentNode {
|
|
40
|
+
private events;
|
|
41
|
+
id: string;
|
|
42
|
+
type: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
parent?: ComponentNode;
|
|
45
|
+
tags: string[];
|
|
46
|
+
children: {
|
|
47
|
+
[key: string]: ComponentNode[];
|
|
48
|
+
};
|
|
49
|
+
changesets: Changeset[];
|
|
50
|
+
attributes: ComponentNodeAttributes;
|
|
51
|
+
private mountCount;
|
|
52
|
+
constructor(events: EventManager, type: string);
|
|
53
|
+
mount(viewOutletContainer: Container, element?: HTMLElement): UnmountComponentNode;
|
|
54
|
+
appendChild(node: ComponentNode, branch?: string): void;
|
|
55
|
+
prependChild(node: ComponentNode, branch?: string): void;
|
|
56
|
+
touchProperties(properties: ResolveComponentNodeProperties, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
57
|
+
writeProperties(properties: Partial<ComponentNodeProperties> | ResolveComponentNodeProperties, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
58
|
+
writeLayout(layout: Partial<ComponentNodeLayout> | ResolveComponentNodeLayout, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
59
|
+
writeContext(context: Partial<ComponentNodeContext> | ResolveComponentNodeContext, options?: ChangesetOptions, removable?: boolean): RemoveChangeset;
|
|
60
|
+
getChildren(branch?: string): ComponentNode[];
|
|
61
|
+
remove(): void;
|
|
62
|
+
removeChild(node: ComponentNode): void;
|
|
63
|
+
}
|