@tiptap/core 3.4.5 → 3.4.6
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/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +20 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/InputRule.ts +12 -6
- package/src/inputRules/markInputRule.ts +2 -0
- package/src/inputRules/nodeInputRule.ts +7 -0
- package/src/inputRules/textInputRule.ts +2 -1
- package/src/inputRules/textblockTypeInputRule.ts +2 -0
- package/src/inputRules/wrappingInputRule.ts +2 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/core",
|
|
3
3
|
"description": "headless rich text editor",
|
|
4
|
-
"version": "3.4.
|
|
4
|
+
"version": "3.4.6",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"jsx-dev-runtime"
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@tiptap/pm": "^3.4.
|
|
55
|
+
"@tiptap/pm": "^3.4.6"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@tiptap/pm": "^3.4.
|
|
58
|
+
"@tiptap/pm": "^3.4.6"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
package/src/InputRule.ts
CHANGED
|
@@ -33,6 +33,8 @@ export class InputRule {
|
|
|
33
33
|
can: () => CanCommands
|
|
34
34
|
}) => void | null
|
|
35
35
|
|
|
36
|
+
undoable: boolean
|
|
37
|
+
|
|
36
38
|
constructor(config: {
|
|
37
39
|
find: InputRuleFinder
|
|
38
40
|
handler: (props: {
|
|
@@ -43,9 +45,11 @@ export class InputRule {
|
|
|
43
45
|
chain: () => ChainedCommands
|
|
44
46
|
can: () => CanCommands
|
|
45
47
|
}) => void | null
|
|
48
|
+
undoable?: boolean
|
|
46
49
|
}) {
|
|
47
50
|
this.find = config.find
|
|
48
51
|
this.handler = config.handler
|
|
52
|
+
this.undoable = config.undoable ?? true
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -149,12 +153,14 @@ function run(config: {
|
|
|
149
153
|
|
|
150
154
|
// store transform as meta data
|
|
151
155
|
// so we can undo input rules within the `undoInputRules` command
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
if (rule.undoable) {
|
|
157
|
+
tr.setMeta(plugin, {
|
|
158
|
+
transform: tr,
|
|
159
|
+
from,
|
|
160
|
+
to,
|
|
161
|
+
text,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
158
164
|
|
|
159
165
|
view.dispatch(tr)
|
|
160
166
|
matched = true
|
|
@@ -14,6 +14,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
14
14
|
export function markInputRule(config: {
|
|
15
15
|
find: InputRuleFinder
|
|
16
16
|
type: MarkType
|
|
17
|
+
undoable?: boolean
|
|
17
18
|
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
18
19
|
}) {
|
|
19
20
|
return new InputRule({
|
|
@@ -62,5 +63,6 @@ export function markInputRule(config: {
|
|
|
62
63
|
tr.removeStoredMark(config.type)
|
|
63
64
|
}
|
|
64
65
|
},
|
|
66
|
+
undoable: config.undoable,
|
|
65
67
|
})
|
|
66
68
|
}
|
|
@@ -21,6 +21,12 @@ export function nodeInputRule(config: {
|
|
|
21
21
|
*/
|
|
22
22
|
type: NodeType
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Whether the input rule should be undoable
|
|
26
|
+
* when the user presses backspace.
|
|
27
|
+
*/
|
|
28
|
+
undoable?: boolean
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* A function that returns the attributes for the node
|
|
26
32
|
* can also be an object of attributes
|
|
@@ -62,5 +68,6 @@ export function nodeInputRule(config: {
|
|
|
62
68
|
|
|
63
69
|
tr.scrollIntoView()
|
|
64
70
|
},
|
|
71
|
+
undoable: config.undoable,
|
|
65
72
|
})
|
|
66
73
|
}
|
|
@@ -6,7 +6,7 @@ import { InputRule } from '../InputRule.js'
|
|
|
6
6
|
* matched text is typed into it.
|
|
7
7
|
* @see https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#input-rules
|
|
8
8
|
*/
|
|
9
|
-
export function textInputRule(config: { find: InputRuleFinder; replace: string }) {
|
|
9
|
+
export function textInputRule(config: { find: InputRuleFinder; replace: string; undoable?: boolean }) {
|
|
10
10
|
return new InputRule({
|
|
11
11
|
find: config.find,
|
|
12
12
|
handler: ({ state, range, match }) => {
|
|
@@ -30,5 +30,6 @@ export function textInputRule(config: { find: InputRuleFinder; replace: string }
|
|
|
30
30
|
|
|
31
31
|
state.tr.insertText(insert, start, end)
|
|
32
32
|
},
|
|
33
|
+
undoable: config.undoable,
|
|
33
34
|
})
|
|
34
35
|
}
|
|
@@ -15,6 +15,7 @@ import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
|
15
15
|
export function textblockTypeInputRule(config: {
|
|
16
16
|
find: InputRuleFinder
|
|
17
17
|
type: NodeType
|
|
18
|
+
undoable?: boolean
|
|
18
19
|
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
19
20
|
}) {
|
|
20
21
|
return new InputRule({
|
|
@@ -29,5 +30,6 @@ export function textblockTypeInputRule(config: {
|
|
|
29
30
|
|
|
30
31
|
state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes)
|
|
31
32
|
},
|
|
33
|
+
undoable: config.undoable,
|
|
32
34
|
})
|
|
33
35
|
}
|
|
@@ -28,6 +28,7 @@ export function wrappingInputRule(config: {
|
|
|
28
28
|
keepMarks?: boolean
|
|
29
29
|
keepAttributes?: boolean
|
|
30
30
|
editor?: Editor
|
|
31
|
+
undoable?: boolean
|
|
31
32
|
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null
|
|
32
33
|
joinPredicate?: (match: ExtendedRegExpMatchArray, node: ProseMirrorNode) => boolean
|
|
33
34
|
}) {
|
|
@@ -76,5 +77,6 @@ export function wrappingInputRule(config: {
|
|
|
76
77
|
tr.join(range.from - 1)
|
|
77
78
|
}
|
|
78
79
|
},
|
|
80
|
+
undoable: config.undoable,
|
|
79
81
|
})
|
|
80
82
|
}
|