declarative-ui-core 1.0.6 → 1.0.8

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 +127 -112
  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 A, useState as G, useEffect as C, useMemo as S } from "react";
2
+ import { useRef as T, useState as D, 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";
@@ -67,35 +67,35 @@ function X({ componentId: i, component: t }) {
67
67
  ] }) })
68
68
  ] });
69
69
  }
70
- function T(i, t) {
70
+ function A(i, t) {
71
71
  if (!t) return;
72
72
  const e = t.startsWith("data.") ? t.slice(5) : t, n = i.data?.[e];
73
73
  if (!(!n || n.source !== "inline"))
74
74
  return n.rows;
75
75
  }
76
76
  function Y({ page: i, componentId: t, component: e }) {
77
- const n = T(i, e.dataRef) ?? [], l = e.config?.mode, s = e.config?.displayFields, p = s && s.length > 0 ? s : n.length > 0 ? Object.keys(n[0]) : [];
77
+ const n = A(i, e.dataRef) ?? [], l = e.config?.mode, s = e.config?.displayFields, y = s && s.length > 0 ? s : n.length > 0 ? Object.keys(n[0]) : [];
78
78
  return /* @__PURE__ */ v("div", { style: o.panel, children: [
79
79
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: e.title ?? t }) }),
80
- /* @__PURE__ */ r("div", { style: o.panelBody, children: l === "kv" && n.length === 1 ? /* @__PURE__ */ r("div", { style: o.kvList, children: Object.entries(n[0]).map(([y, m]) => /* @__PURE__ */ v("div", { style: o.kvRow, children: [
81
- /* @__PURE__ */ r("div", { style: o.kvKey, children: y }),
82
- /* @__PURE__ */ r("div", { style: o.kvValue, children: String(m) })
83
- ] }, y)) }) : p.length > 0 ? /* @__PURE__ */ r("div", { style: o.listCards, children: n.map((y, m) => /* @__PURE__ */ r("div", { style: o.listCard, children: p.map((b) => /* @__PURE__ */ v("div", { style: o.listCardRow, children: [
80
+ /* @__PURE__ */ r("div", { style: o.panelBody, children: l === "kv" && n.length === 1 ? /* @__PURE__ */ r("div", { style: o.kvList, children: Object.entries(n[0]).map(([f, h]) => /* @__PURE__ */ v("div", { style: o.kvRow, children: [
81
+ /* @__PURE__ */ r("div", { style: o.kvKey, children: f }),
82
+ /* @__PURE__ */ r("div", { style: o.kvValue, children: String(h) })
83
+ ] }, f)) }) : y.length > 0 ? /* @__PURE__ */ r("div", { style: o.listCards, children: n.map((f, h) => /* @__PURE__ */ r("div", { style: o.listCard, children: y.map((b) => /* @__PURE__ */ v("div", { style: o.listCardRow, children: [
84
84
  /* @__PURE__ */ r("div", { style: o.listCardLabel, children: b }),
85
- /* @__PURE__ */ r("div", { style: o.listCardValue, children: String(y[b] ?? "") })
86
- ] }, b)) }, m)) }) : /* @__PURE__ */ r("pre", { style: o.pre, children: JSON.stringify(n, null, 2) }) })
85
+ /* @__PURE__ */ r("div", { style: o.listCardValue, children: String(f[b] ?? "") })
86
+ ] }, b)) }, h)) }) : /* @__PURE__ */ r("pre", { style: o.pre, children: JSON.stringify(n, null, 2) }) })
87
87
  ] });
88
88
  }
