react-smart-copy 1.1.0 → 1.1.1

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
@@ -255,7 +255,10 @@ export interface CopyMachineOptions {
255
255
  readonly adapter?: ClipboardAdapter;
256
256
  /** Time in `copied` before returning to `idle`. `false`/`Infinity` disables. Default 2000. */
257
257
  readonly resetAfterMs?: number | false;
258
- /** Max `retry()` calls after the first failure. Default 3. */
258
+ /**
259
+ * Max `retry()` calls after the first failure. Default 3. `0` disables
260
+ * retry; `Infinity` allows unlimited retries.
261
+ */
259
262
  readonly maxRetries?: number;
260
263
  /**
261
264
  * Share "Copied" with other machines: only one member of a coordinator
package/dist/index.d.ts CHANGED
@@ -255,7 +255,10 @@ export interface CopyMachineOptions {
255
255
  readonly adapter?: ClipboardAdapter;
256
256
  /** Time in `copied` before returning to `idle`. `false`/`Infinity` disables. Default 2000. */
257
257
  readonly resetAfterMs?: number | false;
258
- /** Max `retry()` calls after the first failure. Default 3. */
258
+ /**
259
+ * Max `retry()` calls after the first failure. Default 3. `0` disables
260
+ * retry; `Infinity` allows unlimited retries.
261
+ */
259
262
  readonly maxRetries?: number;
260
263
  /**
261
264
  * Share "Copied" with other machines: only one member of a coordinator
package/dist/index.js CHANGED
@@ -1218,6 +1218,36 @@ function LiveRegion({ message, politeness = "polite", visuallyHidden = true, sty
1218
1218
  });
1219
1219
  }
1220
1220
  //#endregion
1221
+ //#region src/react/TriggerLabel.tsx
1222
+ /**
1223
+ * Default trigger label shared by `CopyField` and `PasteField`: every state's
1224
+ * text is stacked in one grid cell, so the button is always as wide as its
1225
+ * longest label and never resizes (no layout shift). Only the active label is
1226
+ * visible and exposed to assistive tech; the crossfade is skipped when the
1227
+ * user prefers reduced motion.
1228
+ */
1229
+ function TriggerLabel({ status, labels }) {
1230
+ const reduceMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
1231
+ return /* @__PURE__ */ jsx("span", {
1232
+ style: { display: "inline-grid" },
1233
+ children: Object.keys(labels).map((candidate) => {
1234
+ const active = candidate === status;
1235
+ return /* @__PURE__ */ jsx("span", {
1236
+ "data-trigger-label": candidate,
1237
+ "data-active": active ? "" : void 0,
1238
+ "aria-hidden": !active || void 0,
1239
+ style: {
1240
+ gridArea: "1 / 1",
1241
+ opacity: active ? 1 : 0,
1242
+ visibility: active ? "visible" : "hidden",
1243
+ ...reduceMotion ? {} : { transition: "opacity 150ms ease, visibility 150ms" }
1244
+ },
1245
+ children: labels[candidate]
1246
+ }, candidate);
1247
+ })
1248
+ });
1249
+ }
1250
+ //#endregion
1221
1251
  //#region src/react/CopyField.tsx
1222
1252
  const defaultCopyFieldMessages = {
1223
1253
  copied: "Copied to clipboard",
@@ -1333,38 +1363,6 @@ const DEFAULT_TRIGGER_TEXT$1 = {
1333
1363
  copied: "Copied",
1334
1364
  error: "Retry"
1335
1365
  };
1336
- const TRIGGER_STATUSES = [
1337
- "idle",
1338
- "copying",
1339
- "copied",
1340
- "error"
1341
- ];
1342
- /**
1343
- * Default label: every state's text is stacked in the same grid cell, so the
1344
- * button is always as wide as its longest label and never resizes (no layout
1345
- * shift). Only the active one is visible; the others crossfade out.
1346
- */
1347
- function DefaultTriggerLabel$1({ status }) {
1348
- const reduceMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
1349
- return /* @__PURE__ */ jsx("span", {
1350
- style: { display: "inline-grid" },
1351
- children: TRIGGER_STATUSES.map((candidate) => {
1352
- const active = candidate === status;
1353
- return /* @__PURE__ */ jsx("span", {
1354
- "data-trigger-label": candidate,
1355
- "data-active": active ? "" : void 0,
1356
- "aria-hidden": active ? void 0 : true,
1357
- style: {
1358
- gridArea: "1 / 1",
1359
- opacity: active ? 1 : 0,
1360
- visibility: active ? "visible" : "hidden",
1361
- ...reduceMotion ? {} : { transition: "opacity 150ms ease, visibility 150ms" }
1362
- },
1363
- children: DEFAULT_TRIGGER_TEXT$1[candidate]
1364
- }, candidate);
1365
- })
1366
- });
1367
- }
1368
1366
  /**
1369
1367
  * Headless compound component for a labelled, copyable value.
1370
1368
  *
@@ -1386,20 +1384,23 @@ const CopyField = {
1386
1384
  revealed: field.revealed,
1387
1385
  canRetry: field.canRetry
1388
1386
  };
1389
- const computedAriaLabel = ariaLabel ?? field.messages.triggerLabel(field.label);
1390
- const safeAriaLabel = computedAriaLabel.length > 0 ? computedAriaLabel : `Copy ${field.label}`;
1387
+ const safeAriaLabel = (ariaLabel ?? field.messages.triggerLabel(field.label)) || defaultCopyFieldMessages.triggerLabel(field.label);
1391
1388
  return /* @__PURE__ */ jsx("button", {
1392
1389
  ...rest,
1393
1390
  ref,
1394
1391
  type: "button",
1395
1392
  "aria-label": safeAriaLabel,
1393
+ "aria-busy": field.status === "copying" ? true : void 0,
1396
1394
  "data-state": field.status,
1397
1395
  "data-display-state": field.displayStatus,
1398
1396
  "data-revealed": field.revealed ? "" : void 0,
1399
1397
  onClick: composeEventHandlers(onClick, () => {
1400
1398
  field.copyValue();
1401
1399
  }),
1402
- children: typeof children === "function" ? children(renderProps) : children ?? /* @__PURE__ */ jsx(DefaultTriggerLabel$1, { status: field.displayStatus })
1400
+ children: typeof children === "function" ? children(renderProps) : children ?? /* @__PURE__ */ jsx(TriggerLabel, {
1401
+ status: field.displayStatus,
1402
+ labels: DEFAULT_TRIGGER_TEXT$1
1403
+ })
1403
1404
  });
1404
1405
  })
