<commit_before>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:angular_components/annotations/rtl_annotation.dart';
import 'package:angular_components/content/deferred_content.dart';
import 'package:angular_components/content/deferred_content_aware.dart';
import 'package:angular_components/dynamic_component/dynamic_component.dart';
import 'package:angular_components/focus/keyboard_only_focus_indicator.dart';
import 'package:angular_components/laminate/enums/alignment.dart';
import 'package:angular_components/laminate/popup/popup.dart';
import 'package:angular_components/material_list/material_list.dart';
import 'package:angular_components/material_popup/material_popup.dart';
import 'package:angular_components/material_select/activation_handler.dart';
import 'package:angular_components/material_select/dropdown_button.dart';
import 'package:angular_components/material_select/material_select_base.dart';
import 'package:angular_components/material_select/material_select_dropdown_item.dart';
import 'package:angular_components/material_select/shift_click_selection.dart';
import 'package:angular_components/mixins/button_wrapper.dart';
import 'package:angular_components/mixins/material_dropdown_base.dart';
import 'package:angular_components/mixins/track_layout_changes.dart';
import 'package:angular_components/model/a11y/active_item.dart';
import 'package:angular_components/model/a11y/keyboard_handler_mixin.dart';
import 'package:angular_components/model/selection/select.dart';
import 'package:angular_components/model/selection/selection_container.dart';
import 'package:angular_components/model/selection/selection_model.dart';
import 'package:angular_components/model/selection/selection_options.dart';
import 'package:angular_components/model/ui/has_factory.dart';
import 'package:angular_components/model/ui/template_support.dart';
import 'package:angular_components/utils/angular/css/css.dart';
import 'package:angular_components/utils/id_generator/id_generator.dart';

