improve new extensions

This commit is contained in:
Philipp Kühn
2020-11-16 09:43:17 +01:00
parent 034ee139a3
commit c87f49c1fe
50 changed files with 296 additions and 377 deletions

View File

@@ -63,55 +63,6 @@ export interface ExtensionSpec<Options = any, Commands = {}> {
}) => Plugin[],
}
// /**
// * Extension interface for internal usage
// */
// export type Extension = Required<Omit<ExtensionSpec, 'defaultOptions'> & {
// type: string,
// options: {
// [key: string]: any
// },
// }>
// /**
// * Default extension
// */
// export const defaultExtension: Extension = {
// name: 'extension',
// type: 'extension',
// options: {},
// addGlobalAttributes: () => [],
// addCommands: () => ({}),
// addKeyboardShortcuts: () => ({}),
// addInputRules: () => [],
// addPasteRules: () => [],
// addProseMirrorPlugins: () => [],
// }
// export function createExtension<Options extends {}, Commands extends {}>(config: ExtensionSpec<Options, Commands>) {
// const extend = <ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionSpec<ExtendedOptions, ExtendedCommands>>) => {
// return createExtension({
// ...config,
// ...extendedConfig,
// } as ExtensionSpec<ExtendedOptions, ExtendedCommands>)
// }
// const setOptions = (options?: Partial<Options>) => {
// const { defaultOptions, ...rest } = config
// return {
// ...defaultExtension,
// ...rest,
// options: {
// ...defaultOptions,
// ...options,
// } as Options,
// }
// }
// return Object.assign(setOptions, { config, extend })
// }
export class Extension<Options = any, Commands = any> {
config: Required<ExtensionSpec> = {
name: 'extension',
@@ -144,6 +95,8 @@ export class Extension<Options = any, Commands = any> {
...this.config.defaultOptions,
...options,
}
return this
}
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionSpec<ExtendedOptions, ExtendedCommands>>) {