89
89
  function I() {
90
- const i = A(null), [t, e] = G({ width: 0, height: 0 });
90
+ const i = T(null), [t, e] = D({ width: 0, height: 0 });
91
91
  return C(() => {
92
92
  const n = i.current;
93
93
  if (!n) return;
94
94
  const l = new ResizeObserver((s) => {
95
- const p = s[0];
96
- if (!p) return;
97
- const y = p.contentRect, m = { width: Math.round(y.width), height: Math.round(y.height) };
98
- e((b) => Math.abs(b.width - m.width) <= 1 && Math.abs(b.height - m.height) <= 1 ? b : m);
95
+ const y = s[0];
96
+ if (!y) return;
97
+ const f = y.contentRect, h = { width: Math.round(f.width), height: Math.round(f.height) };
98
+ e((b) => Math.abs(b.width - h.width) <= 1 && Math.abs(b.height - h.height) <= 1 ? b : h);
99
99
  });
100
100
  return l.observe(n), () => l.disconnect();
101
101
  }, []), { ref: i, size: t };
@@ -117,11 +117,11 @@ function _(i) {
117
117
  const t = i, e = Array.isArray(t.markers) ? t.markers : void 0, n = e ? e.map((l) => {
118
118
  if (!l) return null;
119
119
  if ("lngLat" in l) {
120
- const s = l, p = s.lngLat;
121
- if (Array.isArray(p) && p.length === 2)
120
+ const s = l, y = s.lngLat;
121
+ if (Array.isArray(y) && y.length === 2)
122
122
  return {
123
123
  name: typeof s.name == "string" ? s.name : void 0,
124
- lngLat: [Number(p[0]), Number(p[1])],
124
+ lngLat: [Number(y[0]), Number(y[1])],
125
125
  popup: typeof s.popup == "string" ? s.popup : void 0,
126
126
  shape: typeof s.shape == "string" ? s.shape : void 0,
127
127
  color: typeof s.color == "string" ? s.color : void 0,
@@ -131,11 +131,11 @@ function _(i) {
131
131
  if ("longitude" in l && "latitude" in l) {
132
132
  const s = l;
133
133
  if (typeof s.longitude == "number" && typeof s.latitude == "number") {
134
- const p = typeof s.title == "string" ? s.title : void 0, y = typeof s.description == "string" ? s.description : void 0;
134
+ const y = typeof s.title == "string" ? s.title : void 0, f = typeof s.description == "string" ? s.description : void 0;
135
135
  return {
136
- name: p,
136
+ name: y,
137
137
  lngLat: [Number(s.longitude), Number(s.latitude)],
138
- popup: y,
138
+ popup: f,
139
139
  shape: typeof s.shape == "string" ? s.shape : void 0,
140
140
  color: typeof s.color == "string" ? s.color : void 0,
141
141
  radius: typeof s.radius == "number" ? s.radius : void 0
@@ -175,8 +175,8 @@ function H(i, t) {
175
175
  type: "geojson",
176
176
  data: l
177
177
  };
178
- const p = Array.isArray(i.layers) ? [...i.layers] : [], y = !V(i, e), m = p.filter((b) => b && typeof b == "object" && b.id !== n);
179
- return y && m.push({
178
+ const y = Array.isArray(i.layers) ? [...i.layers] : [], f = !V(i, e), h = y.filter((b) => b && typeof b == "object" && b.id !== n);
179
+ return f && h.push({
180
180
  id: n,
181
181
  type: "circle",
182
182
  source: e,
@@ -190,7 +190,7 @@ function H(i, t) {
190
190
  }), {
191
191
  ...i,
192
192
  sources: s,
193
- layers: m
193
+ layers: h
194
194
  };
195
195
  }
196
196
  function E(i, t) {
@@ -203,8 +203,8 @@ function E(i, t) {
203
203
  console.error("[MapLibreGL] Error adding/updating source:", s);
204
204
  }
205
205
  try {
206
- const s = i.getStyle(), p = V(s, e);
207
- console.log("[MapLibreGL] hasAnyLayerUsingSource:", p, "hasLayer:", !!i.getLayer(n)), !p && !i.getLayer(n) && (console.log("[MapLibreGL] Adding circle layer"), i.addLayer({
206
+ const s = i.getStyle(), y = V(s, e);
207
+ console.log("[MapLibreGL] hasAnyLayerUsingSource:", y, "hasLayer:", !!i.getLayer(n)), !y && !i.getLayer(n) && (console.log("[MapLibreGL] Adding circle layer"), i.addLayer({
208
208
  id: n,
209
209
  type: "circle",
210
210
  source: e,
@@ -221,22 +221,22 @@ function E(i, t) {
221
221
  }
222
222
  }
223
223
  function Q({ page: i, componentId: t, component: e }) {
224
- const n = e.title ?? t, l = "circle-data", { ref: s, size: p } = I(), y = A(null), m = A([]), b = A(/* @__PURE__ */ new Map()), c = S(() => _(e.config), [e.config]), u = S(() => T(i, e.dataRef), [i, e.dataRef]), w = S(() => {
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(() => {
225
225
  if (!u || u.length === 0) return null;
226
- let d = 1 / 0, a = 1 / 0, L = -1 / 0, f = -1 / 0;
227
- for (const h of u) {
228
- const k = typeof h.longitude == "number" ? h.longitude : typeof h.lng == "number" ? h.lng : typeof h.lon == "number" ? h.lon : void 0, j = typeof h.latitude == "number" ? h.latitude : typeof h.lat == "number" ? h.lat : void 0;
229
- typeof k != "number" || typeof j != "number" || !Number.isFinite(k) || !Number.isFinite(j) || (d = Math.min(d, k), a = Math.min(a, j), L = Math.max(L, k), f = Math.max(f, j));
226
+ let d = 1 / 0, a = 1 / 0, L = -1 / 0, p = -1 / 0;
227
+ 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));
230
230
  }
231
- return !Number.isFinite(d) || !Number.isFinite(a) || !Number.isFinite(L) || !Number.isFinite(f) ? null : [
231
+ return !Number.isFinite(d) || !Number.isFinite(a) || !Number.isFinite(L) || !Number.isFinite(p) ? null : [
232
232
  [d, a],
233
- [L, f]
233
+ [L, p]
234
234
  ];
235
- }, [u]), g = S(() => {
235
+ }, [u]), g = j(() => {
236
236
  if (!c.options) return;
237
237
  const { projection: d, ...a } = c.options;
238
238
  return a;
239
- }, [c.options]), x = S(() => {
239
+ }, [c.options]), x = j(() => {
240
240
  const d = c.options?.projection;
241
241
  if (typeof d == "string") return d;
242
242
  if (d && typeof d == "object" && typeof d.name == "string") return d.name;
@@ -245,7 +245,7 @@ function Q({ page: i, componentId: t, component: e }) {
245
245
  if (typeof a == "string") return a;
246
246
  if (a && typeof a == "object" && typeof a.name == "string") return a.name;
247
247
  if (a && typeof a == "object" && typeof a.type == "string") return a.type;
248
- }, [c.options, c.style]), M = typeof c.style == "string" && typeof x == "string", R = typeof c.style == "string" && Array.isArray(u) && u.length > 0, U = S(
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(
249
249
  () => ({
250
250
  version: 8,
251
251
  sources: {},
@@ -253,56 +253,56 @@ function Q({ page: i, componentId: t, component: e }) {
253
253
  }),
254
254
  []
255
255
  ), N = (d) => {
256
- if (!M && !R) return;
256
+ if (!S && !R) return;
257
257
  const a = c.style, L = b.current.get(a);
258
258
  if (L) {
259
259
  try {
260
- let f = L;
261
- M && (f = { ...f ?? {}, projection: { type: x } }), R && e.dataRef && u && (f = H(f, u) ?? f), d.setStyle(f);
260
+ let p = L;
261
+ S && (p = { ...p ?? {}, projection: { type: x } }), R && e.dataRef && u && (p = H(p, u) ?? p), d.setStyle(p);
262
262
  } catch {
263
263
  }
264
264
  return;
265
265
  }
266
- fetch(a).then((f) => f.json()).then((f) => {
267
- b.current.set(a, f);
268
- let h = f ?? {};
269
- M && (h = { ...h, projection: { type: x } }), R && e.dataRef && u && (h = H(h, u) ?? h);
266
+ fetch(a).then((p) => p.json()).then((p) => {
267
+ b.current.set(a, p);
268
+ let m = p ?? {};
269
+ S && (m = { ...m, projection: { type: x } }), R && e.dataRef && u && (m = H(m, u) ?? m);
270
270
  try {
271
- d.setStyle(h);
271
+ d.setStyle(m);
272
272
  } catch {
273
273
  }
274
274
  }).catch(() => {
275
275
  });
276
- }, z = S(() => {
276
+ }, z = j(() => {
277
277
  if (c.style)
278
278
  return typeof c.style == "object" && c.style && e.dataRef && Array.isArray(u) && u.length > 0 ? H(c.style, u) ?? c.style : c.style;
279
279
  }, [c.style, e.dataRef, u]);
280
280
  return C(() => {
281
281
  const d = s.current;
282
282
  if (!d || !z) return;
283
- if (!y.current) {
283
+ if (!f.current) {
284
284
  const L = {
285
285
  container: d,
286
- style: typeof z == "string" && (M || R) ? U : z,
286
+ style: typeof z == "string" && (S || R) ? U : z,
287
287
  attributionControl: {},
288
288
  ...g ?? {}
289
- }, f = new P.Map(L);
290
- N(f);
291
- const h = () => q(f, x);
292
- f.once("load", h), f.once("style.load", h), f.addControl(new P.NavigationControl({ visualizePitch: !0 }), "top-right");
289
+ }, p = new P.Map(L);
290
+ N(p);
291
+ const m = () => q(p, x);
292
+ p.once("load", m), p.once("style.load", m), p.addControl(new P.NavigationControl({ visualizePitch: !0 }), "top-right");
293
293
  const k = () => {
294
- if (u && u.length > 0 && (E(f, u), !c.options?.center && c.options?.zoom === void 0 && w))
294
+ if (u && u.length > 0 && (E(p, u), !c.options?.center && c.options?.zoom === void 0 && w))
295
295
  try {
296
- f.fitBounds(w, { padding: 30, duration: 0, maxZoom: 12 });
296
+ p.fitBounds(w, { padding: 30, duration: 0, maxZoom: 12 });
297
297
  } catch {
298
298
  }
299
299
  };
300
- return f.once("style.load", k), y.current = f, () => {
301
- m.current.forEach((j) => j.remove()), m.current = [], y.current = null, f.remove();
300
+ return p.on("styledata", k), p.once("load", k), f.current = p, () => {
301
+ h.current.forEach((M) => M.remove()), h.current = [], f.current = null, p.remove();
302
302
  };
303
303
  }
304
- const a = y.current;
305
- if (M || R)
304
+ const a = f.current;
305
+ if (S || R)
306
306
  N(a);
307
307
  else
308
308
  try {
@@ -318,56 +318,71 @@ function Q({ page: i, componentId: t, component: e }) {
318
318
  a.jumpTo({ center: c.options.center, zoom: c.options.zoom });
319
319
  } catch {
320
320
  }
321
- }, [z, g, s, x, R, M, u, w, c.options?.center, c.options?.zoom]), C(() => {
322
- const d = y.current;
321
+ }, [z, g, s, x, R, S, u, w, c.options?.center, c.options?.zoom]), C(() => {
322
+ const d = f.current;
323
323
  if (!d || !u || u.length === 0) return;
324
324
  const a = () => {
325
- if (E(d, u), !c.options?.center && c.options?.zoom === void 0 && w)
325
+ if (console.log("[MapLibreGL] apply() called, isStyleLoaded:", d.isStyleLoaded()), E(d, u), !c.options?.center && c.options?.zoom === void 0 && w)
326
326
  try {
327
327
  d.fitBounds(w, { padding: 30, duration: 0, maxZoom: 12 });
328
328
  } catch {
329
329
  }
330
330
  };
331
- d.isStyleLoaded() ? a() : (d.once("style.load", a), d.once("load", a));
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
+ }, 2e3);
343
+ return () => {
344
+ clearTimeout(m);
345
+ };
346
+ }
332
347
  }, [u, w, c.options?.center, c.options?.zoom]), C(() => {
333
- const d = y.current;
334
- d && (p.width <= 0 || p.height <= 0 || d.resize());
335
- }, [p.width, p.height]), C(() => {
336
- const d = y.current;
348
+ const d = f.current;
349
+ d && (y.width <= 0 || y.height <= 0 || d.resize());
350
+ }, [y.width, y.height]), C(() => {
351
+ const d = f.current;
337
352
  if (!d || !u || u.length === 0) return;
338
353
  const a = new P.Popup({
339
354
  closeButton: !1,
340
355
  closeOnClick: !1
341
356
  }), L = (k) => {
342
357
  if (!k.features || k.features.length === 0) return;
343
- const j = k.features[0], $ = j.properties ?? {}, B = $.name ?? $.region ?? $.title ?? $.label ?? $.description;
358
+ const M = k.features[0], $ = M.properties ?? {}, B = $.name ?? $.region ?? $.title ?? $.label ?? $.description;
344
359
  if (B) {
345
360
  d.getCanvas().style.cursor = "pointer";
346
- const Z = j.geometry.coordinates.slice();
361
+ const Z = M.geometry.coordinates.slice();
347
362
  a.setLngLat(Z).setHTML(`<div style="padding: 4px 8px; font-size: 13px;">${B}</div>`).addTo(d);
348
363
  }
349
- }, f = () => {
364
+ }, p = () => {
350
365
  d.getCanvas().style.cursor = "", a.remove();
351
- }, h = () => {
352
- d.getLayer(l) ? (d.on("mouseenter", l, L), d.on("mouseleave", l, f)) : d.once("styledata", h);
366
+ }, m = () => {
367
+ d.getLayer(l) ? (d.on("mouseenter", l, L), d.on("mouseleave", l, p)) : d.once("styledata", m);
353
368
  };
354
- return h(), () => {
355
- a.remove(), d && !d._removed && d.getLayer(l) && (d.off("mouseenter", l, L), d.off("mouseleave", l, f));
369
+ return m(), () => {
370
+ a.remove(), d && !d._removed && d.getLayer(l) && (d.off("mouseenter", l, L), d.off("mouseleave", l, p));
356
371
  };
357
372
  }, [u, l]), C(() => {
358
- const d = y.current;
359
- d && (m.current.forEach((a) => a.remove()), m.current = [], (c.markers ?? []).forEach((a) => {
360
- const f = a.shape === "circle" || typeof a.radius == "number" || typeof a.color == "string" ? document.createElement("div") : null;
361
- if (f) {
373
+ const d = f.current;
374
+ d && (h.current.forEach((a) => a.remove()), h.current = [], (c.markers ?? []).forEach((a) => {
375
+ const p = a.shape === "circle" || typeof a.radius == "number" || typeof a.color == "string" ? document.createElement("div") : null;
376
+ if (p) {
362
377
  const k = typeof a.radius == "number" && Number.isFinite(a.radius) ? Math.max(2, a.radius) : 8;
363
- f.style.width = `${k * 2}px`, f.style.height = `${k * 2}px`, f.style.borderRadius = "999px", f.style.background = typeof a.color == "string" ? a.color : "#2563eb", f.style.border = "2px solid #ffffff", f.style.boxShadow = "0 2px 10px rgba(0,0,0,0.25)";
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)";
364
379
  }
365
- const h = new P.Marker(f ? { element: f } : void 0).setLngLat(a.lngLat);
380
+ const m = new P.Marker(p ? { element: p } : void 0).setLngLat(a.lngLat);
366
381
  if (a.popup || a.name) {
367
382
  const k = a.popup ?? `<div style="font-size:12px"><strong>${a.name ?? ""}</strong></div>`;
368
- h.setPopup(new P.Popup({ offset: 20 }).setHTML(k));
383
+ m.setPopup(new P.Popup({ offset: 20 }).setHTML(k));
369
384
  }
370
- h.addTo(d), m.current.push(h);
385
+ m.addTo(d), h.current.push(m);
371
386
  }));
372
387
  }, [c.markers]), /* @__PURE__ */ v("div", { style: o.panel, children: [
373
388
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: n }) }),
@@ -397,7 +412,7 @@ F.initialize({
397
412
  securityLevel: "loose"
398
413
  });
399
414
  function te({ page: i, componentId: t, component: e }) {
400
- const n = e.title ?? t, l = typeof e.config?.mermaid == "string" ? e.config.mermaid : "", s = A(null), [p, y] = G(1);
415
+ const n = e.title ?? t, l = typeof e.config?.mermaid == "string" ? e.config.mermaid : "", s = T(null), [y, f] = D(1);
401
416
  C(() => {
402
417
  if (!l || !s.current) return;
403
418
  (async () => {
@@ -413,7 +428,7 @@ function te({ page: i, componentId: t, component: e }) {
413
428
  }
414
429
  })();
415
430
  }, [l, t]);
416
- const m = () => y((u) => Math.min(u + 0.2, 3)), b = () => y((u) => Math.max(u - 0.2, 0.5)), c = () => y(1);
431
+ const h = () => f((u) => Math.min(u + 0.2, 3)), b = () => f((u) => Math.max(u - 0.2, 0.5)), c = () => f(1);
417
432
  return l ? /* @__PURE__ */ v("div", { style: o.panel, children: [
418
433
  /* @__PURE__ */ v("div", { style: o.panelHeader, children: [
419
434
  /* @__PURE__ */ r("div", { style: o.panelTitle, children: n }),
@@ -448,7 +463,7 @@ function te({ page: i, componentId: t, component: e }) {
448
463
  },
449
464
  title: "Reset zoom",
450
465
  children: [
451
- Math.round(p * 100),
466
+ Math.round(y * 100),
452
467
  "%"
453
468
  ]
454
469
  }
@@ -456,7 +471,7 @@ function te({ page: i, componentId: t, component: e }) {
456
471
  /* @__PURE__ */ r(
457
472
  "button",
458
473
  {
459
- onClick: m,
474
+ onClick: h,
460
475
  style: {
461
476
  padding: "4px 8px",
462
477
  fontSize: "12px",
@@ -481,7 +496,7 @@ function te({ page: i, componentId: t, component: e }) {
481
496
  {
482
497
  ref: s,
483
498
  style: {
484
- transform: `scale(${p})`,
499
+ transform: `scale(${y})`,
485
500
  transformOrigin: "center center",
486
501
  transition: "transform 0.2s ease"
487
502
  }
@@ -493,12 +508,12 @@ function te({ page: i, componentId: t, component: e }) {
493
508
  ] });
494
509
  }
495
510
  function re({ page: i, componentId: t, component: e }) {
496
- const n = T(i, e.dataRef) ?? [], l = e.config?.columns, s = l && l.length ? l : Object.keys(n[0] ?? {}).map((p) => ({ key: p, label: p }));
511
+ const n = A(i, e.dataRef) ?? [], l = e.config?.columns, s = l && l.length ? l : Object.keys(n[0] ?? {}).map((y) => ({ key: y, label: y }));
497
512
  return /* @__PURE__ */ v("div", { style: o.panel, children: [
498
513
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: e.title ?? t }) }),
499
514
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ r("div", { style: o.tableWrap, children: /* @__PURE__ */ v("table", { style: o.table, children: [
500
- /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ r("tr", { children: s.map((p) => /* @__PURE__ */ r("th", { style: o.th, children: p.label }, p.key)) }) }),
501
- /* @__PURE__ */ r("tbody", { children: n.map((p, y) => /* @__PURE__ */ r("tr", { children: s.map((m) => /* @__PURE__ */ r("td", { style: o.td, children: String(p[m.key] ?? "") }, m.key)) }, y)) })
515
+ /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ r("tr", { children: s.map((y) => /* @__PURE__ */ r("th", { style: o.th, children: y.label }, y.key)) }) }),
516
+ /* @__PURE__ */ r("tbody", { children: n.map((y, f) => /* @__PURE__ */ r("tr", { children: s.map((h) => /* @__PURE__ */ r("td", { style: o.td, children: String(y[h.key] ?? "") }, h.key)) }, f)) })
502
517
  ] }) }) })
503
518
  ] });
504
519
  }
@@ -518,13 +533,13 @@ function ne(i) {
518
533
  return t(i);
519
534
  }
520
535
  function oe({ page: i, componentId: t, component: e }) {
521
- const n = T(i, e.dataRef), { ref: l, size: s } = I(), p = e.spec ?? {}, y = p.config ?? {}, m = {
522
- ...y,
523
- axis: { ...y.axis, grid: !1 },
524
- axisX: { ...y.axisX, grid: !1 },
525
- axisY: { ...y.axisY, grid: !1 },
526
- view: { ...y.view, stroke: null }
527
- }, b = { ...p, config: m }, c = s.width > 0 && s.height > 0 ? {
536
+ const n = A(i, e.dataRef), { ref: l, size: s } = I(), y = e.spec ?? {}, f = y.config ?? {}, h = {
537
+ ...f,
538
+ axis: { ...f.axis, grid: !1 },
539
+ axisX: { ...f.axisX, grid: !1 },
540
+ axisY: { ...f.axisY, grid: !1 },
541
+ view: { ...f.view, stroke: null }
542
+ }, b = { ...y, config: h }, c = s.width > 0 && s.height > 0 ? {
528
543
  ...b,
529
544
  autosize: { type: "fit", contains: "padding" },
530
545
  width: Math.floor(s.width),
@@ -535,7 +550,7 @@ function oe({ page: i, componentId: t, component: e }) {
535
550
  /* @__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 }) }) })
536
551
  ] });
537
552
  }
538
- function O({ page: i, componentId: t, component: e }) {
553
+ function G({ page: i, componentId: t, component: e }) {
539
554
  switch (e.type) {
540
555
  case "vegalite5":
541
556
  return /* @__PURE__ */ r(oe, { page: i, componentId: t, component: e });
@@ -555,27 +570,27 @@ function O({ page: i, componentId: t, component: e }) {
555
570
  return /* @__PURE__ */ r(ie, { page: i, componentId: t, component: e });
556
571
  }
557
572
  }
558
- function D(i, t, e) {
573
+ function O(i, t, e) {
559
574
  return Math.min(e, Math.max(t, i));
560
575
  }
561
576
  function se(i) {
562
577
  const t = i.reduce((n, l) => Math.max(n, l.y + l.h), 0), e = i.reduce((n, l) => Math.max(n, l.x + l.w), 0);
563
578
  return { maxBottom: t, maxRight: e };
564
579
  }
565
- function we({ page: i }) {
566
- const { ref: t, size: e } = I(), n = i.layout.cols ?? 24, l = i.layout.rowHeight ?? 30, s = i.layout.margin?.[0] ?? 10, p = i.layout.margin?.[1] ?? 10, y = i.layout.containerPadding?.[0] ?? 0, m = i.layout.containerPadding?.[1] ?? 0, { maxBottom: b } = se(i.layout.items), c = b * l + Math.max(0, b - 1) * p + m * 2, u = e.width > 0 ? e.width < 768 : !1, w = [...i.layout.items].sort((g, x) => g.y - x.y || g.x - x.x);
580
+ 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);
567
582
  return /* @__PURE__ */ r("div", { ref: t, children: u ? /* @__PURE__ */ r(
568
583
  "div",
569
584
  {
570
585
  style: {
571
586
  display: "flex",
572
587
  flexDirection: "column",
573
- gap: p,
574
- padding: `${m}px ${y}px`
588
+ gap: y,
589
+ padding: `${h}px ${f}px`
575
590
  },
576
591
  children: w.map((g) => {
577
- const x = i.components[g.i], M = g.h * l + Math.max(0, g.h - 1) * p;
578
- return /* @__PURE__ */ r("div", { style: { width: "100%", height: M }, children: x ? /* @__PURE__ */ r(O, { page: i, componentId: g.i, component: x }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
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: [
579
594
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: g.i }) }),
580
595
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ v("div", { style: o.error, children: [
581
596
  "No entry in components for id: ",
@@ -589,10 +604,10 @@ function we({ page: i }) {
589
604
  {
590
605
  style: {
591
606
  ...o.canvas,
592
- padding: `${m}px ${y}px`,
607
+ padding: `${h}px ${f}px`,
593
608
  gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))`,
594
609
  gridAutoRows: `${l}px`,
595
- gap: `${p}px ${s}px`,
610
+ gap: `${y}px ${s}px`,
596
611
  minHeight: c
597
612
  },
598
613
  children: i.layout.items.map((g) => {
@@ -601,12 +616,12 @@ function we({ page: i }) {
601
616
  "div",
602
617
  {
603
618
  style: {
604
- gridColumnStart: D(g.x + 1, 1, n + 1),
605
- gridColumnEnd: `span ${D(g.w, 1, n)}`,
619
+ gridColumnStart: O(g.x + 1, 1, n + 1),
620
+ gridColumnEnd: `span ${O(g.w, 1, n)}`,
606
621
  gridRowStart: Math.max(1, g.y + 1),
607
622
  gridRowEnd: `span ${Math.max(1, g.h)}`
608
623
  },
609
- children: x ? /* @__PURE__ */ r(O, { page: i, componentId: g.i, component: x }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
624
+ children: x ? /* @__PURE__ */ r(G, { page: i, componentId: g.i, component: x }) : /* @__PURE__ */ v("div", { style: o.panel, children: [
610
625
  /* @__PURE__ */ r("div", { style: o.panelHeader, children: /* @__PURE__ */ r("div", { style: o.panelTitle, children: g.i }) }),
611
626
  /* @__PURE__ */ r("div", { style: o.panelBody, children: /* @__PURE__ */ v("div", { style: o.error, children: [
612
627
  "No entry in components for id: ",
@@ -620,14 +635,14 @@ function we({ page: i }) {
620
635
  }
621
636
  ) });
622
637
  }
623
- const le = "https://json-schema.org/draft/2020-12/schema", ae = "https://example.com/ai-canvas/page.schema.json", de = "AI Canvas Page", ce = "object", pe = !1, fe = ["layout", "components", "data"], ye = { meta: { $ref: "#/$defs/Meta" }, layout: { $ref: "#/$defs/Layout" }, components: { $ref: "#/$defs/Components" }, data: { $ref: "#/$defs/Data" } }, ue = { Meta: { type: "object", additionalProperties: !1, properties: { title: { type: "string", minLength: 1 }, description: { type: "string" }, version: { type: "string" } } }, Layout: { type: "object", additionalProperties: !1, required: ["engine", "items"], properties: { engine: { type: "string", enum: ["rgl"] }, cols: { type: "integer", minimum: 1, default: 24 }, rowHeight: { type: "integer", minimum: 1, default: 30 }, margin: { type: "array", items: { type: "integer", minimum: 0 }, minItems: 2, maxItems: 2, default: [10, 10] }, containerPadding: { type: "array", items: { type: "integer", minimum: 0 }, minItems: 2, maxItems: 2, default: [0, 0] }, items: { type: "array", minItems: 1, items: { $ref: "#/$defs/RglItem" } } } }, RglItem: { type: "object", additionalProperties: !1, required: ["i", "x", "y", "w", "h"], properties: { i: { type: "string", minLength: 1 }, x: { type: "integer", minimum: 0 }, y: { type: "integer", minimum: 0 }, w: { type: "integer", minimum: 1 }, h: { type: "integer", minimum: 1 }, static: { type: "boolean", default: !1 } } }, Components: { type: "object", description: "Map of componentId -> component config. Keys should match layout.items[*].i.", additionalProperties: { $ref: "#/$defs/Component" } }, Component: { type: "object", additionalProperties: !1, required: ["type"], properties: { type: { type: "string", enum: ["vegalite5", "map", "list", "form", "table", "markdown", "mermaid"] }, title: { type: "string" }, dataRef: { type: "string", minLength: 1 }, config: { type: "object", description: "Component-specific configuration (non-Vega-Lite components). Keep flexible for now.", additionalProperties: !0, default: {} }, spec: { type: "object", description: "Vega-Lite spec (only for type=vegalite5).", additionalProperties: !0 } }, allOf: [{ if: { properties: { type: { const: "vegalite5" } }, required: ["type"] }, then: { required: ["spec"] }, else: { properties: { spec: !1 } } }, { if: { properties: { type: { const: "map" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, description: "MapLibre GL JS configuration. Provide either a MapLibre Style Specification object (Mapbox style spec v8) directly, or an object like { style: <style-spec-or-url>, options: <map options> }." } } } }, { if: { properties: { type: { const: "table" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["columns"], properties: { columns: { type: "array", minItems: 1, items: { $ref: "#/$defs/Column" } } } } } } }, { if: { properties: { type: { const: "form" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["columns"], properties: { columns: { type: "array", minItems: 1, items: { $ref: "#/$defs/Column" } } } } } } }, { if: { properties: { type: { const: "list" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0 } } } }, { if: { properties: { type: { const: "markdown" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["md"], properties: { md: { type: "string", minLength: 1, description: "Markdown content to render" } } } } } }, { if: { properties: { type: { const: "mermaid" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["mermaid"], properties: { mermaid: { type: "string", minLength: 1, description: "Mermaid diagram definition" } } } } } }] }, Column: { type: "object", additionalProperties: !1, required: ["key", "label"], properties: { key: { type: "string", minLength: 1 }, label: { type: "string", minLength: 1 } } }, Data: { type: "object", description: "Map of datasetName -> inline dataset.", additionalProperties: { $ref: "#/$defs/InlineDataset" } }, InlineDataset: { type: "object", additionalProperties: !1, required: ["source", "rows"], properties: { source: { type: "string", enum: ["inline"] }, rows: { type: "array", items: { type: "object", additionalProperties: !0 } } } } }, Le = {
638
+ const le = "https://json-schema.org/draft/2020-12/schema", ae = "https://example.com/ai-canvas/page.schema.json", de = "AI Canvas Page", ce = "object", pe = !1, ye = ["layout", "components", "data"], fe = { meta: { $ref: "#/$defs/Meta" }, layout: { $ref: "#/$defs/Layout" }, components: { $ref: "#/$defs/Components" }, data: { $ref: "#/$defs/Data" } }, ue = { Meta: { type: "object", additionalProperties: !1, properties: { title: { type: "string", minLength: 1 }, description: { type: "string" }, version: { type: "string" } } }, Layout: { type: "object", additionalProperties: !1, required: ["engine", "items"], properties: { engine: { type: "string", enum: ["rgl"] }, cols: { type: "integer", minimum: 1, default: 24 }, rowHeight: { type: "integer", minimum: 1, default: 30 }, margin: { type: "array", items: { type: "integer", minimum: 0 }, minItems: 2, maxItems: 2, default: [10, 10] }, containerPadding: { type: "array", items: { type: "integer", minimum: 0 }, minItems: 2, maxItems: 2, default: [0, 0] }, items: { type: "array", minItems: 1, items: { $ref: "#/$defs/RglItem" } } } }, RglItem: { type: "object", additionalProperties: !1, required: ["i", "x", "y", "w", "h"], properties: { i: { type: "string", minLength: 1 }, x: { type: "integer", minimum: 0 }, y: { type: "integer", minimum: 0 }, w: { type: "integer", minimum: 1 }, h: { type: "integer", minimum: 1 }, static: { type: "boolean", default: !1 } } }, Components: { type: "object", description: "Map of componentId -> component config. Keys should match layout.items[*].i.", additionalProperties: { $ref: "#/$defs/Component" } }, Component: { type: "object", additionalProperties: !1, required: ["type"], properties: { type: { type: "string", enum: ["vegalite5", "map", "list", "form", "table", "markdown", "mermaid"] }, title: { type: "string" }, dataRef: { type: "string", minLength: 1 }, config: { type: "object", description: "Component-specific configuration (non-Vega-Lite components). Keep flexible for now.", additionalProperties: !0, default: {} }, spec: { type: "object", description: "Vega-Lite spec (only for type=vegalite5).", additionalProperties: !0 } }, allOf: [{ if: { properties: { type: { const: "vegalite5" } }, required: ["type"] }, then: { required: ["spec"] }, else: { properties: { spec: !1 } } }, { if: { properties: { type: { const: "map" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, description: "MapLibre GL JS configuration. Provide either a MapLibre Style Specification object (Mapbox style spec v8) directly, or an object like { style: <style-spec-or-url>, options: <map options> }." } } } }, { if: { properties: { type: { const: "table" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["columns"], properties: { columns: { type: "array", minItems: 1, items: { $ref: "#/$defs/Column" } } } } } } }, { if: { properties: { type: { const: "form" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["columns"], properties: { columns: { type: "array", minItems: 1, items: { $ref: "#/$defs/Column" } } } } } } }, { if: { properties: { type: { const: "list" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0 } } } }, { if: { properties: { type: { const: "markdown" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["md"], properties: { md: { type: "string", minLength: 1, description: "Markdown content to render" } } } } } }, { if: { properties: { type: { const: "mermaid" } }, required: ["type"] }, then: { properties: { config: { type: "object", additionalProperties: !0, required: ["mermaid"], properties: { mermaid: { type: "string", minLength: 1, description: "Mermaid diagram definition" } } } } } }] }, Column: { type: "object", additionalProperties: !1, required: ["key", "label"], properties: { key: { type: "string", minLength: 1 }, label: { type: "string", minLength: 1 } } }, Data: { type: "object", description: "Map of datasetName -> inline dataset.", additionalProperties: { $ref: "#/$defs/InlineDataset" } }, InlineDataset: { type: "object", additionalProperties: !1, required: ["source", "rows"], properties: { source: { type: "string", enum: ["inline"] }, rows: { type: "array", items: { type: "object", additionalProperties: !0 } } } } }, we = {
624
639
  $schema: le,
625
640
  $id: ae,
626
641
  title: de,
627
642
  type: ce,
628
643
  additionalProperties: pe,
629
- required: fe,
630
- properties: ye,
644
+ required: ye,
645
+ properties: fe,
631
646
  $defs: ue
632
647
  };
633
648
  function ke(i) {
@@ -651,8 +666,8 @@ function ke(i) {
651
666
  return e(t), t;
652
667
  }
653
668
  export {
654
- we as CanvasRenderer,
655
- Le as PAGE_SCHEMA,
669
+ Le as CanvasRenderer,
670
+ we as PAGE_SCHEMA,
656
671
  ke as schemaWithoutRemoteVegaLiteRef,
657
672
  o as styles
658
673
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "declarative-ui-core",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",