mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
perf: 文本编辑优化
This commit is contained in:
parent
e7cb6a9b2f
commit
b32182fc8d
@ -6,6 +6,7 @@ import {
|
|||||||
smartQuotes,
|
smartQuotes,
|
||||||
emDash,
|
emDash,
|
||||||
ellipsis,
|
ellipsis,
|
||||||
|
InputRule,
|
||||||
} from 'prosemirror-inputrules'
|
} from 'prosemirror-inputrules'
|
||||||
|
|
||||||
const blockQuoteRule = (nodeType: NodeType) => wrappingInputRule(/^\s*>\s$/, nodeType)
|
const blockQuoteRule = (nodeType: NodeType) => wrappingInputRule(/^\s*>\s$/, nodeType)
|
||||||
@ -23,6 +24,19 @@ const bulletListRule = (nodeType: NodeType) => wrappingInputRule(/^\s*([-+*])\s$
|
|||||||
|
|
||||||
const codeBlockRule = (nodeType: NodeType) => textblockTypeInputRule(/^```$/, nodeType)
|
const codeBlockRule = (nodeType: NodeType) => textblockTypeInputRule(/^```$/, nodeType)
|
||||||
|
|
||||||
|
const linkRule = () => {
|
||||||
|
const urlRegEx = /(?:https?:\/\/)?[\w-]+(?:\.[\w-]+)+\.?(?:\d+)?(?:\/\S*)?$/
|
||||||
|
|
||||||
|
return new InputRule(urlRegEx, (state, match, start, end) => {
|
||||||
|
const { schema } = state
|
||||||
|
|
||||||
|
const tr = state.tr.insertText(match[0], start, end)
|
||||||
|
const mark = schema.marks.link.create({ href: match[0], title: match[0] })
|
||||||
|
|
||||||
|
return tr.addMark(start, start + match[0].length, mark)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const buildInputRules = (schema: Schema) => {
|
export const buildInputRules = (schema: Schema) => {
|
||||||
const rules = [
|
const rules = [
|
||||||
...smartQuotes,
|
...smartQuotes,
|
||||||
@ -33,6 +47,7 @@ export const buildInputRules = (schema: Schema) => {
|
|||||||
rules.push(orderedListRule(schema.nodes.ordered_list))
|
rules.push(orderedListRule(schema.nodes.ordered_list))
|
||||||
rules.push(bulletListRule(schema.nodes.bullet_list))
|
rules.push(bulletListRule(schema.nodes.bullet_list))
|
||||||
rules.push(codeBlockRule(schema.nodes.code_block))
|
rules.push(codeBlockRule(schema.nodes.code_block))
|
||||||
|
rules.push(linkRule())
|
||||||
|
|
||||||
return inputRules({ rules })
|
return inputRules({ rules })
|
||||||
}
|
}
|
@ -38,6 +38,7 @@ export const buildKeymap = (schema: Schema) => {
|
|||||||
))
|
))
|
||||||
bind('Mod-[', liftListItem(schema.nodes.list_item))
|
bind('Mod-[', liftListItem(schema.nodes.list_item))
|
||||||
bind('Mod-]', sinkListItem(schema.nodes.list_item))
|
bind('Mod-]', sinkListItem(schema.nodes.list_item))
|
||||||
|
bind('Tab', sinkListItem(schema.nodes.list_item))
|
||||||
|
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ const strikethrough: MarkSpec = {
|
|||||||
getAttrs: value => value === 'line-through' && null
|
getAttrs: value => value === 'line-through' && null
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
toDOM: () => ['span', { style: 'text-decoration-line: line-through' }, 0],
|
toDOM: () => ['span', { style: 'text-decoration-line: line-through;' }, 0],
|
||||||
}
|
}
|
||||||
|
|
||||||
const underline: MarkSpec = {
|
const underline: MarkSpec = {
|
||||||
@ -52,7 +52,7 @@ const underline: MarkSpec = {
|
|||||||
getAttrs: value => value === 'underline' && null
|
getAttrs: value => value === 'underline' && null
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
toDOM: () => ['span', { style: 'text-decoration: underline' }, 0],
|
toDOM: () => ['span', { style: 'text-decoration: underline;' }, 0],
|
||||||
}
|
}
|
||||||
|
|
||||||
const forecolor: MarkSpec = {
|
const forecolor: MarkSpec = {
|
||||||
@ -110,7 +110,7 @@ const fontsize: MarkSpec = {
|
|||||||
toDOM: mark => {
|
toDOM: mark => {
|
||||||
const { fontsize } = mark.attrs
|
const { fontsize } = mark.attrs
|
||||||
let style = ''
|
let style = ''
|
||||||
if (fontsize) style += `font-size: ${fontsize}`
|
if (fontsize) style += `font-size: ${fontsize};`
|
||||||
return ['span', { style }, 0]
|
return ['span', { style }, 0]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ const fontname: MarkSpec = {
|
|||||||
toDOM: mark => {
|
toDOM: mark => {
|
||||||
const { fontname } = mark.attrs
|
const { fontname } = mark.attrs
|
||||||
let style = ''
|
let style = ''
|
||||||
if (fontname) style += `font-family: ${fontname}`
|
if (fontname) style += `font-family: ${fontname};`
|
||||||
return ['span', { style }, 0]
|
return ['span', { style }, 0]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user