diff --git a/docs/gridsome.server.js b/docs/gridsome.server.js index c4dc9255..7d9bfde2 100644 --- a/docs/gridsome.server.js +++ b/docs/gridsome.server.js @@ -71,7 +71,7 @@ module.exports = function (api) { .test(/\.tsx?$/) .use() .loader('ts-loader') - .options({ transpileOnly: true, appendTsSuffixTo: [/\.vue$/] }) + .options({ transpileOnly: false, appendTsSuffixTo: [/\.vue$/] }) config.module .rule('jsx') diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 1509bbfa..a74273b6 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -134,15 +134,16 @@ export class Editor extends EventEmitter { tr, } + const self = this Object.defineProperty(props, 'commands', { get: function() { return Object.fromEntries(Object - .entries(this.commands) + .entries(self.commands) .map(([name, command]) => { - return [name, (...args) => command(...args)(props)] + return [name, (...args: any[]) => command(...args)(props)] })) }.bind(this) - }); + }) const callback = command(...args)(props) @@ -154,7 +155,7 @@ export class Editor extends EventEmitter { public chain() { const { tr } = this.state - const callbacks = [] + const callbacks: boolean[] = [] return new Proxy({}, { get: (target, name: string, proxy) => { @@ -179,12 +180,13 @@ export class Editor extends EventEmitter { tr, } + const self = this Object.defineProperty(props, 'commands', { get: function() { return Object.fromEntries(Object - .entries(this.commands) + .entries(self.commands) .map(([name, command]) => { - return [name, (...args) => command(...args)(props)] + return [name, (...args: any[]) => command(...args)(props)] })) }.bind(this) }); diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts index bec1e0ad..a21df16d 100644 --- a/packages/core/src/commands/insertHTML.ts +++ b/packages/core/src/commands/insertHTML.ts @@ -1,5 +1,5 @@ import { DOMParser } from 'prosemirror-model' -import { Selection } from 'prosemirror-state' +import { Selection, Transaction } from 'prosemirror-state' import { Command } from '../Editor' import elementFromString from '../utils/elementFromString' import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform" @@ -14,14 +14,15 @@ declare module '../Editor' { // TODO: move to utils // 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 if (last < startLen) return let step = tr.steps[last] if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return - let map = tr.mapping.maps[last], end - map.forEach((_from, _to, _newFrom, newTo) => { if (end == null) end = newTo }) - tr.setSelection(Selection.near(tr.doc.resolve(end), bias)) + let map = tr.mapping.maps[last] + let end = 0 + 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 }) => { diff --git a/packages/core/src/commands/removeMarks.ts b/packages/core/src/commands/removeMarks.ts index 9fe98d41..8b4d2847 100644 --- a/packages/core/src/commands/removeMarks.ts +++ b/packages/core/src/commands/removeMarks.ts @@ -8,7 +8,7 @@ declare module '../Editor' { } } -export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => { +export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => { const { selection } = tr const { from, to, empty } = selection @@ -19,7 +19,7 @@ export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => { Object .entries(state.schema.marks) .forEach(([name, mark]) => { - tr.removeMark(from, to, mark) + tr.removeMark(from, to, mark as any) }) return true diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index bc9717bd..50a7641c 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -13,11 +13,7 @@ declare module '../Editor' { } } -export const setContent: SetContentCommand = (content = null, emitUpdate = false, parseOptions = {}) => ({ tr, editor }) => { - if (content === null) { - return false - } - +export const setContent: SetContentCommand = (content = '', emitUpdate = false, parseOptions = {}) => ({ tr, editor }) => { const { createDocument } = editor const { doc } = tr const document = createDocument(content, parseOptions) diff --git a/packages/extension-list-item/index.ts b/packages/extension-list-item/index.ts index a29b53da..4b55442b 100644 --- a/packages/extension-list-item/index.ts +++ b/packages/extension-list-item/index.ts @@ -12,7 +12,7 @@ export default new Node() toDOM: () => ['li', 0], })) .keys(({ editor, name }) => ({ - Enter: () => editor.splitListItem(name).focus() + // Enter: () => editor.chain().focus().splitListItem(name).run() // Tab: () => editor.sinkListItem(name), // 'Shift-Tab': () => editor.liftListItem(name), }))