@progress/kendo-angular-menu
Version:
Kendo UI Angular Menu component
140 lines (139 loc) • 5.18 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 { MenuBase } from '../menu-base';
import { BindingDirectiveBase } from './binding-directive-base';
import { getter } from './utils';
import * as i0 from "@angular/core";
import * as i1 from "../menu-base";
/**
* Represents a directive that converts the provided flat data to [MenuItems]({% slug api_menu_menuitem %}) and binds them to the Menu.
*
* @example
* ```html
* <kendo-menu [kendoMenuFlatBinding]="flatData" [textField]="'text'" [idField]="'id'" [parentIdField]="'parentId'">
* </kendo-menu>
* ```
*
* @remarks
* Applied to: {@link MenuComponent}.
*/
export class FlatBindingDirective extends BindingDirectiveBase {
/**
* Specifies the array of data which will be used to populate the Menu.
*/
data;
/**
* Defines the `text` field of the items.
*/
textField;
/**
* Defines the `url` field of the items.
*/
urlField;
/**
* Defines the `icon` field of the items.
*/
iconField;
/**
* Defines the `svgIcon` field of the items.
*/
svgIconField;
/**
* Defines the `disabled` field of the items.
*/
disabledField;
/**
* Defines the `cssClass` field of the items.
*/
cssClassField;
/**
* Defines the `cssStyle` field of the items.
*/
cssStyleField;
/**
* Defines the `separator` field of the items.
*/
separatorField;
/**
* Defines the `id` field of the items.
*/
idField;
/**
* Defines the parent `id` field of the items.
*/
parentIdField;
constructor(menu) {
super(menu);
}
mapItems(items) {
if (!this.idField || !this.parentIdField) {
return items.map(item => this.createItem(item));
}
const result = [];
const map = {};
for (let idx = 0; idx < items.length; idx++) {
const item = items[idx];
const menuItem = this.createItem(item);
const id = getter(this.idField)(item);
const parentId = getter(this.parentIdField)(item);
if (parentId === null || parentId === undefined) {
result.push(menuItem);
}
else {
const parent = map[parentId] = map[parentId] || {};
parent.items = parent.items || [];
parent.items.push(menuItem);
}
if (map[id]) {
menuItem.items = map[id].items;
}
map[id] = menuItem;
}
return result;
}
createItem(dataItem) {
const result = { data: dataItem };
const fields = this.fields;
for (let idx = 0; idx < fields.length; idx++) {
const { source, target } = fields[idx];
result[target] = getter(source)(dataItem);
}
return result;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FlatBindingDirective, deps: [{ token: i1.MenuBase }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: FlatBindingDirective, isStandalone: true, selector: "[kendoMenuFlatBinding]", inputs: { data: ["kendoMenuFlatBinding", "data"], textField: "textField", urlField: "urlField", iconField: "iconField", svgIconField: "svgIconField", disabledField: "disabledField", cssClassField: "cssClassField", cssStyleField: "cssStyleField", separatorField: "separatorField", idField: "idField", parentIdField: "parentIdField" }, exportAs: ["kendoMenuFlatBinding"], usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FlatBindingDirective, decorators: [{
type: Directive,
args: [{
exportAs: 'kendoMenuFlatBinding',
selector: '[kendoMenuFlatBinding]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i1.MenuBase }]; }, propDecorators: { data: [{
type: Input,
args: ["kendoMenuFlatBinding"]
}], textField: [{
type: Input
}], urlField: [{
type: Input
}], iconField: [{
type: Input
}], svgIconField: [{
type: Input
}], disabledField: [{
type: Input
}], cssClassField: [{
type: Input
}], cssStyleField: [{
type: Input
}], separatorField: [{
type: Input
}], idField: [{
type: Input
}], parentIdField: [{
type: Input
}] } });