<commit_before>import Directive from '@grid/view/directives/directive';
import {EventListener, EventManager} from '@grid/core/infrastructure';
import DragService from './drag.service';
import {DRAG_NAME, DROP_EFFECT_NAME, CAN_DRAG_NAME, VIEW_CORE_NAME} from '@grid/view/definition';
import {GRID_PREFIX} from '@grid/core/definition';

class Drag extends Directive(DRAG_NAME, {view: `^^?${VIEW_CORE_NAME}`}) {
	constructor($element) {
		super();

		this.element = $element[0];
		this.listener = new EventListener(this.element, new EventManager(this));
	}

	onInit() {
		this.element.classList.add(`${GRID_PREFIX}-can-drag`);
		this.listener.on('dragstart', this.start);
		this.listener.on('dragend', this.end.bind(this));
	}

	onDestroy() {
		this.element.classList.remove(`${GRID_PREFIX}-can-drag`);
		this.listener.off()
	}

	start(e) {
		const transfer = e.dataTransfer;
		if (this.canDrag(this.event()) === false) {
			e.preventDefault();
			transfer.effectAllowed = 'none';
			return false;
		}

		const source = this.transfer();
		this.element.classList.add(`${GRID_PREFIX}-drag`);
		transfer.setData(DragService.mimeType, DragService.encode(source));
		transfer.effectAllowed = this.effect || 'move';
		DragService.transfer = source;

		if (this.view) {
			const model = this.view.model;
			model.drag({isActive: true});
		}
	}

	end() {
		this.element.classList.remove(`${GRID_PREFIX}-drag`);
		DragService.transfer = null;

		if (this.view) {
			const model = this.view.model;
			model.drag({isActive: false});
		}
	}

	event() {
		const source = this.transfer();
		return {
			$event: {
				source: source,
				target: null
			}
		};
	}<commit_msg>set drag image<commit_after>import Directive from '@grid/view/directives/directive';
import {EventListener, EventManager} from '@grid/core/infrastructure';
import DragService from './drag.service';
import {DRAG_NAME, DROP_EFFECT_NAME, CAN_DRAG_NAME, VIEW_CORE_NAME} from '@grid/view/definition';
import {GRID_PREFIX} from '@grid/core/definition';

class Drag extends Directive(DRAG_NAME, {view: `^^?${VIEW_CORE_NAME}`}) {
	constructor($element) {
		super();

		this.element = $element[0];
		this.listener = new EventListener(this.element, new EventManager(this));
	}

	onInit() {
		this.element.classList.add(`${GRID_PREFIX}-can-drag`);
		this.listener.on('dragstart', this.start);
		this.listener.on('dragend', this.end.bind(this));
	}

	onDestroy() {
		this.element.classList.remove(`${GRID_PREFIX}-can-drag`);
		this.listener.off()
	}

	start(e) {
		const transfer = e.dataTransfer;
		if (this.canDrag(this.event()) === false) {
			e.preventDefault();
			transfer.effectAllowed = 'none';
			return false;
		}

		const source = this.transfer();
		this.element.classList.add(`${GRID_PREFIX}-drag`);
		transfer.setData(DragService.mimeType, DragService.encode(source));
		transfer.effectAllowed = this.effect || 'move';
		transfer.setDragImage(this.element, 0, 0);
		DragService.transfer = source;

		if (this.view) {
			const model = this.view.model;
			model.drag({isActive: true});
		}
	}

	end() {
		this.element.classList.remove(`${GRID_PREFIX}-drag`);
		DragService.transfer = null;

		if (this.view) {
			const model = this.view.model;
			model.drag({isActive: false});
		}
	}

	event() {
		const source = this.transfer();
		return {
			$event: {
				source: source,
				target: null
			}
		};
	}
{'fraction_non_alphanumeric': 0.1675595238095238, 'fraction_numerical': 0.0011904761904761906, 'mean_word_length': 4.420967741935484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '103086', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1153, 'n_words': 203}