arengibook 3.1.314-main → 3.1.315-main

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.
Files changed (2) hide show
  1. package/dist/index.js +77 -44
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37178,8 +37178,15 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37178
37178
  loading = _useState20[0],
37179
37179
  setLoading = _useState20[1];
37180
37180
  var loadLazyTimeout = useRef();
37181
- useRef(1);
37182
- useRef('');
37181
+ var currentPageRef = useRef(1);
37182
+ var hasMoreRef = useRef(true);
37183
+ var isLoadingRef = useRef(false);
37184
+ var searchTermRef = useRef('');
37185
+ var loadedOptionsRef = useRef([]);
37186
+ var updateLoadedOptions = function updateLoadedOptions(opts) {
37187
+ loadedOptionsRef.current = opts;
37188
+ setLoadedOptions(opts);
37189
+ };
37183
37190
  var inverseColor = function inverseColor(hexColor) {
37184
37191
  var r = parseInt(hexColor.substr(1, 2), 16);
37185
37192
  var g = parseInt(hexColor.substr(3, 2), 16);
@@ -37404,6 +37411,7 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37404
37411
  _context.n = 3;
37405
37412
  break;
37406
37413
  }
37414
+ hasMoreRef.current = false;
37407
37415
  return _context.a(2, {
37408
37416
  options: [],
37409
37417
  hasMore: false
@@ -37460,9 +37468,12 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37460
37468
  }, [optionSelected]);
