Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext Clipboard Handlers

From Leeroopedia
Knowledge Sources
Domains Editor, Clipboard, React
Last Updated 2026-10-24 00:00 GMT

Overview

⚠ DEPRECATED: Custom copy and paste event handlers for the legacy Plate editor, providing clean markdown serialization on copy and markdown-to-nodes deserialization on paste. Only imported by the dead PlateMarkdown component. See Heuristic:0xranx_OpenContext_Warning_Deprecated_Plate_Editor.

Description

The clipboardHandlers.js module in src/ui/src/editor/ exports createCopyHandler and createPasteHandler. The copy handler prevents default DOM copying, serializes the selected Slate fragment to markdown via a provided serializer, and writes to both the Web Clipboard API and Tauri-compatible clipboard. The paste handler detects markdown syntax in pasted text, and if found, deserializes it to Plate nodes via a provided deserializer and inserts them as a fragment. Rich HTML without markdown syntax is left to Plate's default handling.

Usage

Import these factory functions in PlateMarkdown.jsx to attach custom clipboard behavior to the Plate editor.

Code Reference

Source Location

Signature

export function createCopyHandler(editor, serializeMarkdown) // → (event) => void
export function createPasteHandler(editor, deserializeMarkdown, Transforms, options = {}) // → (event) => void

Import

import { createCopyHandler, createPasteHandler } from './editor/clipboardHandlers';

I/O Contract

Inputs

Name Type Required Description
editor PlateEditor Yes Plate/Slate editor instance
serializeMarkdown Function Yes (copy) Serializes fragment to markdown string
deserializeMarkdown Function Yes (paste) Deserializes markdown to Plate nodes
Transforms object Yes (paste) Slate Transforms for insertFragment
options.onError Function No Error callback for paste failures

Usage Examples

Attaching to Plate Editor

import { createCopyHandler, createPasteHandler } from './editor/clipboardHandlers';
import { Transforms } from 'slate';

const copyHandler = createCopyHandler(editor, serializeMarkdown);
const pasteHandler = createPasteHandler(editor, deserializeMarkdown, Transforms, {
  onError: (err) => showToast('Paste failed'),
});

// Attach to DOM
editorEl.addEventListener('copy', copyHandler);
editorEl.addEventListener('paste', pasteHandler);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment