selection-model.d-C_vvNGP-.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { Subject } from 'rxjs';
  2. /**
  3. * Class to be used to power selecting one or more options from a list.
  4. */
  5. declare class SelectionModel<T> {
  6. private _multiple;
  7. private _emitChanges;
  8. compareWith?: ((o1: T, o2: T) => boolean) | undefined;
  9. /** Currently-selected values. */
  10. private _selection;
  11. /** Keeps track of the deselected options that haven't been emitted by the change event. */
  12. private _deselectedToEmit;
  13. /** Keeps track of the selected options that haven't been emitted by the change event. */
  14. private _selectedToEmit;
  15. /** Cache for the array value of the selected items. */
  16. private _selected;
  17. /** Selected values. */
  18. get selected(): T[];
  19. /** Event emitted when the value has changed. */
  20. readonly changed: Subject<SelectionChange<T>>;
  21. constructor(_multiple?: boolean, initiallySelectedValues?: T[], _emitChanges?: boolean, compareWith?: ((o1: T, o2: T) => boolean) | undefined);
  22. /**
  23. * Selects a value or an array of values.
  24. * @param values The values to select
  25. * @return Whether the selection changed as a result of this call
  26. * @breaking-change 16.0.0 make return type boolean
  27. */
  28. select(...values: T[]): boolean | void;
  29. /**
  30. * Deselects a value or an array of values.
  31. * @param values The values to deselect
  32. * @return Whether the selection changed as a result of this call
  33. * @breaking-change 16.0.0 make return type boolean
  34. */
  35. deselect(...values: T[]): boolean | void;
  36. /**
  37. * Sets the selected values
  38. * @param values The new selected values
  39. * @return Whether the selection changed as a result of this call
  40. * @breaking-change 16.0.0 make return type boolean
  41. */
  42. setSelection(...values: T[]): boolean | void;
  43. /**
  44. * Toggles a value between selected and deselected.
  45. * @param value The value to toggle
  46. * @return Whether the selection changed as a result of this call
  47. * @breaking-change 16.0.0 make return type boolean
  48. */
  49. toggle(value: T): boolean | void;
  50. /**
  51. * Clears all of the selected values.
  52. * @param flushEvent Whether to flush the changes in an event.
  53. * If false, the changes to the selection will be flushed along with the next event.
  54. * @return Whether the selection changed as a result of this call
  55. * @breaking-change 16.0.0 make return type boolean
  56. */
  57. clear(flushEvent?: boolean): boolean | void;
  58. /**
  59. * Determines whether a value is selected.
  60. */
  61. isSelected(value: T): boolean;
  62. /**
  63. * Determines whether the model does not have a value.
  64. */
  65. isEmpty(): boolean;
  66. /**
  67. * Determines whether the model has a value.
  68. */
  69. hasValue(): boolean;
  70. /**
  71. * Sorts the selected values based on a predicate function.
  72. */
  73. sort(predicate?: (a: T, b: T) => number): void;
  74. /**
  75. * Gets whether multiple values can be selected.
  76. */
  77. isMultipleSelection(): boolean;
  78. /** Emits a change event and clears the records of selected and deselected values. */
  79. private _emitChangeEvent;
  80. /** Selects a value. */
  81. private _markSelected;
  82. /** Deselects a value. */
  83. private _unmarkSelected;
  84. /** Clears out the selected values. */
  85. private _unmarkAll;
  86. /**
  87. * Verifies the value assignment and throws an error if the specified value array is
  88. * including multiple values while the selection model is not supporting multiple values.
  89. */
  90. private _verifyValueAssignment;
  91. /** Whether there are queued up change to be emitted. */
  92. private _hasQueuedChanges;
  93. /** Returns a value that is comparable to inputValue by applying compareWith function, returns the same inputValue otherwise. */
  94. private _getConcreteValue;
  95. }
  96. /**
  97. * Event emitted when the value of a MatSelectionModel has changed.
  98. * @docs-private
  99. */
  100. interface SelectionChange<T> {
  101. /** Model that dispatched the event. */
  102. source: SelectionModel<T>;
  103. /** Options that were added to the model. */
  104. added: T[];
  105. /** Options that were removed from the model. */
  106. removed: T[];
  107. }
  108. /**
  109. * Returns an error that reports that multiple values are passed into a selection model
  110. * with a single value.
  111. * @docs-private
  112. */
  113. declare function getMultipleValuesInSingleSelectionError(): Error;
  114. export { SelectionModel as S, getMultipleValuesInSingleSelectionError as g };
  115. export type { SelectionChange as a };