Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(website): [playground] allow to choose file extensions#6785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
armano2 merged 13 commits intov6fromchore/playground-file-type-selection
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
a77fcf0
chore(website): [playground] allow to choose file extensions
armano2Mar 29, 2023
75611fb
chore(website): use config fileTypes in readFileType
armano2Mar 29, 2023
6e4acd2
fix: remove unnecessary determineLanguage function
armano2Mar 30, 2023
bec4560
fix: remove unnecessary fallback
armano2Mar 30, 2023
e3d57f5
fix: always include extension in generated url
armano2Mar 30, 2023
03be3c8
fix: change default fileType to tsx
armano2Mar 30, 2023
b8b54a4
fix: save fileType to localStorage
armano2Mar 30, 2023
d0c57ac
fix: use `ts.Extension` as type
armano2Mar 30, 2023
bf04456
chore: change default fileType to '.tsx'
armano2Mar 30, 2023
0746aa0
chore(website): [playground] use react-router instead of window.history
armano2Mar 30, 2023
c315dbe
Merge remote-tracking branch 'origin/v6' into chore/playground-file-t…
armano2Apr 2, 2023
e317691
fix: apply changes from code reivew
armano2Apr 2, 2023
c5d359b
fix: correct issue after merge
armano2Apr 2, 2023
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
13 changes: 7 additions & 6 deletionspackages/website/src/components/OptionsSelector.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ import IconExternalLink from '@theme/Icon/ExternalLink';
import React, { useCallback } from 'react';

