Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands): add joinUp and joinDown command & refactor join command code #3455

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.