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

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
import { Mark } from '@tiptap/core' import { Mark } from '@tiptap/core'
import { toggleMark } from 'prosemirror-commands' import { toggleMark } from 'prosemirror-commands'
import { MarkSpec } from 'prosemirror-model'
declare module '@tiptap/core/src/Editor' { declare module '@tiptap/core/src/Editor' {
interface Editor { interface Editor {
@@ -18,7 +19,7 @@ export default class Bold extends Mark {
}) })
} }
schema() { schema(): MarkSpec {
return { return {
parseDOM: [ parseDOM: [
{ {
@@ -26,12 +27,12 @@ export default class Bold extends Mark {
}, },
{ {
tag: 'b', 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], toDOM: () => ['strong', 0],
} }

View File

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

View File

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

View File

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

View File

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