@telia-ace/widget-runtime-flamingo 1.1.2 → 1.1.3

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 (70) hide show
  1. package/component-platform-factory.d.ts +13 -0
  2. package/context/children.context.d.ts +4 -0
  3. package/context/component-node.context.d.ts +4 -0
  4. package/context/container.context.d.ts +4 -0
  5. package/context/context.context.d.ts +3 -0
  6. package/context/layout.context.d.ts +3 -0
  7. package/context/properties.context.d.ts +3 -0
  8. package/controllers/actions-controller.d.ts +14 -0
  9. package/core/create-lit-component.d.ts +11 -0
  10. package/core/get-render-state.d.ts +4 -0
  11. package/data-provider/data-provider.d.ts +24 -0
  12. package/data-provider/providers/guide-provider.plugin.d.ts +2 -0
  13. package/index-4be3f206.mjs +3409 -0
  14. package/index-5087564d.mjs +335 -0
  15. package/index-6dd00f59.js +1 -0
  16. package/index-e07bd0fb.js +206 -0
  17. package/{src/index.ts → index.d.ts} +1 -13
  18. package/index.js +1 -0
  19. package/index.mjs +17 -0
  20. package/mixins/widget-component.mixin.d.ts +24 -0
  21. package/package.json +1 -1
  22. package/render-049911af.mjs +458 -0
  23. package/render-f343a6c5.js +120 -0
  24. package/services.d.ts +5 -0
  25. package/ui/area.d.ts +9 -0
  26. package/ui/branding.d.ts +1 -0
  27. package/ui/get-css-props.d.ts +5 -0
  28. package/ui/get-layout-props.d.ts +9 -0
  29. package/ui/html-element-handlers.d.ts +14 -0
  30. package/ui/prepare-dom.d.ts +21 -0
  31. package/ui/render.d.ts +3 -0
  32. package/ui/trigger-component.d.ts +20 -0
  33. package/ui/view-outlet.d.ts +36 -0
  34. package/ui/wrapper.d.ts +21 -0
  35. package/widget.d.ts +54 -0
  36. package/.eslintrc.json +0 -30
  37. package/README.md +0 -11
  38. package/project.json +0 -48
  39. package/src/component-platform-factory.ts +0 -163
  40. package/src/context/children.context.ts +0 -4
  41. package/src/context/component-node.context.ts +0 -6
  42. package/src/context/container.context.ts +0 -6
  43. package/src/context/context.context.ts +0 -3
  44. package/src/context/layout.context.ts +0 -3
  45. package/src/context/properties.context.ts +0 -3
  46. package/src/controllers/actions-controller.ts +0 -55
  47. package/src/core/create-lit-component.ts +0 -31
  48. package/src/core/get-render-state.ts +0 -25
  49. package/src/data-provider/data-provider.ts +0 -87
  50. package/src/data-provider/providers/guide-provider.plugin.ts +0 -64
  51. package/src/declaration.d.ts +0 -2
  52. package/src/mixins/widget-component.mixin.ts +0 -231
  53. package/src/services.ts +0 -27
  54. package/src/ui/area.ts +0 -97
  55. package/src/ui/branding.ts +0 -25
  56. package/src/ui/get-css-props.ts +0 -23
  57. package/src/ui/get-layout-props.ts +0 -41
  58. package/src/ui/html-element-handlers.ts +0 -140
  59. package/src/ui/index.ts +0 -6
  60. package/src/ui/prepare-dom.ts +0 -164
  61. package/src/ui/render.ts +0 -19
  62. package/src/ui/trigger-component.ts +0 -200
  63. package/src/ui/view-outlet.ts +0 -172
  64. package/src/ui/wrapper.ts +0 -247
  65. package/src/vite.env.d.ts +0 -1
  66. package/src/widget.ts +0 -748
  67. package/tsconfig.json +0 -23
  68. package/tsconfig.lib.json +0 -10
  69. package/tsconfig.spec.json +0 -19
  70. package/vite.config.ts +0 -56
