From d05c9fda3efce27b7ea0489a2b15261131df8efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 16 Nov 2020 21:54:40 +0100 Subject: [PATCH] refactoring --- packages/core/src/Editor.ts | 13 ++----------- packages/core/src/Extension.ts | 5 +++-- packages/core/src/Mark.ts | 11 +++++------ packages/core/src/Node.ts | 11 +++++------ packages/core/src/index.ts | 4 ++-- packages/core/src/types.ts | 13 +++++++++++-- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index dd5ce37a..30309009 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -14,25 +14,16 @@ import createStyleTag from './utils/createStyleTag' import CommandManager from './CommandManager' import ExtensionManager from './ExtensionManager' import EventEmitter from './EventEmitter' -import { Extensions, EditorContent, CommandSpec } from './types' +import { EditorOptions, EditorContent, CommandSpec } from './types' import * as extensions from './extensions' import style from './style' export { extensions } -interface HTMLElement { +export interface HTMLElement { editor?: Editor } -interface EditorOptions { - element: Element, - content: EditorContent, - extensions: Extensions, - injectCSS: boolean, - autoFocus: 'start' | 'end' | number | boolean | null, - editable: boolean, -} - @magicMethods export class Editor extends EventEmitter { diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index 4061ec2a..50e7157d 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -1,4 +1,5 @@ import { Plugin } from 'prosemirror-state' +import { InputRule } from 'prosemirror-inputrules' import { Editor } from './Editor' import { GlobalAttributes } from './types' @@ -44,7 +45,7 @@ export interface ExtensionConfig { addInputRules?: (this: { options: Options, editor: Editor, - }) => any[], + }) => InputRule[], /** * Paste rules @@ -52,7 +53,7 @@ export interface ExtensionConfig { addPasteRules?: (this: { options: Options, editor: Editor, - }) => any[], + }) => Plugin[], /** * ProseMirror plugins diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index b765b687..6d4a948a 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -5,8 +5,9 @@ import { MarkType, } from 'prosemirror-model' import { Plugin } from 'prosemirror-state' +import { InputRule } from 'prosemirror-inputrules' import { ExtensionConfig } from './Extension' -import { Attribute, Overwrite } from './types' +import { Attributes, Overwrite } from './types' import { Editor } from './Editor' export interface MarkConfig extends Overwrite, { @@ -59,9 +60,7 @@ export interface MarkConfig extends Overwrite { - [key: string]: Attribute - }, + ) => Attributes, /** * Commands @@ -90,7 +89,7 @@ export interface MarkConfig extends Overwrite any[], + }) => InputRule[], /** * Paste rules @@ -99,7 +98,7 @@ export interface MarkConfig extends Overwrite any[], + }) => Plugin[], /** * ProseMirror plugins diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index f42600b9..b5ba6c13 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -5,8 +5,9 @@ import { NodeType, } from 'prosemirror-model' import { Plugin } from 'prosemirror-state' +import { InputRule } from 'prosemirror-inputrules' import { ExtensionConfig } from './Extension' -import { Attribute, NodeViewRenderer, Overwrite } from './types' +import { Attributes, NodeViewRenderer, Overwrite } from './types' import { Editor } from './Editor' export interface NodeConfig extends Overwrite, { @@ -94,9 +95,7 @@ export interface NodeConfig extends Overwrite { - [key: string]: Attribute - }, + ) => Attributes, /** * Commands @@ -125,7 +124,7 @@ export interface NodeConfig extends Overwrite any[], + }) => InputRule[], /** * Paste rules @@ -134,7 +133,7 @@ export interface NodeConfig extends Overwrite any[], + }) => Plugin[], /** * ProseMirror plugins diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index b30af2a4..dfbc639e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,8 +4,6 @@ export * from './Node' export * from './Mark' export * from './types' -export interface AllExtensions {} - export { default as nodeInputRule } from './inputRules/nodeInputRule' export { default as markInputRule } from './inputRules/markInputRule' 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 getMarkAttrs } from './utils/getMarkAttrs' export { default as mergeAttributes } from './utils/mergeAttributes' + +export interface AllExtensions {} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 4dc1ebf9..fef308bb 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -7,6 +7,17 @@ import { Mark } from './Mark' import { Editor } from './Editor' 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 Command = (props: { @@ -22,8 +33,6 @@ export type Command = (props: { export type CommandSpec = (...args: any[]) => Command -export type Extensions = (Extension | Node | Mark)[] - export type Attribute = { default: any, rendered?: boolean,