refactoring

This commit is contained in:
Philipp Kühn
2020-11-16 21:42:35 +01:00
parent f17b5f977c
commit 13a314e123
34 changed files with 94 additions and 109 deletions

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ view }) => {
const element = view.dom as HTMLElement

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (emitUpdate: Boolean = false): Command => ({ commands }) => {
return commands.setContent('', emitUpdate)

View File

@@ -1,5 +1,5 @@
import { liftTarget } from 'prosemirror-transform'
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ state, tr, dispatch }) => {
const { selection } = tr

View File

@@ -1,5 +1,5 @@
import { deleteSelection } from 'prosemirror-commands'
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ state, dispatch }) => {
return deleteSelection(state, dispatch)

View File

@@ -1,6 +1,6 @@
import { TextSelection } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'

View File

@@ -1,5 +1,6 @@
import { TextSelection } from 'prosemirror-state'
import { Editor, Command } from '../Editor'
import { Editor } from '../Editor'
import { Command } from '../types'
import minMax from '../utils/minMax'
type Position = 'start' | 'end' | number | boolean | null

View File

@@ -2,7 +2,7 @@ import { DOMParser } from 'prosemirror-model'
import { Selection, Transaction } from 'prosemirror-state'
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
import elementFromString from '../utils/elementFromString'
import { Command } from '../Editor'
import { Command } from '../types'
// TODO: move to utils
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (value: string): Command => ({ tr, dispatch }) => {
if (dispatch) {

View File

@@ -1,6 +1,6 @@
import { liftListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
export default (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {

View File

@@ -1,5 +1,5 @@
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ tr, state, dispatch }) => {
const { selection } = tr

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (attributeNames: string[] = []): Command => ({ tr, state, dispatch }) => {
const { selection } = tr

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ tr, dispatch }) => {
if (dispatch) {

View File

@@ -1,5 +1,5 @@
import { selectAll } from 'prosemirror-commands'
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ state, dispatch }) => {
return selectAll(state, dispatch)

View File

@@ -1,5 +1,5 @@
import { selectParentNode } from 'prosemirror-commands'
import { Command } from '../Editor'
import { Command } from '../types'
export default (): Command => ({ state, dispatch }) => {
return selectParentNode(state, dispatch)

View File

@@ -1,6 +1,6 @@
import { NodeType } from 'prosemirror-model'
import { setBlockType } from 'prosemirror-commands'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
export default (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {

View File

@@ -1,5 +1,5 @@
import { TextSelection } from 'prosemirror-state'
import { Command } from '../Editor'
import { Command } from '../types'
export default (content: string, emitUpdate: Boolean = false, parseOptions = {}): Command => ({ tr, editor, dispatch }) => {
const { createDocument } = editor

View File

@@ -1,6 +1,6 @@
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
export default (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {

View File

@@ -1,7 +1,7 @@
import { canSplit } from 'prosemirror-transform'
import { ContentMatch, Fragment } from 'prosemirror-model'
import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state'
import { Command } from '../Editor'
import { Command } from '../types'
function defaultBlockAt(match: ContentMatch) {
for (let i = 0; i < match.edgeCount; i + 1) {

View File

@@ -1,6 +1,6 @@
import { splitListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
export default (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {

View File

@@ -1,5 +1,5 @@
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import nodeIsActive from '../utils/nodeIsActive'
import getNodeType from '../utils/getNodeType'

View File

@@ -1,6 +1,6 @@
import { findParentNode } from 'prosemirror-utils'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
import isList from '../utils/isList'

View File

@@ -1,6 +1,6 @@
import { toggleMark } from 'prosemirror-commands'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
import markIsActive from '../utils/markIsActive'

View File

@@ -1,6 +1,6 @@
import { wrapIn, lift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import nodeIsActive from '../utils/nodeIsActive'
import getNodeType from '../utils/getNodeType'

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])): Command => props => {
const items = typeof commands === 'function'

View File

@@ -1,5 +1,5 @@
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
import getMarkAttrs from '../utils/getMarkAttrs'

View File

@@ -1,4 +1,4 @@
import { Command } from '../Editor'
import { Command } from '../types'
export default (attributes: {}): Command => ({ tr, state, dispatch }) => {
const { selection } = tr

View File

@@ -1,6 +1,6 @@
import { wrapInList } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import { Command } from '../types'
import getNodeType from '../utils/getNodeType'
export default (typeOrName: string | NodeType, attrs?: {}): Command => ({ state, dispatch }) => {