@telia-ace/knowledge-widget-plugins 1.0.1

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 (51) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +3 -0
  3. package/lib/favorite/favorite-platform.d.ts +9 -0
  4. package/lib/favorite/favorite-platform.js +97 -0
  5. package/lib/favorite/favorite.d.ts +9 -0
  6. package/lib/favorite/favorite.js +34 -0
  7. package/lib/favorite/index.d.ts +2 -0
  8. package/lib/favorite/index.js +7 -0
  9. package/lib/favorite/utils.d.ts +8 -0
  10. package/lib/favorite/utils.js +131 -0
  11. package/lib/index.d.ts +3 -0
  12. package/lib/index.js +12 -0
  13. package/lib/legacy-resources/index.d.ts +2 -0
  14. package/lib/legacy-resources/index.js +7 -0
  15. package/lib/legacy-resources/legacy-resources.d.ts +14 -0
  16. package/lib/legacy-resources/legacy-resources.js +56 -0
  17. package/lib/misc-behavior/deny-auto-expand-contact-methods-handler.d.ts +9 -0
  18. package/lib/misc-behavior/deny-auto-expand-contact-methods-handler.js +70 -0
  19. package/lib/misc-behavior/hide-back-on-single-contact-method-handler.d.ts +8 -0
  20. package/lib/misc-behavior/hide-back-on-single-contact-method-handler.js +110 -0
  21. package/lib/misc-behavior/index.d.ts +2 -0
  22. package/lib/misc-behavior/index.js +7 -0
  23. package/lib/misc-behavior/plugin.d.ts +19 -0
  24. package/lib/misc-behavior/plugin.js +105 -0
  25. package/lib/misc-behavior/search-guide-list-keyboard-navigation-handler.d.ts +7 -0
  26. package/lib/misc-behavior/search-guide-list-keyboard-navigation-handler.js +141 -0
  27. package/lib-esm/favorite/favorite-platform.d.ts +9 -0
  28. package/lib-esm/favorite/favorite-platform.js +95 -0
  29. package/lib-esm/favorite/favorite.d.ts +9 -0
  30. package/lib-esm/favorite/favorite.js +29 -0
  31. package/lib-esm/favorite/index.d.ts +2 -0
  32. package/lib-esm/favorite/index.js +2 -0
  33. package/lib-esm/favorite/utils.d.ts +8 -0
  34. package/lib-esm/favorite/utils.js +123 -0
  35. package/lib-esm/index.d.ts +3 -0
  36. package/lib-esm/index.js +3 -0
  37. package/lib-esm/legacy-resources/index.d.ts +2 -0
  38. package/lib-esm/legacy-resources/index.js +2 -0
  39. package/lib-esm/legacy-resources/legacy-resources.d.ts +14 -0
  40. package/lib-esm/legacy-resources/legacy-resources.js +54 -0
  41. package/lib-esm/misc-behavior/deny-auto-expand-contact-methods-handler.d.ts +9 -0
  42. package/lib-esm/misc-behavior/deny-auto-expand-contact-methods-handler.js +68 -0
  43. package/lib-esm/misc-behavior/hide-back-on-single-contact-method-handler.d.ts +8 -0
  44. package/lib-esm/misc-behavior/hide-back-on-single-contact-method-handler.js +108 -0
  45. package/lib-esm/misc-behavior/index.d.ts +2 -0
  46. package/lib-esm/misc-behavior/index.js +2 -0
  47. package/lib-esm/misc-behavior/plugin.d.ts +19 -0
  48. package/lib-esm/misc-behavior/plugin.js +100 -0
  49. package/lib-esm/misc-behavior/search-guide-list-keyboard-navigation-handler.d.ts +7 -0
  50. package/lib-esm/misc-behavior/search-guide-list-keyboard-navigation-handler.js +139 -0
  51. package/package.json +39 -0
