webim-adapter 0.7.0 → 0.8.0

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.
@@ -430,7 +430,8 @@ function te(e, t) {
430
430
  //#region ../ui/src/components/builder/views.jsx
431
431
  var U = n({
432
432
  tenant: "",
433
- apiUrl: "/api"
433
+ apiUrl: "/api",
434
+ locale: ""
434
435
  }), W = n(null), G = n(null), ne = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
435
436
  function K(e, t) {
436
437
  if (t) return t.includes(".") ? t.split(".").reduce((e, t) => e && typeof e == "object" ? e[t] : void 0, e) : e?.[t];
@@ -446,7 +447,7 @@ var re = (e) => {
446
447
  return t;
447
448
  };
448
449
  function q(e) {
449
- return e == null ? "" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? String(e) : typeof e == "object" && !Array.isArray(e) && ("name" in e || "slug" in e) ? String(e.name ?? e.slug ?? "") : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : Array.isArray(e?.parts) ? e.parts.map((e) => e?.text ?? "").join("") : Array.isArray(e?.items) ? e.items.map((e) => e?.text ?? "").join(" ") : e && (e.name != null || e.slug != null) ? String(e.name ?? e.slug) : "").filter(Boolean).join(" ") : "";
450
+ return e == null ? "" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? String(e) : typeof e == "object" && !Array.isArray(e) && ("label" in e || "name" in e || "slug" in e) ? String(e.label ?? e.name ?? e.slug ?? "") : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : Array.isArray(e?.parts) ? e.parts.map((e) => e?.text ?? "").join("") : Array.isArray(e?.items) ? e.items.map((e) => e?.text ?? "").join(" ") : e && (e.label != null || e.name != null || e.slug != null) ? String(e.label ?? e.name ?? e.slug) : "").filter(Boolean).join(" ") : "";
450
451
  }
