<commit_before>import 'es6-shim';
import PropTypes from 'prop-types';
import React from 'react';

import Quill from 'quill';
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";

var icons = Quill.import('ui/icons');
icons['footnote'] = 'Add footnote';
icons['endnote'] = 'Add endnote';
icons['import_docx'] = 'Import DOCX';

import "../modules/footnote";
import "../modules/endnote";
import Noties from "../modules/noties";

// Table module for Quill
import "../modules/table";

// Ajax library for uploading DOCX files
import axios from 'axios';

import "../css/formatted-text-editor.css";

const uuidv4 = require('uuid/v4');


// Function to return closest element based on a selector.
// If self attribute is true, search is also applied to the element itself
function closest(el, selector, self=false) {
    var matchesFn;
    ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector','oMatchesSelector'].some(function(fn) {
        if (typeof document.body[fn] == 'function') {
            matchesFn = fn;
            return true;
        }
        return false;
    })
    if (self && el[matchesFn](selector)) return el;
    var parent;
    while (el) {
        parent = el.parentElement;
        if (parent && parent[matchesFn](selector)) {
            return parent;
        }
        el = parent;
    }
    return null;
}


class FormattedTextEditor extends React.Component {
  static propTypes = {
    contentRef: PropTypes.string.isRequired
  };

  constructor(props){
    super(props);
    this.uid = `quill-${uuidv4()}`;
    this.updateContent = this._updateContent.bind(this);
    this.docxUpload = this._docxUpload.bind(this);

    this.handleFootnote = this.handleFootnote.bind(this);
    this.handleEndnote = this.handleEndnote.bind(this);
    this.handleFootnoteClick = this.handleFootnoteClick.bind(this);
    this.handleEndnoteClick = this.handleEndnoteClick.bind(this);
    this.saveNote = this.saveNote.bind(this);

    this.state = {
      noteLabel: '',
      noteElement: null,
      noteText: '',
      noteDialogDisplay: 'none',
      mainEditorDisplay: 'block',
    };

    const self = this;

    this.toolbarOptions = {
      container: [
        [{ 'header': [false, 1, 2, 3, 4] }],
        ['bold', 'italic', 'underline', 'strike'],
        [{ 'color': [] }, { 'background': [] }],
        [{ 'script': 'sub'}, { 'script': 'super' }],
        ['link', 'image'],
        [{ 'list': 'ordered'}, { 'list': 'bullet' }],
        [{ table: FormattedTextEditor.tableOptions() }, { table: 'append-row' }, { table: 'append-col' }],
        ['footnote', 'endnote', 'import_docx'],
      ],
      handlers: {
        'footnote': this.handleFootnote,
        'endnote': this.handleEndnote,
        'import_docx': this.importDocxCallback(),
      }
    };
  }

  _loadContent(){
    const v = document.getElementById(this.props.contentRef).value;
    try {
      return JSON.parse(v);
    } catch(err) {}
    return {format: 'html', content: v};
  }

  _updateContent(){
    const el = document.getElementById(this.props.contentRef)
    el.value = JSON.stringify({
      format: 'html',
      doc: this.editor.getContents(),
      content: '<p style="display:none;"></p>' +
          this._prepareHtmlForSaving(this.editor.root.innerHTML) +
          '<p style="display:none;"></p>'
    });<commit_msg>Removed images upload button in formatted text editors<commit_after>import 'es6-shim';
import PropTypes from 'prop-types';
import React from 'react';

import Quill from 'quill';
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";

var icons = Quill.import('ui/icons');
icons['footnote'] = 'Add footnote';
icons['endnote'] = 'Add endnote';
icons['import_docx'] = 'Import DOCX';

import "../modules/footnote";
import "../modules/endnote";
import Noties from "../modules/noties";

// Table module for Quill
import "../modules/table";

// Ajax library for uploading DOCX files
import axios from 'axios';

import "../css/formatted-text-editor.css";

const uuidv4 = require('uuid/v4');


// Function to return closest element based on a selector.
// If self attribute is true, search is also applied to the element itself
function closest(el, selector, self=false) {
    var matchesFn;
    ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector','oMatchesSelector'].some(function(fn) {
        if (typeof document.body[fn] == 'function') {
            matchesFn = fn;
            return true;
        }
        return false;
    })
    if (self && el[matchesFn](selector)) return el;
    var parent;
    while (el) {
        parent = el.parentElement;
        if (parent && parent[matchesFn](selector)) {
            return parent;
        }
        el = parent;
    }
    return null;
}


class FormattedTextEditor extends React.Component {
  static propTypes = {
    contentRef: PropTypes.string.isRequired
  };

  constructor(props){
    super(props);
    this.uid = `quill-${uuidv4()}`;
    this.updateContent = this._updateContent.bind(this);
    this.docxUpload = this._docxUpload.bind(this);

    this.handleFootnote = this.handleFootnote.bind(this);
    this.handleEndnote = this.handleEndnote.bind(this);
    this.handleFootnoteClick = this.handleFootnoteClick.bind(this);
    this.handleEndnoteClick = this.handleEndnoteClick.bind(this);
    this.saveNote = this.saveNote.bind(this);

    this.state = {
      noteLabel: '',
      noteElement: null,
      noteText: '',
      noteDialogDisplay: 'none',
      mainEditorDisplay: 'block',
    };

    const self = this;

    this.toolbarOptions = {
      container: [
        [{ 'header': [false, 1, 2, 3, 4] }],
        ['bold', 'italic', 'underline', 'strike'],
        [{ 'color': [] }, { 'background': [] }],
        [{ 'script': 'sub'}, { 'script': 'super' }],
        ['link'],
        [{ 'list': 'ordered'}, { 'list': 'bullet' }],
        [{ table: FormattedTextEditor.tableOptions() }, { table: 'append-row' }, { table: 'append-col' }],
        ['footnote', 'endnote', 'import_docx'],
      ],
      handlers: {
        'footnote': this.handleFootnote,
        'endnote': this.handleEndnote,
        'import_docx': this.importDocxCallback(),
      }
    };
  }

  _loadContent(){
    const v = document.getElementById(this.props.contentRef).value;
    try {
      return JSON.parse(v);
    } catch(err) {}
    return {format: 'html', content: v};
  }

  _updateContent(){
    const el = document.getElementById(this.props.contentRef)
    el.value = JSON.stringify({
      format: 'html',
      doc: this.editor.getContents(),
      content: '<p style="display:none;"></p>' +
          this._prepareHtmlForSaving(this.editor.root.innerHTML) +
          '<p style="display:none;"></p>'
    });
{'fraction_non_alphanumeric': 0.16014814814814815, 'fraction_numerical': 0.0023703703703703703, 'mean_word_length': 3.0256410256410255, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3837994', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2057, 'n_words': 456}