feat: Add context menu functionality for PDF components with options to view, copy URL, and download

This commit is contained in:
2025-09-20 11:54:37 +00:00
parent a61f57db13
commit 7b5ba74d8b
3 changed files with 149 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
import { DeesElement, property, html, customElement, domtools, type TemplateResult, type CSSResult, } from '@design.estate/dees-element';
import { Deferred } from '@push.rocks/smartpromise';
import { DeesContextmenu } from '../dees-contextmenu.js';
import '../dees-icon.js';
// import type pdfjsTypes from 'pdfjs-dist';
@@ -26,6 +28,8 @@ export class DeesPdf extends DeesElement {
public pdfUrl: string =
'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf';
constructor() {
super();
@@ -49,9 +53,15 @@ export class DeesPdf extends DeesElement {
#pdfcanvas {
box-shadow: 0px 0px 5px #ccc;
width: 100%;
cursor: pointer;
}
</style>
<canvas id="pdfcanvas" .height=${0} .width=${0}></canvas>
<canvas
id="pdfcanvas"
.height=${0}
.width=${0}
></canvas>
`;
}
@@ -69,6 +79,8 @@ export class DeesPdf extends DeesElement {
}
await DeesPdf.pdfJsReady;
this.displayContent();
}
public async displayContent() {
@@ -112,4 +124,37 @@ export class DeesPdf extends DeesElement {
}
);
}
/**
* Provide context menu items for the global context menu handler
*/
public getContextMenuItems() {
return [
{
name: 'Open PDF in New Tab',
iconName: 'lucide:ExternalLink',
action: async () => {
window.open(this.pdfUrl, '_blank');
}
},
{ divider: true },
{
name: 'Copy PDF URL',
iconName: 'lucide:Copy',
action: async () => {
await navigator.clipboard.writeText(this.pdfUrl);
}
},
{
name: 'Download PDF',
iconName: 'lucide:Download',
action: async () => {
const link = document.createElement('a');
link.href = this.pdfUrl;
link.download = this.pdfUrl.split('/').pop() || 'document.pdf';
link.click();
}
}
];
}
}