@rivet-health/design-system 33.1.2 → 34.0.0

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.
@@ -2001,6 +2001,7 @@ var RivSelect;
2001
2001
  error: null,
2002
2002
  },
2003
2003
  sourceOptionGroups: [],
2004
+ originalOptionGroups: [],
2004
2005
  selection: {
2005
2006
  selected: new OptionSet(),
2006
2007
  },
@@ -2014,7 +2015,7 @@ var RivSelect;
2014
2015
  const actions = new Subject();
2015
2016
  const internalActions = new Subject();
2016
2017
  const coreStateWithSelectionSnapshot = merge(actions, internalActions).pipe(scan(([state, snapshot], action) => {
2017
- const newState = sideEffects(reduce(state, action), action, source, internalActions);
2018
+ const newState = sideEffects(reduce(state, action, options), action, source, internalActions);
2018
2019
  const newSelectionSnapshot = (action.type === 'openChange' && action.open) ||
2019
2020
  (action.type === 'loadComplete' &&
2020
2021
  (newState.display.open || (options === null || options === void 0 ? void 0 : options.inline)))
@@ -2028,7 +2029,7 @@ var RivSelect;
2028
2029
  const state = connectable(coreStateWithSelectionSnapshot.pipe(map(([s, selectionAtOpen]) => {
2029
2030
  var _a, _b, _c, _d, _e, _f;
2030
2031
  const allOptionGroups = s.sourceOptionGroups.map(optionGroup => {
2031
- return Object.assign(Object.assign({}, optionGroup), { options: optionGroup.options.map(option => augmentOptionToFullOption(s, option)) });
2032
+ return Object.assign(Object.assign({}, optionGroup), { options: optionGroup.options.map(option => augmentOptionToFullOption(s, option, options)) });
2032
2033
  });
2033
2034
  const topLevelOptions = getTopLevelOptions(allOptionGroups);
2034
2035
  const sortedOptionGroups = (options === null || options === void 0 ? void 0 : options.allowMultiSelect)
@@ -2227,7 +2228,10 @@ var RivSelect;
2227
2228
  : null)));
2228
2229
  });
2229
2230
  }
2230
- return [{ options: addHighlightsToOption(ordered) }];
2231
+ return {
2232
+ data: [{ options: addHighlightsToOption(ordered) }],
2233
+ originalData: data,
2234
+ };
2231
2235
  });
2232
2236
  return createManager(source, options);
2233
2237
  }
@@ -2358,7 +2362,16 @@ var RivSelect;
2358
2362
  if ((options === null || options === void 0 ? void 0 : options.selectedOptionLimit) === undefined) {
2359
2363
  return optionGroups;
2360
2364
  }
2361
- const selectedOrIndeterminateTopOptions = topLevelOptions.filter(option => option.selected != false);
2365
+ // When useTopLevelOptionsForDisplay is true and search is active, count
2366
+ // selected top-level options from the original (unfiltered) data to ensure
2367
+ // already-selected options that don't match the search are still counted.
2368
+ const useOriginalForCounting = (options === null || options === void 0 ? void 0 : options.useTopLevelOptionsForDisplay) &&
2369
+ state.query.search &&
2370
+ state.originalOptionGroups.length > 0;
2371
+ const topOptionsForCounting = useOriginalForCounting
2372
+ ? getTopLevelOptions(state.originalOptionGroups).map(option => augmentOptionToFullOption(state, option, options))
2373
+ : topLevelOptions;
2374
+ const selectedOrIndeterminateTopOptions = topOptionsForCounting.filter(option => option.selected != false);
2362
2375
  const numSelectedOptions = (options === null || options === void 0 ? void 0 : options.useTopLevelOptionsForDisplay)
2363
2376
  ? selectedOrIndeterminateTopOptions.length
2364
2377
  : state.selection.selected.size;
@@ -2431,13 +2444,43 @@ var RivSelect;
2431
2444
  return false;
2432
2445
  return 'indeterminate';
2433
2446
  }
