replace NodeExtension with Node, replace MarkExtension with Mark

This commit is contained in:
Philipp Kühn
2020-11-16 11:19:43 +01:00
parent b44aafa97c
commit 8a7603edaf
31 changed files with 105 additions and 99 deletions

View File

@@ -15,8 +15,8 @@ import CommandManager from './CommandManager'
import ExtensionManager from './ExtensionManager'
import EventEmitter from './EventEmitter'
import { Extension } from './Extension'
import { NodeExtension } from './NodeExtension'
import { MarkExtension } from './MarkExtension'
import { Node } from './Node'
import { Mark } from './Mark'
import { Extensions, UnionToIntersection } from './types'
import * as extensions from './extensions'
import style from './style'
@@ -43,10 +43,10 @@ export interface AllExtensions {}
export type UnfilteredCommands = {
[Item in keyof AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
? ExtensionCommands
: AllExtensions[Item] extends NodeExtension<any, infer NodeExtensionCommands>
? NodeExtensionCommands
: AllExtensions[Item] extends MarkExtension<any, infer MarkExtensionCommands>
? MarkExtensionCommands
: AllExtensions[Item] extends Node<any, infer NodeCommands>
? NodeCommands
: AllExtensions[Item] extends Mark<any, infer MarkCommands>
? MarkCommands
: never
}

View File

@@ -1,5 +1,8 @@
import {
DOMOutputSpec, MarkSpec, Mark, MarkType,
DOMOutputSpec,
MarkSpec,
Mark as ProseMirrorMark,
MarkType,
} from 'prosemirror-model'
import { Plugin } from 'prosemirror-state'
import { ExtensionSpec } from './Extension'
@@ -44,7 +47,7 @@ export interface MarkExtensionSpec<Options = any, Commands = {}> extends Overwri
options: Options,
},
props: {
mark: Mark,
mark: ProseMirrorMark,
HTMLAttributes: { [key: string]: any },
}
) => DOMOutputSpec) | null,
@@ -106,7 +109,7 @@ export interface MarkExtensionSpec<Options = any, Commands = {}> extends Overwri
}) => Plugin[],
}> {}
export class MarkExtension<Options = any, Commands = {}> {
export class Mark<Options = any, Commands = {}> {
config: Required<MarkExtensionSpec> = {
name: 'mark',
defaultOptions: {},
@@ -137,11 +140,11 @@ export class MarkExtension<Options = any, Commands = {}> {
}
static create<O, C>(config: MarkExtensionSpec<O, C>) {
return new MarkExtension<O, C>(config)
return new Mark<O, C>(config)
}
configure(options: Partial<Options>) {
return MarkExtension
return Mark
.create<Options, Commands>(this.config as MarkExtensionSpec<Options, Commands>)
.#configure({
...this.config.defaultOptions,
@@ -159,7 +162,7 @@ export class MarkExtension<Options = any, Commands = {}> {
}
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkExtensionSpec<ExtendedOptions, ExtendedCommands>>) {
return new MarkExtension<ExtendedOptions, ExtendedCommands>({
return new Mark<ExtendedOptions, ExtendedCommands>({
...this.config,
...extendedConfig,
} as MarkExtensionSpec<ExtendedOptions, ExtendedCommands>)

View File

@@ -1,5 +1,8 @@
import {
DOMOutputSpec, NodeSpec, Node, NodeType,
DOMOutputSpec,
NodeSpec,
Node as ProseMirrorNode,
NodeType,
} from 'prosemirror-model'
import { Plugin } from 'prosemirror-state'
import { ExtensionSpec } from './Extension'
@@ -79,7 +82,7 @@ export interface NodeExtensionSpec<Options = any, Commands = {}> extends Overwri
options: Options,
},
props: {
node: Node,
node: ProseMirrorNode,
HTMLAttributes: { [key: string]: any },
}
) => DOMOutputSpec) | null,
@@ -150,7 +153,7 @@ export interface NodeExtensionSpec<Options = any, Commands = {}> extends Overwri
}) => NodeViewRenderer) | null,
}> {}
export class NodeExtension<Options = any, Commands = {}> {
export class Node<Options = any, Commands = {}> {
config: Required<NodeExtensionSpec> = {
name: 'node',
defaultOptions: {},
@@ -189,11 +192,11 @@ export class NodeExtension<Options = any, Commands = {}> {
}
static create<O, C>(config: NodeExtensionSpec<O, C>) {
return new NodeExtension<O, C>(config)
return new Node<O, C>(config)
}
configure(options: Partial<Options>) {
return NodeExtension
return Node
.create<Options, Commands>(this.config as NodeExtensionSpec<Options, Commands>)
.#configure({
...this.config.defaultOptions,
@@ -211,7 +214,7 @@ export class NodeExtension<Options = any, Commands = {}> {
}
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeExtensionSpec<ExtendedOptions, ExtendedCommands>>) {
return new NodeExtension<ExtendedOptions, ExtendedCommands>({
return new Node<ExtendedOptions, ExtendedCommands>({
...this.config,
...extendedConfig,
} as NodeExtensionSpec<ExtendedOptions, ExtendedCommands>)

View File

@@ -6,8 +6,8 @@ export {
} from './Editor'
export * from './Extension'
export * from './NodeExtension'
export * from './MarkExtension'
export * from './Node'
export * from './Mark'
export * from './types'
export { default as nodeInputRule } from './inputRules/nodeInputRule'

View File

@@ -1,11 +1,11 @@
import { Node } from 'prosemirror-model'
import { Node as ProseMirrorNode } from 'prosemirror-model'
import { Decoration, NodeView } from 'prosemirror-view'
import { Extension } from './Extension'
import { NodeExtension } from './NodeExtension'
import { MarkExtension } from './MarkExtension'
import { Node } from './Node'
import { Mark } from './Mark'
import { Editor } from './Editor'
export type Extensions = (Extension | NodeExtension | MarkExtension)[]
export type Extensions = (Extension | Node | Mark)[]
export type Attribute = {
default: any,
@@ -46,7 +46,7 @@ export type AnyObject = {
export type NodeViewRendererProps = {
editor: Editor,
node: Node,
node: ProseMirrorNode,
getPos: (() => number) | boolean,
decorations: Decoration[],
HTMLAttributes: { [key: string]: any },

View File

@@ -1,12 +1,12 @@
import { Extensions } from '../types'
import { Extension } from '../Extension'
import { NodeExtension } from '../NodeExtension'
import { MarkExtension } from '../MarkExtension'
import { Node } from '../Node'
import { Mark } from '../Mark'
export default function splitExtensions(extensions: Extensions) {
const baseExtensions = extensions.filter(extension => extension instanceof Extension) as Extension[]
const nodeExtensions = extensions.filter(extension => extension instanceof NodeExtension) as NodeExtension[]
const markExtensions = extensions.filter(extension => extension instanceof MarkExtension) as MarkExtension[]
const nodeExtensions = extensions.filter(extension => extension instanceof Node) as Node[]
const markExtensions = extensions.filter(extension => extension instanceof Mark) as Mark[]
return {
baseExtensions,

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export interface BlockquoteOptions {
@@ -9,7 +9,7 @@ export interface BlockquoteOptions {
export const inputRegex = /^\s*>\s$/gm
const Blockquote = NodeExtension.create({
const Blockquote = Node.create({
name: 'blockquote',
defaultOptions: <BlockquoteOptions>{

View File

@@ -1,5 +1,5 @@
import {
Command, MarkExtension, markInputRule, markPasteRule,
Command, Mark, markInputRule, markPasteRule,
} from '@tiptap/core'
export interface BoldOptions {
@@ -13,7 +13,7 @@ export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/gm
const Bold = MarkExtension.create({
const Bold = Mark.create({
name: 'bold',
defaultOptions: <BoldOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export interface BulletListOptions {
@@ -9,7 +9,7 @@ export interface BulletListOptions {
export const inputRegex = /^\s*([-+*])\s$/
const BulletList = NodeExtension.create({
const BulletList = Node.create({
name: 'bulletList',
defaultOptions: <BulletListOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { textblockTypeInputRule } from 'prosemirror-inputrules'
export interface CodeBlockOptions {
@@ -11,7 +11,7 @@ export interface CodeBlockOptions {
export const backtickInputRegex = /^```(?<language>[a-z]*)? $/
export const tildeInputRegex = /^~~~(?<language>[a-z]*)? $/
const CodeBlock = NodeExtension.create({
const CodeBlock = Node.create({
name: 'codeBlock',
defaultOptions: <CodeBlockOptions>{

View File

@@ -1,6 +1,6 @@
import {
Command,
MarkExtension,
Mark,
markInputRule,
markPasteRule,
} from '@tiptap/core'
@@ -14,7 +14,7 @@ export interface CodeOptions {
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
const Code = MarkExtension.create({
const Code = Mark.create({
name: 'code',
defaultOptions: <CodeOptions>{

View File

@@ -1,6 +1,6 @@
import { NodeExtension } from '@tiptap/core'
import { Node } from '@tiptap/core'
const Document = NodeExtension.create({
const Document = Node.create({
name: 'document',
topNode: true,
content: 'block+',

View File

@@ -1,7 +1,7 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { exitCode } from 'prosemirror-commands'
const HardBreak = NodeExtension.create({
const HardBreak = Node.create({
name: 'hardBreak',
inline: true,

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { textblockTypeInputRule } from 'prosemirror-inputrules'
type Level = 1 | 2 | 3 | 4 | 5 | 6
@@ -10,7 +10,7 @@ export interface HeadingOptions {
},
}
const Heading = NodeExtension.create({
const Heading = Node.create({
name: 'heading',
defaultOptions: <HeadingOptions>{

View File

@@ -1,6 +1,6 @@
import {
Command,
MarkExtension,
Mark,
markInputRule,
markPasteRule,
} from '@tiptap/core'
@@ -14,7 +14,7 @@ export interface HighlightOptions {
export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm
export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm
const Highlight = MarkExtension.create({
const Highlight = Mark.create({
name: 'highlight',
defaultOptions: <HighlightOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension, nodeInputRule } from '@tiptap/core'
import { Command, Node, nodeInputRule } from '@tiptap/core'
export interface HorizontalRuleOptions {
HTMLAttributes: {
@@ -6,7 +6,7 @@ export interface HorizontalRuleOptions {
},
}
const HorizontalRule = NodeExtension.create({
const HorizontalRule = Node.create({
name: 'horizontalRule',
defaultOptions: <HorizontalRuleOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension, nodeInputRule } from '@tiptap/core'
import { Command, Node, nodeInputRule } from '@tiptap/core'
export interface ImageOptions {
inline: boolean,
@@ -9,7 +9,7 @@ export interface ImageOptions {
export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
const Image = NodeExtension.create({
const Image = Node.create({
name: 'image',
defaultOptions: <ImageOptions>{

View File

@@ -1,6 +1,6 @@
import {
Command,
MarkExtension,
Mark,
markInputRule,
markPasteRule,
} from '@tiptap/core'
@@ -16,7 +16,7 @@ export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm
export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm
export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm
const Italic = MarkExtension.create({
const Italic = Mark.create({
name: 'italic',
defaultOptions: <ItalicOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, MarkExtension, markPasteRule } from '@tiptap/core'
import { Command, Mark, markPasteRule } from '@tiptap/core'
import { Plugin, PluginKey } from 'prosemirror-state'
export interface LinkOptions {
@@ -10,7 +10,7 @@ export interface LinkOptions {
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)/gi
const Link = MarkExtension.create({
const Link = Mark.create({
name: 'link',
inclusive: false,

View File

@@ -1,4 +1,4 @@
import { NodeExtension } from '@tiptap/core'
import { Node } from '@tiptap/core'
export interface ListItemOptions {
HTMLAttributes: {
@@ -6,7 +6,7 @@ export interface ListItemOptions {
},
}
const ListItem = NodeExtension.create({
const ListItem = Node.create({
name: 'listItem',
defaultOptions: <ListItemOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export interface OrderedListOptions {
@@ -9,7 +9,7 @@ export interface OrderedListOptions {
export const inputRegex = /^(\d+)\.\s$/
const OrderedList = NodeExtension.create({
const OrderedList = Node.create({
name: 'orderedList',
defaultOptions: <OrderedListOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension } from '@tiptap/core'
import { Command, Node } from '@tiptap/core'
export interface ParagraphOptions {
HTMLAttributes: {
@@ -6,7 +6,7 @@ export interface ParagraphOptions {
},
}
const Paragraph = NodeExtension.create({
const Paragraph = Node.create({
name: 'paragraph',
defaultOptions: <ParagraphOptions>{

View File

@@ -1,6 +1,6 @@
import {
Command,
MarkExtension,
Mark,
markInputRule,
markPasteRule,
} from '@tiptap/core'
@@ -14,7 +14,7 @@ export interface StrikeOptions {
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
const Strike = MarkExtension.create({
const Strike = Mark.create({
name: 'strike',
defaultOptions: <StrikeOptions>{

View File

@@ -1,4 +1,4 @@
import { NodeExtension, mergeAttributes } from '@tiptap/core'
import { Node, mergeAttributes } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules'
export interface TaskItemOptions {
@@ -10,7 +10,7 @@ export interface TaskItemOptions {
export const inputRegex = /^\s*(\[([ |x])\])\s$/
const TaskItem = NodeExtension.create({
const TaskItem = Node.create({
name: 'taskItem',
defaultOptions: <TaskItemOptions>{

View File

@@ -1,4 +1,4 @@
import { Command, NodeExtension, mergeAttributes } from '@tiptap/core'
import { Command, Node, mergeAttributes } from '@tiptap/core'
export interface TaskListOptions {
HTMLAttributes: {
@@ -6,7 +6,7 @@ export interface TaskListOptions {
},
}
const TaskList = NodeExtension.create({
const TaskList = Node.create({
name: 'taskList',
defaultOptions: <TaskListOptions>{

View File

@@ -1,6 +1,6 @@
import { Command, MarkExtension, getMarkAttrs } from '@tiptap/core'
import { Command, Mark, getMarkAttrs } from '@tiptap/core'
const TextStyle = MarkExtension.create({
const TextStyle = Mark.create({
name: 'textStyle',
parseHTML() {

View File

@@ -1,6 +1,6 @@
import { NodeExtension } from '@tiptap/core'
import { Node } from '@tiptap/core'
const Text = NodeExtension.create({
const Text = Node.create({
name: 'text',
group: 'inline',
})

View File

@@ -1,4 +1,4 @@
import { Command, MarkExtension } from '@tiptap/core'
import { Command, Mark } from '@tiptap/core'
export interface UnderlineOptions {
HTMLAttributes: {
@@ -6,7 +6,7 @@ export interface UnderlineOptions {
},
}
const Underline = MarkExtension.create({
const Underline = Mark.create({
name: 'underline',
defaultOptions: <UnderlineOptions>{