Skip to content

Commit

Permalink
Rewrite Playground Editor details, add PWA install.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Sep 14, 2023
1 parent a6b2e67 commit bb1ec67
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 295 deletions.
Binary file modified autocorrect-website/bun.lockb
Binary file not shown.
130 changes: 58 additions & 72 deletions autocorrect-website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,77 @@
<meta charset="utf-8" />
<title>AutoCorrect</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="manifest" href="/manifest.webmanifest">
<link rel="alternate icon" type="image/png"
href="https://user-images.githubusercontent.com/5518/194691346-13856309-266b-4bf6-b505-5a8b15d0c02e.png" />
</head>

<body>
<script type="module" src="/src/app.tsx"></script>

<div class="container">
<div class="mb-10 space-y-6 text-center ">
<div class="flex justify-center"><img
src="https://user-images.githubusercontent.com/5518/194691346-13856309-266b-4bf6-b505-5a8b15d0c02e.png"
width="120" />
</div>
<h1 class="text-3xl">AutoCorrect</h1>
<div class="space-y-3">
<div class="text-2xl navbar">
<a href="#try">Demo</a> /
<a href="https://github.com/huacnlee/autocorrect" target="_blank">GitHub</a>
<div id="app">
<div class="container">
<div class="mb-10 space-y-6 text-center ">
<div class="flex justify-center"><img
src="https://user-images.githubusercontent.com/5518/194691346-13856309-266b-4bf6-b505-5a8b15d0c02e.png"
width="120" />
</div>
<div class="sub-navbar">
<a href="https://github.com/huacnlee/autocorrect/actions?query=workflow%3ACI"><img
src="https://github.com/huacnlee/autocorrect/workflows/CI/badge.svg" alt="Go"></a>
<a href="https://github.com/huacnlee/autocorrect/releases"><img
src="https://img.shields.io/github/v/release/huacnlee/autocorrect?label=CLI&color=blue"
alt="GitHub release (latest by date)"></a>
<a href="https://hub.docker.com/r/huacnlee/autocorrect"><img
src="https://img.shields.io/docker/v/huacnlee/autocorrect?label=Docker&color=blue"
alt="Docker Image Version (latest server)"></a>
<a href="https://crates.io/crates/autocorrect"><img
src="https://img.shields.io/crates/v/autocorrect?color=1t&label=Crate" alt="Crates.io"></a>
<a href="https://www.npmjs.com/package/@huacnlee/autocorrect"><img
src="https://img.shields.io/npm/v/@huacnlee/autocorrect?color=1t&label=NPM" alt="NPM"></a>
<a href="https://pypi.org/project/autocorrect-py/"><img
src="https://img.shields.io/pypi/v/autocorrect-py?color=1&label=PyPI" alt="PyPI version"></a>
<a href="https://rubygems.org/gems/autocorrect-rb"><img
src="https://img.shields.io/gem/v/autocorrect-rb?color=1&label=Gem" alt="Gem Version"></a>
<a href="https://repo1.maven.org/maven2/io/github/huacnlee/autocorrect-java/"><img alt="Maven Central"
src="https://img.shields.io/maven-central/v/io.github.huacnlee/autocorrect-java?color=1&label=Maven"></a>
<h1 class="text-3xl">AutoCorrect</h1>
<div class="intro">
<p>A linter and formatter for help you improve copywriting, to correct spaces, punctuations between CJK
(Chinese, Japanese, Korean).</p>
</div>
<div class="flex flex-col justify-center space-y-2 text-center md:flex-row md:space-y-0 md:space-x-6">
<a href="https://github.com/huacnlee/autocorrect/releases/latest" target="_blank" class="btn btn-download">
<div class="text-lg">Download</div>
<div class="text-xs text-gray-200">macOS / Windows / Linux</div>
</a>
<a href="vscode:extension/huacnlee.autocorrect" class="btn btn-install">
<div class="text-lg">Install Extension</div>
<div class="text-xs text-gray-200">Visual Studio Code</div>
</a>
<a href="https://plugins.jetbrains.com/plugin/20244-autocorrect" target="_blank" class="btn btn-install2">
<div class="text-lg">Install Plugin</div>
<div class="text-xs text-gray-200">Intellij Platform</div>
</a>
</div>
<div class="codeblock-wrap">
<pre class="codeblock"><span>brew install autocorrect</span></pre>
<div class="text-gray-200">Or just install via this:</div>
<pre class="codeblock"><span>curl -sSL https://git.io/JcGER | sh</span></pre>
</div>
<div class="intro">
<p>Like Eslint, Rubocop, Gofmt ..., AutoCorrect allow us to checking soure code, and output as colorized diff
with corrected suggest. You can intergrating to CI (GitLab CI, GitHub Action, Travis CI....) for use to
checking the contents in source code. Recognize the file name, and find out the strings and the comment
part.
</p>
<p>基于 Rust 编写的 CLI 工具,用于「自动纠正」或「检查并建议」文案,给 CJK(中文、日语、韩语)与英文混写的场景,补充正确的空格,同时尝试以安全的方式自动纠正标点符号等等。</p>
<p>类似 ESlint、Rubocop、Gofmt 等工具,AutoCorrect 可以用于 CI 环境,它提供 Lint 功能能便捷的检测出项目中有问题的文案,起到统一规范的作用。</p>
<p>支持各种类型源代码文件,能自动识别文件名,并准确找到字符串、注释做自动纠正。</p>
</div>
</div>
<div class="intro">
<p>A linter and formatter for help you improve copywriting, to correct spaces, punctuations between CJK
(Chinese, Japanese, Korean).</p>
</div>
<div class="flex flex-col justify-center space-y-2 text-center md:flex-row md:space-y-0 md:space-x-6">
<a href="https://github.com/huacnlee/autocorrect/releases/latest" target="_blank" class="btn btn-download">
<div class="text-lg">Download</div>
<div class="text-xs text-gray-200">macOS / Windows / Linux</div>
</a>
<a href="vscode:extension/huacnlee.autocorrect" class="btn btn-install">
<div class="text-lg">Install Extension</div>
<div class="text-xs text-gray-200">Visual Studio Code</div>
</a>
<a href="https://plugins.jetbrains.com/plugin/20244-autocorrect" target="_blank" class="btn btn-install2">
<div class="text-lg">Install Plugin</div>
<div class="text-xs text-gray-200">Intellij Platform</div>
</a>

