<commit_before>define(
  'ephox.darwin.demo.DarwinTableDemo',

  [
    'ephox.compass.Arr',
    'ephox.darwin.api.InputHandlers',
    'ephox.darwin.api.SelectionKeys',
    'ephox.fred.PlatformDetection',
    'ephox.fussy.api.WindowSelection',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.sugar.api.Attr',
    'ephox.sugar.api.Body',
    'ephox.sugar.api.Compare',
    'ephox.sugar.api.Direction',
    'ephox.sugar.api.DomEvent',
    'ephox.sugar.api.Element',
    'ephox.sugar.api.Insert',
    'ephox.sugar.api.Node',
    'ephox.sugar.api.Replication',
    'ephox.sugar.api.SelectorFilter',
    'ephox.sugar.api.SelectorFind',
    'ephox.sugar.api.Traverse',
    'global!Math',
    'global!document'
  ],

  function (Arr, InputHandlers, SelectionKeys, PlatformDetection, WindowSelection, Fun, Option, Attr, Body, Compare, Direction, DomEvent, Element, Insert, Node, Replication, SelectorFilter, SelectorFind, Traverse, Math, document) {
    return function () {

      var detection = PlatformDetection.detect();

      var ephoxUi = SelectorFind.first('#ephox-ui').getOrDie();
      Attr.set(ephoxUi, 'contenteditable', 'true');

      var style = Element.fromHtml(
        '<style>' +
          'table { border-collapse: separate; border-spacing: 30px; }\n' +
          'td { text-align: left; border: 1px solid #aaa; font-size: 20px; }\n' +
          'td.ephox-darwin-selected { background: #cadbee; }\n' +
          '#coords { position: fixed; right: 0px; bottom: 0px; background: #ddd }' +
        '</style>'
      );

      var table = Element.fromHtml(
        '<table style="width: 400px;">' +
          '<tbody>' +
            '<tr style="height: 20px;"><td>A</td><td rowspan="2" colspan="2">B</td><td>C</td></tr>' +
            '<tr style="height: 20px;"><td>D</td><td colspan="1" rowspan="2">E</td>' +
            '<tr style="height: 20px;"><td colspan="3" rowspan="3">F</td></tr>' +
            '<tr style="height: 20px;"><td>G</td></tr>' +
            '<tr style="height: 20px;"><td>H</td></tr>' +
            '<tr style="height: 20px;"><td rowspan="2" colspan="1">I</td><td>J</td><td colspan="2">K</td></tr>' +
            '<tr style="height: 20px;"><td colspan="2">L</td><td>M</td></tr>' +
          '</tbody>' +
        '</table>'
      );

      // var table = Element.fromHtml(
      //   '<table>' +
      //     '<tbody>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;">A1</td>' +
      //         '<td style="min-width: 100px;">B1<br /></td>' +
      //         '<td style="min-width: 100px;" colspan=2>C1<br /><br /><br /></td>' +
      //         // '<td style="min-width: 100px;">D1</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;" colspan="2">A2</td>' +
      //         // '<td style="min-width: 100px;">B2<br /><br /></td>' +
      //         '<td style="min-width: 100px;"><p>C2</p><p>More</p></td>' +
      //         '<td style="min-width: 100px;"><br />D2</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;">A3</td>' +
      //         '<td style="min-width: 100px;"><br /></td>' +
      //         '<td style="min-width: 100px;"><br /></td>' +
      //         '<td style="min-width: 100px;">D3</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;">A4</td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;"><br /></td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;"><br /></td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;">D4</td>' +
      //       '</tr>' +
      //     '</tbody>' +
      //   '</table>'
      // );

      Insert.append(ephoxUi, table);
      Insert.append(Element.fromDom(document.head), style);

      var rtlTable = Replication.deep(table);
      Attr.set(rtlTable, 'dir', 'rtl');
      Insert.append(ephoxUi, rtlTable);

      var cloneDiv = Element.fromTag('div');
      Attr.set(cloneDiv, 'contenteditable', 'true');
      var clone = Replication.deep(table);
      Insert.append(cloneDiv, clone);
      Insert.append(Body.body(), cloneDiv);

      Insert.append(Body.body(), Element.fromHtml('<span id="coords">(0, 0)</span>'));
      DomEvent.bind(Body.body(), 'mousemove', function (event) {
        document.querySelector('#coords').innerHTML = '(' + event.raw().clientX + ', ' + event.raw().clientY + ')';
      });

      var mouseHandlers = InputHandlers.mouse(window, ephoxUi);
      var keyHandlers = InputHandlers.keyboard(window, ephoxUi, Fun.curry(Compare.eq, table));

      DomEvent.bind(ephoxUi, 'mousedown', mouseHandlers.mousedown);
      DomEvent.bind(ephoxUi, 'mouseover', mouseHandlers.mouseover);
      DomEvent.bind(ephoxUi, 'mouseup', mouseHandlers.mouseup);

      var handleResponse = function (event, response) {
        if (response.kill()) event.kill();
        response.selection().each(function (ns) {
          WindowSelection.set(window, ns);<commit_msg>TBIO-405: cleanup<commit_after>define(
  'ephox.darwin.demo.DarwinTableDemo',

  [
    'ephox.compass.Arr',
    'ephox.darwin.api.InputHandlers',
    'ephox.darwin.api.SelectionKeys',
    'ephox.fred.PlatformDetection',
    'ephox.fussy.api.WindowSelection',
    'ephox.peanut.Fun',
    'ephox.perhaps.Option',
    'ephox.sugar.api.Attr',
    'ephox.sugar.api.Body',
    'ephox.sugar.api.Compare',
    'ephox.sugar.api.Direction',
    'ephox.sugar.api.DomEvent',
    'ephox.sugar.api.Element',
    'ephox.sugar.api.Insert',
    'ephox.sugar.api.Node',
    'ephox.sugar.api.Replication',
    'ephox.sugar.api.SelectorFilter',
    'ephox.sugar.api.SelectorFind',
    'ephox.sugar.api.Traverse',
    'global!Math',
    'global!document'
  ],

  function (Arr, InputHandlers, SelectionKeys, PlatformDetection, WindowSelection, Fun, Option, Attr, Body, Compare, Direction, DomEvent, Element, Insert, Node, Replication, SelectorFilter, SelectorFind, Traverse, Math, document) {
    return function () {

      var detection = PlatformDetection.detect();

      var ephoxUi = SelectorFind.first('#ephox-ui').getOrDie();
      Attr.set(ephoxUi, 'contenteditable', 'true');

      var style = Element.fromHtml(
        '<style>' +
          'table { border-collapse: separate; border-spacing: 30px; }\n' +
          'td { text-align: left; border: 1px solid #aaa; font-size: 20px; }\n' +
          'td.ephox-darwin-selected { background: #cadbee; }\n' +
          '#coords { position: fixed; right: 0px; bottom: 0px; background: #ddd }' +
        '</style>'
      );

      var table = Element.fromHtml(
        '<table style="width: 400px;">' +
          '<tbody>' +
            '<tr style="height: 20px;"><td>A</td><td rowspan="2" colspan="2">B</td><td>C</td></tr>' +
            '<tr style="height: 20px;"><td>D</td><td colspan="1" rowspan="2">E</td>' +
            '<tr style="height: 20px;"><td colspan="3" rowspan="3">F</td></tr>' +
            '<tr style="height: 20px;"><td>G</td></tr>' +
            '<tr style="height: 20px;"><td>H</td></tr>' +
            '<tr style="height: 20px;"><td rowspan="2" colspan="1">I</td><td>J</td><td colspan="2">K</td></tr>' +
            '<tr style="height: 20px;"><td colspan="2">L</td><td>M</td></tr>' +
          '</tbody>' +
        '</table>'
      );

/* Uncomment for normal table with no colspans.
      // var table = Element.fromHtml(
      //   '<table>' +
      //     '<tbody>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;">A1</td>' +
      //         '<td style="min-width: 100px;">B1<br /></td>' +
      //         '<td style="min-width: 100px;" colspan=2>C1<br /><br /><br /></td>' +
      //         // '<td style="min-width: 100px;">D1</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;">A2</td>' +
      //         '<td style="min-width: 100px;">B2<br /><br /></td>' +
      //         '<td style="min-width: 100px;"><p>C2</p><p>More</p></td>' +
      //         '<td style="min-width: 100px;"><br />D2</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="min-width: 100px;">A3</td>' +
      //         '<td style="min-width: 100px;"><br /></td>' +
      //         '<td style="min-width: 100px;"><br /></td>' +
      //         '<td style="min-width: 100px;">D3</td>' +
      //       '</tr>' +
      //       '<tr>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;">A4</td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;"><br /></td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;"><br /></td>' +
      //         '<td style="padding-top: 100px;" style="min-width: 100px;">D4</td>' +
      //       '</tr>' +
      //     '</tbody>' +
      //   '</table>'
      // );
*/

      Insert.append(ephoxUi, table);
      Insert.append(Element.fromDom(document.head), style);

      var rtlTable = Replication.deep(table);
      Attr.set(rtlTable, 'dir', 'rtl');
      Insert.append(ephoxUi, rtlTable);

      var cloneDiv = Element.fromTag('div');
      Attr.set(cloneDiv, 'contenteditable', 'true');
      var clone = Replication.deep(table);
      Insert.append(cloneDiv, clone);
      Insert.append(Body.body(), cloneDiv);

      Insert.append(Body.body(), Element.fromHtml('<span id="coords">(0, 0)</span>'));
      DomEvent.bind(Body.body(), 'mousemove', function (event) {
        document.querySelector('#coords').innerHTML = '(' + event.raw().clientX + ', ' + event.raw().clientY + ')';
      });

      var mouseHandlers = InputHandlers.mouse(window, ephoxUi);
      var keyHandlers = InputHandlers.keyboard(window, ephoxUi, Fun.curry(Compare.eq, table));

      DomEvent.bind(ephoxUi, 'mousedown', mouseHandlers.mousedown);
      DomEvent.bind(ephoxUi, 'mouseover', mouseHandlers.mouseover);
      DomEvent.bind(ephoxUi, 'mouseup', mouseHandlers.mouseup);

      var handleResponse = function (event, response) {
        if (response.kill()) event.kill();
        response.selection().each(function (ns) {
          WindowSelection.set(window, ns);
{'fraction_non_alphanumeric': 0.21700706991358995, 'fraction_numerical': 0.021798900235663787, 'mean_word_length': 2.4052156469408223, 'pattern_counts': {'":': 0, '<': 215, '<?xml version=': 0, '>': 215, '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': '1783097', 'n_tokens_mistral': 3725, 'n_tokens_neox': 3553, 'n_words': 568}