@chaibuilder/pages 0.16.0 → 0.16.2
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-BxEty5Ow.cjs → 2AITGKQY-8xBkB8Pv.cjs} +1 -1
- package/dist/{2AITGKQY-BFankGad.js → 2AITGKQY-DI5Po2Nc.js} +2 -2
- package/dist/{NCMVHL6D-DP-qw6yT.cjs → NCMVHL6D-B4xqJIpr.cjs} +1 -1
- package/dist/{NCMVHL6D-DFMKkQPN.js → NCMVHL6D-kHUQxG8D.js} +2 -2
- package/dist/{ZDWCUMSJ-Cu1VTliO.cjs → ZDWCUMSJ-CjlhoCfQ.cjs} +1 -1
- package/dist/{ZDWCUMSJ-DU81uAQq.js → ZDWCUMSJ-DRgY2Er1.js} +1 -1
- package/dist/{add-new-language-page-0zC1CJZK.js → add-new-language-page-DSB8ohdj.js} +2 -2
- package/dist/{add-new-language-page-DQ46xqnc.cjs → add-new-language-page-noBKABVx.cjs} +1 -1
- package/dist/{add-new-page-CUtZhDvi.js → add-new-page-BYkFbQvH.js} +1 -1
- package/dist/{add-new-page-Ca2H2J-2.cjs → add-new-page-CByS9KqS.cjs} +1 -1
- package/dist/ai-panel-content-BBnzp4fO.cjs +1 -0
- package/dist/ai-panel-content-DET3HjIR.js +54 -0
- package/dist/ai-panel-default-lang-BYfcAA8u.js +178 -0
- package/dist/ai-panel-default-lang-D-RS6z5I.cjs +1 -0
- package/dist/ai-panel-other-lang-BoD4FsoG.cjs +1 -0
- package/dist/ai-panel-other-lang-TVjNYPRK.js +150 -0
- package/dist/{ai-panel-quick-prompts-DiNVPPAn.cjs → ai-panel-quick-prompts-BGBdrdP7.cjs} +1 -1
- package/dist/{ai-panel-quick-prompts-CpzN48cl.js → ai-panel-quick-prompts-BPrA9nvg.js} +1 -1
- package/dist/ai-prompt-input-DB1FpA_q.cjs +1 -0
- package/dist/ai-prompt-input-qegCvwnu.js +222 -0
- package/dist/ai-translation-prompt--HB1UAhC.js +28 -0
- package/dist/ai-translation-prompt-Bj-AM4xK.cjs +1 -0
- package/dist/{delete-page-BS10zPLU.js → delete-page-C7xfkDN5.js} +1 -1
- package/dist/{delete-page-ClgtvB6n.cjs → delete-page-DJLNpUxo.cjs} +1 -1
- package/dist/{digital-asset-manager-MK8ZL6Nd.cjs → digital-asset-manager-BblMbig0.cjs} +1 -1
- package/dist/{digital-asset-manager-D_FFLECK.js → digital-asset-manager-INrgGoC0.js} +1 -1
- package/dist/{duplicate-page-C1r4cCIJ.js → duplicate-page-B8k4yZxa.js} +2 -2
- package/dist/{duplicate-page-BaZrekqu.cjs → duplicate-page-C9XewuHN.cjs} +1 -1
- package/dist/{dynamic-page-selector-CjtnFkxO.js → dynamic-page-selector-C7Vos5-l.js} +1 -1
- package/dist/{dynamic-page-selector-C4R_vhhz.cjs → dynamic-page-selector-CYYnEngT.cjs} +1 -1
- package/dist/index-CyHmr87X.cjs +5 -0
- package/dist/{index-D_qadcqD.js → index-DRQI9rlW.js} +864 -858
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-diff-viewer-BURQmaIL.js → json-diff-viewer-8vUwU0Sk.js} +1 -1
- package/dist/{json-diff-viewer-CyZVbnpL.cjs → json-diff-viewer-DVskWjAL.cjs} +1 -1
- package/dist/{lang-panel-C8yx7PSU.js → lang-panel-B8SeKnwN.js} +2 -2
- package/dist/{lang-panel-SUARS5YU.cjs → lang-panel-BeyCHr4u.cjs} +1 -1
- package/dist/{mark-as-template-CUHypMlj.js → mark-as-template-CpNHtyfB.js} +1 -1
- package/dist/{mark-as-template-DS-nfI06.cjs → mark-as-template-DTEF_hyN.cjs} +1 -1
- package/dist/{no-language-page-content-qoHrlxwD.js → no-language-page-content-BPiFDGJr.js} +1 -1
- package/dist/{no-language-page-content-DZj3cmtM.cjs → no-language-page-content-DnAP2ICP.cjs} +1 -1
- package/dist/{page-creator-HwE9ST54.cjs → page-creator-BawPgFIv.cjs} +1 -1
- package/dist/{page-creator-C8VQGfap.js → page-creator-BiDN-rLc.js} +2 -2
- package/dist/{page-lock-request-CBVKtxVj.js → page-lock-request-BVYclE6H.js} +1 -1
- package/dist/{page-lock-request-Db7-x_EI.cjs → page-lock-request-wIw-W5qT.cjs} +1 -1
- package/dist/{page-locked-by-dialog-DEC58QPA.js → page-locked-by-dialog-CuHvd48D.js} +1 -1
- package/dist/{page-locked-by-dialog-CvRDaBcN.cjs → page-locked-by-dialog-jZDY0omZ.cjs} +1 -1
- package/dist/{page-manager-new-CBxSkcYY.cjs → page-manager-new-BmZlPcpL.cjs} +1 -1
- package/dist/{page-manager-new-B1PDwz2w.js → page-manager-new-kMwd9hkH.js} +2 -2
- package/dist/{page-manager-search-and-filter-0eTSE1C1.js → page-manager-search-and-filter-BU-1wFbM.js} +1 -1
- package/dist/{page-manager-search-and-filter-BRLPHE64.cjs → page-manager-search-and-filter-DMauRN5Y.cjs} +1 -1
- package/dist/{page-revisions-content-CTrVTQ_s.cjs → page-revisions-content-BH0Xy_k9.cjs} +1 -1
- package/dist/{page-revisions-content-CKcp4He4.js → page-revisions-content-c32By7XR.js} +2 -2
- package/dist/{prompt-helper-BtijECyh.cjs → prompt-helper-BLBZjr5q.cjs} +3 -3
- package/dist/{prompt-helper-CfyAlam9.js → prompt-helper-Bh7WyDYo.js} +31 -19
- package/dist/{publish-pages-content-B6HGaUtO.cjs → publish-pages-content-B5UqPZy0.cjs} +1 -1
- package/dist/{publish-pages-content-BMaeNHV2.js → publish-pages-content-BB6l92oG.js} +2 -2
- package/dist/{save-to-lib-BKKTPv4h.cjs → save-to-lib-DM1MzZTb.cjs} +1 -1
- package/dist/{save-to-lib-CccnzwO8.js → save-to-lib-NvQZll63.js} +1 -1
- package/dist/{seo-panel-4KK4r-BP.js → seo-panel-BsMBb5Ep.js} +1 -1
- package/dist/{seo-panel-DL_rcWwC.cjs → seo-panel-C20m5SFc.cjs} +1 -1
- package/dist/server.cjs +11 -8
- package/dist/server.d.ts +2 -1
- package/dist/server.js +144 -141
- package/dist/{shared-json-ld-DGW40Ccy.js → shared-json-ld-BVqIgANo.js} +1 -1
- package/dist/{shared-json-ld-BuYzbmKx.cjs → shared-json-ld-CfWO90c0.cjs} +1 -1
- package/dist/{slug-input--8SgDwYu.cjs → slug-input-BewLv-d8.cjs} +1 -1
- package/dist/{slug-input-DH5w0H22.js → slug-input-RCGUFL2T.js} +1 -1
- package/dist/{theme-panel-footer-Co5VI_i9.cjs → theme-panel-footer-8oSQtfZ5.cjs} +1 -1
- package/dist/{theme-panel-footer-CHR7J97n.js → theme-panel-footer-BJB36k8A.js} +1 -1
- package/dist/{unmark-as-template-DlA879QF.js → unmark-as-template-CGZ0CCI2.js} +1 -1
- package/dist/{unmark-as-template-B3h10oHA.cjs → unmark-as-template-DLNmyum3.cjs} +1 -1
- package/dist/{unpublish-page-Bfo_DuW5.cjs → unpublish-page-B_xQPGsZ.cjs} +1 -1
- package/dist/{unpublish-page-JzGl35pF.js → unpublish-page-CEtpcrvc.js} +1 -1
- package/dist/{web-preview-CJ6JyhJD.js → web-preview-CCGkTRU3.js} +1 -1
- package/dist/{web-preview-oG2epixb.cjs → web-preview-Cifi0bwK.cjs} +1 -1
- package/package.json +1 -1
- package/dist/ai-panel-content-CV-HTsAs.cjs +0 -1
- package/dist/ai-panel-content-r2jlUBoR.js +0 -52
- package/dist/ai-panel-default-lang-D6RAQW1X.js +0 -173
- package/dist/ai-panel-default-lang-EH3w6g25.cjs +0 -1
- package/dist/ai-panel-other-lang-BeTdv7yM.js +0 -133
- package/dist/ai-panel-other-lang-_gGQTjZQ.cjs +0 -1
- package/dist/ai-prompt-input-D-F23bdc.cjs +0 -1
- package/dist/ai-prompt-input-vAcIZSB1.js +0 -133
- package/dist/ai-translation-prompt-AImJlmDg.cjs +0 -1
- package/dist/ai-translation-prompt-BKyp1IW2.js +0 -63
- package/dist/index-C64wG61b.cjs +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as n, Fragment as j } 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 { am as ge, an as fe, A as U, ar as le, aw as pe, ax as se, ay as re, az as de, aA as xe, aB as Ne, aC as be, g as ye, aD as ve } from "./index-
|
|
4
|
+
import { am as ge, an as fe, A as U, ar as le, aw as pe, ax as se, ay as re, az as de, aA as xe, aB as Ne, aC as be, g as ye, aD as ve } from "./index-DRQI9rlW.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 G, Button as v, AlertDialog as _, AlertDialogContent as R, AlertDialogHeader as M, AlertDialogTitle as q, AlertDialogDescription as H, AlertDialogFooter as Q, AlertDialogCancel as V, AlertDialogAction as K, Tooltip as E, TooltipTrigger as J, TooltipContent as O, ScrollArea as Ce, Card as Se, CardHeader as Pe, CardTitle as Te, AlertDialogTrigger as De, CardContent as Le, Textarea as Ee } from "@chaibuilder/sdk/ui";
|
|
6
6
|
import { filter as Je, find as Oe } from "lodash-es";
|
|
7
7
|
import { Info as Fe, Loader as F, Plus as ke, Eye as je, Edit as Ge, Trash as Be } from "lucide-react";
|
|
@@ -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-C64wG61b.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-CyHmr87X.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 +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-CyHmr87X.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-DRQI9rlW.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 +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-CyHmr87X.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 { jsxs as c, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { u, a as d, t as h } from "./index-
|
|
2
|
+
import { u, a as d, t as h } from "./index-DRQI9rlW.js";
|
|
3
3
|
import { useTheme as b, useTranslation as g } from "@chaibuilder/sdk";
|
|
4
4
|
import { Button as o } from "@chaibuilder/sdk/ui";
|
|
5
5
|
const x = () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as o } from "react/jsx-runtime";
|
|
2
|
-
import { o as p } from "./index-
|
|
2
|
+
import { o as p } from "./index-DRQI9rlW.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-CyHmr87X.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 +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-CyHmr87X.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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as o, jsxs as l } from "react/jsx-runtime";
|
|
2
|
-
import { l as u } from "./index-
|
|
2
|
+
import { l as u } from "./index-DRQI9rlW.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: t }) => {
|
|
@@ -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-DRQI9rlW.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-CyHmr87X.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","fill-rule":"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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-C64wG61b.cjs"),b=require("@chaibuilder/sdk"),y=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),n=require("react"),N=require("sonner"),k=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-default-lang-EH3w6g25.cjs"))),A=n.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-other-lang-_gGQTjZQ.cjs"))),z=()=>{const{t:r}=b.useTranslation(),[m,o]=n.useState(""),[t,l]=n.useState([]),[a,c]=n.useState(!1),[i,u]=n.useState(null),[p,d]=n.useState(null),{selectedLang:f,fallbackLang:P}=b.useLanguages(),S=j.useBuilderFetch(),[q]=j.useSearchParams(),v=q.get("page"),w=(t==null?void 0:t.filter(s=>s.role==="user").length)>=4,L=(t==null?void 0:t.filter(s=>s.role==="user").length)>=10;n.useEffect(()=>{l([])},[f,v]);const x=()=>{l([]),o(""),d(null),u(null),c(!1)},g={t:r,fetch:S,input:m,messages:t,setInput:o,isLoading:a,handleStop:()=>{i&&(i.abort(),u(null)),c(!1),o(""),d(null),l(s=>{const h=s[s.length-1];return h&&h.role==="assistant"&&!h.content.trim()?s.slice(0,-1):s}),N.toast.info(r("Generation stopped"))},handleReset:x,setMessages:l,setIsLoading:c,currentBlock:p,fallbackLang:P,abortController:i,setCurrentBlock:d,setAbortController:u,forceNewConversation:L,suggestNewConversation:w};return e.jsxs(e.Fragment,{children:[a&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col bg-white",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("Your conversation will not be saved")}),(t==null?void 0:t.length)>0&&e.jsx(y.Button,{variant:"outline",size:"icon",onClick:x,className:"h-6 w-6",disabled:a,children:e.jsx(C.Plus,{})})]}),e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading AI Panel..."}),children:f?e.jsx(A,{...g,selectedLang:f}):e.jsx(k,{...g})})]})]})};exports.default=z;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { jsxs as h, Fragment as A, jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { q as S, i as j } from "./index-D_qadcqD.js";
|
|
3
|
-
import { useTranslation as y, useLanguages as B } from "@chaibuilder/sdk";
|
|
4
|
-
import { Button as F } from "@chaibuilder/sdk/ui";
|
|
5
|
-
import { Plus as z } from "lucide-react";
|
|
6
|
-
import { lazy as x, useState as l, useEffect as I, Suspense as M } from "react";
|
|
7
|
-
import { toast as q } from "sonner";
|
|
8
|
-
const D = x(() => import("./ai-panel-default-lang-D6RAQW1X.js")), E = x(() => import("./ai-panel-other-lang-BeTdv7yM.js")), Q = () => {
|
|
9
|
-
const { t: s } = y(), [b, r] = l(""), [e, o] = l([]), [a, i] = l(!1), [c, u] = l(null), [w, f] = l(null), { selectedLang: d, fallbackLang: L } = B(), P = S(), [C] = j(), N = C.get("page"), v = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 4, k = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 10;
|
|
10
|
-
I(() => {
|
|
11
|
-
o([]);
|
|
12
|
-
}, [d, N]);
|
|
13
|
-
const p = () => {
|
|
14
|
-
o([]), r(""), f(null), u(null), i(!1);
|
|
15
|
-
}, g = {
|
|
16
|
-
t: s,
|
|
17
|
-
fetch: P,
|
|
18
|
-
input: b,
|
|
19
|
-
messages: e,
|
|
20
|
-
setInput: r,
|
|
21
|
-
isLoading: a,
|
|
22
|
-
handleStop: () => {
|
|
23
|
-
c && (c.abort(), u(null)), i(!1), r(""), f(null), o((t) => {
|
|
24
|
-
const m = t[t.length - 1];
|
|
25
|
-
return m && m.role === "assistant" && !m.content.trim() ? t.slice(0, -1) : t;
|
|
26
|
-
}), q.info(s("Generation stopped"));
|
|
27
|
-
},
|
|
28
|
-
handleReset: p,
|
|
29
|
-
setMessages: o,
|
|
30
|
-
setIsLoading: i,
|
|
31
|
-
currentBlock: w,
|
|
32
|
-
fallbackLang: L,
|
|
33
|
-
abortController: c,
|
|
34
|
-
setCurrentBlock: f,
|
|
35
|
-
setAbortController: u,
|
|
36
|
-
forceNewConversation: k,
|
|
37
|
-
suggestNewConversation: v
|
|
38
|
-
};
|
|
39
|
-
return /* @__PURE__ */ h(A, { children: [
|
|
40
|
-
a && /* @__PURE__ */ n("div", { className: "fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent" }),
|
|
41
|
-
/* @__PURE__ */ h("div", { className: "flex h-full w-full flex-col bg-white", children: [
|
|
42
|
-
/* @__PURE__ */ h("div", { className: "flex w-full items-center justify-between", children: [
|
|
43
|
-
/* @__PURE__ */ n("p", { className: "text-xs text-gray-500", children: s("Your conversation will not be saved") }),
|
|
44
|
-
(e == null ? void 0 : e.length) > 0 && /* @__PURE__ */ n(F, { variant: "outline", size: "icon", onClick: p, className: "h-6 w-6", disabled: a, children: /* @__PURE__ */ n(z, {}) })
|
|
45
|
-
] }),
|
|
46
|
-
/* @__PURE__ */ n(M, { fallback: /* @__PURE__ */ n("div", { children: "Loading AI Panel..." }), children: d ? /* @__PURE__ */ n(E, { ...g, selectedLang: d }) : /* @__PURE__ */ n(D, { ...g }) })
|
|
47
|
-
] })
|
|
48
|
-
] });
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
Q as default
|
|
52
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { jsxs as w, Fragment as X, jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { useAddBlock as Y, useReplaceBlock as Z, useSelectedBlock as ee, useBlocksHtmlForAi as te, useHtmlToBlocks as re } from "@chaibuilder/sdk";
|
|
3
|
-
import { Bot as ne, Plus as oe } from "lucide-react";
|
|
4
|
-
import { lazy as _, useRef as le, useEffect as se, Suspense as T } from "react";
|
|
5
|
-
import { toast as ae } from "sonner";
|
|
6
|
-
import { a as ce } from "./prompt-helper-CfyAlam9.js";
|
|
7
|
-
function ie(t) {
|
|
8
|
-
if (!t) return "";
|
|
9
|
-
let e = t.trim();
|
|
10
|
-
return e = e.replace(/^```html\n?/i, ""), e = e.replace(/^```\n?/, ""), e = e.replace(/\n?```$/, ""), e = e.trim(), e;
|
|
11
|
-
}
|
|
12
|
-
function de(t) {
|
|
13
|
-
if (!t) return "";
|
|
14
|
-
const e = ie(t);
|
|
15
|
-
return e.length === 0 || !e.includes("<") || !e.includes(">") ? "" : e;
|
|
16
|
-
}
|
|
17
|
-
const ue = (t) => {
|
|
18
|
-
const e = document.getElementById("canvas-iframe");
|
|
19
|
-
if (!e) return null;
|
|
20
|
-
const s = e == null ? void 0 : e.contentDocument;
|
|
21
|
-
if (!s) return null;
|
|
22
|
-
const l = s.querySelector(`[data-block-id="${t}"]`);
|
|
23
|
-
if (!l) return null;
|
|
24
|
-
if (t === "canvas") {
|
|
25
|
-
const c = s.createElement("div");
|
|
26
|
-
return c.style.height = "100vh", l.appendChild(c), c;
|
|
27
|
-
}
|
|
28
|
-
return l;
|
|
29
|
-
}, me = _(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), fe = _(() => import("./ai-prompt-input-vAcIZSB1.js")), ve = ({
|
|
30
|
-
t,
|
|
31
|
-
fetch: e,
|
|
32
|
-
input: s,
|
|
33
|
-
messages: l,
|
|
34
|
-
setInput: c,
|
|
35
|
-
isLoading: u,
|
|
36
|
-
setMessages: g,
|
|
37
|
-
handleReset: D,
|
|
38
|
-
handleStop: j,
|
|
39
|
-
setIsLoading: k,
|
|
40
|
-
currentBlock: M,
|
|
41
|
-
fallbackLang: V,
|
|
42
|
-
setCurrentBlock: E,
|
|
43
|
-
setAbortController: A,
|
|
44
|
-
forceNewConversation: v,
|
|
45
|
-
suggestNewConversation: z
|
|
46
|
-
}) => {
|
|
47
|
-
const N = le(null), { addPredefinedBlock: q } = Y(), U = Z(), m = ee(), W = te(), $ = re(), C = () => {
|
|
48
|
-
var o;
|
|
49
|
-
(o = N.current) == null || o.scrollIntoView({ behavior: "smooth" });
|
|
50
|
-
};
|
|
51
|
-
se(() => {
|
|
52
|
-
C();
|
|
53
|
-
}, [l, u]);
|
|
54
|
-
const K = async (o, f, B) => {
|
|
55
|
-
var F;
|
|
56
|
-
if (!o || u) return;
|
|
57
|
-
const r = m;
|
|
58
|
-
E(m);
|
|
59
|
-
const H = W();
|
|
60
|
-
if (m && !H) {
|
|
61
|
-
ae.error(t("Something went wrong. Please try again."));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const I = {
|
|
65
|
-
id: Date.now().toString(),
|
|
66
|
-
role: "user",
|
|
67
|
-
content: ce({
|
|
68
|
-
language: V,
|
|
69
|
-
userInput: f || o,
|
|
70
|
-
currentHtml: H
|
|
71
|
-
}),
|
|
72
|
-
userMessage: o
|
|
73
|
-
}, R = { id: Date.now().toString(), role: "assistant", content: "" };
|
|
74
|
-
g((i) => [...i, I, R]), k(!0);
|
|
75
|
-
const L = new AbortController();
|
|
76
|
-
A(L);
|
|
77
|
-
try {
|
|
78
|
-
const i = {
|
|
79
|
-
messages: [...l, I].map((x) => ({
|
|
80
|
-
role: x.role,
|
|
81
|
-
content: x.content
|
|
82
|
-
}))
|
|
83
|
-
};
|
|
84
|
-
B && (i.image = B);
|
|
85
|
-
const h = await e({ body: { action: "ASK_AI", data: i }, streamResponse: !0 });
|
|
86
|
-
if (!h.ok)
|
|
87
|
-
throw new Error(t("Failed to get AI response"));
|
|
88
|
-
const p = (F = h.body) == null ? void 0 : F.getReader(), O = new TextDecoder();
|
|
89
|
-
let b = "";
|
|
90
|
-
if (!p) throw new Error(t("Response body is not readable"));
|
|
91
|
-
const d = ue(r ? r == null ? void 0 : r._id : "canvas");
|
|
92
|
-
for (; ; ) {
|
|
93
|
-
const { done: x, value: J } = await p.read();
|
|
94
|
-
if (x) {
|
|
95
|
-
d && !r && d.remove();
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
const Q = O.decode(J, { stream: !0 });
|
|
99
|
-
if (b += Q, d) {
|
|
100
|
-
d.innerHTML = b;
|
|
101
|
-
const y = d.getBoundingClientRect(), a = document.getElementById("canvas-iframe"), P = a == null ? void 0 : a.contentWindow;
|
|
102
|
-
P && (y.top >= 0 && y.bottom <= P.innerHeight || d.scrollIntoView({ behavior: "smooth", block: "nearest" }));
|
|
103
|
-
}
|
|
104
|
-
g(
|
|
105
|
-
(y) => y.map((a) => a.id === R.id ? { ...a, content: b } : a)
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
const G = de(b), S = $(G);
|
|
109
|
-
r != null && r._id ? (console.log("Editing block", r == null ? void 0 : r._id, S), U(r == null ? void 0 : r._id, S)) : q([...S], r == null ? void 0 : r._parent, -1);
|
|
110
|
-
} catch (i) {
|
|
111
|
-
if (i.name !== "AbortError") {
|
|
112
|
-
const h = {
|
|
113
|
-
id: (Date.now() + 1).toString(),
|
|
114
|
-
role: "assistant",
|
|
115
|
-
content: t("Sorry, I encountered an error. Please try again.")
|
|
116
|
-
};
|
|
117
|
-
g((p) => [...p, h]);
|
|
118
|
-
}
|
|
119
|
-
} finally {
|
|
120
|
-
c(""), k(!1), E(null), A(null);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
return /* @__PURE__ */ w(X, { children: [
|
|
124
|
-
/* @__PURE__ */ w("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: [
|
|
125
|
-
l.length === 0 && /* @__PURE__ */ n("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: /* @__PURE__ */ w("div", { className: "mx-auto mt-8 text-center text-gray-500", children: [
|
|
126
|
-
/* @__PURE__ */ n(ne, { size: 48, className: "mx-auto mb-4 text-gray-300" }),
|
|
127
|
-
/* @__PURE__ */ n("p", { className: "mx-auto max-w-[75%] text-sm", children: t("Start a conversation with the AI assistant to generate and update your sections") })
|
|
128
|
-
] }) }),
|
|
129
|
-
l.map(
|
|
130
|
-
(o, f) => o.role !== "system" && /* @__PURE__ */ n(T, { fallback: /* @__PURE__ */ n("div", { children: "Loading..." }), children: /* @__PURE__ */ n(
|
|
131
|
-
me,
|
|
132
|
-
{
|
|
133
|
-
message: o,
|
|
134
|
-
isUser: o.role === "user",
|
|
135
|
-
isLoading: o.role === "assistant" && u && f === l.length - 1
|
|
136
|
-
}
|
|
137
|
-
) }, f)
|
|
138
|
-
),
|
|
139
|
-
z && !u && /* @__PURE__ */ n(
|
|
140
|
-
"button",
|
|
141
|
-
{
|
|
142
|
-
onClick: D,
|
|
143
|
-
className: "flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",
|
|
144
|
-
children: /* @__PURE__ */ n("div", { className: "flex flex-col", children: /* @__PURE__ */ w("span", { className: "flex items-center gap-1 text-xs font-medium text-blue-700", children: [
|
|
145
|
-
/* @__PURE__ */ n(oe, { className: "h-4 w-4 capitalize text-blue-600" }),
|
|
146
|
-
t(v ? "Start" : "New"),
|
|
147
|
-
" ",
|
|
148
|
-
t("Conversation"),
|
|
149
|
-
" ",
|
|
150
|
-
!v && /* @__PURE__ */ n("span", { className: "text-[10px] font-extralight text-blue-600", children: t("For best results") })
|
|
151
|
-
] }) })
|
|
152
|
-
}
|
|
153
|
-
),
|
|
154
|
-
/* @__PURE__ */ n("div", { ref: N })
|
|
155
|
-
] }),
|
|
156
|
-
!v && /* @__PURE__ */ n("div", { className: "border-gray-200 pb-2", children: /* @__PURE__ */ n(T, { fallback: /* @__PURE__ */ n("div", { children: "Loading..." }), children: /* @__PURE__ */ n(
|
|
157
|
-
fe,
|
|
158
|
-
{
|
|
159
|
-
input: s,
|
|
160
|
-
setInput: c,
|
|
161
|
-
onSend: K,
|
|
162
|
-
onStop: j,
|
|
163
|
-
isLoading: u,
|
|
164
|
-
selectedLang: "",
|
|
165
|
-
currentBlock: m || M,
|
|
166
|
-
disabled: (s == null ? void 0 : s.length) === 0
|
|
167
|
-
}
|
|
168
|
-
) }) })
|
|
169
|
-
] });
|
|
170
|
-
};
|
|
171
|
-
export {
|
|
172
|
-
ve as default
|
|
173
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("@chaibuilder/sdk"),F=require("lucide-react"),d=require("react"),X=require("sonner"),Y=require("./prompt-helper-BtijECyh.cjs");function Z(n){if(!n)return"";let e=n.trim();return e=e.replace(/^```html\n?/i,""),e=e.replace(/^```\n?/,""),e=e.replace(/\n?```$/,""),e=e.trim(),e}function ee(n){if(!n)return"";const e=Z(n);return e.length===0||!e.includes("<")||!e.includes(">")?"":e}const te=n=>{const e=document.getElementById("canvas-iframe");if(!e)return null;const l=e==null?void 0:e.contentDocument;if(!l)return null;const s=l.querySelector(`[data-block-id="${n}"]`);if(!s)return null;if(n==="canvas"){const a=l.createElement("div");return a.style.height="100vh",s.appendChild(a),a}return s},ne=d.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),re=d.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-D-F23bdc.cjs"))),oe=({t:n,fetch:e,input:l,messages:s,setInput:a,isLoading:m,setMessages:v,handleReset:T,handleStop:_,setIsLoading:k,currentBlock:D,fallbackLang:M,setCurrentBlock:R,setAbortController:E,forceNewConversation:j,suggestNewConversation:z})=>{const q=d.useRef(null),{addPredefinedBlock:V}=f.useAddBlock(),O=f.useReplaceBlock(),h=f.useSelectedBlock(),U=f.useBlocksHtmlForAi(),W=f.useHtmlToBlocks(),$=()=>{var o;(o=q.current)==null||o.scrollIntoView({behavior:"smooth"})};d.useEffect(()=>{$()},[s,m]);const C=async(o,x,A)=>{var B;if(!o||m)return;const r=h;R(h);const H=U();if(h&&!H){X.toast.error(n("Something went wrong. Please try again."));return}const N={id:Date.now().toString(),role:"user",content:Y.getUserPrompt({language:M,userInput:x||o,currentHtml:H}),userMessage:o},P={id:Date.now().toString(),role:"assistant",content:""};v(i=>[...i,N,P]),k(!0);const K=new AbortController;E(K);try{const i={messages:[...s,N].map(w=>({role:w.role,content:w.content}))};A&&(i.image=A);const b=await e({body:{action:"ASK_AI",data:i},streamResponse:!0});if(!b.ok)throw new Error(n("Failed to get AI response"));const p=(B=b.body)==null?void 0:B.getReader(),L=new TextDecoder;let y="";if(!p)throw new Error(n("Response body is not readable"));const u=te(r?r==null?void 0:r._id:"canvas");for(;;){const{done:w,value:J}=await p.read();if(w){u&&!r&&u.remove();break}const Q=L.decode(J,{stream:!0});if(y+=Q,u){u.innerHTML=y;const g=u.getBoundingClientRect(),c=document.getElementById("canvas-iframe"),I=c==null?void 0:c.contentWindow;I&&(g.top>=0&&g.bottom<=I.innerHeight||u.scrollIntoView({behavior:"smooth",block:"nearest"}))}v(g=>g.map(c=>c.id===P.id?{...c,content:y}:c))}const G=ee(y),S=W(G);r!=null&&r._id?(console.log("Editing block",r==null?void 0:r._id,S),O(r==null?void 0:r._id,S)):V([...S],r==null?void 0:r._parent,-1)}catch(i){if(i.name!=="AbortError"){const b={id:(Date.now()+1).toString(),role:"assistant",content:n("Sorry, I encountered an error. Please try again.")};v(p=>[...p,b])}}finally{a(""),k(!1),R(null),E(null)}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[s.length===0&&t.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:t.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[t.jsx(F.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),t.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:n("Start a conversation with the AI assistant to generate and update your sections")})]})}),s.map((o,x)=>o.role!=="system"&&t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(ne,{message:o,isUser:o.role==="user",isLoading:o.role==="assistant"&&m&&x===s.length-1})},x)),z&&!m&&t.jsx("button",{onClick:T,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:t.jsx("div",{className:"flex flex-col",children:t.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[t.jsx(F.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),n(j?"Start":"New")," ",n("Conversation")," ",!j&&t.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:n("For best results")})]})})}),t.jsx("div",{ref:q})]}),!j&&t.jsx("div",{className:"border-gray-200 pb-2",children:t.jsx(d.Suspense,{fallback:t.jsx("div",{children:"Loading..."}),children:t.jsx(re,{input:l,setInput:a,onSend:C,onStop:_,isLoading:m,selectedLang:"",currentBlock:h||D,disabled:(l==null?void 0:l.length)===0})})})]})};exports.default=oe;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { jsxs as i, Fragment as V, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { useTranslation as W, useSelectedBlock as G, useI18nBlocks as H, useStreamMultipleBlocksProps as Q } from "@chaibuilder/sdk";
|
|
3
|
-
import { Bot as X, Plus as Y } from "lucide-react";
|
|
4
|
-
import { lazy as b, useRef as Z, useEffect as $, Suspense as f } from "react";
|
|
5
|
-
import { g as L } from "./prompt-helper-CfyAlam9.js";
|
|
6
|
-
const ee = b(() => import("./ai-panel-message-bubble-DPAaAMAZ.js")), te = b(() => import("./ai-translation-prompt-BKyp1IW2.js")), se = b(() => import("./ai-prompt-input-vAcIZSB1.js")), ce = ({
|
|
7
|
-
fetch: E,
|
|
8
|
-
input: l,
|
|
9
|
-
messages: n,
|
|
10
|
-
setInput: x,
|
|
11
|
-
isLoading: r,
|
|
12
|
-
handleStop: P,
|
|
13
|
-
handleReset: R,
|
|
14
|
-
setMessages: p,
|
|
15
|
-
setIsLoading: d,
|
|
16
|
-
selectedLang: c,
|
|
17
|
-
currentBlock: j,
|
|
18
|
-
fallbackLang: O,
|
|
19
|
-
abortController: u,
|
|
20
|
-
setAbortController: D,
|
|
21
|
-
forceNewConversation: m,
|
|
22
|
-
suggestNewConversation: F
|
|
23
|
-
}) => {
|
|
24
|
-
const { t: s } = W(), y = Z(null), w = G(), g = H(), I = Q(), M = () => {
|
|
25
|
-
var t;
|
|
26
|
-
(t = y.current) == null || t.scrollIntoView({ behavior: "smooth" });
|
|
27
|
-
};
|
|
28
|
-
$(() => {
|
|
29
|
-
M();
|
|
30
|
-
}, [n, r]);
|
|
31
|
-
const k = async (t, o) => {
|
|
32
|
-
var v;
|
|
33
|
-
const N = (t == null ? void 0 : t.toLowerCase()) === "translate", T = {
|
|
34
|
-
id: Date.now().toString(),
|
|
35
|
-
role: "user",
|
|
36
|
-
content: L({
|
|
37
|
-
fallbackLang: O,
|
|
38
|
-
userInput: o || t,
|
|
39
|
-
language: c,
|
|
40
|
-
blocks: N ? g() : g(c)
|
|
41
|
-
}),
|
|
42
|
-
userMessage: o || t || s("Translate the content")
|
|
43
|
-
};
|
|
44
|
-
d(!0);
|
|
45
|
-
const z = new AbortController();
|
|
46
|
-
D(z);
|
|
47
|
-
const U = { id: Date.now().toString(), role: "assistant", content: "" };
|
|
48
|
-
p((S) => [...S, T, U]), d(!0);
|
|
49
|
-
try {
|
|
50
|
-
const B = await E({ body: { action: "ASK_AI", data: {
|
|
51
|
-
messages: [T],
|
|
52
|
-
initiator: N ? "TRANSLATE_CONTENT" : "UPDATE_CONTENT"
|
|
53
|
-
} }, streamResponse: !0 });
|
|
54
|
-
if (!B.ok)
|
|
55
|
-
throw new Error(s("Failed to get AI response"));
|
|
56
|
-
const A = (v = B.body) == null ? void 0 : v.getReader(), _ = new TextDecoder();
|
|
57
|
-
let a = "";
|
|
58
|
-
if (!A) throw new Error(s("Response body is not readable"));
|
|
59
|
-
for (; ; ) {
|
|
60
|
-
const { done: C, value: J } = await A.read();
|
|
61
|
-
if (C)
|
|
62
|
-
break;
|
|
63
|
-
const K = _.decode(J, { stream: !0 });
|
|
64
|
-
a += K, p((h) => (h[h.length - 1].content = a, [...h]));
|
|
65
|
-
}
|
|
66
|
-
const q = JSON.parse(a == null ? void 0 : a.replace("```json", "").replace("```", ""));
|
|
67
|
-
I(q);
|
|
68
|
-
} catch {
|
|
69
|
-
u == null || u.abort();
|
|
70
|
-
} finally {
|
|
71
|
-
d(!1), x("");
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return /* @__PURE__ */ i(V, { children: [
|
|
75
|
-
/* @__PURE__ */ e("div", { className: "py-2", children: /* @__PURE__ */ e(f, { fallback: /* @__PURE__ */ e("div", { children: s("Loading...") }), children: /* @__PURE__ */ e(
|
|
76
|
-
te,
|
|
77
|
-
{
|
|
78
|
-
isLoading: r,
|
|
79
|
-
selectedBlock: w,
|
|
80
|
-
selectedLang: c,
|
|
81
|
-
onClick: k
|
|
82
|
-
}
|
|
83
|
-
) }) }),
|
|
84
|
-
/* @__PURE__ */ i("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: [
|
|
85
|
-
n.length === 0 && /* @__PURE__ */ e("div", { className: "flex-1 space-y-3 overflow-y-auto py-4", children: /* @__PURE__ */ i("div", { className: "mx-auto mt-8 text-center text-gray-500", children: [
|
|
86
|
-
/* @__PURE__ */ e(X, { size: 48, className: "mx-auto mb-4 text-gray-300" }),
|
|
87
|
-
/* @__PURE__ */ e("p", { className: "mx-auto max-w-[75%] text-sm", children: s("Start a conversation with the AI assistant to translate your content") })
|
|
88
|
-
] }) }),
|
|
89
|
-
n.map(
|
|
90
|
-
(t, o) => t.role !== "system" && /* @__PURE__ */ e(f, { fallback: /* @__PURE__ */ e("div", { children: s("Loading...") }), children: /* @__PURE__ */ e(
|
|
91
|
-
ee,
|
|
92
|
-
{
|
|
93
|
-
message: t,
|
|
94
|
-
isUser: t.role === "user",
|
|
95
|
-
isLoading: t.role === "assistant" && r && o === n.length - 1
|
|
96
|
-
}
|
|
97
|
-
) }, o)
|
|
98
|
-
),
|
|
99
|
-
F && !r && /* @__PURE__ */ e(
|
|
100
|
-
"button",
|
|
101
|
-
{
|
|
102
|
-
onClick: R,
|
|
103
|
-
className: "flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",
|
|
104
|
-
children: /* @__PURE__ */ e("div", { className: "flex flex-col", children: /* @__PURE__ */ i("span", { className: "flex items-center gap-1 text-xs font-medium text-blue-700", children: [
|
|
105
|
-
/* @__PURE__ */ e(Y, { className: "h-4 w-4 capitalize text-blue-600" }),
|
|
106
|
-
m ? s("Start ") : "",
|
|
107
|
-
" ",
|
|
108
|
-
s("New Conversation"),
|
|
109
|
-
" ",
|
|
110
|
-
!m && /* @__PURE__ */ e("span", { className: "text-[10px] font-extralight text-blue-600", children: s("For best results") })
|
|
111
|
-
] }) })
|
|
112
|
-
}
|
|
113
|
-
),
|
|
114
|
-
/* @__PURE__ */ e("div", { ref: y })
|
|
115
|
-
] }),
|
|
116
|
-
!m && /* @__PURE__ */ e("div", { className: "border-gray-200 pb-2", children: /* @__PURE__ */ e(f, { fallback: /* @__PURE__ */ e("div", { children: s("Loading...") }), children: /* @__PURE__ */ e(
|
|
117
|
-
se,
|
|
118
|
-
{
|
|
119
|
-
input: l,
|
|
120
|
-
setInput: x,
|
|
121
|
-
onSend: k,
|
|
122
|
-
onStop: P,
|
|
123
|
-
isLoading: r,
|
|
124
|
-
selectedLang: c,
|
|
125
|
-
currentBlock: w || j,
|
|
126
|
-
disabled: (l == null ? void 0 : l.length) === 0
|
|
127
|
-
}
|
|
128
|
-
) }) })
|
|
129
|
-
] });
|
|
130
|
-
};
|
|
131
|
-
export {
|
|
132
|
-
ce as default
|
|
133
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("@chaibuilder/sdk"),B=require("lucide-react"),r=require("react"),K=require("./prompt-helper-BtijECyh.cjs"),V=r.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-message-bubble-Bl-aUeU4.cjs"))),W=r.lazy(()=>Promise.resolve().then(()=>require("./ai-translation-prompt-AImJlmDg.cjs"))),G=r.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-D-F23bdc.cjs"))),Q=({fetch:P,input:a,messages:c,setInput:b,isLoading:n,handleStop:q,handleReset:A,setMessages:j,setIsLoading:d,selectedLang:i,currentBlock:R,fallbackLang:E,abortController:x,setAbortController:O,forceNewConversation:h,suggestNewConversation:z})=>{const{t}=u.useTranslation(),f=r.useRef(null),y=u.useSelectedBlock(),p=u.useI18nBlocks(),M=u.useStreamMultipleBlocksProps(),D=()=>{var s;(s=f.current)==null||s.scrollIntoView({behavior:"smooth"})};r.useEffect(()=>{D()},[c,n]);const g=async(s,o)=>{var v;const k=(s==null?void 0:s.toLowerCase())==="translate",w={id:Date.now().toString(),role:"user",content:K.getTranslationUserPrompt({fallbackLang:E,userInput:o||s,language:i,blocks:k?p():p(i)}),userMessage:o||s||t("Translate the content")};d(!0);const F=new AbortController;O(F);const I={id:Date.now().toString(),role:"assistant",content:""};j(N=>[...N,w,I]),d(!0);try{const S=await P({body:{action:"ASK_AI",data:{messages:[w],initiator:k?"TRANSLATE_CONTENT":"UPDATE_CONTENT"}},streamResponse:!0});if(!S.ok)throw new Error(t("Failed to get AI response"));const T=(v=S.body)==null?void 0:v.getReader(),U=new TextDecoder;let l="";if(!T)throw new Error(t("Response body is not readable"));for(;;){const{done:C,value:H}=await T.read();if(C)break;const J=U.decode(H,{stream:!0});l+=J,j(m=>(m[m.length-1].content=l,[...m]))}const _=JSON.parse(l==null?void 0:l.replace("```json","").replace("```",""));M(_)}catch{x==null||x.abort()}finally{d(!1),b("")}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(W,{isLoading:n,selectedBlock:y,selectedLang:i,onClick:g})})}),e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[c.length===0&&e.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:e.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[e.jsx(B.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:t("Start a conversation with the AI assistant to translate your content")})]})}),c.map((s,o)=>s.role!=="system"&&e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(V,{message:s,isUser:s.role==="user",isLoading:s.role==="assistant"&&n&&o===c.length-1})},o)),z&&!n&&e.jsx("button",{onClick:A,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-blue-200 bg-blue-50 p-1.5 text-left transition-colors hover:bg-blue-100",children:e.jsx("div",{className:"flex flex-col",children:e.jsxs("span",{className:"flex items-center gap-1 text-xs font-medium text-blue-700",children:[e.jsx(B.Plus,{className:"h-4 w-4 capitalize text-blue-600"}),h?t("Start "):""," ",t("New Conversation")," ",!h&&e.jsx("span",{className:"text-[10px] font-extralight text-blue-600",children:t("For best results")})]})})}),e.jsx("div",{ref:f})]}),!h&&e.jsx("div",{className:"border-gray-200 pb-2",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{children:t("Loading...")}),children:e.jsx(G,{input:a,setInput:b,onSend:g,onStop:q,isLoading:n,selectedLang:i,currentBlock:y||R,disabled:(a==null?void 0:a.length)===0})})})]})};exports.default=Q;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),z=require("@chaibuilder/sdk"),x=require("lucide-react"),i=require("react"),A=i.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-quick-prompts-DiNVPPAn.cjs"))),P=({input:r,setInput:u,onSend:h,onStop:p,isLoading:s,disabled:f,currentBlock:b,selectedLang:a})=>{const{t:l}=z.useTranslation(),d=i.useRef(null),g=i.useRef(null),[o,m]=i.useState(null),w=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),r.trim()&&!s&&(h(r==null?void 0:r.trim(),void 0,o||void 0),m(null)))},N=()=>{const t=d.current;t&&(t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px")},S=t=>{var c;const n=(c=t.target.files)==null?void 0:c[0];if(n&&n.type.startsWith("image/")){const v=new FileReader;v.onload=C=>{var j,y;const q=(j=C.target)==null?void 0:j.result;m(q),u(l("Generate UI based on given image ")),(y=d.current)==null||y.focus()},v.readAsDataURL(n)}t.target.value=""},k=()=>{var t;(t=g.current)==null||t.click()},R=()=>{h(r==null?void 0:r.trim(),void 0,o||void 0),m(null)};return i.useEffect(()=>{N()},[r]),e.jsxs("div",{className:"relative",children:[!o&&!(a&&!b)&&e.jsx("div",{className:`mx-auto flex w-full max-w-[95%] flex-col items-center overflow-hidden rounded-t-md border-x border-t border-gray-200 ${s?"pointer-events-none opacity-50":""}`,children:e.jsx(A,{currentBlock:b,selectedLang:a,onSelect:(t,n)=>{var c;u(n+" "),(c=d.current)==null||c.focus()}})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[o&&e.jsxs("div",{className:"relative flex w-max items-center justify-start gap-x-2 px-2 pt-2",children:[e.jsx("img",{src:o,alt:"Selected attachment",className:"max-h-16 max-w-full rounded-md border"}),e.jsx("button",{onClick:()=>m(null),className:"absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",title:l("Remove image"),children:e.jsx(x.X,{className:"h-2 w-2"})})]}),e.jsx("textarea",{ref:d,value:r,onChange:t=>u(t.target.value),onKeyDown:w,placeholder:l(a?"Ask to update content":"Ask me anything..."),className:`max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${s?"cursor-not-allowed opacity-50":""}`,rows:3,disabled:s}),e.jsxs("div",{className:"flex items-center justify-between p-2",children:[a?e.jsx("div",{}):e.jsx("button",{disabled:s,onClick:k,className:`p-1.5 text-gray-400 hover:text-gray-500 ${s||a?"cursor-not-allowed opacity-50":""}`,title:l("Attach Image"),children:e.jsx(x.Paperclip,{size:16})}),e.jsx("input",{disabled:s,ref:g,type:"file",accept:"image/*",onChange:S,className:"hidden"}),s?e.jsxs("button",{onClick:p,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:l("Stop generation"),children:[e.jsx(x.Square,{size:16})," ",e.jsx("span",{className:"text-xs",children:l("Stop")})]}):e.jsx("button",{onClick:R,disabled:!r.trim()||f,className:`rounded-md bg-blue-500 p-1.5 text-white ${!r.trim()||f?"cursor-not-allowed opacity-50":"transition-colors hover:bg-blue-600"}`,children:e.jsx(x.Send,{size:16})})]})]})]})};exports.default=P;
|