Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 5a831c0

Browse files
committed
patch: simplify docs editor
1 parent 6b811cd commit 5a831c0

File tree

5 files changed

+6
-102
lines changed

5 files changed

+6
-102
lines changed

website/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"prism-react-renderer": "^1.3.5",
2323
"react": "^17.0.2",
2424
"react-dom": "^17.0.2",
25-
"react-split-pane": "^0.1.92",
26-
"use-editable": "^2.3.3"
25+
"react-split-pane": "^0.1.92"
2726
},
2827
"devDependencies": {
2928
"@docusaurus/module-type-aliases": "2.2.0",

website/src/components/TutorialComponents/index.tsx

Lines changed: 5 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ interface CodeBlockProps {
1818
code: string
1919
result: { [key: string]: string }
2020
githubRepo: string | undefined
21-
editable: boolean
2221
showLineNumbers: boolean
23-
readonly: boolean
2422
langVersion?: string
2523
tool?: string
2624
prefix?: string
@@ -32,66 +30,22 @@ interface CodeBlockProps {
3230

3331
function RunButton(props: {
3432
onClick: () => Promise<void>
35-
runFinished: boolean
3633
}) {
37-
const { onClick, runFinished } = props
38-
const text = "Run"
34+
const { onClick } = props
3935
return (
4036
<button className="button button--primary" onClick={onClick}>
41-
{runFinished ? text : "Running..."}
37+
Run
4238
</button>
4339
)
4440
}
4541

46-
function Output(props: {
47-
language: string
48-
result: { [key: string]: string | Array<string> }
49-
codeChanged: boolean
50-
statusCodes: { [key: string]: string }
51-
}) {
52-
const { language, result, codeChanged, statusCodes } = props
53-
const success = result.status === statusCodes.success
54-
const timeout = result.status === statusCodes.timeout
55-
const emptyOutput = result.output === ""
56-
57-
if (emptyOutput) return null
58-
59-
const regularOutput = (
60-
<pre className={codeChanged ? styles.outdated : ""}>
61-
{success ? (
62-
""
63-
) : timeout ? (
64-
<span style={{ color: "red" }}>
65-
{`--${language} timeout--`}
66-
</span>
67-
) : (
68-
<span style={{ color: "red" }}>
69-
<b>Script contains one or more errors: </b>
70-
<br />
71-
</span>
72-
)}
73-
{success ? result.output : !timeout && result.error}
74-
</pre>
75-
)
76-
77-
return (
78-
<div>
79-
<b>Output{codeChanged ? " (outdated)" : ""}:</b>
80-
<br />
81-
{regularOutput}
82-
</div>
83-
)
84-
}
85-
8642
function CustomCodeEditor(props: {
8743
id: string
8844
input: string
8945
showLineNumbers?: boolean
9046
language?: string
91-
editable?: boolean
9247
onChange?: (code: string) => void
9348
githubRepo: string | undefined
94-
readonly: boolean
9549
prefix?: string
9650
sandbox?: {
9751
files: Record<string, { content: string }>
@@ -102,10 +56,8 @@ function CustomCodeEditor(props: {
10256
input,
10357
language,
10458
showLineNumbers,
105-
editable,
10659
githubRepo,
10760
onChange,
108-
readonly,
10961
sandbox,
11062
prefix,
11163
} = props
@@ -119,7 +71,6 @@ function CustomCodeEditor(props: {
11971
<Container
12072
as="div"
12173
className={clsx(
122-
editable ? styles.editable : "",
12374
codeBlockContainerStyles.codeBlockContainer,
12475
ThemeClassNames.common.codeBlock,
12576
language && `language-${language}`
@@ -128,13 +79,13 @@ function CustomCodeEditor(props: {
12879
<CodeEditor
12980
code={input}
13081
theme={prismTheme}
131-
disabled={!editable}
82+
disabled={false}
13283
key={String(isBrowser)}
13384
className={codeBlockContentStyles.codeBlockContent}
13485
onChange={onChange}
13586
language={language}
13687
prism={Prism}
137-
readonly={readonly}
88+
readonly={true}
13889
showLineNumbers={showLineNumbers}
13990
sandbox={sandbox}
14091
prefix={prefix}
@@ -154,18 +105,12 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
154105
code,
155106
result,
156107
githubRepo,
157-
editable,
158108
showLineNumbers,
159-
readonly,
160109
sandbox,
161110
prefix,
162111
} = input
163-
const [currCode, setCurrCode] = useState(code)
112+
const currCode = code
164113
const [outputRendered, setOutputRendered] = useState(false)
165-
const [runFinished, setRunFinished] = useState(true)
166-
const [output, setOutput] = useState(result)
167-
const [lastSnippet, setLastSnippet] = useState(code)
168-
const codeChanged = lastSnippet !== currCode
169114
const { setSource } = useContext(DevToolsContext)
170115
const clientConfig = {
171116
ts: input => {
@@ -176,7 +121,6 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
176121

177122
// bypassing server-side rendering
178123
const onDidClickRun = async () => {
179-
setRunFinished(false)
180124
const newResult = { ...result }
181125
let errorMsg: string
182126

@@ -216,50 +160,29 @@ export default function CustomCodeBlock(props: { input: CodeBlockProps }) {
216160
newResult.status = `${lang}-web-failed`
217161
throw new Error(errorMsg)
218162
} finally {
219-
setLastSnippet(input)
220-
setOutput(newResult)
221-
setRunFinished(true)
222163
if (!outputRendered) {
223164
setOutputRendered(true) // hack for the playground editor
224165
}
225166
}
226167
}
227168

228-
const onDidChangeCode = (code: string) => {
229-
setCurrCode(code)
230-
}
231-
232169
return (
233170
<div>
234171
<CustomCodeEditor
235172
input={code}
236173
id={result.hash}
237174
showLineNumbers={showLineNumbers}
238-
onChange={onDidChangeCode}
239-
editable={editable || outputRendered}
240175
language={highlight}
241176
githubRepo={githubRepo}
242-
readonly={readonly}
243177
sandbox={sandbox}
244178
prefix={prefix}
245179
/>
246180
<>
247181
<div className={styles.buttons}>
248182
<RunButton
249183
onClick={onDidClickRun}
250-
runFinished={runFinished}
251184
/>
252185
</div>
253-
{outputRendered ? (
254-
<Output
255-
language={lang}
256-
codeChanged={codeChanged}
257-
result={output}
258-
statusCodes={statusCodes}
259-
/>
260-
) : (
261-
<div />
262-
)}
263186
</>
264187
</div>
265188
)

website/src/components/TutorialComponents/styles.module.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
@import '../../css/custom.css';
22

3-
.editable {
4-
border-color: var(--ifm-color-primary-light);
5-
border-width: 2px;
6-
border-style: solid;
7-
}
8-
9-
.outdated {
10-
color: grey;
11-
}
12-
133
.buttons {
144
display: flex;
155
align-items: center;

website/src/remark/render-code-blocks.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ export default function plugin() {
222222
statusCodes: langConfig.statusCodes ?? {},
223223
code,
224224
result: result,
225-
editable: true,
226-
readonly: langConfig.readonly ?? true,
227225
showLineNumbers: showLineNumbers,
228226
sandbox: langConfig.sandbox,
229227
prefix: langConfig.prefix,
@@ -254,7 +252,6 @@ export default function plugin() {
254252
statusCodes: buildConfig.statusCodes,
255253
code: value,
256254
result: result,
257-
readonly: false,
258255
showLineNumbers: showLineNumbers,
259256
langVersion: buildConfig.langVersion,
260257
tool: buildConfig.npmPackage,

website/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7834,11 +7834,6 @@ use-composed-ref@^1.3.0:
78347834
resolved "https://registry.yarnpkg.com/use-composed-ref/-/use-composed-ref-1.3.0.tgz#3d8104db34b7b264030a9d916c5e94fbe280dbda"
78357835
integrity sha512-GLMG0Jc/jiKov/3Ulid1wbv3r54K9HlMW29IWcDFPEqFkSO2nS0MuefWgMJpeHQ9YJeXDL3ZUF+P3jdXlZX/cQ==
78367836

7837-
use-editable@^2.3.3:
7838-
version "2.3.3"
7839-
resolved "https://registry.yarnpkg.com/use-editable/-/use-editable-2.3.3.tgz#a292fe9ba4c291cd28d1cc2728c75a5fc8d9a33f"
7840-
integrity sha512-7wVD2JbfAFJ3DK0vITvXBdpd9JAz5BcKAAolsnLBuBn6UDDwBGuCIAGvR3yA2BNKm578vAMVHFCWaOcA+BhhiA==
7841-
78427837
use-isomorphic-layout-effect@^1.1.1:
78437838
version "1.1.2"
78447839
resolved "https://registry.yarnpkg.com/use-isomorphic-layout-effect/-/use-isomorphic-layout-effect-1.1.2.tgz#497cefb13d863d687b08477d9e5a164ad8c1a6fb"

0 commit comments

Comments
 (0)