@coffre/ui 0.6.0 → 0.6.2

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.
Files changed (103) hide show
  1. package/dist/chunks/{affordances-D0GyCT-I.js → affordances-Dtyha68j.js} +10 -2
  2. package/dist/chunks/{affordances-D0GyCT-I.js.map → affordances-Dtyha68j.js.map} +1 -1
  3. package/dist/chunks/{audit-sentence-CUUMshIp.js → audit-sentence-BVv_9_nq.js} +2 -2
  4. package/dist/chunks/{audit-sentence-CUUMshIp.js.map → audit-sentence-BVv_9_nq.js.map} +1 -1
  5. package/dist/chunks/{connected-apps-IP0KfUjo.js → connected-apps-rBF9XUob.js} +4 -4
  6. package/dist/chunks/{connected-apps-IP0KfUjo.js.map → connected-apps-rBF9XUob.js.map} +1 -1
  7. package/dist/chunks/{delete-place-CVv6CN5y.js → delete-place-CkGezx5R.js} +4 -4
  8. package/dist/chunks/{delete-place-CVv6CN5y.js.map → delete-place-CkGezx5R.js.map} +1 -1
  9. package/dist/chunks/{directory-pMVS1m-c.js → directory-SRN01yP6.js} +38 -32
  10. package/dist/chunks/directory-SRN01yP6.js.map +1 -0
  11. package/dist/chunks/{folders-hR2Lnk0k.js → folders-Dw240WMJ.js} +2 -2
  12. package/dist/chunks/{folders-hR2Lnk0k.js.map → folders-Dw240WMJ.js.map} +1 -1
  13. package/dist/chunks/{grants-CgC8Ybhu.js → grants-1E1vqkM0.js} +5 -5
  14. package/dist/chunks/{grants-CgC8Ybhu.js.map → grants-1E1vqkM0.js.map} +1 -1
  15. package/dist/chunks/multi-combobox-CsIXihuc.js +99 -0
  16. package/dist/chunks/multi-combobox-CsIXihuc.js.map +1 -0
  17. package/dist/chunks/{offboarding-3fzRjKla.js → offboarding-Bt7KSixm.js} +3 -3
  18. package/dist/chunks/{offboarding-3fzRjKla.js.map → offboarding-Bt7KSixm.js.map} +1 -1
  19. package/dist/chunks/{principal-page-CYJIJAdp.js → principal-page-Cbx2l6XL.js} +21 -24
  20. package/dist/chunks/principal-page-Cbx2l6XL.js.map +1 -0
  21. package/dist/chunks/{project-page-lO5P6iCb.js → project-page-DKo2AFYg.js} +2 -2
  22. package/dist/chunks/{project-page-lO5P6iCb.js.map → project-page-DKo2AFYg.js.map} +1 -1
  23. package/dist/chunks/{queries-gigcQOO_.js → queries-BvSw1xBN.js} +87 -15
  24. package/dist/chunks/queries-BvSw1xBN.js.map +1 -0
  25. package/dist/chunks/{references-DZ179hTJ.js → references-DCoSPtvw.js} +4 -4
  26. package/dist/chunks/{references-DZ179hTJ.js.map → references-DCoSPtvw.js.map} +1 -1
  27. package/dist/chunks/{role-field-DiqiFwm_.js → role-field-D98CvNEg.js} +2 -2
  28. package/dist/chunks/{role-field-DiqiFwm_.js.map → role-field-D98CvNEg.js.map} +1 -1
  29. package/dist/chunks/{row-state-Zf3kZVhd.js → row-state-BsIHspy4.js} +2 -2
  30. package/dist/chunks/{row-state-Zf3kZVhd.js.map → row-state-BsIHspy4.js.map} +1 -1
  31. package/dist/chunks/{theme-B6-V9JvY.js → theme-3b4DnCow.js} +2 -2
  32. package/dist/chunks/{theme-B6-V9JvY.js.map → theme-3b4DnCow.js.map} +1 -1
  33. package/dist/chunks/{ui-Br-dNUTc.js → ui-2kwXXfrX.js} +95 -22
  34. package/dist/chunks/ui-2kwXXfrX.js.map +1 -0
  35. package/dist/chunks/{use-action-CQGGNqWb.js → use-action-Bv7yQ0DW.js} +2 -2
  36. package/dist/chunks/{use-action-CQGGNqWb.js.map → use-action-Bv7yQ0DW.js.map} +1 -1
  37. package/dist/chunks/{use-change-BdS1gzyo.js → use-change-DIQTGXER.js} +58 -17
  38. package/dist/chunks/use-change-DIQTGXER.js.map +1 -0
  39. package/dist/chunks/{use-shell-BCU505bx.js → use-shell-DhFoHjDS.js} +2 -2
  40. package/dist/chunks/{use-shell-BCU505bx.js.map → use-shell-DhFoHjDS.js.map} +1 -1
  41. package/dist/index.d.ts +13 -164
  42. package/dist/index.js +142 -129
  43. package/dist/index.js.map +1 -1
  44. package/dist/pages/account.js +8 -8
  45. package/dist/pages/approval.js +1 -1
  46. package/dist/pages/audit.js +46 -60
  47. package/dist/pages/audit.js.map +1 -1
  48. package/dist/pages/device-login.js +1 -1
  49. package/dist/pages/environment.js +458 -241
  50. package/dist/pages/environment.js.map +1 -1
  51. package/dist/pages/login.js +2 -2
  52. package/dist/pages/oauth-authorize.js +1 -1
  53. package/dist/pages/project-access.js +8 -8
  54. package/dist/pages/project-environments.js +19 -58
  55. package/dist/pages/project-environments.js.map +1 -1
  56. package/dist/pages/project-settings.d.ts +1 -1
  57. package/dist/pages/project-settings.js +54 -75
  58. package/dist/pages/project-settings.js.map +1 -1
  59. package/dist/pages/project.js +3 -7
  60. package/dist/pages/project.js.map +1 -1
  61. package/dist/pages/projects.js +51 -78
  62. package/dist/pages/projects.js.map +1 -1
  63. package/dist/pages/service-account.js +11 -136
  64. package/dist/pages/service-account.js.map +1 -1
  65. package/dist/pages/service-accounts.js +4 -4
  66. package/dist/pages/settings.js +5 -5
  67. package/dist/pages/unregistered.js +1 -1
  68. package/dist/pages/user.js +5 -5
  69. package/dist/pages/users.js +4 -4
  70. package/package.json +3 -3
  71. package/src/components/actions-log.tsx +1 -1
  72. package/src/components/affordances.ts +12 -0
  73. package/src/components/command-palette.tsx +4 -5
  74. package/src/components/directory.tsx +18 -18
  75. package/src/components/missing.tsx +63 -67
  76. package/src/components/principal-page.tsx +10 -14
  77. package/src/components/service-tokens.tsx +2 -11
  78. package/src/components/shell.tsx +79 -75
  79. package/src/components/trusted-workloads.tsx +2 -11
  80. package/src/components/ui.tsx +35 -25
  81. package/src/lib/changes.ts +63 -12
  82. package/src/lib/clipboard.ts +40 -0
  83. package/src/lib/copy-attempts.ts +103 -0
  84. package/src/lib/dismissal.ts +24 -0
  85. package/src/lib/optimistic.ts +3 -1
  86. package/src/lib/queries.ts +108 -14
  87. package/src/lib/row-reads.ts +64 -0
  88. package/src/options.ts +38 -50
  89. package/src/pages/audit.tsx +15 -24
  90. package/src/pages/environment.tsx +326 -97
  91. package/src/pages/project-environments.tsx +8 -34
  92. package/src/pages/project-settings.tsx +9 -20
  93. package/src/pages/project.tsx +1 -5
  94. package/src/pages/projects.tsx +13 -28
  95. package/src/parity.ts +3 -3
  96. package/src/styles/globals.css +87 -128
  97. package/dist/chunks/directory-pMVS1m-c.js.map +0 -1
  98. package/dist/chunks/principal-page-CYJIJAdp.js.map +0 -1
  99. package/dist/chunks/project-environments-lEzFHUt4.js +0 -11
  100. package/dist/chunks/project-environments-lEzFHUt4.js.map +0 -1
  101. package/dist/chunks/queries-gigcQOO_.js.map +0 -1
  102. package/dist/chunks/ui-Br-dNUTc.js.map +0 -1
  103. package/dist/chunks/use-change-BdS1gzyo.js.map +0 -1
