Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -1,73 +1,53 @@
|
|||||||
# React + TypeScript + Vite
|
# YvCode
|
||||||
|
|
||||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
A lightweight code-canvas editor to create export-ready images for social media (code blocks, text, arrows, backgrounds, and branding).
|
||||||
|
|
||||||
Currently, two official plugins are available:
|

|
||||||
|
|
||||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
## Features
|
||||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
||||||
|
|
||||||
## React Compiler
|
- Canvas editor built on Konva (move/resize/rotate elements)
|
||||||
|
- Elements: Code block, Text, Arrow
|
||||||
|
- Backgrounds: solid + gradient, optional brand strip
|
||||||
|
- Branding overlay (name/title/avatar + social handles)
|
||||||
|
- Layers panel (reorder, lock, hide/show)
|
||||||
|
- Export image: PNG or JPEG (2x)
|
||||||
|
- Project files: export/import as JSON
|
||||||
|
- Recent projects list (local)
|
||||||
|
- Undo/Redo + keyboard shortcuts
|
||||||
|
|
||||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
## Keyboard shortcuts
|
||||||
|
|
||||||
## Expanding the ESLint configuration
|
- New canvas: `⌘N`
|
||||||
|
- Open project JSON: `⌘O`
|
||||||
|
- Export project JSON: `⌘S`
|
||||||
|
- Undo / Redo: `⌘Z` / `⇧⌘Z`
|
||||||
|
- Duplicate selected: `⌘D`
|
||||||
|
- Delete selected: `Backspace` / `Delete`
|
||||||
|
- Zoom in/out: `⌘+` / `⌘-`
|
||||||
|
- Toggle grid: `⌘;`
|
||||||
|
- Tools: Select `V`, Code `C`, Text `T`, Arrow `A`
|
||||||
|
- Deselect: `Esc`
|
||||||
|
|
||||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
## Getting started
|
||||||
|
|
||||||
```js
|
Requirements: Node.js (recommended: latest LTS)
|
||||||
export default defineConfig([
|
|
||||||
globalIgnores(['dist']),
|
|
||||||
{
|
|
||||||
files: ['**/*.{ts,tsx}'],
|
|
||||||
extends: [
|
|
||||||
// Other configs...
|
|
||||||
|
|
||||||
// Remove tseslint.configs.recommended and replace with this
|
```bash
|
||||||
tseslint.configs.recommendedTypeChecked,
|
npm install
|
||||||
// Alternatively, use this for stricter rules
|
npm run dev
|
||||||
tseslint.configs.strictTypeChecked,
|
|
||||||
// Optionally, add this for stylistic rules
|
|
||||||
tseslint.configs.stylisticTypeChecked,
|
|
||||||
|
|
||||||
// Other configs...
|
|
||||||
],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
||||||
tsconfigRootDir: import.meta.dirname,
|
|
||||||
},
|
|
||||||
// other options...
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
Then open the URL printed by Vite.
|
||||||
|
|
||||||
```js
|
## Scripts
|
||||||
// eslint.config.js
|
|
||||||
import reactX from 'eslint-plugin-react-x'
|
|
||||||
import reactDom from 'eslint-plugin-react-dom'
|
|
||||||
|
|
||||||
export default defineConfig([
|
- `npm run dev` — start the dev server
|
||||||
globalIgnores(['dist']),
|
- `npm run build` — typecheck and build for production
|
||||||
{
|
- `npm run preview` — preview the production build
|
||||||
files: ['**/*.{ts,tsx}'],
|
- `npm run lint` — run ESLint
|
||||||
extends: [
|
|
||||||
// Other configs...
|
## Docs
|
||||||
// Enable lint rules for React
|
|
||||||
reactX.configs['recommended-typescript'],
|
- Product spec: [docs/spec.md](docs/spec.md)
|
||||||
// Enable lint rules for React DOM
|
- UI design notes: [docs/design.md](docs/design.md)
|
||||||
reactDom.configs.recommended,
|
|
||||||
],
|
|
||||||
languageOptions: {
|
|
||||||
parserOptions: {
|
|
||||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
||||||
tsconfigRootDir: import.meta.dirname,
|
|
||||||
},
|
|
||||||
// other options...
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
```
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 652 KiB |
Reference in New Issue
Block a user