add new syntax to all packages
This commit is contained in:
@@ -63,51 +63,93 @@ 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
|
||||
},
|
||||
}>
|
||||
// /**
|
||||
// * 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: () => [],
|
||||
}
|
||||
// /**
|
||||
// * 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>)
|
||||
// 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',
|
||||
defaultOptions: {},
|
||||
addGlobalAttributes: () => [],
|
||||
addCommands: () => ({}),
|
||||
addKeyboardShortcuts: () => ({}),
|
||||
addInputRules: () => [],
|
||||
addPasteRules: () => [],
|
||||
addProseMirrorPlugins: () => [],
|
||||
}
|
||||
|
||||
const setOptions = (options?: Partial<Options>) => {
|
||||
const { defaultOptions, ...rest } = config
|
||||
options!: Options
|
||||
|
||||
return {
|
||||
...defaultExtension,
|
||||
...rest,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
...options,
|
||||
} as Options,
|
||||
constructor(config: ExtensionSpec<Options, Commands>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: ExtensionSpec<O, C>) {
|
||||
return new Extension<O, C>(config)
|
||||
}
|
||||
|
||||
set(options: Options) {
|
||||
this.options = {
|
||||
...this.config.defaultOptions,
|
||||
...options,
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign(setOptions, { config, extend })
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionSpec<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new Extension<ExtendedOptions, ExtendedCommands>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as ExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
DOMOutputSpec, MarkSpec, Mark, MarkType,
|
||||
} from 'prosemirror-model'
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { ExtensionSpec, defaultExtension } from './Extension'
|
||||
import { ExtensionSpec } from './Extension'
|
||||
import { Attributes, Overwrite } from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
@@ -106,46 +106,95 @@ export interface MarkExtensionSpec<Options = any, Commands = {}> extends Overwri
|
||||
}) => Plugin[],
|
||||
}> {}
|
||||
|
||||
export type MarkExtension = Required<Omit<MarkExtensionSpec, 'defaultOptions'> & {
|
||||
type: string,
|
||||
options: {
|
||||
[key: string]: any
|
||||
},
|
||||
}>
|
||||
// export type MarkExtension = Required<Omit<MarkExtensionSpec, 'defaultOptions'> & {
|
||||
// type: string,
|
||||
// options: {
|
||||
// [key: string]: any
|
||||
// },
|
||||
// }>
|
||||
|
||||
const defaultMark: MarkExtension = {
|
||||
...defaultExtension,
|
||||
type: 'mark',
|
||||
name: 'mark',
|
||||
inclusive: null,
|
||||
excludes: null,
|
||||
group: null,
|
||||
spanning: null,
|
||||
parseHTML: () => null,
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
}
|
||||
// const defaultMark: MarkExtension = {
|
||||
// ...defaultExtension,
|
||||
// type: 'mark',
|
||||
// name: 'mark',
|
||||
// inclusive: null,
|
||||
// excludes: null,
|
||||
// group: null,
|
||||
// spanning: null,
|
||||
// parseHTML: () => null,
|
||||
// renderHTML: null,
|
||||
// addAttributes: () => ({}),
|
||||
// }
|
||||
|
||||
export function createMark<Options extends {}, Commands extends {}>(config: MarkExtensionSpec<Options, Commands>) {
|
||||
const extend = <ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkExtensionSpec<ExtendedOptions, ExtendedCommands>>) => {
|
||||
return createMark({
|
||||
...config,
|
||||
...extendedConfig,
|
||||
} as MarkExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
// export function createMark<Options extends {}, Commands extends {}>(config: MarkExtensionSpec<Options, Commands>) {
|
||||
// const extend = <ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkExtensionSpec<ExtendedOptions, ExtendedCommands>>) => {
|
||||
// return createMark({
|
||||
// ...config,
|
||||
// ...extendedConfig,
|
||||
// } as MarkExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
// }
|
||||
|
||||
// const setOptions = (options?: Partial<Options>) => {
|
||||
// const { defaultOptions, ...rest } = config
|
||||
|
||||
// return {
|
||||
// ...defaultMark,
|
||||
// ...rest,
|
||||
// options: {
|
||||
// ...defaultOptions,
|
||||
// ...options,
|
||||
// } as Options,
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Object.assign(setOptions, { config, extend })
|
||||
// }
|
||||
|
||||
export class MarkExtension<Options = any, Commands = any> {
|
||||
config: Required<MarkExtensionSpec> = {
|
||||
name: 'mark',
|
||||
defaultOptions: {},
|
||||
addGlobalAttributes: () => [],
|
||||
addCommands: () => ({}),
|
||||
addKeyboardShortcuts: () => ({}),
|
||||
addInputRules: () => [],
|
||||
addPasteRules: () => [],
|
||||
addProseMirrorPlugins: () => [],
|
||||
inclusive: null,
|
||||
excludes: null,
|
||||
group: null,
|
||||
spanning: null,
|
||||
parseHTML: () => null,
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
}
|
||||
|
||||
const setOptions = (options?: Partial<Options>) => {
|
||||
const { defaultOptions, ...rest } = config
|
||||
options!: Options
|
||||
|
||||
return {
|
||||
...defaultMark,
|
||||
...rest,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
...options,
|
||||
} as Options,
|
||||
constructor(config: MarkExtensionSpec<Options, Commands>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: MarkExtensionSpec<O, C>) {
|
||||
return new MarkExtension<O, C>(config)
|
||||
}
|
||||
|
||||
set(options: Options) {
|
||||
this.options = {
|
||||
...this.config.defaultOptions,
|
||||
...options,
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign(setOptions, { config, extend })
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkExtensionSpec<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new MarkExtension<ExtendedOptions, ExtendedCommands>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as MarkExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
DOMOutputSpec, NodeSpec, Node, NodeType,
|
||||
} from 'prosemirror-model'
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { ExtensionSpec, defaultExtension } from './Extension'
|
||||
import { ExtensionSpec } from './Extension'
|
||||
import { Attributes, NodeViewRenderer, Overwrite } from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
@@ -150,54 +150,111 @@ export interface NodeExtensionSpec<Options = any, Commands = {}> extends Overwri
|
||||
}) => NodeViewRenderer) | null,
|
||||
}> {}
|
||||
|
||||
export type NodeExtension = Required<Omit<NodeExtensionSpec, 'defaultOptions'> & {
|
||||
type: string,
|
||||
options: {
|
||||
[key: string]: any
|
||||
},
|
||||
}>
|
||||
// export type NodeExtension = Required<Omit<NodeExtensionSpec, 'defaultOptions'> & {
|
||||
// type: string,
|
||||
// options: {
|
||||
// [key: string]: any
|
||||
// },
|
||||
// }>
|
||||
|
||||
const defaultNode: NodeExtension = {
|
||||
...defaultExtension,
|
||||
type: 'node',
|
||||
name: 'node',
|
||||
topNode: false,
|
||||
content: null,
|
||||
marks: null,
|
||||
group: null,
|
||||
inline: null,
|
||||
atom: null,
|
||||
selectable: null,
|
||||
draggable: null,
|
||||
code: null,
|
||||
defining: null,
|
||||
isolating: null,
|
||||
parseHTML: () => null,
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
addNodeView: null,
|
||||
}
|
||||
// const defaultNode: NodeExtension = {
|
||||
// ...defaultExtension,
|
||||
// type: 'node',
|
||||
// name: 'node',
|
||||
// topNode: false,
|
||||
// content: null,
|
||||
// marks: null,
|
||||
// group: null,
|
||||
// inline: null,
|
||||
// atom: null,
|
||||
// selectable: null,
|
||||
// draggable: null,
|
||||
// code: null,
|
||||
// defining: null,
|
||||
// isolating: null,
|
||||
// parseHTML: () => null,
|
||||
// renderHTML: null,
|
||||
// addAttributes: () => ({}),
|
||||
// addNodeView: null,
|
||||
// }
|
||||
|
||||
export function createNode<Options extends {}, Commands extends {}>(config: NodeExtensionSpec<Options, Commands>) {
|
||||
const extend = <ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeExtensionSpec<ExtendedOptions, ExtendedCommands>>) => {
|
||||
return createNode({
|
||||
...config,
|
||||
...extendedConfig,
|
||||
} as NodeExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
// export function createNode<Options extends {}, Commands extends {}>(config: NodeExtensionSpec<Options, Commands>) {
|
||||
// const extend = <ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeExtensionSpec<ExtendedOptions, ExtendedCommands>>) => {
|
||||
// return createNode({
|
||||
// ...config,
|
||||
// ...extendedConfig,
|
||||
// } as NodeExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
// }
|
||||
|
||||
// const setOptions = (options?: Partial<Options>) => {
|
||||
// const { defaultOptions, ...rest } = config
|
||||
|
||||
// return {
|
||||
// ...defaultNode,
|
||||
// ...rest,
|
||||
// options: {
|
||||
// ...defaultOptions,
|
||||
// ...options,
|
||||
// } as Options,
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Object.assign(setOptions, { config, extend })
|
||||
// }
|
||||
|
||||
export class NodeExtension<Options = any, Commands = any> {
|
||||
config: Required<NodeExtensionSpec> = {
|
||||
name: 'node',
|
||||
defaultOptions: {},
|
||||
addGlobalAttributes: () => [],
|
||||
addCommands: () => ({}),
|
||||
addKeyboardShortcuts: () => ({}),
|
||||
addInputRules: () => [],
|
||||
addPasteRules: () => [],
|
||||
addProseMirrorPlugins: () => [],
|
||||
topNode: false,
|
||||
content: null,
|
||||
marks: null,
|
||||
group: null,
|
||||
inline: null,
|
||||
atom: null,
|
||||
selectable: null,
|
||||
draggable: null,
|
||||
code: null,
|
||||
defining: null,
|
||||
isolating: null,
|
||||
parseHTML: () => null,
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
addNodeView: null,
|
||||
}
|
||||
|
||||
const setOptions = (options?: Partial<Options>) => {
|
||||
const { defaultOptions, ...rest } = config
|
||||
options!: Options
|
||||
|
||||
return {
|
||||
...defaultNode,
|
||||
...rest,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
...options,
|
||||
} as Options,
|
||||
constructor(config: NodeExtensionSpec<Options, Commands>) {
|
||||
this.config = {
|
||||
...this.config,
|
||||
...config,
|
||||
}
|
||||
|
||||
this.options = this.config.defaultOptions
|
||||
}
|
||||
|
||||
static create<O, C>(config: NodeExtensionSpec<O, C>) {
|
||||
return new NodeExtension<O, C>(config)
|
||||
}
|
||||
|
||||
set(options: Options) {
|
||||
this.options = {
|
||||
...this.config.defaultOptions,
|
||||
...options,
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign(setOptions, { config, extend })
|
||||
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeExtensionSpec<ExtendedOptions, ExtendedCommands>>) {
|
||||
return new NodeExtension<ExtendedOptions, ExtendedCommands>({
|
||||
...this.config,
|
||||
...extendedConfig,
|
||||
} as NodeExtensionSpec<ExtendedOptions, ExtendedCommands>)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createExtension } from '../Extension'
|
||||
import { Extension } from '../Extension'
|
||||
import blur from '../commands/blur'
|
||||
import clearContent from '../commands/clearContent'
|
||||
import clearNodes from '../commands/clearNodes'
|
||||
@@ -28,7 +28,7 @@ import updateMarkAttributes from '../commands/updateMarkAttributes'
|
||||
import updateNodeAttributes from '../commands/updateNodeAttributes'
|
||||
import wrapInList from '../commands/wrapInList'
|
||||
|
||||
export const Commands = createExtension({
|
||||
export const Commands = Extension.create({
|
||||
addCommands() {
|
||||
return {
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { createExtension } from '../Extension'
|
||||
import { Extension } from '../Extension'
|
||||
|
||||
export const Editable = createExtension({
|
||||
export const Editable = Extension.create({
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
new Plugin({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { createExtension } from '../Extension'
|
||||
import { Extension } from '../Extension'
|
||||
|
||||
export const FocusEvents = createExtension({
|
||||
export const FocusEvents = Extension.create({
|
||||
addProseMirrorPlugins() {
|
||||
const { editor } = this
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
selectNodeBackward,
|
||||
} from 'prosemirror-commands'
|
||||
import { undoInputRule } from 'prosemirror-inputrules'
|
||||
import { createExtension } from '../Extension'
|
||||
import { Extension } from '../Extension'
|
||||
|
||||
export const Keymap = createExtension({
|
||||
export const Keymap = Extension.create({
|
||||
addKeyboardShortcuts() {
|
||||
const handleBackspace = () => this.editor.commands.try(({ state, dispatch }) => [
|
||||
() => undoInputRule(state, dispatch),
|
||||
|
||||
Reference in New Issue
Block a user