2 lines
24 KiB
JavaScript
2 lines
24 KiB
JavaScript
import{r as m,j as e}from"./router-zNjPR4CY.js";import{x as A,y as L,p as $,B as v,g as I,I as E,C as F,L as N,E as ee,S as q,f as V,b as se,d as te,e as ae,X as G,Y as Q,T as fe,O as ve,P as ye,R as Ne,D as be,i as we,j as Ce,k as Se,l as Pe,a3 as ke,af as Oe,ag as Re,ah as Ee}from"./index-CuOHsLf7.js";import{S as re}from"./switch-Kc2EZ0Ga.js";import{S as ne}from"./slider-mDhSC-zv.js";import{T as Te}from"./textarea-8PIujbf-.js";import{B}from"./badge-CDs67obV.js";import{u as Ae,a as X,s as Le,K as $e,P as _e,b as Fe,D as Me,c as ze,S as Ve,v as Be,d as Je,C as He}from"./dnd-BoJ1-vkD.js";import{S as ce,a as le,b as ie,c as oe,d as de}from"./select-DGqIoF9r.js";import{W as J,w as Ie,ao as Ke,v as Ue,R as We,P as K,e as qe,S as Ge,L as U,s as Qe,y as ue,g as Y,ag as Xe,af as Ye,aY as Ze,a6 as De,a7 as es,ah as ss,ai as Z,a as ts,$ as as,a0 as rs}from"./icons-DTcdLw9j.js";import{C as ns}from"./CodeEditor-4JcGD1og.js";import{p as cs}from"./parse-BBzU4wsN.js";import{R as ls,a as is,u as os}from"./restart-overlay-B44c6hlE.js";import{g as ds}from"./installed-CHw5f9lL.js";import"./misc-BwRzHX8c.js";import"./radix-C-ZuImoP.js";import"./utils-DjBw3JGv.js";import"./progress-C6-hh8fF.js";import"./system-api-DeeJapvB.js";async function us(s){const r=await A(`/api/webui/plugins/config/${s}/schema`,{headers:L()}),a=await $(r);if(!a.success)return a;const n=a.data;return!n.success||!n.schema?{success:!1,error:n.message||"获取配置 Schema 失败"}:{success:!0,data:n.schema}}async function xs(s){const r=await A(`/api/webui/plugins/config/${s}`,{headers:L()}),a=await $(r);if(!a.success)return a;const n=a.data;return!n.success||!n.config?{success:!1,error:n.message||"获取配置失败"}:{success:!0,data:n.config}}async function ms(s){const r=await A(`/api/webui/plugins/config/${s}/raw`,{headers:L()}),a=await $(r);if(!a.success)return a;const n=a.data;return!n.success||!n.config?{success:!1,error:n.message||"获取配置失败"}:{success:!0,data:n.config}}async function hs(s,r){const a=await A(`/api/webui/plugins/config/${s}`,{method:"PUT",headers:L(),body:JSON.stringify({config:r})});return await $(a)}async function gs(s,r){const a=await A(`/api/webui/plugins/config/${s}/raw`,{method:"PUT",headers:L(),body:JSON.stringify({config:r})});return await $(a)}async function ps(s){const r=await A(`/api/webui/plugins/config/${s}/reset`,{method:"POST",headers:L()});return await $(r)}async function js(s){const r=await A(`/api/webui/plugins/config/${s}/toggle`,{method:"POST",headers:L()});return await $(r)}function fs({id:s,index:r,itemType:a,itemFields:n,value:u,onChange:c,onRemove:x,disabled:t,canRemove:d,placeholder:i}){const{attributes:y,listeners:j,setNodeRef:b,transform:f,transition:R,isDragging:S}=Je({id:s,disabled:t}),P={transform:He.Transform.toString(f),transition:R};return e.jsxs("div",{ref:b,style:P,className:I("flex items-start gap-2 group",S&&"opacity-50 z-50"),children:[e.jsx("button",{type:"button",className:I("flex-shrink-0 p-2 cursor-grab active:cursor-grabbing","text-muted-foreground hover:text-foreground transition-colors","opacity-0 group-hover:opacity-100 focus:opacity-100",t&&"cursor-not-allowed opacity-30"),...y,...j,children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1 min-w-0",children:a==="object"&&n?e.jsx(vs,{value:u,onChange:c,fields:n,disabled:t}):a==="number"?e.jsx(E,{type:"number",value:u??"",onChange:k=>c(parseFloat(k.target.value)||0),placeholder:i??`第 ${r+1} 项`,disabled:t,className:"font-mono"}):e.jsx(E,{type:"text",value:u??"",onChange:k=>c(k.target.value),placeholder:i??`第 ${r+1} 项`,disabled:t})}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",onClick:x,disabled:t||!d,className:I("flex-shrink-0 text-muted-foreground hover:text-destructive","opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"),children:e.jsx(Ue,{className:"h-4 w-4"})})]})}function vs({value:s,onChange:r,fields:a,disabled:n}){const u=m.useCallback((x,t)=>{r({...s,[x]:t})},[s,r]),c=(x,t)=>{const d=s?.[x];if(t.type==="boolean"||t.type==="switch")return e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(N,{className:"text-xs text-muted-foreground",children:t.label??x}),e.jsx(re,{checked:!!(d??t.default),onCheckedChange:i=>u(x,i),disabled:n})]});if(t.type==="slider"||t.type==="number"&&t.min!=null&&t.max!=null){const i=d??t.default??t.min??0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(N,{className:"text-xs text-muted-foreground",children:t.label??x}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i})]}),e.jsx(ne,{value:[i],onValueChange:y=>u(x,y[0]),min:t.min??0,max:t.max??100,step:t.step??1,disabled:n,className:"py-1"})]})}return t.type==="select"&&t.choices?e.jsxs("div",{className:"space-y-1",children:[e.jsx(N,{className:"text-xs text-muted-foreground",children:t.label??x}),e.jsxs(ce,{value:String(d??t.default??""),onValueChange:i=>u(x,i),disabled:n,children:[e.jsx(le,{className:"h-8 text-sm",children:e.jsx(ie,{placeholder:t.placeholder??"请选择"})}),e.jsx(oe,{children:t.choices.map(i=>e.jsx(de,{value:String(i),children:String(i)},String(i)))})]})]}):t.type==="number"?e.jsxs("div",{className:"space-y-1",children:[e.jsx(N,{className:"text-xs text-muted-foreground",children:t.label??x}),e.jsx(E,{type:"number",value:d??t.default??"",onChange:i=>u(x,parseFloat(i.target.value)||0),placeholder:t.placeholder,disabled:n,className:"h-8 text-sm"})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsx(N,{className:"text-xs text-muted-foreground",children:t.label??x}),e.jsx(E,{type:"text",value:d??t.default??"",onChange:i=>u(x,i.target.value),placeholder:t.placeholder,disabled:n,className:"h-8 text-sm"})]})};return e.jsx(F,{className:"p-3 space-y-2 bg-muted/30",children:Object.entries(a).map(([x,t])=>e.jsx("div",{children:c(x,t)},x))})}function ys({value:s,onChange:r,itemType:a="string",itemFields:n,minItems:u,maxItems:c,disabled:x,placeholder:t}){const d=m.useMemo(()=>Array.isArray(s)?s:typeof s=="string"&&s.trim()?s.split(",").map(h=>h.trim()):[],[s]),[i]=m.useState(()=>new Map),y=m.useCallback(h=>(i.has(h)||i.set(h,`item-${Date.now()}-${h}-${Math.random().toString(36).slice(2)}`),i.get(h)),[i]),j=m.useMemo(()=>{const h=[];for(let g=0;g<d.length;g++)h.push(y(g));return h},[d.length,y]),b=Ae(X(_e,{activationConstraint:{distance:8}}),X($e,{coordinateGetter:Le})),f=m.useCallback(h=>{const{active:g,over:l}=h;if(l&&g.id!==l.id){const p=j.indexOf(g.id),C=j.indexOf(l.id),T=Fe(d,p,C);r(T)}},[d,j,r]),R=m.useCallback(()=>{if(c!=null&&d.length>=c)return;let h;a==="object"&&n?h=Object.fromEntries(Object.entries(n).map(([g,l])=>[g,l.default??""])):a==="number"?h=0:h="",r([...d,h])},[d,c,a,n,r]),S=m.useCallback((h,g)=>{const l=[...d];l[h]=g,r(l)},[d,r]),P=m.useCallback(h=>{if(u!=null&&d.length<=u)return;const g=d.filter((l,p)=>p!==h);i.delete(h),r(g)},[d,u,i,r]),k=c==null||d.length<c,_=u==null||d.length>u;return e.jsxs("div",{className:"space-y-2",children:[d.length===0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4 justify-center border border-dashed rounded-md",children:[e.jsx(J,{className:"h-4 w-4"}),e.jsx("span",{children:"暂无数据,点击下方按钮添加"})]}):e.jsx(Me,{sensors:b,collisionDetection:ze,onDragEnd:f,children:e.jsx(Ve,{items:j,strategy:Be,children:e.jsx("div",{className:"space-y-2",children:d.map((h,g)=>e.jsx(fs,{id:j[g],index:g,itemType:a,itemFields:n,value:h,onChange:l=>S(g,l),onRemove:()=>P(g),disabled:x,canRemove:_,placeholder:t},j[g]))})})}),e.jsxs(v,{type:"button",variant:"outline",size:"sm",onClick:R,disabled:x||!k,className:"w-full",children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"}),"添加项目",c!==void 0&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",d.length,"/",c,")"]})]}),(u!=null||c!=null)&&(u!==null||c!==null)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:u!=null&&c!=null?`允许 ${u} - ${c} 项`:u!=null?`至少 ${u} 项`:`最多 ${c} 项`})]})}function Ns(s,r){const a=r.split(".").filter(Boolean);let n=s;for(const u of a){if(!n||typeof n!="object"||Array.isArray(n))return;n=n[u]}if(!(!n||typeof n!="object"||Array.isArray(n)))return n}function bs(s,r,a,n){const u=r.split(".").filter(Boolean),c={...s};let x=c,t=s;for(const d of u){const i=t?.[d],y=i&&typeof i=="object"&&!Array.isArray(i)?{...i}:{};x[d]=y,x=y,t=i&&typeof i=="object"&&!Array.isArray(i)?i:void 0}return x[a]=n,c}function ws({field:s,value:r,onChange:a}){const[n,u]=m.useState(!1);switch(s.ui_type){case"switch":return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(N,{children:s.label}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]}),e.jsx(re,{checked:!!(r??s.default),onCheckedChange:a,disabled:s.disabled})]});case"number":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsx(E,{type:"number",value:r??s.default,onChange:c=>a(parseFloat(c.target.value)||0),min:s.min,max:s.max,step:s.step??1,placeholder:s.placeholder,disabled:s.disabled}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});case"slider":return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(N,{children:s.label}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r??s.default})]}),e.jsx(ne,{value:[r??s.default],onValueChange:c=>a(c[0]),min:s.min??0,max:s.max??100,step:s.step??1,disabled:s.disabled}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});case"select":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsxs(ce,{value:String(r??s.default),onValueChange:a,disabled:s.disabled,children:[e.jsx(le,{children:e.jsx(ie,{placeholder:s.placeholder??"请选择"})}),e.jsx(oe,{children:s.choices?.map(c=>e.jsx(de,{value:String(c),children:String(c)},String(c)))})]}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});case"textarea":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsx(Te,{value:r??s.default,onChange:c=>a(c.target.value),placeholder:s.placeholder,rows:s.rows??3,disabled:s.disabled}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});case"password":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{type:n?"text":"password",value:r??"",onChange:c=>a(c.target.value),placeholder:s.placeholder,disabled:s.disabled,className:"pr-10"}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3",onClick:()=>u(!n),children:n?e.jsx(as,{className:"h-4 w-4"}):e.jsx(rs,{className:"h-4 w-4"})})]}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});case"list":return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsx(ys,{value:Array.isArray(r)?r:Array.isArray(s.default)?s.default:[],onChange:c=>a(c),itemType:s.item_type??"string",itemFields:s.item_fields,minItems:s.min_items,maxItems:s.max_items,disabled:s.disabled,placeholder:s.placeholder}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]});default:return e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{children:s.label}),e.jsx(E,{type:"text",value:r??s.default??"",onChange:c=>a(c.target.value),placeholder:s.placeholder,maxLength:s.max_length,disabled:s.disabled}),s.hint&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.hint})]})}}function D({section:s,config:r,onChange:a}){const[n,u]=m.useState(!s.collapsed),c=Ns(r,s.name),x=Object.entries(s.fields).filter(([,t])=>!t.hidden).sort(([,t],[,d])=>t.order-d.order);return e.jsx(Oe,{open:n,onOpenChange:u,children:e.jsxs(F,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(se,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n?e.jsx(ts,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(ue,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(te,{className:"text-lg",children:s.title})]}),e.jsxs(B,{variant:"secondary",className:"text-xs",children:[x.length," 项"]})]}),s.description&&e.jsx(ae,{className:"ml-6",children:s.description})]})}),e.jsx(Ee,{children:e.jsx(V,{className:"space-y-4 pt-0",children:x.map(([t,d])=>e.jsx(ws,{field:d,value:c?.[t],onChange:i=>a(s.name,t,i),sectionName:s.name},t))})})]})})}function Cs({plugin:s,onBack:r}){const{toast:a}=ee(),{triggerRestart:n,isRestarting:u}=os(),[c,x]=m.useState("visual"),[t,d]=m.useState(null),[i,y]=m.useState({}),[j,b]=m.useState({}),[f,R]=m.useState(""),[S,P]=m.useState(""),[k,_]=m.useState(!0),[h,g]=m.useState(!1),[l,p]=m.useState(!1),[C,T]=m.useState(!1),[xe,M]=m.useState(!1),z=m.useCallback(async()=>{_(!0);try{const[o,w,O]=await Promise.all([us(s.id),xs(s.id),ms(s.id)]);if(!o.success){a({title:"加载配置架构失败",description:o.error,variant:"destructive"});return}if(!w.success){a({title:"加载配置数据失败",description:w.error,variant:"destructive"});return}if(!O.success){a({title:"加载原始配置失败",description:O.error,variant:"destructive"});return}d(o.data),y(w.data),b(JSON.parse(JSON.stringify(w.data))),R(O.data),P(O.data)}catch(o){a({title:"加载配置失败",description:o instanceof Error?o.message:"未知错误",variant:"destructive"})}finally{_(!1)}},[s.id,a]);m.useEffect(()=>{z()},[z]),m.useEffect(()=>{p(c==="visual"?JSON.stringify(i)!==JSON.stringify(j):f!==S)},[i,j,f,S,c]);const W=(o,w,O)=>{y(je=>bs(je,o,w,O))},me=async()=>{g(!0);try{if(c==="source"){try{cs(f)}catch(o){T(!0),a({title:"TOML 格式错误",description:o instanceof Error?o.message:"无法解析 TOML 配置,请检查语法",variant:"destructive"}),g(!1);return}await gs(s.id,f),P(f),T(!1)}else await hs(s.id,i),b(JSON.parse(JSON.stringify(i)));a({title:"配置已保存",description:"更改将在插件重新加载后生效"})}catch(o){a({title:"保存失败",description:o instanceof Error?o.message:"未知错误",variant:"destructive"})}finally{g(!1)}},he=async()=>{try{const o=await ps(s.id);if(!o.success){a({title:"重置失败",description:o.error,variant:"destructive"});return}a({title:"配置已重置",description:"下次加载插件时将使用默认配置"}),M(!1),z()}catch(o){a({title:"重置失败",description:o instanceof Error?o.message:"未知错误",variant:"destructive"})}},ge=async()=>{try{const o=await js(s.id);if(!o.success){a({title:"切换失败",description:o.error,variant:"destructive"});return}a({title:o.data.message,description:o.data.note}),z()}catch(o){a({title:"切换状态失败",description:o instanceof Error?o.message:"未知错误",variant:"destructive"})}};if(k)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(U,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!t)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 space-y-4",children:[e.jsx(J,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"无法加载配置"}),e.jsxs(v,{onClick:r,variant:"outline",children:[e.jsx(Y,{className:"h-4 w-4 mr-2"}),"返回"]})]});const pe=Object.values(t.sections).sort((o,w)=>o.order-w.order),H=i.plugin?.enabled!==!1;return e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(v,{variant:"ghost",size:"icon",onClick:r,children:e.jsx(Y,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:t.plugin_info.name||s.manifest.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(B,{variant:H?"default":"secondary",children:H?"已启用":"已禁用"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",t.plugin_info.version||s.manifest.version]})]})]})]}),e.jsxs("div",{className:"flex gap-2 ml-10 sm:ml-0",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:()=>x(c==="visual"?"source":"visual"),children:c==="visual"?e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"h-4 w-4 mr-2"}),"源代码"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"可视化"]})}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>n(),disabled:u,children:[e.jsx(Ze,{className:`h-4 w-4 mr-2 ${u?"animate-spin":""}`}),"重启麦麦"]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:ge,children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),H?"禁用":"启用"]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>M(!0),children:[e.jsx(es,{className:"h-4 w-4 mr-2"}),"重置"]}),e.jsxs(v,{size:"sm",onClick:me,disabled:!l||h,children:[h?e.jsx(U,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ss,{className:"h-4 w-4 mr-2"}),"保存"]})]})]}),l&&e.jsx(F,{className:"border-orange-200 bg-orange-50 dark:bg-orange-950/20 dark:border-orange-900",children:e.jsx(V,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-4 w-4 text-orange-600"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"有未保存的更改"})]})})}),c==="source"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(G,{children:[e.jsx(J,{className:"h-4 w-4"}),e.jsxs(Q,{children:[e.jsx("strong",{children:"源代码模式(高级功能):"}),"直接编辑 TOML 配置文件。保存时会验证格式,只有格式正确才能保存。",C&&e.jsx("span",{className:"text-destructive font-semibold ml-2",children:"⚠️ 上次保存失败,请检查 TOML 格式"})]})]}),e.jsx(ns,{value:f,onChange:o=>{R(o),C&&T(!1)},language:"toml",height:"calc(100vh - 350px)",minHeight:"500px",placeholder:"TOML 配置内容"})]}),c==="visual"&&e.jsxs(e.Fragment,{children:[e.jsxs(G,{children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsxs(Q,{children:[e.jsx("strong",{children:"提示:"}),"如果插件当前未加载或未启用,WebUI 适配器的高级插件可视化编辑功能可能会不可用。 请确保插件已启用并成功加载后,再进行配置编辑。"]})]}),t.layout.type==="tabs"&&t.layout.tabs.length>0?e.jsxs(fe,{defaultValue:t.layout.tabs[0]?.id,children:[e.jsx(ve,{children:t.layout.tabs.map(o=>e.jsxs(ye,{value:o.id,children:[o.title,o.badge&&e.jsx(B,{variant:"secondary",className:"ml-2 text-xs",children:o.badge})]},o.id))}),t.layout.tabs.map(o=>e.jsx(Ne,{value:o.id,className:"space-y-4 mt-4",children:o.sections.map(w=>{const O=t.sections[w];return O?e.jsx(D,{section:O,config:i,onChange:W},w):null})},o.id))]}):e.jsx("div",{className:"space-y-4",children:pe.map(o=>e.jsx(D,{section:o,config:i,onChange:W},o.name))})]}),e.jsx(be,{open:xe,onOpenChange:M,children:e.jsxs(we,{children:[e.jsxs(Ce,{children:[e.jsx(Se,{children:"确认重置配置"}),e.jsx(Pe,{children:"这将删除当前配置文件,下次加载插件时将使用默认配置。此操作不可撤销。"})]}),e.jsxs(ke,{children:[e.jsx(v,{variant:"outline",onClick:()=>M(!1),children:"取消"}),e.jsx(v,{variant:"destructive",onClick:he,children:"确认重置"})]})]})})]})}function Ks(){return e.jsx(ls,{children:e.jsx(Ss,{})})}function Ss(){const{toast:s}=ee(),[r,a]=m.useState([]),[n,u]=m.useState(!0),[c,x]=m.useState(""),[t,d]=m.useState(null),i=async()=>{u(!0);try{const l=await ds();if(!l.success){s({title:"加载插件列表失败",description:l.error,variant:"destructive"});return}a(l.data)}catch(l){s({title:"加载插件列表失败",description:l instanceof Error?l.message:"未知错误",variant:"destructive"})}finally{u(!1)}};m.useEffect(()=>{i()},[]);const j=r.filter(l=>{const p=c.toLowerCase();return l.id.toLowerCase().includes(p)||l.manifest.name.toLowerCase().includes(p)||l.manifest.description?.toLowerCase().includes(p)}).filter((l,p,C)=>p===C.findIndex(T=>T.id===l.id)),b=l=>l.disabled===!0||l.enabled===!1,f=l=>!b(l)&&(l.load_status==="success"||l.loaded===!0),R=l=>!b(l)&&!f(l),S=r.length,P=r.filter(b).length,k=S-P,_=r.filter(f).length,h=r.filter(R).length,g=l=>b(l)?{dotClassName:"bg-muted-foreground/45",label:"已禁用"}:f(l)?{dotClassName:"bg-emerald-500 shadow-[0_0_0_3px_rgba(16,185,129,0.16)]",label:"加载成功"}:{dotClassName:"bg-red-500 shadow-[0_0_0_3px_rgba(239,68,68,0.16)]",label:"加载失败"};return t?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-full",children:e.jsx("div",{className:"p-4 sm:p-6",children:e.jsx(Cs,{plugin:t,onBack:()=>d(null)})})}),e.jsx(is,{})]}):e.jsx(q,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"插件配置"}),e.jsx("p",{className:"text-muted-foreground mt-1 sm:mt-2 text-sm sm:text-base",children:"管理和配置已安装的插件"})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:i,children:[e.jsx(We,{className:`h-4 w-4 mr-2 ${n?"animate-spin":""}`}),"刷新"]})]}),e.jsx(F,{children:e.jsxs(V,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-2 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-4 w-4 text-muted-foreground"}),"已安装 ",e.jsx("strong",{children:S})," 个插件"]}),e.jsxs("span",{children:["已启用 ",e.jsx("strong",{className:"text-emerald-600",children:k})," 个"]}),e.jsxs("span",{children:["已禁用 ",e.jsx("strong",{className:"text-muted-foreground",children:P})," 个"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-2 border-t pt-3 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4 text-emerald-600"}),"加载成功 ",e.jsx("strong",{className:"text-emerald-600",children:_})," 个"]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"h-4 w-4 text-red-600"}),"加载失败 ",e.jsx("strong",{className:"text-red-600",children:h})," 个"]})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ge,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"搜索插件...",value:c,onChange:l=>x(l.target.value),className:"pl-9"})]}),e.jsxs(F,{children:[e.jsxs(se,{children:[e.jsx(te,{children:"已安装的插件"}),e.jsx(ae,{children:"点击插件查看和编辑配置"})]}),e.jsx(V,{children:n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(U,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 space-y-4",children:[e.jsx(K,{className:"h-16 w-16 text-muted-foreground/50"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-lg font-medium text-muted-foreground",children:c?"没有找到匹配的插件":"暂无已安装的插件"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c?"尝试其他搜索关键词":"前往插件市场安装插件"})]})]}):e.jsx("div",{className:"space-y-2",children:j.map(l=>{const p=g(l);return e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 cursor-pointer transition-colors ${b(l)?"opacity-70":""}`,role:"button",tabIndex:0,onClick:()=>d(l),onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),d(l))},children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full flex-shrink-0 ${p.dotClassName}`,title:p.label,"aria-label":p.label}),e.jsx("div",{className:"h-10 w-10 rounded-lg bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(K,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-medium truncate",children:l.manifest.name}),e.jsxs(B,{variant:"secondary",className:"text-xs flex-shrink-0",children:["v",l.manifest.version]})]}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:l.manifest.description||"暂无描述"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(v,{variant:"ghost",size:"sm",children:e.jsx(Qe,{className:"h-4 w-4"})}),e.jsx(ue,{className:"h-4 w-4 text-muted-foreground"})]})]},l.id)})})})]})]})})}export{Ks as PluginConfigPage};
|