@telia-ace/widget-utilities 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +6 -0
- package/README.md +3 -0
- package/lib/append-class-names.d.ts +6 -0
- package/lib/append-class-names.js +84 -0
- package/lib/batch.d.ts +4 -0
- package/lib/batch.js +38 -0
- package/lib/camilize.d.ts +1 -0
- package/lib/camilize.js +29 -0
- package/lib/category-trail.d.ts +14 -0
- package/lib/category-trail.js +96 -0
- package/lib/create-params.d.ts +21 -0
- package/lib/create-params.js +108 -0
- package/lib/data-uri-to-blob.d.ts +2 -0
- package/lib/data-uri-to-blob.js +20 -0
- package/lib/debug.d.ts +52 -0
- package/lib/debug.js +155 -0
- package/lib/deep-clone.d.ts +2 -0
- package/lib/deep-clone.js +21 -0
- package/lib/find-and-activate-stored-widgets.d.ts +9 -0
- package/lib/find-and-activate-stored-widgets.js +27 -0
- package/lib/find-category-by-id.d.ts +6 -0
- package/lib/find-category-by-id.js +89 -0
- package/lib/format-date.d.ts +2 -0
- package/lib/format-date.js +23 -0
- package/lib/format-url.d.ts +2 -0
- package/lib/format-url.js +111 -0
- package/lib/get-cookie.d.ts +1 -0
- package/lib/get-cookie.js +18 -0
- package/lib/has-non-empty-categories.d.ts +2 -0
- package/lib/has-non-empty-categories.js +23 -0
- package/lib/hash.d.ts +1 -0
- package/lib/hash.js +16 -0
- package/lib/html-parent-contains.d.ts +7 -0
- package/lib/html-parent-contains.js +21 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +57 -0
- package/lib/is-anchor-link.d.ts +2 -0
- package/lib/is-anchor-link.js +9 -0
- package/lib/kebab-case.d.ts +1 -0
- package/lib/kebab-case.js +9 -0
- package/lib/lock.d.ts +9 -0
- package/lib/lock.js +78 -0
- package/lib/merge-deep.d.ts +7 -0
- package/lib/merge-deep.js +72 -0
- package/lib/notify-data-loaded.d.ts +6 -0
- package/lib/notify-data-loaded.js +96 -0
- package/lib/remove-null-and-undefined-values.d.ts +6 -0
- package/lib/remove-null-and-undefined-values.js +12 -0
- package/lib/set-cookie.d.ts +1 -0
- package/lib/set-cookie.js +12 -0
- package/lib/shallow-compare.d.ts +6 -0
- package/lib/shallow-compare.js +25 -0
- package/lib/uuid.d.ts +1 -0
- package/lib/uuid.js +12 -0
- package/lib/wait-for.d.ts +20 -0
- package/lib/wait-for.js +52 -0
- package/lib-esm/append-class-names.d.ts +6 -0
- package/lib-esm/append-class-names.js +77 -0
- package/lib-esm/batch.d.ts +4 -0
- package/lib-esm/batch.js +36 -0
- package/lib-esm/camilize.d.ts +1 -0
- package/lib-esm/camilize.js +26 -0
- package/lib-esm/category-trail.d.ts +14 -0
- package/lib-esm/category-trail.js +87 -0
- package/lib-esm/create-params.d.ts +21 -0
- package/lib-esm/create-params.js +105 -0
- package/lib-esm/data-uri-to-blob.d.ts +2 -0
- package/lib-esm/data-uri-to-blob.js +18 -0
- package/lib-esm/debug.d.ts +52 -0
- package/lib-esm/debug.js +151 -0
- package/lib-esm/deep-clone.d.ts +2 -0
- package/lib-esm/deep-clone.js +19 -0
- package/lib-esm/find-and-activate-stored-widgets.d.ts +9 -0
- package/lib-esm/find-and-activate-stored-widgets.js +25 -0
- package/lib-esm/find-category-by-id.d.ts +6 -0
- package/lib-esm/find-category-by-id.js +87 -0
- package/lib-esm/format-date.d.ts +2 -0
- package/lib-esm/format-date.js +21 -0
- package/lib-esm/format-url.d.ts +2 -0
- package/lib-esm/format-url.js +109 -0
- package/lib-esm/get-cookie.d.ts +1 -0
- package/lib-esm/get-cookie.js +15 -0
- package/lib-esm/has-non-empty-categories.d.ts +2 -0
- package/lib-esm/has-non-empty-categories.js +18 -0
- package/lib-esm/hash.d.ts +1 -0
- package/lib-esm/hash.js +13 -0
- package/lib-esm/html-parent-contains.d.ts +7 -0
- package/lib-esm/html-parent-contains.js +19 -0
- package/lib-esm/index.d.ts +27 -0
- package/lib-esm/index.js +24 -0
- package/lib-esm/is-anchor-link.d.ts +2 -0
- package/lib-esm/is-anchor-link.js +7 -0
- package/lib-esm/kebab-case.d.ts +1 -0
- package/lib-esm/kebab-case.js +6 -0
- package/lib-esm/lock.d.ts +9 -0
- package/lib-esm/lock.js +75 -0
- package/lib-esm/merge-deep.d.ts +7 -0
- package/lib-esm/merge-deep.js +67 -0
- package/lib-esm/notify-data-loaded.d.ts +6 -0
- package/lib-esm/notify-data-loaded.js +94 -0
- package/lib-esm/remove-null-and-undefined-values.d.ts +6 -0
- package/lib-esm/remove-null-and-undefined-values.js +10 -0
- package/lib-esm/set-cookie.d.ts +1 -0
- package/lib-esm/set-cookie.js +9 -0
- package/lib-esm/shallow-compare.d.ts +6 -0
- package/lib-esm/shallow-compare.js +23 -0
- package/lib-esm/uuid.d.ts +1 -0
- package/lib-esm/uuid.js +9 -0
- package/lib-esm/wait-for.d.ts +20 -0
- package/lib-esm/wait-for.js +50 -0
- package/package.json +35 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (s: string): string;
|
package/lib-esm/hash.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function (s) {
|
|
2
|
+
var hash = 0;
|
|
3
|
+
if (s.length === 0) {
|
|
4
|
+
return hash.toString();
|
|
5
|
+
}
|
|
6
|
+
// tslint:disable-next-line:no-increment-decrement
|
|
7
|
+
for (var i = 0; i < s.length; i++) {
|
|
8
|
+
var char = s.charCodeAt(i);
|
|
9
|
+
hash = (hash << 5) - hash + char;
|
|
10
|
+
hash = hash & hash;
|
|
11
|
+
}
|
|
12
|
+
return hash.toString();
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether or not the passed child is a descendant
|
|
3
|
+
* of the passed parent.
|
|
4
|
+
* Will return true if falsey parent or child.
|
|
5
|
+
*/
|
|
6
|
+
export default (function (parent, child) {
|
|
7
|
+
if (!parent || !child) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
var node = child.parentNode;
|
|
11
|
+
var hasChild = false;
|
|
12
|
+
while (node !== null) {
|
|
13
|
+
if (node === parent) {
|
|
14
|
+
hasChild = true;
|
|
15
|
+
}
|
|
16
|
+
node = node.parentNode;
|
|
17
|
+
}
|
|
18
|
+
return hasChild;
|
|
19
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { default as appendClassNames } from './append-class-names';
|
|
2
|
+
export { default as createBatch } from './batch';
|
|
3
|
+
export type { Batch, BatchFunction } from './batch';
|
|
4
|
+
export { default as camilize } from './camilize';
|
|
5
|
+
export { buildCategoryTrail, categoryTrail, getCategoryTrailAsObjects } from './category-trail';
|
|
6
|
+
export { default as createParams } from './create-params';
|
|
7
|
+
export type { Params, ParamValue } from './create-params';
|
|
8
|
+
export { default as dataURItoBlob } from './data-uri-to-blob';
|
|
9
|
+
export { debugLog, Logger } from './debug';
|
|
10
|
+
export { default as deepClone } from './deep-clone';
|
|
11
|
+
export { default as findAndActivateStoredWidgets } from './find-and-activate-stored-widgets';
|
|
12
|
+
export { default as findCategoryById } from './find-category-by-id';
|
|
13
|
+
export { default as formatDate } from './format-date';
|
|
14
|
+
export { default as formatUrl } from './format-url';
|
|
15
|
+
export { default as getCookie } from './get-cookie';
|
|
16
|
+
export { default as hash } from './hash';
|
|
17
|
+
export { default as htmlParentContains } from './html-parent-contains';
|
|
18
|
+
export { default as kebabCase } from './kebab-case';
|
|
19
|
+
export { default as lock } from './lock';
|
|
20
|
+
export { default as mergeDeep } from './merge-deep';
|
|
21
|
+
export { default as notifyDataLoaded } from './notify-data-loaded';
|
|
22
|
+
export { default as removeNullAndUndefinedValues } from './remove-null-and-undefined-values';
|
|
23
|
+
export { default as setCookie } from './set-cookie';
|
|
24
|
+
export { default as shallowCompare } from './shallow-compare';
|
|
25
|
+
export { default as uuid } from './uuid';
|
|
26
|
+
export { default as WaitFor } from './wait-for';
|
|
27
|
+
export type { WaitForOptions } from './wait-for';
|
package/lib-esm/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { default as appendClassNames } from './append-class-names';
|
|
2
|
+
export { default as createBatch } from './batch';
|
|
3
|
+
export { default as camilize } from './camilize';
|
|
4
|
+
export { buildCategoryTrail, categoryTrail, getCategoryTrailAsObjects } from './category-trail';
|
|
5
|
+
export { default as createParams } from './create-params';
|
|
6
|
+
export { default as dataURItoBlob } from './data-uri-to-blob';
|
|
7
|
+
export { debugLog, Logger } from './debug';
|
|
8
|
+
export { default as deepClone } from './deep-clone';
|
|
9
|
+
export { default as findAndActivateStoredWidgets } from './find-and-activate-stored-widgets';
|
|
10
|
+
export { default as findCategoryById } from './find-category-by-id';
|
|
11
|
+
export { default as formatDate } from './format-date';
|
|
12
|
+
export { default as formatUrl } from './format-url';
|
|
13
|
+
export { default as getCookie } from './get-cookie';
|
|
14
|
+
export { default as hash } from './hash';
|
|
15
|
+
export { default as htmlParentContains } from './html-parent-contains';
|
|
16
|
+
export { default as kebabCase } from './kebab-case';
|
|
17
|
+
export { default as lock } from './lock';
|
|
18
|
+
export { default as mergeDeep } from './merge-deep';
|
|
19
|
+
export { default as notifyDataLoaded } from './notify-data-loaded';
|
|
20
|
+
export { default as removeNullAndUndefinedValues } from './remove-null-and-undefined-values';
|
|
21
|
+
export { default as setCookie } from './set-cookie';
|
|
22
|
+
export { default as shallowCompare } from './shallow-compare';
|
|
23
|
+
export { default as uuid } from './uuid';
|
|
24
|
+
export { default as WaitFor } from './wait-for';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function kebabCase(string: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type Task = () => Promise<any> | any;
|
|
2
|
+
export declare type AddTask = (task: Task) => Promise<any>;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a lock for the specified owner that allows only one executing
|
|
5
|
+
* task simultaneously.
|
|
6
|
+
* @param key Lock owner.
|
|
7
|
+
*/
|
|
8
|
+
export default function lock(key: object, lockWarningTime?: number, lockErrorTime?: number): AddTask;
|
|
9
|
+
export {};
|
package/lib-esm/lock.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Logger } from './debug';
|
|
2
|
+
var Queue = /** @class */ (function () {
|
|
3
|
+
function Queue(lockWarningTime, lockErrorTime) {
|
|
4
|
+
this.lockWarningTime = lockWarningTime;
|
|
5
|
+
this.lockErrorTime = lockErrorTime;
|
|
6
|
+
this.tasks = [];
|
|
7
|
+
this.current = Promise.resolve();
|
|
8
|
+
this.next = this.next.bind(this);
|
|
9
|
+
}
|
|
10
|
+
Queue.prototype.add = function (task, resolve, reject, done) {
|
|
11
|
+
this.tasks.push({ task: task, resolve: resolve, reject: reject, done: done });
|
|
12
|
+
this.next();
|
|
13
|
+
};
|
|
14
|
+
Queue.prototype.next = function () {
|
|
15
|
+
var _this = this;
|
|
16
|
+
this.current = this.current.then(function () {
|
|
17
|
+
var next = _this.tasks.shift();
|
|
18
|
+
if (next) {
|
|
19
|
+
var errorTimeout_1; // NodeJS.Timeout
|
|
20
|
+
var warningTimeout_1 = setTimeout(function () {
|
|
21
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
22
|
+
// tslint:disable-next-line max-line-length
|
|
23
|
+
Logger.warn("A lock has exceeded ".concat(_this.lockWarningTime, " ms. Waiting additional ").concat(_this.lockErrorTime, " ms before rejecting the task."), next);
|
|
24
|
+
}
|
|
25
|
+
errorTimeout_1 = setTimeout(function () {
|
|
26
|
+
next.reject('lock timeout exceeded');
|
|
27
|
+
}, _this.lockErrorTime);
|
|
28
|
+
}, _this.lockWarningTime);
|
|
29
|
+
var taskPromise_1 = Promise.resolve(next.task()).then(function (result) {
|
|
30
|
+
clearTimeout(warningTimeout_1);
|
|
31
|
+
clearTimeout(errorTimeout_1);
|
|
32
|
+
return result;
|
|
33
|
+
});
|
|
34
|
+
return Promise.resolve(taskPromise_1)
|
|
35
|
+
.then(_this.next)
|
|
36
|
+
.then(function () {
|
|
37
|
+
return taskPromise_1.then(function (data) {
|
|
38
|
+
next.done();
|
|
39
|
+
next.resolve(data);
|
|
40
|
+
});
|
|
41
|
+
})
|
|
42
|
+
.catch(function (reason) {
|
|
43
|
+
next.done();
|
|
44
|
+
next.reject(reason);
|
|
45
|
+
return _this.next();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return Queue;
|
|
52
|
+
}());
|
|
53
|
+
var locks = new WeakMap();
|
|
54
|
+
/**
|
|
55
|
+
* Creates a lock for the specified owner that allows only one executing
|
|
56
|
+
* task simultaneously.
|
|
57
|
+
* @param key Lock owner.
|
|
58
|
+
*/
|
|
59
|
+
export default function lock(key, lockWarningTime, lockErrorTime) {
|
|
60
|
+
if (lockWarningTime === void 0) { lockWarningTime = 5000; }
|
|
61
|
+
if (lockErrorTime === void 0) { lockErrorTime = 1000; }
|
|
62
|
+
if (!locks.has(key)) {
|
|
63
|
+
locks.set(key, new Queue(lockWarningTime, lockErrorTime));
|
|
64
|
+
}
|
|
65
|
+
return function (task) {
|
|
66
|
+
return new Promise(function (resolve, reject) {
|
|
67
|
+
var queue = locks.get(key);
|
|
68
|
+
queue.add(task, resolve, reject, function () {
|
|
69
|
+
if (!queue.tasks.length) {
|
|
70
|
+
locks.delete(key);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param target Target to merge into
|
|
3
|
+
* @param sources Source to merge into target
|
|
4
|
+
* @returns Clone (new reference) with merged sources
|
|
5
|
+
*/
|
|
6
|
+
declare const mergeDeep: <Target, Source>(target: Target, ...sources: Source[]) => Target & Source;
|
|
7
|
+
export default mergeDeep;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
import deepClone from './deep-clone';
|
|
27
|
+
var isObject = function (item) {
|
|
28
|
+
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* @param target Target to merge into
|
|
32
|
+
* @param sources Source to merge into target
|
|
33
|
+
* @returns Clone (new reference) with merged sources
|
|
34
|
+
*/
|
|
35
|
+
var mergeDeep = function (target) {
|
|
36
|
+
var sources = [];
|
|
37
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
38
|
+
sources[_i - 1] = arguments[_i];
|
|
39
|
+
}
|
|
40
|
+
var clonedTarget = deepClone(target);
|
|
41
|
+
var clonedSources = deepClone(sources);
|
|
42
|
+
return mergeDeepRecursive.apply(void 0, __spreadArray([clonedTarget], __read(clonedSources), false));
|
|
43
|
+
};
|
|
44
|
+
var mergeDeepRecursive = function (target) {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
var sources = [];
|
|
47
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
48
|
+
sources[_i - 1] = arguments[_i];
|
|
49
|
+
}
|
|
50
|
+
if (!sources.length)
|
|
51
|
+
return target;
|
|
52
|
+
var source = sources.shift();
|
|
53
|
+
if (isObject(target) && isObject(source)) {
|
|
54
|
+
for (var key in source) {
|
|
55
|
+
if (isObject(source[key])) {
|
|
56
|
+
if (!target[key])
|
|
57
|
+
Object.assign(target, (_a = {}, _a[key] = {}, _a));
|
|
58
|
+
mergeDeepRecursive(target[key], source[key]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return mergeDeepRecursive.apply(void 0, __spreadArray([target], __read(sources), false));
|
|
66
|
+
};
|
|
67
|
+
export default mergeDeep;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch widget:data-loaded event when all components
|
|
3
|
+
* is considered to be finished loading their initial data
|
|
4
|
+
*/
|
|
5
|
+
var watchForLoadingComplete = function (container, widgetDOMElement) {
|
|
6
|
+
var isLoading = function () { return widgetDOMElement.querySelectorAll('[data-loading=true]').length > 0; };
|
|
7
|
+
var complete = function () {
|
|
8
|
+
var dispatched = false;
|
|
9
|
+
return function () {
|
|
10
|
+
if (dispatched) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
var widget = container.get('$widget');
|
|
14
|
+
widget.events.dispatch('widget:data-loaded', {
|
|
15
|
+
element: widgetDOMElement,
|
|
16
|
+
});
|
|
17
|
+
dispatched = true;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var handleComplete = complete();
|
|
21
|
+
if (!isLoading()) {
|
|
22
|
+
return handleComplete();
|
|
23
|
+
}
|
|
24
|
+
var observer = new MutationObserver(function (mutations, observer) {
|
|
25
|
+
var check = mutations.find(function (mutation) {
|
|
26
|
+
return mutation.type === 'attributes' && mutation.attributeName === 'data-loading';
|
|
27
|
+
});
|
|
28
|
+
if (check && !isLoading()) {
|
|
29
|
+
observer.disconnect();
|
|
30
|
+
handleComplete();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
observer.observe(widgetDOMElement, {
|
|
34
|
+
attributes: true,
|
|
35
|
+
childList: true,
|
|
36
|
+
subtree: true,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Wait for all visible components to render
|
|
41
|
+
*/
|
|
42
|
+
var notifyDataLoaded = function (viewOutletContainer, widgetDOMElement) {
|
|
43
|
+
var widget = viewOutletContainer.get('$widget');
|
|
44
|
+
widget.container.getAsync('components').then(function (components) {
|
|
45
|
+
components.events.subscribeOnce('components:component-model-initialized', function () {
|
|
46
|
+
// Store the names of all visible components we should wait for
|
|
47
|
+
var waitingFor = components.nodes.visible.reduce(function (acc, node) {
|
|
48
|
+
if (!node.name ||
|
|
49
|
+
!node.type ||
|
|
50
|
+
node.type === 'view' ||
|
|
51
|
+
node.type === 'root' ||
|
|
52
|
+
node.attributes.layout.size === 'none') {
|
|
53
|
+
return acc;
|
|
54
|
+
}
|
|
55
|
+
acc.push(node.name);
|
|
56
|
+
return acc;
|
|
57
|
+
}, []);
|
|
58
|
+
var complete = false;
|
|
59
|
+
var observer = new MutationObserver(function (mutations, observer) {
|
|
60
|
+
mutations.forEach(function (mutation) {
|
|
61
|
+
if (mutation.addedNodes) {
|
|
62
|
+
var componentElements_1 = Array.from(mutation.addedNodes).reduce(function (acc, element) {
|
|
63
|
+
var dataName = element.getAttribute && element.getAttribute('data-name');
|
|
64
|
+
if (dataName && waitingFor.indexOf(dataName) > -1) {
|
|
65
|
+
acc.push(dataName);
|
|
66
|
+
}
|
|
67
|
+
return acc;
|
|
68
|
+
}, []);
|
|
69
|
+
// Remove added elements from the list of elements we are waiting for
|
|
70
|
+
waitingFor = waitingFor.filter(function (name) {
|
|
71
|
+
return componentElements_1.indexOf(name) === -1;
|
|
72
|
+
});
|
|
73
|
+
// When the list is empty, we are finished waiting for components to render
|
|
74
|
+
if (!complete && waitingFor.length === 0) {
|
|
75
|
+
complete = true;
|
|
76
|
+
// Creates a new observer that observes data-loading changes
|
|
77
|
+
watchForLoadingComplete(viewOutletContainer, widgetDOMElement);
|
|
78
|
+
observer.disconnect();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
observer.observe(widgetDOMElement, {
|
|
84
|
+
attributes: false,
|
|
85
|
+
characterData: false,
|
|
86
|
+
childList: true,
|
|
87
|
+
subtree: true,
|
|
88
|
+
attributeOldValue: false,
|
|
89
|
+
characterDataOldValue: false,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
export default notifyDataLoaded;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var removeNullAndUndefinedValues = function (object) {
|
|
2
|
+
if (object === void 0) { object = {}; }
|
|
3
|
+
Object.keys(object).forEach(function (key) {
|
|
4
|
+
if (object[key] === null || typeof object[key] === 'undefined') {
|
|
5
|
+
delete object[key];
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return object;
|
|
9
|
+
};
|
|
10
|
+
export default removeNullAndUndefinedValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function setCookie(cookieName: string, value: any, days: number): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function setCookie(cookieName, value, days) {
|
|
2
|
+
var expires = '';
|
|
3
|
+
if (days) {
|
|
4
|
+
var date = new Date();
|
|
5
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
6
|
+
expires = "; expires=".concat(date.toUTCString());
|
|
7
|
+
}
|
|
8
|
+
document.cookie = "".concat(cookieName, "=").concat(value).concat(expires, "; path=/");
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default (function (a, b) {
|
|
2
|
+
var equal = true;
|
|
3
|
+
if (Object.keys(a).length !== Object.keys(b).length) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
var missingKey = Object.keys(a).some(function (key) {
|
|
7
|
+
var found = Object.keys(b).some(function (bKey) {
|
|
8
|
+
return key === bKey;
|
|
9
|
+
});
|
|
10
|
+
return !found;
|
|
11
|
+
});
|
|
12
|
+
if (missingKey) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
Object.keys(a).forEach(function (key) {
|
|
16
|
+
if (equal) {
|
|
17
|
+
var c = typeof a[key] === 'undefined' ? '' : a[key];
|
|
18
|
+
var d = typeof b[key] === 'undefined' ? '' : b[key];
|
|
19
|
+
equal = c.toString() === d.toString();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return equal;
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function uuid(): string;
|
package/lib-esm/uuid.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var s4 = function () {
|
|
2
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
3
|
+
.toString(16)
|
|
4
|
+
.substring(1);
|
|
5
|
+
};
|
|
6
|
+
export default function uuid() {
|
|
7
|
+
// tslint:disable-next-line prefer-template
|
|
8
|
+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare type Action = (...args: any[]) => Function | false;
|
|
2
|
+
export declare type WaitForOptions = {
|
|
3
|
+
callCount?: number;
|
|
4
|
+
};
|
|
5
|
+
export default class WaitFor {
|
|
6
|
+
private queue;
|
|
7
|
+
private queueAttempt;
|
|
8
|
+
private queueAttemptCalls;
|
|
9
|
+
private callCount;
|
|
10
|
+
constructor(options?: WaitForOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Add action to the queue
|
|
13
|
+
*/
|
|
14
|
+
add: (action: Action) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Go through queue and attempt to call each action
|
|
17
|
+
*/
|
|
18
|
+
processQueue: () => void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var WaitFor = /** @class */ (function () {
|
|
2
|
+
function WaitFor(options) {
|
|
3
|
+
var _this = this;
|
|
4
|
+
this.queue = [];
|
|
5
|
+
this.queueAttemptCalls = 0;
|
|
6
|
+
this.callCount = 5;
|
|
7
|
+
/**
|
|
8
|
+
* Add action to the queue
|
|
9
|
+
*/
|
|
10
|
+
this.add = function (action) {
|
|
11
|
+
_this.queue.push(action);
|
|
12
|
+
_this.queueAttempt = setInterval(_this.processQueue, 1000);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Go through queue and attempt to call each action
|
|
16
|
+
*/
|
|
17
|
+
this.processQueue = function () {
|
|
18
|
+
if (_this.queue.length > 0) {
|
|
19
|
+
var indexOfActionsEmitted_1 = [];
|
|
20
|
+
_this.queue.forEach(function (queuedAction, index) {
|
|
21
|
+
var evaluate = queuedAction();
|
|
22
|
+
if (typeof evaluate === 'function') {
|
|
23
|
+
evaluate();
|
|
24
|
+
indexOfActionsEmitted_1.push(index);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
// clean up queue
|
|
28
|
+
_this.queue = _this.queue.filter(function (_, index) {
|
|
29
|
+
if (indexOfActionsEmitted_1.indexOf(index) > -1) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
if (_this.queueAttempt) {
|
|
35
|
+
clearInterval(_this.queueAttempt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (_this.queueAttemptCalls > _this.callCount) {
|
|
39
|
+
clearInterval(_this.queueAttempt);
|
|
40
|
+
_this.queueAttemptCalls = 0;
|
|
41
|
+
}
|
|
42
|
+
_this.queueAttemptCalls = _this.queueAttemptCalls + 1;
|
|
43
|
+
};
|
|
44
|
+
if (options && options.callCount) {
|
|
45
|
+
this.callCount = options.callCount;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return WaitFor;
|
|
49
|
+
}());
|
|
50
|
+
export default WaitFor;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telia-ace/widget-utilities",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Internal utilities used by ACE Widget packages.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"author": "Telia Company AB",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"telia"
|
|
9
|
+
],
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"module": "lib-esm/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"LICENSE.txt",
|
|
14
|
+
"README.md",
|
|
15
|
+
"lib/",
|
|
16
|
+
"lib-esm/"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "cleandir lib && cleandir lib-esm",
|
|
23
|
+
"compile": "tsc -p ./tsconfig.cjs.json && tsc -p ./tsconfig.esm.json"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"typings": "lib/index.d.ts",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@webprovisions/platform": "^1.1.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^17.0.21",
|
|
32
|
+
"clean-dir": "^1.0.3",
|
|
33
|
+
"typescript": "^4.6.2"
|
|
34
|
+
}
|
|
35
|
+
}
|