@@ -1,22 +1,22 @@
1
- import { n as isActiveAccessibleEnvironment } from "../chunks/project-environments-lEzFHUt4.js";
2
- import { a as ErrorLine, c as Notice, d as Tip, i as EmptyState, l as Spinner, m as breakAfterUnderscores, n as ConfirmDialog, o as MenuPopup, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-Br-dNUTc.js";
3
- import { i as SecretReadOnly } from "../chunks/affordances-D0GyCT-I.js";
1
+ import { E as isActiveAccessibleEnvironment, i as keys, t as affects, v as queries, w as canRevealSecrets } from "../chunks/queries-BvSw1xBN.js";
2
+ import { a as ErrorLine, c as Notice, d as Tip, g as createCopier, h as breakAfterUnderscores, i as EmptyState, l as Spinner, n as ConfirmDialog, o as MenuPopup, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-2kwXXfrX.js";
3
+ import { i as SecretReadOnly } from "../chunks/affordances-Dtyha68j.js";
4
4
  import { $ as SlashCircle, A as History, D as Generate, E as Folder, G as Plus, H as MoreHorizontal, J as Search, L as Lock, M as Key, S as Clock, T as EyeOff, W as Pencil, Z as Shuffle, _ as Check, g as ArrowRight, h as Archive, i as PageHeader, k as Hash, n as ClosedDoor, o as failureMessage, p as AlertCircle, q as RotateBack, rt as Upload, st as X, t as Card, tt as Terminal, u as useCoffre, w as Eye, x as ChevronsUpDown, y as ChevronDown } from "../chunks/page-JTORvh-N.js";
5
- import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-Zf3kZVhd.js";
6
- import { g as queries, i as keys, t as affects, x as canRevealSecrets } from "../chunks/queries-gigcQOO_.js";
7
- import { t as useShell } from "../chunks/use-shell-BCU505bx.js";
8
- import { D as companionsOf, O as hasSecretEditConflict, S as restoreSecret, T as saveSecrets, _ as moveSecret, a as archiveSecret, k as secretChangeFor, n as useChangeStatus, r as UnsavedEdits, t as useChange } from "../chunks/use-change-BdS1gzyo.js";
9
- import { i as secretKeyProblem } from "../chunks/validation-DiHIwZRA.js";
5
+ import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-BsIHspy4.js";
6
+ import { t as useShell } from "../chunks/use-shell-DhFoHjDS.js";
7
+ import { A as saveSecrets, D as restoreSecret, E as restoreMissing, M as companionsOf, N as hasSecretEditConflict, P as secretChangeFor, a as UnsavedEdits, b as missingList, i as changeOptions, m as dismissMissing, n as useChangeStatus, r as changeKey, s as archiveSecret, t as useChange, x as moveSecret } from "../chunks/use-change-DIQTGXER.js";
8
+ import { i as secretKeyProblem, n as folderProblem } from "../chunks/validation-DiHIwZRA.js";
10
9
  import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
11
- import { t as useAction } from "../chunks/use-action-CQGGNqWb.js";
12
- import { n as FolderRow, r as MoveToFolder, t as FolderMenu } from "../chunks/folders-hR2Lnk0k.js";
13
- import { i as ReferenceValue, n as LentReferences, o as archiveBlockers, r as MakeReference, t as ArchiveBlocked } from "../chunks/references-DZ179hTJ.js";
14
- import { useEffect, useId, useRef, useState } from "react";
10
+ import { t as useAction } from "../chunks/use-action-Bv7yQ0DW.js";
11
+ import { n as FolderRow, r as MoveToFolder, t as FolderMenu } from "../chunks/folders-Dw240WMJ.js";
12
+ import { t as MultiCombobox } from "../chunks/multi-combobox-CsIXihuc.js";
13
+ import { i as ReferenceValue, n as LentReferences, o as archiveBlockers, r as MakeReference, t as ArchiveBlocked } from "../chunks/references-DCoSPtvw.js";
14
+ import { useEffect, useId, useReducer, useRef, useState } from "react";
15
15
  import { Link } from "@tanstack/react-router";
16
16
  import { toast } from "sonner";
17
17
  import { Menu } from "@base-ui/react/menu";
18
18
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
19
- import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
19
+ import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from "@tanstack/react-query";
20
20
  import { CoffreError, ageInDays, byFolder, foldersOf, olderThan, planImport, shownMember } from "@coffre/client";
21
21
  import { parseDotenv } from "@coffre/core/dotenv";
22
22
  //#region src/lib/reveal.ts
@@ -24,6 +24,54 @@ function revealIsCurrent(reveal, currentVersion) {
24
24
  return reveal !== null && reveal.version === currentVersion;
25
25
  }
26
26
  //#endregion
27
+ //#region src/lib/row-reads.ts
28
+ var noReads = {
29
+ reveal: null,
30
+ revealing: false,
31
+ error: null,
32
+ copyError: null
33
+ };
34
+ function rowReads(state, action) {
35
+ switch (action.type) {
36
+ case "set-reveal": return {
37
+ ...state,
38
+ reveal: action.reveal
39
+ };
40
+ case "read-started": return {
41
+ ...state,
42
+ revealing: true
43
+ };
44
+ case "read-succeeded": return {
45
+ ...state,
46
+ revealing: false,
47
+ error: null,
48
+ reveal: action.reveal ?? state.reveal
49
+ };
50
+ case "read-failed": return {
51
+ ...state,
52
+ revealing: false,
53
+ error: action.message
54
+ };
55
+ case "copy-started":
56
+ case "copy-succeeded": return {
57
+ ...state,
58
+ copyError: null
59
+ };
60
+ case "copy-failed": return {
61
+ ...state,
62
+ copyError: action.message
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Whether the eye button is out of reach: while a read is on its way and there
68
+ * is nothing on screen yet. Once a value is shown, Hide is always available,
69
+ * whatever else is being read.
70
+ */
71
+ function revealToggleDisabled(state, shown) {
72
+ return shown === null && state.revealing;
73
+ }
74
+ //#endregion
27
75
  //#region src/lib/secret-order.ts
28
76
  /**
29
77
  * The keys in `sort`'s order, from the listing's, by name. By age, those
@@ -579,13 +627,33 @@ function NamedValue({ label, format, name, onName, value, describedBy }) {
579
627
  });
580
628
  }
581
629
  //#endregion
630
+ //#region src/lib/dismissal.ts
631
+ /**
632
+ * Dismiss missing keys, and say so at once in a toast with Undo. A refused
633
+ * dismissal turns that toast into why it was refused, so the reason shows
634
+ * whatever the list does next: when reading it again fails too, the panel
635
+ * has no rows left to say it beneath.
636
+ */
637
+ function dismissWithUndo(entries, { dismiss, restore }) {
638
+ const said = toast.success(entries.length === 1 ? `${entries[0].key} dismissed` : `${entries.length} keys dismissed`, { action: {
639
+ label: "Undo",
640
+ onClick: () => void restore(entries).catch((error) => toast.error(`Not restored. ${failureMessage(error)}`))
641
+ } });
642
+ dismiss(entries).catch((error) => toast.error(`Not dismissed. ${failureMessage(error)}`, {
643
+ id: said,
644
+ action: void 0
645
+ }));
646
+ return said;
647
+ }
648
+ //#endregion
582
649
  //#region src/components/missing.tsx
583
650
  /**
584
651
  * Keys the environment's siblings have and it lacks, by name, whether you
585
- * read them or not (docs/design/environments.md): each with Add, which opens a new row with
586
- * its name, and Dismiss, which the whole team then sees, and below them
587
- * Dismiss all and what was dismissed, each with Restore. Nothing shows when
588
- * nothing is missing or dismissed.
652
+ * read them or not (docs/design/environments.md): each with Add, which opens
653
+ * a new row with its name, and Dismiss, which the whole team then sees, and
654
+ * below them Dismiss all. Nothing shows when nothing is missing, dismissed
655
+ * keys included: they are restored from the CLI (`coffre missing
656
+ * --dismissed`), or by Undo right after dismissing.
589
657
  */
590
658
  function MissingKeys({ project, environment, canWrite, onAdd }) {
591
659
  const coffre = useCoffre();
@@ -594,118 +662,84 @@ function MissingKeys({ project, environment, canWrite, onAdd }) {
594
662
  environment
595
663
  };
596
664
  const { data } = useQuery(queries.missing(coffre, place));
597
- const { run, pending, error } = useAction();
598
- const [showDismissed, setShowDismissed] = useState(false);
599
- if (data?.ok !== true || data.missing.length === 0 && data.dismissed.length === 0) return null;
600
- const { missing, dismissed } = data;
601
- const path = `${project}/${environment}`;
602
- const dismiss = (patch) => void run(() => coffre.environments.dismiss(path, patch), { affects: affects.secrets(place) });
603
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Card, {
665
+ const queryClient = useQueryClient();
666
+ const dismissKeys = useMutation(changeOptions(queryClient, dismissMissing(coffre, place))).mutateAsync;
667
+ const restoreKeys = useMutation(changeOptions(queryClient, restoreMissing(coffre, place))).mutateAsync;
668
+ const list = missingList(place);
669
+ const { status, dismiss: forget } = useChangeStatus(list.queryKey);
670
+ const missing = data === void 0 ? [] : list.items(data);
671
+ if (missing.length === 0) return null;
672
+ const columns = canWrite ? 3 : 2;
673
+ const dismiss = (entries) => void dismissWithUndo(entries, {
674
+ dismiss: dismissKeys,
675
+ restore: restoreKeys
676
+ });
677
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Card, {
604
678
  wide: true,
605
679
  labelledBy: "missing-keys",
606
- title: missing.length === 0 ? "Nothing missing" : `${missing.length} ${missing.length === 1 ? "key" : "keys"} from other environments ${missing.length === 1 ? "isn't" : "aren't"} here`,
680
+ title: `${missing.length} ${missing.length === 1 ? "key" : "keys"} from other environments ${missing.length === 1 ? "isn't" : "aren't"} here`,
607
681
  description: "Compared with every other environment of the project, by key name.",
608
- children: [/* @__PURE__ */ jsx("div", {
682
+ children: /* @__PURE__ */ jsx("div", {
609
683
  className: "dt-wrap",
610
684
  children: /* @__PURE__ */ jsx("table", {
611
685
  className: "dt stacks missing-keys",
612
- children: /* @__PURE__ */ jsxs("tbody", { children: [
613
- missing.map((entry) => /* @__PURE__ */ jsxs("tr", { children: [
614
- /* @__PURE__ */ jsx("td", {
615
- className: "mono",
616
- "data-label": "Key",
617
- children: entry.key
618
- }),
619
- /* @__PURE__ */ jsxs("td", {
620
- className: "cell-muted",
621
- "data-label": "In",
622
- children: [
623
- "In ",
624
- entry.in.join(", "),
625
- entry.folder !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [
626
- ", in ",
627
- entry.folder,
628
- "/"
629
- ] })
630
- ]
631
- }),
632
- canWrite && /* @__PURE__ */ jsx("td", {
633
- className: "col-actions",
634
- children: /* @__PURE__ */ jsxs("div", {
635
- className: "acts",
636
- children: [/* @__PURE__ */ jsx("button", {
637
- type: "button",
638
- className: "btn btn-sm",
639
- onClick: () => onAdd(entry.key),
640
- children: "Add"
641
- }), /* @__PURE__ */ jsx("button", {
642
- type: "button",
643
- className: "btn btn-sm btn-quiet",
644
- disabled: pending,
645
- onClick: () => dismiss({ [entry.key]: true }),
646
- children: "Dismiss"
647
- })]
648
- })
649
- })
650
- ] }, entry.key)),
651
- showDismissed && dismissed.length > 0 && /* @__PURE__ */ jsx("tr", {
652
- className: "folder-row",
653
- children: /* @__PURE__ */ jsx("th", {
654
- colSpan: canWrite ? 3 : 2,
655
- scope: "rowgroup",
656
- children: "Dismissed"
657
- })
658
- }),
659
- showDismissed && dismissed.map((entry) => /* @__PURE__ */ jsxs("tr", { children: [
660
- /* @__PURE__ */ jsx("td", {
661
- className: "mono",
662
- "data-label": "Key",
663
- children: entry.key
664
- }),
665
- /* @__PURE__ */ jsxs("td", {
666
- className: "cell-muted",
667
- "data-label": "Dismissed",
668
- children: [
669
- "By ",
670
- entry.dismissedBy,
671
- " ",
672
- /* @__PURE__ */ jsx(Timestamp, {
673
- iso: entry.dismissedAt,
674
- display: "relative"
675
- }),
676
- "; in ",
677
- entry.in.join(", ")
678
- ]
679
- }),
680
- canWrite && /* @__PURE__ */ jsx("td", {
681
- className: "col-actions",
682
- children: /* @__PURE__ */ jsx("button", {
683
- type: "button",
684
- className: "btn btn-sm",
685
- disabled: pending,
686
- onClick: () => dismiss({ [entry.key]: null }),
687
- children: "Restore"
686
+ children: /* @__PURE__ */ jsx("tbody", { children: missing.map((entry) => {
687
+ const state = status(entry.key);
688
+ return [/* @__PURE__ */ jsxs("tr", {
689
+ className: rowClass(state),
690
+ children: [
691
+ /* @__PURE__ */ jsx("td", {
692
+ className: "mono",
693
+ "data-label": "Key",
694
+ children: entry.key
695
+ }),
696
+ /* @__PURE__ */ jsxs("td", {
697
+ className: "cell-muted",
698
+ "data-label": "In",
699
+ children: [
700
+ "In ",
701
+ entry.in.join(", "),
702
+ entry.folder !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [
703
+ ", in ",
704
+ entry.folder,
705
+ "/"
706
+ ] })
707
+ ]
708
+ }),
709
+ canWrite && /* @__PURE__ */ jsx("td", {
710
+ className: "col-actions",
711
+ children: /* @__PURE__ */ jsxs("div", {
712
+ className: "acts",
713
+ children: [/* @__PURE__ */ jsx("button", {
714
+ type: "button",
715
+ className: "btn btn-sm",
716
+ onClick: () => onAdd(entry.key),
717
+ children: "Add"
718
+ }), /* @__PURE__ */ jsx("button", {
719
+ type: "button",
720
+ className: "btn btn-sm btn-quiet",
721
+ onClick: () => dismiss([entry]),
722
+ children: "Dismiss"
723
+ })]
724
+ })
688
725
  })
689
- })
690
- ] }, `dismissed:${entry.key}`))
691
- ] })
726
+ ]
727
+ }, entry.key), /* @__PURE__ */ jsx(RowFailure, {
728
+ status: state,
729
+ columns,
730
+ onDismiss: () => state.state === "failed" && forget(state.mutationId)
731
+ }, `failure:${entry.key}`)];
732
+ }) })
692
733
  })
693
- }), error !== null && /* @__PURE__ */ jsx(ErrorLine, { error })]
694
- }), /* @__PURE__ */ jsxs("div", {
734
+ })
735
+ }), canWrite && missing.length > 1 && /* @__PURE__ */ jsx("div", {
695
736
  className: "table-actions",
696
- children: [canWrite && missing.length > 1 && /* @__PURE__ */ jsx("button", {
737
+ children: /* @__PURE__ */ jsx("button", {
697
738
  type: "button",
698
739
  className: "btn",
699
- disabled: pending,
700
- onClick: () => dismiss(Object.fromEntries(missing.map((entry) => [entry.key, true]))),
740
+ onClick: () => dismiss(missing),
701
741
  children: "Dismiss all"
702
- }), dismissed.length > 0 && /* @__PURE__ */ jsx("button", {
703
- type: "button",
704
- className: "btn btn-quiet",
705
- "aria-expanded": showDismissed,
706
- onClick: () => setShowDismissed((open) => !open),
707
- children: showDismissed ? "Hide dismissed" : `Dismissed (${dismissed.length})`
708
- })]
742
+ })
709
743
  })] });
710
744
  }
