react-smart-copy 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,97 @@
1
1
 
2
- import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
2
+ import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, DragEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
3
+ //#region src/core/paste-reader.d.ts
4
+ /** Friendly names for the common cases. */
5
+ type PasteAcceptShorthand = 'text' | 'html' | 'image' | 'any';
6
+ /**
7
+ * What a paste may contain, in any order: a shorthand, an exact MIME type
8
+ * (`'image/png'`) or a wildcard (`'image/*'`, `'*\/*'`).
9
+ * `image/svg+xml` is only accepted when listed exactly (it is scriptable XML).
10
+ */
11
+ type PasteAccept = PasteAcceptShorthand | `${string}/${string}`;
12
+ interface PasteLimits {
13
+ /**
14
+ * Total size cap across all accepted items, in UTF-8 bytes. Strings are measured as
15
+ * they would be encoded, matching `Blob.size`, so every paste path counts the same way.
16
+ * Default 32 MiB.
17
+ */
18
+ readonly maxBytes?: number;
19
+ /** Max number of accepted items (types + files). Default 32. */
20
+ readonly maxItems?: number;
21
+ }
22
+ interface PasteReadOptions extends PasteLimits {
23
+ /** Default `['text']` (plain text only): the safest choice. */
24
+ readonly accept?: readonly PasteAccept[];
25
+ }
26
+ /** Validated, normalised options that adapters receive. */
27
+ interface ResolvedPasteReadOptions {
28
+ /** Normalised patterns: `type/subtype`, `type/*` or `*\/*`. */
29
+ readonly accept: readonly string[];
30
+ readonly maxBytes: number;
31
+ readonly maxItems: number;
32
+ }
33
+ /** Where the content came from: a Clipboard API read, a `paste` event, or a drag-and-drop `drop` event. */
34
+ type PasteSource = 'clipboard' | 'event' | 'drop';
35
+ /** One accepted clipboard entry. Textual types are decoded to `string`, everything else stays a `Blob`. */
36
+ interface PasteItem {
37
+ readonly type: string;
38
+ readonly data: string | Blob;
39
+ }
40
+ /**
41
+ * Everything the paste produced. Treat all of it as untrusted user input:
42
+ * in particular never inject `html` into the DOM without sanitising it.
43
+ */
44
+ interface PasteResult {
45
+ readonly source: PasteSource;
46
+ /** Every accepted entry, in clipboard order. */
47
+ readonly items: readonly PasteItem[];
48
+ /** `text/plain`, when accepted and present. */
49
+ readonly text: string | null;
50
+ /** `text/html`, when accepted and present. UNTRUSTED markup: sanitise before rendering. */
51
+ readonly html: string | null;
52
+ /** Raster images, verified from their bytes (PNG, JPEG, GIF, WebP, AVIF, BMP), typed accordingly. */
53
+ readonly images: readonly Blob[];
54
+ /** Files from a paste event (e.g. copied in the OS file manager). Includes image files. */
55
+ readonly files: readonly File[];
56
+ /**
57
+ * The entries of `files` that are also in `images`: verified image files, keeping their
58
+ * names, ready for `FormData`. Derived by the paste machine, so it is always consistent.
59
+ */
60
+ readonly imageFiles: readonly File[];
61
+ }
62
+ /** What a {@link PasteAdapter} resolves with. `imageFiles` is derived from it by the machine. */
63
+ type PasteReadResult = Omit<PasteResult, 'imageFiles'>;
64
+ export declare const DEFAULT_PASTE_ACCEPT: readonly PasteAccept[];
65
+ export declare const DEFAULT_PASTE_MAX_BYTES: number;
66
+ export declare const DEFAULT_PASTE_MAX_ITEMS = 32;
67
+ /** Validates and normalises paste options. Throws a classified `invalid-payload` failure. */
68
+ export declare function resolvePasteReadOptions(options?: PasteReadOptions): ResolvedPasteReadOptions;
69
+ /** Structural view of a `DataTransferItem`: only what is readable while dragging. */
70
+ interface DataTransferItemLike {
71
+ /** `'string'` or `'file'`. */
72
+ readonly kind: string;
73
+ readonly type: string;
74
+ }
75
+ /** Structural view of `DataTransfer` (paste and drop events). */
76
+ interface DataTransferLike {
77
+ readonly types: ArrayLike<string>;
78
+ getData(format: string): string;
79
+ readonly files?: ArrayLike<File> | null;
80
+ readonly items?: ArrayLike<DataTransferItemLike> | null;
81
+ }
82
+ /**
83
+ * Whether a drag in progress could drop anything `accept`s. Uses only what
84
+ * browsers expose before the drop (item kinds and types, never the data).
85
+ * A file whose type is not known yet (some browsers hide it while dragging)
86
+ * counts as a maybe: the drop itself is checked against `accept`.
87
+ */
88
+ export declare function canAcceptDrag(data: DataTransferLike, options: ResolvedPasteReadOptions): boolean;
89
+ /** Structural view of a `ClipboardItem` as returned by `navigator.clipboard.read()`. */
90
+ interface ClipboardItemLike {
91
+ readonly types: readonly string[];
92
+ getType(type: string): Promise<Blob>;
93
+ }
94
+ //#endregion
3
95
  //#region src/core/errors.d.ts
