@10x-media/fields 0.1.0-beta.1 → 0.1.0-beta.10

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 (244) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +7 -3
  3. package/dist/exports/client.d.ts +10 -1
  4. package/dist/exports/client.js +9 -1
  5. package/dist/exports/color-utils.d.ts +2 -1
  6. package/dist/exports/color-utils.js +2 -1
  7. package/dist/exports/color.d.ts +2 -1
  8. package/dist/exports/color.js +2 -1
  9. package/dist/exports/encrypted.d.ts +7 -4
  10. package/dist/exports/encrypted.js +6 -3
  11. package/dist/exports/measurement-utils.d.ts +9 -0
  12. package/dist/exports/measurement-utils.js +8 -0
  13. package/dist/exports/measurement.d.ts +11 -0
  14. package/dist/exports/measurement.js +10 -0
  15. package/dist/exports/phone-utils.d.ts +4 -0
  16. package/dist/exports/phone-utils.js +4 -0
  17. package/dist/exports/phone.d.ts +6 -0
  18. package/dist/exports/phone.js +3 -0
  19. package/dist/exports/rsc.d.ts +5 -1
  20. package/dist/exports/rsc.js +5 -1
  21. package/dist/exports/types.d.ts +3 -2
  22. package/dist/fields/color/client/ColorField.d.ts +2 -0
  23. package/dist/fields/color/client/ColorField.js +35 -293
  24. package/dist/fields/color/client/ColorField.js.map +1 -1
  25. package/dist/fields/color/client/ColorInput.d.ts +44 -0
  26. package/dist/fields/color/client/ColorInput.js +374 -0
  27. package/dist/fields/color/client/ColorInput.js.map +1 -0
  28. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  29. package/dist/fields/color/client/ColorPickerPanel.js +29 -4
  30. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  31. package/dist/fields/color/client/colorField.css +30 -0
  32. package/dist/fields/color/colorField.js +36 -8
  33. package/dist/fields/color/colorField.js.map +1 -1
  34. package/dist/fields/color/presetChip.js +10 -9
  35. package/dist/fields/color/presetChip.js.map +1 -1
  36. package/dist/fields/color/presetReference.d.ts +13 -0
  37. package/dist/fields/color/presetReference.js +94 -0
  38. package/dist/fields/color/presetReference.js.map +1 -0
  39. package/dist/fields/color/server/ColorCell.js +7 -1
  40. package/dist/fields/color/server/ColorCell.js.map +1 -1
  41. package/dist/fields/color/server/colorCell.css +5 -0
  42. package/dist/fields/color/valueIssue.js +23 -0
  43. package/dist/fields/color/valueIssue.js.map +1 -0
  44. package/dist/fields/encrypted/boot.js +2 -1
  45. package/dist/fields/encrypted/boot.js.map +1 -1
  46. package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
  47. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  48. package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
  49. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  50. package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
  51. package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
  52. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
  53. package/dist/fields/encrypted/components/ProtectedField.css +134 -39
  54. package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
  55. package/dist/fields/encrypted/components/ProtectedField.js +14 -0
  56. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  57. package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
  58. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
  59. package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
  60. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
  61. package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
  62. package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
  63. package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
  64. package/dist/fields/encrypted/crypto/wire.js +1 -1
  65. package/dist/fields/encrypted/encryptedField.js +63 -6
  66. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  67. package/dist/fields/encrypted/generateSecret.d.ts +10 -0
  68. package/dist/fields/encrypted/generateSecret.js +41 -0
  69. package/dist/fields/encrypted/generateSecret.js.map +1 -0
  70. package/dist/fields/encrypted/hint.js +67 -0
  71. package/dist/fields/encrypted/hint.js.map +1 -0
  72. package/dist/fields/encrypted/hooks.js +59 -31
  73. package/dist/fields/encrypted/hooks.js.map +1 -1
  74. package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
  75. package/dist/fields/encrypted/queryRewrite.js +34 -8
  76. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  77. package/dist/fields/encrypted/rawRead.d.ts +24 -0
  78. package/dist/fields/encrypted/rawRead.js +40 -0
  79. package/dist/fields/encrypted/rawRead.js.map +1 -0
  80. package/dist/fields/encrypted/scan.js +21 -4
  81. package/dist/fields/encrypted/scan.js.map +1 -1
  82. package/dist/fields/encrypted/types.d.ts +67 -2
  83. package/dist/fields/encrypted/types.js +8 -1
  84. package/dist/fields/encrypted/types.js.map +1 -1
  85. package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
  86. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
  87. package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
  88. package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
  89. package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
  90. package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
  91. package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
  92. package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
  93. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  94. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  95. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  96. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
  97. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  98. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  99. package/dist/fields/icon/client/icon-field.css +4 -2
  100. package/dist/fields/icon/codegen/emit.js +2 -2
  101. package/dist/fields/icon/codegen/emit.js.map +1 -1
  102. package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
  103. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  104. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  105. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  106. package/dist/fields/icon/shared/iconLabel.js +1 -1
  107. package/dist/fields/icon/shared/iconLabel.js.map +1 -1
  108. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  109. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  110. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  111. package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
  112. package/dist/fields/measurement/client/MeasurementField.js +70 -0
  113. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  114. package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
  115. package/dist/fields/measurement/client/MeasurementInput.js +327 -0
  116. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
  117. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  118. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  119. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  120. package/dist/fields/measurement/client/editModel.js +124 -0
  121. package/dist/fields/measurement/client/editModel.js.map +1 -0
  122. package/dist/fields/measurement/client/measurementCell.css +4 -0
  123. package/dist/fields/measurement/client/measurementField.css +215 -0
  124. package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
  125. package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
  126. package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
  127. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  128. package/dist/fields/measurement/engine/convert.js +21 -0
  129. package/dist/fields/measurement/engine/convert.js.map +1 -0
  130. package/dist/fields/measurement/engine/format.d.ts +37 -0
  131. package/dist/fields/measurement/engine/format.js +156 -0
  132. package/dist/fields/measurement/engine/format.js.map +1 -0
  133. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  134. package/dist/fields/measurement/engine/locale.js +79 -0
  135. package/dist/fields/measurement/engine/locale.js.map +1 -0
  136. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  137. package/dist/fields/measurement/engine/precision.js +63 -0
  138. package/dist/fields/measurement/engine/precision.js.map +1 -0
  139. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  140. package/dist/fields/measurement/engine/registry.js +117 -0
  141. package/dist/fields/measurement/engine/registry.js.map +1 -0
  142. package/dist/fields/measurement/engine/units.d.ts +178 -0
  143. package/dist/fields/measurement/engine/units.js +198 -0
  144. package/dist/fields/measurement/engine/units.js.map +1 -0
  145. package/dist/fields/measurement/measurementField.d.ts +17 -0
  146. package/dist/fields/measurement/measurementField.js +139 -0
  147. package/dist/fields/measurement/measurementField.js.map +1 -0
  148. package/dist/fields/measurement/options.d.ts +76 -0
  149. package/dist/fields/measurement/options.js +9 -0
  150. package/dist/fields/measurement/options.js.map +1 -0
  151. package/dist/fields/measurement/presets.d.ts +117 -0
  152. package/dist/fields/measurement/presets.js +136 -0
  153. package/dist/fields/measurement/presets.js.map +1 -0
  154. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  155. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  156. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  157. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  158. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  159. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  160. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  161. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  162. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  163. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  164. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  165. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  166. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  167. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  168. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  169. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  170. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  171. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  172. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  173. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  174. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  175. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  176. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  177. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  178. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  179. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  180. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  181. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  182. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  183. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  184. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  185. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  186. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  187. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  188. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  189. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  190. package/dist/fields/phoneNumber/options.d.ts +72 -0
  191. package/dist/fields/phoneNumber/options.js +37 -0
  192. package/dist/fields/phoneNumber/options.js.map +1 -0
  193. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  194. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  195. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  196. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  197. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  198. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  199. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  200. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  201. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  202. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  203. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  204. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  205. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  206. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  207. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  208. package/dist/index.d.ts +5 -3
  209. package/dist/index.js +35 -1
  210. package/dist/index.js.map +1 -1
  211. package/dist/translations/ar.js +62 -0
  212. package/dist/translations/ar.js.map +1 -0
  213. package/dist/translations/de.js +19 -1
  214. package/dist/translations/de.js.map +1 -1
  215. package/dist/translations/en.js +19 -1
  216. package/dist/translations/en.js.map +1 -1
  217. package/dist/translations/es.js +62 -0
  218. package/dist/translations/es.js.map +1 -0
  219. package/dist/translations/fr.js +62 -0
  220. package/dist/translations/fr.js.map +1 -0
  221. package/dist/translations/id.js +62 -0
  222. package/dist/translations/id.js.map +1 -0
  223. package/dist/translations/index.d.ts +10 -1
  224. package/dist/translations/index.js +19 -1
  225. package/dist/translations/index.js.map +1 -1
  226. package/dist/translations/keys.d.ts +19 -1
  227. package/dist/translations/keys.js +20 -2
  228. package/dist/translations/keys.js.map +1 -1
  229. package/dist/translations/ko.js +62 -0
  230. package/dist/translations/ko.js.map +1 -0
  231. package/dist/translations/pt.js +62 -0
  232. package/dist/translations/pt.js.map +1 -0
  233. package/dist/translations/ru.js +62 -0
  234. package/dist/translations/ru.js.map +1 -0
  235. package/dist/translations/uk.js +62 -0
  236. package/dist/translations/uk.js.map +1 -0
  237. package/dist/translations/zh.js +62 -0
  238. package/dist/translations/zh.js.map +1 -0
  239. package/dist/types.d.ts +41 -1
  240. package/dist/utils/resolveStaticLabel.js +13 -0
  241. package/dist/utils/resolveStaticLabel.js.map +1 -0
  242. package/package.json +28 -6
  243. package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
  244. package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
