Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(rich-text-editor): adjust style, fit Highlight, Default, Disabled #357

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 78 additions & 45 deletions packages/renderless/src/rich-text-edtior/vue.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,84 @@
export const api = ['state']
export const api = ['state', 'setLink', 'handleChange']
export const renderless = (
props,
{ computed, onMounted, onBeforeUnmount, reactive },
{ vm, emit, parent },
{ useEditor, Collaboration, Y, WebrtcProvider, StarterKit, Table, TableCell, TableHeader, TableRow, Color, TextStyle, Image }
props,
{ computed, onMounted, onBeforeUnmount, reactive },
{ vm, emit, parent },
{ useEditor, Collaboration, Y, WebrtcProvider, StarterKit, Table, TableCell, TableHeader, TableRow, Color, TextStyle, Image, Highlight, Link, Underline, Subscript, Superscript }
) => {
const ydoc = new Y.Doc()
const provider = new WebrtcProvider('tiny-examsple-document', ydoc)
const ydoc = new Y.Doc()
const provider = new WebrtcProvider('tiny-examsple-document', ydoc)

const editor = useEditor({
extensions: [
StarterKit?.configure({
// 开启多人协作功能要关闭默认的history模式
history: false,
}),
Collaboration?.configure({
document: ydoc,
}),
Table.configure({
resizable: true,
}),
TableCell, TableHeader, TableRow,
Color, TextStyle,
Image,
],
content: 'Example Tesxt',
autofocus: true,
editable: true,
injectCSS: false,
})
const addImage = (editor) => {
const url = window.prompt('URL')

if (url) {
editor.chain().focus().setImage({ src: url }).run()
}
const editor = useEditor({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一块的配置看能不能单独抽离出去,让用户可以自定义

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块的抽离的话我想着是往后面,那版专门抽离配置,所以目前没考虑

extensions: [
StarterKit?.configure({
// 开启多人协作功能要关闭默认的history模式
history: false,
}),
Collaboration?.configure({
document: ydoc,
}),
Table.configure({
resizable: true,
}),
TableCell, TableHeader, TableRow,
Color, TextStyle,
Image,
Highlight,
Link,
Underline,
Subscript,
Superscript
],
content: 'Example Tesxt',
autofocus: true,
editable: true,
injectCSS: false,
})
const handleChange = (event) => {
const file = event.target.files[0]
if (!file.type.match("image.*")) {
console.log("请选择图片文件!")
return
}
const reader = new FileReader()
reader.onload = function (e) {
editor.value.chain().focus().setImage({ src: e.target?.result }).run()
}
reader.readAsDataURL(file)
}
const setLink = () => {
const previousUrl = editor.value.getAttributes('link').href
const url = window.prompt('URL', previousUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果url存在,不需要做操作吗?

if (url === null) {
return
}
const state = reactive({
editor: null,
addImage: addImage,
})
state.editor = editor
const api = {
state,
if (url === '') {
editor.value
.chain()
.focus()
.extendMarkRange('link')
.unsetLink()
.run()
return
}
onBeforeUnmount(() => {
state.editor.destroy()
})
return api
editor.value
.chain()
.focus()
.extendMarkRange('link')
.setLink({ href: url })
.run()
}
const state = reactive({
editor: null,
})
state.editor = editor
const api = {
state,
setLink,
handleChange,
}
onBeforeUnmount(() => {
state.editor.destroy()
})
return api
}
Loading