feat: enhance ArticleEditorCanvas with new icons and table insertion functionality
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
BoldOutlined,
|
BoldOutlined,
|
||||||
|
CodeOutlined,
|
||||||
ItalicOutlined,
|
ItalicOutlined,
|
||||||
|
StrikethroughOutlined,
|
||||||
OrderedListOutlined,
|
OrderedListOutlined,
|
||||||
PicCenterOutlined,
|
MinusOutlined,
|
||||||
PictureOutlined,
|
PictureOutlined,
|
||||||
RedoOutlined,
|
RedoOutlined,
|
||||||
|
TableOutlined,
|
||||||
UndoOutlined,
|
UndoOutlined,
|
||||||
UnorderedListOutlined,
|
UnorderedListOutlined,
|
||||||
} from "@ant-design/icons-vue";
|
} from "@ant-design/icons-vue";
|
||||||
@@ -15,11 +18,13 @@ import {
|
|||||||
insertImageCommand,
|
insertImageCommand,
|
||||||
toggleEmphasisCommand,
|
toggleEmphasisCommand,
|
||||||
toggleStrongCommand,
|
toggleStrongCommand,
|
||||||
|
toggleInlineCodeCommand,
|
||||||
wrapInBlockquoteCommand,
|
wrapInBlockquoteCommand,
|
||||||
wrapInBulletListCommand,
|
wrapInBulletListCommand,
|
||||||
wrapInHeadingCommand,
|
wrapInHeadingCommand,
|
||||||
wrapInOrderedListCommand,
|
wrapInOrderedListCommand,
|
||||||
} from "@milkdown/kit/preset/commonmark";
|
} from "@milkdown/kit/preset/commonmark";
|
||||||
|
import { insertTableCommand, toggleStrikethroughCommand } from "@milkdown/kit/preset/gfm";
|
||||||
import { callCommand, replaceAll } from "@milkdown/kit/utils";
|
import { callCommand, replaceAll } from "@milkdown/kit/utils";
|
||||||
import { Crepe, CrepeFeature } from "@milkdown/crepe";
|
import { Crepe, CrepeFeature } from "@milkdown/crepe";
|
||||||
import "@milkdown/crepe/theme/common/style.css";
|
import "@milkdown/crepe/theme/common/style.css";
|
||||||
@@ -142,16 +147,20 @@ function insertImage(): void {
|
|||||||
|
|
||||||
runCommand(insertImageCommand, { src: src.trim() });
|
runCommand(insertImageCommand, { src: src.trim() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertTable(): void {
|
||||||
|
runCommand(insertTableCommand, { row: 3, col: 3 });
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="article-editor-canvas" :class="{ 'article-editor-canvas--disabled': disabled }">
|
<div class="article-editor-canvas" :class="{ 'article-editor-canvas--disabled': disabled }">
|
||||||
<div class="article-editor-canvas__toolbar">
|
<div class="article-editor-canvas__toolbar">
|
||||||
<a-button size="small" type="text" @click="runCommand(undoCommand)">
|
<a-button size="small" type="text" @click="runCommand(undoCommand)">
|
||||||
<template #icon><UndoOutlined /></template>
|
<template #icon><IconFont type="icon-Undo" /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button size="small" type="text" @click="runCommand(redoCommand)">
|
<a-button size="small" type="text" @click="runCommand(redoCommand)">
|
||||||
<template #icon><RedoOutlined /></template>
|
<template #icon><IconFont type="icon-redo" /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<span class="article-editor-canvas__divider"></span>
|
<span class="article-editor-canvas__divider"></span>
|
||||||
<a-button size="small" type="text" @click="runCommand(wrapInHeadingCommand, 1)">H1</a-button>
|
<a-button size="small" type="text" @click="runCommand(wrapInHeadingCommand, 1)">H1</a-button>
|
||||||
@@ -164,18 +173,28 @@ function insertImage(): void {
|
|||||||
<a-button size="small" type="text" @click="runCommand(toggleEmphasisCommand)">
|
<a-button size="small" type="text" @click="runCommand(toggleEmphasisCommand)">
|
||||||
<template #icon><ItalicOutlined /></template>
|
<template #icon><ItalicOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button size="small" type="text" @click="runCommand(wrapInBlockquoteCommand)">
|
<a-button size="small" type="text" @click="runCommand(toggleStrikethroughCommand)">
|
||||||
“ ”
|
<template #icon><StrikethroughOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<span class="article-editor-canvas__divider"></span>
|
||||||
|
<a-button size="small" type="text" style="font-size: 16px; font-weight: bold; line-height: 1" @click="runCommand(wrapInBlockquoteCommand)">
|
||||||
|
"
|
||||||
|
</a-button>
|
||||||
|
<a-button size="small" type="text" @click="runCommand(insertHrCommand)">
|
||||||
|
<template #icon><MinusOutlined /></template>
|
||||||
|
</a-button>
|
||||||
|
<span class="article-editor-canvas__divider"></span>
|
||||||
<a-button size="small" type="text" @click="runCommand(wrapInBulletListCommand)">
|
<a-button size="small" type="text" @click="runCommand(wrapInBulletListCommand)">
|
||||||
<template #icon><UnorderedListOutlined /></template>
|
<template #icon><UnorderedListOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button size="small" type="text" @click="runCommand(wrapInOrderedListCommand)">
|
<a-button size="small" type="text" @click="runCommand(wrapInOrderedListCommand)">
|
||||||
<template #icon><OrderedListOutlined /></template>
|
<template #icon><OrderedListOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button size="small" type="text" @click="runCommand(insertHrCommand)">
|
|
||||||
<template #icon><PicCenterOutlined /></template>
|
<a-button size="small" type="text" @click="insertTable">
|
||||||
|
<template #icon><TableOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<span class="article-editor-canvas__divider"></span>
|
||||||
<a-button size="small" type="text" @click="insertImage">
|
<a-button size="small" type="text" @click="insertImage">
|
||||||
<template #icon><PictureOutlined /></template>
|
<template #icon><PictureOutlined /></template>
|
||||||
</a-button>
|
</a-button>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { createFromIconfontCN } from "@ant-design/icons-vue";
|
||||||
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
import {
|
import {
|
||||||
@@ -65,6 +66,13 @@ const queryClient = new QueryClient({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
|
const IconFont = createFromIconfontCN({
|
||||||
|
// 需要替换为你自己真实项目的 js 地址,才能显示出你的 '#icon-line-global_undo'。
|
||||||
|
scriptUrl: "//at.alicdn.com/t/c/font_5154382_bf9lssq7ar.js",
|
||||||
|
});
|
||||||
|
app.component("IconFont", IconFont);
|
||||||
|
|
||||||
app.component("ATextarea", Input.TextArea);
|
app.component("ATextarea", Input.TextArea);
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user