From 282cdfebd6228cb46a40dcb8bfe644add5085fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 16 Nov 2020 15:56:44 +0100 Subject: [PATCH] move some types --- packages/core/src/CommandManager.ts | 8 ++- packages/core/src/Editor.ts | 86 +++++++++-------------------- 2 files changed, 32 insertions(+), 62 deletions(-) diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index 8ac590f9f..ceeecfc4f 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -2,6 +2,8 @@ import { EditorState, Transaction } from 'prosemirror-state' import { Editor, CommandSpec, + SingleCommands, + ChainedCommands, } from './Editor' import getAllMethodNames from './utils/getAllMethodNames' @@ -56,7 +58,7 @@ export default class CommandManager { } return [name, method] - })) as Tiptap.SingleCommands + })) as SingleCommands } public createChain(startTr?: Transaction, shouldDispatch = true) { @@ -90,7 +92,7 @@ export default class CommandManager { return proxy } }, - }) as Tiptap.ChainedCommands + }) as ChainedCommands } public createCan(startTr?: Transaction) { @@ -103,7 +105,7 @@ export default class CommandManager { .entries(commands) .map(([name, command]) => { return [name, (...args: any[]) => command(...args)({ ...props, dispatch })] - })) as Tiptap.SingleCommands + })) as SingleCommands return { ...formattedCommands, diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index efa0af640..e6dfcf4b5 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -24,9 +24,9 @@ import style from './style' export type Command = (props: { editor: Editor, tr: Transaction, - commands: Tiptap.SingleCommands, - can: () => Tiptap.SingleCommands & { chain: () => Tiptap.ChainedCommands }, - chain: () => Tiptap.ChainedCommands, + commands: SingleCommands, + can: () => SingleCommands & { chain: () => ChainedCommands }, + chain: () => ChainedCommands, state: EditorState, view: EditorView, dispatch: ((args?: any) => any) | undefined, @@ -41,68 +41,36 @@ export interface CommandsSpec { declare global { namespace Tiptap { export interface AllExtensions {} - - export type UnfilteredCommands = { - [Item in keyof AllExtensions]: AllExtensions[Item] extends Extension - ? ExtensionCommands - : AllExtensions[Item] extends Node - ? NodeCommands - : AllExtensions[Item] extends Mark - ? MarkCommands - : never - } - - type ValuesOf = T[keyof T]; - type KeysWithTypeOf = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] - type AllCommands = UnionToIntersection>>> - - export type SingleCommands = { - [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => boolean - : never - } - - export type ChainedCommands = { - [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => ChainedCommands - : never - } & { - run: () => boolean - } } } -// type blub = Tiptap.AllExtensions +type UnfilteredCommands = { + [Item in keyof Tiptap.AllExtensions]: Tiptap.AllExtensions[Item] extends Extension + ? ExtensionCommands + : Tiptap.AllExtensions[Item] extends Node + ? NodeCommands + : Tiptap.AllExtensions[Item] extends Mark + ? MarkCommands + : never +} -// export interface AllExtensions {} +type ValuesOf = T[keyof T]; +type KeysWithTypeOf = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] +type AllCommands = UnionToIntersection>>> -// export type UnfilteredCommands = { -// [Item in keyof Tiptap.AllExtensions]: AllExtensions[Item] extends Extension -// ? ExtensionCommands -// : AllExtensions[Item] extends Node -// ? NodeCommands -// : AllExtensions[Item] extends Mark -// ? MarkCommands -// : never -// } +export type SingleCommands = { + [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => boolean + : never +} -// type ValuesOf = T[keyof T]; -// type KeysWithTypeOf = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] -// type AllCommands = UnionToIntersection>>> - -// export type SingleCommands = { -// [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any -// ? (...args: Parameters) => boolean -// : never -// } - -// export type ChainedCommands = { -// [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any -// ? (...args: Parameters) => ChainedCommands -// : never -// } & { -// run: () => boolean -// } +export type ChainedCommands = { + [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => ChainedCommands + : never +} & { + run: () => boolean +} type EditorContent = string | JSON | null