<commit_before>import {computedFrom, inject, bindable, bindingMode} from "aurelia-framework";
import {Config} from "aurelia-api";
import {logger} from "../aurelia-autocomplete";
import {DOM} from "aurelia-pal";
import {resolvedView} from "aurelia-view-manager";

@resolvedView('spoonx/auto-complete', 'autocomplete')
@inject(Config, DOM.Element)
export class AutoCompleteCustomElement {

  lastFindPromise;

  // the query string is set after selecting an option. To avoid this
  // triggering a new query we set the justSelected to true. When true it will
  // avoid performing a query until it is toggled of.
  justSelected = false;

  // Holds the value last used to perform a search
  previousValue = null;

  // Simple property that maintains if this is the initial (first) request.
  initial = true;

  hasFocus = false;

  // How many characters are required to type before starting a search.
  @bindable minInput = 0;

  // the name of the input element
  @bindable name = '';

  // The max amount of results to return. (optional)
  @bindable limit = 10;

  // Debounce value
  @bindable debounce = 100;

  // The string that is appended to the api endpoint. e.g. api.com/language. language is the resource.
  @bindable resource;

  // Used when one already has a list of items to filter on. Requests is not necessary
  @bindable items;

  // The string to be used to do a contains search with. By default it will look if the name contains this value.
  @bindable({defaultBindingMode: bindingMode.twoWay}) value = '';

  // Can be used to select default element visually
  @bindable selected;

  // The property to query on.
  @bindable attribute = 'name';

  // Used to pass the result of the selected value to the user's view model
  @bindable({defaultBindingMode: bindingMode.twoWay}) result = null;

  // The results returned from the endpoint. These can be observed and mutated.
  @bindable({defaultBindingMode: bindingMode.twoWay}) results = [];

  // Which relations to populate for results
  @bindable populate = null;

  // The label to show in the footer. Gets pulled through aurelia-i18n.
  @bindable footerLabel = 'Create';

  // Callback to call when the footer gets clicked.
  @bindable footerSelected;

  // Never, always or no-results
  @bindable footerVisibility = 'never';

  // Used to determine the string to be shown as option label
  @bindable label = result => {
    return typeof result === 'object' && result !== null ? result[this.attribute] : result;
  };

  // Allow to overwrite the default apiEndpoint
  @bindable endpoint;
   
  // Input field's placeholder
  @bindable placeholder = 'Search';

  // Sort method that takes a list and returns a sorted list. No sorting by default.
  @bindable sort = items => items;

  // Used to make the criteria more specific
  @bindable criteria = {};

  @computedFrom('results', 'value')
  get showFooter() {
    let visibility = this.footerVisibility;

    return visibility === 'always'
      || (visibility === 'no-results' && this.value && this.value.length && (!this.results || !this.results.length));
  }

  /**
   * Autocomplete constructor.
   *
   * @param {Config}  api
   * @param {Element} element
   */
  constructor(api, element) {
    this.element     = element;
    this.apiEndpoint = api;
  }

  /**<commit_msg>style(project): remove trailing spaces<commit_after>import {computedFrom, inject, bindable, bindingMode} from "aurelia-framework";
import {Config} from "aurelia-api";
import {logger} from "../aurelia-autocomplete";
import {DOM} from "aurelia-pal";
import {resolvedView} from "aurelia-view-manager";

@resolvedView('spoonx/auto-complete', 'autocomplete')
@inject(Config, DOM.Element)
export class AutoCompleteCustomElement {

  lastFindPromise;

  // the query string is set after selecting an option. To avoid this
  // triggering a new query we set the justSelected to true. When true it will
  // avoid performing a query until it is toggled of.
  justSelected = false;

  // Holds the value last used to perform a search
  previousValue = null;

  // Simple property that maintains if this is the initial (first) request.
  initial = true;

  hasFocus = false;

  // How many characters are required to type before starting a search.
  @bindable minInput = 0;

  // the name of the input element
  @bindable name = '';

  // The max amount of results to return. (optional)
  @bindable limit = 10;

  // Debounce value
  @bindable debounce = 100;

  // The string that is appended to the api endpoint. e.g. api.com/language. language is the resource.
  @bindable resource;

  // Used when one already has a list of items to filter on. Requests is not necessary
  @bindable items;

  // The string to be used to do a contains search with. By default it will look if the name contains this value.
  @bindable({defaultBindingMode: bindingMode.twoWay}) value = '';

  // Can be used to select default element visually
  @bindable selected;

  // The property to query on.
  @bindable attribute = 'name';

  // Used to pass the result of the selected value to the user's view model
  @bindable({defaultBindingMode: bindingMode.twoWay}) result = null;

  // The results returned from the endpoint. These can be observed and mutated.
  @bindable({defaultBindingMode: bindingMode.twoWay}) results = [];

  // Which relations to populate for results
  @bindable populate = null;

  // The label to show in the footer. Gets pulled through aurelia-i18n.
  @bindable footerLabel = 'Create';

  // Callback to call when the footer gets clicked.
  @bindable footerSelected;

  // Never, always or no-results
  @bindable footerVisibility = 'never';

  // Used to determine the string to be shown as option label
  @bindable label = result => {
    return typeof result === 'object' && result !== null ? result[this.attribute] : result;
  };

  // Allow to overwrite the default apiEndpoint
  @bindable endpoint;

  // Input field's placeholder
  @bindable placeholder = 'Search';

  // Sort method that takes a list and returns a sorted list. No sorting by default.
  @bindable sort = items => items;

  // Used to make the criteria more specific
  @bindable criteria = {};

  @computedFrom('results', 'value')
  get showFooter() {
    let visibility = this.footerVisibility;

    return visibility === 'always'
      || (visibility === 'no-results' && this.value && this.value.length && (!this.results || !this.results.length));
  }

  /**
   * Autocomplete constructor.
   *
   * @param {Config}  api
   * @param {Element} element
   */
  constructor(api, element) {
    this.element     = element;
    this.apiEndpoint = api;
  }

  /**
{'fraction_non_alphanumeric': 0.10241327300150829, 'fraction_numerical': 0.0024132730015082957, 'mean_word_length': 3.3826834104428287, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1529214', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1818, 'n_words': 757}