This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resize feature supports for image and iframe (#2)
- Loading branch information
Showing
14 changed files
with
580 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/editor/src/components/block/BlockActionButton.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script lang="ts" setup> | ||
import { VTooltip } from "floating-vue"; | ||
withDefaults( | ||
defineProps<{ | ||
tooltip?: string; | ||
selected?: boolean; | ||
}>(), | ||
{ | ||
tooltip: undefined, | ||
selected: false, | ||
} | ||
); | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-tooltip="tooltip" | ||
class="editor-block__actions-button" | ||
:class="{ | ||
'editor-block__actions-button--selected': selected, | ||
}" | ||
> | ||
<slot name="icon" /> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss"> | ||
.editor-block__actions-button { | ||
@apply p-1.5 bg-gray-50 rounded-md cursor-pointer hover:bg-gray-100; | ||
&--selected { | ||
@apply bg-gray-200; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts" setup> | ||
import { computed } from "vue"; | ||
import { VTooltip } from "floating-vue"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
tooltip?: string; | ||
modelValue: string; | ||
}>(), | ||
{ | ||
tooltip: undefined, | ||
} | ||
); | ||
const emit = defineEmits<{ | ||
(emit: "update:modelValue", value: string): void; | ||
}>(); | ||
const value = computed({ | ||
get: () => props.modelValue, | ||
set: (value: string) => emit("update:modelValue", value), | ||
}); | ||
</script> | ||
|
||
<template> | ||
<input | ||
v-model.lazy.trim="value" | ||
v-tooltip="tooltip" | ||
class="editor-block__actions-input" | ||
/> | ||
</template> | ||
|
||
<style lang="scss"> | ||
.editor-block__actions-input { | ||
@apply bg-gray-50 rounded-md hover:bg-gray-100 block px-2 w-32 py-1.5 text-sm text-gray-900 border border-gray-300 focus:ring-blue-500 focus:border-blue-500; | ||
} | ||
</style> |
10 changes: 10 additions & 0 deletions
10
packages/editor/src/components/block/BlockActionSeparator.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template> | ||
<div class="editor-block__actions-separator"></div> | ||
</template> | ||
|
||
<style> | ||
.editor-block__actions-separator { | ||
@apply h-5 bg-gray-100 mx-1.5; | ||
width: 1px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<script lang="ts" setup> | ||
import type { Editor } from "@tiptap/vue-3"; | ||
import { Dropdown as VDropdown } from "floating-vue"; | ||
import { computed, ref } from "vue"; | ||
import MdiDeleteForeverOutline from "~icons/mdi/delete-forever-outline?color=red"; | ||
import MdiArrowULeftBottom from "~icons/mdi/arrow-u-left-bottom"; | ||
import BlockActionSeparator from "./BlockActionSeparator.vue"; | ||
import BlockActionButton from "./BlockActionButton.vue"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
selected: boolean; | ||
editor: Editor; | ||
getPos: () => number; | ||
deleteNode: () => void; | ||
}>(), | ||
{ | ||
selected: false, | ||
} | ||
); | ||
const hover = ref(false); | ||
const dropdownVisible = computed(() => { | ||
return hover.value || props.selected; | ||
}); | ||
function handleInsertNewLine() { | ||
props.editor.commands.insertContentAt( | ||
props.getPos() + 1, | ||
[{ type: "paragraph", content: "" }], | ||
{ | ||
updateSelection: true, | ||
} | ||
); | ||
props.editor.commands.focus(props.getPos() + 2, { | ||
scrollIntoView: true, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<section | ||
class="editor-block" | ||
:class="{ 'editor-block--selected': selected }" | ||
@mouseenter="hover = true" | ||
@mouseleave="hover = false" | ||
> | ||
<VDropdown | ||
placement="bottom-end" | ||
:shown="dropdownVisible" | ||
:auto-hide="false" | ||
:triggers="[]" | ||
:distance="8" | ||
theme="editor-block-dropdown" | ||
> | ||
<div class="editor-block__content"> | ||
<slot name="content" /> | ||
</div> | ||
<template #popper> | ||
<div class="editor-block__actions"> | ||
<slot name="actions" /> | ||
|
||
<BlockActionButton tooltip="换行" @click="handleInsertNewLine"> | ||
<template #icon> | ||
<MdiArrowULeftBottom /> | ||
</template> | ||
</BlockActionButton> | ||
|
||
<BlockActionSeparator /> | ||
|
||
<BlockActionButton tooltip="删除" @click="deleteNode"> | ||
<template #icon> | ||
<MdiDeleteForeverOutline /> | ||
</template> | ||
</BlockActionButton> | ||
</div> | ||
</template> | ||
</VDropdown> | ||
</section> | ||
</template> | ||
|
||
<style lang="scss"> | ||
.editor-block { | ||
@apply relative; | ||
&__content { | ||
@apply transition-all | ||
rounded | ||
p-2; | ||
} | ||
&__actions { | ||
@apply p-1 flex flex-row gap-0.5 items-center; | ||
} | ||
&:hover & { | ||
&__content { | ||
@apply bg-gray-50; | ||
} | ||
} | ||
&--selected & { | ||
&__content { | ||
@apply bg-gray-50; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9cfb8f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
richtext-editor – ./
richtext-editor-halo-dev.vercel.app
richtext-editor-git-main-halo-dev.vercel.app
richtext-editor-seven.vercel.app