@progress/kendo-angular-treeview
Version:
Kendo UI TreeView for Angular
77 lines (76 loc) • 4.01 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* 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";
/**
* Represents the directive that enables you to update the initially provided data array during drag-and-drop.
*
* Use this directive 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.
*
* Providing a custom `editService` allows you to handle the
* [`addItem`](slug:api_treeview_treeviewcomponent#additem) and [`removeItem`](slug:api_treeview_treeviewcomponent#removeitem)
* events when they are triggered by the TreeView component.
*
* @example
* ```html
* <kendo-treeview
* kendoTreeViewDragAndDrop
* kendoTreeViewDragAndDropEditing
* [nodes]="nodes"
* textField="text">
* </kendo-treeview>
* ```
*
* @remarks
* Applied to: {@link TreeViewComponent}
*/
export class DragAndDropEditingDirective {
treeview;
/**
* Specifies the handlers called on drag-and-drop [`addItem`](slug:api_treeview_treeviewcomponent#additem)
* and [`removeItem`](slug:api_treeview_treeviewcomponent#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
}] } });