<commit_before>import { Component, keys } from 'substance'
import { createEditorContext, EditorSession } from '../../kit'
import ArticleAPI from '../ArticleAPI'

// Base-class for Manuscript- and MetadataEditor to reduced code-redundancy
export default class EditorPanel extends Component {
  constructor (...args) {
    super(...args)

    this._initialize(this.props)
  }

  getActionHandlers () {
    return {
      executeCommand: this._executeCommand,
      toggleOverlay: this._toggleOverlay,
      startWorkflow: this._startWorkflow,
      closeModal: this._closeModal,
      scrollElementIntoView: this._scrollElementIntoView
    }
  }

  // TODO: shouldn't we react on willReceiveProps?
  _initialize (props) {
    const { articleSession, config, archive, editorState, viewName } = props

    // TODO: I want to refactor how EditorSessions are created
    // particularly I want to work on the multi-view/user sessions
    const editorSession = new EditorSession(viewName, articleSession, config, this, editorState)
    const api = new ArticleAPI(editorSession, archive, config, articleSession, { getContext: () => this.context })

    const context = Object.assign(createEditorContext(config, editorSession), {
      api,
      archive,
      editor: this,
      urlResolver: archive,
      editable: true
    })

    this.api = api
    this.appState = context.appState
    this.context = context
    this.editorSession = editorSession

    this.editorSession.initialize()
    this.appState.addObserver(['workflowId'], this.rerender, this, { stage: 'render' })
    this.appState.addObserver(['settings'], this._onSettingsUpdate, this, { stage: 'render' })

    // HACK: ATM there is no better way than to listen to an archive<commit_msg>Fix creation of EditorPanel context.<commit_after>import { Component, keys } from 'substance'
import { createEditorContext, EditorSession } from '../../kit'
import ArticleAPI from '../ArticleAPI'

// Base-class for Manuscript- and MetadataEditor to reduced code-redundancy
export default class EditorPanel extends Component {
  constructor (...args) {
    super(...args)

    this._initialize(this.props)
  }

  getActionHandlers () {
    return {
      executeCommand: this._executeCommand,
      toggleOverlay: this._toggleOverlay,
      startWorkflow: this._startWorkflow,
      closeModal: this._closeModal,
      scrollElementIntoView: this._scrollElementIntoView
    }
  }

  // TODO: shouldn't we react on willReceiveProps?
  _initialize (props) {
    const { articleSession, config, archive, editorState, viewName } = props

    // TODO: I want to refactor how EditorSessions are created
    // particularly I want to work on the multi-view/user sessions
    const editorSession = new EditorSession(viewName, articleSession, config, this, editorState)
    const api = new ArticleAPI(editorSession, archive, config, articleSession, { getContext: () => this.context })

    // ATTENTION: augmenting the default context with editor stuff and api etc.
    // TODO: try to find a more idiomatic approach, without needing to hack the context
    // This should be solvable by sharing things like 'api' on the ArticlePanel level
    // and adding other things to getChildContext()
    const context = Object.assign(this.context, createEditorContext(config, editorSession), {
      api,
      archive,
      editor: this,
      urlResolver: archive,
      editable: true
    })

    this.api = api
    this.appState = context.appState
    this.context = context
    this.editorSession = editorSession

    this.editorSession.initialize()
    this.appState.addObserver(['workflowId'], this.rerender, this, { stage: 'render' })
    this.appState.addObserver(['settings'], this._onSettingsUpdate, this, { stage: 'render' })

    // HACK: ATM there is no better way than to listen to an archive
{'fraction_non_alphanumeric': 0.09721136304404483, 'fraction_numerical': 0.0, 'mean_word_length': 3.5206124852767964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4803192', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1012, 'n_words': 324}