@tiptap/core 2.0.0-beta.204 → 2.0.0-beta.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.0.0-beta.204",
4
+ "version": "2.0.0-beta.206",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -31,7 +31,16 @@
31
31
  "src",
32
32
  "dist"
33
33
  ],
34
- "dependencies": {
34
+ "peerDependencies": {
35
+ "prosemirror-commands": "^1.3.1",
36
+ "prosemirror-keymap": "^1.2.0",
37
+ "prosemirror-model": "^1.18.1",
38
+ "prosemirror-schema-list": "^1.2.2",
39
+ "prosemirror-state": "^1.4.1",
40
+ "prosemirror-transform": "^1.7.0",
41
+ "prosemirror-view": "^1.28.2"
42
+ },
43
+ "devDependencies": {
35
44
  "prosemirror-commands": "^1.3.1",
36
45
  "prosemirror-keymap": "^1.2.0",
37
46
  "prosemirror-model": "^1.18.1",
@@ -0,0 +1,41 @@
1
+ import { RawCommands } from '../types'
2
+
3
+ declare module '@tiptap/core' {
4
+ interface Commands<ReturnType> {
5
+ deleteCurrentNode: {
6
+ /**
7
+ * Delete the node that currently has the selection anchor.
8
+ */
9
+ deleteCurrentNode: () => ReturnType,
10
+ }
11
+ }
12
+ }
13
+
14
+ export const deleteCurrentNode: RawCommands['deleteCurrentNode'] = () => ({ tr, dispatch }) => {
15
+ const { selection } = tr
16
+ const currentNode = selection.$anchor.node()
17
+
18
+ // if there is content inside the current node, break out of this command
19
+ if (currentNode.content.size > 0) {
20
+ return false
21
+ }
22
+
23
+ const $pos = tr.selection.$anchor
24
+
25
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
26
+ const node = $pos.node(depth)
27
+
28
+ if (node.type === currentNode.type) {
29
+ if (dispatch) {
30
+ const from = $pos.before(depth)
31
+ const to = $pos.after(depth)
32
+
33
+ tr.delete(from, to).scrollIntoView()
34
+ }
35
+
36
+ return true
37
+ }
38
+ }
39
+
40
+ return false
41
+ }
@@ -3,6 +3,7 @@ export * from './clearContent'
3
3
  export * from './clearNodes'
4
4
  export * from './command'
5
5
  export * from './createParagraphNear'
6
+ export * from './deleteCurrentNode'
6
7
  export * from './deleteNode'
7
8
  export * from './deleteRange'
8
9
  export * from './deleteSelection'
@@ -14,8 +15,7 @@ export * from './focus'
14
15
  export * from './forEach'
15
16
  export * from './insertContent'
16
17
  export * from './insertContentAt'
17
- export * from './joinBackward'
18
- export * from './joinForward'
18
+ export * from './join'
19
19
  export * from './keyboardShortcut'
20
20
  export * from './lift'
21
21
  export * from './liftEmptyBlock'
@@ -0,0 +1,50 @@
1
+ import {
2
+ joinBackward as originalJoinBackward, joinDown as originalJoinDown, joinForward as originalJoinForward, joinUp as originalJoinUp,
3
+ } from 'prosemirror-commands'
4
+
5
+ import { RawCommands } from '../types'
6
+
7
+ declare module '@tiptap/core' {
8
+ interface Commands<ReturnType> {
9
+ joinUp: {
10
+ /**
11
+ * Join two nodes Up.
12
+ */
13
+ joinUp: () => ReturnType,
14
+ }
15
+ joinDown: {
16
+ /**
17
+ * Join two nodes Down.
18
+ */
19
+ joinDown: () => ReturnType,
20
+ }
21
+ joinBackward: {
22
+ /**
23
+ * Join two nodes Backwards.
24
+ */
25
+ joinBackward: () => ReturnType,
26
+ }
27
+ joinForward: {
28
+ /**
29
+ * Join two nodes Forwards.
30
+ */
31
+ joinForward: () => ReturnType,
32
+ }
33
+ }
34
+ }
35
+
36
+ export const joinUp: RawCommands['joinUp'] = () => ({ state, dispatch }) => {
37
+ return originalJoinUp(state, dispatch)
38
+ }
39
+
40
+ export const joinDown: RawCommands['joinDown'] = () => ({ state, dispatch }) => {
41
+ return originalJoinDown(state, dispatch)
42
+ }
43
+
44
+ export const joinBackward: RawCommands['joinBackward'] = () => ({ state, dispatch }) => {
45
+ return originalJoinBackward(state, dispatch)
46
+ }
47
+
48
+ export const joinForward: RawCommands['joinForward'] = () => ({ state, dispatch }) => {
49
+ return originalJoinForward(state, dispatch)
50
+ }
@@ -37,6 +37,7 @@ export const Keymap = Extension.create({
37
37
 
38
38
  const handleDelete = () => this.editor.commands.first(({ commands }) => [
39
39
  () => commands.deleteSelection(),
40
+ () => commands.deleteCurrentNode(),
40
41
  () => commands.joinForward(),
41
42
  () => commands.selectNodeForward(),
42
43
  ])
package/src/types.ts CHANGED
@@ -252,3 +252,5 @@ export type TextSerializer = (props: {
252
252
  export type ExtendedRegExpMatchArray = RegExpMatchArray & {
253
253
  data?: Record<string, any>,
254
254
  }
255
+
256
+ export type Dispatch = ((args?: any) => any) | undefined
@@ -1,12 +0,0 @@
1
- import { RawCommands } from '../types';
2
- declare module '@tiptap/core' {
3
- interface Commands<ReturnType> {
4
- joinBackward: {
5
- /**
6
- * Join two nodes backward.
7
- */
8
- joinBackward: () => ReturnType;
9
- };
10
- }
11
- }
12
- export declare const joinBackward: RawCommands['joinBackward'];
@@ -1,12 +0,0 @@
1
- import { RawCommands } from '../types';
2
- declare module '@tiptap/core' {
3
- interface Commands<ReturnType> {
4
- joinForward: {
5
- /**
6
- * Join two nodes forward.
7
- */
8
- joinForward: () => ReturnType;
9
- };
10
- }
11
- }
12
- export declare const joinForward: RawCommands['joinForward'];
@@ -1,18 +0,0 @@
1
- import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
2
-
3
- import { RawCommands } from '../types'
4
-
5
- declare module '@tiptap/core' {
6
- interface Commands<ReturnType> {
7
- joinBackward: {
8
- /**
9
- * Join two nodes backward.
10
- */
11
- joinBackward: () => ReturnType,
12
- }
13
- }
14
- }
15
-
16
- export const joinBackward: RawCommands['joinBackward'] = () => ({ state, dispatch }) => {
17
- return originalJoinBackward(state, dispatch)
18
- }
@@ -1,18 +0,0 @@
1
- import { joinForward as originalJoinForward } from 'prosemirror-commands'
2
-
3
- import { RawCommands } from '../types'
4
-
5
- declare module '@tiptap/core' {
6
- interface Commands<ReturnType> {
7
- joinForward: {
8
- /**
9
- * Join two nodes forward.
10
- */
11
- joinForward: () => ReturnType,
12
- }
13
- }
14
- }
15
-
16
- export const joinForward: RawCommands['joinForward'] = () => ({ state, dispatch }) => {
17
- return originalJoinForward(state, dispatch)
18
- }