@kiva/kv-components 8.5.6 → 8.6.1

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,4 +1,4 @@
1
- import { toRefs as h, ref as r, nextTick as k, computed as x, watch as S, onMounted as C, onBeforeUnmount as B } from "vue";
1
+ import { toRefs as h, ref as u, nextTick as k, computed as x, watch as S, onMounted as C, onBeforeUnmount as B } from "vue";
2
2
  import { mdiClose as E } from "@mdi/js";
3
3
  import { useFocusTrap as L } from "@vueuse/integrations/useFocusTrap";
4
4
  import { hideOthers as w } from "../vendor/aria-hidden/dist/es2015/index.js";
@@ -57,16 +57,16 @@ const A = {
57
57
  ],
58
58
  setup(v, { emit: g }) {
59
59
  const {
60
- visible: u,
60
+ visible: o,
61
61
  variant: d,
62
62
  preventClose: p
63
- } = h(v), o = r(null), t = r(null), m = r(null), a = r(null), i = r(null);
63
+ } = h(v), n = u(null), t = u(null), m = u(null), a = u(null), i = u(null);
64
64
  k(() => {
65
65
  const {
66
66
  activate: e,
67
67
  deactivate: l
68
68
  } = L([
69
- o.value,
69
+ n.value,
70
70
  // This lightbox
71
71
  '[role="alert"]'
72
72
  // Any open toasts/alerts on the page
@@ -77,36 +77,36 @@ const A = {
77
77
  a.value = e, i.value = l;
78
78
  });
79
79
  let c = null, s = null;
80
- const b = x(() => d.value === "alert" ? "alertdialog" : "dialog"), n = (e = "") => {
80
+ const b = x(() => d.value === "alert" ? "alertdialog" : "dialog"), r = (e = "") => {
81
81
  var l;
82
- o.value && t.value && ((l = i.value) == null || l.call(i), t.value.scrollTop = 0, I(t.value)), P(), c && (c(), c = null), document.removeEventListener("keyup", s), g("lightbox-closed", { type: e });
82
+ n.value && t.value && ((l = i.value) == null || l.call(i), t.value.scrollTop = 0, I(t.value)), P(), c && (c(), c = null), document.removeEventListener("keyup", s), o.value && g("lightbox-closed", { type: e });
83
83
  };
84
84
  s = (e) => {
85
- e && e.key === "Escape" && !p.value && n();
85
+ e && e.key === "Escape" && !p.value && r();
86
86
  };
87
87
  const y = () => {
88
- p.value || n("background-click");
88
+ p.value || r("background-click");
89
89
  }, f = () => {
90
- u.value && (document.addEventListener("keyup", s), k(() => {
90
+ o.value && (document.addEventListener("keyup", s), k(() => {
91
91
  var e;
92
- if (o.value && t.value && ((e = a.value) == null || e.call(a), c = w(o.value), K(t.value)), q(), d.value === "alert") {
92
+ if (n.value && t.value && ((e = a.value) == null || e.call(a), c = w(n.value), K(t.value)), q(), d.value === "alert") {
93
93
  const l = m.value.querySelector("button");
94
94
  l && l.focus();
95
95
  }
96
96
  }));
97
97
  };
98
- return S(u, () => {
99
- u.value ? f() : n();
98
+ return S(o, () => {
99
+ o.value ? f() : r();
100
100
  }), C(() => {
101
- u.value && f();
102
- }), B(() => n()), {
101
+ o.value && f();
102
+ }), B(() => r()), {
103
103
  mdiClose: E,
104
104
  role: b,
105
- kvLightbox: o,
105
+ kvLightbox: n,
106
106
  kvLightboxBody: t,
107
107
  onKeyUp: s,
108
108
  onScreenClick: y,
109
- hide: n,
109
+ hide: r,
110
110
  show: f,
111
111
  controlsRef: m
112
112
  };
@@ -83,7 +83,8 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
83
83
  mapLibreReady: boolean;
84
84
  mapLoaded: boolean;
85
85
  zoomActive: boolean;
86
- countriesBorders: {};
86
+ countriesBorders: any;
87
+ countriesBordersPromise: any;
87
88
  }, {
88
89
  mapDimensions(): {
89
90
  height: string;
@@ -104,7 +105,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
104
105
  destroyWrapperObserver(): void;
105
106
  checkWebGL(): boolean;
106
107
  initializeMap(): void;
107
- initializeLeaflet(): void;
108
+ initializeLeaflet(): Promise<void>;
108
109
  initializeMapLibre(): void;
109
110
  animateMap(): void;
110
111
  checkIntersectionObserverSupport(): boolean;
@@ -117,6 +118,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
117
118
  loaded: boolean;
118
119
  }>;
119
120
  getCountriesData(): any;
121
+ ensureCountriesBordersLoaded(): any;
120
122
  countryStyle(feature: any): {
121
123
  color: any;
122
124
  fillColor: string;
@@ -1,6 +1,6 @@
1
- import o from "@kiva/kv-tokens";
2
- import { computeMapCenter as l, computeMapZoom as h, generateMapMarkers as c, animationCoordinator as m, getCountryColor as r } from "../utils/mapUtils.js";
3
- const f = {
1
+ import r from "@kiva/kv-tokens";
2
+ import { computeMapCenter as l, computeMapZoom as h, generateMapMarkers as c, animationCoordinator as u, getCountryColor as n } from "../utils/mapUtils.js";
3
+ const p = {
4
4
  name: "KvMap",
5
5
  props: {
6
6
  /**
@@ -173,13 +173,14 @@ const f = {
173
173
  mapLibreReady: !1,
174
174
  mapLoaded: !1,
175
175
  zoomActive: !1,
176
- countriesBorders: {}
176
+ countriesBorders: null,
177
+ countriesBordersPromise: null
177
178
  };
178
179
  },
179
180
  computed: {
180
181
  mapDimensions() {
181
- var a;
182
- const e = (a = this.$el) == null ? void 0 : a.getBoundingClientRect(), t = e ? `${e.width / this.aspectRatio}px` : "300px", i = e ? `${e.width}px` : "100%";
182
+ var s;
183
+ const e = (s = this.$el) == null ? void 0 : s.getBoundingClientRect(), t = e ? `${e.width / this.aspectRatio}px` : "300px", i = e ? `${e.width}px` : "100%";
183
184
  return {
184
185
  height: this.height ? `${this.height}px` : t,
185
186
  width: this.width ? `${this.width}px` : i,
@@ -226,8 +227,8 @@ const f = {
226
227
  t === null && this.effectiveLat !== null && !this.mapLibreReady && !this.leafletReady && this.initializeMap();
227
228
  },
228
229
  countriesData: {
229
- handler() {
230
- this.optimizeInitialMapZoom && !this.mapLibreReady && !this.leafletReady && this.initializeMap();
230
+ handler(e) {
231
+ e != null && e.length && this.ensureCountriesBordersLoaded(), this.optimizeInitialMapZoom && !this.mapLibreReady && !this.leafletReady && this.initializeMap();
231
232
  },
232
233
  deep: !0
233
234
  },
@@ -235,22 +236,23 @@ const f = {
235
236
  this.mapInstance && (this.mapInstance.remove(), this.initializeLeaflet());
236
237
  }
237
238
  },
238
- async mounted() {
239
- this.countriesData && (this.countriesBorders = await import("../data/ne_110m_admin_0_countries.json.js")), !this.mapLibreReady && !this.leafletReady && this.initializeMap();
239
+ mounted() {
240
+ var e;
241
+ (e = this.countriesData) != null && e.length && this.ensureCountriesBordersLoaded(), !this.mapLibreReady && !this.leafletReady && this.initializeMap();
240
242
  },
241
243
  beforeDestroy() {
242
244
  this.mapInstance && (!this.hasWebGL && !this.leafletReady && this.mapInstance.off(), this.mapInstance.remove()), this.destroyWrapperObserver();
243
245
  },
244
246
  methods: {
245
247
  activateZoom(e = !1) {
246
- const { mapInstance: t, hasWebGL: i, mapLibreReady: a } = this, s = t.getZoom();
247
- if (!e && s === this.effectiveZoomLevel || e && s === this.initialZoom) return !1;
248
+ const { mapInstance: t, hasWebGL: i, mapLibreReady: s } = this, a = t.getZoom();
249
+ if (!e && a === this.effectiveZoomLevel || e && a === this.initialZoom) return !1;
248
250
  this.zoomActive = !0;
249
- const n = window.setTimeout(() => {
250
- i && a ? t.zoomTo(
251
+ const o = window.setTimeout(() => {
252
+ i && s ? t.zoomTo(
251
253
  e ? this.initialZoom : this.effectiveZoomLevel,
252
254
  { duration: 1200 }
253
- ) : t.setZoom(e ? this.initialZoom : this.effectiveZoomLevel), clearTimeout(n), this.zoomActive = !1;
255
+ ) : t.setZoom(e ? this.initialZoom : this.effectiveZoomLevel), clearTimeout(o), this.zoomActive = !1;
254
256
  }, this.autoZoomDelay);
255
257
  },
256
258
  createWrapperObserver() {
@@ -259,8 +261,8 @@ const f = {
259
261
  targets: [(e = this.$refs) == null ? void 0 : e[this.refString]],
260
262
  callback: (t) => {
261
263
  t.forEach((i) => {
262
- var a, s;
263
- i.target === ((a = this.$refs) == null ? void 0 : a[this.refString]) && !this.zoomActive && i.intersectionRatio > 0 && (this.initialZoom !== null && this.activateZoom(), (s = this.advancedAnimation) != null && s.borrowerPoints && this.animateMap());
264
+ var s, a;
265
+ i.target === ((s = this.$refs) == null ? void 0 : s[this.refString]) && !this.zoomActive && i.intersectionRatio > 0 && (this.initialZoom !== null && this.activateZoom(), (a = this.advancedAnimation) != null && a.borrowerPoints && this.animateMap());
264
266
  });
265
267
  }
266
268
  });
@@ -281,7 +283,7 @@ const f = {
281
283
  i.loaded && !this.mapLoaded && this.effectiveLat != null && this.effectiveLong != null && (this.initializeLeaflet(), this.leafletReady = !0);
282
284
  })), document.head.appendChild(e), document.head.appendChild(t);
283
285
  },
284
- initializeLeaflet() {
286
+ async initializeLeaflet() {
285
287
  this.mapInstance = L.map(`kv-map-holder-${this.mapId}`, {
286
288
  center: [this.effectiveLat, this.effectiveLong],
287
289
  zoom: this.initialZoom || this.effectiveZoomLevel,
@@ -290,7 +292,8 @@ const f = {
290
292
  zoomControl: this.showZoomControl,
291
293
  scrollWheelZoom: !1,
292
294
  doubleClickZoom: !1,
293
- attributionControl: !1
295
+ attributionControl: !1,
296
+ worldCopyJump: !0
294
297
  });
295
298
  let e = "https://api.maptiler.com/maps/landscape/{z}/{x}/{y}.png?key=n1Mz5ziX3k6JfdjFe7mx";
296
299
  this.showLabels && (e = "https://api.maptiler.com/maps/bright/{z}/{x}/{y}.png?key=n1Mz5ziX3k6JfdjFe7mx"), L.tileLayer(e, {
@@ -298,7 +301,7 @@ const f = {
298
301
  zoomOffset: -1,
299
302
  minZoom: 1,
300
303
  crossOrigin: !0
301
- }).addTo(this.mapInstance), this.countriesData.length > 0 && (L.geoJson(
304
+ }).addTo(this.mapInstance), this.countriesData.length > 0 && (await this.ensureCountriesBordersLoaded(), this.countriesBorders && (L.geoJson(
302
305
  this.getCountriesData(),
303
306
  {
304
307
  style: this.countryStyle,
@@ -307,17 +310,17 @@ const f = {
307
310
  ).addTo(this.mapInstance), this.countriesData.forEach((t) => {
308
311
  if (t.numLoansFundraising > 0 && this.showFundraisingLoans) {
309
312
  const i = L.circle([t.lat, t.long], {
310
- color: o.colors.black,
313
+ color: r.colors.black,
311
314
  weight: 1,
312
- fillColor: o.colors.brand[900],
315
+ fillColor: r.colors.brand[900],
313
316
  fillOpacity: 1,
314
317
  radius: 13e4
315
- }).addTo(this.mapInstance), a = `Click to see ${t.numLoansFundraising} fundraising loans in ${t.label}`;
316
- i.bindTooltip(a), i.on("click", () => {
318
+ }).addTo(this.mapInstance), s = `Click to see ${t.numLoansFundraising} fundraising loans in ${t.label}`;
319
+ i.bindTooltip(s), i.on("click", () => {
317
320
  this.circleMapClicked(t.isoCode);
318
321
  });
319
322
  }
320
- })), this.mapLoaded = !0, this.initialZoom !== null && this.createWrapperObserver();
323
+ }))), this.mapLoaded = !0, this.initialZoom !== null && this.createWrapperObserver();
321
324
  },
322
325
  initializeMapLibre() {
323
326
  let e = "https://api.maptiler.com/maps/landscape/style.json?key=n1Mz5ziX3k6JfdjFe7mx";
@@ -340,7 +343,7 @@ const f = {
340
343
  this.mapInstance.style.stylesheet.layers.forEach((e) => {
341
344
  e.type === "symbol" && this.mapInstance.removeLayer(e.id);
342
345
  }), c(this.mapInstance, this.advancedAnimation.borrowerPoints), setTimeout(() => {
343
- m(this.mapInstance, this.advancedAnimation.borrowerPoints).then(() => {
346
+ u(this.mapInstance, this.advancedAnimation.borrowerPoints).then(() => {
344
347
  this.mapInstance.dragPan.enable(), this.mapInstance.scrollZoom.enable(), this.mapInstance.scrollZoom.enable(), this.mapInstance.easeTo({
345
348
  center: [this.effectiveLong, this.effectiveLat],
346
349
  zoom: this.initialZoom || this.effectiveZoomLevel
@@ -357,42 +360,50 @@ const f = {
357
360
  targets: i
358
361
  } = {}) {
359
362
  if (this.checkIntersectionObserverSupport()) {
360
- const a = new IntersectionObserver(e, t);
361
- return i.forEach((s) => a.observe(s)), a;
363
+ const s = new IntersectionObserver(e, t);
364
+ return i.forEach((a) => s.observe(a)), s;
362
365
  }
363
366
  },
364
367
  testDelayedGlobalLibrary(e, t = 3e3) {
365
- return new Promise((i, a) => {
366
- typeof window > "u" && a(new Error("window object not available"));
367
- let s;
368
- const n = window.setInterval(() => {
369
- typeof window[e] < "u" && (clearInterval(n), clearTimeout(s), i({ loaded: !0 }));
368
+ return new Promise((i, s) => {
369
+ typeof window > "u" && s(new Error("window object not available"));
370
+ let a;
371
+ const o = window.setInterval(() => {
372
+ typeof window[e] < "u" && (clearInterval(o), clearTimeout(a), i({ loaded: !0 }));
370
373
  }, 100);
371
- s = window.setTimeout(() => {
372
- clearInterval(n), clearTimeout(s), i({ loaded: !1 });
374
+ a = window.setTimeout(() => {
375
+ clearInterval(o), clearTimeout(a), i({ loaded: !1 });
373
376
  }, t);
374
377
  });
375
378
  },
376
379
  getCountriesData() {
377
- const e = this.countriesBorders.features ?? [];
378
- return e.forEach((t, i) => {
379
- const a = this.countriesData.find((s) => s.isoCode === t.properties.iso_a2);
380
- a && (e[i].lenderLoans = a.value, e[i].numLoansFundraising = a.numLoansFundraising);
381
- }), this.countriesBorders;
380
+ if (!this.countriesBorders)
381
+ return { type: "FeatureCollection", features: [] };
382
+ const e = this.countriesBorders, t = e.features ?? [];
383
+ return t.forEach((i, s) => {
384
+ const a = this.countriesData.find((o) => o.isoCode === i.properties.iso_a2);
385
+ a && (t[s].lenderLoans = a.value, t[s].numLoansFundraising = a.numLoansFundraising);
386
+ }), e;
387
+ },
388
+ ensureCountriesBordersLoaded() {
389
+ return this.countriesBorders ? Promise.resolve(this.countriesBorders) : (this.countriesBordersPromise || (this.countriesBordersPromise = import("../data/ne_110m_admin_0_countries.json.js").then((e) => {
390
+ const t = e.default ?? e;
391
+ return JSON.parse(JSON.stringify(t));
392
+ }).then((e) => (this.countriesBorders = e, this.countriesBorders)).catch(() => (this.countriesBordersPromise = null, null))), this.countriesBordersPromise);
382
393
  },
383
394
  countryStyle(e) {
384
395
  return {
385
- color: o.colors.white,
396
+ color: r.colors.white,
386
397
  // eslint-disable-next-line max-len
387
- fillColor: r(e.lenderLoans, this.countriesData, o, this.defaultBaseColor),
398
+ fillColor: n(e.lenderLoans, this.countriesData, r, this.defaultBaseColor),
388
399
  weight: 1,
389
400
  fillOpacity: 1
390
401
  };
391
402
  },
392
403
  onEachCountryFeature(e, t) {
393
404
  if (!this.showTooltips) return;
394
- const i = e.lenderLoans ? `${e.lenderLoans} loan${e.lenderLoans > 1 ? "s" : ""}` : "0 loans", a = `${e.properties.name} <br/> ${i}`;
395
- t.bindTooltip(a, {
405
+ const i = e.lenderLoans ? `${e.lenderLoans} loan${e.lenderLoans > 1 ? "s" : ""}` : "0 loans", s = `${e.properties.name} <br/> ${i}`;
406
+ t.bindTooltip(s, {
396
407
  sticky: !0
397
408
  }), t.on({
398
409
  mouseover: this.highlightFeature,
@@ -401,14 +412,14 @@ const f = {
401
412
  },
402
413
  highlightFeature(e) {
403
414
  e.target.setStyle({
404
- fillColor: o.colors.gray[500]
415
+ fillColor: r.colors.gray[500]
405
416
  });
406
417
  },
407
418
  resetHighlight(e) {
408
419
  const t = e.target, { feature: i } = t;
409
420
  t.setStyle({
410
421
  // eslint-disable-next-line max-len
411
- fillColor: r(i.lenderLoans, this.countriesData, o, this.defaultBaseColor)
422
+ fillColor: n(i.lenderLoans, this.countriesData, r, this.defaultBaseColor)
412
423
  });
413
424
  },
414
425
  circleMapClicked(e) {
@@ -417,5 +428,5 @@ const f = {
417
428
  }
418
429
  };
419
430
  export {
420
- f as default
431
+ p as default
421
432
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "8.5.6",
3
+ "version": "8.6.1",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -125,5 +125,5 @@
125
125
  "embla-carousel-fade",
126
126
  "popper.js"
127
127
  ],
128
- "gitHead": "f5556880afcdae5bef45601e29353e5c9406160f"
128
+ "gitHead": "b6dac1744af7425bf3691ef1cbf3d67b156e18f6"
129
129
  }