Initial commit
This commit is contained in:
13
.dockerignore
Normal file
13
.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
node_modules
|
||||
dist
|
||||
.git
|
||||
.gitignore
|
||||
README.md
|
||||
.vscode
|
||||
.idea
|
||||
*.log
|
||||
npm-debug.log*
|
||||
.DS_Store
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем package файлы
|
||||
COPY package*.json ./
|
||||
|
||||
# Устанавливаем зависимости
|
||||
RUN npm ci
|
||||
|
||||
# Копируем исходный код
|
||||
COPY . .
|
||||
|
||||
# Собираем production build
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем package файлы и устанавливаем зависимости
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Копируем собранные файлы из builder
|
||||
COPY --from=builder /app/dist ./dist
|
||||
|
||||
# Открываем порт
|
||||
EXPOSE 4173
|
||||
|
||||
# Запускаем serve для SPA (поддерживает client-side routing)
|
||||
CMD ["npm", "run", "preview"]
|
||||
73
README.md
Normal file
73
README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
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
|
||||
- [@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
|
||||
|
||||
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).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
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:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
23
eslint.config.js
Normal file
23
eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
17
index.html
Normal file
17
index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Code Formatter</title>
|
||||
<!-- Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400&family=JetBrains+Mono:wght@300&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
4300
package-lock.json
generated
Normal file
4300
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
Normal file
32
package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "jsonformatter",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "serve -s dist -l 4173"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-router-dom": "^7.9.6",
|
||||
"serve": "^14.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.1",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.46.4",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
18
src/App.tsx
Normal file
18
src/App.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import { HomePage } from './pages/HomePage';
|
||||
import { JsonFormatterPage } from './pages/JsonFormatterPage';
|
||||
import { SqlFormatterPage } from './pages/SqlFormatterPage';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/" element={<HomePage />} />
|
||||
<Route path="/json" element={<JsonFormatterPage />} />
|
||||
<Route path="/sql" element={<SqlFormatterPage />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
1
src/assets/react.svg
Normal file
1
src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
56
src/components/FileUploader.css
Normal file
56
src/components/FileUploader.css
Normal file
@@ -0,0 +1,56 @@
|
||||
.file-uploader {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.file-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.upload-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 2rem 2.5rem;
|
||||
background: white;
|
||||
border: 3px dashed #dee2e6;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.upload-label:hover {
|
||||
border-color: #667eea;
|
||||
background: #f8f9ff;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 24px rgba(102, 126, 234, 0.2);
|
||||
}
|
||||
|
||||
.upload-label svg {
|
||||
color: #667eea;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.upload-label:hover svg {
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
.upload-label span {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.upload-label {
|
||||
padding: 1.5rem 2rem;
|
||||
}
|
||||
|
||||
.upload-label span {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
75
src/components/FileUploader.tsx
Normal file
75
src/components/FileUploader.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { useRef, type ChangeEvent } from 'react';
|
||||
import { validateJsonFile } from '../utils/jsonFormatter';
|
||||
import './FileUploader.css';
|
||||
|
||||
interface FileUploaderProps {
|
||||
onFileLoad: (content: string) => void;
|
||||
onError: (error: string) => void;
|
||||
label?: string;
|
||||
accept?: string;
|
||||
validator?: (file: File) => { valid: boolean; error?: string };
|
||||
}
|
||||
|
||||
export function FileUploader({
|
||||
onFileLoad,
|
||||
onError,
|
||||
label = 'Загрузить JSON файл',
|
||||
accept = '.json,application/json',
|
||||
validator = validateJsonFile
|
||||
}: FileUploaderProps) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleFileChange = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
// Валидация файла
|
||||
const validation = validator(file);
|
||||
if (!validation.valid) {
|
||||
onError(validation.error || 'Ошибка валидации файла');
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Чтение файла
|
||||
try {
|
||||
const content = await file.text();
|
||||
onFileLoad(content);
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = '';
|
||||
}
|
||||
} catch (error) {
|
||||
onError('Ошибка при чтении файла');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="file-uploader">
|
||||
<label htmlFor="file-input" className="upload-label">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||
<polyline points="17 8 12 3 7 8" />
|
||||
<line x1="12" y1="3" x2="12" y2="15" />
|
||||
</svg>
|
||||
<span>{label}</span>
|
||||
</label>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
id="file-input"
|
||||
type="file"
|
||||
accept={accept}
|
||||
onChange={handleFileChange}
|
||||
className="file-input"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
57
src/components/FontSelector.css
Normal file
57
src/components/FontSelector.css
Normal file
@@ -0,0 +1,57 @@
|
||||
.font-selector {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1.5rem;
|
||||
background: white;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.font-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.font-label svg {
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.font-select {
|
||||
width: 100%;
|
||||
padding: 0.65rem 1rem;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
background: white;
|
||||
color: #2d3748;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.font-select:hover {
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.font-select:focus {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.font-select option {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.font-selector {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
}
|
||||
}
|
||||
40
src/components/FontSelector.tsx
Normal file
40
src/components/FontSelector.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import './FontSelector.css';
|
||||
|
||||
export type FontFamily = 'jetbrains' | 'fira';
|
||||
|
||||
interface FontSelectorProps {
|
||||
selectedFont: FontFamily;
|
||||
onFontChange: (font: FontFamily) => void;
|
||||
}
|
||||
|
||||
const FONTS = [
|
||||
{ value: 'jetbrains' as FontFamily, label: 'JetBrains Mono', family: 'JetBrains Mono' },
|
||||
{ value: 'fira' as FontFamily, label: 'Fira Mono', family: 'Fira Mono' }
|
||||
];
|
||||
|
||||
export function FontSelector({ selectedFont, onFontChange }: FontSelectorProps) {
|
||||
return (
|
||||
<div className="font-selector">
|
||||
<label htmlFor="font-select" className="font-label">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="4 7 4 4 20 4 20 7"></polyline>
|
||||
<line x1="9" y1="20" x2="15" y2="20"></line>
|
||||
<line x1="12" y1="4" x2="12" y2="20"></line>
|
||||
</svg>
|
||||
Шрифт
|
||||
</label>
|
||||
<select
|
||||
id="font-select"
|
||||
className="font-select"
|
||||
value={selectedFont}
|
||||
onChange={(e) => onFontChange(e.target.value as FontFamily)}
|
||||
>
|
||||
{FONTS.map(font => (
|
||||
<option key={font.value} value={font.value} style={{ fontFamily: font.family }}>
|
||||
{font.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
58
src/components/JsonEditor.css
Normal file
58
src/components/JsonEditor.css
Normal file
@@ -0,0 +1,58 @@
|
||||
.json-editor {
|
||||
flex: 0 0 33.33%;
|
||||
max-width: 500px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 75vh;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.json-editor h2 {
|
||||
margin: 0;
|
||||
padding: 1.5rem;
|
||||
background: #f8f9fa;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.editor-textarea {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
border: none;
|
||||
padding: 1.5rem;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
resize: none;
|
||||
outline: none;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.editor-textarea.error {
|
||||
background: #fff5f5;
|
||||
}
|
||||
|
||||
.editor-textarea::placeholder {
|
||||
color: #adb5bd;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
padding: 1rem 1.5rem;
|
||||
background: #fee;
|
||||
color: #c92a2a;
|
||||
font-size: 0.9rem;
|
||||
border-top: 1px solid #fcc;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.json-editor {
|
||||
flex: 1;
|
||||
max-width: 100%;
|
||||
height: 40vh;
|
||||
}
|
||||
}
|
||||
46
src/components/JsonEditor.tsx
Normal file
46
src/components/JsonEditor.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { type ChangeEvent } from 'react';
|
||||
import './JsonEditor.css';
|
||||
|
||||
export type FontFamily = 'jetbrains' | 'fira';
|
||||
|
||||
interface JsonEditorProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
error?: string;
|
||||
title?: string;
|
||||
placeholder?: string;
|
||||
fontFamily?: FontFamily;
|
||||
}
|
||||
|
||||
const FONT_FAMILIES = {
|
||||
jetbrains: "'JetBrains Mono', monospace",
|
||||
fira: "'Fira Mono', monospace"
|
||||
};
|
||||
|
||||
export function JsonEditor({
|
||||
value,
|
||||
onChange,
|
||||
error,
|
||||
title = 'Ввод JSON',
|
||||
placeholder = 'Введите JSON данные или загрузите файл...',
|
||||
fontFamily = 'jetbrains'
|
||||
}: JsonEditorProps) {
|
||||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
onChange(e.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="json-editor">
|
||||
<h2>{title}</h2>
|
||||
<textarea
|
||||
className={`editor-textarea ${error ? 'error' : ''}`}
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
spellCheck={false}
|
||||
style={{ fontFamily: FONT_FAMILIES[fontFamily] }}
|
||||
/>
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
131
src/components/JsonViewer.css
Normal file
131
src/components/JsonViewer.css
Normal file
@@ -0,0 +1,131 @@
|
||||
.json-viewer {
|
||||
flex: 0 0 33.33%;
|
||||
max-width: 500px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 75vh;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.viewer-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.5rem;
|
||||
background: #f8f9fa;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
}
|
||||
|
||||
.viewer-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.copy-button {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.copy-button:hover {
|
||||
background: #5568d3;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.copy-button:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.copy-button svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.viewer-content {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
padding: 1.5rem;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
overflow: auto;
|
||||
background: white;
|
||||
color: #212529;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.viewer-content:empty::before {
|
||||
content: attr(data-placeholder);
|
||||
color: #adb5bd;
|
||||
}
|
||||
|
||||
/* Подсветка синтаксиса JSON */
|
||||
.viewer-content .key {
|
||||
color: #8B1538;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.viewer-content .string {
|
||||
color: #0D5F0D;
|
||||
}
|
||||
|
||||
.viewer-content .number {
|
||||
color: #003A70;
|
||||
}
|
||||
|
||||
.viewer-content .boolean {
|
||||
color: #d73a49;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.viewer-content .null {
|
||||
color: #6f42c1;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.copy-notification {
|
||||
position: absolute;
|
||||
bottom: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: #38a169;
|
||||
color: white;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
animation: slideUp 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.json-viewer {
|
||||
flex: 1;
|
||||
max-width: 100%;
|
||||
height: 40vh;
|
||||
}
|
||||
}
|
||||
83
src/components/JsonViewer.tsx
Normal file
83
src/components/JsonViewer.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { syntaxHighlight } from '../utils/syntaxHighlight';
|
||||
import './JsonViewer.css';
|
||||
|
||||
export type FontFamily = 'jetbrains' | 'fira';
|
||||
|
||||
interface JsonViewerProps {
|
||||
value: string;
|
||||
title?: string;
|
||||
placeholder?: string;
|
||||
fontFamily?: FontFamily;
|
||||
}
|
||||
|
||||
const FONT_FAMILIES = {
|
||||
jetbrains: "'JetBrains Mono', monospace",
|
||||
fira: "'Fira Mono', monospace"
|
||||
};
|
||||
|
||||
export function JsonViewer({
|
||||
value,
|
||||
title = 'Форматированный JSON',
|
||||
placeholder = 'Форматированный результат появится здесь...',
|
||||
fontFamily = 'jetbrains'
|
||||
}: JsonViewerProps) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const highlightedValue = useMemo(() => {
|
||||
return value ? syntaxHighlight(value) : '';
|
||||
}, [value]);
|
||||
|
||||
const handleCopy = async () => {
|
||||
if (!value) return;
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
} catch (err) {
|
||||
console.error('Ошибка копирования:', err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="json-viewer">
|
||||
<div className="viewer-header">
|
||||
<h2>{title}</h2>
|
||||
{value && (
|
||||
<button
|
||||
className="copy-button"
|
||||
onClick={handleCopy}
|
||||
title="Копировать в буфер обмена"
|
||||
>
|
||||
{copied ? (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
|
||||
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{value ? (
|
||||
<pre
|
||||
className="viewer-content"
|
||||
dangerouslySetInnerHTML={{ __html: highlightedValue }}
|
||||
style={{ fontFamily: FONT_FAMILIES[fontFamily] }}
|
||||
/>
|
||||
) : (
|
||||
<pre
|
||||
className="viewer-content"
|
||||
style={{ fontFamily: FONT_FAMILIES[fontFamily] }}
|
||||
>
|
||||
{placeholder}
|
||||
</pre>
|
||||
)}
|
||||
{copied && <div className="copy-notification">Скопировано!</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
26
src/index.css
Normal file
26
src/index.css
Normal file
@@ -0,0 +1,26 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:root {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
149
src/pages/FormatterPage.css
Normal file
149
src/pages/FormatterPage.css
Normal file
@@ -0,0 +1,149 @@
|
||||
.formatter-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.formatter-header {
|
||||
padding: 1.5rem 2rem;
|
||||
color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 8px;
|
||||
transition: all 0.2s ease;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
transform: translateX(-4px);
|
||||
}
|
||||
|
||||
.header-content {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header-content h1 {
|
||||
margin: 0 0 0.25rem;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header-content p {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.mode-toggle {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
padding: 0.65rem 1.25rem;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: white;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
border-radius: 10px;
|
||||
transition: all 0.3s ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.toggle-button:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.toggle-button.active {
|
||||
background: white;
|
||||
color: #667eea;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.formatter-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 2rem;
|
||||
padding: 2rem;
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.controls-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.formatter-header {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
order: -1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
order: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mode-toggle {
|
||||
order: 2;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.formatter-container {
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.formatter-header {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.header-content h1 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.header-content p {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
145
src/pages/HomePage.css
Normal file
145
src/pages/HomePage.css
Normal file
@@ -0,0 +1,145 @@
|
||||
.home-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.home-header {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.home-header h1 {
|
||||
margin: 0 0 0.5rem;
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.home-header p {
|
||||
margin: 0;
|
||||
font-size: 1.2rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.tools-container {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
justify-content: center;
|
||||
align-items: stretch;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
flex: 1;
|
||||
max-width: 500px;
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 2.5rem;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tool-card:hover {
|
||||
transform: translateY(-8px);
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 1.5rem;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.tool-card h2 {
|
||||
margin: 0 0 1rem;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 700;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.tool-card > p {
|
||||
margin: 0 0 1.5rem;
|
||||
font-size: 1rem;
|
||||
color: #718096;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.feature-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.feature-list li {
|
||||
padding: 0.75rem 0;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
color: #4a5568;
|
||||
font-size: 0.95rem;
|
||||
position: relative;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.feature-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.feature-list li::before {
|
||||
content: "✓";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.tools-container {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.home-header h1 {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.home-page {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.home-header h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
}
|
||||
}
|
||||
48
src/pages/HomePage.tsx
Normal file
48
src/pages/HomePage.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import './HomePage.css';
|
||||
|
||||
export function HomePage() {
|
||||
return (
|
||||
<div className="home-page">
|
||||
<header className="home-header">
|
||||
<h1>Code Formatter</h1>
|
||||
<p>Выберите инструмент для форматирования кода</p>
|
||||
</header>
|
||||
|
||||
<div className="tools-container">
|
||||
<Link to="/json" className="tool-card">
|
||||
<div className="tool-icon">
|
||||
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M4 7h3a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-3" />
|
||||
<path d="M20 7h-3a2 2 0 0 0 -2 2v6a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</div>
|
||||
<h2>JSON Formatter</h2>
|
||||
<p>Форматирование и валидация JSON данных</p>
|
||||
<ul className="feature-list">
|
||||
<li>Форматирование с отступами</li>
|
||||
<li>Минификация JSON</li>
|
||||
<li>Подсветка синтаксиса</li>
|
||||
<li>Валидация ошибок</li>
|
||||
</ul>
|
||||
</Link>
|
||||
|
||||
<Link to="/sql" className="tool-card">
|
||||
<div className="tool-icon">
|
||||
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
</div>
|
||||
<h2>SQL Formatter</h2>
|
||||
<p>Форматирование SQL запросов по стандартам Mozilla</p>
|
||||
<ul className="feature-list">
|
||||
<li>Форматирование по Mozilla Style Guide</li>
|
||||
<li>Uppercase ключевые слова</li>
|
||||
<li>Правильные отступы</li>
|
||||
<li>Читаемая структура</li>
|
||||
</ul>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
96
src/pages/JsonFormatterPage.tsx
Normal file
96
src/pages/JsonFormatterPage.tsx
Normal file
@@ -0,0 +1,96 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { JsonEditor, type FontFamily } from '../components/JsonEditor';
|
||||
import { JsonViewer } from '../components/JsonViewer';
|
||||
import { FileUploader } from '../components/FileUploader';
|
||||
import { FontSelector } from '../components/FontSelector';
|
||||
import { formatJson } from '../utils/jsonFormatter';
|
||||
import './FormatterPage.css';
|
||||
|
||||
export function JsonFormatterPage() {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [formattedValue, setFormattedValue] = useState('');
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
const [isMinified, setIsMinified] = useState(false);
|
||||
const [selectedFont, setSelectedFont] = useState<FontFamily>('jetbrains');
|
||||
|
||||
useEffect(() => {
|
||||
if (!inputValue.trim()) {
|
||||
setFormattedValue('');
|
||||
setError(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = formatJson(inputValue, isMinified);
|
||||
if (result.success && result.formatted) {
|
||||
setFormattedValue(result.formatted);
|
||||
setError(undefined);
|
||||
} else {
|
||||
setFormattedValue('');
|
||||
setError(result.error);
|
||||
}
|
||||
}, [inputValue, isMinified]);
|
||||
|
||||
const handleFileLoad = (content: string) => {
|
||||
setInputValue(content);
|
||||
};
|
||||
|
||||
const handleFileError = (errorMessage: string) => {
|
||||
setError(errorMessage);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="formatter-page">
|
||||
<header className="formatter-header">
|
||||
<Link to="/" className="back-button">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M19 12H5M12 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Назад
|
||||
</Link>
|
||||
<div className="header-content">
|
||||
<h1>JSON Formatter</h1>
|
||||
</div>
|
||||
<div className="mode-toggle">
|
||||
<button
|
||||
className={`toggle-button ${!isMinified ? 'active' : ''}`}
|
||||
onClick={() => setIsMinified(false)}
|
||||
>
|
||||
Форматировать
|
||||
</button>
|
||||
<button
|
||||
className={`toggle-button ${isMinified ? 'active' : ''}`}
|
||||
onClick={() => setIsMinified(true)}
|
||||
>
|
||||
Минифицировать
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="formatter-container">
|
||||
<JsonEditor
|
||||
value={inputValue}
|
||||
onChange={setInputValue}
|
||||
error={error}
|
||||
fontFamily={selectedFont}
|
||||
/>
|
||||
|
||||
<div className="controls-column">
|
||||
<FileUploader
|
||||
onFileLoad={handleFileLoad}
|
||||
onError={handleFileError}
|
||||
/>
|
||||
<FontSelector
|
||||
selectedFont={selectedFont}
|
||||
onFontChange={setSelectedFont}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<JsonViewer
|
||||
value={formattedValue}
|
||||
fontFamily={selectedFont}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
104
src/pages/SqlFormatterPage.tsx
Normal file
104
src/pages/SqlFormatterPage.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { JsonEditor, type FontFamily } from '../components/JsonEditor';
|
||||
import { JsonViewer } from '../components/JsonViewer';
|
||||
import { FileUploader } from '../components/FileUploader';
|
||||
import { FontSelector } from '../components/FontSelector';
|
||||
import { formatSql, validateSqlFile } from '../utils/sqlFormatter';
|
||||
import './FormatterPage.css';
|
||||
|
||||
export function SqlFormatterPage() {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [formattedValue, setFormattedValue] = useState('');
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
const [isMinified, setIsMinified] = useState(false);
|
||||
const [selectedFont, setSelectedFont] = useState<FontFamily>('jetbrains');
|
||||
|
||||
useEffect(() => {
|
||||
if (!inputValue.trim()) {
|
||||
setFormattedValue('');
|
||||
setError(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = formatSql(inputValue, isMinified);
|
||||
if (result.success && result.formatted) {
|
||||
setFormattedValue(result.formatted);
|
||||
setError(undefined);
|
||||
} else {
|
||||
setFormattedValue('');
|
||||
setError(result.error);
|
||||
}
|
||||
}, [inputValue, isMinified]);
|
||||
|
||||
const handleFileLoad = (content: string) => {
|
||||
setInputValue(content);
|
||||
};
|
||||
|
||||
const handleFileError = (errorMessage: string) => {
|
||||
setError(errorMessage);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className="formatter-page">
|
||||
<header className="formatter-header">
|
||||
<Link to="/" className="back-button">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M19 12H5M12 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Назад
|
||||
</Link>
|
||||
<div className="header-content">
|
||||
<h1>SQL Formatter</h1>
|
||||
</div>
|
||||
<div className="mode-toggle">
|
||||
<button
|
||||
className={`toggle-button ${!isMinified ? 'active' : ''}`}
|
||||
onClick={() => setIsMinified(false)}
|
||||
>
|
||||
Форматировать
|
||||
</button>
|
||||
<button
|
||||
className={`toggle-button ${isMinified ? 'active' : ''}`}
|
||||
onClick={() => setIsMinified(true)}
|
||||
>
|
||||
Минифицировать
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="formatter-container">
|
||||
<JsonEditor
|
||||
value={inputValue}
|
||||
onChange={setInputValue}
|
||||
error={error}
|
||||
title="Ввод SQL"
|
||||
placeholder="Введите SQL запрос или загрузите файл..."
|
||||
fontFamily={selectedFont}
|
||||
/>
|
||||
|
||||
<div className="controls-column">
|
||||
<FileUploader
|
||||
onFileLoad={handleFileLoad}
|
||||
onError={handleFileError}
|
||||
label="Загрузить SQL файл"
|
||||
accept=".sql,text/plain"
|
||||
validator={validateSqlFile}
|
||||
/>
|
||||
<FontSelector
|
||||
selectedFont={selectedFont}
|
||||
onFontChange={setSelectedFont}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<JsonViewer
|
||||
value={formattedValue}
|
||||
title="Форматированный SQL"
|
||||
placeholder="Форматированный результат появится здесь..."
|
||||
fontFamily={selectedFont}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
54
src/utils/jsonFormatter.ts
Normal file
54
src/utils/jsonFormatter.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
export interface FormatResult {
|
||||
success: boolean;
|
||||
formatted?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export function formatJson(input: string, minify: boolean = false): FormatResult {
|
||||
if (!input.trim()) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Введите JSON данные'
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(input);
|
||||
const formatted = minify
|
||||
? JSON.stringify(parsed)
|
||||
: JSON.stringify(parsed, null, 2);
|
||||
return {
|
||||
success: true,
|
||||
formatted
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Ошибка парсинга JSON'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function minifyJson(input: string): FormatResult {
|
||||
return formatJson(input, true);
|
||||
}
|
||||
|
||||
export function validateJsonFile(file: File): { valid: boolean; error?: string } {
|
||||
// Проверка расширения
|
||||
if (!file.name.endsWith('.json')) {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Файл должен иметь расширение .json'
|
||||
};
|
||||
}
|
||||
|
||||
// Проверка MIME type
|
||||
if (file.type && file.type !== 'application/json') {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Файл должен быть JSON типа'
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
126
src/utils/sqlFormatter.ts
Normal file
126
src/utils/sqlFormatter.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
export interface FormatResult {
|
||||
success: boolean;
|
||||
formatted?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// SQL ключевые слова для преобразования в UPPERCASE
|
||||
const SQL_KEYWORDS = [
|
||||
'SELECT', 'FROM', 'WHERE', 'JOIN', 'LEFT', 'RIGHT', 'INNER', 'OUTER', 'FULL',
|
||||
'ON', 'AND', 'OR', 'NOT', 'IN', 'EXISTS', 'BETWEEN', 'LIKE', 'IS', 'NULL',
|
||||
'GROUP', 'BY', 'HAVING', 'ORDER', 'ASC', 'DESC', 'LIMIT', 'OFFSET',
|
||||
'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'CREATE', 'TABLE',
|
||||
'ALTER', 'DROP', 'AS', 'DISTINCT', 'COUNT', 'SUM', 'AVG', 'MAX', 'MIN',
|
||||
'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'WITH', 'UNION', 'ALL', 'INTERSECT',
|
||||
'EXCEPT', 'CROSS', 'USING', 'NATURAL', 'PRIMARY', 'KEY', 'FOREIGN',
|
||||
'REFERENCES', 'CONSTRAINT', 'INDEX', 'VIEW', 'PROCEDURE', 'FUNCTION'
|
||||
];
|
||||
|
||||
// Создаем регулярное выражение для поиска ключевых слов
|
||||
const keywordRegex = new RegExp(
|
||||
`\\b(${SQL_KEYWORDS.join('|')})\\b`,
|
||||
'gi'
|
||||
);
|
||||
|
||||
export function formatSql(input: string, minify: boolean = false): FormatResult {
|
||||
if (!input.trim()) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Введите SQL запрос'
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
if (minify) {
|
||||
// Минификация: убираем лишние пробелы и переносы
|
||||
const minified = input
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
return {
|
||||
success: true,
|
||||
formatted: minified
|
||||
};
|
||||
}
|
||||
|
||||
// Форматирование по правилам Mozilla
|
||||
let formatted = input;
|
||||
|
||||
// 1. Преобразуем ключевые слова в UPPERCASE
|
||||
formatted = formatted.replace(keywordRegex, (match) => match.toUpperCase());
|
||||
|
||||
// 2. Убираем лишние пробелы
|
||||
formatted = formatted.replace(/\s+/g, ' ').trim();
|
||||
|
||||
// 3. Форматируем SELECT
|
||||
formatted = formatted.replace(/SELECT\s+/gi, 'SELECT\n ');
|
||||
formatted = formatted.replace(/,\s*/g, ',\n ');
|
||||
|
||||
// 4. Форматируем FROM
|
||||
formatted = formatted.replace(/\s+FROM\s+/gi, '\nFROM ');
|
||||
|
||||
// 5. Форматируем JOINы
|
||||
formatted = formatted.replace(/\s+(LEFT|RIGHT|INNER|OUTER|FULL|CROSS)?\s*(JOIN)\s+/gi,
|
||||
(_match, type) => {
|
||||
const joinType = type ? `${type.toUpperCase()} ` : '';
|
||||
return `\n${joinType}JOIN `;
|
||||
}
|
||||
);
|
||||
|
||||
// 6. Форматируем ON
|
||||
formatted = formatted.replace(/\s+ON\s+/gi, '\n ON ');
|
||||
formatted = formatted.replace(/\s+USING\s+/gi, '\n USING ');
|
||||
|
||||
// 7. Форматируем WHERE
|
||||
formatted = formatted.replace(/\s+WHERE\s+/gi, '\nWHERE\n ');
|
||||
|
||||
// 8. Форматируем AND/OR в WHERE
|
||||
formatted = formatted.replace(/\s+(AND|OR)\s+/gi, (_match, keyword) => {
|
||||
return `\n ${keyword.toUpperCase()} `;
|
||||
});
|
||||
|
||||
// 9. Форматируем GROUP BY
|
||||
formatted = formatted.replace(/\s+GROUP\s+BY\s+/gi, '\nGROUP BY\n ');
|
||||
|
||||
// 10. Форматируем ORDER BY
|
||||
formatted = formatted.replace(/\s+ORDER\s+BY\s+/gi, '\nORDER BY\n ');
|
||||
|
||||
// 11. Форматируем HAVING
|
||||
formatted = formatted.replace(/\s+HAVING\s+/gi, '\nHAVING\n ');
|
||||
|
||||
// 12. Форматируем LIMIT/OFFSET
|
||||
formatted = formatted.replace(/\s+LIMIT\s+/gi, '\nLIMIT ');
|
||||
formatted = formatted.replace(/\s+OFFSET\s+/gi, '\nOFFSET ');
|
||||
|
||||
// 13. Форматируем WITH (CTE)
|
||||
formatted = formatted.replace(/WITH\s+/gi, 'WITH ');
|
||||
|
||||
// 14. Убираем лишние пробелы в начале и конце строк
|
||||
formatted = formatted
|
||||
.split('\n')
|
||||
.map(line => line.trimEnd())
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
formatted
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Ошибка форматирования SQL'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function validateSqlFile(file: File): { valid: boolean; error?: string } {
|
||||
// Проверка расширения
|
||||
if (!file.name.endsWith('.sql')) {
|
||||
return {
|
||||
valid: false,
|
||||
error: 'Файл должен иметь расширение .sql'
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
24
src/utils/syntaxHighlight.ts
Normal file
24
src/utils/syntaxHighlight.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export function syntaxHighlight(json: string): string {
|
||||
if (!json) return '';
|
||||
|
||||
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
return json.replace(
|
||||
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
|
||||
(match) => {
|
||||
let cls = 'number';
|
||||
if (/^"/.test(match)) {
|
||||
if (/:$/.test(match)) {
|
||||
cls = 'key';
|
||||
} else {
|
||||
cls = 'string';
|
||||
}
|
||||
} else if (/true|false/.test(match)) {
|
||||
cls = 'boolean';
|
||||
} else if (/null/.test(match)) {
|
||||
cls = 'null';
|
||||
}
|
||||
return '<span class="' + cls + '">' + match + '</span>';
|
||||
}
|
||||
);
|
||||
}
|
||||
28
tsconfig.app.json
Normal file
28
tsconfig.app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
26
tsconfig.node.json
Normal file
26
tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
16
vite.config.ts
Normal file
16
vite.config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
preview: {
|
||||
host: '0.0.0.0',
|
||||
port: 4173,
|
||||
strictPort: true,
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user