Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(playground): Implement playground option #4606
  • Loading branch information
denbezrukov committed Jun 23, 2023
commit f7f8325e4d5403a8387bccd8c89c545735455975
4 changes: 2 additions & 2 deletions website/src/playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CodeMirror from "./CodeMirror";
import DiagnosticsPane from "./components/DiagnosticsPane";
import Resizable from "./components/Resizable";
import SettingsPane from "./components/SettingsPane";
import SettingsPanel from "./components/SettingsPanel";
import Tabs from "./components/Tabs";
import ControlFlowTab from "./tabs/ControlFlowTab";
import DiagnosticsConsoleTab from "./tabs/DiagnosticsConsoleTab";
Expand Down Expand Up @@ -266,7 +266,7 @@ export default function PlaygroundLoader({

return (
<>
<SettingsPane
<SettingsPanel
onReset={resetPlaygroundState}
state={playgroundState}
setPlaygroundState={setPlaygroundState}
Expand Down
3 changes: 3 additions & 0 deletions website/src/playground/PlaygroundLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ function initState(
importSortingEnabled:
searchParams.get("importSortingEnabled") === "true" ||
defaultPlaygroundState.settings.importSortingEnabled,
unsafeParameterDecoratorsEnabled:
searchParams.get("unsafeParameterDecoratorsEnabled") === "true" ||
defaultPlaygroundState.settings.unsafeParameterDecoratorsEnabled,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect, useState } from "react";

const isCollapsedStore = createLocalStorage("settings-collapsed");

export default function SettingsPane(props: SettingsTabProps) {
export default function SettingsPanel(props: SettingsTabProps) {
const [isCollapsed, setIsCollapsed] = useState(isCollapsedStore.getBoolean());

function collapseToggle() {
Expand All @@ -17,7 +17,7 @@ export default function SettingsPane(props: SettingsTabProps) {
}, [isCollapsed]);

return (
<div className="settings-pane">
<div className="settings-panel">
{!isCollapsed && (
<div className="fields">
<SettingsTab {...props} />
Expand Down
34 changes: 33 additions & 1 deletion website/src/playground/tabs/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function SettingsTab({
lintRules,
enabledLinting,
importSortingEnabled,
unsafeParameterDecoratorsEnabled,
},
},
}: SettingsTabProps) {
Expand Down Expand Up @@ -95,6 +96,11 @@ export default function SettingsTab({
"importSortingEnabled",
);

const setUnsafeParameterDecoratorsEnabled = createPlaygroundSettingsSetter(
setPlaygroundState,
"unsafeParameterDecoratorsEnabled",
);

function setCurrentFilename(newFilename: string) {
setPlaygroundState((state) => {
if (state.currentFile === newFilename) {
Expand Down Expand Up @@ -244,7 +250,14 @@ export default function SettingsTab({
importSortingEnabled={importSortingEnabled}
setImportSorting={setImportSorting}
/>
<SyntaxSettings filename={currentFile} setFilename={setCurrentFilename} />
<SyntaxSettings
filename={currentFile}
setFilename={setCurrentFilename}
unsafeParameterDecoratorsEnabled={unsafeParameterDecoratorsEnabled}
setUnsafeParameterDecoratorsEnabled={
setUnsafeParameterDecoratorsEnabled
}
/>
</div>
);
}
Expand Down Expand Up @@ -426,9 +439,13 @@ function FilenameInput({
function SyntaxSettings({
filename,
setFilename,
unsafeParameterDecoratorsEnabled,
setUnsafeParameterDecoratorsEnabled,
}: {
filename: string;
setFilename: (filename: string) => void;
unsafeParameterDecoratorsEnabled: boolean;
setUnsafeParameterDecoratorsEnabled: (value: boolean) => void;
}) {
const isScript = isScriptFilename(filename);

Expand Down Expand Up @@ -496,6 +513,21 @@ function SyntaxSettings({
/>
<label htmlFor="jsx">JSX</label>
</div>

<div className="field-row">
<input
id="parameter-decorators"
name="parameter-decorators"
type="checkbox"
checked={unsafeParameterDecoratorsEnabled}
onChange={(e) =>
setUnsafeParameterDecoratorsEnabled(e.target.checked)
}
/>
<label htmlFor="parameter-decorators">
Parameter decorators enabled
</label>
</div>
</section>
</>
);
Expand Down
2 changes: 2 additions & 0 deletions website/src/playground/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface PlaygroundSettings {
lintRules: LintRules;
enabledLinting: boolean;
importSortingEnabled: boolean;
unsafeParameterDecoratorsEnabled: boolean;
}

export interface PlaygroundFileState {
Expand Down Expand Up @@ -149,6 +150,7 @@ export const defaultPlaygroundState: PlaygroundState = {
lintRules: LintRules.Recommended,
enabledLinting: true,
importSortingEnabled: true,
unsafeParameterDecoratorsEnabled: true,
},
};

Expand Down
4 changes: 4 additions & 0 deletions website/src/playground/workers/romeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ self.addEventListener("message", async (e) => {
trailingComma,
semicolons,
importSortingEnabled,
unsafeParameterDecoratorsEnabled,
} = e.data.settings as PlaygroundSettings;

configuration = {
Expand Down Expand Up @@ -104,6 +105,9 @@ self.addEventListener("message", async (e) => {
semicolons:
semicolons === Semicolons.Always ? "always" : "asNeeded",
},
parser: {
unsafeParameterDecoratorsEnabled,
},
},
};

Expand Down
8 changes: 4 additions & 4 deletions website/src/styles/playground/_settings.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@import "../../styles/_variables";
@import "../../styles/_mixins";

.settings-pane {
.settings-panel {
flex-shrink: 0;
overflow: auto;
font-size: 14px;
display: flex;
border-right: 1px solid var(--playground-border);
background-color: var(--container-color);

@include dark-mode {
background-color: rgba(255, 255, 255, 0.2);
}
Expand Down Expand Up @@ -161,15 +161,15 @@

&.disabled {
opacity: 0.4;

&, * {
cursor: not-allowed;
}
}
}
}

.react-tabs__tab-panel .settings-pane {
.react-tabs__tab-panel .settings-panel {
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.1) !important;
Expand Down