@streamscloud/kit 0.95.3 → 0.95.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,9 +6,9 @@ export declare class HtmlHelper {
|
|
|
6
6
|
*/
|
|
7
7
|
static escapeSpecialChars(s: string): string;
|
|
8
8
|
/**
|
|
9
|
-
* Strips leading / trailing whitespace from a field's current value in place,
|
|
10
|
-
* changed. Dispatches nothing — the caller emits. Call at
|
|
11
|
-
* swallow the space in "hello world" as it is typed.
|
|
9
|
+
* Strips leading / trailing whitespace from a field's current value in place, keeping the selection on
|
|
10
|
+
* the same characters, and returns whether it changed. Dispatches nothing — the caller emits. Call at
|
|
11
|
+
* commit points only: on `input` it would swallow the space in "hello world" as it is typed.
|
|
12
12
|
*/
|
|
13
13
|
static trimElementValue(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
14
14
|
/**
|
|
@@ -81,16 +81,24 @@ export class HtmlHelper {
|
|
|
81
81
|
return s.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Strips leading / trailing whitespace from a field's current value in place,
|
|
85
|
-
* changed. Dispatches nothing — the caller emits. Call at
|
|
86
|
-
* swallow the space in "hello world" as it is typed.
|
|
84
|
+
* Strips leading / trailing whitespace from a field's current value in place, keeping the selection on
|
|
85
|
+
* the same characters, and returns whether it changed. Dispatches nothing — the caller emits. Call at
|
|
86
|
+
* commit points only: on `input` it would swallow the space in "hello world" as it is typed.
|
|
87
87
|
*/
|
|
88
88
|
static trimElementValue(element) {
|
|
89
|
-
const
|
|
90
|
-
|
|
89
|
+
const value = element.value;
|
|
90
|
+
const trimmed = value.trim();
|
|
91
|
+
if (trimmed === value) {
|
|
91
92
|
return false;
|
|
92
93
|
}
|
|
94
|
+
const { selectionStart, selectionEnd, selectionDirection } = element;
|
|
93
95
|
element.value = trimmed;
|
|
96
|
+
if (selectionStart !== null && selectionEnd !== null) {
|
|
97
|
+
const removedFromStart = value.length - value.trimStart().length;
|
|
98
|
+
const toTrimmedPosition = (position) => Math.min(Math.max(position - removedFromStart, 0), trimmed.length);
|
|
99
|
+
// Not limited to the focused field: trimming runs on blur, and a caller inserting at the caret afterwards reads this selection.
|
|
100
|
+
element.setSelectionRange(toTrimmedPosition(selectionStart), toTrimmedPosition(selectionEnd), selectionDirection ?? undefined);
|
|
101
|
+
}
|
|
94
102
|
return true;
|
|
95
103
|
}
|
|
96
104
|
/**
|