@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,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
var deep_clone_1 = __importDefault(require("./deep-clone"));
|
|
32
|
+
var isObject = function (item) {
|
|
33
|
+
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* @param target Target to merge into
|
|
37
|
+
* @param sources Source to merge into target
|
|
38
|
+
* @returns Clone (new reference) with merged sources
|
|
39
|
+
*/
|
|
40
|
+
var mergeDeep = function (target) {
|
|
41
|
+
var sources = [];
|
|
42
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
43
|
+
sources[_i - 1] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
var clonedTarget = (0, deep_clone_1.default)(target);
|
|
46
|
+
var clonedSources = (0, deep_clone_1.default)(sources);
|
|
47
|
+
return mergeDeepRecursive.apply(void 0, __spreadArray([clonedTarget], __read(clonedSources), false));
|
|
48
|
+
};
|
|
49
|
+
var mergeDeepRecursive = function (target) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
var sources = [];
|
|
52
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
53
|
+
sources[_i - 1] = arguments[_i];
|
|
54
|
+
}
|
|
55
|
+
if (!sources.length)
|
|
56
|
+
return target;
|
|
57
|
+
var source = sources.shift();
|
|
58
|
+
if (isObject(target) && isObject(source)) {
|
|
59
|
+
for (var key in source) {
|
|
60
|
+
if (isObject(source[key])) {
|
|
61
|
+
if (!target[key])
|
|
62
|
+
Object.assign(target, (_a = {}, _a[key] = {}, _a));
|
|
63
|
+
mergeDeepRecursive(target[key], source[key]);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return mergeDeepRecursive.apply(void 0, __spreadArray([target], __read(sources), false));
|
|
71
|
+
};
|
|
72
|
+
exports.default = mergeDeep;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Dispatch widget:data-loaded event when all components
|
|
5
|
+
* is considered to be finished loading their initial data
|
|
6
|
+
*/
|
|
7
|
+
var watchForLoadingComplete = function (container, widgetDOMElement) {
|
|
8
|
+
var isLoading = function () { return widgetDOMElement.querySelectorAll('[data-loading=true]').length > 0; };
|
|
9
|
+
var complete = function () {
|
|
10
|
+
var dispatched = false;
|
|
11
|
+
return function () {
|
|
12
|
+
if (dispatched) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
var widget = container.get('$widget');
|
|
16
|
+
widget.events.dispatch('widget:data-loaded', {
|
|
17
|
+
element: widgetDOMElement,
|
|
18
|
+
});
|
|
19
|
+
dispatched = true;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
var handleComplete = complete();
|
|
23
|
+
if (!isLoading()) {
|
|
24
|
+
return handleComplete();
|
|
25
|
+
}
|
|
26
|
+
var observer = new MutationObserver(function (mutations, observer) {
|
|
27
|
+
var check = mutations.find(function (mutation) {
|
|
28
|
+
return mutation.type === 'attributes' && mutation.attributeName === 'data-loading';
|
|
29
|
+
});
|
|
30
|
+
if (check && !isLoading()) {
|
|
31
|
+
observer.disconnect();
|
|
32
|
+
handleComplete();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
observer.observe(widgetDOMElement, {
|
|
36
|
+
attributes: true,
|
|
37
|
+
childList: true,
|
|
38
|
+
subtree: true,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Wait for all visible components to render
|
|
43
|
+
*/
|
|
44
|
+
var notifyDataLoaded = function (viewOutletContainer, widgetDOMElement) {
|
|
45
|
+
var widget = viewOutletContainer.get('$widget');
|
|
46
|
+
widget.container.getAsync('components').then(function (components) {
|
|
47
|
+
components.events.subscribeOnce('components:component-model-initialized', function () {
|
|
48
|
+
// Store the names of all visible components we should wait for
|
|
49
|
+
var waitingFor = components.nodes.visible.reduce(function (acc, node) {
|
|
50
|
+
if (!node.name ||
|
|
51
|
+
!node.type ||
|
|
52
|
+
node.type === 'view' ||
|
|
53
|
+
node.type === 'root' ||
|
|
54
|
+
node.attributes.layout.size === 'none') {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
acc.push(node.name);
|
|
58
|
+
return acc;
|
|
59
|
+
}, []);
|
|
60
|
+
var complete = false;
|
|
61
|
+
var observer = new MutationObserver(function (mutations, observer) {
|
|
62
|
+
mutations.forEach(function (mutation) {
|
|
63
|
+
if (mutation.addedNodes) {
|
|
64
|
+
var componentElements_1 = Array.from(mutation.addedNodes).reduce(function (acc, element) {
|
|
65
|
+
var dataName = element.getAttribute && element.getAttribute('data-name');
|
|
66
|
+
if (dataName && waitingFor.indexOf(dataName) > -1) {
|
|
67
|
+
acc.push(dataName);
|
|
68
|
+
}
|
|
69
|
+
return acc;
|
|
70
|
+
}, []);
|
|
71
|
+
// Remove added elements from the list of elements we are waiting for
|
|
72
|
+
waitingFor = waitingFor.filter(function (name) {
|
|
73
|
+
return componentElements_1.indexOf(name) === -1;
|
|
74
|
+
});
|
|
75
|
+
// When the list is empty, we are finished waiting for components to render
|
|
76
|
+
if (!complete && waitingFor.length === 0) {
|
|
77
|
+
complete = true;
|
|
78
|
+
// Creates a new observer that observes data-loading changes
|
|
79
|
+
watchForLoadingComplete(viewOutletContainer, widgetDOMElement);
|
|
80
|
+
observer.disconnect();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
observer.observe(widgetDOMElement, {
|
|
86
|
+
attributes: false,
|
|
87
|
+
characterData: false,
|
|
88
|
+
childList: true,
|
|
89
|
+
subtree: true,
|
|
90
|
+
attributeOldValue: false,
|
|
91
|
+
characterDataOldValue: false,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
exports.default = notifyDataLoaded;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var removeNullAndUndefinedValues = function (object) {
|
|
4
|
+
if (object === void 0) { object = {}; }
|
|
5
|
+
Object.keys(object).forEach(function (key) {
|
|
6
|
+
if (object[key] === null || typeof object[key] === 'undefined') {
|
|
7
|
+
delete object[key];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return object;
|
|
11
|
+
};
|
|
12
|
+
exports.default = removeNullAndUndefinedValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function setCookie(cookieName: string, value: any, days: number): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function setCookie(cookieName, value, days) {
|
|
4
|
+
var expires = '';
|
|
5
|
+
if (days) {
|
|
6
|
+
var date = new Date();
|
|
7
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
8
|
+
expires = "; expires=".concat(date.toUTCString());
|
|
9
|
+
}
|
|
10
|
+
document.cookie = "".concat(cookieName, "=").concat(value).concat(expires, "; path=/");
|
|
11
|
+
}
|
|
12
|
+
exports.default = setCookie;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (function (a, b) {
|
|
4
|
+
var equal = true;
|
|
5
|
+
if (Object.keys(a).length !== Object.keys(b).length) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var missingKey = Object.keys(a).some(function (key) {
|
|
9
|
+
var found = Object.keys(b).some(function (bKey) {
|
|
10
|
+
return key === bKey;
|
|
11
|
+
});
|
|
12
|
+
return !found;
|
|
13
|
+
});
|
|
14
|
+
if (missingKey) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
Object.keys(a).forEach(function (key) {
|
|
18
|
+
if (equal) {
|
|
19
|
+
var c = typeof a[key] === 'undefined' ? '' : a[key];
|
|
20
|
+
var d = typeof b[key] === 'undefined' ? '' : b[key];
|
|
21
|
+
equal = c.toString() === d.toString();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return equal;
|
|
25
|
+
});
|
package/lib/uuid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function uuid(): string;
|
package/lib/uuid.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var s4 = function () {
|
|
4
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
5
|
+
.toString(16)
|
|
6
|
+
.substring(1);
|
|
7
|
+
};
|
|
8
|
+
function uuid() {
|
|
9
|
+
// tslint:disable-next-line prefer-template
|
|
10
|
+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
11
|
+
}
|
|
12
|
+
exports.default = uuid;
|
|
@@ -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 {};
|
package/lib/wait-for.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var WaitFor = /** @class */ (function () {
|
|
4
|
+
function WaitFor(options) {
|
|
5
|
+
var _this = this;
|
|
6
|
+
this.queue = [];
|
|
7
|
+
this.queueAttemptCalls = 0;
|
|
8
|
+
this.callCount = 5;
|
|
9
|
+
/**
|
|
10
|
+
* Add action to the queue
|
|
11
|
+
*/
|
|
12
|
+
this.add = function (action) {
|
|
13
|
+
_this.queue.push(action);
|
|
14
|
+
_this.queueAttempt = setInterval(_this.processQueue, 1000);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Go through queue and attempt to call each action
|
|
18
|
+
*/
|
|
19
|
+
this.processQueue = function () {
|
|
20
|
+
if (_this.queue.length > 0) {
|
|
21
|
+
var indexOfActionsEmitted_1 = [];
|
|
22
|
+
_this.queue.forEach(function (queuedAction, index) {
|
|
23
|
+
var evaluate = queuedAction();
|
|
24
|
+
if (typeof evaluate === 'function') {
|
|
25
|
+
evaluate();
|
|
26
|
+
indexOfActionsEmitted_1.push(index);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
// clean up queue
|
|
30
|
+
_this.queue = _this.queue.filter(function (_, index) {
|
|
31
|
+
if (indexOfActionsEmitted_1.indexOf(index) > -1) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
if (_this.queueAttempt) {
|
|
37
|
+
clearInterval(_this.queueAttempt);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (_this.queueAttemptCalls > _this.callCount) {
|
|
41
|
+
clearInterval(_this.queueAttempt);
|
|
42
|
+
_this.queueAttemptCalls = 0;
|
|
43
|
+
}
|
|
44
|
+
_this.queueAttemptCalls = _this.queueAttemptCalls + 1;
|
|
45
|
+
};
|
|
46
|
+
if (options && options.callCount) {
|
|
47
|
+
this.callCount = options.callCount;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return WaitFor;
|
|
51
|
+
}());
|
|
52
|
+
exports.default = WaitFor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare type ArgumentHandler = string | [boolean, string | string[]] | undefined;
|
|
2
|
+
export declare function uniqueClassArray(classNames: string[]): string[];
|
|
3
|
+
export declare function append(className1?: string, className2?: string): string;
|
|
4
|
+
export declare function handleFunctionArgument(expression: boolean, classes: string | string[]): string | undefined;
|
|
5
|
+
export default function appendClassNames(...args: ArgumentHandler[]): string;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { Logger } from '.';
|
|
27
|
+
export function uniqueClassArray(classNames) {
|
|
28
|
+
var classArray = [];
|
|
29
|
+
classNames.forEach(function (c) {
|
|
30
|
+
if (classArray.indexOf(c) === -1) {
|
|
31
|
+
classArray.push(c);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return classArray;
|
|
35
|
+
}
|
|
36
|
+
export function append(className1, className2) {
|
|
37
|
+
if (className1 === void 0) { className1 = ''; }
|
|
38
|
+
if (className2 === void 0) { className2 = ''; }
|
|
39
|
+
var classNames = className1.split(' ').concat(className2.split(' '));
|
|
40
|
+
return uniqueClassArray(classNames).join(' ').trim();
|
|
41
|
+
}
|
|
42
|
+
export function handleFunctionArgument(expression, classes) {
|
|
43
|
+
if (Boolean(expression)) {
|
|
44
|
+
if (typeof classes === 'string') {
|
|
45
|
+
return classes;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(classes)) {
|
|
48
|
+
var className_1 = '';
|
|
49
|
+
classes.forEach(function (c) { return (className_1 = append(className_1, c)); });
|
|
50
|
+
return className_1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export default function appendClassNames() {
|
|
55
|
+
var args = [];
|
|
56
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
57
|
+
args[_i] = arguments[_i];
|
|
58
|
+
}
|
|
59
|
+
var className = '';
|
|
60
|
+
if (args.length) {
|
|
61
|
+
args.forEach(function (argument) {
|
|
62
|
+
if (typeof argument === 'string') {
|
|
63
|
+
className = append(className, argument);
|
|
64
|
+
}
|
|
65
|
+
else if (Array.isArray(argument)) {
|
|
66
|
+
className = append(className, handleFunctionArgument.apply(void 0, __spreadArray([], __read(argument), false)));
|
|
67
|
+
}
|
|
68
|
+
else if (typeof argument !== 'undefined' && argument !== null) {
|
|
69
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
70
|
+
Logger.warn.apply(Logger, __spreadArray(['appendClassNames: arguments either have' +
|
|
71
|
+
'to be a string or [boolean, ...string[]]. Passed args:'], __read(args), false));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return className;
|
|
77
|
+
}
|
package/lib-esm/batch.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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 createBatch = function (delay, createFallback) {
|
|
18
|
+
var timeout;
|
|
19
|
+
var queue = [];
|
|
20
|
+
return function (fn) {
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
queue.push([fn, resolve, reject]);
|
|
24
|
+
timeout = setTimeout(function () {
|
|
25
|
+
var acc = createFallback();
|
|
26
|
+
queue.forEach(function (_a) {
|
|
27
|
+
var _b = __read(_a, 3), fn = _b[0], resolve = _b[1], reject = _b[2];
|
|
28
|
+
acc = fn(acc);
|
|
29
|
+
});
|
|
30
|
+
queue = [];
|
|
31
|
+
resolve(acc);
|
|
32
|
+
}, delay);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export default createBatch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function camilize(obj: any): any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default function camilize(obj) {
|
|
2
|
+
var camilizedObject = {};
|
|
3
|
+
if (typeof obj === 'number' || typeof obj === 'string') {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
for (var prop in obj) {
|
|
7
|
+
if (obj.hasOwnProperty(prop)) {
|
|
8
|
+
var p = obj[prop];
|
|
9
|
+
var camilizedProp = prop.substring(0, 1).toLowerCase() + prop.substring(1);
|
|
10
|
+
if (Object.prototype.toString.call(p) === '[object Array]') {
|
|
11
|
+
camilizedObject[camilizedProp] = [];
|
|
12
|
+
for (var i = 0, c = p.length; i < c; i++) {
|
|
13
|
+
// tslint:disable-line no-increment-decrement
|
|
14
|
+
camilizedObject[camilizedProp].push(camilize(p[i]));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (p !== null && typeof p === 'object') {
|
|
18
|
+
camilizedObject[camilizedProp] = camilize(p);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
camilizedObject[camilizedProp] = p;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return camilizedObject;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
2
|
+
declare type Item = {
|
|
3
|
+
id: string;
|
|
4
|
+
items?: Item[];
|
|
5
|
+
title: string;
|
|
6
|
+
symbol?: any;
|
|
7
|
+
};
|
|
8
|
+
declare type ChildParentStructure = {
|
|
9
|
+
[key: number]: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function categoryTrail(id: string, items: Item[], ids?: string[], structure?: ChildParentStructure): string[];
|
|
12
|
+
export declare const getCategoryTrailAsObjects: (trail: string[], categories: Item[]) => Map<string, Item>;
|
|
13
|
+
export declare const buildCategoryTrail: (routeName: string, categoryIds: string | string[], container: Container, dataType?: 'guide-categories' | 'contact-method-categories') => Promise<any[]>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import createParams from './create-params';
|
|
2
|
+
import { default as findCategoryById } from './find-category-by-id';
|
|
3
|
+
import formatUrl from './format-url';
|
|
4
|
+
function childParentStructure(items, structure, parent) {
|
|
5
|
+
if (structure === void 0) { structure = {}; }
|
|
6
|
+
items.forEach(function (item) {
|
|
7
|
+
if (parent) {
|
|
8
|
+
structure[+item.id] = parent;
|
|
9
|
+
}
|
|
10
|
+
if (item.items) {
|
|
11
|
+
childParentStructure(item.items, structure, item.id);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return structure;
|
|
15
|
+
}
|
|
16
|
+
export function categoryTrail(id, items, ids, structure) {
|
|
17
|
+
if (ids === void 0) { ids = [id]; }
|
|
18
|
+
if (structure === void 0) { structure = childParentStructure(items); }
|
|
19
|
+
var addAncestors = function (id) {
|
|
20
|
+
var parentId = structure[+id];
|
|
21
|
+
if (parentId) {
|
|
22
|
+
ids.unshift(parentId);
|
|
23
|
+
addAncestors(parentId);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var parentId = structure[+id];
|
|
27
|
+
if (parentId) {
|
|
28
|
+
ids.unshift(parentId);
|
|
29
|
+
addAncestors(parentId);
|
|
30
|
+
}
|
|
31
|
+
return ids;
|
|
32
|
+
}
|
|
33
|
+
export var getCategoryTrailAsObjects = function (trail, categories) {
|
|
34
|
+
if (typeof trail === 'undefined' || typeof categories === 'undefined') {
|
|
35
|
+
return new Map();
|
|
36
|
+
}
|
|
37
|
+
return new Map(trail.map(function (categoryId) {
|
|
38
|
+
var category = findCategoryById(categoryId, categories);
|
|
39
|
+
return [categoryId, category];
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
export var buildCategoryTrail = function (routeName, categoryIds, container, dataType) {
|
|
43
|
+
if (dataType === void 0) { dataType = 'guide-categories'; }
|
|
44
|
+
return container.getAsync('dataClient').then(function (dataClient) {
|
|
45
|
+
return dataClient
|
|
46
|
+
.fetch(dataType, { expandCategories: 'descendants' })
|
|
47
|
+
.then(function (_a) {
|
|
48
|
+
var categories = _a.categories;
|
|
49
|
+
var buildTrail = function (id) {
|
|
50
|
+
var trail = categoryTrail(id, categories);
|
|
51
|
+
var objectTrail = getCategoryTrailAsObjects(trail, categories);
|
|
52
|
+
var result = [];
|
|
53
|
+
trail.forEach(function (categoryId) {
|
|
54
|
+
var category = objectTrail.get(categoryId);
|
|
55
|
+
if (category) {
|
|
56
|
+
result.push({
|
|
57
|
+
routeName: routeName,
|
|
58
|
+
title: category.title,
|
|
59
|
+
symbol: category.symbol,
|
|
60
|
+
id: category.id,
|
|
61
|
+
routeParams: dataType === 'contact-method-categories'
|
|
62
|
+
? createParams({
|
|
63
|
+
contactCategory: category.id,
|
|
64
|
+
uriName: formatUrl(category.title),
|
|
65
|
+
})
|
|
66
|
+
: createParams({
|
|
67
|
+
guideCategory: category.id,
|
|
68
|
+
uriName: formatUrl(category.title),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
if (Array.isArray(categoryIds)) {
|
|
76
|
+
return categoryIds.reduce(function (acc, id) {
|
|
77
|
+
var result = buildTrail(id);
|
|
78
|
+
if (result.length > 0) {
|
|
79
|
+
acc.push(result);
|
|
80
|
+
}
|
|
81
|
+
return acc;
|
|
82
|
+
}, []);
|
|
83
|
+
}
|
|
84
|
+
return buildTrail(categoryIds);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare type Input = {
|
|
2
|
+
phrase?: string;
|
|
3
|
+
category?: ParamValue;
|
|
4
|
+
guideCategory?: ParamValue;
|
|
5
|
+
contactCategory?: ParamValue;
|
|
6
|
+
take?: number;
|
|
7
|
+
connectionKey?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
uriName?: string;
|
|
10
|
+
sorting?: string;
|
|
11
|
+
tag?: string;
|
|
12
|
+
tagId?: string | number;
|
|
13
|
+
tagTitle?: string;
|
|
14
|
+
} & {
|
|
15
|
+
[key: string]: ParamValue;
|
|
16
|
+
};
|
|
17
|
+
export declare type ParamValue = string | number | any;
|
|
18
|
+
export declare type Params = {
|
|
19
|
+
[key: string]: ParamValue;
|
|
20
|
+
};
|
|
21
|
+
export default function createParams(args?: Input): Params;
|