@octostar/map-component 0.1.2 → 0.1.13

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { useState, useRef, useEffect, useMemo, useCallback, forwardRef, useImperativeHandle } from "react";
2
+ import { createContext, useContext, useState, useRef, useEffect, useMemo, useCallback, forwardRef, useImperativeHandle } from "react";
3
3
  import maplibregl from "maplibre-gl";
4
4
  import MapboxDraw from "@mapbox/mapbox-gl-draw";
5
5
  import * as turf from "@turf/turf";
@@ -7,7 +7,7 @@ import proj4 from "proj4";
7
7
  import * as THREE from "three";
8
8
  import { saveAs } from "file-saver";
9
9
  import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filter, X, Ruler, Move, Navigation, Pencil, Database, Search, MapPin, Minus, Pentagon, Type, MoveRight, Undo2, Redo2, Trash2, Loader2, Home, Building2, Store, Factory, Warehouse, Church, Hospital, School, GraduationCap, Library, Landmark, Castle, Car, Bus, Train, Plane, Ship, Bike, Fuel, Utensils, Coffee, Beer, Wine, Pizza, IceCream, Trees, Mountain, Waves, Sun, Cloud, Umbrella, Flower2, Leaf, Heart, Star, Flag, AlertTriangle, Info, HelpCircle, CheckCircle, XCircle, PlusCircle, MinusCircle, Zap, Flame, Camera, Music, Film, Gamepad2, Trophy, Medal, Tent, Compass, Briefcase, Wrench, Hammer, Scissors, Paintbrush, Palette, ShoppingCart, Gift, Package, CreditCard, Wallet, Phone, Mail, Globe, Wifi, Radio, Tv, User, Users, Baby, Dog, Cat, Bird, Apple, Carrot, Egg, Anchor, Lock, Key, Shield, Eye, Clock, Calendar, Bookmark, Tag, Triangle, Octagon, ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Map as Map$1, Satellite, MoreHorizontal, Upload, Download, FolderOpen, Focus, Box, Layers, ChevronRight, EyeOff, Smile, Plus, Save, Blend, SkipBack, Pause, Play, TestTube, GripVertical, FileJson, Check, AlertCircle } from "lucide-react";
10
- import { App, Tooltip, Dropdown, Button, Divider, Modal, Tabs, Input, Popover, Switch, Slider, Tag as Tag$1, Select, Collapse, ColorPicker, Card, Table, DatePicker } from "antd";
10
+ import { App, message, Tooltip, Dropdown, Button, Divider, Modal, Tabs, Input, Popover, Switch, Slider, Tag as Tag$1, Select, Collapse, ColorPicker, Card, Table, DatePicker } from "antd";
11
11
  import { clsx } from "clsx";
12
12
  import { twMerge } from "tailwind-merge";
13
13
  import { format } from "date-fns";
@@ -17,14 +17,25 @@ import * as toGeoJSON from "@mapbox/togeojson";
17
17
  function cn(...inputs) {
18
18
  return twMerge(clsx(inputs));
19
19
  }
20
+ const ToastContext = createContext(null);
20
21
  function useToast() {
21
- const { message } = App.useApp();
22
+ const externalToast = useContext(ToastContext);
23
+ if (externalToast) {
24
+ return { toast: externalToast };
25
+ }
26
+ let message$1 = null;
27
+ try {
28
+ const app = App.useApp();
29
+ message$1 = app.message;
30
+ } catch {
31
+ }
22
32
  const toast = ({ title, description, variant }) => {
23
33
  const content = description ? `${title ? title + ": " : ""}${description}` : title;
34
+ const msg = message$1 ?? message;
24
35
  if (variant === "destructive") {
25
- message.error(content);
36
+ msg.error(content);
26
37
  } else {
27
- message.success(content);
38
+ msg.success(content);
28
39
  }
29
40
  };
30
41
  return { toast };
@@ -4594,7 +4605,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
4594
4605
  hideBasemapSwitcher = false,
4595
4606
  externalPersistence = false,
4596
4607
  enableKeyboardShortcuts = true,
4597
- enableProperties = true
4608
+ enableProperties = true,
4609
+ toastProvider
4598
4610
  }, ref) {
4599
4611
  const mapContainer = useRef(null);
4600
4612
  const map = useRef(null);
@@ -4667,7 +4679,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
4667
4679
  const [labelsSuppressed, setLabelsSuppressed] = useState(true);
4668
4680
  const [contextMenu, setContextMenu] = useState(null);
4669
4681
  const timelineStore = useTimelineStore();
4670
- const { toast } = useToast();
4682
+ const { toast: internalToast } = useToast();
4683
+ const toast = toastProvider ?? internalToast;
4671
4684
  useEffect(() => {
4672
4685
  const handleError = (event) => {
4673
4686
  const msg = event.message || "";
@@ -4679,13 +4692,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
4679
4692
  };
4680
4693
  const handleUnhandledRejection = (event) => {
4681
4694
  var _a;
4682
- let message = "";
4695
+ let message2 = "";
4683
4696
  try {
4684
- message = ((_a = event.reason) == null ? void 0 : _a.message) || String(event.reason);
4697
+ message2 = ((_a = event.reason) == null ? void 0 : _a.message) || String(event.reason);
4685
4698
  } catch {
4686
- message = "unknown";
4699
+ message2 = "unknown";
4687
4700
  }
4688
- if (message.includes("unknown feature value") || message.includes("getSource") || message.includes("WebGL") || message.includes("style") || message.includes("tile") || message.includes("Map container") || message.includes("already running") || message.includes("out of range") || message.includes("DEM data")) {
4701
+ if (message2.includes("unknown feature value") || message2.includes("getSource") || message2.includes("WebGL") || message2.includes("style") || message2.includes("tile") || message2.includes("Map container") || message2.includes("already running") || message2.includes("out of range") || message2.includes("DEM data")) {
4689
4702
  event.preventDefault();
4690
4703
  return;
4691
4704
  }
@@ -9833,7 +9846,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9833
9846
  ] })
9834
9847
  ] }) });
9835
9848
  }
9836
- return /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative ${className || ""}`, "data-testid": "map-editor-canvas", children: [
9849
+ const toastContextValue = toastProvider ?? null;
9850
+ return /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative ${className || ""}`, "data-testid": "map-editor-canvas", children: [
9837
9851
  /* @__PURE__ */ jsx(
9838
9852
  "div",
9839
9853
  {
@@ -10081,7 +10095,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10081
10095
  onGoTo: (coords, zoom) => {
10082
10096
  if (map.current) {
10083
10097
  const currentZoom = map.current.getZoom();
10084
- map.current.flyTo({ center: coords, zoom: zoom ?? Math.max(currentZoom, 10), duration: 2e3 });
10098
+ map.current.flyTo({ center: coords, zoom: zoom ?? Math.max(currentZoom, 14), duration: 2e3 });
10085
10099
  }
10086
10100
  },
10087
10101
  showClearFilter,
@@ -10355,7 +10369,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10355
10369
  "data-testid": "input-file-geojson"
10356
10370
  }
10357
10371
  )
10358
- ] }) });
10372
+ ] }) }) });
10359
10373
  });
10360
10374
  function ActionPanel({ onSave, onLoad, disabled }) {
10361
10375
  return /* @__PURE__ */ jsxs(