Skip to content

Commit

Permalink
feat: 🎸 高亮块
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxqc committed Sep 5, 2022
1 parent 069c91f commit a218c2e
Show file tree
Hide file tree
Showing 25 changed files with 560 additions and 90 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ declare module '@vue/runtime-core' {
ElSelect: typeof import('element-plus/es')['ElSelect']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElUpload: typeof import('element-plus/es')['ElUpload']
ExtensionViewsCustomBlockView: typeof import('./src/components/extensionViews/CustomBlockView.vue')['default']
ExtensionViewsIframeView: typeof import('./src/components/extensionViews/IframeView.vue')['default']
ExtensionViewsImageView: typeof import('./src/components/extensionViews/ImageView.vue')['default']
ExtensionViewsTaskItemView: typeof import('./src/components/extensionViews/TaskItemView.vue')['default']
IconIcon: typeof import('./src/components/Icon/Icon.vue')['default']
MenuBar: typeof import('./src/components/menuBar/Index.vue')['default']
MenuBubble: typeof import('./src/components/menuBubble/Index.vue')['default']
MenuBubbleCustomBlockBubbleMenu: typeof import('./src/components/menuBubble/CustomBlockBubbleMenu.vue')['default']
MenuBubbleImageBubbleMenu: typeof import('./src/components/menuBubble/ImageBubbleMenu.vue')['default']
MenuBubbleLinkBubbleMenu: typeof import('./src/components/menuBubble/LinkBubbleMenu.vue')['default']
MenuCommandsCodeBlock: typeof import('./src/components/menuCommands/CodeBlock.vue')['default']
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"@tiptap/extension-text-style": "^2.0.0-beta.26",
"@tiptap/extension-underline": "^2.0.0-beta.25",
"@tiptap/vue-3": "^2.0.0-beta.96",
"highlight.js": "^11.6.0",
"codemirror": "^5.65.8",
"highlight.js": "^11.6.0",
"lowlight": "^2.7.0"
},
"devDependencies": {
Expand Down
22 changes: 3 additions & 19 deletions preview/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,10 @@ import {
FormatClear,
Fullscreen, SelectAll, CodeBlock, BulletList, OrderedList, Image, TaskList,
Table,
Iframe, Gapcursor, TextStyle,
Iframe, Gapcursor, TextStyle, CustomBlock,
} from '../../src/index'
const content = ref(` <p>
Press Command/Ctrl + Enter to leave the fenced code block and continue typing in boring paragraphs.
</p>
<pre><code class="language-javascript">for (var i=1; i <= 20; i++)
{
if (i % 15 == 0)
console.log("FizzBuzz");
else if (i % 3 == 0)
console.log("Fizz");
else if (i % 5 == 0)
console.log("Buzz");
else
console.log(i);
}</code></pre>
<p>
Press Command/Ctrl + Enter to leave the fenced code block and continue typing in boring paragraphs.
</p>
\``)
const content = ref('<div class="custom-block info"><pre><code class="language-javascript">console.log(12312321)</code></pre></div><p></p><p>大萨达</p><p></p><p>das的as</p><div class="custom-block info"><p>dsadsadsad</p></div><p></p>')
const extensions = [
Document, Text, Paragraph, Heading, Blockquote, Bold, Underline, Italic, Strike, Link, History, TextStyle,
Expand All @@ -75,6 +58,7 @@ const extensions = [
Table.configure({ resizable: true }),
Iframe,
CodeBlock.configure({ languageClassPrefix: 'language-', defaultLanguage: 'plaintext', lowlight }),
CustomBlock,
CodeView.configure({
codemirror,
codemirrorOptions: {
Expand Down
35 changes: 35 additions & 0 deletions src/components/extensionViews/CustomBlockView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<node-view-wrapper
as="div"
class="custom-block"
:class="node?.attrs.type"
>
<!-- when image is break text or float bubble menu's position is miscalculated use el-popover instead bubble menu -->
<el-popover
placement="top"
:show-arrow="false"
trigger="hover"
popper-class="editor-custom-block-popper"
>
<CustomBlockBubbleMenu
:node="node"
:editor="editor"
:update-attrs="updateAttributes"
/>
<template #reference>
<NodeViewContent />
</template>
</el-popover>
</node-view-wrapper>
</template>
<script setup>
import { defineProps } from 'vue';
import { NodeViewWrapper, NodeViewContent, nodeViewProps } from '@tiptap/vue-3';
import { ElPopover } from 'element-plus';
import CustomBlockBubbleMenu from '../menuBubble/CustomBlockBubbleMenu.vue'
const props = defineProps(nodeViewProps)
console.log(props.node)
</script>
2 changes: 1 addition & 1 deletion src/components/extensionViews/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:visible="selected"
:show-arrow="false"
placement="top"
popper-class="el-tiptap-image-popper"
popper-class="editor-image-popper"
>
<image-bubble-menu
:node="node"
Expand Down
139 changes: 139 additions & 0 deletions src/components/menuBubble/CustomBlockBubbleMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<template>
<div class="custom-block-bubble-menu">
<div
class="custom-checkbox tips"
:class="[node.attrs.type === 'tips' && 'checked']"
@click="handleCheckboxClick('tips')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox info"
:class="[node.attrs.type === 'info' && 'checked']"
@click="handleCheckboxClick('info')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox warning"
:class="[node.attrs.type === 'warning' && 'checked']"
@click="handleCheckboxClick('warning')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox success"
:class="[node.attrs.type === 'success' && 'checked']"
@click="handleCheckboxClick('success')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox danger"
:class="[node.attrs.type === 'danger' && 'checked']"
@click="handleCheckboxClick('danger')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox color1"
:class="[node.attrs.type === 'color1' && 'checked']"
@click="handleCheckboxClick('color1')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox color2"
:class="[node.attrs.type === 'color2' && 'checked']"
@click="handleCheckboxClick('color2')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox color3"
:class="[node.attrs.type === 'color3' && 'checked']"
@click="handleCheckboxClick('color3')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox color4"
:class="[node.attrs.type === 'color4' && 'checked']"
@click="handleCheckboxClick('color4')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
<div
class="custom-checkbox color5"
:class="[node.attrs.type === 'color5' && 'checked']"
@click="handleCheckboxClick('color5')"
>
<input
class="custom-checkbox__original"
type="checkbox"
aria-hidden="false"
>
<span class="custom-checkbox__inner" />
</div>
</div>
</template>

<script lang="ts" setup>
import { defineProps } from 'vue';
import { nodeViewProps } from '@tiptap/vue-3';
const props = defineProps({
editor: nodeViewProps.editor,
node: nodeViewProps.node,
updateAttrs: nodeViewProps.updateAttributes,
})
const handleCheckboxClick = (type: string) => {
props.updateAttrs({ type })
}
</script>
2 changes: 1 addition & 1 deletion src/components/menuCommands/ColorPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:disabled="isCodeViewMode"
placement="bottom"
trigger="click"
popper-class="el-tiptap-popper"
popper-class="editor-popper"
>
<div class="color-set">
<div
Expand Down
6 changes: 3 additions & 3 deletions src/components/menuCommands/FontFamilyDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
/>

<template #dropdown>
<el-dropdown-menu class="el-tiptap-dropdown-menu">
<el-dropdown-menu class="editor-dropdown-menu">
<el-dropdown-item
v-for="name in fontFamilies"
:key="name"
:command="name"
:class="{
'el-tiptap-dropdown-menu__item--active': name === activeFontFamily,
'editor-dropdown-menu__item--active': name === activeFontFamily,
}"
class="el-tiptap-dropdown-menu__item"
class="editor-dropdown-menu__item"
>
<span
:data-font="name"
Expand Down
10 changes: 5 additions & 5 deletions src/components/menuCommands/FontSizeDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
/>

<template #dropdown>
<el-dropdown-menu class="el-tiptap-dropdown-menu">
<el-dropdown-menu class="editor-dropdown-menu">
<!-- default size -->
<el-dropdown-item
:command="defaultSize"
:class="{
'el-tiptap-dropdown-menu__item--active':
'editor-dropdown-menu__item--active':
activeFontSize === defaultSize,
}"
class="el-tiptap-dropdown-menu__item"
class="editor-dropdown-menu__item"
>
<span data-font-size="default">{{
t('editor.extensions.FontSize.default')
Expand All @@ -32,10 +32,10 @@
:key="fontSize"
:command="fontSize"
:class="{
'el-tiptap-dropdown-menu__item--active':
'editor-dropdown-menu__item--active':
fontSize === activeFontSize,
}"
class="el-tiptap-dropdown-menu__item"
class="editor-dropdown-menu__item"
>
<span :data-font-size="fontSize">{{ fontSize }}</span>
</el-dropdown-item>
Expand Down
8 changes: 4 additions & 4 deletions src/components/menuCommands/HeadingDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<el-dropdown
placement="bottom"
trigger="click"
popper-class="el-tiptap-dropdown-popper"
popper-class="editor-dropdown-popper"
@command="toggleHeading"
>
<command-button
Expand All @@ -13,7 +13,7 @@
icon="heading"
/>
<template #dropdown>
<el-dropdown-menu class="el-tiptap-dropdown-menu">
<el-dropdown-menu class="editor-dropdown-menu">
<el-dropdown-item
v-for="level in [0, ...levels]"
:key="level"
Expand All @@ -22,14 +22,14 @@
<div
:class="[
{
'el-tiptap-dropdown-menu__item--active':
'editor-dropdown-menu__item--active':
level > 0
? editor.isActive('heading', {
level,
})
: editor.isActive('paragraph'),
},
'el-tiptap-dropdown-menu__item',
'editor-dropdown-menu__item',
]"
>
<template v-if="level > 0">
Expand Down
2 changes: 1 addition & 1 deletion src/components/menuCommands/HighlightPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:disabled="isCodeViewMode"
placement="bottom"
trigger="click"
popper-class="el-tiptap-popper"
popper-class="editor-popper"
>
<div class="color-set">
<div
Expand Down
6 changes: 3 additions & 3 deletions src/components/menuCommands/LineHeightDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
<template #dropdown>
<el-dropdown-menu
slot="dropdown"
class="el-tiptap-dropdown-menu"
class="editor-dropdown-menu"
>
<el-dropdown-item
v-for="lineHeight in lineHeights"
:key="lineHeight"
:command="lineHeight"
:class="{
'el-tiptap-dropdown-menu__item--active':
'editor-dropdown-menu__item--active':
isLineHeightActive(lineHeight),
}"
class="el-tiptap-dropdown-menu__item"
class="editor-dropdown-menu__item"
>
<span>{{ lineHeight }}</span>
</el-dropdown-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:title="t('editor.extensions.Image.control.edit_image.title')"
:append-to-body="true"
width="400px"
custom-class="el-tiptap-edit-image-dialog"
custom-class="editor-edit-image-dialog"
>
<el-form
:model="imageAttrs"
Expand Down
Loading

0 comments on commit a218c2e

Please sign in to comment.