diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index 09acc21..fad0149 100755 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -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); diff --git a/js/Utility.js b/js/Utility.js index c0e1194..2a72ea7 100755 --- a/js/Utility.js +++ b/js/Utility.js @@ -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 + } } diff --git a/js/template/StringPinTemplate.js b/js/template/StringPinTemplate.js index db0e0c9..2761166 100644 --- a/js/template/StringPinTemplate.js +++ b/js/template/StringPinTemplate.js @@ -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)