-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Checkbox): added parse dom rules and fixed pasting of checkboxes (#…
…523)
- Loading branch information
Showing
8 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Slice} from 'prosemirror-model'; | ||
import {Plugin} from 'prosemirror-state'; | ||
|
||
import {checkboxType} from '../CheckboxSpecs'; | ||
|
||
export const fixPastePlugin = () => | ||
new Plugin({ | ||
props: { | ||
transformPasted(slice) { | ||
const {firstChild} = slice.content; | ||
if (firstChild && firstChild.type === checkboxType(firstChild.type.schema)) { | ||
// When paste html with checkboxes and checkbox is first node, | ||
// pm creates slice with broken openStart and openEnd. | ||
// And content is inserted without a container block for checkboxes. | ||
// It is fixed by create new slice with zeroed openStart and openEnd. | ||
return new Slice(slice.content, 0, 0); | ||
} | ||
|
||
return slice; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/* eslint-disable no-implicit-globals */ | ||
import type {Node, Schema} from 'prosemirror-model'; | ||
import {EditorState} from 'prosemirror-state'; | ||
import {EditorState, type Plugin} from 'prosemirror-state'; | ||
import {EditorView} from 'prosemirror-view'; | ||
|
||
import {dispatchPasteEvent} from './dispatch-event'; | ||
|
||
export function parseDOM(schema: Schema, html: string, doc: Node): void { | ||
const view = new EditorView(null, {state: EditorState.create({schema})}); | ||
export function parseDOM(schema: Schema, html: string, doc: Node, plugins?: Plugin[]): void { | ||
const view = new EditorView(null, {state: EditorState.create({schema}), plugins}); | ||
dispatchPasteEvent(view, {'text/html': html}); | ||
expect(view.state.doc).toMatchNode(doc); | ||
} |