@cdek-it/widget 3.13.0 → 3.13.1

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.
@@ -6597,30 +6597,11 @@ const map = defineStore("map", () => {
6597
6597
  left: config.map.defaultCenter,
6598
6598
  right: config.map.defaultCenter
6599
6599
  });
6600
- const polygonBounds = computed(() => {
6601
- const minLng = Math.min(bounds.left[0], bounds.right[0]);
6602
- const maxLng = Math.max(bounds.left[0], bounds.right[0]);
6603
- const minLat = Math.min(bounds.left[1], bounds.right[1]);
6604
- const maxLat = Math.max(bounds.left[1], bounds.right[1]);
6605
- return {
6606
- latitude_right_top: maxLat,
6607
- longitude_right_top: maxLng,
6608
- latitude_left_bottom: minLat,
6609
- longitude_left_bottom: minLng
6610
- };
6611
- });
6612
- const filteredOffices = computed(() => {
6613
- if (bounds.left[0] === bounds.right[0] && bounds.left[1] === bounds.right[1]) {
6614
- return packageSuitedOffices.value;
6615
- }
6616
- const minLng = Math.min(bounds.left[0], bounds.right[0]);
6617
- const maxLng = Math.max(bounds.left[0], bounds.right[0]);
6618
- const minLat = Math.min(bounds.left[1], bounds.right[1]);
6619
- const maxLat = Math.max(bounds.left[1], bounds.right[1]);
6620
- return packageSuitedOffices.value.filter(
6621
- (office) => office.location[0] >= minLng && office.location[0] <= maxLng && office.location[1] >= minLat && office.location[1] <= maxLat
6622
- );
6623
- });
6600
+ const filteredOffices = computed(
6601
+ () => packageSuitedOffices.value.filter(
6602
+ (office) => office.location[0] <= bounds.right[0] && office.location[1] >= bounds.right[1] && office.location[0] >= bounds.left[0] && office.location[1] <= bounds.left[1]
6603
+ )
6604
+ );
6624
6605
  const searchedOffices = computed(() => {
6625
6606
  if (searchStorage.value.length === 0)
6626
6607
  return [];
@@ -6639,8 +6620,10 @@ const map = defineStore("map", () => {
6639
6620
  bounds.right = newBounds[1];
6640
6621
  location.center = updateObject.location.center;
6641
6622
  location.zoom = updateObject.location.zoom;
6642
- }, 500);
6623
+ searchStorage.loading = false;
6624
+ }, 2e3);
6643
6625
  const update2 = (updateObject) => {
6626
+ searchStorage.loading = true;
6644
6627
  debouncedUpdate(updateObject);
6645
6628
  };
