|
1 | | -import { $, component$, useSignal } from '@builder.io/qwik'; |
| 1 | +import { $, component$, createSignal, useSignal } from '@builder.io/qwik'; |
2 | 2 | import { CodeBlock } from '../components/code-block/code-block'; |
3 | 3 | import type { ReplModuleOutput } from './types'; |
4 | 4 | const FILE_MODULE_DIV_ID = 'file-modules-client-modules'; |
@@ -35,22 +35,34 @@ export const ReplOutputModules = component$(({ outputs, headerText }: ReplOutput |
35 | 35 | </div> |
36 | 36 | </div> |
37 | 37 | <div class="file-modules" id={FILE_MODULE_DIV_ID}> |
38 | | - {outputs.map((o, i) => ( |
39 | | - <div class="file-item" data-output-item={i} key={o.path}> |
40 | | - <div class="file-info"> |
41 | | - <span>{o.path}</span> |
42 | | - {o.size ? <span class="file-size">({o.size})</span> : null} |
| 38 | + {outputs.map((o, i) => { |
| 39 | + const isLarge = o.code.length > 3000; |
| 40 | + if (isLarge && !o.shorten) { |
| 41 | + o.shorten = createSignal(true); |
| 42 | + } |
| 43 | + const code = o.shorten?.value ? o.code.slice(0, 3000) : o.code; |
| 44 | + return ( |
| 45 | + <div class="file-item" data-output-item={i} key={o.path}> |
| 46 | + <div class="file-info"> |
| 47 | + <span>{o.path}</span> |
| 48 | + {o.size ? <span class="file-size">({o.size})</span> : null} |
| 49 | + </div> |
| 50 | + <div class="file-text"> |
| 51 | + <CodeBlock |
| 52 | + pathInView$={pathInView$} |
| 53 | + path={o.path} |
| 54 | + code={code} |
| 55 | + observerRootId={FILE_MODULE_DIV_ID} |
| 56 | + /> |
| 57 | + {o.shorten && ( |
| 58 | + <button onClick$={() => (o.shorten.value = !o.shorten.value)}> |
| 59 | + {o.shorten.value ? 'Truncated - show more' : 'Show less'} |
| 60 | + </button> |
| 61 | + )} |
| 62 | + </div> |
43 | 63 | </div> |
44 | | - <div class="file-text"> |
45 | | - <CodeBlock |
46 | | - pathInView$={pathInView$} |
47 | | - path={o.path} |
48 | | - code={o.code} |
49 | | - observerRootId={FILE_MODULE_DIV_ID} |
50 | | - /> |
51 | | - </div> |
52 | | - </div> |
53 | | - ))} |
| 64 | + ); |
| 65 | + })} |
54 | 66 | </div> |
55 | 67 | </div> |
56 | 68 | ); |
|
0 commit comments