improve schema types

This commit is contained in:
Philipp Kühn 2020-03-31 22:57:39 +02:00
parent 208ba890ef
commit c60ad0f107
8 changed files with 19 additions and 19 deletions

View File

@ -1,4 +1,3 @@
import collect from 'collect.js'
import { EventEmitter } from 'events'
import { EditorState, TextSelection } from 'prosemirror-state'
import { EditorView} from 'prosemirror-view'
@ -8,7 +7,6 @@ import { keymap } from 'prosemirror-keymap'
import { baseKeymap } from 'prosemirror-commands'
import { dropCursor } from 'prosemirror-dropcursor'
import { gapCursor } from 'prosemirror-gapcursor'
import magicMethods from './utils/magicMethods'
import elementFromString from './utils/elementFromString'
import injectCSS from './utils/injectCSS'
@ -119,7 +117,6 @@ export class Editor extends EventEmitter {
}
private get plugins() {
console.log(this.extensionManager.plugins)
return [
...this.extensionManager.plugins,
...this.extensionManager.keymaps,

View File

@ -1,4 +1,5 @@
import Extension from './Extension'
import { MarkSpec } from 'prosemirror-model'
export default abstract class Mark extends Extension {
@ -8,9 +9,7 @@ export default abstract class Mark extends Extension {
public type = 'mark'
schema(): any {
return null
}
abstract schema(): MarkSpec
get schemaType() {
return this.editor.schema.marks[this.name]

View File

@ -1,4 +1,5 @@
import Extension from './Extension'
import { NodeSpec } from 'prosemirror-model'
export default abstract class Node extends Extension {
@ -10,9 +11,7 @@ export default abstract class Node extends Extension {
public topNode = false
schema(): any {
return null
}
abstract schema(): NodeSpec
get schemaType() {
return this.editor.schema.nodes[this.name]

View File

@ -1,5 +1,6 @@
import { Mark } from '@tiptap/core'
import { toggleMark } from 'prosemirror-commands'
import { MarkSpec } from 'prosemirror-model'
declare module '@tiptap/core/src/Editor' {
interface Editor {
@ -18,7 +19,7 @@ export default class Bold extends Mark {
})
}
schema() {
schema(): MarkSpec {
return {
parseDOM: [
{
@ -26,12 +27,12 @@ export default class Bold extends Mark {
},
{
tag: 'b',
getAttrs: (node: HTMLElement) => node.style.fontWeight !== 'normal' && null,
getAttrs: node => (node as HTMLElement).style.fontWeight !== 'normal' && null,
},
{
style: 'font-weight',
getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value as string) && null,
},
// {
// style: 'font-weight',
// getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null,
// },
],
toDOM: () => ['strong', 0],
}

View File

@ -1,4 +1,5 @@
import { Node } from '@tiptap/core'
import { NodeSpec } from 'prosemirror-model'
export default class Document extends Node {
@ -6,7 +7,7 @@ export default class Document extends Node {
topNode = true
schema() {
schema(): NodeSpec {
return {
content: 'block+',
}

View File

@ -1,5 +1,6 @@
import { Mark } from '@tiptap/core'
import { toggleMark } from 'prosemirror-commands'
import { MarkSpec } from 'prosemirror-model'
declare module '@tiptap/core/src/Editor' {
interface Editor {
@ -18,7 +19,7 @@ export default class Italic extends Mark {
})
}
schema() {
schema(): MarkSpec {
return {
parseDOM: [
{ tag: 'i' },

View File

@ -1,10 +1,11 @@
import { Node } from '@tiptap/core'
import { NodeSpec } from 'prosemirror-model'
export default class Paragraph extends Node {
name = 'paragraph'
schema() {
schema(): NodeSpec {
return {
content: 'inline*',
group: 'block',

View File

@ -1,10 +1,11 @@
import { Node } from '@tiptap/core'
import { NodeSpec } from 'prosemirror-model'
export default class Text extends Node {
name = 'text'
schema() {
schema(): NodeSpec {
return {
group: 'inline',
}