@maplat/ui 0.11.4 → 0.11.5

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/src/ui_marker.ts CHANGED
@@ -29,7 +29,8 @@ import type { MarkerData, MediaSetting, MediaObject } from "./types";
29
29
  export function poiWebControl(
30
30
  ui: MaplatUi,
31
31
  div: HTMLElement,
32
- data: MarkerData
32
+ data: MarkerData,
33
+ showShare: boolean = true
33
34
  ) {
34
35
  // let poiSwiper: SwiperInstance | undefined;
35
36
  div.innerHTML = "";
@@ -113,15 +114,15 @@ export function poiWebControl(
113
114
  }
114
115
 
115
116
  // Map other attributes
116
- Object.keys(mediaObj).forEach(key => {
117
- if (["src", "type", "thumbnail", "desc"].includes(key)) return;
117
+ for (const key of Object.keys(mediaObj)) {
118
+ if (["src", "type", "thumbnail", "desc"].includes(key)) continue;
118
119
  const val = mediaObj[key];
119
120
  if (typeof val === "boolean") {
120
121
  if (val) slideAttrs += ` ${key}`;
121
122
  } else if (val !== undefined && val !== null) {
122
123
  slideAttrs += ` ${key}="${val}"`;
123
124
  }
124
- });
125
+ }
125
126
 
126
127
  slides.push(`<cc-swiper-slide ${slideAttrs}></cc-swiper-slide>`);
127
128
  });
@@ -153,6 +154,36 @@ export function poiWebControl(
153
154
  (htmlDiv.querySelector(".poi_desc") as HTMLElement).innerHTML = (
154
155
  ui.core!.translate(data.desc) || ""
155
156
  ).replace(/\n/g, "<br>");
157
+
158
+ // Show/hide share buttons based on showShare parameter
159
+ const shareButtons =
160
+ ui.core!.mapDivDocument!.querySelector(".poi_share_buttons");
161
+ const qrDiv = ui.core!.mapDivDocument!.querySelector(".qr_view_poi");
162
+
163
+ if (showShare) {
164
+ shareButtons?.classList.remove("hide");
165
+ qrDiv?.classList.remove("hide");
166
+
167
+ // Auto-generate QR code
168
+ if (qrDiv) {
169
+ import("qrcode").then(QRCode => {
170
+ QRCode.toCanvas(
171
+ window.location.href,
172
+ { width: 128, margin: 1 },
173
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174
+ (err: any, canvas: any) => {
175
+ if (!err) {
176
+ qrDiv.innerHTML = "";
177
+ qrDiv.appendChild(canvas);
178
+ }
179
+ }
180
+ );
181
+ });
182
+ }
183
+ } else {
184
+ shareButtons?.classList.add("hide");
185
+ qrDiv?.classList.add("hide");
186
+ }
156
187
  }
157
188
 
158
189
  return undefined;
@@ -204,18 +235,26 @@ export function handleMarkerAction(ui: MaplatUi, data: MarkerData) {
204
235
  }
205
236
  }
206
237
 
207
- poiWebControl(ui, poiWebDiv as HTMLElement, data);
238
+ // Show share buttons only if both enableShare and stateUrl are true
239
+ const showShare = ui.enableShare && !!ui.appOption.stateUrl;
240
+ poiWebControl(ui, poiWebDiv as HTMLElement, data, showShare);
208
241
 
209
242
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
210
243
  const hiddenFunc = (_event: any) => {
211
244
  modalElm.removeEventListener("hidden.bs.modal", hiddenFunc, false);
212
- ui.core!.unselectMarker();
245
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
246
+ (ui.core as any).unselectMarker?.();
247
+ ui.selectedMarkerNamespaceID = undefined;
248
+ ui.updateUrl();
213
249
  };
214
250
  modalElm.addEventListener("hidden.bs.modal", hiddenFunc, false);
215
251
 
216
- ui.core!.selectMarker(data.namespaceID);
252
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
+ (ui.core as any).selectMarker?.(data.namespaceID);
254
+ ui.selectedMarkerNamespaceID = data.namespaceID;
217
255
  ui.modalSetting("poi");
218
256
  modal.show();
257
+ ui.updateUrl();
219
258
  }
220
259
 
221
260
  export function showContextMenu(ui: MaplatUi, list: MarkerData[]) {
@@ -354,16 +393,14 @@ export function setHideMarker(ui: MaplatUi, flag: boolean) {
354
393
 
355
394
  export function checkOverlayID(ui: MaplatUi, mapID: string) {
356
395
  const swiper = ui.overlaySwiper;
357
- const sliders = swiper.$el[0].querySelectorAll(".swiper-slide");
358
- for (let i = 0; i < sliders.length; i++) {
359
- const slider = sliders[i];
360
- if (slider.getAttribute("data") === mapID) {
361
- return true;
362
- }
363
- }
364
- return false;
396
+ const sliders = Array.from(swiper.$el[0].querySelectorAll(".swiper-slide"));
397
+ return sliders.some(slider => slider.getAttribute("data") === mapID);
365
398
  }
366
399
 
367
- export function handleMarkerActionById(_ui: MaplatUi, markerId: string) {
368
- console.log(`Open marker: ${markerId}`);
400
+ export function handleMarkerActionById(ui: MaplatUi, markerId: string) {
401
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
+ const data = (ui.core as any).getMarker(markerId);
403
+ if (data) {
404
+ handleMarkerAction(ui, data);
405
+ }
369
406
  }
package/src/ui_utils.ts CHANGED
@@ -12,11 +12,11 @@ export function prepareModal(modalElm: Element | HTMLElement, options?: any) {
12
12
 
13
13
  if (!el.hasAttribute(MODAL_CLOSE_ATTACHED)) {
14
14
  const closeBtns = el.querySelectorAll(".close, .modal-footer button");
15
- for (let i = 0; i < closeBtns.length; i++) {
16
- closeBtns[i].addEventListener("click", () => {
15
+ closeBtns.forEach(btn => {
16
+ btn.addEventListener("click", () => {
17
17
  modal.hide();
18
18
  });
19
- }
19
+ });
20
20
  el.setAttribute(MODAL_CLOSE_ATTACHED, "true");
21
21
  }
22
22
 
@@ -85,11 +85,11 @@ export function ellips(mapDivDocument: HTMLElement) {
85
85
  }
86
86
  };
87
87
  const swiperItems = mapDivDocument.querySelectorAll(".swiper-slide div");
88
- for (let i = 0; i < swiperItems.length; i++) {
89
- const swiperItem = swiperItems[i] as HTMLElement;
88
+ swiperItems.forEach(item => {
89
+ const swiperItem = item as HTMLElement;
90
90
  stringSplit(swiperItem);
91
91
  omitCheck(swiperItem);
92
- }
92
+ });
93
93
  }
94
94
 
95
95
  export function isMaplatSource(source: unknown): source is {