react-smart-copy 1.21.0 → 1.22.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
@@ -6,6 +6,7 @@ import { a as ClipboardItemData, i as ClipboardItemConstructorLike, n as Clipboa
6
6
  import { _ as registerCopyInterceptor, a as CopyInterceptOptions, c as CopyInterceptTransform, d as DEFAULT_INTERCEPTED_EVENTS, f as InterceptedCopyKind, g as readCopySelection, h as interceptCopyEvent, i as CopyInterceptFailureMode, l as CopyInterceptorOptions, m as SyncMultiPayload, n as CopyEventLike, o as CopyInterceptOutcome, p as SyncCopyPayload, r as CopyInterceptDecision, s as CopyInterceptPassReason, t as ClipboardDataLike, u as CopySelection } from "./chunks/copy-interceptor-CZWzGOkL.cjs";
7
7
  import { a as createBrowserPasteAdapter, i as PasteEnvironment, n as PasteAdapter, r as PasteClipboardLike, t as BrowserPasteAdapterOptions } from "./chunks/paste-adapter--SPL4PRE.cjs";
8
8
  import { a as ShareMethod, c as ShareOutcome, i as ShareEnvironment, n as ResolvedShare, o as ShareMode, r as ShareContent, s as ShareOptions, t as CopyReason } from "./chunks/share-C0esXvRK.cjs";
9
+ import { n as OtpFieldOptions, r as OtpSnapshot } from "./chunks/field-BTsKTs2M.cjs";
9
10
  import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, DragEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
10
11
  //#region src/react/useCopy.d.ts
11
12
  type UseCopyOptions = CopyMachineOptions;
@@ -508,5 +509,45 @@ interface UseShareResult {
508
509
  */
509
510
  export declare function useShare(options?: UseShareOptions): UseShareResult;
510
511
  //#endregion
511
- export { BlobSource, BrowserClipboardAdapterOptions, type BrowserPasteAdapterOptions, ClipboardAdapter, ClipboardDataLike, ClipboardEnvironment, ClipboardItemConstructorLike, ClipboardItemData, type ClipboardItemLike, ClipboardLike, ClipboardOperation, CopiedState, CopyCancelReason, CopyCoordinator, CopyCoordinatorMember, CopyError, CopyErrorType, CopyEventLike, CopyFailure, type CopyFieldContextValue, type CopyFieldLabelProps, type CopyFieldMessages, type CopyFieldRootProps, type CopyFieldTriggerProps, type CopyFieldTriggerRenderProps, type CopyFieldValueProps, type CopyGroupProps, CopyIgnoredReason, CopyInput, CopyInterceptDecision, CopyInterceptFailureMode, CopyInterceptOptions, CopyInterceptOutcome, CopyInterceptPassReason, CopyInterceptTransform, CopyInterceptorOptions, CopyMachine, CopyMachineOptions, CopyMachineOptionsSource, CopyOutcome, CopyPayload, CopyPayloadKind, type CopyReason, CopySelection, CopySource, CopyState, CopyStatus, CopyingState, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_RESET_AFTER_MS, type DataTransferItemLike, DataTransferLike, DragCopyDecision, DragCopyItem, DragCopyOptions, DragCopyOutcome, DragCopyPassReason, DragCopyPayload, DragCopySource, DragCopyState, DragCopyStatus, DragEffectAllowed, DragMultiPayload, DragStartEventLike, ErrorState, HtmlPayload, IDLE_STATE, IMAGE_MIME_TYPE, IdleState, ImagePayload, InterceptedCopyKind, JsonPayload, type LiveRegionProps, MultiPayload, MultiPayloadItem, type OperationContext, PASTE_IDLE_STATE, type PasteAccept, type PasteAcceptShorthand, type PasteAdapter, PasteCancelReason, type PasteClipboardLike, PasteDropEventLike, type PasteDropTargetProps, type PasteEnvironment, PasteErrorState, PasteEventLike, type PasteFieldContextValue, type PasteFieldLabelProps, type PasteFieldMessages, type PasteFieldPreviewProps, type PasteFieldPreviewRenderProps, type PasteFieldRootProps, type PasteFieldStatusProps, type PasteFieldTriggerProps, type PasteFieldTriggerRenderProps, type PasteFieldZoneProps, PasteIdleState, PasteIgnoredReason, type PasteItem, type PasteLimits, PasteMachine, PasteMachineOptions, PasteMachineOptionsSource, PasteOutcome, type PasteReadOptions, type PasteReadResult, PasteReadState, PasteReadingState, type PasteResult, type PasteSource, PasteState, PasteStatus, type PasteTargetProps, RasterImageMimeType, RegisterDragCopyResult, type ResolvedPasteReadOptions, type ResolvedShare, type RevealReason, type RevealTargetProps, SVG_MIME_TYPE, type ShareContent, type ShareEnvironment, type ShareMethod, type ShareMode, type ShareOptions, type ShareOutcome, type ShareStatus, SyncCopyPayload, SyncMultiPayload, TextPayload, type UseCopyInterceptorOptions, type UseCopyInterceptorResult, type UseCopyOptions, type UseCopyResult, type UseDisplayStatusOptions, type UseDragCopyOptions, type UseDragCopyResult, type UsePasteDisplayStatusOptions, type UsePasteOptions, type UsePasteResult, type UseRevealOnInteractionOptions, type UseRevealOnInteractionResult, type UseShareOptions, type UseShareOutcome, type UseShareResult, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, validatePayload };
512
+ //#region src/react/useOtpField.d.ts
513
+ type UseOtpFieldOptions = OtpFieldOptions;
514
+ /** Props for one box: spread them on an `<input>`. The field sets its value; don't pass `value`. */
515
+ interface OtpInputProps {
516
+ readonly ref: (element: HTMLInputElement | null) => void;
517
+ readonly type: 'text';
518
+ readonly autoComplete: 'one-time-code' | 'off';
519
+ readonly inputMode: 'numeric' | 'text';
520
+ readonly 'aria-label': string;
521
+ readonly autoCapitalize: 'off' | 'characters';
522
+ readonly spellCheck: false;
523
+ readonly pattern?: string;
524
+ }
525
+ interface UseOtpFieldResult extends OtpSnapshot {
526
+ /** Props for box `index` (0 to `length - 1`). Render one `<input>` for each. */
527
+ readonly getInputProps: (index: number) => OtpInputProps;
528
+ /** Fills the boxes with `code` from the first. Stable identity. */
529
+ readonly setValue: (code: string) => void;
530
+ /** Empties every box and focuses the first. Stable identity. */
531
+ readonly clear: () => void;
532
+ /** Focuses the first empty box. Stable identity. */
533
+ readonly focus: () => void;
534
+ }
535
+ /**
536
+ * A one-time code field of single-character boxes, headless: typing moves to the next box
537
+ * and Backspace to the one before; pasting a code (or an SMS holding one) into any box
538
+ * fills them all; an SMS autofill (iOS, Android) and, with `webOtp`, the WebOTP API do too.
539
+ * Every box has an accessible name; name the group around them.
540
+ *
541
+ * `length`, `alphabet` and `webOtp` are read when the field is made: a change makes a new,
542
+ * empty field. Callbacks and `label` may change on every render.
543
+ *
544
+ * @example
545
+ * const otp = useOtpField({ length: 6, onComplete: (code) => void verify(code) });
546
+ * <div role="group" aria-label="Verification code">
547
+ * {Array.from({ length: 6 }, (_, index) => <input key={index} {...otp.getInputProps(index)} />)}
548
+ * </div>
549
+ */
550
+ export declare function useOtpField(options?: UseOtpFieldOptions): UseOtpFieldResult;
551
+ //#endregion
552
+ export { BlobSource, BrowserClipboardAdapterOptions, type BrowserPasteAdapterOptions, ClipboardAdapter, ClipboardDataLike, ClipboardEnvironment, ClipboardItemConstructorLike, ClipboardItemData, type ClipboardItemLike, ClipboardLike, ClipboardOperation, CopiedState, CopyCancelReason, CopyCoordinator, CopyCoordinatorMember, CopyError, CopyErrorType, CopyEventLike, CopyFailure, type CopyFieldContextValue, type CopyFieldLabelProps, type CopyFieldMessages, type CopyFieldRootProps, type CopyFieldTriggerProps, type CopyFieldTriggerRenderProps, type CopyFieldValueProps, type CopyGroupProps, CopyIgnoredReason, CopyInput, CopyInterceptDecision, CopyInterceptFailureMode, CopyInterceptOptions, CopyInterceptOutcome, CopyInterceptPassReason, CopyInterceptTransform, CopyInterceptorOptions, CopyMachine, CopyMachineOptions, CopyMachineOptionsSource, CopyOutcome, CopyPayload, CopyPayloadKind, type CopyReason, CopySelection, CopySource, CopyState, CopyStatus, CopyingState, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_RESET_AFTER_MS, type DataTransferItemLike, DataTransferLike, DragCopyDecision, DragCopyItem, DragCopyOptions, DragCopyOutcome, DragCopyPassReason, DragCopyPayload, DragCopySource, DragCopyState, DragCopyStatus, DragEffectAllowed, DragMultiPayload, DragStartEventLike, ErrorState, HtmlPayload, IDLE_STATE, IMAGE_MIME_TYPE, IdleState, ImagePayload, InterceptedCopyKind, JsonPayload, type LiveRegionProps, MultiPayload, MultiPayloadItem, type OperationContext, type OtpInputProps, PASTE_IDLE_STATE, type PasteAccept, type PasteAcceptShorthand, type PasteAdapter, PasteCancelReason, type PasteClipboardLike, PasteDropEventLike, type PasteDropTargetProps, type PasteEnvironment, PasteErrorState, PasteEventLike, type PasteFieldContextValue, type PasteFieldLabelProps, type PasteFieldMessages, type PasteFieldPreviewProps, type PasteFieldPreviewRenderProps, type PasteFieldRootProps, type PasteFieldStatusProps, type PasteFieldTriggerProps, type PasteFieldTriggerRenderProps, type PasteFieldZoneProps, PasteIdleState, PasteIgnoredReason, type PasteItem, type PasteLimits, PasteMachine, PasteMachineOptions, PasteMachineOptionsSource, PasteOutcome, type PasteReadOptions, type PasteReadResult, PasteReadState, PasteReadingState, type PasteResult, type PasteSource, PasteState, PasteStatus, type PasteTargetProps, RasterImageMimeType, RegisterDragCopyResult, type ResolvedPasteReadOptions, type ResolvedShare, type RevealReason, type RevealTargetProps, SVG_MIME_TYPE, type ShareContent, type ShareEnvironment, type ShareMethod, type ShareMode, type ShareOptions, type ShareOutcome, type ShareStatus, SyncCopyPayload, SyncMultiPayload, TextPayload, type UseCopyInterceptorOptions, type UseCopyInterceptorResult, type UseCopyOptions, type UseCopyResult, type UseDisplayStatusOptions, type UseDragCopyOptions, type UseDragCopyResult, type UseOtpFieldOptions, type UseOtpFieldResult, type UsePasteDisplayStatusOptions, type UsePasteOptions, type UsePasteResult, type UseRevealOnInteractionOptions, type UseRevealOnInteractionResult, type UseShareOptions, type UseShareOutcome, type UseShareResult, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, validatePayload };
512
553
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { a as ClipboardItemData, i as ClipboardItemConstructorLike, n as Clipboa
6
6
  import { _ as registerCopyInterceptor, a as CopyInterceptOptions, c as CopyInterceptTransform, d as DEFAULT_INTERCEPTED_EVENTS, f as InterceptedCopyKind, g as readCopySelection, h as interceptCopyEvent, i as CopyInterceptFailureMode, l as CopyInterceptorOptions, m as SyncMultiPayload, n as CopyEventLike, o as CopyInterceptOutcome, p as SyncCopyPayload, r as CopyInterceptDecision, s as CopyInterceptPassReason, t as ClipboardDataLike, u as CopySelection } from "./chunks/copy-interceptor-C6NABy1l.js";
7
7
  import { a as createBrowserPasteAdapter, i as PasteEnvironment, n as PasteAdapter, r as PasteClipboardLike, t as BrowserPasteAdapterOptions } from "./chunks/paste-adapter-uahXnTYk.js";
8
8
  import { a as ShareMethod, c as ShareOutcome, i as ShareEnvironment, n as ResolvedShare, o as ShareMode, r as ShareContent, s as ShareOptions, t as CopyReason } from "./chunks/share-e7FenIr2.js";
9
+ import { n as OtpFieldOptions, r as OtpSnapshot } from "./chunks/field-BTsKTs2M.js";
9
10
  import { ButtonHTMLAttributes, CSSProperties, ClipboardEventHandler, DragEventHandler, FocusEventHandler, HTMLAttributes, PointerEventHandler, ReactNode, RefCallback } from "react";
10
11
  //#region src/react/useCopy.d.ts
11
12
  type UseCopyOptions = CopyMachineOptions;
@@ -508,5 +509,45 @@ interface UseShareResult {
508
509
  */
509
510
  export declare function useShare(options?: UseShareOptions): UseShareResult;
510
511
  //#endregion
511
- export { BlobSource, BrowserClipboardAdapterOptions, type BrowserPasteAdapterOptions, ClipboardAdapter, ClipboardDataLike, ClipboardEnvironment, ClipboardItemConstructorLike, ClipboardItemData, type ClipboardItemLike, ClipboardLike, ClipboardOperation, CopiedState, CopyCancelReason, CopyCoordinator, CopyCoordinatorMember, CopyError, CopyErrorType, CopyEventLike, CopyFailure, type CopyFieldContextValue, type CopyFieldLabelProps, type CopyFieldMessages, type CopyFieldRootProps, type CopyFieldTriggerProps, type CopyFieldTriggerRenderProps, type CopyFieldValueProps, type CopyGroupProps, CopyIgnoredReason, CopyInput, CopyInterceptDecision, CopyInterceptFailureMode, CopyInterceptOptions, CopyInterceptOutcome, CopyInterceptPassReason, CopyInterceptTransform, CopyInterceptorOptions, CopyMachine, CopyMachineOptions, CopyMachineOptionsSource, CopyOutcome, CopyPayload, CopyPayloadKind, type CopyReason, CopySelection, CopySource, CopyState, CopyStatus, CopyingState, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_RESET_AFTER_MS, type DataTransferItemLike, DataTransferLike, DragCopyDecision, DragCopyItem, DragCopyOptions, DragCopyOutcome, DragCopyPassReason, DragCopyPayload, DragCopySource, DragCopyState, DragCopyStatus, DragEffectAllowed, DragMultiPayload, DragStartEventLike, ErrorState, HtmlPayload, IDLE_STATE, IMAGE_MIME_TYPE, IdleState, ImagePayload, InterceptedCopyKind, JsonPayload, type LiveRegionProps, MultiPayload, MultiPayloadItem, type OperationContext, PASTE_IDLE_STATE, type PasteAccept, type PasteAcceptShorthand, type PasteAdapter, PasteCancelReason, type PasteClipboardLike, PasteDropEventLike, type PasteDropTargetProps, type PasteEnvironment, PasteErrorState, PasteEventLike, type PasteFieldContextValue, type PasteFieldLabelProps, type PasteFieldMessages, type PasteFieldPreviewProps, type PasteFieldPreviewRenderProps, type PasteFieldRootProps, type PasteFieldStatusProps, type PasteFieldTriggerProps, type PasteFieldTriggerRenderProps, type PasteFieldZoneProps, PasteIdleState, PasteIgnoredReason, type PasteItem, type PasteLimits, PasteMachine, PasteMachineOptions, PasteMachineOptionsSource, PasteOutcome, type PasteReadOptions, type PasteReadResult, PasteReadState, PasteReadingState, type PasteResult, type PasteSource, PasteState, PasteStatus, type PasteTargetProps, RasterImageMimeType, RegisterDragCopyResult, type ResolvedPasteReadOptions, type ResolvedShare, type RevealReason, type RevealTargetProps, SVG_MIME_TYPE, type ShareContent, type ShareEnvironment, type ShareMethod, type ShareMode, type ShareOptions, type ShareOutcome, type ShareStatus, SyncCopyPayload, SyncMultiPayload, TextPayload, type UseCopyInterceptorOptions, type UseCopyInterceptorResult, type UseCopyOptions, type UseCopyResult, type UseDisplayStatusOptions, type UseDragCopyOptions, type UseDragCopyResult, type UsePasteDisplayStatusOptions, type UsePasteOptions, type UsePasteResult, type UseRevealOnInteractionOptions, type UseRevealOnInteractionResult, type UseShareOptions, type UseShareOutcome, type UseShareResult, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, validatePayload };
512
+ //#region src/react/useOtpField.d.ts
513
+ type UseOtpFieldOptions = OtpFieldOptions;
514
+ /** Props for one box: spread them on an `<input>`. The field sets its value; don't pass `value`. */
515
+ interface OtpInputProps {
516
+ readonly ref: (element: HTMLInputElement | null) => void;
517
+ readonly type: 'text';
518
+ readonly autoComplete: 'one-time-code' | 'off';
519
+ readonly inputMode: 'numeric' | 'text';
520
+ readonly 'aria-label': string;
521
+ readonly autoCapitalize: 'off' | 'characters';
522
+ readonly spellCheck: false;
523
+ readonly pattern?: string;
524
+ }
525
+ interface UseOtpFieldResult extends OtpSnapshot {
526
+ /** Props for box `index` (0 to `length - 1`). Render one `<input>` for each. */
527
+ readonly getInputProps: (index: number) => OtpInputProps;
528
+ /** Fills the boxes with `code` from the first. Stable identity. */
529
+ readonly setValue: (code: string) => void;
530
+ /** Empties every box and focuses the first. Stable identity. */
531
+ readonly clear: () => void;
532
+ /** Focuses the first empty box. Stable identity. */
533
+ readonly focus: () => void;
534
+ }
535
+ /**
536
+ * A one-time code field of single-character boxes, headless: typing moves to the next box
537
+ * and Backspace to the one before; pasting a code (or an SMS holding one) into any box
538
+ * fills them all; an SMS autofill (iOS, Android) and, with `webOtp`, the WebOTP API do too.
539
+ * Every box has an accessible name; name the group around them.
540
+ *
541
+ * `length`, `alphabet` and `webOtp` are read when the field is made: a change makes a new,
542
+ * empty field. Callbacks and `label` may change on every render.
543
+ *
544
+ * @example
545
+ * const otp = useOtpField({ length: 6, onComplete: (code) => void verify(code) });
546
+ * <div role="group" aria-label="Verification code">
547
+ * {Array.from({ length: 6 }, (_, index) => <input key={index} {...otp.getInputProps(index)} />)}
548
+ * </div>
549
+ */
550
+ export declare function useOtpField(options?: UseOtpFieldOptions): UseOtpFieldResult;
551
+ //#endregion
552
+ export { BlobSource, BrowserClipboardAdapterOptions, type BrowserPasteAdapterOptions, ClipboardAdapter, ClipboardDataLike, ClipboardEnvironment, ClipboardItemConstructorLike, ClipboardItemData, type ClipboardItemLike, ClipboardLike, ClipboardOperation, CopiedState, CopyCancelReason, CopyCoordinator, CopyCoordinatorMember, CopyError, CopyErrorType, CopyEventLike, CopyFailure, type CopyFieldContextValue, type CopyFieldLabelProps, type CopyFieldMessages, type CopyFieldRootProps, type CopyFieldTriggerProps, type CopyFieldTriggerRenderProps, type CopyFieldValueProps, type CopyGroupProps, CopyIgnoredReason, CopyInput, CopyInterceptDecision, CopyInterceptFailureMode, CopyInterceptOptions, CopyInterceptOutcome, CopyInterceptPassReason, CopyInterceptTransform, CopyInterceptorOptions, CopyMachine, CopyMachineOptions, CopyMachineOptionsSource, CopyOutcome, CopyPayload, CopyPayloadKind, type CopyReason, CopySelection, CopySource, CopyState, CopyStatus, CopyingState, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_RESET_AFTER_MS, type DataTransferItemLike, DataTransferLike, DragCopyDecision, DragCopyItem, DragCopyOptions, DragCopyOutcome, DragCopyPassReason, DragCopyPayload, DragCopySource, DragCopyState, DragCopyStatus, DragEffectAllowed, DragMultiPayload, DragStartEventLike, ErrorState, HtmlPayload, IDLE_STATE, IMAGE_MIME_TYPE, IdleState, ImagePayload, InterceptedCopyKind, JsonPayload, type LiveRegionProps, MultiPayload, MultiPayloadItem, type OperationContext, type OtpInputProps, PASTE_IDLE_STATE, type PasteAccept, type PasteAcceptShorthand, type PasteAdapter, PasteCancelReason, type PasteClipboardLike, PasteDropEventLike, type PasteDropTargetProps, type PasteEnvironment, PasteErrorState, PasteEventLike, type PasteFieldContextValue, type PasteFieldLabelProps, type PasteFieldMessages, type PasteFieldPreviewProps, type PasteFieldPreviewRenderProps, type PasteFieldRootProps, type PasteFieldStatusProps, type PasteFieldTriggerProps, type PasteFieldTriggerRenderProps, type PasteFieldZoneProps, PasteIdleState, PasteIgnoredReason, type PasteItem, type PasteLimits, PasteMachine, PasteMachineOptions, PasteMachineOptionsSource, PasteOutcome, type PasteReadOptions, type PasteReadResult, PasteReadState, PasteReadingState, type PasteResult, type PasteSource, PasteState, PasteStatus, type PasteTargetProps, RasterImageMimeType, RegisterDragCopyResult, type ResolvedPasteReadOptions, type ResolvedShare, type RevealReason, type RevealTargetProps, SVG_MIME_TYPE, type ShareContent, type ShareEnvironment, type ShareMethod, type ShareMode, type ShareOptions, type ShareOutcome, type ShareStatus, SyncCopyPayload, SyncMultiPayload, TextPayload, type UseCopyInterceptorOptions, type UseCopyInterceptorResult, type UseCopyOptions, type UseCopyResult, type UseDisplayStatusOptions, type UseDragCopyOptions, type UseDragCopyResult, type UseOtpFieldOptions, type UseOtpFieldResult, type UsePasteDisplayStatusOptions, type UsePasteOptions, type UsePasteResult, type UseRevealOnInteractionOptions, type UseRevealOnInteractionResult, type UseShareOptions, type UseShareOutcome, type UseShareResult, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, validatePayload };
512
553
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-D
6
6
  import { _ as resolveMaxRetries, a as applyDragCopy, c as interceptCopyEvent, d as DEFAULT_RESET_AFTER_MS, f as IDLE_STATE, g as invoke, h as DEFAULT_MAX_RETRIES, i as createBrowserPasteAdapter, l as readCopySelection, m as createCopyMachine, n as canRetryPasteState, o as registerDragCopy, p as canRetryState, r as createPasteMachine, s as DEFAULT_INTERCEPTED_EVENTS, t as PASTE_IDLE_STATE, u as registerCopyInterceptor, v as createCopyCoordinator } from "./chunks/core-Cp2HSpaz.js";
7
7
  import { i as canAcceptDrag, l as resolvePasteReadOptions, n as DEFAULT_PASTE_MAX_BYTES, r as DEFAULT_PASTE_MAX_ITEMS, t as DEFAULT_PASTE_ACCEPT } from "./chunks/paste-reader-D9i7yMXF.js";
8
8
  import { i as shareOrCopy, r as shareMethod, t as TOUCH_FIRST } from "./chunks/share-Bop47Znn.js";
9
+ import { t as createOtpField } from "./chunks/field-Cdq2LxEO.js";
9
10
  import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
10
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
12
  //#region src/react/CopyGroup.tsx
@@ -1112,6 +1113,93 @@ function useShare(options = {}) {
1112
1113
  ]);
1113
1114
  }
1114
1115
  //#endregion
1115
- export { CopyFailure, CopyField, CopyGroup, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_MIN_PENDING_MS, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_PASTE_MIN_PENDING_MS, DEFAULT_PASTE_PENDING_DELAY_MS, DEFAULT_PENDING_DELAY_MS, DEFAULT_RESET_AFTER_MS, IDLE_STATE, IMAGE_MIME_TYPE, LiveRegion, PASTE_IDLE_STATE, PasteField, SVG_MIME_TYPE, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, defaultCopyFieldMessages, defaultPasteFieldMessages, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, useCopy, useCopyField, useCopyGroup, useCopyInterceptor, useDisplayStatus, useDragCopy, usePaste, usePasteDisplayStatus, usePasteField, useRevealOnInteraction, useShare, validatePayload, visuallyHiddenStyle };
1116
+ //#region src/react/useOtpField.ts
1117
+ const defaultLabel = (numeric) => (index, length) => `${numeric ? "Digit" : "Character"} ${String(index + 1)} of ${String(length)}`;
1118
+ /**
1119
+ * A one-time code field of single-character boxes, headless: typing moves to the next box
1120
+ * and Backspace to the one before; pasting a code (or an SMS holding one) into any box
1121
+ * fills them all; an SMS autofill (iOS, Android) and, with `webOtp`, the WebOTP API do too.
1122
+ * Every box has an accessible name; name the group around them.
1123
+ *
1124
+ * `length`, `alphabet` and `webOtp` are read when the field is made: a change makes a new,
1125
+ * empty field. Callbacks and `label` may change on every render.
1126
+ *
1127
+ * @example
1128
+ * const otp = useOtpField({ length: 6, onComplete: (code) => void verify(code) });
1129
+ * <div role="group" aria-label="Verification code">
1130
+ * {Array.from({ length: 6 }, (_, index) => <input key={index} {...otp.getInputProps(index)} />)}
1131
+ * </div>
1132
+ */
1133
+ function useOtpField(options = {}) {
1134
+ const latest = useRef(options);
1135
+ useIsomorphicLayoutEffect(() => {
1136
+ latest.current = options;
1137
+ });
1138
+ const length = options.length ?? 6;
1139
+ const alphabet = options.alphabet ?? "numeric";
1140
+ const webOtp = options.webOtp === true;
1141
+ const field = useMemo(() => createOtpField({
1142
+ length,
1143
+ alphabet,
1144
+ webOtp,
1145
+ label: (index, total) => (latest.current.label ?? defaultLabel(alphabet === "numeric"))(index, total),
1146
+ onChange: (snapshot) => latest.current.onChange?.(snapshot),
1147
+ onComplete: (code) => latest.current.onComplete?.(code)
1148
+ }), [
1149
+ length,
1150
+ alphabet,
1151
+ webOtp
1152
+ ]);
1153
+ const snapshot = useSyncExternalStore(field.subscribe, field.getSnapshot, field.getSnapshot);
1154
+ const elements = useRef([]);
1155
+ const refs = useMemo(() => Array.from({ length }, (_, index) => (element) => {
1156
+ elements.current[index] = element;
1157
+ }), [length]);
1158
+ const attached = useRef(null);
1159
+ useIsomorphicLayoutEffect(() => {
1160
+ const inputs = elements.current.slice(0, length).filter((element) => element !== null);
1161
+ const current = attached.current;
1162
+ if (current !== null && current.field === field && current.inputs.length === inputs.length && current.inputs.every((input, index) => input === inputs[index])) return;
1163
+ current?.detach();
1164
+ attached.current = inputs.length === length ? {
1165
+ field,
1166
+ inputs,
1167
+ detach: field.attach(inputs)
1168
+ } : null;
1169
+ });
1170
+ useEffect(() => () => {
1171
+ attached.current?.detach();
1172
+ attached.current = null;
1173
+ }, []);
1174
+ const labelOf = options.label;
1175
+ const getInputProps = useCallback((index) => {
1176
+ const numeric = alphabet === "numeric";
1177
+ const label = (labelOf ?? defaultLabel(numeric))(index, length);
1178
+ return {
1179
+ ref: refs[index] ?? (() => void 0),
1180
+ type: "text",
1181
+ autoComplete: index === 0 ? "one-time-code" : "off",
1182
+ inputMode: numeric ? "numeric" : "text",
1183
+ "aria-label": label,
1184
+ autoCapitalize: numeric ? "off" : "characters",
1185
+ spellCheck: false,
1186
+ ...numeric ? { pattern: "[0-9]*" } : {}
1187
+ };
1188
+ }, [
1189
+ alphabet,
1190
+ length,
1191
+ refs,
1192
+ labelOf
1193
+ ]);
1194
+ return {
1195
+ ...snapshot,
1196
+ getInputProps,
1197
+ setValue: field.setValue,
1198
+ clear: field.clear,
1199
+ focus: field.focus
1200
+ };
1201
+ }
1202
+ //#endregion
1203
+ export { CopyFailure, CopyField, CopyGroup, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_MIN_PENDING_MS, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_PASTE_MIN_PENDING_MS, DEFAULT_PASTE_PENDING_DELAY_MS, DEFAULT_PENDING_DELAY_MS, DEFAULT_RESET_AFTER_MS, IDLE_STATE, IMAGE_MIME_TYPE, LiveRegion, PASTE_IDLE_STATE, PasteField, SVG_MIME_TYPE, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, defaultCopyFieldMessages, defaultPasteFieldMessages, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, useCopy, useCopyField, useCopyGroup, useCopyInterceptor, useDisplayStatus, useDragCopy, useOtpField, usePaste, usePasteDisplayStatus, usePasteField, useRevealOnInteraction, useShare, validatePayload, visuallyHiddenStyle };
1116
1204
 
1117
1205
  //# sourceMappingURL=index.js.map