import { useClipboard } from '../hooks/useClipboard';
importCheckboxfrom './inputs/Checkbox';
import{ fileTypes }from './config';
import Dropdown from './inputs/Dropdown';
import Tooltip from './inputs/Tooltip';
import ActionLabel from './layout/ActionLabel';
Expand DownExpand Up@@ -74,11 +74,12 @@ function OptionsSelectorContent({
<InputLabel name="TSEslint">{process.env.TS_ESLINT_VERSION}</InputLabel>
</Expander>
<Expander label="Options">
<InputLabel name="Enable jsx">
<Checkbox
name="jsx"
checked={state.jsx}
onChange={(e): void => setState({ jsx: e })}
<InputLabel name="File type">
<Dropdown
name="fileType"
value={state.fileType}
onChange={(fileType): void => setState({ fileType })}
options={fileTypes}
/>
</InputLabel>
<InputLabel name="Source type">
Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/Playground.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ import type {

function Playground(): JSX.Element {
const [state, setState] = useHashState({
jsx: false,
fileType: '.tsx',
showAST: false,
sourceType: 'module',
code: '',
Expand DownExpand Up@@ -131,7 +131,7 @@ function Playground(): JSX.Element {
</div>
<LoadingEditor
ts={state.ts}
jsx={state.jsx}
fileType={state.fileType}
activeTab={activeTab}
code={state.code}
tsconfig={state.tsconfig}
Expand Down
24 changes: 19 additions & 5 deletionspackages/website/src/components/config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
export const detailTabs = [
{ value: false as const, label: 'Errors' },
{ value: 'es' as const, label: 'ESTree' },
{ value: 'ts' as const, label: 'TypeScript' },
{ value: 'scope' as const, label: 'Scope' },
import type { ConfigFileType, ConfigShowAst } from './types';

export const detailTabs: { value: ConfigShowAst; label: string }[] = [
{ value: false, label: 'Errors' },
{ value: 'es', label: 'ESTree' },
{ value: 'ts', label: 'TypeScript' },
{ value: 'scope', label: 'Scope' },
];

export const fileTypes: ConfigFileType[] = [
'.ts',
'.tsx',
'.js',
'.jsx',
'.d.ts',
'.cjs',
'.mjs',
'.cts',
'.mts',
];
4 changes: 0 additions & 4 deletionspackages/website/src/components/config/utils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,10 +79,6 @@ export function toJson(cfg: unknown): string {
return JSON.stringify(cfg, null, 2);
}

export function toJsonConfig(cfg: unknown, prop: string): string {
return toJson({ [prop]: cfg });
}

export function getTypescriptOptions(): OptionDeclarations[] {
const allowedCategories = [
'Command-line Options',
Expand Down
28 changes: 12 additions & 16 deletionspackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,7 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
tsconfig,
eslintrc,
selectedRange,
jsx,
fileType,
onEsASTChange,
onScopeChange,
onTsASTChange,
Expand DownExpand Up@@ -84,11 +84,11 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
]);

useEffect(() => {
const newPath =jsx ? '/input.tsx' : '/input.ts';
const newPath =`/input${fileType}`;
if (tabs.code.uri.path !== newPath) {
const newModel = sandboxInstance.monaco.editor.createModel(
tabs.code.getValue(),
'typescript',
undefined,
sandboxInstance.monaco.Uri.file(newPath),
);
newModel.updateOptions({ tabSize: 2, insertSpaces: true });
Expand All@@ -98,22 +98,15 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
tabs.code.dispose();
tabs.code = newModel;
}
}, [
jsx,
sandboxInstance.editor,
sandboxInstance.monaco.Uri,
sandboxInstance.monaco.editor,
tabs,
]);
}, [fileType, sandboxInstance.editor, sandboxInstance.monaco, tabs]);

useEffect(() => {
const config = createCompilerOptions(
jsx,
parseTSConfig(tsconfig).compilerOptions,
);
webLinter.updateCompilerOptions(config);
sandboxInstance.setCompilerSettings(config);
}, [jsx,sandboxInstance, tsconfig, webLinter]);
}, [sandboxInstance, tsconfig, webLinter]);

useEffect(() => {
webLinter.updateRules(parseESLintRC(eslintrc).rules);
Expand All@@ -128,10 +121,10 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
const lintEditor = debounce(() => {
console.info('[Editor] linting triggered');

webLinter.updateParserOptions(jsx,sourceType);
webLinter.updateParserOptions(sourceType);

try {
const messages = webLinter.lint(code);
const messages = webLinter.lint(code, tabs.code.uri.path);

const markers = parseLintResults(messages, codeActions, ruleId =>
sandboxInstance.monaco.Uri.parse(
Expand DownExpand Up@@ -164,7 +157,7 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
lintEditor();
}, [
code,
jsx,
fileType,
tsconfig,
eslintrc,
sourceType,
Expand DownExpand Up@@ -239,7 +232,10 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
run(editor) {
const editorModel = editor.getModel();
if (editorModel) {
const fixed = webLinter.fix(editor.getValue());
const fixed = webLinter.fix(
editor.getValue(),
editorModel.uri.path,
);
if (fixed.fixed) {
editorModel.pushEditOperations(
null,
Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/editor/config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,16 +4,16 @@ import type Monaco from 'monaco-editor';
import { getTypescriptOptions } from '../config/utils';

export function createCompilerOptions(
jsx = false,
tsConfig: Record<string, unknown> = {},
): Monaco.languages.typescript.CompilerOptions {
const config = window.ts.convertCompilerOptionsFromJson(
{
// ts and monaco has different type as monaco types are not changing base on ts version
target: 'esnext',
module: 'esnext',
jsx: 'preserve',
...tsConfig,
jsx: jsx ? 'preserve' : undefined,
allowJs: true,
lib: Array.isArray(tsConfig.lib) ? tsConfig.lib : undefined,
moduleResolution: undefined,
plugins: undefined,
Expand Down
12 changes: 2 additions & 10 deletionspackages/website/src/components/editor/useSandboxServices.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,22 +33,14 @@ export const useSandboxServices = (
): Error | SandboxServices | undefined => {
const { onLoaded } = props;
const [services, setServices] = useState<Error | SandboxServices>();
const [loadedTs, setLoadedTs] = useState<string>(props.ts);
const { colorMode } = useColorMode();

useEffect(() => {
if (props.ts !== loadedTs) {
window.location.reload();
}
}, [props.ts, loadedTs]);

useEffect(() => {
let sandboxInstance: SandboxInstance | undefined;
setLoadedTs(props.ts);

sandboxSingleton(props.ts)
.then(async ({ main, sandboxFactory, lintUtils }) => {
const compilerOptions = createCompilerOptions(props.jsx);
const compilerOptions = createCompilerOptions();

const sandboxConfig: Partial<SandboxConfig> = {
text: props.code,
Expand DownExpand Up@@ -128,7 +120,7 @@ export const useSandboxServices = (
};
// colorMode and jsx can't be reactive here because we don't want to force a recreation
// updating of colorMode and jsx is handled in LoadedEditor
}, [props.ts, onLoaded]);
}, []);

return services;
};
Loading

[8]ページ先頭

©2009-2025 Movatter.jp