@mapka/maplibre-gl-sdk 0.16.3 → 0.16.4

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.
@@ -1,5 +1,9 @@
1
+ import { useState } from "preact/hooks";
1
2
  import type { MapkaPopupOptionsResolved } from "../types/popup.js";
2
- import { PopupListItem } from "./PopupListItem.js";
3
+ import { PopupContent } from "./PopupContent.js";
4
+ import { ChevronUpIcon } from "./icons/ChevronUpIcon.js";
5
+ import { ChevronDownIcon } from "./icons/ChevronDownIcon.js";
6
+ import { noop } from "es-toolkit";
3
7
 
4
8
  interface PopupCollectionProps {
5
9
  items: MapkaPopupOptionsResolved[];
@@ -9,19 +13,90 @@ export function PopupCustomElement({ popup }: { popup: HTMLElement }) {
9
13
  return popup;
10
14
  }
11
15
 
16
+ interface PopupListNavProps {
17
+ index: number;
18
+ total: number;
19
+ onPrev: (e: Event) => void;
20
+ onNext: (e: Event) => void;
21
+ }
22
+
23
+ function PopupListNav({ index, total, onPrev, onNext }: PopupListNavProps) {
24
+ const isFirst = index === 0;
25
+ const isLast = index === total - 1;
26
+
27
+ return (
28
+ <div class="mapka-popup-list-nav">
29
+ <button
30
+ type="button"
31
+ class="mapka-popup-list-nav-btn"
32
+ onClick={onPrev}
33
+ disabled={isFirst}
34
+ aria-label="Previous popup"
35
+ >
36
+ <ChevronUpIcon />
37
+ </button>
38
+ <div class="mapka-popup-list-nav-counter">
39
+ <span>{index + 1}</span>
40
+ <span class="mapka-popup-list-nav-counter-divider" />
41
+ <span>{total}</span>
42
+ </div>
43
+ <button
44
+ type="button"
45
+ class="mapka-popup-list-nav-btn"
46
+ onClick={onNext}
47
+ disabled={isLast}
48
+ aria-label="Next popup"
49
+ >
50
+ <ChevronDownIcon />
51
+ </button>
52
+ </div>
53
+ );
54
+ }
55
+
12
56
  export function PopupList({ items }: PopupCollectionProps) {
57
+ const [index, setIndex] = useState(0);
58
+ const safeIndex = Math.min(index, items.length - 1);
59
+
60
+ const handlePrev = (e: Event) => {
61
+ e.stopPropagation();
62
+ if (safeIndex > 0) {
63
+ setIndex(safeIndex - 1);
64
+ }
65
+ };
66
+
67
+ const handleNext = (e: Event) => {
68
+ e.stopPropagation();
69
+ if (safeIndex < items.length - 1) {
70
+ setIndex(safeIndex + 1);
71
+ }
72
+ };
73
+ const { id, content } = items[safeIndex];
13
74
  return (
14
75
  <div class="mapka-popup-list-wrapper">
15
76
  <div class="mapka-popup-list">
16
- {items.map(({ content, id }) =>
17
- content instanceof HTMLElement ? (
18
- <PopupCustomElement key={id} popup={content} />
19
- ) : (
20
- <PopupListItem key={id} popup={content} />
21
- ),
77
+ {content instanceof HTMLElement ? (
78
+ <PopupCustomElement key={id} popup={content} />
79
+ ) : (
80
+ <PopupContent
81
+ key={id}
82
+ title={content.title}
83
+ description={content.description}
84
+ rows={content.rows}
85
+ imageUrls={content.imageUrls}
86
+ primaryAction={content.primaryAction}
87
+ closeButton={false}
88
+ onClose={noop}
89
+ />
22
90
  )}
23
91
  </div>
24
- <div class="mapka-popup-list-gradient" />
92
+ {items.length > 1 && (
93
+ <PopupListNav
94
+ index={safeIndex}
95
+ total={items.length}
96
+ onPrev={handlePrev}
97
+ onNext={handleNext}
98
+ />
99
+ )}
25
100
  </div>
26
101
  );
27
102
  }
@@ -0,0 +1,20 @@
1
+ export function ChevronDownIcon() {
2
+ return (
3
+ <svg
4
+ viewBox="0 0 16 16"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ aria-hidden="true"
7
+ focusable="false"
8
+ class="mapka-popup-icon mapka-popup-icon-sm"
9
+ >
10
+ <path
11
+ d="M3 6 7.3 10.3a1 1 0 0 0 1.4 0L13 6"
12
+ fill="none"
13
+ stroke="currentColor"
14
+ stroke-width="1.5"
15
+ stroke-linecap="round"
16
+ stroke-linejoin="round"
17
+ />
18
+ </svg>
19
+ );
20
+ }
@@ -0,0 +1,20 @@
1
+ export function ChevronUpIcon() {
2
+ return (
3
+ <svg
4
+ viewBox="0 0 16 16"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ aria-hidden="true"
7
+ focusable="false"
8
+ class="mapka-popup-icon mapka-popup-icon-sm"
9
+ >
10
+ <path
11
+ d="M3 10 7.3 5.7a1 1 0 0 1 1.4 0L13 10"
12
+ fill="none"
13
+ stroke="currentColor"
14
+ stroke-width="1.5"
15
+ stroke-linecap="round"
16
+ stroke-linejoin="round"
17
+ />
18
+ </svg>
19
+ );
20
+ }
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  /* Draw Control Styles */
4
2
  .mapka-draw-control {
5
3
  display: flex;
@@ -50,4 +48,4 @@
50
48
  .mapka-draw-control-button--clear:hover {
51
49
  background-color: #fee2e2;
52
50
  color: #dc2626;
53
- }
51
+ }
package/src/map.ts CHANGED
@@ -87,7 +87,13 @@ export class MapkaMap extends maplibregl.Map {
87
87
  public scrollPopups: boolean = true;
88
88
  public popups: MapMapkaPopup[] = [];
89
89
 
90
- public constructor({ transformRequest, apiKey, maxPopups = 1, scrollPopups = true, ...options }: MapkaMapOptions) {
90
+ public constructor({
91
+ transformRequest,
92
+ apiKey,
93
+ maxPopups = 1,
94
+ scrollPopups = true,
95
+ ...options
96
+ }: MapkaMapOptions) {
91
97
  super({
92
98
  ...options,
93
99
  transformRequest: createTransformRequest(apiKey, transformRequest),
@@ -58,7 +58,6 @@ function clustersByLocation(
58
58
  });
59
59
  }
60
60
  }
61
-
62
61
  return clusters;
63
62
  }
64
63
 
package/src/styles.css CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  @import "./components/ImageCarousel.css";
4
4
  @import "./components/PopupList.css";
5
- @import "./components/PopupListItem.css";
6
5
  @import "./components/PopupDataRows.css";
7
6
  @import "./components/PopupContent.css";
8
7
  @import "./controls/MapkaDrawControl.css";
@@ -1,13 +0,0 @@
1
- import type { MapkaPopupContent } from "../types/popup.js";
2
- interface PopupHeaderProps {
3
- title?: string;
4
- description?: string;
5
- imageUrls: string[];
6
- }
7
- export declare function PopupHeader({ title, description, imageUrls: [firstImage] }: PopupHeaderProps): import("preact").JSX.Element;
8
- interface PopupCollectionItemProps {
9
- popup: MapkaPopupContent;
10
- }
11
- export declare function PopupListItem({ popup: { title, description, rows, imageUrls }, }: PopupCollectionItemProps): import("preact").JSX.Element;
12
- export {};
13
- //# sourceMappingURL=PopupListItem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PopupListItem.d.ts","sourceRoot":"","sources":["../../src/components/PopupListItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,gBAAgB,gCAW5F;AAED,UAAU,wBAAwB;IAChC,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAS,EAAE,SAAc,EAAE,GACzD,EAAE,wBAAwB,gCAW1B"}
@@ -1,11 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { PopupDataRows } from "./PopupDataRows.js";
3
- export function PopupHeader({ title, description, imageUrls: [firstImage] }) {
4
- return (_jsxs("div", { class: "mapka-popup-list-item-header", children: [firstImage && _jsx("img", { src: firstImage, alt: title, class: "mapka-popup-list-item-image" }), _jsxs("div", { class: "mapka-popup-list-item-info", children: [title && _jsx("span", { class: "mapka-popup-list-item-title", children: title }), description && _jsx("span", { class: "mapka-popup-list-item-description", children: description })] })] }));
5
- }
6
- export function PopupListItem({ popup: { title, description, rows = [], imageUrls = [] }, }) {
7
- const hasImages = Boolean(imageUrls.length);
8
- const hasHeader = Boolean(title || description || hasImages);
9
- const hasDataRows = Boolean(rows.length);
10
- return (_jsxs("div", { class: "mapka-popup-list-item", children: [hasHeader && _jsx(PopupHeader, { title: title, description: description, imageUrls: imageUrls }), hasDataRows && _jsx(PopupDataRows, { rows: rows })] }));
11
- }
@@ -1,61 +0,0 @@
1
- .mapka-popup-list-item {
2
- display: flex;
3
- flex-direction: column;
4
- gap: 4px;
5
- background: #fff;
6
- border-radius: 8px;
7
- overflow: hidden;
8
- cursor: pointer;
9
- }
10
-
11
- .mapka-popup-list-item + .mapka-popup-list-item {
12
- border-top: 1px solid #dcdfe3;
13
- padding-top: 8px;
14
- }
15
-
16
- .mapka-popup-list-item-header {
17
- display: flex;
18
- flex-direction: row;
19
- height: 90px;
20
- overflow: hidden;
21
- border-radius: 8px;
22
- }
23
-
24
- .mapka-popup-list-item-image {
25
- width: 90px;
26
- height: 90px;
27
- border-radius: 8px;
28
- object-fit: cover;
29
- flex-shrink: 0;
30
- background: #ccd1d6;
31
- }
32
-
33
- .mapka-popup-list-item-info {
34
- display: flex;
35
- flex-direction: column;
36
- gap: 4px;
37
- flex: 1;
38
- padding: 4px 4px 4px 8px;
39
- min-width: 0;
40
- }
41
-
42
- .mapka-popup-list-item-title {
43
- margin: 0;
44
- font-weight: 700;
45
- font-size: 16px;
46
- line-height: 20px;
47
- color: #4f4f4f;
48
- }
49
-
50
- .mapka-popup-list-item-description {
51
- margin: 0;
52
- font-weight: 400;
53
- font-size: 12px;
54
- line-height: 16px;
55
- color: #4f4f4f;
56
- overflow: hidden;
57
- display: -webkit-box;
58
- -webkit-line-clamp: 3;
59
- line-clamp: 3;
60
- -webkit-box-orient: vertical;
61
- }
@@ -1,40 +0,0 @@
1
- import { PopupDataRows } from "./PopupDataRows.js";
2
- import type { MapkaPopupContent } from "../types/popup.js";
3
-
4
- interface PopupHeaderProps {
5
- title?: string;
6
- description?: string;
7
- imageUrls: string[];
8
- }
9
-
10
- export function PopupHeader({ title, description, imageUrls: [firstImage] }: PopupHeaderProps) {
11
- return (
12
- <div class="mapka-popup-list-item-header">
13
- {firstImage && <img src={firstImage} alt={title} class="mapka-popup-list-item-image" />}
14
-
15
- <div class="mapka-popup-list-item-info">
16
- {title && <span class="mapka-popup-list-item-title">{title}</span>}
17
- {description && <span class="mapka-popup-list-item-description">{description}</span>}
18
- </div>
19
- </div>
20
- );
21
- }
22
-
23
- interface PopupCollectionItemProps {
24
- popup: MapkaPopupContent;
25
- }
26
-
27
- export function PopupListItem({
28
- popup: { title, description, rows = [], imageUrls = [] },
29
- }: PopupCollectionItemProps) {
30
- const hasImages = Boolean(imageUrls.length);
31
- const hasHeader = Boolean(title || description || hasImages);
32
- const hasDataRows = Boolean(rows.length);
33
-
34
- return (
35
- <div class="mapka-popup-list-item">
36
- {hasHeader && <PopupHeader title={title} description={description} imageUrls={imageUrls} />}
37
- {hasDataRows && <PopupDataRows rows={rows} />}
38
- </div>
39
- );
40
- }