6646
6629
  const customClick = (_updateObject, event) => {
@@ -6687,7 +6670,6 @@ const map = defineStore("map", () => {
6687
6670
  packageSuitedOffices,
6688
6671
  update: update2,
6689
6672
  bounds,
6690
- polygonBounds,
6691
6673
  filteredOffices,
6692
6674
  fixedBounds,
6693
6675
  fixedParams,
@@ -20286,18 +20268,14 @@ class CdekApi extends AbstractApi {
20286
20268
  constructor(servicePath) {
20287
20269
  super();
20288
20270
  __publicField(this, "getOfficesAbort");
20289
- __publicField(this, "getOfficesByCoordinateAbort");
20290
20271
  __publicField(this, "getPriceAbort");
20291
20272
  __publicField(this, "servicePath");
20292
- this.getOfficesAbort = this.getPriceAbort = this.getOfficesByCoordinateAbort = null;
20273
+ this.getOfficesAbort = this.getPriceAbort = null;
20293
20274
  this.servicePath = servicePath;
20294
20275
  }
20295
20276
  cancelOfficeRequest() {
20296
20277
  this.cancelRequest(this.getOfficesAbort, "offices");
20297
20278
  }
20298
- cancelOfficesByCoordinateRequest() {
20299
- this.cancelRequest(this.getOfficesByCoordinateAbort, "officesByCoordinate");
20300
- }
20301
20279
  cancelPriceRequest() {
20302
20280
  this.cancelRequest(this.getPriceAbort, "prices");
20303
20281
  }
@@ -20398,54 +20376,6 @@ class CdekApi extends AbstractApi {
20398
20376
  searchStorage.loading = false;
20399
20377
  return offices;
20400
20378
  }
20401
- async getOfficesByCoordinate(params) {
20402
- const searchStorage = search();
20403
- const coreStorage = core();
20404
- searchStorage.loading = true;
20405
- if (coreStorage.debug) {
20406
- console.debug("[CDEK] Loading points by coordinate from service", params);
20407
- }
20408
- const additionalParams = {};
20409
- if (coreStorage.params.sender) {
20410
- additionalParams.is_handout_only = false;
20411
- additionalParams.is_reception = true;
20412
- } else {
20413
- additionalParams.is_handout = true;
20414
- }
20415
- this.cancelOfficesByCoordinateRequest();
20416
- this.getOfficesByCoordinateAbort = new AbortController();
20417
- const offices = await axios.get(this.servicePath, {
20418
- params: {
20419
- ...searchStorage.filters,
20420
- ...additionalParams,
20421
- ...params,
20422
- action: "byCoordinate"
20423
- },
20424
- signal: this.getOfficesByCoordinateAbort.signal
20425
- }).then((r) => {
20426
- const data = typeof r.data === "string" ? JSON.parse(r.data) : r.data;
20427
- const officeList = Array.isArray(data) ? data : (data == null ? void 0 : data.delivery_points) || (data == null ? void 0 : data.items) || [];
20428
- return this.formatOffices(officeList);
20429
- }).catch((e) => {
20430
- if (axios.isCancel(e)) {
20431
- if (core().debug) {
20432
- console.debug("[CDEK] Offices by coordinate request cancelled");
20433
- }
20434
- throw e;
20435
- }
20436
- console.error("[CDEK] Service error", e);
20437
- map().mapLoadError = YandexMapErrorCode.SERVICE_ERROR;
20438
- return [];
20439
- });
20440
- if (coreStorage.debug) {
20441
- console.debug("[CDEK] Got points by coordinate", offices);
20442
- }
20443
- searchStorage.loading = false;
20444
- return offices;
20445
- }
20446
- async getOfficesByCoordinates(params) {
20447
- return this.getOfficesByCoordinate(params);
20448
- }
20449
20379
  async fetchOfficePage(additionalParams, pageNumber, sizeNumber) {
20450
20380
  return axios.get(this.servicePath, {
20451
20381
  params: {
@@ -20770,75 +20700,36 @@ class Widget {
20770
20700
  hideFilters: this.params.hideFilters,
20771
20701
  filters: this.params.forceFilters
20772
20702
  });
20773
- const initializeLocationAndOffices = async () => {
20774
- try {
20775
- if (typeof this.params.defaultLocation === "string") {
20776
- const geoData = await this.yandexApi.geocodeString(this.params.defaultLocation);
20777
- if (geoData.found < 1) {
20778
- throw new Error("[CDEK] Unable to geocode default location");
20779
- }
20780
- mapStorage.location.center = geoData.members[0].position;
20781
- } else {
20782
- mapStorage.location.center = this.params.defaultLocation;
20783
- }
20784
- await this.fixBounds();
20785
- if (coreStorage.params.offices !== null || coreStorage.params.officesRaw !== null) {
20786
- mapStorage.offices = await this.cdekApi.getOffices();
20787
- }
20788
- if (coreStorage.params.selected.office !== null) {
20789
- this.selectOffice(coreStorage.params.selected.office);
20703
+ coreStorage.lockUi();
20704
+ if (typeof this.params.defaultLocation === "string") {
20705
+ this.yandexApi.geocodeString(this.params.defaultLocation).then((geoData) => {
20706
+ if (geoData.found < 1) {
20707
+ throw new Error("[CDEK] Unable to geocode default location");
20790
20708
  }
20791
- } catch (e) {
20792
- if (!isCancel(e)) {
20793
- console.error("[CDEK] Error initializing widget location/offices", e);
20794
- }
20795
- } finally {
20796
- coreStorage.unlockUi();
20797
- }
20798
- };
20799
- initializeLocationAndOffices().then();
20800
- const debouncedLoadOfficesByBounds = debounce(async () => {
20801
- if (coreStorage.params.offices !== null || coreStorage.params.officesRaw !== null) {
20709
+ mapStorage.location.center = geoData.members[0].position;
20710
+ }).then(this.fixBounds.bind(this)).finally(coreStorage.unlockUi);
20711
+ } else {
20712
+ mapStorage.location.center = this.params.defaultLocation;
20713
+ this.fixBounds().then(coreStorage.unlockUi);
20714
+ }
20715
+ this.cdekApi.getOffices().then((offices) => mapStorage.offices = offices).then(() => {
20716
+ if (coreStorage.params.selected.office === null)
20802
20717
  return;
20803
- }
20804
- searchStorage.loading = true;
20805
- this.cdekApi.cancelOfficesByCoordinateRequest();
20806
- try {
20807
- mapStorage.offices = await this.cdekApi.getOfficesByCoordinate(mapStorage.polygonBounds);
20808
- if (coreStorage.params.selected.office !== null && mapStorage.exactOffice === null) {
20809
- this.selectOffice(coreStorage.params.selected.office);
20810
- }
20811
- } catch (e) {
20812
- if (!isCancel(e))
20813
- throw e;
20814
- } finally {
20815
- searchStorage.loading = false;
20816
- }
20817
- }, 500);
20718
+ this.selectOffice(coreStorage.params.selected.office);
20719
+ }).finally(coreStorage.unlockUi);
20818
20720
  const debouncedUpdate = debounce(async (input, forceUpdate = false) => {
20819
20721
  try {
20820
20722
  if (forceUpdate) {
20821
- if (coreStorage.params.offices !== null || coreStorage.params.officesRaw !== null) {
20822
- mapStorage.offices = await this.cdekApi.getOffices();
20823
- } else {
20824
- mapStorage.offices = await this.cdekApi.getOfficesByCoordinate(mapStorage.polygonBounds);
20825
- }
20723
+ mapStorage.offices = [];
20724
+ mapStorage.offices = await this.cdekApi.getOffices();
20826
20725
  }
20827
20726
  searchStorage.searchResults = (await this.yandexApi.geocodeString(input)).members;
20727
+ searchStorage.loading = false;
20828
20728
  } catch (e) {
20829
20729
  if (!isCancel(e))
20830
20730
  throw e;
20831
- } finally {
20832
- searchStorage.loading = false;
20833
20731
  }
20834
- }, 500);
20835
- watch(
20836
- () => [mapStorage.bounds.left, mapStorage.bounds.right],
20837
- () => {
20838
- debouncedLoadOfficesByBounds();
20839
- },
20840
- { deep: true }
20841
- );
20732
+ }, 1e3);
20842
20733
  searchStorage.$subscribe(async (mutation, state) => {
20843
20734
  if (mutation.storeId !== "search" || mutation.type !== "patch object") {
20844
20735
  return;
@@ -20849,7 +20740,6 @@ class Widget {
20849
20740
  }
20850
20741
  searchStorage.loading = true;
20851
20742
  this.cdekApi.cancelOfficeRequest();
20852
- this.cdekApi.cancelOfficesByCoordinateRequest();
20853
20743
  this.yandexApi.cancelGeocodeStringRequest();
20854
20744
  await debouncedUpdate(state.value, forceUpdate);
20855
20745
  });
@@ -20947,7 +20837,7 @@ class Widget {
20947
20837
  if (store2.uiLoadLocksCounter > 0)
20948
20838
  return;
20949
20839
  if (store2.debug) {
20950
- console.debug("[CDEK] Widget 3.12.0 has been loaded");
20840
+ console.debug("[CDEK] Widget 3.13.0 has been loaded");
20951
20841
  }
20952
20842
  (_a = this.params.onReady) == null ? void 0 : _a.bind(this)();
20953
20843
  });