@@ -0,0 +1,286 @@
1
+ "use client";
2
+ import { formatHint } from "../hint.js";
3
+ import { keys } from "../../../translations/keys.js";
4
+ import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
5
+ import { dotString } from "./MaskDots.js";
6
+ import { generateSecret } from "../generateSecret.js";
7
+ import { ActionButton } from "./WriteOnlyActions.js";
8
+ import { applyBlur, applyClear, applyInput, applySave, applyUndo } from "./writeOnlyIntent.js";
9
+ import { FieldDescription, FieldError, FieldLabel, useDocumentEvents, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
10
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
11
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
12
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
+ //#region src/fields/encrypted/components/WriteOnlyField.tsx
14
+ /**
15
+ * Editor for `protection: 'writeOnly'`. The plaintext never reaches the client
16
+ * (reads strip the field), so there is nothing to reveal and nothing to bind:
17
+ * the control is one always-editable input. A stored value shows as a
18
+ * placeholder (the identification hint when configured, dots otherwise), typing
19
+ * stages a replacement that stays visible until save (the reveal-once window
20
+ * for generated secrets), and emptying the input reverts to keeping the stored
21
+ * value. Clear is the isClearable × inside the input; an undo arrow follows a
22
+ * clear because the cleared secret cannot be retyped from memory. Every action
23
+ * lives inside the input row (or the label row for structural types), so the
24
+ * field never grows past its native height.
25
+ */
26
+ const WriteOnlyField = (props) => {
27
+ if (props.placement === "label-row") return /* @__PURE__ */ jsx(StructuralWriteOnly, { ...props });
28
+ return /* @__PURE__ */ jsx(InlineWriteOnly, { ...props });
29
+ };
30
+ const InlineWriteOnly = ({ clearable, componentKey, field, generate, hintPath, maskDots, path, placement, setPath }) => {
31
+ const { t } = useTranslation$1();
32
+ const { setValue, value } = useField({ path });
33
+ const isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true);
34
+ const hint = useFormFields(([fields]) => {
35
+ const stored = fields?.[hintPath]?.value;
36
+ return typeof stored === "string" && stored.length > 0 ? stored : void 0;
37
+ });
38
+ const submitted = useFormSubmitted();
39
+ const invalid = useFormFields(([fields]) => fields?.[path]?.valid === false);
40
+ const showFieldError = submitted && invalid;
41
+ const [cleared, setCleared] = useState(false);
42
+ const inputRef = useRef(null);
43
+ const { mostRecentUpdate } = useDocumentEvents();
44
+ const lastUpdateAt = useRef(mostRecentUpdate?.updatedAt);
45
+ useEffect(() => {
46
+ if (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) return;
47
+ lastUpdateAt.current = mostRecentUpdate.updatedAt;
48
+ const resolved = applySave();
49
+ setValue(resolved.value, true);
50
+ setCleared(resolved.cleared);
51
+ }, [mostRecentUpdate?.updatedAt, setValue]);
52
+ const isNumber = componentKey === "number";
53
+ const typed = isNumber ? typeof value === "number" : typeof value === "string" && value !== "";
54
+ const commit = useCallback((outcome) => {
55
+ setValue(outcome.value);
56
+ setCleared(outcome.cleared);
57
+ }, [setValue]);
58
+ const handleChange = useCallback((event) => {
59
+ commit(applyInput(event.target.value, {
60
+ cleared,
61
+ isNumber
62
+ }));
63
+ }, [
64
+ cleared,
65
+ commit,
66
+ isNumber
67
+ ]);
68
+ const handleBlur = useCallback(() => {
69
+ const outcome = applyBlur(value, {
70
+ cleared,
71
+ isNumber
72
+ });
73
+ if (outcome) commit(outcome);
74
+ }, [
75
+ cleared,
76
+ commit,
77
+ isNumber,
78
+ value
79
+ ]);
80
+ const handleClear = useCallback(() => {
81
+ const outcome = applyClear({
82
+ cleared,
83
+ clearable,
84
+ isSet,
85
+ typed
86
+ });
87
+ if (outcome) commit(outcome);
88
+ }, [
89
+ cleared,
90
+ clearable,
91
+ commit,
92
+ isSet,
93
+ typed
94
+ ]);
95
+ const handleUndo = useCallback(() => {
96
+ commit(applyUndo());
97
+ }, [commit]);
98
+ const runGenerate = useCallback(async () => {
99
+ if (!generate) return;
100
+ commit({
101
+ cleared: false,
102
+ value: await generateSecret(generate)
103
+ });
104
+ requestAnimationFrame(() => {
105
+ inputRef.current?.focus();
106
+ inputRef.current?.select?.();
107
+ });
108
+ }, [commit, generate]);
109
+ const placeholder = typed ? void 0 : cleared ? t(keys.clearedOnSave) : !isSet ? typeof field.admin?.placeholder === "string" ? field.admin.placeholder : void 0 : hint ? formatHint(hint, maskDots) : dotString(maskDots);
110
+ const showClear = typed || clearable && isSet && !cleared;
111
+ const inputId = `field-${path.replace(/\./g, "__")}`;
112
+ const displayValue = typed ? String(value) : "";
113
+ const actions = /* @__PURE__ */ jsxs(Fragment$1, { children: [generate ? /* @__PURE__ */ jsx(ActionButton, {
114
+ attached: placement === "attached",
115
+ kind: "generate",
116
+ label: t(keys.generateValue),
117
+ onClick: runGenerate
118
+ }) : null, cleared && !typed ? /* @__PURE__ */ jsx(ActionButton, {
119
+ attached: placement === "attached",
120
+ kind: "undo",
121
+ label: t(keys.undoClear),
122
+ onClick: handleUndo
123
+ }) : showClear ? /* @__PURE__ */ jsx(ActionButton, {
124
+ attached: placement === "attached",
125
+ kind: "clear",
126
+ label: t(keys.clearValue),
127
+ onClick: handleClear
128
+ }) : null] });
129
+ const styles = useMemo(() => mergeFieldStyles(field), [field]);
130
+ const isTextarea = componentKey === "textarea";
131
+ const inputProps = {
132
+ autoComplete: "off",
133
+ className: ["tenx-protected-field__wo-input", !typed && isSet && !cleared && "tenx-protected-field__wo-input--set"].filter(Boolean).join(" "),
134
+ id: inputId,
135
+ name: path,
136
+ onBlur: handleBlur,
137
+ onChange: handleChange,
138
+ placeholder,
139
+ value: displayValue
140
+ };
141
+ return /* @__PURE__ */ jsxs("div", {
142
+ className: [
143
+ "field-type",
144
+ componentKey,
145
+ showFieldError && "error",
146
+ "tenx-protected-field",
147
+ placement === "attached" ? "tenx-protected-field--attached" : "tenx-protected-field--corner"
148
+ ].filter(Boolean).join(" "),
149
+ style: styles,
150
+ children: [/* @__PURE__ */ jsx(FieldLabel, {
151
+ label: field.label,
152
+ localized: field.localized,
153
+ path,
154
+ required: field.required
155
+ }), /* @__PURE__ */ jsxs("div", {
156
+ className: "field-type__wrap",
157
+ children: [
158
+ /* @__PURE__ */ jsx(FieldError, { path }),
159
+ isTextarea ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("textarea", {
160
+ ...inputProps,
161
+ ref: (el) => {
162
+ inputRef.current = el;
163
+ },
164
+ rows: field.admin?.rows ?? 4
165
+ }), /* @__PURE__ */ jsx("div", {
166
+ className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner tenx-protected-field__actions--corner",
167
+ children: actions
168
+ })] }) : /* @__PURE__ */ jsxs("div", {
169
+ className: "tenx-protected-field__attached-row",
170
+ children: [/* @__PURE__ */ jsx("input", {
171
+ ...inputProps,
172
+ ref: (el) => {
173
+ inputRef.current = el;
174
+ },
175
+ inputMode: isNumber ? "decimal" : void 0,
176
+ type: isNumber ? "number" : componentKey === "email" && typed ? "email" : "text"
177
+ }), /* @__PURE__ */ jsx("div", {
178
+ className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached",
179
+ children: actions
180
+ })]
181
+ }),
182
+ /* @__PURE__ */ jsx(FieldDescription, {
183
+ description: field.admin?.description,
184
+ path
185
+ })
186
+ ]
187
+ })]
188
+ });
189
+ };
190
+ /**
191
+ * Label-row variant for structural types (date, select, checkbox, code, json,
192
+ * point, radio, and any hasMany surface): these have no single-line input to
193
+ * type into, so replace goes through a pencil that mounts the real native
194
+ * editor, with clear and undo beside it on the label line, exactly where the
195
+ * masked eye sits.
196
+ */
197
+ const StructuralWriteOnly = ({ clearable, field, maskDots, Native, nativeProps, path, setPath }) => {
198
+ const { t } = useTranslation$1();
199
+ const { setValue, value } = useField({ path });
200
+ const isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true);
201
+ const [mode, setMode] = useState("idle");
202
+ const styles = useMemo(() => mergeFieldStyles(field), [field]);
203
+ const { mostRecentUpdate } = useDocumentEvents();
204
+ const lastUpdateAt = useRef(mostRecentUpdate?.updatedAt);
205
+ useEffect(() => {
206
+ if (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) return;
207
+ lastUpdateAt.current = mostRecentUpdate.updatedAt;
208
+ setValue(void 0, true);
209
+ setMode("idle");
210
+ }, [mostRecentUpdate?.updatedAt, setValue]);
211
+ const toggleEdit = useCallback(() => {
212
+ if (mode === "editing") {
213
+ if (value !== void 0) setValue(void 0);
214
+ setMode("idle");
215
+ return;
216
+ }
217
+ setMode("editing");
218
+ }, [
219
+ mode,
220
+ setValue,
221
+ value
222
+ ]);
223
+ const clear = useCallback(() => {
224
+ setValue(null);
225
+ setMode("cleared");
226
+ }, [setValue]);
227
+ const undoClear = useCallback(() => {
228
+ setValue(void 0);
229
+ setMode("idle");
230
+ }, [setValue]);
231
+ if (!isSet) return /* @__PURE__ */ jsx(Native, { ...nativeProps });
232
+ return /* @__PURE__ */ jsxs("div", {
233
+ className: "tenx-protected-field tenx-protected-field--label-row",
234
+ children: [mode === "editing" ? /* @__PURE__ */ jsx(Native, { ...nativeProps }) : /* @__PURE__ */ jsxs("div", {
235
+ className: "field-type tenx-protected-field__wo-face",
236
+ style: styles,
237
+ children: [/* @__PURE__ */ jsx(FieldLabel, {
238
+ label: field.label,
239
+ localized: field.localized,
240
+ path,
241
+ required: field.required
242
+ }), /* @__PURE__ */ jsxs("div", {
243
+ className: "field-type__wrap",
244
+ children: [
245
+ /* @__PURE__ */ jsx(FieldError, { path }),
246
+ /* @__PURE__ */ jsx("div", {
247
+ className: "tenx-protected-field__wo-face-box",
248
+ children: mode === "cleared" ? /* @__PURE__ */ jsx("span", {
249
+ className: "tenx-protected-field__wo-face-msg",
250
+ children: t(keys.clearedOnSave)
251
+ }) : /* @__PURE__ */ jsx("span", {
252
+ "aria-label": t(keys.writeOnlyValue),
253
+ className: "tenx-protected-field__dots",
254
+ role: "img",
255
+ children: dotString(maskDots)
256
+ })
257
+ }),
258
+ /* @__PURE__ */ jsx(FieldDescription, {
259
+ description: field.admin?.description,
260
+ path
261
+ })
262
+ ]
263
+ })]
264
+ }), /* @__PURE__ */ jsx("div", {
265
+ className: "tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--label-row",
266
+ children: mode === "cleared" ? /* @__PURE__ */ jsx(ActionButton, {
267
+ kind: "undo",
268
+ label: t(keys.undoClear),
269
+ onClick: undoClear
270
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ActionButton, {
271
+ kind: "edit",
272
+ label: t(keys.replaceValue),
273
+ onClick: toggleEdit,
274
+ pressed: mode === "editing"
275
+ }), clearable && mode !== "editing" ? /* @__PURE__ */ jsx(ActionButton, {
276
+ kind: "clear",
277
+ label: t(keys.clearValue),
278
+ onClick: clear
279
+ }) : null] })
280
+ })]
281
+ });
282
+ };
283
+ //#endregion
284
+ export { WriteOnlyField };
285
+
286
+ //# sourceMappingURL=WriteOnlyField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteOnlyField.js","names":["useTranslation"],"sources":["../../../../src/fields/encrypted/components/WriteOnlyField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseDocumentEvents,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { generateSecret, type NormalizedGenerate } from '../generateSecret'\nimport { formatHint } from '../hint'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig, Placement } from './placement'\nimport { ActionButton } from './WriteOnlyActions'\nimport { applyBlur, applyClear, applyInput, applySave, applyUndo } from './writeOnlyIntent'\n\ntype NativeComponent = React.ComponentType<Record<string, unknown>>\n\nexport interface WriteOnlyFieldProps {\n\tclearable: boolean\n\tcomponentKey: string\n\tfield: EncryptedFieldConfig\n\tgenerate?: NormalizedGenerate\n\thintPath: string\n\tmaskDots: number\n\tNative: NativeComponent\n\tnativeProps: Record<string, unknown>\n\tpath: string\n\tplacement: Placement\n\tsetPath: string\n}\n\n/**\n * Editor for `protection: 'writeOnly'`. The plaintext never reaches the client\n * (reads strip the field), so there is nothing to reveal and nothing to bind:\n * the control is one always-editable input. A stored value shows as a\n * placeholder (the identification hint when configured, dots otherwise), typing\n * stages a replacement that stays visible until save (the reveal-once window\n * for generated secrets), and emptying the input reverts to keeping the stored\n * value. Clear is the isClearable × inside the input; an undo arrow follows a\n * clear because the cleared secret cannot be retyped from memory. Every action\n * lives inside the input row (or the label row for structural types), so the\n * field never grows past its native height.\n */\nexport const WriteOnlyField: React.FC<WriteOnlyFieldProps> = (props) => {\n\tif (props.placement === 'label-row') {\n\t\treturn <StructuralWriteOnly {...props} />\n\t}\n\treturn <InlineWriteOnly {...props} />\n}\n\nconst InlineWriteOnly: React.FC<WriteOnlyFieldProps> = ({\n\tclearable,\n\tcomponentKey,\n\tfield,\n\tgenerate,\n\thintPath,\n\tmaskDots,\n\tpath,\n\tplacement,\n\tsetPath,\n}) => {\n\tconst { t } = useTranslation()\n\tconst { setValue, value } = useField<unknown>({ path })\n\tconst isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true)\n\tconst hint = useFormFields(([fields]) => {\n\t\tconst stored = fields?.[hintPath]?.value\n\t\treturn typeof stored === 'string' && stored.length > 0 ? stored : undefined\n\t})\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showFieldError = submitted && invalid\n\tconst [cleared, setCleared] = useState(false)\n\tconst inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null)\n\n\t// A successful save ends the reveal-once window: the staged plaintext (typed\n\t// or generated) is dropped and the field returns to its concealed face\n\t// immediately, not on the next page load. The edit view fires reportUpdate\n\t// only on success, so a failed save keeps the user's input. This write is\n\t// housekeeping, not an edit: disableModifyingForm keeps it from re-dirtying\n\t// the form Payload just marked clean, which would resurrect the\n\t// leave-without-saving warning on every navigation after a save.\n\tconst { mostRecentUpdate } = useDocumentEvents()\n\tconst lastUpdateAt = useRef(mostRecentUpdate?.updatedAt)\n\tuseEffect(() => {\n\t\tif (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) {\n\t\t\treturn\n\t\t}\n\t\tlastUpdateAt.current = mostRecentUpdate.updatedAt\n\t\tconst resolved = applySave()\n\t\tsetValue(resolved.value, true)\n\t\tsetCleared(resolved.cleared)\n\t}, [mostRecentUpdate?.updatedAt, setValue])\n\n\tconst isNumber = componentKey === 'number'\n\tconst typed = isNumber ? typeof value === 'number' : typeof value === 'string' && value !== ''\n\n\tconst commit = useCallback(\n\t\t(outcome: { cleared: boolean; value: unknown }) => {\n\t\t\tsetValue(outcome.value)\n\t\t\tsetCleared(outcome.cleared)\n\t\t},\n\t\t[setValue]\n\t)\n\n\tconst handleChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n\t\t\tcommit(applyInput(event.target.value, { cleared, isNumber }))\n\t\t},\n\t\t[cleared, commit, isNumber]\n\t)\n\n\tconst handleBlur = useCallback(() => {\n\t\tconst outcome = applyBlur(value, { cleared, isNumber })\n\t\tif (outcome) {\n\t\t\tcommit(outcome)\n\t\t}\n\t}, [cleared, commit, isNumber, value])\n\n\tconst handleClear = useCallback(() => {\n\t\tconst outcome = applyClear({ cleared, clearable, isSet, typed })\n\t\tif (outcome) {\n\t\t\tcommit(outcome)\n\t\t}\n\t}, [cleared, clearable, commit, isSet, typed])\n\n\tconst handleUndo = useCallback(() => {\n\t\tcommit(applyUndo())\n\t}, [commit])\n\n\tconst runGenerate = useCallback(async () => {\n\t\tif (!generate) return\n\t\tcommit({ cleared: false, value: await generateSecret(generate) })\n\t\t// Select the fresh secret so the reveal-once window is one Cmd+C away.\n\t\trequestAnimationFrame(() => {\n\t\t\tinputRef.current?.focus()\n\t\t\tinputRef.current?.select?.()\n\t\t})\n\t}, [commit, generate])\n\n\t// Three unmistakable staged states: concealed face (text-colored hint/dots)\n\t// means keep, visible plaintext means replace, and the muted removal notice\n\t// means clear. Erasing typed text returns to whichever of the first and\n\t// last the user was in when they started typing.\n\tconst placeholder = typed\n\t\t? undefined\n\t\t: cleared\n\t\t\t? t(keys.clearedOnSave)\n\t\t\t: !isSet\n\t\t\t\t? typeof field.admin?.placeholder === 'string'\n\t\t\t\t\t? field.admin.placeholder\n\t\t\t\t\t: undefined\n\t\t\t\t: hint\n\t\t\t\t\t? formatHint(hint, maskDots)\n\t\t\t\t\t: dotString(maskDots)\n\n\tconst showClear = typed || (clearable && isSet && !cleared)\n\tconst inputId = `field-${path.replace(/\\./g, '__')}`\n\tconst displayValue = typed ? String(value) : ''\n\n\tconst actions = (\n\t\t<>\n\t\t\t{generate ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"generate\"\n\t\t\t\t\tlabel={t(keys.generateValue)}\n\t\t\t\t\tonClick={runGenerate}\n\t\t\t\t/>\n\t\t\t) : null}\n\t\t\t{cleared && !typed ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"undo\"\n\t\t\t\t\tlabel={t(keys.undoClear)}\n\t\t\t\t\tonClick={handleUndo}\n\t\t\t\t/>\n\t\t\t) : showClear ? (\n\t\t\t\t<ActionButton\n\t\t\t\t\tattached={placement === 'attached'}\n\t\t\t\t\tkind=\"clear\"\n\t\t\t\t\tlabel={t(keys.clearValue)}\n\t\t\t\t\tonClick={handleClear}\n\t\t\t\t/>\n\t\t\t) : null}\n\t\t</>\n\t)\n\n\t// A custom Field component short-circuits the path where Payload applies\n\t// admin.width and admin.style, so the field has to carry them itself.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst isTextarea = componentKey === 'textarea'\n\tconst inputProps = {\n\t\tautoComplete: 'off',\n\t\tclassName: [\n\t\t\t'tenx-protected-field__wo-input',\n\t\t\t!typed && isSet && !cleared && 'tenx-protected-field__wo-input--set',\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(' '),\n\t\tid: inputId,\n\t\tname: path,\n\t\tonBlur: handleBlur,\n\t\tonChange: handleChange,\n\t\tplaceholder,\n\t\tvalue: displayValue,\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\tcomponentKey,\n\t\t\t\tshowFieldError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\tplacement === 'attached'\n\t\t\t\t\t? 'tenx-protected-field--attached'\n\t\t\t\t\t: 'tenx-protected-field--corner',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<FieldLabel\n\t\t\t\tlabel={field.label}\n\t\t\t\tlocalized={field.localized}\n\t\t\t\tpath={path}\n\t\t\t\trequired={field.required}\n\t\t\t/>\n\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t<FieldError path={path} />\n\t\t\t\t{isTextarea ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\t{...inputProps}\n\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\tinputRef.current = el\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\trows={field.admin?.rows ?? 4}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner tenx-protected-field__actions--corner\">\n\t\t\t\t\t\t\t{actions}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<div className=\"tenx-protected-field__attached-row\">\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t{...inputProps}\n\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\tinputRef.current = el\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\tinputMode={isNumber ? 'decimal' : undefined}\n\t\t\t\t\t\t\ttype={isNumber ? 'number' : componentKey === 'email' && typed ? 'email' : 'text'}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--attached\">\n\t\t\t\t\t\t\t{actions}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/**\n * Label-row variant for structural types (date, select, checkbox, code, json,\n * point, radio, and any hasMany surface): these have no single-line input to\n * type into, so replace goes through a pencil that mounts the real native\n * editor, with clear and undo beside it on the label line, exactly where the\n * masked eye sits.\n */\nconst StructuralWriteOnly: React.FC<WriteOnlyFieldProps> = ({\n\tclearable,\n\tfield,\n\tmaskDots,\n\tNative,\n\tnativeProps,\n\tpath,\n\tsetPath,\n}) => {\n\tconst { t } = useTranslation()\n\tconst { setValue, value } = useField<unknown>({ path })\n\tconst isSet = useFormFields(([fields]) => fields?.[setPath]?.value === true)\n\tconst [mode, setMode] = useState<'cleared' | 'editing' | 'idle'>('idle')\n\t// The concealed face stands in for the native field, so it has to carry the\n\t// same width; without it the field would change width as the mode changes.\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\t// Mirror of the inline variant's save-conceal: a successful save drops any\n\t// staged edit and folds the field back to its concealed face, without\n\t// re-dirtying the form Payload just marked clean (disableModifyingForm).\n\tconst { mostRecentUpdate } = useDocumentEvents()\n\tconst lastUpdateAt = useRef(mostRecentUpdate?.updatedAt)\n\tuseEffect(() => {\n\t\tif (!mostRecentUpdate?.updatedAt || mostRecentUpdate.updatedAt === lastUpdateAt.current) {\n\t\t\treturn\n\t\t}\n\t\tlastUpdateAt.current = mostRecentUpdate.updatedAt\n\t\tsetValue(undefined, true)\n\t\tsetMode('idle')\n\t}, [mostRecentUpdate?.updatedAt, setValue])\n\n\tconst toggleEdit = useCallback(() => {\n\t\tif (mode === 'editing') {\n\t\t\t// Discard only what was staged: cancelling an untouched editor must not\n\t\t\t// mark the form modified.\n\t\t\tif (value !== undefined) {\n\t\t\t\tsetValue(undefined)\n\t\t\t}\n\t\t\tsetMode('idle')\n\t\t\treturn\n\t\t}\n\t\tsetMode('editing')\n\t}, [mode, setValue, value])\n\n\tconst clear = useCallback(() => {\n\t\tsetValue(null)\n\t\tsetMode('cleared')\n\t}, [setValue])\n\n\tconst undoClear = useCallback(() => {\n\t\tsetValue(undefined)\n\t\tsetMode('idle')\n\t}, [setValue])\n\n\tif (!isSet) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\treturn (\n\t\t<div className=\"tenx-protected-field tenx-protected-field--label-row\">\n\t\t\t{mode === 'editing' ? (\n\t\t\t\t<Native {...nativeProps} />\n\t\t\t) : (\n\t\t\t\t<div className=\"field-type tenx-protected-field__wo-face\" style={styles}>\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\tlabel={field.label}\n\t\t\t\t\t\tlocalized={field.localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={field.required}\n\t\t\t\t\t/>\n\t\t\t\t\t<div className=\"field-type__wrap\">\n\t\t\t\t\t\t<FieldError path={path} />\n\t\t\t\t\t\t<div className=\"tenx-protected-field__wo-face-box\">\n\t\t\t\t\t\t\t{mode === 'cleared' ? (\n\t\t\t\t\t\t\t\t<span className=\"tenx-protected-field__wo-face-msg\">{t(keys.clearedOnSave)}</span>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\taria-label={t(keys.writeOnlyValue)}\n\t\t\t\t\t\t\t\t\tclassName=\"tenx-protected-field__dots\"\n\t\t\t\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{dotString(maskDots)}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<FieldDescription description={field.admin?.description} path={path} />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--label-row\">\n\t\t\t\t{mode === 'cleared' ? (\n\t\t\t\t\t<ActionButton kind=\"undo\" label={t(keys.undoClear)} onClick={undoClear} />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkind=\"edit\"\n\t\t\t\t\t\t\tlabel={t(keys.replaceValue)}\n\t\t\t\t\t\t\tonClick={toggleEdit}\n\t\t\t\t\t\t\tpressed={mode === 'editing'}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{clearable && mode !== 'editing' ? (\n\t\t\t\t\t\t\t<ActionButton kind=\"clear\" label={t(keys.clearValue)} onClick={clear} />\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAa,kBAAiD,UAAU;CACvE,IAAI,MAAM,cAAc,aACvB,OAAO,oBAAC,qBAAD,EAAqB,GAAI,MAAQ,CAAA;CAEzC,OAAO,oBAAC,iBAAD,EAAiB,GAAI,MAAQ,CAAA;AACrC;AAEA,MA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AW,MAAM;IACX;IACN,UAAU,MAAM;GAChB,CAAA,GACD,qBAAC,OAAD;IAAK,WAAU;cAAf;KACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;KACzB,oBAAC,OAAD;MAAK,WAAU;gBACb,SAAS,YACT,oBAAC,QAAD;OAAM,WAAU;iBAAqC,EAAE,KAAK,aAAa;MAAQ,CAAA,IAEjF,oBAAC,QAAD;OACC,cAAY,EAAE,KAAK,cAAc;OACjC,WAAU;OACV,MAAK;iBAEJ,UAAU,QAAQ;MACd,CAAA;KAEH,CAAA;KACL,oBAAC,kBAAD;MAAkB,aAAa,MAAM,OAAO;MAAmB;KAAO,CAAA;IAClE;KACD;MAEN,oBAAC,OAAD;GAAK,WAAU;aACb,SAAS,YACT,oBAAC,cAAD;IAAc,MAAK;IAAO,OAAO,EAAE,KAAK,SAAS;IAAG,SAAS;GAAY,CAAA,IAEzE,qBAAA,YAAA,EAAA,UAAA,CACC,oBAAC,cAAD;IACC,MAAK;IACL,OAAO,EAAE,KAAK,YAAY;IAC1B,SAAS;IACT,SAAS,SAAS;GAClB,CAAA,GACA,aAAa,SAAS,YACtB,oBAAC,cAAD;IAAc,MAAK;IAAQ,OAAO,EAAE,KAAK,UAAU;IAAG,SAAS;GAAQ,CAAA,IACpE,IACH,EAAA,CAAA;EAEC,CAAA,CACD;;AAEP"}
@@ -0,0 +1,69 @@
1
+ //#region src/fields/encrypted/components/writeOnlyIntent.ts
2
+ /** The staged form value after the input's text changes. */
3
+ const applyInput = (text, { cleared, isNumber }) => {
4
+ if (text === "") return {
5
+ cleared,
6
+ value: cleared ? null : void 0
7
+ };
8
+ if (isNumber) {
9
+ const parsed = Number.parseFloat(text);
10
+ return {
11
+ cleared,
12
+ value: Number.isNaN(parsed) ? cleared ? null : void 0 : parsed
13
+ };
14
+ }
15
+ return {
16
+ cleared,
17
+ value: text
18
+ };
19
+ };
20
+ /**
21
+ * The × action clears what is "in" the control: staged text first (returning
22
+ * to the lineage state), then the stored value (entering the undoable cleared
23
+ * state). Returns null when the action does not apply (nothing typed and
24
+ * nothing clearable to clear).
25
+ */
26
+ const applyClear = ({ cleared, clearable, isSet, typed }) => {
27
+ if (typed) return {
28
+ cleared,
29
+ value: cleared ? null : void 0
30
+ };
31
+ if (clearable && isSet && !cleared) return {
32
+ cleared: true,
33
+ value: null
34
+ };
35
+ return null;
36
+ };
37
+ /** Undo leaves the cleared state, back to keeping the stored value. */
38
+ const applyUndo = () => ({
39
+ cleared: false,
40
+ value: void 0
41
+ });
42
+ /**
43
+ * Blur trims staged text: a pasted credential's trailing newline or space
44
+ * would otherwise be sealed into a broken secret nobody can ever read back to
45
+ * debug. Whitespace-only input counts as emptied. Returns null when nothing
46
+ * changes (numbers, untyped states, already-trimmed text).
47
+ */
48
+ const applyBlur = (value, { cleared, isNumber }) => {
49
+ if (isNumber || typeof value !== "string" || value === "") return null;
50
+ const trimmed = value.trim();
51
+ if (trimmed === value) return null;
52
+ if (trimmed === "") return {
53
+ cleared,
54
+ value: cleared ? null : void 0
55
+ };
56
+ return {
57
+ cleared,
58
+ value: trimmed
59
+ };
60
+ };
61
+ /** A successful save resolves every staged intent; the server state is now truth. */
62
+ const applySave = () => ({
63
+ cleared: false,
64
+ value: void 0
65
+ });
66
+ //#endregion
67
+ export { applyBlur, applyClear, applyInput, applySave, applyUndo };
68
+
69
+ //# sourceMappingURL=writeOnlyIntent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeOnlyIntent.js","names":[],"sources":["../../../../src/fields/encrypted/components/writeOnlyIntent.ts"],"sourcesContent":["/**\n * Intent state machine for the write-only editor, kept pure so every\n * transition is unit-testable. A write-only form value means:\n *\n * undefined keep the stored value (concealed face shows dots/hint)\n * null clear the stored value on save (\"will be removed\" face)\n * string replace the stored value with this plaintext (visible)\n *\n * `cleared` is the lineage flag: it survives typing, so erasing a half-typed\n * replacement returns the field to the state the user was in when they\n * started typing (keep, or their explicitly chosen clear), never silently\n * cancelling a clear.\n */\n\nexport interface WriteOnlyOutcome {\n\tcleared: boolean\n\tvalue: null | number | string | undefined\n}\n\nexport interface InputContext {\n\tcleared: boolean\n\tisNumber: boolean\n}\n\n/** The staged form value after the input's text changes. */\nexport const applyInput = (text: string, { cleared, isNumber }: InputContext): WriteOnlyOutcome => {\n\tif (text === '') {\n\t\t// Emptied input returns to the lineage state: a prior explicit clear\n\t\t// stays a clear; otherwise the stored value stays kept.\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\tif (isNumber) {\n\t\tconst parsed = Number.parseFloat(text)\n\t\treturn { cleared, value: Number.isNaN(parsed) ? (cleared ? null : undefined) : parsed }\n\t}\n\treturn { cleared, value: text }\n}\n\nexport interface ClearContext {\n\tcleared: boolean\n\tclearable: boolean\n\tisSet: boolean\n\ttyped: boolean\n}\n\n/**\n * The × action clears what is \"in\" the control: staged text first (returning\n * to the lineage state), then the stored value (entering the undoable cleared\n * state). Returns null when the action does not apply (nothing typed and\n * nothing clearable to clear).\n */\nexport const applyClear = ({\n\tcleared,\n\tclearable,\n\tisSet,\n\ttyped,\n}: ClearContext): null | WriteOnlyOutcome => {\n\tif (typed) {\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\tif (clearable && isSet && !cleared) {\n\t\treturn { cleared: true, value: null }\n\t}\n\treturn null\n}\n\n/** Undo leaves the cleared state, back to keeping the stored value. */\nexport const applyUndo = (): WriteOnlyOutcome => ({ cleared: false, value: undefined })\n\n/**\n * Blur trims staged text: a pasted credential's trailing newline or space\n * would otherwise be sealed into a broken secret nobody can ever read back to\n * debug. Whitespace-only input counts as emptied. Returns null when nothing\n * changes (numbers, untyped states, already-trimmed text).\n */\nexport const applyBlur = (\n\tvalue: unknown,\n\t{ cleared, isNumber }: InputContext\n): null | WriteOnlyOutcome => {\n\tif (isNumber || typeof value !== 'string' || value === '') {\n\t\treturn null\n\t}\n\tconst trimmed = value.trim()\n\tif (trimmed === value) {\n\t\treturn null\n\t}\n\tif (trimmed === '') {\n\t\treturn { cleared, value: cleared ? null : undefined }\n\t}\n\treturn { cleared, value: trimmed }\n}\n\n/** A successful save resolves every staged intent; the server state is now truth. */\nexport const applySave = (): WriteOnlyOutcome => ({ cleared: false, value: undefined })\n"],"mappings":";;AAyBA,MAAa,cAAc,MAAc,EAAE,SAAS,eAA+C;CAClG,IAAI,SAAS,IAGZ,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,IAAI,UAAU;EACb,MAAM,SAAS,OAAO,WAAW,IAAI;EACrC,OAAO;GAAE;GAAS,OAAO,OAAO,MAAM,MAAM,IAAK,UAAU,OAAO,KAAA,IAAa;EAAO;CACvF;CACA,OAAO;EAAE;EAAS,OAAO;CAAK;AAC/B;;;;;;;AAeA,MAAa,cAAc,EAC1B,SACA,WACA,OACA,YAC4C;CAC5C,IAAI,OACH,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,IAAI,aAAa,SAAS,CAAC,SAC1B,OAAO;EAAE,SAAS;EAAM,OAAO;CAAK;CAErC,OAAO;AACR;;AAGA,MAAa,mBAAqC;CAAE,SAAS;CAAO,OAAO,KAAA;AAAU;;;;;;;AAQrF,MAAa,aACZ,OACA,EAAE,SAAS,eACkB;CAC7B,IAAI,YAAY,OAAO,UAAU,YAAY,UAAU,IACtD,OAAO;CAER,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,YAAY,OACf,OAAO;CAER,IAAI,YAAY,IACf,OAAO;EAAE;EAAS,OAAO,UAAU,OAAO,KAAA;CAAU;CAErD,OAAO;EAAE;EAAS,OAAO;CAAQ;AAClC;;AAGA,MAAa,mBAAqC;CAAE,SAAS;CAAO,OAAO,KAAA;AAAU"}
@@ -10,6 +10,15 @@ declare class AuthenticationFailedError extends Error {
10
10
  readonly keyId: string;
11
11
  constructor(keyId: string);
12
12
  }
