Back to Tldraw

Clipboard events

apps/examples/src/examples/data/assets/clipboard-events/README.md

5.2.4828 B
Original Source

Intercept clipboard copy, cut, and paste using onBeforeCopyToClipboard and onBeforePasteFromClipboard.


This example shows how to filter or cancel clipboard operations. The hooks run for both keyboard shortcuts and menu actions.

  • onBeforeCopyToClipboard — Receives serialized TLContent plus operation ('copy' | 'cut') and source ('native' | 'menu'). Return a modified TLContent to change what is written, or false to cancel the write (for cut, the selection is not removed).

  • onBeforePasteFromClipboard — Runs when pasted content is about to be applied. Receives source ('native-event' | 'clipboard-read'). Return false to cancel, or a modified TLExternalContent to transform. This hook applies to clipboard paste only, not file drops or other putExternalContent calls.