@@ -0,0 +1,19 @@
1
+ import { Plugin } from '@telia-ace/knowledge-widget-core';
2
+ import { Container } from '@webprovisions/platform';
3
+ export declare type Settings = {
4
+ denyAutoExpandContactMethods?: string;
5
+ hideBackOnSingleContactMethod?: boolean;
6
+ searchToGuideListArrowKeyNavigation?: boolean;
7
+ };
8
+ export declare type Listerners = {
9
+ parent: HTMLElement | Window;
10
+ handler: (...args: any[]) => void;
11
+ type: string;
12
+ }[];
13
+ export default class MiscBehaviorPlugin extends Plugin {
14
+ settings: Settings;
15
+ listeners: Listerners;
16
+ constructor(container: Container, settings?: Settings);
17
+ initialize(): Promise<void>;
18
+ deactivate(): void;
19
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ var knowledge_widget_core_1 = require("@telia-ace/knowledge-widget-core");
58
+ var deny_auto_expand_contact_methods_handler_1 = __importDefault(require("./deny-auto-expand-contact-methods-handler"));
59
+ var hide_back_on_single_contact_method_handler_1 = __importDefault(require("./hide-back-on-single-contact-method-handler"));
60
+ var search_guide_list_keyboard_navigation_handler_1 = __importDefault(require("./search-guide-list-keyboard-navigation-handler"));
61
+ var MiscBehaviorPlugin = /** @class */ (function (_super) {
62
+ __extends(MiscBehaviorPlugin, _super);
63
+ function MiscBehaviorPlugin(container, settings) {
64
+ if (settings === void 0) { settings = {}; }
65
+ var _this = _super.call(this, container) || this;
66
+ _this.settings = settings;
67
+ _this.listeners = [];
68
+ return _this;
69
+ }
70
+ MiscBehaviorPlugin.prototype.initialize = function () {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var _a;
73
+ return __generator(this, function (_b) {
74
+ switch (_b.label) {
75
+ case 0:
76
+ _a = this;
77
+ return [4 /*yield*/, Promise.all([
78
+ Promise.resolve((0, hide_back_on_single_contact_method_handler_1.default)(this.container, this.settings)),
79
+ Promise.resolve((0, deny_auto_expand_contact_methods_handler_1.default)(this.container, this.settings)),
80
+ Promise.resolve((0, search_guide_list_keyboard_navigation_handler_1.default)(this.container, this.settings)),
81
+ ]).then(function (listenerArray) {
82
+ var listeners = [];
83
+ listenerArray.forEach(function (a) { return a.forEach(function (l) { return listeners.push(l); }); });
84
+ listeners.forEach(function (_a) {
85
+ var parent = _a.parent, type = _a.type, handler = _a.handler;
86
+ parent.addEventListener(type, handler);
87
+ });
88
+ return listeners;
89
+ })];
90
+ case 1:
91
+ _a.listeners = _b.sent();
92
+ return [2 /*return*/];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ MiscBehaviorPlugin.prototype.deactivate = function () {
98
+ this.listeners.forEach(function (listener) {
99
+ var parent = listener.parent, handler = listener.handler, type = listener.type;
100
+ parent.removeEventListener(type, handler);
101
+ });
102
+ };
103
+ return MiscBehaviorPlugin;
104
+ }(knowledge_widget_core_1.Plugin));
105
+ exports.default = MiscBehaviorPlugin;
@@ -0,0 +1,7 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ import { Listerners, Settings } from './plugin';
3
+ declare const _default: (container: Container, settings: Settings) => Promise<Listerners>;
4
+ /**
5
+ * Will focus guide-list when focusing search-input and pressing arrow-down key
6
+ */
7
+ export default _default;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ var isQuickFilterOpen = function (searchElements) {
56
+ return searchElements.reduce(function (acc, current) {
57
+ if (acc) {
58
+ return acc;
59
+ }
60
+ var _a = __read(Array.from((current === null || current === void 0 ? void 0 : current.getElementsByClassName('humany-quick-filter-dropdown')) || []), 1), element = _a[0];
61
+ if (element) {
62
+ return true;
63
+ }
64
+ return false;
65
+ }, false);
66
+ };
67
+ var isSearchElementFocused = function (searchElements) {
68
+ return searchElements.reduce(function (acc, current) {
69
+ if (acc) {
70
+ return acc;
71
+ }
72
+ var _a = __read(Array.from((current === null || current === void 0 ? void 0 : current.getElementsByTagName('input')) || []), 1), input = _a[0];
73
+ if (input && input === document.activeElement) {
74
+ return true;
75
+ }
76
+ return false;
77
+ }, false);
78
+ };
79
+ var getGuideListLinks = function () {
80
+ return Array.from(document.querySelectorAll('[data-component-type="guide-list"]')).reduce(function (acc, current) {
81
+ var links = Array.from(current.getElementsByTagName('a'));
82
+ links.forEach(function (l) { return acc.push(l); });
83
+ return acc;
84
+ }, []);
85
+ };
86
+ /**
87
+ * Will focus guide-list when focusing search-input and pressing arrow-down key
88
+ */
89
+ exports.default = (function (container, settings) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var _a, searchToGuideListArrowKeyNavigation;
91
+ return __generator(this, function (_b) {
92
+ _a = settings.searchToGuideListArrowKeyNavigation, searchToGuideListArrowKeyNavigation = _a === void 0 ? false : _a;
93
+ if (searchToGuideListArrowKeyNavigation) {
94
+ return [2 /*return*/, container.getAsync('components').then(function (platform) {
95
+ var all = platform.nodes.all;
96
+ var searchComponentIds = all.filter(function (n) { return n.type === 'search'; }).map(function (n) { return n.id; });
97
+ var listeners = [];
98
+ listeners.push({
99
+ parent: window,
100
+ type: 'keydown',
101
+ handler: function (e) {
102
+ var _a, _b, _c, _d;
103
+ var searchComponentElements = [];
104
+ searchComponentIds.forEach(function (id) {
105
+ var element = document.getElementById(id);
106
+ if (element) {
107
+ searchComponentElements.push(element);
108
+ }
109
+ });
110
+ var quickFilterDropdownOpen = isQuickFilterOpen(searchComponentElements);
111
+ var searchElementIsFocused = isSearchElementFocused(searchComponentElements);
112
+ var guideListLinks = getGuideListLinks();
113
+ var guideListLinkFocusIndex = guideListLinks.indexOf(document.activeElement);
114
+ if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') &&
115
+ (searchElementIsFocused || guideListLinkFocusIndex > -1)) {
116
+ e.preventDefault();
117
+ }
118
+ if (e.key === 'ArrowDown' &&
119
+ searchElementIsFocused &&
120
+ !quickFilterDropdownOpen) {
121
+ guideListLinks[0].focus();
122
+ }
123
+ else {
124
+ if (e.key === 'ArrowUp' && guideListLinkFocusIndex === 0) {
125
+ (_b = (_a = searchComponentElements[0]) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('input')[0]) === null || _b === void 0 ? void 0 : _b.focus();
126
+ }
127
+ else if (e.key === 'ArrowUp' && guideListLinkFocusIndex > -1) {
128
+ (_c = guideListLinks[guideListLinkFocusIndex - 1]) === null || _c === void 0 ? void 0 : _c.focus();
129
+ }
130
+ else if (e.key === 'ArrowDown' && guideListLinkFocusIndex > -1) {
131
+ (_d = guideListLinks[guideListLinkFocusIndex + 1]) === null || _d === void 0 ? void 0 : _d.focus();
132
+ }
133
+ }
134
+ },
135
+ });
136
+ return listeners;
137
+ })];
138
+ }
139
+ return [2 /*return*/, Promise.resolve([])];
140
+ });
141
+ }); });
@@ -0,0 +1,9 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ export declare type FavoritePlatform = {
3
+ add: (guideId: string) => Promise<string[]>;
4
+ remove: (guideId: string) => Promise<string[]>;
5
+ clear: () => Promise<string[]>;
6
+ get: () => string[];
7
+ };
8
+ declare const createFavoritePlatform: (container: Container) => FavoritePlatform;
9
+ export default createFavoritePlatform;
@@ -0,0 +1,95 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { addFavoriteToStorage, notifyListeners, readFavoritesFromStorage, removeAllFavoritesFromStorage, removeFavoriteFromStorage, } from './utils';
38
+ var createFavoritePlatform = function (container) {
39
+ var favorites = [];
40
+ var initialize = function () {
41
+ readFavoritesFromStorage(container).then(function (items) {
42
+ favorites = items;
43
+ });
44
+ };
45
+ var get = function () {
46
+ return favorites;
47
+ };
48
+ var add = function (guideId) { return __awaiter(void 0, void 0, void 0, function () {
49
+ var updated;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0: return [4 /*yield*/, addFavoriteToStorage(guideId, container)];
53
+ case 1:
54
+ updated = _a.sent();
55
+ favorites = updated;
56
+ notifyListeners(container, { updated: updated });
57
+ return [2 /*return*/, updated];
58
+ }
59
+ });
60
+ }); };
61
+ var clear = function () { return __awaiter(void 0, void 0, void 0, function () {
62
+ var updated;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0: return [4 /*yield*/, removeAllFavoritesFromStorage(container)];
66
+ case 1:
67
+ updated = _a.sent();
68
+ favorites = updated;
69
+ notifyListeners(container, { updated: updated });
70
+ return [2 /*return*/, updated];
71
+ }
72
+ });
73
+ }); };
74
+ var remove = function (guideId) { return __awaiter(void 0, void 0, void 0, function () {
75
+ var updated;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4 /*yield*/, removeFavoriteFromStorage(guideId, container)];
79
+ case 1:
80
+ updated = _a.sent();
81
+ favorites = updated;
82
+ notifyListeners(container, { updated: updated });
83
+ return [2 /*return*/, updated];
84
+ }
85
+ });
86
+ }); };
87
+ initialize();
88
+ return {
89
+ add: add,
90
+ get: get,
91
+ clear: clear,
92
+ remove: remove,
93
+ };
94
+ };
95
+ export default createFavoritePlatform;
@@ -0,0 +1,9 @@
1
+ import { Plugin } from '@telia-ace/knowledge-widget-core';
2
+ import { Container } from '@webprovisions/platform';
3
+ import { FavoritePlatform } from './favorite-platform';
4
+ export declare type FavoritePluginSettings = {};
5
+ export default class FavoritePlugin extends Plugin {
6
+ settings: FavoritePluginSettings;
7
+ handler: FavoritePlatform;
8
+ constructor(container: Container, settings: FavoritePluginSettings);
9
+ }
@@ -0,0 +1,29 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { Plugin } from '@telia-ace/knowledge-widget-core';
17
+ import createFavoritePlatform from './favorite-platform';
18
+ var FavoritePlugin = /** @class */ (function (_super) {
19
+ __extends(FavoritePlugin, _super);
20
+ function FavoritePlugin(container, settings) {
21
+ var _this = _super.call(this, container) || this;
22
+ _this.settings = settings;
23
+ _this.handler = createFavoritePlatform(container);
24
+ container.register('favorites', _this.handler);
25
+ return _this;
26
+ }
27
+ return FavoritePlugin;
28
+ }(Plugin));
29
+ export default FavoritePlugin;
@@ -0,0 +1,2 @@
1
+ import FavoritePlugin from './favorite';
2
+ export default FavoritePlugin;
@@ -0,0 +1,2 @@
1
+ import FavoritePlugin from './favorite';
2
+ export default FavoritePlugin;
@@ -0,0 +1,8 @@
1
+ import { Container } from '@webprovisions/platform';
2
+ export declare const addFavoriteToStorage: (guideId: string, container: Container) => Promise<string[]>;
3
+ export declare const removeFavoriteFromStorage: (guideId: string, container: Container) => Promise<string[]>;
4
+ export declare const readFavoritesFromStorage: (container: Container) => Promise<string[]>;
5
+ export declare const removeAllFavoritesFromStorage: (container: Container) => Promise<never[]>;
6
+ export declare const notifyListeners: (container: Container, data: {
7
+ updated: string[];
8
+ }) => void;
@@ -0,0 +1,123 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { createStorageWriter, readStorage, StorageCategory, StorageMedium, } from '@telia-ace/widget-services';
38
+ var storageKey = 'favorites';
39
+ var createWriter = function (container) { return __awaiter(void 0, void 0, void 0, function () {
40
+ return __generator(this, function (_a) {
41
+ switch (_a.label) {
42
+ case 0: return [4 /*yield*/, createStorageWriter(container, storageKey, StorageCategory.Necessary, {
43
+ medium: StorageMedium.Local,
44
+ })];
45
+ case 1: return [2 /*return*/, _a.sent()];
46
+ }
47
+ });
48
+ }); };
49
+ var getStoredFavorites = function (container) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0: return [4 /*yield*/, readStorage(container, storageKey, StorageMedium.Local)];
52
+ case 1: return [2 /*return*/, (_a.sent()) || []];
53
+ }
54
+ }); }); };
55
+ export var addFavoriteToStorage = function (guideId, container) { return __awaiter(void 0, void 0, void 0, function () {
56
+ var write, favorites, updated;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0: return [4 /*yield*/, createWriter(container)];
60
+ case 1:
61
+ write = _a.sent();
62
+ return [4 /*yield*/, getStoredFavorites(container)];
63
+ case 2:
64
+ favorites = _a.sent();
65
+ if (favorites.indexOf(guideId) > -1) {
66
+ return [2 /*return*/, favorites];
67
+ }
68
+ updated = favorites.concat(guideId);
69
+ write(updated);
70
+ return [2 /*return*/, updated];
71
+ }
72
+ });
73
+ }); };
74
+ export var removeFavoriteFromStorage = function (guideId, container) { return __awaiter(void 0, void 0, void 0, function () {
75
+ var write, favorites, updated;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4 /*yield*/, createWriter(container)];
79
+ case 1:
80
+ write = _a.sent();
81
+ return [4 /*yield*/, getStoredFavorites(container)];
82
+ case 2:
83
+ favorites = _a.sent();
84
+ updated = favorites.filter(function (id) { return id !== guideId; });
85
+ write(updated);
86
+ return [2 /*return*/, updated];
87
+ }
88
+ });
89
+ }); };
90
+ export var readFavoritesFromStorage = function (container) { return __awaiter(void 0, void 0, void 0, function () {
91
+ var favorites, e_1;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ _a.trys.push([0, 2, , 3]);
96
+ return [4 /*yield*/, getStoredFavorites(container)];
97
+ case 1:
98
+ favorites = _a.sent();
99
+ return [2 /*return*/, favorites];
100
+ case 2:
101
+ e_1 = _a.sent();
102
+ return [2 /*return*/, []];
103
+ case 3: return [2 /*return*/];
104
+ }
105
+ });
106
+ }); };
107
+ export var removeAllFavoritesFromStorage = function (container) { return __awaiter(void 0, void 0, void 0, function () {
108
+ var write;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0: return [4 /*yield*/, createWriter(container)];
112
+ case 1:
113
+ write = _a.sent();
114
+ write([]);
115
+ return [2 /*return*/, []];
116
+ }
117
+ });
118
+ }); };
119
+ export var notifyListeners = function (container, data) {
120
+ var updated = data.updated;
121
+ var events = container.get('$widget').events;
122
+ events.dispatch('widget:favorites-updated', { updated: updated });
123
+ };
@@ -0,0 +1,3 @@
1
+ export { default as FavoritePlugin } from './favorite';
2
+ export { default as LegacyResourcesPlugin } from './legacy-resources';
3
+ export { default as MiscBehaviorPlugin } from './misc-behavior';
@@ -0,0 +1,3 @@
1
+ export { default as FavoritePlugin } from './favorite';
2
+ export { default as LegacyResourcesPlugin } from './legacy-resources';
3
+ export { default as MiscBehaviorPlugin } from './misc-behavior';
@@ -0,0 +1,2 @@
1
+ import LegacyResources from './legacy-resources';
2
+ export default LegacyResources;
@@ -0,0 +1,2 @@
1
+ import LegacyResources from './legacy-resources';
2
+ export default LegacyResources;
@@ -0,0 +1,14 @@
1
+ import { Plugin } from '@telia-ace/knowledge-widget-core';
2
+ import { Container } from '@webprovisions/platform';
3
+ declare type Settings = {
4
+ initialCss?: string;
5
+ };
6
+ /**
7
+ * Downloads legacy resources for a widget. These resources are to be treated as legacy. When the
8
+ * Webprovisions bundling service is available these resources should be included as their own
9
+ * plugins and be part of the output.
10
+ */
11
+ export default class LegacyResourcesPlugin extends Plugin {
12
+ constructor(container: Container, settings?: Settings);
13
+ }
14
+ export {};
@@ -0,0 +1,54 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { ResourceLoader } from '@telia-ace/knowledge-resource-loader';
17
+ import { Plugin } from '@telia-ace/knowledge-widget-core';
18
+ var getHostFromUrl = function (url) {
19
+ var parser = document.createElement('a');
20
+ parser.href = url;
21
+ return "//".concat(parser.hostname, "/");
22
+ };
23
+ /**
24
+ * Downloads legacy resources for a widget. These resources are to be treated as legacy. When the
25
+ * Webprovisions bundling service is available these resources should be included as their own
26
+ * plugins and be part of the output.
27
+ */
28
+ var LegacyResourcesPlugin = /** @class */ (function (_super) {
29
+ __extends(LegacyResourcesPlugin, _super);
30
+ function LegacyResourcesPlugin(container, settings) {
31
+ if (settings === void 0) { settings = {}; }
32
+ var _this = _super.call(this, container) || this;
33
+ _this.widget.events.subscribeOnce('widget:attached', function () {
34
+ var _a;
35
+ var projection = _this.container.get('$settings').data.projection;
36
+ if (projection) {
37
+ var host = getHostFromUrl(projection);
38
+ var loader = new ResourceLoader();
39
+ loader.add("".concat(host, "ClientLibraries/Supplementary/font-awesome-4.7.0/css/font-awesome.min.css")); // tslint:disable-line max-line-length
40
+ loader.add("".concat(host).concat((_a = _this.container.parent) === null || _a === void 0 ? void 0 : _a.name, "/widgets.css"));
41
+ loader.load();
42
+ }
43
+ var _b = settings.initialCss, initialCss = _b === void 0 ? '' : _b;
44
+ if (initialCss.length) {
45
+ var style = document.createElement('style');
46
+ style.innerHTML = initialCss;
47
+ document.head.appendChild(style);
48
+ }
49
+ });
50
+ return _this;
51
+ }
52
+ return LegacyResourcesPlugin;
53
+ }(Plugin));
54
+ export default LegacyResourcesPlugin;