@nextgis/geocoder 1.12.1 → 1.14.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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./lib/geocoder.cjs.prod.js');
5
- } else {
3
+ if (process.env.NODE_ENV === 'development') {
6
4
  module.exports = require('./lib/geocoder.cjs.js');
5
+ } else {
6
+ module.exports = require('./lib/geocoder.cjs.prod.js');
7
7
  }
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.12.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.14.0; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/geocoder; version: 1.12.1; author: NextGIS */
1
+ /** Bundle of @nextgis/geocoder; version: 1.14.0; author: NextGIS */
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -1370,31 +1370,31 @@ var Cache = Cache$1;
1370
1370
  /**
1371
1371
  * Thrown when...
1372
1372
  */
1373
- var NgwError = /** @class */ (function (_super) {
1374
- __extends(NgwError, _super);
1375
- function NgwError(er) {
1373
+ var NetworkError = /** @class */ (function (_super) {
1374
+ __extends(NetworkError, _super);
1375
+ function NetworkError(url) {
1376
1376
  var _this = _super.call(this) || this;
1377
- _this.name = 'NgwError';
1378
- Object.assign(_this, er);
1379
- Object.setPrototypeOf(_this, NgwError.prototype);
1377
+ _this.name = 'NetworkError';
1378
+ Object.setPrototypeOf(_this, NetworkError.prototype);
1379
+ _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
1380
1380
  return _this;
1381
1381
  }
1382
- return NgwError;
1382
+ return NetworkError;
1383
1383
  }(Error));
1384
1384
 
1385
1385
  /**
1386
1386
  * Thrown when...
1387
1387
  */
1388
- var NetworkError = /** @class */ (function (_super) {
1389
- __extends(NetworkError, _super);
1390
- function NetworkError(url) {
1388
+ var NgwError = /** @class */ (function (_super) {
1389
+ __extends(NgwError, _super);
1390
+ function NgwError(er) {
1391
1391
  var _this = _super.call(this) || this;
1392
- _this.name = 'NetworkError';
1393
- Object.setPrototypeOf(_this, NetworkError.prototype);
1394
- _this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
1392
+ _this.name = 'NgwError';
1393
+ Object.assign(_this, er);
1394
+ Object.setPrototypeOf(_this, NgwError.prototype);
1395
1395
  return _this;
1396
1396
  }
1397
- return NetworkError;
1397
+ return NgwError;
1398
1398
  }(Error));
1399
1399
 
1400
1400
  function isObject(val) {
@@ -1508,11 +1508,6 @@ var loadData;
1508
1508
  xhr.abort();
1509
1509
  });
1510
1510
  }
1511
- if (options.signal) {
1512
- options.signal.addEventListener('abort', function () {
1513
- xhr.abort();
1514
- });
1515
- }
1516
1511
  xhr.send(data);
1517
1512
  };
1518
1513
  }
@@ -1963,6 +1958,7 @@ var NgwConnector$1 = /** @class */ (function () {
1963
1958
  this.id = ID++;
1964
1959
  this.emitter = new events.exports.EventEmitter();
1965
1960
  this.routeStr = '/api/component/pyramid/route';
1961
+ this.activeRequests = [];
1966
1962
  var exist = findConnector(options);
1967
1963
  if (exist) {
1968
1964
  return exist;
@@ -2048,6 +2044,7 @@ var NgwConnector$1 = /** @class */ (function () {
2048
2044
  * Disconnecting a user. Aborting all current requests
2049
2045
  */
2050
2046
  NgwConnector.prototype.logout = function () {
2047
+ this.abort();
2051
2048
  removeConnector(this);
2052
2049
  this.options.auth = undefined;
2053
2050
  this.user = undefined;
@@ -2100,6 +2097,17 @@ var NgwConnector$1 = /** @class */ (function () {
2100
2097
  }
2101
2098
  }
2102
2099
  };
2100
+ /** Stop all api requests */
2101
+ NgwConnector.prototype.abort = function () {
2102
+ for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
2103
+ var req = _a[_i];
2104
+ req.cancel();
2105
+ }
2106
+ this.activeRequests = [];
2107
+ };
2108
+ NgwConnector.prototype.getActiveApiRequests = function () {
2109
+ return __spreadArray([], this.activeRequests, true);
2110
+ };
2103
2111
  /**
2104
2112
  * Send request to NGW api router.
2105
2113
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -2314,14 +2322,20 @@ var NgwConnector$1 = /** @class */ (function () {
2314
2322
  NgwConnector.prototype._loadData = function (url, options) {
2315
2323
  var _this = this;
2316
2324
  options.responseType = options.responseType || 'json';
2317
- return new CancelablePromise(function (resolve, reject, onCancel) {
2325
+ var request = new CancelablePromise(function (resolve, reject, onCancel) {
2318
2326
  if (_this.user) {
2319
2327
  options = options || {};
2320
2328
  // options.withCredentials = true;
2321
2329
  options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
2322
2330
  }
2323
2331
  loadData(url, resolve, options, reject, onCancel);
2324
- }).catch(function (httpError) {
2332
+ })
2333
+ .then(function (resp) {
2334
+ _this._cleanActiveRequests(request);
2335
+ return resp;
2336
+ })
2337
+ .catch(function (httpError) {
2338
+ _this._cleanActiveRequests(request);
2325
2339
  if (httpError instanceof CancelablePromise.CancelError) ;
2326
2340
  else {
2327
2341
  // @ts-ignore
@@ -2334,6 +2348,20 @@ var NgwConnector$1 = /** @class */ (function () {
2334
2348
  }
2335
2349
  }
2336
2350
  });
2351
+ if (options.signal &&
2352
+ typeof options.signal.addEventListener === 'function') {
2353
+ options.signal.addEventListener('abort', function () {
2354
+ request.cancel();
2355
+ });
2356
+ }
2357
+ this.activeRequests.push(request);
2358
+ return request;
2359
+ };
2360
+ NgwConnector.prototype._cleanActiveRequests = function (request) {
2361
+ var activeRequestIndex = this.activeRequests.indexOf(request);
2362
+ if (activeRequestIndex !== -1) {
2363
+ this.activeRequests.splice(activeRequestIndex, 1);
2364
+ }
2337
2365
  };
2338
2366
  NgwConnector.prototype._handleHttpError = function (er) {
2339
2367
  if (er) {