451
452
  function ie(e, t) {
452
453
  let n = t?.data ?? {}, r = re(n);
@@ -1476,14 +1477,20 @@ var $e = {
1476
1477
  width: "100%",
1477
1478
  boxSizing: "border-box"
1478
1479
  };
1479
- function tt({ field: e, value: t, onChange: n, inert: r }) {
1480
- let i = /* @__PURE__ */ u("span", {
1480
+ function tt(e, t) {
1481
+ let n = Array.isArray(e?.options) ? e.options : [];
1482
+ if (!e?.parentField) return n;
1483
+ let r = t?.[e.parentField];
1484
+ return r ? n.filter((e) => typeof e == "string" ? !1 : !e.parent || e.parent === r) : [];
1485
+ }
1486
+ function nt({ field: e, value: t, onChange: n, inert: r, values: i }) {
1487
+ let a = /* @__PURE__ */ u("span", {
1481
1488
  style: {
1482
1489
  ...Je,
1483
1490
  fontSize: 14
1484
1491
  },
1485
1492
  children: [e.label, e.required ? " *" : ""]
1486
- }), a = {
1493
+ }), o = {
1487
1494
  name: e.name,
1488
1495
  required: e.required || void 0,
1489
1496
  placeholder: e.placeholder || void 0,
@@ -1531,20 +1538,21 @@ function tt({ field: e, value: t, onChange: n, inert: r }) {
1531
1538
  }) : null : /* @__PURE__ */ u("label", {
1532
1539
  style: $e,
1533
1540
  children: [
1534
- i,
1541
+ a,
1535
1542
  e.type === "textarea" || e.multiline ? /* @__PURE__ */ l("textarea", {
1536
- ...a,
1543
+ ...o,
1537
1544
  rows: 4,
1538
1545
  style: {
1539
1546
  ...et,
1540
1547
  resize: "vertical"
1541
1548
  }
1542
1549
  }) : e.type === "select" ? /* @__PURE__ */ u("select", {
1543
- ...a,
1550
+ ...o,
1551
+ disabled: o.disabled || !!e.parentField && !i?.[e.parentField],
1544
1552
  children: [/* @__PURE__ */ l("option", {
1545
1553
  value: "",
1546
1554
  children: e.placeholder || "—"
1547
- }), (e.options ?? []).map((e, t) => /* @__PURE__ */ l("option", {
1555
+ }), tt(e, i).map((e, t) => /* @__PURE__ */ l("option", {
1548
1556
  value: typeof e == "string" ? e : e.value,
1549
1557
  children: typeof e == "string" ? e : e.label ?? e.value
1550
1558
  }, t))]
@@ -1571,7 +1579,7 @@ function tt({ field: e, value: t, onChange: n, inert: r }) {
1571
1579
  fontSize: 14
1572
1580
  }
1573
1581
  }) : /* @__PURE__ */ l("input", {
1574
- ...a,
1582
+ ...o,
1575
1583
  type: {
1576
1584
  email: "email",
1577
1585
  number: "number",
@@ -1591,7 +1599,7 @@ function tt({ field: e, value: t, onChange: n, inert: r }) {
1591
1599
  ]
1592
1600
  });
1593
1601
  }
1594
- function nt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d, auto: f, submitLabel: p, nodeRef: m, inert: h, children: g, linked: _, show: v }) {
1602
+ function rt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d, auto: f, submitLabel: p, nodeRef: m, inert: h, children: g, linked: _, show: v }) {
1595
1603
  let { tenant: y, apiUrl: b } = r(U), [S, C] = s("form"), [w, T] = s(null), [E, D] = s({}), [O, k] = s(0), A = h ? v || "form" : S;
1596
1604
  i(() => {
1597
1605
  if (!f || !d) return;
@@ -1619,10 +1627,14 @@ function nt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d,
1619
1627
  })), P = M.length > 1, F = Math.min(O, Math.max(0, N.length - 1)), I = P ? N[F]?.fields ?? [] : N.flatMap((e) => e.fields), L = I.filter((e) => {
1620
1628
  let t = E[e.name];
1621
1629
  return e.required && (t == null || t === "" || t === !1);
1622
- }), R = F >= N.length - 1, z = (e, t) => D((n) => ({
1623
- ...n,
1624
- [e]: t
1625
- }));
1630
+ }), R = F >= N.length - 1, z = (e, t) => D((n) => {
1631
+ let r = {
1632
+ ...n,
1633
+ [e]: t
1634
+ };
1635
+ for (let t of Array.isArray(w?.fields) ? w.fields : []) t?.parentField === e && delete r[t.name];
1636
+ return r;
1637
+ });
1626
1638
  return /* @__PURE__ */ u("div", {
1627
1639
  ref: m,
1628
1640
  style: x(e),
@@ -1673,7 +1685,7 @@ function nt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d,
1673
1685
  display: A === "success" ? "none" : "flex"
1674
1686
  },
1675
1687
  children: f && d ? /* @__PURE__ */ u(c, { children: [
1676
- P && /* @__PURE__ */ l(mt, {
1688
+ P && /* @__PURE__ */ l(ht, {
1677
1689
  steps: N.map((e) => ({ label: e.section?.label ?? "Start" })),
1678
1690
  active: F + 1,
1679
1691
  style: { marginBottom: 8 }
@@ -1686,9 +1698,10 @@ function nt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d,
1686
1698
  },
1687
1699
  children: N[F].section.help
1688
1700
  }),
1689
- I.map((e) => /* @__PURE__ */ l(tt, {
1701
+ I.map((e) => /* @__PURE__ */ l(nt, {
1690
1702
  field: e,
1691
1703
  value: E[e.name],
1704
+ values: E,
1692
1705
  onChange: z,
1693
1706
  inert: h
1694
1707
  }, e.name)),
@@ -1758,7 +1771,7 @@ function nt({ style: e, action: t, method: n, name: a, enctype: o, formSlug: d,
1758
1771
  ]
1759
1772
  });
1760
1773
  }
1761
- function rt({ text: e, parts: t, style: n, nodeRef: r, linked: i }) {
1774
+ function it({ text: e, parts: t, style: n, nodeRef: r, linked: i }) {
1762
1775
  return /* @__PURE__ */ l("label", {
1763
1776
  ref: r,
1764
1777
  style: {
@@ -1768,7 +1781,7 @@ function rt({ text: e, parts: t, style: n, nodeRef: r, linked: i }) {
1768
1781
  children: Z(t, e, i)
1769
1782
  });
1770
1783
  }
1771
- function it({ type: e = "text", name: t, placeholder: n, required: r, style: i, nodeRef: a, inert: o }) {
1784
+ function at({ type: e = "text", name: t, placeholder: n, required: r, style: i, nodeRef: a, inert: o }) {
1772
1785
  return /* @__PURE__ */ l("input", {
1773
1786
  ref: a,
1774
1787
  type: e,
@@ -1782,7 +1795,7 @@ function it({ type: e = "text", name: t, placeholder: n, required: r, style: i,
1782
1795
  ...Ze(o)
1783
1796
  });
1784
1797
  }
1785
- function at({ name: e, placeholder: t, rows: n = 4, required: r, style: i, nodeRef: a, inert: o }) {
1798
+ function ot({ name: e, placeholder: t, rows: n = 4, required: r, style: i, nodeRef: a, inert: o }) {
1786
1799
  return /* @__PURE__ */ l("textarea", {
1787
1800
  ref: a,
1788
1801
  name: e || void 0,
@@ -1797,7 +1810,7 @@ function at({ name: e, placeholder: t, rows: n = 4, required: r, style: i, nodeR
1797
1810
  ...Ze(o)
1798
1811
  });
1799
1812
  }
1800
- function ot({ kind: e = "checkbox", label: t, name: n, value: r, required: i, style: a, nodeRef: o, inert: s }) {
1813
+ function st({ kind: e = "checkbox", label: t, name: n, value: r, required: i, style: a, nodeRef: o, inert: s }) {
1801
1814
  return /* @__PURE__ */ u("label", {
1802
1815
  ref: o,
1803
1816
  style: {
@@ -1818,7 +1831,7 @@ function ot({ kind: e = "checkbox", label: t, name: n, value: r, required: i, st
1818
1831
  }), t]
1819
1832
  });
1820
1833
  }
1821
- function st({ name: e, placeholder: t, options: n = [], required: r, style: i, nodeRef: a, inert: o }) {
1834
+ function ct({ name: e, placeholder: t, options: n = [], required: r, style: i, nodeRef: a, inert: o }) {
1822
1835
  return /* @__PURE__ */ u("select", {
1823
1836
  ref: a,
1824
1837
  name: e || void 0,
@@ -1841,7 +1854,7 @@ function st({ name: e, placeholder: t, options: n = [], required: r, style: i, n
1841
1854
  }, t))]
1842
1855
  });
1843
1856
  }
1844
- function ct({ name: e, accept: t, required: n, text: r = "Choose a file…", style: i, nodeRef: a, inert: o }) {
1857
+ function lt({ name: e, accept: t, required: n, text: r = "Choose a file…", style: i, nodeRef: a, inert: o }) {
1845
1858
  let [c, d] = s(null);
1846
1859
  return /* @__PURE__ */ u("label", {
1847
1860
  ref: a,
@@ -1873,7 +1886,7 @@ function ct({ name: e, accept: t, required: n, text: r = "Choose a file…", sty
1873
1886
  ]
1874
1887
  });
1875
1888
  }
1876
- function lt({ text: e = "Submit", style: t, nodeRef: n, inert: r }) {
1889
+ function ut({ text: e = "Submit", style: t, nodeRef: n, inert: r }) {
1877
1890
  return /* @__PURE__ */ l("button", {
1878
1891
  ref: n,
1879
1892
  type: r ? "button" : "submit",
@@ -1893,7 +1906,7 @@ function lt({ text: e = "Submit", style: t, nodeRef: n, inert: r }) {
1893
1906
  children: e
1894
1907
  });
1895
1908
  }
1896
- function ut({ cols: e = 2, rows: t = 1, style: n, nodeRef: r, linked: i }) {
1909
+ function dt({ cols: e = 2, rows: t = 1, style: n, nodeRef: r, linked: i }) {
1897
1910
  let a = Math.max(1, (Number(e) || 1) * (Number(t) || 1));
1898
1911
  return /* @__PURE__ */ l("div", {
1899
1912
  ref: r,
@@ -1910,48 +1923,52 @@ function ut({ cols: e = 2, rows: t = 1, style: n, nodeRef: r, linked: i }) {
1910
1923
  }, t))
1911
1924
  });
1912
1925
  }
1913
- function dt({ collection: e, limit: t = 6, layout: n = "grid", columns: a = 3, imageField: o, titleField: c = "name", textField: d, custom: f, templateId: p, style: m, nodeRef: h }) {
1914
- let { tenant: g, apiUrl: _ } = r(U), v = r(G), y = r(W)?.[e], [b, S] = s(null);
1926
+ function ft({ collection: e, limit: t = 6, layout: n = "grid", columns: a = 3, imageField: o, titleField: c = "name", textField: d, custom: f, templateId: p, style: m, nodeRef: h }) {
1927
+ let { tenant: g, apiUrl: _, locale: v } = r(U), y = r(G), b = r(W)?.[e], [S, C] = s(null);
1915
1928
  if (i(() => {
1916
- if (!e || y) return;
1917
- let t = !0, n = e.startsWith("api:") ? `${_}/data/${encodeURIComponent(e.slice(4))}` : `${_}/dynamic/${encodeURIComponent(e)}`;
1918
- return fetch(n, { headers: g ? { "x-tenant": g } : {} }).then((e) => e.json()).then((e) => t && S(Array.isArray(e?.payload) ? e.payload.filter((e) => e && typeof e == "object") : [])).catch(() => t && S([])), () => {
1929
+ if (!e || b) return;
1930
+ let t = !0, n = e.startsWith("api:") ? `${_}/data/${encodeURIComponent(e.slice(4))}` : `${_}/dynamic/${encodeURIComponent(e)}${v ? `?locale=${encodeURIComponent(v)}` : ""}`;
1931
+ return fetch(n, { headers: g ? { "x-tenant": g } : {} }).then((e) => e.json()).then((e) => {
1932
+ let n = Array.isArray(e?.payload) ? e.payload : Array.isArray(e?.payload?.data) ? e.payload.data : [];
1933
+ return t && C(n.filter((e) => e && typeof e == "object"));
1934
+ }).catch(() => t && C([])), () => {
1919
1935
  t = !1;
1920
1936
  };
1921
1937
  }, [
1922
1938
  e,
1923
1939
  g,
1924
1940
  _,
1925
- y
1941
+ v,
1942
+ b
1926
1943
  ]), !e) return null;
1927
- let C = (y ?? b ?? []).slice(0, Math.max(1, Number(t) || 6)), w = Math.min(Math.max(Number(a) || 3, 1), 6), T = n === "list" ? {
1944
+ let w = (b ?? S ?? []).slice(0, Math.max(1, Number(t) || 6)), T = Math.min(Math.max(Number(a) || 3, 1), 6), E = n === "list" ? {
1928
1945
  display: "flex",
1929
1946
  flexDirection: "column",
1930
1947
  gap: 20
1931
1948
  } : {
1932
1949
  display: "grid",
1933
- gridTemplateColumns: `repeat(${w}, minmax(0, 1fr))`,
1950
+ gridTemplateColumns: `repeat(${T}, minmax(0, 1fr))`,
1934
1951
  gap: 24
1935
1952
  };
1936
- return f && p && v?.render ? /* @__PURE__ */ l("div", {
1953
+ return f && p && y?.render ? /* @__PURE__ */ l("div", {
1937
1954
  ref: h,
1938
1955
  style: {
1939
1956
  width: "100%",
1940
- ...T,
1957
+ ...E,
1941
1958
  ...x(m)
1942
1959
  },
1943
- children: C.map((e) => /* @__PURE__ */ l("div", {
1960
+ children: w.map((e) => /* @__PURE__ */ l("div", {
1944
1961
  style: { minWidth: 0 },
1945
- children: v.render(p, (t) => ie(t, e))
1962
+ children: y.render(p, (t) => ie(t, e))
1946
1963
  }, e.id ?? e?.data?.slug))
1947
1964
  }) : /* @__PURE__ */ l("div", {
1948
1965
  ref: h,
1949
1966
  style: {
1950
1967
  width: "100%",
1951
- ...T,
1968
+ ...E,
1952
1969
  ...x(m)
1953
1970
  },
1954
- children: C.map((e) => {
1971
+ children: w.map((e) => {
1955
1972
  let t = o ? K(e?.data, o) : null, r = c ? q(K(e?.data, c)) : null, i = d ? K(e?.data, d) : null, a = Array.isArray(i) ? i : null, s = a || i == null ? null : q(i), f = n === "list";
1956
1973
  return /* @__PURE__ */ u("div", {
1957
1974
  style: {
@@ -2007,7 +2024,7 @@ function dt({ collection: e, limit: t = 6, layout: n = "grid", columns: a = 3, i
2007
2024
  })
2008
2025
  });
2009
2026
  }
2010
- function ft({ items: e = [], separator: t = "/", style: n, nodeRef: r }) {
2027
+ function pt({ items: e = [], separator: t = "/", style: n, nodeRef: r }) {
2011
2028
  return e.length ? /* @__PURE__ */ l("nav", {
2012
2029
  ref: r,
2013
2030
  "aria-label": "Breadcrumb",
@@ -2057,7 +2074,7 @@ function ft({ items: e = [], separator: t = "/", style: n, nodeRef: r }) {
2057
2074
  })
2058
2075
  }) : null;
2059
2076
  }
2060
- function pt({ pages: e = 5, current: t = 1, prevNext: n = !0, href: r = "#", style: i, nodeRef: a }) {
2077
+ function mt({ pages: e = 5, current: t = 1, prevNext: n = !0, href: r = "#", style: i, nodeRef: a }) {
2061
2078
  let o = Math.min(Math.max(Number(e) || 1, 1), 50), s = Math.min(Math.max(Number(t) || 1, 1), o), c = (e) => r && r !== "#" ? r.replace("{page}", String(e)) : "#", d = (e) => ({
2062
2079
  display: "inline-flex",
2063
2080
  alignItems: "center",
@@ -2110,7 +2127,7 @@ function pt({ pages: e = 5, current: t = 1, prevNext: n = !0, href: r = "#", sty
2110
2127
  ]
2111
2128
  });
2112
2129
  }
2113
- function mt({ steps: e = [], active: n = 1, vertical: r = !1, style: i, nodeRef: a }) {
2130
+ function ht({ steps: e = [], active: n = 1, vertical: r = !1, style: i, nodeRef: a }) {
2114
2131
  if (!e.length) return null;
2115
2132
  let o = Math.min(Math.max(Number(n) || 1, 1), e.length), s = (e) => ({
2116
2133
  width: 32,
@@ -2188,7 +2205,7 @@ function mt({ steps: e = [], active: n = 1, vertical: r = !1, style: i, nodeRef:
2188
2205
  })
2189
2206
  });
2190
2207
  }
2191
- var ht = {
2208
+ var gt = {
2192
2209
  small: {
2193
2210
  w: 132,
2194
2211
  h: 46,
@@ -2210,10 +2227,10 @@ var ht = {
2210
2227
  title: 12.5,
2211
2228
  avatar: 46
2212
2229
  }
2213
- }, gt = (e) => ht[e] ?? ht.medium;
2214
- ht.medium.w, ht.medium.h;
2215
- function _t(e, { size: t = "medium", horizontal: n = !1 } = {}) {
2216
- let r = gt(t), i = n ? r.h : r.w, a = n ? 16 : 20, o = (n ? r.w : r.h) + (n ? 56 : 48), s = Array.isArray(e) ? e.filter((e) => e && e.id) : [], c = new Set(s.map((e) => e.id)), l = /* @__PURE__ */ new Map(), u = [];
2230
+ }, _t = (e) => gt[e] ?? gt.medium;
2231
+ gt.medium.w, gt.medium.h;
2232
+ function vt(e, { size: t = "medium", horizontal: n = !1 } = {}) {
2233
+ let r = _t(t), i = n ? r.h : r.w, a = n ? 16 : 20, o = (n ? r.w : r.h) + (n ? 56 : 48), s = Array.isArray(e) ? e.filter((e) => e && e.id) : [], c = new Set(s.map((e) => e.id)), l = /* @__PURE__ */ new Map(), u = [];
2217
2234
  for (let e of s) e.parent && c.has(e.parent) && e.parent !== e.id ? (l.has(e.parent) || l.set(e.parent, []), l.get(e.parent).push(e)) : u.push(e);
2218
2235
  let d = /* @__PURE__ */ new Map(), f = (e, t) => {
2219
2236
  if (t.has(e.id)) return 0;
@@ -2265,18 +2282,18 @@ function _t(e, { size: t = "medium", horizontal: n = !1 } = {}) {
2265
2282
  horizontal: n
2266
2283
  };
2267
2284
  }
2268
- var vt = (e, t) => {
2285
+ var yt = (e, t) => {
2269
2286
  let n = String(e ?? "");
2270
2287
  return n.length > t ? `${n.slice(0, t - 1)}…` : n;
2271
- }, yt = (e) => {
2288
+ }, bt = (e) => {
2272
2289
  let t = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(String(e ?? "").trim());
2273
2290
  if (!t) return "#ffffff";
2274
2291
  let n = t[1];
2275
2292
  n.length === 3 && (n = [...n].map((e) => e + e).join(""));
2276
2293
  let r = parseInt(n, 16);
2277
2294
  return .299 * (r >> 16 & 255) + .587 * (r >> 8 & 255) + .114 * (r & 255) > 150 ? "#111827" : "#ffffff";
2278
- }, bt = (e) => !!(e?.cv?.trim?.() || e?.photo);
2279
- function xt(e, t = {}) {
2295
+ }, xt = (e) => !!(e?.cv?.trim?.() || e?.photo);
2296
+ function St(e, t = {}) {
2280
2297
  let n = Array.isArray(e) ? e.filter((e) => e && typeof e == "object" && e.id) : [], r = (e) => Array.isArray(e) ? e[0] : e, i = (e) => e == null ? "" : q(e);
2281
2298
  return n.map((e) => {
2282
2299
  let n = e.data ?? {}, a = r(n[t.parentField]), o = a && typeof a == "object" ? a.id ?? null : a || null;
@@ -2291,11 +2308,11 @@ function xt(e, t = {}) {
2291
2308
  };
2292
2309
  });
2293
2310
  }
2294
- var St = {
2311
+ var Ct = {
2295
2312
  size: 36,
2296
2313
  pad: 10
2297
2314
  };
2298
- function Ct({ node: e, onClose: t }) {
2315
+ function wt({ node: e, onClose: t }) {
2299
2316
  return i(() => {
2300
2317
  let e = (e) => e.key === "Escape" && t();
2301
2318
  return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
@@ -2413,7 +2430,7 @@ function Ct({ node: e, onClose: t }) {
2413
2430
  })
2414
2431
  });
2415
2432
  }
2416
- function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField: d, parentField: f, cvField: p, hrefField: m, size: h = "medium", horizontal: g = !1, style: _, nodeRef: v, interactive: y = !0 }) {
2433
+ function Tt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField: d, parentField: f, cvField: p, hrefField: m, size: h = "medium", horizontal: g = !1, style: _, nodeRef: v, interactive: y = !0 }) {
2417
2434
  let b = a(), [S, C] = s(null), { tenant: w, apiUrl: T } = r(U), E = r(W)?.[t], [D, O] = s(null);
2418
2435
  i(() => {
2419
2436
  if (!t || E) return;
@@ -2430,14 +2447,14 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2430
2447
  T,
2431
2448
  E
2432
2449
  ]);
2433
- let k = t ? xt(E ?? D ?? [], {
2450
+ let k = t ? St(E ?? D ?? [], {
2434
2451
  nameField: n,
2435
2452
  titleField: o,
2436
2453
  photoField: d,
2437
2454
  parentField: f,
2438
2455
  cvField: p,
2439
2456
  hrefField: m
2440
- }) : e, A = gt(h), { boxes: j, links: M, width: N, height: P } = _t(k, {
2457
+ }) : e, A = _t(h), { boxes: j, links: M, width: N, height: P } = vt(k, {
2441
2458
  size: h,
2442
2459
  horizontal: g
2443
2460
  });
@@ -2483,7 +2500,7 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2483
2500
  stroke: "rgba(148, 163, 184, 0.7)",
2484
2501
  strokeWidth: "1.5"
2485
2502
  }, t)), j.map(({ node: e, x: t, y: n }) => {
2486
- let r = F.has(e.id), i = !!e.color2, a = !!e.color || r || i, o = e.color || (r ? "var(--page-accent, #4f46e5)" : "var(--page-bg, #ffffff)"), s = e.color ? yt(e.color) : r ? "var(--page-accent-text, #ffffff)" : "var(--page-text, #111827)", d = i ? yt(e.color2) : s, f = y && (bt(e) || e.href), p = () => bt(e) ? C(e) : window.open(e.href, "_blank", "noreferrer"), m = e.photo ? t + St.pad + A.avatar + 8 : t + A.w / 2, h = e.photo ? "start" : "middle", g = e.photo ? Math.floor((A.w - A.avatar - 26) / 7) : Math.floor(A.w / 7.6), _ = A.h / 2, v = [e.name, e.title].map((e) => String(e ?? "").trim()).filter(Boolean);
2503
+ let r = F.has(e.id), i = !!e.color2, a = !!e.color || r || i, o = e.color || (r ? "var(--page-accent, #4f46e5)" : "var(--page-bg, #ffffff)"), s = e.color ? bt(e.color) : r ? "var(--page-accent-text, #ffffff)" : "var(--page-text, #111827)", d = i ? bt(e.color2) : s, f = y && (xt(e) || e.href), p = () => xt(e) ? C(e) : window.open(e.href, "_blank", "noreferrer"), m = e.photo ? t + Ct.pad + A.avatar + 8 : t + A.w / 2, h = e.photo ? "start" : "middle", g = e.photo ? Math.floor((A.w - A.avatar - 26) / 7) : Math.floor(A.w / 7.6), _ = A.h / 2, v = [e.name, e.title].map((e) => String(e ?? "").trim()).filter(Boolean);
2487
2504
  return /* @__PURE__ */ u("g", {
2488
2505
  onClick: f ? p : void 0,
2489
2506
  style: f ? { cursor: "pointer" } : void 0,
@@ -2547,13 +2564,13 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2547
2564
  e.photo && /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("clipPath", {
2548
2565
  id: `${b}-${e.id}`,
2549
2566
  children: /* @__PURE__ */ l("circle", {
2550
- cx: t + St.pad + A.avatar / 2,
2567
+ cx: t + Ct.pad + A.avatar / 2,
2551
2568
  cy: n + A.h / 2,
2552
2569
  r: A.avatar / 2
2553
2570
  })
2554
2571
  }), /* @__PURE__ */ l("image", {
2555
2572
  href: e.photo,
2556
- x: t + St.pad,
2573
+ x: t + Ct.pad,
2557
2574
  y: n + (A.h - A.avatar) / 2,
2558
2575
  width: A.avatar,
2559
2576
  height: A.avatar,
@@ -2567,7 +2584,7 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2567
2584
  fontSize: A.title,
2568
2585
  fontWeight: "600",
2569
2586
  fill: s,
2570
- children: vt(e.title, g + 4)
2587
+ children: yt(e.title, g + 4)
2571
2588
  }), e.name && /* @__PURE__ */ l("text", {
2572
2589
  x: m,
2573
2590
  y: n + _ + _ / 2 + A.name * .35,
@@ -2575,7 +2592,7 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2575
2592
  fontSize: A.name,
2576
2593
  fontWeight: "600",
2577
2594
  fill: d,
2578
- children: vt(e.name, g)
2595
+ children: yt(e.name, g)
2579
2596
  })] }) : /* @__PURE__ */ u(c, { children: [v[0] && /* @__PURE__ */ l("text", {
2580
2597
  x: m,
2581
2598
  y: n + (v[1] ? A.h * .43 : A.h * .57),
@@ -2583,7 +2600,7 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2583
2600
  fontSize: A.name,
2584
2601
  fontWeight: "600",
2585
2602
  fill: s,
2586
- children: vt(v[0], g)
2603
+ children: yt(v[0], g)
2587
2604
  }), v[1] && /* @__PURE__ */ l("text", {
2588
2605
  x: m,
2589
2606
  y: n + A.h * .73,
@@ -2591,18 +2608,18 @@ function wt({ nodes: e = [], source: t, nameField: n, titleField: o, photoField:
2591
2608
  fontSize: A.title,
2592
2609
  opacity: "0.7",
2593
2610
  fill: s,
2594
- children: vt(v[1], g + 4)
2611
+ children: yt(v[1], g + 4)
2595
2612
  })] })
2596
2613
  ]
2597
2614
  }, e.id);
2598
2615
  })]
2599
- }), S && /* @__PURE__ */ l(Ct, {
2616
+ }), S && /* @__PURE__ */ l(wt, {
2600
2617
  node: S,
2601
2618
  onClose: () => C(null)
2602
2619
  })]
2603
2620
  });
2604
2621
  }
2605
- function Tt({ columns: e = [], rows: t = [], source: n, limit: a = 10, striped: o = !0, bordered: c = !1, compact: d = !1, style: f, nodeRef: p }) {
2622
+ function Et({ columns: e = [], rows: t = [], source: n, limit: a = 10, striped: o = !0, bordered: c = !1, compact: d = !1, style: f, nodeRef: p }) {
2606
2623
  let { tenant: m, apiUrl: h } = r(U), g = r(W)?.[n], [_, v] = s(null);
2607
2624
  if (i(() => {
2608
2625
  if (!n || g) return;
@@ -2653,7 +2670,7 @@ function Tt({ columns: e = [], rows: t = [], source: n, limit: a = 10, striped:
2653
2670
  })
2654
2671
  });
2655
2672
  }
2656
- var Et = {
2673
+ var Dt = {
2657
2674
  PageRoot: le,
2658
2675
  Section: ue,
2659
2676
  Container: de,
@@ -2666,13 +2683,13 @@ var Et = {
2666
2683
  SliderBlock: Be,
2667
2684
  CanvasSlider: Ve,
2668
2685
  TabsBlock: Ge,
2669
- QuickStack: ut,
2670
- CollectionList: dt,
2671
- BreadcrumbsBlock: ft,
2672
- PaginationBlock: pt,
2673
- StepperBlock: mt,
2674
- OrgChartBlock: wt,
2675
- TableBlock: Tt,
2686
+ QuickStack: dt,
2687
+ CollectionList: ft,
2688
+ BreadcrumbsBlock: pt,
2689
+ PaginationBlock: mt,
2690
+ StepperBlock: ht,
2691
+ OrgChartBlock: Tt,
2692
+ TableBlock: Et,
2676
2693
  AccordionBlock: Ke,
2677
2694
  NavbarBlock: We,
2678
2695
  ListBlock: Se,
@@ -2685,21 +2702,21 @@ var Et = {
2685
2702
  YouTubeBlock: Ae,
2686
2703
  IframeBlock: je,
2687
2704
  EmbedBlock: Me,
2688
- FormBlock: nt,
2689
- FormLabel: rt,
2690
- FormInput: it,
2691
- FormTextarea: at,
2692
- FormCheckbox: (e) => /* @__PURE__ */ l(ot, {
2705
+ FormBlock: rt,
2706
+ FormLabel: it,
2707
+ FormInput: at,
2708
+ FormTextarea: ot,
2709
+ FormCheckbox: (e) => /* @__PURE__ */ l(st, {
2693
2710
  kind: "checkbox",
2694
2711
  ...e
2695
2712
  }),
2696
- FormRadio: (e) => /* @__PURE__ */ l(ot, {
2713
+ FormRadio: (e) => /* @__PURE__ */ l(st, {
2697
2714
  kind: "radio",
2698
2715
  ...e
2699
2716
  }),
2700
- FormSelect: st,
2701
- FormFile: ct,
2702
- FormSubmit: lt
2717
+ FormSelect: ct,
2718
+ FormFile: lt,
2719
+ FormSubmit: ut
2703
2720
  };
2704
2721
  //#endregion
2705
2722
  //#region ../ui/src/components/builder/render.jsx
@@ -2713,7 +2730,7 @@ function Q(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
2713
2730
  let c = new Set(i).add(n);
2714
2731
  return /* @__PURE__ */ l(t, { children: Q(s.template.rootId, s.template.nodes, r, c, a) }, e);
2715
2732
  }
2716
- let u = Et[s];
2733
+ let u = Dt[s];
2717
2734
  if (!u) return null;
2718
2735
  let d = (o.nodes ?? []).map((e) => Q(e, n, r, i, a)).filter(Boolean), f = Object.entries(o.linkedNodes ?? {}), p = f.length ? Object.fromEntries(f.map(([e, t]) => [e, Q(t, n, r, i)])) : void 0;
2719
2736
  return /* @__PURE__ */ l(u, {
@@ -2728,8 +2745,8 @@ function Q(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
2728
2745
  }
2729
2746
  //#endregion
2730
2747
  //#region ../ui/src/components/builder/PageRenderer.jsx
2731
- var Dt = (e) => Object.entries(e).map(([e, t]) => `${e}: ${t};`).join(" ");
2732
- function Ot({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, custom: s, tenant: c, apiUrl: d, datasets: f, locale: m, direction: g }) {
2748
+ var Ot = (e) => Object.entries(e).map(([e, t]) => `${e}: ${t};`).join(" ");
2749
+ function kt({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, custom: s, tenant: c, apiUrl: d, datasets: f, locale: m, direction: g }) {
2733
2750
  let v = s?.js?.trim();
2734
2751
  if (i(() => {
2735
2752
  if (!v) return;
@@ -2751,7 +2768,8 @@ function Ot({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, cu
2751
2768
  if (r !== "auto") return /* @__PURE__ */ l(U.Provider, {
2752
2769
  value: {
2753
2770
  tenant: c || "",
2754
- apiUrl: d || "/api"
2771
+ apiUrl: d || "/api",
2772
+ locale: m || ""
2755
2773
  },
2756
2774
  children: /* @__PURE__ */ l(W.Provider, {
2757
2775
  value: f ?? null,
@@ -2779,7 +2797,8 @@ function Ot({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, cu
2779
2797
  return /* @__PURE__ */ l(U.Provider, {
2780
2798
  value: {
2781
2799
  tenant: c || "",
2782
- apiUrl: d || "/api"
2800
+ apiUrl: d || "/api",
2801
+ locale: m || ""
2783
2802
  },
2784
2803
  children: /* @__PURE__ */ l(W.Provider, {
2785
2804
  value: f ?? null,
@@ -2794,8 +2813,8 @@ function Ot({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, cu
2794
2813
  ...a
2795
2814
  },
2796
2815
  children: [
2797
- /* @__PURE__ */ l("style", { children: `.webim-page { ${Dt(V(D.light))} }
2798
- @media (prefers-color-scheme: dark) { .webim-page { ${Dt(V(D.dark))} } }` }),
2816
+ /* @__PURE__ */ l("style", { children: `.webim-page { ${Ot(V(D.light))} }
2817
+ @media (prefers-color-scheme: dark) { .webim-page { ${Ot(V(D.dark))} } }` }),
2799
2818
  E,
2800
2819
  C && /* @__PURE__ */ l("style", { children: C }),
2801
2820
  w && /* @__PURE__ */ l("style", { children: w }),
@@ -2809,8 +2828,8 @@ function Ot({ blocks: e, theme: t, components: n, mode: r = "auto", style: a, cu
2809
2828
  }
2810
2829
  //#endregion
2811
2830
  //#region src/WebimContent.jsx
2812
- function kt({ bundle: e, mode: t = "auto", style: n }) {
2813
- return e?.blocks?.ROOT ? /* @__PURE__ */ l(Ot, {
2831
+ function At({ bundle: e, mode: t = "auto", style: n }) {
2832
+ return e?.blocks?.ROOT ? /* @__PURE__ */ l(kt, {
2814
2833
  blocks: e.blocks,
2815
2834
  theme: e.theme,
2816
2835
  components: e.components,
@@ -2826,7 +2845,7 @@ function kt({ bundle: e, mode: t = "auto", style: n }) {
2826
2845
  }
2827
2846
  //#endregion
2828
2847
  //#region src/bundle.js
2829
- function At({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
2848
+ function jt({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
2830
2849
  let a = {
2831
2850
  ...t?.global ?? {},
2832
2851
  ...t?.tenant ?? {}
@@ -2849,18 +2868,18 @@ function At({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
2849
2868
  }
2850
2869
  //#endregion
2851
2870
  //#region src/fetchPage.js
2852
- var jt = async (e) => {
2871
+ var Mt = async (e) => {
2853
2872
  let t = await e.json().catch(() => null);
2854
2873
  if (!e.ok || t?.success === !1) throw Error(t?.error?.message || `Request failed (${e.status})`);
2855
2874
  return t?.payload ?? t;
2856
2875
  };
2857
- async function Mt({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, fetch: o }) {
2876
+ async function Nt({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, fetch: o }) {
2858
2877
  if (!e) throw Error("fetchPage: apiUrl is required");
2859
2878
  if (!n) throw Error("fetchPage: slug is required");
2860
2879
  let s = o ?? fetch, c = e.replace(/\/$/, ""), l = {
2861
2880
  ...t ? { "x-tenant": t } : {},
2862
2881
  ...a ? { authorization: `Bearer ${a}` } : {}
2863
- }, [u, d] = await Promise.all([s(`${c}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: l }).then(jt), s(`${c}/settings/public`, { headers: l }).then(jt)]), f = At({
2882
+ }, [u, d] = await Promise.all([s(`${c}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: l }).then(Mt), s(`${c}/settings/public`, { headers: l }).then(Mt)]), f = jt({
2864
2883
  page: u,
2865
2884
  settings: d,
2866
2885
  tenant: t,
@@ -2868,7 +2887,7 @@ async function Mt({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token:
2868
2887
  locale: r
2869
2888
  }), p = [...new Set(Object.values(f.blocks ?? {}).map((e) => e?.type?.resolvedName === "CollectionList" ? e.props?.collection : e?.type?.resolvedName === "TableBlock" || e?.type?.resolvedName === "OrgChartBlock" ? e.props?.source : null).filter(Boolean))];
2870
2889
  if (p.length) {
2871
- let e = (e) => e.startsWith("api:") ? `${c}/data/${encodeURIComponent(e.slice(4))}` : `${c}/dynamic/${encodeURIComponent(e)}${r ? `?locale=${encodeURIComponent(r)}` : ""}`, t = await Promise.all(p.map((t) => s(e(t), { headers: l }).then(jt).then((e) => [t, Array.isArray(e) ? e : []]).catch(() => [t, []])));
2890
+ let e = (e) => e.startsWith("api:") ? `${c}/data/${encodeURIComponent(e.slice(4))}` : `${c}/dynamic/${encodeURIComponent(e)}${r ? `?locale=${encodeURIComponent(r)}` : ""}`, t = await Promise.all(p.map((t) => s(e(t), { headers: l }).then(Mt).then((e) => [t, Array.isArray(e) ? e : Array.isArray(e?.data) ? e.data : []]).catch(() => [t, []])));
2872
2891
  f.datasets = Object.fromEntries(t);
2873
2892
  }
2874
2893
  return f;
@@ -2881,14 +2900,14 @@ var $ = (e) => String(e ?? "").replace(/[&<>"]/g, (e) => ({
2881
2900
  ">": "&gt;",
2882
2901
  "\"": "&quot;"
2883
2902
  })[e]);
2884
- function Nt(t, { mode: n = "auto", style: r } = {}) {
2885
- return e(/* @__PURE__ */ l(kt, {
2903
+ function Pt(t, { mode: n = "auto", style: r } = {}) {
2904
+ return e(/* @__PURE__ */ l(At, {
2886
2905
  bundle: t,
2887
2906
  mode: n,
2888
2907
  style: r
2889
2908
  }));
2890
2909
  }
2891
- function Pt(e, { mode: t = "auto", lang: n } = {}) {
2910
+ function Ft(e, { mode: t = "auto", lang: n } = {}) {
2892
2911
  let r = e.seo ?? {}, i = n || e.locale || "en", a = p(e.direction, i), o = r.title || e.title || e.slug || "Page", s = e.custom?.js?.trim(), c = [
2893
2912
  "<meta charset=\"utf-8\"/>",
2894
2913
  "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>",
@@ -2905,10 +2924,10 @@ function Pt(e, { mode: t = "auto", lang: n } = {}) {
2905
2924
  ${c}
2906
2925
  </head>
2907
2926
  <body>
2908
- ${Nt(e, { mode: t })}
2927
+ ${Pt(e, { mode: t })}
2909
2928
  ${s ? `<script>${s.replaceAll("<\/script", "<\\/script")}<\/script>` : ""}
2910
2929
  </body>
2911
2930
  </html>`;
2912
2931
  }
2913
2932
  //#endregion
2914
- export { At as assembleBundle, Mt as fetchPage, Nt as renderBundleHtml, Pt as renderPageDocument };
2933
+ export { jt as assembleBundle, Nt as fetchPage, Pt as renderBundleHtml, Ft as renderPageDocument };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webim-adapter",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Render WebIM builder pages inside any React app",
5
5
  "author": "Orhan POLAT",
6
6
  "license": "ISC",