2434
- function augmentOptionToFullOption(state, option) {
2435
- var _a;
2447
+ function augmentOptionToFullOption(state, option, managerOptions) {
2448
+ var _a, _b;
2436
2449
  if ((_a = option.children) === null || _a === void 0 ? void 0 : _a.length) {
2437
- const augmentedChildren = option.children.map(child => augmentOptionToFullOption(state, child));
2438
- return Object.assign(Object.assign({}, option), { children: augmentedChildren, selected: getParentMultiSelectionState(augmentedChildren), expanded: state.query.search
2450
+ const augmentedChildren = option.children.map(child => augmentOptionToFullOption(state, child, managerOptions));
2451
+ const selectableWhenSearching = (_b = managerOptions === null || managerOptions === void 0 ? void 0 : managerOptions.allowSelectNonLeafDuringSearch) !== null && _b !== void 0 ? _b : false;
2452
+ // When allowSelectNonLeafDuringSearch is enabled and search is active,
2453
+ // calculate selection state from ALL original children, not just the
2454
+ // filtered ones visible in search results.
2455
+ const useOriginalForSelectionState = (managerOptions === null || managerOptions === void 0 ? void 0 : managerOptions.allowSelectNonLeafDuringSearch) &&
2456
+ state.query.search &&
2457
+ state.originalOptionGroups.length > 0;
2458
+ let selected;
2459
+ if (useOriginalForSelectionState) {
2460
+ const originalOption = findOption(getTopLevelOptions(state.originalOptionGroups), option.id);
2461
+ if (originalOption) {
2462
+ const allLeaves = flattenOptions([originalOption], true);
2463
+ const selectedCount = allLeaves.filter(leaf => state.selection.selected.has(leaf)).length;
2464
+ if (selectedCount === 0) {
2465
+ selected = false;
2466
+ }
2467
+ else if (selectedCount === allLeaves.length) {
2468
+ selected = true;
2469
+ }
2470
+ else {
2471
+ selected = 'indeterminate';
2472
+ }
2473
+ }
2474
+ else {
2475
+ selected = getParentMultiSelectionState(augmentedChildren);
2476
+ }
2477
+ }
2478
+ else {
2479
+ selected = getParentMultiSelectionState(augmentedChildren);
2480
+ }
2481
+ return Object.assign(Object.assign({}, option), { children: augmentedChildren, selected, expanded: state.query.search
2439
2482
  ? true
2440
- : state.display.expandedOptions.has(option.id), selectable: !state.query.search, expandable: !state.query.search });
2483
+ : state.display.expandedOptions.has(option.id), selectable: !state.query.search || selectableWhenSearching, expandable: !state.query.search });
2441
2484
  }
2442
2485
  return Object.assign(Object.assign({}, option), { children: undefined, selected: state.selection.selected.has(option), expanded: false, selectable: true, expandable: false });
2443
2486
  }
@@ -2501,14 +2544,24 @@ var RivSelect;
2501
2544
  }
2502
2545
  }));
2503
2546
  }
2504
- function toggleSelected(state, id) {
2547
+ function toggleSelected(state, id, managerOptions) {
2548
+ var _a;
2505
2549
  const topLevelOptions = getTopLevelOptions(state.sourceOptionGroups);
2506
2550
  const option = findOption(topLevelOptions, id);
2507
2551
  if (!option)
2508
2552
  return state;
2509
2553
  const newSelection = new OptionSet(state.selection.selected);
2510
- const newValue = !(augmentOptionToFullOption(state, option).selected === true);
2511
- const leaves = flattenOptions([option], true);
2554
+ const newValue = !(augmentOptionToFullOption(state, option, managerOptions).selected === true);
2555
+ // When allowSelectNonLeafDuringSearch is enabled and search is active,
2556
+ // use the original (unfiltered) data to get all children, not just
2557
+ // those visible in the filtered search results.
2558
+ const useOriginalData = (managerOptions === null || managerOptions === void 0 ? void 0 : managerOptions.allowSelectNonLeafDuringSearch) &&
2559
+ state.query.search &&
2560
+ state.originalOptionGroups.length > 0;
2561
+ const optionForLeaves = useOriginalData
2562
+ ? (_a = findOption(getTopLevelOptions(state.originalOptionGroups), id)) !== null && _a !== void 0 ? _a : option
2563
+ : option;
2564
+ const leaves = flattenOptions([optionForLeaves], true);
2512
2565
  for (const leaf of leaves) {
2513
2566
  if (newValue) {
2514
2567
  newSelection.add(leaf);
@@ -2559,8 +2612,12 @@ var RivSelect;
2559
2612
  action.type === 'orderChange' ||
2560
2613
  (action.type === 'openChange' && action.open)) {
2561
2614
  source(state.query, action)
2562
- .then(data => {
2563
- internalActions.next({ type: 'loadComplete', data });
2615
+ .then(result => {
2616
+ const data = Array.isArray(result) ? result : result.data;
2617
+ const originalData = Array.isArray(result)
2618
+ ? undefined
2619
+ : result.originalData;
2620
+ internalActions.next({ type: 'loadComplete', data, originalData });
2564
2621
  })
2565
2622
  .catch(error => {
2566
2623
  // eslint-disable-next-line no-console
@@ -2574,7 +2631,8 @@ var RivSelect;
2574
2631
  }
2575
2632
  return state;
2576
2633
  }
2577
- function reduce(state, action) {
2634
+ function reduce(state, action, managerOptions) {
2635
+ var _a;
2578
2636
  switch (action.type) {
2579
2637
  case 'load':
2580
2638
  return state;
@@ -2582,7 +2640,7 @@ var RivSelect;
2582
2640
  return Object.assign(Object.assign({}, state), { load: {
2583
2641
  loading: false,
2584
2642
  error: null,
2585
- }, sourceOptionGroups: action.data });
2643
+ }, sourceOptionGroups: action.data, originalOptionGroups: (_a = action.originalData) !== null && _a !== void 0 ? _a : [] });
2586
2644
  case 'loadError':
2587
2645
  return Object.assign(Object.assign({}, state), { load: {
2588
2646
  loading: false,
@@ -2597,7 +2655,7 @@ var RivSelect;
2597
2655
  case 'selectionChange':
2598
2656
  return Object.assign(Object.assign({}, state), { selection: action.payload });
2599
2657
  case 'toggleOptionSelected':
2600
- return toggleSelected(state, action.id);
2658
+ return toggleSelected(state, action.id, managerOptions);
2601
2659
  case 'setSelectedOption':
2602
2660
  return setSelectedOption(state, action.id);
2603
2661
  case 'visibleSelectedChange':