diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index 7f157c97..7ecce474 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -1,54 +1,151 @@ +import cloneDeep from 'clone-deep' import { Plugin } from 'prosemirror-state' -import { Editor, Command } from './Editor' +import { Editor, CommandSpec } from './Editor' -export default abstract class Extension { +// export default abstract class Extension { - constructor(options = {}) { - this.options = { - ...this.defaultOptions(), - ...options, +// constructor(options = {}) { +// this.options = { +// ...this.defaultOptions(), +// ...options, +// } +// } + +// editor!: Editor +// options: { [key: string]: any } = {} + +// public abstract name: string + +// public extensionType = 'extension' + +// public created() {} + +// public bindEditor(editor: Editor): void { +// this.editor = editor +// } + +// defaultOptions(): { [key: string]: any } { +// return {} +// } + +// update(): any { +// return () => {} +// } + +// plugins(): Plugin[] { +// return [] +// } + +// inputRules(): any { +// return [] +// } + +// pasteRules(): any { +// return [] +// } + +// keys(): { [key: string]: Function } { +// return {} +// } + +// commands(): { [key: string]: Command } { +// return {} +// } + +// } + +type AnyObject = { + [key: string]: any +} + +type NoInfer = [T][T extends any ? 0 : never] + +export interface ExtensionCallback { + name: string + editor: Editor + options: any +} + +export interface ExtensionExtends { + name: string + options: AnyObject + commands: (params: Callback) => CommandSpec + inputRules: (params: Callback) => any[] + pasteRules: (params: Callback) => any[] + keys: (params: Callback) => { + [key: string]: Function + } + plugins: (params: Callback) => Plugin[] +} + +export default class Extension { + type = 'extension' + configs: any = {} + usedOptions: Partial = {} + + protected storeConfig(key: string, value: any, stategy: 'extend' | 'overwrite') { + const item = { + stategy, + value, + } + + if (this.configs[key]) { + this.configs[key].push(item) + } else { + this.configs[key] = [item] } } + + public configure(options: Partial) { + this.usedOptions = { ...this.usedOptions, ...options } + return this + } + + public name(value: Extends['name']) { + this.storeConfig('name', value, 'overwrite') + return this + } + + public defaults(value: Options) { + this.storeConfig('defaults', value, 'overwrite') + return this + } + + public commands(value: Extends['commands']) { + this.storeConfig('commands', value, 'overwrite') + return this + } + + public keys(value: Extends['keys']) { + this.storeConfig('keys', value, 'overwrite') + return this + } + + public inputRules(value: Extends['inputRules']) { + this.storeConfig('inputRules', value, 'overwrite') + return this + } + + public pasteRules(value: Extends['pasteRules']) { + this.storeConfig('pasteRules', value, 'overwrite') + return this + } + + public plugins(value: Extends['plugins']) { + this.storeConfig('plugins', value, 'overwrite') + return this + } + + public extend>(key: T, value: Extends[T]) { + this.storeConfig(key, value, 'extend') + return this + } - editor!: Editor - options: { [key: string]: any } = {} - - public abstract name: string - - public extensionType = 'extension' + public create() { + type ParentOptions = Options - public created() {} - - public bindEditor(editor: Editor): void { - this.editor = editor + return (options?: Partial>) => { + return cloneDeep(this, true).configure(options as Options) + } } - - defaultOptions(): { [key: string]: any } { - return {} - } - - update(): any { - return () => {} - } - - plugins(): Plugin[] { - return [] - } - - inputRules(): any { - return [] - } - - pasteRules(): any { - return [] - } - - keys(): { [key: string]: Function } { - return {} - } - - commands(): { [key: string]: Command } { - return {} - } - } diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 06cc4ca7..0d52e8e7 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -1,18 +1,37 @@ -import Extension from './Extension' -import { MarkSpec } from 'prosemirror-model' +import { MarkSpec, MarkType } from 'prosemirror-model' +import Extension, { ExtensionCallback, ExtensionExtends } from './Extension' -export default abstract class Mark extends Extension { +// export default abstract class Mark extends Extension { - constructor(options = {}) { - super(options) - } +// constructor(options = {}) { +// super(options) +// } - public extensionType = 'mark' +// public extensionType = 'mark' - abstract schema(): MarkSpec +// abstract schema(): MarkSpec - get type() { - return this.editor.schema.marks[this.name] - } +// get type() { +// return this.editor.schema.marks[this.name] +// } +// } + +export interface MarkCallback extends ExtensionCallback { + // TODO: fix optional + type?: MarkType } + +export interface MarkExtends extends ExtensionExtends { + topMark: boolean + schema: (params: Callback) => MarkSpec +} + +export default class Mark extends Extension { + type = 'node' + + public schema(value: MarkExtends['schema']) { + this.storeConfig('schema', value, 'overwrite') + return this + } +} \ No newline at end of file diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 79436aa9..6cca747c 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -1,20 +1,44 @@ -import Extension from './Extension' -import { NodeSpec } from 'prosemirror-model' +import { NodeSpec, NodeType } from 'prosemirror-model' +import Extension, { ExtensionCallback, ExtensionExtends } from './Extension' -export default abstract class Node extends Extension { +// export default abstract class Node extends Extension { - constructor(options = {}) { - super(options) - } +// constructor(options = {}) { +// super(options) +// } - public extensionType = 'node' +// public extensionType = 'node' - public topNode = false +// public topNode = false - abstract schema(): NodeSpec +// abstract schema(): NodeSpec - get type() { - return this.editor.schema.nodes[this.name] - } +// get type() { +// return this.editor.schema.nodes[this.name] +// } +// } + +export interface NodeCallback extends ExtensionCallback { + // TODO: fix optional + type?: NodeType +} + +export interface NodeExtends extends ExtensionExtends { + topNode: boolean + schema: (params: Callback) => NodeSpec +} + +export default class Node extends Extension { + type = 'node' + + public topNode(value: NodeExtends['topNode'] = true) { + this.storeConfig('topNode', value, 'overwrite') + return this + } + + public schema(value: NodeExtends['schema']) { + this.storeConfig('schema', value, 'overwrite') + return this + } } diff --git a/packages/core/src/test.ts b/packages/core/src/test.ts index f5997f4f..cff68258 100644 --- a/packages/core/src/test.ts +++ b/packages/core/src/test.ts @@ -1,7 +1,7 @@ import { NodeSpec, NodeType } from "prosemirror-model"; import deepmerge from 'deepmerge' import collect from 'collect.js' -import { Editor, CommandSpec } from '@tiptap/core' +import { Editor, CommandSpec, ComponentRenderer } from '@tiptap/core' import cloneDeep from 'clone-deep' import { Plugin } from "prosemirror-state"; @@ -815,7 +815,7 @@ class ExtensionTest) { + public configure(options: Partial) { this.usedOptions = { ...this.usedOptions, ...options } return this } @@ -864,7 +864,7 @@ class ExtensionTest(options?: Partial>) => { - return cloneDeep(this, true).options(options as Options) + return cloneDeep(this, true).configure(options as Options) } } } @@ -922,11 +922,83 @@ const Suggestion = new NodeTest() })) .create() -const Blub = new ExtensionTest() - .name('bla') - .create() +// TODO: Erweitern +// const CustomHeadlineAligned = new Headline() +// .name('custom_headline') +// .extend('defaults', { +// levels: [1, 2, 3], +// class: 'font-xs text-outline text-center', +// alignments: ['left', 'center', 'right'], +// }) -console.log(Suggestion(), Suggestion().topNode().options({ trigger: 'jo' })) +// const CustomHeadlineTag = new Headline() +// .name('custom_headline') +// .configure({ +// class: 'custom-headline', +// }) +// .schema(() => ({ +// toDOM: () => ['h1', 0], +// toVue: Component, +// })) +// .merge('schema', () => ({ +// parseDOM: [ +// { +// tag: 'x-custom-headline', +// } +// ], +// })) + + + + + +// const Blub = new ExtensionTest() +// .name('bla') +// .create() + +console.log(Suggestion()) + + + + + +// export const Suggestion = new Suggestion() +// .name('suggestion') +// .defaults({ +// trigger: '@', +// levels: [1, 2, 3], +// }) +// .extend('schema', ({ editor, name, type}) => ({ +// // levels: [1, 2, 3, 4, 5, 6], +// toDOM: () => ['strong', 0], +// })) +// .create() + + +// const Mention = Suggestion() +// .name('mention') +// .configure({ +// trigger: '@' +// }) +// .create() + +// const Hashtag = Suggestion() +// .name('hashtag') +// .options({ +// trigger: '#' +// }) +// .create() + + +// new Editor({ +// extensions: [ +// // Mention({}), +// // Hashtag(), +// // Suggestion({ trigger: '#'}).name('hashtag'), + +// // Suggestion.option({ trigger: '@'}).name('mention'), +// ] +// }) // interface MentionOptions { // trigger: string diff --git a/packages/extension-bold/index.ts b/packages/extension-bold/index.ts index 2daffc53..1dd519af 100644 --- a/packages/extension-bold/index.ts +++ b/packages/extension-bold/index.ts @@ -1,5 +1,4 @@ -import { Mark, CommandSpec, markInputRule, markPasteRule } from '@tiptap/core' -import { MarkSpec } from 'prosemirror-model' +import { Mark, markInputRule, markPasteRule } from '@tiptap/core' import VerEx from 'verbal-expressions' declare module '@tiptap/core/src/Editor' { @@ -8,75 +7,62 @@ declare module '@tiptap/core/src/Editor' { } } -export default class Bold extends Mark { - - name = 'bold' - - schema(): MarkSpec { - return { - parseDOM: [ - { - tag: 'strong', - }, - { - tag: 'b', - 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, - }, - ], - toDOM: () => ['strong', 0], - } - } - - commands(): CommandSpec { - return { - bold: next => () => { - this.editor.toggleMark(this.name) - next() +export default new Mark() + .name('bold') + .schema(() => ({ + parseDOM: [ + { + tag: 'strong', }, - } - } + { + tag: 'b', + 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, + }, + ], + toDOM: () => ['strong', 0], + })) + .commands(({ editor, name }) => ({ + bold: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-b': () => editor.bold() + })) + // .inputRules(({ type }) => { + // return ['**', '__'].map(character => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find(character) + // .beginCapture() + // .somethingBut(character) + // .endCapture() + // .find(character) + // .endCapture() + // .endOfLine() - keys() { - return { - 'Mod-b': () => this.editor.bold() - } - } + // return markInputRule(regex, type) + // }) + // }) + // .pasteRules(({ type }) => { + // return ['**', '__'].map(character => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find(character) + // .beginCapture() + // .somethingBut(character) + // .endCapture() + // .find(character) + // .endCapture() - inputRules() { - return ['**', '__'].map(character => { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find(character) - .beginCapture() - .somethingBut(character) - .endCapture() - .find(character) - .endCapture() - .endOfLine() - - return markInputRule(regex, this.type) - }) - } - - pasteRules() { - return ['**', '__'].map(character => { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find(character) - .beginCapture() - .somethingBut(character) - .endCapture() - .find(character) - .endCapture() - - return markPasteRule(regex, this.type) - }) - } - -} \ No newline at end of file + // return markPasteRule(regex, type) + // }) + // }) + .create() diff --git a/packages/extension-code/index.ts b/packages/extension-code/index.ts index 815b2aee..3efec669 100644 --- a/packages/extension-code/index.ts +++ b/packages/extension-code/index.ts @@ -1,5 +1,4 @@ -import { Mark, markInputRule, markPasteRule, CommandSpec } from '@tiptap/core' -import { MarkSpec } from 'prosemirror-model' +import { Mark, markInputRule, markPasteRule } from '@tiptap/core' import VerEx from 'verbal-expressions' declare module '@tiptap/core/src/Editor' { @@ -8,62 +7,49 @@ declare module '@tiptap/core/src/Editor' { } } -export default class Code extends Mark { +export default new Mark() + .name('code') + .schema(() => ({ + excludes: '_', + parseDOM: [ + { tag: 'code' }, + ], + toDOM: () => ['code', 0], + })) + .commands(({ editor, name }) => ({ + code: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-`': () => editor.code() + })) + // .inputRules(({ type }) => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find('`') + // .beginCapture() + // .somethingBut('`') + // .endCapture() + // .find('`') + // .endCapture() + // .endOfLine() - name = 'code' + // return [markInputRule(regex, type)] + // }) + // .pasteRules(({ type }) => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find('`') + // .beginCapture() + // .somethingBut('`') + // .endCapture() + // .find('`') + // .endCapture() - schema(): MarkSpec { - return { - excludes: '_', - parseDOM: [ - { tag: 'code' }, - ], - toDOM: () => ['code', 0], - } - } - - commands(): CommandSpec { - return { - code: next => () => { - this.editor.toggleMark(this.name) - next() - }, - } - } - - keys() { - return { - 'Mod-`': () => this.editor.code() - } - } - - inputRules() { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find('`') - .beginCapture() - .somethingBut('`') - .endCapture() - .find('`') - .endCapture() - .endOfLine() - - return markInputRule(regex, this.type) - } - - pasteRules() { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find('`') - .beginCapture() - .somethingBut('`') - .endCapture() - .find('`') - .endCapture() - - return markPasteRule(regex, this.type) - } - -} \ No newline at end of file + // return [markPasteRule(regex, type)] + // }) + .create() diff --git a/packages/extension-codeblock/index.ts b/packages/extension-codeblock/index.ts index 96ed30dc..dfd2a736 100644 --- a/packages/extension-codeblock/index.ts +++ b/packages/extension-codeblock/index.ts @@ -1,23 +1,17 @@ import { Node } from '@tiptap/core' -import { NodeSpec } from 'prosemirror-model' -export default class CodeBlock extends Node { - - name = 'code_block' - - schema(): NodeSpec { - return { - content: 'text*', - marks: '', - group: 'block', - code: true, - defining: true, - draggable: false, - parseDOM: [ - { tag: 'pre', preserveWhitespace: 'full' }, - ], - toDOM: () => ['pre', ['code', 0]], - } - } - -} \ No newline at end of file +export default new Node() + .name('code_block') + .schema(() => ({ + content: 'text*', + marks: '', + group: 'block', + code: true, + defining: true, + draggable: false, + parseDOM: [ + { tag: 'pre', preserveWhitespace: 'full' }, + ], + toDOM: () => ['pre', ['code', 0]], + })) + .create() diff --git a/packages/extension-document/index.ts b/packages/extension-document/index.ts index 86213562..7099a8d4 100644 --- a/packages/extension-document/index.ts +++ b/packages/extension-document/index.ts @@ -1,16 +1,9 @@ import { Node } from '@tiptap/core' -import { NodeSpec } from 'prosemirror-model' -export default class Document extends Node { - - name = 'document' - - topNode = true - - schema(): NodeSpec { - return { - content: 'block+', - } - } - -} \ No newline at end of file +export default new Node() + .name('document') + .topNode() + .schema(() => ({ + content: 'block+', + })) + .create() \ No newline at end of file diff --git a/packages/extension-focus/index.ts b/packages/extension-focus/index.ts index ae00586c..aeeb4ab9 100644 --- a/packages/extension-focus/index.ts +++ b/packages/extension-focus/index.ts @@ -7,52 +7,40 @@ interface FocusOptions { nested: boolean, } -export default class Focus extends Extension { +export default new Extension() + .name('focus') + .defaults({ + className: 'has-focus', + nested: false, + }) + .plugins(({ editor, options }) => [ + new Plugin({ + props: { + decorations: ({ doc, selection }) => { + const { isEditable, isFocused } = editor + const { anchor } = selection + const decorations: Decoration[] = [] - name = 'focus' + if (!isEditable || !isFocused) { + return + } - constructor(options: Partial = {}) { - super(options) - } + doc.descendants((node, pos) => { + const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize) - defaultOptions(): FocusOptions { - return { - className: 'has-focus', - nested: false, - } - } - - plugins() { - return [ - new Plugin({ - props: { - decorations: ({ doc, selection }) => { - const { isEditable, isFocused } = this.editor - const { anchor } = selection - const decorations: Decoration[] = [] - - if (!isEditable || !isFocused) { - return + if (hasAnchor && !node.isText) { + const decoration = Decoration.node(pos, pos + node.nodeSize, { + class: options.className, + }) + decorations.push(decoration) } - doc.descendants((node, pos) => { - const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize) + return options.nested + }) - if (hasAnchor && !node.isText) { - const decoration = Decoration.node(pos, pos + node.nodeSize, { - class: this.options.className, - }) - decorations.push(decoration) - } - - return this.options.nested - }) - - return DecorationSet.create(doc, decorations) - }, + return DecorationSet.create(doc, decorations) }, - }), - ] - } - -} + }, + }), + ]) + .create() diff --git a/packages/extension-heading/index.ts b/packages/extension-heading/index.ts index 72b631e9..0b124c62 100644 --- a/packages/extension-heading/index.ts +++ b/packages/extension-heading/index.ts @@ -15,60 +15,44 @@ declare module '@tiptap/core/src/Editor' { } } -export default class Heading extends Node { - - name = 'heading' - - constructor(options: Partial = {}) { - super(options) - } - - defaultOptions(): HeadingOptions { - return { - levels: [1, 2, 3, 4, 5, 6], - } - } - - schema(): NodeSpec { - return { - attrs: { - level: { - default: 1, - }, +export default new Node() + .name('heading') + .defaults({ + levels: [1, 2, 3, 4, 5, 6], + }) + .schema(({ options }) => ({ + attrs: { + level: { + default: 1, }, - content: 'inline*', - group: 'block', - defining: true, - draggable: false, - parseDOM: this.options.levels - .map((level: Level) => ({ - tag: `h${level}`, - attrs: { level }, - })), - toDOM: node => [`h${node.attrs.level}`, 0], - } - } + }, + content: 'inline*', + group: 'block', + defining: true, + draggable: false, + parseDOM: options.levels + .map((level: Level) => ({ + tag: `h${level}`, + attrs: { level }, + })), + toDOM: node => [`h${node.attrs.level}`, 0], + })) + .commands(({ editor, name }) => ({ + [name]: next => attrs => { + editor.toggleNode(name, 'paragraph', attrs) + next() + }, + })) + // .inputRules(({ options, type }) => { + // return options.levels.map((level: Level) => { + // const regex = VerEx() + // .startOfLine() + // .find('#') + // .repeatPrevious(level) + // .whitespace() + // .endOfLine() - commands(): CommandSpec { - return { - heading: next => attrs => { - this.editor.toggleNode(this.name, 'paragraph', attrs) - next() - }, - } - } - - inputRules() { - return this.options.levels.map((level: Level) => { - const regex = VerEx() - .startOfLine() - .find('#') - .repeatPrevious(level) - .whitespace() - .endOfLine() - - return textblockTypeInputRule(regex, this.type, { level }) - }) - } - -} \ No newline at end of file + // return textblockTypeInputRule(regex, type, { level }) + // }) + // }) + .create() diff --git a/packages/extension-history/index.ts b/packages/extension-history/index.ts index 2bc3ac75..2038ee81 100644 --- a/packages/extension-history/index.ts +++ b/packages/extension-history/index.ts @@ -1,4 +1,4 @@ -import { Extension, CommandSpec } from '@tiptap/core' +import { Extension } from '@tiptap/core' import { history, undo, @@ -15,48 +15,30 @@ declare module '@tiptap/core/src/Editor' { } interface HistoryOptions { - historyPluginOptions?: Object, + historyPluginOptions: Object, } -export default class History extends Extension { - - name = 'history' - - constructor(options: Partial = {}) { - super(options) - } - - defaultOptions(): HistoryOptions { - return { - historyPluginOptions: {}, - } - } - - commands(): CommandSpec { - return { - undo: (next, { view }) => () => { - undo(view.state, view.dispatch) - next() - }, - redo: (next, { view }) => () => { - redo(view.state, view.dispatch) - next() - }, - } - } - - keys() { - return { - 'Mod-z': () => this.editor.undo(), - 'Mod-y': () => this.editor.redo(), - 'Shift-Mod-z': () => this.editor.redo(), - } - } - - plugins() { - return [ - history(this.options.historyPluginOptions) - ] - } - -} \ No newline at end of file +export default new Extension() + .name('history') + .defaults({ + historyPluginOptions: {}, + }) + .commands(() => ({ + undo: (next, { view }) => () => { + undo(view.state, view.dispatch) + next() + }, + redo: (next, { view }) => () => { + redo(view.state, view.dispatch) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-z': () => editor.undo(), + 'Mod-y': () => editor.redo(), + 'Shift-Mod-z': () => editor.redo(), + })) + .plugins(({ options }) => [ + history(options.historyPluginOptions) + ]) + .create() diff --git a/packages/extension-italic/index.ts b/packages/extension-italic/index.ts index d0492e4b..ad809602 100644 --- a/packages/extension-italic/index.ts +++ b/packages/extension-italic/index.ts @@ -1,5 +1,4 @@ -import { Mark, markInputRule, markPasteRule, CommandSpec } from '@tiptap/core' -import { MarkSpec } from 'prosemirror-model' +import { Mark, markInputRule, markPasteRule } from '@tiptap/core' import VerEx from 'verbal-expressions' declare module '@tiptap/core/src/Editor' { @@ -8,67 +7,54 @@ declare module '@tiptap/core/src/Editor' { } } -export default class Italic extends Mark { +export default new Mark() + .name('italic') + .schema(() => ({ + parseDOM: [ + { tag: 'i' }, + { tag: 'em' }, + { style: 'font-style=italic' }, + ], + toDOM: () => ['em', 0], + })) + .commands(({ editor, name }) => ({ + italic: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-i': () => editor.italic() + })) + // .inputRules(({ type }) => { + // return ['*', '_'].map(character => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find(character) + // .beginCapture() + // .somethingBut(character) + // .endCapture() + // .find(character) + // .endCapture() + // .endOfLine() - name = 'italic' + // return markInputRule(regex, type) + // }) + // }) + // .pasteRules(({ type }) => { + // return ['*', '_'].map(character => { + // const regex = VerEx() + // .add('(?:^|\\s)') + // .beginCapture() + // .find(character) + // .beginCapture() + // .somethingBut(character) + // .endCapture() + // .find(character) + // .endCapture() - schema(): MarkSpec { - return { - parseDOM: [ - { tag: 'i' }, - { tag: 'em' }, - { style: 'font-style=italic' }, - ], - toDOM: () => ['em', 0], - } - } - - commands(): CommandSpec { - return { - italic: next => () => { - this.editor.toggleMark(this.name) - next() - }, - } - } - - keys() { - return { - 'Mod-i': () => this.editor.italic() - } - } - - inputRules() { - return ['*', '_'].map(character => { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find(character) - .beginCapture() - .somethingBut(character) - .endCapture() - .find(character) - .endCapture() - .endOfLine() - - return markInputRule(regex, this.type) - }) - } - - pasteRules() { - return ['*', '_'].map(character => { - const regex = VerEx() - .add('(?:^|\\s)') - .beginCapture() - .find(character) - .beginCapture() - .somethingBut(character) - .endCapture() - .find(character) - .endCapture() - - return markPasteRule(regex, this.type) - }) - } - -} \ No newline at end of file + // return markPasteRule(regex, type) + // }) + // }) + .create() diff --git a/packages/extension-paragraph/index.ts b/packages/extension-paragraph/index.ts index 05a386aa..a09ee093 100644 --- a/packages/extension-paragraph/index.ts +++ b/packages/extension-paragraph/index.ts @@ -1,19 +1,13 @@ import { Node } from '@tiptap/core' -import { NodeSpec } from 'prosemirror-model' // import ParagraphComponent from './paragraph.vue' -export default class Paragraph extends Node { - - name = 'paragraph' - - schema(): NodeSpec { - return { - content: 'inline*', - group: 'block', - parseDOM: [{ tag: 'p' }], - toDOM: () => ['p', 0], - // toVue: ParagraphComponent, - } - } - -} \ No newline at end of file +export default new Node() + .name('paragraph') + .schema(() => ({ + content: 'inline*', + group: 'block', + parseDOM: [{ tag: 'p' }], + toDOM: () => ['p', 0], + // toVue: ParagraphComponent, + })) + .create() \ No newline at end of file diff --git a/packages/extension-text/index.ts b/packages/extension-text/index.ts index 3ca1675b..46fe7b40 100644 --- a/packages/extension-text/index.ts +++ b/packages/extension-text/index.ts @@ -1,14 +1,8 @@ import { Node } from '@tiptap/core' -import { NodeSpec } from 'prosemirror-model' -export default class Text extends Node { - - name = 'text' - - schema(): NodeSpec { - return { - group: 'inline', - } - } - -} \ No newline at end of file +export default new Node() + .name('text') + .schema(() => ({ + group: 'inline', + })) + .create() \ No newline at end of file diff --git a/packages/starter-kit/index.ts b/packages/starter-kit/index.ts index 93e6fb89..0e3915a9 100644 --- a/packages/starter-kit/index.ts +++ b/packages/starter-kit/index.ts @@ -10,14 +10,14 @@ import Heading from '@tiptap/extension-heading' export default function defaultExtensions() { return [ - new Document(), - new History(), - new Paragraph(), - new Text(), - new Bold(), - new Italic(), - new Code(), - new CodeBlock(), - new Heading(), + Document(), + History(), + Paragraph(), + Text(), + Bold(), + Italic(), + Code(), + CodeBlock(), + Heading(), ] } \ No newline at end of file diff --git a/packages/vue-starter-kit/index.ts b/packages/vue-starter-kit/index.ts index 0c749598..3cb508c2 100644 --- a/packages/vue-starter-kit/index.ts +++ b/packages/vue-starter-kit/index.ts @@ -12,14 +12,14 @@ import Heading from '@tiptap/extension-heading' export function defaultExtensions() { return [ - new Document(), - new History(), - new Paragraph(), - new Text(), - new Bold(), - new Italic(), - new Code(), - new CodeBlock(), - new Heading(), + Document(), + History(), + Paragraph(), + Text(), + Bold(), + Italic(), + Code(), + CodeBlock(), + Heading(), ] } \ No newline at end of file