webim-adapter 0.25.0 → 0.26.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.
@@ -3797,43 +3797,156 @@ function tn({ greeting: e = "Hi", signOutLabel: t = "Sign out", showEmail: n = !
3797
3797
  });
3798
3798
  }
3799
3799
  //#endregion
3800
+ //#region ../ui/src/components/builder/apps/language/manifest.js
3801
+ var nn = {
3802
+ id: "language",
3803
+ label: "Language",
3804
+ category: "Apps",
3805
+ keys: ["SiteLanguagePicker"],
3806
+ ssr: "prefetch",
3807
+ settings: ["locales"]
3808
+ };
3809
+ //#endregion
3810
+ //#region ../ui/src/components/builder/apps/language/views.jsx
3811
+ function rn(e) {
3812
+ let t = e?.locales, n = [typeof t?.default == "string" && t.default.trim() ? t.default.trim() : "", ...Array.isArray(t?.enabled) ? t.enabled : []].filter((e) => typeof e == "string" && e.trim());
3813
+ return [...new Set(n.map((e) => e.trim()))];
3814
+ }
3815
+ var an = (e) => e && e.charAt(0).toUpperCase() + e.slice(1);
3816
+ function on(e, t) {
3817
+ let n = String(e ?? "").toUpperCase();
3818
+ if (t === "code") return n;
3819
+ let r = "";
3820
+ try {
3821
+ r = an(new Intl.DisplayNames([e], { type: "language" }).of(e) ?? "");
3822
+ } catch {}
3823
+ return !r || r.toUpperCase() === n ? n : t === "both" ? `${n} — ${r}` : r;
3824
+ }
3825
+ function sn(e, t) {
3826
+ let n = t ? "" : `?locale=${encodeURIComponent(e)}`;
3827
+ if (typeof window > "u") return n || "?";
3828
+ try {
3829
+ let n = new URL(window.location.href);
3830
+ return t ? n.searchParams.delete("locale") : n.searchParams.set("locale", e), n.searchParams.delete("page"), `${n.pathname}${n.search}${n.hash}`;
3831
+ } catch {
3832
+ return n || "/";
3833
+ }
3834
+ }
3835
+ function cn({ variant: e, display: t, separator: n, label: r, style: a, nodeRef: o, inert: s }) {
3836
+ let c = i(V), l = rn(c?.settings), u = l[0] ?? "", p = l.includes(c?.locale) ? c.locale : u, m = {
3837
+ display: "inline-flex",
3838
+ alignItems: "center",
3839
+ gap: 8,
3840
+ ...D(a)
3841
+ };
3842
+ if (l.length < 2) return s ? /* @__PURE__ */ d("div", {
3843
+ ref: o,
3844
+ style: {
3845
+ ...m,
3846
+ padding: "8px 12px",
3847
+ border: "1px dashed rgba(100, 116, 139, 0.45)",
3848
+ borderRadius: 6,
3849
+ color: "rgba(100, 116, 139, 0.8)",
3850
+ fontSize: 12
3851
+ },
3852
+ children: "Add site languages in Settings → Languages"
3853
+ }) : null;
3854
+ let h = r ? /* @__PURE__ */ d("span", {
3855
+ style: { opacity: .7 },
3856
+ children: r
3857
+ }) : null;
3858
+ return e === "inline" ? /* @__PURE__ */ f("div", {
3859
+ ref: o,
3860
+ style: m,
3861
+ children: [h, l.map((e, r) => /* @__PURE__ */ f("span", {
3862
+ style: {
3863
+ display: "inline-flex",
3864
+ alignItems: "center",
3865
+ gap: 8
3866
+ },
3867
+ children: [r > 0 && /* @__PURE__ */ d("span", {
3868
+ style: { opacity: .4 },
3869
+ children: n ?? "·"
3870
+ }), /* @__PURE__ */ d("a", {
3871
+ href: sn(e, e === u),
3872
+ hrefLang: e,
3873
+ "aria-current": e === p ? "true" : void 0,
3874
+ onClick: s ? (e) => e.preventDefault() : void 0,
3875
+ style: {
3876
+ color: e === p ? "var(--page-accent, inherit)" : "inherit",
3877
+ fontWeight: e === p ? 600 : 400,
3878
+ textDecoration: "none",
3879
+ cursor: s ? "default" : "pointer"
3880
+ },
3881
+ children: on(e, t)
3882
+ })]
3883
+ }, e))]
3884
+ }) : /* @__PURE__ */ f("div", {
3885
+ ref: o,
3886
+ style: m,
3887
+ children: [h, /* @__PURE__ */ d("select", {
3888
+ "aria-label": r || "Language",
3889
+ value: p,
3890
+ onChange: s ? void 0 : (e) => {
3891
+ let t = e.target.value;
3892
+ window.location.assign(sn(t, t === u));
3893
+ },
3894
+ onKeyDown: s ? (e) => e.preventDefault() : void 0,
3895
+ style: {
3896
+ font: "inherit",
3897
+ color: "inherit",
3898
+ background: "var(--page-surface, transparent)",
3899
+ border: "1px solid var(--page-border, rgba(148, 163, 184, 0.4))",
3900
+ borderRadius: 6,
3901
+ padding: "4px 8px",
3902
+ cursor: s ? "default" : "pointer"
3903
+ },
3904
+ children: l.map((e) => /* @__PURE__ */ d("option", {
3905
+ value: e,
3906
+ children: on(e, t)
3907
+ }, e))
3908
+ })]
3909
+ });
3910
+ }
3911
+ //#endregion
3800
3912
  //#region ../ui/src/components/builder/apps/index.js
