@telia-ace/widget-types-grid 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.
Files changed (91) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +3 -0
  3. package/lib/component-platform-factory.d.ts +13 -0
  4. package/lib/component-platform-factory.js +105 -0
  5. package/lib/index.d.ts +4 -0
  6. package/lib/index.js +16 -0
  7. package/lib/services.d.ts +7 -0
  8. package/lib/services.js +99 -0
  9. package/lib/site-provider.d.ts +5 -0
  10. package/lib/site-provider.js +18 -0
  11. package/lib/ui/animated-view.d.ts +6 -0
  12. package/lib/ui/animated-view.js +142 -0
  13. package/lib/ui/component.d.ts +18 -0
  14. package/lib/ui/component.js +179 -0
  15. package/lib/ui/detached-component.d.ts +7 -0
  16. package/lib/ui/detached-component.js +73 -0
  17. package/lib/ui/determine-slide-direction.d.ts +26 -0
  18. package/lib/ui/determine-slide-direction.js +51 -0
  19. package/lib/ui/html-element-handlers.d.ts +18 -0
  20. package/lib/ui/html-element-handlers.js +128 -0
  21. package/lib/ui/index.d.ts +6 -0
  22. package/lib/ui/index.js +19 -0
  23. package/lib/ui/not-found.d.ts +6 -0
  24. package/lib/ui/not-found.js +83 -0
  25. package/lib/ui/prepare-dom.d.ts +20 -0
  26. package/lib/ui/prepare-dom.js +122 -0
  27. package/lib/ui/render.d.ts +3 -0
  28. package/lib/ui/render.js +11 -0
  29. package/lib/ui/resolvable-component.d.ts +7 -0
  30. package/lib/ui/resolvable-component.js +87 -0
  31. package/lib/ui/switch.d.ts +11 -0
  32. package/lib/ui/switch.js +58 -0
  33. package/lib/ui/unmount.d.ts +2 -0
  34. package/lib/ui/unmount.js +4 -0
  35. package/lib/ui/use-component-node-properties.d.ts +3 -0
  36. package/lib/ui/use-component-node-properties.js +44 -0
  37. package/lib/ui/use-router.d.ts +4 -0
  38. package/lib/ui/use-router.js +32 -0
  39. package/lib/ui/view-outlet.d.ts +32 -0
  40. package/lib/ui/view-outlet.js +151 -0
  41. package/lib/ui/view.d.ts +6 -0
  42. package/lib/ui/view.js +75 -0
  43. package/lib/ui/wrapper.d.ts +7 -0
  44. package/lib/ui/wrapper.js +108 -0
  45. package/lib/widget.d.ts +54 -0
  46. package/lib/widget.js +554 -0
  47. package/lib-esm/component-platform-factory.d.ts +13 -0
  48. package/lib-esm/component-platform-factory.js +101 -0
  49. package/lib-esm/index.d.ts +4 -0
  50. package/lib-esm/index.js +4 -0
  51. package/lib-esm/services.d.ts +7 -0
  52. package/lib-esm/services.js +67 -0
  53. package/lib-esm/site-provider.d.ts +5 -0
  54. package/lib-esm/site-provider.js +14 -0
  55. package/lib-esm/ui/animated-view.d.ts +6 -0
  56. package/lib-esm/ui/animated-view.js +114 -0
  57. package/lib-esm/ui/component.d.ts +18 -0
  58. package/lib-esm/ui/component.js +150 -0
  59. package/lib-esm/ui/detached-component.d.ts +7 -0
  60. package/lib-esm/ui/detached-component.js +45 -0
  61. package/lib-esm/ui/determine-slide-direction.d.ts +26 -0
  62. package/lib-esm/ui/determine-slide-direction.js +46 -0
  63. package/lib-esm/ui/html-element-handlers.d.ts +18 -0
  64. package/lib-esm/ui/html-element-handlers.js +120 -0
  65. package/lib-esm/ui/index.d.ts +6 -0
  66. package/lib-esm/ui/index.js +6 -0
  67. package/lib-esm/ui/not-found.d.ts +6 -0
  68. package/lib-esm/ui/not-found.js +58 -0
  69. package/lib-esm/ui/prepare-dom.d.ts +20 -0
  70. package/lib-esm/ui/prepare-dom.js +116 -0
  71. package/lib-esm/ui/render.d.ts +3 -0
  72. package/lib-esm/ui/render.js +6 -0
  73. package/lib-esm/ui/resolvable-component.d.ts +7 -0
  74. package/lib-esm/ui/resolvable-component.js +62 -0
  75. package/lib-esm/ui/switch.d.ts +11 -0
  76. package/lib-esm/ui/switch.js +53 -0
  77. package/lib-esm/ui/unmount.d.ts +2 -0
  78. package/lib-esm/ui/unmount.js +2 -0
  79. package/lib-esm/ui/use-component-node-properties.d.ts +3 -0
  80. package/lib-esm/ui/use-component-node-properties.js +42 -0
  81. package/lib-esm/ui/use-router.d.ts +4 -0
  82. package/lib-esm/ui/use-router.js +30 -0
  83. package/lib-esm/ui/view-outlet.d.ts +32 -0
  84. package/lib-esm/ui/view-outlet.js +126 -0
  85. package/lib-esm/ui/view.d.ts +6 -0
  86. package/lib-esm/ui/view.js +70 -0
  87. package/lib-esm/ui/wrapper.d.ts +7 -0
  88. package/lib-esm/ui/wrapper.js +80 -0
  89. package/lib-esm/widget.d.ts +54 -0
  90. package/lib-esm/widget.js +551 -0
  91. package/package.json +52 -0