@@ -1,231 +0,0 @@
1
- import { LitElement, css } from 'lit';
2
- import { childrenContext } from '../context/children.context';
3
- import { propertiesCtx } from '../context/properties.context';
4
- import { contextCtx } from '../context/context.context';
5
- import { layoutCtx } from '../context/layout.context';
6
- import { ContextProvider, consume } from '@lit-labs/context';
7
- import {
8
- Container,
9
- EventSubscriptionCancellation,
10
- } from '@webprovisions/platform';
11
- import { containerContext } from '../context/container.context';
12
- import { property, state } from 'lit/decorators.js';
13
- import {
14
- ComponentDescriptor,
15
- ComponentPlatform,
16
- ComponentResolver,
17
- asDescriptor,
18
- } from '@telia-ace/widget-core';
19
- import { descriptorContext } from '../context/component-node.context';
20
- import { ActionsController } from '../controllers/actions-controller';
21
- import { mapBranding } from '../ui/branding';
22
- import { appendStyleFromProperties } from '../ui/get-css-props';
23
-
24
- // eslint-disable-next-line @typescript-eslint/ban-types
25
- type Constructor<T = {}> = new (...args: any[]) => T;
26
-
27
- export declare class WidgetComponentInterface {
28
- entry: string;
29
- descriptor?: ComponentDescriptor;
30
- component?: any;
31
- layout: Record<string, any>;
32
- context: Record<string, any>;
33
- properties: Record<string, any>;
34
- container?: Container;
35
- actions: ActionsController;
36
- _contextProvider: ContextProvider<typeof contextCtx>;
37
- _propertiesProvider: ContextProvider<typeof propertiesCtx>;
38
- _childrenProvider: ContextProvider<typeof childrenContext>;
39
- }
40
-
41
- export const WidgetComponent = <T extends Constructor<LitElement>>(
42
- superClass: T
43
- ) => {
44
- class WidgetComponentClass extends superClass {
45
- static styles = [
46
- (superClass as unknown as typeof LitElement).styles ?? [],
47
- css`
48
- :host {
49
- font-family: var(--font-family);
50
- grid-column: span var(--width);
51
- max-width: 100%;
52
- overflow: hidden;
53
- box-sizing: border-box;
54
- display: block;
55
- }
56
- * {
57
- box-sizing: border-box;
58
- }
59
- `,
60
- ];
61
-
62
- @consume({ context: containerContext })
63
- @property({ attribute: false })
64
- public container?: Container;
65
-
66
- @property()
67
- entry = '';
68
-
69
- private _descriptorProvider = new ContextProvider(
70
- this,
71
- descriptorContext,
72
- undefined
73
- );
74
- _childrenProvider = new ContextProvider(this, childrenContext, []);
75
- _propertiesProvider = new ContextProvider(this, propertiesCtx, {});
76
- _contextProvider = new ContextProvider(this, contextCtx, {});
77
- private _layoutProvider = new ContextProvider(this, layoutCtx, {});
78
-
79
- private _propertyChangeListener?: EventSubscriptionCancellation;
80
- private _contextChangeListener?: EventSubscriptionCancellation;
81
- private _layoutChangeListener?: EventSubscriptionCancellation;
82
- private _unmountNode?: any;
83
-
84
- actions = new ActionsController(this);
85
-
86
- @state()
87
- descriptor?: ComponentDescriptor;
88
-
89
- @state()
90
- component?: any;
91
-
92
- @state()
93
- context: Record<string, any> = {};
94
-
95
- @state()
96
- layout: Record<string, any> = {};
97
-
98
- @state()
99
- properties: Record<string, any> = {};
100
-
101
- override connectedCallback() {
102
- super.connectedCallback();
103
-
104
- if (this.container) {
105
- this.actions.setContainer(this.container);
106
- ComponentPlatform.getInstance(this.container).then(
107
- async (componentPlatform) => {
108
- const componentNode = componentPlatform.nodes.get(this.entry);
109
- if (componentNode) {
110
- this._propertyChangeListener = componentPlatform.events.subscribe(
111
- 'components:properties-changed',
112
- (_event, data) => {
113
- if (
114
- componentNode.id === data.node.id /*&& isMounted.current*/
115
- ) {
116
- this._setProperties(data.node.attributes.properties);
117
- }
118
- }
119
- );
120
- this._contextChangeListener = componentPlatform.events.subscribe(
121
- 'components:context-changed',
122
- (_event, data) => {
123
- if (
124
- componentNode.id === data.node.id /*&& isMounted.current*/
125
- ) {
126
- this._setContext(data.node.attributes.context);
127
- }
128
- }
129
- );
130
- this._layoutChangeListener = componentPlatform.events.subscribe(
131
- 'components:layout-changed',
132
- (_event, data) => {
133
- if (
134
- componentNode.id === data.node.id /*&& isMounted.current*/
135
- ) {
136
- this._setLayout(data.node.attributes.layout);
137
- }
138
- }
139
- );
140
-
141
- const branch = 'default'; // TODO:
142
-
143
- this._unmountNode = componentNode.mount(this.container!);
144
-
145
- this._setDescriptor(asDescriptor(componentNode, branch));
146
- this._setProperties(componentNode.attributes.properties);
147
- this._setContext(componentNode.attributes.context);
148
- this._setLayout(this.layout);
149
-
150
- const children = componentNode
151
- .getChildren(branch)
152
- .map((child) => asDescriptor(child));
153
-
154
- this._childrenProvider.setValue(children);
155
-
156
- const resolver: ComponentResolver =
157
- await this.container!.getAsync('componentResolver');
158
-
159
- if (this.descriptor?.type === 'area') {
160
- return;
161
- }
162
-
163
- const componentResolver = resolver.getComponent(
164
- this.descriptor?.type || ''
165
- );
166
- if (componentResolver.then) {
167
- componentResolver.then((componentModule: any) => {
168
- this.component = componentModule.default;
169
- });
170
- }
171
- }
172
- }
173
- );
174
- }
175
- }
176
-
177
- override disconnectedCallback(): void {
178
- super.disconnectedCallback();
179
-
180
- if (this._propertyChangeListener) {
181
- this._propertyChangeListener();
182
- }
183
- if (this._contextChangeListener) {
184
- this._contextChangeListener();
185
- }
186
- if (this._layoutChangeListener) {
187
- this._layoutChangeListener();
188
- }
189
-
190
- if (this._unmountNode) {
191
- this._unmountNode();
192
- }
193
- }
194
-
195
- override updated() {
196
- if (this.container) {
197
- this.actions.setContainer(this.container);
198
- }
199
- mapBranding(this.context, (this.renderRoot as any).host);
200
-
201
- (this.renderRoot as any).host.style.setProperty(
202
- '--width',
203
- this.layout.size === 'full'
204
- ? 'var(--columns, 1)'
205
- : `min(${this.layout.size || 'var(--columns)'}, var(--columns))`
206
- );
207
-
208
- appendStyleFromProperties((this.renderRoot as any).host, this.properties);
209
- }
210
-
211
- private _setProperties(value: Record<string, any>) {
212
- this._propertiesProvider.setValue(value);
213
- this.properties = value;
214
- }
215
- private _setContext(value: Record<string, any>) {
216
- this._contextProvider.setValue(value);
217
- this.context = value;
218
- }
219
- private _setLayout(value: Record<string, any>) {
220
- this._layoutProvider.setValue(value);
221
- this.layout = value;
222
- }
223
- private _setDescriptor(value: ComponentDescriptor) {
224
- this.descriptor = value;
225
- this._descriptorProvider.setValue(value);
226
- this.actions.setDescriptor(value);
227
- }
228
- }
229
- // Cast return type to your mixin's interface intersected with the superClass type
230
- return WidgetComponentClass as Constructor<WidgetComponentInterface> & T;
231
- };
package/src/services.ts DELETED
@@ -1,27 +0,0 @@
1
- import { Container } from '@webprovisions/platform';
2
- import { createPlatform } from './component-platform-factory';
3
-
4
- export const createStorageService = (_container: Container) => {
5
- return import('@telia-ace/widget-services').then(({ StorageProvider }) => {
6
- return new StorageProvider();
7
- });
8
- };
9
-
10
- export const createActionResolver = (container: Container) => {
11
- return import('@telia-ace/widget-core').then(({ ActionResolver }) => {
12
- return new ActionResolver(container);
13
- });
14
- };
15
-
16
- export const createComponentResolver = (container: Container) => {
17
- return import('@telia-ace/widget-core').then(({ ComponentResolver }) => {
18
- return new ComponentResolver(container);
19
- });
20
- };
21
-
22
- export const createComponentPlatform = (container: Container) => {
23
- return import('@telia-ace/widget-core').then(() => {
24
- // ({ ComponentPlatform, createComponentModel }) => {
25
- return createPlatform(container.get('$widget'));
26
- });
27
- };
package/src/ui/area.ts DELETED
@@ -1,97 +0,0 @@
1
- import { LitElement, css, html } from 'lit';
2
- import { customElement } from 'lit/decorators.js';
3
- import { until } from 'lit/directives/until.js';
4
- import { mapBranding } from './branding';
5
- import { appendStyleFromProperties } from './get-css-props';
6
- import { ComponentDescriptor, ComponentResolver } from '@telia-ace/widget-core';
7
- import { WidgetComponent } from '../mixins/widget-component.mixin';
8
-
9
- const WidgetElement = WidgetComponent(LitElement);
10
-
11
- @customElement('ace-area')
12
- export class AreaComponent extends WidgetElement {
13
- static override styles = [
14
- WidgetElement.styles || [],
15
- css`
16
- :host {
17
- height: 100%;
18
- display: grid;
19
- justify-content: center;
20
- grid-auto-rows: max-content;
21
- grid-template-rows: auto;
22
- grid-template-columns: repeat(var(--columns), 1fr);
23
- }
24
- `,
25
- ];
26
-
27
- private _resolveChildComponent = async (type: string) => {
28
- const resolver: ComponentResolver = await this.container!.getAsync(
29
- 'componentResolver'
30
- );
31
-
32
- const componentResolver = resolver.getComponent(type);
33
- if (componentResolver.then) {
34
- return componentResolver.then((componentModule: any) => {
35
- return componentModule.default;
36
- });
37
- }
38
- };
39
-
40
- private _resolveAllChildren = async (children: ComponentDescriptor[]) => {
41
- return Promise.all(
42
- children.map(async (child) => {
43
- let component: any = customElements.get(`ace-${child.type}`);
44
-
45
- if (!component) {
46
- component = await this._resolveChildComponent(child.type || '');
47
- }
48
-
49
- return {
50
- ...child,
51
- component,
52
- };
53
- })
54
- );
55
- };
56
-
57
- override render() {
58
- mapBranding(this.context, (this.renderRoot as any).host);
59
-
60
- (this.renderRoot as any).host.style.setProperty(
61
- '--width',
62
- this.layout.size === 'full'
63
- ? 'var(--columns, 1)'
64
- : `min(${this.layout.size || 'var(--columns)'}, var(--columns))`
65
- );
66
-
67
- (this.renderRoot as any).host.style.setProperty(
68
- '--columns',
69
- this._propertiesProvider.value.columns?.toString() || '1'
70
- );
71
-
72
- appendStyleFromProperties(
73
- (this.renderRoot as any).host,
74
- this._propertiesProvider.value
75
- );
76
-
77
- return html`
78
- ${until(
79
- this._resolveAllChildren(this._childrenProvider.value).then(
80
- (children) => {
81
- return html`
82
- ${children.map((child) => {
83
- if (child.type === 'area') {
84
- return html`<ace-area entry=${child.id}></ace-area>`;
85
- }
86
-
87
- const instance = new child.component();
88
- instance.entry = child.id;
89
- return instance;
90
- })}
91
- `;
92
- }
93
- )
94
- )}
95
- `;
96
- }
97
- }
@@ -1,25 +0,0 @@
1
- const mapValue = (value: string, cssVar: string, el: HTMLElement) => {
2
- if (value) {
3
- el.style.setProperty(cssVar, value);
4
- }
5
- };
6
-
7
- export const mapBranding = (context: Record<string, any>, el: HTMLElement) => {
8
- mapValue(context.colors?.primary, '--primary-color', el);
9
- mapValue(context.colors?.secondary, '--secondary-color', el);
10
- mapValue(context.colors?.text, '--text-color', el);
11
- mapValue(context.colors?.link, '--link-color', el);
12
- mapValue(context.colors?.gray, '--gray-color', el);
13
- mapValue(context.colors?.grayDark, '--gray-dark-color', el);
14
-
15
- mapValue(context.spacing?.xs, '--spacing-xs', el);
16
- mapValue(context.spacing?.sm, '--spacing-sm', el);
17
- mapValue(context.spacing?.md, '--spacing-md', el);
18
- mapValue(context.spacing?.lg, '--spacing-lg', el);
19
- mapValue(context.spacing?.xl, '--spacing-xl', el);
20
-
21
- mapValue(context.boxShadow, '--box-shadow', el);
22
- mapValue(context.borderRadius, '--border-radius', el);
23
- mapValue(context.borderRadiusSm, '--border-radius-sm', el);
24
- mapValue(context.fontFamily, '--font-family', el);
25
- };
@@ -1,23 +0,0 @@
1
- const filterCssProps = (props: Record<string, any>) => {
2
- const cssProps: { [key: string]: any } = {};
3
-
4
- Object.keys(props).forEach((key) => {
5
- if (key.indexOf('css-') > -1) {
6
- cssProps[key] = props[key];
7
- }
8
- });
9
-
10
- return cssProps;
11
- };
12
-
13
- export const appendStyleFromProperties = (
14
- elem: HTMLElement,
15
- p: Record<string, any>
16
- ) => {
17
- const props = filterCssProps(p);
18
- Object.entries(props).forEach(([key, value]) => {
19
- elem.style.setProperty(key.replace('css-', ''), value);
20
- });
21
- };
22
-
23
- export default filterCssProps;
@@ -1,41 +0,0 @@
1
- type LayoutSettings = {
2
- values: Record<string, string>;
3
- breakpoints?: string[];
4
- };
5
-
6
- export const getLayoutProps = (
7
- settings: LayoutSettings[],
8
- activeBreakpoints: string[],
9
- hasTrigger = false
10
- ) => {
11
- const layoutProps = settings.reduce<Record<string, string>>(
12
- (acc, { breakpoints = [], values }) => {
13
- if (!breakpoints.length) {
14
- return { ...acc, ...values };
15
- }
16
-
17
- if (
18
- activeBreakpoints.some((breakpoint) => breakpoints.includes(breakpoint))
19
- ) {
20
- return { ...acc, ...values };
21
- }
22
- return acc;
23
- },
24
- {}
25
- );
26
-
27
- const styles: Record<string, string> = {};
28
- const type = layoutProps.type;
29
-
30
- styles.height = layoutProps.height || '';
31
- styles.width = layoutProps.width || '';
32
-
33
- if (layoutProps.type === 'floating') {
34
- //
35
- } else if (layoutProps.type === 'inline') {
36
- if (hasTrigger) {
37
- styles['height'] = 'calc(100vh - 120px)';
38
- }
39
- }
40
- return { type, styles };
41
- };
@@ -1,140 +0,0 @@
1
- const triggerTabHandler = (triggerDOMElement: HTMLElement) => {
2
- const toggleTabbing = (element: HTMLElement, tabbing: boolean) => {
3
- if (!element) {
4
- return;
5
- }
6
-
7
- if (tabbing) {
8
- element.classList.add('ace-tabbing');
9
- } else {
10
- element.classList.remove('ace-tabbing');
11
- }
12
- };
13
-
14
- const handleKeydown = (e: KeyboardEvent) => {
15
- if (e.key === 'Tab') {
16
- toggleTabbing(triggerDOMElement, true);
17
- } else if (
18
- !(
19
- e.key === 'Enter' &&
20
- document.activeElement &&
21
- document.activeElement.classList.contains('ace-widget-trigger')
22
- )
23
- ) {
24
- toggleTabbing(triggerDOMElement, false);
25
- }
26
- };
27
-
28
- const handleClick = (_e: MouseEvent) => {
29
- if (
30
- document.activeElement &&
31
- document.activeElement.classList.contains('ace-widget-trigger') &&
32
- document.activeElement.classList.contains('ace-tabbing')
33
- ) {
34
- return;
35
- }
36
- toggleTabbing(triggerDOMElement, false);
37
- };
38
-
39
- document.addEventListener('keydown', handleKeydown);
40
- document.addEventListener('click', handleClick);
41
-
42
- return () => {
43
- document.removeEventListener('keydown', handleKeydown);
44
- document.removeEventListener('click', handleClick);
45
- };
46
- };
47
-
48
- export type TriggerElementOptions = {
49
- symbol?: { type: string; content: string };
50
- widgetName: string;
51
- label?: string;
52
- ariaLabel?: string;
53
- tooltip?: string;
54
- };
55
-
56
- export function createTriggerElement(
57
- element: HTMLElement,
58
- options: TriggerElementOptions
59
- ) {
60
- const {
61
- // symbol,
62
- widgetName,
63
- label = '',
64
- ariaLabel = '',
65
- tooltip = '',
66
- } = options;
67
-
68
- element.classList.add('ace-widget-trigger');
69
- element.classList.add(`ace-widget_${widgetName}`);
70
-
71
- if (label.length) {
72
- element.classList.add('trigger-has-text');
73
- }
74
-
75
- if (ariaLabel.length && !element.getAttribute('aria-label')) {
76
- element.setAttribute('aria-label', ariaLabel);
77
- }
78
-
79
- if (ariaLabel.length && !element.getAttribute('tabindex')) {
80
- element.setAttribute('tabindex', '0');
81
- }
82
-
83
- if (tooltip.length && !element.getAttribute('title')) {
84
- element.setAttribute('title', tooltip);
85
- }
86
-
87
- return triggerTabHandler(element);
88
- }
89
-
90
- export function setInactive(
91
- elements: HTMLElement | HTMLElement[],
92
- title?: string
93
- ) {
94
- if (elements instanceof HTMLElement) {
95
- if (title) {
96
- elements.setAttribute('title', title);
97
- }
98
- elements.classList.remove('ace-trigger-active');
99
- elements.classList.remove('ace-trigger-loading');
100
- } else if (elements instanceof Array) {
101
- elements.forEach((e) => {
102
- if (title) {
103
- e.setAttribute('title', title);
104
- }
105
- e.classList.remove('ace-trigger-active');
106
- e.classList.remove('ace-trigger-loading');
107
- });
108
- }
109
- }
110
- export function setLoading(elements: HTMLElement | HTMLElement[]) {
111
- if (elements instanceof HTMLElement) {
112
- elements.classList.remove('ace-trigger-active');
113
- elements.classList.add('ace-trigger-loading');
114
- } else if (elements instanceof Array) {
115
- elements.forEach((e) => {
116
- e.classList.remove('ace-trigger-active');
117
- e.classList.add('ace-trigger-loading');
118
- });
119
- }
120
- }
121
- export function setActive(
122
- elements: HTMLElement | HTMLElement[],
123
- title?: string
124
- ) {
125
- if (elements instanceof HTMLElement) {
126
- if (title) {
127
- elements.setAttribute('title', title);
128
- }
129
- elements.classList.add('ace-trigger-active');
130
- elements.classList.remove('ace-trigger-loading');
131
- } else if (elements instanceof Array) {
132
- elements.forEach((e) => {
133
- if (title) {
134
- e.setAttribute('title', title);
135
- }
136
- e.classList.add('ace-trigger-active');
137
- e.classList.remove('ace-trigger-loading');
138
- });
139
- }
140
- }
package/src/ui/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // export { default as AnimatedView } from './animated-view';
2
- // export { default as Component } from './_component';
3
- export { prepareDOMElements, TriggerType } from './prepare-dom';
4
- // export { default as ResolvableComponent } from './resolvable-component';
5
- // export { default as View } from './view';
6
- // export { default as Wrapper } from './wrapper';