UNPKG

@progress/kendo-angular-spreadsheet

Version:

A Spreadsheet Component for Angular

73 lines (72 loc) 3.8 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive } from '@angular/core'; import { Subscription } from 'rxjs'; import { ToolBarDropDownButtonComponent } from '@progress/kendo-angular-toolbar'; import { SpreadsheetLocalizationService } from '../../localization/spreadsheet-localization.service'; import { SpreadsheetService } from '../../common/spreadsheet.service'; import { commandIcons, commandSVGIcons } from '../shared/command-icons'; import { MERGE } from '../shared/constants'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-toolbar"; import * as i2 from "../../localization/spreadsheet-localization.service"; import * as i3 from "../../common/spreadsheet.service"; /** * @hidden */ export class SpreadsheetMergeDirective { host; spreadsheetService; commandName = 'merge'; subs = new Subscription(); selectedRange; constructor(host, localization, spreadsheetService) { this.host = host; this.spreadsheetService = spreadsheetService; host.svgIcon = commandSVGIcons[this.commandName]; host.icon = commandIcons[this.commandName]; host.arrowIcon = true; host.fillMode = 'flat'; host.data = MERGE.map(item => ({ ...item, textKey: localization.get(item.commandId) })); this.subs.add(host.itemClick.subscribe((e) => this.onItemClick(e))); host.title = localization.get(this.commandName); host.textField = 'textKey'; } ngOnInit() { this.subs.add(this.host.open.subscribe(() => { const sheet = this.spreadsheetService.spreadsheet.activeSheet(); const isMergedCellWithinRange = this.hasMergedCells(sheet); const unmergeItem = this.host.data.find(i => i.commandName === 'unmerge'); unmergeItem.disabled = !isMergedCellWithinRange; })); this.subs.add(this.spreadsheetService.selectionChanged.subscribe(range => this.selectedRange = range)); } ngOnDestroy() { this.subs.unsubscribe(); } onItemClick(item) { if (item.disabled) { return; } const value = item.value || null; const options = { command: 'MergeCellCommand', options: { property: item.commandName, value } }; this.spreadsheetService.spreadsheet.executeCommand(options); } hasMergedCells(sheet) { const range = sheet._ref(this.selectedRange); return sheet._getMergedCells(range).hasMerged; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SpreadsheetMergeDirective, deps: [{ token: i1.ToolBarDropDownButtonComponent }, { token: i2.SpreadsheetLocalizationService }, { token: i3.SpreadsheetService }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: SpreadsheetMergeDirective, isStandalone: true, selector: "[kendoSpreadsheetMerge]", ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: SpreadsheetMergeDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoSpreadsheetMerge]', standalone: true }] }], ctorParameters: function () { return [{ type: i1.ToolBarDropDownButtonComponent }, { type: i2.SpreadsheetLocalizationService }, { type: i3.SpreadsheetService }]; } });