webim-adapter 2.10.7 → 2.10.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.
- package/build/webim-adapter.js +28 -5
- package/build/webim-embed.js +1 -1
- package/build/webim-ssr.js +42 -19
- package/package.json +1 -1
package/build/webim-adapter.js
CHANGED
|
@@ -15921,8 +15921,31 @@ function ad({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, cu
|
|
|
15921
15921
|
}
|
|
15922
15922
|
//#endregion
|
|
15923
15923
|
//#region src/WebimContent.jsx
|
|
15924
|
-
function od(
|
|
15925
|
-
|
|
15924
|
+
function od(e) {
|
|
15925
|
+
let t = e?.apiUrl, n = e?.tenant, r = e?.slug;
|
|
15926
|
+
s(() => {
|
|
15927
|
+
if (typeof window > "u" || !r || !t || new URLSearchParams(window.location.search).has("preview") || navigator.doNotTrack === "1" || window.doNotTrack === "1") return;
|
|
15928
|
+
let e = `webim.viewed.${n}.${r}`;
|
|
15929
|
+
try {
|
|
15930
|
+
if (window.sessionStorage.getItem(e)) return;
|
|
15931
|
+
window.sessionStorage.setItem(e, "1");
|
|
15932
|
+
} catch {}
|
|
15933
|
+
let i = `${t}/site/views?tenant=${encodeURIComponent(n ?? "")}&slug=${encodeURIComponent(r)}`;
|
|
15934
|
+
try {
|
|
15935
|
+
navigator.sendBeacon?.(i) || fetch(i, {
|
|
15936
|
+
method: "POST",
|
|
15937
|
+
keepalive: !0,
|
|
15938
|
+
mode: "no-cors"
|
|
15939
|
+
}).catch(() => {});
|
|
15940
|
+
} catch {}
|
|
15941
|
+
}, [
|
|
15942
|
+
t,
|
|
15943
|
+
n,
|
|
15944
|
+
r
|
|
15945
|
+
]);
|
|
15946
|
+
}
|
|
15947
|
+
function sd({ bundle: e, mode: t = "auto", style: n }) {
|
|
15948
|
+
return od(e), e?.blocks?.ROOT ? /* @__PURE__ */ h(ad, {
|
|
15926
15949
|
blocks: e.blocks,
|
|
15927
15950
|
theme: e.theme,
|
|
15928
15951
|
components: e.components,
|
|
@@ -15941,7 +15964,7 @@ function od({ bundle: e, mode: t = "auto", style: n }) {
|
|
|
15941
15964
|
}
|
|
15942
15965
|
//#endregion
|
|
15943
15966
|
//#region src/WebimPage.jsx
|
|
15944
|
-
function
|
|
15967
|
+
function cd({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, mode: o = "auto", style: c, fallback: l = null, errorFallback: f = null, onLoad: p, onError: m }) {
|
|
15945
15968
|
let [g, _] = d({ status: "loading" }), v = u({
|
|
15946
15969
|
onLoad: p,
|
|
15947
15970
|
onError: m
|
|
@@ -15978,11 +16001,11 @@ function sd({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, mo
|
|
|
15978
16001
|
r,
|
|
15979
16002
|
i,
|
|
15980
16003
|
a
|
|
15981
|
-
]), g.status === "loading" ? l : g.status === "error" ? typeof f == "function" ? f(g.error) : f : /* @__PURE__ */ h(
|
|
16004
|
+
]), g.status === "loading" ? l : g.status === "error" ? typeof f == "function" ? f(g.error) : f : /* @__PURE__ */ h(sd, {
|
|
15982
16005
|
bundle: g.bundle,
|
|
15983
16006
|
mode: o,
|
|
15984
16007
|
style: c
|
|
15985
16008
|
});
|
|
15986
16009
|
}
|
|
15987
16010
|
//#endregion
|
|
15988
|
-
export { ad as PageRenderer,
|
|
16011
|
+
export { ad as PageRenderer, sd as WebimContent, cd as WebimPage, ft as fetchPage, qr as renderRichContent, ct as resolveTheme };
|
package/build/webim-embed.js
CHANGED
|
@@ -112,4 +112,4 @@ Error generating stack: `+e.message+`
|
|
|
112
112
|
.webim-page[data-webim-mode="dark"] { ${Object.entries(Ze(e.dark)).map(([e,t])=>`${e}: ${t} !important;`).join(` `)} }`;function rd({blocks:e,theme:t,components:n,mode:r=`auto`,style:i,custom:a,animations:o,tenant:s,apiUrl:c,datasets:u,locale:d,direction:f,settings:p,siteUser:m,param:g}){let _=a?.js?.trim(),y=p&&p[`site.code`]&&typeof p[`site.code`]==`object`?p[`site.code`]:null,b=typeof y?.js==`string`?y.js.trim():``,x=typeof y?.css==`string`?y.css.trim():``;if((0,l.useEffect)(()=>{if(!b)return;let e=document.createElement(`script`);return e.text=b,document.body.appendChild(e),()=>e.remove()},[b]),(0,l.useEffect)(()=>{if(!_)return;let e=document.createElement(`script`);return e.text=_,document.body.appendChild(e),()=>e.remove()},[_]),!e?.ROOT)return null;let S={lang:d||void 0,dir:Tt(f,d)},C=`.webim-page, .webim-page *, .webim-page *::before, .webim-page *::after { box-sizing: border-box; }
|
|
113
113
|
`+Re+`
|
|
114
114
|
`+ht,w={minHeight:`100%`,display:`flex`,flexDirection:`column`},T=St(e,n),E=Pe(p),D=ed(`ROOT`,e,n,void 0,{skipTarget:T||void 0,elementDefaults:E}),O=T?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`style`,{children:gt}),(0,G.jsx)(`a`,{className:`webim-skip`,href:`#${T.htmlId}`,children:pt(d||p?.locales?.default)(`skip`)})]}):null,k=(0,l.useMemo)(()=>({render:(t,r)=>ed(t,e,n,void 0,{mapProps:r,elementDefaults:E})}),[e,n,E]),A=Oe(e,n,E),j=De(e,n,E),M=a?.css?.trim(),N=F(o),P=Je(t),I=[P.font,P.headingFont].filter(e=>typeof e==`string`&&e.trim()&&e!==`inherit`&&!Ge[e]),L=[...new Set([...v(e,n),...I])].map(e=>(0,G.jsx)(`link`,{rel:`stylesheet`,precedence:`default`,href:h(e)},e)),R=nd(P),z=nt(t);return r===`auto`?(0,G.jsx)(Xn.Provider,{value:{tenant:s||``,apiUrl:c||`/api`,locale:d||``,settings:p??null,param:g||``},children:(0,G.jsx)(gs,{initialUser:m,children:(0,G.jsx)(Zn.Provider,{value:u??null,children:(0,G.jsx)(tr.Provider,{value:k,children:(0,G.jsxs)(`div`,{...S,className:`webim-page`,style:{...w,...Qe(t),...i},children:[O,(0,G.jsx)(`style`,{children:`.webim-page { ${td(Ze(P.light))} }
|
|
115
|
-
@media (prefers-color-scheme: dark) { .webim-page { ${td(Ze(P.dark))} } }`}),(0,G.jsx)(`style`,{children:R}),L,(0,G.jsx)(`style`,{children:C}),z&&(0,G.jsx)(`style`,{children:z}),A&&(0,G.jsx)(`style`,{children:A}),j&&(0,G.jsx)(`style`,{children:j}),N&&(0,G.jsx)(`style`,{children:N}),x&&(0,G.jsx)(`style`,{children:x}),M&&(0,G.jsx)(`style`,{children:M}),D]})})})})}):(0,G.jsx)(Xn.Provider,{value:{tenant:s||``,apiUrl:c||`/api`,locale:d||``,settings:p??null,param:g||``},children:(0,G.jsx)(gs,{initialUser:m,children:(0,G.jsx)(Zn.Provider,{value:u??null,children:(0,G.jsx)(tr.Provider,{value:k,children:(0,G.jsxs)(`div`,{...S,className:`webim-page`,style:{...w,...at(t,r),...i},children:[O,L,(0,G.jsx)(`style`,{children:R}),(0,G.jsx)(`style`,{children:C}),z&&(0,G.jsx)(`style`,{children:z}),A&&(0,G.jsx)(`style`,{children:A}),j&&(0,G.jsx)(`style`,{children:j}),N&&(0,G.jsx)(`style`,{children:N}),x&&(0,G.jsx)(`style`,{children:x}),M&&(0,G.jsx)(`style`,{children:M}),D]})})})})})}function id({bundle:e,mode:t=`auto`,style:n}){return e?.blocks?.ROOT?(0,G.jsx)(rd,{blocks:e.blocks,theme:e.theme,components:e.components,custom:e.custom,animations:e.animations,tenant:e.tenant,apiUrl:e.apiUrl,datasets:e.datasets,locale:e.locale,direction:e.direction,settings:e.settings,param:e.param,mode:st(t,e.scheme),style:n}):null}function
|
|
115
|
+
@media (prefers-color-scheme: dark) { .webim-page { ${td(Ze(P.dark))} } }`}),(0,G.jsx)(`style`,{children:R}),L,(0,G.jsx)(`style`,{children:C}),z&&(0,G.jsx)(`style`,{children:z}),A&&(0,G.jsx)(`style`,{children:A}),j&&(0,G.jsx)(`style`,{children:j}),N&&(0,G.jsx)(`style`,{children:N}),x&&(0,G.jsx)(`style`,{children:x}),M&&(0,G.jsx)(`style`,{children:M}),D]})})})})}):(0,G.jsx)(Xn.Provider,{value:{tenant:s||``,apiUrl:c||`/api`,locale:d||``,settings:p??null,param:g||``},children:(0,G.jsx)(gs,{initialUser:m,children:(0,G.jsx)(Zn.Provider,{value:u??null,children:(0,G.jsx)(tr.Provider,{value:k,children:(0,G.jsxs)(`div`,{...S,className:`webim-page`,style:{...w,...at(t,r),...i},children:[O,L,(0,G.jsx)(`style`,{children:R}),(0,G.jsx)(`style`,{children:C}),z&&(0,G.jsx)(`style`,{children:z}),A&&(0,G.jsx)(`style`,{children:A}),j&&(0,G.jsx)(`style`,{children:j}),N&&(0,G.jsx)(`style`,{children:N}),x&&(0,G.jsx)(`style`,{children:x}),M&&(0,G.jsx)(`style`,{children:M}),D]})})})})})}function id(e){let t=e?.apiUrl,n=e?.tenant,r=e?.slug;(0,l.useEffect)(()=>{if(typeof window>`u`||!r||!t||new URLSearchParams(window.location.search).has(`preview`)||navigator.doNotTrack===`1`||window.doNotTrack===`1`)return;let e=`webim.viewed.${n}.${r}`;try{if(window.sessionStorage.getItem(e))return;window.sessionStorage.setItem(e,`1`)}catch{}let i=`${t}/site/views?tenant=${encodeURIComponent(n??``)}&slug=${encodeURIComponent(r)}`;try{navigator.sendBeacon?.(i)||fetch(i,{method:`POST`,keepalive:!0,mode:`no-cors`}).catch(()=>{})}catch{}},[t,n,r])}function ad({bundle:e,mode:t=`auto`,style:n}){return id(e),e?.blocks?.ROOT?(0,G.jsx)(rd,{blocks:e.blocks,theme:e.theme,components:e.components,custom:e.custom,animations:e.animations,tenant:e.tenant,apiUrl:e.apiUrl,datasets:e.datasets,locale:e.locale,direction:e.direction,settings:e.settings,param:e.param,mode:st(t,e.scheme),style:n}):null}function od({apiUrl:e,tenant:t,slug:n,locale:r,preview:i,token:a,mode:o=`auto`,style:s,fallback:c=null,errorFallback:u=null,onLoad:d,onError:f}){let[p,m]=(0,l.useState)({status:`loading`}),h=(0,l.useRef)({onLoad:d,onError:f});return h.current={onLoad:d,onError:f},(0,l.useEffect)(()=>{let o=!0;return m({status:`loading`}),ut({apiUrl:e,tenant:t,slug:n,locale:r,preview:i,token:a}).then(e=>{o&&(m({status:`ready`,bundle:e}),h.current.onLoad?.(e))}).catch(e=>{o&&(m({status:`error`,error:e}),h.current.onError?.(e))}),()=>{o=!1}},[e,t,n,r,i,a]),p.status===`loading`?c:p.status===`error`?typeof u==`function`?u(p.error):u:(0,G.jsx)(ad,{bundle:p.bundle,mode:o,style:s})}function sd(e,t={}){let n=(0,u.createRoot)(e);return n.render((0,G.jsx)(od,{apiUrl:t.apiUrl||t.api,tenant:t.tenant,slug:t.slug,locale:t.locale||void 0,token:t.token||void 0,mode:t.mode||`auto`,onError:e=>console.error(`[webim-embed]`,t.slug,e)})),n}function cd(e=document){for(let t of e.querySelectorAll(`[data-webim-page]:not([data-webim-mounted])`))t.setAttribute(`data-webim-mounted`,``),sd(t,t.dataset)}var ld=document.currentScript,ud=()=>{if(cd(),ld?.dataset.slug){let e=document.createElement(`div`);e.setAttribute(`data-webim-mounted`,``),ld.parentElement&&ld.parentElement!==document.head?ld.insertAdjacentElement(`beforebegin`,e):document.body.appendChild(e),sd(e,ld.dataset)}};document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,ud,{once:!0}):ud(),window.WebimEmbed={mount:sd,scan:cd}})();
|
package/build/webim-ssr.js
CHANGED
|
@@ -15878,8 +15878,31 @@ function id({ blocks: e, theme: t, components: n, mode: r = "auto", style: i, cu
|
|
|
15878
15878
|
}
|
|
15879
15879
|
//#endregion
|
|
15880
15880
|
//#region src/WebimContent.jsx
|
|
15881
|
-
function ad(
|
|
15882
|
-
|
|
15881
|
+
function ad(e) {
|
|
15882
|
+
let t = e?.apiUrl, n = e?.tenant, r = e?.slug;
|
|
15883
|
+
c(() => {
|
|
15884
|
+
if (typeof window > "u" || !r || !t || new URLSearchParams(window.location.search).has("preview") || navigator.doNotTrack === "1" || window.doNotTrack === "1") return;
|
|
15885
|
+
let e = `webim.viewed.${n}.${r}`;
|
|
15886
|
+
try {
|
|
15887
|
+
if (window.sessionStorage.getItem(e)) return;
|
|
15888
|
+
window.sessionStorage.setItem(e, "1");
|
|
15889
|
+
} catch {}
|
|
15890
|
+
let i = `${t}/site/views?tenant=${encodeURIComponent(n ?? "")}&slug=${encodeURIComponent(r)}`;
|
|
15891
|
+
try {
|
|
15892
|
+
navigator.sendBeacon?.(i) || fetch(i, {
|
|
15893
|
+
method: "POST",
|
|
15894
|
+
keepalive: !0,
|
|
15895
|
+
mode: "no-cors"
|
|
15896
|
+
}).catch(() => {});
|
|
15897
|
+
} catch {}
|
|
15898
|
+
}, [
|
|
15899
|
+
t,
|
|
15900
|
+
n,
|
|
15901
|
+
r
|
|
15902
|
+
]);
|
|
15903
|
+
}
|
|
15904
|
+
function od({ bundle: e, mode: t = "auto", style: n }) {
|
|
15905
|
+
return ad(e), e?.blocks?.ROOT ? /* @__PURE__ */ g(id, {
|
|
15883
15906
|
blocks: e.blocks,
|
|
15884
15907
|
theme: e.theme,
|
|
15885
15908
|
components: e.components,
|
|
@@ -15898,24 +15921,24 @@ function ad({ bundle: e, mode: t = "auto", style: n }) {
|
|
|
15898
15921
|
}
|
|
15899
15922
|
//#endregion
|
|
15900
15923
|
//#region src/fetchPage.js
|
|
15901
|
-
var
|
|
15924
|
+
var sd = async (e) => {
|
|
15902
15925
|
let t = await e.json().catch(() => null);
|
|
15903
15926
|
if (!e.ok || t?.success === !1) throw Error(t?.error?.message || `Request failed (${e.status})`);
|
|
15904
15927
|
return t?.payload ?? t;
|
|
15905
15928
|
};
|
|
15906
|
-
async function
|
|
15929
|
+
async function cd({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token: a, page: o, fetch: s }) {
|
|
15907
15930
|
if (!e) throw Error("fetchPage: apiUrl is required");
|
|
15908
15931
|
if (!n) throw Error("fetchPage: slug is required");
|
|
15909
15932
|
let c = s ?? fetch, l = e.replace(/\/$/, ""), u = {
|
|
15910
15933
|
...t ? { "x-tenant": t } : {},
|
|
15911
15934
|
...a ? { authorization: `Bearer ${a}` } : {}
|
|
15912
|
-
}, [d, f] = await Promise.all([c(`${l}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: u }).then(
|
|
15935
|
+
}, [d, f] = await Promise.all([c(`${l}/render/${encodeURIComponent(n)}${i ? `?preview=${encodeURIComponent(i)}` : ""}`, { headers: u }).then(sd), c(`${l}/settings/public`, { headers: u }).then(sd)]), p = mt({
|
|
15913
15936
|
page: d,
|
|
15914
15937
|
settings: f,
|
|
15915
15938
|
tenant: t,
|
|
15916
15939
|
apiUrl: l,
|
|
15917
15940
|
locale: r
|
|
15918
|
-
}), m = [...new Set(
|
|
15941
|
+
}), m = [...new Set(ld(p.blocks, p.components).map((e) => e?.type?.resolvedName === "CollectionList" ? e.props?.collection : [
|
|
15919
15942
|
"TableBlock",
|
|
15920
15943
|
"OrgChartBlock",
|
|
15921
15944
|
"NavbarBlock",
|
|
@@ -15926,7 +15949,7 @@ async function sd({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token:
|
|
|
15926
15949
|
"LogoCarousel"
|
|
15927
15950
|
].includes(e?.type?.resolvedName) ? e.props?.source : null).filter(Boolean))];
|
|
15928
15951
|
if (m.length) {
|
|
15929
|
-
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(
|
|
15952
|
+
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(sd).then((e) => {
|
|
15930
15953
|
let n = Array.isArray(e) ? e : Array.isArray(e?.data) ? e.data : [], r = Number(e?.total?.filtered ?? e?.total?.all ?? n.length);
|
|
15931
15954
|
return [[t, n], [`${t}:total`, Number.isFinite(r) ? r : n.length]];
|
|
15932
15955
|
}).catch(() => [[t, []]])));
|
|
@@ -15938,7 +15961,7 @@ async function sd({ apiUrl: e, tenant: t, slug: n, locale: r, preview: i, token:
|
|
|
15938
15961
|
__page: Math.floor(h)
|
|
15939
15962
|
}), p;
|
|
15940
15963
|
}
|
|
15941
|
-
function
|
|
15964
|
+
function ld(e, t) {
|
|
15942
15965
|
let n = [], r = /* @__PURE__ */ new Set(), i = (e) => {
|
|
15943
15966
|
Object.values(e ?? {}).forEach((e) => {
|
|
15944
15967
|
n.push(e);
|
|
@@ -15950,41 +15973,41 @@ function cd(e, t) {
|
|
|
15950
15973
|
}
|
|
15951
15974
|
//#endregion
|
|
15952
15975
|
//#region src/ssr.jsx
|
|
15953
|
-
var
|
|
15976
|
+
var ud = (e) => String(e ?? "").replace(/[&<>"]/g, (e) => ({
|
|
15954
15977
|
"&": "&",
|
|
15955
15978
|
"<": "<",
|
|
15956
15979
|
">": ">",
|
|
15957
15980
|
"\"": """
|
|
15958
15981
|
})[e]);
|
|
15959
|
-
function
|
|
15960
|
-
return e(/* @__PURE__ */ g(
|
|
15982
|
+
function dd(t, { mode: n = "auto", style: r } = {}) {
|
|
15983
|
+
return e(/* @__PURE__ */ g(od, {
|
|
15961
15984
|
bundle: t,
|
|
15962
15985
|
mode: n,
|
|
15963
15986
|
style: r
|
|
15964
15987
|
}));
|
|
15965
15988
|
}
|
|
15966
|
-
function
|
|
15989
|
+
function fd(e, { mode: t = "auto", lang: n } = {}) {
|
|
15967
15990
|
let r = e.seo ?? {}, i = n || e.locale || "en", a = b(e.direction, i), o = ht(e) || "Page", s = e.custom?.js?.trim(), c = e.settings?.["site.code"], l = typeof c?.js == "string" ? c.js.trim() : "", u = (e) => `<script>${e.replaceAll("<\/script", "<\\/script")}<\/script>`, d = [
|
|
15968
15991
|
"<meta charset=\"utf-8\"/>",
|
|
15969
15992
|
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>",
|
|
15970
|
-
`<title>${
|
|
15971
|
-
r.description && `<meta name="description" content="${
|
|
15972
|
-
`<meta property="og:title" content="${
|
|
15973
|
-
r.image && `<meta property="og:image" content="${
|
|
15993
|
+
`<title>${ud(o)}</title>`,
|
|
15994
|
+
r.description && `<meta name="description" content="${ud(r.description)}"/>`,
|
|
15995
|
+
`<meta property="og:title" content="${ud(o)}"/>`,
|
|
15996
|
+
r.image && `<meta property="og:image" content="${ud(r.image)}"/>`,
|
|
15974
15997
|
r.noindex && "<meta name=\"robots\" content=\"noindex\"/>",
|
|
15975
15998
|
"<style>html,body{margin:0;height:100%}</style>"
|
|
15976
15999
|
].filter(Boolean).join("\n");
|
|
15977
16000
|
return `<!doctype html>
|
|
15978
|
-
<html lang="${
|
|
16001
|
+
<html lang="${ud(i)}"${a ? ` dir="${a}"` : ""}>
|
|
15979
16002
|
<head>
|
|
15980
16003
|
${d}
|
|
15981
16004
|
</head>
|
|
15982
16005
|
<body>
|
|
15983
|
-
${
|
|
16006
|
+
${dd(e, { mode: t })}
|
|
15984
16007
|
${l ? u(l) : ""}
|
|
15985
16008
|
${s ? u(s) : ""}
|
|
15986
16009
|
</body>
|
|
15987
16010
|
</html>`;
|
|
15988
16011
|
}
|
|
15989
16012
|
//#endregion
|
|
15990
|
-
export { mt as assembleBundle, ht as documentTitle,
|
|
16013
|
+
export { mt as assembleBundle, ht as documentTitle, cd as fetchPage, dd as renderBundleHtml, fd as renderPageDocument };
|