@@ -3,16 +3,16 @@ import {css, customElement, html, LitElement, property, repeat, state} from '@um
33import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api' ;
44import { UmbSorterController } from '@umbraco-cms/backoffice/sorter' ;
55import { UMB_LINK_PICKER_MODAL , UmbLinkPickerLink } from '@umbraco-cms/backoffice/multi-url-picker' ;
6- import { UMB_MEDIA_PICKER_MODAL } from '@umbraco-cms/backoffice/media' ;
6+ import { UMB_MEDIA_PICKER_MODAL } from '@umbraco-cms/backoffice/media' ;
77import './umbnav-item.ts' ;
88import UmbNavItem from './umbnav-item.ts' ;
99import { UMB_MODAL_MANAGER_CONTEXT , UmbModalManagerContext , } from '@umbraco-cms/backoffice/modal' ;
1010import { v4 as uuidv4 } from 'uuid' ;
11- import { UmbPropertyValueChangeEvent , UmbPropertyEditorConfigProperty } from "@umbraco-cms/backoffice/property-editor" ;
11+ import { UmbPropertyEditorConfigProperty , UmbPropertyValueChangeEvent } from "@umbraco-cms/backoffice/property-editor" ;
1212import { DocumentService , MediaService } from '@umbraco-cms/backoffice/external/backend-api' ;
1313import { UMBNAV_TEXT_ITEM_MODAL } from "./modals/text-item-modal-token.ts" ;
14- import { UMBNAV_VISIBILITY_ITEM_MODAL } from "./modals/visibility-item-modal-token.ts" ;
15- import { UMBNAV_SETTINGS_ITEM_MODAL } from "./modals/settings-item-modal-token.ts" ;
14+ import { UMBNAV_VISIBILITY_ITEM_MODAL } from "./modals/visibility-item-modal-token.ts" ;
15+ import { UMBNAV_SETTINGS_ITEM_MODAL } from "./modals/settings-item-modal-token.ts" ;
1616import { Guid , ImageItem , ModelEntryType } from "./umbnav.token.ts" ;
1717
1818@customElement ( 'umbnav-group' )
@@ -37,6 +37,16 @@ export class UmbNavGroup extends UmbElementMixin(LitElement) {
3737 this . requestUpdate ( 'value' , oldValue ) ;
3838 this . #dispatchChangeEvent( ) ;
3939 } ,
40+ onRequestMove : ( { item} ) => {
41+ if ( this . maxDepth === 0 ) {
42+ return true ;
43+ }
44+
45+ if ( item . children ) {
46+ return this . depth + this . #calculateTotalDepth( item . children ) <= this . maxDepth ;
47+ }
48+
49+ return this . depth <= this . maxDepth ; }
4050 } ) ;
4151
4252 @state ( )
@@ -53,6 +63,17 @@ export class UmbNavGroup extends UmbElementMixin(LitElement) {
5363 @property ( { type : Boolean , reflect : true } )
5464 nested : boolean = false ;
5565
66+ @property ( { type : Number , reflect : true } )
67+ depth : number = 0 ;
68+
69+ @state ( )
70+ disallowed : boolean = false ;
71+
72+ @state ( )
73+ public get maxDepth ( ) : number {
74+ return < number > this . config ?. find ( item => item . alias === 'maxDepth' ) ?. value ?? 0 ;
75+ }
76+
5677 @property ( { type : Boolean , reflect : true } )
5778 public get expandAll ( ) : boolean {
5879 return this . _expandAll ;
@@ -106,6 +127,15 @@ export class UmbNavGroup extends UmbElementMixin(LitElement) {
106127 } ) ;
107128 }
108129
130+ #calculateTotalDepth( children : ModelEntryType [ ] ) : number {
131+ if ( ! children || children . length === 0 ) {
132+ return 0 ;
133+ }
134+ return children . reduce ( ( total , child ) => {
135+ return total + 1 + this . #calculateTotalDepth( child . children ) ;
136+ } , 0 ) ;
137+ }
138+
109139 removeItem = ( event : CustomEvent < { key : string } > ) => {
110140 const { key} = event . detail ;
111141
@@ -569,9 +599,10 @@ export class UmbNavGroup extends UmbElementMixin(LitElement) {
569599 @remove-node-event = ${ this . removeItem } >
570600 <umbnav- group
571601 ?nested= ${ true }
572- class= "${ this . expandAll || item . key != null && this . expandedItems . includes ( item . key ) ? 'expanded' : 'collapsed' } "
602+ class= "${ this . expandAll || item . key != null && this . expandedItems . includes ( item . key ) ? 'expanded' : 'collapsed' } ${ this . disallowed ? 'disallowed' : '' } "
573603 .config = ${ this . config }
574604 .value = ${ item . children }
605+ .depth = ${ this . depth + 1 }
575606 @change = ${ ( e : Event ) => {
576607 item = { ...item , children : ( e . target as UmbNavGroup ) . value } ;
577608 this . updateItem ( item ) ;
@@ -642,6 +673,32 @@ export class UmbNavGroup extends UmbElementMixin(LitElement) {
642673 padding-top : 1px ;
643674 padding-bottom : 3px ;
644675 }
676+
677+ .disallowed {
678+ cursor : not-allowed;
679+ background : red;
680+ }
681+
682+ : host ([disallow-drop ])::before {
683+ content : '' ;
684+ position : absolute;
685+ z-index : 1 ;
686+ inset : 0 ;
687+ border : 2px solid var (--uui-color-danger );
688+ border-radius : calc (var (--uui-border-radius ) * 2 );
689+ pointer-events : none;
690+ }
691+
692+ : host ([disallow-drop ])::after {
693+ content : '' ;
694+ position : absolute;
695+ z-index : 1 ;
696+ inset : 0 ;
697+ border-radius : calc (var (--uui-border-radius ) * 2 );
698+ background-color : var (--uui-color-danger );
699+ opacity : 0.2 ;
700+ pointer-events : none;
701+ }
645702 ` ,
646703 ] ;
647704}
0 commit comments