@chaibuilder/pages 0.16.24 → 0.16.26
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/dist/{2AITGKQY-UndKMj-X.cjs → 2AITGKQY-Be359164.cjs} +1 -1
- package/dist/{2AITGKQY-Ir_ZXu1s.js → 2AITGKQY-CoZaZMrf.js} +2 -2
- package/dist/{NCMVHL6D-B3xcD0Vz.js → NCMVHL6D-C2p_bwgN.js} +2 -2
- package/dist/{NCMVHL6D-taGMv4he.cjs → NCMVHL6D-CmKLw38-.cjs} +1 -1
- package/dist/{ZDWCUMSJ-Cot4ixKZ.cjs → ZDWCUMSJ-DDHOTUX8.cjs} +1 -1
- package/dist/{ZDWCUMSJ-B1vApR00.js → ZDWCUMSJ-DmZy2MGb.js} +1 -1
- package/dist/{active-in-another-tab-Kp8LaYW5.js → active-in-another-tab-At1yEu4g.js} +1 -1
- package/dist/{active-in-another-tab-DYU7aCUa.cjs → active-in-another-tab-B1PAoWFL.cjs} +1 -1
- package/dist/{add-new-language-page-CkyPkpzC.cjs → add-new-language-page-B7fKZbYT.cjs} +1 -1
- package/dist/{add-new-language-page-0J2KTKg6.js → add-new-language-page-BfPVFqO4.js} +2 -2
- package/dist/{add-new-page-DPtVHa8m.cjs → add-new-page-DBVt7xSO.cjs} +1 -1
- package/dist/{add-new-page-BjxHUGIo.js → add-new-page-GZdKxwCY.js} +1 -1
- package/dist/{ai-panel-content-CMfopU0G.js → ai-panel-content-CWw-2gPV.js} +2 -2
- package/dist/{ai-panel-content-nmbQV7rT.cjs → ai-panel-content-Cv67WLJd.cjs} +1 -1
- package/dist/{ai-panel-default-lang-7L9rURdC.js → ai-panel-default-lang-B1WScOB4.js} +3 -3
- package/dist/{ai-panel-default-lang-B5eNybL4.cjs → ai-panel-default-lang-BBk6sSyh.cjs} +2 -2
- package/dist/{ai-panel-other-lang-DLn89TFE.cjs → ai-panel-other-lang-BrVV9nKv.cjs} +1 -1
- package/dist/{ai-panel-other-lang-U5XRqxbF.js → ai-panel-other-lang-DgNon2GH.js} +3 -3
- package/dist/{ai-prompt-input-B24vn-LG.js → ai-prompt-input-B6KsNLgP.js} +2 -2
- package/dist/ai-prompt-input-DSmIbsS_.cjs +1 -0
- package/dist/{ai-translation-prompt-CB67Sqo9.cjs → ai-translation-prompt-BYTviKVU.cjs} +1 -1
- package/dist/{ai-translation-prompt-cym054ja.js → ai-translation-prompt-CfnXqyai.js} +1 -1
- package/dist/button-CMMN5Cp4.cjs +1 -0
- package/dist/button-CggatMM3.js +48 -0
- package/dist/{continue-editing-in-this-client-BYJaymOL.cjs → continue-editing-in-this-client--Fzos10u.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-BDYiQrbE.js → continue-editing-in-this-client--RRixZUo.js} +1 -1
- package/dist/{delete-page-BXEQB0Si.cjs → delete-page-BOuq3v6x.cjs} +1 -1
- package/dist/{delete-page-CvSN4E4V.js → delete-page-CeJdK5hc.js} +1 -1
- package/dist/{digital-asset-manager-CF1Lyc5K.cjs → digital-asset-manager-BUEa7fSG.cjs} +1 -1
- package/dist/{digital-asset-manager-BxbX7ji1.js → digital-asset-manager-D6GbpYDo.js} +1 -1
- package/dist/{duplicate-page-BFnuk1nL.js → duplicate-page-C7FjAbqP.js} +2 -2
- package/dist/{duplicate-page-C32_9H41.cjs → duplicate-page-Ch9Fn-Gu.cjs} +1 -1
- package/dist/{dynamic-page-selector-CLxpglyO.cjs → dynamic-page-selector-CZNYCxbJ.cjs} +1 -1
- package/dist/{dynamic-page-selector-CSTuQhej.js → dynamic-page-selector-C_-ihnB7.js} +1 -1
- package/dist/{index-Bre43r-W.cjs → index-CJcS3b8n.cjs} +5 -5
- package/dist/{index-tgsBai_8.js → index-CtRx3Y3K.js} +1039 -1028
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/{json-diff-viewer-2gVCV5T-.js → json-diff-viewer-DX4sQltt.js} +1 -1
- package/dist/{json-diff-viewer-34Sqd4il.cjs → json-diff-viewer-DluaC8tY.cjs} +1 -1
- package/dist/{lang-panel-CXIcTGVk.cjs → lang-panel-DFe4DfU4.cjs} +1 -1
- package/dist/{lang-panel-Cj0axCpE.js → lang-panel-p7OYw-2c.js} +2 -2
- package/dist/{mark-as-template-DKBwTiMJ.cjs → mark-as-template-Biqpp8uM.cjs} +1 -1
- package/dist/{mark-as-template-1TuznHtx.js → mark-as-template-CuPKgc5N.js} +1 -1
- package/dist/{no-language-page-content-C265--no.js → no-language-page-content-B_zNVuVO.js} +1 -1
- package/dist/{no-language-page-content-B8udZsi2.cjs → no-language-page-content-oy4ZcH34.cjs} +1 -1
- package/dist/{no-language-page-dialog-CctilPnb.cjs → no-language-page-dialog-CTRG81hU.cjs} +1 -1
- package/dist/{no-language-page-dialog-DgaP74-Y.js → no-language-page-dialog-Q2rvsEP6.js} +2 -2
- package/dist/{page-creator-NkF29o0S.cjs → page-creator-CVrbjJa-.cjs} +1 -1
- package/dist/{page-creator-Cer7L7dg.js → page-creator-b6UTCFeu.js} +2 -2
- package/dist/{page-lock-0qEG4sLX.cjs → page-lock-DUwWdppB.cjs} +1 -1
- package/dist/{page-lock-DNrP3AhL.js → page-lock-Dl5CmUgk.js} +2 -2
- package/dist/{page-locked-dialog-B9p5gIGE.cjs → page-locked-dialog-DeUMR-pV.cjs} +1 -1
- package/dist/{page-locked-dialog-U5eDKeBc.js → page-locked-dialog-MJ3kA-oQ.js} +1 -1
- package/dist/page-manager-new-C3XuiDiM.cjs +1 -0
- package/dist/page-manager-new-C8PGR_4a.js +394 -0
- package/dist/{page-manager-search-and-filter-DKrQdcb0.cjs → page-manager-search-and-filter-BdfXZwwH.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-DDdYtDF7.js → page-manager-search-and-filter-DIz68YHL.js} +1 -1
- package/dist/{page-revisions-content-CoVYI0hI.js → page-revisions-content-BvYTXKgT.js} +2 -2
- package/dist/{page-revisions-content-NE8Y5DrC.cjs → page-revisions-content-CwrPL9kp.cjs} +1 -1
- package/dist/pages.css +1 -1
- package/dist/{publish-pages-content-KgbEbRVV.js → publish-pages-content-9VBFj6LH.js} +2 -2
- package/dist/{publish-pages-content-CCUKnVTH.cjs → publish-pages-content-DTPjR33T.cjs} +1 -1
- package/dist/{save-to-lib-CQmcDI5w.js → save-to-lib-Bkou78G6.js} +1 -1
- package/dist/{save-to-lib-C06RQn4k.cjs → save-to-lib-ByoB0FW5.cjs} +1 -1
- package/dist/selected-block-display-Auur5nl7.cjs +16 -0
- package/dist/selected-block-display-D1L4e4Cb.js +355 -0
- package/dist/{seo-panel-C-dqg-1A.js → seo-panel-KjxjFcdp.js} +16 -16
- package/dist/{seo-panel-hwJUoGfJ.cjs → seo-panel-Mjkh_Urn.cjs} +1 -1
- package/dist/{shared-json-ld-BP2l89h2.cjs → shared-json-ld-DYD7q8ST.cjs} +1 -1
- package/dist/{shared-json-ld-BUPafGh_.js → shared-json-ld-S9OIaOTA.js} +1 -1
- package/dist/{slug-input-91_G-ww1.cjs → slug-input-C0BtQs2w.cjs} +1 -1
- package/dist/{slug-input-hcJHNszn.js → slug-input-CUTtvZQ9.js} +1 -1
- package/dist/{take-over-request-Dw2P9U_Q.js → take-over-request-CXED2804.js} +1 -1
- package/dist/{take-over-request-kRGwkXvv.cjs → take-over-request-Dh9HVZPO.cjs} +1 -1
- package/dist/{theme-panel-footer-2qsvp4AM.js → theme-panel-footer-CftO53LS.js} +1 -1
- package/dist/{theme-panel-footer-DmO4-lci.cjs → theme-panel-footer-tdNtbqZs.cjs} +1 -1
- package/dist/{unmark-as-template-DbXx3l6p.js → unmark-as-template-Dp6S9dY3.js} +1 -1
- package/dist/{unmark-as-template-BBzZqNJt.cjs → unmark-as-template-DyUqAa9Z.cjs} +1 -1
- package/dist/{unpublish-page-BKQqPk_e.js → unpublish-page-c382vh74.js} +1 -1
- package/dist/{unpublish-page-CHYNjTFU.cjs → unpublish-page-ch791au1.cjs} +1 -1
- package/dist/{web-preview-BKoPv6AO.js → web-preview-DiOChE4E.js} +1 -1
- package/dist/{web-preview-D4KdtUYp.cjs → web-preview-cls5-Dlv.cjs} +1 -1
- package/package.json +3 -3
- package/dist/ai-prompt-input-6LzuYu5L.cjs +0 -1
- package/dist/page-manager-new-BL5S9ccS.cjs +0 -1
- package/dist/page-manager-new-DGaBkeJp.js +0 -354
- package/dist/selected-block-display-7n8S3vf1.js +0 -394
- package/dist/selected-block-display-DDC1_UC8.cjs +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s } from "react/jsx-runtime";
|
|
2
|
-
import { l as ye, ar as ve, aq as xe, A as Ne, L as Z, aw as we,
|
|
2
|
+
import { l as ye, ar as ve, aq as xe, A as Ne, L as Z, aw as we, aK as Se, aL as De, i as be, ay as Oe, aM as Le, aN as Ce, aO as E, aP as Ie, aE as ee } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useLanguages as z, useTranslation as ke, useSidebarActivePanel as Ee, usePermissions as Te } from "@chaibuilder/sdk";
|
|
4
4
|
import { find as Fe, get as h, isEqual as te, isEmpty as je } from "lodash-es";
|
|
5
5
|
import { useMemo as Re, useRef as ae, useState as j, useEffect as se } from "react";
|
|
@@ -11,7 +11,7 @@ import { g as _ } from "./get-seo-defaults-9zHebckY.js";
|
|
|
11
11
|
const ze = () => {
|
|
12
12
|
const { selectedLang: a } = z(), { data: u, isFetching: c } = ye();
|
|
13
13
|
return { data: Re(() => Fe(u, { lang: a || "" }) || {}, [u, a]), isFetching: c };
|
|
14
|
-
},
|
|
14
|
+
}, Ke = () => {
|
|
15
15
|
var p;
|
|
16
16
|
const u = (p = document.getElementById("canvas-iframe").contentDocument) == null ? void 0 : p.body.innerHTML;
|
|
17
17
|
if (!u) return null;
|
|
@@ -28,7 +28,7 @@ const ze = () => {
|
|
|
28
28
|
}) => {
|
|
29
29
|
const i = ve(), r = xe(), { selectedLang: x, fallbackLang: p } = z(), { mutate: d, isPending: m } = qe({
|
|
30
30
|
mutationFn: async () => {
|
|
31
|
-
const b =
|
|
31
|
+
const b = Ke();
|
|
32
32
|
return await i(r, {
|
|
33
33
|
action: Ne.GENERATE_SEO_FIELD,
|
|
34
34
|
data: {
|
|
@@ -60,7 +60,7 @@ const ze = () => {
|
|
|
60
60
|
children: m ? /* @__PURE__ */ e(He, { className: "h-3 w-3 animate-spin text-yellow-500" }) : /* @__PURE__ */ e(_e, { className: "text-yellow-500" })
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
|
-
},
|
|
63
|
+
}, Ye = ({
|
|
64
64
|
isOpen: a,
|
|
65
65
|
onClose: u,
|
|
66
66
|
onSave: c,
|
|
@@ -86,14 +86,14 @@ const ze = () => {
|
|
|
86
86
|
/* @__PURE__ */ e(P, { onClick: c, disabled: r, children: r ? "Saving..." : "Save & Switch" })
|
|
87
87
|
] })
|
|
88
88
|
] }) });
|
|
89
|
-
},
|
|
89
|
+
}, We = (a) => {
|
|
90
90
|
if (!a) return !0;
|
|
91
91
|
try {
|
|
92
92
|
return JSON.parse(a), !0;
|
|
93
93
|
} catch {
|
|
94
94
|
return !1;
|
|
95
95
|
}
|
|
96
|
-
},
|
|
96
|
+
}, Qe = (a, u) => {
|
|
97
97
|
const c = a.selectionStart || 0, i = a.selectionEnd || 0, r = a.value, x = r.substring(0, c), p = r.substring(i), d = `{{${u}}}`, m = x + "" + d + p, b = c + 0 + // Account for space before if added
|
|
98
98
|
d.length;
|
|
99
99
|
return {
|
|
@@ -101,7 +101,7 @@ const ze = () => {
|
|
|
101
101
|
newCursorPos: b
|
|
102
102
|
};
|
|
103
103
|
}, Xe = () => {
|
|
104
|
-
const { t: a } = ke(), [, u] = Ee(), { data: c } = we(), { data: i } = Se(), { data: r, isFetching: x } = ze(), p = r == null ? void 0 : r.seo, d = ae(null), [m, b] = j("seo"), J = c == null ? void 0 : c.id, oe = c == null ? void 0 : c.pageType, C = De(oe), { selectedLang:
|
|
104
|
+
const { t: a } = ke(), [, u] = Ee(), { data: c } = we(), { data: i } = Se(), { data: r, isFetching: x } = ze(), p = r == null ? void 0 : r.seo, d = ae(null), [m, b] = j("seo"), J = c == null ? void 0 : c.id, oe = c == null ? void 0 : c.pageType, C = De(oe), { selectedLang: K, fallbackLang: le } = z(), g = K || le, [Y, U] = j(!1), [re, W] = j(!1), [ie, G] = j(!1), [w, M] = j(null), [n, S] = j({
|
|
105
105
|
keyword: "",
|
|
106
106
|
title: "",
|
|
107
107
|
description: "",
|
|
@@ -117,7 +117,7 @@ const ze = () => {
|
|
|
117
117
|
jsonLD: "{}",
|
|
118
118
|
metaOther: "{}",
|
|
119
119
|
...p
|
|
120
|
-
}), T = ae({}), { mutate: ce, isPending: B } = be(), f = B ||
|
|
120
|
+
}), T = ae({}), { mutate: ce, isPending: B } = be(), f = B || Y || re, { hasPermission: de } = Te(), o = de(Oe.EDIT_SEO), [me] = Le(), he = h(me, "features.canResetSeoToDefault", !1), Q = !K || n.jsonLD !== "{}";
|
|
121
121
|
se(() => {
|
|
122
122
|
if (!x && p && J) {
|
|
123
123
|
const t = {
|
|
@@ -173,7 +173,7 @@ const ze = () => {
|
|
|
173
173
|
}, ue = async () => {
|
|
174
174
|
if (!(!C || !g))
|
|
175
175
|
try {
|
|
176
|
-
|
|
176
|
+
W(!0);
|
|
177
177
|
const t = _(C, g), l = {
|
|
178
178
|
...n,
|
|
179
179
|
jsonLD: h(t, "seo.jsonLD", "")
|
|
@@ -182,7 +182,7 @@ const ze = () => {
|
|
|
182
182
|
} catch (t) {
|
|
183
183
|
O.error(a("Failed to reset JSON-LD")), console.error("Reset JSON-LD error:", t);
|
|
184
184
|
} finally {
|
|
185
|
-
|
|
185
|
+
W(!1);
|
|
186
186
|
}
|
|
187
187
|
}, pe = async () => {
|
|
188
188
|
if (!(!C || !g))
|
|
@@ -214,7 +214,7 @@ const ze = () => {
|
|
|
214
214
|
}, L = (t, l) => {
|
|
215
215
|
const D = document.getElementById(l);
|
|
216
216
|
if (D) {
|
|
217
|
-
const { value: V, newCursorPos: v } =
|
|
217
|
+
const { value: V, newCursorPos: v } = Qe(D, t);
|
|
218
218
|
d.current = {
|
|
219
219
|
id: l,
|
|
220
220
|
position: v
|
|
@@ -580,7 +580,7 @@ const ze = () => {
|
|
|
580
580
|
/* @__PURE__ */ e("div", { className: m === "jsonld" ? "" : "sr-only", children: /* @__PURE__ */ e("div", { className: "space-y-4", children: /* @__PURE__ */ s("div", { className: "space-y-1", children: [
|
|
581
581
|
/* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
|
|
582
582
|
/* @__PURE__ */ e(N, { className: "text-xs", htmlFor: "jsonLD", children: a("JSON-LD") }),
|
|
583
|
-
|
|
583
|
+
Q && /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ e(A, { keyword: n.keyword, onComplete: F("jsonLD"), field: "jsonLD" }) })
|
|
584
584
|
] }),
|
|
585
585
|
/* @__PURE__ */ e("div", { className: "hidden", children: JSON.stringify(i) }),
|
|
586
586
|
/* @__PURE__ */ e(
|
|
@@ -597,7 +597,7 @@ const ze = () => {
|
|
|
597
597
|
pageData: i || {},
|
|
598
598
|
rows: 12,
|
|
599
599
|
handleFieldInsert: L,
|
|
600
|
-
hasJsonLdForSelectedLang:
|
|
600
|
+
hasJsonLdForSelectedLang: Q,
|
|
601
601
|
copyJsonLDFromDefaultPage: fe
|
|
602
602
|
}
|
|
603
603
|
)
|
|
@@ -615,7 +615,7 @@ const ze = () => {
|
|
|
615
615
|
m === "jsonld" ? ue() : m === "opengraph" ? pe() : ge();
|
|
616
616
|
},
|
|
617
617
|
disabled: f || !o || !C,
|
|
618
|
-
children: a(
|
|
618
|
+
children: a(Y ? "Resetting..." : `Reset to ${m === "jsonld" ? "Default JSON-LD" : m === "opengraph" ? "Default Open Graph" : "Default SEO"}`)
|
|
619
619
|
}
|
|
620
620
|
) : /* @__PURE__ */ e("div", {}),
|
|
621
621
|
/* @__PURE__ */ s("div", { className: "flex items-center gap-4", children: [
|
|
@@ -623,7 +623,7 @@ const ze = () => {
|
|
|
623
623
|
P,
|
|
624
624
|
{
|
|
625
625
|
onClick: X,
|
|
626
|
-
disabled: !
|
|
626
|
+
disabled: !We(n == null ? void 0 : n.jsonLD) || (T.current[g] ? te(T.current[g], n) : !1) || f || !o,
|
|
627
627
|
children: a(B ? "Saving..." : "Save")
|
|
628
628
|
}
|
|
629
629
|
),
|
|
@@ -639,7 +639,7 @@ const ze = () => {
|
|
|
639
639
|
] })
|
|
640
640
|
] }),
|
|
641
641
|
/* @__PURE__ */ e(
|
|
642
|
-
|
|
642
|
+
Ye,
|
|
643
643
|
{
|
|
644
644
|
isOpen: ie,
|
|
645
645
|
onClose: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-Bre43r-W.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-CJcS3b8n.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-Bre43r-W.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-CJcS3b8n.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as n, Fragment as G } from "react/jsx-runtime";
|
|
2
2
|
import { useLanguages as me } from "@chaibuilder/sdk";
|
|
3
3
|
import { useQuery as he, useQueryClient as ue } from "@tanstack/react-query";
|
|
4
|
-
import { aq as ge, ar as fe, A as U, aw as te, aC as pe, aD as se, aE as re, aF as de, aG as xe, aH as Ne, aI as be, l as ye, aJ as ve } from "./index-
|
|
4
|
+
import { aq as ge, ar as fe, A as U, aw as te, aC as pe, aD as se, aE as re, aF as de, aG as xe, aH as Ne, aI as be, l as ye, aJ as ve } from "./index-CtRx3Y3K.js";
|
|
5
5
|
import { Dialog as $, DialogContent as W, DialogHeader as Y, DialogTitle as X, Alert as we, AlertDescription as Ae, Label as y, Input as j, Button as v, AlertDialog as _, AlertDialogContent as R, AlertDialogHeader as q, AlertDialogTitle as M, AlertDialogDescription as H, AlertDialogFooter as Q, AlertDialogCancel as V, AlertDialogAction as K, Tooltip as L, TooltipTrigger as J, TooltipContent as F, ScrollArea as Ce, Card as Se, CardHeader as Pe, CardTitle as Te, AlertDialogTrigger as De, CardContent as Ee, Textarea as Le } from "@chaibuilder/sdk/ui";
|
|
6
6
|
import { filter as Je, find as Fe } from "lodash-es";
|
|
7
7
|
import { Info as Oe, Loader as O, Plus as ke, Eye as Ge, Edit as je, Trash as Be } from "lucide-react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),u=require("./index-
|
|
1
|
+
"use strict";const s=require("react/jsx-runtime"),u=require("./index-CJcS3b8n.cjs"),b=require("@chaibuilder/sdk/ui"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const l=t.pop()||"";a=!!u.LANGUAGES[l]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:l}){const[g,p]=d.useState(e),[o,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:o?"border-red-500":""}),o&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:o})]}),l&&l!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:l})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as i, jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { L as d } from "./index-
|
|
2
|
+
import { L as d } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { Input as v } from "@chaibuilder/sdk/ui";
|
|
4
4
|
import { useState as x, useEffect as C } from "react";
|
|
5
5
|
const y = (e) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import { an as N, b as C, a as b, ao as v, B as E, E as d, P as m } from "./index-
|
|
2
|
+
import { an as N, b as C, a as b, ao as v, B as E, E as d, P as m } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useSavePage as T, useTranslation as w } from "@chaibuilder/sdk";
|
|
4
4
|
import { Card as I, CardHeader as k, CardTitle as y, CardContent as R, CardFooter as S, Button as u } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { AlertCircle as A, UserIcon as P, Check as _, X as q } from "lucide-react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-CJcS3b8n.cjs"),m=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),l=require("lucide-react"),j=require("react"),p=()=>{const i=t.useSendRealtimeEvent(),{pageLockMeta:r}=t.usePageLockMeta(),{setPageStatus:d}=t.usePageLockStatus(),{savePageAsync:x}=m.useSavePage(),h=r==null?void 0:r.requestingUserId,{data:s,isFetching:g}=t.useChaiUserInfo(h||""),o=g?"Fetching user...":(s==null?void 0:s.name)||"Current editor",[u,c]=j.useState(!1),N=async()=>{c(!0),await x(),i(t.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT,r),d(t.PAGE_STATUS.CHECKING),setTimeout(()=>c(!1),2e3)},f=()=>{c(!0),i(t.EVENT.TAKE_OVER_REJECTED,r),d(t.PAGE_STATUS.EDITING),setTimeout(()=>c(!1),2e3)},{t:n}=m.useTranslation();return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(l.AlertCircle,{className:"h-8 w-8 rounded-md bg-amber-500/20 p-1.5 text-amber-500"}),n("Take Over Requested")]})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Requested by"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}):e.jsx(l.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:o}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-gray-700",children:o})," ",n("has requested to")," ",e.jsx("span",{className:"font-medium text-gray-500",children:"take over"})," ",n("editing this page."),"."," ",n("Do you want to allow them to continue?")]})]}),e.jsxs(a.CardFooter,{className:"flex gap-2",children:[e.jsxs(a.Button,{disabled:u,variant:"default",onClick:N,className:"flex-1 gap-2",children:[e.jsx(l.Check,{className:"h-4 w-4"}),n("Accept")]}),e.jsxs(a.Button,{disabled:u,variant:"outline",onClick:f,className:"flex-1 gap-2",children:[e.jsx(l.X,{className:"h-4 w-4"}),n("Reject")]})]})]})})};exports.default=p;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as c, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { e as d, f as h, t as u } from "./index-
|
|
2
|
+
import { e as d, f as h, t as u } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useTheme as b, useTranslation as f } from "@chaibuilder/sdk";
|
|
4
4
|
import { Button as o } from "@chaibuilder/sdk/ui";
|
|
5
5
|
const x = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-CJcS3b8n.cjs"),o=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),h=()=>{const[t]=o.useTheme(),{mutate:c,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),{t:a}=o.useTranslation(),l=()=>{n({settings:{theme:t}})},d=async()=>{await n({settings:{theme:t}}),c({ids:["THEME"]},{onSuccess:()=>{s.throwConfetti("BOTTOM_RIGHT")}})};return e.jsxs("div",{className:"flex items-center justify-center gap-x-3 border-t bg-white py-3",children:[e.jsx(r.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:l,children:a("Save draft")}),e.jsx(r.Button,{size:"sm",disabled:i||u,onClick:d,children:a("Publish")})]})};exports.default=h;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as o } from "react/jsx-runtime";
|
|
2
|
-
import { s as p } from "./index-
|
|
2
|
+
import { s as p } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useTranslation as u } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as d, DialogContent as g, DialogHeader as h, DialogTitle as f, DialogDescription as k, DialogFooter as D, Button as s } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { useState as x } from "react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-CJcS3b8n.cjs"),d=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),m=require("react"),p=({page:i,onClose:n})=>{const{t:a}=d.useTranslation(),[r,s]=m.useState(!1),o=u.useUnmarkAsTemplate(),l=()=>{s(!0),o.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:c=>{c.stopPropagation(),n()},children:a("Cancel")}),e.jsx(t.Button,{variant:"default",disabled:r,onClick:l,children:a("Unmark as template")})]})]})})};exports.default=p;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as o, jsxs as t } from "react/jsx-runtime";
|
|
2
|
-
import { o as u } from "./index-
|
|
2
|
+
import { o as u } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useTranslation as a } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as h, DialogContent as d, DialogHeader as m, DialogTitle as b, DialogDescription as D, DialogFooter as f, Button as s } from "@chaibuilder/sdk/ui";
|
|
5
5
|
const g = ({ page: n, onClose: l }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("./index-CJcS3b8n.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),d=({page:i,onClose:t})=>{const{t:e}=c.useTranslation(),{mutate:r,isPending:l}=u.useUnpublishPage(),o=async()=>{r(i,{onSuccess:t})};return n.jsx(s.Dialog,{open:!!i,onOpenChange:t,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:e("Confirm action")}),n.jsxs(s.DialogDescription,{children:[e("Are you sure you want to unpublish")," ",n.jsx("b",{children:(i==null?void 0:i.name)??(i==null?void 0:i.slug)}),"?"]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:t,children:e("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:l,onClick:o,children:e(l?"Updating...":"Unpublish")})]})]})})};exports.default=d;
|
|
@@ -4,7 +4,7 @@ import { Button as s } from "@chaibuilder/sdk/ui";
|
|
|
4
4
|
import { useAtom as h } from "jotai";
|
|
5
5
|
import { map as p } from "lodash-es";
|
|
6
6
|
import { Smartphone as w, Tablet as f, Laptop as u, LaptopMinimal as x } from "lucide-react";
|
|
7
|
-
import { p as v, T as _ } from "./index-
|
|
7
|
+
import { p as v, T as _ } from "./index-CtRx3Y3K.js";
|
|
8
8
|
const b = [
|
|
9
9
|
{
|
|
10
10
|
title: "mobile_xs_title",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-CJcS3b8n.cjs"),m=[{title:"mobile_xs_title",content:"mobile_xs_content",icon:e.jsx(n.Smartphone,{className:"h-4 w-4"}),width:400},{title:"tablet_md_title",content:"tablet_md_content",icon:e.jsx(n.Tablet,{className:"h-4 w-4"}),width:800},{title:"desktop_xl_title",content:"desktop_xl_content",icon:e.jsx(n.Laptop,{className:"h-4 w-4"}),width:1200},{title:"large_desktop_2xl_title",content:"large_desktop_2xl_content",icon:e.jsx(n.LaptopMinimal,{className:"h-4 w-4"}),width:1600}],w=({currentWidth:t,width:s,icon:l,setIframeWidth:i})=>e.jsx(a.Button,{className:"px-3 py-3",onClick:()=>i(s),variant:s===t?"default":"ghost",children:l}),p=()=>{const[t,s]=o.useState(1200),l=r=>s(r),[i,d]=h.useAtom(c.previewUrlAtom);if(!i)return null;const u=()=>{d("")};return e.jsxs("div",{className:"absolute inset-0 z-[999999] flex h-screen w-screen flex-col overflow-hidden bg-gray-100",children:[e.jsxs("div",{className:"flex h-[50px] items-center justify-center border-b border-gray-200 px-4 shadow-sm",children:[e.jsx("div",{className:"flex items-center justify-center rounded-md border border-gray-300",children:x.map(m,r=>o.createElement(w,{...r,setIframeWidth:l,key:r.title,currentWidth:t}))})," ",e.jsx(c.Tooltip,{content:"Exit Preview",delayDuration:0,children:e.jsx(a.Button,{variant:"destructive",size:"sm",onClick:u,children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M2 3C2 2.44772 2.44772 2 3 2H12C12.5523 2 13 2.44772 13 3V12C13 12.5523 12.5523 13 12 13H3C2.44772 13 2 12.5523 2 12V3ZM12 3H3V12H12V3Z",fill:"currentColor",fillRule:"evenodd","clip-rule":"evenodd"})})})})]}),e.jsx("iframe",{style:{width:`${t}px`,transition:"width 0.3s ease-in-out"},className:"no-scrollbar mx-auto h-full overflow-y-auto border bg-white",src:i})]})};exports.default=p;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Suraj Air",
|
|
4
4
|
"license": "Private",
|
|
5
5
|
"homepage": "https://chaibuilder.com",
|
|
6
|
-
"version": "0.16.
|
|
6
|
+
"version": "0.16.26",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@chaibuilder/runtime": "2.2.0",
|
|
61
|
-
"@chaibuilder/sdk": "3.1.
|
|
61
|
+
"@chaibuilder/sdk": "3.1.32",
|
|
62
62
|
"@types/react": "*",
|
|
63
63
|
"@types/react-dom": "*",
|
|
64
64
|
"jotai": "2.14.0",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@chaibuilder/runtime": "2.2.0",
|
|
78
|
-
"@chaibuilder/sdk": "3.1.
|
|
78
|
+
"@chaibuilder/sdk": "3.1.32",
|
|
79
79
|
"@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
|
|
80
80
|
"@radix-ui/react-collapsible": "^1.1.12",
|
|
81
81
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("./selected-block-display-DDC1_UC8.cjs"),d=require("react"),R=require("cmdk"),b=require("lucide-react"),ye=require("@radix-ui/react-dialog"),Ne=require("@radix-ui/react-dropdown-menu"),we=require("@radix-ui/react-hover-card"),J=require("class-variance-authority"),Se=require("@radix-ui/react-select"),Ie=require("@chaibuilder/sdk"),U=require("./ai-panel-content-nmbQV7rT.cjs");function q(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const n=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,n.get?n:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const p=q(d),z=q(ye),w=q(Ne),G=q(we),I=q(Se),Ce=z.Root,ke=z.Trigger,Re=z.Portal,Q=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Overlay,{ref:a,className:r.cn("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...s}));Q.displayName=z.Overlay.displayName;const Z=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(Re,{children:[e.jsx(Q,{}),e.jsxs(z.Content,{ref:n,className:r.cn("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...a,children:[s,e.jsxs(z.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(b.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Z.displayName=z.Content.displayName;const ee=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Title,{ref:a,className:r.cn("text-lg font-semibold leading-none tracking-tight",t),...s}));ee.displayName=z.Title.displayName;const De=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Description,{ref:a,className:r.cn("text-sm text-muted-foreground",t),...s}));De.displayName=z.Description.displayName;const te=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command,{ref:a,className:r.cn("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...s}));te.displayName=R.Command.displayName;const se=p.forwardRef(({className:t,...s},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(b.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(R.Command.Input,{ref:a,className:r.cn("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...s})]}));se.displayName=R.Command.Input.displayName;const ae=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.List,{ref:a,className:r.cn("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...s}));ae.displayName=R.Command.List.displayName;const ze=p.forwardRef((t,s)=>e.jsx(R.Command.Empty,{ref:s,className:"py-6 text-center text-sm",...t}));ze.displayName=R.Command.Empty.displayName;const ne=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Group,{ref:a,className:r.cn("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...s}));ne.displayName=R.Command.Group.displayName;const Pe=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Separator,{ref:a,className:r.cn("-mx-1 h-px bg-border",t),...s}));Pe.displayName=R.Command.Separator.displayName;const oe=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Item,{ref:a,className:r.cn("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t),...s}));oe.displayName=R.Command.Item.displayName;const Te=w.Root,Le=w.Trigger,Ae=p.forwardRef(({className:t,inset:s,children:a,...n},l)=>e.jsxs(w.SubTrigger,{ref:l,className:r.cn("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",t),...n,children:[a,e.jsx(b.ChevronRight,{className:"ml-auto"})]}));Ae.displayName=w.SubTrigger.displayName;const Me=p.forwardRef(({className:t,...s},a)=>e.jsx(w.SubContent,{ref:a,className:r.cn("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...s}));Me.displayName=w.SubContent.displayName;const re=p.forwardRef(({className:t,sideOffset:s=4,...a},n)=>e.jsx(w.Portal,{children:e.jsx(w.Content,{ref:n,sideOffset:s,className:r.cn("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...a})}));re.displayName=w.Content.displayName;const ie=p.forwardRef(({className:t,inset:s,...a},n)=>e.jsx(w.Item,{ref:n,className:r.cn("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",t),...a}));ie.displayName=w.Item.displayName;const _e=p.forwardRef(({className:t,children:s,checked:a,...n},l)=>e.jsxs(w.CheckboxItem,{ref:l,className:r.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:a,...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(b.Check,{className:"h-4 w-4"})})}),s]}));_e.displayName=w.CheckboxItem.displayName;const Oe=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(w.RadioItem,{ref:n,className:r.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(b.Circle,{className:"h-2 w-2 fill-current"})})}),s]}));Oe.displayName=w.RadioItem.displayName;const Ue=p.forwardRef(({className:t,inset:s,...a},n)=>e.jsx(w.Label,{ref:n,className:r.cn("px-2 py-1.5 text-sm font-semibold",s&&"pl-8",t),...a}));Ue.displayName=w.Label.displayName;const qe=p.forwardRef(({className:t,...s},a)=>e.jsx(w.Separator,{ref:a,className:r.cn("-mx-1 my-1 h-px bg-muted",t),...s}));qe.displayName=w.Separator.displayName;const Be=G.Root,Ee=G.Trigger,le=p.forwardRef(({className:t,align:s="center",sideOffset:a=4,...n},l)=>e.jsx(G.Content,{ref:l,align:s,sideOffset:a,className:r.cn("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]",t),...n}));le.displayName=G.Content.displayName;const Fe=p.forwardRef(({className:t,type:s,...a},n)=>e.jsx("input",{type:s,className:r.cn("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:n,...a}));Fe.displayName="Input";const ce=p.forwardRef(({className:t,...s},a)=>e.jsx("textarea",{className:r.cn("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:a,...s}));ce.displayName="Textarea";function Ge({className:t,...s}){return e.jsx("div",{"data-slot":"input-group",role:"group",className:r.cn("group/input-group border-input dark:bg-input/30 shadow-xs relative flex w-full items-center rounded-md border outline-none transition-[color,box-shadow]","h-9 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:ring-ring has-[[data-slot=input-group-control]:focus-visible]:ring-1","has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",t),...s})}const Ve=J.cva("text-muted-foreground flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.4rem] has-[>kbd]:mr-[-0.35rem]","block-start":"[.border-b]:pb-3 order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5","block-end":"[.border-t]:pt-3 order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5"}},defaultVariants:{align:"inline-start"}});function de({className:t,align:s="inline-start",...a}){return e.jsx("div",{role:"group","data-slot":"input-group-addon","data-align":s,className:r.cn(Ve({align:s}),t),onClick:n=>{var l,g;n.target.closest("button")||(g=(l=n.currentTarget.parentElement)==null?void 0:l.querySelector("input"))==null||g.focus()},...a})}const He=J.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",sm:"h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5","icon-xs":"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function ue({className:t,type:s="button",variant:a="ghost",size:n="xs",...l}){return e.jsx(r.Button,{type:s,"data-size":n,variant:a,className:r.cn(He({size:n}),t),...l})}function We({className:t,...s}){return e.jsx(ce,{"data-slot":"input-group-control",className:r.cn("flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",t),...s})}const Ke=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(I.Trigger,{ref:n,className:r.cn("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...a,children:[s,e.jsx(I.Icon,{asChild:!0,children:e.jsx(b.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ke.displayName=I.Trigger.displayName;const me=p.forwardRef(({className:t,...s},a)=>e.jsx(I.ScrollUpButton,{ref:a,className:r.cn("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(b.ChevronUp,{className:"h-4 w-4"})}));me.displayName=I.ScrollUpButton.displayName;const pe=p.forwardRef(({className:t,...s},a)=>e.jsx(I.ScrollDownButton,{ref:a,className:r.cn("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(b.ChevronDown,{className:"h-4 w-4"})}));pe.displayName=I.ScrollDownButton.displayName;const Xe=p.forwardRef(({className:t,children:s,position:a="popper",...n},l)=>e.jsx(I.Portal,{children:e.jsxs(I.Content,{ref:l,className:r.cn("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:a,...n,children:[e.jsx(me,{}),e.jsx(I.Viewport,{className:r.cn("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:s}),e.jsx(pe,{})]})}));Xe.displayName=I.Content.displayName;const Ye=p.forwardRef(({className:t,...s},a)=>e.jsx(I.Label,{ref:a,className:r.cn("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...s}));Ye.displayName=I.Label.displayName;const $e=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(I.Item,{ref:n,className:r.cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(I.ItemIndicator,{children:e.jsx(b.Check,{className:"h-4 w-4"})})}),e.jsx(I.ItemText,{children:s})]}));$e.displayName=I.Item.displayName;const Je=p.forwardRef(({className:t,...s},a)=>e.jsx(I.Separator,{ref:a,className:r.cn("-mx-1 my-1 h-px bg-muted",t),...s}));Je.displayName=I.Separator.displayName;const Qe="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ze=(t=21)=>{let s="",a=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)s+=Qe[a[t]&63];return s};const et=d.createContext(null),tt=d.createContext(null),fe=()=>d.useContext(et),st=()=>d.useContext(tt),xe=d.createContext(null),V=()=>{const t=st(),s=d.useContext(xe),a=t??s;if(!a)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return a};function at({data:t,className:s,...a}){var v;const n=V(),l=t.filename||"",u=((v=t.mediaType)!=null&&v.startsWith("image/")&&t.url?"image":"file")==="image",y=l||(u?"Image":"Attachment");return e.jsxs(gt,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs("div",{className:r.cn("group relative flex h-8 cursor-default select-none items-center gap-1.5 rounded-md border border-border px-1.5 text-sm font-medium transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",s),...a,children:[e.jsxs("div",{className:"relative size-5 shrink-0",children:[e.jsx("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:u?e.jsx("img",{alt:l||"attachment",className:"size-5 object-cover",height:20,src:t.url,width:20}):e.jsx("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:e.jsx(b.PaperclipIcon,{className:"size-3"})})}),e.jsxs(r.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:k=>{k.stopPropagation(),n.remove(t.id)},type:"button",variant:"ghost",children:[e.jsx(b.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Remove"})]})]}),e.jsx("span",{className:"flex-1 truncate",children:y})]},t.id)}),e.jsx(ht,{className:"w-auto p-2",children:e.jsxs("div",{className:"w-auto space-y-3",children:[u&&e.jsx("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:e.jsx("img",{alt:l||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:t.url,width:448})}),e.jsx("div",{className:"flex items-center gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[e.jsx("h4",{className:"truncate text-sm font-semibold leading-none",children:l||(u?"Image":"Attachment")}),t.mediaType&&e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:t.mediaType})]})})]})})]})}function nt({children:t,className:s,...a}){const n=V();return n.files.length?e.jsx("div",{className:r.cn("flex flex-wrap items-center gap-2 p-3",s),...a,children:n.files.map(l=>e.jsx(d.Fragment,{children:t(l)},l.id))}):null}const ot=({label:t="Add photos or files",...s})=>{const a=V();return e.jsxs(ie,{...s,onSelect:n=>{n.preventDefault(),a.openFileDialog()},children:[e.jsx(b.ImageIcon,{className:"mr-2 size-4"})," ",t]})},rt=({className:t,accept:s,multiple:a,globalDrop:n,syncHiddenInput:l,maxFiles:g,maxFileSize:u,onError:y,onSubmit:v,children:k,...T})=>{const o=fe(),c=!!o,m=d.useRef(null),P=d.useRef(null),C=d.useRef(null);d.useEffect(()=>{var N;const i=(N=P.current)==null?void 0:N.closest("form");i instanceof HTMLFormElement&&(C.current=i)},[]);const[D,A]=d.useState([]),j=c?o.attachments.files:D,M=d.useCallback(()=>{var i;(i=m.current)==null||i.click()},[]),B=d.useCallback(i=>!s||s.trim()===""?!0:s.includes("image/*")?i.type.startsWith("image/"):!0,[s]),E=d.useCallback(i=>{const N=Array.from(i),h=N.filter(S=>B(S));if(N.length&&h.length===0){y==null||y({code:"accept",message:"No files match the accepted types."});return}const x=S=>u?S.size<=u:!0,f=h.filter(x);if(h.length>0&&f.length===0){y==null||y({code:"max_file_size",message:"All files exceed the maximum size."});return}A(S=>{const _=typeof g=="number"?Math.max(0,g-S.length):void 0,je=typeof _=="number"?f.slice(0,_):f;typeof _=="number"&&f.length>_&&(y==null||y({code:"max_files",message:"Too many files. Some were not added."}));const Y=[];for(const H of je)Y.push({id:Ze(),type:"file",url:URL.createObjectURL(H),mediaType:H.type,filename:H.name});return S.concat(Y)})},[B,g,u,y]),L=c?i=>o.attachments.add(i):E,O=c?i=>o.attachments.remove(i):i=>A(N=>{const h=N.find(x=>x.id===i);return h!=null&&h.url&&URL.revokeObjectURL(h.url),N.filter(x=>x.id!==i)}),F=c?()=>o.attachments.clear():()=>A(i=>{for(const N of i)N.url&&URL.revokeObjectURL(N.url);return[]}),K=c?()=>o.attachments.openFileDialog():M;d.useEffect(()=>{c&&o.__registerFileInput(m,()=>{var i;return(i=m.current)==null?void 0:i.click()})},[c,o]),d.useEffect(()=>{l&&m.current&&j.length===0&&(m.current.value="")},[j,l]),d.useEffect(()=>{const i=C.current;if(!i)return;const N=x=>{var f,S;(S=(f=x.dataTransfer)==null?void 0:f.types)!=null&&S.includes("Files")&&x.preventDefault()},h=x=>{var f,S,_;(S=(f=x.dataTransfer)==null?void 0:f.types)!=null&&S.includes("Files")&&x.preventDefault(),(_=x.dataTransfer)!=null&&_.files&&x.dataTransfer.files.length>0&&L(x.dataTransfer.files)};return i.addEventListener("dragover",N),i.addEventListener("drop",h),()=>{i.removeEventListener("dragover",N),i.removeEventListener("drop",h)}},[L]),d.useEffect(()=>{if(!n)return;const i=h=>{var x,f;(f=(x=h.dataTransfer)==null?void 0:x.types)!=null&&f.includes("Files")&&h.preventDefault()},N=h=>{var x,f,S;(f=(x=h.dataTransfer)==null?void 0:x.types)!=null&&f.includes("Files")&&h.preventDefault(),(S=h.dataTransfer)!=null&&S.files&&h.dataTransfer.files.length>0&&L(h.dataTransfer.files)};return document.addEventListener("dragover",i),document.addEventListener("drop",N),()=>{document.removeEventListener("dragover",i),document.removeEventListener("drop",N)}},[L,n]),d.useEffect(()=>()=>{if(!c)for(const i of j)i.url&&URL.revokeObjectURL(i.url)},[c,j]);const ge=i=>{i.currentTarget.files&&L(i.currentTarget.files)},he=async i=>{const h=await(await fetch(i)).blob();return new Promise((x,f)=>{const S=new FileReader;S.onloadend=()=>x(S.result),S.onerror=f,S.readAsDataURL(h)})},be=d.useMemo(()=>({files:j.map(i=>({...i,id:i.id})),add:L,remove:O,clear:F,openFileDialog:K,fileInputRef:m}),[j,L,O,F,K]),ve=i=>{i.preventDefault();const N=i.currentTarget,h=c?o.textInput.value:new FormData(N).get("message")||"";c||N.reset(),Promise.all(j.map(async({id:x,...f})=>f.url&&f.url.startsWith("blob:")?{...f,url:await he(f.url)}:f)).then(x=>{try{const f=v({text:h,files:x},i);f instanceof Promise?f.then(()=>{F(),c&&o.textInput.clear()}).catch(()=>{}):(F(),c&&o.textInput.clear())}catch{}})},X=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"hidden",ref:P}),e.jsx("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:a,onChange:ge,ref:m,title:"Upload files",type:"file"}),e.jsx("form",{className:r.cn("w-full",t),onSubmit:ve,...T,children:e.jsx(Ge,{className:"overflow-hidden",children:k})})]});return c?X:e.jsx(xe.Provider,{value:be,children:X})},it=({onChange:t,className:s,placeholder:a="What would you like to know?",...n})=>{const l=fe(),g=V(),[u,y]=d.useState(!1),v=o=>{if(o.key==="Enter"){if(u||o.nativeEvent.isComposing||o.shiftKey)return;o.preventDefault();const c=o.currentTarget.form,m=c==null?void 0:c.querySelector('button[type="submit"]');if(m!=null&&m.disabled)return;c==null||c.requestSubmit()}if(o.key==="Backspace"&&o.currentTarget.value===""&&g.files.length>0){o.preventDefault();const c=g.files.at(-1);c&&g.remove(c.id)}},k=o=>{var P;const c=(P=o.clipboardData)==null?void 0:P.items;if(!c)return;const m=[];for(const C of c)if(C.kind==="file"){const D=C.getAsFile();D&&m.push(D)}m.length>0&&(o.preventDefault(),g.add(m))},T=l?{value:l.textInput.value,onChange:o=>{l.textInput.setInput(o.currentTarget.value),t==null||t(o)}}:{onChange:t};return e.jsx(We,{className:r.cn("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>y(!1),onCompositionStart:()=>y(!0),onKeyDown:v,onPaste:k,placeholder:a,...n,...T})},lt=({className:t,...s})=>e.jsx(de,{align:"block-end",className:r.cn("order-first flex-wrap gap-1",t),...s}),ct=({className:t,...s})=>e.jsx(de,{align:"block-end",className:r.cn("justify-between gap-1",t),...s}),dt=({className:t,...s})=>e.jsx("div",{className:r.cn("flex items-center gap-1",t),...s}),W=({variant:t="ghost",className:s,size:a,...n})=>{const l=a??(d.Children.count(n.children)>1?"sm":"icon-sm");return e.jsx(ue,{className:r.cn(s),size:l,type:"button",variant:t,...n})},ut=t=>e.jsx(Te,{...t}),mt=({className:t,children:s,...a})=>e.jsx(Le,{asChild:!0,children:e.jsx(W,{className:t,...a,children:s??e.jsx(b.PlusIcon,{className:"size-4"})})}),pt=({className:t,...s})=>e.jsx(re,{align:"start",className:r.cn(t),...s}),ft=({className:t,variant:s="default",size:a="icon-sm",status:n,children:l,...g})=>{let u=e.jsx(b.CornerDownLeftIcon,{className:"size-4"});return n==="submitted"?u=e.jsx(b.Loader2Icon,{className:"size-4 animate-spin"}):n==="streaming"?u=e.jsx(b.SquareIcon,{className:"size-4"}):n==="error"&&(u=e.jsx(b.XIcon,{className:"size-4"})),e.jsx(ue,{"aria-label":"Submit",className:r.cn(t),size:a,type:"submit",variant:s,...g,children:l??u})},xt=({className:t,textareaRef:s,onTranscriptionChange:a,...n})=>{const[l,g]=d.useState(!1),[u,y]=d.useState(null),v=d.useRef(null);d.useEffect(()=>{if(typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)){const T=window.SpeechRecognition||window.webkitSpeechRecognition,o=new T;o.continuous=!0,o.interimResults=!0,o.lang="en-US",o.onstart=()=>{g(!0)},o.onend=()=>{g(!1)},o.onresult=c=>{var P;let m="";for(let C=c.resultIndex;C<c.results.length;C++){const D=c.results[C];D.isFinal&&(m+=((P=D[0])==null?void 0:P.transcript)??"")}if(m&&(s!=null&&s.current)){const C=s.current,D=C.value,A=D+(D?" ":"")+m;C.value=A,C.dispatchEvent(new Event("input",{bubbles:!0})),a==null||a(A)}},o.onerror=c=>{console.error("Speech recognition error:",c.error),g(!1)},v.current=o,y(o)}return()=>{v.current&&v.current.stop()}},[s,a]);const k=d.useCallback(()=>{u&&(l?u.stop():u.start())},[u,l]);return e.jsx(W,{className:r.cn("relative transition-all duration-200",l&&"animate-pulse bg-accent text-accent-foreground",t),disabled:!u,onClick:k,...n,children:e.jsx(b.MicIcon,{className:"size-4"})})},gt=({openDelay:t=0,closeDelay:s=0,...a})=>e.jsx(Be,{closeDelay:s,openDelay:t,...a}),ht=({align:t="start",...s})=>e.jsx(le,{align:t,...s}),bt=t=>e.jsx(Ce,{...t}),vt=t=>e.jsx(ke,{...t}),jt=({className:t,children:s,title:a="Model Selector",...n})=>e.jsxs(Z,{className:r.cn("p-0",t),...n,children:[e.jsx(ee,{className:"sr-only",children:a}),e.jsx(te,{className:"**:data-[slot=command-input-wrapper]:h-auto",children:s})]}),yt=({className:t,...s})=>e.jsx(se,{className:r.cn("h-auto py-3.5",t),...s}),Nt=t=>e.jsx(ae,{...t}),wt=t=>e.jsx(ne,{...t}),St=t=>e.jsx(oe,{...t}),It=({provider:t,className:s,...a})=>e.jsx("img",{...a,alt:`${t} logo`,className:r.cn("size-3 dark:invert",s),height:12,src:`https://models.dev/logos/${t}.svg`,width:12}),Ct=({className:t,...s})=>e.jsx("span",{className:r.cn("flex-1 truncate text-left",t),...s}),kt=({selectedModel:t,onModelChange:s,disabled:a=!1})=>{const[n,l]=d.useState(!1),[g,u]=d.useState(""),y=U.getModelById(t)||U.getDefaultModel(),k=U.AI_MODELS.filter(o=>o.name.toLowerCase().includes(g.toLowerCase())||o.provider.toLowerCase().includes(g.toLowerCase())).reduce((o,c)=>(o[c.provider]||(o[c.provider]=[]),o[c.provider].push(c),o),{}),T=o=>{s(o),l(!1),u("")};return e.jsxs(bt,{open:n,onOpenChange:l,children:[e.jsx(vt,{asChild:!0,children:e.jsxs(r.Button,{variant:"outline",size:"sm",disabled:a,className:"h-8 gap-1 px-2 text-xs",children:[e.jsx(b.Cpu,{size:14}),e.jsx("span",{className:"max-w-20 truncate",children:y.name})]})}),e.jsxs(jt,{className:"w-96 p-0",children:[e.jsx(yt,{placeholder:"Search models...",value:g,onValueChange:u}),e.jsx(Nt,{children:Object.entries(k).map(([o,c])=>e.jsx(wt,{heading:o.charAt(0).toUpperCase()+o.slice(1),children:c.map(m=>e.jsxs(St,{value:m.id,onSelect:()=>T(m.id),className:"flex cursor-pointer items-center gap-2 p-2",children:[e.jsx(It,{provider:m.provider}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx(Ct,{children:m.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]}),t===m.id&&e.jsx("div",{className:"h-2 w-2 rounded-full bg-blue-500"})]},m.id))},o))})]})]})},$="chai-ai-selected-model",Rt=({input:t,setInput:s,onSend:a,onStop:n,isLoading:l,disabled:g,selectedLang:u,selectedModel:y=U.getDefaultModel().id,onModelChange:v})=>{const{t:k}=Ie.useTranslation(),[T,o]=d.useState(y),[c,m]=d.useState(null),P=d.useRef(null),[C,D]=d.useState(!1);d.useEffect(()=>{if(!u){const j=localStorage.getItem($);if(j)o(j),v==null||v(j);else{const M=U.getDefaultModel().id;o(M),v==null||v(M)}}},[u,v]);const A=j=>{var E;const M=j.files.find(L=>{var O;return(O=L.mediaType)==null?void 0:O.startsWith("image/")}),B=(M==null?void 0:M.url)||c;a((E=j.text)==null?void 0:E.trim(),void 0,B,T),m(null)};return e.jsx("div",{className:"relative",children:e.jsx("div",{className:"border-gray-20 rounded-lg border",children:e.jsxs(rt,{onSubmit:A,accept:"image/*",className:"flex h-auto w-full flex-col",children:[e.jsx(lt,{className:"p-0",children:e.jsx(nt,{className:"pb-0",children:j=>e.jsx(at,{className:"text-xs",data:j})})}),e.jsx(it,{ref:P,value:t,onChange:j=>s(j.target.value),placeholder:k(u?"Ask to update content":"Ask me anything..."),disabled:l,className:"max-h-[200px] min-h-[60px] w-full",rows:3}),e.jsxs(ct,{children:[u?e.jsx("div",{}):e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(mt,{disabled:l,children:e.jsx(b.Paperclip,{size:16})}),e.jsx(pt,{children:e.jsx(ot,{})})]}),e.jsx(xt,{textareaRef:P,onTranscriptionChange:s,disabled:l}),e.jsx(kt,{selectedModel:T,onModelChange:j=>{o(j),v==null||v(j),localStorage.setItem($,j)},disabled:l}),e.jsxs(W,{className:"hidden",size:"sm",onClick:()=>D(!C),variant:C?"default":"ghost",children:[e.jsx(b.GlobeIcon,{size:16}),e.jsx("span",{children:"Search"})]})]}),l?e.jsxs("button",{onClick:n,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:k("Stop generation"),children:[e.jsx(b.Square,{size:16})," ",e.jsx("span",{className:"text-xs",children:k("Stop")})]}):e.jsx(ft,{disabled:!t.trim()||g,children:e.jsx(b.Send,{size:16})})]})]})})})};exports.default=Rt;
|