@deck.gl/widgets 9.2.8 → 9.2.10

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.cjs CHANGED
@@ -462,6 +462,15 @@ var import_preact6 = require("preact");
462
462
  // dist/lib/components/dropdown-menu.js
463
463
  var import_jsx_runtime9 = require("preact/jsx-runtime");
464
464
  var import_hooks = require("preact/hooks");
465
+ function getMenuItemValue(item) {
466
+ return typeof item === "string" ? item : item.value;
467
+ }
468
+ function getMenuItemLabel(item) {
469
+ return typeof item === "string" ? item : item.label;
470
+ }
471
+ function getMenuItemIcon(item) {
472
+ return typeof item === "string" ? void 0 : item.icon;
473
+ }
465
474
  var DropdownMenu = (props) => {
466
475
  const [isOpen, setIsOpen] = (0, import_hooks.useState)(false);
467
476
  const dropdownRef = (0, import_hooks.useRef)(null);
@@ -477,42 +486,17 @@ var DropdownMenu = (props) => {
477
486
  document.removeEventListener("mousedown", handleClickOutside);
478
487
  };
479
488
  }, []);
480
- const handleSelect = (value) => {
481
- props.onSelect(value);
489
+ const handleSelect = (item) => {
490
+ props.onSelect(getMenuItemValue(item));
482
491
  setIsOpen(false);
483
492
  };
484
- return (0, import_jsx_runtime9.jsxs)("div", { className: "dropdown-container", ref: dropdownRef, style: {
485
- position: "relative",
486
- display: "inline-block",
487
- ...props.style
488
- }, children: [(0, import_jsx_runtime9.jsx)("button", { onClick: toggleDropdown, style: {
489
- width: "30px",
490
- height: "30px",
491
- display: "flex",
492
- alignItems: "center",
493
- justifyContent: "center",
494
- border: "1px solid #ccc",
495
- borderRadius: "4px",
496
- background: "#fff",
497
- cursor: "pointer",
498
- padding: 0
499
- }, children: "\u25BC" }), isOpen && (0, import_jsx_runtime9.jsx)("ul", { style: {
500
- position: "absolute",
501
- top: "100%",
502
- right: "100%",
503
- background: "#fff",
504
- border: "1px solid #ccc",
505
- borderRadius: "4px",
506
- listStyle: "none",
507
- padding: "4px 0",
508
- margin: 0,
509
- zIndex: 1e3,
510
- minWidth: "200px"
511
- }, children: props.menuItems.map((item) => (0, import_jsx_runtime9.jsx)("li", { onClick: () => handleSelect(item), style: {
512
- padding: "4px 8px",
513
- cursor: "pointer",
514
- whiteSpace: "nowrap"
515
- }, children: item }, item)) })] });
493
+ if (props.menuItems.length === 0) {
494
+ return null;
495
+ }
496
+ return (0, import_jsx_runtime9.jsxs)("div", { className: "deck-widget-dropdown-container", ref: dropdownRef, style: props.style, children: [(0, import_jsx_runtime9.jsx)("button", { className: "deck-widget-dropdown-button", onClick: toggleDropdown, children: (0, import_jsx_runtime9.jsx)("span", { className: `deck-widget-dropdown-icon ${isOpen ? "open" : ""}` }) }), isOpen && (0, import_jsx_runtime9.jsx)("ul", { className: "deck-widget-dropdown-menu", children: props.menuItems.map((item) => {
497
+ const icon = getMenuItemIcon(item);
498
+ return (0, import_jsx_runtime9.jsxs)("li", { className: "deck-widget-dropdown-item", onClick: () => handleSelect(item), children: [icon && (0, import_jsx_runtime9.jsx)("span", { className: "deck-widget-dropdown-item-icon", style: { maskImage: `url("${icon}")`, WebkitMaskImage: `url("${icon}")` } }), getMenuItemLabel(item)] }, getMenuItemValue(item));
499
+ }) })] });
516
500
  };
517
501
 
518
502
  // dist/lib/geocode/geocoder-history.js
