Update default value for string input

This commit is contained in:
barsdeveloper
2022-04-23 00:31:01 +02:00
parent 1a282b6c8c
commit 7f1a1b13d4
3 changed files with 41 additions and 0 deletions

20
dist/ueblueprint.js vendored
View File

@@ -390,6 +390,16 @@ class Utility {
}
return [...(new Set(result.concat(...a, ...b)))]
}
/**
* @param {String} value
*/
static sanitizeInputString(value) {
return value
.replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol
.replaceAll("\n", "\\r\\n") // Replace newline with \r\n
}
}
// @ts-check
@@ -2859,6 +2869,15 @@ class StringPinTemplate extends PinTemplate {
return true
}
/**
* @param {PinElement} pin
*/
getInput(pin) {
return Utility.sanitizeInputString(
/** @type {HTMLElement} */(pin.querySelector(".ueb-pin-input-content")).innerText
)
}
/**
* @param {PinElement} pin
*/
@@ -2885,6 +2904,7 @@ class StringPinTemplate extends PinTemplate {
this.onFocusOutHandler = (e) => {
e.preventDefault();
document.getSelection().removeAllRanges(); // Deselect text inside the input
pin.entity.DefaultValue = this.getInput(pin);
pin.blueprint.dispatchEditTextEvent(false);
};
this.input.addEventListener("focus", this.onFocusHandler);

View File

@@ -139,4 +139,14 @@ export default class Utility {
}
return [...(new Set(result.concat(...a, ...b)))]
}
/**
* @param {String} value
*/
static sanitizeInputString(value) {
return value
.replace(/\n$/, "") // Remove trailing newline
.replaceAll("\u00A0", " ") // Replace special space symbol
.replaceAll("\n", "\\r\\n") // Replace newline with \r\n
}
}

View File

@@ -3,6 +3,7 @@
import html from "./html"
import MouseIgnore from "../input/mouse/MouseIgnore"
import PinTemplate from "./PinTemplate"
import Utility from "../Utility"
/**
* @typedef {import("../element/PinElement").default} PinElement
@@ -17,6 +18,15 @@ export default class StringPinTemplate extends PinTemplate {
return true
}
/**
* @param {PinElement} pin
*/
getInput(pin) {
return Utility.sanitizeInputString(
/** @type {HTMLElement} */(pin.querySelector(".ueb-pin-input-content")).innerText
)
}
/**
* @param {PinElement} pin
*/
@@ -43,6 +53,7 @@ export default class StringPinTemplate extends PinTemplate {
this.onFocusOutHandler = (e) => {
e.preventDefault()
document.getSelection().removeAllRanges() // Deselect text inside the input
pin.entity.DefaultValue = this.getInput(pin)
pin.blueprint.dispatchEditTextEvent(false)
}
this.input.addEventListener("focus", this.onFocusHandler)