UNPKG

@techdocs/cli

Version:

Utility CLI for managing TechDocs sites in Backstage.

4 lines (3 loc) • 10.1 kB
"use strict";(()=>{(self.webpackChunktechdocs_cli_embedded_app=self.webpackChunktechdocs_cli_embedded_app||[]).push([[9234],{99234:(Ce,I,c)=>{c.r(I),c.d(I,{RealLogViewer:()=>ke});var d=c(31085),v=c(10394),A=c(29365),G=c(99594),$=c(53373),b=c.n($),f=c(14041),Y=c(18690),X=c(19686),B=c(84392),w=c(84774);const R=(0,w.A)(),F=/\n\r?/g,Z=Object.fromEntries(Object.entries({1:e=>({...e,bold:!0}),3:e=>({...e,italic:!0}),4:e=>({...e,underline:!0}),22:({bold:e,...t})=>t,23:({italic:e,...t})=>t,24:({underline:e,...t})=>t,30:e=>({...e,foreground:"black"}),31:e=>({...e,foreground:"red"}),32:e=>({...e,foreground:"green"}),33:e=>({...e,foreground:"yellow"}),34:e=>({...e,foreground:"blue"}),35:e=>({...e,foreground:"magenta"}),36:e=>({...e,foreground:"cyan"}),37:e=>({...e,foreground:"white"}),39:({foreground:e,...t})=>t,90:e=>({...e,foreground:"grey"}),40:e=>({...e,background:"black"}),41:e=>({...e,background:"red"}),42:e=>({...e,background:"green"}),43:e=>({...e,background:"yellow"}),44:e=>({...e,background:"blue"}),45:e=>({...e,background:"magenta"}),46:e=>({...e,background:"cyan"}),47:e=>({...e,background:"white"}),49:({background:e,...t})=>t}).map(([e,t])=>[`\x1B[${e}m`,t]));class C{lineNumber;chunks;text;constructor(t=1,n=[]){this.lineNumber=t,this.chunks=n,this.text=n.map(r=>r.text).join("").toLocaleLowerCase("en-US")}lastChunk(){return this.chunks[this.chunks.length-1]}replaceLastChunk(t){t&&(this.chunks.splice(this.chunks.length-1,1,...t),this.text=this.chunks.map(n=>n.text).join("").toLocaleLowerCase("en-US"))}}class J{text="";lines=[];process(t){if(this.text===t)return this.lines;if(this.text&&t.startsWith(this.text)){const n=this.lines.length>0?this.lines.length-1:0,r=this.lines[n]??new C,o=r.lastChunk(),l=this.processLines((o?.text??"")+t.slice(this.text.length),o?.modifiers,r?.lineNumber);r.replaceLastChunk(l[0]?.chunks),this.lines[n]=r,this.lines=this.lines.concat(l.slice(1))}else this.lines=this.processLines(t);return this.text=t,this.lines}processLines=(t,n={},r=1)=>{const o=[];let l=n,i=r,u=0;for(F.lastIndex=0;;){const s=F.exec(t);if(!s){const x=this.processText(t.slice(u),l);return o.push(new C(i,x)),o}const h=t.slice(u,s.index);u=s.index+s[0].length;const a=this.processText(h,l);o.push(new C(i,a)),l=a[a.length-1].modifiers??l,i+=1}};processText=(t,n)=>{const r=[];let o=n,l=0;for(R.lastIndex=0;;){const i=R.exec(t);if(!i)return r.push({text:t.slice(l),modifiers:o}),r;const u=t.slice(l,i.index);r.push({text:u,modifiers:o}),l=i.index+i[0].length,o=this.processCode(i[0],o)}};processCode=(t,n)=>Z[t]?.(n)??n}var Q=c(95479),M=c.n(Q),q=c(37639),_=c(72072);function ee(e,t){const n=new Array;if(t.bold&&n.push(e.modifierBold),t.italic&&n.push(e.modifierItalic),t.underline&&n.push(e.modifierUnderline),t.foreground){const r=`modifierForeground${M()(t.foreground)}`;n.push(e[r])}if(t.background){const r=`modifierBackground${M()(t.background)}`;n.push(e[r])}return n.length>0?n.join(" "):void 0}function te(e,t){if(!t||!e.includes(t))return;const n=new Array;let r=0;for(;;){const o=e.indexOf(t,r);if(o===-1)break;const l=o+t.length;n.push({start:o,end:l}),r=l}return n}function ne(e,t){const n=te(e.text,t);if(!n)return e.chunks;const r=new Array;let o=0,l=0,i=n[l];for(const u of e.chunks){const{text:s,modifiers:h}=u;if(!i||o+s.length<i.start){r.push(u),o+=s.length;continue}let a=0;for(;i;){const p=Math.max(i.start-o,0);if(p>s.length)break;const g=Math.min(i.end-o,s.length);if(p>a&&r.push({text:s.slice(a,p),modifiers:h}),g>p&&r.push({modifiers:h,highlight:l,text:s.slice(p,g)}),a=g,i.end-o===g)l+=1,i=n[l];else break}a<s.length&&r.push({text:s.slice(a),modifiers:h}),o+=s.length}return r}const se=({attributes:e,content:t})=>{const{href:n,...r}=e;return(0,d.jsx)(_.N_,{to:n,...r,children:t})};function oe({line:e,classes:t,searchText:n,highlightResultIndex:r,setRowHeight:o}){const l=(0,f.useRef)(null),i=(0,f.useMemo)(()=>ne(e,n),[e,n]);(0,f.useEffect)(()=>{l.current&&o&&o(e.lineNumber,l.current.offsetHeight)},[e.lineNumber,o]);const u=(0,f.useMemo)(()=>i.map(({text:s,modifiers:h,highlight:a},x)=>(0,d.jsx)("span",{className:b()(ee(t,h),a!==void 0&&(a===r?t.textSelectedHighlight:t.textHighlight),{[t.textWrap]:!!o}),children:(0,d.jsx)(q.A,{options:{render:se},children:s})},x)),[i,r,t,o]);return(0,d.jsx)("span",{ref:l,children:u})}var re=c(16249),ie=c(72501),le=c(68887),ce=c(63798),N=c(65859);function ae(e){const{resultCount:t,resultIndexStep:n,toggleShouldFilter:r}=e,o=e.resultIndex??0,l=i=>{i.key==="Enter"&&(i.metaKey||i.ctrlKey||i.altKey?r():n(i.shiftKey))};return(0,d.jsxs)(d.Fragment,{children:[t!==void 0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(A.A,{size:"small",onClick:()=>n(!0),children:(0,d.jsx)(le.A,{})}),(0,d.jsxs)(ie.A,{children:[Math.min(o+1,t),"/",t]}),(0,d.jsx)(A.A,{size:"small",onClick:()=>n(),children:(0,d.jsx)(ce.A,{})})]}),(0,d.jsx)(re.A,{size:"small",variant:"standard",placeholder:"Search",value:e.searchInput,onKeyPress:l,onChange:i=>e.setSearchInput(i.target.value)}),(0,d.jsx)(A.A,{size:"small",onClick:r,children:e.shouldFilter?(0,d.jsx)(N.A,{color:"primary"}):(0,d.jsx)(N.A,{color:"disabled"})})]})}var de=c(58837),T=c(268),S=c(95186),z=c(38084),E=c(54024),W=c(40935),K=c(4499),H=c(85229),O=c(42020),V=c(6456);const P=40,ue=(0,de.A)(e=>({root:{background:e.palette.background.paper},header:{height:P,display:"flex",alignItems:"center",justifyContent:"flex-end"},log:{fontFamily:'"Monaco", monospace',fontSize:e.typography.pxToRem(12),lineHeight:"20px"},line:{position:"relative",whiteSpace:"pre",display:"flex",alignItems:"flex-start","&:hover":{background:e.palette.action.hover}},lineSelected:{background:e.palette.action.selected,"&:hover":{background:e.palette.action.selected}},lineCopyButton:{position:"absolute",paddingTop:0,paddingBottom:0},lineNumber:{display:"inline-block",textAlign:"end",width:60,marginRight:e.spacing(1),cursor:"pointer",flexShrink:0},textHighlight:{background:(0,T.X4)(e.palette.info.main,.15)},textSelectedHighlight:{background:(0,T.X4)(e.palette.info.main,.4)},modifierBold:{fontWeight:e.typography.fontWeightBold},modifierItalic:{fontStyle:"italic"},modifierUnderline:{textDecoration:"underline"},modifierForegroundBlack:{color:S.A.black},modifierForegroundRed:{color:z.A[500]},modifierForegroundGreen:{color:E.A[500]},modifierForegroundYellow:{color:W.A[500]},modifierForegroundBlue:{color:K.A[500]},modifierForegroundMagenta:{color:H.A[500]},modifierForegroundCyan:{color:O.A[500]},modifierForegroundWhite:{color:S.A.white},modifierForegroundGrey:{color:V.A[500]},modifierBackgroundBlack:{background:S.A.black},modifierBackgroundRed:{background:z.A[500]},modifierBackgroundGreen:{background:E.A[500]},modifierBackgroundYellow:{background:W.A[500]},modifierBackgroundBlue:{background:K.A[500]},modifierBackgroundMagenta:{background:H.A[500]},modifierBackgroundCyan:{background:O.A[500]},modifierBackgroundWhite:{background:S.A.white},modifierBackgroundGrey:{background:V.A[500]},textWrap:{whiteSpace:"pre-wrap",wordBreak:"break-all"}}),{name:"BackstageLogViewer"});var he=c(42);function fe(e,t){if(!t)return{lines:e};const n=[],r=[];for(const o of e)if(o.text.includes(t)){n.push(o);let l=0,i=0;for(;;){const u=o.text.indexOf(t,l);if(u===-1)break;r.push({lineNumber:o.lineNumber,lineIndex:i++}),l=u+t.length}}return{lines:n,results:r}}function ge(e){const[t,n]=(0,f.useState)(""),r=t.toLocaleLowerCase("en-US"),[o,l]=(0,f.useState)(0),[i,u]=(0,he.e)(!1),s=(0,f.useMemo)(()=>fe(e,r),[e,r]),h=s.results?s.results[Math.min(o,s.results.length-1)]:void 0,a=s.results?.length,x=p=>{if(p){if(a!==void 0){const g=Math.min(o-1,a-2);l(g<0?a-1:g)}}else if(a!==void 0){const g=o+1;l(g>=a?0:g)}};return{lines:i?s.lines:e,searchText:r,searchInput:t,setSearchInput:n,shouldFilter:i,toggleShouldFilter:u,resultCount:a,resultIndex:o,resultIndexStep:x,resultLine:h?.lineNumber,resultLineIndex:h?.lineIndex}}var me=c(72427),xe=c(39837),pe=c(36338);function ye(e){const t=(0,me.gf)(xe.m),[n,r]=(0,f.useState)(),o=n?Math.min(n.start,n.end):void 0,l=n?Math.max(n.start,n.end):void 0,[{error:i},u]=(0,pe.A)();return(0,f.useEffect)(()=>{i&&t.post(i)},[i,t]),{shouldShowButton(s){return o===s||l===s},isSelected(s){return n?o<=s&&s<=l:!1},setSelection(s,h){r(h?a=>a?{start:a.start,end:s}:{start:s,end:s}:a=>a?.start===s&&a?.end===s?void 0:{start:s,end:s})},copySelection(){if(n){const s=e.slice(Math.min(n.start,n.end)-1,Math.max(n.start,n.end)).map(h=>h.chunks.map(a=>a.text).join("")).join(` `);u(s),r(void 0)}}}}function ke(e){const t=ue({classes:e.classes}),[n,r]=(0,f.useState)(null),o=e.textWrap??!1,l=(0,f.useRef)({}),u=(0,f.useMemo)(()=>new J,[]).process(e.text),s=ge(u),h=ye(u),a=(0,Y.zy)();(0,f.useEffect)(()=>{n&&n.scrollToItem(u.length-1,"end")},[n,u]),(0,f.useEffect)(()=>{n&&(s.resultLine?n.scrollToItem(s.resultLine-1,"center"):n.scrollToItem(u.length-1,"end"))},[n,s.resultLine,u]),(0,f.useEffect)(()=>{if(a.hash){const m=parseInt(a.hash.replace(/\D/g,""),10);h.setSelection(m,!1)}},[]);const x=(m,y)=>{h.setSelection(m,y.shiftKey)};function p(m,y){o&&n&&(n.resetAfterIndex(0),l.current[m-1]=y)}function g(m){return l.current[m]||20}return(0,d.jsx)(X.Ay,{children:({height:m,width:y})=>{const L={ref:r,className:t.log,height:(m||480)-P,width:y||640,itemData:s.lines,itemCount:s.lines.length},U=({index:Ae,style:Se,data:ve})=>{const D=ve[Ae],{lineNumber:k}=D;return(0,d.jsxs)(v.A,{style:{...Se},className:b()(t.line,{[t.lineSelected]:h.isSelected(k)}),children:[h.shouldShowButton(k)&&(0,d.jsx)(A.A,{"data-testid":"copy-button",size:"small",className:t.lineCopyButton,onClick:()=>h.copySelection(),children:(0,d.jsx)(G.A,{fontSize:"inherit"})}),(0,d.jsx)("a",{role:"row",target:"_self",href:`#line-${k}`,className:t.lineNumber,onClick:j=>x(k,j),onKeyPress:j=>x(k,j),children:k}),(0,d.jsx)(oe,{setRowHeight:o?p:void 0,line:D,classes:t,searchText:s.searchText,highlightResultIndex:s.resultLine===k?s.resultLineIndex:void 0})]})};return(0,d.jsxs)(v.A,{style:{width:y,height:m},className:t.root,children:[(0,d.jsx)(v.A,{className:t.header,children:(0,d.jsx)(ae,{...s})}),o?(0,d.jsx)(B._m,{...L,itemSize:g,children:U}):(0,d.jsx)(B.Y1,{...L,itemSize:20,children:U})]})}})}}}]);})(); //# sourceMappingURL=9234.a1d6ef55.chunk.js.map