add NodeSchemaFields interface

This commit is contained in:
Philipp Kühn 2021-02-19 10:09:25 +01:00
parent 6f9557294e
commit 4a58978ffb
4 changed files with 17 additions and 10 deletions

View File

@ -10,7 +10,11 @@ import { InputRule } from 'prosemirror-inputrules'
import { ExtensionConfig } from './Extension' import { ExtensionConfig } from './Extension'
import mergeDeep from './utilities/mergeDeep' import mergeDeep from './utilities/mergeDeep'
import { import {
Attributes, NodeViewRenderer, Overwrite, RawCommands, Attributes,
NodeViewRenderer,
Overwrite,
RawCommands,
NodeSchemaFields,
} from './types' } from './types'
import { Editor } from './Editor' import { Editor } from './Editor'
@ -253,7 +257,7 @@ export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Opt
export class Node<Options = any> { export class Node<Options = any> {
type = 'node' type = 'node'
config: Required<NodeConfig> = { config: Required<NodeConfig> & NodeSchemaFields<Options> = {
name: 'node', name: 'node',
defaultOptions: {}, defaultOptions: {},
addGlobalAttributes: () => [], addGlobalAttributes: () => [],
@ -291,7 +295,7 @@ export class Node<Options = any> {
options!: Options options!: Options
constructor(config: NodeConfig<Options>) { constructor(config: NodeConfig<Options> & NodeSchemaFields<Options>) {
this.config = { this.config = {
...this.config, ...this.config,
...config, ...config,
@ -300,13 +304,13 @@ export class Node<Options = any> {
this.options = this.config.defaultOptions this.options = this.config.defaultOptions
} }
static create<O>(config: NodeConfig<O>) { static create<O>(config: NodeConfig<O> & NodeSchemaFields<O>) {
return new Node<O>(config) return new Node<O>(config)
} }
configure(options: Partial<Options> = {}) { configure(options: Partial<Options> = {}) {
return Node return Node
.create<Options>(this.config as NodeConfig<Options>) .create<Options>(this.config as (NodeConfig<Options> & NodeSchemaFields<Options>))
.#configure(options) .#configure(options)
} }
@ -316,10 +320,10 @@ export class Node<Options = any> {
return this return this
} }
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>) { extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions> & NodeSchemaFields<ExtendedOptions>>) {
return new Node<ExtendedOptions>({ return new Node<ExtendedOptions>({
...this.config, ...this.config,
...extendedConfig, ...extendedConfig,
} as NodeConfig<ExtendedOptions>) } as NodeConfig<ExtendedOptions> & NodeSchemaFields<ExtendedOptions>)
} }
} }

View File

@ -23,3 +23,6 @@ export { default as isCellSelection } from './helpers/isCellSelection'
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos' export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
export interface Commands {} export interface Commands {}
// eslint-disable-next-line
export interface NodeSchemaFields<Options = any> {}

View File

@ -14,9 +14,9 @@ import { Extension } from './Extension'
import { Node } from './Node' import { Node } from './Node'
import { Mark } from './Mark' import { Mark } from './Mark'
import { Editor } from './Editor' import { Editor } from './Editor'
import { Commands } from '.' import { Commands, NodeSchemaFields } from '.'
export { Commands } export { Commands, NodeSchemaFields }
export type Extensions = (Extension | Node | Mark)[] export type Extensions = (Extension | Node | Mark)[]

View File

@ -66,7 +66,7 @@ declare module '@tiptap/core' {
} }
} }
interface NodeConfig<Options> { interface NodeSchemaFields<Options> {
/** /**
* Table Role * Table Role
*/ */