13
+ /**
14
+ * The ciphertext authenticated (correct key + AAD + tag) but the decrypted
15
+ * bytes are not valid JSON. Distinct from AuthenticationFailedError: auth
16
+ * succeeded, so this is non-retryable corruption, not a wrong key or AAD.
17
+ */
18
+ declare class CorruptPlaintextError extends Error {
19
+ readonly keyId: string;
20
+ constructor(keyId: string, cause: unknown);
21
+ }
13
22
  /**
14
23
  * True only for a structurally valid wire string: prefix, 5 segments, base64url
15
24
  * charset, and correct IV/tag byte lengths (a full parseWire, minus the GCM
@@ -19,5 +28,5 @@ declare class AuthenticationFailedError extends Error {
19
28
  */
20
29
  declare const isSealed: (value: unknown) => value is string;
21
30
  //#endregion
22
- export { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed };
31
+ export { AuthenticationFailedError, CorruptPlaintextError, MalformedCiphertextError, UnknownKeyIdError, isSealed };
23
32
  //# sourceMappingURL=wire.d.ts.map
@@ -130,6 +130,6 @@ const unseal = (value, dataKeys, aadCandidates) => {
130
130
  throw new AuthenticationFailedError(keyId);
131
131
  };
132
132
  //#endregion
