UNPKG

@lobehub/cli-ui

Version:
2 lines (1 loc) 5.32 kB
var _=Object.defineProperty;var h=(o,e)=>_(o,"name",{value:e,configurable:!0});import{consola as D}from"consola";import L from"node:process";import{jsx as t,jsxs as A}from"react/jsx-runtime";import{Box as y,Text as T,useInput as z,useApp as G,render as J}from"ink";import{memo as I,useState as k,useRef as K,useEffect as M,useCallback as X,useMemo as j,createElement as O}from"react";import N from"arr-rotate";import Y from"fast-deep-equal";import Z from"figures";import{Badge as V,extendTheme as H,defaultTheme as ee,ThemeProvider as oe}from"@inkjs/ui";var re={error:h((o,e)=>{D.error(o),e&&L.exit(1)},"error"),info:h((o,e)=>{D.info(o),e&&L.exit(0)},"info"),success:h((o,e)=>{D.success(o),e&&L.exit(0)},"success"),warn:h((o,e)=>{D.warn(o),e&&L.exit(0)},"warn")};const te={blue:"#8ae8ff",cyan:"#95f3d9",geekblue:"#369eff",gold:"#ffcb47",gray:"#777777",green:"#55b467",lime:"#c4f042",magenta:"#e34ba9",orange:"#ff802b",pink:"#eb2f96",purple:"#bd54c6",red:"#f04f88",volcano:"#ec5e41",yellow:"#ffef5c"},ce={colorError:"red",colorInfo:"blue",colorPrimary:"cyan",colorSuccess:"green",colorWarning:"yellow"};var ne={colorBgContainer:"#111111",colorBgElevated:"#222222",colorBgLayout:"#000000",colorBgSpotlight:"#444444",colorBorder:"#333333",colorBorderSecondary:"#2d2d2d",colorText:"#ffffff",colorTextDescription:"#6f6f6f",colorTextPlaceholder:"#555555",colorTextQuaternary:"#555555",colorTextSecondary:"#aaaaaa",colorTextTertiary:"#6f6f6f",...ce,...te};const S=h(()=>ne,"useTheme"),U=I(({show:o=!0,children:e,footer:n,reverse:r=!1,header:l,headerConfig:s,footerConfig:x,bodyConfig:a,title:d,...v})=>{const c=S();if(!o)return;const f=(d||l)&&t(y,{borderColor:c.colorBorder,borderLeft:!1,borderRight:!1,borderStyle:"bold",borderTop:!1,flexDirection:"row",justifyContent:"center",paddingLeft:1,paddingRight:1,...s,children:d?t(T,{bold:!0,children:d.toUpperCase()}):l}),m=t(y,{flexDirection:"column",paddingLeft:1,paddingRight:1,...a,children:e}),i=n&&t(y,{borderBottom:r,borderColor:c.colorBorder,borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:!r,flexDirection:"row",paddingLeft:1,paddingRight:1,...x,children:n});return A(y,{alignItems:"stretch",borderColor:c.colorBorder,borderStyle:"bold",flexDirection:"column",...v,children:[f,r?i:m,r?m:i]})}),le=I(({highlightColor:o,isSelected:e=!1})=>t(y,{marginRight:1,children:e?t(T,{color:o,children:Z.pointer}):t(T,{children:" "})})),se=I(({highlightColor:o,isSelected:e=!1,label:n})=>t(T,{color:e?o:void 0,children:n})),$=I(({highlightColor:o,items:e=[],isFocused:n=!0,initialIndex:r=0,indicatorComponent:l=le,itemComponent:s=se,limit:x,onSelect:a,onHighlight:d})=>{const v=S(),c=typeof x=="number"&&e.length>x,f=c?Math.min(x,e.length):e.length,m=f-1,[i,u]=k(r>m?m-r:0),[p,B]=k(r?r>m?m:r:0),F=K(e);M(()=>{Y(F.current.map(g=>g.value),e.map(g=>g.value))||(u(0),B(0)),F.current=e},[e]),z(X((g,C)=>{if(C.upArrow){const b=(c?f:e.length)-1,R=p===0,E=c?p:b,w=R?i+1:i,P=R?E:p-1;u(w),B(P);const W=c?N(e,w).slice(0,f):e;typeof d=="function"&&d(W[P])}if(C.downArrow){const b=p===(c?f:e.length)-1,R=c?p:0,E=b?i-1:i,w=b?R:p+1;u(E),B(w);const P=c?N(e,E).slice(0,f):e;typeof d=="function"&&d(P[w])}if(C.return){const b=c?N(e,i).slice(0,f):e;typeof a=="function"&&a(b[p])}},[c,f,i,p,e,a,d]),{isActive:n});const Q=j(()=>c?N(e,i).slice(0,f):e,[c,i,f]);return t(y,{flexDirection:"column",children:Q.map((g,C)=>{const b=C===p;return A(y,{children:[O(l,{highlightColor:o??v.colorPrimary,isSelected:b}),O(s,{...g,highlightColor:o??v.colorPrimary,isSelected:b})]},g.key??g.value)})})}),de=I(({maxLength:o=30,defaultValue:e,label:n,showValue:r=!0,value:l})=>{const s=S(),x=j(()=>n+Array.from({length:o-n.length}).fill("").join(" "),[n,o]),a=j(()=>e===l,[e,l]);return A(T,{children:[x,e?t(V,{color:a?s.colorText:s.colorInfo,children:r?l:a?"DEFAULT":"CUSTOM"}):t(V,{color:a?s.colorError:s.colorSuccess,children:r?l:a?"UNSET":"SET"})]})}),ae=I(({active:o,setActive:e,maxLength:n=30,show:r=!0,items:l,logo:s,title:x,...a})=>{const[d,v]=k(),c=S(),{exit:f}=G(),m=j(()=>[...l.map(u=>({label:t(de,{defaultValue:u.defaultValue,label:u.label,maxLength:n,showValue:u.showValue,value:u.value}),value:u.key})),{label:"Exit",value:"exit"}],[l]),i=h(u=>{u.value==="exit"&&f();const p=l.find(B=>B.key===u.value);p&&(v(p),e?.(u.value))},"handleSelect");if(r)return o&&d?t(U,{footer:d.desc&&A(T,{color:c.colorTextDescription,children:[t(T,{bold:!0,children:"\u{1F449}NOTE: "}),d.desc]}),title:[s,d.label].filter(Boolean).join(" "),...a,children:d.children}):t(U,{show:!o,title:[s,x].filter(Boolean).join(" "),...a,children:t($,{items:m,onSelect:i})})}),q=I(({children:o})=>{const e=S();M(()=>{},[]);const n=H(ee,{components:{Select:{styles:{focusIndicator:h(()=>({color:e.colorInfo}),"focusIndicator"),label({isFocused:r,isSelected:l}){let s;return l?s=e.colorSuccess:r&&(s=e.colorPrimary),{color:s}},selectedIndicator:h(()=>({color:e.colorPrimary}),"selectedIndicator")}}}});return t(oe,{theme:n,children:o})}),fe=h(o=>J(t(q,{children:o})),"render"),ie=I(({children:o,direction:e="top",...n})=>{const r=S();return t(y,{borderBottom:e!=="top",borderColor:r.colorBorder,borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:e==="top",flexDirection:"column",...n,children:o})});export{ae as ConfigPanel,U as Panel,$ as SelectInput,ie as SplitView,q as ThemeProvider,re as alert,fe as render,S as useTheme};