aktion-runtime 0.5.6 → 0.5.7

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.
package/dist/testing.js CHANGED
@@ -19578,7 +19578,7 @@ function syncFormState(oldEl, newEl) {
19578
19578
  return;
19579
19579
  }
19580
19580
  if (oldEl instanceof HTMLSelectElement && newEl instanceof HTMLSelectElement) {
19581
- if (!isFocused(oldEl) && oldEl.value !== newEl.value) {
19581
+ if (oldEl.value !== newEl.value) {
19582
19582
  oldEl.value = newEl.value;
19583
19583
  }
19584
19584
  return;
@@ -19587,20 +19587,43 @@ function syncFormState(oldEl, newEl) {
19587
19587
  function syncInput(oldEl, newEl) {
19588
19588
  if (oldEl.type === "checkbox" || oldEl.type === "radio") {
19589
19589
  const desired2 = newEl.hasAttribute("checked") || newEl.checked;
19590
- if (oldEl.checked !== desired2 && !isFocused(oldEl)) {
19590
+ if (oldEl.checked !== desired2) {
19591
19591
  oldEl.checked = desired2;
19592
19592
  }
19593
19593
  return;
19594
19594
  }
19595
19595
  const desired = newEl.getAttribute("value") ?? newEl.value ?? "";
19596
- if (!isFocused(oldEl) && oldEl.value !== desired) {
19597
- oldEl.value = desired;
19596
+ if (oldEl.value !== desired) {
19597
+ assignValuePreservingCaret(oldEl, desired);
19598
19598
  }
19599
19599
  }
19600
19600
  function syncTextArea(oldEl, newEl) {
19601
19601
  const desired = newEl.value ?? newEl.textContent ?? "";
19602
- if (!isFocused(oldEl) && oldEl.value !== desired) {
19603
- oldEl.value = desired;
19602
+ if (oldEl.value !== desired) {
19603
+ assignValuePreservingCaret(oldEl, desired);
19604
+ }
19605
+ }
19606
+ function assignValuePreservingCaret(el2, desired) {
19607
+ if (!isFocused(el2)) {
19608
+ el2.value = desired;
19609
+ return;
19610
+ }
19611
+ let start = null;
19612
+ let end = null;
19613
+ try {
19614
+ start = el2.selectionStart;
19615
+ end = el2.selectionEnd;
19616
+ } catch {
19617
+ }
19618
+ const prevLen = el2.value.length;
19619
+ el2.value = desired;
19620
+ if (start == null || end == null) return;
19621
+ const atEnd = start >= prevLen && end >= prevLen;
19622
+ const nextStart = atEnd ? desired.length : Math.min(start, desired.length);
19623
+ const nextEnd = atEnd ? desired.length : Math.min(end, desired.length);
19624
+ try {
19625
+ el2.setSelectionRange(nextStart, nextEnd);
19626
+ } catch {
19604
19627
  }
19605
19628
  }
19606
19629
  function isFocused(el2) {