Skip to content

Commit 2db1204

Browse files
committed
Address review feedback: improve fallback logic and revert unrelated formatting changes
1 parent 4a67d4d commit 2db1204

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/components/CodeEmbed/index.jsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect, useRef } from "preact/hooks";
2-
import { useLiveRegion } from "../hooks/useLiveRegion";
2+
import { useLiveRegion } from '../hooks/useLiveRegion';
33
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
44
import { javascript } from "@codemirror/lang-javascript";
55
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";
@@ -38,19 +38,14 @@ export const CodeEmbed = (props) => {
3838
);
3939

4040
let { previewWidth, previewHeight } = props;
41-
const canvasMatch =
42-
/createCanvas\(\s*(\d+),\s*(\d+)\s*(?:,\s*(?:P2D|WEBGL)\s*)?\)/m.exec(
43-
initialCode,
44-
);
41+
const canvasMatch = /createCanvas\(\s*(\d+),\s*(\d+)\s*(?:,\s*(?:P2D|WEBGL)\s*)?\)/m.exec(initialCode);
4542
if (canvasMatch) {
4643
previewWidth = previewWidth || parseFloat(canvasMatch[1]);
4744
previewHeight = previewHeight || parseFloat(canvasMatch[2]);
4845
}
4946

5047
// Quick hack to make room for DOM that gets added below the canvas by default
51-
const domMatch = /create(Button|Select|P|Div|Input|ColorPicker)/.exec(
52-
initialCode,
53-
);
48+
const domMatch = /create(Button|Select|P|Div|Input|ColorPicker)/.exec(initialCode);
5449
if (domMatch && previewHeight) {
5550
previewHeight += 100;
5651
}
@@ -59,9 +54,9 @@ export const CodeEmbed = (props) => {
5954
// Ensures DOM-based examples (e.g., createCapture with noCanvas) are visible.
6055
const DEFAULT_PREVIEW_WIDTH = 400;
6156
const DEFAULT_PREVIEW_HEIGHT = 300;
62-
if (previewWidth === undefined && previewHeight === undefined) {
63-
previewWidth = DEFAULT_PREVIEW_WIDTH;
64-
previewHeight = DEFAULT_PREVIEW_HEIGHT;
57+
if (previewWidth === undefined || previewHeight === undefined) {
58+
previewWidth = previewWidth ?? DEFAULT_PREVIEW_WIDTH;
59+
previewHeight = previewHeight ?? DEFAULT_PREVIEW_HEIGHT;
6560
}
6661

6762
const largeSketch = previewWidth && previewWidth > 770 - 60;
@@ -100,7 +95,7 @@ export const CodeEmbed = (props) => {
10095
>
10196
{props.previewable ? (
10297
<div
103-
className={`ml-0 flex w-fit gap-[20px] ${largeSketch ? "flex-col" : props.allowSideBySide ? "" : "flex-col lg:flex-row"}`}
98+
className={`ml-0 flex w-fit gap-[20px] ${largeSketch ? "flex-col" : (props.allowSideBySide ? "" : "flex-col lg:flex-row")}`}
10499
>
105100
<div>
106101
<CodeFrame
@@ -110,16 +105,10 @@ export const CodeEmbed = (props) => {
110105
base={props.base}
111106
frameRef={codeFrameRef}
112107
lazyLoad={props.lazyLoad}
113-
scripts={
114-
props.includeSound
115-
? [cdnLibraryUrl, cdnSoundUrl]
116-
: [cdnLibraryUrl]
117-
}
108+
scripts={props.includeSound ? [cdnLibraryUrl, cdnSoundUrl] :[cdnLibraryUrl]}
118109
/>
119110
</div>
120-
<div
121-
className={`flex gap-2.5 ${largeSketch ? "flex-row" : "md:flex-row lg:flex-col"}`}
122-
>
111+
<div className={`flex gap-2.5 ${largeSketch ? "flex-row" : "md:flex-row lg:flex-col"}`}>
123112
<CircleButton
124113
className="bg-bg-gray-40"
125114
onClick={updateOrReRun}

0 commit comments

Comments
 (0)