<commit_before>import isUndefined from 'lodash/isUndefined';
import isBoolean from 'lodash/isBoolean';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
import isPlainObject from 'lodash/isPlainObject';
import isFunction from 'lodash/isFunction';
import isEmpty from 'lodash/isEmpty';

import map from 'lodash/map';
import reduce from 'lodash/reduce';
import filter from 'lodash/filter';

import {
  getRefinements,
  clearRefinementsFromState,
  clearRefinementsAndSearch,
  checkRendering,
} from '../../lib/utils.js';

const usage = `Usage:
var customCurrentRefinedValues = connectCurrentRefinedValues(function renderFn(params, isFirstRendering) {
  // params = {
  //   attributes,
  //   clearAllClick,
  //   clearAllPosition,
  //   clearAllURL,
  //   refine,
  //   createURL,
  //   refinements,
  //   instantSearchInstance,
  //   widgetParams,
  // }
});
search.addWidget(
  customCurrentRefinedValues({
    [ attributes = [] ],
    [ onlyListedAttributes = false ],
    [ clearsQuery = false ]
  })
);
Full documentation available at https://community.algolia.com/instantsearch.js/connectors/connectCurrentRefinedValues.html
`;

/**
 * @typedef {Object} CurrentRefinedValuesRenderingOptions
 * @property {Object.<string, object>} attributes Original `CurrentRefinedValuesWidgetOptions.attributes` mapped by keys.
 * @property {function} clearAllClick Clears all the currently refined values.
 * @property {function} clearAllURL Generate a URL which leads to a state where all the refinements have been cleared.
 * @property {function(item)} refine Clears a single refinement.
 * @property {function(item): string} createURL Creates an individual url where a single refinement is cleared.
 * @property {Object[]} refinements All the current refinements.
 * @property {Object} widgetParams All original `CustomCurrentRefinedValuesWidgetOptions` forwarded to the `renderFn`.
 */

/**
 * @typedef {Object} CurrentRefinedValuesAttributes
 * @property {string} name Mandatory field which is the name of the attribute.
 * @property {string} label The label to apply on a refinement per attribute.
 */

/**
 * @typedef {Object} CustomCurrentRefinedValuesWidgetOptions
 * @property {CurrentRefinedValuesAttributes[]} [attributes = []] Specification for the display of
 * refinements per attribute (default: `[]`). By default, the widget will display all the filters
 * set with no special treatment for the label.
 * @property {boolean} [onlyListedAttributes = false] Limit the displayed refinement to the list specified.
 * @property {boolean} [clearsQuery = false] Clears also the active search query when using clearAll.
 */

/**
 * **CurrentRefinedValues** connector provides the logic to build a widget that will give
 * the user the ability to see all the currently aplied filters and, remove some or all of
 * them.
 *
 * This provides a `refine(item)` function to remove a selected refinement and a `clearAllClick`
 * function to clear all the filters. Those functions can see their behaviour change based on
 * the widget options used.
 * @type {Connector}
 * @param {function(CurrentRefinedValuesRenderingOptions)} renderFn Rendering function for the custom **CurrentRefinedValues** widget.
 * @return {function(CustomCurrentRefinedValuesWidgetOptions)} Re-usable widget factory for a custom **CurrentRefinedValues** widget.
 * @example
 * // custom `renderFn` to render the custom ClearAll widget
 * function renderFn(CurrentRefinedValuesRenderingOptions, isFirstRendering) {
 *   var containerNode = CurrentRefinedValuesRenderingOptions.widgetParams.containerNode;
 *   if (isFirstRendering) {
 *     containerNode
 *       .html('<ul id="refiments"></ul><div id="cta-container"></div>');
 *   }
 *
 *   containerNode
 *     .find('#cta-container > a')
 *     .off('click');
 *
 *   containerNode
 *     .find('li > a')
 *     .each(function() { $(this).off('click') });
 *
 *   if (refinements && refinements.length > 0) {
 *     containerNode
 *       .find('#cta-container')
 *       .html('<a href="' + CurrentRefinedValuesRenderingOptions.clearAllURL + '">Clear all </a>');
 *
 *     containerNode
 *       .find('#cta-container > a')
 *       .on('click', function(event) {
 *         event.preventDefault();
 *         CurrentRefinedValuesRenderingOptions.clearAllClick();
 *       });<commit_msg>doc(connectCurrentRefinedValues): fix live example<commit_after>import isUndefined from 'lodash/isUndefined';
import isBoolean from 'lodash/isBoolean';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
import isPlainObject from 'lodash/isPlainObject';
import isFunction from 'lodash/isFunction';
import isEmpty from 'lodash/isEmpty';

import map from 'lodash/map';
import reduce from 'lodash/reduce';
import filter from 'lodash/filter';

import {
  getRefinements,
  clearRefinementsFromState,
  clearRefinementsAndSearch,
  checkRendering,
} from '../../lib/utils.js';

const usage = `Usage:
var customCurrentRefinedValues = connectCurrentRefinedValues(function renderFn(params, isFirstRendering) {
  // params = {
  //   attributes,
  //   clearAllClick,
  //   clearAllPosition,
  //   clearAllURL,
  //   refine,
  //   createURL,
  //   refinements,
  //   instantSearchInstance,
  //   widgetParams,
  // }
});
search.addWidget(
  customCurrentRefinedValues({
    [ attributes = [] ],
    [ onlyListedAttributes = false ],
    [ clearsQuery = false ]
  })
);
Full documentation available at https://community.algolia.com/instantsearch.js/connectors/connectCurrentRefinedValues.html
`;

/**
 * @typedef {Object} CurrentRefinedValuesRenderingOptions
 * @property {Object.<string, object>} attributes Original `CurrentRefinedValuesWidgetOptions.attributes` mapped by keys.
 * @property {function} clearAllClick Clears all the currently refined values.
 * @property {function} clearAllURL Generate a URL which leads to a state where all the refinements have been cleared.
 * @property {function(item)} refine Clears a single refinement.
 * @property {function(item): string} createURL Creates an individual url where a single refinement is cleared.
 * @property {Object[]} refinements All the current refinements.
 * @property {Object} widgetParams All original `CustomCurrentRefinedValuesWidgetOptions` forwarded to the `renderFn`.
 */