3801
- var nn = [Yt], rn = {
3913
+ var ln = [Yt, nn], un = {
3802
3914
  SiteLoginForm: en,
3803
- SiteAccountMenu: tn
3915
+ SiteAccountMenu: tn,
3916
+ SiteLanguagePicker: cn
3804
3917
  };
3805
- new Set(nn.filter((e) => e.ssr === "shell").flatMap((e) => e.keys));
3918
+ new Set(ln.filter((e) => e.ssr === "shell").flatMap((e) => e.keys));
3806
3919
  //#endregion
3807
3920
  //#region ../ui/src/components/builder/plugins/runtime.js
3808
- var an = /* @__PURE__ */ new Map();
3809
- function on(e) {
3810
- if (an.has(e)) return an.get(e);
3921
+ var dn = /* @__PURE__ */ new Map();
3922
+ function fn(e) {
3923
+ if (dn.has(e)) return dn.get(e);
3811
3924
  let t = URL.createObjectURL(new Blob([e], { type: "text/javascript" })), n = import(
3812
3925
  /* @vite-ignore */
3813
3926
  /* webpackIgnore: true */
3814
3927
  t
3815
3928
  ).finally(() => URL.revokeObjectURL(t));
3816
- return an.set(e, n), n;
3929
+ return dn.set(e, n), n;
3817
3930
  }
3818
- function sn(e) {
3931
+ function pn(e) {
3819
3932
  let t = e && typeof e == "object" ? e.builder_plugins : null, n = t && typeof t == "object" ? t.plugins : null;
3820
3933
  return n && typeof n == "object" ? n : {};
3821
3934
  }
3822
3935
  //#endregion
3823
3936
  //#region ../ui/src/components/builder/plugins/view.jsx
3824
- async function cn(e, t) {
3825
- let n = await on(e);
3937
+ async function mn(e, t) {
3938
+ let n = await fn(e);
3826
3939
  return (Array.isArray(n?.default?.blocks) ? n.default.blocks : []).find((e) => e?.id === t && typeof e.mount == "function") ?? null;
3827
3940
  }
3828
- var ln = {
3941
+ var hn = {
3829
3942
  padding: "10px 12px",
3830
3943
  border: "1px dashed rgba(148, 163, 184, 0.5)",
3831
3944
  borderRadius: 8,
3832
3945
  fontSize: 12,
3833
3946
  opacity: .6
3834
3947
  };
3835
- function un({ pluginId: e, blockId: t, props: n, style: r, nodeRef: o }) {
3836
- let s = i(V), l = sn(s?.settings)[e], u = c(null), p = c(null), m = {
3948
+ function gn({ pluginId: e, blockId: t, props: n, style: r, nodeRef: o }) {
3949
+ let s = i(V), l = pn(s?.settings)[e], u = c(null), p = c(null), m = {
3837
3950
  tenant: s?.tenant ?? "",
3838
3951
  apiUrl: s?.apiUrl ?? "/api",
3839
3952
  locale: s?.locale ?? "",
@@ -3845,7 +3958,7 @@ function un({ pluginId: e, blockId: t, props: n, style: r, nodeRef: o }) {
3845
3958
  let e = u.current;
3846
3959
  if (!l?.code || !e) return;
3847
3960
  let n = !0;
3848
- return cn(l.code, t).then((e) => {
3961
+ return mn(l.code, t).then((e) => {
3849
3962
  if (!(!n || !e || !u.current)) {
3850
3963
  p.current = e;
3851
3964
  try {
@@ -3875,7 +3988,7 @@ function un({ pluginId: e, blockId: t, props: n, style: r, nodeRef: o }) {
3875
3988
  }) : /* @__PURE__ */ f("div", {
3876
3989
  ref: o,
3877
3990
  style: {
3878
- ...ln,
3991
+ ...hn,
3879
3992
  ...D(r)
3880
3993
  },
3881
3994
  children: [
@@ -3887,12 +4000,12 @@ function un({ pluginId: e, blockId: t, props: n, style: r, nodeRef: o }) {
3887
4000
  }
3888
4001
  //#endregion
3889
4002
  //#region ../ui/src/components/builder/render.jsx
3890
- var dn = {
4003
+ var _n = {
3891
4004
  ...Jt,
3892
- ...rn,
3893
- PluginBlock: un
4005
+ ...un,
4006
+ PluginBlock: gn
3894
4007
  };
3895
- function fn(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
4008
+ function vn(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
3896
4009
  let o = n[e];
3897
4010
  if (!o || o.hidden) return null;
3898
4011
  let s = o.type?.resolvedName, c = a?.mapProps ? a.mapProps(o.props ?? {}, s) : o.props ?? {};
@@ -3900,11 +4013,11 @@ function fn(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
3900
4013
  let n = o.props?.componentId, s = r?.[n];
3901
4014
  if (!s?.template || i.has(n)) return null;
3902
4015
  let c = new Set(i).add(n);
3903
- return /* @__PURE__ */ d(t, { children: fn(s.template.rootId, s.template.nodes, r, c, a) }, e);
4016
+ return /* @__PURE__ */ d(t, { children: vn(s.template.rootId, s.template.nodes, r, c, a) }, e);
3904
4017
  }
3905
- let l = dn[s];
4018
+ let l = _n[s];
3906
4019
  if (!l) return null;
3907
- let u = (o.nodes ?? []).map((e) => fn(e, n, r, i, a)).filter(Boolean), f = Object.entries(o.linkedNodes ?? {}), p = f.length ? Object.fromEntries(f.map(([e, t]) => [e, fn(t, n, r, i)])) : void 0, m = /* @__PURE__ */ d(l, {
4020
+ let u = (o.nodes ?? []).map((e) => vn(e, n, r, i, a)).filter(Boolean), f = Object.entries(o.linkedNodes ?? {}), p = f.length ? Object.fromEntries(f.map(([e, t]) => [e, vn(t, n, r, i)])) : void 0, m = /* @__PURE__ */ d(l, {
3908
4021
  ...c,
3909
4022
  ...s === "CollectionList" ? { templateId: o.linkedNodes?.card } : null,
3910
4023
  linked: p,
@@ -3920,9 +4033,9 @@ function fn(e, n, r, i = /* @__PURE__ */ new Set(), a = void 0) {
3920
4033
  }
3921
4034
  //#endregion
3922
4035
  //#region ../ui/src/components/builder/PageRenderer.jsx
3923
- var pn = (e) => Object.entries(e).map(([e, t]) => `${e}: ${t};`).join(" "), mn = (e) => `.webim-page[data-webim-mode="light"] { ${Object.entries(B(e.light)).map(([e, t]) => `${e}: ${t} !important;`).join(" ")} }
4036
+ var yn = (e) => Object.entries(e).map(([e, t]) => `${e}: ${t};`).join(" "), bn = (e) => `.webim-page[data-webim-mode="light"] { ${Object.entries(B(e.light)).map(([e, t]) => `${e}: ${t} !important;`).join(" ")} }
3924
4037
  .webim-page[data-webim-mode="dark"] { ${Object.entries(B(e.dark)).map(([e, t]) => `${e}: ${t} !important;`).join(" ")} }`;
3925
- function hn({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, custom: o, tenant: c, apiUrl: l, datasets: u, locale: p, direction: m, settings: g, siteUser: _ }) {
4038
+ function xn({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, custom: o, tenant: c, apiUrl: l, datasets: u, locale: p, direction: m, settings: g, siteUser: _ }) {
3926
4039
  let v = o?.js?.trim();
3927
4040
  if (a(() => {
3928
4041
  if (!v) return;
@@ -3936,11 +4049,11 @@ function hn({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, cu
3936
4049
  minHeight: "100%",
3937
4050
  display: "flex",
3938
4051
  flexDirection: "column"
3939
- }, w = fn("ROOT", e, n), T = s(() => ({ render: (t, r) => fn(t, e, n, void 0, { mapProps: r }) }), [e, n]), E = re(e, n), D = ne(e, n), O = o?.css?.trim(), k = z(t), A = [k.font, k.headingFont].filter((e) => typeof e == "string" && e.trim() && e !== "inherit" && !R[e]), j = [.../* @__PURE__ */ new Set([...C(e, n), ...A])].map((e) => /* @__PURE__ */ d("link", {
4052
+ }, w = vn("ROOT", e, n), T = s(() => ({ render: (t, r) => vn(t, e, n, void 0, { mapProps: r }) }), [e, n]), E = re(e, n), D = ne(e, n), O = o?.css?.trim(), k = z(t), A = [k.font, k.headingFont].filter((e) => typeof e == "string" && e.trim() && e !== "inherit" && !R[e]), j = [.../* @__PURE__ */ new Set([...C(e, n), ...A])].map((e) => /* @__PURE__ */ d("link", {
3940
4053
  rel: "stylesheet",
3941
4054
  precedence: "default",
3942
4055
  href: b(e)
3943
- }, e)), M = mn(k);
4056
+ }, e)), M = bn(k);
3944
4057
  return r === "auto" ? /* @__PURE__ */ d(V.Provider, {
3945
4058
  value: {
3946
4059
  tenant: c || "",
@@ -3963,8 +4076,8 @@ function hn({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, cu
3963
4076
  ...i
3964
4077
  },
3965
4078
  children: [
3966
- /* @__PURE__ */ d("style", { children: `.webim-page { ${pn(B(k.light))} }
3967
- @media (prefers-color-scheme: dark) { .webim-page { ${pn(B(k.dark))} } }` }),
4079
+ /* @__PURE__ */ d("style", { children: `.webim-page { ${yn(B(k.light))} }
4080
+ @media (prefers-color-scheme: dark) { .webim-page { ${yn(B(k.dark))} } }` }),
3968
4081
  /* @__PURE__ */ d("style", { children: M }),
3969
4082
  j,
3970
4083
  /* @__PURE__ */ d("style", { children: x }),
@@ -4015,8 +4128,8 @@ function hn({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, cu
4015
4128
  }
4016
4129
  //#endregion
4017
4130
  //#region src/WebimContent.jsx
4018
- function gn({ bundle: e, mode: t = "auto", style: n }) {
4019
- return e?.blocks?.ROOT ? /* @__PURE__ */ d(hn, {
4131
+ function Sn({ bundle: e, mode: t = "auto", style: n }) {
4132
+ return e?.blocks?.ROOT ? /* @__PURE__ */ d(xn, {
4020
4133
  blocks: e.blocks,
4021
4134
  theme: e.theme,
4022
4135
  components: e.components,
@@ -4033,7 +4146,7 @@ function gn({ bundle: e, mode: t = "auto", style: n }) {
4033
4146
  }
4034
4147
  //#endregion
4035
4148
  //#region src/bundle.js
4036
- function _n({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
4149
+ function Cn({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
4037
4150
  let a = {
4038
4151
  ...t?.global ?? {},
4039
4152
  ...t?.tenant ?? {}
@@ -4058,18 +4171,18 @@ function _n({ page: e, settings: t, tenant: n, apiUrl: r, locale: i }) {
4058
4171
  }
4059
4172
  //#endregion
4060
4173
  //#region src/fetchPage.js
4061
- var vn = async (e) => {
4174
+ var wn = async (e) => {
4062
4175
  let t = await e.json().catch(() => null);
4063
4176
  if (!e.ok || t?.success === !1) throw Error(t?.error?.message || `Request failed (${e.status})`);
4064
4177
  return t?.payload ?? t;
4065
4178
  };
4066
- async function yn({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, page: o, fetch: s }) {
4179
+ async function Tn({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, page: o, fetch: s }) {
4067
4180
  if (!e) throw Error("fetchPage: apiUrl is required");
4068
4181
  if (!n) throw Error("fetchPage: slug is required");
4069
4182
  let c = s ?? fetch, l = e.replace(/\/$/, ""), u = {
4070
4183
  ...t ? { "x-tenant": t } : {},
4071
4184
  ...a ? { authorization: `Bearer ${a}` } : {}
4072
- }, [d, f] = await Promise.all([c(`${l}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: u }).then(vn), c(`${l}/settings/public`, { headers: u }).then(vn)]), p = _n({
4185
+ }, [d, f] = await Promise.all([c(`${l}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: u }).then(wn), c(`${l}/settings/public`, { headers: u }).then(wn)]), p = Cn({
4073
4186
  page: d,
4074
4187
  settings: f,
4075
4188
  tenant: t,
@@ -4077,7 +4190,7 @@ async function yn({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token:
4077
4190
  locale: r
4078
4191
  }), m = [...new Set(Object.values(p.blocks ?? {}).map((e) => e?.type?.resolvedName === "CollectionList" ? e.props?.collection : e?.type?.resolvedName === "TableBlock" || e?.type?.resolvedName === "OrgChartBlock" ? e.props?.source : null).filter(Boolean))];
4079
4192
  if (m.length) {
4080
- let e = (e) => e.startsWith("api:") ? `${l}/data/${encodeURIComponent(e.slice(4))}` : `${l}/dynamic/${encodeURIComponent(e)}?all=1${r ? `&locale=${encodeURIComponent(r)}` : ""}`, t = await Promise.all(m.map((t) => c(e(t), { headers: u }).then(vn).then((e) => {
4193
+ let e = (e) => e.startsWith("api:") ? `${l}/data/${encodeURIComponent(e.slice(4))}` : `${l}/dynamic/${encodeURIComponent(e)}?all=1${r ? `&locale=${encodeURIComponent(r)}` : ""}`, t = await Promise.all(m.map((t) => c(e(t), { headers: u }).then(wn).then((e) => {
4081
4194
  let n = Array.isArray(e) ? e : Array.isArray(e?.data) ? e.data : [], r = Number(e?.total?.filtered ?? e?.total?.all ?? n.length);
4082
4195
  return [[t, n], [`${t}:total`, Number.isFinite(r) ? r : n.length]];
4083
4196
  }).catch(() => [[t, []]])));
@@ -4091,40 +4204,40 @@ async function yn({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token:
4091
4204
  }
4092
4205
  //#endregion
4093
4206
  //#region src/ssr.jsx
4094
- var bn = (e) => String(e ?? "").replace(/[&<>"]/g, (e) => ({
4207
+ var En = (e) => String(e ?? "").replace(/[&<>"]/g, (e) => ({
4095
4208
  "&": "&amp;",
4096
4209
  "<": "&lt;",
4097
4210
  ">": "&gt;",
4098
4211
  "\"": "&quot;"
4099
4212
  })[e]);
4100
- function xn(t, { mode: n = "auto", style: r } = {}) {
4101
- return e(/* @__PURE__ */ d(gn, {
4213
+ function Dn(t, { mode: n = "auto", style: r } = {}) {
4214
+ return e(/* @__PURE__ */ d(Sn, {
4102
4215
  bundle: t,
4103
4216
  mode: n,
4104
4217
  style: r
4105
4218
  }));
4106
4219
  }
4107
- function Sn(e, { mode: t = "auto", lang: n } = {}) {
4220
+ function On(e, { mode: t = "auto", lang: n } = {}) {
4108
4221
  let r = e.seo ?? {}, i = n || e.locale || "en", a = h(e.direction, i), o = r.title || e.title || e.slug || "Page", s = e.custom?.js?.trim(), c = [
4109
4222
  "<meta charset=\"utf-8\"/>",
4110
4223
  "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>",
4111
- `<title>${bn(o)}</title>`,
4112
- r.description && `<meta name="description" content="${bn(r.description)}"/>`,
4113
- `<meta property="og:title" content="${bn(o)}"/>`,
4114
- r.image && `<meta property="og:image" content="${bn(r.image)}"/>`,
4224
+ `<title>${En(o)}</title>`,
4225
+ r.description && `<meta name="description" content="${En(r.description)}"/>`,
4226
+ `<meta property="og:title" content="${En(o)}"/>`,
4227
+ r.image && `<meta property="og:image" content="${En(r.image)}"/>`,
4115
4228
  r.noindex && "<meta name=\"robots\" content=\"noindex\"/>",
4116
4229
  "<style>html,body{margin:0;height:100%}</style>"
4117
4230
  ].filter(Boolean).join("\n");
4118
4231
  return `<!doctype html>
4119
- <html lang="${bn(i)}"${a ? ` dir="${a}"` : ""}>
4232
+ <html lang="${En(i)}"${a ? ` dir="${a}"` : ""}>
4120
4233
  <head>
4121
4234
  ${c}
4122
4235
  </head>
4123
4236
  <body>
4124
- ${xn(e, { mode: t })}
4237
+ ${Dn(e, { mode: t })}
4125
4238
  ${s ? `<script>${s.replaceAll("<\/script", "<\\/script")}<\/script>` : ""}
4126
4239
  </body>
4127
4240
  </html>`;
4128
4241
  }
4129
4242
  //#endregion
4130
- export { _n as assembleBundle, yn as fetchPage, xn as renderBundleHtml, Sn as renderPageDocument };
4243
+ export { Cn as assembleBundle, Tn as fetchPage, Dn as renderBundleHtml, On as renderPageDocument };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webim-adapter",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Render WebIM builder pages inside any React app",
5
5
  "author": "Orhan POLAT",
6
6
  "license": "ISC",