@streamscloud/kit 0.95.2 → 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, returning whether it
10
- * changed. Dispatches nothing — the caller emits. Call at commit points only: on `input` it would
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('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
82
82
  }
83
83
  /**
84
- * Strips leading / trailing whitespace from a field's current value in place, returning whether it
85
- * changed. Dispatches nothing — the caller emits. Call at commit points only: on `input` it would
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 trimmed = element.value.trim();
90
- if (trimmed === element.value) {
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
  /**
@@ -14,6 +14,8 @@ type Props = {
14
14
  panel?: boolean;
15
15
  /** Keep open on any click inside the content. */
16
16
  keepOpen?: boolean;
17
+ /** Make the trigger fill its parent's box (`width: 100%; height: 100%`) — e.g. a submenu row spanning the menu width. */
18
+ fillContainer?: boolean;
17
19
  on?: {
18
20
  opened?: () => void;
19
21
  closed?: () => void;
@@ -364,7 +364,7 @@ Props for keeping the popover open during interaction:
364
364
  border-radius: inherit;
365
365
  }
366
366
  .popover__anchor {
367
- display: flex;
367
+ display: grid;
368
368
  width: 100%;
369
369
  }
370
370
  .popover--disabled {
@@ -29,6 +29,7 @@ type Props = {
29
29
  * A snippet is the content of the trigger `<button>`, so non-interactive only — `Button type="presentational"` for a button look.
30
30
  * `{ custom }` replaces the button with the consumer's own control: its clicks toggle the popover, and its `id`, `disabled`, `aria-expanded`
31
31
  * and `aria-haspopup` are the consumer's (`on.opened` / `on.closed` report the state). `id`, `tabbable` and the aria props here are not applied to it.
32
+ * The control stretches to the trigger's box, so with `fillContainer` or `--sc-kit--popover--width` it fills that width.
32
33
  * @default chevron-down icon
33
34
  */
34
35
  trigger?: Snippet | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.95.2",
3
+ "version": "0.95.4",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",