1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Desktop: Add write() method to Plugin Clipboard API (#13348)

This commit is contained in:
bwat47
2025-10-06 04:31:27 -04:00
committed by GitHub
parent 6fdfd6eae6
commit fd180ae0b4
2 changed files with 61 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
/* eslint-disable multiline-comment-style */ /* eslint-disable multiline-comment-style */
import { ClipboardContent } from './types';
export default class JoplinClipboard { export default class JoplinClipboard {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
@@ -59,4 +61,39 @@ export default class JoplinClipboard {
return this.electronClipboard_.availableFormats(); return this.electronClipboard_.availableFormats();
} }
/**
* Writes multiple formats to the clipboard simultaneously.
* This allows setting both text/plain and text/html at the same time.
*
* <span class="platform-desktop">desktop</span>
*
* @example
* ```typescript
* await joplin.clipboard.write({
* text: 'Plain text version',
* html: '<strong>HTML version</strong>'
* });
* ```
*/
public async write(content: ClipboardContent): Promise<void> {
const clipboardData: Record<string, unknown> = {};
if (content.text !== undefined) {
clipboardData.text = content.text;
}
if (content.html !== undefined) {
clipboardData.html = content.html;
}
if (content.image !== undefined) {
clipboardData.image = this.electronNativeImage_.createFromDataURL(content.image);
}
// Only write to clipboard if there's actually data to write
if (Object.keys(clipboardData).length > 0) {
this.electronClipboard_.write(clipboardData);
}
}
} }

View File

@@ -588,6 +588,30 @@ export interface SettingSection {
*/ */
export type Path = string[]; export type Path = string[];
// =================================================================
// Clipboard API types
// =================================================================
/**
* Represents content that can be written to the clipboard in multiple formats.
*/
export interface ClipboardContent {
/**
* Plain text representation of the content
*/
text?: string;
/**
* HTML representation of the content
*/
html?: string;
/**
* Image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format
*/
image?: string;
}
// ================================================================= // =================================================================
// Content Script types // Content Script types
// ================================================================= // =================================================================