You've already forked joplin
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:
@@ -1,5 +1,7 @@
|
||||
/* eslint-disable multiline-comment-style */
|
||||
|
||||
import { ClipboardContent } from './types';
|
||||
|
||||
export default class JoplinClipboard {
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -588,6 +588,30 @@ export interface SettingSection {
|
||||
*/
|
||||
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
|
||||
// =================================================================
|
||||
|
||||
Reference in New Issue
Block a user