@superleapai/flow-ui 2.5.10 → 2.5.11

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.
@@ -346,20 +346,20 @@
346
346
 
347
347
  var optionsList = document.createElement("div");
348
348
  optionsList.className = "overflow-y-auto max-h-[45vh] p-2 w-full rounded-4 bg-fill-quarternary-fill-white record-multiselect-options";
349
-
350
- // Add scroll listener for infinite scroll
351
- optionsList.addEventListener("scroll", function () {
352
- if (isFetchingMore || !hasMoreRecords) return;
353
- var scrollHeight = optionsList.scrollHeight;
354
- var scrollTop = optionsList.scrollTop;
355
- var clientHeight = optionsList.clientHeight;
356
-
357
- // Trigger load more when scrolled to bottom (with 50px threshold)
358
- if (scrollTop + clientHeight >= scrollHeight - 50) {
359
- loadMoreRecords();
360
- }
361
- });
362
-
349
+
350
+ var loadMoreSentinel = null;
351
+ var loadMoreObserver =
352
+ typeof IntersectionObserver !== "undefined"
353
+ ? new IntersectionObserver(
354
+ function (entries) {
355
+ if (!entries.length || !entries[0].isIntersecting) return;
356
+ if (isFetchingMore || !hasMoreRecords) return;
357
+ loadMoreRecords();
358
+ },
359
+ { root: optionsList, rootMargin: "50px", threshold: 0 },
360
+ )
361
+ : null;
362
+
363
363
  content.appendChild(optionsList);
364
364
 
365
365
  var Popover = getDep("Popover");
@@ -619,11 +619,17 @@
619
619
  opt.remove();
620
620
  });
621
621
 
622
- var oldStates = optionsList.querySelectorAll(".record-multiselect-loading, .record-multiselect-empty");
622
+ if (loadMoreSentinel && loadMoreObserver) {
623
+ loadMoreObserver.unobserve(loadMoreSentinel);
624
+ loadMoreSentinel = null;
625
+ }
626
+ var oldStates = optionsList.querySelectorAll(
627
+ ".record-multiselect-loading, .record-multiselect-empty, .record-multiselect-sentinel",
628
+ );
623
629
  oldStates.forEach(function (el) {
624
630
  el.remove();
625
631
  });
626
-
632
+
627
633
  filteredRecords.forEach(function (rec) {
628
634
  var recordId = rec.id || rec.value;
629
635
  var recordLabel = rec.name || rec.label || rec.value;
@@ -738,6 +744,15 @@
738
744
 
739
745
  if (isFetchingMore) {
740
746
  showLoadingMore();
747
+ } else if (hasMoreRecords && filteredRecords.length > 0 && loadMoreObserver) {
748
+ // Sentinel: when visible (short list or user scrolled to bottom), load more automatically
749
+ var sentinel = document.createElement("div");
750
+ sentinel.className = "record-multiselect-sentinel";
751
+ sentinel.setAttribute("aria-hidden", "true");
752
+ sentinel.style.cssText = "height:1px;visibility:hidden;pointer-events:none;";
753
+ optionsList.appendChild(sentinel);
754
+ loadMoreSentinel = sentinel;
755
+ loadMoreObserver.observe(sentinel);
741
756
  }
742
757
  }
743
758
 
@@ -345,18 +345,18 @@
345
345
  optionsList.className =
346
346
  "overflow-y-auto max-h-[45vh] p-2 w-full rounded-4 bg-fill-quarternary-fill-white record-select-options";
347
347
 
348
- // Add scroll listener for infinite scroll
349
- optionsList.addEventListener("scroll", function () {
350
- if (isFetchingMore || !hasMoreRecords) return;
351
- var scrollHeight = optionsList.scrollHeight;
352
- var scrollTop = optionsList.scrollTop;
353
- var clientHeight = optionsList.clientHeight;
354
-
355
- // Trigger load more when scrolled to bottom (with 50px threshold)
356
- if (scrollTop + clientHeight >= scrollHeight - 50) {
357
- loadMoreRecords();
358
- }
359
- });
348
+ var loadMoreSentinel = null;
349
+ var loadMoreObserver =
350
+ typeof IntersectionObserver !== "undefined"
351
+ ? new IntersectionObserver(
352
+ function (entries) {
353
+ if (!entries.length || !entries[0].isIntersecting) return;
354
+ if (isFetchingMore || !hasMoreRecords) return;
355
+ loadMoreRecords();
356
+ },
357
+ { root: optionsList, rootMargin: "50px", threshold: 0 },
358
+ )
359
+ : null;
360
360
 
361
361
  content.appendChild(optionsList);
362
362
 
@@ -694,9 +694,13 @@
694
694
  opt.remove();
695
695
  });
696
696
 
697
- // Remove old loading/empty states
697
+ // Remove old loading/empty states and sentinel (unobserve first)
698
+ if (loadMoreSentinel && loadMoreObserver) {
699
+ loadMoreObserver.unobserve(loadMoreSentinel);
700
+ loadMoreSentinel = null;
701
+ }
698
702
  var oldStates = optionsList.querySelectorAll(
699
- ".record-select-loading, .record-select-empty",
703
+ ".record-select-loading, .record-select-empty, .record-select-sentinel",
700
704
  );
701
705
  oldStates.forEach(function (el) {
702
706
  el.remove();
@@ -778,6 +782,15 @@
778
782
  // Add loading more indicator at the bottom if fetching
779
783
  if (isFetchingMore) {
780
784
  showLoadingMore();
785
+ } else if (hasMoreRecords && filteredRecords.length > 0 && loadMoreObserver) {
786
+ // Sentinel: when visible (short list or user scrolled to bottom), load more automatically
787
+ var sentinel = document.createElement("div");
788
+ sentinel.className = "record-select-sentinel";
789
+ sentinel.setAttribute("aria-hidden", "true");
790
+ sentinel.style.cssText = "height:1px;visibility:hidden;pointer-events:none;";
791
+ optionsList.appendChild(sentinel);
792
+ loadMoreSentinel = sentinel;
793
+ loadMoreObserver.observe(sentinel);
781
794
  }
782
795
  }
783
796