File tree Expand file tree Collapse file tree
src/lib/components/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232
3333 export let open = false ;
3434 export let className = ' ' ;
35+
36+ const RESULT_PREVIEW_LIMIT = 10000 ;
37+ let expandedResult = false ;
38+
39+ $ : if (! open ) expandedResult = false ;
3540 export let buttonClassName =
3641 ' w-fit text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition' ;
3742
216221 content ={` \`\`\` json\n ${JSON .stringify (parsedResult , null , 2 )}\n\`\`\` ` }
217222 />
218223 {:else }
224+ {@const resultStr = String (parsedResult )}
225+ {@const isTruncated = resultStr .length > RESULT_PREVIEW_LIMIT && ! expandedResult }
219226 <pre
220- class ="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono" >{String (
221- parsedResult
222- )}</pre >
227+ class ="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono" >{isTruncated ? resultStr .slice (0 , RESULT_PREVIEW_LIMIT ) : resultStr }</pre >
228+ {#if isTruncated }
229+ <button
230+ class =" mt-1 text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition"
231+ on:click |stopPropagation ={() => {
232+ expandedResult = true ;
233+ }}
234+ >
235+ {$i18n .t (' Show all ({{COUNT}} characters)' , {
236+ COUNT: resultStr .length .toLocaleString ()
237+ })}
238+ </button >
239+ {/if }
223240 {/if }
224241 </div >
225242 </div >
You can’t perform that action at this time.
0 commit comments