Skip to content

Instantly share code, notes, and snippets.

@darkfrog26

darkfrog26/attempt.scala

Last active Jan 9, 2021
Embed
What would you like to do?
@js.native
@JSGlobal("BlotEmbed")
class BlotEmbed extends js.Object {
var blotName: String = js.native
var tagName: String = js.native
var className: String = js.native
def create(data: js.Object): html.Element = js.native
def setDataValues(element: html.Element, data: js.Object): html.Element = js.native
def value(domNode: html.Element): js.Object = js.native
}
object TestBlot extends BlotEmbed {
@JSExportStatic
override def create(data: js.Object): Element = {
val node = super.create(data)
val block = document.createElement("span")
block.classList.add("ql-testing")
block.innerHTML = data.asInstanceOf[Value].value
node.appendChild(block)
setDataValues(node, data)
}
@JSExportStatic
override def setDataValues(element: Element, data: js.Object): Element = {
// TODO: implement
element
}
@JSExportStatic
override def value(domNode: Element): js.Object = js.Object()
}
trait Value {
def value: String
}
const BlotEmbed = Quill.import("blots/embed");
class TestBlot extends BlotEmbed {
static create(data) {
const node = super.create();
const block = document.createElement("span");
block.className = "ql-testing";
block.innerHTML = data.value;
node.appendChild(block);
return TestBlot.setDataValues(node, data);
}
static setDataValues(element, data) {
const domNode = element;
Object.keys(data).forEach(key => {
domNode.dataset[key] = data[key];
});
return domNode;
}
static value(domNode) {
return domNode.dataset;
}
}
TestBlot.blotName = "testing";
TestBlot.tagName = "span";
TestBlot.className = "testing";
Quill.register(TestBlot);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment