-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
222 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<script lang="ts"> | ||
import * as monaco from 'monaco-editor' | ||
import { formatHex } from 'culori' | ||
import { onMount } from 'svelte' | ||
import { colorTheme } from '../../utils/shiki-theme' | ||
import Button from '../Button.svelte' | ||
let editor: monaco.editor.IStandaloneCodeEditor | null = null | ||
let toRgb = (color: string): string => { | ||
if (!color) { | ||
return color | ||
} | ||
let hex = formatHex(color) | ||
if (!hex) { | ||
throw new Error(`Could not convert ${JSON.stringify(color)} to RGB`) | ||
} | ||
return hex | ||
} | ||
let resolveCssVariable = (variable: string): string => { | ||
if (!variable) { | ||
return variable | ||
} | ||
let styles = getComputedStyle(document.documentElement) | ||
let cleanVariable = variable.replace(/^var\(/u, '').replace(/\)$/u, '') | ||
return styles.getPropertyValue(cleanVariable).trim() | ||
} | ||
let defineMonacoTheme = (themeName: string): void => { | ||
monaco.editor.defineTheme(themeName, { | ||
rules: colorTheme.tokenColors | ||
?.flatMap(token => | ||
(Array.isArray(token.scope) ? token.scope : [token.scope]).map( | ||
scope => ({ | ||
foreground: toRgb( | ||
resolveCssVariable( | ||
token.settings.foreground ?? | ||
colorTheme.colors!['editor.foreground']!, | ||
), | ||
), | ||
fontStyle: token.settings.fontStyle ?? 'normal', | ||
token: scope, | ||
}), | ||
), | ||
) | ||
.filter( | ||
({ foreground }) => !!foreground, | ||
) as monaco.editor.ITokenThemeRule[], | ||
colors: Object.fromEntries( | ||
Object.entries(colorTheme.colors!) | ||
.map(([key, value]) => [key, toRgb(resolveCssVariable(value))]) | ||
.filter(([_, value]) => !!value), | ||
), | ||
base: 'vs-dark', | ||
inherit: false, | ||
}) | ||
} | ||
onMount(() => { | ||
let container: HTMLElement | null = document.querySelector('.monaco') | ||
if (container) { | ||
defineMonacoTheme('css-variables') | ||
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({ | ||
noSemanticValidation: true, | ||
noSyntaxValidation: true, | ||
}) | ||
editor = monaco.editor.create(container, { | ||
minimap: { | ||
enabled: false, | ||
}, | ||
// @ts-ignore | ||
'bracketPairColorization.enabled': false, | ||
fontFamily: 'var(--font-family-code)', | ||
language: 'typescript', | ||
matchBrackets: 'never', | ||
automaticLayout: true, | ||
value: 'const a = 3', | ||
lineHeight: 1.7, | ||
fontSize: 15, | ||
}) | ||
monaco.editor.setTheme('css-variables') | ||
editor.onDidChangeModelContent(() => {}) | ||
} | ||
}) | ||
</script> | ||
|
||
<div class="wrapper"> | ||
<Button color="primary" content="Fix ESLint problems" /> | ||
<div class="monaco" /> | ||
</div> | ||
|
||
<style> | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--space-l); | ||
} | ||
.monaco { | ||
inline-size: 100%; | ||
block-size: 600px; | ||
overflow: hidden; | ||
border-radius: var(--border-radius); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
import Editor from '../components/Editor/Editor.svelte' | ||
import ContentLayout from '../layouts/Content.astro' | ||
--- | ||
|
||
<ContentLayout | ||
keywords={[ | ||
'eslint', | ||
'eslint rules', | ||
'eslint plugin', | ||
'coding standards', | ||
'code quality', | ||
'linting rules', | ||
'javascript linting', | ||
'code consistency', | ||
'eslint setup', | ||
'codebase maintenance', | ||
]} | ||
description="Explore our extensive list of ESLint Plugin Perfectionist rules to enforce coding standards and improve code quality. Learn how each rule can help you maintain a consistent and error-free codebase." | ||
path={[ | ||
{ | ||
href: '/playground', | ||
name: 'Playground', | ||
}, | ||
]} | ||
title="Playground" | ||
showFooter={false} | ||
> | ||
<h1>Playground</h1> | ||
<Editor client:only="svelte" /> | ||
</ContentLayout> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.