This commit is contained in:
Philipp Kühn 2020-03-30 12:40:25 +02:00
parent 9c6e553a2b
commit fd476901c4
9 changed files with 92 additions and 6 deletions

View File

@ -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'

View File

@ -106,6 +106,7 @@ export class Editor extends EventEmitter {
nodes: this.extensionManager.nodes,
marks: this.extensionManager.marks,
})
this.emit('schemaCreated')
}
private get plugins() {

View File

@ -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
View 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]
}
}

View File

@ -14,4 +14,8 @@ export default abstract class Node extends Extension {
return null
}
get schemaType() {
return this.editor.schema.nodes[this.name]
}
}

View 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],
}
}
}

View 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"
}
}

View File

@ -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,
// }
// }

View File

@ -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(),
],
})
},