<commit_before>import {
	Component,
	Input,
	ViewEncapsulation,
	OnInit,
	ElementRef,
	NgZone,
	Inject,
	ChangeDetectorRef
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { Action } from 'ng2-qgrid/core/action/action';
import { AppError } from 'ng2-qgrid/core/infrastructure/error';
import { ColumnModel } from 'ng2-qgrid/core/column-type/column.model';
import { Command } from 'ng2-qgrid/core/command/command';
import { EventListener } from 'ng2-qgrid/core/infrastructure/event.listener';
import { EventManager } from 'ng2-qgrid/core/infrastructure/event.manager';
import { eventPath } from 'ng2-qgrid/core/services/dom';
import { FetchContext } from 'ng2-qgrid/core/fetch/fetch.context';
import { Grid } from './grid.service';
import { GridCtrl } from 'ng2-qgrid/core/grid/grid.ctrl';
import { GridModel } from '../../plugins/plugin.service';
import { LayerService } from '../layer/layer.service';
import { ModelBuilderService } from '../model/model-builder.service';
import { noop } from 'ng2-qgrid/core/utility/kit';
import { PipeContext } from 'ng2-qgrid/core/pipe/pipe.item';
import { RootComponent } from '../../infrastructure/component/root.component';
import { RootService } from '../../infrastructure/component/root.service';
import { StyleRowContext, StyleCellContext } from 'ng2-qgrid/core/style/style.context';
import { TableCommandManager } from 'ng2-qgrid/core/command/table.command.manager';
import { TemplateCacheService } from '../../template/template-cache.service';
import { TemplateLinkService } from '../../template/template-link.service';
import { TemplateService } from '../../template/template.service';
import { ThemeService } from '../../template/theme.service';
import { ViewCoreService } from '../../main/core/view/view-core.service';
import { VisibilityModel } from 'ng2-qgrid/core/visibility/visibility.model';

@Component({
	selector: 'q-grid',
	providers: [
		RootService,
		TemplateCacheService,
		TemplateService,
		ViewCoreService,
		Grid,
		TemplateLinkService,
		LayerService
	],
	styleUrls: ['../../assets/index.scss'],
	templateUrl: './grid.component.html',
	encapsulation: ViewEncapsulation.None
})
export class GridComponent extends RootComponent implements OnInit {
	@Input() model: GridModel;

	@Input('actions') actionItems: Array<Action>;

	@Input('header') gridTitle: string;
	@Input('caption') gridCaption: string;
	@Input('interactionMode') gridInteractionMode: 'full' | 'readonly' | 'detached';

	@Input('id') gridId: string;

	@Input('columns') dataColumns: Array<ColumnModel>;
	@Input('pipe') dataPipe: Array<(memo: any, context: PipeContext, next: (memo: any) => void) => any>;
	@Input('rows') dataRows: Array<any>;

	@Input() editCancel: Command;
	@Input() editCommit: Command;
	@Input() editEnter: Command;
	@Input() editMethod: null | 'batch';
	@Input() editMode: null | 'cell' | 'row';
	@Input() editReset: Command;

	@Input() filterFetch: (key: string, context: FetchContext) => any | Promise<any>;
	@Input() filterUnit: 'default' | 'row';

	@Input() groupBy: Array<string>;
	@Input() groupMode: 'nest' | 'column' | 'subhead' | 'rowspan';
	@Input() groupSummary: null | 'leaf';

	@Input() pivotBy: Array<string>;

	@Input('selection') selectionItems: Array<any>;
	@Input() selectionArea: 'custom' | 'body';
	@Input() selectionKey: {
		row: () => void,
		column: () => void
	};
	@Input() selectionMode: 'single' | 'multiple' | 'range' | 'singleOnly';
	@Input() selectionUnit: 'row' | 'cell' | 'column' | 'mix';

	@Input() scrollMode: 'default' | 'virtual';

	@Input() sortBy: Array<string>;
	@Input() sortMode: 'single' | 'multiple';
	@Input() sortTrigger: Array<string>;

	@Input() styleCell:
		(row: any, column: ColumnModel, context: StyleCellContext) => void
			| { [key: string]: (row: any, column: ColumnModel, context: any) => void };

	@Input() styleRow:
		(row: any, context: StyleRowContext) => void;

	themeComponent: any;

	constructor(
		private root: RootService,
		private elementRef: ElementRef,
		private zone: NgZone,
		private layerService: LayerService,
		private cd: ChangeDetectorRef,
		modelBuilder: ModelBuilderService,
		@Inject(DOCUMENT) private document: any,
		theme: ThemeService,
	) {
		super(modelBuilder);

		this.models = [
			'action',
			'data',
			'edit',
			'filter',
			'grid',
			'group',
			'pivot',
			'row',
			'selection',
			'scroll',
			'sort',
			'style'
		];

		this.modelChanged.watch(model => this.root.model = model);

		if (!theme.component) {
			throw new AppError(
				'grid.component',
				'Ensure that grid theme module was included'
			);
		}

		this.themeComponent = theme.component;
	}

	ngOnInit() {
		super.ngOnInit();

		const { model } = this.root;
		const { nativeElement } = this.elementRef;

		model.style({
			classList: Array.from(nativeElement.classList)
		});

		const ctrl = this.using(new GridCtrl(model, {
			layerFactory: () => this.layerService,
			element: nativeElement
		}));

		this.root.table = ctrl.table;
		this.root.bag = ctrl.bag;
		this.root.markup = ctrl.markup;

		this.root.commandManager = new TableCommandManager(
			f => f(),
			ctrl.table
		);

		const listener = new EventListener(nativeElement, new EventManager(this));
		const docListener = new EventListener(this.document, new EventManager(this));<commit_msg>Add source to style mutation<commit_after>import {
	Component,
	Input,
	ViewEncapsulation,
	OnInit,
	ElementRef,
	NgZone,
	Inject,
	ChangeDetectorRef
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { Action } from 'ng2-qgrid/core/action/action';
import { AppError } from 'ng2-qgrid/core/infrastructure/error';
import { ColumnModel } from 'ng2-qgrid/core/column-type/column.model';
import { Command } from 'ng2-qgrid/core/command/command';
import { EventListener } from 'ng2-qgrid/core/infrastructure/event.listener';
import { EventManager } from 'ng2-qgrid/core/infrastructure/event.manager';
import { eventPath } from 'ng2-qgrid/core/services/dom';
import { FetchContext } from 'ng2-qgrid/core/fetch/fetch.context';
import { Grid } from './grid.service';
import { GridCtrl } from 'ng2-qgrid/core/grid/grid.ctrl';
import { GridModel } from '../../plugins/plugin.service';
import { LayerService } from '../layer/layer.service';
import { ModelBuilderService } from '../model/model-builder.service';
import { noop } from 'ng2-qgrid/core/utility/kit';
import { PipeContext } from 'ng2-qgrid/core/pipe/pipe.item';
import { RootComponent } from '../../infrastructure/component/root.component';
import { RootService } from '../../infrastructure/component/root.service';
import { StyleRowContext, StyleCellContext } from 'ng2-qgrid/core/style/style.context';
import { TableCommandManager } from 'ng2-qgrid/core/command/table.command.manager';
import { TemplateCacheService } from '../../template/template-cache.service';
import { TemplateLinkService } from '../../template/template-link.service';
import { TemplateService } from '../../template/template.service';
import { ThemeService } from '../../template/theme.service';
import { ViewCoreService } from '../../main/core/view/view-core.service';
import { VisibilityModel } from 'ng2-qgrid/core/visibility/visibility.model';

@Component({
	selector: 'q-grid',
	providers: [
		RootService,
		TemplateCacheService,
		TemplateService,
		ViewCoreService,
		Grid,
		TemplateLinkService,
		LayerService
	],
	styleUrls: ['../../assets/index.scss'],
	templateUrl: './grid.component.html',
	encapsulation: ViewEncapsulation.None
})
export class GridComponent extends RootComponent implements OnInit {
	@Input() model: GridModel;

	@Input('actions') actionItems: Array<Action>;

	@Input('header') gridTitle: string;
	@Input('caption') gridCaption: string;
	@Input('interactionMode') gridInteractionMode: 'full' | 'readonly' | 'detached';

	@Input('id') gridId: string;

	@Input('columns') dataColumns: Array<ColumnModel>;
	@Input('pipe') dataPipe: Array<(memo: any, context: PipeContext, next: (memo: any) => void) => any>;
	@Input('rows') dataRows: Array<any>;

	@Input() editCancel: Command;
	@Input() editCommit: Command;
	@Input() editEnter: Command;
	@Input() editMethod: null | 'batch';
	@Input() editMode: null | 'cell' | 'row';
	@Input() editReset: Command;

	@Input() filterFetch: (key: string, context: FetchContext) => any | Promise<any>;
	@Input() filterUnit: 'default' | 'row';

	@Input() groupBy: Array<string>;
	@Input() groupMode: 'nest' | 'column' | 'subhead' | 'rowspan';
	@Input() groupSummary: null | 'leaf';

	@Input() pivotBy: Array<string>;

	@Input('selection') selectionItems: Array<any>;
	@Input() selectionArea: 'custom' | 'body';
	@Input() selectionKey: {
		row: () => void,
		column: () => void
	};
	@Input() selectionMode: 'single' | 'multiple' | 'range' | 'singleOnly';
	@Input() selectionUnit: 'row' | 'cell' | 'column' | 'mix';

	@Input() scrollMode: 'default' | 'virtual';

	@Input() sortBy: Array<string>;
	@Input() sortMode: 'single' | 'multiple';
	@Input() sortTrigger: Array<string>;

	@Input() styleCell:
		(row: any, column: ColumnModel, context: StyleCellContext) => void
			| { [key: string]: (row: any, column: ColumnModel, context: any) => void };

	@Input() styleRow:
		(row: any, context: StyleRowContext) => void;

	themeComponent: any;

	constructor(
		private root: RootService,
		private elementRef: ElementRef,
		private zone: NgZone,
		private layerService: LayerService,
		private cd: ChangeDetectorRef,
		modelBuilder: ModelBuilderService,
		@Inject(DOCUMENT) private document: any,
		theme: ThemeService,
	) {
		super(modelBuilder);

		this.models = [
			'action',
			'data',
			'edit',
			'filter',
			'grid',
			'group',
			'pivot',
			'row',
			'selection',
			'scroll',
			'sort',
			'style'
		];

		this.modelChanged.watch(model => this.root.model = model);

		if (!theme.component) {
			throw new AppError(
				'grid.component',
				'Ensure that grid theme module was included'
			);
		}

		this.themeComponent = theme.component;
	}

	ngOnInit() {
		super.ngOnInit();

		const { model } = this.root;
		const { nativeElement } = this.elementRef;

		model.style({
			classList: Array.from(nativeElement.classList)
		}, {
			source: 'grid'
		});

		const ctrl = this.using(new GridCtrl(model, {
			layerFactory: () => this.layerService,
			element: nativeElement
		}));

		this.root.table = ctrl.table;
		this.root.bag = ctrl.bag;
		this.root.markup = ctrl.markup;

		this.root.commandManager = new TableCommandManager(
			f => f(),
			ctrl.table
		);

		const listener = new EventListener(nativeElement, new EventManager(this));
		const docListener = new EventListener(this.document, new EventManager(this));
{'fraction_non_alphanumeric': 0.16446872645064053, 'fraction_numerical': 0.0026375282592313487, 'mean_word_length': 4.599683544303797, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, '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': '7302403', 'n_tokens_mistral': 3612, 'n_tokens_neox': 3395, 'n_words': 787}