@@ -705,6 +689,12 @@ function dmsToDecimal(s) {
705
689
 
706
690
  // dist/geocoder-widget.js
707
691
  var CURRENT_LOCATION2 = "current";
692
+ var LOCATION_ICON = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960'%3E%3Cpath d='M480-480q33 0 56.5-23.5T560-560q0-33-23.5-56.5T480-640q-33 0-56.5 23.5T400-560q0 33 23.5 56.5T480-480Zm0 294q122-112 181-203.5T720-552q0-109-69.5-178.5T480-800q-101 0-170.5 69.5T240-552q0 71 59 162.5T480-186Zm0 106Q319-217 239.5-334.5T160-552q0-150 96.5-239T480-880q127 0 223.5 89T800-552q0 100-79.5 217.5T480-80Z'/%3E%3C/svg%3E`;
693
+ var CURRENT_LOCATION_ITEM = {
694
+ label: "Current location",
695
+ value: CURRENT_LOCATION2,
696
+ icon: LOCATION_ICON
697
+ };
708
698
  var GeocoderWidget = class extends import_core6.Widget {
709
699
  constructor(props = {}) {
710
700
  super(props);
@@ -713,6 +703,7 @@ var GeocoderWidget = class extends import_core6.Widget {
713
703
  this.geocodeHistory = new GeocoderHistory({});
714
704
  this.addressText = "";
715
705
  this.geocoder = CoordinatesGeocoder;
706
+ this.isGettingLocation = false;
716
707
  this.setInput = (text) => {
717
708
  this.addressText = text;
718
709
  };
@@ -721,17 +712,41 @@ var GeocoderWidget = class extends import_core6.Widget {
721
712
  this.handleSubmit();
722
713
  }
723
714
  };
724
- this.handleSelect = (address) => {
725
- this.setInput(address);
726
- this.handleSubmit();
715
+ this.handleSelect = (value) => {
716
+ if (value === CURRENT_LOCATION2) {
717
+ this.getCurrentLocation();
718
+ } else {
719
+ this.setInput(value);
720
+ this.handleSubmit();
721
+ }
727
722
  };
728
723
  this.handleSubmit = () => {
729
724
  this.geocode(this.addressText);
730
725
  };
726
+ this.getCurrentLocation = async () => {
727
+ this.isGettingLocation = true;
728
+ if (this.rootElement) {
729
+ this.updateHTML();
730
+ }
731
+ try {
732
+ const coordinates = await CurrentLocationGeocoder.geocode();
733
+ if (coordinates) {
734
+ this.setViewState(coordinates);
735
+ }
736
+ } catch (error) {
737
+ this.geocodeHistory.errorText = error instanceof Error ? error.message : "Location error";
738
+ } finally {
739
+ this.isGettingLocation = false;
740
+ if (this.rootElement) {
741
+ this.updateHTML();
742
+ }
743
+ }
744
+ };
731
745
  this.geocode = async (address) => {
732
- const useGeolocation = this.props._geolocation && address === CURRENT_LOCATION2;
733
- const geocoder = useGeolocation ? CurrentLocationGeocoder : this.geocoder;
734
- const coordinates = await this.geocodeHistory.geocode(geocoder, this.addressText, this.props.apiKey);
746
+ const coordinates = await this.geocodeHistory.geocode(this.geocoder, this.addressText, this.props.apiKey);
747
+ if (this.rootElement) {
748
+ this.updateHTML();
749
+ }
735
750
  if (coordinates) {
736
751
  this.setViewState(coordinates);
737
752
  }
@@ -749,35 +764,19 @@ var GeocoderWidget = class extends import_core6.Widget {
749
764
  super.setProps(props);
750
765
  }
751
766
  onRenderHTML(rootElement) {
752
- const menuItems = this.props._geolocation ? [CURRENT_LOCATION2, ...this.geocodeHistory.addressHistory] : [...this.geocodeHistory.addressHistory];
753
- (0, import_preact6.render)((0, import_jsx_runtime10.jsxs)("div", { className: "deck-widget-geocoder", style: {
754
- pointerEvents: "auto",
755
- display: "flex",
756
- alignItems: "center",
757
- flexWrap: "wrap"
758
- // Allows wrapping on smaller screens
759
- }, children: [(0, import_jsx_runtime10.jsx)("input", {
767
+ const menuItems = this.props._geolocation ? [CURRENT_LOCATION_ITEM, ...this.geocodeHistory.addressHistory] : [...this.geocodeHistory.addressHistory];
768
+ (0, import_preact6.render)((0, import_jsx_runtime10.jsxs)("div", { className: "deck-widget-geocoder", children: [(0, import_jsx_runtime10.jsx)("input", {
769
+ className: "deck-widget-geocoder-input",
760
770
  type: "text",
761
- placeholder: this.geocoder.placeholderLocation ?? "Enter address or location",
771
+ placeholder: this.isGettingLocation ? "Finding your location..." : this.geocoder.placeholderLocation ?? "Enter address or location",
762
772
  value: this.geocodeHistory.addressText,
763
773
  // @ts-expect-error event type
764
774
  onInput: (e) => {
765
775
  var _a;
766
776
  return this.setInput(((_a = e.target) == null ? void 0 : _a.value) || "");
767
777
  },
768
- onKeyPress: this.handleKeyPress,
769
- style: {
770
- flex: "1 1 auto",
771
- minWidth: "200px",
772
- margin: 0,
773
- padding: "8px",
774
- boxSizing: "border-box"
775
- }
776
- }), (0, import_jsx_runtime10.jsx)(DropdownMenu, { menuItems, onSelect: this.handleSelect, style: {
777
- margin: 2,
778
- padding: "4px 2px",
779
- boxSizing: "border-box"
780
- } }), this.geocodeHistory.errorText && (0, import_jsx_runtime10.jsx)("div", { className: "error", children: this.geocodeHistory.errorText })] }), rootElement);
778
+ onKeyPress: this.handleKeyPress
779
+ }), (0, import_jsx_runtime10.jsx)(DropdownMenu, { menuItems, onSelect: this.handleSelect }), this.geocodeHistory.errorText && (0, import_jsx_runtime10.jsx)("div", { className: "deck-widget-geocoder-error", children: this.geocodeHistory.errorText })] }), rootElement);
781
780
  }
782
781
  // TODO - MOVE TO WIDGETIMPL?
783
782
  setViewState(viewState) {
@@ -1502,7 +1501,13 @@ var LightTheme = {
1502
1501
  "--button-text": "rgb(24, 24, 26, 1)",
1503
1502
  "--icon-compass-north-color": "rgb(240, 92, 68)",
1504
1503
  "--icon-compass-south-color": "rgb(204, 204, 204)",
1505
- "--menu-gap": "4px"
1504
+ "--menu-gap": "4px",
1505
+ "--menu-background": "#fff",
1506
+ "--menu-backdrop-filter": "unset",
1507
+ "--menu-border": "unset",
1508
+ "--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25)",
1509
+ "--menu-text": "rgb(24, 24, 26, 1)",
1510
+ "--menu-item-hover": "rgba(0, 0, 0, 0.08)"
1506
1511
  };
1507
1512
  var DarkTheme = {
1508
1513
  "--widget-margin": "12px",
@@ -1518,7 +1523,13 @@ var DarkTheme = {
1518
1523
  "--button-text": "rgb(215, 214, 229, 1)",
1519
1524
  "--icon-compass-north-color": "rgb(240, 92, 68)",
1520
1525
  "--icon-compass-south-color": "rgb(200, 199, 209)",
1521
- "--menu-gap": "4px"
1526
+ "--menu-gap": "4px",
1527
+ "--menu-background": "rgba(18, 18, 20, 1)",
1528
+ "--menu-backdrop-filter": "unset",
1529
+ "--menu-border": "unset",
1530
+ "--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25)",
1531
+ "--menu-text": "rgb(215, 214, 229, 1)",
1532
+ "--menu-item-hover": "rgba(255, 255, 255, 0.1)"
1522
1533
  };
1523
1534
  var LightGlassTheme = {
1524
1535
  "--widget-margin": "12px",
@@ -1534,7 +1545,13 @@ var LightGlassTheme = {
1534
1545
  "--button-text": "rgb(24, 24, 26, 1)",
1535
1546
  "--icon-compass-north-color": "rgb(240, 92, 68)",
1536
1547
  "--icon-compass-south-color": "rgb(204, 204, 204)",
1537
- "--menu-gap": "4px"
1548
+ "--menu-gap": "4px",
1549
+ "--menu-background": "rgba(255, 255, 255, 0.6)",
1550
+ "--menu-backdrop-filter": "blur(4px)",
1551
+ "--menu-border": "1px solid rgba(255, 255, 255, 0.6)",
1552
+ "--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25), 0px 0px 8px 0px rgba(0, 0, 0, 0.1) inset",
1553
+ "--menu-text": "rgb(24, 24, 26, 1)",
1554
+ "--menu-item-hover": "rgba(0, 0, 0, 0.08)"
1538
1555
  };
1539
1556
  var DarkGlassTheme = {
1540
1557
  "--widget-margin": "12px",
@@ -1550,7 +1567,13 @@ var DarkGlassTheme = {
1550
1567
  "--button-text": "rgb(215, 214, 229, 1)",
1551
1568
  "--icon-compass-north-color": "rgb(240, 92, 68)",
1552
1569
  "--icon-compass-south-color": "rgb(200, 199, 209)",
1553
- "--menu-gap": "4px"
1570
+ "--menu-gap": "4px",
1571
+ "--menu-background": "rgba(18, 18, 20, 0.75)",
1572
+ "--menu-backdrop-filter": "blur(4px)",
1573
+ "--menu-border": "1px solid rgba(18, 18, 20, 0.75)",
1574
+ "--menu-shadow": "0px 0px 8px 0px rgba(0, 0, 0, 0.25), 0px 0px 8px 0px rgba(0, 0, 0, 0.1) inset",
1575
+ "--menu-text": "rgb(215, 214, 229, 1)",
1576
+ "--menu-item-hover": "rgba(255, 255, 255, 0.1)"
1554
1577
  };
1555
1578
 
1556
1579
  // dist/theme-widget.js