Skip to content

Commit

Permalink
feat(commands): add joinUp and joinDown command (#3455)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch authored Nov 25, 2022
1 parent 1c3568d commit 343ce75
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 38 deletions.
8 changes: 8 additions & 0 deletions docs/api/commands/join-down.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# joinDown
The `joinDown` command joins the selected block, or if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling below it. [See also](https://prosemirror.net/docs/ref/#commands.joinDown)

## Usage
```js
editor.commands.joinDown()
```

8 changes: 8 additions & 0 deletions docs/api/commands/join-up.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# joinUp
The `joinUp` command joins the selected block, or if there is a text selection, the closest ancestor block of the selection that can be joined, with the sibling above it. [See also](https://prosemirror.net/docs/ref/#commands.joinUp)

## Usage
```js
editor.commands.joinUp()
```

3 changes: 1 addition & 2 deletions packages/core/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export * from './focus'
export * from './forEach'
export * from './insertContent'
export * from './insertContentAt'
export * from './joinBackward'
export * from './joinForward'
export * from './join'
export * from './keyboardShortcut'
export * from './lift'
export * from './liftEmptyBlock'
Expand Down
50 changes: 50 additions & 0 deletions packages/core/src/commands/join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
joinBackward as originalJoinBackward, joinDown as originalJoinDown, joinForward as originalJoinForward, joinUp as originalJoinUp,
} from 'prosemirror-commands'

import { RawCommands } from '../types'

declare module '@tiptap/core' {
interface Commands<ReturnType> {
joinUp: {
/**
* Join two nodes Up.
*/
joinUp: () => ReturnType,
}
joinDown: {
/**
* Join two nodes Down.
*/
joinDown: () => ReturnType,
}
joinBackward: {
/**
* Join two nodes Backwards.
*/
joinBackward: () => ReturnType,
}
joinForward: {
/**
* Join two nodes Forwards.
*/
joinForward: () => ReturnType,
}
}
}

export const joinUp: RawCommands['joinUp'] = () => ({ state, dispatch }) => {
return originalJoinUp(state, dispatch)
}

export const joinDown: RawCommands['joinDown'] = () => ({ state, dispatch }) => {
return originalJoinDown(state, dispatch)
}

export const joinBackward: RawCommands['joinBackward'] = () => ({ state, dispatch }) => {
return originalJoinBackward(state, dispatch)
}

export const joinForward: RawCommands['joinForward'] = () => ({ state, dispatch }) => {
return originalJoinForward(state, dispatch)
}
18 changes: 0 additions & 18 deletions packages/core/src/commands/joinBackward.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/core/src/commands/joinForward.ts

This file was deleted.

0 comments on commit 343ce75

Please sign in to comment.