@@ -0,0 +1,101 @@
1
+ import { ComponentPlatform, ComponentQuery, createComponentModel, } from '@telia-ace/widget-core';
2
+ import { createStorageWriter, readStorage, StorageCategory, StorageMedium, } from '@telia-ace/widget-services';
3
+ import { lock } from '@telia-ace/widget-utilities';
4
+ import { WidgetState } from '@webprovisions/platform';
5
+ var STORAGE_KEY = 'changesets';
6
+ var convertSettingsToAttributes = function (settings) {
7
+ var attributes = { tags: settings.tags };
8
+ if (settings.context && typeof settings.context !== 'function') {
9
+ attributes.context = settings.context;
10
+ }
11
+ if (settings.properties && typeof settings.properties !== 'function') {
12
+ attributes.properties = settings.properties;
13
+ }
14
+ if (settings.layout && typeof settings.layout !== 'function') {
15
+ attributes.layout = settings.layout;
16
+ }
17
+ return attributes;
18
+ };
19
+ var LocalStorageChangesetProvider = /** @class */ (function () {
20
+ function LocalStorageChangesetProvider(container, storageWriter) {
21
+ this.container = container;
22
+ this.storageWriter = storageWriter;
23
+ }
24
+ LocalStorageChangesetProvider.create = function (container) {
25
+ return createStorageWriter(container, STORAGE_KEY, StorageCategory.Necessary, {
26
+ medium: StorageMedium.Local,
27
+ }).then(function (storageWriter) { return new LocalStorageChangesetProvider(container, storageWriter); });
28
+ };
29
+ LocalStorageChangesetProvider.prototype.write = function (key, target, attributes, options) {
30
+ var _this = this;
31
+ return lock(this)(function () {
32
+ return readStorage(_this.container, STORAGE_KEY, StorageMedium.Local).then(function (bag) {
33
+ if (bag === void 0) { bag = {}; }
34
+ var _a = bag.keys, keys = _a === void 0 ? [] : _a, _b = bag.items, items = _b === void 0 ? {} : _b;
35
+ var existingIndex = keys.indexOf(key);
36
+ if (existingIndex > -1) {
37
+ keys.splice(existingIndex, 1);
38
+ }
39
+ keys.push(key);
40
+ items[key] = {
41
+ options: options,
42
+ attributes: convertSettingsToAttributes(attributes),
43
+ rules: target.rules,
44
+ };
45
+ return _this.storageWriter({ keys: keys, items: items });
46
+ });
47
+ });
48
+ };
49
+ LocalStorageChangesetProvider.prototype.remove = function (key) {
50
+ var _this = this;
51
+ return lock(this)(function () {
52
+ return readStorage(_this.container, STORAGE_KEY, StorageMedium.Local).then(function (bag) {
53
+ if (bag === void 0) { bag = {}; }
54
+ var _a = bag.keys, keys = _a === void 0 ? [] : _a, _b = bag.items, items = _b === void 0 ? {} : _b;
55
+ var indexToRemove = keys.indexOf(key);
56
+ if (indexToRemove > -1) {
57
+ keys.splice(indexToRemove, 1);
58
+ delete items[key];
59
+ return _this.storageWriter(bag);
60
+ }
61
+ });
62
+ });
63
+ };
64
+ LocalStorageChangesetProvider.prototype.load = function (platform) {
65
+ var _this = this;
66
+ return lock(this)(function () {
67
+ return readStorage(_this.container, STORAGE_KEY, StorageMedium.Local).then(function (bag) {
68
+ if (bag === void 0) { bag = {}; }
69
+ var _a = bag.keys, keys = _a === void 0 ? [] : _a, _b = bag.items, items = _b === void 0 ? {} : _b;
70
+ keys.forEach(function (key) {
71
+ var item = items[key];
72
+ if (item) {
73
+ var rules = item.rules, attributes = item.attributes, options = item.options;
74
+ platform.write({
75
+ attributes: attributes,
76
+ options: options,
77
+ target: new ComponentQuery(platform, rules),
78
+ });
79
+ }
80
+ });
81
+ });
82
+ });
83
+ };
84
+ return LocalStorageChangesetProvider;
85
+ }());
86
+ export { LocalStorageChangesetProvider };
87
+ export var createPlatform = function (widget) {
88
+ var container = widget.container;
89
+ return LocalStorageChangesetProvider.create(container).then(function (localStorage) {
90
+ var settings = container.get('$settings');
91
+ var providers = { localStorage: localStorage };
92
+ var platform = new ComponentPlatform(widget, providers);
93
+ var destructComponentModel = createComponentModel(platform, settings);
94
+ widget.events.subscribe('widget:state-change', function (event, data) {
95
+ if (data.state === WidgetState.Deactivating) {
96
+ destructComponentModel();
97
+ }
98
+ });
99
+ return platform;
100
+ });
101
+ };
@@ -0,0 +1,4 @@
1
+ export { default as Component, styling as genericComponentStyling } from './ui/component';
2
+ export { default as DetachedComponent } from './ui/detached-component';
3
+ export { default as NotFound } from './ui/not-found';
4
+ export { default as GridWidget, default as Widget } from './widget';
@@ -0,0 +1,4 @@
1
+ export { default as Component, styling as genericComponentStyling } from './ui/component';
2
+ export { default as DetachedComponent } from './ui/detached-component';
3
+ export { default as NotFound } from './ui/not-found';
4
+ export { default as GridWidget, default as Widget } from './widget';
@@ -0,0 +1,7 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ export declare const createRoutingService: (container: Container) => Promise<any>;
3
+ export declare const createStorageService: (container: Container) => Promise<import("@telia-ace/widget-services").StorageProvider>;
4
+ export declare const createServiceClient: (container: Container) => Promise<any>;
5
+ export declare const createActionResolver: (container: Container) => Promise<import("@telia-ace/widget-core").ActionResolver>;
6
+ export declare const createComponentResolver: (container: Container) => Promise<import("@telia-ace/widget-core").ComponentResolver>;
7
+ export declare const createComponentPlatform: (container: Container) => Promise<import("@telia-ace/widget-core").ComponentPlatform>;
@@ -0,0 +1,67 @@
1
+ import { createPlatform } from './component-platform-factory';
2
+ import { createSiteProvider } from './site-provider';
3
+ export var createRoutingService = function (container) {
4
+ return import('@telia-ace/widget-routing').then(function (_a) {
5
+ var RoutingService = _a.RoutingService, HistoryMode = _a.HistoryMode;
6
+ return container.get('settings').then(function (settings) {
7
+ var _a = settings.routing, _b = _a.initialPath, initialPath = _b === void 0 ? '/' : _b, _c = _a.mode, mode = _c === void 0 ? HistoryMode.scopedHash : _c, basePath = _a.basePath, views = settings.views;
8
+ var routingService = new RoutingService(container, {
9
+ initialPath: initialPath,
10
+ mode: mode,
11
+ routes: Object.keys(views).map(function (name) { return ({
12
+ name: name,
13
+ path: views[name].path,
14
+ }); }),
15
+ basePath: basePath,
16
+ });
17
+ return routingService;
18
+ });
19
+ });
20
+ };
21
+ export var createStorageService = function (container) {
22
+ return import('@telia-ace/widget-services').then(function (_a) {
23
+ var StorageProvider = _a.StorageProvider;
24
+ return new StorageProvider();
25
+ });
26
+ };
27
+ export var createServiceClient = function (container) {
28
+ return import('@telia-ace/knowledge-serviceclient').then(function (_a) {
29
+ var ServiceClient = _a.ServiceClient, ServiceProxy = _a.ServiceProxy;
30
+ return container.get('settings').then(function (settings) {
31
+ var _a = container.get('$widget'), name = _a.name, events = _a.events;
32
+ var _b = settings.data, _c = _b.projection, projection = _c === void 0 ? '' : _c, _d = _b.site, site = _d === void 0 ? 'current' : _d, _e = _b.forceHttps, forceHttps = _e === void 0 ? false : _e;
33
+ var proxy = new ServiceProxy(projection, { credentials: 'same-origin' });
34
+ // Replacing '_contact' & '_contact-method' while
35
+ // still using the shadow widget concept
36
+ var client = new ServiceClient(proxy, {
37
+ funnel: name.replace('_contact-method', '').replace('_contact', ''),
38
+ site: createSiteProvider(site, forceHttps),
39
+ });
40
+ events.subscribe('widget:settings-updated', function (event, _a) {
41
+ var data = _a.data;
42
+ if (data && data.projection !== projection) {
43
+ client.proxy.setBaseUrl(data.projection);
44
+ }
45
+ });
46
+ return client;
47
+ });
48
+ });
49
+ };
50
+ export var createActionResolver = function (container) {
51
+ return import('@telia-ace/widget-core').then(function (_a) {
52
+ var ActionResolver = _a.ActionResolver;
53
+ return new ActionResolver(container);
54
+ });
55
+ };
56
+ export var createComponentResolver = function (container) {
57
+ return import('@telia-ace/widget-core').then(function (_a) {
58
+ var ComponentResolver = _a.ComponentResolver;
59
+ return new ComponentResolver(container);
60
+ });
61
+ };
62
+ export var createComponentPlatform = function (container) {
63
+ return import('@telia-ace/widget-core').then(function (_a) {
64
+ var ComponentPlatform = _a.ComponentPlatform, createComponentModel = _a.createComponentModel;
65
+ return createPlatform(container.get('$widget'));
66
+ });
67
+ };
@@ -0,0 +1,5 @@
1
+ export declare type SiteLocation = {
2
+ host: string;
3
+ pathname: string;
4
+ };
5
+ export declare const createSiteProvider: (site: 'current' | 'referrer', forceHttps: boolean) => (() => string);
@@ -0,0 +1,14 @@
1
+ export var createSiteProvider = function (site, forceHttps) {
2
+ return function () {
3
+ var parseLocation = function (href) {
4
+ var link = document.createElement('a');
5
+ link.href = href;
6
+ return link;
7
+ };
8
+ var location = window.location;
9
+ if (site === 'referrer' && document.referrer) {
10
+ location = parseLocation(document.referrer);
11
+ }
12
+ return [forceHttps ? 'https:' : '', '//', location.host, location.pathname].join('');
13
+ };
14
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare type Props = {
3
+ className?: string;
4
+ };
5
+ declare const AnimatedView: React.FC<Props>;
6
+ export default AnimatedView;
@@ -0,0 +1,114 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ var __rest = (this && this.__rest) || function (s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ import { Grid, transitionComposer, useComponentNode, useContainer, useContext, useProperties, useRouteData, useRouter, useScroll, } from '@telia-ace/widget-ui';
44
+ import { appendClassNames } from '@telia-ace/widget-utilities';
45
+ import React, { useState } from 'react';
46
+ import { Transition, TransitionGroup } from 'react-transition-group';
47
+ import styled from 'styled-components';
48
+ import Component from './component';
49
+ import { determineSlideDirection, SlideDirection } from './determine-slide-direction';
50
+ import Switch from './switch';
51
+ var StyledViewContainer = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative;\n width: 100%;\n flex: 1;\n"], ["\n position: relative;\n width: 100%;\n flex: 1;\n"])));
52
+ var StyledView = styled(Grid)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: absolute;\n left: 0;\n right: 0;\n ", "\n ", "\n"], ["\n position: absolute;\n left: 0;\n right: 0;\n ", "\n ", "\n"])), function (p) { return !!p.animationCss && p.animationCss; }, function (p) { return !!p.scrollableCss && p.scrollableCss; });
53
+ var routeHierarchy = {
54
+ index: 1,
55
+ search: 2,
56
+ browse: 3,
57
+ guide: 4,
58
+ contact: 5,
59
+ 'contact-method': 6,
60
+ conversation: 7,
61
+ };
62
+ var AnimatedView = function (_a) {
63
+ var _b = _a.className, className = _b === void 0 ? '' : _b, other = __rest(_a, ["className"]);
64
+ var _c = __read(useState('index'), 2), routeName = _c[0], setRouteName = _c[1];
65
+ var _d = __read(useState(SlideDirection.forth), 2), transitionDirection = _d[0], setTransitionDirection = _d[1];
66
+ var nextRoute = useRouteData();
67
+ var router = useRouter();
68
+ var properties = useProperties();
69
+ var context = useContext();
70
+ var container = useContainer();
71
+ var node = useComponentNode();
72
+ var _e = context.gap, gap = _e === void 0 ? '0' : _e;
73
+ var _f = properties.columns, columns = _f === void 0 ? 1 : _f, _g = properties.animation, animation = _g === void 0 ? 'none' : _g, _h = properties.scrollable, scrollable = _h === void 0 ? false : _h, areaProperties = __rest(properties, ["columns", "animation", "scrollable"]);
74
+ var _j = __read(useScroll(scrollable), 2), scrollableCss = _j[0], elem = _j[1];
75
+ if (!node || !router) {
76
+ return null;
77
+ }
78
+ var location = router.location;
79
+ if (nextRoute.name !== routeName && nextRoute.name !== '' && animation) {
80
+ setTransitionDirection(determineSlideDirection(routeName, nextRoute.name, routeHierarchy));
81
+ setRouteName(nextRoute.name);
82
+ }
83
+ var views = container.get('$settings').views;
84
+ if (!Object.keys(views).length) {
85
+ return null;
86
+ }
87
+ var renderView = function (name, transitionState, direction) {
88
+ var animationStyles = getAnimation(transitionState, direction);
89
+ var childNode = node.getChildren(name)[0];
90
+ return (React.createElement(StyledView, __assign({}, other, areaProperties, { scrollableCss: scrollableCss, ref: elem, columns: columns, gap: gap }, animationStyles, { className: appendClassNames(className, 'humany-view') }),
91
+ React.createElement(Component, { id: childNode.id, branch: "default" })));
92
+ };
93
+ var getAnimation = function (transitionState, direction) {
94
+ var _a;
95
+ if (animation === 'slide' || animation === 'fade') {
96
+ return _a = {
97
+ animationCss: transitionComposer.composeViewTransition(transitionState, animation, direction)
98
+ },
99
+ _a['data-state'] = transitionState,
100
+ _a;
101
+ }
102
+ return;
103
+ };
104
+ return (React.createElement(StyledViewContainer, { className: "humany-animated-view" },
105
+ React.createElement(TransitionGroup, { component: null, childFactory: function (child) {
106
+ return React.cloneElement(child, { direction: transitionDirection });
107
+ } },
108
+ React.createElement(Transition, { key: routeName, timeout: { enter: 500, exit: 500 }, onEnter: function (node) { return node === null || node === void 0 ? void 0 : node.clientHeight; }, unmountOnExit: true, direction: SlideDirection.forth }, function (state, _a) {
109
+ var direction = _a.direction;
110
+ return (React.createElement(Switch, { views: views, location: location, render: function (name) { return renderView(name, state, direction); } }));
111
+ }))));
112
+ };
113
+ export default AnimatedView;
114
+ var templateObject_1, templateObject_2;
@@ -0,0 +1,18 @@
1
+ import { ComponentNode } from '@telia-ace/widget-core';
2
+ import React from 'react';
3
+ import { DefaultTheme } from 'styled-components';
4
+ declare type Props = {
5
+ className?: string;
6
+ isTabbing?: boolean;
7
+ id: string;
8
+ branch: string;
9
+ node?: ComponentNode;
10
+ ariaLabel?: string;
11
+ tabIndex?: number;
12
+ };
13
+ declare const Component: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
14
+ export declare const styling: import("styled-components").FlattenInterpolation<import("styled-components").ThemedStyledProps<{
15
+ 'data-width': number;
16
+ 'data-indent': number;
17
+ }, DefaultTheme>>;
18
+ export default Component;
@@ -0,0 +1,150 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
5
+ var __assign = (this && this.__assign) || function () {
6
+ __assign = Object.assign || function(t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
+ t[p] = s[p];
11
+ }
12
+ return t;
13
+ };
14
+ return __assign.apply(this, arguments);
15
+ };
16
+ var __rest = (this && this.__rest) || function (s, e) {
17
+ var t = {};
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
19
+ t[p] = s[p];
20
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
21
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
22
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
23
+ t[p[i]] = s[p[i]];
24
+ }
25
+ return t;
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ import { asDescriptor } from '@telia-ace/widget-core';
44
+ import { ComponentNodeContext, ComponentPropertyContext, filterCssProps, paddedBorderTabStyle, useColumns, useComponentPlatform, useContainer, useContext, useLayout, } from '@telia-ace/widget-ui';
45
+ import React, { forwardRef, useEffect, useState } from 'react';
46
+ import styled, { css, ThemeContext, ThemeProvider } from 'styled-components';
47
+ import AnimatedView from './animated-view';
48
+ import ResolvableComponent from './resolvable-component';
49
+ import useComponentNodeProperties from './use-component-node-properties';
50
+ import View from './view';
51
+ var isVisible = function (size, node) {
52
+ if (node) {
53
+ return true;
54
+ }
55
+ if (typeof size === 'string') {
56
+ return size === 'full';
57
+ }
58
+ return size > 0;
59
+ };
60
+ var Component = forwardRef(function (_a, ref) {
61
+ var _b;
62
+ var _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.isTabbing, isTabbing = _d === void 0 ? false : _d, id = _a.id, branch = _a.branch, node = _a.node, ariaLabel = _a.ariaLabel, tabIndex = _a.tabIndex, other = __rest(_a, ["className", "isTabbing", "id", "branch", "node", "ariaLabel", "tabIndex"]);
63
+ var components = useComponentPlatform();
64
+ var container = useContainer();
65
+ var _e = __read(useState(), 2), descriptor = _e[0], setDescriptor = _e[1];
66
+ var themeContext = React.useContext(ThemeContext) || {};
67
+ var columns = useColumns();
68
+ var context = useContext(id);
69
+ var properties = useComponentNodeProperties(id);
70
+ var _f = useLayout(id), _g = _f.size, size = _g === void 0 ? 'none' : _g, _h = _f.indent, indent = _h === void 0 ? 0 : _h;
71
+ var visible = isVisible(size, node);
72
+ useEffect(function () {
73
+ if (components) {
74
+ if (id && !node) {
75
+ var componentNode = components.nodes.get(id);
76
+ if (componentNode) {
77
+ setDescriptor(asDescriptor(componentNode, branch));
78
+ if (visible) {
79
+ var unmount_1 = componentNode.mount(container);
80
+ return function () {
81
+ unmount_1();
82
+ };
83
+ }
84
+ }
85
+ }
86
+ else if (node) {
87
+ setDescriptor(asDescriptor(node, branch));
88
+ var unmount_2 = node.mount(container);
89
+ return function () {
90
+ unmount_2();
91
+ };
92
+ }
93
+ }
94
+ }, [components, id, node, visible]);
95
+ if (!descriptor || !visible) {
96
+ return null;
97
+ }
98
+ var cardinal = context.cardinal, _j = context.fonts, contextFonts = _j === void 0 ? {} : _j, _k = context.accessibility, accessibility = _k === void 0 ? {} : _k, restContext = __rest(context, ["cardinal", "fonts", "accessibility"]);
99
+ var fonts = {
100
+ type: contextFonts.type,
101
+ base: contextFonts.base || '16px',
102
+ small: contextFonts.small || '0.8em',
103
+ normal: contextFonts.normal || '1em',
104
+ medium: contextFonts.medium || '1.2em',
105
+ large: contextFonts.large || '1.6em',
106
+ huge: contextFonts.huge || '2.5em',
107
+ };
108
+ var theme = __assign(__assign({}, restContext), { fonts: fonts, accessibility: __assign(__assign({}, accessibility), { isTabbing: ((_b = themeContext.accessibility) === null || _b === void 0 ? void 0 : _b.isTabbing) || isTabbing }) });
109
+ if (typeof cardinal === 'number') {
110
+ theme.sizes = {
111
+ cardinal: cardinal,
112
+ small: "".concat(cardinal, "px"),
113
+ normal: "".concat(cardinal * 3, "px"),
114
+ medium: "".concat(cardinal * 5, "px"),
115
+ large: "".concat(cardinal * 8, "px"),
116
+ };
117
+ }
118
+ return (React.createElement(ThemeProvider, { theme: theme },
119
+ React.createElement(ComponentNodeContext.Provider, { value: descriptor },
120
+ React.createElement(ComponentPropertyContext.Provider, { value: properties }, (function () {
121
+ var props = __assign({ 'data-width': size === 'full' ? columns : Math.min(size, columns), 'data-indent': indent, 'data-name': descriptor.name, 'data-node-id': descriptor.id, 'data-component-type': descriptor.type, 'aria-label': ariaLabel, tabIndex: tabIndex, id: descriptor.id, role: properties && properties.role }, other);
122
+ switch (descriptor.type) {
123
+ case 'view': {
124
+ return typeof properties.animation === 'string' &&
125
+ properties.animation !== 'none' ? (React.createElement(StyledAnimatedView, __assign({}, props, { className: className }))) : (React.createElement(StyledView, __assign({}, props, { className: className })));
126
+ }
127
+ default: {
128
+ var cssProps = filterCssProps(properties);
129
+ return (React.createElement(ResolvableComponent, __assign({ ref: ref }, props, cssProps, { className: className })));
130
+ }
131
+ }
132
+ })()))));
133
+ });
134
+ export var styling = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n outline: none;\n box-sizing: border-box;\n * {\n ", "\n box-sizing: border-box;\n }\n\n grid-column: ", ";\n\n ", "\n\n ", "\n\n &:focus {\n ", ";\n }\n"], ["\n outline: none;\n box-sizing: border-box;\n * {\n ", "\n box-sizing: border-box;\n }\n\n grid-column: ", ";\n\n ", "\n\n ", "\n\n &:focus {\n ", ";\n }\n"])), function (p) { var _a; return !((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && 'outline: none;'; }, function (p) {
135
+ return p['data-indent']
136
+ ? "".concat(p['data-indent'] + 1, " / ").concat(p['data-indent'] + p['data-width'] + 1)
137
+ : "span ".concat(p['data-width']);
138
+ }, function (p) {
139
+ var _a;
140
+ return ((_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.type) &&
141
+ "\n font-family: ".concat(p.theme.fonts.type, ";\n\n input, textarea {\n font-family: ").concat(p.theme.fonts.type, ";\n }\n ");
142
+ }, function (p) {
143
+ var _a;
144
+ return ((_a = p.theme.fonts) === null || _a === void 0 ? void 0 : _a.base) &&
145
+ "\n font-size: ".concat(p.theme.fonts.base, ";\n ");
146
+ }, function (p) { var _a; return ((_a = p.theme.accessibility) === null || _a === void 0 ? void 0 : _a.isTabbing) && paddedBorderTabStyle; });
147
+ var StyledView = styled(View)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), styling);
148
+ var StyledAnimatedView = styled(AnimatedView)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), styling);
149
+ export default Component;
150
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1,7 @@
1
+ import { ComponentNode, ComponentPlatform } from '@telia-ace/widget-core';
2
+ import React from 'react';
3
+ declare type Props = {
4
+ builder: (components: ComponentPlatform) => Promise<ComponentNode>;
5
+ };
6
+ declare const DetachedComponent: React.FC<Props>;
7
+ export default DetachedComponent;
@@ -0,0 +1,45 @@
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 { useContainer } from '@telia-ace/widget-ui';
18
+ import React, { useEffect, useState } from 'react';
19
+ import Component from './component';
20
+ var DetachedComponent = function (_a) {
21
+ var builder = _a.builder;
22
+ var container = useContainer();
23
+ var _b = __read(useState(null), 2), node = _b[0], setNode = _b[1];
24
+ useEffect(function () {
25
+ container.getAsync('components').then(function (components) {
26
+ return builder(components).then(function (createdNode) {
27
+ setNode(createdNode);
28
+ });
29
+ });
30
+ }, []);
31
+ useEffect(function () {
32
+ return function () {
33
+ if (node) {
34
+ container.getAsync('components').then(function (components) {
35
+ components.nodes.detached = components.nodes.detached.filter(function (n) { return n.id !== node.id; });
36
+ });
37
+ }
38
+ };
39
+ }, [node]);
40
+ if (!node) {
41
+ return null;
42
+ }
43
+ return React.createElement(Component, { id: node.id, node: node, branch: "default" });
44
+ };
45
+ export default DetachedComponent;
@@ -0,0 +1,26 @@
1
+ export declare enum SlideDirection {
2
+ back = "back",
3
+ forth = "forth"
4
+ }
5
+ export interface RouteStructure {
6
+ name: string;
7
+ children: RouteStructure[];
8
+ }
9
+ /**
10
+ * Recursively find the parents of a nested route
11
+ * @param routeName Name of route to find
12
+ * @param routes Routes to look in
13
+ * @param trail Trail of parents
14
+ * @param level Level of the array currently looking in
15
+ */
16
+ export declare const findParentRoutes: (routeName: string, routes: RouteStructure[], trail?: string[], level?: number) => string[] | null;
17
+ /**
18
+ * Determine if the sliding animation should back or forth
19
+ * @param currentRouteName Name of current route
20
+ * @param nextRouteName Name of route to transition to
21
+ * @param routeRanking Hierarchical route ranking for the widget
22
+ */
23
+ export declare const determineSlideDirection: (currentRouteName: string, nextRouteName: string, routeRanking: RouteRanking) => SlideDirection;
24
+ export declare type RouteRanking = {
25
+ [key: string]: number;
26
+ };
@@ -0,0 +1,46 @@
1
+ export var SlideDirection;
2
+ (function (SlideDirection) {
3
+ SlideDirection["back"] = "back";
4
+ SlideDirection["forth"] = "forth";
5
+ })(SlideDirection || (SlideDirection = {}));
6
+ /**
7
+ * Recursively find the parents of a nested route
8
+ * @param routeName Name of route to find
9
+ * @param routes Routes to look in
10
+ * @param trail Trail of parents
11
+ * @param level Level of the array currently looking in
12
+ */
13
+ export var findParentRoutes = function (routeName, routes, trail, level) {
14
+ if (trail === void 0) { trail = []; }
15
+ if (level === void 0) { level = 0; }
16
+ var found = null;
17
+ routes.forEach(function (route, index) {
18
+ if (!found) {
19
+ if (route.name === routeName) {
20
+ found = route;
21
+ }
22
+ else {
23
+ trail[level] = route.name;
24
+ found = findParentRoutes(routeName, route.children, trail, level + 1);
25
+ }
26
+ }
27
+ });
28
+ if (!found) {
29
+ return null;
30
+ }
31
+ return trail;
32
+ };
33
+ /**
34
+ * Determine if the sliding animation should back or forth
35
+ * @param currentRouteName Name of current route
36
+ * @param nextRouteName Name of route to transition to
37
+ * @param routeRanking Hierarchical route ranking for the widget
38
+ */
39
+ export var determineSlideDirection = function (currentRouteName, nextRouteName, routeRanking) {
40
+ if (typeof routeRanking[currentRouteName] === 'number' &&
41
+ typeof routeRanking[nextRouteName] === 'number' &&
42
+ routeRanking[currentRouteName] > routeRanking[nextRouteName]) {
43
+ return SlideDirection.back;
44
+ }
45
+ return SlideDirection.forth;
46
+ };
@@ -0,0 +1,18 @@
1
+ export declare const renderSymbol: (symbol?: {
2
+ type: string;
3
+ content: string;
4
+ } | undefined) => string | undefined;
5
+ export declare type TriggerElementOptions = {
6
+ symbol?: {
7
+ type: string;
8
+ content: string;
9
+ };
10
+ widgetName: string;
11
+ label?: string;
12
+ ariaLabel?: string;
13
+ tooltip?: string;
14
+ };
15
+ export declare function createTriggerElement(element: HTMLElement, options: TriggerElementOptions): () => void;
16
+ export declare function setInactive(elements: HTMLElement | HTMLElement[], title?: string): void;
17
+ export declare function setLoading(elements: HTMLElement | HTMLElement[]): void;
18
+ export declare function setActive(elements: HTMLElement | HTMLElement[], title?: string): void;