Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("includes context for text selections", () => {
let d = doc(blockquote(ul(li(p("fo<a>o"), p("b<b>ar")))))
let view = tempEditor({doc: d})
let slice = TextSelection.create(d, d.tag.a, d.tag.b).content(), {dom, text} = serializeForClipboard(view, slice)
ist(dom.innerHTML, '<li data-pm-slice="2 2 ["blockquote",null,"bullet_list",null]"><p>o</p><p>b</p></li>')
ist(parseFromClipboard(view, text, dom.innerHTML, false, d.resolve(1)), d.slice(d.tag.a, d.tag.b, true), eq)
ist(parseFromClipboard(view, text, dom.innerHTML, true, d.resolve(1)), new Slice(doc(p("o"), p("b")).content, 1, 1), eq)
})
</b></a>
it("preserves openEnd when top isn't placed", () =>
repl(doc(ul(li(p("ab<a>cd")), li(p("ef<b>gh")))),
doc(ul(li(p("ABCD")), li(p("EFGH")))).slice(5, 13, true),
doc(ul(li(p("abCD")), li(p("EFgh"))))))
</b></a>
it("allows deleting a selected block", () => {
let state = new TestState({doc: doc(p("foo"), ul(li(p("bar")), li(p("baz")), li(p("quux")))), schema})
state.nodeSel(0)
state.deleteSelection()
ist(state.doc, doc(ul(li(p("bar")), li(p("baz")), li(p("quux")))), eq)
ist(state.selection.head, 3)
state.nodeSel(2)
state.deleteSelection()
ist(state.doc, doc(ul(li(p("baz")), li(p("quux")))), eq)
ist(state.selection.head, 3)
state.nodeSel(9)
state.deleteSelection()
ist(state.doc, doc(ul(li(p("baz")))), eq)
ist(state.selection.head, 6)
state.nodeSel(0)
state.deleteSelection()
ist(state.doc, doc(p()), eq)
})
it("joins lists when lifting a list between them", () =>
apply(doc(ul(li(p("a"))), blockquote("<a>", ul(li(p("b")))), ul(li(p("c")))),
autoJoin(lift, ["bullet_list"]),
doc(ul(li(p("a")), li(p("b")), li(p("c"))))))
})</a>
it("deletes empty parent nodes", () =>
del(doc(blockquote(ul(li("<a>", p("foo"), "<b>")), p("x"))),
doc(blockquote("</b></a><b><a><b>", p("x")))))
</b></a></b>
it("can cut across different depths", () =>
t(doc(ul(li(p("hello")), li(p("wo<a>rld")), li(p("x"))), p(em("bo<b>o"))),
doc(ul(li(p("rld")), li(p("x"))), p(em("bo"))), 3, 1))
</b></a>
it("will sanely clean up top-level nodes in HTML", () => {
let view = tempEditor(), $p = view.state.doc.resolve(1)
ist(parseFromClipboard(view, "", "<ul><li>foo</li></ul>bar<br>", false, $p),
new Slice(doc(ul(li(p("foo"))), p("bar", br)).content, 3, 1), eq)
ist(parseFromClipboard(view, "", "<ul><li>foo</li></ul>bar<br><p>x</p>", false, $p),
new Slice(doc(ul(li(p("foo"))), p("bar", br), p("x")).content, 3, 1), eq)
ist(parseFromClipboard(view, "", "<li>foo</li><li>bar</li><p>x</p>", false, $p),
new Slice(doc(ol(li(p("foo")), li(p("bar"))), p("x")).content, 3, 1), eq)
})
it("will join multiple levels when possible", () =>
repl(doc(blockquote(ul(li(p("a")), li(p("b<a>")), li(p("c")), li(p("<b>d")), li(p("e"))))),
null,
doc(blockquote(ul(li(p("a")), li(p("b</b></a><b><a><b>d")), li(p("e")))))))
</b></a></b>
it("can be queried for the DOM position at a doc position", () => {
let view = tempEditor({doc: doc(ul(li(p(strong("foo")))))})
let inText = view.domAtPos(4)
ist(inText.offset, 1)
ist(inText.node.nodeValue, "foo")
let beforeLI = view.domAtPos(1)
ist(beforeLI.offset, 0)
ist(beforeLI.node.nodeName, "UL")
let afterP = view.domAtPos(7)
ist(afterP.offset, 1)
ist(afterP.node.nodeName, "LI")
})
it("makes arrow motion go through selectable block nodes", () => {
let view = tempEditor({doc: doc(p("hello<a>"), hr, ul(li(p("there"))))})
view.dispatchEvent(event(DOWN))
ist(view.state.selection.from, 7)
setSel(view, 11)
view.dispatchEvent(event(UP))
ist(view.state.selection.from, 7)
})
</a>