/**
 * @typedef {Object} CurrentRefinedValuesAttributes
 * @property {string} name Mandatory field which is the name of the attribute.
 * @property {string} label The label to apply on a refinement per attribute.
 */

/**
 * @typedef {Object} CustomCurrentRefinedValuesWidgetOptions
 * @property {CurrentRefinedValuesAttributes[]} [attributes = []] Specification for the display of
 * refinements per attribute (default: `[]`). By default, the widget will display all the filters
 * set with no special treatment for the label.
 * @property {boolean} [onlyListedAttributes = false] Limit the displayed refinement to the list specified.
 * @property {boolean} [clearsQuery = false] Clears also the active search query when using clearAll.
 */

/**
 * **CurrentRefinedValues** connector provides the logic to build a widget that will give
 * the user the ability to see all the currently aplied filters and, remove some or all of
 * them.
 *
 * This provides a `refine(item)` function to remove a selected refinement and a `clearAllClick`
 * function to clear all the filters. Those functions can see their behaviour change based on
 * the widget options used.
 * @type {Connector}
 * @param {function(CurrentRefinedValuesRenderingOptions)} renderFn Rendering function for the custom **CurrentRefinedValues** widget.
 * @return {function(CustomCurrentRefinedValuesWidgetOptions)} Re-usable widget factory for a custom **CurrentRefinedValues** widget.
 * @example
 * // custom `renderFn` to render the custom ClearAll widget
 * function renderFn(CurrentRefinedValuesRenderingOptions, isFirstRendering) {
 *   var containerNode = CurrentRefinedValuesRenderingOptions.widgetParams.containerNode;
 *   if (isFirstRendering) {
 *     containerNode
 *       .html('<ul id="refiments"></ul><div id="cta-container"></div>');
 *   }
 *
 *   containerNode
 *     .find('#cta-container > a')
 *     .off('click');
 *
 *   containerNode
 *     .find('li > a')
 *     .each(function() { $(this).off('click') });
 *
 *   if (CurrentRefinedValuesRenderingOptions.refinements
 *       && CurrentRefinedValuesRenderingOptions.refinements.length > 0) {
 *     containerNode
 *       .find('#cta-container')
 *       .html('<a href="' + CurrentRefinedValuesRenderingOptions.clearAllURL + '">Clear all </a>');
 *
 *     containerNode
 *       .find('#cta-container > a')
 *       .on('click', function(event) {
 *         event.preventDefault();
 *         CurrentRefinedValuesRenderingOptions.clearAllClick();
 *       });
{'fraction_non_alphanumeric': 0.11022907688818326, 'fraction_numerical': 0.00022680880018144704, 'mean_word_length': 4.390586797066015, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '3141014', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2390, 'n_words': 745}