add mark
This commit is contained in:
@@ -4,3 +4,4 @@ export default Editor
|
|||||||
export { Editor }
|
export { Editor }
|
||||||
export { default as Extension } from './src/Extension'
|
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,
|
nodes: this.extensionManager.nodes,
|
||||||
marks: this.extensionManager.marks,
|
marks: this.extensionManager.marks,
|
||||||
})
|
})
|
||||||
|
this.emit('schemaCreated')
|
||||||
}
|
}
|
||||||
|
|
||||||
private get plugins() {
|
private get plugins() {
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ export default class ExtensionManager {
|
|||||||
this.extensions = extensions
|
this.extensions = extensions
|
||||||
this.extensions.forEach(extension => {
|
this.extensions.forEach(extension => {
|
||||||
extension.bindEditor(editor)
|
extension.bindEditor(editor)
|
||||||
|
editor.on('schemaCreated', () => {
|
||||||
extension.created()
|
extension.created()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
get topNode() {
|
get topNode() {
|
||||||
|
|||||||
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
|
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() {
|
// commands() {
|
||||||
// return {
|
// return {
|
||||||
// undo: () => undo,
|
// undo: (next, { view }) => {
|
||||||
// redo: () => redo,
|
// undo(view.state, view.dispatch)
|
||||||
// undoDepth: () => undoDepth,
|
// next()
|
||||||
// redoDepth: () => redoDepth,
|
// },
|
||||||
|
// 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 Paragraph from '@tiptap/extension-paragraph'
|
||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import History from '@tiptap/extension-history'
|
import History from '@tiptap/extension-history'
|
||||||
|
import Bold from '@tiptap/extension-bold'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -39,6 +40,7 @@ export default {
|
|||||||
new Paragraph(),
|
new Paragraph(),
|
||||||
new Text(),
|
new Text(),
|
||||||
new History(),
|
new History(),
|
||||||
|
new Bold(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user