Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ist = require("ist")
const {eq, doc, p, pre, h1, a, em, img: img_, br, strong, blockquote} = require("prosemirror-test-builder")
const {EditorState, TextSelection} = require("prosemirror-state")
const {tempEditor, findTextNode} = require("./view")
const img = img_({src: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="})
function setSel(aNode, aOff, fNode, fOff) {
let r = document.createRange(), s = window.getSelection()
r.setEnd(fNode || aNode, fNode ? fOff : aOff)
r.setStart(aNode, aOff)
s.removeAllRanges()
s.addRange(r)
}
function flush(view) {
view.domObserver.flush()
}
describe("DOM change", () => {
it("notices when text is added", () => {
let view = tempEditor({doc: doc(p("hello"))})
it("can change an inline node", () =>
markup(doc(p("foo<a>", img, "bar")),
doc(p("foo", img({src: "bar", alt: "y"}), "bar")),
"image", {src: "bar", alt: "y"}))
})</a>
it("can replace content with an inline node", () =>
repl(doc(p("<a>fo<b>o")), img(), doc(p("</b></a><b><a>", img, "o"))))
</a></b>
ist(derivedDOM.innerHTML, declaredDOM.innerHTML)
ist(DOMParser.fromSchema(schema).parse(derivedDOM), doc, eq)
}
}
it("can represent simple node",
test(doc(p("hello")),
"<p>hello</p>"))
it("can represent a line break",
test(doc(p("hi", br, "there")),
"<p>hi<br>there</p>"))
it("can represent an image",
test(doc(p("hi", img({alt: "x"}), "there")),
'<p>hi<img alt="x" src="img.png">there</p>'))
it("joins styles",
test(doc(p("one", strong("two", em("three")), em("four"), "five")),
"<p>one<strong>two</strong><em><strong>three</strong>four</em>five</p>"))
it("can represent links",
test(doc(p("a ", a({href: "foo"}, "big ", a({href: "bar"}, "nested"), " link"))),
"<p>a <a href="\"foo\"">big </a><a href="\"bar\"">nested</a><a href="\"foo\""> link</a></p>"))
it("can represent and unordered list",
test(doc(ul(li(p("one")), li(p("two")), li(p("three", strong("!")))), p("after")),
"<ul><li><p>one</p></li><li><p>two</p></li><li><p>three<strong>!</strong></p></li></ul><p>after</p>"))
it("can represent an ordered list",
test(doc(ol(li(p("one")), li(p("two")), li(p("three", strong("!")))), p("after")),
const {doc, blockquote, p, em, img: img_, strong, code, br, hr, ul, li} = require("prosemirror-test-builder")
const ist = require("ist")
const {Selection, NodeSelection} = require("prosemirror-state")
const {tempEditor, findTextNode} = require("./view")
const {Decoration, DecorationSet} = require("..")
const img = img_({src: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="})
function allPositions(doc) {
let found = []
function scan(node, start) {
if (node.isTextblock) {
for (let i = 0; i <= node.content.size; i++) found.push(start + i)
} else {
node.forEach((child, offset) => scan(child, start + offset + 1))
}
}
scan(doc, 0)
return found
}
function setDOMSel(node, offset) {
let range = document.createRange()