selection.d.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { Subject } from 'rxjs';
  9. /**
  10. * Class to be used to power selecting one or more options from a list.
  11. */
  12. export declare class SelectionModel<T> {
  13. private _multiple;
  14. private _emitChanges;
  15. /** Currently-selected values. */
  16. private _selection;
  17. /** Keeps track of the deselected options that haven't been emitted by the change event. */
  18. private _deselectedToEmit;
  19. /** Keeps track of the selected options that haven't been emitted by the change event. */
  20. private _selectedToEmit;
  21. /** Cache for the array value of the selected items. */
  22. private _selected;
  23. /** Selected values. */
  24. readonly selected: T[];
  25. /** Event emitted when the value has changed. */
  26. changed: Subject<SelectionChange<T>>;
  27. /**
  28. * Event emitted when the value has changed.
  29. * @deprecated Use `changed` instead.
  30. * @breaking-change 8.0.0 To be changed to `changed`
  31. */
  32. onChange: Subject<SelectionChange<T>>;
  33. constructor(_multiple?: boolean, initiallySelectedValues?: T[], _emitChanges?: boolean);
  34. /**
  35. * Selects a value or an array of values.
  36. */
  37. select(...values: T[]): void;
  38. /**
  39. * Deselects a value or an array of values.
  40. */
  41. deselect(...values: T[]): void;
  42. /**
  43. * Toggles a value between selected and deselected.
  44. */
  45. toggle(value: T): void;
  46. /**
  47. * Clears all of the selected values.
  48. */
  49. clear(): void;
  50. /**
  51. * Determines whether a value is selected.
  52. */
  53. isSelected(value: T): boolean;
  54. /**
  55. * Determines whether the model does not have a value.
  56. */
  57. isEmpty(): boolean;
  58. /**
  59. * Determines whether the model has a value.
  60. */
  61. hasValue(): boolean;
  62. /**
  63. * Sorts the selected values based on a predicate function.
  64. */
  65. sort(predicate?: (a: T, b: T) => number): void;
  66. /**
  67. * Gets whether multiple values can be selected.
  68. */
  69. isMultipleSelection(): boolean;
  70. /** Emits a change event and clears the records of selected and deselected values. */
  71. private _emitChangeEvent;
  72. /** Selects a value. */
  73. private _markSelected;
  74. /** Deselects a value. */
  75. private _unmarkSelected;
  76. /** Clears out the selected values. */
  77. private _unmarkAll;
  78. /**
  79. * Verifies the value assignment and throws an error if the specified value array is
  80. * including multiple values while the selection model is not supporting multiple values.
  81. */
  82. private _verifyValueAssignment;
  83. }
  84. /**
  85. * Event emitted when the value of a MatSelectionModel has changed.
  86. * @docs-private
  87. */
  88. export interface SelectionChange<T> {
  89. /** Model that dispatched the event. */
  90. source: SelectionModel<T>;
  91. /** Options that were added to the model. */
  92. added: T[];
  93. /** Options that were removed from the model. */
  94. removed: T[];
  95. }
  96. /**
  97. * Returns an error that reports that multiple values are passed into a selection model
  98. * with a single value.
  99. * @docs-private
  100. */
  101. export declare function getMultipleValuesInSingleSelectionError(): Error;