711
745
  //#endregion
@@ -719,6 +753,10 @@ var Route = pageRoute();
719
753
  * already logged, and re-revealing writes a second, honest audit row.
720
754
  */
721
755
  var REVEAL_TTL_SECONDS = 45;
756
+ /** Why a read of a secret's value failed, as the row says it. */
757
+ function readFailureMessage(failure) {
758
+ return failure instanceof CoffreError ? failureMessage(failure) : "The request could not be sent. Nothing was read.";
759
+ }
722
760
  function EnvironmentPage() {
723
761
  const { project, environment } = Route.useParams();
724
762
  const { data: result } = useSuspenseQuery(queries.secrets(useCoffre(), {
@@ -754,6 +792,7 @@ function EnvironmentPage() {
754
792
  }
755
793
  function EnvironmentLedger({ project, environment, permissions, keys: keys$1, rotateAfterDays }) {
756
794
  const coffre = useCoffre();
795
+ const queryClient = useQueryClient();
757
796
  const { principal } = useShell();
758
797
  const save = useChange(saveSecrets(coffre, {
759
798
  project,
@@ -796,12 +835,14 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
796
835
  by,
797
836
  descending: current.by === by && !current.descending
798
837
  }));
838
+ const [addingFolder, setAddingFolder] = useState(false);
799
839
  const nextDraftId = useRef(0);
800
840
  const canWrite = permissions.includes("secret.write");
801
841
  const canArchive = permissions.includes("secret.archive");
802
842
  const canReveal = canRevealSecrets(permissions);
803
843
  const active = byFolder(keys$1.filter((entry) => !entry.archived)).flatMap(([, entries]) => entries);
804
844
  const folders = foldersOf(active);
845
+ const settled = active.filter((entry) => status(entry.key).state !== "pending" && secretChangeFor(changes, entry.key) === void 0);
805
846
  const refile = useAction();
806
847
  const place = `${project}/${environment}`;
807
848
  const folderMenu = (folder, count) => canWrite && /* @__PURE__ */ jsx(FolderMenu, {
@@ -893,6 +934,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
893
934
  function sendAlone(batch) {
894
935
  setSaveError(null);
895
936
  save(batch, { onError: (error) => {
937
+ forgetRefusal(batch);
896
938
  const left = error instanceof UnsavedEdits ? error.outcome : batch;
897
939
  setDrafts((rows) => [...rows, ...left.drafts]);
898
940
  setChanges((current) => ({
@@ -925,17 +967,25 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
925
967
  setChanges({});
926
968
  setEditing(/* @__PURE__ */ new Set());
927
969
  setSaveError(null);
928
- for (const entry of keys$1) {
929
- const state = status(entry.key);
930
- if (state.state === "failed") dismiss(state.mutationId);
931
- }
970
+ }
971
+ /**
972
+ * A refused save leaves its rows no failure of their own: its edits come
973
+ * back on them, and the bar under the table says why. Every other refused
974
+ * change, a move for one, says why beneath its row.
975
+ */
976
+ function forgetRefusal(batch) {
977
+ const saves = queryClient.getMutationCache().findAll({ mutationKey: changeKey(keys.secrets({
978
+ project,
979
+ environment
980
+ })) });
981
+ for (const each of saves) if (each.state.variables === batch) dismiss(each.mutationId);
932
982
  }
933
983
  /**
934
984
  * Write every pending edit (`saveSecrets`): renames one by one, then the
935
985
  * rest as one patch that lands whole or not at all. The edits show in the
936
986
  * list at once, each row marked as saving; whatever did not land comes
937
987
  * back as pending, so pressing save again retries exactly that, and the
938
- * save bar says why.
988
+ * bar under the table says why.
939
989
  */
940
990
  function saveChanges() {
941
991
  if (!ready) return;
@@ -949,6 +999,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
949
999
  setEditing(/* @__PURE__ */ new Set());
950
1000
  setSaveError(null);
951
1001
  save(batch, { onError: (error) => {
1002
+ forgetRefusal(batch);
952
1003
  const left = error instanceof UnsavedEdits ? error.outcome : batch;
953
1004
  setDrafts(left.drafts);
954
1005
  setChanges(left.changes);
@@ -1011,11 +1062,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
1011
1062
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
1012
1063
  /* @__PURE__ */ jsx(PageHeader, {
1013
1064
  tile: project,
1014
- title: environment,
1015
- aside: /* @__PURE__ */ jsx(EnvironmentName, {
1016
- project,
1017
- environment
1018
- })
1065
+ title: environment
1019
1066
  }),
1020
1067
  (active.length > 0 || drafts.length > 0) && /* @__PURE__ */ jsxs("div", {
1021
1068
  className: "toolbar",
@@ -1069,10 +1116,10 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
1069
1116
  onAdd: addDraft
1070
1117
  }),
1071
1118
  refile.error !== null && /* @__PURE__ */ jsx(ErrorLine, { error: refile.error }),
1072
- /* @__PURE__ */ jsx("section", {
1119
+ /* @__PURE__ */ jsxs("section", {
1073
1120
  className: "card card-wide",
1074
1121
  "aria-label": "Secrets",
1075
- children: active.length === 0 && drafts.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
1122
+ children: [active.length === 0 && drafts.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
1076
1123
  title: "No secrets yet",
1077
1124
  children: canWrite ? "Add them one by one, or import a .env file." : "Adding secrets here needs secret.write."
1078
1125
  }) : /* @__PURE__ */ jsx("div", {
@@ -1156,6 +1203,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
1156
1203
  environments: readable,
1157
1204
  status: state,
1158
1205
  disabled: state.state === "pending",
1206
+ onDismiss: dismiss,
1159
1207
  columns,
1160
1208
  onEdit: () => setEditing((current) => new Set(current).add(entry.key)),
1161
1209
  onPatch: (patch) => patchChange(entry, patch),
@@ -1205,18 +1253,39 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
1205
1253
  }, draft.id))
1206
1254
  ] })]
1207
1255
  })
1208
- })
1256
+ }), pendingCount > 0 && /* @__PURE__ */ jsx(PendingBar, {
1257
+ pending,
1258
+ ready,
1259
+ error: saveError ?? problem,
1260
+ onDiscard: discardAll,
1261
+ onSave: saveChanges
1262
+ })]
1209
1263
  }),
1210
1264
  canWrite && /* @__PURE__ */ jsxs("div", {
1211
1265
  className: "table-actions",
1212
- children: [/* @__PURE__ */ jsxs("button", {
1213
- className: "btn btn-primary",
1214
- onClick: () => addDraft(),
1215
- children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "New secret"]
1216
- }), canReveal && /* @__PURE__ */ jsx(ImportEnv, {
1217
- project,
1218
- environment
1219
- })]
1266
+ children: [
1267
+ /* @__PURE__ */ jsx(AddButton, {
1268
+ onAddSecret: () => addDraft(),
1269
+ onAddFolder: () => setAddingFolder(true),
1270
+ canAddFolder: settled.length > 0
1271
+ }),
1272
+ canReveal && /* @__PURE__ */ jsx(ImportEnv, {
1273
+ project,
1274
+ environment
1275
+ }),
1276
+ /* @__PURE__ */ jsx(AddFolder, {
1277
+ open: addingFolder,
1278
+ onOpenChange: setAddingFolder,
1279
+ keys: settled.map((entry) => entry.key),
1280
+ folders,
1281
+ onAdd: (folder, keys) => {
1282
+ for (const entry of settled) if (keys.includes(entry.key) && entry.folder !== folder) move({
1283
+ key: entry.key,
1284
+ folder
1285
+ });
1286
+ }
1287
+ })
1288
+ ]
1220
1289
  }),
1221
1290
  archived.length > 0 && /* @__PURE__ */ jsx(Card, {
1222
1291
  wide: true,
@@ -1273,68 +1342,180 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, ro
1273
1342
  }, entry.key)) })]
1274
1343
  })
