From 4a58978ffb0d12918d93e31d818b155a6327ba12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 19 Feb 2021 10:09:25 +0100 Subject: [PATCH] add NodeSchemaFields interface --- packages/core/src/Node.ts | 18 +++++++++++------- packages/core/src/index.ts | 3 +++ packages/core/src/types.ts | 4 ++-- packages/extension-table/src/table.ts | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 221e9ce43..edf0e94fa 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -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 extends Overwrite { type = 'node' - config: Required = { + config: Required & NodeSchemaFields = { name: 'node', defaultOptions: {}, addGlobalAttributes: () => [], @@ -291,7 +295,7 @@ export class Node { options!: Options - constructor(config: NodeConfig) { + constructor(config: NodeConfig & NodeSchemaFields) { this.config = { ...this.config, ...config, @@ -300,13 +304,13 @@ export class Node { this.options = this.config.defaultOptions } - static create(config: NodeConfig) { + static create(config: NodeConfig & NodeSchemaFields) { return new Node(config) } configure(options: Partial = {}) { return Node - .create(this.config as NodeConfig) + .create(this.config as (NodeConfig & NodeSchemaFields)) .#configure(options) } @@ -316,10 +320,10 @@ export class Node { return this } - extend(extendedConfig: Partial>) { + extend(extendedConfig: Partial & NodeSchemaFields>) { return new Node({ ...this.config, ...extendedConfig, - } as NodeConfig) + } as NodeConfig & NodeSchemaFields) } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ba9532754..7f9ae9060 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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 {} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 54bd8b0dc..b156f4877 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -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)[] diff --git a/packages/extension-table/src/table.ts b/packages/extension-table/src/table.ts index 7a36c8229..07245972e 100644 --- a/packages/extension-table/src/table.ts +++ b/packages/extension-table/src/table.ts @@ -66,7 +66,7 @@ declare module '@tiptap/core' { } } - interface NodeConfig { + interface NodeSchemaFields { /** * Table Role */