133
- export { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed, parseWire, seal, unseal };
133
+ export { AuthenticationFailedError, CorruptPlaintextError, MalformedCiphertextError, UnknownKeyIdError, isSealed, parseWire, seal, unseal };
134
134
 
135
135
  //# sourceMappingURL=wire.js.map
@@ -1,7 +1,9 @@
1
1
  import { validateKeysConfig } from "./crypto/keys.js";
2
2
  import { FIELDS_CUSTOM_KEY } from "./types.js";
3
- import { makeAfterReadHook, makeBeforeChangeHook, makeRichTextCiphertextHook, makeRichTextDecryptHook, makeRichTextSealHook, makeRichTextValidate } from "./hooks.js";
3
+ import { normalizeHint } from "./hint.js";
4
+ import { makeAfterReadHook, makeBeforeChangeHook, makeRichTextCiphertextHook, makeRichTextDecryptHook, makeRichTextSealHook, makeRichTextValidate, makeSetIndicatorHook } from "./hooks.js";
4
5
  import { clampMaskDots } from "./maskDots.js";
6
+ import { normalizeGenerate } from "./generateSecret.js";
5
7
  import { typescriptSchemaFor } from "./typescriptSchema.js";
6
8
  import { makeComposedValidate, makeEffectiveValidator } from "./validators.js";
