<commit_before>import React from 'react'
import insertCss from 'insert-css'
import merge from 'lodash/merge'
import Dialogs from 'dialogs'
import { ipcRenderer, remote, shell } from 'electron'
import styled from 'styled-components'

import Sidebar from './Sidebar'
import i18n from '../lib/i18n'
import pkg from '../../package.json'

let iD = window.iD
let DOMParser = window.DOMParser

const Overlay = styled.div`
  position: absolute;
  height: 100%;
  width: 100%;
  .menu {
    position: absolute;
    top: 10px;
    right: 10px;
  }
`

export default class MapEditor extends React.Component {
  constructor (props) {
    super(props)
    var self = this
    this.refreshWindow = this.refreshWindow.bind(this)
    this.zoomToDataRequest = this.zoomToDataRequest.bind(this)
    this.zoomToDataResponse = this.zoomToDataResponse.bind(this)
    this.zoomToLatLonResponse = this.zoomToLatLonResponse.bind(this)
    this.changeLanguageRequest = this.changeLanguageRequest.bind(this)
    ipcRenderer.on('zoom-to-data-request', this.zoomToDataRequest)
    ipcRenderer.on('zoom-to-data-response', self.zoomToDataResponse)
    ipcRenderer.on('zoom-to-latlon-response', self.zoomToLatLonResponse)
    ipcRenderer.on('change-language-request', self.changeLanguageRequest)
    ipcRenderer.on('refresh-window', self.refreshWindow)
    ipcRenderer.on('updated-settings', function () {
      self.updateSettings()
    })
  }

  componentWillUnmount () {
    ipcRenderer.removeListener('zoom-to-data-request', this.zoomToDataRequest)
    ipcRenderer.removeListener('zoom-to-data-response', this.zoomToDataResponse)
    ipcRenderer.removeListener('zoom-to-latlon-response', this.zoomToLatLonResponse)
    ipcRenderer.removeListener('change-language-request', this.changeLanguageRequest)
    ipcRenderer.removeListener('refresh-window', this.refreshWindow)
  }

  render () {
    return (
      <div className='full'>
        <Overlay>
          <Sidebar
            changeView={this.props.changeView}
            openModal={this.props.openModal}
          />
        </Overlay>
        <div id='container' />
      </div>
    )
  }

  refreshWindow () {
    if (this.id) {
      var history = this.id.history()
      var saved = history.toJSON()
      this.id.flush()
      history.fromJSON(saved)
    }
  }

  componentDidMount () {
    var self = this
    this.mounted = true
    this.updateSettings()

    var serverUrl = 'http://' + remote.getGlobal('osmServerHost')
    this.id = iD.Context()
      .assetPath('node_modules/id-mapeo/dist/')
      .preauth({ url: serverUrl })
      .minEditableZoom(14)

    this.id.version = pkg.version
    this.customDefs = this.id.container()
      .append('svg')
      .style('position', 'absolute')
      .style('width', '0px')
      .style('height', '0px')
      .attr('id', 'custom-defs')
      .append('defs')

    this.customDefs.append('svg')

    this.id.ui()(document.getElementById('container'), function onLoad () {
      var links = document.querySelectorAll('a[href^="http"]')
      links.forEach(function (link) {
        var href = link.getAttribute('href')<commit_msg>BUG(MapEditor): if there's no history, don't throw an error when refreshing window<commit_after>import React from 'react'
import insertCss from 'insert-css'
import merge from 'lodash/merge'
import Dialogs from 'dialogs'
import { ipcRenderer, remote, shell } from 'electron'
import styled from 'styled-components'

import Sidebar from './Sidebar'
import i18n from '../lib/i18n'
import pkg from '../../package.json'

let iD = window.iD
let DOMParser = window.DOMParser

const Overlay = styled.div`
  position: absolute;
  height: 100%;
  width: 100%;
  .menu {
    position: absolute;
    top: 10px;
    right: 10px;
  }
`

export default class MapEditor extends React.Component {
  constructor (props) {
    super(props)
    var self = this
    this.refreshWindow = this.refreshWindow.bind(this)
    this.zoomToDataRequest = this.zoomToDataRequest.bind(this)
    this.zoomToDataResponse = this.zoomToDataResponse.bind(this)
    this.zoomToLatLonResponse = this.zoomToLatLonResponse.bind(this)
    this.changeLanguageRequest = this.changeLanguageRequest.bind(this)
    ipcRenderer.on('zoom-to-data-request', this.zoomToDataRequest)
    ipcRenderer.on('zoom-to-data-response', self.zoomToDataResponse)
    ipcRenderer.on('zoom-to-latlon-response', self.zoomToLatLonResponse)
    ipcRenderer.on('change-language-request', self.changeLanguageRequest)
    ipcRenderer.on('refresh-window', self.refreshWindow)
    ipcRenderer.on('updated-settings', function () {
      self.updateSettings()
    })
  }

  componentWillUnmount () {
    ipcRenderer.removeListener('zoom-to-data-request', this.zoomToDataRequest)
    ipcRenderer.removeListener('zoom-to-data-response', this.zoomToDataResponse)
    ipcRenderer.removeListener('zoom-to-latlon-response', this.zoomToLatLonResponse)
    ipcRenderer.removeListener('change-language-request', this.changeLanguageRequest)
    ipcRenderer.removeListener('refresh-window', this.refreshWindow)
  }

  render () {
    return (
      <div className='full'>
        <Overlay>
          <Sidebar
            changeView={this.props.changeView}
            openModal={this.props.openModal}
          />
        </Overlay>
        <div id='container' />
      </div>
    )
  }

  refreshWindow () {
    if (this.id) {
      var history = this.id.history()
      var saved = history.toJSON()
      this.id.flush()
      if (saved) history.fromJSON(saved)
    }
  }

  componentDidMount () {
    var self = this
    this.mounted = true
    this.updateSettings()

    var serverUrl = 'http://' + remote.getGlobal('osmServerHost')
    this.id = iD.Context()
      .assetPath('node_modules/id-mapeo/dist/')
      .preauth({ url: serverUrl })
      .minEditableZoom(14)

    this.id.version = pkg.version
    this.customDefs = this.id.container()
      .append('svg')
      .style('position', 'absolute')
      .style('width', '0px')
      .style('height', '0px')
      .attr('id', 'custom-defs')
      .append('defs')

    this.customDefs.append('svg')

    this.id.ui()(document.getElementById('container'), function onLoad () {
      var links = document.querySelectorAll('a[href^="http"]')
      links.forEach(function (link) {
        var href = link.getAttribute('href')
{'fraction_non_alphanumeric': 0.13447510307643515, 'fraction_numerical': 0.005708848715509039, 'mean_word_length': 3.331730769230769, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3280328', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1958, 'n_words': 358}