util-helpers 4.20.1 → 4.20.3
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/dist/util-helpers.js +42 -38
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/ajax.js +4 -2
- package/esm/calculateCursorPosition.js +2 -2
- package/esm/compressImage.js +2 -2
- package/esm/download.js +3 -2
- package/esm/filterTree.js +3 -3
- package/esm/findTreeNode.js +3 -3
- package/esm/findTreeNodes.js +3 -3
- package/esm/findTreeSelect.js +3 -3
- package/esm/getImageInfo.js +2 -2
- package/esm/index.js +1 -1
- package/esm/listToTree.js +2 -2
- package/esm/loadImage.js +4 -3
- package/esm/loadImageWithBlob.js +9 -7
- package/esm/loadScript.js +2 -1
- package/esm/transformFieldNames.js +5 -4
- package/esm/treeToList.js +3 -3
- package/esm/utils/native.js +5 -0
- package/lib/VERSION.js +1 -1
- package/lib/ajax.js +4 -2
- package/lib/calculateCursorPosition.js +1 -1
- package/lib/compressImage.js +2 -2
- package/lib/download.js +3 -2
- package/lib/filterTree.js +2 -2
- package/lib/findTreeNode.js +2 -2
- package/lib/findTreeNodes.js +2 -2
- package/lib/findTreeSelect.js +2 -2
- package/lib/getImageInfo.js +2 -2
- package/lib/index.js +1 -1
- package/lib/listToTree.js +1 -1
- package/lib/loadImage.js +4 -3
- package/lib/loadImageWithBlob.js +9 -7
- package/lib/loadScript.js +2 -1
- package/lib/transformFieldNames.js +4 -3
- package/lib/treeToList.js +2 -2
- package/lib/utils/native.js +5 -0
- package/package.json +2 -2
- package/types/compressImage.d.ts +3 -1
- package/types/getImageInfo.d.ts +3 -1
- package/types/loadImageWithBlob.d.ts +3 -1
- package/types/utils/native.d.ts +6 -0
package/esm/VERSION.js
CHANGED
package/esm/ajax.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { objectKeys } from './utils/native.js';
|
|
2
|
+
|
|
1
3
|
function ajax(url, options) {
|
|
2
4
|
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
3
5
|
return new Promise(function (resolve, reject) {
|
|
@@ -14,7 +16,7 @@ function ajax(url, options) {
|
|
|
14
16
|
xhr.responseType = responseType;
|
|
15
17
|
}
|
|
16
18
|
if (typeof headers === 'object') {
|
|
17
|
-
|
|
19
|
+
objectKeys(headers).map(function (item) {
|
|
18
20
|
xhr.setRequestHeader(item, headers[item]);
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -39,7 +41,7 @@ function ajax(url, options) {
|
|
|
39
41
|
load: wrapSuccess(onLoad),
|
|
40
42
|
loadend: onLoadEnd
|
|
41
43
|
};
|
|
42
|
-
var eventKeys =
|
|
44
|
+
var eventKeys = objectKeys(events);
|
|
43
45
|
eventKeys.map(function (item) {
|
|
44
46
|
var func = events[item];
|
|
45
47
|
if (func) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { toString } from 'ut2';
|
|
1
|
+
import { toString, isArray } from 'ut2';
|
|
2
2
|
|
|
3
3
|
function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, options) {
|
|
4
4
|
if (options === void 0) { options = {}; }
|
|
5
5
|
var _a = options.placeholderChar, placeholderChar = _a === void 0 ? ' ' : _a, _b = options.maskReg, maskReg = _b === void 0 ? /\D/g : _b, type = options.type;
|
|
6
6
|
var realCtrlValue = toString(prevCtrlValue);
|
|
7
7
|
var realRawValue = toString(rawValue);
|
|
8
|
-
var placeholderChars =
|
|
8
|
+
var placeholderChars = isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
9
9
|
var editLength = realRawValue.length - realCtrlValue.length;
|
|
10
10
|
var isAddition = editLength > 0;
|
|
11
11
|
var pos = prevPos;
|
package/esm/compressImage.js
CHANGED
|
@@ -11,8 +11,8 @@ function canvasToBlob(canvas, type, quality) {
|
|
|
11
11
|
function compressImage(img, options) {
|
|
12
12
|
if (options === void 0) { options = {}; }
|
|
13
13
|
return new Promise(function (resolve, reject) {
|
|
14
|
-
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw;
|
|
15
|
-
loadImageWithBlob(img, cacheImage)
|
|
14
|
+
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
|
|
15
|
+
loadImageWithBlob(img, cacheImage, ajaxOptions)
|
|
16
16
|
.then(function (_a) {
|
|
17
17
|
var image = _a.image, blob = _a.blob;
|
|
18
18
|
var numWidth = toNumber(width);
|
package/esm/download.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isBlob, isPromiseLike } from 'ut2';
|
|
|
3
3
|
import dataURLToBlob from './dataURLToBlob.js';
|
|
4
4
|
import isUrl from './isUrl.js';
|
|
5
5
|
import ajax from './ajax.js';
|
|
6
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
6
7
|
|
|
7
8
|
function saver(blobUrl, fileName) {
|
|
8
9
|
if (fileName === void 0) { fileName = ''; }
|
|
@@ -76,9 +77,9 @@ function download(data, options) {
|
|
|
76
77
|
navigator.msSaveBlob(payload, fileName || 'download');
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
|
-
url =
|
|
80
|
+
url = createObjectURL(payload);
|
|
80
81
|
saver(url, fileName);
|
|
81
|
-
|
|
82
|
+
revokeObjectURL(url);
|
|
82
83
|
}
|
|
83
84
|
return [2, Promise.resolve()];
|
|
84
85
|
}
|
package/esm/filterTree.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
5
5
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
6
6
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
7
7
|
var result = [];
|
|
8
|
-
if (!
|
|
8
|
+
if (!isArray(tree)) {
|
|
9
9
|
return result;
|
|
10
10
|
}
|
|
11
11
|
tree.forEach(function (item) {
|
|
@@ -16,7 +16,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
16
16
|
if (predicate(newItem)) {
|
|
17
17
|
if (isObject(newItem)) {
|
|
18
18
|
var childs = newItem[childrenField];
|
|
19
|
-
if (
|
|
19
|
+
if (isArray(childs) && childs.length > 0) {
|
|
20
20
|
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
21
21
|
}
|
|
22
22
|
}
|
package/esm/findTreeNode.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function findTreeNode(tree, predicate, childrenField) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
7
|
var stack = [];
|
|
8
8
|
var node;
|
|
9
|
-
if (!
|
|
9
|
+
if (!isArray(tree)) {
|
|
10
10
|
return node;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -21,7 +21,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
21
21
|
}
|
|
22
22
|
if (isObject(temp)) {
|
|
23
23
|
var childs = temp[childrenField];
|
|
24
|
-
if (
|
|
24
|
+
if (isArray(childs) && childs.length > 0) {
|
|
25
25
|
childs.forEach(function (c) {
|
|
26
26
|
stack.push(c);
|
|
27
27
|
});
|
package/esm/findTreeNodes.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function findTreeNodes(tree, predicate, childrenField) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
7
|
var stack = [];
|
|
8
8
|
var nodes = [];
|
|
9
|
-
if (!
|
|
9
|
+
if (!isArray(tree)) {
|
|
10
10
|
return nodes;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -20,7 +20,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
20
20
|
}
|
|
21
21
|
if (isObject(temp)) {
|
|
22
22
|
var childs = temp[childrenField];
|
|
23
|
-
if (
|
|
23
|
+
if (isArray(childs) && childs.length > 0) {
|
|
24
24
|
childs.forEach(function (c) {
|
|
25
25
|
stack.push(c);
|
|
26
26
|
});
|
package/esm/findTreeSelect.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __values } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
5
5
|
var e_1, _a;
|
|
6
6
|
if (path === void 0) { path = []; }
|
|
7
|
-
if (!
|
|
7
|
+
if (!isArray(tree)) {
|
|
8
8
|
return [];
|
|
9
9
|
}
|
|
10
10
|
try {
|
|
@@ -16,7 +16,7 @@ function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
|
16
16
|
}
|
|
17
17
|
if (isObject(item)) {
|
|
18
18
|
var childs = item[childrenField];
|
|
19
|
-
if (
|
|
19
|
+
if (isArray(childs) && childs.length > 0) {
|
|
20
20
|
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
21
21
|
if (findChildren.length > 0) {
|
|
22
22
|
return findChildren;
|
package/esm/getImageInfo.js
CHANGED
|
@@ -10,14 +10,14 @@ function calcContrast(w, h) {
|
|
|
10
10
|
}
|
|
11
11
|
var cacheImage;
|
|
12
12
|
var cacheResult;
|
|
13
|
-
function getImageInfo(img, useCache) {
|
|
13
|
+
function getImageInfo(img, useCache, ajaxOptions) {
|
|
14
14
|
if (useCache === void 0) { useCache = true; }
|
|
15
15
|
return new Promise(function (resolve, reject) {
|
|
16
16
|
if (useCache && cacheImage === img && cacheResult) {
|
|
17
17
|
resolve(cacheResult);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
loadImageWithBlob(img, false)
|
|
20
|
+
loadImageWithBlob(img, false, ajaxOptions)
|
|
21
21
|
.then(function (_a) {
|
|
22
22
|
var image = _a.image, blob = _a.blob;
|
|
23
23
|
var width = image.width, height = image.height;
|
package/esm/index.js
CHANGED
package/esm/listToTree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function processEmptyChildren(arr, options) {
|
|
5
5
|
var _a = options.childrenField, childrenField = _a === void 0 ? 'children' : _a, _b = options.emptyChildrenValue, emptyChildrenValue = _b === void 0 ? 'none' : _b;
|
|
@@ -22,7 +22,7 @@ function listToTree(list, options) {
|
|
|
22
22
|
var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
|
|
23
23
|
var tree = [];
|
|
24
24
|
var record = {};
|
|
25
|
-
if (!
|
|
25
|
+
if (!isArray(list)) {
|
|
26
26
|
return tree;
|
|
27
27
|
}
|
|
28
28
|
list.forEach(function (item) {
|
package/esm/loadImage.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBlob } from 'ut2';
|
|
2
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
2
3
|
|
|
3
4
|
var cacheImage;
|
|
4
5
|
var cacheResult;
|
|
@@ -10,14 +11,14 @@ function loadImage(img, useCache) {
|
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
12
13
|
var imgIsBlob_1 = isBlob(img);
|
|
13
|
-
var url_1 = imgIsBlob_1 ?
|
|
14
|
+
var url_1 = imgIsBlob_1 ? createObjectURL(img) : img;
|
|
14
15
|
var image_1 = new Image();
|
|
15
16
|
if (!imgIsBlob_1) {
|
|
16
17
|
image_1.crossOrigin = 'anonymous';
|
|
17
18
|
}
|
|
18
19
|
image_1.onload = function () {
|
|
19
20
|
if (imgIsBlob_1) {
|
|
20
|
-
|
|
21
|
+
revokeObjectURL(url_1);
|
|
21
22
|
}
|
|
22
23
|
if (useCache) {
|
|
23
24
|
cacheImage = img;
|
|
@@ -27,7 +28,7 @@ function loadImage(img, useCache) {
|
|
|
27
28
|
};
|
|
28
29
|
image_1.onerror = function (err) {
|
|
29
30
|
if (imgIsBlob_1) {
|
|
30
|
-
|
|
31
|
+
revokeObjectURL(url_1);
|
|
31
32
|
}
|
|
32
33
|
console.error("[loadImage] The image load failed, '".concat(img, "'."));
|
|
33
34
|
reject(err);
|
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { __assign } from 'tslib';
|
|
1
2
|
import { isBlob } from 'ut2';
|
|
2
3
|
import ajax from './ajax.js';
|
|
4
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
3
5
|
|
|
4
6
|
var SuccessResponseStatus = [200, 304];
|
|
5
|
-
function getBlob(img) {
|
|
7
|
+
function getBlob(img, ajaxOptions) {
|
|
6
8
|
return new Promise(function (resolve, reject) {
|
|
7
9
|
if (isBlob(img)) {
|
|
8
10
|
resolve(img);
|
|
9
11
|
}
|
|
10
12
|
else {
|
|
11
|
-
ajax(img, { responseType: 'blob' })
|
|
13
|
+
ajax(img, __assign({ responseType: 'blob', headers: { 'sec-fetch-site': 'none' } }, ajaxOptions))
|
|
12
14
|
.then(function (ev) {
|
|
13
15
|
var responseStatus = ev.target.status;
|
|
14
16
|
if (SuccessResponseStatus.indexOf(responseStatus) !== -1) {
|
|
@@ -24,19 +26,19 @@ function getBlob(img) {
|
|
|
24
26
|
}
|
|
25
27
|
var cacheImage;
|
|
26
28
|
var cacheResult;
|
|
27
|
-
function loadImageWithBlob(img, useCache) {
|
|
29
|
+
function loadImageWithBlob(img, useCache, ajaxOptions) {
|
|
28
30
|
if (useCache === void 0) { useCache = true; }
|
|
29
31
|
return new Promise(function (resolve, reject) {
|
|
30
32
|
if (useCache && cacheImage === img && cacheResult) {
|
|
31
33
|
resolve(cacheResult);
|
|
32
34
|
}
|
|
33
35
|
else {
|
|
34
|
-
getBlob(img)
|
|
36
|
+
getBlob(img, ajaxOptions)
|
|
35
37
|
.then(function (blob) {
|
|
36
|
-
var url =
|
|
38
|
+
var url = createObjectURL(blob);
|
|
37
39
|
var image = new Image();
|
|
38
40
|
image.onload = function () {
|
|
39
|
-
|
|
41
|
+
revokeObjectURL(url);
|
|
40
42
|
var result = { blob: blob, image: image };
|
|
41
43
|
if (useCache) {
|
|
42
44
|
cacheImage = img;
|
|
@@ -45,7 +47,7 @@ function loadImageWithBlob(img, useCache) {
|
|
|
45
47
|
resolve(result);
|
|
46
48
|
};
|
|
47
49
|
image.onerror = function (err) {
|
|
48
|
-
|
|
50
|
+
revokeObjectURL(url);
|
|
49
51
|
console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
|
|
50
52
|
reject(err);
|
|
51
53
|
};
|
package/esm/loadScript.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __rest, __assign } from 'tslib';
|
|
2
|
+
import { objectKeys } from './utils/native.js';
|
|
2
3
|
|
|
3
4
|
function loadScript(src, options) {
|
|
4
5
|
return new Promise(function (resolve, reject) {
|
|
@@ -13,7 +14,7 @@ function loadScript(src, options) {
|
|
|
13
14
|
script[key] = props[key];
|
|
14
15
|
}
|
|
15
16
|
if (typeof attrs === 'object') {
|
|
16
|
-
|
|
17
|
+
objectKeys(attrs).forEach(function (key) {
|
|
17
18
|
script.setAttribute(key, attrs[key]);
|
|
18
19
|
});
|
|
19
20
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
|
+
import { objectKeys } from './utils/native.js';
|
|
3
4
|
|
|
4
5
|
function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
5
6
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
6
|
-
if (!
|
|
7
|
+
if (!isArray(data)) {
|
|
7
8
|
return data;
|
|
8
9
|
}
|
|
9
10
|
if (data.length <= 0) {
|
|
@@ -16,10 +17,10 @@ function transformFieldNames(data, fieldNames, childrenField, nodeAssign) {
|
|
|
16
17
|
}
|
|
17
18
|
var newItem = nodeAssign === 'spread' ? __assign({}, item) : item;
|
|
18
19
|
var delKeys = [];
|
|
19
|
-
if (childrenField &&
|
|
20
|
+
if (childrenField && isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
20
21
|
newItem[childrenField] = recusion(newItem[childrenField].slice());
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
objectKeys(fieldNames).forEach(function (newKey) {
|
|
23
24
|
var oldKey = fieldNames[newKey];
|
|
24
25
|
if (oldKey in newItem) {
|
|
25
26
|
newItem[newKey] = newItem[oldKey];
|
package/esm/treeToList.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
|
-
import { isObject } from 'ut2';
|
|
2
|
+
import { isArray, isObject } from 'ut2';
|
|
3
3
|
|
|
4
4
|
function treeToList(tree, childrenField) {
|
|
5
5
|
var list = [];
|
|
6
|
-
if (!
|
|
6
|
+
if (!isArray(tree)) {
|
|
7
7
|
return list;
|
|
8
8
|
}
|
|
9
9
|
function recusion(arr) {
|
|
@@ -12,7 +12,7 @@ function treeToList(tree, childrenField) {
|
|
|
12
12
|
var newItem = __assign({}, item);
|
|
13
13
|
list.push(newItem);
|
|
14
14
|
if (newItem[childrenField]) {
|
|
15
|
-
if (
|
|
15
|
+
if (isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
16
16
|
recusion(newItem[childrenField]);
|
|
17
17
|
}
|
|
18
18
|
delete newItem[childrenField];
|
package/lib/VERSION.js
CHANGED
package/lib/ajax.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var native = require('./utils/native.js');
|
|
4
|
+
|
|
3
5
|
function ajax(url, options) {
|
|
4
6
|
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
5
7
|
return new Promise(function (resolve, reject) {
|
|
@@ -16,7 +18,7 @@ function ajax(url, options) {
|
|
|
16
18
|
xhr.responseType = responseType;
|
|
17
19
|
}
|
|
18
20
|
if (typeof headers === 'object') {
|
|
19
|
-
|
|
21
|
+
native.objectKeys(headers).map(function (item) {
|
|
20
22
|
xhr.setRequestHeader(item, headers[item]);
|
|
21
23
|
});
|
|
22
24
|
}
|
|
@@ -41,7 +43,7 @@ function ajax(url, options) {
|
|
|
41
43
|
load: wrapSuccess(onLoad),
|
|
42
44
|
loadend: onLoadEnd
|
|
43
45
|
};
|
|
44
|
-
var eventKeys =
|
|
46
|
+
var eventKeys = native.objectKeys(events);
|
|
45
47
|
eventKeys.map(function (item) {
|
|
46
48
|
var func = events[item];
|
|
47
49
|
if (func) {
|
|
@@ -7,7 +7,7 @@ function calculateCursorPosition(prevPos, prevCtrlValue, rawValue, ctrlValue, op
|
|
|
7
7
|
var _a = options.placeholderChar, placeholderChar = _a === void 0 ? ' ' : _a, _b = options.maskReg, maskReg = _b === void 0 ? /\D/g : _b, type = options.type;
|
|
8
8
|
var realCtrlValue = ut2.toString(prevCtrlValue);
|
|
9
9
|
var realRawValue = ut2.toString(rawValue);
|
|
10
|
-
var placeholderChars =
|
|
10
|
+
var placeholderChars = ut2.isArray(placeholderChar) ? placeholderChar : [placeholderChar];
|
|
11
11
|
var editLength = realRawValue.length - realCtrlValue.length;
|
|
12
12
|
var isAddition = editLength > 0;
|
|
13
13
|
var pos = prevPos;
|
package/lib/compressImage.js
CHANGED
|
@@ -13,8 +13,8 @@ function canvasToBlob(canvas, type, quality) {
|
|
|
13
13
|
function compressImage(img, options) {
|
|
14
14
|
if (options === void 0) { options = {}; }
|
|
15
15
|
return new Promise(function (resolve, reject) {
|
|
16
|
-
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw;
|
|
17
|
-
loadImageWithBlob(img, cacheImage)
|
|
16
|
+
var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
|
|
17
|
+
loadImageWithBlob(img, cacheImage, ajaxOptions)
|
|
18
18
|
.then(function (_a) {
|
|
19
19
|
var image = _a.image, blob = _a.blob;
|
|
20
20
|
var numWidth = ut2.toNumber(width);
|
package/lib/download.js
CHANGED
|
@@ -5,6 +5,7 @@ var ut2 = require('ut2');
|
|
|
5
5
|
var dataURLToBlob = require('./dataURLToBlob.js');
|
|
6
6
|
var isUrl = require('./isUrl.js');
|
|
7
7
|
var ajax = require('./ajax.js');
|
|
8
|
+
var native = require('./utils/native.js');
|
|
8
9
|
|
|
9
10
|
function saver(blobUrl, fileName) {
|
|
10
11
|
if (fileName === void 0) { fileName = ''; }
|
|
@@ -78,9 +79,9 @@ function download(data, options) {
|
|
|
78
79
|
navigator.msSaveBlob(payload, fileName || 'download');
|
|
79
80
|
}
|
|
80
81
|
else {
|
|
81
|
-
url =
|
|
82
|
+
url = native.createObjectURL(payload);
|
|
82
83
|
saver(url, fileName);
|
|
83
|
-
|
|
84
|
+
native.revokeObjectURL(url);
|
|
84
85
|
}
|
|
85
86
|
return [2, Promise.resolve()];
|
|
86
87
|
}
|
package/lib/filterTree.js
CHANGED
|
@@ -7,7 +7,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
7
7
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
8
8
|
if (nodeAssign === void 0) { nodeAssign = 'spread'; }
|
|
9
9
|
var result = [];
|
|
10
|
-
if (!
|
|
10
|
+
if (!ut2.isArray(tree)) {
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
13
|
tree.forEach(function (item) {
|
|
@@ -18,7 +18,7 @@ function filterTree(tree, predicate, childrenField, nodeAssign) {
|
|
|
18
18
|
if (predicate(newItem)) {
|
|
19
19
|
if (ut2.isObject(newItem)) {
|
|
20
20
|
var childs = newItem[childrenField];
|
|
21
|
-
if (
|
|
21
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
22
22
|
newItem[childrenField] = filterTree(childs, predicate, childrenField, nodeAssign);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/lib/findTreeNode.js
CHANGED
|
@@ -8,7 +8,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
8
8
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
9
9
|
var stack = [];
|
|
10
10
|
var node;
|
|
11
|
-
if (!
|
|
11
|
+
if (!ut2.isArray(tree)) {
|
|
12
12
|
return node;
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
@@ -23,7 +23,7 @@ function findTreeNode(tree, predicate, childrenField) {
|
|
|
23
23
|
}
|
|
24
24
|
if (ut2.isObject(temp)) {
|
|
25
25
|
var childs = temp[childrenField];
|
|
26
|
-
if (
|
|
26
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
27
27
|
childs.forEach(function (c) {
|
|
28
28
|
stack.push(c);
|
|
29
29
|
});
|
package/lib/findTreeNodes.js
CHANGED
|
@@ -8,7 +8,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
8
8
|
if (childrenField === void 0) { childrenField = 'children'; }
|
|
9
9
|
var stack = [];
|
|
10
10
|
var nodes = [];
|
|
11
|
-
if (!
|
|
11
|
+
if (!ut2.isArray(tree)) {
|
|
12
12
|
return nodes;
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
@@ -22,7 +22,7 @@ function findTreeNodes(tree, predicate, childrenField) {
|
|
|
22
22
|
}
|
|
23
23
|
if (ut2.isObject(temp)) {
|
|
24
24
|
var childs = temp[childrenField];
|
|
25
|
-
if (
|
|
25
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
26
26
|
childs.forEach(function (c) {
|
|
27
27
|
stack.push(c);
|
|
28
28
|
});
|
package/lib/findTreeSelect.js
CHANGED
|
@@ -6,7 +6,7 @@ var ut2 = require('ut2');
|
|
|
6
6
|
function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
7
7
|
var e_1, _a;
|
|
8
8
|
if (path === void 0) { path = []; }
|
|
9
|
-
if (!
|
|
9
|
+
if (!ut2.isArray(tree)) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
@@ -18,7 +18,7 @@ function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
|
18
18
|
}
|
|
19
19
|
if (ut2.isObject(item)) {
|
|
20
20
|
var childs = item[childrenField];
|
|
21
|
-
if (
|
|
21
|
+
if (ut2.isArray(childs) && childs.length > 0) {
|
|
22
22
|
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
23
23
|
if (findChildren.length > 0) {
|
|
24
24
|
return findChildren;
|
package/lib/getImageInfo.js
CHANGED
|
@@ -12,14 +12,14 @@ function calcContrast(w, h) {
|
|
|
12
12
|
}
|
|
13
13
|
var cacheImage;
|
|
14
14
|
var cacheResult;
|
|
15
|
-
function getImageInfo(img, useCache) {
|
|
15
|
+
function getImageInfo(img, useCache, ajaxOptions) {
|
|
16
16
|
if (useCache === void 0) { useCache = true; }
|
|
17
17
|
return new Promise(function (resolve, reject) {
|
|
18
18
|
if (useCache && cacheImage === img && cacheResult) {
|
|
19
19
|
resolve(cacheResult);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
loadImageWithBlob(img, false)
|
|
22
|
+
loadImageWithBlob(img, false, ajaxOptions)
|
|
23
23
|
.then(function (_a) {
|
|
24
24
|
var image = _a.image, blob = _a.blob;
|
|
25
25
|
var width = image.width, height = image.height;
|
package/lib/index.js
CHANGED
|
@@ -65,7 +65,7 @@ var findTreeSelect = require('./findTreeSelect.js');
|
|
|
65
65
|
var config = require('./utils/config.js');
|
|
66
66
|
var VERSION = require('./VERSION.js');
|
|
67
67
|
|
|
68
|
-
exports.version = "4.20.
|
|
68
|
+
exports.version = "4.20.3";
|
|
69
69
|
|
|
70
70
|
exports.isMobile = isMobile;
|
|
71
71
|
exports.isTelephone = isTelephone;
|
package/lib/listToTree.js
CHANGED
|
@@ -24,7 +24,7 @@ function listToTree(list, options) {
|
|
|
24
24
|
var _a = options.keyField, keyField = _a === void 0 ? 'id' : _a, _b = options.parentField, parentField = _b === void 0 ? 'pid' : _b, _c = options.childrenField, childrenField = _c === void 0 ? 'children' : _c, _d = options.emptyChildrenValue, emptyChildrenValue = _d === void 0 ? 'none' : _d, _e = options.nodeAssign, nodeAssign = _e === void 0 ? 'spread' : _e;
|
|
25
25
|
var tree = [];
|
|
26
26
|
var record = {};
|
|
27
|
-
if (!
|
|
27
|
+
if (!ut2.isArray(list)) {
|
|
28
28
|
return tree;
|
|
29
29
|
}
|
|
30
30
|
list.forEach(function (item) {
|
package/lib/loadImage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
|
+
var native = require('./utils/native.js');
|
|
4
5
|
|
|
5
6
|
var cacheImage;
|
|
6
7
|
var cacheResult;
|
|
@@ -12,14 +13,14 @@ function loadImage(img, useCache) {
|
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
15
|
var imgIsBlob_1 = ut2.isBlob(img);
|
|
15
|
-
var url_1 = imgIsBlob_1 ?
|
|
16
|
+
var url_1 = imgIsBlob_1 ? native.createObjectURL(img) : img;
|
|
16
17
|
var image_1 = new Image();
|
|
17
18
|
if (!imgIsBlob_1) {
|
|
18
19
|
image_1.crossOrigin = 'anonymous';
|
|
19
20
|
}
|
|
20
21
|
image_1.onload = function () {
|
|
21
22
|
if (imgIsBlob_1) {
|
|
22
|
-
|
|
23
|
+
native.revokeObjectURL(url_1);
|
|
23
24
|
}
|
|
24
25
|
if (useCache) {
|
|
25
26
|
cacheImage = img;
|
|
@@ -29,7 +30,7 @@ function loadImage(img, useCache) {
|
|
|
29
30
|
};
|
|
30
31
|
image_1.onerror = function (err) {
|
|
31
32
|
if (imgIsBlob_1) {
|
|
32
|
-
|
|
33
|
+
native.revokeObjectURL(url_1);
|
|
33
34
|
}
|
|
34
35
|
console.error("[loadImage] The image load failed, '".concat(img, "'."));
|
|
35
36
|
reject(err);
|