Skip to content

Commit 4b3b549

Browse files
committed
Merge branch 'Umbraco-V15' into develop
2 parents 0c806b1 + fee81b3 commit 4b3b549

File tree

5 files changed

+93
-10
lines changed

5 files changed

+93
-10
lines changed

Umbraco.Community.UmbNav.Core/Extensions/UmbNavItemExtensions.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,24 @@ public static string Url(this UmbNavItem item, string? culture = null, UrlMode m
117117
return item.Url ?? "#";
118118
}
119119

120-
public static bool IsActive(this UmbNavItem item, IPublishedContent currentPage, bool checkAncestors = false)
120+
public static bool IsActive(this UmbNavItem item, IPublishedContent currentPage, bool checkAncestors = false, int? minLevel = null)
121121
{
122-
if (item.ContentKey == currentPage.Key)
122+
var contentKey = item.ContentKey ?? item.Content?.Key;
123+
124+
if (contentKey is null || currentPage is null) return false;
125+
126+
var key = currentPage.Key;
127+
128+
if (contentKey == key)
123129
{
124130
return true;
125131
}
132+
133+
if (minLevel.HasValue && currentPage.Level > minLevel)
134+
{
135+
return currentPage.Ancestors().Any(x => x.Level >= minLevel
136+
&& x.Key == contentKey.GetValueOrDefault());
137+
}
126138

127139
if (checkAncestors)
128140
{

Umbraco.Community.UmbNav/src/manifest.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ const umbNavPropertyEditorUiManifest: ManifestPropertyEditorUi = {
5454
label : "Hide noreferrer Toggle",
5555
description : "Hide the ability to toggle noreferrer",
5656
propertyEditorUiAlias : "Umb.PropertyEditorUi.Toggle"
57-
}
57+
},
58+
{
59+
alias : "maxDepth",
60+
label : "Max Depth",
61+
description : "The maximum number of levels in the navigation",
62+
propertyEditorUiAlias : "Umb.PropertyEditorUi.Integer"
63+
}
5864
],
5965
defaultData : [
6066
{
@@ -84,7 +90,11 @@ const umbNavPropertyEditorUiManifest: ManifestPropertyEditorUi = {
8490
{
8591
alias : "hideNoreferrer",
8692
value : false
87-
}
93+
},
94+
{
95+
alias : "maxDepth",
96+
value : 0
97+
}
8898
]
8999
}
90100
}

Umbraco.Community.UmbNav/src/umbnav-group.ts

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import {css, customElement, html, LitElement, property, repeat, state} from '@um
33
import {UmbElementMixin} from '@umbraco-cms/backoffice/element-api';
44
import {UmbSorterController} from '@umbraco-cms/backoffice/sorter';
55
import {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';
77
import './umbnav-item.ts';
88
import UmbNavItem from './umbnav-item.ts';
99
import {UMB_MODAL_MANAGER_CONTEXT, UmbModalManagerContext,} from '@umbraco-cms/backoffice/modal';
1010
import {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";
1212
import {DocumentService, MediaService} from '@umbraco-cms/backoffice/external/backend-api';
1313
import {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";
1616
import {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
}

Umbraco.Community.UmbNav/src/umbnav-property-editor-ui.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export default class UmbNavSorterPropertyEditorUIElement extends UmbElementMixin
1919
@property({ attribute: false })
2020
config: UmbPropertyEditorConfigCollection | undefined;
2121

22+
@property()
23+
depth: number = 0;
24+
2225
@state()
2326
public get enableToggleAllButton(): Boolean {
2427
return <Boolean>this.config?.find(item => item.alias === 'enableToggleAllButton')?.value ?? false;
@@ -53,6 +56,7 @@ export default class UmbNavSorterPropertyEditorUIElement extends UmbElementMixin
5356
.expandAll=${this.expandAll}
5457
.config=${this.config ?? [] as Array<UmbPropertyEditorConfigProperty>}
5558
.value=${this.value === undefined ? [] : this.value}
59+
.depth=${this.depth}
5660
@toggle-expandall-event=${this.toggleAllNodesEvent}
5761
@change=${this.onChange}></umbnav-group>
5862
</div>

Umbraco.Community.UmbNav/src/umbnav.token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type ModelEntryType = {
2424
hideLoggedIn?: boolean | null | undefined,
2525
hideLoggedOut?: boolean | null | undefined,
2626
noopener?: string | null | undefined,
27-
noreferrer?: string | null | undefined,
27+
noreferrer?: string | null | undefined
2828
}
2929

3030
export type ImageItem = {

0 commit comments

Comments
 (0)