|
1 | 1 | import { Editor, EditorOptions, Extension } from "@tiptap/core";
|
2 |
| -import { Fragment, Node, Slice } from "prosemirror-model"; |
| 2 | +import { Node } from "prosemirror-model"; |
3 | 3 | // import "./blocknote.css";
|
4 | 4 | import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
|
5 | 5 | import * as Y from "yjs";
|
@@ -69,6 +69,7 @@ import { getDefaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMen
|
69 | 69 | import { TableHandlesProsemirrorPlugin } from "./extensions/TableHandles/TableHandlesPlugin";
|
70 | 70 | import { UniqueID } from "./extensions/UniqueID/UniqueID";
|
71 | 71 | import { UnreachableCaseError, mergeCSSClasses } from "./shared/utils";
|
| 72 | +import { transformPasted } from "./transformPasted"; |
72 | 73 |
|
73 | 74 | export type BlockNoteEditorOptions<
|
74 | 75 | BSpecs extends BlockSpecs,
|
@@ -445,50 +446,7 @@ export class BlockNoteEditor<
|
445 | 446 | newOptions.domAttributes?.editor?.class || ""
|
446 | 447 | ),
|
447 | 448 | },
|
448 |
| - transformPasted(slice, view) { |
449 |
| - // helper function |
450 |
| - function removeChild(node: Fragment, n: number) { |
451 |
| - const children: any[] = []; |
452 |
| - node.forEach((child, _, i) => { |
453 |
| - if (i !== n) { |
454 |
| - children.push(child); |
455 |
| - } |
456 |
| - }); |
457 |
| - return Fragment.from(children); |
458 |
| - } |
459 |
| - |
460 |
| - // fix for https://github.com/ProseMirror/prosemirror/issues/1430#issuecomment-1822570821 |
461 |
| - let f = Fragment.from(slice.content); |
462 |
| - for (let i = 0; i < f.childCount; i++) { |
463 |
| - if (f.child(i).type.spec.group === "blockContent") { |
464 |
| - const content = [f.child(i)]; |
465 |
| - if (i + 1 < f.childCount) { |
466 |
| - // when there is a blockGroup, it should be nested in the new blockcontainer |
467 |
| - if (f.child(i + 1).type.spec.group === "blockGroup") { |
468 |
| - const nestedChild = f |
469 |
| - .child(i + 1) |
470 |
| - .child(0) |
471 |
| - .child(0); |
472 |
| - |
473 |
| - if ( |
474 |
| - nestedChild.type.name === "bulletListItem" || |
475 |
| - nestedChild.type.name === "numberedListItem" |
476 |
| - ) { |
477 |
| - content.push(f.child(i + 1)); |
478 |
| - f = removeChild(f, i + 1); |
479 |
| - } |
480 |
| - } |
481 |
| - } |
482 |
| - const container = view.state.schema.nodes.blockContainer.create( |
483 |
| - undefined, |
484 |
| - content |
485 |
| - ); |
486 |
| - f = f.replaceChild(i, container); |
487 |
| - } |
488 |
| - } |
489 |
| - |
490 |
| - return new Slice(f, slice.openStart, slice.openEnd); |
491 |
| - }, |
| 449 | + transformPasted, |
492 | 450 | },
|
493 | 451 | };
|
494 | 452 |
|
|
0 commit comments