</div>
<div class="codeblock-wrap">
<pre class="codeblock"><span>brew install autocorrect</span></pre>
<div class="text-gray-200">Or just install via this:</div>
<pre class="codeblock"><span>curl -sSL https://git.io/JcGER | sh</span></pre>
</div>
<div class="intro">
<p>Like Eslint, Rubocop, Gofmt ..., AutoCorrect allow us to checking soure code, and output as colorized diff
with corrected suggest. You can intergrating to CI (GitLab CI, GitHub Action, Travis CI....) for use to
checking the contents in source code. Recognize the file name, and find out the strings and the comment part.
<p>
<img class="w-full max-w-4xl mx-auto"
src="https://user-images.githubusercontent.com/5518/191890126-4e0c99dc-91ce-4262-a774-3813a636eea1.png" />

<img class="w-full max-w-4xl mx-auto"
src="https://user-images.githubusercontent.com/5518/192738752-89a9e4f5-75cb-40af-b84d-04889d22e834.png" />
</p>
<p>基于 Rust 编写的 CLI 工具,用于「自动纠正」或「检查并建议」文案,给 CJK(中文、日语、韩语)与英文混写的场景,补充正确的空格,同时尝试以安全的方式自动纠正标点符号等等。</p>
<p>类似 ESlint、Rubocop、Gofmt 等工具,AutoCorrect 可以用于 CI 环境,它提供 Lint 功能能便捷的检测出项目中有问题的文案,起到统一规范的作用。</p>
<p>支持各种类型源代码文件,能自动识别文件名,并准确找到字符串、注释做自动纠正。</p>
</div>
<div class="absolute top-0 bottom-0 left-0 right-0 flex space-x-4 text-center bg-white">
<div class="flex-1 py-1 m-6 space-y-6 w-[400px] animate-pulse">
<div class="w-2/6 h-4 rounded bg-slate-200"></div>
<div class="w-8/12 h-2 col-span-2 rounded bg-slate-200"></div>
<div class="w-6/12 h-2 col-span-2 rounded bg-slate-200"></div>
<div class="w-10/12 h-2 col-span-2 rounded bg-slate-200"></div>
<div class="w-full h-4 col-span-2 mt-2 rounded bg-slate-200"></div>
<div class="w-10/12 h-2 col-span-2 mt-2 rounded bg-slate-200"></div>
<div class="w-2/6 h-2 col-span-2 mt-2 rounded bg-slate-200"></div>

<p>
<img class="w-full max-w-4xl mx-auto"
src="https://user-images.githubusercontent.com/5518/191890126-4e0c99dc-91ce-4262-a774-3813a636eea1.png" />

<img class="w-full max-w-4xl mx-auto"
src="https://user-images.githubusercontent.com/5518/192738752-89a9e4f5-75cb-40af-b84d-04889d22e834.png" />
</p>
</div>
</div>
</div>

<h2 id="try" class="mb-6 text-2xl">Try AutoCorrect</h2>
<div id="app-editor"></div>
</div>
</body>

