Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/react/src/components/lib/Lines.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default function Lines(props) {
overflow: "visible",
pointerEvents: "none",
willChange: "transform",
transform: `translate3d(${line.connector_x}px, ${line.connector_y}px, 0)`,
transform: `translate3d(${line.x1}px, ${line.y1}px, 0)`,
};
return (
<svg
className="sl-svg-line"
className="sl-connector-svg"
key={index}
width="4"
height="4"
Expand Down
3 changes: 2 additions & 1 deletion demo/react/src/components/lib/Node.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default function Node({ nodeObject, children }) {
))}

<div
className={"sl-node " + (nodeStyle["_focus"] ? "focus" : "")}
className={"sl-node"}
data-snapline-state={nodeStyle["_focus"] ? "focus" : "idle"}
ref={nodeDom}
style={nodeStyle}
>
Expand Down
69 changes: 35 additions & 34 deletions demo/vanilla/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ document.addEventListener("DOMContentLoaded", function () {

document
.getElementById("mathButton")
.addEventListener("mouseup", (e) => addNode(e, "node-math"));
.addEventListener("mouseup", (e) => addNode(e, "sl-node-math"));
document
.getElementById("lerpButton")
.addEventListener("mouseup", (e) => addNode(e, "node-lerp"));
.addEventListener("mouseup", (e) => addNode(e, "sl-node-lerp"));
document
.getElementById("printButton")
.addEventListener("mouseup", (e) => addNode(e, "node-print"));
.addEventListener("mouseup", (e) => addNode(e, "sl-node-print"));
document
.getElementById("constantButton")
.addEventListener("mouseup", (e) => addNode(e, "node-constant"));
.addEventListener("mouseup", (e) => addNode(e, "sl-node-number"));

container = document.getElementById("sl-canvas-container");
canvas = document.getElementById("sl-canvas");
Expand All @@ -36,20 +36,20 @@ document.addEventListener("DOMContentLoaded", function () {

sl.init(container, canvas, background, selection);

let node1 = addNode("node-constant", -250, -150);
let node2 = addNode("node-constant", -250, 0);
let node3 = addNode("node-math", 0, -150);
let node4 = addNode("node-print", 250, -150);
let node1 = addNode("sl-node-number", -250, -150);
let node2 = addNode("sl-node-number", -250, 0);
let node3 = addNode("sl-node-math", 0, -150);
let node4 = addNode("sl-node-print", 250, -150);

node1
.getConnector("output")
.connectToConnector(node3.getConnector("input_1"), null);
node2
.getConnector("output")
.connectToConnector(node3.getConnector("input_2"), null);
node3
.getConnector("result")
.connectToConnector(node4.getConnector("input"), null);
// node3
// .getConnector("result")
// .connectToConnector(node4.getConnector("input"), null);
});

document.addEventListener("click", function (e) {
Expand All @@ -66,8 +66,9 @@ function toggleMenu(e, id) {

function addNode(name, x, y) {
let ele = document.createElement(name);
ele.classList.add("sl-node");
let node = sl.createNode(ele, x, y);
let node = sl.createNode(ele, x, y, {
nodeClass: name.split("-")[2],
});
ele.initComponent(node);

canvas.appendChild(ele);
Expand All @@ -88,17 +89,15 @@ function addNode(name, x, y) {
// }

customElements.define(
"node-math",
"sl-node-math",
class extends HTMLElement {
constructor() {
super();

const template = document.getElementById("node-math").content;
const templateClone = template.cloneNode(true);

console.debug("node-math", templateClone);

this._node = templateClone.querySelector(".sl-node");
const templateClone = document
.getElementById("node-math")
.content.cloneNode(true);
this._node = templateClone;
this._input_1 = templateClone.querySelector("#input_1");
this._input_2 = templateClone.querySelector("#input_2");
this._form_1 = templateClone.querySelector("#form_1");
Expand Down Expand Up @@ -174,15 +173,16 @@ customElements.define(
);

customElements.define(
"node-lerp",
"sl-node-lerp",
class extends HTMLElement {
constructor() {
super();

const template = document.getElementById("node-lerp").content;
const templateClone = template.cloneNode(true);
const templateClone = document
.getElementById("node-lerp")
.content.cloneNode(true);

this._node = templateClone.querySelector(".sl-node");
this._node = templateClone;
this._input_1 = templateClone.querySelector("#input_1");
this._input_2 = templateClone.querySelector("#input_2");
this._form_1 = templateClone.querySelector("#form_1");
Expand Down Expand Up @@ -247,15 +247,16 @@ customElements.define(
);

customElements.define(
"node-print",
"sl-node-print",
class extends HTMLElement {
constructor() {
super();

const template = document.getElementById("node-print").content;
const templateClone = template.cloneNode(true);
const templateClone = document
.getElementById("node-print")
.content.cloneNode(true);

this._node = templateClone.querySelector(".sl-node");
this._node = templateClone;
this._input = templateClone.querySelector("#input");
this._print = templateClone.querySelector("#print");

Expand All @@ -279,23 +280,23 @@ customElements.define(
);

customElements.define(
"node-constant",
"sl-node-number",
class extends HTMLElement {
constructor() {
super();

const template = document.getElementById("node-constant").content;
const templateClone = template.cloneNode(true);

this._node = templateClone.querySelector(".sl-node");
const templateClone = document
.getElementById("node-number")
.content.cloneNode(true);
this._node = templateClone;
this._value = templateClone.querySelector("#value");
this._output = templateClone.querySelector("#output");

this.templateClone = templateClone;
}

connectedCallback() {
this.append(this.templateClone);
this.append(this._node);
}

initComponent(nodeRef) {
Expand Down
2 changes: 1 addition & 1 deletion demo/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
</template>

<template id="node-constant">
<template id="node-number">
<div class="sl-row right">
<span class="sl-connector right" id="output"></span>
</div>
Expand Down
Loading