4
96
  /**
5
97
  * Every way a clipboard operation can fail, as a closed union.
@@ -66,8 +158,11 @@ export declare function copyFailure(type: CopyErrorType, message: string, cause?
66
158
  export declare function toCopyError(cause: unknown, operation?: ClipboardOperation): CopyError;
67
159
  /** Default English, user-facing sentence for a copy error. Replace for i18n. */
68
160
  export declare function describeCopyError(error: CopyError): string;
69
- /** Default English, user-facing sentence for a paste error. Replace for i18n. */
70
- export declare function describePasteError(error: CopyError): string;
161
+ /**
162
+ * Default English, user-facing sentence for a paste error. Pass the error
163
+ * state's `source` to word drag-and-drop failures as drops. Replace for i18n.
164
+ */
165
+ export declare function describePasteError(error: CopyError, source?: PasteSource): string;
71
166
  //#endregion
72
167
  //#region src/core/machine-shared.d.ts
73
168
  /**
@@ -333,84 +428,6 @@ export declare function canRetryState(state: CopyState, maxRetries?: number): bo
333
428
  /** Framework-agnostic copy state machine. */
334
429
  export declare function createCopyMachine(options?: CopyMachineOptionsSource): CopyMachine;
335
430
  //#endregion
336
- //#region src/core/paste-reader.d.ts
337
- /** Friendly names for the common cases. */
338
- type PasteAcceptShorthand = 'text' | 'html' | 'image' | 'any';
339
- /**
340
- * What a paste may contain, in any order: a shorthand, an exact MIME type
341
- * (`'image/png'`) or a wildcard (`'image/*'`, `'*\/*'`).
342
- * `image/svg+xml` is only accepted when listed exactly (it is scriptable XML).
343
- */
344
- type PasteAccept = PasteAcceptShorthand | `${string}/${string}`;
345
- interface PasteLimits {
346
- /**
347
- * Total size cap across all accepted items, in UTF-8 bytes. Strings are measured as
348
- * they would be encoded, matching `Blob.size`, so every paste path counts the same way.
349
- * Default 32 MiB.
350
- */
351
- readonly maxBytes?: number;
352
- /** Max number of accepted items (types + files). Default 32. */
353
- readonly maxItems?: number;
354
- }
355
- interface PasteReadOptions extends PasteLimits {
356
- /** Default `['text']` (plain text only): the safest choice. */
357
- readonly accept?: readonly PasteAccept[];
358
- }
359
- /** Validated, normalised options that adapters receive. */
360
- interface ResolvedPasteReadOptions {
361
- /** Normalised patterns: `type/subtype`, `type/*` or `*\/*`. */
362
- readonly accept: readonly string[];
363
- readonly maxBytes: number;
364
- readonly maxItems: number;
365
- }
366
- /** Where the content came from. */
367
- type PasteSource = 'clipboard' | 'event';
368
- /** One accepted clipboard entry. Textual types are decoded to `string`, everything else stays a `Blob`. */
369
- interface PasteItem {
370
- readonly type: string;
371
- readonly data: string | Blob;
372
- }
373
- /**
374
- * Everything the paste produced. Treat all of it as untrusted user input:
375
- * in particular never inject `html` into the DOM without sanitising it.
376
- */
377
- interface PasteResult {
378
- readonly source: PasteSource;
379
- /** Every accepted entry, in clipboard order. */
380
- readonly items: readonly PasteItem[];
381
- /** `text/plain`, when accepted and present. */
382
- readonly text: string | null;
383
- /** `text/html`, when accepted and present. UNTRUSTED markup: sanitise before rendering. */
384
- readonly html: string | null;
385
- /** Raster images, verified from their bytes (PNG, JPEG, GIF, WebP, AVIF, BMP), typed accordingly. */
386
- readonly images: readonly Blob[];
387
- /** Files from a paste event (e.g. copied in the OS file manager). Includes image files. */
388
- readonly files: readonly File[];
389
- /**
390
- * The entries of `files` that are also in `images`: verified image files, keeping their
391
- * names, ready for `FormData`. Derived by the paste machine, so it is always consistent.
392
- */
393
- readonly imageFiles: readonly File[];
394
- }
395
- /** What a {@link PasteAdapter} resolves with. `imageFiles` is derived from it by the machine. */
396
- type PasteReadResult = Omit<PasteResult, 'imageFiles'>;
397
- export declare const DEFAULT_PASTE_ACCEPT: readonly PasteAccept[];
398
- export declare const DEFAULT_PASTE_MAX_BYTES: number;
399
- export declare const DEFAULT_PASTE_MAX_ITEMS = 32;
400
- /** Validates and normalises paste options. Throws a classified `invalid-payload` failure. */
401
- export declare function resolvePasteReadOptions(options?: PasteReadOptions): ResolvedPasteReadOptions;
402
- /** Structural view of `DataTransfer` (paste events). */
403
- interface DataTransferLike {
404
- readonly types: ArrayLike<string>;
405
- getData(format: string): string;
406
- readonly files?: ArrayLike<File> | null;
407
- }
408
- /** Structural view of a `ClipboardItem` as returned by `navigator.clipboard.read()`. */
409
- interface ClipboardItemLike {
410
- readonly types: readonly string[];
411
- getType(type: string): Promise<Blob>;
412
- }
413
- //#endregion
414
431
  //#region src/core/paste-adapter.d.ts
