Published
Edited
Nov 5, 2021
2 stars
Insert cell
Insert cell
Insert cell
viewof editor = {
const element = html`<div />`;
const editor = new Editor({
element,
extensions: [StarterKit, NodeView],
content: `<p>Hello World!</p>
<node-view></node-view>`
});
element.value = editor;
return element;
}
Insert cell
editor
Insert cell
editor.getJSON()
Insert cell
Insert cell
TipTapComponent = component(() => {
const { useEditor, EditorContent } = TipTapReact;
const editor = useEditor({
extensions: [StarterKit],
content: `<p>Hello World! 🌎️</p>`
});
// return EditorContent({ editor });
return jsx`<EditorContent editor=${editor} />`;
})
Insert cell
render(() => jsx`<${TipTapComponent} />`)
Insert cell
NodeView = Node.create({
name: "nodeView",

group: "block",

atom: true,

addAttributes() {
return {
count: {
default: 0
}
};
},

parseHTML() {
return [
{
tag: "node-view"
}
];
},

renderHTML({ HTMLAttributes }) {
return ["node-view", TipTap.mergeAttributes(HTMLAttributes)];
},

addNodeView() {
return ({ editor, node, getPos }) => {
const { view } = editor;

// Markup
/*
<div class="node-view">
<span class="label">Node view</span>

<div class="content">
<button>
This button has been clicked ${node.attrs.count} times.
</button>
</div>
</div>
*/

const dom = document.createElement("div");
dom.classList.add("node-view");

const label = document.createElement("span");
label.classList.add("label");
label.innerHTML = "Node view";

const content = document.createElement("div");
content.classList.add("content");

const button = document.createElement("button");
button.innerHTML = `This button has been clicked ${node.attrs.count} times.`;
button.addEventListener("click", () => {
if (typeof getPos === "function") {
view.dispatch(
view.state.tr.setNodeMarkup(getPos(), undefined, {
count: node.attrs.count + 1
})
);

editor.commands.focus();
}
});
content.append(button);

dom.append(label, content);

return {
dom
};
};
}
})
Insert cell
Insert cell
StarterKit = {
const { default: StarterKit } = await import(
"//cdn.skypack.dev/@tiptap/starter-kit?min"
);
return StarterKit;
}
Insert cell
Node = TipTap.Node
Insert cell
Editor = TipTap.Editor
Insert cell
TipTap = import("//cdn.skypack.dev/@tiptap/core?min")
Insert cell
TipTapReact = import("//cdn.skypack.dev/@tiptap/react")
// TipTapReact = import("//esm.sh/@tiptap/react?deps=react@17.0.2")
Insert cell
import { render, component, createElement, jsx } from "@gnestor/react"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more