Show at least one decimal digit

This commit is contained in:
barsdeveloper
2022-04-27 21:28:37 +02:00
parent df518ccd3c
commit db0e3d0801
7 changed files with 65 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["../../scss/style.scss","../../scss/ueb-node.scss","../../scss/ueb-pin.scss","../../scss/ueb-link.scss","../../scss/ueb-type-color.scss"],"names":[],"mappings":"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","file":"ueb-style.css"}
{"version":3,"sourceRoot":"","sources":["../../scss/style.scss","../../scss/ueb-node.scss","../../scss/ueb-pin.scss","../../scss/ueb-link.scss","../../scss/ueb-type-color.scss"],"names":[],"mappings":"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","file":"ueb-style.css"}

45
dist/ueblueprint.js vendored
View File

@@ -287,7 +287,7 @@ class TypeInitialization {
class Utility {
static sigmoid(x, curvature = 1.7) {
return 1 / (1 + (x / Math.pow(1 - x, -curvature)))
return 1 / (1 + (x / (1 - x) ** -curvature))
}
static clamp(val, min, max) {
@@ -298,6 +298,19 @@ class Utility {
return Number(getComputedStyle(element).getPropertyValue("--ueb-scale"))
}
/**
* @param {Number} num
* @param {Number} decimals
*/
static minDecimals(num, decimals = 1) {
const powered = num * 10 ** decimals;
if (Math.abs(powered % 1) > Number.EPSILON) {
// More decimal digits than required
return num.toString()
}
return num.toFixed(decimals)
}
/**
* @param {Number[]} viewportLocation
* @param {HTMLElement} movementElement
@@ -2974,6 +2987,7 @@ class IInputPinTemplate extends PinTemplate {
setup(pin) {
super.setup(pin);
if (this.input = pin.querySelector(".ueb-pin-input-content")) {
this.setInput(pin, pin.entity.DefaultValue);
let self = this;
this.onFocusHandler = (e) => {
pin.blueprint.dispatchEditTextEvent(true);
@@ -2981,7 +2995,7 @@ class IInputPinTemplate extends PinTemplate {
this.onFocusOutHandler = (e) => {
e.preventDefault();
document.getSelection().removeAllRanges(); // Deselect text inside the input
self.acceptInput(pin);
self.setInput(pin, this.getInput(pin));
pin.blueprint.dispatchEditTextEvent(false);
};
this.input.addEventListener("focus", this.onFocusHandler);
@@ -3024,9 +3038,13 @@ class IInputPinTemplate extends PinTemplate {
/**
* @param {PinElement} pin
* @param {String} value
*/
acceptInput(pin) {
setInput(pin, value) {
pin.entity.DefaultValue = this.getInput(pin);
pin.querySelector(".ueb-pin-input-content")
// @ts-expect-error
.innerText = Utility.decodeInputString(value);
}
/**
@@ -3036,9 +3054,7 @@ class IInputPinTemplate extends PinTemplate {
if (pin.isInput()) {
return html`
<div class="ueb-pin-input">
<div class="ueb-pin-input-content" role="textbox" contenteditable="true">
${Utility.decodeInputString(sanitizeText(pin.entity.getDefaultValue()))}
</div>
<div class="ueb-pin-input-content" role="textbox" contenteditable="true"></div>
</div>
`
}
@@ -3054,15 +3070,17 @@ class IInputPinTemplate extends PinTemplate {
class RealPinTemplate extends IInputPinTemplate {
/**
* @param {PinElement} pin
* @param {String} value
*/
acceptInput(pin) {
const value = parseFloat(this.getInput(pin));
pin.entity.DefaultValue = isNaN(value)
? pin.entity.AutogeneratedDefaultValue
: value.toString();
setInput(pin, value) {
let num = parseFloat(this.getInput(pin));
if (isNaN(num)) {
num = parseFloat(pin.entity.AutogeneratedDefaultValue);
}
value = Utility.minDecimals(num);
super.setInput(pin, value);
}
}
@@ -3378,7 +3396,7 @@ class NodeTemplate extends SelectableDraggableTemplate {
</div>
${node.entity.EnabledState.toString() == "DevelopmentOnly" ? html`
<div class="ueb-node-developmentonly">Development Only</div>
` : ""}
` : ""}
${node.entity.AdvancedPinDisplay ? html`
<div class="ueb-node-expansion">
<svg
@@ -3390,7 +3408,6 @@ class NodeTemplate extends SelectableDraggableTemplate {
viewBox="4 4 24 24"
>
<path
fill-rule="evenodd"
d="
M 16.003 18.626
l 7.081 -7.081

View File

@@ -5,7 +5,7 @@ import TypeInitialization from "./entity/TypeInitialization"
export default class Utility {
static sigmoid(x, curvature = 1.7) {
return 1 / (1 + (x / Math.pow(1 - x, -curvature)))
return 1 / (1 + (x / (1 - x) ** -curvature))
}
static clamp(val, min, max) {
@@ -16,6 +16,19 @@ export default class Utility {
return Number(getComputedStyle(element).getPropertyValue("--ueb-scale"))
}
/**
* @param {Number} num
* @param {Number} decimals
*/
static minDecimals(num, decimals = 1) {
const powered = num * 10 ** decimals
if (Math.abs(powered % 1) > Number.EPSILON) {
// More decimal digits than required
return num.toString()
}
return num.toFixed(decimals)
}
/**
* @param {Number[]} viewportLocation
* @param {HTMLElement} movementElement

View File

@@ -22,6 +22,7 @@ export default class IInputPinTemplate extends PinTemplate {
setup(pin) {
super.setup(pin)
if (this.input = pin.querySelector(".ueb-pin-input-content")) {
this.setInput(pin, pin.entity.DefaultValue)
let self = this
this.onFocusHandler = (e) => {
pin.blueprint.dispatchEditTextEvent(true)
@@ -29,7 +30,7 @@ export default class IInputPinTemplate extends PinTemplate {
this.onFocusOutHandler = (e) => {
e.preventDefault()
document.getSelection().removeAllRanges() // Deselect text inside the input
self.acceptInput(pin)
self.setInput(pin, this.getInput(pin))
pin.blueprint.dispatchEditTextEvent(false)
}
this.input.addEventListener("focus", this.onFocusHandler)
@@ -72,9 +73,13 @@ export default class IInputPinTemplate extends PinTemplate {
/**
* @param {PinElement} pin
* @param {String} value
*/
acceptInput(pin) {
setInput(pin, value) {
pin.entity.DefaultValue = this.getInput(pin)
pin.querySelector(".ueb-pin-input-content")
// @ts-expect-error
.innerText = Utility.decodeInputString(value)
}
/**
@@ -84,9 +89,7 @@ export default class IInputPinTemplate extends PinTemplate {
if (pin.isInput()) {
return html`
<div class="ueb-pin-input">
<div class="ueb-pin-input-content" role="textbox" contenteditable="true">
${Utility.decodeInputString(sanitizeText(pin.entity.getDefaultValue()))}
</div>
<div class="ueb-pin-input-content" role="textbox" contenteditable="true"></div>
</div>
`
}

View File

@@ -36,7 +36,7 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
</div>
${node.entity.EnabledState.toString() == "DevelopmentOnly" ? html`
<div class="ueb-node-developmentonly">Development Only</div>
` : ""}
` : ""}
${node.entity.AdvancedPinDisplay ? html`
<div class="ueb-node-expansion">
<svg
@@ -48,7 +48,6 @@ export default class NodeTemplate extends SelectableDraggableTemplate {
viewBox="4 4 24 24"
>
<path
fill-rule="evenodd"
d="
M 16.003 18.626
l 7.081 -7.081

View File

@@ -1,5 +1,6 @@
// @ts-check
import Utility from "../Utility"
import IInputPinTemplate from "./IInputPinTemplate"
/**
@@ -8,14 +9,16 @@ import IInputPinTemplate from "./IInputPinTemplate"
export default class RealPinTemplate extends IInputPinTemplate {
/**
* @param {PinElement} pin
* @param {String} value
*/
acceptInput(pin) {
const value = parseFloat(this.getInput(pin))
pin.entity.DefaultValue = isNaN(value)
? pin.entity.AutogeneratedDefaultValue
: value.toString()
setInput(pin, value) {
let num = parseFloat(this.getInput(pin))
if (isNaN(num)) {
num = parseFloat(pin.entity.AutogeneratedDefaultValue)
}
value = Utility.minDecimals(num)
super.setInput(pin, value)
}
}