refactoring
This commit is contained in:
@@ -14,25 +14,16 @@ import createStyleTag from './utils/createStyleTag'
|
|||||||
import CommandManager from './CommandManager'
|
import CommandManager from './CommandManager'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
import EventEmitter from './EventEmitter'
|
import EventEmitter from './EventEmitter'
|
||||||
import { Extensions, EditorContent, CommandSpec } from './types'
|
import { EditorOptions, EditorContent, CommandSpec } from './types'
|
||||||
import * as extensions from './extensions'
|
import * as extensions from './extensions'
|
||||||
import style from './style'
|
import style from './style'
|
||||||
|
|
||||||
export { extensions }
|
export { extensions }
|
||||||
|
|
||||||
interface HTMLElement {
|
export interface HTMLElement {
|
||||||
editor?: Editor
|
editor?: Editor
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EditorOptions {
|
|
||||||
element: Element,
|
|
||||||
content: EditorContent,
|
|
||||||
extensions: Extensions,
|
|
||||||
injectCSS: boolean,
|
|
||||||
autoFocus: 'start' | 'end' | number | boolean | null,
|
|
||||||
editable: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
@magicMethods
|
@magicMethods
|
||||||
export class Editor extends EventEmitter {
|
export class Editor extends EventEmitter {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Plugin } from 'prosemirror-state'
|
import { Plugin } from 'prosemirror-state'
|
||||||
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
import { GlobalAttributes } from './types'
|
import { GlobalAttributes } from './types'
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ export interface ExtensionConfig<Options = any, Commands = {}> {
|
|||||||
addInputRules?: (this: {
|
addInputRules?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
}) => any[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paste rules
|
* Paste rules
|
||||||
@@ -52,7 +53,7 @@ export interface ExtensionConfig<Options = any, Commands = {}> {
|
|||||||
addPasteRules?: (this: {
|
addPasteRules?: (this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
}) => any[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProseMirror plugins
|
* ProseMirror plugins
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import {
|
|||||||
MarkType,
|
MarkType,
|
||||||
} from 'prosemirror-model'
|
} from 'prosemirror-model'
|
||||||
import { Plugin } from 'prosemirror-state'
|
import { Plugin } from 'prosemirror-state'
|
||||||
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import { ExtensionConfig } from './Extension'
|
import { ExtensionConfig } from './Extension'
|
||||||
import { Attribute, Overwrite } from './types'
|
import { Attributes, Overwrite } from './types'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
|
|
||||||
export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
||||||
@@ -59,9 +60,7 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
},
|
},
|
||||||
) => {
|
) => Attributes,
|
||||||
[key: string]: Attribute
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands
|
* Commands
|
||||||
@@ -90,7 +89,7 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
}) => any[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paste rules
|
* Paste rules
|
||||||
@@ -99,7 +98,7 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: MarkType,
|
type: MarkType,
|
||||||
}) => any[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProseMirror plugins
|
* ProseMirror plugins
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import {
|
|||||||
NodeType,
|
NodeType,
|
||||||
} from 'prosemirror-model'
|
} from 'prosemirror-model'
|
||||||
import { Plugin } from 'prosemirror-state'
|
import { Plugin } from 'prosemirror-state'
|
||||||
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
import { ExtensionConfig } from './Extension'
|
import { ExtensionConfig } from './Extension'
|
||||||
import { Attribute, NodeViewRenderer, Overwrite } from './types'
|
import { Attributes, NodeViewRenderer, Overwrite } from './types'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
|
|
||||||
export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
|
||||||
@@ -94,9 +95,7 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
this: {
|
this: {
|
||||||
options: Options,
|
options: Options,
|
||||||
},
|
},
|
||||||
) => {
|
) => Attributes,
|
||||||
[key: string]: Attribute
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands
|
* Commands
|
||||||
@@ -125,7 +124,7 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
}) => any[],
|
}) => InputRule[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paste rules
|
* Paste rules
|
||||||
@@ -134,7 +133,7 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
|||||||
options: Options,
|
options: Options,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
}) => any[],
|
}) => Plugin[],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProseMirror plugins
|
* ProseMirror plugins
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ export * from './Node'
|
|||||||
export * from './Mark'
|
export * from './Mark'
|
||||||
export * from './types'
|
export * from './types'
|
||||||
|
|
||||||
export interface AllExtensions {}
|
|
||||||
|
|
||||||
export { default as nodeInputRule } from './inputRules/nodeInputRule'
|
export { default as nodeInputRule } from './inputRules/nodeInputRule'
|
||||||
export { default as markInputRule } from './inputRules/markInputRule'
|
export { default as markInputRule } from './inputRules/markInputRule'
|
||||||
export { default as markPasteRule } from './pasteRules/markPasteRule'
|
export { default as markPasteRule } from './pasteRules/markPasteRule'
|
||||||
@@ -15,3 +13,5 @@ export { default as generateHTML } from './utils/generateHTML'
|
|||||||
export { default as getHTMLFromFragment } from './utils/getHTMLFromFragment'
|
export { default as getHTMLFromFragment } from './utils/getHTMLFromFragment'
|
||||||
export { default as getMarkAttrs } from './utils/getMarkAttrs'
|
export { default as getMarkAttrs } from './utils/getMarkAttrs'
|
||||||
export { default as mergeAttributes } from './utils/mergeAttributes'
|
export { default as mergeAttributes } from './utils/mergeAttributes'
|
||||||
|
|
||||||
|
export interface AllExtensions {}
|
||||||
|
|||||||
@@ -7,6 +7,17 @@ import { Mark } from './Mark'
|
|||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
import { AllExtensions } from '.'
|
import { AllExtensions } from '.'
|
||||||
|
|
||||||
|
export type Extensions = (Extension | Node | Mark)[]
|
||||||
|
|
||||||
|
export interface EditorOptions {
|
||||||
|
element: Element,
|
||||||
|
content: EditorContent,
|
||||||
|
extensions: Extensions,
|
||||||
|
injectCSS: boolean,
|
||||||
|
autoFocus: 'start' | 'end' | number | boolean | null,
|
||||||
|
editable: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
export type EditorContent = string | JSON | null
|
export type EditorContent = string | JSON | null
|
||||||
|
|
||||||
export type Command = (props: {
|
export type Command = (props: {
|
||||||
@@ -22,8 +33,6 @@ export type Command = (props: {
|
|||||||
|
|
||||||
export type CommandSpec = (...args: any[]) => Command
|
export type CommandSpec = (...args: any[]) => Command
|
||||||
|
|
||||||
export type Extensions = (Extension | Node | Mark)[]
|
|
||||||
|
|
||||||
export type Attribute = {
|
export type Attribute = {
|
||||||
default: any,
|
default: any,
|
||||||
rendered?: boolean,
|
rendered?: boolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user