Merge branch 'feature/remove-async-commands' into main
This commit is contained in:
@@ -56,6 +56,7 @@ export class Editor extends EventEmitter {
|
|||||||
private commands: { [key: string]: any } = {}
|
private commands: { [key: string]: any } = {}
|
||||||
private css!: HTMLStyleElement
|
private css!: HTMLStyleElement
|
||||||
private lastCommand = Promise.resolve()
|
private lastCommand = Promise.resolve()
|
||||||
|
public lastCommandValue: any = undefined
|
||||||
public schema!: Schema
|
public schema!: Schema
|
||||||
public view!: EditorView
|
public view!: EditorView
|
||||||
public selection = { from: 0, to: 0 }
|
public selection = { from: 0, to: 0 }
|
||||||
@@ -69,6 +70,7 @@ export class Editor extends EventEmitter {
|
|||||||
editable: true,
|
editable: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constructor(options: Partial<EditorOptions> = {}) {
|
constructor(options: Partial<EditorOptions> = {}) {
|
||||||
super()
|
super()
|
||||||
this.options = { ...this.options, ...options }
|
this.options = { ...this.options, ...options }
|
||||||
@@ -163,12 +165,50 @@ export class Editor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.commands[name] = this.chainCommand((...args: any) => {
|
this.commands[name] = this.chainCommand((...args: any) => {
|
||||||
return new Promise(resolve => callback(resolve, this.proxy)(...args))
|
// console.log('command', this.lastCommandValue)
|
||||||
|
const commandValue = callback(() => {}, this.proxy)(...args)
|
||||||
|
|
||||||
|
// if (commandValue !== undefined) {
|
||||||
|
this.lastCommandValue = commandValue
|
||||||
|
// }
|
||||||
|
|
||||||
|
return this.proxy
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.proxy
|
return this.proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call a command.
|
||||||
|
*
|
||||||
|
* @param name The name of the command you want to call.
|
||||||
|
* @param options The options of the command.
|
||||||
|
*/
|
||||||
|
public command(name: string, ...options: any) {
|
||||||
|
return this.commands[name](...options)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a command to make it chainable.
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
*/
|
||||||
|
private chainCommand = (method: Function) => (...args: any) => {
|
||||||
|
// console.log('chain', this.lastCommandValue)
|
||||||
|
// this.lastCommand = this.lastCommand
|
||||||
|
// .then(() => {
|
||||||
|
|
||||||
|
// const jo = method.apply(this, args)
|
||||||
|
|
||||||
|
// console.log({jo})
|
||||||
|
// })
|
||||||
|
// // .then(method.apply(this, args))
|
||||||
|
// .catch(console.error)
|
||||||
|
method.apply(this, args)
|
||||||
|
|
||||||
|
return this.proxy
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a ProseMirror plugin.
|
* Register a ProseMirror plugin.
|
||||||
*
|
*
|
||||||
@@ -199,29 +239,6 @@ export class Editor extends EventEmitter {
|
|||||||
this.view.updateState(state)
|
this.view.updateState(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Call a command.
|
|
||||||
*
|
|
||||||
* @param name The name of the command you want to call.
|
|
||||||
* @param options The options of the command.
|
|
||||||
*/
|
|
||||||
public command(name: string, ...options: any) {
|
|
||||||
return this.commands[name](...options)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a command to make it chainable.
|
|
||||||
*
|
|
||||||
* @param method
|
|
||||||
*/
|
|
||||||
private chainCommand = (method: Function) => (...args: any) => {
|
|
||||||
this.lastCommand = this.lastCommand
|
|
||||||
.then(() => method.apply(this, args))
|
|
||||||
.catch(console.error)
|
|
||||||
|
|
||||||
return this.proxy
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an extension manager.
|
* Creates an extension manager.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -94,7 +94,18 @@ export default class ExtensionManager {
|
|||||||
return collect(this.extensions)
|
return collect(this.extensions)
|
||||||
.map(extension => extension.config.keys)
|
.map(extension => extension.config.keys)
|
||||||
.filter(keys => keys)
|
.filter(keys => keys)
|
||||||
.map(keys => keymap(keys))
|
.map(keys => {
|
||||||
|
const values = Object.entries(keys).map(([key, action]) => {
|
||||||
|
return [key, () => {
|
||||||
|
this.editor.lastCommandValue = undefined
|
||||||
|
// @ts-ignore
|
||||||
|
const bla = action().lastCommandValue
|
||||||
|
// console.log({bla})
|
||||||
|
return bla
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return keymap(Object.fromEntries(values))
|
||||||
|
})
|
||||||
.toArray()
|
.toArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,5 +61,8 @@ export default (next: Function, editor: Editor) => (position = null) => {
|
|||||||
|
|
||||||
view.dispatch(transaction)
|
view.dispatch(transaction)
|
||||||
view.focus()
|
view.focus()
|
||||||
|
//@ts-ignore
|
||||||
|
// console.log(bla)
|
||||||
|
// return 'FOCUS'
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,6 @@ export default (next: Function, editor: Editor) => (typeOrName: string | NodeTyp
|
|||||||
const { view, state, schema } = editor
|
const { view, state, schema } = editor
|
||||||
const type = getNodeType(typeOrName, schema)
|
const type = getNodeType(typeOrName, schema)
|
||||||
|
|
||||||
splitListItem(type)(state, view.dispatch)
|
return splitListItem(type)(state, view.dispatch)
|
||||||
next()
|
// next()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default new Node()
|
|||||||
toDOM: () => ['li', 0],
|
toDOM: () => ['li', 0],
|
||||||
}))
|
}))
|
||||||
.keys(({ editor, name }) => ({
|
.keys(({ editor, name }) => ({
|
||||||
// Enter: () => editor.splitListItem(name),
|
Enter: () => editor.splitListItem(name).focus()
|
||||||
// Tab: () => editor.sinkListItem(name),
|
// Tab: () => editor.sinkListItem(name),
|
||||||
// 'Shift-Tab': () => editor.liftListItem(name),
|
// 'Shift-Tab': () => editor.liftListItem(name),
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user