import { __require as requireDraftJsDebugLogging } from './DraftJsDebugLogging.js';
import { __require as requireEditorState } from './EditorState.js';
import { __require as requireGetContentEditableContainer } from './getContentEditableContainer.js';
import { __require as requireGetDraftEditorSelection } from './getDraftEditorSelection.js';

/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 * 
 * @emails oncall+draft_js
 */

var editOnSelect_1;
var hasRequiredEditOnSelect;

function requireEditOnSelect () {
	if (hasRequiredEditOnSelect) return editOnSelect_1;
	hasRequiredEditOnSelect = 1;

	var DraftJsDebugLogging = requireDraftJsDebugLogging();

	var EditorState = requireEditorState();

	var getContentEditableContainer = requireGetContentEditableContainer();

	var getDraftEditorSelection = requireGetDraftEditorSelection();

	function editOnSelect(editor) {
	  if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
	    if (editor._blockSelectEvents) {
	      var _editorState = editor.props.editorState;

	      var selectionState = _editorState.getSelection();

	      DraftJsDebugLogging.logBlockedSelectionEvent({
	        // For now I don't think we need any other info
	        anonymizedDom: 'N/A',
	        extraParams: JSON.stringify({
	          stacktrace: new Error().stack
	        }),
	        selectionState: JSON.stringify(selectionState.toJS())
	      });
	    }

	    return;
	  }

	  var editorState = editor.props.editorState;
	  var documentSelection = getDraftEditorSelection(editorState, getContentEditableContainer(editor));
	  var updatedSelectionState = documentSelection.selectionState;

	  if (updatedSelectionState !== editorState.getSelection()) {
	    if (documentSelection.needsRecovery) {
	      editorState = EditorState.forceSelection(editorState, updatedSelectionState);
	    } else {
	      editorState = EditorState.acceptSelection(editorState, updatedSelectionState);
	    }

	    editor.update(editorState);
	  }
	}

	editOnSelect_1 = editOnSelect;
	return editOnSelect_1;
}

export { requireEditOnSelect as __require };
//# sourceMappingURL=editOnSelect.js.map
