@telia-ace/widget-types-grid 1.0.7 → 1.0.10

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 (96) hide show
  1. package/{lib-esm → dist}/component-platform-factory.d.ts +0 -0
  2. package/{lib → dist}/index.d.ts +2 -1
  3. package/dist/index.js +1416 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/render.js +95 -0
  6. package/dist/render.js.map +1 -0
  7. package/{lib-esm → dist}/services.d.ts +0 -0
  8. package/{lib-esm → dist}/site-provider.d.ts +0 -0
  9. package/{lib-esm → dist}/ui/animated-view.d.ts +0 -0
  10. package/{lib-esm → dist}/ui/component.d.ts +0 -5
  11. package/{lib-esm → dist}/ui/detached-component.d.ts +0 -0
  12. package/{lib-esm → dist}/ui/determine-slide-direction.d.ts +0 -0
  13. package/{lib-esm → dist}/ui/html-element-handlers.d.ts +0 -0
  14. package/{lib-esm → dist}/ui/index.d.ts +0 -0
  15. package/{lib-esm → dist}/ui/not-found.d.ts +0 -0
  16. package/{lib-esm → dist}/ui/prepare-dom.d.ts +0 -0
  17. package/{lib-esm → dist}/ui/render.d.ts +0 -0
  18. package/{lib-esm → dist}/ui/resolvable-component.d.ts +0 -0
  19. package/dist/ui/styles.d.ts +17 -0
  20. package/{lib-esm → dist}/ui/switch.d.ts +0 -0
  21. package/{lib-esm → dist}/ui/unmount.d.ts +0 -0
  22. package/{lib-esm → dist}/ui/use-component-node-properties.d.ts +0 -0
  23. package/{lib-esm → dist}/ui/use-router.d.ts +0 -0
  24. package/{lib-esm → dist}/ui/view-outlet.d.ts +0 -0
  25. package/{lib-esm → dist}/ui/view.d.ts +0 -0
  26. package/{lib-esm → dist}/ui/wrapper.d.ts +0 -0
  27. package/dist/unmount.js +4 -0
  28. package/dist/unmount.js.map +1 -0
  29. package/{lib-esm → dist}/widget.d.ts +0 -0
  30. package/package.json +18 -17
  31. package/lib/component-platform-factory.d.ts +0 -13
  32. package/lib/component-platform-factory.js +0 -105
  33. package/lib/index.js +0 -16
  34. package/lib/services.d.ts +0 -7
  35. package/lib/services.js +0 -99
  36. package/lib/site-provider.d.ts +0 -5
  37. package/lib/site-provider.js +0 -18
  38. package/lib/ui/animated-view.d.ts +0 -6
  39. package/lib/ui/animated-view.js +0 -142
  40. package/lib/ui/component.d.ts +0 -21
  41. package/lib/ui/component.js +0 -180
  42. package/lib/ui/detached-component.d.ts +0 -7
  43. package/lib/ui/detached-component.js +0 -73
  44. package/lib/ui/determine-slide-direction.d.ts +0 -26
  45. package/lib/ui/determine-slide-direction.js +0 -51
  46. package/lib/ui/html-element-handlers.d.ts +0 -18
  47. package/lib/ui/html-element-handlers.js +0 -128
  48. package/lib/ui/index.d.ts +0 -6
  49. package/lib/ui/index.js +0 -19
  50. package/lib/ui/not-found.d.ts +0 -6
  51. package/lib/ui/not-found.js +0 -83
  52. package/lib/ui/prepare-dom.d.ts +0 -20
  53. package/lib/ui/prepare-dom.js +0 -122
  54. package/lib/ui/render.d.ts +0 -3
  55. package/lib/ui/render.js +0 -11
  56. package/lib/ui/resolvable-component.d.ts +0 -7
  57. package/lib/ui/resolvable-component.js +0 -87
  58. package/lib/ui/switch.d.ts +0 -11
  59. package/lib/ui/switch.js +0 -58
  60. package/lib/ui/unmount.d.ts +0 -2
  61. package/lib/ui/unmount.js +0 -4
  62. package/lib/ui/use-component-node-properties.d.ts +0 -3
  63. package/lib/ui/use-component-node-properties.js +0 -44
  64. package/lib/ui/use-router.d.ts +0 -4
  65. package/lib/ui/use-router.js +0 -32
  66. package/lib/ui/view-outlet.d.ts +0 -32
  67. package/lib/ui/view-outlet.js +0 -151
  68. package/lib/ui/view.d.ts +0 -6
  69. package/lib/ui/view.js +0 -75
  70. package/lib/ui/wrapper.d.ts +0 -7
  71. package/lib/ui/wrapper.js +0 -108
  72. package/lib/widget.d.ts +0 -54
  73. package/lib/widget.js +0 -554
  74. package/lib-esm/component-platform-factory.js +0 -101
  75. package/lib-esm/index.d.ts +0 -4
  76. package/lib-esm/index.js +0 -4
  77. package/lib-esm/services.js +0 -67
  78. package/lib-esm/site-provider.js +0 -14
  79. package/lib-esm/ui/animated-view.js +0 -114
  80. package/lib-esm/ui/component.js +0 -151
  81. package/lib-esm/ui/detached-component.js +0 -45
  82. package/lib-esm/ui/determine-slide-direction.js +0 -46
  83. package/lib-esm/ui/html-element-handlers.js +0 -120
  84. package/lib-esm/ui/index.js +0 -6
  85. package/lib-esm/ui/not-found.js +0 -58
  86. package/lib-esm/ui/prepare-dom.js +0 -116
  87. package/lib-esm/ui/render.js +0 -6
  88. package/lib-esm/ui/resolvable-component.js +0 -62
  89. package/lib-esm/ui/switch.js +0 -53
  90. package/lib-esm/ui/unmount.js +0 -2
  91. package/lib-esm/ui/use-component-node-properties.js +0 -42
  92. package/lib-esm/ui/use-router.js +0 -30
  93. package/lib-esm/ui/view-outlet.js +0 -126
  94. package/lib-esm/ui/view.js +0 -70
  95. package/lib-esm/ui/wrapper.js +0 -80
  96. package/lib-esm/widget.js +0 -551
