mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
add NodeSchemaFields interface
This commit is contained in:
parent
6f9557294e
commit
4a58978ffb
@ -10,7 +10,11 @@ import { InputRule } from 'prosemirror-inputrules'
|
||||
import { ExtensionConfig } from './Extension'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import {
|
||||
Attributes, NodeViewRenderer, Overwrite, RawCommands,
|
||||
Attributes,
|
||||
NodeViewRenderer,
|
||||
Overwrite,
|
||||
RawCommands,
|
||||
NodeSchemaFields,
|
||||
} from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
@ -253,7 +257,7 @@ export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Opt
|
||||
export class Node<Options = any> {
|
||||
type = 'node'
|
||||
|
||||
config: Required<NodeConfig> = {
|
||||
config: Required<NodeConfig> & NodeSchemaFields<Options> = {
|
||||
name: 'node',
|
||||
defaultOptions: {},
|
||||
addGlobalAttributes: () => [],
|
||||
@ -291,7 +295,7 @@ export class Node<Options = any> {
|
||||
|
||||
options!: Options
|
||||
|
||||
constructor(config: NodeConfig<Options>) {
|
||||
constructor(config: NodeConfig<Options> & NodeSchemaFields<Options>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
@ -300,13 +304,13 @@ export class Node<Options = any> {
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O>(config: NodeConfig<O>) {
|
||||
static create<O>(config: NodeConfig<O> & NodeSchemaFields<O>) {
|
||||
return new Node<O>(config)
|
||||
}
|
||||
|
||||
configure(options: Partial<Options> = {}) {
|
||||
return Node
|
||||
.create<Options>(this.config as NodeConfig<Options>)
|
||||
.create<Options>(this.config as (NodeConfig<Options> & NodeSchemaFields<Options>))
|
||||
.#configure(options)
|
||||
}
|
||||
|
||||
@ -316,10 +320,10 @@ export class Node<Options = any> {
|
||||
return this
|
||||
}
|
||||
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>) {
|
||||
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions> & NodeSchemaFields<ExtendedOptions>>) {
|
||||
return new Node<ExtendedOptions>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as NodeConfig<ExtendedOptions>)
|
||||
} as NodeConfig<ExtendedOptions> & NodeSchemaFields<ExtendedOptions>)
|
||||
}
|
||||
}
|
||||
|
@ -23,3 +23,6 @@ export { default as isCellSelection } from './helpers/isCellSelection'
|
||||
export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos'
|
||||
|
||||
export interface Commands {}
|
||||
|
||||
// eslint-disable-next-line
|
||||
export interface NodeSchemaFields<Options = any> {}
|
||||
|
@ -14,9 +14,9 @@ import { Extension } from './Extension'
|
||||
import { Node } from './Node'
|
||||
import { Mark } from './Mark'
|
||||
import { Editor } from './Editor'
|
||||
import { Commands } from '.'
|
||||
import { Commands, NodeSchemaFields } from '.'
|
||||
|
||||
export { Commands }
|
||||
export { Commands, NodeSchemaFields }
|
||||
|
||||
export type Extensions = (Extension | Node | Mark)[]
|
||||
|
||||
|
@ -66,7 +66,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
interface NodeConfig<Options> {
|
||||
interface NodeSchemaFields<Options> {
|
||||
/**
|
||||
* Table Role
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user