.
This commit is contained in:
1 parent
120f150ee3
commit
b0140fbafb
9 files changed
+742
-8
No files matched your search
@@ -14,9 +14,13 @@ 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 } from 'lexical';
|
||||
import { INSERT_TABLE_COMMAND } from '@lexical/table';
|
||||
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';
|
||||
@@ -40,11 +44,46 @@ const editorTheme = {
|
||||
underline: 'underline',
|
||||
code: 'bg-[#1e1e1e] px-1.5 py-0.5 rounded font-mono text-sm text-[#4db8ff]',
|
||||
},
|
||||
code: 'bg-[#1e1e1e] p-4 rounded font-mono text-sm text-[#e4e4e4] mb-2 block overflow-x-auto',
|
||||
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 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]',
|
||||
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',
|
||||
};
|
||||
|
||||
interface LexicalEditorProps {
|
||||
@@ -77,6 +116,23 @@ const FONT_SIZES = [
|
||||
{ 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
|
||||
@@ -182,6 +238,7 @@ function ToolbarPlugin({ fontFamily, setFontFamily, fontSize, setFontSize }: Too
|
||||
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;
|
||||
@@ -446,6 +503,28 @@ function ToolbarPlugin({ fontFamily, setFontFamily, fontSize, setFontSize }: Too
|
||||
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 */}
|
||||
@@ -628,6 +707,40 @@ function ToolbarPlugin({ fontFamily, setFontFamily, fontSize, setFontSize }: Too
|
||||
)}
|
||||
</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 */}
|
||||
@@ -712,7 +825,11 @@ export function LexicalEditor({ initialContent, onChange, placeholder = '내용
|
||||
<HistoryPlugin />
|
||||
<ListPlugin />
|
||||
<LinkPlugin />
|
||||
<TablePlugin />
|
||||
<TablePlugin hasCellMerge={true} hasCellBackgroundColor={true} />
|
||||
<TableResizerPlugin />
|
||||
<CodeHighlightPlugin />
|
||||
<CodeActionMenuPlugin />
|
||||
<CodeLanguagePlugin />
|
||||
<OnChangePluginWrapper onChange={onChange} />
|
||||
<InitialContentPlugin content={initialContent} />
|
||||
<HeadingIdPlugin />
|
||||
|
||||
Reference in new issue
Block a user