refactor: remove AnyObject type

This commit is contained in:
Philipp Kühn 2021-04-21 09:43:31 +02:00
parent d720d77e8d
commit 1c8ca95de2
64 changed files with 108 additions and 196 deletions

View File

@ -12,7 +12,7 @@ Pass a string (JSON or HTML) as [content](/guide/output). The editor will only r
By default, it doesnt trigger the update event. Passing `true` doesnt prevent triggering the update event. By default, it doesnt trigger the update event. Passing `true` doesnt prevent triggering the update event.
`parseOptions?: AnyObject` `parseOptions?: Record<string, any>`
Options to configure the parsing can be passed during initialization and/or with setContent. Read more about parseOptions in the [ProseMirror documentation](https://prosemirror.net/docs/ref/#model.ParseOptions). Options to configure the parsing can be passed during initialization and/or with setContent. Read more about parseOptions in the [ProseMirror documentation](https://prosemirror.net/docs/ref/#model.ParseOptions).

View File

@ -7,7 +7,7 @@ The `updateAttributes` command sets attributes of a node or mark to new values.
Pass the type you want to update, for example `'heading'`. Pass the type you want to update, for example `'heading'`.
`attributes: AnyObject` `attributes: Record<string, any>`
This expects an object with the attributes that need to be updated. It doesnt need to have all attributes. This expects an object with the attributes that need to be updated. It doesnt need to have all attributes.

View File

@ -19,7 +19,6 @@ import {
CanCommands, CanCommands,
ChainedCommands, ChainedCommands,
SingleCommands, SingleCommands,
AnyObject,
} from './types' } from './types'
import * as extensions from './extensions' import * as extensions from './extensions'
import style from './style' import style from './style'
@ -341,7 +340,7 @@ export class Editor extends EventEmitter {
* *
* @param name Name of the node * @param name Name of the node
*/ */
public getNodeAttributes(name: string): AnyObject { public getNodeAttributes(name: string): Record<string, any> {
return getNodeAttributes(this.state, name) return getNodeAttributes(this.state, name)
} }
@ -350,7 +349,7 @@ export class Editor extends EventEmitter {
* *
* @param name Name of the mark * @param name Name of the mark
*/ */
public getMarkAttributes(name: string): AnyObject { public getMarkAttributes(name: string): Record<string, any> {
return getMarkAttributes(this.state, name) return getMarkAttributes(this.state, name)
} }
@ -377,7 +376,7 @@ export class Editor extends EventEmitter {
/** /**
* Get the document as JSON. * Get the document as JSON.
*/ */
public getJSON(): AnyObject { public getJSON(): Record<string, any> {
return this.state.doc.toJSON() return this.state.doc.toJSON()
} }

View File

@ -102,9 +102,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'], parent: ParentConfig<ExtensionConfig<Options>>['extendNodeSchema'],
}, },
extension: Node, extension: Node,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* Extend Mark Schema * Extend Mark Schema
@ -116,9 +114,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'], parent: ParentConfig<ExtensionConfig<Options>>['extendMarkSchema'],
}, },
extension: Mark, extension: Mark,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* The editor is not ready yet. * The editor is not ready yet.

View File

@ -113,9 +113,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<MarkConfig<Options>>['extendNodeSchema'], parent: ParentConfig<MarkConfig<Options>>['extendNodeSchema'],
}, },
extension: Node, extension: Node,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* Extend Mark Schema * Extend Mark Schema
@ -127,9 +125,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<MarkConfig<Options>>['extendMarkSchema'], parent: ParentConfig<MarkConfig<Options>>['extendMarkSchema'],
}, },
extension: Mark, extension: Mark,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* The editor is not ready yet. * The editor is not ready yet.
@ -297,7 +293,7 @@ declare module '@tiptap/core' {
}, },
props: { props: {
mark: ProseMirrorMark, mark: ProseMirrorMark,
HTMLAttributes: { [key: string]: any }, HTMLAttributes: Record<string, any>,
}, },
) => DOMOutputSpec) | null, ) => DOMOutputSpec) | null,

