Skip to content

Commit 0c027bb

Browse files
committed
feat(repl): show/hide large code blocks
1 parent bc0caa4 commit 0c027bb

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

packages/docs/src/repl/repl-output-modules.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $, component$, useSignal } from '@builder.io/qwik';
1+
import { $, component$, createSignal, useSignal } from '@builder.io/qwik';
22
import { CodeBlock } from '../components/code-block/code-block';
33
import type { ReplModuleOutput } from './types';
44
const FILE_MODULE_DIV_ID = 'file-modules-client-modules';
@@ -35,22 +35,34 @@ export const ReplOutputModules = component$(({ outputs, headerText }: ReplOutput
3535
</div>
3636
</div>
3737
<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>
4363
</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+
})}
5466
</div>
5567
</div>
5668
);

packages/docs/src/repl/repl-output-panel.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { component$, useComputed$ } from '@builder.io/qwik';
1+
import { component$ } from '@builder.io/qwik';
22
import { CodeBlock } from '../components/code-block/code-block';
33
import { ReplOutputModules } from './repl-output-modules';
44
import { ReplOutputSymbols } from './repl-output-symbols';
@@ -8,10 +8,6 @@ import type { ReplAppInput, ReplStore } from './types';
88

99
export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProps) => {
1010
const diagnosticsLen = store.diagnostics.length + store.monacoDiagnostics.length;
11-
const clientBundlesNoCore = useComputed$(() =>
12-
// Qwik Core is not interesting and is large, slowing down the UI
13-
store.clientBundles.filter((b) => !b.path.endsWith('qwikCore.js'))
14-
);
1511

1612
return (
1713
<div class="repl-panel repl-output-panel">
@@ -115,7 +111,7 @@ export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProp
115111
) : null}
116112

117113
{store.selectedOutputPanel === 'clientBundles' ? (
118-
<ReplOutputModules headerText="/build/" outputs={clientBundlesNoCore.value} />
114+
<ReplOutputModules headerText="/build/" outputs={store.clientBundles} />
119115
) : null}
120116

121117
{store.selectedOutputPanel === 'serverModules' ? (

packages/docs/src/repl/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { NoSerialize, Signal } from '@builder.io/qwik';
12
import type {
23
Diagnostic,
34
QwikManifest,
45
QwikRollupPluginOptions,
56
TransformModule,
67
} from '@builder.io/qwik/optimizer';
7-
import type { NoSerialize } from '@builder.io/qwik';
88

99
export interface ReplAppInput {
1010
buildId: number;
@@ -58,6 +58,7 @@ export interface ReplModuleOutput {
5858
path: string;
5959
code: string;
6060
size?: string;
61+
shorten?: Signal<boolean>;
6162
}
6263

6364
export interface ReplMessageBase {

packages/docs/src/repl/worker/app-bundle-client.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ export const appBundleClient = async (
104104
});
105105
}
106106

107-
result.transformedModules = result.transformedModules.filter((f) => {
108-
return (
109-
!f.path.endsWith('app.js') &&
110-
!f.path.endsWith('entry.server.js') &&
111-
!f.path.endsWith('root.js')
112-
);
113-
});
114-
115107
result.events.push({
116108
kind: 'console-log',
117109
scope: 'build',

0 commit comments

Comments
 (0)