mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-03-17 05:47:34 +08:00
Show at least one decimal digit
This commit is contained in:
45
dist/ueblueprint.js
vendored
45
dist/ueblueprint.js
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user