7
9
  //#region src/fields/encrypted/encryptedField.ts
@@ -101,15 +103,29 @@ const buildRichTextFields = (args) => {
101
103
  * `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.
102
104
  */
103
105
  const encryptedField = (source, options = {}) => {
104
- const { keys, maskDots: maskDotsOption, onDecryptFailure, overrides, protection = "masked", queryable = false } = options;
106
+ const { aadScope, clearable, generate, hint, keys, maskDots: maskDotsOption, onDecryptFailure, overrides, protection = "masked", queryable = false } = options;
105
107
  const maskDots = clampMaskDots(maskDotsOption);
108
+ const writeOnly = protection === "writeOnly";
106
109
  if (keys) validateKeysConfig(keys);
110
+ if (aadScope !== void 0 && (aadScope === "" || aadScope.includes("."))) throw new Error(`@10x-media/fields: encryptedField '${source.name}': aadScope must be a non-empty string without '.' ('.' separates AAD components, so a dotted scope would make the binding ambiguous)`);
107
111
  const hasMany = "hasMany" in source && source.hasMany === true;
108
112
  const unique = "unique" in source && source.unique === true;
113
+ const required = "required" in source && source.required === true;
114
+ if (!writeOnly && (hint || generate || clearable !== void 0)) throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint, generate, and clearable require protection 'writeOnly'`);
115
+ if (hint && hasMany) throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint is not supported with hasMany (one hint cannot identify many values)`);
116
+ if (hint && source.type !== "text" && source.type !== "email") throw new Error(`@10x-media/fields: encryptedField '${source.name}': hint is only supported for text and email fields (a hint slices leading/trailing characters)`);
117
+ if (generate && source.type !== "text") throw new Error(`@10x-media/fields: encryptedField '${source.name}': generate is only supported for text fields`);
118
+ if (clearable === true && required) throw new Error(`@10x-media/fields: encryptedField '${source.name}': clearable cannot be enabled on a required field (clearing it could never save)`);
119
+ const normalizedHint = hint ? normalizeHint(hint, source.name) : void 0;
120
+ const normalizedGenerate = generate ? normalizeGenerate(generate, source.name) : void 0;
121
+ const resolvedClearable = writeOnly ? clearable ?? !required : false;
122
+ if (writeOnly && queryable) throw new Error(`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' cannot be combined with queryable (the blind index is an equality oracle: anyone with list access could probe guesses of the secret)`);
123
+ if (writeOnly && source.type === "richText") throw new Error(`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' is not supported for richText (editing rich text requires the client to see it; use 'masked' instead)`);
109
124
  if (queryable && hasMany) throw new Error(`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`);
110
125
  if (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) throw new Error(`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`);
111
126
  if (unique && !queryable) throw new Error(`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`);
