@tiptap/core 2.1.13 → 2.1.14
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 +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +6 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/PasteRule.d.ts +1 -1
- package/package.json +2 -2
- package/src/PasteRule.ts +4 -3
- package/src/helpers/getMarksBetween.ts +4 -0
|
@@ -8,7 +8,7 @@ export declare type PasteRuleMatch = {
|
|
|
8
8
|
match?: RegExpMatchArray;
|
|
9
9
|
data?: Record<string, any>;
|
|
10
10
|
};
|
|
11
|
-
export declare type PasteRuleFinder = RegExp | ((text: string) => PasteRuleMatch[] | null | undefined);
|
|
11
|
+
export declare type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent) => PasteRuleMatch[] | null | undefined);
|
|
12
12
|
export declare class PasteRule {
|
|
13
13
|
find: PasteRuleFinder;
|
|
14
14
|
handler: (props: {
|
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.1.
|
|
4
|
+
"version": "2.1.14",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tiptap/pm": "^2.1.
|
|
35
|
+
"@tiptap/pm": "^2.1.14"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
package/src/PasteRule.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type PasteRuleMatch = {
|
|
|
21
21
|
data?: Record<string, any>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type PasteRuleFinder = RegExp | ((text: string) => PasteRuleMatch[] | null | undefined)
|
|
24
|
+
export type PasteRuleFinder = RegExp | ((text: string, event?: ClipboardEvent) => PasteRuleMatch[] | null | undefined)
|
|
25
25
|
|
|
26
26
|
export class PasteRule {
|
|
27
27
|
find: PasteRuleFinder
|
|
@@ -58,12 +58,13 @@ export class PasteRule {
|
|
|
58
58
|
const pasteRuleMatcherHandler = (
|
|
59
59
|
text: string,
|
|
60
60
|
find: PasteRuleFinder,
|
|
61
|
+
event?: ClipboardEvent,
|
|
61
62
|
): ExtendedRegExpMatchArray[] => {
|
|
62
63
|
if (isRegExp(find)) {
|
|
63
64
|
return [...text.matchAll(find)]
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
const matches = find(text)
|
|
67
|
+
const matches = find(text, event)
|
|
67
68
|
|
|
68
69
|
if (!matches) {
|
|
69
70
|
return []
|
|
@@ -119,7 +120,7 @@ function run(config: {
|
|
|
119
120
|
const resolvedTo = Math.min(to, pos + node.content.size)
|
|
120
121
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc')
|
|
121
122
|
|
|
122
|
-
const matches = pasteRuleMatcherHandler(textToMatch, rule.find)
|
|
123
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent)
|
|
123
124
|
|
|
124
125
|
matches.forEach(match => {
|
|
125
126
|
if (match.index === undefined) {
|
|
@@ -26,6 +26,10 @@ export function getMarksBetween(from: number, to: number, doc: ProseMirrorNode):
|
|
|
26
26
|
})
|
|
27
27
|
} else {
|
|
28
28
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
29
|
+
if (!node || node.nodeSize === undefined) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
marks.push(
|
|
30
34
|
...node.marks.map(mark => ({
|
|
31
35
|
from: pos,
|