@activecollab/components 1.0.304 → 1.0.305

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/index.js CHANGED
@@ -10377,51 +10377,61 @@
10377
10377
  return [selected];
10378
10378
  }, [selected]);
10379
10379
  var handleSort = React.useCallback(function (opts) {
10380
+ var _opts$;
10380
10381
  if (keepSameOptionsOrder) {
10381
10382
  return opts;
10382
10383
  }
10383
- var selectedIdsSet = new Set(selectedOptions);
10384
- if (opts.every(function (opt) {
10385
- return !opt.options;
10386
- })) {
10387
- var sortedOptions = opts.filter(function (opt) {
10388
- return selectedIdsSet.has(opt.id);
10389
- }).concat(opts.filter(function (opt) {
10390
- return !selectedIdsSet.has(opt.id);
10391
- }));
10392
- var selectedOptionsInOrder = sortedOptions.filter(function (opt) {
10393
- return selectedIdsSet.has(opt.id);
10394
- }).sort(function (a, b) {
10395
- return selectedOptions.indexOf(a.id) - selectedOptions.indexOf(b.id);
10396
- });
10397
- return selectedOptionsInOrder.concat(sortedOptions.filter(function (opt) {
10398
- return !selectedIdsSet.has(opt.id);
10399
- }));
10400
- }
10401
- return opts.map(function (group) {
10402
- var groupSelectedOptions = group.options.filter(function (opt) {
10403
- return selectedIdsSet.has(opt.id);
10404
- });
10405
- var groupUnselectedOptions = group.options.filter(function (opt) {
10406
- return !selectedIdsSet.has(opt.id);
10407
- });
10408
- var selectedOptionsInOrder = groupSelectedOptions.sort(function (a, b) {
10409
- return selectedOptions.indexOf(a.id) - selectedOptions.indexOf(b.id);
10384
+ var isGrouped = Array.isArray((_opts$ = opts[0]) === null || _opts$ === void 0 ? void 0 : _opts$.options);
10385
+ if (isGrouped) {
10386
+ return opts.map(function (group) {
10387
+ var sortedGroupOptions = group.options.sort(function (a, b) {
10388
+ if (selectedOptions.includes(b.id) && !selectedOptions.includes(a.id)) {
10389
+ return 1;
10390
+ }
10391
+ if (selectedOptions.includes(a.id) && !selectedOptions.includes(b.id)) {
10392
+ return -1;
10393
+ }
10394
+ return 0;
10395
+ });
10396
+ return _objectSpread2(_objectSpread2({}, group), {}, {
10397
+ options: sortedGroupOptions
10398
+ });
10410
10399
  });
10411
- var finalOptionsInGroup = selectedOptionsInOrder.concat(groupUnselectedOptions);
10412
- return _objectSpread2(_objectSpread2({}, group), {}, {
10413
- options: finalOptionsInGroup
10400
+ } else {
10401
+ return opts.sort(function (a, b) {
10402
+ if (selectedOptions.includes(b.id) && !selectedOptions.includes(a.id)) {
10403
+ return 1;
10404
+ }
10405
+ if (selectedOptions.includes(a.id) && !selectedOptions.includes(b.id)) {
10406
+ return -1;
10407
+ }
10408
+ return 0;
10414
10409
  });
10415
- });
10410
+ }
10416
10411
  // eslint-disable-next-line react-hooks/exhaustive-deps
10417
10412
  }, []);
10418
10413
  var sortList = React.useCallback(function (options) {
10414
+ var _options$;
10419
10415
  if (disabledInternalSort) {
10420
10416
  return handleSort(_toConsumableArray(options));
10421
10417
  }
10422
- return handleSort(_toConsumableArray(options).sort(function (a, b) {
10423
- return sortDirection === "asc" ? a.name.localeCompare(b.name) : b.name.localeCompare(a.name);
10424
- }));
10418
+ var isGrouped = Array.isArray((_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.options);
10419
+ if (isGrouped) {
10420
+ var sortedOptions = options.map(function (group) {
10421
+ var sortedGroupOptions = group.options.sort(function (a, b) {
10422
+ return sortDirection === "asc" ? a.name.localeCompare(b.name) : b.name.localeCompare(a.name);
10423
+ });
10424
+ return _objectSpread2(_objectSpread2({}, group), {}, {
10425
+ options: handleSort(sortedGroupOptions)
10426
+ });
10427
+ });
10428
+ return handleSort(sortedOptions);
10429
+ } else {
10430
+ var _sortedOptions = options.sort(function (a, b) {
10431
+ return sortDirection === "asc" ? a.name.localeCompare(b.name) : b.name.localeCompare(a.name);
10432
+ });
10433
+ return handleSort(_sortedOptions);
10434
+ }
10425
10435
  }, [sortDirection, disabledInternalSort, handleSort]);
10426
10436
  var sortedList = React.useMemo(function () {
10427
10437
  return sortList(options);