first commit
This commit is contained in:
commit
2bcc676df1
24 files changed
+6255
No files matched your search
+24
@@ -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?
|
||||||
@@ -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...
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
||||||
@@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
<!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>editor</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Generated
+3978
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"name": "@dahyeon/editor",
|
||||||
|
"private": false,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"module": "dist/index.js",
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"files": ["dist"],
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"import": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist",
|
||||||
|
"build": "vite build && npm run build:types",
|
||||||
|
"dev": "vite"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^19",
|
||||||
|
"react-dom": "^19"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"lexical": "^0.38.2",
|
||||||
|
"@lexical/html": "^0.38.2",
|
||||||
|
"@lexical/list": "^0.38.2",
|
||||||
|
"@lexical/markdown": "^0.38.2",
|
||||||
|
"@lexical/react": "^0.38.2",
|
||||||
|
"@lexical/rich-text": "^0.38.2",
|
||||||
|
"@lexical/selection": "^0.38.2",
|
||||||
|
"@lexical/utils": "^0.38.2",
|
||||||
|
"@lexkit/editor": "^0.0.37"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"tailwindcss": "^4.1.17",
|
||||||
|
"@tailwindcss/vite": "^4.1.17",
|
||||||
|
"@eslint/js": "^9.39.1",
|
||||||
|
"@types/node": "^24.10.0",
|
||||||
|
"@types/react": "^19.2.2",
|
||||||
|
"@types/react-dom": "^19.2.2",
|
||||||
|
"@vitejs/plugin-react": "^5.1.0",
|
||||||
|
"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.3",
|
||||||
|
"vite": "^7.2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 |
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#root {
|
||||||
|
max-width: 1280px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 6em;
|
||||||
|
padding: 1.5em;
|
||||||
|
will-change: filter;
|
||||||
|
transition: filter 300ms;
|
||||||
|
}
|
||||||
|
.logo:hover {
|
||||||
|
filter: drop-shadow(0 0 2em #646cffaa);
|
||||||
|
}
|
||||||
|
.logo.react:hover {
|
||||||
|
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes logo-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
a:nth-of-type(2) .logo {
|
||||||
|
animation: logo-spin infinite 20s linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
padding: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-the-docs {
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import reactLogo from './assets/react.svg'
|
||||||
|
import viteLogo from '/vite.svg'
|
||||||
|
import './App.css'
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<a href="https://vite.dev" target="_blank">
|
||||||
|
<img src={viteLogo} className="logo" alt="Vite logo" />
|
||||||
|
</a>
|
||||||
|
<a href="https://react.dev" target="_blank">
|
||||||
|
<img src={reactLogo} className="logo react" alt="React logo" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<h1>Vite + React</h1>
|
||||||
|
<div className="card">
|
||||||
|
<button onClick={() => setCount((count) => count + 1)}>
|
||||||
|
count is {count}
|
||||||
|
</button>
|
||||||
|
<p>
|
||||||
|
Edit <code>src/App.tsx</code> and save to test HMR
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p className="read-the-docs">
|
||||||
|
Click on the Vite and React logos to learn more
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
||||||
@@ -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 |
@@ -0,0 +1,105 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
|
||||||
|
const LANGUAGE_LABELS: { [key: string]: string } = {
|
||||||
|
csharp: 'C#',
|
||||||
|
javascript: 'JavaScript',
|
||||||
|
typescript: 'TypeScript',
|
||||||
|
python: 'Python',
|
||||||
|
java: 'Java',
|
||||||
|
cpp: 'C++',
|
||||||
|
c: 'C',
|
||||||
|
html: 'HTML',
|
||||||
|
css: 'CSS',
|
||||||
|
sql: 'SQL',
|
||||||
|
json: 'JSON',
|
||||||
|
markdown: 'Markdown',
|
||||||
|
bash: 'Bash',
|
||||||
|
plain: 'Plain Text',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CodeActionMenuPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateCodeBlocks = () => {
|
||||||
|
// 현재 포커스 저장
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
|
||||||
|
// 모든 code 요소에 data-language-label 추가
|
||||||
|
const codeBlocks = document.querySelectorAll('code[data-language]');
|
||||||
|
|
||||||
|
codeBlocks.forEach((codeBlock) => {
|
||||||
|
if (!(codeBlock instanceof HTMLElement)) return;
|
||||||
|
|
||||||
|
const style = window.getComputedStyle(codeBlock);
|
||||||
|
if (style.display !== 'block') return;
|
||||||
|
|
||||||
|
const language = codeBlock.dataset.language || 'plain';
|
||||||
|
const languageLabel = LANGUAGE_LABELS[language] || language;
|
||||||
|
|
||||||
|
// data 속성에 언어 라벨 저장 (CSS에서 사용)
|
||||||
|
codeBlock.dataset.languageLabel = languageLabel;
|
||||||
|
|
||||||
|
// 복사 버튼이 이미 있는지 확인
|
||||||
|
// const existingBtn = codeBlock.parentElement?.querySelector('.floating-copy-btn');
|
||||||
|
// if (existingBtn) return;
|
||||||
|
|
||||||
|
// // 복사 버튼 생성 (code 요소 다음에 배치)
|
||||||
|
// const copyBtn = document.createElement('button');
|
||||||
|
// copyBtn.className = 'floating-copy-btn';
|
||||||
|
// copyBtn.type = 'button';
|
||||||
|
// copyBtn.innerHTML = '📋';
|
||||||
|
// copyBtn.title = '복사';
|
||||||
|
// copyBtn.contentEditable = 'false';
|
||||||
|
// copyBtn.onclick = (e) => {
|
||||||
|
// e.preventDefault();
|
||||||
|
// e.stopPropagation();
|
||||||
|
// const code = codeBlock.textContent || '';
|
||||||
|
// navigator.clipboard.writeText(code).then(() => {
|
||||||
|
// copyBtn.innerHTML = '✓';
|
||||||
|
// copyBtn.title = '복사됨!';
|
||||||
|
// setTimeout(() => {
|
||||||
|
// copyBtn.innerHTML = '📋';
|
||||||
|
// copyBtn.title = '복사';
|
||||||
|
// }, 2000);
|
||||||
|
// }).catch(() => {
|
||||||
|
// alert('복사에 실패했습니다.');
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
// code 요소 바로 다음에 삽입
|
||||||
|
// if (codeBlock.nextSibling) {
|
||||||
|
// codeBlock.parentNode?.insertBefore(copyBtn, codeBlock.nextSibling);
|
||||||
|
// } else {
|
||||||
|
// codeBlock.parentNode?.appendChild(copyBtn);
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
|
||||||
|
// 포커스 복원
|
||||||
|
if (activeElement && activeElement !== document.activeElement && activeElement instanceof HTMLElement) {
|
||||||
|
setTimeout(() => {
|
||||||
|
activeElement.focus();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 초기 실행
|
||||||
|
updateCodeBlocks();
|
||||||
|
setTimeout(updateCodeBlocks, 500);
|
||||||
|
|
||||||
|
const unregister = editor.registerUpdateListener(() => {
|
||||||
|
setTimeout(updateCodeBlocks, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 주기적 실행 간격을 길게 (포커스 문제 방지)
|
||||||
|
const interval = setInterval(updateCodeBlocks, 10000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unregister();
|
||||||
|
clearInterval(interval);
|
||||||
|
};
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
import { registerCodeHighlighting } from '@lexical/code';
|
||||||
|
|
||||||
|
export function CodeHighlightPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return registerCodeHighlighting(editor);
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
import { CodeNode } from '@lexical/code';
|
||||||
|
import { $isCodeNode } from '@lexical/code';
|
||||||
|
|
||||||
|
export function CodeLanguagePlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Use Lexical's MutationListener to safely update DOM when CodeNode changes
|
||||||
|
const removeMutationListener = editor.registerMutationListener(CodeNode, (mutatedNodes) => {
|
||||||
|
editor.getEditorState().read(() => {
|
||||||
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
||||||
|
// Handle created or updated nodes
|
||||||
|
if (mutation === 'created' || mutation === 'updated') {
|
||||||
|
const node = editor.getElementByKey(nodeKey);
|
||||||
|
if (node instanceof HTMLElement) {
|
||||||
|
|
||||||
|
const language = node.getAttribute("data-highlight-language"); //className.replace('data-highlight-language', '');
|
||||||
|
node.setAttribute('data-language', language!);
|
||||||
|
/**
|
||||||
|
* 더 좋은 방법이 있을 때까지..
|
||||||
|
*/
|
||||||
|
// const codeElement = node.querySelector('code');
|
||||||
|
// if (codeElement && codeElement.classList.length > 0) {
|
||||||
|
// const languageClass = Array.from(codeElement.classList).find(cls => cls.startsWith('language-'));
|
||||||
|
// if (languageClass) {
|
||||||
|
// const language = languageClass.replace('language-', '');
|
||||||
|
// node.setAttribute('data-language', language);
|
||||||
|
// } else {
|
||||||
|
// node.setAttribute('data-language', 'plain text');
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// node.setAttribute('data-language', 'plain text');
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initial setup: update all existing code blocks
|
||||||
|
editor.getEditorState().read(() => {
|
||||||
|
const root = editor.getRootElement();
|
||||||
|
if (!root) return;
|
||||||
|
|
||||||
|
editor.getEditorState()._nodeMap.forEach((node) => {
|
||||||
|
if ($isCodeNode(node)) {
|
||||||
|
const element = editor.getElementByKey(node.__key);
|
||||||
|
if (element instanceof HTMLElement) {
|
||||||
|
console.log(element)
|
||||||
|
const language = element.getAttribute("data-highlight-language"); //className.replace('data-highlight-language', '');
|
||||||
|
element.setAttribute('data-language', language!);
|
||||||
|
// const codeElement = element.querySelector('code');
|
||||||
|
// if (codeElement && codeElement.classList.length > 0) {
|
||||||
|
// const languageClass = Array.from(codeElement.classList).find(cls => cls.startsWith('language-'));
|
||||||
|
// if (languageClass) {
|
||||||
|
// const language = languageClass.replace('language-', '');
|
||||||
|
// element.setAttribute('data-language', language);
|
||||||
|
// } else {
|
||||||
|
// element.setAttribute('data-language', 'plain text');
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// element.setAttribute('data-language', 'plain text');
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return removeMutationListener;
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { Link, useLocation, useParams, useNavigate } from 'react-router-dom';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { getPages, type Page } from '../entities/page';
|
||||||
|
import { getSpaceByKey } from '../entities/space';
|
||||||
|
import { useApiClient } from './hooks/useApiClient';
|
||||||
|
import { MagnifyingGlassIcon, FileTextIcon, PlusIcon, ChevronRightIcon, ChevronDownIcon, DotsHorizontalIcon } from '@radix-ui/react-icons';
|
||||||
|
|
||||||
|
interface TreeNodeProps {
|
||||||
|
page: Page;
|
||||||
|
children: Page[];
|
||||||
|
allPages: Page[];
|
||||||
|
searchQuery: string;
|
||||||
|
level: number;
|
||||||
|
spaceKey: string;
|
||||||
|
onLinkClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TreeNode({ page, children, allPages, searchQuery, level, spaceKey, onLinkClick }: TreeNodeProps) {
|
||||||
|
const location = useLocation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [isExpanded, setIsExpanded] = useState(true);
|
||||||
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
const isActive = location.pathname === `/spaces/${spaceKey}/pages/${page.id}`;
|
||||||
|
|
||||||
|
const hasChildren = children.length > 0;
|
||||||
|
const matchesSearch = searchQuery === '' || page.title.toLowerCase().includes(searchQuery.toLowerCase());
|
||||||
|
|
||||||
|
if (!matchesSearch && searchQuery !== '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAddSubPage = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
// Navigate to new page creation with parent page ID
|
||||||
|
navigate(`/spaces/${spaceKey}/pages/new?parentId=${page.id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMenuClick = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
// TODO: Show context menu
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
className="relative group"
|
||||||
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
|
>
|
||||||
|
<div className={`flex items-center transition-all ${isHovered ? 'pr-16' : 'pr-1'}`}>
|
||||||
|
<button
|
||||||
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
|
className="p-1 hover:bg-[#2d2d30] rounded transition-colors flex-shrink-0"
|
||||||
|
>
|
||||||
|
{hasChildren ? (
|
||||||
|
isExpanded ? (
|
||||||
|
<ChevronDownIcon className="h-3 w-3 text-[#9d9d9d]" />
|
||||||
|
) : (
|
||||||
|
<ChevronRightIcon className="h-3 w-3 text-[#9d9d9d]" />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<div className="w-5" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Link
|
||||||
|
to={`/spaces/${spaceKey}/pages/${page.id}`}
|
||||||
|
onClick={onLinkClick}
|
||||||
|
className={`flex-1 flex items-center gap-2 px-2 py-1.5 text-sm rounded transition-colors min-w-0 ${
|
||||||
|
isActive
|
||||||
|
? 'bg-[#0078d4] text-white'
|
||||||
|
: 'text-[#e4e4e4] hover:bg-[#2d2d30]'
|
||||||
|
}`}
|
||||||
|
style={{ paddingLeft: `${level * 12 + 8}px` }}
|
||||||
|
>
|
||||||
|
<FileTextIcon className="h-3.5 w-3.5 flex-shrink-0" />
|
||||||
|
<span className="truncate">{page.title}</span>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Action buttons - fixed on the right side, shown on hover */}
|
||||||
|
<div className={`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5 bg-[#252526] transition-opacity ${isHovered ? 'opacity-100' : 'opacity-0'}`}>
|
||||||
|
<button
|
||||||
|
onClick={handleAddSubPage}
|
||||||
|
className="p-1 hover:bg-[#3e3e42] rounded transition-colors"
|
||||||
|
title="하위 페이지 추가"
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-3.5 w-3.5 text-[#9d9d9d] hover:text-[#e4e4e4]" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleMenuClick}
|
||||||
|
className="p-1 hover:bg-[#3e3e42] rounded transition-colors"
|
||||||
|
title="더보기"
|
||||||
|
>
|
||||||
|
<DotsHorizontalIcon className="h-3.5 w-3.5 text-[#9d9d9d] hover:text-[#e4e4e4]" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{hasChildren && isExpanded && (
|
||||||
|
<div>
|
||||||
|
{children.map(child => {
|
||||||
|
const grandChildren = allPages.filter(p => p.parentId === child.id);
|
||||||
|
return (
|
||||||
|
<TreeNode
|
||||||
|
key={child.id}
|
||||||
|
page={child}
|
||||||
|
children={grandChildren}
|
||||||
|
allPages={allPages}
|
||||||
|
searchQuery={searchQuery}
|
||||||
|
level={level + 1}
|
||||||
|
spaceKey={spaceKey}
|
||||||
|
onLinkClick={onLinkClick}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LeftSidebarProps {
|
||||||
|
isMobileOpen: boolean;
|
||||||
|
onMobileClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LeftSidebar({ isMobileOpen, onMobileClose }: LeftSidebarProps) {
|
||||||
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
const { spaceKey } = useParams<{ spaceKey: string }>();
|
||||||
|
const apiClient = useApiClient();
|
||||||
|
|
||||||
|
// Get space info to fetch its pages
|
||||||
|
const { data: space, isLoading: isLoadingSpace, error: spaceError } = useQuery({
|
||||||
|
queryKey: ['space', spaceKey],
|
||||||
|
queryFn: () => getSpaceByKey(apiClient, spaceKey!),
|
||||||
|
enabled: !!spaceKey,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch pages for the current space
|
||||||
|
const { data: pages = [], isLoading: isLoadingPages, error: pagesError } = useQuery({
|
||||||
|
queryKey: ['pages', space?.id],
|
||||||
|
queryFn: () => getPages(apiClient, space!.id),
|
||||||
|
enabled: !!space?.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build tree structure
|
||||||
|
const rootPages = pages.filter(page => !page.parentId).sort((a, b) => (a.order || 0) - (b.order || 0));
|
||||||
|
|
||||||
|
// Close mobile sidebar on navigation
|
||||||
|
const handleLinkClick = () => {
|
||||||
|
if (window.innerWidth < 1024) { // lg breakpoint
|
||||||
|
onMobileClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Mobile overlay */}
|
||||||
|
{isMobileOpen && (
|
||||||
|
<div
|
||||||
|
className="fixed inset-0 bg-black/50 z-20 lg:hidden"
|
||||||
|
onClick={onMobileClose}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Sidebar */}
|
||||||
|
<aside className={`
|
||||||
|
w-64 h-screen fixed left-0 top-0 bg-[#252526] border-r border-[#3e3e42]
|
||||||
|
flex flex-col overflow-hidden z-30 transition-transform duration-300
|
||||||
|
lg:translate-x-0
|
||||||
|
${
|
||||||
|
isMobileOpen ? 'translate-x-0' : '-translate-x-full'
|
||||||
|
}
|
||||||
|
`}>
|
||||||
|
{/* Search Box */}
|
||||||
|
<div className="p-4 border-b border-[#3e3e42]">
|
||||||
|
<div className="relative">
|
||||||
|
<MagnifyingGlassIcon className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-[#9d9d9d]" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
placeholder="Find by title"
|
||||||
|
className="w-full pl-9 pr-3 py-2 bg-[#2d2d30] border border-[#3e3e42] rounded text-sm text-[#e4e4e4] placeholder-[#9d9d9d] focus:outline-none focus:border-[#0078d4]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Navigation */}
|
||||||
|
<div className="flex-1 overflow-y-auto">
|
||||||
|
<nav className="p-2">
|
||||||
|
{spaceKey && (
|
||||||
|
<div className="mb-2">
|
||||||
|
<Link
|
||||||
|
to={`/spaces/${spaceKey}/pages/new`}
|
||||||
|
className="flex items-center gap-2 px-3 py-2 text-sm rounded hover:bg-[#2d2d30] text-[#4db8ff] transition-colors"
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-4 w-4" />
|
||||||
|
새 페이지 만들기
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
{isLoadingSpace || isLoadingPages ? (
|
||||||
|
<div className="px-3 py-2 text-sm text-[#9d9d9d]">
|
||||||
|
불러오는 중...
|
||||||
|
</div>
|
||||||
|
) : spaceError || pagesError ? (
|
||||||
|
<div className="px-3 py-2 text-sm text-red-400">
|
||||||
|
오류: {(spaceError || pagesError)?.message}
|
||||||
|
</div>
|
||||||
|
) : rootPages.length === 0 ? (
|
||||||
|
<div className="px-3 py-2 text-sm text-[#9d9d9d]">
|
||||||
|
페이지가 없습니다
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
rootPages.map(page => {
|
||||||
|
const children = pages.filter(p => p.parentId === page.id).sort((a, b) => (a.order || 0) - (b.order || 0));
|
||||||
|
return (
|
||||||
|
<TreeNode
|
||||||
|
key={page.id}
|
||||||
|
page={page}
|
||||||
|
children={children}
|
||||||
|
allPages={pages}
|
||||||
|
searchQuery={searchQuery}
|
||||||
|
level={0}
|
||||||
|
spaceKey={spaceKey || ''}
|
||||||
|
onLinkClick={handleLinkClick}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,841 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
||||||
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
||||||
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
||||||
|
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
||||||
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
||||||
|
import { ListPlugin } from '@lexical/react/LexicalListPlugin';
|
||||||
|
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
||||||
|
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
||||||
|
import { ListNode, ListItemNode } from '@lexical/list';
|
||||||
|
import { CodeNode, CodeHighlightNode } from '@lexical/code';
|
||||||
|
import { LinkNode, AutoLinkNode } from '@lexical/link';
|
||||||
|
import { TableNode, TableCellNode, TableRowNode } from '@lexical/table';
|
||||||
|
import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
||||||
|
import { TableResizerPlugin } from './TableResizerPlugin';
|
||||||
|
import { CodeHighlightPlugin } from './CodeHighlightPlugin';
|
||||||
|
import { CodeActionMenuPlugin } from './CodeActionMenuPlugin';
|
||||||
|
import { CodeLanguagePlugin } from './CodeLanguagePlugin';
|
||||||
|
import type { EditorState } from 'lexical';
|
||||||
|
import { $getRoot, $createParagraphNode, $createTextNode, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, $getSelection, $isRangeSelection, TextNode, type LexicalNode } from 'lexical';
|
||||||
|
import { INSERT_TABLE_COMMAND, $isTableCellNode } from '@lexical/table';
|
||||||
|
import { $createHeadingNode } from '@lexical/rich-text';
|
||||||
|
import { INSERT_UNORDERED_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND } from '@lexical/list';
|
||||||
|
import { $createCodeNode } from '@lexical/code';
|
||||||
|
import { $setBlocksType } from '@lexical/selection';
|
||||||
|
|
||||||
|
const editorTheme = {
|
||||||
|
paragraph: 'mb-2 text-[#e4e4e4]',
|
||||||
|
heading: {
|
||||||
|
h1: 'text-3xl font-bold mb-4 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
h2: 'text-2xl font-bold mb-3 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
h3: 'text-xl font-semibold mb-2 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
ul: 'list-disc list-inside mb-2 text-[#e4e4e4]',
|
||||||
|
ol: 'list-decimal list-inside mb-2 text-[#e4e4e4]',
|
||||||
|
listitem: 'ml-4',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
bold: 'font-bold',
|
||||||
|
italic: 'italic',
|
||||||
|
underline: 'underline',
|
||||||
|
code: 'bg-[#1e1e1e] px-1.5 py-0.5 rounded font-mono text-sm text-[#4db8ff]',
|
||||||
|
},
|
||||||
|
code: 'relative bg-[#1e1e1e] border border-[#3e3e42] rounded-md font-mono text-sm mb-2 block',
|
||||||
|
codeHighlight: {
|
||||||
|
atrule: 'token atrule',
|
||||||
|
attr: 'token attr',
|
||||||
|
boolean: 'token boolean',
|
||||||
|
builtin: 'token builtin',
|
||||||
|
cdata: 'token cdata',
|
||||||
|
char: 'token char',
|
||||||
|
class: 'token class-name',
|
||||||
|
'class-name': 'token class-name',
|
||||||
|
comment: 'token comment',
|
||||||
|
constant: 'token constant',
|
||||||
|
deleted: 'token deleted',
|
||||||
|
doctype: 'token doctype',
|
||||||
|
entity: 'token entity',
|
||||||
|
function: 'token function',
|
||||||
|
important: 'token important',
|
||||||
|
inserted: 'token inserted',
|
||||||
|
keyword: 'token keyword',
|
||||||
|
namespace: 'token namespace',
|
||||||
|
number: 'token number',
|
||||||
|
operator: 'token operator',
|
||||||
|
prolog: 'token prolog',
|
||||||
|
property: 'token property',
|
||||||
|
punctuation: 'token punctuation',
|
||||||
|
regex: 'token regex',
|
||||||
|
selector: 'token selector',
|
||||||
|
string: 'token string',
|
||||||
|
symbol: 'token symbol',
|
||||||
|
tag: 'token tag',
|
||||||
|
url: 'token url',
|
||||||
|
variable: 'token variable',
|
||||||
|
},
|
||||||
|
link: 'text-[#4db8ff] hover:text-[#8cd7ff] underline cursor-pointer',
|
||||||
|
table: 'border-collapse w-full my-4',
|
||||||
|
tableCell: 'border border-[#3e3e42] px-3 py-2 text-[#e4e4e4] relative',
|
||||||
|
tableCellHeader: 'border border-[#3e3e42] px-3 py-2 text-[#e4e4e4] font-bold bg-[#2d2d30] relative',
|
||||||
|
tableRow: '',
|
||||||
|
tableSelection: 'table-cell-selected',
|
||||||
|
tableCellSelected: 'table-cell-selected',
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface LexicalEditorProps {
|
||||||
|
initialContent?: string;
|
||||||
|
onChange: (content: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FONT_FAMILIES = [
|
||||||
|
{ name: 'Noto Sans KR', value: '"Noto Sans KR", sans-serif' },
|
||||||
|
{ name: 'Noto Serif KR', value: '"Noto Serif KR", serif' },
|
||||||
|
{ name: 'Gothic A1', value: '"Gothic A1", sans-serif' },
|
||||||
|
{ name: 'Gowun Batang', value: '"Gowun Batang", serif' },
|
||||||
|
{ name: 'Gowun Dodum', value: '"Gowun Dodum", sans-serif' },
|
||||||
|
{ name: 'Asta Sans', value: '"Asta Sans", sans-serif' },
|
||||||
|
{ name: 'Chiron GoRound TC', value: '"Chiron GoRound TC", sans-serif' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const FONT_SIZES = [
|
||||||
|
{ name: '10px', value: '10px' },
|
||||||
|
{ name: '12px', value: '12px' },
|
||||||
|
{ name: '14px', value: '14px' },
|
||||||
|
{ name: '16px', value: '16px' },
|
||||||
|
{ name: '18px', value: '18px' },
|
||||||
|
{ name: '20px', value: '20px' },
|
||||||
|
{ name: '24px', value: '24px' },
|
||||||
|
{ name: '28px', value: '28px' },
|
||||||
|
{ name: '32px', value: '32px' },
|
||||||
|
{ name: '36px', value: '36px' },
|
||||||
|
{ name: '48px', value: '48px' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const CELL_COLORS = [
|
||||||
|
{ name: '없음', value: 'transparent' },
|
||||||
|
{ name: '빨강', value: '#ffebee' },
|
||||||
|
{ name: '주황', value: '#fff3e0' },
|
||||||
|
{ name: '노랑', value: '#fffde7' },
|
||||||
|
{ name: '초록', value: '#e8f5e9' },
|
||||||
|
{ name: '파랑', value: '#e3f2fd' },
|
||||||
|
{ name: '보라', value: '#f3e5f5' },
|
||||||
|
{ name: '회색', value: '#f5f5f5' },
|
||||||
|
{ name: '진한 빨강', value: '#ef5350' },
|
||||||
|
{ name: '진한 주황', value: '#ff9800' },
|
||||||
|
{ name: '진한 노랑', value: '#fdd835' },
|
||||||
|
{ name: '진한 초록', value: '#66bb6a' },
|
||||||
|
{ name: '진한 파랑', value: '#42a5f5' },
|
||||||
|
{ name: '진한 보라', value: '#ab47bc' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function OnChangePluginWrapper({ onChange }: { onChange: (content: string) => void }) {
|
||||||
|
const handleChange = (editorState: EditorState) => {
|
||||||
|
// Serialize the entire editor state as JSON to preserve formatting
|
||||||
|
const json = JSON.stringify(editorState.toJSON());
|
||||||
|
onChange(json);
|
||||||
|
};
|
||||||
|
|
||||||
|
return <OnChangePlugin onChange={handleChange} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function InitialContentPlugin({ content }: { content?: string }) {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
const isInitialized = useRef(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Only set initial content once, on mount
|
||||||
|
if (content && !isInitialized.current) {
|
||||||
|
isInitialized.current = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to parse as JSON first (new format)
|
||||||
|
const editorState = editor.parseEditorState(content);
|
||||||
|
editor.setEditorState(editorState);
|
||||||
|
} catch {
|
||||||
|
// Fallback to plain text (legacy format)
|
||||||
|
editor.update(() => {
|
||||||
|
const root = $getRoot();
|
||||||
|
root.clear();
|
||||||
|
|
||||||
|
const lines = content.split('\n');
|
||||||
|
lines.forEach((line) => {
|
||||||
|
const paragraph = $createParagraphNode();
|
||||||
|
const text = $createTextNode(line);
|
||||||
|
paragraph.append(text);
|
||||||
|
root.append(paragraph);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [editor, content]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AutoFocusPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
editor.focus();
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function HeadingIdPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Add data attribute and ID to heading elements for TOC
|
||||||
|
const updateHeadings = () => {
|
||||||
|
const headings = document.querySelectorAll('h1, h2, h3');
|
||||||
|
headings.forEach((heading, index) => {
|
||||||
|
if (heading instanceof HTMLElement) {
|
||||||
|
if (!heading.hasAttribute('data-lexical-heading')) {
|
||||||
|
heading.setAttribute('data-lexical-heading', 'true');
|
||||||
|
}
|
||||||
|
if (!heading.id) {
|
||||||
|
const text = heading.textContent || '';
|
||||||
|
heading.id = `heading-${index}-${text.toLowerCase().replace(/\s+/g, '-').slice(0, 30)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial update
|
||||||
|
updateHeadings();
|
||||||
|
|
||||||
|
// Also register mutation listener
|
||||||
|
const unregister = editor.registerMutationListener(HeadingNode, () => {
|
||||||
|
setTimeout(updateHeadings, 50);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update periodically as backup
|
||||||
|
const interval = setInterval(updateHeadings, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unregister();
|
||||||
|
clearInterval(interval);
|
||||||
|
};
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ToolbarPluginProps {
|
||||||
|
fontFamily: string;
|
||||||
|
setFontFamily: (font: string) => void;
|
||||||
|
fontSize: string;
|
||||||
|
setFontSize: (size: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ToolbarPlugin({ fontFamily, setFontFamily, fontSize, setFontSize }: ToolbarPluginProps) {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
const [showTablePicker, setShowTablePicker] = useState(false);
|
||||||
|
const [tableSize, setTableSize] = useState({ rows: 0, cols: 0 });
|
||||||
|
const [showColorPicker, setShowColorPicker] = useState(false);
|
||||||
|
|
||||||
|
const handleFontChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
const newFont = e.target.value;
|
||||||
|
setFontFamily(newFont);
|
||||||
|
|
||||||
|
// Apply font to selected text only
|
||||||
|
editor.update(() => {
|
||||||
|
const selection = $getSelection();
|
||||||
|
if ($isRangeSelection(selection)) {
|
||||||
|
// Check if there's actually a selection
|
||||||
|
if (selection.isCollapsed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodes = selection.getNodes();
|
||||||
|
if (nodes.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const anchor = selection.anchor;
|
||||||
|
const focus = selection.focus;
|
||||||
|
const [start, end] = anchor.isBefore(focus) ? [anchor, focus] : [focus, anchor];
|
||||||
|
|
||||||
|
nodes.forEach((node, idx) => {
|
||||||
|
if (node instanceof TextNode) {
|
||||||
|
const isFirst = idx === 0;
|
||||||
|
const isLast = idx === nodes.length - 1;
|
||||||
|
const isOnlyNode = nodes.length === 1;
|
||||||
|
|
||||||
|
let startOffset = 0;
|
||||||
|
let endOffset = node.getTextContentSize();
|
||||||
|
|
||||||
|
// Determine start offset for the first node
|
||||||
|
if (isFirst && start.getNode() === node) {
|
||||||
|
startOffset = start.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine end offset for the last node
|
||||||
|
if (isLast && end.getNode() === node) {
|
||||||
|
endOffset = end.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if no actual text is selected in this node
|
||||||
|
if (startOffset >= endOffset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the text splitting
|
||||||
|
if (isOnlyNode || (isFirst && isLast)) {
|
||||||
|
// Single node selection
|
||||||
|
if (startOffset === 0 && endOffset === node.getTextContentSize()) {
|
||||||
|
// Entire node is selected
|
||||||
|
applyFontToNode(node, newFont);
|
||||||
|
} else if (startOffset === 0) {
|
||||||
|
// Selection starts at beginning
|
||||||
|
const [leftNode] = node.splitText(endOffset);
|
||||||
|
applyFontToNode(leftNode, newFont);
|
||||||
|
} else if (endOffset === node.getTextContentSize()) {
|
||||||
|
// Selection ends at end
|
||||||
|
const [, rightNode] = node.splitText(startOffset);
|
||||||
|
applyFontToNode(rightNode, newFont);
|
||||||
|
} else {
|
||||||
|
// Selection is in the middle
|
||||||
|
const [, middleNode] = node.splitText(startOffset);
|
||||||
|
const [selectedNode] = middleNode.splitText(endOffset - startOffset);
|
||||||
|
applyFontToNode(selectedNode, newFont);
|
||||||
|
}
|
||||||
|
} else if (isFirst) {
|
||||||
|
// First node of multi-node selection
|
||||||
|
if (startOffset === 0) {
|
||||||
|
applyFontToNode(node, newFont);
|
||||||
|
} else {
|
||||||
|
const [, rightNode] = node.splitText(startOffset);
|
||||||
|
applyFontToNode(rightNode, newFont);
|
||||||
|
}
|
||||||
|
} else if (isLast) {
|
||||||
|
// Last node of multi-node selection
|
||||||
|
if (endOffset === node.getTextContentSize()) {
|
||||||
|
applyFontToNode(node, newFont);
|
||||||
|
} else {
|
||||||
|
const [leftNode] = node.splitText(endOffset);
|
||||||
|
applyFontToNode(leftNode, newFont);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Middle nodes are fully selected
|
||||||
|
applyFontToNode(node, newFont);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyFontToNode = (node: TextNode, fontFamily: string) => {
|
||||||
|
applyStyleToNode(node, 'font-family', fontFamily);
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyStyleToNode = (node: TextNode, property: string, value: string) => {
|
||||||
|
const currentStyle = node.getStyle();
|
||||||
|
const regex = new RegExp(`${property}:[^;]+;?`, 'g');
|
||||||
|
const styleWithoutProperty = currentStyle.replace(regex, '').trim();
|
||||||
|
const newStyle = styleWithoutProperty
|
||||||
|
? `${styleWithoutProperty}; ${property}: ${value}`
|
||||||
|
: `${property}: ${value}`;
|
||||||
|
node.setStyle(newStyle);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFontSizeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
const newSize = e.target.value;
|
||||||
|
setFontSize(newSize);
|
||||||
|
applyFontSizeToSelection(newSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const increaseFontSize = () => {
|
||||||
|
const currentIdx = FONT_SIZES.findIndex(f => f.value === fontSize);
|
||||||
|
const nextIdx = Math.min(currentIdx + 1, FONT_SIZES.length - 1);
|
||||||
|
const newSize = FONT_SIZES[nextIdx].value;
|
||||||
|
setFontSize(newSize);
|
||||||
|
applyFontSizeToSelection(newSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const decreaseFontSize = () => {
|
||||||
|
const currentIdx = FONT_SIZES.findIndex(f => f.value === fontSize);
|
||||||
|
const prevIdx = Math.max(currentIdx - 1, 0);
|
||||||
|
const newSize = FONT_SIZES[prevIdx].value;
|
||||||
|
setFontSize(newSize);
|
||||||
|
applyFontSizeToSelection(newSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyFontSizeToSelection = (size: string) => {
|
||||||
|
editor.update(() => {
|
||||||
|
const selection = $getSelection();
|
||||||
|
if ($isRangeSelection(selection)) {
|
||||||
|
if (selection.isCollapsed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodes = selection.getNodes();
|
||||||
|
if (nodes.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const anchor = selection.anchor;
|
||||||
|
const focus = selection.focus;
|
||||||
|
const [start, end] = anchor.isBefore(focus) ? [anchor, focus] : [focus, anchor];
|
||||||
|
|
||||||
|
nodes.forEach((node, idx) => {
|
||||||
|
if (node instanceof TextNode) {
|
||||||
|
const isFirst = idx === 0;
|
||||||
|
const isLast = idx === nodes.length - 1;
|
||||||
|
const isOnlyNode = nodes.length === 1;
|
||||||
|
|
||||||
|
let startOffset = 0;
|
||||||
|
let endOffset = node.getTextContentSize();
|
||||||
|
|
||||||
|
if (isFirst && start.getNode() === node) {
|
||||||
|
startOffset = start.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLast && end.getNode() === node) {
|
||||||
|
endOffset = end.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startOffset >= endOffset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isOnlyNode || (isFirst && isLast)) {
|
||||||
|
if (startOffset === 0 && endOffset === node.getTextContentSize()) {
|
||||||
|
applyStyleToNode(node, 'font-size', size);
|
||||||
|
} else if (startOffset === 0) {
|
||||||
|
const [leftNode] = node.splitText(endOffset);
|
||||||
|
applyStyleToNode(leftNode, 'font-size', size);
|
||||||
|
} else if (endOffset === node.getTextContentSize()) {
|
||||||
|
const [, rightNode] = node.splitText(startOffset);
|
||||||
|
applyStyleToNode(rightNode, 'font-size', size);
|
||||||
|
} else {
|
||||||
|
const [, middleNode] = node.splitText(startOffset);
|
||||||
|
const [selectedNode] = middleNode.splitText(endOffset - startOffset);
|
||||||
|
applyStyleToNode(selectedNode, 'font-size', size);
|
||||||
|
}
|
||||||
|
} else if (isFirst) {
|
||||||
|
if (startOffset === 0) {
|
||||||
|
applyStyleToNode(node, 'font-size', size);
|
||||||
|
} else {
|
||||||
|
const [, rightNode] = node.splitText(startOffset);
|
||||||
|
applyStyleToNode(rightNode, 'font-size', size);
|
||||||
|
}
|
||||||
|
} else if (isLast) {
|
||||||
|
if (endOffset === node.getTextContentSize()) {
|
||||||
|
applyStyleToNode(node, 'font-size', size);
|
||||||
|
} else {
|
||||||
|
const [leftNode] = node.splitText(endOffset);
|
||||||
|
applyStyleToNode(leftNode, 'font-size', size);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
applyStyleToNode(node, 'font-size', size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatBold = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatItalic = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatUnderline = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatCode = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertHeading = (level: 'h1' | 'h2' | 'h3') => {
|
||||||
|
editor.update(() => {
|
||||||
|
const selection = $getSelection();
|
||||||
|
if ($isRangeSelection(selection)) {
|
||||||
|
$setBlocksType(selection, () => $createHeadingNode(level));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertBulletList = () => {
|
||||||
|
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertNumberedList = () => {
|
||||||
|
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertCodeBlock = () => {
|
||||||
|
editor.update(() => {
|
||||||
|
const selection = $getSelection();
|
||||||
|
if ($isRangeSelection(selection)) {
|
||||||
|
$setBlocksType(selection, () => $createCodeNode());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatAlignLeft = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatAlignCenter = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatAlignRight = () => {
|
||||||
|
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right');
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertTable = (rows: number, cols: number) => {
|
||||||
|
editor.dispatchCommand(INSERT_TABLE_COMMAND, { rows: String(rows), columns: String(cols) });
|
||||||
|
setShowTablePicker(false);
|
||||||
|
setTableSize({ rows: 0, cols: 0 });
|
||||||
|
};
|
||||||
|
|
||||||
|
const setCellBackgroundColor = (color: string) => {
|
||||||
|
editor.update(() => {
|
||||||
|
const selection = $getSelection();
|
||||||
|
if (!selection) return;
|
||||||
|
|
||||||
|
const nodes = selection.getNodes();
|
||||||
|
|
||||||
|
nodes.forEach(node => {
|
||||||
|
// 선택된 노드의 부모를 찾아서 TableCellNode인지 확인
|
||||||
|
let currentNode: LexicalNode | null = node;
|
||||||
|
while (currentNode) {
|
||||||
|
if ($isTableCellNode(currentNode)) {
|
||||||
|
currentNode.setBackgroundColor(color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currentNode = currentNode.getParent();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setShowColorPicker(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-1 p-2 bg-[#252526] border border-[#3e3e42] rounded-t mb-[-1px] relative z-10">
|
||||||
|
{/* Font Family */}
|
||||||
|
<select
|
||||||
|
value={fontFamily}
|
||||||
|
onChange={handleFontChange}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors border border-[#3e3e42] focus:outline-none focus:border-[#0078d4] cursor-pointer"
|
||||||
|
title="텍스트를 선택한 후 글꼴을 변경하세요"
|
||||||
|
>
|
||||||
|
{FONT_FAMILIES.map((font) => (
|
||||||
|
<option key={font.value} value={font.value} style={{ fontFamily: font.value }}>
|
||||||
|
{font.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
{/* Font Size */}
|
||||||
|
<select
|
||||||
|
value={fontSize}
|
||||||
|
onChange={handleFontSizeChange}
|
||||||
|
className="w-20 px-2 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors border border-[#3e3e42] focus:outline-none focus:border-[#0078d4] cursor-pointer"
|
||||||
|
title="텍스트를 선택한 후 크기를 변경하세요"
|
||||||
|
>
|
||||||
|
{FONT_SIZES.map((size) => (
|
||||||
|
<option key={size.value} value={size.value}>
|
||||||
|
{size.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={decreaseFontSize}
|
||||||
|
className="px-2 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="글씨 크기 감소"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
가-
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={increaseFontSize}
|
||||||
|
className="px-2 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="글씨 크기 증가"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
가+
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="w-px h-6 bg-[#3e3e42] mx-1 self-center"></div>
|
||||||
|
|
||||||
|
{/* Text Formatting */}
|
||||||
|
<button
|
||||||
|
onClick={formatBold}
|
||||||
|
className="px-3 py-1.5 text-sm font-bold bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Bold (Ctrl+B)"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
B
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={formatItalic}
|
||||||
|
className="px-3 py-1.5 text-sm italic bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Italic (Ctrl+I)"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
I
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={formatUnderline}
|
||||||
|
className="px-3 py-1.5 text-sm underline bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Underline (Ctrl+U)"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
U
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={formatCode}
|
||||||
|
className="px-3 py-1.5 text-sm font-mono bg-[#2d2d30] hover:bg-[#3e3e42] text-[#4db8ff] rounded transition-colors"
|
||||||
|
title="Inline Code"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
</>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="w-px h-6 bg-[#3e3e42] mx-1 self-center"></div>
|
||||||
|
|
||||||
|
{/* Headings */}
|
||||||
|
<button
|
||||||
|
onClick={() => insertHeading('h1')}
|
||||||
|
className="px-3 py-1.5 text-sm font-bold bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Heading 1"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
H1
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => insertHeading('h2')}
|
||||||
|
className="px-3 py-1.5 text-sm font-bold bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Heading 2"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
H2
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => insertHeading('h3')}
|
||||||
|
className="px-3 py-1.5 text-sm font-semibold bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Heading 3"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
H3
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="w-px h-6 bg-[#3e3e42] mx-1 self-center"></div>
|
||||||
|
|
||||||
|
{/* Lists */}
|
||||||
|
<button
|
||||||
|
onClick={insertBulletList}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Bullet List"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
• List
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={insertNumberedList}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Numbered List"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
1. List
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={insertCodeBlock}
|
||||||
|
className="px-3 py-1.5 text-sm font-mono bg-[#2d2d30] hover:bg-[#3e3e42] text-[#4db8ff] rounded transition-colors"
|
||||||
|
title="Code Block"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{'{ }'}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="w-px h-6 bg-[#3e3e42] mx-1 self-center"></div>
|
||||||
|
|
||||||
|
{/* Table */}
|
||||||
|
<div className="relative">
|
||||||
|
<button
|
||||||
|
onClick={() => setShowTablePicker(!showTablePicker)}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="표 삽입"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
⊞
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{showTablePicker && (
|
||||||
|
<div className="absolute top-full left-0 mt-1 p-2 bg-[#252526] border border-[#3e3e42] rounded shadow-lg z-20">
|
||||||
|
<div className="text-xs text-[#9d9d9d] mb-2 text-center">
|
||||||
|
{tableSize.rows > 0 && tableSize.cols > 0
|
||||||
|
? `${tableSize.rows} x ${tableSize.cols} 표 삽입`
|
||||||
|
: '표 삽입'}
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-0.5">
|
||||||
|
{Array.from({ length: 8 }, (_, row) => (
|
||||||
|
<div key={row} className="flex gap-0.5">
|
||||||
|
{Array.from({ length: 10 }, (_, col) => (
|
||||||
|
<div
|
||||||
|
key={col}
|
||||||
|
className={`w-5 h-5 border border-[#3e3e42] cursor-pointer transition-colors ${
|
||||||
|
row < tableSize.rows && col < tableSize.cols
|
||||||
|
? 'bg-[#0078d4]'
|
||||||
|
: 'bg-[#2d2d30] hover:bg-[#3e3e42]'
|
||||||
|
}`}
|
||||||
|
onMouseEnter={() => setTableSize({ rows: row + 1, cols: col + 1 })}
|
||||||
|
onClick={() => insertTable(row + 1, col + 1)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Cell Background Color */}
|
||||||
|
<div className="relative">
|
||||||
|
<button
|
||||||
|
onClick={() => setShowColorPicker(!showColorPicker)}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="셀 배경색 (셀을 선택하세요)"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
🎨
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{showColorPicker && (
|
||||||
|
<div className="absolute top-full left-0 mt-1 p-3 bg-[#252526] border border-[#3e3e42] rounded shadow-lg z-20 min-w-[200px]">
|
||||||
|
<div className="text-xs text-[#9d9d9d] mb-2">셀 배경색</div>
|
||||||
|
<div className="grid grid-cols-3 gap-2">
|
||||||
|
{CELL_COLORS.map((color) => (
|
||||||
|
<button
|
||||||
|
key={color.value}
|
||||||
|
onClick={() => setCellBackgroundColor(color.value)}
|
||||||
|
className="px-2 py-1.5 text-xs rounded hover:bg-[#3e3e42] transition-colors text-left"
|
||||||
|
style={{ backgroundColor: color.value === 'transparent' ? '#2d2d30' : color.value }}
|
||||||
|
title={color.name}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<span className={color.value === 'transparent' ? 'text-[#e4e4e4]' : 'text-[#1e1e1e]'}>
|
||||||
|
{color.name}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-px h-6 bg-[#3e3e42] mx-1 self-center"></div>
|
||||||
|
|
||||||
|
{/* Alignment */}
|
||||||
|
<button
|
||||||
|
onClick={formatAlignLeft}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Align Left"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
≡
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={formatAlignCenter}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Align Center"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
≣
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={formatAlignRight}
|
||||||
|
className="px-3 py-1.5 text-sm bg-[#2d2d30] hover:bg-[#3e3e42] text-[#e4e4e4] rounded transition-colors"
|
||||||
|
title="Align Right"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
≡
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError(error: Error) {
|
||||||
|
console.error('Lexical Error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LexicalEditor({ initialContent, onChange, placeholder = '내용을 입력하세요...' }: LexicalEditorProps) {
|
||||||
|
const [fontFamily, setFontFamily] = useState(FONT_FAMILIES[0].value);
|
||||||
|
const [fontSize, setFontSize] = useState(FONT_SIZES[3].value); // Default: 16px
|
||||||
|
|
||||||
|
const initialConfig = {
|
||||||
|
namespace: 'WikiEditor',
|
||||||
|
theme: editorTheme,
|
||||||
|
onError,
|
||||||
|
nodes: [
|
||||||
|
HeadingNode,
|
||||||
|
ListNode,
|
||||||
|
ListItemNode,
|
||||||
|
QuoteNode,
|
||||||
|
CodeNode,
|
||||||
|
CodeHighlightNode,
|
||||||
|
LinkNode,
|
||||||
|
AutoLinkNode,
|
||||||
|
TableNode,
|
||||||
|
TableCellNode,
|
||||||
|
TableRowNode,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative">
|
||||||
|
<LexicalComposer initialConfig={initialConfig}>
|
||||||
|
<div className="relative">
|
||||||
|
<ToolbarPlugin
|
||||||
|
fontFamily={fontFamily}
|
||||||
|
setFontFamily={setFontFamily}
|
||||||
|
fontSize={fontSize}
|
||||||
|
setFontSize={setFontSize}
|
||||||
|
/>
|
||||||
|
<RichTextPlugin
|
||||||
|
contentEditable={
|
||||||
|
<ContentEditable
|
||||||
|
className="min-h-[400px] w-full px-4 py-2.5 bg-[#2d2d30] border border-[#3e3e42] rounded rounded-t-none text-[#e4e4e4] focus:outline-none focus:border-[#0078d4] focus:ring-1 focus:ring-[#0078d4] text-sm overflow-y-auto"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
placeholder={
|
||||||
|
<div className="absolute top-2.5 left-4 text-[#9d9d9d] pointer-events-none text-sm">
|
||||||
|
{placeholder}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
ErrorBoundary={LexicalErrorBoundary}
|
||||||
|
/>
|
||||||
|
<HistoryPlugin />
|
||||||
|
<ListPlugin />
|
||||||
|
<LinkPlugin />
|
||||||
|
<TablePlugin hasCellMerge={true} hasCellBackgroundColor={true} />
|
||||||
|
<TableResizerPlugin />
|
||||||
|
<CodeHighlightPlugin />
|
||||||
|
<CodeActionMenuPlugin />
|
||||||
|
<CodeLanguagePlugin />
|
||||||
|
<OnChangePluginWrapper onChange={onChange} />
|
||||||
|
<InitialContentPlugin content={initialContent} />
|
||||||
|
<HeadingIdPlugin />
|
||||||
|
<AutoFocusPlugin />
|
||||||
|
</div>
|
||||||
|
</LexicalComposer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
||||||
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
||||||
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
||||||
|
import { HeadingNode, QuoteNode } from '@lexical/rich-text';
|
||||||
|
import { ListNode, ListItemNode } from '@lexical/list';
|
||||||
|
import { CodeNode, CodeHighlightNode } from '@lexical/code';
|
||||||
|
import { registerCodeHighlighting } from '@lexical/code';
|
||||||
|
import { CodeLanguagePlugin } from './CodeLanguagePlugin';
|
||||||
|
import { CodeActionMenuPlugin } from './CodeActionMenuPlugin';
|
||||||
|
import { LinkNode, AutoLinkNode } from '@lexical/link';
|
||||||
|
import { TableNode, TableCellNode, TableRowNode } from '@lexical/table';
|
||||||
|
import { $getRoot, $createParagraphNode, $createTextNode } from 'lexical';
|
||||||
|
|
||||||
|
const viewerTheme = {
|
||||||
|
paragraph: 'mb-4 leading-relaxed text-[#e4e4e4]',
|
||||||
|
heading: {
|
||||||
|
h1: 'text-3xl font-bold mb-4 mt-6 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
h2: 'text-2xl font-bold mb-3 mt-5 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
h3: 'text-xl font-semibold mb-2 mt-4 text-[#e4e4e4] scroll-mt-20',
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
ul: 'list-disc ml-6 mb-4 text-[#e4e4e4]',
|
||||||
|
ol: 'list-decimal ml-6 mb-4 text-[#e4e4e4]',
|
||||||
|
listitem: 'mb-1',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
bold: 'font-bold',
|
||||||
|
italic: 'italic',
|
||||||
|
underline: 'underline',
|
||||||
|
code: 'bg-[#1e1e1e] px-1.5 py-0.5 rounded font-mono text-sm text-[#4db8ff]',
|
||||||
|
},
|
||||||
|
code: 'relative bg-[#1e1e1e] border border-[#3e3e42] rounded-md font-mono text-sm mb-4 block',
|
||||||
|
codeHighlight: {
|
||||||
|
atrule: 'token atrule',
|
||||||
|
attr: 'token attr',
|
||||||
|
boolean: 'token boolean',
|
||||||
|
builtin: 'token builtin',
|
||||||
|
cdata: 'token cdata',
|
||||||
|
char: 'token char',
|
||||||
|
class: 'token class-name',
|
||||||
|
'class-name': 'token class-name',
|
||||||
|
comment: 'token comment',
|
||||||
|
constant: 'token constant',
|
||||||
|
deleted: 'token deleted',
|
||||||
|
doctype: 'token doctype',
|
||||||
|
entity: 'token entity',
|
||||||
|
function: 'token function',
|
||||||
|
important: 'token important',
|
||||||
|
inserted: 'token inserted',
|
||||||
|
keyword: 'token keyword',
|
||||||
|
namespace: 'token namespace',
|
||||||
|
number: 'token number',
|
||||||
|
operator: 'token operator',
|
||||||
|
prolog: 'token prolog',
|
||||||
|
property: 'token property',
|
||||||
|
punctuation: 'token punctuation',
|
||||||
|
regex: 'token regex',
|
||||||
|
selector: 'token selector',
|
||||||
|
string: 'token string',
|
||||||
|
symbol: 'token symbol',
|
||||||
|
tag: 'token tag',
|
||||||
|
url: 'token url',
|
||||||
|
variable: 'token variable',
|
||||||
|
},
|
||||||
|
link: 'text-[#4db8ff] hover:text-[#8cd7ff] underline cursor-pointer',
|
||||||
|
table: 'border-collapse table-auto w-full my-4',
|
||||||
|
tableCell: 'border border-[#3e3e42] px-3 py-2 text-[#e4e4e4] min-w-[100px]',
|
||||||
|
tableCellHeader: 'border border-[#3e3e42] px-3 py-2 text-[#e4e4e4] font-bold bg-[#2d2d30]',
|
||||||
|
};
|
||||||
|
|
||||||
|
interface LexicalViewerProps {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function HeadingIdPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Add data attribute and ID to heading elements for TOC
|
||||||
|
const updateHeadings = () => {
|
||||||
|
const headings = document.querySelectorAll('.lexical-viewer h1, .lexical-viewer h2, .lexical-viewer h3');
|
||||||
|
headings.forEach((heading, index) => {
|
||||||
|
if (heading instanceof HTMLElement) {
|
||||||
|
heading.setAttribute('data-lexical-heading', 'true');
|
||||||
|
if (!heading.id) {
|
||||||
|
const text = heading.textContent || '';
|
||||||
|
heading.id = `heading-${index}-${text.toLowerCase().replace(/\s+/g, '-').slice(0, 30)}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial update with delay
|
||||||
|
setTimeout(updateHeadings, 100);
|
||||||
|
|
||||||
|
// Also register mutation listener
|
||||||
|
const unregister = editor.registerMutationListener(HeadingNode, () => {
|
||||||
|
setTimeout(updateHeadings, 50);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update periodically as backup
|
||||||
|
const interval = setInterval(updateHeadings, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unregister();
|
||||||
|
clearInterval(interval);
|
||||||
|
};
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ContentPlugin({ content }: { content: string }) {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Register code highlighting
|
||||||
|
return registerCodeHighlighting(editor);
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
// Try to parse as JSON first (new format with formatting)
|
||||||
|
const editorState = editor.parseEditorState(content);
|
||||||
|
editor.setEditorState(editorState);
|
||||||
|
} catch {
|
||||||
|
// Fallback to plain text (legacy format)
|
||||||
|
editor.update(() => {
|
||||||
|
const root = $getRoot();
|
||||||
|
root.clear();
|
||||||
|
|
||||||
|
const lines = content.split('\n');
|
||||||
|
lines.forEach((line) => {
|
||||||
|
const paragraph = $createParagraphNode();
|
||||||
|
if (line.trim() === '') {
|
||||||
|
// Empty line for spacing
|
||||||
|
paragraph.append($createTextNode(''));
|
||||||
|
} else {
|
||||||
|
const text = $createTextNode(line);
|
||||||
|
paragraph.append(text);
|
||||||
|
}
|
||||||
|
root.append(paragraph);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make editor read-only
|
||||||
|
editor.setEditable(false);
|
||||||
|
}, [editor, content]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError(error: Error) {
|
||||||
|
console.error('Lexical Viewer Error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LexicalViewer({ content }: LexicalViewerProps) {
|
||||||
|
const initialConfig = {
|
||||||
|
namespace: 'WikiViewer',
|
||||||
|
theme: viewerTheme,
|
||||||
|
onError,
|
||||||
|
editable: false,
|
||||||
|
nodes: [
|
||||||
|
HeadingNode,
|
||||||
|
ListNode,
|
||||||
|
ListItemNode,
|
||||||
|
QuoteNode,
|
||||||
|
CodeNode,
|
||||||
|
CodeHighlightNode,
|
||||||
|
LinkNode,
|
||||||
|
AutoLinkNode,
|
||||||
|
TableNode,
|
||||||
|
TableCellNode,
|
||||||
|
TableRowNode,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="prose prose-invert max-w-none">
|
||||||
|
<LexicalComposer initialConfig={initialConfig}>
|
||||||
|
<RichTextPlugin
|
||||||
|
contentEditable={
|
||||||
|
<ContentEditable
|
||||||
|
className="text-[#e4e4e4] text-base focus:outline-none lexical-viewer"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
placeholder={null}
|
||||||
|
ErrorBoundary={LexicalErrorBoundary}
|
||||||
|
/>
|
||||||
|
<ContentPlugin content={content} />
|
||||||
|
<HeadingIdPlugin />
|
||||||
|
<CodeLanguagePlugin />
|
||||||
|
<CodeActionMenuPlugin />
|
||||||
|
</LexicalComposer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
||||||
|
|
||||||
|
export function TableResizerPlugin() {
|
||||||
|
const [editor] = useLexicalComposerContext();
|
||||||
|
const isResizingCell = useRef(false);
|
||||||
|
const isResizingTable = useRef(false);
|
||||||
|
const currentCell = useRef<HTMLTableCellElement | null>(null);
|
||||||
|
const currentTable = useRef<HTMLTableElement | null>(null);
|
||||||
|
const startX = useRef(0);
|
||||||
|
const startWidth = useRef(0);
|
||||||
|
const originalWidths = useRef<number[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const editorElement = editor.getRootElement();
|
||||||
|
if (!editorElement) return;
|
||||||
|
|
||||||
|
const handleMouseDown = (e: MouseEvent) => {
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
|
||||||
|
const cell = target.closest('td, th') as HTMLTableCellElement;
|
||||||
|
if (!cell) return;
|
||||||
|
|
||||||
|
const table = cell.closest('table') as HTMLTableElement;
|
||||||
|
if (!table) return;
|
||||||
|
|
||||||
|
const rect = cell.getBoundingClientRect();
|
||||||
|
const isNearRightEdge = e.clientX > rect.right - 6;
|
||||||
|
|
||||||
|
if (!isNearRightEdge) return;
|
||||||
|
|
||||||
|
// 현재 행의 모든 셀 가져오기
|
||||||
|
const row = cell.parentElement as HTMLTableRowElement;
|
||||||
|
const cells = Array.from(row.cells);
|
||||||
|
const cellIndex = cells.indexOf(cell);
|
||||||
|
const isLastCell = cellIndex === cells.length - 1;
|
||||||
|
|
||||||
|
if (isLastCell) {
|
||||||
|
// 마지막 셀: 표 전체 크기 조정 (왼쪽으로만)
|
||||||
|
e.preventDefault();
|
||||||
|
isResizingTable.current = true;
|
||||||
|
currentTable.current = table;
|
||||||
|
startX.current = e.clientX;
|
||||||
|
startWidth.current = table.offsetWidth;
|
||||||
|
|
||||||
|
// 모든 열의 현재 너비 저장 (비율 유지용)
|
||||||
|
const firstRow = table.rows[0];
|
||||||
|
originalWidths.current = Array.from(firstRow.cells).map(c => c.offsetWidth);
|
||||||
|
|
||||||
|
document.body.style.cursor = 'col-resize';
|
||||||
|
document.body.style.userSelect = 'none';
|
||||||
|
} else {
|
||||||
|
// 일반 셀: 개별 열 크기 조정
|
||||||
|
e.preventDefault();
|
||||||
|
isResizingCell.current = true;
|
||||||
|
currentCell.current = cell;
|
||||||
|
startX.current = e.clientX;
|
||||||
|
startWidth.current = cell.offsetWidth;
|
||||||
|
|
||||||
|
document.body.style.cursor = 'col-resize';
|
||||||
|
document.body.style.userSelect = 'none';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseMove = (e: MouseEvent) => {
|
||||||
|
if (isResizingTable.current && currentTable.current) {
|
||||||
|
// 표 전체 크기 조정 (왼쪽으로만)
|
||||||
|
const diff = e.clientX - startX.current;
|
||||||
|
|
||||||
|
// 오른쪽으로 늘리기 방지 (diff > 0이면 오른쪽)
|
||||||
|
if (diff > 0) return;
|
||||||
|
|
||||||
|
const newTableWidth = Math.max(300, startWidth.current + diff); // 최소 300px
|
||||||
|
const scale = newTableWidth / startWidth.current;
|
||||||
|
|
||||||
|
// 표 너비 설정
|
||||||
|
currentTable.current.style.width = `${newTableWidth}px`;
|
||||||
|
currentTable.current.style.margin = '0 auto'; // 가운데 정렬
|
||||||
|
|
||||||
|
// 모든 행의 셀 너비를 비율에 맞게 조정
|
||||||
|
Array.from(currentTable.current.rows).forEach(row => {
|
||||||
|
Array.from(row.cells).forEach((cell, idx) => {
|
||||||
|
const originalWidth = originalWidths.current[idx];
|
||||||
|
const newWidth = originalWidth * scale;
|
||||||
|
cell.style.width = `${newWidth}px`;
|
||||||
|
cell.style.minWidth = `${newWidth}px`;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else if (isResizingCell.current && currentCell.current) {
|
||||||
|
// 개별 셀 크기 조정
|
||||||
|
const diff = e.clientX - startX.current;
|
||||||
|
const newWidth = Math.max(50, startWidth.current + diff);
|
||||||
|
|
||||||
|
currentCell.current.style.width = `${newWidth}px`;
|
||||||
|
currentCell.current.style.minWidth = `${newWidth}px`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseUp = () => {
|
||||||
|
if (isResizingCell.current || isResizingTable.current) {
|
||||||
|
isResizingCell.current = false;
|
||||||
|
isResizingTable.current = false;
|
||||||
|
currentCell.current = null;
|
||||||
|
currentTable.current = null;
|
||||||
|
originalWidths.current = [];
|
||||||
|
document.body.style.cursor = '';
|
||||||
|
document.body.style.userSelect = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
editorElement.addEventListener('mousedown', handleMouseDown);
|
||||||
|
document.addEventListener('mousemove', handleMouseMove);
|
||||||
|
document.addEventListener('mouseup', handleMouseUp);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
editorElement.removeEventListener('mousedown', handleMouseDown);
|
||||||
|
document.removeEventListener('mousemove', handleMouseMove);
|
||||||
|
document.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
};
|
||||||
|
}, [editor]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
import './styles.css';
|
||||||
|
|
||||||
|
export { LexicalEditor } from './editor/LexicalEditor';
|
||||||
|
export type { LexicalEditorProps } from './editor/LexicalEditor';
|
||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Asta+Sans:wght@300..800&family=Chiron+GoRound+TC:wght@200..900&family=Gothic+A1&family=Gowun+Batang&family=Gowun+Dodum&family=Noto+Sans+KR:wght@100..900&family=Noto+Serif+KR:wght@200..900&display=swap');
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
|
||||||
|
/* Lexical 에디터와 뷰어에서 인라인 스타일 허용 */
|
||||||
|
.lexical-viewer span[style*="font-family"],
|
||||||
|
[contenteditable="true"] span[style*="font-family"] {
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 테이블 스타일 */
|
||||||
|
[contenteditable="true"] table {
|
||||||
|
table-layout: auto;
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 테이블 셀 리사이즈 가능하게 */
|
||||||
|
[contenteditable="true"] table td,
|
||||||
|
[contenteditable="true"] table th {
|
||||||
|
position: relative;
|
||||||
|
overflow: visible;
|
||||||
|
-webkit-user-select: text;
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 셀 선택 시 부드러운 전환 */
|
||||||
|
[contenteditable="true"] table td,
|
||||||
|
[contenteditable="true"] table th {
|
||||||
|
transition: background-color 0.15s ease, outline 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 테이블 열 리사이저 (경계선) */
|
||||||
|
[contenteditable="true"] table td:not(:last-child),
|
||||||
|
[contenteditable="true"] table th:not(:last-child) {
|
||||||
|
border-right: 2px solid #3e3e42;
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
[contenteditable="true"] table td:not(:last-child):hover,
|
||||||
|
[contenteditable="true"] table th:not(:last-child):hover {
|
||||||
|
border-right: 3px solid #0078d4;
|
||||||
|
cursor: col-resize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 마지막 셀: 표 전체 크기 조정 (왼쪽으로만) */
|
||||||
|
[contenteditable="true"] table td:last-child,
|
||||||
|
[contenteditable="true"] table th:last-child {
|
||||||
|
border-right: 2px solid #3e3e42;
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
[contenteditable="true"] table td:last-child:hover,
|
||||||
|
[contenteditable="true"] table th:last-child:hover {
|
||||||
|
border-right: 4px solid #ff9800;
|
||||||
|
cursor: ew-resize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 열 크기 조정 핸들 추가 */
|
||||||
|
[contenteditable="true"] table td::after,
|
||||||
|
[contenteditable="true"] table th::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
right: -3px;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 6px;
|
||||||
|
cursor: col-resize;
|
||||||
|
z-index: 5;
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
[contenteditable="true"] table td:not(:last-child):hover::after,
|
||||||
|
[contenteditable="true"] table th:not(:last-child):hover::after {
|
||||||
|
background-color: rgba(0, 120, 212, 0.3);
|
||||||
|
z-index: 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 마지막 셀 핸들은 주황색 */
|
||||||
|
[contenteditable="true"] table td:last-child:hover::after,
|
||||||
|
[contenteditable="true"] table th:last-child:hover::after {
|
||||||
|
background-color: rgba(255, 152, 0, 0.4);
|
||||||
|
cursor: ew-resize;
|
||||||
|
z-index: 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lexical 선택된 셀 - 클래스 기반 */
|
||||||
|
[contenteditable="true"] table td.table-cell-selected,
|
||||||
|
[contenteditable="true"] table th.table-cell-selected,
|
||||||
|
[contenteditable="true"] table td.selected,
|
||||||
|
[contenteditable="true"] table th.selected,
|
||||||
|
[contenteditable="true"] table td[class*="selected"],
|
||||||
|
[contenteditable="true"] table th[class*="selected"] {
|
||||||
|
background-color: rgba(0, 120, 212, 0.3) !important;
|
||||||
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lexical 포커스된 셀 */
|
||||||
|
[contenteditable="true"] table td:focus-within,
|
||||||
|
[contenteditable="true"] table th:focus-within {
|
||||||
|
outline: 2px solid #0078d4;
|
||||||
|
outline-offset: -1px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 셀 내부 콘텐츠가 선택된 경우 */
|
||||||
|
[contenteditable="true"] table td:has(:focus),
|
||||||
|
[contenteditable="true"] table th:has(:focus) {
|
||||||
|
background-color: rgba(0, 120, 212, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 셀 내부 콘텐츠 영역 */
|
||||||
|
[contenteditable="true"] table td,
|
||||||
|
[contenteditable="true"] table th {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 텍스트 드래그 선택 시 하이라이트 (기본 브라우저 선택) */
|
||||||
|
[contenteditable="true"] table ::selection {
|
||||||
|
background-color: rgba(0, 120, 212, 0.6) !important;
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
[contenteditable="true"] table::-moz-selection {
|
||||||
|
background-color: rgba(0, 120, 212, 0.6) !important;
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lexical 테이블 셀 선택 오버레이 제거 (기본 스타일과 충돌 방지) */
|
||||||
|
[contenteditable="true"] table td .TableCellResizer,
|
||||||
|
[contenteditable="true"] table th .TableCellResizer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 테이블 전체 선택 스타일 */
|
||||||
|
[contenteditable="true"] table[data-table-selected] td,
|
||||||
|
[contenteditable="true"] table[data-table-selected] th {
|
||||||
|
background-color: rgba(0, 120, 212, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lexical 기본 선택 하이라이트 오버라이드 */
|
||||||
|
[contenteditable="true"] .PlaygroundEditorTheme__tableCellSelected {
|
||||||
|
background-color: rgba(0, 120, 212, 0.25) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 셀 배경색이 설정된 경우 텍스트 색상 보정 */
|
||||||
|
[contenteditable="true"] table td[style*="background-color"],
|
||||||
|
[contenteditable="true"] table th[style*="background-color"],
|
||||||
|
.lexical-viewer table td[style*="background-color"],
|
||||||
|
.lexical-viewer table th[style*="background-color"] {
|
||||||
|
color: #1e1e1e;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 투명 배경색은 원래 텍스트 색상 유지 */
|
||||||
|
[contenteditable="true"] table td[style*="transparent"],
|
||||||
|
[contenteditable="true"] table th[style*="transparent"],
|
||||||
|
.lexical-viewer table td[style*="transparent"],
|
||||||
|
.lexical-viewer table th[style*="transparent"] {
|
||||||
|
color: #e4e4e4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 뷰어의 테이블 */
|
||||||
|
.lexical-viewer table {
|
||||||
|
table-layout: auto;
|
||||||
|
width: 100%;
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 코드 블록 스타일 */
|
||||||
|
code[data-language] {
|
||||||
|
display: block !important;
|
||||||
|
position: relative;
|
||||||
|
background-color: #1e1e1e;
|
||||||
|
border: 1px solid #3e3e42;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 3.5rem 1rem 1rem 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
overflow-x: auto;
|
||||||
|
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #e4e4e4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CSS로 헤더 배경 생성 */
|
||||||
|
code[data-language]::before {
|
||||||
|
content: attr(data-language-label);
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background-color: #2d2d30;
|
||||||
|
border-bottom: 1px solid #3e3e42;
|
||||||
|
border-radius: 6px 6px 0 0;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #e4e4e4;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 플로팅 복사 버튼 */
|
||||||
|
.floating-copy-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 0.5rem;
|
||||||
|
right: 1rem;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
background: #3e3e42;
|
||||||
|
color: #e4e4e4;
|
||||||
|
border: 1px solid #4e4e52;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
z-index: 200;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floating-copy-btn:hover {
|
||||||
|
background: #4e4e52;
|
||||||
|
border-color: #5e5e62;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prism 토큰 색상 커스터마이징 (다크 테마) */
|
||||||
|
.token.comment,
|
||||||
|
.token.prolog,
|
||||||
|
.token.doctype,
|
||||||
|
.token.cdata {
|
||||||
|
color: #6a9955;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.punctuation {
|
||||||
|
color: #d4d4d4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.property,
|
||||||
|
.token.tag,
|
||||||
|
.token.boolean,
|
||||||
|
.token.number,
|
||||||
|
.token.constant,
|
||||||
|
.token.symbol,
|
||||||
|
.token.deleted {
|
||||||
|
color: #b5cea8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.selector,
|
||||||
|
.token.attr-name,
|
||||||
|
.token.string,
|
||||||
|
.token.char,
|
||||||
|
.token.builtin,
|
||||||
|
.token.inserted {
|
||||||
|
color: #ce9178;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.operator,
|
||||||
|
.token.entity,
|
||||||
|
.token.url,
|
||||||
|
.language-css .token.string,
|
||||||
|
.style .token.string {
|
||||||
|
color: #d4d4d4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.atrule,
|
||||||
|
.token.attr-value,
|
||||||
|
.token.keyword {
|
||||||
|
color: #569cd6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.function,
|
||||||
|
.token.class-name {
|
||||||
|
color: #dcdcaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token.regex,
|
||||||
|
.token.important,
|
||||||
|
.token.variable {
|
||||||
|
color: #d16969;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 코드 블록 선택 스타일 */
|
||||||
|
[contenteditable="true"] pre::selection,
|
||||||
|
[contenteditable="true"] pre code::selection {
|
||||||
|
background-color: rgba(0, 120, 212, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
@apply border-[#3e3e42];
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
@apply text-[#4db8ff] hover:text-[#8cd7ff] transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
@apply bg-[#2d2d30] px-1 py-0.5 rounded text-sm;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: ['./src/**/*.{ts,tsx}'],
|
||||||
|
prefix: 'dhe-',
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
@@ -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"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import react from '@vitejs/plugin-react';
|
||||||
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react(), tailwindcss()],
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: 'src/index.tsx',
|
||||||
|
formats: ['es'],
|
||||||
|
fileName: () => 'index.js', // 🔥 이거 중요
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
external: [
|
||||||
|
'react',
|
||||||
|
'react-dom',
|
||||||
|
'lexical',
|
||||||
|
'@lexical/react',
|
||||||
|
'@lexical/html',
|
||||||
|
'@lexical/list',
|
||||||
|
'@lexical/markdown',
|
||||||
|
'@lexical/rich-text',
|
||||||
|
'@lexical/selection',
|
||||||
|
'@lexical/utils',
|
||||||
|
'@lexkit/editor',
|
||||||
|
],
|
||||||
|
output: {
|
||||||
|
globals: {
|
||||||
|
react: 'React',
|
||||||
|
'react-dom': 'ReactDOM'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in new issue
Block a user