refactor: remove list and divider buttons from RichTextEditor toolbar
This commit is contained in:
@@ -35,7 +35,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
|
|
||||||
const execCommand = (command: string) => {
|
const execCommand = (command: string) => {
|
||||||
editorRef.current?.focus();
|
editorRef.current?.focus();
|
||||||
|
|
||||||
if (command === 'bold') {
|
if (command === 'bold') {
|
||||||
document.execCommand('bold', false);
|
document.execCommand('bold', false);
|
||||||
} else if (command === 'italic') {
|
} else if (command === 'italic') {
|
||||||
@@ -57,7 +57,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
} else if (command === 'redo') {
|
} else if (command === 'redo') {
|
||||||
document.execCommand('redo', false);
|
document.execCommand('redo', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateValue();
|
updateValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
tableHTML += '</tr>';
|
tableHTML += '</tr>';
|
||||||
}
|
}
|
||||||
tableHTML += '</table><p><br></p>';
|
tableHTML += '</table><p><br></p>';
|
||||||
|
|
||||||
if (editorRef.current) {
|
if (editorRef.current) {
|
||||||
editorRef.current.focus();
|
editorRef.current.focus();
|
||||||
document.execCommand('insertHTML', false, tableHTML);
|
document.execCommand('insertHTML', false, tableHTML);
|
||||||
@@ -93,7 +93,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
if (!editorRef.current) return;
|
if (!editorRef.current) return;
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (!selection || selection.rangeCount === 0) return;
|
if (!selection || selection.rangeCount === 0) return;
|
||||||
|
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
let cell = range.commonAncestorContainer;
|
let cell = range.commonAncestorContainer;
|
||||||
while (cell && cell !== editorRef.current) {
|
while (cell && cell !== editorRef.current) {
|
||||||
@@ -114,7 +114,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
if (!editorRef.current) return;
|
if (!editorRef.current) return;
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (!selection || selection.rangeCount === 0) return;
|
if (!selection || selection.rangeCount === 0) return;
|
||||||
|
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
let cell = range.commonAncestorContainer;
|
let cell = range.commonAncestorContainer;
|
||||||
while (cell && cell !== editorRef.current) {
|
while (cell && cell !== editorRef.current) {
|
||||||
@@ -143,7 +143,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
if (!editorRef.current) return;
|
if (!editorRef.current) return;
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (!selection || selection.rangeCount === 0) return;
|
if (!selection || selection.rangeCount === 0) return;
|
||||||
|
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
let cell = range.commonAncestorContainer;
|
let cell = range.commonAncestorContainer;
|
||||||
while (cell && cell !== editorRef.current) {
|
while (cell && cell !== editorRef.current) {
|
||||||
@@ -182,13 +182,13 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
<Underline className="w-4 h-4" />
|
<Underline className="w-4 h-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
<ToolbarDivider />
|
<ToolbarDivider />
|
||||||
<ToolbarButton onClick={() => execCommand('insertUnorderedList')} title="Bullet List">
|
{/* <ToolbarButton onClick={() => execCommand('insertUnorderedList')} title="Bullet List">
|
||||||
<List className="w-4 h-4" />
|
<List className="w-4 h-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
<ToolbarButton onClick={() => execCommand('insertOrderedList')} title="Numbered List">
|
<ToolbarButton onClick={() => execCommand('insertOrderedList')} title="Numbered List">
|
||||||
<ListOrdered className="w-4 h-4" />
|
<ListOrdered className="w-4 h-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
<ToolbarDivider />
|
<ToolbarDivider /> */}
|
||||||
<ToolbarButton onClick={() => execCommand('justifyLeft')} title="Align Left">
|
<ToolbarButton onClick={() => execCommand('justifyLeft')} title="Align Left">
|
||||||
<AlignLeft className="w-4 h-4" />
|
<AlignLeft className="w-4 h-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
@@ -207,7 +207,7 @@ export default function RichTextEditor({ value, onChange, placeholder = 'Enter d
|
|||||||
<div className="absolute top-full left-0 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg p-2 z-50 min-w-[160px]">
|
<div className="absolute top-full left-0 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg p-2 z-50 min-w-[160px]">
|
||||||
<div className="text-xs text-slate-500 mb-2 px-1">Insert Table</div>
|
<div className="text-xs text-slate-500 mb-2 px-1">Insert Table</div>
|
||||||
<div className="grid grid-cols-4 gap-1 mb-2">
|
<div className="grid grid-cols-4 gap-1 mb-2">
|
||||||
{[2, 3, 4, 5].map(rows =>
|
{[2, 3, 4, 5].map(rows =>
|
||||||
<Fragment key={rows}>
|
<Fragment key={rows}>
|
||||||
{[2, 3, 4, 5].map(cols => (
|
{[2, 3, 4, 5].map(cols => (
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user