Various fixes and refactoring

This commit is contained in:
barsdeveloper
2022-04-03 23:01:35 +02:00
parent 2456caf2b7
commit 7f223555db
22 changed files with 507 additions and 514 deletions

View File

@@ -1,5 +1,6 @@
// @ts-check
import Configuration from "../Configuration"
import html from "./html"
import ITemplate from "./ITemplate"
import sanitizeText from "./sanitizeText"
@@ -71,15 +72,15 @@ export default class BlueprintTemplate extends ITemplate {
super.apply(blueprint)
blueprint.classList.add("ueb", `ueb-zoom-${blueprint.zoom}`)
Object.entries({
"--ueb-font-size": sanitizeText(blueprint.settings.fontSize),
"--ueb-grid-size": `${sanitizeText(blueprint.settings.gridSize)}px`,
"--ueb-grid-line-width": `${sanitizeText(blueprint.settings.gridLineWidth)}px`,
"--ueb-grid-line-color": sanitizeText(blueprint.settings.gridLineColor),
"--ueb-grid-set": sanitizeText(blueprint.settings.gridSet),
"--ueb-grid-set-line-color": sanitizeText(blueprint.settings.gridSetLineColor),
"--ueb-grid-axis-line-color": sanitizeText(blueprint.settings.gridAxisLineColor),
"--ueb-node-radius": `${sanitizeText(blueprint.settings.nodeRadius)}px`,
"--ueb-link-min-width": sanitizeText(blueprint.settings.linkMinWidth)
"--ueb-font-size": sanitizeText(Configuration.fontSize),
"--ueb-grid-size": `${sanitizeText(Configuration.gridSize)}px`,
"--ueb-grid-line-width": `${sanitizeText(Configuration.gridLineWidth)}px`,
"--ueb-grid-line-color": sanitizeText(Configuration.gridLineColor),
"--ueb-grid-set": sanitizeText(Configuration.gridSet),
"--ueb-grid-set-line-color": sanitizeText(Configuration.gridSetLineColor),
"--ueb-grid-axis-line-color": sanitizeText(Configuration.gridAxisLineColor),
"--ueb-node-radius": `${sanitizeText(Configuration.nodeRadius)}px`,
"--ueb-link-min-width": sanitizeText(Configuration.linkMinWidth)
}).forEach(entry => blueprint.style.setProperty(entry[0], entry[1]))
blueprint.headerElement = blueprint.querySelector('.ueb-viewport-header')
blueprint.overlayElement = blueprint.querySelector('.ueb-viewport-overlay')

View File

@@ -27,8 +27,8 @@ export default class LinkMessageTemplate extends ITemplate {
apply(linkMessage) {
const a = super.apply(linkMessage)
const linkMessageSetup = _ => linkMessage.querySelector(".ueb-link-message").innerText = linkMessage.message(
linkMessage.linkElement.getSourcePin(),
linkMessage.linkElement.getDestinationPin()
linkMessage.linkElement.sourcePin,
linkMessage.linkElement.destinationPin
)
linkMessage.linkElement = linkMessage.closest(LinkElement.tagName)
if (linkMessage.linkElement) {

View File

@@ -1,5 +1,6 @@
// @ts-check
import Configuration from "../Configuration"
import html from "./html"
import ITemplate from "./ITemplate"
import sanitizeText from "./sanitizeText"
@@ -85,6 +86,10 @@ export default class LinkTemplate extends ITemplate {
}
link.classList.add("ueb-positioned")
link.pathElement = link.querySelector("path")
const referencePin = link.sourcePin ?? link.destinationPin
if (referencePin) {
link.style.setProperty("--ueb-pin-color", referencePin.getColor())
}
}
/**
@@ -92,10 +97,6 @@ export default class LinkTemplate extends ITemplate {
*/
applyStartDragging(link) {
link.blueprint.dataset.creatingLink = "true"
const referencePin = link.getSourcePin() ?? link.getDestinationPin()
if (referencePin) {
link.style.setProperty("--ueb-pin-color", referencePin.getColor())
}
link.classList.add("ueb-link-dragging")
}
@@ -123,7 +124,7 @@ export default class LinkTemplate extends ITemplate {
*/
applyFullLocation(link) {
const dx = Math.max(Math.abs(link.sourceLocation[0] - link.destinationLocation[0]), 1)
const width = Math.max(dx, link.blueprint.settings.linkMinWidth)
const width = Math.max(dx, Configuration.linkMinWidth)
const height = Math.max(Math.abs(link.sourceLocation[1] - link.destinationLocation[1]), 1)
const fillRatio = dx / width
const aspectRatio = width / height
@@ -152,7 +153,7 @@ export default class LinkTemplate extends ITemplate {
* fillRatio
let c2 = LinkTemplate.c2Clamped(xInverted ? -dx : dx) + start
c2 = Math.min(c2, LinkTemplate.c2DecreasingValue(width))
const d = link.blueprint.settings.linkRightSVGPath(start, c1, c2)
const d = Configuration.linkRightSVGPath(start, c1, c2)
// TODO move to CSS when Firefox will support property d and css will have enough functions
link.pathElement?.setAttribute("d", d)
}

View File

@@ -22,7 +22,7 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
<div class="ueb-node-header">
<span class="ueb-node-name">
<span class="ueb-node-symbol"></span>
<span class="ueb-node-text">${sanitizeText(node.entity.getName())}</span>
<span class="ueb-node-text">${sanitizeText(node.getNodeName())}</span>
</span>
</div>
<div class="ueb-node-body">
@@ -46,7 +46,9 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
if (node.selected) {
node.classList.add("ueb-selected")
}
node.dataset.name = node.getNodeName()
const name = node.entity.getNameAndNumber()
node.dataset.name = sanitizeText(name[0])
node.dataset.count = sanitizeText(name[1])
if (node.entity.AdvancedPinDisplay) {
node.dataset.advancedDisplay = node.entity.AdvancedPinDisplay.toString()
}

View File

@@ -71,7 +71,7 @@ export default class PinTemplate extends ITemplate {
pin.dataset.advancedView = "true"
}
pin.clickableElement = pin
window.customElements.whenDefined("ueb-node").then(_ => pin.nodeElement = pin.closest("ueb-node"))
pin.nodeElement = pin.closest("ueb-node")
pin.getLinks().forEach(pinReference => {
const targetPin = pin.blueprint.getPin(pinReference)
if (targetPin) {

View File

@@ -11,10 +11,7 @@ const tagReplacement = {
}
function sanitizeText(value) {
if (value.constructor === String) {
return value.replace(/[&<>'"]/g, tag => tagReplacement[tag])
}
return value
return value.toString().replace(/[&<>'"]/g, tag => tagReplacement[tag])
}
export default sanitizeText