Skip to content

Commit faf1a09

Browse files
refactor: solved the bug mentioned in #246 (#247)
Co-authored-by: Sanchit Bajaj <55249639+Sanchitbajaj02@users.noreply.github.com>
1 parent 67d4e6c commit faf1a09

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/components/Editor/EditorMenuBar.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,102 +21,130 @@ import { Codepen } from "react-feather";
2121
const EditorMenubar = ({ editor }: { editor: Editor }) => {
2222
const MenuBarFunctions = [
2323
{
24+
id: 1,
2425
title: "bold",
2526
onFunction: () => editor.chain().focus().toggleBold().run(),
2627
offFunction: () => !editor.can().chain().focus().toggleBold().run(),
2728
icon: Bold,
2829
},
2930
{
31+
id: 2,
3032
title: "italic",
3133
onFunction: () => editor.chain().focus().toggleItalic().run(),
3234
offFunction: () => !editor.can().chain().focus().toggleItalic().run(),
3335
icon: Italic,
3436
},
3537
{
38+
id: 3,
3639
title: "strike",
3740
onFunction: () => editor.chain().focus().toggleStrike().run(),
3841
offFunction: () => !editor.can().chain().focus().toggleStrike().run(),
3942
icon: Strikethrough,
4043
},
4144
{
45+
id: 4,
46+
4247
title: "code",
4348
onFunction: () => editor.chain().focus().toggleCode().run(),
4449
offFunction: () => !editor.can().chain().focus().toggleCode().run(),
4550
icon: Code,
4651
},
4752
{
53+
id: 5,
54+
4855
title: `heading`,
4956
attribute: { level: 1 },
5057
onFunction: () => editor.chain().focus().toggleHeading({ level: 1 }).run(),
5158
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 1 }).run(),
5259
icon: Heading1,
5360
},
5461
{
62+
id: 6,
63+
5564
title: "heading",
5665
attribute: { level: 2 } || null,
5766
onFunction: () => editor.chain().focus().toggleHeading({ level: 2 }).run(),
5867
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 2 }).run(),
5968
icon: Heading2,
6069
},
6170
{
71+
id: 7,
72+
6273
title: "heading",
6374
attribute: { level: 3 } || null,
6475
onFunction: () => editor.chain().focus().toggleHeading({ level: 3 }).run(),
6576
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 3 }).run(),
6677
icon: Heading3,
6778
},
6879
{
80+
id: 8,
81+
6982
title: "heading",
7083
attribute: { level: 4 } || null,
7184
onFunction: () => editor.chain().focus().toggleHeading({ level: 4 }).run(),
7285
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 4 }).run(),
7386
icon: Heading4,
7487
},
7588
{
89+
id: 9,
7690
title: "heading",
7791
attribute: { level: 5 } || null,
7892
onFunction: () => editor.chain().focus().toggleHeading({ level: 5 }).run(),
7993
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 5 }).run(),
8094
icon: Heading5,
8195
},
8296
{
97+
id: 10,
98+
8399
title: "heading",
84100
attribute: { level: 6 } || null,
85101
onFunction: () => editor.chain().focus().toggleHeading({ level: 6 }).run(),
86102
offFunction: () => !editor.can().chain().focus().toggleHeading({ level: 6 }).run(),
87103
icon: Heading6,
88104
},
89105
{
106+
id: 11,
107+
90108
title: "bulletList",
91109
onFunction: () => editor.chain().focus().toggleBulletList().run(),
92110
offFunction: () => !editor.can().chain().focus().toggleBulletList().run(),
93111
icon: List,
94112
},
95113
{
114+
id: 12,
115+
96116
title: "orderedList",
97117
onFunction: () => editor.chain().focus().toggleOrderedList().run(),
98118
offFunction: () => !editor.can().chain().focus().toggleOrderedList().run(),
99119
icon: ListOrdered,
100120
},
101121
{
122+
id: 13,
123+
102124
title: "codeBlock",
103125
onFunction: () => editor.chain().focus().toggleCodeBlock().run(),
104126
offFunction: () => !editor.can().chain().focus().toggleCodeBlock().run(),
105127
icon: Codepen,
106128
},
107129
{
130+
id: 14,
131+
108132
title: "blockquote",
109133
onFunction: () => editor.chain().focus().toggleBlockquote().run(),
110134
offFunction: () => !editor.can().chain().focus().toggleBlockquote().run(),
111135
icon: Quote,
112136
},
113137
{
138+
id: 15,
139+
114140
title: "undo",
115141
onFunction: () => editor.chain().focus().undo().run(),
116142
offFunction: () => !editor.can().chain().focus().undo().run(),
117143
icon: Undo,
118144
},
119145
{
146+
id: 16,
147+
120148
title: "redo",
121149
onFunction: () => editor.chain().focus().redo().run(),
122150
offFunction: () => !editor.can().chain().focus().redo().run(),
@@ -130,7 +158,7 @@ const EditorMenubar = ({ editor }: { editor: Editor }) => {
130158
{MenuBarFunctions.length > 0 &&
131159
MenuBarFunctions.map((menu) => (
132160
<button
133-
key={menu.title}
161+
key={menu.id}
134162
role="button"
135163
onClick={(e) => {
136164
e.preventDefault();

src/components/Editor/Markdown.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ const Markdown = ({ editorState, setEditorState }: EditorProps) => {
107107
<BubbleMenu className="bubble-menu" tippyOptions={{ duration: 100 }} editor={editor}>
108108
<div className="flex gap-1 bg-white px-4 py-1 text-black rounded-sm">
109109
{BubbleMenuFunctions.length > 0 &&
110-
BubbleMenuFunctions.map((func) => (
110+
BubbleMenuFunctions.map((func, index) => (
111111
<button
112-
key={func.title}
112+
key={index}
113113
role="button"
114114
onClick={(e) => {
115115
e.preventDefault();
@@ -132,9 +132,9 @@ const Markdown = ({ editorState, setEditorState }: EditorProps) => {
132132
<FloatingMenu className="floating-menu" tippyOptions={{ duration: 100 }} editor={editor}>
133133
<div className="flex gap-1 bg-white px-4 py-1 text-black rounded-sm">
134134
{FloatingMenuFunctions.length > 0 &&
135-
FloatingMenuFunctions.map((func) => (
135+
FloatingMenuFunctions.map((func, index) => (
136136
<button
137-
key={func.title}
137+
key={index}
138138
role="button"
139139
onClick={(e) => {
140140
e.preventDefault();

0 commit comments

Comments
 (0)