fix ts errors
This commit is contained in:
@@ -71,7 +71,7 @@ module.exports = function (api) {
|
|||||||
.test(/\.tsx?$/)
|
.test(/\.tsx?$/)
|
||||||
.use()
|
.use()
|
||||||
.loader('ts-loader')
|
.loader('ts-loader')
|
||||||
.options({ transpileOnly: true, appendTsSuffixTo: [/\.vue$/] })
|
.options({ transpileOnly: false, appendTsSuffixTo: [/\.vue$/] })
|
||||||
|
|
||||||
config.module
|
config.module
|
||||||
.rule('jsx')
|
.rule('jsx')
|
||||||
|
|||||||
@@ -134,15 +134,16 @@ export class Editor extends EventEmitter {
|
|||||||
tr,
|
tr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const self = this
|
||||||
Object.defineProperty(props, 'commands', {
|
Object.defineProperty(props, 'commands', {
|
||||||
get: function() {
|
get: function() {
|
||||||
return Object.fromEntries(Object
|
return Object.fromEntries(Object
|
||||||
.entries(this.commands)
|
.entries(self.commands)
|
||||||
.map(([name, command]) => {
|
.map(([name, command]) => {
|
||||||
return [name, (...args) => command(...args)(props)]
|
return [name, (...args: any[]) => command(...args)(props)]
|
||||||
}))
|
}))
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
});
|
})
|
||||||
|
|
||||||
const callback = command(...args)(props)
|
const callback = command(...args)(props)
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ export class Editor extends EventEmitter {
|
|||||||
|
|
||||||
public chain() {
|
public chain() {
|
||||||
const { tr } = this.state
|
const { tr } = this.state
|
||||||
const callbacks = []
|
const callbacks: boolean[] = []
|
||||||
|
|
||||||
return new Proxy({}, {
|
return new Proxy({}, {
|
||||||
get: (target, name: string, proxy) => {
|
get: (target, name: string, proxy) => {
|
||||||
@@ -179,12 +180,13 @@ export class Editor extends EventEmitter {
|
|||||||
tr,
|
tr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const self = this
|
||||||
Object.defineProperty(props, 'commands', {
|
Object.defineProperty(props, 'commands', {
|
||||||
get: function() {
|
get: function() {
|
||||||
return Object.fromEntries(Object
|
return Object.fromEntries(Object
|
||||||
.entries(this.commands)
|
.entries(self.commands)
|
||||||
.map(([name, command]) => {
|
.map(([name, command]) => {
|
||||||
return [name, (...args) => command(...args)(props)]
|
return [name, (...args: any[]) => command(...args)(props)]
|
||||||
}))
|
}))
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DOMParser } from 'prosemirror-model'
|
import { DOMParser } from 'prosemirror-model'
|
||||||
import { Selection } from 'prosemirror-state'
|
import { Selection, Transaction } from 'prosemirror-state'
|
||||||
import { Command } from '../Editor'
|
import { Command } from '../Editor'
|
||||||
import elementFromString from '../utils/elementFromString'
|
import elementFromString from '../utils/elementFromString'
|
||||||
import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform"
|
import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform"
|
||||||
@@ -14,14 +14,15 @@ declare module '../Editor' {
|
|||||||
|
|
||||||
// TODO: move to utils
|
// TODO: move to utils
|
||||||
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
||||||
function selectionToInsertionEnd(tr, startLen, bias) {
|
function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number) {
|
||||||
let last = tr.steps.length - 1
|
let last = tr.steps.length - 1
|
||||||
if (last < startLen) return
|
if (last < startLen) return
|
||||||
let step = tr.steps[last]
|
let step = tr.steps[last]
|
||||||
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return
|
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return
|
||||||
let map = tr.mapping.maps[last], end
|
let map = tr.mapping.maps[last]
|
||||||
map.forEach((_from, _to, _newFrom, newTo) => { if (end == null) end = newTo })
|
let end = 0
|
||||||
tr.setSelection(Selection.near(tr.doc.resolve(end), bias))
|
map.forEach((_from, _to, _newFrom, newTo) => { if (end == 0) end = newTo })
|
||||||
|
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const insertHTML: InsertHTMLCommand = value => ({ tr, editor }) => {
|
export const insertHTML: InsertHTMLCommand = value => ({ tr, editor }) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ declare module '../Editor' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => {
|
export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const { from, to, empty } = selection
|
const { from, to, empty } = selection
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => {
|
|||||||
Object
|
Object
|
||||||
.entries(state.schema.marks)
|
.entries(state.schema.marks)
|
||||||
.forEach(([name, mark]) => {
|
.forEach(([name, mark]) => {
|
||||||
tr.removeMark(from, to, mark)
|
tr.removeMark(from, to, mark as any)
|
||||||
})
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -13,11 +13,7 @@ declare module '../Editor' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setContent: SetContentCommand = (content = null, emitUpdate = false, parseOptions = {}) => ({ tr, editor }) => {
|
export const setContent: SetContentCommand = (content = '', emitUpdate = false, parseOptions = {}) => ({ tr, editor }) => {
|
||||||
if (content === null) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const { createDocument } = editor
|
const { createDocument } = editor
|
||||||
const { doc } = tr
|
const { doc } = tr
|
||||||
const document = createDocument(content, parseOptions)
|
const document = createDocument(content, parseOptions)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default new Node()
|
|||||||
toDOM: () => ['li', 0],
|
toDOM: () => ['li', 0],
|
||||||
}))
|
}))
|
||||||
.keys(({ editor, name }) => ({
|
.keys(({ editor, name }) => ({
|
||||||
Enter: () => editor.splitListItem(name).focus()
|
// Enter: () => editor.chain().focus().splitListItem(name).run()
|
||||||
// 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