37461
37469
  useEffect(function () {
37462
37470
  setOptionSelected(objValue ? objValue === null || objValue === void 0 ? void 0 : objValue[optionValue] : value !== null && value !== void 0 ? value : null);
37471
+ currentPageRef.current = 1;
37472
+ hasMoreRef.current = true;
37473
+ isLoadingRef.current = false;
37463
37474
  var loadInitialOptions = /*#__PURE__*/function () {
37464
37475
  var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
37465
- var result, _result$options, exists;
37476
+ var result, initialOpts, exists;
37466
37477
  return _regenerator().w(function (_context2) {
37467
37478
  while (1) switch (_context2.n) {
37468
37479
  case 0:
@@ -37472,16 +37483,15 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37472
37483
  });
37473
37484
  case 1:
37474
37485
  result = _context2.v;
37475
- setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37486
+ hasMoreRef.current = (result === null || result === void 0 ? void 0 : result.hasMore) !== false;
37487
+ initialOpts = (result === null || result === void 0 ? void 0 : result.options) || [];
37476
37488
  if (objValue) {
37477
- exists = result === null || result === void 0 || (_result$options = result.options) === null || _result$options === void 0 ? void 0 : _result$options.some(function (opt) {
37489
+ exists = initialOpts.some(function (opt) {
37478
37490
  return opt[optionValue] === objValue[optionValue];
37479
37491
  });
37480
- if (!exists) {
37481
- setLoadedOptions(function (prev) {
37482
- return [].concat(_toConsumableArray$a(prev), [objValue]);
37483
- });
37484
- }
37492
+ updateLoadedOptions(exists ? initialOpts : [].concat(_toConsumableArray$a(initialOpts), [objValue]));
37493
+ } else {
37494
+ updateLoadedOptions(initialOpts);
37485
37495
  }
37486
37496
  case 2:
37487
37497
  return _context2.a(2);
@@ -37572,21 +37582,30 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37572
37582
  } else if (typeof onChange === 'string' && typeof window[onChange] === 'function') {
37573
37583
  window[onChange](null);
37574
37584
  }
37585
+ searchTermRef.current = '';
37586
+ currentPageRef.current = 1;
37587
+ hasMoreRef.current = true;
37588
+ isLoadingRef.current = false;
37575
37589
  loadOptions('', [], {
37576
37590
  page: 1
37577
37591
  }).then(function (result) {
37578
- setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37592
+ hasMoreRef.current = (result === null || result === void 0 ? void 0 : result.hasMore) !== false;
37593
+ updateLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37579
37594
  });
37580
37595
  };
37581
37596
  var handleInputChange = /*#__PURE__*/function () {
37582
37597
  var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e) {
37583
- var search, result, _result$options2, _result, filteredOptions;
37598
+ var search, result, _result$options, _result, filteredOptions;
37584
37599
  return _regenerator().w(function (_context3) {
37585
37600
  while (1) switch (_context3.n) {
37586
37601
  case 0:
37587
37602
  search = e.target.value;
37588
37603
  setInputValue(search);
37589
37604
  if (typeof onSearch === 'function') onSearch(search);
37605
+ searchTermRef.current = search;
37606
+ currentPageRef.current = 1;
37607
+ hasMoreRef.current = true;
37608
+ isLoadingRef.current = false;
37590
37609
  if (search) {
37591
37610
  _context3.n = 2;
37592
37611
  break;
@@ -37597,7 +37616,8 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37597
37616
  });
37598
37617
  case 1:
37599
37618
  result = _context3.v;
37600
- setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37619
+ hasMoreRef.current = (result === null || result === void 0 ? void 0 : result.hasMore) !== false;
37620
+ updateLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37601
37621
  _context3.n = 4;
37602
37622
  break;
37603
37623
  case 2:
@@ -37607,10 +37627,11 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37607
37627
  });
37608
37628
  case 3:
37609
37629
  _result = _context3.v;
37610
- filteredOptions = (_result === null || _result === void 0 || (_result$options2 = _result.options) === null || _result$options2 === void 0 ? void 0 : _result$options2.filter(function (opt) {
37630
+ hasMoreRef.current = (_result === null || _result === void 0 ? void 0 : _result.hasMore) !== false;
37631
+ filteredOptions = (_result === null || _result === void 0 || (_result$options = _result.options) === null || _result$options === void 0 ? void 0 : _result$options.filter(function (opt) {
37611
37632
  return opt[optionLabel].toLowerCase().includes(search.toLowerCase());
37612
37633
  })) || [];
37613
- setLoadedOptions(filteredOptions);
37634
+ updateLoadedOptions(filteredOptions);
37614
37635
  case 4:
37615
37636
  return _context3.a(2);
37616
37637
  }
@@ -37684,38 +37705,50 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37684
37705
  }, truncateLabel(selectedOption[optionLabel]));
37685
37706
  };
37686
37707
 
37687
- // 🔹 Fonction de lazy loading (simulation d’un backend)
37708
+ // 🔹 Lazy loading paginé au scroll (même logique que MultiSelectMetaAsync)
37688
37709
  var onLazyLoad = function onLazyLoad(event) {
37689
37710
  setLoading(true);
37690
- if (loadLazyTimeout.current) {
37691
- clearTimeout(loadLazyTimeout.current);
37692
- }
37693
- loadLazyTimeout.current = setTimeout(function () {
37694
- var first = event.first,
37695
- last = event.last;
37696
- var _items = _toConsumableArray$a(loadedOptions);
37697
- for (var i = first; i < last; i++) {
37698
- if (!_items[i]) {
37699
- _items[i] = _defineProperty$g(_defineProperty$g({}, optionLabel, "Option #".concat(i)), optionValue, i);
37700
- }
37701
- }
37702
- setLoadedOptions(_items);
37703
- setLoading(false);
37704
- var virtualscroll1 = document.querySelector('.p-virtualscroller.p-dropdown-items-wrapper');
37705
- if (virtualscroll1) {
37706
- virtualscroll1.style.height = "auto";
37707
- }
37708
- var hiddenSelectDiv = document.querySelector('.p-hidden-accessible.p-dropdown-hidden-select');
37709
- if (hiddenSelectDiv) {
37710
- var nextEl = hiddenSelectDiv.nextElementSibling;
37711
- if (nextEl && nextEl.tagName === 'INPUT' && nextEl.value && nextEl.value.trim() !== '') {
37712
- var virtualscroll = document.querySelector('.p-virtualscroller.p-dropdown-items-wrapper');
37713
- if (virtualscroll) {
37714
- virtualscroll.style.height = 'auto';
37715
- }
37711
+ if (event.last < loadedOptionsRef.current.length - 1 || !hasMoreRef.current) {
37712
+ setTimeout(function () {
37713
+ return setLoading(false);
37714
+ }, 0);
37715
+ return;
37716
+ }
37717
+ if (isLoadingRef.current) return;
37718
+ isLoadingRef.current = true;
37719
+ if (loadLazyTimeout.current) clearTimeout(loadLazyTimeout.current);
37720
+ loadLazyTimeout.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
37721
+ var nextPage, result, newOptions;
37722
+ return _regenerator().w(function (_context4) {
37723
+ while (1) switch (_context4.n) {
37724
+ case 0:
37725
+ nextPage = currentPageRef.current + 1;
37726
+ _context4.n = 1;
37727
+ return loadOptions(searchTermRef.current, [], {
37728
+ page: nextPage
37729
+ });
37730
+ case 1:
37731
+ result = _context4.v;
37732
+ newOptions = (result === null || result === void 0 ? void 0 : result.options) || [];
37733
+ if (!(newOptions.length === 0)) {
37734
+ _context4.n = 2;
37735
+ break;
37736
+ }
37737
+ hasMoreRef.current = false;
37738
+ isLoadingRef.current = false;
37739
+ setLoading(false);
37740
+ return _context4.a(2);
37741
+ case 2:
37742
+ updateLoadedOptions([].concat(_toConsumableArray$a(loadedOptionsRef.current), _toConsumableArray$a(newOptions)));
37743
+ hasMoreRef.current = (result === null || result === void 0 ? void 0 : result.hasMore) !== false;
37744
+ currentPageRef.current = nextPage;
37745
+ isLoadingRef.current = false;
37746
+ setLoading(false);
37747
+ case 3:
37748
+ return _context4.a(2);
37716
37749
  }
37717
- }
37718
- }, Math.random() * 1000 + 250);
37750
+ }, _callee4);
37751
+ })), 500);
37719
37752
  };
37720
37753
  useEffect(function () {
37721
37754
  var handleAnyClick = function handleAnyClick(e) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arengibook",
3
3
  "private": false,
4
- "version": "3.1.314-main",
4
+ "version": "3.1.315-main",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {