kui-utils 0.0.24 → 0.0.25
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/cjs/index.js +111 -0
- package/cjs/index.js.map +1 -1
- package/index.d.ts +9 -1
- package/index.js +107 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var React = require('react');
|
|
|
6
6
|
var _ = require('lodash');
|
|
7
7
|
var reactRouterDom = require('react-router-dom');
|
|
8
8
|
var mobx = require('mobx');
|
|
9
|
+
var luxon = require('luxon');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
12
|
|
|
@@ -2044,6 +2045,110 @@ var updateQueryParams = function (newLink) {
|
|
|
2044
2045
|
window.history.pushState({ route: route }, "", route);
|
|
2045
2046
|
};
|
|
2046
2047
|
|
|
2048
|
+
function cleanObjectForIndexDB(value) {
|
|
2049
|
+
if (typeof value === "undefined")
|
|
2050
|
+
return null;
|
|
2051
|
+
if (value instanceof File)
|
|
2052
|
+
return value;
|
|
2053
|
+
if (value instanceof luxon.DateTime)
|
|
2054
|
+
return value.toISO();
|
|
2055
|
+
if (mobx.isObservable(value)) {
|
|
2056
|
+
return cleanObjectForIndexDB(mobx.toJS(value));
|
|
2057
|
+
}
|
|
2058
|
+
if (Array.isArray(value)) {
|
|
2059
|
+
return value.map(function (item) { return cleanObjectForIndexDB(item); });
|
|
2060
|
+
}
|
|
2061
|
+
if (value !== null && typeof value === "object") {
|
|
2062
|
+
var plainObject = {};
|
|
2063
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
2064
|
+
for (var key in value) {
|
|
2065
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
2066
|
+
if (value.hasOwnProperty(key)) {
|
|
2067
|
+
var objectValue = value[key];
|
|
2068
|
+
if (typeof objectValue !== "function" && objectValue !== undefined) {
|
|
2069
|
+
plainObject[key] = cleanObjectForIndexDB(objectValue);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
return plainObject;
|
|
2074
|
+
}
|
|
2075
|
+
return value;
|
|
2076
|
+
}
|
|
2077
|
+
var transactionQueue = Promise.resolve();
|
|
2078
|
+
function addToIndexDBWithQueue(db, storeName, data, loader) {
|
|
2079
|
+
transactionQueue = transactionQueue
|
|
2080
|
+
.then(function () {
|
|
2081
|
+
return new Promise(function (resolve, reject) {
|
|
2082
|
+
if (db && db.objectStoreNames.contains(storeName) && data) {
|
|
2083
|
+
var transaction = db.transaction(storeName, "readwrite");
|
|
2084
|
+
var store = transaction.objectStore(storeName);
|
|
2085
|
+
// eslint-disable-next-line no-param-reassign
|
|
2086
|
+
data.id = 1;
|
|
2087
|
+
var formattedData = cleanObjectForIndexDB(data);
|
|
2088
|
+
var request_1 = store.put(formattedData);
|
|
2089
|
+
request_1.onsuccess = function () {
|
|
2090
|
+
resolve(request_1);
|
|
2091
|
+
};
|
|
2092
|
+
request_1.onerror = function () {
|
|
2093
|
+
loader.setError("Не удалось сохранить данные в локальное хранилище");
|
|
2094
|
+
reject();
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
});
|
|
2098
|
+
})
|
|
2099
|
+
.catch(function (error) {
|
|
2100
|
+
console.error("Ошибка в очереди транзакций:", error);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
var readFromIndexDB = function (db, name, loader) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2104
|
+
var transaction, request_2;
|
|
2105
|
+
return __generator(this, function (_a) {
|
|
2106
|
+
if (db.objectStoreNames.contains(name)) {
|
|
2107
|
+
transaction = db.transaction(name, "readonly").objectStore(name);
|
|
2108
|
+
request_2 = transaction.getAll();
|
|
2109
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
2110
|
+
request_2.onerror = function () {
|
|
2111
|
+
reject();
|
|
2112
|
+
loader.setError("Не удалось сохранить данные в локальное хранилище");
|
|
2113
|
+
};
|
|
2114
|
+
request_2.onsuccess = function () {
|
|
2115
|
+
var _a;
|
|
2116
|
+
resolve((_a = request_2.result) === null || _a === void 0 ? void 0 : _a[0]);
|
|
2117
|
+
};
|
|
2118
|
+
})];
|
|
2119
|
+
}
|
|
2120
|
+
return [2 /*return*/, null];
|
|
2121
|
+
});
|
|
2122
|
+
}); };
|
|
2123
|
+
var initIndexDB = function (dbName, onupgradeneeded, loader, setIndexDB) {
|
|
2124
|
+
var dbRequest = indexedDB.open(dbName, 1);
|
|
2125
|
+
dbRequest.onerror = function () {
|
|
2126
|
+
loader.setError("Ошибка при открытии хранилища на устройстве. Данные не будут сохраняться локально");
|
|
2127
|
+
};
|
|
2128
|
+
dbRequest.onsuccess = function () {
|
|
2129
|
+
var db = dbRequest.result;
|
|
2130
|
+
setIndexDB(db);
|
|
2131
|
+
};
|
|
2132
|
+
dbRequest.onupgradeneeded = function () { return onupgradeneeded(dbRequest.result); };
|
|
2133
|
+
};
|
|
2134
|
+
var addIndexDBStore = function (db, name) {
|
|
2135
|
+
if (db && !db.objectStoreNames.contains(name)) {
|
|
2136
|
+
db.createObjectStore(name, { keyPath: "id" });
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
var clearIndexStore = function (db, name) {
|
|
2140
|
+
if (db) {
|
|
2141
|
+
var transaction = db.transaction(name, "readwrite");
|
|
2142
|
+
var objectStore = transaction.objectStore(name);
|
|
2143
|
+
objectStore.clear();
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
var clearIndexStores = function (db, stores) {
|
|
2147
|
+
Array.from(stores).forEach(function (name) {
|
|
2148
|
+
clearIndexStore(db, name);
|
|
2149
|
+
});
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2047
2152
|
function setCookie(name, value, options) {
|
|
2048
2153
|
if (options === void 0) { options = {}; }
|
|
2049
2154
|
var cookieOptions = __assign({ path: "/" }, options);
|
|
@@ -2368,14 +2473,18 @@ exports.MultistepForm = MultistepForm;
|
|
|
2368
2473
|
exports.Paginator = Paginator;
|
|
2369
2474
|
exports.SortingFilter = SortingFilter;
|
|
2370
2475
|
exports.accountRegExp = accountRegExp;
|
|
2476
|
+
exports.addIndexDBStore = addIndexDBStore;
|
|
2371
2477
|
exports.addLeadZero = addLeadZero;
|
|
2372
2478
|
exports.addToArrayByCondition = addToArrayByCondition;
|
|
2479
|
+
exports.addToIndexDBWithQueue = addToIndexDBWithQueue;
|
|
2373
2480
|
exports.applyMask = applyMask;
|
|
2374
2481
|
exports.bicRegExp = bicRegExp;
|
|
2375
2482
|
exports.callPromises = callPromises;
|
|
2376
2483
|
exports.carNumberRegExp = carNumberRegExp;
|
|
2377
2484
|
exports.checkIsIOS = checkIsIOS;
|
|
2378
2485
|
exports.cleanEmptyFields = cleanEmptyFields;
|
|
2486
|
+
exports.clearIndexStore = clearIndexStore;
|
|
2487
|
+
exports.clearIndexStores = clearIndexStores;
|
|
2379
2488
|
exports.clearNotValidFields = clearNotValidFields;
|
|
2380
2489
|
exports.copyInfo = copyInfo;
|
|
2381
2490
|
exports.corrAccountRegExp = corrAccountRegExp;
|
|
@@ -2394,12 +2503,14 @@ exports.getFileNameFromUrl = getFileNameFromUrl;
|
|
|
2394
2503
|
exports.getNestedData = getNestedData;
|
|
2395
2504
|
exports.getPhoneNumberFromPhoneParams = getPhoneNumberFromPhoneParams;
|
|
2396
2505
|
exports.getPhoneParamsFromString = getPhoneParamsFromString;
|
|
2506
|
+
exports.initIndexDB = initIndexDB;
|
|
2397
2507
|
exports.innRegExp = innRegExp;
|
|
2398
2508
|
exports.isValidWithMaskExp = isValidWithMaskExp;
|
|
2399
2509
|
exports.mediumPasswordRegExp = mediumPasswordRegExp;
|
|
2400
2510
|
exports.monthYearRegExp = monthYearRegExp;
|
|
2401
2511
|
exports.phoneRegExp = phoneRegExp;
|
|
2402
2512
|
exports.promisesWithCallback = promisesWithCallback;
|
|
2513
|
+
exports.readFromIndexDB = readFromIndexDB;
|
|
2403
2514
|
exports.resHandler = resHandler;
|
|
2404
2515
|
exports.setCookie = setCookie;
|
|
2405
2516
|
exports.simplePasswordRegExp = simplePasswordRegExp;
|