View File

@ -113,9 +113,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<NodeConfig<Options>>['extendNodeSchema'], parent: ParentConfig<NodeConfig<Options>>['extendNodeSchema'],
}, },
extension: Node, extension: Node,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* Extend Mark Schema * Extend Mark Schema
@ -127,9 +125,7 @@ declare module '@tiptap/core' {
parent: ParentConfig<NodeConfig<Options>>['extendMarkSchema'], parent: ParentConfig<NodeConfig<Options>>['extendMarkSchema'],
}, },
extension: Node, extension: Node,
) => { ) => Record<string, any>) | null,
[key: string]: any,
}) | null,
/** /**
* The editor is not ready yet. * The editor is not ready yet.
@ -362,7 +358,7 @@ declare module '@tiptap/core' {
}, },
props: { props: {
node: ProseMirrorNode, node: ProseMirrorNode,
HTMLAttributes: { [key: string]: any }, HTMLAttributes: Record<string, any>,
} }
) => DOMOutputSpec) | null, ) => DOMOutputSpec) | null,

View File

@ -1,6 +1,6 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
import { Command, RawCommands, AnyObject } from '../types' import { Command, RawCommands } from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -8,7 +8,7 @@ declare module '@tiptap/core' {
/** /**
* Insert a node at the current position. * Insert a node at the current position.
*/ */
insertNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, insertNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { lift as originalLift } from 'prosemirror-commands' import { lift as originalLift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { Command, RawCommands, AnyObject } from '../types' import { Command, RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive' import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
@ -10,7 +10,7 @@ declare module '@tiptap/core' {
/** /**
* Removes an existing wrap. * Removes an existing wrap.
*/ */
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,5 +1,5 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { Command, RawCommands, AnyObject } from '../types' import { Command, RawCommands } from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -7,7 +7,7 @@ declare module '@tiptap/core' {
/** /**
* Replaces text with a node. * Replaces text with a node.
*/ */
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, replace: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,11 +1,6 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
import { import { Command, RawCommands, Range } from '../types'
Command,
RawCommands,
Range,
AnyObject,
} from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -13,7 +8,7 @@ declare module '@tiptap/core' {
/** /**
* Replaces text with a node within a range. * Replaces text with a node within a range.
*/ */
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command, replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,11 +1,6 @@
import { TextSelection } from 'prosemirror-state' import { TextSelection } from 'prosemirror-state'
import createDocument from '../helpers/createDocument' import createDocument from '../helpers/createDocument'
import { import { Command, RawCommands, Content } from '../types'
AnyObject,
Command,
RawCommands,
Content,
} from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -16,7 +11,7 @@ declare module '@tiptap/core' {
setContent: ( setContent: (
content: Content, content: Content,
emitUpdate?: Boolean, emitUpdate?: Boolean,
parseOptions?: AnyObject, parseOptions?: Record<string, any>,
) => Command, ) => Command,
} }
} }

View File

@ -1,5 +1,5 @@
import { MarkType } from 'prosemirror-model' import { MarkType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType' import getMarkType from '../helpers/getMarkType'
import getMarkAttributes from '../helpers/getMarkAttributes' import getMarkAttributes from '../helpers/getMarkAttributes'
@ -9,7 +9,7 @@ declare module '@tiptap/core' {
/** /**
* Add a mark with new attributes. * Add a mark with new attributes.
*/ */
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { setBlockType } from 'prosemirror-commands' import { setBlockType } from 'prosemirror-commands'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' { declare module '@tiptap/core' {
@ -9,7 +9,7 @@ declare module '@tiptap/core' {
/** /**
* Replace a given range with a node. * Replace a given range with a node.
*/ */
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,5 +1,5 @@
import { MarkType } from 'prosemirror-model' import { MarkType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType' import getMarkType from '../helpers/getMarkType'
import isMarkActive from '../helpers/isMarkActive' import isMarkActive from '../helpers/isMarkActive'
@ -9,7 +9,7 @@ declare module '@tiptap/core' {
/** /**
* Toggle a mark on and off. * Toggle a mark on and off.
*/ */
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, toggleMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,5 +1,5 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive' import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
@ -9,7 +9,7 @@ declare module '@tiptap/core' {
/** /**
* Toggle a node with another node. * Toggle a node with another node.
*/ */
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command, toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { wrapIn, lift } from 'prosemirror-commands' import { wrapIn, lift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive' import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
@ -10,7 +10,7 @@ declare module '@tiptap/core' {
/** /**
* Wraps nodes in another node, or removes an existing wrap. * Wraps nodes in another node, or removes an existing wrap.
*/ */
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -2,7 +2,7 @@ import { NodeType, MarkType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
import getMarkType from '../helpers/getMarkType' import getMarkType from '../helpers/getMarkType'
import getSchemaTypeNameByName from '../helpers/getSchemaTypeNameByName' import getSchemaTypeNameByName from '../helpers/getSchemaTypeNameByName'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -10,7 +10,7 @@ declare module '@tiptap/core' {
/** /**
* Update attributes of a node or mark. * Update attributes of a node or mark.
*/ */
updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: AnyObject) => Command, updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
declare module '@tiptap/core' { declare module '@tiptap/core' {
interface Commands { interface Commands {
@ -8,7 +8,7 @@ declare module '@tiptap/core' {
/** /**
* Update attributes of a node. * Update attributes of a node.
*/ */
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command, updateNodeAttributes: (typeOrName: string | NodeType, attributes: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { wrapIn as originalWrapIn } from 'prosemirror-commands' import { wrapIn as originalWrapIn } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive' import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
@ -10,7 +10,7 @@ declare module '@tiptap/core' {
/** /**
* Wraps nodes in another node. * Wraps nodes in another node.
*/ */
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { wrapInList as originalWrapInList } from 'prosemirror-schema-list' import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import { AnyObject, Command, RawCommands } from '../types' import { Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType' import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' { declare module '@tiptap/core' {
@ -9,7 +9,7 @@ declare module '@tiptap/core' {
/** /**
* Wrap a node in a list. * Wrap a node in a list.
*/ */
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
} }
} }
} }

View File

@ -1,11 +1,11 @@
import { Schema, Node as ProseMirrorNode } from 'prosemirror-model' import { Schema, Node as ProseMirrorNode } from 'prosemirror-model'
import { AnyObject, Content } from '../types' import { Content } from '../types'
import createNodeFromContent from './createNodeFromContent' import createNodeFromContent from './createNodeFromContent'
export default function createDocument( export default function createDocument(
content: Content, content: Content,
schema: Schema, schema: Schema,
parseOptions: AnyObject = {}, parseOptions: Record<string, any> = {},
): ProseMirrorNode { ): ProseMirrorNode {
return createNodeFromContent(content, schema, { slice: false, parseOptions }) as ProseMirrorNode return createNodeFromContent(content, schema, { slice: false, parseOptions }) as ProseMirrorNode
} }

View File

@ -5,11 +5,11 @@ import {
Fragment, Fragment,
} from 'prosemirror-model' } from 'prosemirror-model'
import elementFromString from '../utilities/elementFromString' import elementFromString from '../utilities/elementFromString'
import { AnyObject, Content } from '../types' import { Content } from '../types'
export type CreateNodeFromContentOptions = { export type CreateNodeFromContentOptions = {
slice?: boolean, slice?: boolean,
parseOptions?: AnyObject, parseOptions?: Record<string, any>,
} }
export default function createNodeFromContent( export default function createNodeFromContent(

View File

@ -1,9 +1,9 @@
import { AnyExtension, AnyObject, RemoveThis } from '../types' import { AnyExtension, RemoveThis } from '../types'
export default function getExtensionField<T = any>( export default function getExtensionField<T = any>(
extension: AnyExtension, extension: AnyExtension,
field: string, field: string,
context: AnyObject = {}, context: Record<string, any> = {},
): RemoveThis<T> { ): RemoveThis<T> {
if (extension.config[field] === undefined && extension.parent) { if (extension.config[field] === undefined && extension.parent) {

View File

@ -1,9 +1,8 @@
import { EditorState } from 'prosemirror-state' import { EditorState } from 'prosemirror-state'
import { Mark, MarkType } from 'prosemirror-model' import { Mark, MarkType } from 'prosemirror-model'
import getMarkType from './getMarkType' import getMarkType from './getMarkType'
import { AnyObject } from '../types'
export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): AnyObject { export default function getMarkAttributes(state: EditorState, typeOrName: string | MarkType): Record<string, any> {
const type = getMarkType(typeOrName, state.schema) const type = getMarkType(typeOrName, state.schema)
const { from, to, empty } = state.selection const { from, to, empty } = state.selection
let marks: Mark[] = [] let marks: Mark[] = []

View File

@ -1,9 +1,8 @@
import { EditorState } from 'prosemirror-state' import { EditorState } from 'prosemirror-state'
import { Node, NodeType } from 'prosemirror-model' import { Node, NodeType } from 'prosemirror-model'
import getNodeType from './getNodeType' import getNodeType from './getNodeType'
import { AnyObject } from '../types'
export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): AnyObject { export default function getNodeAttributes(state: EditorState, typeOrName: string | NodeType): Record<string, any> {
const type = getNodeType(typeOrName, state.schema) const type = getNodeType(typeOrName, state.schema)
const { from, to } = state.selection const { from, to } = state.selection
let nodes: Node[] = [] let nodes: Node[] = []

View File

@ -1,8 +1,8 @@
import { Node, Mark } from 'prosemirror-model' import { Node, Mark } from 'prosemirror-model'
import { ExtensionAttribute, AnyObject } from '../types' import { ExtensionAttribute } from '../types'
import mergeAttributes from '../utilities/mergeAttributes' import mergeAttributes from '../utilities/mergeAttributes'
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): AnyObject { export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): Record<string, any> {
return extensionAttributes return extensionAttributes
.filter(item => item.attribute.rendered) .filter(item => item.attribute.rendered)
.map(item => { .map(item => {

View File

@ -1,10 +1,10 @@
import { AnyObject, ExtensionAttribute } from '../types' import { ExtensionAttribute } from '../types'
export default function getSplittedAttributes( export default function getSplittedAttributes(
extensionAttributes: ExtensionAttribute[], extensionAttributes: ExtensionAttribute[],
typeName: string, typeName: string,
attributes: AnyObject, attributes: Record<string, any>,
): AnyObject { ): Record<string, any> {
return Object.fromEntries(Object return Object.fromEntries(Object
.entries(attributes) .entries(attributes)
.filter(([name]) => { .filter(([name]) => {

View File

@ -2,9 +2,8 @@ import { EditorState } from 'prosemirror-state'
import isNodeActive from './isNodeActive' import isNodeActive from './isNodeActive'
import isMarkActive from './isMarkActive' import isMarkActive from './isMarkActive'
import getSchemaTypeNameByName from './getSchemaTypeNameByName' import getSchemaTypeNameByName from './getSchemaTypeNameByName'
import { AnyObject } from '../types'
export default function isActive(state: EditorState, name: string | null, attributes: AnyObject = {}): boolean { export default function isActive(state: EditorState, name: string | null, attributes: Record<string, any> = {}): boolean {
if (!name) { if (!name) {
return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes) return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes)
} }

View File

@ -2,12 +2,12 @@ import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model' import { MarkType } from 'prosemirror-model'
import objectIncludes from '../utilities/objectIncludes' import objectIncludes from '../utilities/objectIncludes'
import getMarkType from './getMarkType' import getMarkType from './getMarkType'
import { AnyObject, MarkRange } from '../types' import { MarkRange } from '../types'
export default function isMarkActive( export default function isMarkActive(
state: EditorState, state: EditorState,
typeOrName: MarkType | string | null, typeOrName: MarkType | string | null,
attributes: AnyObject = {}, attributes: Record<string, any> = {},
): boolean { ): boolean {
const { from, to, empty } = state.selection const { from, to, empty } = state.selection
const type = typeOrName const type = typeOrName

View File

@ -2,12 +2,12 @@ import { EditorState } from 'prosemirror-state'
import { NodeType } from 'prosemirror-model' import { NodeType } from 'prosemirror-model'
import objectIncludes from '../utilities/objectIncludes' import objectIncludes from '../utilities/objectIncludes'
import getNodeType from './getNodeType' import getNodeType from './getNodeType'
import { AnyObject, NodeRange } from '../types' import { NodeRange } from '../types'
export default function isNodeActive( export default function isNodeActive(
state: EditorState, state: EditorState,
typeOrName: NodeType | string | null, typeOrName: NodeType | string | null,
attributes: AnyObject = {}, attributes: Record<string, any> = {},
): boolean { ): boolean {
const { from, to, empty } = state.selection const { from, to, empty } = state.selection
const type = typeOrName const type = typeOrName

View File

@ -60,7 +60,7 @@ export interface EditorOptions {
onDestroy: () => void, onDestroy: () => void,
} }
export type Content = string | AnyObject | null export type Content = string | Record<string, any> | null
export type CommandProps = { export type CommandProps = {
editor: Editor, editor: Editor,
@ -82,8 +82,8 @@ export type KeyboardShortcutCommand = (props: { editor: Editor }) => boolean
export type Attribute = { export type Attribute = {
default: any, default: any,
rendered?: boolean, rendered?: boolean,
renderHTML?: ((attributes: { [key: string]: any }) => { [key: string]: any } | null) | null, renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null,
parseHTML?: ((element: HTMLElement) => { [key: string]: any } | null) | null, parseHTML?: ((element: HTMLElement) => Record<string, any> | null) | null,
keepOnSplit: boolean, keepOnSplit: boolean,
} }
@ -115,10 +115,6 @@ export type Diff<T extends keyof any, U extends keyof any> =
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U; export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
export type AnyObject = {
[key: string]: any
}
export type ValuesOf<T> = T[keyof T]; export type ValuesOf<T> = T[keyof T];
export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
@ -130,14 +126,14 @@ export type NodeViewProps = {
selected: boolean, selected: boolean,
extension: Node, extension: Node,
getPos: () => number, getPos: () => number,
updateAttributes: (attributes: AnyObject) => void, updateAttributes: (attributes: Record<string, any>) => void,
} }
export type NodeViewRendererProps = { export type NodeViewRendererProps = {
editor: Editor, editor: Editor,
node: ProseMirrorNode, node: ProseMirrorNode,
getPos: (() => number) | boolean, getPos: (() => number) | boolean,
HTMLAttributes: { [key: string]: any }, HTMLAttributes: Record<string, any>,
decorations: Decoration[], decorations: Decoration[],
extension: Node, extension: Node,
} }

View File

@ -1,18 +1,16 @@
import { AnyObject } from '../types'
/** /**
* Remove a property or an array of properties from an object * Remove a property or an array of properties from an object
* @param obj Object * @param obj Object
* @param key Key to remove * @param key Key to remove
*/ */
export default function deleteProps(obj: AnyObject, propOrProps: string | string[]): AnyObject { export default function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
const props = typeof propOrProps === 'string' const props = typeof propOrProps === 'string'
? [propOrProps] ? [propOrProps]
: propOrProps : propOrProps
return Object return Object
.keys(obj) .keys(obj)
.reduce((newObj: AnyObject, prop) => { .reduce((newObj: Record<string, any>, prop) => {
if (!props.includes(prop)) { if (!props.includes(prop)) {
newObj[prop] = obj[prop] newObj[prop] = obj[prop]
} }

View File

@ -1,6 +1,4 @@
import { AnyObject } from '../types' export default function mergeAttributes(...objects: Record<string, any>[]): Record<string, any> {
export default function mergeAttributes(...objects: AnyObject[]): AnyObject {
return objects return objects
.filter(item => !!item) .filter(item => !!item)
.reduce((items, item) => { .reduce((items, item) => {

View File

@ -1,7 +1,6 @@
import { AnyObject } from '../types'
import isPlainObject from './isPlainObject' import isPlainObject from './isPlainObject'
export default function mergeDeep(target: AnyObject, source: AnyObject): AnyObject { export default function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any> {
const output = { ...target } const output = { ...target }
if (isPlainObject(target) && isPlainObject(source)) { if (isPlainObject(target) && isPlainObject(source)) {

View File

@ -1,11 +1,9 @@
import { AnyObject } from '../types'
/** /**
* Check if object1 includes object2 * Check if object1 includes object2
* @param object1 Object * @param object1 Object
* @param object2 Object * @param object2 Object
*/ */
export default function objectIncludes(object1: AnyObject, object2: AnyObject): boolean { export default function objectIncludes(object1: Record<string, any>, object2: Record<string, any>): boolean {
const keys = Object.keys(object2) const keys = Object.keys(object2)
if (!keys.length) { if (!keys.length) {

View File

@ -2,9 +2,7 @@ import { Command, Node, mergeAttributes } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules' import { wrappingInputRule } from 'prosemirror-inputrules'
export interface BlockquoteOptions { export interface BlockquoteOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
} from '@tiptap/core' } from '@tiptap/core'
export interface BoldOptions { export interface BoldOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -2,9 +2,7 @@ import { Command, Node, mergeAttributes } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules' import { wrappingInputRule } from 'prosemirror-inputrules'
export interface BulletListOptions { export interface BulletListOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -3,9 +3,7 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules'
export interface CodeBlockOptions { export interface CodeBlockOptions {
languageClassPrefix: string, languageClassPrefix: string,
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
} from '@tiptap/core' } from '@tiptap/core'
export interface CodeOptions { export interface CodeOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,10 +1,10 @@
import { Extension, Command, AnyObject } from '@tiptap/core' import { Extension, Command } from '@tiptap/core'
import { yCursorPlugin } from 'y-prosemirror' import { yCursorPlugin } from 'y-prosemirror'
export interface CollaborationCursorOptions { export interface CollaborationCursorOptions {
provider: any, provider: any,
user: { [key: string]: any }, user: Record<string, any>,
render (user: { [key: string]: any }): HTMLElement, render (user: Record<string, any>): HTMLElement,
onUpdate: (users: { clientId: string, [key: string]: any }[]) => null, onUpdate: (users: { clientId: string, [key: string]: any }[]) => null,
} }
@ -14,12 +14,12 @@ declare module '@tiptap/core' {
/** /**
* Update details of the current user * Update details of the current user
*/ */
user: (attributes: AnyObject) => Command, user: (attributes: Record<string, any>) => Command,
} }
} }
} }
const awarenessStatesToArray = (states: Map<number, { [key: string]: any }>) => { const awarenessStatesToArray = (states: Map<number, Record<string, any>>) => {
return Array.from(states.entries()).map(([key, value]) => { return Array.from(states.entries()).map(([key, value]) => {
return { return {
clientId: key, clientId: key,

View File

@ -2,9 +2,7 @@ import { Command, Node, mergeAttributes } from '@tiptap/core'
import { exitCode } from 'prosemirror-commands' import { exitCode } from 'prosemirror-commands'
export interface HardBreakOptions { export interface HardBreakOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -5,9 +5,7 @@ type Level = 1 | 2 | 3 | 4 | 5 | 6
export interface HeadingOptions { export interface HeadingOptions {
levels: Level[], levels: Level[],
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -8,9 +8,7 @@ import {
export interface HighlightOptions { export interface HighlightOptions {
multicolor: boolean, multicolor: boolean,
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
import { TextSelection } from 'prosemirror-state' import { TextSelection } from 'prosemirror-state'
export interface HorizontalRuleOptions { export interface HorizontalRuleOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
export interface ImageOptions { export interface ImageOptions {
inline: boolean, inline: boolean,
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
} from '@tiptap/core' } from '@tiptap/core'
export interface ItalicOptions { export interface ItalicOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -8,9 +8,7 @@ import { Plugin, PluginKey } from 'prosemirror-state'
export interface LinkOptions { export interface LinkOptions {
openOnClick: boolean, openOnClick: boolean,
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,9 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core' import { Node, mergeAttributes } from '@tiptap/core'
export interface ListItemOptions { export interface ListItemOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
export const ListItem = Node.create<ListItemOptions>({ export const ListItem = Node.create<ListItemOptions>({

View File

@ -2,9 +2,7 @@ import { Node, mergeAttributes } from '@tiptap/core'
import Suggestion, { SuggestionOptions } from '@tiptap/suggestion' import Suggestion, { SuggestionOptions } from '@tiptap/suggestion'
export type MentionOptions = { export type MentionOptions = {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any,
},
suggestion: Omit<SuggestionOptions, 'editor'>, suggestion: Omit<SuggestionOptions, 'editor'>,
} }

View File

@ -2,9 +2,7 @@ import { Command, Node, mergeAttributes } from '@tiptap/core'
import { wrappingInputRule } from 'prosemirror-inputrules' import { wrappingInputRule } from 'prosemirror-inputrules'
export interface OrderedListOptions { export interface OrderedListOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,9 +1,7 @@
import { Command, Node, mergeAttributes } from '@tiptap/core' import { Command, Node, mergeAttributes } from '@tiptap/core'
export interface ParagraphOptions { export interface ParagraphOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -7,9 +7,7 @@ import {
} from '@tiptap/core' } from '@tiptap/core'
export interface StrikeOptions { export interface StrikeOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,10 +1,9 @@
import { Node, mergeAttributes } from '@tiptap/core' import { Node, mergeAttributes } from '@tiptap/core'
export interface TableCellOptions { export interface TableCellOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
export const TableCell = Node.create<TableCellOptions>({ export const TableCell = Node.create<TableCellOptions>({
name: 'tableCell', name: 'tableCell',

View File

@ -1,9 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core' import { Node, mergeAttributes } from '@tiptap/core'
export interface TableHeaderOptions { export interface TableHeaderOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
export const TableHeader = Node.create<TableHeaderOptions>({ export const TableHeader = Node.create<TableHeaderOptions>({
name: 'tableHeader', name: 'tableHeader',

View File

@ -1,9 +1,7 @@
import { Node, mergeAttributes } from '@tiptap/core' import { Node, mergeAttributes } from '@tiptap/core'
export interface TableRowOptions { export interface TableRowOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
export const TableRow = Node.create<TableRowOptions>({ export const TableRow = Node.create<TableRowOptions>({

View File

@ -32,9 +32,7 @@ import { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllC
import { TableView } from './TableView' import { TableView } from './TableView'
export interface TableOptions { export interface TableOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
resizable: boolean, resizable: boolean,
handleWidth: number, handleWidth: number,
cellMinWidth: number, cellMinWidth: number,

View File

@ -3,9 +3,7 @@ import { wrappingInputRule } from 'prosemirror-inputrules'
export interface TaskItemOptions { export interface TaskItemOptions {
nested: boolean, nested: boolean,
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
export const inputRegex = /^\s*(\[([ |x])\])\s$/ export const inputRegex = /^\s*(\[([ |x])\])\s$/

View File

@ -1,9 +1,7 @@
import { Command, Node, mergeAttributes } from '@tiptap/core' import { Command, Node, mergeAttributes } from '@tiptap/core'
export interface TaskListOptions { export interface TaskListOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -6,9 +6,7 @@ import {
} from '@tiptap/core' } from '@tiptap/core'
export interface TextStyleOptions { export interface TextStyleOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,9 +1,7 @@
import { Command, Mark, mergeAttributes } from '@tiptap/core' import { Command, Mark, mergeAttributes } from '@tiptap/core'
export interface UnderlineOptions { export interface UnderlineOptions {
HTMLAttributes: { HTMLAttributes: Record<string, any>,
[key: string]: any
},
} }
declare module '@tiptap/core' { declare module '@tiptap/core' {

View File

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import { AnyObject } from '@tiptap/core'
import { Editor } from './Editor' import { Editor } from './Editor'
function isClassComponent(Component: any) { function isClassComponent(Component: any) {
@ -12,7 +11,7 @@ function isClassComponent(Component: any) {
export interface ReactRendererOptions { export interface ReactRendererOptions {
editor: Editor, editor: Editor,
props?: AnyObject, props?: Record<string, any>,
as?: string, as?: string,
} }
@ -25,7 +24,7 @@ export class ReactRenderer {
element: Element element: Element
props: AnyObject props: Record<string, any>
reactElement: React.ReactNode reactElement: React.ReactNode
@ -63,7 +62,7 @@ export class ReactRenderer {
} }
} }
updateProps(props: AnyObject = {}): void { updateProps(props: Record<string, any> = {}): void {
this.props = { this.props = {
...this.props, ...this.props,
...props, ...props,

View File

@ -1,5 +1,4 @@
import Vue from 'vue' import Vue from 'vue'
import { AnyObject } from '@tiptap/core'
import { VueConstructor } from 'vue/types/umd' import { VueConstructor } from 'vue/types/umd'
export class VueRenderer { export class VueRenderer {
@ -15,7 +14,7 @@ export class VueRenderer {
return this.ref.$el return this.ref.$el
} }
updateProps(props: AnyObject = {}): void { updateProps(props: Record<string, any> = {}): void {
if (!this.ref.$props) { if (!this.ref.$props) {
return return
} }

View File

@ -1,10 +1,10 @@
import { reactive, markRaw, Component } from 'vue' import { reactive, markRaw, Component } from 'vue'
import { AnyObject, Editor } from '@tiptap/core' import { Editor } from '@tiptap/core'
import { Editor as ExtendedEditor } from './Editor' import { Editor as ExtendedEditor } from './Editor'
export interface VueRendererOptions { export interface VueRendererOptions {
editor: Editor, editor: Editor,
props?: AnyObject, props?: Record<string, any>,
} }
export class VueRenderer { export class VueRenderer {
@ -18,7 +18,7 @@ export class VueRenderer {
element: Element element: Element
props: AnyObject props: Record<string, any>
constructor(component: Component, { props = {}, editor }: VueRendererOptions) { constructor(component: Component, { props = {}, editor }: VueRendererOptions) {
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString() this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
@ -44,7 +44,7 @@ export class VueRenderer {
return this.editor.contentComponent?.ctx.$refs[this.id] return this.editor.contentComponent?.ctx.$refs[this.id]
} }
updateProps(props: AnyObject = {}): void { updateProps(props: Record<string, any> = {}): void {
Object Object
.entries(props) .entries(props)
.forEach(([key, value]) => { .forEach(([key, value]) => {