</html>
4 changes: 3 additions & 1 deletion autocorrect-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
},
"dependencies": {
"@huacnlee/autocorrect": "^2.6.3",
"@monaco-editor/react": "^4.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0"
},
"license": "MIT"
}
17 changes: 17 additions & 0 deletions autocorrect-website/public/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "AutoCorrect",
"short_name": "AutoCorrect",
"description": "AutoCorrect Playground.",
"start_url": "/autocorrect/editor",
"scope": "/autocorrect/",
"display": "standalone",
"background_color": "#FFFFFF",
"theme_color": "#FFFFFF",
"icons": [
{
"src": "https://user-images.githubusercontent.com/5518/194691346-13856309-266b-4bf6-b505-5a8b15d0c02e.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
207 changes: 207 additions & 0 deletions autocorrect-website/src/AppEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import Editor from '@monaco-editor/react';
import * as monaco from 'monaco-editor';
import { useEffect, useState } from 'react';
import examples from './examples';
import './style.scss';
export const autocorrectLib = import('@huacnlee/autocorrect');

export let config = {
rules: {
fullwidth: 2,
'halfwidth-punctuation': 2,
spellcheck: 2,
},
spellcheck: {
words: ['WebAssembly', 'Rust', 'NPM', 'Web', 'JavaScript'],
},
};

export const createMarkers = (result: any) => {
const markers: monaco.editor.IMarkerData[] = result.lines.map(
(lineResult: any) => {
return {
severity:
lineResult.severity === 1
? monaco.MarkerSeverity.Warning
: monaco.MarkerSeverity.Info,
startLineNumber: lineResult.l,
startColumn: lineResult.c,
endLineNumber: lineResult.l,
endColumn: lineResult.c + lineResult.old.length + 1,
message: `AutoCorrect: ${lineResult.new}`,
};
}
);

return markers;
};

autocorrectLib.then((ac) => {
const loadedConfig = ac.loadConfig(JSON.stringify(config));
console.log('Loaded config: ', loadedConfig);
// @ts-ignore
window.autocorrect = ac;
});

export const editorOptions: monaco.editor.IStandaloneEditorConstructionOptions =
{
theme: 'vs',
tabSize: 2,
useTabStops: true,
scrollbar: {
verticalScrollbarSize: 5,
horizontalScrollbarSize: 5,
useShadows: true,
},
renderLineHighlight: 'none',
minimap: {
enabled: false,
},
formatOnPaste: true,
unicodeHighlight: {
ambiguousCharacters: false,
},
};

export const AppEditor = () => {
const [monaco, setMonaco] = useState<any>();
const [editor, setEditor] = useState<monaco.editor.IStandaloneCodeEditor>();
const [message, showMessage] = useState('');
const [fileType, setFileType] = useState('markdown');

// @ts-ignore
const autocorrect = window.autocorrect;

const onLint = () => {
if (!editor) {
return;
}
if (!autocorrect) {
return;
}

const start = new Date();
const result = autocorrect.lintFor(editor.getValue(), fileType);
// @ts-ignore
const duration = new Date() - start;
showMessage(`Speed time: ${duration}ms`);

monaco.editor.setModelMarkers(
// @ts-ignore
editor.getModel(),
'autocorrect',
createMarkers(result)
);

return false;
};

const reloadExample = () => {
loadExampleByFileType(fileType);
};

const loadExampleByFileType = (fileType: string) => {
if (!editor) {
return;
}

// @ts-ignore
const example = examples[fileType];

editor.setValue(example.raw);
// @ts-ignore
monaco.editor.setModelLanguage(editor.getModel(), fileType);
};

const FileTypeOptions = () => {
return (
<>
{Object.keys(examples).map((key) => {
// @ts-ignore
const item = examples[key];
return (
<option key={key} value={key}>
{item.title}
</option>
);
})}
</>
);
};

const onChangeFileType = (e: any) => {
const fileType = e.target?.value;
setFileType(fileType);
loadExampleByFileType(fileType);
};

const formatText = (e: any) => {
e.preventDefault();
if (!editor) {
return;
}

const start = new Date();
const result = autocorrect.formatFor(editor.getValue(), fileType);
// @ts-ignore
const duration = new Date() - start;
showMessage(`Speed time: ${duration}ms`);
console.log(result);

editor.setValue(result.out);
return false;
};

const initEditor = () => {
if (!editor) {
return;
}

editor.onDidChangeModelContent(() => {
onLint();
});

editor.addCommand(monaco.KeyCode.KeyZ + monaco.KeyMod.CtrlCmd, function () {
reloadExample();
});
};

useEffect(() => {
initEditor();
reloadExample();
}, [editor]);

return (
<div className="p-4 text-left app-editor-wrap">
<div className="flex items-center justify-between mx-auto mb-4">
<select
onChange={onChangeFileType}
value={fileType}
className="min-w-[250px]"
>
<FileTypeOptions />
</select>

<div className="flex flex-wrap items-center justify-between space-y-6 lg:flex-nowrap lg:space-x-6 lg:space-y-0">
<span className="message">{message}</span>
<div className="flex gap-3">
<button onClick={reloadExample}>Reset</button>
<button className="btn-primary" onClick={formatText}>
Format
</button>
</div>
</div>
</div>
<div className="editor-wraper absolute bottom-4 left-4 right-4 top-[110px]">
<Editor
defaultLanguage="markdown"
options={editorOptions}
onMount={(editor, monaco) => {
setEditor(editor);
setMonaco(monaco);
}}
/>
</div>
</div>
);
};
Loading

0 comments on commit bb1ec67

Please sign in to comment.