@tiptap/core 2.2.0-rc.3 → 2.2.0-rc.5
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 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +20 -10
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/PasteRule.d.ts +9 -5
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +1 -1
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +1 -1
- package/package.json +2 -2
- package/src/Extension.ts +1 -1
- package/src/Mark.ts +1 -1
- package/src/Node.ts +1 -1
- package/src/PasteRule.ts +26 -8
- package/src/pasteRules/markPasteRule.ts +5 -3
- package/src/pasteRules/nodePasteRule.ts +5 -3
|
@@ -18,16 +18,20 @@ export declare class PasteRule {
|
|
|
18
18
|
commands: SingleCommands;
|
|
19
19
|
chain: () => ChainedCommands;
|
|
20
20
|
can: () => CanCommands;
|
|
21
|
+
pasteEvent: ClipboardEvent;
|
|
22
|
+
dropEvent: DragEvent;
|
|
21
23
|
}) => void | null;
|
|
22
24
|
constructor(config: {
|
|
23
25
|
find: PasteRuleFinder;
|
|
24
26
|
handler: (props: {
|
|
25
|
-
state: EditorState;
|
|
26
|
-
range: Range;
|
|
27
|
-
match: ExtendedRegExpMatchArray;
|
|
28
|
-
commands: SingleCommands;
|
|
29
|
-
chain: () => ChainedCommands;
|
|
30
27
|
can: () => CanCommands;
|
|
28
|
+
chain: () => ChainedCommands;
|
|
29
|
+
commands: SingleCommands;
|
|
30
|
+
dropEvent: DragEvent;
|
|
31
|
+
match: ExtendedRegExpMatchArray;
|
|
32
|
+
pasteEvent: ClipboardEvent;
|
|
33
|
+
range: Range;
|
|
34
|
+
state: EditorState;
|
|
31
35
|
}) => void | null;
|
|
32
36
|
});
|
|
33
37
|
}
|
|
@@ -8,5 +8,5 @@ import { ExtendedRegExpMatchArray } from '../types.js';
|
|
|
8
8
|
export declare function markPasteRule(config: {
|
|
9
9
|
find: PasteRuleFinder;
|
|
10
10
|
type: MarkType;
|
|
11
|
-
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
|
|
11
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>) | false | null;
|
|
12
12
|
}): PasteRule;
|
|
@@ -8,5 +8,5 @@ import { ExtendedRegExpMatchArray } from '../types.js';
|
|
|
8
8
|
export declare function nodePasteRule(config: {
|
|
9
9
|
find: PasteRuleFinder;
|
|
10
10
|
type: NodeType;
|
|
11
|
-
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
|
|
11
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>) | false | null;
|
|
12
12
|
}): PasteRule;
|
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.2.0-rc.
|
|
4
|
+
"version": "2.2.0-rc.5",
|
|
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.2.0-rc.
|
|
35
|
+
"@tiptap/pm": "^2.2.0-rc.5"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tiptap/pm": "^2.0.0"
|
package/src/Extension.ts
CHANGED
|
@@ -357,7 +357,7 @@ export class Extension<Options = any, Storage = any> {
|
|
|
357
357
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
358
358
|
extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
359
359
|
) {
|
|
360
|
-
const extension = new Extension<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
360
|
+
const extension = new Extension<ExtendedOptions, ExtendedStorage>({ ...this.config, ...extendedConfig })
|
|
361
361
|
|
|
362
362
|
extension.parent = this
|
|
363
363
|
|
package/src/Mark.ts
CHANGED
|
@@ -489,7 +489,7 @@ export class Mark<Options = any, Storage = any> {
|
|
|
489
489
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
490
490
|
extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
491
491
|
) {
|
|
492
|
-
const extension = new Mark<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
492
|
+
const extension = new Mark<ExtendedOptions, ExtendedStorage>({ ...this.config, ...extendedConfig })
|
|
493
493
|
|
|
494
494
|
extension.parent = this
|
|
495
495
|
|
package/src/Node.ts
CHANGED
|
@@ -598,7 +598,7 @@ export class Node<Options = any, Storage = any> {
|
|
|
598
598
|
extend<ExtendedOptions = Options, ExtendedStorage = Storage>(
|
|
599
599
|
extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedStorage>> = {},
|
|
600
600
|
) {
|
|
601
|
-
const extension = new Node<ExtendedOptions, ExtendedStorage>(extendedConfig)
|
|
601
|
+
const extension = new Node<ExtendedOptions, ExtendedStorage>({ ...this.config, ...extendedConfig })
|
|
602
602
|
|
|
603
603
|
extension.parent = this
|
|
604
604
|
|
package/src/PasteRule.ts
CHANGED
|
@@ -33,17 +33,21 @@ export class PasteRule {
|
|
|
33
33
|
commands: SingleCommands
|
|
34
34
|
chain: () => ChainedCommands
|
|
35
35
|
can: () => CanCommands
|
|
36
|
+
pasteEvent: ClipboardEvent
|
|
37
|
+
dropEvent: DragEvent
|
|
36
38
|
}) => void | null
|
|
37
39
|
|
|
38
40
|
constructor(config: {
|
|
39
41
|
find: PasteRuleFinder
|
|
40
42
|
handler: (props: {
|
|
41
|
-
state: EditorState
|
|
42
|
-
range: Range
|
|
43
|
-
match: ExtendedRegExpMatchArray
|
|
44
|
-
commands: SingleCommands
|
|
45
|
-
chain: () => ChainedCommands
|
|
46
43
|
can: () => CanCommands
|
|
44
|
+
chain: () => ChainedCommands
|
|
45
|
+
commands: SingleCommands
|
|
46
|
+
dropEvent: DragEvent
|
|
47
|
+
match: ExtendedRegExpMatchArray
|
|
48
|
+
pasteEvent: ClipboardEvent
|
|
49
|
+
range: Range
|
|
50
|
+
state: EditorState
|
|
47
51
|
}) => void | null
|
|
48
52
|
}) {
|
|
49
53
|
this.find = config.find
|
|
@@ -92,9 +96,11 @@ function run(config: {
|
|
|
92
96
|
from: number
|
|
93
97
|
to: number
|
|
94
98
|
rule: PasteRule
|
|
99
|
+
pasteEvent: ClipboardEvent
|
|
100
|
+
dropEvent: DragEvent
|
|
95
101
|
}): boolean {
|
|
96
102
|
const {
|
|
97
|
-
editor, state, from, to, rule,
|
|
103
|
+
editor, state, from, to, rule, pasteEvent, dropEvent,
|
|
98
104
|
} = config
|
|
99
105
|
|
|
100
106
|
const { commands, chain, can } = new CommandManager({
|
|
@@ -134,6 +140,8 @@ function run(config: {
|
|
|
134
140
|
commands,
|
|
135
141
|
chain,
|
|
136
142
|
can,
|
|
143
|
+
pasteEvent,
|
|
144
|
+
dropEvent,
|
|
137
145
|
})
|
|
138
146
|
|
|
139
147
|
handlers.push(handler)
|
|
@@ -155,6 +163,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
155
163
|
let dragSourceElement: Element | null = null
|
|
156
164
|
let isPastedFromProseMirror = false
|
|
157
165
|
let isDroppedFromProseMirror = false
|
|
166
|
+
let pasteEvent = new ClipboardEvent('paste')
|
|
167
|
+
let dropEvent = new DragEvent('drop')
|
|
158
168
|
|
|
159
169
|
const plugins = rules.map(rule => {
|
|
160
170
|
return new Plugin({
|
|
@@ -177,15 +187,18 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
177
187
|
|
|
178
188
|
props: {
|
|
179
189
|
handleDOMEvents: {
|
|
180
|
-
drop: view => {
|
|
190
|
+
drop: (view, event: Event) => {
|
|
181
191
|
isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement
|
|
192
|
+
dropEvent = event as DragEvent
|
|
182
193
|
|
|
183
194
|
return false
|
|
184
195
|
},
|
|
185
196
|
|
|
186
|
-
paste: (
|
|
197
|
+
paste: (_view, event: Event) => {
|
|
187
198
|
const html = (event as ClipboardEvent).clipboardData?.getData('text/html')
|
|
188
199
|
|
|
200
|
+
pasteEvent = event as ClipboardEvent
|
|
201
|
+
|
|
189
202
|
isPastedFromProseMirror = !!html?.includes('data-pm-slice')
|
|
190
203
|
|
|
191
204
|
return false
|
|
@@ -224,6 +237,8 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
224
237
|
from: Math.max(from - 1, 0),
|
|
225
238
|
to: to.b - 1,
|
|
226
239
|
rule,
|
|
240
|
+
pasteEvent,
|
|
241
|
+
dropEvent,
|
|
227
242
|
})
|
|
228
243
|
|
|
229
244
|
// stop if there are no changes
|
|
@@ -231,6 +246,9 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
231
246
|
return
|
|
232
247
|
}
|
|
233
248
|
|
|
249
|
+
dropEvent = new DragEvent('drop')
|
|
250
|
+
pasteEvent = new ClipboardEvent('paste')
|
|
251
|
+
|
|
234
252
|
return tr
|
|
235
253
|
},
|
|
236
254
|
})
|
|
@@ -14,14 +14,16 @@ export function markPasteRule(config: {
|
|
|
14
14
|
type: MarkType
|
|
15
15
|
getAttributes?:
|
|
16
16
|
| Record<string, any>
|
|
17
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
17
|
+
| ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
|
|
18
18
|
| false
|
|
19
19
|
| null
|
|
20
20
|
}) {
|
|
21
21
|
return new PasteRule({
|
|
22
22
|
find: config.find,
|
|
23
|
-
handler: ({
|
|
24
|
-
|
|
23
|
+
handler: ({
|
|
24
|
+
state, range, match, pasteEvent,
|
|
25
|
+
}) => {
|
|
26
|
+
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
|
|
25
27
|
|
|
26
28
|
if (attributes === false || attributes === null) {
|
|
27
29
|
return null
|
|
@@ -13,14 +13,16 @@ export function nodePasteRule(config: {
|
|
|
13
13
|
type: NodeType
|
|
14
14
|
getAttributes?:
|
|
15
15
|
| Record<string, any>
|
|
16
|
-
| ((match: ExtendedRegExpMatchArray) => Record<string, any>)
|
|
16
|
+
| ((match: ExtendedRegExpMatchArray, event: ClipboardEvent) => Record<string, any>)
|
|
17
17
|
| false
|
|
18
18
|
| null
|
|
19
19
|
}) {
|
|
20
20
|
return new PasteRule({
|
|
21
21
|
find: config.find,
|
|
22
|
-
handler({
|
|
23
|
-
|
|
22
|
+
handler({
|
|
23
|
+
match, chain, range, pasteEvent,
|
|
24
|
+
}) {
|
|
25
|
+
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent)
|
|
24
26
|
|
|
25
27
|
if (attributes === false || attributes === null) {
|
|
26
28
|
return null
|