package/dist/index.js ADDED
@@ -0,0 +1,1416 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { asDescriptor, ComponentPlatform, createComponentModel, ComponentQuery, WidgetRenderState } from "@telia-ace/widget-core";
33
+ import { Grid, useRouteData, useRouter, useProperties, useContext, useContainer, useComponentNode, useScroll, transitionComposer, paddedBorderTabStyle, useComponent, useComponentDescriptor, filterCssPropsStyle, useComponentPlatform, useIsMounted, useColumns, useLayout, ComponentNodeContext, ComponentPropertyContext, filterCssProps } from "@telia-ace/widget-ui";
34
+ import React, { useState, forwardRef, useMemo, Suspense, useEffect, useContext as useContext$1 } from "react";
35
+ import styled, { css, ThemeContext, ThemeProvider } from "styled-components";
36
+ import { appendClassNames, notifyDataLoaded, lock, removeNullAndUndefinedValues, uuid } from "@telia-ace/widget-utilities";
37
+ import { TransitionGroup, Transition } from "react-transition-group";
38
+ import { Switch as Switch$1, Route } from "react-router";
39
+ import { onWidgetUrl } from "@telia-ace/widget-routing";
40
+ import { readStorage, StorageMedium, createStorageWriter, StorageCategory, StorageScope } from "@telia-ace/widget-services";
41
+ import { supportBootstrapping } from "@webprovisions/bootstrapping";
42
+ import { WidgetState, WidgetType } from "@webprovisions/platform";
43
+ var SlideDirection = /* @__PURE__ */ ((SlideDirection2) => {
44
+ SlideDirection2["back"] = "back";
45
+ SlideDirection2["forth"] = "forth";
46
+ return SlideDirection2;
47
+ })(SlideDirection || {});
48
+ const determineSlideDirection = (currentRouteName, nextRouteName, routeRanking) => {
49
+ if (typeof routeRanking[currentRouteName] === "number" && typeof routeRanking[nextRouteName] === "number" && routeRanking[currentRouteName] > routeRanking[nextRouteName]) {
50
+ return "back";
51
+ }
52
+ return "forth";
53
+ };
54
+ const Switch = ({ views, location, render }) => {
55
+ return /* @__PURE__ */ React.createElement(Switch$1, {
56
+ location: location ? __spreadProps(__spreadValues({}, location), {
57
+ pathname: location.pathname.split("?")[0]
58
+ }) : location
59
+ }, [
60
+ ...Object.keys(views).filter((key) => !!views[key].path),
61
+ ...Object.keys(views).filter((key) => !views[key].path)
62
+ ].map((name) => {
63
+ const { path } = views[name];
64
+ if (!path) {
65
+ return /* @__PURE__ */ React.createElement(Route, {
66
+ key: name,
67
+ render: () => render(name)
68
+ });
69
+ }
70
+ if (Array.isArray(path)) {
71
+ return path.map((path2) => /* @__PURE__ */ React.createElement(Route, {
72
+ key: name,
73
+ exact: true,
74
+ path: path2,
75
+ render: () => render(name)
76
+ }));
77
+ }
78
+ return /* @__PURE__ */ React.createElement(Route, {
79
+ key: name,
80
+ exact: true,
81
+ path,
82
+ render: () => render(name)
83
+ });
84
+ }));
85
+ };
86
+ const StyledViewContainer = styled.div`
87
+ position: relative;
88
+ width: 100%;
89
+ flex: 1;
90
+ `;
91
+ const StyledView$2 = styled(Grid)`
92
+ position: absolute;
93
+ left: 0;
94
+ right: 0;
95
+ ${(p) => !!p.animationCss && p.animationCss}
96
+ ${(p) => !!p.scrollableCss && p.scrollableCss}
97
+ `;
98
+ const routeHierarchy = {
99
+ index: 1,
100
+ search: 2,
101
+ browse: 3,
102
+ guide: 4,
103
+ contact: 5,
104
+ "contact-method": 6,
105
+ conversation: 7
106
+ };
107
+ const AnimatedView = (_a) => {
108
+ var _b = _a, { className = "" } = _b, other = __objRest(_b, ["className"]);
109
+ const [routeName, setRouteName] = useState("index");
110
+ const [transitionDirection, setTransitionDirection] = useState(SlideDirection.forth);
111
+ const nextRoute = useRouteData();
112
+ const router = useRouter();
113
+ const properties = useProperties();
114
+ const context = useContext();
115
+ const container = useContainer();
116
+ const node = useComponentNode();
117
+ const { gap = "0" } = context;
118
+ const _a2 = properties, { columns = 1, animation = "none", scrollable = false } = _a2, areaProperties = __objRest(_a2, ["columns", "animation", "scrollable"]);
119
+ const [scrollableCss, elem] = useScroll(scrollable);
120
+ if (!node || !router) {
121
+ return null;
122
+ }
123
+ const { location } = router;
124
+ if (nextRoute.name !== routeName && nextRoute.name !== "" && animation) {
125
+ setTransitionDirection(determineSlideDirection(routeName, nextRoute.name, routeHierarchy));
126
+ setRouteName(nextRoute.name);
127
+ }
128
+ const { views } = container.get("$settings");
129
+ if (!Object.keys(views).length) {
130
+ return null;
131
+ }
132
+ const renderView = (name, transitionState, direction) => {
133
+ const animationStyles = getAnimation(transitionState, direction);
134
+ const childNode = node.getChildren(name)[0];
135
+ return /* @__PURE__ */ React.createElement(StyledView$2, __spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({}, other), areaProperties), {
136
+ scrollableCss,
137
+ ref: elem,
138
+ columns,
139
+ gap
140
+ }), animationStyles), {
141
+ className: appendClassNames(className, "humany-view")
142
+ }), /* @__PURE__ */ React.createElement(Component, {
143
+ id: childNode.id,
144
+ branch: "default"
145
+ }));
146
+ };
147
+ const getAnimation = (transitionState, direction) => {
148
+ if (animation === "slide" || animation === "fade") {
149
+ return {
150
+ animationCss: transitionComposer.composeViewTransition(transitionState, animation, direction),
151
+ ["data-state"]: transitionState
152
+ };
153
+ }
154
+ return;
155
+ };
156
+ return /* @__PURE__ */ React.createElement(StyledViewContainer, {
157
+ className: "humany-animated-view"
158
+ }, /* @__PURE__ */ React.createElement(TransitionGroup, {
159
+ component: null,
160
+ childFactory: (child) => React.cloneElement(child, { direction: transitionDirection })
161
+ }, /* @__PURE__ */ React.createElement(Transition, {
162
+ key: routeName,
163
+ timeout: { enter: 500, exit: 500 },
164
+ onEnter: (node2) => node2 == null ? void 0 : node2.clientHeight,
165
+ unmountOnExit: true,
166
+ direction: SlideDirection.forth
167
+ }, (state, { direction }) => /* @__PURE__ */ React.createElement(Switch, {
168
+ views,
169
+ location,
170
+ render: (name) => renderView(name, state, direction)
171
+ }))));
172
+ };
173
+ const StyledView$1 = styled(Grid)`
174
+ ${(p) => !!p.scrollableCss && p.scrollableCss}
175
+ `;
176
+ const View = (_c) => {
177
+ var _d = _c, { className = "" } = _d, other = __objRest(_d, ["className"]);
178
+ const properties = useProperties();
179
+ const context = useContext();
180
+ const container = useContainer();
181
+ const node = useComponentNode();
182
+ const { views } = container.get("$settings");
183
+ const { gap = "0" } = context;
184
+ const _a = properties, { columns = 1, animation = "none", scrollable = false } = _a, areaProperties = __objRest(_a, ["columns", "animation", "scrollable"]);
185
+ const [scrollableCss, elem] = useScroll(scrollable);
186
+ if (!node) {
187
+ return null;
188
+ }
189
+ return /* @__PURE__ */ React.createElement(StyledView$1, __spreadProps(__spreadValues(__spreadValues({}, other), areaProperties), {
190
+ scrollableCss,
191
+ ref: elem,
192
+ columns,
193
+ gap,
194
+ className: appendClassNames(className, "humany-view")
195
+ }), /* @__PURE__ */ React.createElement(Switch, {
196
+ views,
197
+ render: (name) => {
198
+ const childNode = node.getChildren(name)[0];
199
+ return /* @__PURE__ */ React.createElement(Component, {
200
+ id: childNode.id,
201
+ node: childNode,
202
+ branch: "default"
203
+ });
204
+ }
205
+ }));
206
+ };
207
+ const styling = css`
208
+ outline: none;
209
+ box-sizing: border-box;
210
+ * {
211
+ ${(p) => {
212
+ var _a;
213
+ return !((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && "outline: none;";
214
+ }}
215
+ box-sizing: border-box;
216
+ }
217
+
218
+ grid-column: ${(p) => p["data-indent"] ? `${p["data-indent"] + 1} / ${p["data-indent"] + p["data-width"] + 1}` : `span ${p["data-width"]}`};
219
+
220
+ ${(p) => {
221
+ var _a;
222
+ return ((_a = p.theme.fonts) == null ? void 0 : _a.type) && `
223
+ font-family: ${p.theme.fonts.type};
224
+
225
+ input, textarea {
226
+ font-family: ${p.theme.fonts.type};
227
+ }
228
+ `;
229
+ }}
230
+
231
+ ${(p) => {
232
+ var _a;
233
+ return ((_a = p.theme.fonts) == null ? void 0 : _a.base) && `
234
+ font-size: ${p.theme.fonts.base};
235
+ `;
236
+ }}
237
+
238
+ &:focus {
239
+ ${(p) => {
240
+ var _a;
241
+ return ((_a = p.theme.accessibility) == null ? void 0 : _a.isTabbing) && paddedBorderTabStyle;
242
+ }};
243
+ }
244
+ `;
245
+ const StyledView = styled(View)`
246
+ ${styling}
247
+ `;
248
+ const StyledAnimatedView = styled(AnimatedView)`
249
+ ${styling}
250
+ `;
251
+ styled.div`
252
+ text-align: center;
253
+ ${(p) => {
254
+ var _a, _b, _c;
255
+ return typeof ((_a = p.theme.colors) == null ? void 0 : _a.warning) !== "undefined" && css`
256
+ color: ${(_b = p.theme.colors) == null ? void 0 : _b.warning};
257
+ border: 2px dashed ${(_c = p.theme.colors) == null ? void 0 : _c.warning};
258
+ `;
259
+ }}
260
+ ${(p) => typeof p.theme.borderRadius !== "undefined" && `border-radius: ${p.theme.borderRadius};`}
261
+ ${styling}
262
+ `;
263
+ const ResolvableComponent = forwardRef((_e, ref) => {
264
+ var _f = _e, { className = "", children } = _f, other = __objRest(_f, ["className", "children"]);
265
+ const ResolvedComponent = useComponent();
266
+ const { name, type, id } = useComponentDescriptor();
267
+ const StyledResolvableComponent = useMemo(() => {
268
+ if (ResolvedComponent) {
269
+ return styled(ResolvedComponent)`
270
+ ${styling}
271
+ ${filterCssPropsStyle}
272
+ `;
273
+ }
274
+ return null;
275
+ }, [ResolvedComponent]);
276
+ if (typeof ResolvedComponent === "undefined") {
277
+ return null;
278
+ }
279
+ if (ResolvedComponent === null || StyledResolvableComponent === null) {
280
+ return null;
281
+ }
282
+ return /* @__PURE__ */ React.createElement(Suspense, {
283
+ fallback: null
284
+ }, /* @__PURE__ */ React.createElement(StyledResolvableComponent, __spreadProps(__spreadValues({
285
+ ref
286
+ }, other), {
287
+ className: appendClassNames(className, "humany-component", `humany-component-${name}`)
288
+ }), children));
289
+ });
290
+ var useComponentNodeProperties = (id) => {
291
+ const node = useComponentNode(id);
292
+ const components = useComponentPlatform();
293
+ const [properties, setProperties] = useState({});
294
+ const isMounted = useIsMounted();
295
+ useEffect(() => {
296
+ if (node && isMounted.current) {
297
+ setProperties(node.attributes.properties);
298
+ }
299
+ }, [node, id, isMounted]);
300
+ useEffect(() => {
301
+ if (components) {
302
+ const unsubscribe = components.events.subscribe("components:properties-changed", (event, data) => {
303
+ if (node === data.node && isMounted.current) {
304
+ setProperties(data.node.attributes.properties);
305
+ }
306
+ });
307
+ return () => {
308
+ unsubscribe();
309
+ };
310
+ }
311
+ }, [components, isMounted, id, node]);
312
+ return properties;
313
+ };
314
+ const isVisible = (size, node) => {
315
+ if (node) {
316
+ return true;
317
+ }
318
+ if (typeof size === "string") {
319
+ return size === "full";
320
+ }
321
+ return size > 0;
322
+ };
323
+ const Component = forwardRef((_g, ref) => {
324
+ var _h = _g, {
325
+ className = "",
326
+ isTabbing = false,
327
+ id,
328
+ branch,
329
+ node,
330
+ ariaLabel,
331
+ tabIndex,
332
+ context: extraContext
333
+ } = _h, other = __objRest(_h, [
334
+ "className",
335
+ "isTabbing",
336
+ "id",
337
+ "branch",
338
+ "node",
339
+ "ariaLabel",
340
+ "tabIndex",
341
+ "context"
342
+ ]);
343
+ var _b;
344
+ const components = useComponentPlatform();
345
+ const container = useContainer();
346
+ const [descriptor, setDescriptor] = useState();
347
+ const themeContext = React.useContext(ThemeContext) || {};
348
+ const columns = useColumns();
349
+ const context = useContext(id);
350
+ const properties = useComponentNodeProperties(id);
351
+ const { size = "none", indent = 0 } = useLayout(id);
352
+ const visible = isVisible(size, node);
353
+ useEffect(() => {
354
+ if (components) {
355
+ if (id && !node) {
356
+ const componentNode = components.nodes.get(id);
357
+ if (componentNode) {
358
+ setDescriptor(asDescriptor(componentNode, branch));
359
+ if (visible) {
360
+ const unmount = componentNode.mount(container);
361
+ return () => {
362
+ unmount();
363
+ };
364
+ }
365
+ }
366
+ } else if (node) {
367
+ setDescriptor(asDescriptor(node, branch));
368
+ const unmount = node.mount(container);
369
+ return () => {
370
+ unmount();
371
+ };
372
+ }
373
+ }
374
+ }, [components, id, node, visible]);
375
+ if (!descriptor || !visible) {
376
+ return null;
377
+ }
378
+ const mergedContexts = __spreadValues(__spreadValues({}, context), extraContext || {});
379
+ const _a = mergedContexts, {
380
+ cardinal,
381
+ fonts: contextFonts = {},
382
+ accessibility = {}
383
+ } = _a, restContext = __objRest(_a, [
384
+ "cardinal",
385
+ "fonts",
386
+ "accessibility"
387
+ ]);
388
+ const fonts = {
389
+ type: contextFonts.type,
390
+ base: contextFonts.base || "16px",
391
+ small: contextFonts.small || "0.8em",
392
+ normal: contextFonts.normal || "1em",
393
+ medium: contextFonts.medium || "1.2em",
394
+ large: contextFonts.large || "1.6em",
395
+ huge: contextFonts.huge || "2.5em"
396
+ };
397
+ const theme = __spreadProps(__spreadValues({}, restContext), {
398
+ fonts,
399
+ accessibility: __spreadProps(__spreadValues({}, accessibility), {
400
+ isTabbing: ((_b = themeContext.accessibility) == null ? void 0 : _b.isTabbing) || isTabbing
401
+ })
402
+ });
403
+ if (typeof cardinal === "number") {
404
+ theme.sizes = {
405
+ cardinal,
406
+ small: `${cardinal}px`,
407
+ normal: `${cardinal * 3}px`,
408
+ medium: `${cardinal * 5}px`,
409
+ large: `${cardinal * 8}px`
410
+ };
411
+ }
412
+ return /* @__PURE__ */ React.createElement(ThemeProvider, {
413
+ theme
414
+ }, /* @__PURE__ */ React.createElement(ComponentNodeContext.Provider, {
415
+ value: descriptor
416
+ }, /* @__PURE__ */ React.createElement(ComponentPropertyContext.Provider, {
417
+ value: properties
418
+ }, (() => {
419
+ const props = __spreadValues({
420
+ "data-width": size === "full" ? columns : Math.min(size, columns),
421
+ "data-indent": indent,
422
+ "data-name": descriptor.name,
423
+ "data-node-id": descriptor.id,
424
+ "data-component-type": descriptor.type,
425
+ "aria-label": ariaLabel,
426
+ tabIndex,
427
+ id: descriptor.id,
428
+ role: properties && properties.role
429
+ }, other);
430
+ switch (descriptor.type) {
431
+ case "view": {
432
+ return typeof properties.animation === "string" && properties.animation !== "none" ? /* @__PURE__ */ React.createElement(StyledAnimatedView, __spreadProps(__spreadValues({}, props), {
433
+ className
434
+ })) : /* @__PURE__ */ React.createElement(StyledView, __spreadProps(__spreadValues({}, props), {
435
+ className
436
+ }));
437
+ }
438
+ default: {
439
+ const cssProps = filterCssProps(properties);
440
+ return /* @__PURE__ */ React.createElement(ResolvableComponent, __spreadProps(__spreadValues(__spreadValues({
441
+ ref
442
+ }, props), cssProps), {
443
+ className
444
+ }));
445
+ }
446
+ }
447
+ })())));
448
+ });
449
+ const DetachedComponent$1 = ({ builder }) => {
450
+ const container = useContainer();
451
+ const [node, setNode] = useState(null);
452
+ useEffect(() => {
453
+ container.getAsync("components").then((components) => {
454
+ return builder(components).then((createdNode) => {
455
+ setNode(createdNode);
456
+ });
457
+ });
458
+ }, []);
459
+ useEffect(() => {
460
+ return () => {
461
+ if (node) {
462
+ container.getAsync("components").then((components) => {
463
+ components.nodes.detached = components.nodes.detached.filter((n) => n.id !== node.id);
464
+ });
465
+ }
466
+ };
467
+ }, [node]);
468
+ if (!node) {
469
+ return null;
470
+ }
471
+ return /* @__PURE__ */ React.createElement(Component, {
472
+ id: node.id,
473
+ node,
474
+ branch: "default"
475
+ });
476
+ };
477
+ var detachedComponent = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
478
+ __proto__: null,
479
+ "default": DetachedComponent$1
480
+ }, Symbol.toStringTag, { value: "Module" }));
481
+ const DetachedComponent = React.lazy(() => Promise.resolve().then(function() {
482
+ return detachedComponent;
483
+ }));
484
+ const NotFound = ({ showSearch = false }) => {
485
+ const themeContext = useContext$1(ThemeContext);
486
+ const container = useContainer();
487
+ return /* @__PURE__ */ React.createElement(React.Suspense, {
488
+ fallback: null
489
+ }, /* @__PURE__ */ React.createElement(DetachedComponent, {
490
+ builder: (components) => {
491
+ return container.get("settings").then((settings) => {
492
+ var _a;
493
+ const { properties, context } = Object.keys(settings.components).reduce((acc, key) => {
494
+ if (settings.components[key].type === "not-found") {
495
+ acc.properties = settings.components[key].properties;
496
+ acc.context = settings.components[key].context;
497
+ }
498
+ return acc;
499
+ }, { properties: {}, context: {} });
500
+ properties.showSearch = showSearch;
501
+ const node = components.createNode("area", { detached: true });
502
+ node.name = "not-found-area";
503
+ node.writeLayout({
504
+ size: "full"
505
+ });
506
+ if (showSearch) {
507
+ const searchComponentProps = Object.keys(settings.components).reduce((acc, key) => {
508
+ if (settings.components[key].type === "search") {
509
+ return settings.components[key].properties;
510
+ }
511
+ return acc;
512
+ }, {});
513
+ const searchNode = components.createNode("search", { detached: true });
514
+ searchNode.writeLayout({ size: "full" });
515
+ searchNode.writeProperties(__spreadValues({
516
+ "css-margin-bottom": ((_a = themeContext == null ? void 0 : themeContext.sizes) == null ? void 0 : _a.normal) || "15px"
517
+ }, searchComponentProps));
518
+ node.appendChild(searchNode);
519
+ }
520
+ const notFoundNode = components.createNode("not-found", { detached: true });
521
+ notFoundNode.writeLayout({ size: "full" });
522
+ notFoundNode.writeProperties(properties);
523
+ notFoundNode.writeContext(context);
524
+ node.appendChild(notFoundNode);
525
+ return node;
526
+ });
527
+ }
528
+ }));
529
+ };
530
+ const renderSymbol = (symbol) => {
531
+ if (symbol) {
532
+ const { type, content } = symbol;
533
+ switch (type) {
534
+ case "FontAwesome":
535
+ return `<i class="humany-icon fa fa-${content}"></i>`;
536
+ case "Uri":
537
+ return `<i class="humany-icon humany-custom-icon" style="background: url(${content}) no-repeat center center;background-size: contain;"></i>`;
538
+ default:
539
+ return "";
540
+ }
541
+ }
542
+ };
543
+ const triggerTabHandler = (triggerDOMElement) => {
544
+ const toggleTabbing = (element, tabbing) => {
545
+ if (!element) {
546
+ return;
547
+ }
548
+ if (tabbing) {
549
+ element.classList.add("humany-tabbing");
550
+ } else {
551
+ element.classList.remove("humany-tabbing");
552
+ }
553
+ };
554
+ const handleKeydown = (e) => {
555
+ if (e.key === "Tab") {
556
+ toggleTabbing(triggerDOMElement, true);
557
+ } else if (!(e.key === "Enter" && document.activeElement && document.activeElement.classList.contains("humany-trigger"))) {
558
+ toggleTabbing(triggerDOMElement, false);
559
+ }
560
+ };
561
+ const handleClick = (e) => {
562
+ if (document.activeElement && document.activeElement.classList.contains("humany-trigger") && document.activeElement.classList.contains("humany-tabbing")) {
563
+ return;
564
+ }
565
+ toggleTabbing(triggerDOMElement, false);
566
+ };
567
+ document.addEventListener("keydown", handleKeydown);
568
+ document.addEventListener("click", handleClick);
569
+ return () => {
570
+ document.removeEventListener("keydown", handleKeydown);
571
+ document.removeEventListener("click", handleClick);
572
+ };
573
+ };
574
+ function createTriggerElement(element, options) {
575
+ const { symbol, widgetName, label = "", ariaLabel = "", tooltip = "" } = options;
576
+ element.classList.add("humany-trigger");
577
+ element.classList.add(`humany_${widgetName}`);
578
+ if (label.length) {
579
+ element.classList.add("humany-has-text");
580
+ }
581
+ if (ariaLabel.length && !element.getAttribute("aria-label")) {
582
+ element.setAttribute("aria-label", ariaLabel);
583
+ }
584
+ if (ariaLabel.length && !element.getAttribute("tabindex")) {
585
+ element.setAttribute("tabindex", "0");
586
+ }
587
+ if (tooltip.length && !element.getAttribute("title")) {
588
+ element.setAttribute("title", tooltip);
589
+ }
590
+ const symbolHtml = renderSymbol(symbol) || "";
591
+ element.innerHTML = `${symbolHtml}
592
+ <span class="humany-close">
593
+ <svg width="18" height="9" viewBox="0 0 18 9" fill="none" xmlns="http://www.w3.org/2000/svg">
594
+ <path d="M9 9C8.81794 9.00045 8.63759 8.96634 8.46939 8.89965C8.3012 8.83295 8.14851 8.735 8.02015 8.61145L0.194523 1.12367C0.068294 0.99862 -0.00155266 0.831133 2.61958e-05 0.657285C0.00160506 0.483436 0.0744832 0.317136 0.202964 0.194202C0.331445 0.0712675 0.505249 0.00153576 0.686941 2.50649e-05C0.868634 -0.00148563 1.04368 0.0653456 1.17437 0.186125L9 7.6739L16.8256 0.186125C16.9563 0.0653456 17.1314 -0.00148563 17.3131 2.50649e-05C17.4948 0.00153576 17.6686 0.0712675 17.797 0.194202C17.9255 0.317136 17.9984 0.483436 18 0.657285C18.0016 0.831133 17.9317 0.99862 17.8055 1.12367L9.97985 8.61145C9.85149 8.735 9.6988 8.83295 9.53061 8.89965C9.36241 8.96634 9.18206 9.00045 9 9Z" fill="white"/>
595
+ </svg>
596
+ </span>
597
+ <span class="humany-loader">
598
+ <svg viewBox="25 25 50 50">
599
+ <circle
600
+ cx="50"
601
+ cy="50"
602
+ r="20"
603
+ fill="none"
604
+ stroke="#000"
605
+ stroke-width="2"
606
+ stroke-miterlimit="10" />
607
+ </svg>
608
+ </span>
609
+ ${label.length ? `<span>${label}</span>` : ""}`;
610
+ setTimeout(() => element && element.classList.add("humany-rendered"));
611
+ return triggerTabHandler(element);
612
+ }
613
+ function setInactive(elements, title) {
614
+ if (elements instanceof HTMLElement) {
615
+ if (title) {
616
+ elements.setAttribute("title", title);
617
+ }
618
+ elements.classList.remove("humany-active");
619
+ elements.classList.remove("humany-loading");
620
+ } else if (elements instanceof Array) {
621
+ elements.forEach((e) => {
622
+ if (title) {
623
+ e.setAttribute("title", title);
624
+ }
625
+ e.classList.remove("humany-active");
626
+ e.classList.remove("humany-loading");
627
+ });
628
+ }
629
+ }
630
+ function setLoading(elements) {
631
+ if (elements instanceof HTMLElement) {
632
+ elements.classList.remove("humany-active");
633
+ elements.classList.add("humany-loading");
634
+ } else if (elements instanceof Array) {
635
+ elements.forEach((e) => {
636
+ e.classList.remove("humany-active");
637
+ e.classList.add("humany-loading");
638
+ });
639
+ }
640
+ }
641
+ function setActive(elements, title) {
642
+ if (elements instanceof HTMLElement) {
643
+ if (title) {
644
+ elements.setAttribute("title", title);
645
+ }
646
+ elements.classList.add("humany-active");
647
+ elements.classList.remove("humany-loading");
648
+ } else if (elements instanceof Array) {
649
+ elements.forEach((e) => {
650
+ if (title) {
651
+ e.setAttribute("title", title);
652
+ }
653
+ e.classList.add("humany-active");
654
+ e.classList.remove("humany-loading");
655
+ });
656
+ }
657
+ }
658
+ var TriggerType = /* @__PURE__ */ ((TriggerType2) => {
659
+ TriggerType2["Inline"] = "inline";
660
+ TriggerType2["Link"] = "link";
661
+ TriggerType2["Badge"] = "badge";
662
+ TriggerType2["Unsupported"] = "unsupported";
663
+ return TriggerType2;
664
+ })(TriggerType || {});
665
+ const determineProvidedElements = (widgetDOMElement, triggerDOMElement) => {
666
+ if (widgetDOMElement && triggerDOMElement) {
667
+ return "both";
668
+ }
669
+ if (widgetDOMElement) {
670
+ return "widgetDOM";
671
+ }
672
+ if (triggerDOMElement) {
673
+ return "triggerDOM";
674
+ }
675
+ return "none";
676
+ };
677
+ const determineTriggerType = (triggerDefinition) => {
678
+ if (!triggerDefinition) {
679
+ return "inline";
680
+ }
681
+ if (typeof triggerDefinition === "boolean" && triggerDefinition) {
682
+ return "link";
683
+ }
684
+ if (typeof triggerDefinition === "object" && !Array.isArray(triggerDefinition)) {
685
+ return "badge";
686
+ }
687
+ return "unsupported";
688
+ };
689
+ const prepareDOMElements = (name, providedWidgetElement, providedTriggerElement, triggerDefinition, waitWithReplace = false) => {
690
+ var _a, _b;
691
+ const providedElements = determineProvidedElements(providedWidgetElement, providedTriggerElement);
692
+ const triggerType = determineTriggerType(triggerDefinition);
693
+ const cachedOriginals = {
694
+ widgetDOMElement: providedWidgetElement ? providedWidgetElement.cloneNode(true) : void 0,
695
+ triggerDOMElement: providedTriggerElement ? providedTriggerElement.cloneNode(true) : void 0
696
+ };
697
+ const output = {
698
+ triggerType,
699
+ cachedOriginals,
700
+ widgetDOMElement: document.createElement("div")
701
+ };
702
+ switch (providedElements) {
703
+ case "both": {
704
+ output.widgetDOMElement = providedWidgetElement || document.createElement("div");
705
+ if (triggerType !== "inline") {
706
+ output.triggerDOMElement = providedTriggerElement;
707
+ }
708
+ break;
709
+ }
710
+ case "widgetDOM": {
711
+ output.widgetDOMElement = providedWidgetElement || document.createElement("div");
712
+ if (triggerType !== "inline") {
713
+ const triggerElement = document.body.appendChild(document.createElement("a"));
714
+ if (triggerType === "link") {
715
+ triggerElement.innerText = name;
716
+ }
717
+ output.triggerDOMElement = triggerElement;
718
+ }
719
+ break;
720
+ }
721
+ case "triggerDOM": {
722
+ const widgetElement = document.createElement("div");
723
+ output.widgetDOMElement = widgetElement;
724
+ if (triggerType === "inline") {
725
+ widgetElement.id = (providedTriggerElement == null ? void 0 : providedTriggerElement.id) || "";
726
+ if (waitWithReplace) {
727
+ widgetElement.style.display = "none";
728
+ (_a = providedTriggerElement == null ? void 0 : providedTriggerElement.parentNode) == null ? void 0 : _a.appendChild(widgetElement);
729
+ output.callback = () => {
730
+ var _a2;
731
+ (_a2 = providedTriggerElement == null ? void 0 : providedTriggerElement.parentNode) == null ? void 0 : _a2.replaceChild(widgetElement, providedTriggerElement);
732
+ widgetElement.style.display = (providedTriggerElement == null ? void 0 : providedTriggerElement.style.display) || "block";
733
+ };
734
+ } else {
735
+ (_b = providedTriggerElement == null ? void 0 : providedTriggerElement.parentNode) == null ? void 0 : _b.replaceChild(widgetElement, providedTriggerElement);
736
+ }
737
+ output.cachedOriginals.widgetDOMElement = providedTriggerElement;
738
+ output.cachedOriginals.triggerDOMElement = void 0;
739
+ } else {
740
+ output.widgetDOMElement = document.body.appendChild(widgetElement);
741
+ output.triggerDOMElement = providedTriggerElement;
742
+ }
743
+ break;
744
+ }
745
+ case "none": {
746
+ const widgetElement = document.body.appendChild(document.createElement("div"));
747
+ output.widgetDOMElement = widgetElement;
748
+ if (triggerType !== "inline") {
749
+ const triggerElement = document.body.appendChild(document.createElement("a"));
750
+ if (triggerType === "link") {
751
+ triggerElement.innerText = name;
752
+ }
753
+ output.triggerDOMElement = triggerElement;
754
+ }
755
+ break;
756
+ }
757
+ }
758
+ return output;
759
+ };
760
+ const MODALS_STORAGE_KEY = "modals";
761
+ class ViewOutlet {
762
+ constructor(container, options) {
763
+ this.options = options;
764
+ this.unsubscribe = [];
765
+ this.container = container.createChild(this);
766
+ this.container.register("widgetDOMElement", this.options.widgetDOMElement);
767
+ this.container.register("triggerDOMElement", this.options.triggerDOMElement);
768
+ const widget = this.container.get("$widget");
769
+ this.options.widgetDOMElement.classList.add("humany-widget");
770
+ this.options.widgetDOMElement.classList.add(`humany_${widget.name}`);
771
+ const widgetDOMElements = container.get("widgetDOMElements") || [];
772
+ container.register("widgetDOMElements", [
773
+ ...widgetDOMElements,
774
+ this.options.widgetDOMElement
775
+ ]);
776
+ }
777
+ render() {
778
+ const { widgetDOMElement, triggerDOMElement } = this.options;
779
+ const widget = this.container.get("$widget");
780
+ if (widgetDOMElement.getAttribute("data-rendered") === "true") {
781
+ return Promise.resolve();
782
+ }
783
+ if (triggerDOMElement && this.options.triggerType === TriggerType.Badge) {
784
+ setLoading(triggerDOMElement);
785
+ }
786
+ return import("./render.js").then((module) => module.default(this.container, widgetDOMElement)).then(() => {
787
+ widgetDOMElement.setAttribute("data-rendered", "true");
788
+ if (triggerDOMElement && this.options.triggerType === TriggerType.Badge) {
789
+ const tooltip = this.options.triggerOptions.openTooltip;
790
+ setActive(triggerDOMElement, tooltip);
791
+ }
792
+ notifyDataLoaded(this.container, widgetDOMElement);
793
+ const widgets = this.container.get("$environment").widgets.all();
794
+ readStorage(this.container, MODALS_STORAGE_KEY, StorageMedium.Session).then((modals) => {
795
+ if (modals) {
796
+ modals.forEach((modal) => {
797
+ if (widgets.find((w) => w.name === modal.name && w.state === "activated")) {
798
+ widget.events.dispatch("widget:modal-opened", modal);
799
+ }
800
+ });
801
+ }
802
+ });
803
+ });
804
+ }
805
+ renderBadge(options) {
806
+ const { triggerDOMElement } = this.options;
807
+ if (!triggerDOMElement) {
808
+ return;
809
+ }
810
+ if (!triggerDOMElement.getAttribute("role")) {
811
+ triggerDOMElement.setAttribute("role", "button");
812
+ }
813
+ const { name } = this.container.get("$widget");
814
+ const { label, symbol, ariaLabel, closedTooltip, openTooltip } = options;
815
+ const triggerOptions = { closedTooltip, openTooltip };
816
+ this.options.triggerOptions = triggerOptions;
817
+ const removeTriggerListeners = createTriggerElement(triggerDOMElement, {
818
+ label,
819
+ symbol,
820
+ ariaLabel,
821
+ widgetName: name,
822
+ tooltip: closedTooltip
823
+ });
824
+ this.unsubscribe.push(removeTriggerListeners);
825
+ }
826
+ dispose() {
827
+ return import("./unmount.js").then((module) => {
828
+ var _a, _b, _c, _d;
829
+ const { triggerDOMElement, widgetDOMElement } = this.options;
830
+ module.default(widgetDOMElement);
831
+ if (this.options.cachedOriginals.widgetDOMElement) {
832
+ if (widgetDOMElement) {
833
+ (_a = widgetDOMElement.parentNode) == null ? void 0 : _a.replaceChild(this.options.cachedOriginals.widgetDOMElement, widgetDOMElement);
834
+ }
835
+ }
836
+ if (this.options.cachedOriginals.triggerDOMElement) {
837
+ if (triggerDOMElement) {
838
+ (_b = triggerDOMElement.parentNode) == null ? void 0 : _b.replaceChild(this.options.cachedOriginals.triggerDOMElement, triggerDOMElement);
839
+ }
840
+ }
841
+ this.unsubscribe.forEach((unsubscribe) => {
842
+ unsubscribe();
843
+ });
844
+ (_c = widgetDOMElement.parentNode) == null ? void 0 : _c.removeChild(widgetDOMElement);
845
+ (_d = triggerDOMElement == null ? void 0 : triggerDOMElement.parentNode) == null ? void 0 : _d.removeChild(triggerDOMElement);
846
+ });
847
+ }
848
+ }
849
+ const STORAGE_KEY = "changesets";
850
+ const convertSettingsToAttributes = (settings) => {
851
+ const attributes = { tags: settings.tags };
852
+ if (settings.context && typeof settings.context !== "function") {
853
+ attributes.context = settings.context;
854
+ }
855
+ if (settings.properties && typeof settings.properties !== "function") {
856
+ attributes.properties = settings.properties;
857
+ }
858
+ if (settings.layout && typeof settings.layout !== "function") {
859
+ attributes.layout = settings.layout;
860
+ }
861
+ return attributes;
862
+ };
863
+ class LocalStorageChangesetProvider {
864
+ constructor(container, storageWriter) {
865
+ this.container = container;
866
+ this.storageWriter = storageWriter;
867
+ }
868
+ static create(container) {
869
+ return createStorageWriter(container, STORAGE_KEY, StorageCategory.Necessary, {
870
+ medium: StorageMedium.Local
871
+ }).then((storageWriter) => new LocalStorageChangesetProvider(container, storageWriter));
872
+ }
873
+ write(key, target, attributes, options) {
874
+ return lock(this)(() => {
875
+ return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((bag = {}) => {
876
+ const { keys = [], items = {} } = bag;
877
+ const existingIndex = keys.indexOf(key);
878
+ if (existingIndex > -1) {
879
+ keys.splice(existingIndex, 1);
880
+ }
881
+ keys.push(key);
882
+ items[key] = {
883
+ options,
884
+ attributes: convertSettingsToAttributes(attributes),
885
+ rules: target.rules
886
+ };
887
+ return this.storageWriter({ keys, items });
888
+ });
889
+ });
890
+ }
891
+ remove(key) {
892
+ return lock(this)(() => {
893
+ return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((bag = {}) => {
894
+ const { keys = [], items = {} } = bag;
895
+ const indexToRemove = keys.indexOf(key);
896
+ if (indexToRemove > -1) {
897
+ keys.splice(indexToRemove, 1);
898
+ delete items[key];
899
+ return this.storageWriter(bag);
900
+ }
901
+ });
902
+ });
903
+ }
904
+ load(platform) {
905
+ return lock(this)(() => {
906
+ return readStorage(this.container, STORAGE_KEY, StorageMedium.Local).then((bag = {}) => {
907
+ const { keys = [], items = {} } = bag;
908
+ keys.forEach((key) => {
909
+ const item = items[key];
910
+ if (item) {
911
+ const { rules, attributes, options } = item;
912
+ platform.write({
913
+ attributes,
914
+ options,
915
+ target: new ComponentQuery(platform, rules)
916
+ });
917
+ }
918
+ });
919
+ });
920
+ });
921
+ }
922
+ }
923
+ const createPlatform = (widget) => {
924
+ const { container } = widget;
925
+ return LocalStorageChangesetProvider.create(container).then((localStorage) => {
926
+ const settings = container.get("$settings");
927
+ const providers = { localStorage };
928
+ const platform = new ComponentPlatform(widget, providers);
929
+ const destructComponentModel = createComponentModel(platform, settings);
930
+ widget.events.subscribe("widget:state-change", (event, data) => {
931
+ if (data.state === WidgetState.Deactivating) {
932
+ destructComponentModel();
933
+ }
934
+ });
935
+ return platform;
936
+ });
937
+ };
938
+ const createSiteProvider = (site, forceHttps) => {
939
+ return () => {
940
+ const parseLocation = (href) => {
941
+ const link = document.createElement("a");
942
+ link.href = href;
943
+ return link;
944
+ };
945
+ let location = window.location;
946
+ if (site === "referrer" && document.referrer) {
947
+ location = parseLocation(document.referrer);
948
+ }
949
+ return [forceHttps ? "https:" : "", "//", location.host, location.pathname].join("");
950
+ };
951
+ };
952
+ const createRoutingService = (container) => {
953
+ return import("@telia-ace/widget-routing").then(({ RoutingService, HistoryMode }) => {
954
+ return container.get("settings").then((settings) => {
955
+ const {
956
+ routing: { initialPath = "/", mode = HistoryMode.scopedHash, basePath },
957
+ views
958
+ } = settings;
959
+ const routingService = new RoutingService(container, {
960
+ initialPath,
961
+ mode,
962
+ routes: Object.keys(views).map((name) => ({
963
+ name,
964
+ path: views[name].path
965
+ })),
966
+ basePath
967
+ });
968
+ return routingService;
969
+ });
970
+ });
971
+ };
972
+ const createStorageService = (container) => {
973
+ return import("@telia-ace/widget-services").then(({ StorageProvider }) => {
974
+ return new StorageProvider();
975
+ });
976
+ };
977
+ const createServiceClient = (container) => {
978
+ return import("@telia-ace/knowledge-serviceclient").then(({ ServiceClient, ServiceProxy }) => {
979
+ return container.get("settings").then((settings) => {
980
+ const { name, events } = container.get("$widget");
981
+ const {
982
+ data: { projection = "", site = "current", forceHttps = false }
983
+ } = settings;
984
+ const proxy = new ServiceProxy(projection, { credentials: "same-origin" });
985
+ const client = new ServiceClient(proxy, {
986
+ funnel: name.replace("_contact-method", "").replace("_contact", ""),
987
+ site: createSiteProvider(site, forceHttps)
988
+ });
989
+ events.subscribe("widget:settings-updated", (event, { data }) => {
990
+ if (data && data.projection !== projection) {
991
+ client.proxy.setBaseUrl(data.projection);
992
+ }
993
+ });
994
+ return client;
995
+ });
996
+ });
997
+ };
998
+ const createActionResolver = (container) => {
999
+ return import("@telia-ace/widget-core").then(({ ActionResolver }) => {
1000
+ return new ActionResolver(container);
1001
+ });
1002
+ };
1003
+ const createComponentResolver = (container) => {
1004
+ return import("@telia-ace/widget-core").then(({ ComponentResolver }) => {
1005
+ return new ComponentResolver(container);
1006
+ });
1007
+ };
1008
+ const createComponentPlatform = (container) => {
1009
+ return import("@telia-ace/widget-core").then(({ ComponentPlatform: ComponentPlatform2, createComponentModel: createComponentModel2 }) => {
1010
+ return createPlatform(container.get("$widget"));
1011
+ });
1012
+ };
1013
+ const SETTINGS_STORAGE_KEY = "$settings";
1014
+ const OPEN_STORAGE_KEY = "open";
1015
+ const STICKY_WIDGET_STORAGE_KEY = "activeStickyWidget";
1016
+ class Widget extends WidgetType {
1017
+ constructor(container) {
1018
+ super(container);
1019
+ this.outlets = /* @__PURE__ */ new Map();
1020
+ this.activated = void 0;
1021
+ this.subs = [];
1022
+ this.handleBootstrapping = (activationData) => {
1023
+ const options = {
1024
+ triggerDOMElement: activationData.sourceDOMElement,
1025
+ withRenderState: "storage"
1026
+ };
1027
+ this.container.get("settings").then((settings) => {
1028
+ const { activate } = settings;
1029
+ const shouldActivate = typeof activate === "undefined" || activate === null || activate === true;
1030
+ if (shouldActivate) {
1031
+ this.activated = (this.activated || this.widget.activate()).then(() => this.attach(options));
1032
+ }
1033
+ });
1034
+ };
1035
+ this.container.registerAsync("storage", () => createStorageService(this.container));
1036
+ this.container.registerFactory("settings", () => {
1037
+ return readStorage(this.container, SETTINGS_STORAGE_KEY, StorageMedium.Local).then((settings = {}) => {
1038
+ return __spreadValues(__spreadValues({}, this.container.get("$settings")), settings);
1039
+ });
1040
+ });
1041
+ supportBootstrapping(this, "load", this.handleBootstrapping);
1042
+ this.container.registerAsync("componentResolver", () => createComponentResolver(this.container));
1043
+ this.container.registerAsync("matchingClient", () => createServiceClient(this.container));
1044
+ this.container.registerAsync("router", () => createRoutingService(this.container));
1045
+ this.container.registerAsync("actionResolver", () => createActionResolver(this.container));
1046
+ this.container.register("matchMedia", window.matchMedia);
1047
+ this.container.registerAsync("components", () => createComponentPlatform(this.container));
1048
+ }
1049
+ initialize() {
1050
+ const promises = this.container.getManyAsync("actionResolver", "router", "components");
1051
+ return Promise.all([promises, this.container.get("settings")]).then(([{ actionResolver, router, components }, settings]) => {
1052
+ var _a;
1053
+ actionResolver.subscribe(this.widget.name, (origin, action, value) => this.onAction(action, value));
1054
+ const switchViewNodes = (routeName) => {
1055
+ components.nodes.query({ type: "view" }).forEach((viewNode) => {
1056
+ components.setSwitch(viewNode, routeName);
1057
+ });
1058
+ };
1059
+ const initialRoute = ((_a = router.getInitialRoute()) == null ? void 0 : _a.name) || "index";
1060
+ switchViewNodes(initialRoute);
1061
+ this.events.subscribe("widget:data-loaded", (e, { element }) => {
1062
+ if (this.widget.container.get("seoConfiguration")) {
1063
+ this.events.dispatch("widget:preloaded-replaced", {
1064
+ element
1065
+ });
1066
+ }
1067
+ });
1068
+ this.events.subscribe("router:change", (e, { previous = { routeData: {} }, next = { routeData: {} } }) => {
1069
+ const { routeData: prevData } = previous;
1070
+ const { routeData: nextData } = next;
1071
+ const notFoundView = Object.keys(settings.views).reduce((acc, key) => {
1072
+ const view = settings.views[key];
1073
+ if (typeof view.path === "undefined") {
1074
+ return key;
1075
+ }
1076
+ return acc;
1077
+ }, "");
1078
+ if (!nextData.name && notFoundView) {
1079
+ switchViewNodes(notFoundView);
1080
+ } else {
1081
+ switchViewNodes(nextData.name);
1082
+ }
1083
+ removeNullAndUndefinedValues(prevData && prevData.params);
1084
+ removeNullAndUndefinedValues(nextData && nextData.params);
1085
+ this.container.getAsync("actionResolver").then((actionResolver2) => {
1086
+ actionResolver2.action(this.widget.name, "routeChange", {
1087
+ next: nextData,
1088
+ previous: prevData
1089
+ });
1090
+ });
1091
+ });
1092
+ return router.initialize();
1093
+ });
1094
+ }
1095
+ attach(attachData = {}) {
1096
+ return this.container.get("settings").then(({ trigger }) => {
1097
+ var _a, _b;
1098
+ const {
1099
+ widgetDOMElement,
1100
+ key = uuid(),
1101
+ triggerDOMElement,
1102
+ withRenderState
1103
+ } = attachData;
1104
+ const triggerType = determineTriggerType(trigger);
1105
+ const waitWithReplace = triggerType === TriggerType.Inline && ((triggerDOMElement == null ? void 0 : triggerDOMElement.childElementCount) || 0) > 0;
1106
+ const outletOptions = prepareDOMElements(this.widget.name, widgetDOMElement, triggerDOMElement, trigger, waitWithReplace);
1107
+ if (this.outlets.size < 1 && !withRenderState) {
1108
+ this.setRenderState("unset");
1109
+ }
1110
+ const swap = () => {
1111
+ const isReady = () => widgetDOMElement2.querySelectorAll("[data-loading=true]").length === 0;
1112
+ const [widgetDOMElement2] = this.widget.container.get("widgetDOMElements");
1113
+ const watcher = (mutations, observer2) => {
1114
+ if (isReady()) {
1115
+ if (outletOptions.callback) {
1116
+ outletOptions.callback();
1117
+ }
1118
+ observer2.disconnect();
1119
+ }
1120
+ };
1121
+ const options = {
1122
+ attributes: true,
1123
+ subtree: true
1124
+ };
1125
+ if (isReady()) {
1126
+ outletOptions.callback && outletOptions.callback();
1127
+ }
1128
+ const observer = new MutationObserver(watcher);
1129
+ observer.observe(widgetDOMElement2, options);
1130
+ };
1131
+ if (waitWithReplace) {
1132
+ this.widget.container.getAsync("dataClient").then(({ events }) => {
1133
+ events.subscribe("data-client:fetched", (event, data) => {
1134
+ if (data.unresolvedQueries === 0) {
1135
+ swap();
1136
+ }
1137
+ });
1138
+ });
1139
+ }
1140
+ const outlet = this.getOrCreateViewOutlet(key, outletOptions);
1141
+ this.outlets.set(key, outlet);
1142
+ this.widget.events.dispatch("widget:attached", {}, { bubbles: true });
1143
+ if (outletOptions.triggerType === TriggerType.Badge && trigger) {
1144
+ (_a = outletOptions.triggerDOMElement) == null ? void 0 : _a.setAttribute("aria-expanded", "false");
1145
+ outlet == null ? void 0 : outlet.renderBadge(trigger);
1146
+ }
1147
+ if (outletOptions.triggerType !== TriggerType.Inline) {
1148
+ (_b = outletOptions.triggerDOMElement) == null ? void 0 : _b.addEventListener("click", (event) => {
1149
+ event.preventDefault();
1150
+ this.container.get("settings").then(({ trigger: updatedTrigger }) => {
1151
+ outlet.render().then(() => this.renderState()).then((renderState) => {
1152
+ if (updatedTrigger && updatedTrigger.action && updatedTrigger.action === "hide") {
1153
+ return renderState === WidgetRenderState.open ? this.hide() : this.open();
1154
+ }
1155
+ return renderState === WidgetRenderState.open ? this.close() : this.open();
1156
+ });
1157
+ });
1158
+ });
1159
+ }
1160
+ if (this.outlets.size > 1) {
1161
+ return this.renderState().then((state) => {
1162
+ this.triggerStateIfApplicable(state);
1163
+ });
1164
+ }
1165
+ if (withRenderState) {
1166
+ if (withRenderState === "storage") {
1167
+ return this.renderState().then((state) => {
1168
+ if (outletOptions.triggerType === TriggerType.Inline) {
1169
+ this.triggerStateIfApplicable("open");
1170
+ return;
1171
+ }
1172
+ this.triggerStateIfApplicable(state);
1173
+ });
1174
+ }
1175
+ return this.triggerStateIfApplicable(withRenderState);
1176
+ }
1177
+ });
1178
+ }
1179
+ detach(key) {
1180
+ if (key) {
1181
+ if (this.outlets.has(key)) {
1182
+ const outlet = this.outlets.get(key);
1183
+ outlet == null ? void 0 : outlet.dispose();
1184
+ this.outlets.delete(key);
1185
+ return;
1186
+ }
1187
+ return;
1188
+ }
1189
+ this.outlets.forEach((outlet) => {
1190
+ outlet.dispose();
1191
+ });
1192
+ this.outlets.clear();
1193
+ }
1194
+ triggerStateIfApplicable(input) {
1195
+ return this.container.getAsync("router").then((router) => {
1196
+ switch (input) {
1197
+ case "closed":
1198
+ this.close();
1199
+ break;
1200
+ case "open":
1201
+ this.open();
1202
+ break;
1203
+ case "hidden":
1204
+ this.hide();
1205
+ router.start();
1206
+ break;
1207
+ default:
1208
+ return;
1209
+ }
1210
+ });
1211
+ }
1212
+ getOrCreateViewOutlet(key, options) {
1213
+ return this.outlets.has(key) ? this.outlets.get(key) : new ViewOutlet(this.container, options);
1214
+ }
1215
+ render(renderData = {}) {
1216
+ if (renderData.open) {
1217
+ const options = __spreadProps(__spreadValues({}, renderData), {
1218
+ withRenderState: "open"
1219
+ });
1220
+ return this.attach(options);
1221
+ }
1222
+ return this.attach(renderData);
1223
+ }
1224
+ activate(data) {
1225
+ if (data == null ? void 0 : data.override) {
1226
+ this.setSettings(() => data.override);
1227
+ }
1228
+ if (data == null ? void 0 : data.apiNotificationPriorityBy) {
1229
+ this.container.register("apiNotificationPriorityBy", data.apiNotificationPriorityBy);
1230
+ }
1231
+ }
1232
+ setSettings(fn) {
1233
+ return Promise.all([
1234
+ this.container.get("settings"),
1235
+ createStorageWriter(this.container, SETTINGS_STORAGE_KEY, StorageCategory.Necessary, {
1236
+ medium: StorageMedium.Local
1237
+ })
1238
+ ]).then(([settings, write]) => {
1239
+ return Promise.resolve(fn(settings)).then((override) => {
1240
+ return write(override).then(() => {
1241
+ const updated = __spreadValues(__spreadValues({}, settings), override);
1242
+ this.widget.events.dispatch("widget:settings-updated", updated);
1243
+ return updated;
1244
+ });
1245
+ });
1246
+ });
1247
+ }
1248
+ clearSettings() {
1249
+ return createStorageWriter(this.container, SETTINGS_STORAGE_KEY, StorageCategory.Necessary, { medium: StorageMedium.Local }).then((write) => write()).then(() => this.container.get("settings")).then((settings) => {
1250
+ this.widget.events.dispatch("widget:settings-updated", settings);
1251
+ });
1252
+ }
1253
+ action({ action, value }) {
1254
+ return this.container.getAsync("actionResolver").then((actionResolver) => {
1255
+ actionResolver.action(this.widget.name, action, value);
1256
+ });
1257
+ }
1258
+ renderState() {
1259
+ if (onWidgetUrl(this.container)) {
1260
+ return Promise.resolve(WidgetRenderState.open);
1261
+ }
1262
+ const readSessionOpen = () => readStorage(this.container, OPEN_STORAGE_KEY, StorageMedium.Session).then((value = WidgetRenderState.closed) => value);
1263
+ const readLocalOpen = () => readStorage(this.container, OPEN_STORAGE_KEY, StorageMedium.Session).then((value = WidgetRenderState.closed) => value);
1264
+ return this.container.getAsync("router").then((routing) => {
1265
+ if (routing.isSticky()) {
1266
+ return readLocalOpen().then((localOpen) => {
1267
+ return localOpen === WidgetRenderState.open ? localOpen : readSessionOpen();
1268
+ });
1269
+ }
1270
+ return readSessionOpen();
1271
+ });
1272
+ }
1273
+ hide() {
1274
+ if (this.outlets.size < 1) {
1275
+ return Promise.resolve();
1276
+ }
1277
+ this.outlets.forEach((outlet) => outlet.render());
1278
+ return this.action({ action: "hide" }).then(() => {
1279
+ this.setTriggerState(false);
1280
+ });
1281
+ }
1282
+ open() {
1283
+ if (this.outlets.size < 1) {
1284
+ return Promise.resolve();
1285
+ }
1286
+ this.outlets.forEach((outlet) => outlet.render());
1287
+ return this.action({ action: "open" }).then(() => {
1288
+ this.widget.events.dispatch("tracking:widget-rendered", {});
1289
+ return this.onOpen();
1290
+ });
1291
+ }
1292
+ close() {
1293
+ if (this.outlets.size < 1) {
1294
+ return Promise.resolve();
1295
+ }
1296
+ return this.action({ action: "close" }).then(() => this.onClose());
1297
+ }
1298
+ show() {
1299
+ return this.open();
1300
+ }
1301
+ onAction(action, value) {
1302
+ switch (action) {
1303
+ case "close":
1304
+ case "open":
1305
+ case "hide":
1306
+ const newState = action === "open" ? WidgetRenderState.open : action === "close" ? WidgetRenderState.closed : WidgetRenderState.hidden;
1307
+ return this.setRenderState(newState).then(() => {
1308
+ this.setTriggerState(newState === WidgetRenderState.open);
1309
+ if (newState !== WidgetRenderState.hidden) {
1310
+ newState === WidgetRenderState.open ? this.onOpen() : this.onClose();
1311
+ } else {
1312
+ this.outlets.forEach((outlet) => {
1313
+ var _a;
1314
+ return (_a = outlet.options.triggerDOMElement) == null ? void 0 : _a.setAttribute("aria-expanded", "false");
1315
+ });
1316
+ }
1317
+ });
1318
+ }
1319
+ }
1320
+ setRenderState(newState) {
1321
+ const { invoke, events } = this.container.get("$widget");
1322
+ return Promise.all([
1323
+ createStorageWriter(this.container, OPEN_STORAGE_KEY, StorageCategory.Necessary, {
1324
+ medium: StorageMedium.Session
1325
+ }),
1326
+ createStorageWriter(this.container, OPEN_STORAGE_KEY, StorageCategory.Necessary, {
1327
+ medium: StorageMedium.Local,
1328
+ duration: { minutes: 5 }
1329
+ }),
1330
+ this.container.getAsync("router"),
1331
+ invoke("renderState")
1332
+ ]).then(([writeSessionOpen, writeLocalOpen, routing, previousRenderState]) => {
1333
+ if (newState === "unset" || !newState) {
1334
+ writeLocalOpen();
1335
+ writeSessionOpen();
1336
+ } else {
1337
+ if (routing.isSticky()) {
1338
+ writeLocalOpen(newState);
1339
+ }
1340
+ writeSessionOpen(newState);
1341
+ }
1342
+ events.dispatch("widget:render-state-changed", {
1343
+ previous: previousRenderState,
1344
+ next: newState
1345
+ });
1346
+ });
1347
+ }
1348
+ onOpen() {
1349
+ return this.container.getAsync("router").then((router) => {
1350
+ this.outlets.forEach((outlet) => {
1351
+ var _a;
1352
+ return (_a = outlet.options.triggerDOMElement) == null ? void 0 : _a.setAttribute("aria-expanded", "true");
1353
+ });
1354
+ return router.start();
1355
+ });
1356
+ }
1357
+ onClose() {
1358
+ const services = this.container.getManyAsync("router", "components");
1359
+ const resetActivateProp = () => {
1360
+ return this.container.get("settings").then((widgetSettings) => {
1361
+ const { activate } = this.container.get("$settings");
1362
+ if (widgetSettings.activate !== activate) {
1363
+ return this.setSettings(() => Promise.resolve({ activate }));
1364
+ }
1365
+ return Promise.resolve();
1366
+ });
1367
+ };
1368
+ return resetActivateProp().then(() => {
1369
+ return services;
1370
+ }).then(({
1371
+ router,
1372
+ components
1373
+ }) => {
1374
+ const visibleNodes = components.nodes.visible;
1375
+ this.outlets.forEach((outlet) => {
1376
+ var _a;
1377
+ return (_a = outlet.options.triggerDOMElement) == null ? void 0 : _a.setAttribute("aria-expanded", "false");
1378
+ });
1379
+ if (visibleNodes.filter((c) => c.attributes.properties.animation && c.attributes.properties.animation !== "none").length) {
1380
+ return new Promise((resolve) => {
1381
+ setTimeout(() => {
1382
+ resolve(router);
1383
+ }, 200);
1384
+ });
1385
+ }
1386
+ return Promise.resolve(router);
1387
+ }).then((router) => router.stop());
1388
+ }
1389
+ setTriggerState(open) {
1390
+ this.outlets.forEach((outlet) => {
1391
+ const {
1392
+ options: { triggerDOMElement, triggerOptions }
1393
+ } = outlet;
1394
+ const { openTooltip, closedTooltip } = triggerOptions || {};
1395
+ if (triggerDOMElement) {
1396
+ open ? setActive(triggerDOMElement, openTooltip) : setInactive(triggerDOMElement, closedTooltip);
1397
+ }
1398
+ });
1399
+ }
1400
+ deactivate() {
1401
+ this.subs.forEach((s) => s());
1402
+ const promises = [];
1403
+ this.outlets.forEach((outlet) => promises.push(outlet.dispose()));
1404
+ return readStorage(this.container, STICKY_WIDGET_STORAGE_KEY, StorageMedium.Local).then((value) => {
1405
+ if (value === this.widget.name) {
1406
+ return createStorageWriter(this.container, STICKY_WIDGET_STORAGE_KEY, StorageCategory.Necessary, {
1407
+ medium: StorageMedium.Local,
1408
+ scope: StorageScope.Implementation
1409
+ }).then((write) => write()).then(() => Promise.all(promises));
1410
+ }
1411
+ return Promise.all(promises);
1412
+ });
1413
+ }
1414
+ }
1415
+ export { Component, DetachedComponent$1 as DetachedComponent, Widget as GridWidget, NotFound, Widget, styling as genericComponentStyling };
1416
+ //# sourceMappingURL=index.js.map