feat: more editor shortcuts (#338)
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ export const Bold: ICommand = {
|
||||
name: "bold",
|
||||
label: "Bold",
|
||||
icon: "i-mingcute:bold-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "**", append: "**" })
|
||||
},
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ export const Code: ICommand = {
|
||||
name: "code",
|
||||
label: "Inline Code",
|
||||
icon: "i-mingcute:code-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "`", append: "`" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ export const CodeBlock: ICommand = {
|
||||
name: "codeblock",
|
||||
label: "Code Block",
|
||||
icon: "i-mingcute:web-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "```\n", append: "\n```" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { EmojiPicker } from "~/components/common/EmojiPicker"
|
||||
import { ICommand, prependExecute, wrapExecute } from "."
|
||||
|
||||
export const Emoji: ICommand<string> = {
|
||||
name: "emoji",
|
||||
label: "Emoji",
|
||||
icon: "i-mingcute:emoji-2-line",
|
||||
execute: ({ view, payload }) => {
|
||||
wrapExecute({ view, prepend: payload || "", append: "" })
|
||||
},
|
||||
ui: ({ transferPayload }) => (
|
||||
<EmojiPicker onEmojiSelect={(e: any) => transferPayload(e.native)} />
|
||||
),
|
||||
}
|
||||
@@ -4,7 +4,7 @@ export const Heading: ICommand = {
|
||||
name: "heading",
|
||||
label: "Heading",
|
||||
icon: "i-mingcute:heading-2-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
prependExecute({ view, prepend: "## " })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export const Image: ICommand = {
|
||||
name: "upload-image",
|
||||
label: "Upload Image",
|
||||
icon: "i-mingcute:photo-album-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
const input = document.createElement("input")
|
||||
input.type = "file"
|
||||
input.addEventListener("change", async (e: any) => {
|
||||
@@ -25,6 +25,8 @@ export const Image: ICommand = {
|
||||
if (error instanceof Error) {
|
||||
toast.error(error.message, { id: toastId })
|
||||
}
|
||||
} finally {
|
||||
input.remove()
|
||||
}
|
||||
})
|
||||
input.click()
|
||||
|
||||
@@ -4,7 +4,7 @@ export const Italic: ICommand = {
|
||||
name: "italic",
|
||||
label: "Italic",
|
||||
icon: "i-mingcute:italic-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "_", append: "_" })
|
||||
},
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ export const Link: ICommand = {
|
||||
name: "link",
|
||||
label: "Link",
|
||||
icon: "i-mingcute:link-2-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "[", append: "]()" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export const ListOrdered: ICommand = {
|
||||
name: "list-ordered",
|
||||
label: "Ordered List",
|
||||
icon: "i-mingcute:list-ordered-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "1. ", append: "\n" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ export const ListUnordered: ICommand = {
|
||||
name: "list-unordered",
|
||||
label: "Unordered List",
|
||||
icon: "i-mingcute:list-check-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "- ", append: "\n" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ICommand, wrapExecute } from "."
|
||||
|
||||
export const Mention: ICommand = {
|
||||
name: "mention",
|
||||
label: "Mention",
|
||||
icon: "i-mingcute:at-line",
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "::mention{#", append: "}" })
|
||||
},
|
||||
}
|
||||
@@ -4,7 +4,7 @@ export const Quote: ICommand = {
|
||||
name: "quote",
|
||||
label: "Quote",
|
||||
icon: "i-mingcute:quote-left-fill",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "> ", append: "\n" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ export const Strikethrough: ICommand = {
|
||||
name: "strikethrough",
|
||||
label: "Strikethrough",
|
||||
icon: "i-mingcute:strikethrough-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "~~", append: "~~" })
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ export const Underline: ICommand = {
|
||||
name: "underline",
|
||||
label: "Underline",
|
||||
icon: "i-mingcute:underline-line",
|
||||
execute: (view) => {
|
||||
execute: ({ view }) => {
|
||||
wrapExecute({ view, prepend: "<u>", append: "</u>" })
|
||||
},
|
||||
}
|
||||
|
||||
+17
-5
@@ -13,18 +13,28 @@ import { ListUnordered } from "./ListUnordered"
|
||||
import { Quote } from "./Quote"
|
||||
import { Strikethrough } from "./Strikethrough"
|
||||
import { Underline } from "./Underline"
|
||||
import { Mention } from "./Mention"
|
||||
import { Emoji } from "./Emoji"
|
||||
|
||||
export type ICommand = {
|
||||
export type ICommand<P = any> = {
|
||||
icon: string
|
||||
name: string
|
||||
label: string
|
||||
execute: (
|
||||
view: EditorView,
|
||||
execute: (_: {
|
||||
view: EditorView
|
||||
options?: {
|
||||
setPreviewVisible?: Dispatch<SetStateAction<boolean>>
|
||||
container?: HTMLElement | null
|
||||
},
|
||||
) => void
|
||||
}
|
||||
payload?: P
|
||||
}) => void
|
||||
// While the `ui` field exists, the ui component will be rendered in a popover first,
|
||||
// then you can call `transferPayload` to transfer the payload to the `execute` function.
|
||||
// You can find a sample usage in `./Emoji.tsx`.
|
||||
ui?: React.FC<{
|
||||
transferPayload: (payload: P) => void
|
||||
view: EditorView
|
||||
}>
|
||||
}
|
||||
|
||||
export type IPrependExecute = {
|
||||
@@ -127,4 +137,6 @@ export const toolbars: ICommand[] = [
|
||||
ListOrdered,
|
||||
Link,
|
||||
Image,
|
||||
Mention,
|
||||
Emoji,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user