From 59eb68298c2e8ed557a082b8a40c2f364b581abb Mon Sep 17 00:00:00 2001 From: barsdeveloper Date: Sun, 12 Dec 2021 20:35:41 +0100 Subject: [PATCH] Small refactoring --- css/ueblueprint-draggable.css | 3 +-- css/ueblueprint-style.css | 11 +++++++---- dist/ueblueprint.js | 32 +++++++++---------------------- js/Blueprint.js | 2 +- js/graph/GraphElement.js | 2 +- js/graph/GraphLink.js | 2 +- js/graph/GraphNode.js | 2 +- js/graph/GraphPin.js | 2 +- js/graph/GraphSelector.js | 2 +- js/input/Pointing.js | 4 ++-- js/input/Unfocus.js | 2 +- js/selection/OrderedIndexArray.js | 13 ------------- js/template/NodeTemplate.js | 1 - 13 files changed, 26 insertions(+), 52 deletions(-) diff --git a/css/ueblueprint-draggable.css b/css/ueblueprint-draggable.css index 63bf073..79342c8 100644 --- a/css/ueblueprint-draggable.css +++ b/css/ueblueprint-draggable.css @@ -1,5 +1,4 @@ -.ueb-draggable, -.ueb-node { +.ueb-draggable { /* Indicate the element draggable */ cursor: move; /* It will be positioned absolutely */ diff --git a/css/ueblueprint-style.css b/css/ueblueprint-style.css index 3481219..07f9b65 100644 --- a/css/ueblueprint-style.css +++ b/css/ueblueprint-style.css @@ -26,7 +26,7 @@ --ueb-node-radius: 7px; } -u-blueprint { +ueb-blueprint { display: block; position: relative; font-family: Roboto, Noto, Oxygen, Ubuntu, "Open Sans", "Helvetica Neue", @@ -58,7 +58,7 @@ u-blueprint { scrollbar-width: 0; } -u-blueprint[data-focused="true"] .ueb-viewport-body { +ueb-blueprint[data-focused="true"] .ueb-viewport-body { overflow: scroll; } @@ -210,7 +210,7 @@ u-blueprint[data-focused="true"] .ueb-viewport-body { translateY(calc(var(--ueb-translate-y) * 1px)); } -.ueb-node { +ueb-node { display: block; position: absolute; transform: translateX(calc(var(--ueb-position-x) * 1px)) @@ -285,9 +285,12 @@ u-blueprint[data-focused="true"] .ueb-viewport-body { margin-right: auto; } -u-pin { +ueb-pin { display: block; padding: 4px 8px; +} + +ueb-selector[data-selecting="false"] ~ ueb-node ueb-pin { cursor: pointer; } diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index de9b08a..d472a7f 100644 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -105,13 +105,6 @@ class OrderedIndexArray { || comparisonValue != null && position == this.currentPosition && this.comparisonValueSupplier(element) < comparisonValue) { ++this.currentPosition; } - /* - let newArray = new Uint32Array(this.array.length + 1) - newArray.set(this.array.subarray(0, position), 0) - newArray[position] = element - newArray.set(this.array.subarray(position), position + 1) - this.array = newArray - */ this.shiftRight(position); this.array[position] = element; ++this.length; @@ -137,12 +130,6 @@ class OrderedIndexArray { if (position < this.currentPosition) { --this.currentPosition; } - /* - let newArray = new Uint32Array(this.array.length - 1) - newArray.set(this.array.subarray(0, position), 0) - newArray.set(this.array.subarray(position + 1), position) - this.array = newArray - */ this.shiftLeft(position); --this.length; return position @@ -367,7 +354,7 @@ class GraphElement extends HTMLElement { } connectedCallback() { - this.blueprint = this.closest("u-blueprint"); + this.blueprint = this.closest("ueb-blueprint"); this.template.apply(this); } } @@ -454,7 +441,7 @@ class GraphSelector extends GraphElement { } } -customElements.define("u-selector", GraphSelector); +customElements.define("ueb-selector", GraphSelector); /** @typedef {import("../Blueprint").default} Blueprint */ class BlueprintTemplate extends Template { @@ -704,8 +691,8 @@ class Pointing extends Context { const scaleCorrection = 1 / Utility.getScale(this.target); const targetOffset = this.movementSpace.getBoundingClientRect(); let location = [ - (mouseEvent.clientX - targetOffset.x) * scaleCorrection, - (mouseEvent.clientY - targetOffset.y) * scaleCorrection + Math.round((mouseEvent.clientX - targetOffset.x) * scaleCorrection), + Math.round((mouseEvent.clientY - targetOffset.y) * scaleCorrection) ]; return location } @@ -1133,7 +1120,7 @@ class GraphPin extends GraphElement { } } -customElements.define("u-pin", GraphPin); +customElements.define("ueb-pin", GraphPin); /** * @typedef {import("../graph/GraphNode").default} GraphNode @@ -1193,7 +1180,6 @@ class NodeTemplate extends SelectableDraggableTemplate { */ apply(node) { super.apply(node); - node.classList.add("ueb-node"); if (node.selected) { node.classList.add("ueb-selected"); } @@ -1485,7 +1471,7 @@ class GraphNode extends SelectableDraggable { } } -customElements.define("u-node", GraphNode); +customElements.define("ueb-node", GraphNode); var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; @@ -1888,7 +1874,7 @@ class Unfocus extends Context { */ clickedSomewhere(e) { // If target is inside the blueprint grid - if (e.target.closest("u-blueprint")) { + if (e.target.closest("ueb-blueprint")) { return } this.blueprint.setFocused(false); @@ -2297,7 +2283,7 @@ class Blueprint extends GraphElement { } } -customElements.define("u-blueprint", Blueprint); +customElements.define("ueb-blueprint", Blueprint); /** * @typedef {import("../graph/GraphLink").default} GraphLink @@ -2336,7 +2322,7 @@ class GraphLink extends GraphElement { } } -customElements.define("u-link", GraphLink); +customElements.define("ueb-link", GraphLink); class GeneralSerializer extends Serializer { diff --git a/js/Blueprint.js b/js/Blueprint.js index dc43312..0220b5f 100755 --- a/js/Blueprint.js +++ b/js/Blueprint.js @@ -330,4 +330,4 @@ export default class Blueprint extends GraphElement { } } -customElements.define("u-blueprint", Blueprint) +customElements.define("ueb-blueprint", Blueprint) diff --git a/js/graph/GraphElement.js b/js/graph/GraphElement.js index 5d31920..5b35639 100755 --- a/js/graph/GraphElement.js +++ b/js/graph/GraphElement.js @@ -15,7 +15,7 @@ export default class GraphElement extends HTMLElement { } connectedCallback() { - this.blueprint = this.closest("u-blueprint") + this.blueprint = this.closest("ueb-blueprint") this.template.apply(this) } } diff --git a/js/graph/GraphLink.js b/js/graph/GraphLink.js index f0e4a6a..a5f9b17 100755 --- a/js/graph/GraphLink.js +++ b/js/graph/GraphLink.js @@ -19,4 +19,4 @@ export default class GraphLink extends GraphElement { } } -customElements.define("u-link", GraphLink) +customElements.define("ueb-link", GraphLink) diff --git a/js/graph/GraphNode.js b/js/graph/GraphNode.js index 2e5c40a..8d561c6 100755 --- a/js/graph/GraphNode.js +++ b/js/graph/GraphNode.js @@ -56,4 +56,4 @@ export default class GraphNode extends SelectableDraggable { } } -customElements.define("u-node", GraphNode) +customElements.define("ueb-node", GraphNode) diff --git a/js/graph/GraphPin.js b/js/graph/GraphPin.js index 8c5c98d..9311c22 100644 --- a/js/graph/GraphPin.js +++ b/js/graph/GraphPin.js @@ -42,4 +42,4 @@ export default class GraphPin extends GraphElement { } } -customElements.define("u-pin", GraphPin) +customElements.define("ueb-pin", GraphPin) diff --git a/js/graph/GraphSelector.js b/js/graph/GraphSelector.js index 08f659a..4e8fa7d 100755 --- a/js/graph/GraphSelector.js +++ b/js/graph/GraphSelector.js @@ -37,4 +37,4 @@ export default class GraphSelector extends GraphElement { } } -customElements.define("u-selector", GraphSelector) +customElements.define("ueb-selector", GraphSelector) diff --git a/js/input/Pointing.js b/js/input/Pointing.js index affea89..f7d851b 100755 --- a/js/input/Pointing.js +++ b/js/input/Pointing.js @@ -17,8 +17,8 @@ export default class Pointing extends Context { const scaleCorrection = 1 / Utility.getScale(this.target) const targetOffset = this.movementSpace.getBoundingClientRect() let location = [ - (mouseEvent.clientX - targetOffset.x) * scaleCorrection, - (mouseEvent.clientY - targetOffset.y) * scaleCorrection + Math.round((mouseEvent.clientX - targetOffset.x) * scaleCorrection), + Math.round((mouseEvent.clientY - targetOffset.y) * scaleCorrection) ] return location } diff --git a/js/input/Unfocus.js b/js/input/Unfocus.js index 8b5dcb2..32efaf6 100644 --- a/js/input/Unfocus.js +++ b/js/input/Unfocus.js @@ -19,7 +19,7 @@ export default class Unfocus extends Context { */ clickedSomewhere(e) { // If target is inside the blueprint grid - if (e.target.closest("u-blueprint")) { + if (e.target.closest("ueb-blueprint")) { return } this.blueprint.setFocused(false) diff --git a/js/selection/OrderedIndexArray.js b/js/selection/OrderedIndexArray.js index 3310133..59fad37 100755 --- a/js/selection/OrderedIndexArray.js +++ b/js/selection/OrderedIndexArray.js @@ -70,13 +70,6 @@ export default class OrderedIndexArray { || comparisonValue != null && position == this.currentPosition && this.comparisonValueSupplier(element) < comparisonValue) { ++this.currentPosition } - /* - let newArray = new Uint32Array(this.array.length + 1) - newArray.set(this.array.subarray(0, position), 0) - newArray[position] = element - newArray.set(this.array.subarray(position), position + 1) - this.array = newArray - */ this.shiftRight(position) this.array[position] = element ++this.length @@ -102,12 +95,6 @@ export default class OrderedIndexArray { if (position < this.currentPosition) { --this.currentPosition } - /* - let newArray = new Uint32Array(this.array.length - 1) - newArray.set(this.array.subarray(0, position), 0) - newArray.set(this.array.subarray(position + 1), position) - this.array = newArray - */ this.shiftLeft(position) --this.length return position diff --git a/js/template/NodeTemplate.js b/js/template/NodeTemplate.js index 3e63619..bbd288e 100755 --- a/js/template/NodeTemplate.js +++ b/js/template/NodeTemplate.js @@ -61,7 +61,6 @@ export default class NodeTemplate extends SelectableDraggableTemplate { */ apply(node) { super.apply(node) - node.classList.add("ueb-node") if (node.selected) { node.classList.add("ueb-selected") }