@tiptap/core 2.0.0-beta.163 → 2.0.0-beta.164
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/tiptap-core.cjs.js +32 -8
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +32 -8
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +32 -8
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/PasteRule.ts +36 -7
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.
|
|
4
|
+
"version": "2.0.0-beta.164",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"directory": "packages/core"
|
|
46
46
|
},
|
|
47
47
|
"sideEffects": false,
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "9e48f8c23960198b166b23804c094f2ddccc3927"
|
|
49
49
|
}
|
package/src/PasteRule.ts
CHANGED
|
@@ -158,24 +158,53 @@ function run(config: {
|
|
|
158
158
|
*/
|
|
159
159
|
export function pasteRulesPlugin(props: { editor: Editor, rules: PasteRule[] }): Plugin[] {
|
|
160
160
|
const { editor, rules } = props
|
|
161
|
-
let
|
|
161
|
+
let dragSourceElement: Element | null = null
|
|
162
|
+
let isPastedFromProseMirror = false
|
|
163
|
+
let isDroppedFromProseMirror = false
|
|
162
164
|
|
|
163
165
|
const plugins = rules.map(rule => {
|
|
164
166
|
return new Plugin({
|
|
167
|
+
// we register a global drag handler to track the current drag source element
|
|
168
|
+
view(view) {
|
|
169
|
+
const handleDragstart = (event: DragEvent) => {
|
|
170
|
+
dragSourceElement = view.dom.parentElement?.contains(event.target as Element)
|
|
171
|
+
? view.dom.parentElement
|
|
172
|
+
: null
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
window.addEventListener('dragstart', handleDragstart)
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
destroy() {
|
|
179
|
+
window.removeEventListener('dragstart', handleDragstart)
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
|
|
165
184
|
props: {
|
|
166
|
-
|
|
167
|
-
|
|
185
|
+
handleDOMEvents: {
|
|
186
|
+
drop: view => {
|
|
187
|
+
isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement
|
|
188
|
+
|
|
189
|
+
return false
|
|
190
|
+
},
|
|
168
191
|
|
|
169
|
-
|
|
192
|
+
paste: (view, event) => {
|
|
193
|
+
const html = event.clipboardData?.getData('text/html')
|
|
170
194
|
|
|
171
|
-
|
|
195
|
+
isPastedFromProseMirror = !!html?.includes('data-pm-slice')
|
|
196
|
+
|
|
197
|
+
return false
|
|
198
|
+
},
|
|
172
199
|
},
|
|
173
200
|
},
|
|
201
|
+
|
|
174
202
|
appendTransaction: (transactions, oldState, state) => {
|
|
175
203
|
const transaction = transactions[0]
|
|
204
|
+
const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror
|
|
205
|
+
const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror
|
|
176
206
|
|
|
177
|
-
|
|
178
|
-
if (!transaction.getMeta('paste') || isProseMirrorHTML) {
|
|
207
|
+
if (!isPaste && !isDrop) {
|
|
179
208
|
return
|
|
180
209
|
}
|
|
181
210
|
|