415
432
  /** Minimal structural view of `navigator.clipboard` for reading. */
416
433
  interface PasteClipboardLike {
@@ -472,10 +489,10 @@ export type PasteIgnoredReason = 'in-flight' | 'no-accepted-content' | 'nothing-
472
489
  /**
473
490
  * Why an in-flight read was cancelled: `reset` (`reset()` was called),
474
491
  * `disconnect` (its host disconnected, e.g. the React component unmounted) or
475
- * `superseded` (a paste event arrived while a clipboard read was pending).
492
+ * `superseded` (a paste or drop event arrived while a read was pending).
476
493
  */
477
494
  export type PasteCancelReason = 'reset' | 'disconnect' | 'superseded';
478
- /** What `paste()` / `pasteEvent()` / `retry()` resolve to. They never reject. */
495
+ /** What `paste()` / `pasteEvent()` / `dropEvent()` / `retry()` resolve to. They never reject. */
479
496
  export type PasteOutcome = {
480
497
  readonly status: 'read';
481
498
  readonly result: PasteResult;
@@ -491,14 +508,20 @@ export interface PasteEventLike {
491
508
  readonly clipboardData: DataTransferLike | null | undefined;
492
509
  preventDefault(): void;
493
510
  }
511
+ /** Structural view of a DOM / React `drop` event. */
512
+ export interface PasteDropEventLike {
513
+ readonly dataTransfer: DataTransferLike | null | undefined;
514
+ preventDefault(): void;
515
+ }
494
516
  export interface PasteMachineOptions extends PasteReadOptions {
495
517
  /** Defaults to the browser Clipboard API adapter. */
496
518
  readonly adapter?: PasteAdapter;
497
519
  /** Return from `read` to `idle` after this many ms. `false` / `Infinity` / omitted = keep the result. */
498
520
  readonly resetAfterMs?: number | false;
499
521
  /**
500
- * Paste events only: call `event.preventDefault()` when the event carried
501
- * accepted content, so the browser doesn't also insert it. Default `true`.
522
+ * Paste events: call `event.preventDefault()` when the event carried accepted
523
+ * content, so the browser doesn't also insert it. Drop events: always call it,
524
+ * so the browser doesn't open the dropped file. Default `true`.
502
525
  */
503
526
  readonly preventDefault?: boolean;
504
527
  /**
@@ -538,6 +561,13 @@ export interface PasteMachine {
538
561
  * accepted content are ignored and left untouched for the browser.
539
562
  */
540
563
  readonly pasteEvent: (event: PasteEventLike) => Promise<PasteOutcome>;
564
+ /**
565
+ * Handles a drag-and-drop `drop` event exactly like a paste event: same
566
+ * `accept`, limits and image checks, `result.source === 'drop'`. Always calls
567
+ * `event.preventDefault()` (unless `preventDefault: false`), so a rejected
568
+ * file is not opened by the browser in place of the page.
569
+ */
570
+ readonly dropEvent: (event: PasteDropEventLike) => Promise<PasteOutcome>;
541
571
  /**
542
572
  * Re-reads the clipboard after a retryable failure (e.g. permission denied,
543
573
  * page not focused), up to `maxRetries`. Call it from a user gesture.
@@ -743,6 +773,12 @@ interface UsePasteOptions extends PasteMachineOptions {
743
773
  interface PasteTargetProps<T extends Element> {
744
774
  readonly onPaste: ClipboardEventHandler<T>;
745
775
  }
776
+ interface PasteDropTargetProps<T extends Element> {
777
+ readonly onDragEnter: DragEventHandler<T>;
778
+ readonly onDragOver: DragEventHandler<T>;
779
+ readonly onDragLeave: DragEventHandler<T>;
780
+ readonly onDrop: DragEventHandler<T>;
781
+ }
746
782
  interface UsePasteResult<T extends Element = HTMLElement> {
747
783
  /** Full discriminated state; narrow on `state.status`. */
748
784
  readonly state: PasteState;
@@ -756,17 +792,28 @@ interface UsePasteResult<T extends Element = HTMLElement> {
756
792
  readonly paste: PasteMachine['paste'];
757
793
  /** Stable identity. Handles a paste event you received yourself. Never rejects. */
758
794
  readonly pasteEvent: PasteMachine['pasteEvent'];
795
+ /** Stable identity. Handles a drop event you received yourself. Never rejects. */
796
+ readonly dropEvent: PasteMachine['dropEvent'];
759
797
  /** Stable identity. Re-reads the clipboard after a retryable failure, up to `maxRetries`. */
760
798
  readonly retry: PasteMachine['retry'];
761
799
  /** Stable identity. Back to `idle`, discarding and aborting any in-flight read. */
762
800
  readonly reset: PasteMachine['reset'];
763
801
  /** Spread onto an element (drop zone, textarea, editor) to accept Ctrl/⌘+V there. */
764
802
  readonly targetProps: PasteTargetProps<T>;
803
+ /**
804
+ * Spread onto one element to accept drag-and-drop there, through the same
805
+ * `accept` and limits as paste. Only drags carrying accepted types show the
806
+ * drop cursor. Separate from `targetProps` so text fields keep native drops.
807
+ */
808
+ readonly dropTargetProps: PasteDropTargetProps<T>;
809
+ /** An accepted drag is over the `dropTargetProps` element. Style the drop zone with it. */
810
+ readonly isDragOver: boolean;
765
811
  }
766
812
  /**
767
813
  * Paste state machine bound to a component. Supports a "Paste" button
768
- * (`paste()`, may prompt for permission) and keyboard paste (`targetProps`
769
- * or `listenOnDocument`, no prompt). Options may change on every render.
814
+ * (`paste()`, may prompt for permission), keyboard paste (`targetProps` or
815
+ * `listenOnDocument`, no prompt) and drag-and-drop (`dropTargetProps`).
816
+ * Options may change on every render.
770
817
  *
771
818
  * Everything in the result is untrusted user input.
772
819
  */
@@ -816,8 +863,13 @@ export declare function usePasteDisplayStatus(status: PasteStatus, options?: Use
816
863
  interface PasteFieldMessages {
817
864
  /** Announced to screen readers on successful paste. */
818
865
  readonly pasted: string | ((result: PasteResult) => string);
819
- /** Announced on failure. Defaults to {@link describePasteError}. */
820
- readonly error: (error: CopyError) => string;
866
+ /**
867
+ * Announced to screen readers when content is dropped onto the zone. When
868
+ * you override `pasted` but not this, your `pasted` message is used for drops too.
869
+ */
870
+ readonly dropped?: string | ((result: PasteResult) => string);
871
+ /** Announced on failure. Defaults to {@link describePasteError}. `source` tells drops from pastes. */
872
+ readonly error: (error: CopyError, source?: PasteSource) => string;
821
873
  /**
822
874
  * Accessible name of the trigger button. Receives the field's `label` prop.
823
875
  * The returned string must not be empty.
@@ -862,6 +914,11 @@ interface PasteFieldStatusProps extends HTMLAttributes<HTMLSpanElement> {
862
914
  interface PasteFieldZoneProps extends HTMLAttributes<HTMLDivElement> {
863
915
  /** When true, the zone is always focusable (tabIndex=0). Default true. */
864
916
  readonly focusable?: boolean;
917
+ /**
918
+ * Accept drag-and-drop, through the same `accept` and limits as paste.
919
+ * `data-drag-over` is present while an accepted drag is over the zone. Default true.
920
+ */
921
+ readonly droppable?: boolean;
865
922
  }
866
923
  interface PasteFieldTriggerRenderProps {
867
924
  /** The real state. Use for logic. */
@@ -922,5 +979,5 @@ export declare const PasteField: {
922
979
  readonly Preview: import("react").ForwardRefExoticComponent<PasteFieldPreviewProps & import("react").RefAttributes<HTMLDivElement>>;
923
980
  };
924
981
  //#endregion
925
- export type { BrowserPasteAdapterOptions, ClipboardItemLike, CopyFieldContextValue, CopyFieldLabelProps, CopyFieldMessages, CopyFieldRootProps, CopyFieldTriggerProps, CopyFieldTriggerRenderProps, CopyFieldValueProps, CopyGroupProps, DataTransferLike, LiveRegionProps, OperationContext, PasteAccept, PasteAcceptShorthand, PasteAdapter, PasteClipboardLike, PasteEnvironment, PasteFieldContextValue, PasteFieldLabelProps, PasteFieldMessages, PasteFieldPreviewProps, PasteFieldPreviewRenderProps, PasteFieldRootProps, PasteFieldStatusProps, PasteFieldTriggerProps, PasteFieldTriggerRenderProps, PasteFieldZoneProps, PasteItem, PasteLimits, PasteReadOptions, PasteReadResult, PasteResult, PasteSource, PasteTargetProps, ResolvedPasteReadOptions, RevealReason, RevealTargetProps, UseCopyOptions, UseCopyResult, UseDisplayStatusOptions, UsePasteDisplayStatusOptions, UsePasteOptions, UsePasteResult, UseRevealOnInteractionOptions, UseRevealOnInteractionResult };
982
+ export type { BrowserPasteAdapterOptions, ClipboardItemLike, CopyFieldContextValue, CopyFieldLabelProps, CopyFieldMessages, CopyFieldRootProps, CopyFieldTriggerProps, CopyFieldTriggerRenderProps, CopyFieldValueProps, CopyGroupProps, DataTransferItemLike, DataTransferLike, LiveRegionProps, OperationContext, PasteAccept, PasteAcceptShorthand, PasteAdapter, PasteClipboardLike, PasteDropTargetProps, PasteEnvironment, PasteFieldContextValue, PasteFieldLabelProps, PasteFieldMessages, PasteFieldPreviewProps, PasteFieldPreviewRenderProps, PasteFieldRootProps, PasteFieldStatusProps, PasteFieldTriggerProps, PasteFieldTriggerRenderProps, PasteFieldZoneProps, PasteItem, PasteLimits, PasteReadOptions, PasteReadResult, PasteResult, PasteSource, PasteTargetProps, ResolvedPasteReadOptions, RevealReason, RevealTargetProps, UseCopyOptions, UseCopyResult, UseDisplayStatusOptions, UsePasteDisplayStatusOptions, UsePasteOptions, UsePasteResult, UseRevealOnInteractionOptions, UseRevealOnInteractionResult };
926
983
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,97 @@
1
1
 
2
- import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
2
+ import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, DragEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
3
+ //#region src/core/paste-reader.d.ts
4
+ /** Friendly names for the common cases. */
5
+ type PasteAcceptShorthand = 'text' | 'html' | 'image' | 'any';
6
+ /**
7
+ * What a paste may contain, in any order: a shorthand, an exact MIME type
8
+ * (`'image/png'`) or a wildcard (`'image/*'`, `'*\/*'`).
9
+ * `image/svg+xml` is only accepted when listed exactly (it is scriptable XML).
10
+ */
11
+ type PasteAccept = PasteAcceptShorthand | `${string}/${string}`;
12
+ interface PasteLimits {
13
+ /**
14
+ * Total size cap across all accepted items, in UTF-8 bytes. Strings are measured as
15
+ * they would be encoded, matching `Blob.size`, so every paste path counts the same way.
16
+ * Default 32 MiB.
17
+ */
18
+ readonly maxBytes?: number;
19
+ /** Max number of accepted items (types + files). Default 32. */
20
+ readonly maxItems?: number;
21
+ }
22
+ interface PasteReadOptions extends PasteLimits {
23
+ /** Default `['text']` (plain text only): the safest choice. */
24
+ readonly accept?: readonly PasteAccept[];
25
+ }
26
+ /** Validated, normalised options that adapters receive. */
27
+ interface ResolvedPasteReadOptions {
28
+ /** Normalised patterns: `type/subtype`, `type/*` or `*\/*`. */
29
+ readonly accept: readonly string[];
30
+ readonly maxBytes: number;
31
+ readonly maxItems: number;
32
+ }
33
+ /** Where the content came from: a Clipboard API read, a `paste` event, or a drag-and-drop `drop` event. */
34
+ type PasteSource = 'clipboard' | 'event' | 'drop';
35
+ /** One accepted clipboard entry. Textual types are decoded to `string`, everything else stays a `Blob`. */
36
+ interface PasteItem {
37
+ readonly type: string;
38
+ readonly data: string | Blob;
39
+ }
40
+ /**
41
+ * Everything the paste produced. Treat all of it as untrusted user input:
42
+ * in particular never inject `html` into the DOM without sanitising it.
43
+ */
44
+ interface PasteResult {
45
+ readonly source: PasteSource;
46
+ /** Every accepted entry, in clipboard order. */
47
+ readonly items: readonly PasteItem[];
48
+ /** `text/plain`, when accepted and present. */
49
+ readonly text: string | null;
50
+ /** `text/html`, when accepted and present. UNTRUSTED markup: sanitise before rendering. */
51
+ readonly html: string | null;
52
+ /** Raster images, verified from their bytes (PNG, JPEG, GIF, WebP, AVIF, BMP), typed accordingly. */
53
+ readonly images: readonly Blob[];
54
+ /** Files from a paste event (e.g. copied in the OS file manager). Includes image files. */
55
+ readonly files: readonly File[];
56
+ /**
57
+ * The entries of `files` that are also in `images`: verified image files, keeping their
58
+ * names, ready for `FormData`. Derived by the paste machine, so it is always consistent.
59
+ */
60
+ readonly imageFiles: readonly File[];
61
+ }
62
+ /** What a {@link PasteAdapter} resolves with. `imageFiles` is derived from it by the machine. */
63
+ type PasteReadResult = Omit<PasteResult, 'imageFiles'>;
64
+ export declare const DEFAULT_PASTE_ACCEPT: readonly PasteAccept[];
65
+ export declare const DEFAULT_PASTE_MAX_BYTES: number;
66
+ export declare const DEFAULT_PASTE_MAX_ITEMS = 32;
67
+ /** Validates and normalises paste options. Throws a classified `invalid-payload` failure. */
68
+ export declare function resolvePasteReadOptions(options?: PasteReadOptions): ResolvedPasteReadOptions;
69
+ /** Structural view of a `DataTransferItem`: only what is readable while dragging. */
70
+ interface DataTransferItemLike {
71
+ /** `'string'` or `'file'`. */
72
+ readonly kind: string;
73
+ readonly type: string;
74
+ }
75
+ /** Structural view of `DataTransfer` (paste and drop events). */
76
+ interface DataTransferLike {
77
+ readonly types: ArrayLike<string>;
78
+ getData(format: string): string;
79
+ readonly files?: ArrayLike<File> | null;
80
+ readonly items?: ArrayLike<DataTransferItemLike> | null;
81
+ }
82
+ /**
83
+ * Whether a drag in progress could drop anything `accept`s. Uses only what
84
+ * browsers expose before the drop (item kinds and types, never the data).
85
+ * A file whose type is not known yet (some browsers hide it while dragging)
86
+ * counts as a maybe: the drop itself is checked against `accept`.
87
+ */
88
+ export declare function canAcceptDrag(data: DataTransferLike, options: ResolvedPasteReadOptions): boolean;
89
+ /** Structural view of a `ClipboardItem` as returned by `navigator.clipboard.read()`. */
90
+ interface ClipboardItemLike {
91
+ readonly types: readonly string[];
92
+ getType(type: string): Promise<Blob>;
93
+ }
94
+ //#endregion
3
95
  //#region src/core/errors.d.ts
4
96
  /**
5
97
  * Every way a clipboard operation can fail, as a closed union.
@@ -66,8 +158,11 @@ export declare function copyFailure(type: CopyErrorType, message: string, cause?
66
158
  export declare function toCopyError(cause: unknown, operation?: ClipboardOperation): CopyError;
67
159
  /** Default English, user-facing sentence for a copy error. Replace for i18n. */
68
160
  export declare function describeCopyError(error: CopyError): string;
69
- /** Default English, user-facing sentence for a paste error. Replace for i18n. */
70
- export declare function describePasteError(error: CopyError): string;
161
+ /**
162
+ * Default English, user-facing sentence for a paste error. Pass the error
163
+ * state's `source` to word drag-and-drop failures as drops. Replace for i18n.
164
+ */
165
+ export declare function describePasteError(error: CopyError, source?: PasteSource): string;
71
166
  //#endregion
72
167
  //#region src/core/machine-shared.d.ts
73
168
  /**
@@ -333,84 +428,6 @@ export declare function canRetryState(state: CopyState, maxRetries?: number): bo
333
428
  /** Framework-agnostic copy state machine. */
334
429
  export declare function createCopyMachine(options?: CopyMachineOptionsSource): CopyMachine;
335
430
  //#endregion
336
- //#region src/core/paste-reader.d.ts
337
- /** Friendly names for the common cases. */
338
- type PasteAcceptShorthand = 'text' | 'html' | 'image' | 'any';
339
- /**
340
- * What a paste may contain, in any order: a shorthand, an exact MIME type
341
- * (`'image/png'`) or a wildcard (`'image/*'`, `'*\/*'`).
342
- * `image/svg+xml` is only accepted when listed exactly (it is scriptable XML).
343
- */
344
- type PasteAccept = PasteAcceptShorthand | `${string}/${string}`;
345
- interface PasteLimits {
346
- /**
347
- * Total size cap across all accepted items, in UTF-8 bytes. Strings are measured as
348
- * they would be encoded, matching `Blob.size`, so every paste path counts the same way.
349
- * Default 32 MiB.
350
- */
351
- readonly maxBytes?: number;
352
- /** Max number of accepted items (types + files). Default 32. */
353
- readonly maxItems?: number;
354
- }
355
- interface PasteReadOptions extends PasteLimits {
356
- /** Default `['text']` (plain text only): the safest choice. */
357
- readonly accept?: readonly PasteAccept[];
358
- }
359
- /** Validated, normalised options that adapters receive. */
360
- interface ResolvedPasteReadOptions {
361
- /** Normalised patterns: `type/subtype`, `type/*` or `*\/*`. */
362
- readonly accept: readonly string[];
363
- readonly maxBytes: number;
364
- readonly maxItems: number;
365
- }
366
- /** Where the content came from. */
367
- type PasteSource = 'clipboard' | 'event';
368
- /** One accepted clipboard entry. Textual types are decoded to `string`, everything else stays a `Blob`. */
369
- interface PasteItem {
370
- readonly type: string;
371
- readonly data: string | Blob;
372
- }
373
- /**
374
- * Everything the paste produced. Treat all of it as untrusted user input:
375
- * in particular never inject `html` into the DOM without sanitising it.
376
- */
377
- interface PasteResult {
378
- readonly source: PasteSource;
379
- /** Every accepted entry, in clipboard order. */
380
- readonly items: readonly PasteItem[];
381
- /** `text/plain`, when accepted and present. */
382
- readonly text: string | null;
383
- /** `text/html`, when accepted and present. UNTRUSTED markup: sanitise before rendering. */
384
- readonly html: string | null;
385
- /** Raster images, verified from their bytes (PNG, JPEG, GIF, WebP, AVIF, BMP), typed accordingly. */
386
- readonly images: readonly Blob[];
387
- /** Files from a paste event (e.g. copied in the OS file manager). Includes image files. */
388
- readonly files: readonly File[];
389
- /**
390
- * The entries of `files` that are also in `images`: verified image files, keeping their
391
- * names, ready for `FormData`. Derived by the paste machine, so it is always consistent.
392
- */
393
- readonly imageFiles: readonly File[];
394
- }
395
- /** What a {@link PasteAdapter} resolves with. `imageFiles` is derived from it by the machine. */
396
- type PasteReadResult = Omit<PasteResult, 'imageFiles'>;
397
- export declare const DEFAULT_PASTE_ACCEPT: readonly PasteAccept[];
398
- export declare const DEFAULT_PASTE_MAX_BYTES: number;
399
- export declare const DEFAULT_PASTE_MAX_ITEMS = 32;
400
- /** Validates and normalises paste options. Throws a classified `invalid-payload` failure. */
401
- export declare function resolvePasteReadOptions(options?: PasteReadOptions): ResolvedPasteReadOptions;
402
- /** Structural view of `DataTransfer` (paste events). */
403
- interface DataTransferLike {
404
- readonly types: ArrayLike<string>;
405
- getData(format: string): string;
406
- readonly files?: ArrayLike<File> | null;
407
- }
408
- /** Structural view of a `ClipboardItem` as returned by `navigator.clipboard.read()`. */
409
- interface ClipboardItemLike {
410
- readonly types: readonly string[];
411
- getType(type: string): Promise<Blob>;
412
- }
413
- //#endregion
414
431
  //#region src/core/paste-adapter.d.ts
415
432
  /** Minimal structural view of `navigator.clipboard` for reading. */
416
433
  interface PasteClipboardLike {
@@ -472,10 +489,10 @@ export type PasteIgnoredReason = 'in-flight' | 'no-accepted-content' | 'nothing-
472
489
  /**
473
490
  * Why an in-flight read was cancelled: `reset` (`reset()` was called),
474
491
  * `disconnect` (its host disconnected, e.g. the React component unmounted) or
475
- * `superseded` (a paste event arrived while a clipboard read was pending).
492
+ * `superseded` (a paste or drop event arrived while a read was pending).
476
493
  */
477
494
  export type PasteCancelReason = 'reset' | 'disconnect' | 'superseded';
478
- /** What `paste()` / `pasteEvent()` / `retry()` resolve to. They never reject. */
495
+ /** What `paste()` / `pasteEvent()` / `dropEvent()` / `retry()` resolve to. They never reject. */
479
496
  export type PasteOutcome = {
480
497
  readonly status: 'read';
481
498
  readonly result: PasteResult;
@@ -491,14 +508,20 @@ export interface PasteEventLike {
491
508
  readonly clipboardData: DataTransferLike | null | undefined;
492
509
  preventDefault(): void;
493
510
  }
511
+ /** Structural view of a DOM / React `drop` event. */
512
+ export interface PasteDropEventLike {
513
+ readonly dataTransfer: DataTransferLike | null | undefined;
514
+ preventDefault(): void;
515
+ }
494
516
  export interface PasteMachineOptions extends PasteReadOptions {
495
517
  /** Defaults to the browser Clipboard API adapter. */
496
518
  readonly adapter?: PasteAdapter;
497
519
  /** Return from `read` to `idle` after this many ms. `false` / `Infinity` / omitted = keep the result. */
498
520
  readonly resetAfterMs?: number | false;
499
521
  /**
500
- * Paste events only: call `event.preventDefault()` when the event carried
501
- * accepted content, so the browser doesn't also insert it. Default `true`.
522
+ * Paste events: call `event.preventDefault()` when the event carried accepted
523
+ * content, so the browser doesn't also insert it. Drop events: always call it,
524
+ * so the browser doesn't open the dropped file. Default `true`.
502
525
  */
503
526
  readonly preventDefault?: boolean;
504
527
  /**
@@ -538,6 +561,13 @@ export interface PasteMachine {
538
561
  * accepted content are ignored and left untouched for the browser.
539
562
  */
540
563
  readonly pasteEvent: (event: PasteEventLike) => Promise<PasteOutcome>;
564
+ /**
565
+ * Handles a drag-and-drop `drop` event exactly like a paste event: same
566
+ * `accept`, limits and image checks, `result.source === 'drop'`. Always calls
567
+ * `event.preventDefault()` (unless `preventDefault: false`), so a rejected
568
+ * file is not opened by the browser in place of the page.
569
+ */
570
+ readonly dropEvent: (event: PasteDropEventLike) => Promise<PasteOutcome>;
541
571
  /**
542
572
  * Re-reads the clipboard after a retryable failure (e.g. permission denied,
543
573
  * page not focused), up to `maxRetries`. Call it from a user gesture.
@@ -743,6 +773,12 @@ interface UsePasteOptions extends PasteMachineOptions {
743
773
  interface PasteTargetProps<T extends Element> {
744
774
  readonly onPaste: ClipboardEventHandler<T>;
745
775
  }
776
+ interface PasteDropTargetProps<T extends Element> {
777
+ readonly onDragEnter: DragEventHandler<T>;
778
+ readonly onDragOver: DragEventHandler<T>;
779
+ readonly onDragLeave: DragEventHandler<T>;
780
+ readonly onDrop: DragEventHandler<T>;
781
+ }
746
782
  interface UsePasteResult<T extends Element = HTMLElement> {
747
783
  /** Full discriminated state; narrow on `state.status`. */
748
784
  readonly state: PasteState;
@@ -756,17 +792,28 @@ interface UsePasteResult<T extends Element = HTMLElement> {
756
792
  readonly paste: PasteMachine['paste'];
757
793
  /** Stable identity. Handles a paste event you received yourself. Never rejects. */
758
794
  readonly pasteEvent: PasteMachine['pasteEvent'];
795
+ /** Stable identity. Handles a drop event you received yourself. Never rejects. */
796
+ readonly dropEvent: PasteMachine['dropEvent'];
759
797
  /** Stable identity. Re-reads the clipboard after a retryable failure, up to `maxRetries`. */
760
798
  readonly retry: PasteMachine['retry'];
761
799
  /** Stable identity. Back to `idle`, discarding and aborting any in-flight read. */
762
800
  readonly reset: PasteMachine['reset'];
763
801
  /** Spread onto an element (drop zone, textarea, editor) to accept Ctrl/⌘+V there. */
764
802
  readonly targetProps: PasteTargetProps<T>;
803
+ /**
804
+ * Spread onto one element to accept drag-and-drop there, through the same
805
+ * `accept` and limits as paste. Only drags carrying accepted types show the
806
+ * drop cursor. Separate from `targetProps` so text fields keep native drops.
807
+ */
808
+ readonly dropTargetProps: PasteDropTargetProps<T>;
809
+ /** An accepted drag is over the `dropTargetProps` element. Style the drop zone with it. */
810
+ readonly isDragOver: boolean;
765
811
  }
766
812
  /**
767
813
  * Paste state machine bound to a component. Supports a "Paste" button
768
- * (`paste()`, may prompt for permission) and keyboard paste (`targetProps`
769
- * or `listenOnDocument`, no prompt). Options may change on every render.
814
+ * (`paste()`, may prompt for permission), keyboard paste (`targetProps` or
815
+ * `listenOnDocument`, no prompt) and drag-and-drop (`dropTargetProps`).
816
+ * Options may change on every render.
770
817
  *
771
818
  * Everything in the result is untrusted user input.
772
819
  */
@@ -816,8 +863,13 @@ export declare function usePasteDisplayStatus(status: PasteStatus, options?: Use
816
863
  interface PasteFieldMessages {
817
864
  /** Announced to screen readers on successful paste. */
818
865
  readonly pasted: string | ((result: PasteResult) => string);
819
- /** Announced on failure. Defaults to {@link describePasteError}. */
820
- readonly error: (error: CopyError) => string;
866
+ /**
867
+ * Announced to screen readers when content is dropped onto the zone. When
868
+ * you override `pasted` but not this, your `pasted` message is used for drops too.
869
+ */
870
+ readonly dropped?: string | ((result: PasteResult) => string);
871
+ /** Announced on failure. Defaults to {@link describePasteError}. `source` tells drops from pastes. */
872
+ readonly error: (error: CopyError, source?: PasteSource) => string;
821
873
  /**
822
874
  * Accessible name of the trigger button. Receives the field's `label` prop.
823
875
  * The returned string must not be empty.
@@ -862,6 +914,11 @@ interface PasteFieldStatusProps extends HTMLAttributes<HTMLSpanElement> {
862
914
  interface PasteFieldZoneProps extends HTMLAttributes<HTMLDivElement> {
863
915
  /** When true, the zone is always focusable (tabIndex=0). Default true. */
864
916
  readonly focusable?: boolean;
917
+ /**
918
+ * Accept drag-and-drop, through the same `accept` and limits as paste.
919
+ * `data-drag-over` is present while an accepted drag is over the zone. Default true.
920
+ */
921
+ readonly droppable?: boolean;
865
922
  }
866
923
  interface PasteFieldTriggerRenderProps {
867
924
  /** The real state. Use for logic. */
@@ -922,5 +979,5 @@ export declare const PasteField: {
922
979
  readonly Preview: import("react").ForwardRefExoticComponent<PasteFieldPreviewProps & import("react").RefAttributes<HTMLDivElement>>;
923
980
  };
924
981
  //#endregion
925
- export type { BrowserPasteAdapterOptions, ClipboardItemLike, CopyFieldContextValue, CopyFieldLabelProps, CopyFieldMessages, CopyFieldRootProps, CopyFieldTriggerProps, CopyFieldTriggerRenderProps, CopyFieldValueProps, CopyGroupProps, DataTransferLike, LiveRegionProps, OperationContext, PasteAccept, PasteAcceptShorthand, PasteAdapter, PasteClipboardLike, PasteEnvironment, PasteFieldContextValue, PasteFieldLabelProps, PasteFieldMessages, PasteFieldPreviewProps, PasteFieldPreviewRenderProps, PasteFieldRootProps, PasteFieldStatusProps, PasteFieldTriggerProps, PasteFieldTriggerRenderProps, PasteFieldZoneProps, PasteItem, PasteLimits, PasteReadOptions, PasteReadResult, PasteResult, PasteSource, PasteTargetProps, ResolvedPasteReadOptions, RevealReason, RevealTargetProps, UseCopyOptions, UseCopyResult, UseDisplayStatusOptions, UsePasteDisplayStatusOptions, UsePasteOptions, UsePasteResult, UseRevealOnInteractionOptions, UseRevealOnInteractionResult };
982
+ export type { BrowserPasteAdapterOptions, ClipboardItemLike, CopyFieldContextValue, CopyFieldLabelProps, CopyFieldMessages, CopyFieldRootProps, CopyFieldTriggerProps, CopyFieldTriggerRenderProps, CopyFieldValueProps, CopyGroupProps, DataTransferItemLike, DataTransferLike, LiveRegionProps, OperationContext, PasteAccept, PasteAcceptShorthand, PasteAdapter, PasteClipboardLike, PasteDropTargetProps, PasteEnvironment, PasteFieldContextValue, PasteFieldLabelProps, PasteFieldMessages, PasteFieldPreviewProps, PasteFieldPreviewRenderProps, PasteFieldRootProps, PasteFieldStatusProps, PasteFieldTriggerProps, PasteFieldTriggerRenderProps, PasteFieldZoneProps, PasteItem, PasteLimits, PasteReadOptions, PasteReadResult, PasteResult, PasteSource, PasteTargetProps, ResolvedPasteReadOptions, RevealReason, RevealTargetProps, UseCopyOptions, UseCopyResult, UseDisplayStatusOptions, UsePasteDisplayStatusOptions, UsePasteOptions, UsePasteResult, UseRevealOnInteractionOptions, UseRevealOnInteractionResult };
926
983
  //# sourceMappingURL=index.d.ts.map