Clipboard.ts
Clipboard.ts overview
Section titled “Clipboard.ts overview”Browser clipboard integration for Effect programs.
This module defines the Clipboard service, the ClipboardError raised by
failed browser operations, a make constructor for custom implementations,
and a browser-backed layer that uses navigator.clipboard. The service
supports reading and writing text, reading and writing ClipboardItem
payloads, writing one Blob, and clearing the clipboard.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Builds a Clipboard service from primitive read and write operations, deriving clear and writeBlob helpers.
Signature
declare const make: (impl: Omit<Clipboard, "clear" | "writeBlob" | typeof TypeId>) => ClipboardSince v4.0.0
errors
Section titled “errors”ClipboardError (class)
Section titled “ClipboardError (class)”Tagged error raised when a browser clipboard operation fails.
Signature
declare class ClipboardErrorSince v4.0.0
[ErrorTypeId] (property)
Section titled “[ErrorTypeId] (property)”Signature
readonly [ErrorTypeId]: "~@effect/platform-browser/Clipboard/ClipboardError"layers
Section titled “layers”Layer that directly interfaces with the browser Clipboard API.
Signature
declare const layer: Layer.Layer<Clipboard, never, never>Since v4.0.0
models
Section titled “models”Clipboard (interface)
Section titled “Clipboard (interface)”Defines the service interface for reading from, writing to, and clearing the browser clipboard.
When to use
Use when an application needs clipboard operations through an Effect service so browser failures stay in the error channel.
Details
read and write work with ClipboardItem arrays. readString and
writeString use text, writeBlob writes one Blob, and clear writes an
empty string.
Gotchas
Clipboard access generally requires a secure context and may require user
activation, permissions, or a focused document. ClipboardItem and non-text
MIME type support varies by browser. Failed browser operations are surfaced
as ClipboardError.
Signature
export interface Clipboard { readonly [TypeId]: typeof TypeId readonly read: Effect.Effect<ClipboardItems, ClipboardError> readonly readString: Effect.Effect<string, ClipboardError> readonly write: (items: ClipboardItems) => Effect.Effect<void, ClipboardError> readonly writeString: (text: string) => Effect.Effect<void, ClipboardError> readonly writeBlob: (blob: Blob) => Effect.Effect<void, ClipboardError> readonly clear: Effect.Effect<void, ClipboardError>}Since v4.0.0
services
Section titled “services”Clipboard
Section titled “Clipboard”Service tag for browser clipboard capabilities.
When to use
Use when you need to require or provide clipboard capabilities through Effect’s context.
See
makefor building a custom clipboard servicelayerfor providing the browser-backed clipboard service
Signature
declare const Clipboard: Context.Service<Clipboard, Clipboard>Since v4.0.0