<commit_before>import { Objects } from '@ephox/boulder';
import { Arr, Fun, Obj, Options, Cell, Merger, Unique, Option } from '@ephox/katamari';

import * as SystemEvents from '../api/events/SystemEvents';
import * as AlloyLogger from '../log/AlloyLogger';
import { console, window } from '@ephox/dom-globals';
import { Element } from '@ephox/sugar';
import { init } from 'ephox/alloy/dragging/common/DragState';

const unknown = 'unknown';

/*
  typescipt qwerk:
  const debugging: boolean = true;
  if (boolean === false) {  -> this throws a type error! // TS2365:Operator '===' cannot be applied to types 'false' and 'true'
    https://www.typescriptlang.org/play/#src=const%20foo%3A%20boolean%20%3D%20true%3B%0D%0A%0D%0Aif%20(foo%20%3D%3D%3D%20false)%20%7B%0D%0A%20%20%20%20%0D%0A%7D
  }
*/
const debugging: any = true;

const CHROME_INSPECTOR_GLOBAL = '__CHROME_INSPECTOR_CONNECTION_TO_ALLOY__';

enum EventConfiguration {
  STOP,
  NORMAL,
  LOGGING
};

const eventConfig = Cell<Record<string, EventConfiguration>>({ });

export type EventProcessor = (logger: any) => boolean;

const makeEventLogger = (eventName: string, initialTarget: Element) => {
  const sequence = [ ];

  return {
    logEventCut (name, target, purpose) {
      sequence.push({ outcome: 'cut', target, purpose });
    },
    logEventStopped (name, target, purpose) {
      sequence.push({ outcome: 'stopped', target, purpose });
    },
    logNoParent (name, target, purpose) {
      sequence.push({ outcome: 'no-parent', target, purpose });
    },
    logEventNoHandlers (name, target) {
      sequence.push({ outcome: 'no-handlers-left', target });
    },
    logEventResponse (name, target, purpose) {
      sequence.push({ outcome: 'response', purpose, target });
    },
    write () {
      if (Arr.contains([ 'mousemove', 'mouseover', 'mouseout', SystemEvents.systemInit() ], eventName)) { return; }
      // tslint:disable-next-line:no-console
      console.log(eventName, {
        event: eventName,
        target: initialTarget.dom(),
        sequence: Arr.map(sequence, (s) => {
          if (! Arr.contains([ 'cut', 'stopped', 'response' ], s.outcome)) { return s.outcome; } else { return '{' + s.purpose + '} ' + s.outcome + ' at (' + AlloyLogger.element(s.target) + ')'; }
        })
      });
    }
  };
};

const processEvent = (eventName: string, initialTarget: Element, f: EventProcessor) => {
  const status = Objects.readOptFrom(eventConfig.get(), eventName).getOr(<commit_msg>powerful-inspector: partial matches for event debugging<commit_after>import { Objects } from '@ephox/boulder';
import { Arr, Fun, Obj, Options, Cell, Merger, Unique, Option } from '@ephox/katamari';

import * as SystemEvents from '../api/events/SystemEvents';
import * as AlloyLogger from '../log/AlloyLogger';
import { console, window } from '@ephox/dom-globals';
import { Element } from '@ephox/sugar';
import { init } from 'ephox/alloy/dragging/common/DragState';

const unknown = 'unknown';

/*
  typescipt qwerk:
  const debugging: boolean = true;
  if (boolean === false) {  -> this throws a type error! // TS2365:Operator '===' cannot be applied to types 'false' and 'true'
    https://www.typescriptlang.org/play/#src=const%20foo%3A%20boolean%20%3D%20true%3B%0D%0A%0D%0Aif%20(foo%20%3D%3D%3D%20false)%20%7B%0D%0A%20%20%20%20%0D%0A%7D
  }
*/
const debugging: any = true;

const CHROME_INSPECTOR_GLOBAL = '__CHROME_INSPECTOR_CONNECTION_TO_ALLOY__';

enum EventConfiguration {
  STOP,
  NORMAL,
  LOGGING
};

const eventConfig = Cell<Record<string, EventConfiguration>>({ });

export type EventProcessor = (logger: any) => boolean;

const makeEventLogger = (eventName: string, initialTarget: Element) => {
  const sequence = [ ];

  return {
    logEventCut (name, target, purpose) {
      sequence.push({ outcome: 'cut', target, purpose });
    },
    logEventStopped (name, target, purpose) {
      sequence.push({ outcome: 'stopped', target, purpose });
    },
    logNoParent (name, target, purpose) {
      sequence.push({ outcome: 'no-parent', target, purpose });
    },
    logEventNoHandlers (name, target) {
      sequence.push({ outcome: 'no-handlers-left', target });
    },
    logEventResponse (name, target, purpose) {
      sequence.push({ outcome: 'response', purpose, target });
    },
    write () {
      if (Arr.contains([ 'mousemove', 'mouseover', 'mouseout', SystemEvents.systemInit() ], eventName)) { return; }
      // tslint:disable-next-line:no-console
      console.log(eventName, {
        event: eventName,
        target: initialTarget.dom(),
        sequence: Arr.map(sequence, (s) => {
          if (! Arr.contains([ 'cut', 'stopped', 'response' ], s.outcome)) { return s.outcome; } else { return '{' + s.purpose + '} ' + s.outcome + ' at (' + AlloyLogger.element(s.target) + ')'; }
        })
      });
    }
  };
};

const processEvent = (eventName: string, initialTarget: Element, f: EventProcessor) => {
  const status = Objects.readOptFrom(eventConfig.get(), eventName).orThunk(() => {
    const patterns = Obj.keys(eventConfig.get());
    return Options.findMap(patterns, (p) => {
      return eventName.indexOf(p) > -1 ? Option.some(eventConfig.get()[p]) : Option.none();
    });
  }).getOr(
{'fraction_non_alphanumeric': 0.16561120706198426, 'fraction_numerical': 0.017079255421224335, 'mean_word_length': 3.857409133271202, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6532483', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1726, 'n_words': 384}