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