1275
1344
  })
1276
- }),
1277
- pendingCount > 0 && /* @__PURE__ */ jsx("div", {
1278
- className: "savebar",
1279
- role: "region",
1280
- "aria-label": "Unsaved changes",
1281
- children: /* @__PURE__ */ jsxs("div", {
1282
- className: "savebar-inner",
1345
+ })
1346
+ ] });
1347
+ }
1348
+ /**
1349
+ * The pending edits, at the foot of the table they are made in: what they
1350
+ * are, Discard and Save. It sticks to the bottom of the window while the
1351
+ * table runs past it, so Save stays in reach of any row.
1352
+ */
1353
+ function PendingBar({ pending, ready, error, onDiscard, onSave }) {
1354
+ const count = pending.length;
1355
+ return /* @__PURE__ */ jsxs("div", {
1356
+ className: "pending-bar",
1357
+ role: "region",
1358
+ "aria-label": "Unsaved changes",
1359
+ children: [
1360
+ /* @__PURE__ */ jsxs("span", {
1361
+ className: "pending-count",
1283
1362
  children: [
1284
- /* @__PURE__ */ jsxs("span", {
1285
- className: "savebar-count",
1286
- children: [
1287
- /* @__PURE__ */ jsx("span", {
1288
- className: "dot",
1289
- "aria-hidden": true
1290
- }),
1291
- pendingCount,
1292
- " unsaved change",
1293
- pendingCount === 1 ? "" : "s"
1294
- ]
1295
- }),
1296
- /* @__PURE__ */ jsxs("span", {
1297
- className: "savebar-summary",
1298
- children: [pending.slice(0, 3).map((item, index) => /* @__PURE__ */ jsxs("span", { children: [
1299
- index > 0 && " · ",
1300
- /* @__PURE__ */ jsx("span", {
1301
- className: "mono",
1302
- children: item.key
1303
- }),
1304
- " ",
1305
- item.what
1306
- ] }, `${item.key}:${index}`)), pending.length > 3 && ` · and ${pending.length - 3} more`]
1363
+ /* @__PURE__ */ jsx("span", {
1364
+ className: "dot",
1365
+ "aria-hidden": true
1307
1366
  }),
1308
- /* @__PURE__ */ jsxs("div", {
1309
- className: "savebar-actions",
1310
- children: [/* @__PURE__ */ jsx("button", {
1311
- className: "btn btn-sm",
1312
- onClick: discardAll,
1313
- children: "Discard"
1314
- }), /* @__PURE__ */ jsxs("button", {
1315
- className: "btn btn-sm btn-primary",
1316
- onClick: saveChanges,
1317
- disabled: !ready,
1318
- title: "Save (⌘ Enter or Ctrl Enter)",
1319
- "aria-keyshortcuts": "Meta+Enter Control+Enter",
1320
- children: ["Save ", pendingCount === 1 ? "change" : `${pendingCount} changes`]
1321
- })]
1367
+ count,
1368
+ " unsaved change",
1369
+ count === 1 ? "" : "s"
1370
+ ]
1371
+ }),
1372
+ /* @__PURE__ */ jsxs("span", {
1373
+ className: "pending-summary",
1374
+ children: [pending.slice(0, 3).map((item, index) => /* @__PURE__ */ jsxs("span", { children: [
1375
+ index > 0 && " · ",
1376
+ /* @__PURE__ */ jsx("span", {
1377
+ className: "mono",
1378
+ children: item.key
1322
1379
  }),
1323
- (saveError ?? problem) !== null && /* @__PURE__ */ jsxs("p", {
1324
- className: "savebar-error",
1325
- role: "alert",
1326
- children: [/* @__PURE__ */ jsx(AlertCircle, { size: 14 }), /* @__PURE__ */ jsx("span", { children: saveError ?? problem })]
1380
+ " ",
1381
+ item.what
1382
+ ] }, `${item.key}:${index}`)), count > 3 && ` · and ${count - 3} more`]
1383
+ }),
1384
+ /* @__PURE__ */ jsxs("div", {
1385
+ className: "pending-actions",
1386
+ children: [/* @__PURE__ */ jsx("button", {
1387
+ className: "btn btn-sm",
1388
+ onClick: onDiscard,
1389
+ children: "Discard"
1390
+ }), /* @__PURE__ */ jsxs("button", {
1391
+ className: "btn btn-sm btn-primary",
1392
+ onClick: onSave,
1393
+ disabled: !ready,
1394
+ title: "Save (⌘ Enter or Ctrl Enter)",
1395
+ "aria-keyshortcuts": "Meta+Enter Control+Enter",
1396
+ children: ["Save ", count === 1 ? "change" : `${count} changes`]
1397
+ })]
1398
+ }),
1399
+ error !== null && /* @__PURE__ */ jsxs("p", {
1400
+ className: "pending-error",
1401
+ role: "alert",
1402
+ children: [/* @__PURE__ */ jsx(AlertCircle, { size: 14 }), /* @__PURE__ */ jsx("span", { children: error })]
1403
+ })
1404
+ ]
1405
+ });
1406
+ }
1407
+ /**
1408
+ * Add secret, and beside it a menu of the other things to add: a folder.
1409
+ * One button in look, two to the keyboard and to a screen reader, the
1410
+ * second a menu button.
1411
+ */
1412
+ function AddButton({ onAddSecret, onAddFolder, canAddFolder }) {
1413
+ return /* @__PURE__ */ jsxs("div", {
1414
+ className: "split-button",
1415
+ children: [/* @__PURE__ */ jsxs("button", {
1416
+ className: "btn btn-primary",
1417
+ onClick: onAddSecret,
1418
+ children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "Add secret"]
1419
+ }), /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, {
1420
+ className: "btn btn-primary btn-icon",
1421
+ "aria-label": "More to add",
1422
+ children: /* @__PURE__ */ jsx(ChevronDown, { size: 14 })
1423
+ }), /* @__PURE__ */ jsx(MenuPopup, {
1424
+ align: "start",
1425
+ children: /* @__PURE__ */ jsxs(Menu.Item, {
1426
+ className: "menu-item",
1427
+ onClick: onAddFolder,
1428
+ disabled: !canAddFolder,
1429
+ children: [
1430
+ /* @__PURE__ */ jsx(Folder, { size: 14 }),
1431
+ "Add folder…",
1432
+ !canAddFolder && /* @__PURE__ */ jsx("span", {
1433
+ className: "menu-hint",
1434
+ children: "after a secret"
1327
1435
  })
1328
1436
  ]
1329
1437
  })
1330
- })
1331
- ] });
1438
+ })] })]
1439
+ });
1332
1440
  }
