fix more linting errors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
|
||||
import { Command } from '../Editor'
|
||||
|
||||
type DeleteSelectionCommand = () => Command
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Editor, Command } from '../Editor'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { Editor, Command } from '../Editor'
|
||||
import minMax from '../utils/minMax'
|
||||
|
||||
type Position = 'start' | 'end' | number | boolean | null
|
||||
type FocusCommand = (position?: Position) => Command
|
||||
|
||||
declare module '../Editor' {
|
||||
@@ -15,8 +16,6 @@ interface ResolvedSelection {
|
||||
to: number,
|
||||
}
|
||||
|
||||
type Position = 'start' | 'end' | number | boolean | null
|
||||
|
||||
function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection {
|
||||
if (position === null) {
|
||||
return editor.selection
|
||||
@@ -31,7 +30,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
|
||||
|
||||
if (position === 'end') {
|
||||
const { size } = editor.state.doc.content
|
||||
|
||||
|
||||
return {
|
||||
from: size,
|
||||
to: size - 1, // TODO: -1 only for nodes with content
|
||||
@@ -54,9 +53,9 @@ export const focus: FocusCommand = (position = null) => ({ editor, view, tr }) =
|
||||
const resolvedFrom = minMax(from, 0, doc.content.size)
|
||||
const resolvedEnd = minMax(to, 0, doc.content.size)
|
||||
const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)
|
||||
|
||||
|
||||
tr.setSelection(selection)
|
||||
view.focus()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DOMParser } from 'prosemirror-model'
|
||||
import { Selection, Transaction } from 'prosemirror-state'
|
||||
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
|
||||
import { Command } from '../Editor'
|
||||
import elementFromString from '../utils/elementFromString'
|
||||
import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform"
|
||||
|
||||
type InsertHTMLCommand = (value: string) => Command
|
||||
|
||||
@@ -15,13 +15,13 @@ declare module '../Editor' {
|
||||
// TODO: move to utils
|
||||
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
||||
function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number) {
|
||||
let last = tr.steps.length - 1
|
||||
const last = tr.steps.length - 1
|
||||
if (last < startLen) return
|
||||
let step = tr.steps[last]
|
||||
const step = tr.steps[last]
|
||||
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return
|
||||
let map = tr.mapping.maps[last]
|
||||
const map = tr.mapping.maps[last]
|
||||
let end = 0
|
||||
map.forEach((_from, _to, _newFrom, newTo) => { if (end == 0) end = newTo })
|
||||
map.forEach((_from, _to, _newFrom, newTo) => { if (end === 0) end = newTo })
|
||||
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
|
||||
}
|
||||
|
||||
@@ -34,4 +34,4 @@ export const insertHTML: InsertHTMLCommand = value => ({ tr, state }) => {
|
||||
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Command } from '../Editor'
|
||||
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
type LiftListItem = (typeOrName: string | NodeType) => Command
|
||||
@@ -11,7 +11,7 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const liftListItem: LiftListItem = (typeOrName) => ({ state, dispatch }) => {
|
||||
export const liftListItem: LiftListItem = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalLiftListItem(type)(state, dispatch)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
|
||||
@@ -11,10 +11,12 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const removeMark: RemoveMarkCommand = (typeOrName) => ({ tr, state }) => {
|
||||
export const removeMark: RemoveMarkCommand = typeOrName => ({ tr, state }) => {
|
||||
const { selection } = tr
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
let { from, to, $from, empty } = selection
|
||||
let {
|
||||
from, to, $from, empty,
|
||||
} = selection
|
||||
|
||||
if (empty) {
|
||||
const range = getMarkRange($from, type)
|
||||
|
||||
@@ -8,7 +8,7 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => {
|
||||
export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
|
||||
@@ -18,7 +18,7 @@ export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => {
|
||||
|
||||
Object
|
||||
.entries(state.schema.marks)
|
||||
.forEach(([name, mark]) => {
|
||||
.forEach(([, mark]) => {
|
||||
tr.removeMark(from, to, mark as any)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
interface Range {
|
||||
@@ -29,7 +29,7 @@ export const replaceWithNode: ReplaceWithNodeCommand = (typeOrName, attrs = {},
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
view.dispatch(tr.replaceWith(from, to, type.create(attrs)))
|
||||
|
||||
return true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
||||
import { Command } from '../Editor'
|
||||
|
||||
type SelectAllCommand = () => Command
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
|
||||
import { Command } from '../Editor'
|
||||
|
||||
type SelectParentNodeCommand = () => Command
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { Command } from '../Editor'
|
||||
|
||||
type SetContentCommand = (
|
||||
content: string,
|
||||
@@ -18,7 +18,7 @@ export const setContent: SetContentCommand = (content = '', emitUpdate = false,
|
||||
const { doc } = tr
|
||||
const document = createDocument(content, parseOptions)
|
||||
const selection = TextSelection.create(doc, 0, doc.content.size)
|
||||
|
||||
|
||||
tr.setSelection(selection)
|
||||
.replaceSelectionWith(document, false)
|
||||
.setMeta('preventUpdate', !emitUpdate)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Command } from '../Editor'
|
||||
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
type SinkListItem = (typeOrName: string | NodeType) => Command
|
||||
@@ -11,7 +11,7 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const sinkListItem: SinkListItem = (typeOrName) => ({ state, dispatch }) => {
|
||||
export const sinkListItem: SinkListItem = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalSinkListItem(type)(state, dispatch)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Command } from '../Editor'
|
||||
import { splitListItem as originalSplitListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
type SplitListItem = (typeOrName: string | NodeType) => Command
|
||||
@@ -11,7 +11,7 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const splitListItem: SplitListItem = (typeOrName) => ({ state, dispatch }) => {
|
||||
export const splitListItem: SplitListItem = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalSplitListItem(type)(state, dispatch)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Command } from '../Editor'
|
||||
import { wrapInList, liftListItem } from 'prosemirror-schema-list'
|
||||
import { findParentNode } from 'prosemirror-utils'
|
||||
import { Node, NodeType, Schema } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
type ToggleListCommand = (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Command } from '../Editor'
|
||||
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
|
||||
type ToggleMarkCommand = (typeOrName: string | MarkType) => Command
|
||||
@@ -11,7 +11,7 @@ declare module '../Editor' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleMark: ToggleMarkCommand = (typeOrName) => ({ state, dispatch }) => {
|
||||
export const toggleMark: ToggleMarkCommand = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
|
||||
return originalToggleMark(type)(state, dispatch)
|
||||
|
||||
@@ -23,7 +23,7 @@ export const toggleNode: ToggleNodeCommand = (typeOrName, toggleTypeOrName, attr
|
||||
|
||||
if (isActive) {
|
||||
return setBlockType(toggleType)(state, dispatch)
|
||||
} else {
|
||||
return setBlockType(type, attrs)(state, dispatch)
|
||||
}
|
||||
return setBlockType(type, attrs)(state, dispatch)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from '../Editor'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
|
||||
@@ -16,7 +16,8 @@ declare module '../Editor' {
|
||||
|
||||
export const updateMark: UpdateMarkCommand = (typeOrName, attrs = {}) => ({ tr, state }) => {
|
||||
const { selection, doc } = tr
|
||||
let { from, to, $from, empty } = selection
|
||||
let { from, to } = selection
|
||||
const { $from, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
|
||||
if (empty) {
|
||||
|
||||
Reference in New Issue
Block a user