move some types
This commit is contained in:
@@ -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<any, infer ExtensionCommands>
|
||||
? ExtensionCommands
|
||||
: AllExtensions[Item] extends Node<any, infer NodeCommands>
|
||||
? NodeCommands
|
||||
: AllExtensions[Item] extends Mark<any, infer MarkCommands>
|
||||
? MarkCommands
|
||||
: never
|
||||
}
|
||||
|
||||
type ValuesOf<T> = T[keyof T];
|
||||
type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
|
||||
type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
|
||||
|
||||
export type SingleCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// type blub = Tiptap.AllExtensions
|
||||
type UnfilteredCommands = {
|
||||
[Item in keyof Tiptap.AllExtensions]: Tiptap.AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
|
||||
? ExtensionCommands
|
||||
: Tiptap.AllExtensions[Item] extends Node<any, infer NodeCommands>
|
||||
? NodeCommands
|
||||
: Tiptap.AllExtensions[Item] extends Mark<any, infer MarkCommands>
|
||||
? MarkCommands
|
||||
: never
|
||||
}
|
||||
|
||||
// export interface AllExtensions {}
|
||||
type ValuesOf<T> = T[keyof T];
|
||||
type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
|
||||
type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
|
||||
|
||||
// export type UnfilteredCommands = {
|
||||
// [Item in keyof Tiptap.AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
|
||||
// ? ExtensionCommands
|
||||
// : AllExtensions[Item] extends Node<any, infer NodeCommands>
|
||||
// ? NodeCommands
|
||||
// : AllExtensions[Item] extends Mark<any, infer MarkCommands>
|
||||
// ? MarkCommands
|
||||
// : never
|
||||
// }
|
||||
export type SingleCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
|
||||
// type ValuesOf<T> = T[keyof T];
|
||||
// type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
|
||||
// type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
|
||||
|
||||
// export type SingleCommands = {
|
||||
// [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
// ? (...args: Parameters<AllCommands[Item]>) => boolean
|
||||
// : never
|
||||
// }
|
||||
|
||||
// export type ChainedCommands = {
|
||||
// [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
// ? (...args: Parameters<AllCommands[Item]>) => ChainedCommands
|
||||
// : never
|
||||
// } & {
|
||||
// run: () => boolean
|
||||
// }
|
||||
export type ChainedCommands = {
|
||||
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<AllCommands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
}
|
||||
|
||||
type EditorContent = string | JSON | null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user