112
127
  const marker = {
128
+ aadScope,
113
129
  bidxName: queryable ? `${source.name}_bidx` : void 0,
114
130
  fieldName: source.name,
115
131
  hasMany,
@@ -118,7 +134,11 @@ const encryptedField = (source, options = {}) => {
118
134
  normalize: source.type === "email" ? "email" : "standard",
119
135
  onDecryptFailure,
120
136
  queryable,
121
- sourceType: source.type
137
+ setName: writeOnly ? `${source.name}_set` : void 0,
138
+ hint: normalizedHint,
139
+ hintName: normalizedHint ? `${source.name}_hint` : void 0,
140
+ sourceType: source.type,
141
+ writeOnly
122
142
  };
123
143
  if (source.type === "richText") return buildRichTextFields({
124
144
  marker,
@@ -143,12 +163,20 @@ const encryptedField = (source, options = {}) => {
143
163
  componentKey: source.type,
144
164
  fieldPatch,
145
165
  maskDots,
146
- protection
166
+ protection,
167
+ ...writeOnly ? {
168
+ clearable: resolvedClearable,
169
+ ...normalizedGenerate ? { generate: normalizedGenerate } : {}
170
+ } : {}
147
171
  },
148
172
  path: "@10x-media/fields/client#ProtectedField"
149
173
  },
150
- ...protection === "masked" ? { Cell: {
151
- clientProps: { maskDots },
174
+ ...protection !== "none" ? { Cell: {
175
+ clientProps: {
176
+ maskDots,
177
+ ...writeOnly ? { setName: marker.setName } : {},
178
+ ...marker.hintName ? { hintName: marker.hintName } : {}
179
+ },
152
180
  path: "@10x-media/fields/rsc#ProtectedCell"
153
181
  } } : {}
154
182
  }
@@ -166,6 +194,35 @@ const encryptedField = (source, options = {}) => {
166
194
  validate: makeComposedValidate(effective)
167
195
  };
168
196
  if (overrides) stored = overrides({ field: stored });
197
+ if (writeOnly) {
198
+ const setField = {
199
+ name: marker.setName,
200
+ type: "checkbox",
201
+ admin: {
202
+ disableListColumn: true,
203
+ disableListFilter: true,
204
+ hidden: true
205
+ },
206
+ hooks: { afterRead: [makeSetIndicatorHook(marker.fieldName)] },
207
+ virtual: true
208
+ };
209
+ if (!marker.hintName) return [stored, setField];
210
+ const hintField = {
211
+ name: marker.hintName,
212
+ type: "text",
213
+ admin: {
214
+ disableListColumn: true,
215
+ disableListFilter: true,
216
+ hidden: true
217
+ },
218
+ ...marker.localized ? { localized: true } : {}
219
+ };
220
+ return [
221
+ stored,
222
+ setField,
223
+ hintField
224
+ ];
225
+ }
169
226
  if (!queryable) return [stored];
170
227
  const bidx = {
171
228
  name: marker.bidxName,
@@ -1 +1 @@
1
- {"version":3,"file":"encryptedField.js","names":[],"sources":["../../../src/fields/encrypted/encryptedField.ts"],"sourcesContent":["import type { Field, RichTextField, TextField } from 'payload'\nimport { validateKeysConfig } from './crypto/keys'\nimport {\n\tmakeAfterReadHook,\n\tmakeBeforeChangeHook,\n\tmakeRichTextCiphertextHook,\n\tmakeRichTextDecryptHook,\n\tmakeRichTextSealHook,\n\tmakeRichTextValidate,\n} from './hooks'\nimport { clampMaskDots } from './maskDots'\nimport {\n\ttype EncryptedFieldMarker,\n\ttype EncryptedFieldOptions,\n\ttype EncryptedFieldPatch,\n\ttype EncryptedProtection,\n\ttype EncryptedSourceField,\n\ttype EncryptedSourceType,\n\tFIELDS_CUSTOM_KEY,\n} from './types'\nimport { typescriptSchemaFor } from './typescriptSchema'\nimport { makeComposedValidate, makeEffectiveValidator } from './validators'\n\n/** Admin keys forwarded to the client patch so native components render correctly. */\nconst PATCH_ADMIN_KEYS = [\n\t'autoComplete',\n\t'date',\n\t'editorOptions',\n\t'language',\n\t'placeholder',\n\t'rows',\n\t'step',\n] as const\n\n/**\n * Field types whose plaintext is a single scalar the blind index can key on.\n * Blind indexes HMAC a normalized string/number; non-scalar values (objects,\n * tuples, arrays, booleans) have no meaningful equality index, so queryable is\n * rejected for them at the factory (complements the crypto-layer bidx guard).\n */\nconst QUERYABLE_SOURCE_TYPES: ReadonlySet<EncryptedSourceType> = new Set([\n\t'email',\n\t'number',\n\t'text',\n])\n\nconst buildFieldPatch = (source: EncryptedSourceField): EncryptedFieldPatch => {\n\tconst patch: EncryptedFieldPatch = { admin: {}, type: source.type }\n\tif ('hasMany' in source && source.hasMany === true) {\n\t\tpatch.hasMany = true\n\t}\n\tif ('options' in source) {\n\t\tpatch.options = source.options.map((option) => {\n\t\t\tif (typeof option === 'string') {\n\t\t\t\treturn { label: option, value: option }\n\t\t\t}\n\t\t\tif (typeof option.label !== 'string') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@10x-media/fields: encryptedField '${source.name}': option labels must be plain strings (labels travel to the admin client via clientProps)`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn { label: option.label, value: option.value }\n\t\t})\n\t}\n\tconst admin = (source.admin ?? {}) as Record<string, unknown>\n\tfor (const key of PATCH_ADMIN_KEYS) {\n\t\tif (admin[key] !== undefined) {\n\t\t\t;(patch.admin as Record<string, unknown>)[key] = admin[key]\n\t\t}\n\t}\n\treturn patch\n}\n\n/**\n * Emits the two-field pair for an encrypted richText source: a real, virtual\n * (never persisted) richText field carrying the app's full editor for editing,\n * synced by hooks to a hidden ciphertext text sibling that holds the data at\n * rest. A `type:'text'` field cannot trigger Payload's richText schema/import-map\n * pipeline, so a real richText field is required for full node parity; `virtual`\n * keeps its plaintext out of both DB adapters (they skip virtual fields).\n */\nconst buildRichTextFields = (args: {\n\tmarker: EncryptedFieldMarker\n\tprotection: EncryptedProtection\n\tsource: RichTextField\n}): Field[] => {\n\tconst { marker, protection, source } = args\n\tconst storedName = `${source.name}_encrypted`\n\tconst sourceAdmin = source.admin ?? {}\n\tconst virtual: RichTextField = {\n\t\t...source,\n\t\t// editor is inherited from config.editor (or source.editor if pinned) so the\n\t\t// app's complete node set mounts; readOnly:false is required or sanitize\n\t\t// forces a virtual affectsData field readOnly.\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\tcomponents: {\n\t\t\t\t...sourceAdmin.components,\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tField: {\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedRichText',\n\t\t\t\t\t\t\t\tserverProps: { protection },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\treadOnly: false,\n\t\t},\n\t\thooks: {\n\t\t\t...source.hooks,\n\t\t\tafterRead: [makeRichTextDecryptHook(marker, storedName), ...(source.hooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [\n\t\t\t\t...(source.hooks?.beforeChange ?? []),\n\t\t\t\tmakeRichTextSealHook(marker, storedName),\n\t\t\t],\n\t\t},\n\t\ttype: 'richText',\n\t\tvalidate: makeRichTextValidate(),\n\t\tvirtual: true,\n\t}\n\tconst ciphertext: TextField = {\n\t\tname: storedName,\n\t\ttype: 'text',\n\t\t// admin.hidden (not top-level hidden) keeps the value readable by the virtual\n\t\t// field's decrypt hook; top-level hidden strips it early in afterRead and\n\t\t// races the decrypt read.\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tcustom: { [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: { beforeChange: [makeRichTextCiphertextHook(marker)] },\n\t\t...(marker.localized ? { localized: true } : {}),\n\t}\n\treturn [virtual, ciphertext]\n}\n\n/**\n * Wraps a Payload field config (text, textarea, email, number, checkbox,\n * date, select, radio, code, json, point, richText) in transparent AES-256-GCM\n * encryption at rest. Returns `[storedField]`, or `[storedField, bidxField]`\n * when `queryable` adds a blind-index sibling; richText returns\n * `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.\n */\nexport const encryptedField = (\n\tsource: EncryptedSourceField,\n\toptions: EncryptedFieldOptions = {}\n): Field[] => {\n\tconst {\n\t\tkeys,\n\t\tmaskDots: maskDotsOption,\n\t\tonDecryptFailure,\n\t\toverrides,\n\t\tprotection = 'masked',\n\t\tqueryable = false,\n\t} = options\n\tconst maskDots = clampMaskDots(maskDotsOption)\n\tif (keys) {\n\t\tvalidateKeysConfig(keys)\n\t}\n\tconst hasMany = 'hasMany' in source && source.hasMany === true\n\tconst unique = 'unique' in source && source.unique === true\n\tif (queryable && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`\n\t\t)\n\t}\n\tif (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`\n\t\t)\n\t}\n\tif (unique && !queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`\n\t\t)\n\t}\n\n\tconst marker: EncryptedFieldMarker = {\n\t\tbidxName: queryable ? `${source.name}_bidx` : undefined,\n\t\tfieldName: source.name,\n\t\thasMany,\n\t\tkeys,\n\t\tlocalized: 'localized' in source && source.localized === true,\n\t\tnormalize: source.type === 'email' ? 'email' : 'standard',\n\t\tonDecryptFailure,\n\t\tqueryable,\n\t\tsourceType: source.type,\n\t}\n\n\t// richText returns a virtual editor field plus a hidden ciphertext sibling.\n\t// `overrides` targets the scalar stored text column shape, so it does not apply\n\t// to the richText editor field and is intentionally skipped here.\n\tif (source.type === 'richText') {\n\t\treturn buildRichTextFields({ marker, protection, source })\n\t}\n\n\tconst effective = makeEffectiveValidator(source)\n\tconst fieldPatch = buildFieldPatch(source)\n\t// `source` is a union of 12 field types, so `source.admin` (and its\n\t// `components`) carries the union of every field's admin shape. Narrow to the\n\t// stored text field's admin type once here so the passthrough spreads below\n\t// typecheck against the correct target instead of the incompatible union.\n\tconst sourceAdmin = source.admin as TextField['admin']\n\n\t// Spread keeps admin passthrough (description, width, condition, readOnly,\n\t// position, custom labels) and access control on the stored field. Stripped:\n\t// hooks/validate/typescriptSchema/index/unique/editor (rebuilt or moved to the\n\t// bidx sibling); defaultValue (a static default emits a PLAINTEXT column\n\t// default in drizzle, i.e. plaintext at rest on an INSERT that omits the\n\t// column); and source-type-only constraints (options/min/max/min-maxLength)\n\t// which are inert on a text column and already enforced on plaintext by the\n\t// effective validator.\n\tconst {\n\t\tdefaultValue: _defaultValue,\n\t\teditor: _editor,\n\t\thooks: sourceHooks,\n\t\tindex: _index,\n\t\tmax: _max,\n\t\tmaxLength: _maxLength,\n\t\tmin: _min,\n\t\tminLength: _minLength,\n\t\toptions: _options,\n\t\ttypescriptSchema: _ts,\n\t\tunique: _unique,\n\t\tvalidate: _validate,\n\t\t...rest\n\t} = source as EncryptedSourceField & Record<string, unknown>\n\n\tlet stored: TextField = {\n\t\t...(rest as unknown as TextField),\n\t\ttype: 'text',\n\t\t...(hasMany ? { hasMany: true } : {}),\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\t// A non-queryable encrypted field can only ever filter its ciphertext\n\t\t\t// column (matching nothing), so keep it out of the list filter UI. A\n\t\t\t// queryable field stays filterable; the where-rewrite maps it to the\n\t\t\t// blind index.\n\t\t\t...(queryable ? {} : { disableListFilter: true }),\n\t\t\tcomponents: {\n\t\t\t\t...(sourceAdmin?.components ?? {}),\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { componentKey: source.type, fieldPatch, maskDots, protection },\n\t\t\t\t\tpath: '@10x-media/fields/client#ProtectedField',\n\t\t\t\t},\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? { Cell: { clientProps: { maskDots }, path: '@10x-media/fields/rsc#ProtectedCell' } }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t},\n\t\tcustom: { ...source.custom, [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: {\n\t\t\t...sourceHooks,\n\t\t\tafterRead: [makeAfterReadHook(marker), ...(sourceHooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [...(sourceHooks?.beforeChange ?? []), makeBeforeChangeHook(marker)],\n\t\t},\n\t\ttypescriptSchema: typescriptSchemaFor(source),\n\t\tvalidate: makeComposedValidate(effective),\n\t}\n\n\tif (overrides) {\n\t\tstored = overrides({ field: stored })\n\t}\n\n\tif (!queryable) {\n\t\treturn [stored]\n\t}\n\n\t// admin.hidden (not top-level `hidden: true`) keeps the blind index in the\n\t// flattened schema so Payload's query-path validation grants it read\n\t// permission and the where-rewrite can target it; top-level hidden makes a\n\t// rewritten `equals` query fail with a 403. The keyed hash is stripped from\n\t// API responses by the plugin's collection afterRead (see withEncryptedQueryRewrite)\n\t// so the index value never leaves the server; exposing it lets a reader see\n\t// which rows share a value.\n\tconst bidx: TextField = {\n\t\tname: marker.bidxName as string,\n\t\ttype: 'text',\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tindex: true,\n\t\t...(marker.localized ? { localized: true } : {}),\n\t\t...(unique ? { unique: true } : {}),\n\t}\n\treturn [stored, bidx]\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AAQA,MAAM,yBAA2D,IAAI,IAAI;CACxE;CACA;CACA;AACD,CAAC;AAED,MAAM,mBAAmB,WAAsD;CAC9E,MAAM,QAA6B;EAAE,OAAO,CAAC;EAAG,MAAM,OAAO;CAAK;CAClE,IAAI,aAAa,UAAU,OAAO,YAAY,MAC7C,MAAM,UAAU;CAEjB,IAAI,aAAa,QAChB,MAAM,UAAU,OAAO,QAAQ,KAAK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ACX,GAAI,aAAa,cAAc,CAAC;IAChC,OAAO;KACN,aAAa;MAAE,cAAc,OAAO;MAAM;MAAY;MAAU;KAAW;KAC3E,MAAM;IACP;IACA,GAAI,eAAe,WAChB,EAAE,MAAM;KAAE,aAAa,EAAE,SAAS;KAAG,MAAM;IAAsC,EAAE,IACnF,CAAC;GACL;EACD;EACA,QAAQ;GAAE,GAAG,OAAO;IAAS,oBAAoB,EAAE,WAAW,OAAO;EAAE;EACvE,OAAO;GACN,GAAG;GACH,WAAW,CAAC,kBAAkB,MAAM,GAAG,GAAI,aAAa,aAAa,CAAC,CAAE;GACxE,cAAc,CAAC,GAAI,aAAa,gBAAgB,CAAC,GAAI,qBAAqB,MAAM,CAAC;EAClF;EACA,kBAAkB,oBAAoB,MAAM;EAC5C,UAAU,qBAAqB,SAAS;CACzC;CAEA,IAAI,WACH,SAAS,UAAU,EAAE,OAAO,OAAO,CAAC;CAGrC,IAAI,CAAC,WACJ,OAAO,CAAC,MAAM;CAUf,MAAM,OAAkB;EACvB,MAAM,OAAO;EACb,MAAM;EACN,OAAO;GAAE,mBAAmB;GAAM,mBAAmB;GAAM,QAAQ;EAAK;EACxE,OAAO;EACP,GAAI,OAAO,YAAY,EAAE,WAAW,KAAK,IAAI,CAAC;EAC9C,GAAI,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;CAClC;CACA,OAAO,CAAC,QAAQ,IAAI;AACrB"}
1
+ {"version":3,"file":"encryptedField.js","names":[],"sources":["../../../src/fields/encrypted/encryptedField.ts"],"sourcesContent":["import type { CheckboxField, Field, RichTextField, TextField } from 'payload'\nimport { validateKeysConfig } from './crypto/keys'\nimport { normalizeGenerate } from './generateSecret'\nimport { normalizeHint } from './hint'\nimport {\n\tmakeAfterReadHook,\n\tmakeBeforeChangeHook,\n\tmakeRichTextCiphertextHook,\n\tmakeRichTextDecryptHook,\n\tmakeRichTextSealHook,\n\tmakeRichTextValidate,\n\tmakeSetIndicatorHook,\n} from './hooks'\nimport { clampMaskDots } from './maskDots'\nimport {\n\ttype EncryptedFieldMarker,\n\ttype EncryptedFieldOptions,\n\ttype EncryptedFieldPatch,\n\ttype EncryptedProtection,\n\ttype EncryptedSourceField,\n\ttype EncryptedSourceType,\n\tFIELDS_CUSTOM_KEY,\n} from './types'\nimport { typescriptSchemaFor } from './typescriptSchema'\nimport { makeComposedValidate, makeEffectiveValidator } from './validators'\n\n/** Admin keys forwarded to the client patch so native components render correctly. */\nconst PATCH_ADMIN_KEYS = [\n\t'autoComplete',\n\t'date',\n\t'editorOptions',\n\t'language',\n\t'placeholder',\n\t'rows',\n\t'step',\n] as const\n\n/**\n * Field types whose plaintext is a single scalar the blind index can key on.\n * Blind indexes HMAC a normalized string/number; non-scalar values (objects,\n * tuples, arrays, booleans) have no meaningful equality index, so queryable is\n * rejected for them at the factory (complements the crypto-layer bidx guard).\n */\nconst QUERYABLE_SOURCE_TYPES: ReadonlySet<EncryptedSourceType> = new Set([\n\t'email',\n\t'number',\n\t'text',\n])\n\nconst buildFieldPatch = (source: EncryptedSourceField): EncryptedFieldPatch => {\n\tconst patch: EncryptedFieldPatch = { admin: {}, type: source.type }\n\tif ('hasMany' in source && source.hasMany === true) {\n\t\tpatch.hasMany = true\n\t}\n\tif ('options' in source) {\n\t\tpatch.options = source.options.map((option) => {\n\t\t\tif (typeof option === 'string') {\n\t\t\t\treturn { label: option, value: option }\n\t\t\t}\n\t\t\tif (typeof option.label !== 'string') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@10x-media/fields: encryptedField '${source.name}': option labels must be plain strings (labels travel to the admin client via clientProps)`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn { label: option.label, value: option.value }\n\t\t})\n\t}\n\tconst admin = (source.admin ?? {}) as Record<string, unknown>\n\tfor (const key of PATCH_ADMIN_KEYS) {\n\t\tif (admin[key] !== undefined) {\n\t\t\t;(patch.admin as Record<string, unknown>)[key] = admin[key]\n\t\t}\n\t}\n\treturn patch\n}\n\n/**\n * Emits the two-field pair for an encrypted richText source: a real, virtual\n * (never persisted) richText field carrying the app's full editor for editing,\n * synced by hooks to a hidden ciphertext text sibling that holds the data at\n * rest. A `type:'text'` field cannot trigger Payload's richText schema/import-map\n * pipeline, so a real richText field is required for full node parity; `virtual`\n * keeps its plaintext out of both DB adapters (they skip virtual fields).\n */\nconst buildRichTextFields = (args: {\n\tmarker: EncryptedFieldMarker\n\tprotection: EncryptedProtection\n\tsource: RichTextField\n}): Field[] => {\n\tconst { marker, protection, source } = args\n\tconst storedName = `${source.name}_encrypted`\n\tconst sourceAdmin = source.admin ?? {}\n\tconst virtual: RichTextField = {\n\t\t...source,\n\t\t// editor is inherited from config.editor (or source.editor if pinned) so the\n\t\t// app's complete node set mounts; readOnly:false is required or sanitize\n\t\t// forces a virtual affectsData field readOnly.\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\tcomponents: {\n\t\t\t\t...sourceAdmin.components,\n\t\t\t\t...(protection === 'masked'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tField: {\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedRichText',\n\t\t\t\t\t\t\t\tserverProps: { protection },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\treadOnly: false,\n\t\t},\n\t\thooks: {\n\t\t\t...source.hooks,\n\t\t\tafterRead: [makeRichTextDecryptHook(marker, storedName), ...(source.hooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [\n\t\t\t\t...(source.hooks?.beforeChange ?? []),\n\t\t\t\tmakeRichTextSealHook(marker, storedName),\n\t\t\t],\n\t\t},\n\t\ttype: 'richText',\n\t\tvalidate: makeRichTextValidate(),\n\t\tvirtual: true,\n\t}\n\tconst ciphertext: TextField = {\n\t\tname: storedName,\n\t\ttype: 'text',\n\t\t// admin.hidden (not top-level hidden) keeps the value readable by the virtual\n\t\t// field's decrypt hook; top-level hidden strips it early in afterRead and\n\t\t// races the decrypt read.\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tcustom: { [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: { beforeChange: [makeRichTextCiphertextHook(marker)] },\n\t\t...(marker.localized ? { localized: true } : {}),\n\t}\n\treturn [virtual, ciphertext]\n}\n\n/**\n * Wraps a Payload field config (text, textarea, email, number, checkbox,\n * date, select, radio, code, json, point, richText) in transparent AES-256-GCM\n * encryption at rest. Returns `[storedField]`, or `[storedField, bidxField]`\n * when `queryable` adds a blind-index sibling; richText returns\n * `[virtualEditorField, ciphertextField]`. Spread into `fields: [...]`.\n */\nexport const encryptedField = (\n\tsource: EncryptedSourceField,\n\toptions: EncryptedFieldOptions = {}\n): Field[] => {\n\tconst {\n\t\taadScope,\n\t\tclearable,\n\t\tgenerate,\n\t\thint,\n\t\tkeys,\n\t\tmaskDots: maskDotsOption,\n\t\tonDecryptFailure,\n\t\toverrides,\n\t\tprotection = 'masked',\n\t\tqueryable = false,\n\t} = options\n\tconst maskDots = clampMaskDots(maskDotsOption)\n\tconst writeOnly = protection === 'writeOnly'\n\tif (keys) {\n\t\tvalidateKeysConfig(keys)\n\t}\n\t// Checked here rather than at first write: buildAad rejects a dotted\n\t// component at seal time, and an empty scope would silently fall back to the\n\t// slug the option exists to escape.\n\tif (aadScope !== undefined && (aadScope === '' || aadScope.includes('.'))) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': aadScope must be a non-empty string without '.' ('.' separates AAD components, so a dotted scope would make the binding ambiguous)`\n\t\t)\n\t}\n\tconst hasMany = 'hasMany' in source && source.hasMany === true\n\tconst unique = 'unique' in source && source.unique === true\n\tconst required = 'required' in source && source.required === true\n\tif (!writeOnly && (hint || generate || clearable !== undefined)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint, generate, and clearable require protection 'writeOnly'`\n\t\t)\n\t}\n\tif (hint && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint is not supported with hasMany (one hint cannot identify many values)`\n\t\t)\n\t}\n\tif (hint && source.type !== 'text' && source.type !== 'email') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': hint is only supported for text and email fields (a hint slices leading/trailing characters)`\n\t\t)\n\t}\n\tif (generate && source.type !== 'text') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': generate is only supported for text fields`\n\t\t)\n\t}\n\tif (clearable === true && required) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': clearable cannot be enabled on a required field (clearing it could never save)`\n\t\t)\n\t}\n\tconst normalizedHint = hint ? normalizeHint(hint, source.name) : undefined\n\tconst normalizedGenerate = generate ? normalizeGenerate(generate, source.name) : undefined\n\tconst resolvedClearable = writeOnly ? (clearable ?? !required) : false\n\tif (writeOnly && queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' cannot be combined with queryable (the blind index is an equality oracle: anyone with list access could probe guesses of the secret)`\n\t\t)\n\t}\n\tif (writeOnly && source.type === 'richText') {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': protection 'writeOnly' is not supported for richText (editing rich text requires the client to see it; use 'masked' instead)`\n\t\t)\n\t}\n\tif (queryable && hasMany) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is not supported with hasMany`\n\t\t)\n\t}\n\tif (queryable && !QUERYABLE_SOURCE_TYPES.has(source.type)) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': queryable is only supported for text, email, and number fields (the blind index requires a scalar value; '${source.type}' is not scalar)`\n\t\t)\n\t}\n\tif (unique && !queryable) {\n\t\tthrow new Error(\n\t\t\t`@10x-media/fields: encryptedField '${source.name}': unique requires queryable: true (uniqueness is enforced on the blind index; every ciphertext is unique by construction)`\n\t\t)\n\t}\n\n\tconst marker: EncryptedFieldMarker = {\n\t\taadScope,\n\t\tbidxName: queryable ? `${source.name}_bidx` : undefined,\n\t\tfieldName: source.name,\n\t\thasMany,\n\t\tkeys,\n\t\tlocalized: 'localized' in source && source.localized === true,\n\t\tnormalize: source.type === 'email' ? 'email' : 'standard',\n\t\tonDecryptFailure,\n\t\tqueryable,\n\t\tsetName: writeOnly ? `${source.name}_set` : undefined,\n\t\thint: normalizedHint,\n\t\thintName: normalizedHint ? `${source.name}_hint` : undefined,\n\t\tsourceType: source.type,\n\t\twriteOnly,\n\t}\n\n\t// richText returns a virtual editor field plus a hidden ciphertext sibling.\n\t// `overrides` targets the scalar stored text column shape, so it does not apply\n\t// to the richText editor field and is intentionally skipped here.\n\tif (source.type === 'richText') {\n\t\treturn buildRichTextFields({ marker, protection, source })\n\t}\n\n\tconst effective = makeEffectiveValidator(source)\n\tconst fieldPatch = buildFieldPatch(source)\n\t// `source` is a union of 12 field types, so `source.admin` (and its\n\t// `components`) carries the union of every field's admin shape. Narrow to the\n\t// stored text field's admin type once here so the passthrough spreads below\n\t// typecheck against the correct target instead of the incompatible union.\n\tconst sourceAdmin = source.admin as TextField['admin']\n\n\t// Spread keeps admin passthrough (description, width, condition, readOnly,\n\t// position, custom labels) and access control on the stored field. Stripped:\n\t// hooks/validate/typescriptSchema/index/unique/editor (rebuilt or moved to the\n\t// bidx sibling); defaultValue (a static default emits a PLAINTEXT column\n\t// default in drizzle, i.e. plaintext at rest on an INSERT that omits the\n\t// column); and source-type-only constraints (options/min/max/min-maxLength)\n\t// which are inert on a text column and already enforced on plaintext by the\n\t// effective validator.\n\tconst {\n\t\tdefaultValue: _defaultValue,\n\t\teditor: _editor,\n\t\thooks: sourceHooks,\n\t\tindex: _index,\n\t\tmax: _max,\n\t\tmaxLength: _maxLength,\n\t\tmin: _min,\n\t\tminLength: _minLength,\n\t\toptions: _options,\n\t\ttypescriptSchema: _ts,\n\t\tunique: _unique,\n\t\tvalidate: _validate,\n\t\t...rest\n\t} = source as EncryptedSourceField & Record<string, unknown>\n\n\tlet stored: TextField = {\n\t\t...(rest as unknown as TextField),\n\t\ttype: 'text',\n\t\t...(hasMany ? { hasMany: true } : {}),\n\t\tadmin: {\n\t\t\t...sourceAdmin,\n\t\t\t// A non-queryable encrypted field can only ever filter its ciphertext\n\t\t\t// column (matching nothing), so keep it out of the list filter UI. A\n\t\t\t// queryable field stays filterable; the where-rewrite maps it to the\n\t\t\t// blind index.\n\t\t\t...(queryable ? {} : { disableListFilter: true }),\n\t\t\tcomponents: {\n\t\t\t\t...(sourceAdmin?.components ?? {}),\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: {\n\t\t\t\t\t\tcomponentKey: source.type,\n\t\t\t\t\t\tfieldPatch,\n\t\t\t\t\t\tmaskDots,\n\t\t\t\t\t\tprotection,\n\t\t\t\t\t\t...(writeOnly\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tclearable: resolvedClearable,\n\t\t\t\t\t\t\t\t\t...(normalizedGenerate ? { generate: normalizedGenerate } : {}),\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t},\n\t\t\t\t\tpath: '@10x-media/fields/client#ProtectedField',\n\t\t\t\t},\n\t\t\t\t...(protection !== 'none'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tCell: {\n\t\t\t\t\t\t\t\tclientProps: {\n\t\t\t\t\t\t\t\t\tmaskDots,\n\t\t\t\t\t\t\t\t\t...(writeOnly ? { setName: marker.setName } : {}),\n\t\t\t\t\t\t\t\t\t...(marker.hintName ? { hintName: marker.hintName } : {}),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tpath: '@10x-media/fields/rsc#ProtectedCell',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t},\n\t\tcustom: { ...source.custom, [FIELDS_CUSTOM_KEY]: { encrypted: marker } },\n\t\thooks: {\n\t\t\t...sourceHooks,\n\t\t\tafterRead: [makeAfterReadHook(marker), ...(sourceHooks?.afterRead ?? [])],\n\t\t\tbeforeChange: [...(sourceHooks?.beforeChange ?? []), makeBeforeChangeHook(marker)],\n\t\t},\n\t\ttypescriptSchema: typescriptSchemaFor(source),\n\t\tvalidate: makeComposedValidate(effective),\n\t}\n\n\tif (overrides) {\n\t\tstored = overrides({ field: stored })\n\t}\n\n\t// Write-only reads strip the stored field from every response, so the admin\n\t// (and any API consumer) learns set-ness from this virtual sibling instead: a\n\t// never-persisted checkbox computed from the sealed sibling's presence. This\n\t// is the mode's one deliberate leak, existence only. admin.hidden keeps it in\n\t// form state (Payload renders it as a hidden input) without displaying it.\n\tif (writeOnly) {\n\t\tconst setField: CheckboxField = {\n\t\t\tname: marker.setName as string,\n\t\t\ttype: 'checkbox',\n\t\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\t\thooks: { afterRead: [makeSetIndicatorHook(marker.fieldName)] },\n\t\t\tvirtual: true,\n\t\t}\n\t\tif (!marker.hintName) {\n\t\t\treturn [stored, setField]\n\t\t}\n\t\t// The hint is real stored data (derived at seal time in the same\n\t\t// beforeChange that encrypts, so the two can never drift) and is the\n\t\t// identification surface API consumers and the admin read; it is\n\t\t// deliberately NOT stripped from responses.\n\t\tconst hintField: TextField = {\n\t\t\tname: marker.hintName,\n\t\t\ttype: 'text',\n\t\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\t\t...(marker.localized ? { localized: true } : {}),\n\t\t}\n\t\treturn [stored, setField, hintField]\n\t}\n\n\tif (!queryable) {\n\t\treturn [stored]\n\t}\n\n\t// admin.hidden (not top-level `hidden: true`) keeps the blind index in the\n\t// flattened schema so Payload's query-path validation grants it read\n\t// permission and the where-rewrite can target it; top-level hidden makes a\n\t// rewritten `equals` query fail with a 403. The keyed hash is stripped from\n\t// API responses by the plugin's collection afterRead (see withEncryptedQueryRewrite)\n\t// so the index value never leaves the server; exposing it lets a reader see\n\t// which rows share a value.\n\tconst bidx: TextField = {\n\t\tname: marker.bidxName as string,\n\t\ttype: 'text',\n\t\tadmin: { disableListColumn: true, disableListFilter: true, hidden: true },\n\t\tindex: true,\n\t\t...(marker.localized ? { localized: true } : {}),\n\t\t...(unique ? { unique: true } : {}),\n\t}\n\treturn [stored, bidx]\n}\n"],"mappings":";;;;;;;;;;AA2BA,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;;;AAQA,MAAM,yBAA2D,IAAI,IAAI;CACxE;CACA;CACA;AACD,CAAC;AAED,MAAM,mBAAmB,WAAsD;CAC9E,MAAM,QAA6B;EAAE,OAAO,CAAC;EAAG,MAAM,OAAO;CAAK;CAClE,IAAI,aAAa,UAAU,OAAO,YAAY,MAC7C,MAAM,UAAU;CAEjB,IAAI,aAAa,QAChB,MAAM,UAAU,OAAO,QAAQ,KAAK,WAAW;EAC9C,IAAI,OAAO,WAAW,UACrB,OAAO;GAAE,OAAO;GAAQ,OAAO;EAAO;EAEvC,IAAI,OAAO,OAAO,UAAU,UAC3B,MAAM,IAAI,MACT,sCAAsC,OAAO,KAAK,2FACnD;EAED,OAAO;GAAE,OAAO,OAAO;GAAO,OAAO,OAAO;EAAM;CACnD,CAAC;CAEF,MAAM,QAAS,OAAO,SAAS,CAAC;CAChC,KAAK,MAAM,OAAO,kBACjB,IAAI,MAAM,SAAS,KAAA,GACjB,MAAO,MAAkC,OAAO,MAAM;CAGzD,OAAO;AACR;;;;;;;;;AAUA,MAAM,uBAAuB,SAId;CACd,MAAM,EAAE,QAAQ,YAAY,WAAW;CACvC,MAAM,aAAa,GAAG,OAAO,KAAK;CAClC,MAAM,cAAc,OAAO,SAAS,CAAC;CA4CrC,OAAO,CAAC;EA1CP,GAAG;EAIH,OAAO;GACN,GAAG;GACH,YAAY;IACX,GAAG,YAAY;IACf,GAAI,eAAe,WAChB,EACA,OAAO;KACN,MAAM;KACN,aAAa,EAAE,WAAW;IAC3B,EACD,IACC,CAAC;G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