mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
add mark
This commit is contained in:
parent
9c6e553a2b
commit
fd476901c4
@ -3,4 +3,5 @@ import { Editor } from './src/Editor'
|
||||
export default Editor
|
||||
export { Editor }
|
||||
export { default as Extension } from './src/Extension'
|
||||
export { default as Node } from './src/Node'
|
||||
export { default as Node } from './src/Node'
|
||||
export { default as Mark } from './src/Mark'
|
@ -106,6 +106,7 @@ export class Editor extends EventEmitter {
|
||||
nodes: this.extensionManager.nodes,
|
||||
marks: this.extensionManager.marks,
|
||||
})
|
||||
this.emit('schemaCreated')
|
||||
}
|
||||
|
||||
private get plugins() {
|
||||
|
@ -12,7 +12,9 @@ export default class ExtensionManager {
|
||||
this.extensions = extensions
|
||||
this.extensions.forEach(extension => {
|
||||
extension.bindEditor(editor)
|
||||
extension.created()
|
||||
editor.on('schemaCreated', () => {
|
||||
extension.created()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
19
packages/core/src/Mark.ts
Normal file
19
packages/core/src/Mark.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import Extension from './Extension'
|
||||
|
||||
export default abstract class Mark extends Extension {
|
||||
|
||||
constructor(options = {}) {
|
||||
super(options)
|
||||
}
|
||||
|
||||
public type = 'mark'
|
||||
|
||||
schema(): any {
|
||||
return null
|
||||
}
|
||||
|
||||
get schemaType() {
|
||||
return this.editor.schema.marks[this.name]
|
||||
}
|
||||
|
||||
}
|
@ -14,4 +14,8 @@ export default abstract class Node extends Extension {
|
||||
return null
|
||||
}
|
||||
|
||||
get schemaType() {
|
||||
return this.editor.schema.nodes[this.name]
|
||||
}
|
||||
|
||||
}
|
||||
|
34
packages/extension-bold/index.ts
Normal file
34
packages/extension-bold/index.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Mark } from '@tiptap/core'
|
||||
import { toggleMark } from 'prosemirror-commands'
|
||||
|
||||
export default class Bold extends Mark {
|
||||
|
||||
name = 'bold'
|
||||
|
||||
created() {
|
||||
this.editor.registerCommand('bold', next => {
|
||||
toggleMark(this.schemaType)
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
schema() {
|
||||
return {
|
||||
parseDOM: [
|
||||
{
|
||||
tag: 'strong',
|
||||
},
|
||||
{
|
||||
tag: 'b',
|
||||
getAttrs: (node: HTMLElement) => node.style.fontWeight !== 'normal' && null,
|
||||
},
|
||||
// {
|
||||
// style: 'font-weight',
|
||||
// getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null,
|
||||
// },
|
||||
],
|
||||
toDOM: () => ['strong', 0],
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
packages/extension-bold/package.json
Normal file
17
packages/extension-bold/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@tiptap/extension-text",
|
||||
"version": "1.0.0",
|
||||
"source": "index.ts",
|
||||
"main": "dist/tiptap-extension-text.js",
|
||||
"umd:main": "dist/tiptap-extension-text.umd.js",
|
||||
"module": "dist/tiptap-extension-text.mjs",
|
||||
"unpkg": "dist/tiptap-extension-text.js",
|
||||
"jsdelivr": "dist/tiptap-extension-text.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "2.x"
|
||||
}
|
||||
}
|
@ -38,10 +38,16 @@ export default class History extends Extension {
|
||||
|
||||
// commands() {
|
||||
// return {
|
||||
// undo: () => undo,
|
||||
// redo: () => redo,
|
||||
// undoDepth: () => undoDepth,
|
||||
// redoDepth: () => redoDepth,
|
||||
// undo: (next, { view }) => {
|
||||
// undo(view.state, view.dispatch)
|
||||
// next()
|
||||
// },
|
||||
// redo: (next, { view }) => {
|
||||
// redo(view.state, view.dispatch)
|
||||
// next()
|
||||
// },
|
||||
// // undoDepth: () => undoDepth,
|
||||
// // redoDepth: () => redoDepth,
|
||||
// }
|
||||
// }
|
||||
|
||||
|
@ -19,6 +19,7 @@ import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import History from '@tiptap/extension-history'
|
||||
import Bold from '@tiptap/extension-bold'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -39,6 +40,7 @@ export default {
|
||||
new Paragraph(),
|
||||
new Text(),
|
||||
new History(),
|
||||
new Bold(),
|
||||
],
|
||||
})
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user