@telia-ace/widget-runtime-flamingo 1.0.62 → 1.1.1-rc.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/.eslintrc.json +30 -0
- package/README.md +11 -0
- package/package.json +2 -9
- package/project.json +48 -0
- package/src/component-platform-factory.ts +163 -0
- package/src/context/children.context.ts +4 -0
- package/src/context/component-node.context.ts +6 -0
- package/src/context/container.context.ts +6 -0
- package/src/context/context.context.ts +3 -0
- package/src/context/layout.context.ts +3 -0
- package/src/context/properties.context.ts +3 -0
- package/src/controllers/actions-controller.ts +55 -0
- package/src/core/create-lit-component.ts +31 -0
- package/src/core/get-render-state.ts +25 -0
- package/src/data-provider/data-provider.ts +87 -0
- package/src/data-provider/providers/guide-provider.plugin.ts +64 -0
- package/src/declaration.d.ts +2 -0
- package/{index.d.ts → src/index.ts} +13 -1
- package/src/mixins/widget-component.mixin.ts +231 -0
- package/src/services.ts +27 -0
- package/src/ui/area.ts +97 -0
- package/src/ui/branding.ts +25 -0
- package/src/ui/get-css-props.ts +23 -0
- package/src/ui/get-layout-props.ts +41 -0
- package/src/ui/html-element-handlers.ts +140 -0
- package/src/ui/index.ts +6 -0
- package/src/ui/prepare-dom.ts +164 -0
- package/src/ui/render.ts +19 -0
- package/src/ui/trigger-component.ts +200 -0
- package/src/ui/view-outlet.ts +172 -0
- package/src/ui/wrapper.ts +247 -0
- package/src/vite.env.d.ts +1 -0
- package/src/widget.ts +748 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +19 -0
- package/vite.config.ts +56 -0
- package/component-platform-factory.d.ts +0 -13
- package/context/children.context.d.ts +0 -4
- package/context/component-node.context.d.ts +0 -4
- package/context/container.context.d.ts +0 -4
- package/context/context.context.d.ts +0 -3
- package/context/layout.context.d.ts +0 -3
- package/context/properties.context.d.ts +0 -3
- package/controllers/actions-controller.d.ts +0 -14
- package/core/create-lit-component.d.ts +0 -11
- package/core/get-render-state.d.ts +0 -4
- package/data-provider/data-provider.d.ts +0 -24
- package/data-provider/providers/guide-provider.plugin.d.ts +0 -2
- package/index-2f951bfa.mjs +0 -3409
- package/index-38ca4109.js +0 -206
- package/index-5087564d.mjs +0 -335
- package/index-6dd00f59.js +0 -1
- package/index.js +0 -1
- package/index.mjs +0 -17
- package/mixins/widget-component.mixin.d.ts +0 -24
- package/render-55cd6ed9.mjs +0 -456
- package/render-5beab301.js +0 -118
- package/services.d.ts +0 -5
- package/ui/area.d.ts +0 -9
- package/ui/branding.d.ts +0 -1
- package/ui/get-css-props.d.ts +0 -5
- package/ui/get-layout-props.d.ts +0 -9
- package/ui/html-element-handlers.d.ts +0 -14
- package/ui/prepare-dom.d.ts +0 -21
- package/ui/render.d.ts +0 -3
- package/ui/trigger-component.d.ts +0 -20
- package/ui/view-outlet.d.ts +0 -36
- package/ui/wrapper.d.ts +0 -21
- package/widget.d.ts +0 -54
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
+
"rules": {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
|
11
|
+
"rules": {}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"files": ["*.js", "*.jsx"],
|
|
15
|
+
"rules": {}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"files": ["*.json"],
|
|
19
|
+
"parser": "jsonc-eslint-parser",
|
|
20
|
+
"rules": {
|
|
21
|
+
"@nx/dependency-checks": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# widget-runtime
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build widget-runtime` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test widget-runtime` to execute the unit tests via [Jest](https://jestjs.io).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-runtime-flamingo",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.1-rc.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org"
|
|
6
6
|
},
|
|
@@ -12,14 +12,7 @@
|
|
|
12
12
|
"lit": "^2.8.0",
|
|
13
13
|
"@teliads/icons": "^8.4.0",
|
|
14
14
|
"@telia-ace/widget-core": "^1.0.27",
|
|
15
|
-
"@webprovisions/bootstrapping": "^1.0.13"
|
|
16
|
-
"@telia-ace/widget-runtime-flamingo": "1.0.62",
|
|
17
|
-
"@telia-ace/widget-conversation-flamingo": "1.0.62",
|
|
18
|
-
"@telia-ace/knowledge-widget-bot-provider-flamingo": "1.0.62",
|
|
19
|
-
"@telia-ace/knowledge-data-client-flamingo": "1.0.62",
|
|
20
|
-
"@telia-ace/widget-components-copyright-flamingo": "1.0.62",
|
|
21
|
-
"@telia-ace/widget-components-list-flamingo": "1.0.62",
|
|
22
|
-
"@telia-ace/widget-components-widget-header-flamingo": "1.0.62"
|
|
15
|
+
"@webprovisions/bootstrapping": "^1.0.13"
|
|
23
16
|
},
|
|
24
17
|
"main": "./index.js",
|
|
25
18
|
"module": "./index.mjs",
|
package/project.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "runtime",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/runtime/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"executor": "@nx/vite:build",
|
|
9
|
+
"outputs": ["{options.outputPath}"],
|
|
10
|
+
"options": {
|
|
11
|
+
"outputPath": "dist/libs/runtime"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publish": {
|
|
15
|
+
"executor": "nx:run-commands",
|
|
16
|
+
"options": {
|
|
17
|
+
"command": "npm publish",
|
|
18
|
+
"cwd": "dist/libs/runtime"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"prerelease": {
|
|
22
|
+
"executor": "nx:run-commands",
|
|
23
|
+
"options": {
|
|
24
|
+
"command": "npm publish --tag=rc",
|
|
25
|
+
"cwd": "dist/libs/runtime"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"test": {
|
|
29
|
+
"executor": "@nx/vite:test",
|
|
30
|
+
"outputs": ["{options.reportsDirectory}"],
|
|
31
|
+
"options": {
|
|
32
|
+
"passWithNoTests": true,
|
|
33
|
+
"reportsDirectory": "../../coverage/libs/runtime"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"lint": {
|
|
37
|
+
"executor": "@nx/eslint:lint",
|
|
38
|
+
"outputs": ["{options.outputFile}"],
|
|
39
|
+
"options": {
|
|
40
|
+
"lintFilePatterns": [
|
|
41
|
+
"libs/runtime/**/*.ts",
|
|
42
|
+
"libs/runtime/package.json"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"tags": []
|
|
48
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChangesetOptions,
|
|
3
|
+
ChangesetProvider,
|
|
4
|
+
ComponentNodeAttributes,
|
|
5
|
+
ComponentNodeSettings,
|
|
6
|
+
ComponentPlatform,
|
|
7
|
+
ComponentQuery,
|
|
8
|
+
ComponentQueryRule,
|
|
9
|
+
createComponentModel,
|
|
10
|
+
WidgetSettings,
|
|
11
|
+
} from '@telia-ace/widget-core';
|
|
12
|
+
import {
|
|
13
|
+
createStorageWriter,
|
|
14
|
+
readStorage,
|
|
15
|
+
StorageCategory,
|
|
16
|
+
StorageMedium,
|
|
17
|
+
StorageWriter,
|
|
18
|
+
} from '@telia-ace/widget-services';
|
|
19
|
+
import { lock } from '@telia-ace/widget-utilities';
|
|
20
|
+
import { Container, Widget, WidgetState } from '@webprovisions/platform';
|
|
21
|
+
|
|
22
|
+
const STORAGE_KEY = 'changesets';
|
|
23
|
+
|
|
24
|
+
type ChangesetItem = {
|
|
25
|
+
rules: ComponentQueryRule[];
|
|
26
|
+
attributes: Partial<ComponentNodeAttributes>;
|
|
27
|
+
options: ChangesetOptions;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ChangesetItemBag = {
|
|
31
|
+
items?: { [key: string]: ChangesetItem };
|
|
32
|
+
keys?: string[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const convertSettingsToAttributes = (
|
|
36
|
+
settings: Partial<ComponentNodeSettings>
|
|
37
|
+
): Partial<ComponentNodeAttributes> => {
|
|
38
|
+
const attributes: Partial<ComponentNodeAttributes> = { tags: settings.tags };
|
|
39
|
+
if (settings.context && typeof settings.context !== 'function') {
|
|
40
|
+
attributes.context = settings.context;
|
|
41
|
+
}
|
|
42
|
+
if (settings.properties && typeof settings.properties !== 'function') {
|
|
43
|
+
attributes.properties = settings.properties;
|
|
44
|
+
}
|
|
45
|
+
if (settings.layout && typeof settings.layout !== 'function') {
|
|
46
|
+
attributes.layout = settings.layout;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return attributes;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export class LocalStorageChangesetProvider implements ChangesetProvider {
|
|
53
|
+
constructor(
|
|
54
|
+
private container: Container,
|
|
55
|
+
private storageWriter: StorageWriter
|
|
56
|
+
) {}
|
|
57
|
+
|
|
58
|
+
static create(container: Container): Promise<LocalStorageChangesetProvider> {
|
|
59
|
+
return createStorageWriter(
|
|
60
|
+
container,
|
|
61
|
+
STORAGE_KEY,
|
|
62
|
+
StorageCategory.Necessary,
|
|
63
|
+
{
|
|
64
|
+
medium: StorageMedium.Local,
|
|
65
|
+
}
|
|
66
|
+
).then(
|
|
67
|
+
(storageWriter) =>
|
|
68
|
+
new LocalStorageChangesetProvider(container, storageWriter)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
write(
|
|
73
|
+
key: string,
|
|
74
|
+
target: ComponentQuery,
|
|
75
|
+
attributes: Partial<ComponentNodeSettings>,
|
|
76
|
+
options: ChangesetOptions
|
|
77
|
+
): Promise<any> {
|
|
78
|
+
return lock(this)(() => {
|
|
79
|
+
return readStorage<ChangesetItemBag>(
|
|
80
|
+
this.container,
|
|
81
|
+
STORAGE_KEY,
|
|
82
|
+
StorageMedium.Local
|
|
83
|
+
).then((bag = {}) => {
|
|
84
|
+
const { keys = [], items = {} } = bag;
|
|
85
|
+
const existingIndex = keys.indexOf(key);
|
|
86
|
+
if (existingIndex > -1) {
|
|
87
|
+
keys.splice(existingIndex, 1);
|
|
88
|
+
}
|
|
89
|
+
keys.push(key);
|
|
90
|
+
items[key] = {
|
|
91
|
+
options,
|
|
92
|
+
attributes: convertSettingsToAttributes(attributes),
|
|
93
|
+
rules: target.rules,
|
|
94
|
+
};
|
|
95
|
+
return this.storageWriter({ keys, items });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
remove(key: string): Promise<any> {
|
|
101
|
+
return lock(this)(() => {
|
|
102
|
+
return readStorage<ChangesetItemBag>(
|
|
103
|
+
this.container,
|
|
104
|
+
STORAGE_KEY,
|
|
105
|
+
StorageMedium.Local
|
|
106
|
+
).then((bag = {}) => {
|
|
107
|
+
const { keys = [], items = {} } = bag;
|
|
108
|
+
const indexToRemove = keys.indexOf(key);
|
|
109
|
+
if (indexToRemove > -1) {
|
|
110
|
+
keys.splice(indexToRemove, 1);
|
|
111
|
+
delete items[key];
|
|
112
|
+
return this.storageWriter(bag);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
load(platform: ComponentPlatform): Promise<any> {
|
|
119
|
+
return lock(this)(() => {
|
|
120
|
+
return readStorage<ChangesetItemBag>(
|
|
121
|
+
this.container,
|
|
122
|
+
STORAGE_KEY,
|
|
123
|
+
StorageMedium.Local
|
|
124
|
+
).then((bag = {}) => {
|
|
125
|
+
const { keys = [], items = {} } = bag;
|
|
126
|
+
keys.forEach((key) => {
|
|
127
|
+
const item = items[key];
|
|
128
|
+
if (item) {
|
|
129
|
+
const { rules, attributes, options } = item;
|
|
130
|
+
platform.write({
|
|
131
|
+
attributes,
|
|
132
|
+
options,
|
|
133
|
+
target: new ComponentQuery(platform, rules),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const createPlatform = (widget: Widget): Promise<ComponentPlatform> => {
|
|
143
|
+
const { container } = widget;
|
|
144
|
+
return LocalStorageChangesetProvider.create(container).then(
|
|
145
|
+
(localStorage) => {
|
|
146
|
+
const settings: WidgetSettings = container.get('$settings');
|
|
147
|
+
const providers = { localStorage };
|
|
148
|
+
const platform = new ComponentPlatform(widget, providers);
|
|
149
|
+
const destructComponentModel = createComponentModel(platform, settings);
|
|
150
|
+
|
|
151
|
+
widget.events.subscribe(
|
|
152
|
+
'widget:state-change',
|
|
153
|
+
(_event, data: { state: WidgetState }) => {
|
|
154
|
+
if (data.state === WidgetState.Deactivating) {
|
|
155
|
+
destructComponentModel();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return platform;
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReactiveController,
|
|
3
|
+
ReactiveControllerHost,
|
|
4
|
+
ReactiveElement,
|
|
5
|
+
} from 'lit';
|
|
6
|
+
import { Container } from '@webprovisions/platform';
|
|
7
|
+
import {
|
|
8
|
+
ComponentDescriptor,
|
|
9
|
+
ComponentPlatform,
|
|
10
|
+
ComponentQuery,
|
|
11
|
+
} from '@telia-ace/widget-core';
|
|
12
|
+
import { uuid } from '@telia-ace/widget-utilities';
|
|
13
|
+
|
|
14
|
+
export class ActionsController implements ReactiveController {
|
|
15
|
+
host: ReactiveControllerHost;
|
|
16
|
+
|
|
17
|
+
private _container?: Container;
|
|
18
|
+
|
|
19
|
+
private _descriptor?: ComponentDescriptor;
|
|
20
|
+
|
|
21
|
+
constructor(host: ReactiveElement) {
|
|
22
|
+
(this.host = host).addController(this);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
hostConnected() {}
|
|
26
|
+
hostDisconnected() {}
|
|
27
|
+
|
|
28
|
+
setDescriptor(descriptor: ComponentDescriptor) {
|
|
29
|
+
this._descriptor = descriptor;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setContainer(container: Container) {
|
|
33
|
+
this._container = container;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async dispatch(key: string, value: Record<string, any> | string) {
|
|
37
|
+
if (!this._container || !this._descriptor) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const componentPlatform = await ComponentPlatform.getInstance(
|
|
42
|
+
this._container
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const query = new ComponentQuery(componentPlatform).withId(
|
|
46
|
+
this._descriptor.id
|
|
47
|
+
);
|
|
48
|
+
const actions = componentPlatform.actions(
|
|
49
|
+
query,
|
|
50
|
+
this._descriptor.type || uuid()
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
await actions.dispatch(key, value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentResolver,
|
|
3
|
+
extendComponent,
|
|
4
|
+
ExtendComponentHandler,
|
|
5
|
+
ExtendComponentOptions,
|
|
6
|
+
} from '@telia-ace/widget-core';
|
|
7
|
+
import { Container } from '@webprovisions/platform';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Registers a Lit component on the component platform.
|
|
11
|
+
* @param container Container to register the component on.
|
|
12
|
+
* @param type Type name to resolve the component from configuration.
|
|
13
|
+
* @param component Promise resolving to the Lit component for rendering.
|
|
14
|
+
* @param fn Handler for controlling the component.
|
|
15
|
+
*/
|
|
16
|
+
const createLitComponent = (
|
|
17
|
+
container: Container,
|
|
18
|
+
type: string,
|
|
19
|
+
component: any, // e.g. import('./component.ts)
|
|
20
|
+
fn?: ExtendComponentHandler,
|
|
21
|
+
options?: ExtendComponentOptions
|
|
22
|
+
) => {
|
|
23
|
+
return container
|
|
24
|
+
.getAsync('componentResolver')
|
|
25
|
+
.then((componentResolver: ComponentResolver) => {
|
|
26
|
+
componentResolver.registerComponent(type, component);
|
|
27
|
+
return extendComponent(container, type, fn || (() => {}), type, options);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default createLitComponent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ActionResolver, WidgetRenderState } from '@telia-ace/widget-core';
|
|
2
|
+
import { Container } from '@webprovisions/platform';
|
|
3
|
+
|
|
4
|
+
export const getRenderState = async (container: Container) => {
|
|
5
|
+
const widget = container.get('$widget');
|
|
6
|
+
|
|
7
|
+
const renderState: WidgetRenderState = await widget.invoke('renderState');
|
|
8
|
+
|
|
9
|
+
return renderState;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const subscribeToRenderState = async (
|
|
13
|
+
container: Container,
|
|
14
|
+
subscriptionFn: (origin: string, action: string) => void
|
|
15
|
+
) => {
|
|
16
|
+
const widget = container.get('$widget');
|
|
17
|
+
|
|
18
|
+
const actionResolver: ActionResolver = await container.getAsync(
|
|
19
|
+
'actionResolver'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const unsubscribe = actionResolver.subscribe(widget.name, subscriptionFn);
|
|
23
|
+
|
|
24
|
+
return unsubscribe;
|
|
25
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ComponentNodeController } from '@telia-ace/widget-core';
|
|
2
|
+
import { Container } from '@webprovisions/platform';
|
|
3
|
+
|
|
4
|
+
type DataResource = {
|
|
5
|
+
query: (
|
|
6
|
+
input: Record<string, any>,
|
|
7
|
+
providerSettings: Record<string, any>
|
|
8
|
+
) => Promise<any>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type DataProviderSettings = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
export const getProvider = async (
|
|
14
|
+
component: ComponentNodeController,
|
|
15
|
+
container: Container
|
|
16
|
+
) => {
|
|
17
|
+
const providerProperty: string | [string, any] | undefined =
|
|
18
|
+
component.properties().provider;
|
|
19
|
+
let providerSettings = {};
|
|
20
|
+
|
|
21
|
+
let providerKey = '';
|
|
22
|
+
if (Array.isArray(providerProperty)) {
|
|
23
|
+
providerKey = providerProperty[0];
|
|
24
|
+
providerSettings = providerProperty[1];
|
|
25
|
+
} else {
|
|
26
|
+
providerKey = providerProperty || '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const provider: DataProvider | undefined = await container.getAsync(
|
|
30
|
+
providerKey
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (!provider) {
|
|
34
|
+
throw new Error('No provider defined in ListComponent');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
provider.applyComponentNodeSettings(component.node.id, providerSettings);
|
|
38
|
+
|
|
39
|
+
return { provider, settings: providerSettings };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const createDataProvider = async (
|
|
43
|
+
component: ComponentNodeController,
|
|
44
|
+
container: Container
|
|
45
|
+
) => {
|
|
46
|
+
const { provider, settings = {} } = await getProvider(component, container);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
addResource: (resourceKey: string, resource: DataResource) => {
|
|
50
|
+
return provider.addResource(resourceKey, resource);
|
|
51
|
+
},
|
|
52
|
+
getData: (resourceKey: string, input: Record<string, any>) => {
|
|
53
|
+
return provider.getData(resourceKey, input, settings);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export class DataProvider {
|
|
59
|
+
private resources = new Map<string, DataResource>();
|
|
60
|
+
private nodeConfiguration = new Map<string, DataProviderSettings>();
|
|
61
|
+
|
|
62
|
+
constructor(public container: Container) {}
|
|
63
|
+
|
|
64
|
+
async getData(
|
|
65
|
+
resourceKey: string,
|
|
66
|
+
input: Record<string, any>,
|
|
67
|
+
providerSettings: Record<string, any>
|
|
68
|
+
) {
|
|
69
|
+
const entityProvider = this.resources.get(resourceKey);
|
|
70
|
+
|
|
71
|
+
if (!entityProvider) {
|
|
72
|
+
throw new Error(`Unable to get EntityProvider for "${resourceKey}"`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const response = await entityProvider.query(input, providerSettings);
|
|
76
|
+
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
addResource(resourceKey: string, resource: DataResource) {
|
|
81
|
+
this.resources.set(resourceKey, resource);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
applyComponentNodeSettings(nodeId: string, value: DataProviderSettings) {
|
|
85
|
+
this.nodeConfiguration.set(nodeId, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
2
|
+
import { DataProvider } from '../data-provider';
|
|
3
|
+
|
|
4
|
+
type RawGuide = any;
|
|
5
|
+
|
|
6
|
+
const formatGuideToItem = (rawGuide: Record<string, RawGuide>) => {
|
|
7
|
+
return {
|
|
8
|
+
title: rawGuide.Title,
|
|
9
|
+
id: rawGuide.Id.toString(),
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
class GuideProvider extends DataProvider {
|
|
14
|
+
constructor(container: Container) {
|
|
15
|
+
super(container);
|
|
16
|
+
|
|
17
|
+
this.addResource('item', {
|
|
18
|
+
query: async (input: Record<string, any>, providerSettings) => {
|
|
19
|
+
const itemId = input.itemId;
|
|
20
|
+
const client = '78aacc09-ae6f-5485-5ca3-9dacebb95825';
|
|
21
|
+
const funnel = container.get('$widget').name;
|
|
22
|
+
const projection = providerSettings.projection || '';
|
|
23
|
+
|
|
24
|
+
const response = await fetch(
|
|
25
|
+
`${projection}/guides/${itemId}?client=${client}&funnel=${funnel}&site=%2F%2Fdemo.humany.cc%2Fadmin%2Finterfaces&phrase=&connectionId=&p.LastGuideId=2857`
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
|
|
30
|
+
return data ? formatGuideToItem(data) : null;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.addResource('items', {
|
|
35
|
+
query: async (_input, providerSettings) => {
|
|
36
|
+
const client = '';
|
|
37
|
+
const funnel = container.get('$widget').name;
|
|
38
|
+
const projection = providerSettings.projection || '';
|
|
39
|
+
const site = '';
|
|
40
|
+
const skip = '0';
|
|
41
|
+
const take = '10';
|
|
42
|
+
|
|
43
|
+
const response = await fetch(
|
|
44
|
+
`${projection}/guides?client=${client}&funnel=${funnel}&site=${site}&phrase=&skip=${skip}&take=${take}&sorting.type=popularity&sorting.direction=descending`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const data = await response.json();
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
items: (data.Matches || []).map((item: RawGuide) => {
|
|
51
|
+
return formatGuideToItem(item);
|
|
52
|
+
}),
|
|
53
|
+
totalItems: data?.TotalMatches || 0,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const GuideProviderPlugin = async (container: Container) => {
|
|
61
|
+
container.registerAsync('guideProvider', () => {
|
|
62
|
+
return new GuideProvider(container);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
// export { default as Component } from './ui/component';
|
|
2
|
+
// export { default as DetachedComponent } from './ui/detached-component';
|
|
3
|
+
// export { default as NotFound } from './ui/not-found';
|
|
4
|
+
// export { styling as genericComponentStyling } from './ui/styles';
|
|
1
5
|
export { default as GridWidget, default as Widget } from './widget';
|
|
6
|
+
|
|
2
7
|
export { childrenContext } from './context/children.context';
|
|
3
8
|
export { descriptorContext } from './context/component-node.context';
|
|
4
9
|
export { containerContext } from './context/container.context';
|
|
5
10
|
export { contextCtx } from './context/context.context';
|
|
6
11
|
export { layoutCtx } from './context/layout.context';
|
|
7
12
|
export { propertiesCtx } from './context/properties.context';
|
|
13
|
+
|
|
8
14
|
export { ActionsController } from './controllers/actions-controller';
|
|
9
|
-
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
DataProvider,
|
|
18
|
+
createDataProvider,
|
|
19
|
+
} from './data-provider/data-provider';
|
|
10
20
|
export { GuideProviderPlugin } from './data-provider/providers/guide-provider.plugin';
|
|
21
|
+
|
|
11
22
|
export { default as createWebComponent } from './core/create-lit-component';
|
|
23
|
+
|
|
12
24
|
export { WidgetComponent } from './mixins/widget-component.mixin';
|