Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/RightClicker/Client/src/bundle.manifests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { manifests as entrypoints } from "./entrypoints/manifest.js";
import { manifests as entrypoints } from "./entrypoints/manifest.ts";
import { manifests as permissions } from "./permissions/manifest.ts";

// Job of the bundle is to collate all the manifests from different parts of the extension and load other manifests
// We load this bundle from umbraco-package.json
export const manifests: Array<UmbExtensionManifest> = [
...entrypoints
...entrypoints,
...permissions
];
84 changes: 64 additions & 20 deletions src/RightClicker/Client/src/entrypoints/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,75 @@ import type {
UmbEntryPointOnInit,
UmbEntryPointOnUnload,
} from "@umbraco-cms/backoffice/extension-api";
import { UMB_CURRENT_USER_CONTEXT } from "@umbraco-cms/backoffice/current-user";

let rightClickMenuEnabled = false;

function rightClickMenuHandler(e: MouseEvent) {
const path = e.composedPath();
const menuItem = path.find(
(el): el is Element => el instanceof Element && el.tagName === 'UUI-MENU-ITEM'
);
if (menuItem) {
e.preventDefault();
let el: Element | null | undefined = menuItem;
el = el.querySelector('umb-entity-actions-bundle');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('uui-action-bar');
if (!el) return;
el = el.querySelector('umb-entity-actions-dropdown');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('umb-dropdown');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('uui-button');
if (!el) return;
(el as HTMLElement).click();
}
}

function enableRightClickMenu() {
if (!rightClickMenuEnabled) {
document.body.addEventListener('contextmenu', rightClickMenuHandler);
rightClickMenuEnabled = true;
}
}

function disableRightClickMenu() {
if (rightClickMenuEnabled) {
document.body.removeEventListener('contextmenu', rightClickMenuHandler);
rightClickMenuEnabled = false;
}
}

export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => {
document.body.addEventListener('contextmenu', function(e) {
const path = e.composedPath();
const menuItem = path.find(
(el): el is Element => el instanceof Element && el.tagName === 'UUI-MENU-ITEM'
);
if (menuItem) {
e.preventDefault();
// Traverse from menuItem as before
let el: Element | null | undefined = menuItem;
el = el.querySelector('umb-entity-actions-bundle');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('uui-action-bar');
if (!el) return;
el = el.querySelector('umb-entity-actions-dropdown');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('umb-dropdown');
if (!el) return;
el = (el as HTMLElement).shadowRoot?.querySelector('uui-button');
if (!el) return;
(el as HTMLElement).click();
_host.consumeContext(UMB_CURRENT_USER_CONTEXT, (currentUserCtx) => {
let userPermissions: string[] | undefined;
let fallbackPermissions: string[] | undefined;

function evaluatePermissions() {
const hasPermission =
(userPermissions?.includes('RightClicker') ?? false) ||
(fallbackPermissions?.includes('RightClicker') ?? false);

if (hasPermission) {
enableRightClickMenu();
} else {
disableRightClickMenu();
}
}

_host.observe(currentUserCtx?.permissions, (newPermissions) => {
userPermissions = newPermissions as string[] | undefined;
evaluatePermissions();
});

_host.observe(currentUserCtx?.fallbackPermissions, (newFallbacks) => {
fallbackPermissions = newFallbacks;
evaluatePermissions();
});
});
};

export const onUnload: UmbEntryPointOnUnload = (_host, _extensionRegistry) => {
disableRightClickMenu();
};
16 changes: 16 additions & 0 deletions src/RightClicker/Client/src/permissions/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { UMB_DOCUMENT_ENTITY_TYPE } from "@umbraco-cms/backoffice/document";

export const manifests: Array<UmbExtensionManifest> = [
{
type: "entityUserPermission",
alias: "RightClicker.Permission",
name: "RightClicker permission",
forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
meta: {
group: "RightClicker",
label: "Enable old style right clicking context menus",
description: "Gives the user access to right clicking to bring up the context menu in trees",
verbs: ["RightClicker"]
}
},
];

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

23 changes: 19 additions & 4 deletions src/RightClicker/wwwroot/App_Plugins/RightClicker/right-clicker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.