1333
- /** The display name sits beside the slug; it comes from the shell's project tree. */
1334
- function EnvironmentName({ project, environment }) {
1335
- const { projects } = useShell();
1336
- const name = projects.find((entry) => entry.slug === project)?.environments.find((entry) => entry.slug === environment)?.name;
1337
- return name === void 0 ? null : /* @__PURE__ */ jsx(Fragment$1, { children: name });
1441
+ /**
1442
+ * A new folder, and the secrets filed in it. A folder is a name on what it
1443
+ * holds (docs/design/environments.md), so it is made with its first
1444
+ * secrets: one with nothing in it would not be there to see.
1445
+ */
1446
+ function AddFolder({ open, onOpenChange, keys, folders, onAdd }) {
1447
+ const [name, setName] = useState("");
1448
+ const [chosen, setChosen] = useState([]);
1449
+ useEffect(() => {
1450
+ if (!open) return;
1451
+ setName("");
1452
+ setChosen([]);
1453
+ }, [open]);
1454
+ const problem = folderProblem(name);
1455
+ const joins = folders.includes(name);
1456
+ const ready = name !== "" && problem === null && chosen.length > 0;
1457
+ return /* @__PURE__ */ jsx(Modal, {
1458
+ open,
1459
+ onOpenChange,
1460
+ title: "Add a folder",
1461
+ description: "Folders only arrange the list: names, values and access stay as they are.",
1462
+ children: /* @__PURE__ */ jsxs("form", {
1463
+ className: "form",
1464
+ onSubmit: (event) => {
1465
+ event.preventDefault();
1466
+ if (!ready) return;
1467
+ onAdd(name, chosen);
1468
+ onOpenChange(false);
1469
+ },
1470
+ children: [
1471
+ /* @__PURE__ */ jsxs("label", {
1472
+ className: "field",
1473
+ children: [
1474
+ /* @__PURE__ */ jsx("span", {
1475
+ className: "label",
1476
+ children: "Name"
1477
+ }),
1478
+ /* @__PURE__ */ jsx("input", {
1479
+ className: "input",
1480
+ autoFocus: true,
1481
+ spellCheck: false,
1482
+ autoComplete: "off",
1483
+ value: name,
1484
+ "aria-invalid": problem !== null,
1485
+ onChange: (event) => setName(event.target.value)
1486
+ }),
1487
+ /* @__PURE__ */ jsx("span", {
1488
+ className: `hint${problem !== null ? " edit-note-error" : ""}`,
1489
+ children: problem ?? (joins ? `${name} is in use: the secrets join it.` : "One level: no slash.")
1490
+ })
1491
+ ]
1492
+ }),
1493
+ /* @__PURE__ */ jsx(MultiCombobox, {
1494
+ label: "Secrets in it",
1495
+ options: keys,
1496
+ value: chosen,
1497
+ onChange: setChosen,
1498
+ placeholder: "Pick one or more…",
1499
+ hint: "A folder holds at least one secret.",
1500
+ mono: true
1501
+ }),
1502
+ /* @__PURE__ */ jsxs("div", {
1503
+ className: "dialog-actions",
1504
+ children: [/* @__PURE__ */ jsx("button", {
1505
+ className: "btn",
1506
+ type: "button",
1507
+ onClick: () => onOpenChange(false),
1508
+ children: "Cancel"
1509
+ }), /* @__PURE__ */ jsx("button", {
1510
+ className: "btn btn-primary",
1511
+ type: "submit",
1512
+ disabled: !ready,
1513
+ children: "Add folder"
1514
+ })]
1515
+ })
1516
+ ]
1517
+ })
1518
+ });
1338
1519
  }
1339
1520
  var lineCount = (text) => text.split("\n").length;
1340
1521
  function ValueField({ label, value, start = "", onChange, placeholder, disabled, autoFocus, onEscape, generate }) {
@@ -1343,6 +1524,12 @@ function ValueField({ label, value, start = "", onChange, placeholder, disabled,
1343
1524
  const [lines, setLines] = useState(() => start.includes("\n") || value.includes("\n"));
1344
1525
  if (!lines && value.includes("\n")) setLines(true);
1345
1526
  const caret = useRef(null);
1527
+ const insert = (text, field) => {
1528
+ const from = field.selectionStart ?? value.length;
1529
+ const to = field.selectionEnd ?? from;
1530
+ caret.current = from + text.length;
1531
+ onChange(value.slice(0, from) + text + value.slice(to));
1532
+ };
1346
1533
  const field = {
1347
1534
  className: "input input-mono",
1348
1535
  masked: !shown,
@@ -1375,11 +1562,13 @@ function ValueField({ label, value, start = "", onChange, placeholder, disabled,
1375
1562
  const pasted = event.clipboardData.getData("text/plain");
1376
1563
  if (!/[\r\n]/.test(pasted)) return;
1377
1564
  event.preventDefault();
1378
- const text = pasted.replace(/\r\n?/g, "\n");
1379
- const from = event.currentTarget.selectionStart ?? value.length;
1380
- const to = event.currentTarget.selectionEnd ?? from;
1381
- caret.current = from + text.length;
1382
- onChange(value.slice(0, from) + text + value.slice(to));
1565
+ insert(pasted.replace(/\r\n?/g, "\n"), event.currentTarget);
1566
+ },
1567
+ onKeyDown: (event) => {
1568
+ if (event.key === "Enter" && event.shiftKey && !event.metaKey && !event.ctrlKey && !event.nativeEvent.isComposing) {
1569
+ event.preventDefault();
1570
+ insert("\n", event.currentTarget);
1571
+ } else field.onKeyDown(event);
1383
1572
  }
1384
1573
  }),
1385
1574
  /* @__PURE__ */ jsx(Tip, {
@@ -1439,10 +1628,14 @@ function useSecondsLeft(reveal) {
1439
1628
  if (reveal === null) return 0;
1440
1629
  return Math.max(0, Math.ceil(REVEAL_TTL_SECONDS - (now - reveal.at) / 1e3));
1441
1630
  }
1442
- function SecretRow({ number, project, environment, entry, rotateAfterDays, change, editing, canWrite, canArchive, canReveal, folders, onMove, lent, environments, status, disabled, columns, onEdit, onPatch, onUndo, onSave, versionOf, saveReady, onMarkArchive }) {
1443
- const [reveal, setReveal] = useState(null);
1631
+ function SecretRow({ number, project, environment, entry, rotateAfterDays, change, editing, canWrite, canArchive, canReveal, folders, onMove, lent, environments, status, disabled, onDismiss, columns, onEdit, onPatch, onUndo, onSave, versionOf, saveReady, onMarkArchive }) {
1632
+ const [reads, dispatch] = useReducer(rowReads, noReads);
1633
+ const { reveal, revealing, error, copyError } = reads;
1634
+ const setReveal = (next) => dispatch({
1635
+ type: "set-reveal",
1636
+ reveal: next
1637
+ });
1444
1638
  const coffre = useCoffre();
1445
- const [revealing, setRevealing] = useState(false);
1446
1639
  const [historyOpen, setHistoryOpen] = useState(false);
1447
1640
  const [moving, setMoving] = useState(false);
1448
1641
  const [referring, setReferring] = useState(false);
@@ -1454,7 +1647,6 @@ function SecretRow({ number, project, environment, entry, rotateAfterDays, chang
1454
1647
  const { reference } = entry;
1455
1648
  const readVersion = reference === null ? entry.version : reference.version;
1456
1649
  const holderPath = `${project}/${environment}/${entry.key}`;
1457
- const [error, setError] = useState(null);
1458
1650
  const [base, setBase] = useState(null);
1459
1651
  const shown = revealIsCurrent(reveal, readVersion) ? reveal : null;
1460
1652
  useEffect(() => {
@@ -1472,28 +1664,51 @@ function SecretRow({ number, project, environment, entry, rotateAfterDays, chang
1472
1664
  }, [editing]);
1473
1665
  async function readValue({ show = true } = {}) {
1474
1666
  if (shown !== null) return shown.value;
1475
- setRevealing(true);
1667
+ dispatch({ type: "read-started" });
1476
1668
  try {
1477
- const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
1478
- const value = values[entry.key];
1479
- setError(null);
1480
- if (show) setReveal({
1481
- value,
1482
- version: readVersion,
1483
- at: Date.now()
1669
+ const value = await fetchValue();
1670
+ dispatch({
1671
+ type: "read-succeeded",
1672
+ reveal: show ? {
1673
+ value,
1674
+ version: readVersion,
1675
+ at: Date.now()
1676
+ } : null
1484
1677
  });
1485
1678
  return value;
1486
1679
  } catch (failure) {
1487
- setError(failure instanceof CoffreError ? failureMessage(failure) : "The request could not be sent. Nothing was read.");
1680
+ dispatch({
1681
+ type: "read-failed",
1682
+ message: readFailureMessage(failure)
1683
+ });
1488
1684
  return null;
1489
- } finally {
1490
- setRevealing(false);
1491
1685
  }
1492
1686
  }
1687
+ async function fetchValue() {
1688
+ const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
1689
+ return values[entry.key];
1690
+ }
1493
1691
  function toggleReveal() {
1494
1692
  if (shown !== null) setReveal(null);
1495
1693
  else readValue();
1496
1694
  }
1695
+ const [copier] = useState(() => createCopier());
1696
+ function copyValue() {
1697
+ dispatch({ type: "copy-started" });
1698
+ const read = { failed: false };
1699
+ const text = shown !== null ? shown.value : fetchValue().catch((failure) => {
1700
+ read.failed = true;
1701
+ read.failure = failure;
1702
+ throw failure;
1703
+ });
1704
+ copier.run(text).then((result) => {
1705
+ if (result.outcome === "superseded") return;
1706
+ dispatch(result.outcome === "copied" ? { type: "copy-succeeded" } : {
1707
+ type: "copy-failed",
1708
+ message: read.failed ? readFailureMessage(read.failure) : "The browser did not allow copying to the clipboard. Reveal the value and copy it by hand."
1709
+ });
1710
+ });
1711
+ }
1497
1712
  const [opening, setOpening] = useState(false);
1498
1713
  const [focusName, setFocusName] = useState(false);
1499
1714
  async function startEdit({ name = false } = {}) {
@@ -1662,36 +1877,33 @@ function SecretRow({ number, project, environment, entry, rotateAfterDays, chang
1662
1877
  "aria-label": leaving ? `Keep ${entry.key}` : `Cancel editing ${entry.key}`,
1663
1878
  children: /* @__PURE__ */ jsx(X, { size: 15 })
1664
1879
  })
1665
- })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
1666
- shown !== null && /* @__PURE__ */ jsx(CopyButton, {
1880
+ })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(SecretReadOnly, {
1881
+ canReveal,
1882
+ children: [/* @__PURE__ */ jsx(CopyButton, {
1667
1883
  variant: "act",
1668
- value: shown.value,
1884
+ copier,
1885
+ onCopy: copyValue,
1669
1886
  label: `Copy ${entry.key}`
1670
- }),
1671
- /* @__PURE__ */ jsx(SecretReadOnly, {
1672
- canReveal,
1673
- children: /* @__PURE__ */ jsx(Tip, {
1674
- label: shown === null ? "Reveal" : "Hide",
1675
- children: /* @__PURE__ */ jsx("button", {
1676
- className: "act act-icon act-accent",
1677
- onClick: toggleReveal,
1678
- disabled: revealing,
1679
- "aria-label": `${shown === null ? "Reveal" : "Hide"} ${entry.key}`,
1680
- children: revealing && !opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : shown === null ? /* @__PURE__ */ jsx(Eye, { size: 15 }) : /* @__PURE__ */ jsx(EyeOff, { size: 15 })
1681
- })
1682
- })
1683
- }),
1684
- canWrite && /* @__PURE__ */ jsx(Tip, {
1685
- label: "Edit",
1887
+ }), /* @__PURE__ */ jsx(Tip, {
1888
+ label: shown === null ? "Reveal" : "Hide",
1686
1889
  children: /* @__PURE__ */ jsx("button", {
1687
- className: "act act-icon",
1688
- onClick: () => void startEdit(),
1689
- disabled: disabled || revealing,
1690
- "aria-label": `Edit ${entry.key}`,
1691
- children: opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : /* @__PURE__ */ jsx(Pencil, { size: 14 })
1890
+ className: "act act-icon act-accent",
1891
+ onClick: toggleReveal,
1892
+ disabled: revealToggleDisabled(reads, shown),
1893
+ "aria-label": `${shown === null ? "Reveal" : "Hide"} ${entry.key}`,
1894
+ children: revealing && !opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : shown === null ? /* @__PURE__ */ jsx(Eye, { size: 15 }) : /* @__PURE__ */ jsx(EyeOff, { size: 15 })
1692
1895
  })
1896
+ })]
1897
+ }), canWrite && /* @__PURE__ */ jsx(Tip, {
1898
+ label: "Edit",
1899
+ children: /* @__PURE__ */ jsx("button", {
1900
+ className: "act act-icon",
1901
+ onClick: () => void startEdit(),
1902
+ disabled: disabled || revealing,
1903
+ "aria-label": `Edit ${entry.key}`,
1904
+ children: opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : /* @__PURE__ */ jsx(Pencil, { size: 14 })
1693
1905
  })
1694
- ] })
1906
+ })] })
1695
1907
  })]
1696
1908
  })
1697
1909
  }),
@@ -1859,12 +2071,17 @@ function SecretRow({ number, project, environment, entry, rotateAfterDays, chang
1859
2071
  })
1860
2072
  })
1861
2073
  }),
1862
- (error ?? actError) !== null && /* @__PURE__ */ jsx("tr", {
2074
+ (error ?? actError) !== null || copyError !== null ? /* @__PURE__ */ jsx("tr", {
1863
2075
  className: "row-error",
1864
- children: /* @__PURE__ */ jsx("td", {
2076
+ children: /* @__PURE__ */ jsxs("td", {
1865
2077
  colSpan: columns,
1866
- children: /* @__PURE__ */ jsx(ErrorLine, { error: error ?? actError })
2078
+ children: [/* @__PURE__ */ jsx(ErrorLine, { error: error ?? actError }), /* @__PURE__ */ jsx(ErrorLine, { error: copyError })]
1867
2079
  })
2080
+ }) : null,
2081
+ /* @__PURE__ */ jsx(RowFailure, {
2082
+ status,
2083
+ columns,
2084
+ onDismiss: () => status.state === "failed" && onDismiss(status.mutationId)
1868
2085
  })
1869
2086
  ] });
1870
2087
  }