/// Material Dropdown Select is a button-triggered dropdown.
///
/// The `material-dropdown-select` component combines the APIs of
/// `material-select`, and `material-button-dropdown`.
///
/// When used with a single selection model, the dropdown closes upon selection.
/// When using a multi-selection model, the user must close the dropdown by
/// clicking outside of it.
///
/// Selection options may be declared manually by passing `material-select-item`
/// elements. When using the declarative API, the `SelectionModel` and
/// `SelectionOptions` are not injected, so marking the item as selected is not
/// automatic.
///
/// If an `OptionGroup` is empty and has an `emptyLabel` defined, the dropdown
/// will include it with the other groups. If `emptyLabel` is not defined for
/// an empty group it will not appear in the list.
///
/// Supports async suggestions through the [ObserveAware] interface implemented
/// by [SelectionOptions].
///
/// The material-select has a fixed max height and auto overflow. We can add a
/// property for custom max height once there's a use case.
///
/// __Example usage:__
///
///     <material-dropdown-select
///       [buttonText]="buttonText"
///       [selection]="singleSelectModel"
///       [options]="options"
///       [itemRenderer]="itemRenderer"
///       [preferredPositions]="preferredPositions">
///     </material-dropdown-select>
///
/// __Properties:__
///
/// - `selection: SelectionModel` -- The selection model this component
///   controls.
/// - `options: SelectionOptions` -- The options to use for this selection
///   model.
/// - `componentRenderer: ComponentRenderer` -- Function that returns a
///   component to render the Item. The component must implement RendersValue.
/// - `itemRenderer: ItemRenderer` -- Function to convert an option object to
///   string.
/// - `width: int` -- Width of the dropdown/list, default none, valid values are
///   0-5.
/// - `visible: bool` -- Whether the dropdown is visible.
/// - `buttonText: String` -- Text on trigger button.
/// - `buttonAriaLabel: String` -- Aria label for trigger button.
/// - `ariaActiveDescendant: String` -- The id of the selected item in the
///    dropdown when using content projection.
///  - `showButtonBorder: bool` - Whether to show the bottom border of the
///   dropdown button.
/// - `iconName: String` -- Icon to use on button, `arrow_drop_down` by default.
/// - `icon-label: String` -- Aria label for the button icon.
/// - `disabled: bool` -- Whether the control is disabled.
/// - `icon: Icon` -- `Icon` model instance.
/// - `autoDismiss: bool` -- Whether the popup should close when the document
///   pressed.
/// - `popupMatchInputWidth: bool` -- Whether or not the popup width is at least
///   as wide as the select width.
/// - `preferredPositions: List` -- A manual list of preferred auto-alignments
///   for the dropdown popup.
/// - `slide: String` -- Direction of popup scaling. Valid values are `x`, `y`,
///   or `null`.
/// - `deselectOnActivate: bool` -- Whether to deselect a selected option on
///   click or enter/space key. Single selection model only. Defaults to true.
/// - `deselectLabel: String` -- Adds a select item that deselects the current
///   selection.
/// - `labelRenderer: ComponentRenderer` -- Function that returns a component
///   to be used for rendering group labels.
@Component(
  selector: 'material-dropdown-select',
  providers: const [
    const Provider(DropdownHandle,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(HasRenderer, useExisting: MaterialDropdownSelectComponent),
    const Provider(DeferredContentAware,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(SelectionContainer,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(PopupSizeProvider,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(ActivationHandler,
        useExisting: MaterialDropdownSelectComponent),
  ],
  directives: const [
    DeferredContentDirective,
    DropdownButtonComponent,
    DynamicComponent,
    KeyboardOnlyFocusIndicatorDirective,
    MaterialListComponent,
    MaterialPopupComponent,
    MaterialSelectDropdownItemComponent,
    NgFor,
    NgIf,
    PopupSourceDirective,
  ],
  templateUrl: 'material_dropdown_select.html',
  styleUrls: const ['material_dropdown_select.scss.css'],
  // TODO(google): Change to `Visibility.local` to reduce code size.
  visibility: Visibility.all,
)
class MaterialDropdownSelectComponent extends MaterialSelectBase
    with
        MaterialDropdownBase,
        MaterialButtonWrapper,
        TrackLayoutChangesMixin,
        KeyboardHandlerMixin,
        ActivateItemOnKeyPressMixin,
        ShiftClickSelectionMixin
    implements PopupSizeProvider, OnChanges, OnDestroy {
  /// Function for use by NgFor for optionGroup.
  ///
  /// Avoids recreating the DOM for the optionGroup.
  final Function trackByIndexFn = indexIdentityFn;

  /// Keeps track of the active item.
  final ActiveItemModel activeModel;

  /// The id for the contained material-list.<commit_msg>Remove visibility.all from @Component annotations. This is potentially BREAKING change.<commit_after>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:angular_components/annotations/rtl_annotation.dart';
import 'package:angular_components/content/deferred_content.dart';
import 'package:angular_components/content/deferred_content_aware.dart';
import 'package:angular_components/dynamic_component/dynamic_component.dart';
import 'package:angular_components/focus/keyboard_only_focus_indicator.dart';
import 'package:angular_components/laminate/enums/alignment.dart';
import 'package:angular_components/laminate/popup/popup.dart';
import 'package:angular_components/material_list/material_list.dart';
import 'package:angular_components/material_popup/material_popup.dart';
import 'package:angular_components/material_select/activation_handler.dart';
import 'package:angular_components/material_select/dropdown_button.dart';
import 'package:angular_components/material_select/material_select_base.dart';
import 'package:angular_components/material_select/material_select_dropdown_item.dart';
import 'package:angular_components/material_select/shift_click_selection.dart';
import 'package:angular_components/mixins/button_wrapper.dart';
import 'package:angular_components/mixins/material_dropdown_base.dart';
import 'package:angular_components/mixins/track_layout_changes.dart';
import 'package:angular_components/model/a11y/active_item.dart';
import 'package:angular_components/model/a11y/keyboard_handler_mixin.dart';
import 'package:angular_components/model/selection/select.dart';
import 'package:angular_components/model/selection/selection_container.dart';
import 'package:angular_components/model/selection/selection_model.dart';
import 'package:angular_components/model/selection/selection_options.dart';
import 'package:angular_components/model/ui/has_factory.dart';
import 'package:angular_components/model/ui/template_support.dart';
import 'package:angular_components/utils/angular/css/css.dart';
import 'package:angular_components/utils/id_generator/id_generator.dart';

/// Material Dropdown Select is a button-triggered dropdown.
///
/// The `material-dropdown-select` component combines the APIs of
/// `material-select`, and `material-button-dropdown`.
///
/// When used with a single selection model, the dropdown closes upon selection.
/// When using a multi-selection model, the user must close the dropdown by
/// clicking outside of it.
///
/// Selection options may be declared manually by passing `material-select-item`
/// elements. When using the declarative API, the `SelectionModel` and
/// `SelectionOptions` are not injected, so marking the item as selected is not
/// automatic.
///
/// If an `OptionGroup` is empty and has an `emptyLabel` defined, the dropdown
/// will include it with the other groups. If `emptyLabel` is not defined for
/// an empty group it will not appear in the list.
///
/// Supports async suggestions through the [ObserveAware] interface implemented
/// by [SelectionOptions].
///
/// The material-select has a fixed max height and auto overflow. We can add a
/// property for custom max height once there's a use case.
///
/// __Example usage:__
///
///     <material-dropdown-select
///       [buttonText]="buttonText"
///       [selection]="singleSelectModel"
///       [options]="options"
///       [itemRenderer]="itemRenderer"
///       [preferredPositions]="preferredPositions">
///     </material-dropdown-select>
///
/// __Properties:__
///
/// - `selection: SelectionModel` -- The selection model this component
///   controls.
/// - `options: SelectionOptions` -- The options to use for this selection
///   model.
/// - `componentRenderer: ComponentRenderer` -- Function that returns a
///   component to render the Item. The component must implement RendersValue.
/// - `itemRenderer: ItemRenderer` -- Function to convert an option object to
///   string.
/// - `width: int` -- Width of the dropdown/list, default none, valid values are
///   0-5.
/// - `visible: bool` -- Whether the dropdown is visible.
/// - `buttonText: String` -- Text on trigger button.
/// - `buttonAriaLabel: String` -- Aria label for trigger button.
/// - `ariaActiveDescendant: String` -- The id of the selected item in the
///    dropdown when using content projection.
///  - `showButtonBorder: bool` - Whether to show the bottom border of the
///   dropdown button.
/// - `iconName: String` -- Icon to use on button, `arrow_drop_down` by default.
/// - `icon-label: String` -- Aria label for the button icon.
/// - `disabled: bool` -- Whether the control is disabled.
/// - `icon: Icon` -- `Icon` model instance.
/// - `autoDismiss: bool` -- Whether the popup should close when the document
///   pressed.
/// - `popupMatchInputWidth: bool` -- Whether or not the popup width is at least
///   as wide as the select width.
/// - `preferredPositions: List` -- A manual list of preferred auto-alignments
///   for the dropdown popup.
/// - `slide: String` -- Direction of popup scaling. Valid values are `x`, `y`,
///   or `null`.
/// - `deselectOnActivate: bool` -- Whether to deselect a selected option on
///   click or enter/space key. Single selection model only. Defaults to true.
/// - `deselectLabel: String` -- Adds a select item that deselects the current
///   selection.
/// - `labelRenderer: ComponentRenderer` -- Function that returns a component
///   to be used for rendering group labels.
@Component(
  selector: 'material-dropdown-select',
  providers: const [
    const Provider(DropdownHandle,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(HasRenderer, useExisting: MaterialDropdownSelectComponent),
    const Provider(DeferredContentAware,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(SelectionContainer,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(PopupSizeProvider,
        useExisting: MaterialDropdownSelectComponent),
    const Provider(ActivationHandler,
        useExisting: MaterialDropdownSelectComponent),
  ],
  directives: const [
    DeferredContentDirective,
    DropdownButtonComponent,
    DynamicComponent,
    KeyboardOnlyFocusIndicatorDirective,
    MaterialListComponent,
    MaterialPopupComponent,
    MaterialSelectDropdownItemComponent,
    NgFor,
    NgIf,
    PopupSourceDirective,
  ],
  templateUrl: 'material_dropdown_select.html',
  styleUrls: const ['material_dropdown_select.scss.css'],
  visibility: Visibility.all, // injected by directives
)
class MaterialDropdownSelectComponent extends MaterialSelectBase
    with
        MaterialDropdownBase,
        MaterialButtonWrapper,
        TrackLayoutChangesMixin,
        KeyboardHandlerMixin,
        ActivateItemOnKeyPressMixin,
        ShiftClickSelectionMixin
    implements PopupSizeProvider, OnChanges, OnDestroy {
  /// Function for use by NgFor for optionGroup.
  ///
  /// Avoids recreating the DOM for the optionGroup.
  final Function trackByIndexFn = indexIdentityFn;

  /// Keeps track of the active item.
  final ActiveItemModel activeModel;

  /// The id for the contained material-list.
{'fraction_non_alphanumeric': 0.11020795231321547, 'fraction_numerical': 0.00135473819684346, 'mean_word_length': 4.09103448275862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5556790', 'n_tokens_mistral': 4010, 'n_tokens_neox': 3939, 'n_words': 1177}