1405
1406
  };
@@ -1602,22 +1603,24 @@ const Status = /* @__PURE__ */ forwardRef(function PasteFieldStatus({ children,
1602
1603
  });
1603
1604
  });
1604
1605
  /**
1605
- * A drop/paste target area. Spread `usePaste`'s `targetProps` here so the
1606
- * zone accepts keyboard paste events. Also renders a `data-zone` attribute
1607
- * so it can be styled separately from the root.
1606
+ * A focusable paste target. Accepts keyboard paste (Ctrl/⌘+V) without a
1607
+ * permission prompt and renders `data-zone` for styling.
1608
+ *
1609
+ * Accessible name: `aria-label` prop, else `messages.zoneLabel(label)`
1610
+ * ("Paste area for Notes"). Pass `aria-labelledby` explicitly to name it from
1611
+ * another element instead.
1608
1612
  */
1609
1613
  const Zone = /* @__PURE__ */ forwardRef(function PasteFieldZone({ children, focusable = true, onPaste, "aria-label": ariaLabel, tabIndex, ...rest }, ref) {
1610
1614
  const field = usePasteField();
1611
1615
  const { targetProps } = field;
1612
- const computedAriaLabel = ariaLabel ?? field.messages.zoneLabel(field.label);
1613
- const safeAriaLabel = computedAriaLabel.length > 0 ? computedAriaLabel : `Paste area for ${field.label}`;
1616
+ const safeAriaLabel = (ariaLabel ?? field.messages.zoneLabel(field.label)) || defaultPasteFieldMessages.zoneLabel(field.label);
1614
1617
  return /* @__PURE__ */ jsx("div", {
1618
+ "aria-keyshortcuts": "Control+V Meta+V",
1615
1619
  ...rest,
1616
1620
  ref,
1617
1621
  id: field.zoneId,
1618
1622
  role: "region",
1619
1623
  "aria-label": safeAriaLabel,
1620
- "aria-labelledby": field.labelId,
1621
1624
  "data-zone": "",
1622
1625
  "data-state": field.status,
1623
1626
  "data-display-state": field.displayStatus,
@@ -1632,32 +1635,6 @@ const DEFAULT_TRIGGER_TEXT = {
1632
1635
  read: "Pasted",
1633
1636
  error: "Retry"
1634
1637
  };
1635
- const PASTE_STATUSES = [
1636
- "idle",
1637
- "reading",
1638
- "read",
1639
- "error"
1640
- ];
1641
- function DefaultTriggerLabel({ status }) {
1642
- return /* @__PURE__ */ jsx("span", {
1643
- style: { display: "inline-grid" },
1644
- children: PASTE_STATUSES.map((candidate) => {
1645
- const active = candidate === status;
1646
- return /* @__PURE__ */ jsx("span", {
1647
- "data-trigger-label": candidate,
1648
- "data-active": active ? "" : void 0,
1649
- "aria-hidden": active ? void 0 : true,
1650
- style: {
1651
- gridArea: "1 / 1",
1652
- opacity: active ? 1 : 0,
1653
- visibility: active ? "visible" : "hidden",
1654
- transition: "opacity 150ms ease, visibility 150ms"
1655
- },
1656
- children: DEFAULT_TRIGGER_TEXT[candidate]
1657
- }, candidate);
1658
- })
1659
- });
1660
- }
1661
1638
  /**
1662
1639
  * Headless compound component for a labelled, paste-ready field.
1663
1640
  *
@@ -1688,20 +1665,23 @@ const PasteField = {
1688
1665
  state: field.state,
1689
1666
  revealed: field.revealed
1690
1667
  };
1691
- const computedAriaLabel = ariaLabel ?? field.messages.triggerLabel(field.label);
1692
- const safeAriaLabel = computedAriaLabel.length > 0 ? computedAriaLabel : `Paste ${field.label}`;
1668
+ const safeAriaLabel = (ariaLabel ?? field.messages.triggerLabel(field.label)) || defaultPasteFieldMessages.triggerLabel(field.label);
1693
1669
  return /* @__PURE__ */ jsx("button", {
1694
1670
  ...rest,
1695
1671
  ref,
1696
1672
  type: "button",
1697
1673
  "aria-label": safeAriaLabel,
1674
+ "aria-busy": field.status === "reading" ? true : void 0,
1698
1675
  "data-state": field.status,
1699
1676
  "data-display-state": field.displayStatus,
1700
1677
  "data-revealed": field.revealed ? "" : void 0,
1701
1678
  onClick: composeEventHandlers(onClick, () => {
1702
1679
  field.doPaste();
1703
1680
  }),
1704
- children: typeof children === "function" ? children(renderProps) : children ?? /* @__PURE__ */ jsx(DefaultTriggerLabel, { status: field.displayStatus })
1681
+ children: typeof children === "function" ? children(renderProps) : children ?? /* @__PURE__ */ jsx(TriggerLabel, {
1682
+ status: field.displayStatus,
1683
+ labels: DEFAULT_TRIGGER_TEXT
1684
+ })
1705
1685
  });
1706
1686
  })
1707
1687
  };