declarative-ui-core 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +97 -85
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs as v, jsx as r } from "react/jsx-runtime";
2
- import { useRef as T, useState as D, useEffect as C, useMemo as j } from "react";
2
+ import { useRef as T, useState as O, useEffect as C, useMemo as j } from "react";
3
3
  import P from "maplibre-gl";
4
4
  import J from "react-markdown";
5
5
  import F from "mermaid";
@@ -87,7 +87,7 @@ function Y({ page: i, componentId: t, component: e }) {
87
87
  ] });
88
88
  }
89
89
  function I() {
90
- const i = T(null), [t, e] = D({ width: 0, height: 0 });
90
+ const i = T(null), [t, e] = O({ width: 0, height: 0 });
91
91
  return C(() => {
92
92
  const n = i.current;
93
93
  if (!n) return;
@@ -100,7 +100,7 @@ function I() {
100
100
  return l.observe(n), () => l.disconnect();
101
101
  }, []), { ref: i, size: t };
102
102
  }
103
- function q(i, t) {
103
+ function E(i, t) {
104
104
  if (!t) return;
105
105
  const e = i.setProjection;
106
106
  if (typeof e != "function") return;
@@ -193,12 +193,25 @@ function H(i, t) {
193
193
  layers: h
194
194
  };
195
195
  }
196
- function E(i, t) {
196
+ function q(i, t) {
197
197
  const e = "data", n = "circle-data", l = W(t);
198
198
  console.log("[MapLibreGL] ensureDataSourceAndLayer called with", t.length, "rows"), console.log("[MapLibreGL] GeoJSON features:", l.features.length);
199
199
  try {
200
200
  const s = i.getSource(e) ?? null;
201
- s && typeof s.setData == "function" ? (console.log("[MapLibreGL] Updating existing source"), s.setData(l)) : (console.log("[MapLibreGL] Adding new source"), i.addSource(e, { type: "geojson", data: l }));
201
+ if (s && typeof s.setData == "function") {
202
+ console.log("[MapLibreGL] Updating existing source");
203
+ try {
204
+ s.setData(l);
205
+ } catch (y) {
206
+ console.error("[MapLibreGL] Error in setData, trying to remove and re-add source:", y);
207
+ try {
208
+ i.removeSource(e);
209
+ } catch {
210
+ }
211
+ i.addSource(e, { type: "geojson", data: l });
212
+ }
213
+ } else
214
+ console.log("[MapLibreGL] Adding new source"), i.addSource(e, { type: "geojson", data: l });
202
215
  } catch (s) {
203
216
  console.error("[MapLibreGL] Error adding/updating source:", s);
204
217
  }
@@ -221,22 +234,22 @@ function E(i, t) {
221
234
  }
222
235
  }
223
236
  function Q({ page: i, componentId: t, component: e }) {
224
- const n = e.title ?? t, l = "circle-data", { ref: s, size: y } = I(), f = T(null), h = T([]), b = T(/* @__PURE__ */ new Map()), c = j(() => _(e.config), [e.config]), u = j(() => A(i, e.dataRef), [i, e.dataRef]), w = j(() => {
237
+ const n = e.title ?? t, l = "circle-data", { ref: s, size: y } = I(), f = T(null), h = T([]), b = T(/* @__PURE__ */ new Map()), c = j(() => _(e.config), [e.config]), u = j(() => A(i, e.dataRef), [i, e.dataRef]), k = j(() => {
225
238
  if (!u || u.length === 0) return null;
226
- let d = 1 / 0, a = 1 / 0, L = -1 / 0, p = -1 / 0;
239
+ let d = 1 / 0, a = 1 / 0, w = -1 / 0, p = -1 / 0;
227
240
  for (const m of u) {
228
- const k = typeof m.longitude == "number" ? m.longitude : typeof m.lng == "number" ? m.lng : typeof m.lon == "number" ? m.lon : void 0, M = typeof m.latitude == "number" ? m.latitude : typeof m.lat == "number" ? m.lat : void 0;
229
- typeof k != "number" || typeof M != "number" || !Number.isFinite(k) || !Number.isFinite(M) || (d = Math.min(d, k), a = Math.min(a, M), L = Math.max(L, k), p = Math.max(p, M));
241
+ const x = typeof m.longitude == "number" ? m.longitude : typeof m.lng == "number" ? m.lng : typeof m.lon == "number" ? m.lon : void 0, S = typeof m.latitude == "number" ? m.latitude : typeof m.lat == "number" ? m.lat : void 0;
242
+ typeof x != "number" || typeof S != "number" || !Number.isFinite(x) || !Number.isFinite(S) || (d = Math.min(d, x), a = Math.min(a, S), w = Math.max(w, x), p = Math.max(p, S));
230
243
  }
231
- return !Number.isFinite(d) || !Number.isFinite(a) || !Number.isFinite(L) || !Number.isFinite(p) ? null : [
244
+ return !Number.isFinite(d) || !Number.isFinite(a) || !Number.isFinite(w) || !Number.isFinite(p) ? null : [
232
245
  [d, a],
233
- [L, p]
246
+ [w, p]
234
247
  ];
235
248
  }, [u]), g = j(() => {
236
249
  if (!c.options) return;
237
250
  const { projection: d, ...a } = c.options;
238
251
  return a;
239
- }, [c.options]), x = j(() => {
252
+ }, [c.options]), L = j(() => {
240
253
  const d = c.options?.projection;
241
254
  if (typeof d == "string") return d;
242
255
  if (d && typeof d == "object" && typeof d.name == "string") return d.name;
@@ -245,7 +258,7 @@ function Q({ page: i, componentId: t, component: e }) {
245
258
  if (typeof a == "string") return a;
246
259
  if (a && typeof a == "object" && typeof a.name == "string") return a.name;
247
260
  if (a && typeof a == "object" && typeof a.type == "string") return a.type;
248
- }, [c.options, c.style]), S = typeof c.style == "string" && typeof x == "string", R = typeof c.style == "string" && Array.isArray(u) && u.length > 0, U = j(
261
+ }, [c.options, c.style]), M = typeof c.style == "string" && typeof L == "string", R = typeof c.style == "string" && Array.isArray(u) && u.length > 0, U = j(
249
262
  () => ({
250
263
  version: 8,
251
264
  sources: {},
@@ -253,12 +266,12 @@ function Q({ page: i, componentId: t, component: e }) {
253
266
  }),
254
267
  []
255
268
  ), N = (d) => {
256
- if (!S && !R) return;
257
- const a = c.style, L = b.current.get(a);
258
- if (L) {
269
+ if (!M && !R) return;
270
+ const a = c.style, w = b.current.get(a);
271
+ if (w) {
259
272
  try {
260
- let p = L;
261
- S && (p = { ...p ?? {}, projection: { type: x } }), R && e.dataRef && u && (p = H(p, u) ?? p), d.setStyle(p);
273
+ let p = w;
274
+ M && (p = { ...p ?? {}, projection: { type: L } }), R && e.dataRef && u && (p = H(p, u) ?? p), d.setStyle(p);
262
275
  } catch {
263
276
  }
264
277
  return;
@@ -266,85 +279,84 @@ function Q({ page: i, componentId: t, component: e }) {
266
279
  fetch(a).then((p) => p.json()).then((p) => {
267
280
  b.current.set(a, p);
268
281
  let m = p ?? {};
269
- S && (m = { ...m, projection: { type: x } }), R && e.dataRef && u && (m = H(m, u) ?? m);
282
+ M && (m = { ...m, projection: { type: L } }), R && e.dataRef && u && (m = H(m, u) ?? m);
270
283
  try {
271
284
  d.setStyle(m);
272
285
  } catch {
273
286
  }
274
287
  }).catch(() => {
275
288
  });
276
- }, z = j(() => {
289
+ }, $ = j(() => {
277
290
  if (c.style)
278
291
  return typeof c.style == "object" && c.style && e.dataRef && Array.isArray(u) && u.length > 0 ? H(c.style, u) ?? c.style : c.style;
279
292
  }, [c.style, e.dataRef, u]);
280
293
  return C(() => {
281
294
  const d = s.current;
282
- if (!d || !z) return;
295
+ if (!d || !$) return;
283
296
  if (!f.current) {
284
- const L = {
297
+ const w = {
285
298
  container: d,
286
- style: typeof z == "string" && (S || R) ? U : z,
299
+ style: typeof $ == "string" && (M || R) ? U : $,
287
300
  attributionControl: {},
288
301
  ...g ?? {}
289
- }, p = new P.Map(L);
302
+ }, p = new P.Map(w);
290
303
  N(p);
291
- const m = () => q(p, x);
304
+ const m = () => E(p, L);
292
305
  p.once("load", m), p.once("style.load", m), p.addControl(new P.NavigationControl({ visualizePitch: !0 }), "top-right");
293
- const k = () => {
294
- if (u && u.length > 0 && (E(p, u), !c.options?.center && c.options?.zoom === void 0 && w))
295
- try {
296
- p.fitBounds(w, { padding: 30, duration: 0, maxZoom: 12 });
297
- } catch {
298
- }
306
+ const x = () => {
307
+ u && u.length > 0 && setTimeout(() => {
308
+ if (p.isStyleLoaded() && (q(p, u), !c.options?.center && c.options?.zoom === void 0 && k))
309
+ try {
310
+ p.fitBounds(k, { padding: 30, duration: 0, maxZoom: 12 });
311
+ } catch {
312
+ }
313
+ }, 100);
299
314
  };
300
- return p.once("style.load", k), f.current = p, () => {
301
- h.current.forEach((M) => M.remove()), h.current = [], f.current = null, p.remove();
315
+ return p.on("style.load", x), p.once("load", x), f.current = p, () => {
316
+ h.current.forEach((S) => S.remove()), h.current = [], f.current = null, p.remove();
302
317
  };
303
318
  }
304
319
  const a = f.current;
305
- if (S || R)
320
+ if (M || R)
306
321
  N(a);
307
322
  else
308
323
  try {
309
- a.setStyle(z);
324
+ a.setStyle($);
310
325
  } catch {
311
326
  }
312
- if (x) {
313
- const L = () => q(a, x);
314
- a.once("style.load", L), a.once("render", L);
327
+ if (L) {
328
+ const w = () => E(a, L);
329
+ a.once("style.load", w), a.once("render", w);
315
330
  }
316
331
  if (c.options?.center && c.options?.zoom !== void 0)
317
332
  try {
318
333
  a.jumpTo({ center: c.options.center, zoom: c.options.zoom });
319
334
  } catch {
320
335
  }
321
- }, [z, g, s, x, R, S, u, w, c.options?.center, c.options?.zoom]), C(() => {
336
+ }, [$, g, s, L, R, M, u, k, c.options?.center, c.options?.zoom]), C(() => {
322
337
  const d = f.current;
323
338
  if (!d || !u || u.length === 0) return;
324
339
  const a = () => {
325
- if (console.log("[MapLibreGL] apply() called, isStyleLoaded:", d.isStyleLoaded()), E(d, u), !c.options?.center && c.options?.zoom === void 0 && w)
340
+ if (console.log("[MapLibreGL] apply() called, isStyleLoaded:", d.isStyleLoaded()), q(d, u), !c.options?.center && c.options?.zoom === void 0 && k)
326
341
  try {
327
- d.fitBounds(w, { padding: 30, duration: 0, maxZoom: 12 });
342
+ d.fitBounds(k, { padding: 30, duration: 0, maxZoom: 12 });
328
343
  } catch {
329
344
  }
345
+ }, w = [];
346
+ d.isStyleLoaded() && a();
347
+ const p = () => {
348
+ console.log("[MapLibreGL] style.load event fired"), setTimeout(a, 50);
349
+ }, m = () => {
350
+ console.log("[MapLibreGL] load event fired"), setTimeout(a, 50);
330
351
  };
331
- if (d.isStyleLoaded())
332
- a();
333
- else {
334
- const L = () => {
335
- console.log("[MapLibreGL] style.load event fired"), a();
336
- }, p = () => {
337
- console.log("[MapLibreGL] load event fired"), a();
338
- };
339
- d.once("style.load", L), d.once("load", p);
340
- const m = setTimeout(() => {
341
- d.isStyleLoaded() && (console.log("[MapLibreGL] Fallback timer applying data layer"), a());
342
- }, 1e3);
343
- return () => {
344
- clearTimeout(m);
345
- };
346
- }
347
- }, [u, w, c.options?.center, c.options?.zoom]), C(() => {
352
+ return d.once("style.load", p), d.once("load", m), [500, 1e3, 2e3, 3e3].forEach((x) => {
353
+ w.push(setTimeout(() => {
354
+ d.isStyleLoaded() && (console.log(`[MapLibreGL] Fallback timer (${x}ms) applying data layer`), a());
355
+ }, x));
356
+ }), () => {
357
+ w.forEach((x) => clearTimeout(x));
358
+ };
359
+ }, [u, k, c.options?.center, c.options?.zoom]), C(() => {
348
360
  const d = f.current;
349
361
  d && (y.width <= 0 || y.height <= 0 || d.resize());
350
362
  }, [y.width, y.height]), C(() => {
@@ -353,34 +365,34 @@ function Q({ page: i, componentId: t, component: e }) {
353
365
  const a = new P.Popup({
354
366
  closeButton: !1,
355
367
  closeOnClick: !1
356
- }), L = (k) => {
357
- if (!k.features || k.features.length === 0) return;
358
- const M = k.features[0], $ = M.properties ?? {}, B = $.name ?? $.region ?? $.title ?? $.label ?? $.description;
368
+ }), w = (x) => {
369
+ if (!x.features || x.features.length === 0) return;
370
+ const S = x.features[0], z = S.properties ?? {}, B = z.name ?? z.region ?? z.title ?? z.label ?? z.description;
359
371
  if (B) {
360
372
  d.getCanvas().style.cursor = "pointer";
361
- const Z = M.geometry.coordinates.slice();
373
+ const Z = S.geometry.coordinates.slice();
362
374
  a.setLngLat(Z).setHTML(`<div style="padding: 4px 8px; font-size: 13px;">${B}</div>`).addTo(d);
363
375
  }
364
376
  }, p = () => {
365
377
  d.getCanvas().style.cursor = "", a.remove();
366
378
  }, m = () => {
367
- d.getLayer(l) ? (d.on("mouseenter", l, L), d.on("mouseleave", l, p)) : d.once("styledata", m);
379
+ d.getLayer(l) ? (d.on("mouseenter", l, w), d.on("mouseleave", l, p)) : d.once("styledata", m);
368
380
  };
369
381
  return m(), () => {
370
- a.remove(), d && !d._removed && d.getLayer(l) && (d.off("mouseenter", l, L), d.off("mouseleave", l, p));
382
+ a.remove(), d && !d._removed && d.getLayer(l) && (d.off("mouseenter", l, w), d.off("mouseleave", l, p));
371
383
  };
372
384
  }, [u, l]), C(() => {
373
385
  const d = f.current;
374
386
  d && (h.current.forEach((a) => a.remove()), h.current = [], (c.markers ?? []).forEach((a) => {
375
387
  const p = a.shape === "circle" || typeof a.radius == "number" || typeof a.color == "string" ? document.createElement("div") : null;
376
388
  if (p) {
377
- const k = typeof a.radius == "number" && Number.isFinite(a.radius) ? Math.max(2, a.radius) : 8;
378
- p.style.width = `${k * 2}px`, p.style.height = `${k * 2}px`, p.style.borderRadius = "999px", p.style.background = typeof a.color == "string" ? a.color : "#2563eb", p.style.border = "2px solid #ffffff", p.style.boxShadow = "0 2px 10px rgba(0,0,0,0.25)";
389
+ const x = typeof a.radius == "number" && Number.isFinite(a.radius) ? Math.max(2, a.radius) : 8;
390
+ p.style.width = `${x * 2}px`, p.style.height = `${x * 2}px`, p.style.borderRadius = "999px", p.style.background = typeof a.color == "string" ? a.color : "#2563eb", p.style.border = "2px solid #ffffff", p.style.boxShadow = "0 2px 10px rgba(0,0,0,0.25)";
379
391
  }
380
392
  const m = new P.Marker(p ? { element: p } : void 0).setLngLat(a.lngLat);
381
393
  if (a.popup || a.name) {
382
- const k = a.popup ?? `<div style="font-size:12px"><strong>${a.name ?? ""}</strong></div>`;
383
- m.setPopup(new P.Popup({ offset: 20 }).setHTML(k));
394
+ const x = a.popup ?? `<div style="font-size:12px"><strong>${a.name ?? ""}</strong></div>`;
395
+ m.setPopup(new P.Popup({ offset: 20 }).setHTML(x));
384
396
  }
385
397
  m.addTo(d), h.current.push(m);
386
398
  }));
@@ -412,19 +424,19 @@ F.initialize({
412
424
  securityLevel: "loose"
413
425
  });
414
426
  function te({ page: i, componentId: t, component: e }) {
415
- const n = e.title ?? t, l = typeof e.config?.mermaid == "string" ? e.config.mermaid : "", s = T(null), [y, f] = D(1);
427
+ const n = e.title ?? t, l = typeof e.config?.mermaid == "string" ? e.config.mermaid : "", s = T(null), [y, f] = O(1);
416
428
  C(() => {
417
429
  if (!l || !s.current) return;
418
430
  (async () => {
419
431
  try {
420
- const w = `mermaid-${t}-${Date.now()}`, { svg: g } = await F.render(w, l);
432
+ const k = `mermaid-${t}-${Date.now()}`, { svg: g } = await F.render(k, l);
421
433
  if (s.current) {
422
434
  s.current.innerHTML = g;
423
- const x = s.current.querySelector("svg");
424
- x && (x.style.maxWidth = "100%", x.style.height = "auto");
435
+ const L = s.current.querySelector("svg");
436
+ L && (L.style.maxWidth = "100%", L.style.height = "auto");
425
437
  }
426
- } catch (w) {
427
- s.current && (s.current.innerHTML = `<div style="color: #dc2626; padding: 8px;">Error rendering diagram: ${w instanceof Error ? w.message : String(w)}</div>`);
438
+ } catch (k) {
439
+ s.current && (s.current.innerHTML = `<div style="color: #dc2626; padding: 8px;">Error rendering diagram: ${k instanceof Error ? k.message : String(k)}</div>`);
428
440
  }
429
441
  })();
430
442
  }, [l, t]);
@@ -544,9 +556,9 @@ function oe({ page: i, componentId: t, component: e }) {
544
556
  autosize: { type: "fit", contains: "padding" },
545
557
  width: Math.floor(s.width),
546
558
  height: Math.floor(s.height)
547
- } : b, u = n ? { ...c, data: { values: n } } : ne(c) ? { ...c, data: { values: [{}] } } : c, w = e.title === "" ? "" : e.title ?? t;
559
+ } : b, u = n ? { ...c, data: { values: n } } : ne(c) ? { ...c, data: { values: [{}] } } : c, k = e.title === "" ? "" : e.title ?? t;
548
560
  return /* @__PURE__ */ v("div", { style: o.panel, children: [
549
- w ? /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: w }) }) : null,
561
+ k ? /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: k }) }) : null,
550
562
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ r("div", { ref: l, style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ r(K, { spec: u, actions: !1 }) }) })
551
563
  ] });
552
564
  }
@@ -570,7 +582,7 @@ function G({ page: i, componentId: t, component: e }) {
570
582
  return /* @__PURE__ */ r(ie, { page: i, componentId: t, component: e });
571
583
  }
572
584
  }
573
- function O(i, t, e) {
585
+ function D(i, t, e) {
574
586
  return Math.min(e, Math.max(t, i));
575
587
  }
576
588
  function se(i) {
@@ -578,7 +590,7 @@ function se(i) {
578
590
  return { maxBottom: t, maxRight: e };
579
591
  }
580
592
  function Le({ page: i }) {
581
- const { ref: t, size: e } = I(), n = i.layout.cols ?? 24, l = i.layout.rowHeight ?? 30, s = i.layout.margin?.[0] ?? 10, y = i.layout.margin?.[1] ?? 10, f = i.layout.containerPadding?.[0] ?? 0, h = i.layout.containerPadding?.[1] ?? 0, { maxBottom: b } = se(i.layout.items), c = b * l + Math.max(0, b - 1) * y + h * 2, u = e.width > 0 ? e.width < 768 : !1, w = [...i.layout.items].sort((g, x) => g.y - x.y || g.x - x.x);
593
+ const { ref: t, size: e } = I(), n = i.layout.cols ?? 24, l = i.layout.rowHeight ?? 30, s = i.layout.margin?.[0] ?? 10, y = i.layout.margin?.[1] ?? 10, f = i.layout.containerPadding?.[0] ?? 0, h = i.layout.containerPadding?.[1] ?? 0, { maxBottom: b } = se(i.layout.items), c = b * l + Math.max(0, b - 1) * y + h * 2, u = e.width > 0 ? e.width < 768 : !1, k = [...i.layout.items].sort((g, L) => g.y - L.y || g.x - L.x);
582
594
  return /* @__PURE__ */ r("div", { ref: t, children: u ? /* @__PURE__ */ r(
583
595
  "div",
584
596
  {
@@ -588,9 +600,9 @@ function Le({ page: i }) {
588
600
  gap: y,
589
601
  padding: `${h}px ${f}px`
590
602
  },
591
- children: w.map((g) => {
592
- const x = i.components[g.i], S = g.h * l + Math.max(0, g.h - 1) * y;
593
- return /* @__PURE__ */ r("div", { style: { width: "100%", height: S }, children: x ? /* @__PURE__ */ r(G, { page: i, componentId: g.i, component: x }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
603
+ children: k.map((g) => {
604
+ const L = i.components[g.i], M = g.h * l + Math.max(0, g.h - 1) * y;
605
+ return /* @__PURE__ */ r("div", { style: { width: "100%", height: M }, children: L ? /* @__PURE__ */ r(G, { page: i, componentId: g.i, component: L }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
594
606
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: g.i }) }),
595
607
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ v("div", { style: o.error, children: [
596
608
  "No entry in components for id: ",
@@ -611,17 +623,17 @@ function Le({ page: i }) {
611
623
  minHeight: c
612
624
  },
613
625
  children: i.layout.items.map((g) => {
614
- const x = i.components[g.i];
626
+ const L = i.components[g.i];
615
627
  return /* @__PURE__ */ r(
616
628
  "div",
617
629
  {
618
630
  style: {
619
- gridColumnStart: O(g.x + 1, 1, n + 1),
620
- gridColumnEnd: `span ${O(g.w, 1, n)}`,
631
+ gridColumnStart: D(g.x + 1, 1, n + 1),
632
+ gridColumnEnd: `span ${D(g.w, 1, n)}`,
621
633
  gridRowStart: Math.max(1, g.y + 1),
622
634
  gridRowEnd: `span ${Math.max(1, g.h)}`
623
635
  },
624
- children: x ? /* @__PURE__ */ r(G, { page: i, componentId: g.i, component: x }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
636
+ children: L ? /* @__PURE__ */ r(G, { page: i, componentId: g.i, component: L }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
625
637
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: g.i }) }),
626
638
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ v("div", { style: o.error, children: [
627
639
  "No entry in components for id: ",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "declarative-ui-core",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",