@overmap-ai/core 1.0.65-mapbox.1 → 1.0.65-org-projs-only.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.
@@ -397,21 +397,70 @@ var __publicField = (obj, key, value) => {
397
397
  const selectAccessToken = (state) => state.authReducer.accessToken;
398
398
  const selectIsLoggedIn = (state) => state.authReducer.isLoggedIn;
399
399
  const authReducer = authSlice.reducer;
400
- const createPointGeometry = (position) => {
400
+ const coordinatesToLiteral = (coordinates) => {
401
+ return { lng: coordinates[0], lat: coordinates[1] };
402
+ };
403
+ const literalToCoordinates = (literal) => {
404
+ return [literal.lng, literal.lat];
405
+ };
406
+ const flipCoordinates = (coordinates) => {
407
+ return [coordinates[1], coordinates[0]];
408
+ };
409
+ const flipBounds = (bounds) => {
410
+ return [flipCoordinates(bounds[0]), flipCoordinates(bounds[1])];
411
+ };
412
+ function offsetPositionByMeters(originalPosition, latMeters, lngMeters) {
413
+ const { lat, lng } = originalPosition;
414
+ const earthRadius = 6378137;
415
+ const metersPerDegree = 2 * Math.PI * earthRadius / 360;
416
+ const newLng = lng + lngMeters / metersPerDegree / Math.cos(lat * Math.PI / 180);
417
+ const newLat = lat - latMeters / metersPerDegree;
418
+ return { lat: newLat, lng: newLng };
419
+ }
420
+ const createPointGeometry = (coordinates) => {
401
421
  return {
402
422
  type: "Point",
403
- coordinates: position
423
+ coordinates
404
424
  };
405
425
  };
426
+ const coordinatesAreEqual = (a, b) => {
427
+ return a[0] === b[0] && a[1] === b[1];
428
+ };
429
+ const coordinatesToText = (coordinates, decimalPlaces) => {
430
+ if (!coordinates)
431
+ return "(No Location)";
432
+ const { lat, lng } = coordinatesToLiteral(coordinates);
433
+ if (decimalPlaces)
434
+ return `${lat.toFixed(decimalPlaces)}, ${lng.toFixed(decimalPlaces)}`;
435
+ return `${lat}, ${lng}`;
436
+ };
437
+ const coordinatesToUrlText = (coordinates) => {
438
+ const { lat, lng } = coordinatesToLiteral(coordinates);
439
+ return `${lat}%2C${lng}`;
440
+ };
441
+ const openCoordsInGoogleMaps = (coordinates) => {
442
+ const url = `https://www.google.com/maps/search/?api=1&query=${coordinatesToUrlText(coordinates)}`;
443
+ window.open(url);
444
+ };
445
+ const openDirectionsInGoogleMaps = (startingPoint, destination) => {
446
+ const startingPointUrl = coordinatesToUrlText(startingPoint);
447
+ const destinationUrl = coordinatesToUrlText(destination);
448
+ const url = `https://www.google.com/maps/dir/?api=1&origin=${startingPointUrl}&destination=${destinationUrl}`;
449
+ window.open(url);
450
+ };
451
+ const worldBounds = {
452
+ type: "MultiPoint",
453
+ coordinates: [
454
+ [90, -180],
455
+ [-90, 180]
456
+ ]
457
+ };
406
458
  const createMultiPointGeometry = (coordinates) => {
407
459
  return {
408
460
  type: "MultiPoint",
409
461
  coordinates
410
462
  };
411
463
  };
412
- const coordinatesAreEqual = (a, b) => {
413
- return a[0] === b[0] && a[1] === b[1];
414
- };
415
464
  function classNames(...args) {
416
465
  const classes = [];
417
466
  for (const arg of args) {
@@ -589,11 +638,14 @@ var __publicField = (obj, key, value) => {
589
638
  return v.file_sha1 === value.file_sha1;
590
639
  }) === index;
591
640
  }
641
+ function boundsContainPoint(bounds, coordinates) {
642
+ return bounds[0][0] > coordinates[0] && bounds[1][0] < coordinates[0] && bounds[0][1] > coordinates[1] && bounds[1][1] < coordinates[1];
643
+ }
592
644
  const emailRegex = /^.+@.+\..+$/;
593
645
  const fullAssetMarkerSize = 45;
594
646
  const DEFAULT_ISSUE_STATUS = IssueStatus.BACKLOG;
595
647
  const DEFAULT_ISSUE_PRIORITY = IssuePriority.MEDIUM;
596
- const OUTBOX_RETRY_DELAY = 5e3;
648
+ const OUTBOX_RETRY_DELAY = 6e4;
597
649
  const EMPTY_ARRAY = Object.freeze([]);
598
650
  let debug = false;
599
651
  const REACT_APP_DEBUG_MEMOIZATION = {}.REACT_APP_DEBUG_MEMOIZATION || "";
@@ -2311,29 +2363,18 @@ var __publicField = (obj, key, value) => {
2311
2363
  (_state, search) => search
2312
2364
  ],
2313
2365
  (formsMapping, revisions, search) => {
2314
- const { searchTerm, maxResults, favorites, organization } = search;
2315
- const favoriteMatches = [];
2366
+ const { searchTerm, maxResults, organization } = search;
2316
2367
  const regularMatches = [];
2317
2368
  for (const [formId, form] of Object.entries(formsMapping)) {
2318
- if (favorites !== void 0 && form.favorite != favorites)
2319
- continue;
2320
2369
  if (Number.isInteger(organization) && organization !== form.organization) {
2321
2370
  continue;
2322
2371
  }
2323
2372
  const latestRevision = _selectLatestFormRevision(revisions, formId);
2324
2373
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
2325
- if (form.favorite) {
2326
- favoriteMatches.push({ ...form, latestRevision });
2327
- } else {
2328
- regularMatches.push({ ...form, latestRevision });
2329
- }
2330
- }
2331
- if (favoriteMatches.length >= maxResults) {
2332
- break;
2374
+ regularMatches.push({ ...form, latestRevision });
2333
2375
  }
2334
2376
  }
2335
- const maxRegularMatches = maxResults - favoriteMatches.length;
2336
- return [...favoriteMatches, ...regularMatches.slice(0, maxRegularMatches)];
2377
+ return [...regularMatches.slice(0, maxResults)];
2337
2378
  },
2338
2379
  // as the argument is an object, we check the first level of properties for equality
2339
2380
  { memoizeOptions: { equalityCheck: shallowEqual } }
@@ -3360,62 +3401,11 @@ var __publicField = (obj, key, value) => {
3360
3401
  };
3361
3402
  const overmapReducer = toolkit.combineReducers(overmapReducers);
3362
3403
  const resetStore = "RESET";
3363
- function handleWorkspaceRemoval(draft, action) {
3364
- const workspaceId = action.payload;
3365
- const issuesVisibleInWorkspace = Object.values(draft.issueReducer.instances).filter(
3366
- (issue) => issue.visible_in_workspaces.includes(workspaceId)
3367
- );
3368
- const mainWorkspace = selectMainWorkspace(draft);
3369
- if (!mainWorkspace) {
3370
- throw new Error("Main workspace not found");
3371
- }
3372
- if (action.payload === mainWorkspace.offline_id) {
3373
- throw new Error("Tried to delete main workspace");
3374
- }
3375
- const categoriesInThisWorkspace = new Set(
3376
- selectCategoriesOfWorkspace(workspaceId)(draft).map((category) => category.offline_id)
3377
- );
3378
- for (const issue of issuesVisibleInWorkspace) {
3379
- if (issue.category && categoriesInThisWorkspace.has(issue.category)) {
3380
- issue.category = null;
3381
- }
3382
- }
3383
- const issuesWithThisWorkspaceIndex = issuesVisibleInWorkspace.filter(
3384
- (issue) => issue.index_workspace === action.payload
3385
- );
3386
- for (const issue of issuesWithThisWorkspaceIndex) {
3387
- issue.index_workspace = mainWorkspace.offline_id;
3388
- if (!issue.visible_in_workspaces.includes(mainWorkspace.offline_id)) {
3389
- issue.visible_in_workspaces.push(mainWorkspace.offline_id);
3390
- }
3391
- }
3392
- for (const issue of issuesVisibleInWorkspace) {
3393
- const indexOfWorkspace = issue.visible_in_workspaces.indexOf(workspaceId);
3394
- if (indexOfWorkspace === -1) {
3395
- throw new Error("Workspace not found in issue's visible_in_workspaces");
3396
- }
3397
- issue.visible_in_workspaces.splice(indexOfWorkspace, 1);
3398
- }
3399
- for (const issue of issuesVisibleInWorkspace) {
3400
- if (issue.visible_in_workspaces.length === 0) {
3401
- throw new Error(`Unexpected error: Issue ${issue.offline_id} has no visible_in_workspaces`);
3402
- }
3403
- if (issue.index_workspace === action.payload || !issue.index_workspace) {
3404
- throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
3405
- }
3406
- }
3407
- }
3408
3404
  const overmapRootReducer = (state, action) => {
3409
3405
  if (action.type === "auth/setLoggedIn" && !action.payload) {
3410
3406
  return overmapReducer(void 0, action);
3411
3407
  }
3412
- let mutatedState = state;
3413
- if (state && action.type === "workspace/removeWorkspace") {
3414
- mutatedState = toolkit.createNextState(state, (draft) => {
3415
- handleWorkspaceRemoval(draft, action);
3416
- });
3417
- }
3418
- return overmapReducer(mutatedState, action);
3408
+ return overmapReducer(state, action);
3419
3409
  };
3420
3410
  let __OUTBOX_COORDINATOR = null;
3421
3411
  function getOutboxCoordinator() {
@@ -4034,10 +4024,17 @@ var __publicField = (obj, key, value) => {
4034
4024
  }
4035
4025
  }
4036
4026
  class CategoryService extends BaseApiService {
4037
- add(category, workspaceId) {
4038
- const offlineCategory = offline(category);
4039
- const categoryWithWorkspace = { ...offlineCategory, workspace: workspaceId };
4040
- this.dispatch(addCategory(categoryWithWorkspace));
4027
+ add(payload, workspaceId) {
4028
+ const { store } = this.client;
4029
+ const createdBy = store.getState().userReducer.currentUser.id;
4030
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4031
+ const offlineCategory = offline({
4032
+ ...payload,
4033
+ created_by: createdBy,
4034
+ submitted_at: submittedAt,
4035
+ workspace: workspaceId
4036
+ });
4037
+ this.dispatch(addCategory(offlineCategory));
4041
4038
  const promise = this.enqueueRequest({
4042
4039
  description: "Create Category",
4043
4040
  method: HttpMethod.POST,
@@ -4046,10 +4043,10 @@ var __publicField = (obj, key, value) => {
4046
4043
  workspace_id: workspaceId.toString()
4047
4044
  },
4048
4045
  payload: offlineCategory,
4049
- blockers: [],
4046
+ blockers: [workspaceId],
4050
4047
  blocks: [offlineCategory.offline_id]
4051
4048
  });
4052
- return [categoryWithWorkspace, promise];
4049
+ return [offlineCategory, promise];
4053
4050
  }
4054
4051
  update(category, workspaceId) {
4055
4052
  const state = this.client.store.getState();
@@ -4919,11 +4916,7 @@ var __publicField = (obj, key, value) => {
4919
4916
  ...issueType ? { issue_type: issueType } : {}
4920
4917
  },
4921
4918
  payload: issuePayload,
4922
- blockers: [
4923
- "add-issue",
4924
- ...issuePayload.index_workspace ? [issuePayload.index_workspace] : [],
4925
- ...issuePayload.visible_in_workspaces
4926
- ],
4919
+ blockers: ["add-issue", ...issuePayload.index_workspace ? [issuePayload.index_workspace] : []],
4927
4920
  blocks: [issuePayload.offline_id]
4928
4921
  });
4929
4922
  void promise.then((result) => {
@@ -5370,23 +5363,17 @@ var __publicField = (obj, key, value) => {
5370
5363
  * @throws An APIError if the server returns an error, or any other error that may occur.
5371
5364
  */
5372
5365
  async add(project) {
5373
- if (!project.organization_owner && !project.user_owner) {
5374
- throw new Error("Project type was not chosen when trying to create a project");
5375
- }
5376
5366
  if (!project.bounds && !project.canvas_bounds) {
5377
5367
  throw new Error("Project must either have bounds or canvas_bounds set");
5378
5368
  }
5379
- const isOrganizationProject = !!project.organization_owner;
5380
- const url = isOrganizationProject ? `/organizations/${project.organization_owner}/projects/` : "/projects/";
5381
- const projectType = isOrganizationProject ? { organization_owner: project.organization_owner } : { user_owner: project.user_owner };
5382
5369
  return await this.enqueueRequest({
5383
5370
  description: "Create project",
5384
5371
  method: HttpMethod.POST,
5385
- url,
5372
+ url: "/projects/",
5386
5373
  payload: {
5387
5374
  name: project.name,
5388
5375
  bounds: project.bounds,
5389
- ...projectType
5376
+ organization_owner: project.organization_owner
5390
5377
  },
5391
5378
  blockers: [],
5392
5379
  blocks: []
@@ -5704,48 +5691,6 @@ var __publicField = (obj, key, value) => {
5704
5691
  });
5705
5692
  return [fullRevision, offlineFormRevisionAttachments, promise, attachmentsPromise];
5706
5693
  }
5707
- async favorite(formId, projectId) {
5708
- const { store } = this.client;
5709
- const state = store.getState();
5710
- const form = state.formReducer.instances[formId];
5711
- if (!form) {
5712
- throw new Error(`Expected form to exist, got ${form}`);
5713
- }
5714
- this.dispatch(updateForm({ ...form, favorite: true }));
5715
- try {
5716
- await this.enqueueRequest({
5717
- description: "Favorite form",
5718
- method: HttpMethod.POST,
5719
- url: `/forms/${formId}/favorite/${projectId}/`,
5720
- blockers: [formId, `favorite-${formId}`],
5721
- blocks: [`favorite-${formId}`]
5722
- });
5723
- } catch (e) {
5724
- this.dispatch(updateForm(form));
5725
- throw e;
5726
- }
5727
- }
5728
- async unfavorite(formId, projectId) {
5729
- const { store } = this.client;
5730
- const state = store.getState();
5731
- const form = state.formReducer.instances[formId];
5732
- if (!form) {
5733
- throw new Error(`Expected form to exist, got ${form}`);
5734
- }
5735
- this.dispatch(updateForm({ ...form, favorite: false }));
5736
- try {
5737
- return await this.enqueueRequest({
5738
- description: "Unfavorite form",
5739
- method: HttpMethod.DELETE,
5740
- url: `/forms/${formId}/unfavorite/${projectId}/`,
5741
- blockers: [formId, `favorite-${formId}`],
5742
- blocks: [`favorite-${formId}`]
5743
- });
5744
- } catch (e) {
5745
- this.dispatch(updateForm(form));
5746
- throw e;
5747
- }
5748
- }
5749
5694
  async delete(formId) {
5750
5695
  const { store } = this.client;
5751
5696
  const state = store.getState();
@@ -6206,13 +6151,19 @@ var __publicField = (obj, key, value) => {
6206
6151
  }
6207
6152
  }
6208
6153
  class WorkspaceService extends BaseApiService {
6209
- add(workspace) {
6210
- const offlineWorkspace = offline(workspace);
6154
+ add(payload) {
6155
+ const { store } = this.client;
6156
+ const createdBy = store.getState().userReducer.currentUser.id;
6157
+ const offlineWorkspace = offline({
6158
+ ...payload,
6159
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6160
+ created_by: createdBy
6161
+ });
6211
6162
  this.dispatch(addWorkspace(offlineWorkspace));
6212
6163
  const promise = this.enqueueRequest({
6213
6164
  description: "Create Workspace",
6214
6165
  method: HttpMethod.POST,
6215
- url: `/projects/${workspace.project}/workspaces/`,
6166
+ url: `/projects/${payload.project}/workspaces/`,
6216
6167
  payload: offlineWorkspace,
6217
6168
  blockers: ["add-workspace"],
6218
6169
  blocks: [offlineWorkspace.offline_id]
@@ -6629,9 +6580,7 @@ var __publicField = (obj, key, value) => {
6629
6580
  method: HttpMethod.GET,
6630
6581
  url: `/billing/${license.offline_id}/`,
6631
6582
  isAuthNeeded: true,
6632
- blockers: [
6633
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6634
- ],
6583
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6635
6584
  blocks: []
6636
6585
  });
6637
6586
  this.dispatch(updateLicense(result));
@@ -6643,9 +6592,7 @@ var __publicField = (obj, key, value) => {
6643
6592
  method: HttpMethod.DELETE,
6644
6593
  url: `/billing/${license.offline_id}/suspend/`,
6645
6594
  isAuthNeeded: true,
6646
- blockers: [
6647
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6648
- ],
6595
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6649
6596
  blocks: []
6650
6597
  });
6651
6598
  this.dispatch(updateLicense(result));
@@ -6657,9 +6604,7 @@ var __publicField = (obj, key, value) => {
6657
6604
  method: HttpMethod.PATCH,
6658
6605
  url: `/billing/${license.offline_id}/suspend/`,
6659
6606
  isAuthNeeded: true,
6660
- blockers: [
6661
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6662
- ],
6607
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6663
6608
  blocks: []
6664
6609
  });
6665
6610
  this.dispatch(updateLicense(result));
@@ -6671,9 +6616,7 @@ var __publicField = (obj, key, value) => {
6671
6616
  method: HttpMethod.DELETE,
6672
6617
  url: `/billing/${license.offline_id}/`,
6673
6618
  isAuthNeeded: true,
6674
- blockers: [
6675
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6676
- ],
6619
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6677
6620
  blocks: []
6678
6621
  });
6679
6622
  this.dispatch(updateLicense(result));
@@ -6687,7 +6630,7 @@ var __publicField = (obj, key, value) => {
6687
6630
  isAuthNeeded: true,
6688
6631
  payload: { project: project.id },
6689
6632
  blockers: [
6690
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : "",
6633
+ license.organization_owner ? license.organization_owner.toString() : "",
6691
6634
  project.id ? project.id.toString() : ""
6692
6635
  ],
6693
6636
  blocks: ["add-issue", "add-form-entry", "change-access-level", "add-workspace"]
@@ -6701,9 +6644,7 @@ var __publicField = (obj, key, value) => {
6701
6644
  method: HttpMethod.DELETE,
6702
6645
  url: `/billing/${license.offline_id}/project/`,
6703
6646
  isAuthNeeded: true,
6704
- blockers: [
6705
- license.organization_owner ? license.organization_owner.toString() : license.user_owner ? license.user_owner.toString() : ""
6706
- ],
6647
+ blockers: [license.organization_owner ? license.organization_owner.toString() : ""],
6707
6648
  blocks: ["add-issue", "add-form-entry", "change-access-level", "add-workspace"]
6708
6649
  });
6709
6650
  this.dispatch(updateLicense(result));
@@ -7624,6 +7565,7 @@ var __publicField = (obj, key, value) => {
7624
7565
  exports2.authReducer = authReducer;
7625
7566
  exports2.authSlice = authSlice;
7626
7567
  exports2.blobToBase64 = blobToBase64;
7568
+ exports2.boundsContainPoint = boundsContainPoint;
7627
7569
  exports2.categoryReducer = categoryReducer;
7628
7570
  exports2.categorySlice = categorySlice;
7629
7571
  exports2.classNames = classNames;
@@ -7631,6 +7573,9 @@ var __publicField = (obj, key, value) => {
7631
7573
  exports2.clearTokens = clearTokens;
7632
7574
  exports2.constructUploadedFilePayloads = constructUploadedFilePayloads;
7633
7575
  exports2.coordinatesAreEqual = coordinatesAreEqual;
7576
+ exports2.coordinatesToLiteral = coordinatesToLiteral;
7577
+ exports2.coordinatesToText = coordinatesToText;
7578
+ exports2.coordinatesToUrlText = coordinatesToUrlText;
7634
7579
  exports2.createMultiPointGeometry = createMultiPointGeometry;
7635
7580
  exports2.createOfflineAction = createOfflineAction;
7636
7581
  exports2.createPointGeometry = createPointGeometry;
@@ -7693,6 +7638,8 @@ var __publicField = (obj, key, value) => {
7693
7638
  exports2.fileReducer = fileReducer;
7694
7639
  exports2.fileSlice = fileSlice;
7695
7640
  exports2.fileToBlob = fileToBlob;
7641
+ exports2.flipBounds = flipBounds;
7642
+ exports2.flipCoordinates = flipCoordinates;
7696
7643
  exports2.formReducer = formReducer;
7697
7644
  exports2.formRevisionAttachmentReducer = formRevisionAttachmentReducer;
7698
7645
  exports2.formRevisionAttachmentSlice = formRevisionAttachmentSlice;
@@ -7759,14 +7706,18 @@ var __publicField = (obj, key, value) => {
7759
7706
  exports2.issueUpdateSlice = issueUpdateSlice;
7760
7707
  exports2.licenseReducer = licenseReducer;
7761
7708
  exports2.licenseSlice = licenseSlice;
7709
+ exports2.literalToCoordinates = literalToCoordinates;
7762
7710
  exports2.logOnlyOnce = logOnlyOnce;
7763
7711
  exports2.markAsDeleted = markAsDeleted;
7764
7712
  exports2.markForDeletion = markForDeletion;
7765
7713
  exports2.memoize = memoize;
7766
7714
  exports2.moveDocument = moveDocument;
7767
7715
  exports2.offline = offline;
7716
+ exports2.offsetPositionByMeters = offsetPositionByMeters;
7768
7717
  exports2.onlyUniqueHashes = onlyUniqueHashes;
7769
7718
  exports2.onlyUniqueOfflineIds = onlyUniqueOfflineIds;
7719
+ exports2.openCoordsInGoogleMaps = openCoordsInGoogleMaps;
7720
+ exports2.openDirectionsInGoogleMaps = openDirectionsInGoogleMaps;
7770
7721
  exports2.organizationAccessReducer = organizationAccessReducer;
7771
7722
  exports2.organizationAccessSlice = organizationAccessSlice;
7772
7723
  exports2.organizationReducer = organizationReducer;
@@ -8082,6 +8033,7 @@ var __publicField = (obj, key, value) => {
8082
8033
  exports2.warningColor = warningColor;
8083
8034
  exports2.workspaceReducer = workspaceReducer;
8084
8035
  exports2.workspaceSlice = workspaceSlice;
8036
+ exports2.worldBounds = worldBounds;
8085
8037
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
8086
8038
  });
8087
8039
  //# sourceMappingURL=overmap-core.umd.cjs.map