<commit_before>import { AlloySpec, Menu as AlloyMenu, RawDomSchema } from '@ephox/alloy';
import { ItemSpec } from '@ephox/alloy/lib/main/ts/ephox/alloy/ui/types/ItemTypes';
import { Arr, Fun, Obj } from '@ephox/katamari';

const chunk = <I>(rowDom: RawDomSchema, numColumns: number) => {
  return (items: I[]) => {
    const chunks = Arr.chunk(items, numColumns);
    return Arr.map(chunks, (c) => ({
      dom: rowDom,
      components: c
    }));
  };
};

const forSwatch = (columns: number | 'auto') => {
  return {
    dom: {
      tag: 'div',
      classes: [ 'tox-menu' ]
    },
    components: [
      {
        dom: {
          tag: 'div',
          classes: [ 'tox-swatches' ]
        },
        components: [
          AlloyMenu.parts().items({
            preprocess: columns !== 'auto' ? chunk(
              {
                tag: 'div',
                classes: [ 'tox-swatches__row' ]
              },
              columns
            ) : Fun.identity
          })
        ]
      }
    ]
  };
};

const forToolbar = (columns: number) => {
  return {
    dom: {
      tag: 'div',
      // TODO: Configurable lg setting?
      classes: [ 'tox-menu', 'tox-collection', 'tox-collection--toolbar', 'tox-collection--toolbar-lg' ]
    },
    components: [
      AlloyMenu.parts().items({
        preprocess: chunk(
          {
            tag: 'div',
            classes: [ 'tox-collection__group' ]
          },
          columns
        )
      })
    ]
  };
};

// NOTE: That type signature isn't quite true.
const preprocessCollection = (items: ItemSpec[], isSeparator: (a: ItemSpec, index: number) => boolean): AlloySpec[] => {
  const allSplits = [ ];
  let currentSplit = [ ];
  Arr.each(items, (item, i) => {
    if (isSeparator(item, i)) {
      if (currentSplit.length > 0) {
        allSplits.push(currentSplit);
      }
      currentSplit = [ ];
      if (Obj.has(item, 'dom') && Obj.has(item.dom, 'innerHtml')) {
        currentSplit.push(item);
      }
    } else {
      currentSplit.push(item);
    }
  });

  if (currentSplit.length > 0) {
    allSplits.push(currentSplit);
  }

  return Arr.map(allSplits, (s) => {
    return {
      dom: {
        tag: 'div',<commit_msg>TINY-2226 Remove extraneous check<commit_after>import { AlloySpec, Menu as AlloyMenu, RawDomSchema } from '@ephox/alloy';
import { ItemSpec } from '@ephox/alloy/lib/main/ts/ephox/alloy/ui/types/ItemTypes';
import { Arr, Fun, Obj } from '@ephox/katamari';

const chunk = <I>(rowDom: RawDomSchema, numColumns: number) => {
  return (items: I[]) => {
    const chunks = Arr.chunk(items, numColumns);
    return Arr.map(chunks, (c) => ({
      dom: rowDom,
      components: c
    }));
  };
};

const forSwatch = (columns: number | 'auto') => {
  return {
    dom: {
      tag: 'div',
      classes: [ 'tox-menu' ]
    },
    components: [
      {
        dom: {
          tag: 'div',
          classes: [ 'tox-swatches' ]
        },
        components: [
          AlloyMenu.parts().items({
            preprocess: columns !== 'auto' ? chunk(
              {
                tag: 'div',
                classes: [ 'tox-swatches__row' ]
              },
              columns
            ) : Fun.identity
          })
        ]
      }
    ]
  };
};

const forToolbar = (columns: number) => {
  return {
    dom: {
      tag: 'div',
      // TODO: Configurable lg setting?
      classes: [ 'tox-menu', 'tox-collection', 'tox-collection--toolbar', 'tox-collection--toolbar-lg' ]
    },
    components: [
      AlloyMenu.parts().items({
        preprocess: chunk(
          {
            tag: 'div',
            classes: [ 'tox-collection__group' ]
          },
          columns
        )
      })
    ]
  };
};

// NOTE: That type signature isn't quite true.
const preprocessCollection = (items: ItemSpec[], isSeparator: (a: ItemSpec, index: number) => boolean): AlloySpec[] => {
  const allSplits = [ ];
  let currentSplit = [ ];
  Arr.each(items, (item, i) => {
    if (isSeparator(item, i)) {
      if (currentSplit.length > 0) {
        allSplits.push(currentSplit);
      }
      currentSplit = [ ];
      if (Obj.has(item.dom, 'innerHtml')) {
        currentSplit.push(item);
      }
    } else {
      currentSplit.push(item);
    }
  });

  if (currentSplit.length > 0) {
    allSplits.push(currentSplit);
  }

  return Arr.map(allSplits, (s) => {
    return {
      dom: {
        tag: 'div',
{'fraction_non_alphanumeric': 0.16166439290586632, 'fraction_numerical': 0.0018190086402910413, 'mean_word_length': 1.8959842001316656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5277658', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1446, 'n_words': 290}