UNPKG

@progress/kendo-angular-treeview

Version:
62 lines (61 loc) 3.84 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, Input } from '@angular/core'; import { Subscription } from 'rxjs'; import { TreeViewComponent } from '../treeview.component'; import { isPresent } from '../utils'; import * as i0 from "@angular/core"; import * as i1 from "../treeview.component"; /** * A directive which enables the update of the initially provided data array during drag-and-drop. * * Either use this directive in combination with one of the data binding directives ([`kendoTreeViewHierarchyBinding`]({% slug api_treeview_hierarchybindingdirective %}) * or [`kendoTreeViewFlatDataBinding`]({% slug api_treeview_flatdatabindingdirective %})) which set their own edit handlers, or provide * your own [`editService`]({% slug api_treeview_editservice %}) to this directive. The latter subscribes to and calls the * [`addItem`]({% slug api_treeview_treeviewcomponent %}#toc-additem) and [`removeItem`]({% slug api_treeview_treeviewcomponent %}#toc-removeitem) * handlers when the corresponding events are triggered by the TreeView component. */ export class DragAndDropEditingDirective { treeview; /** * Specifies the handlers called on drag-and-drop [`addItem`]({% slug api_treeview_treeviewcomponent %}#toc-additem) * and [`removeItem`]({% slug api_treeview_treeviewcomponent %}#toc-removeitem) events. */ set editService(service) { this.treeview.editService = service; } subscriptions = new Subscription(); constructor(treeview) { this.treeview = treeview; this.subscriptions.add(this.treeview.addItem.subscribe(this.handleAdd.bind(this))); this.subscriptions.add(this.treeview.removeItem.subscribe(this.handleRemove.bind(this))); } ngOnDestroy() { this.subscriptions.unsubscribe(); } handleAdd(args) { if (!isPresent(this.treeview.editService)) { throw new Error('No `editService` provided. Either provide your own implementation or use this directive in combination with one of the data binding directives (`kendoTreeViewHierarchyBinding` or `kendoTreeViewFlatDataBinding`).'); } this.treeview.editService.add(args); } handleRemove(args) { if (!isPresent(this.treeview.editService)) { throw new Error('No `editService` provided. Either provide your own implementation or use this directive in combination with one of the data binding directives (`kendoTreeViewHierarchyBinding` or `kendoTreeViewFlatDataBinding`).'); } this.treeview.editService.remove(args); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DragAndDropEditingDirective, deps: [{ token: i1.TreeViewComponent }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: DragAndDropEditingDirective, isStandalone: true, selector: "[kendoTreeViewDragAndDropEditing]", inputs: { editService: "editService" }, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DragAndDropEditingDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoTreeViewDragAndDropEditing]', standalone: true }] }], ctorParameters: function () { return [{ type: i1.TreeViewComponent }]; }, propDecorators: { editService: [{ type: Input }] } });