@10x-media/fields 0.1.0-beta.4 → 0.1.0-beta.6

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 (85) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/LICENSE +21 -21
  3. package/README.md +3 -1
  4. package/dist/exports/encrypted.d.ts +7 -4
  5. package/dist/exports/encrypted.js +6 -3
  6. package/dist/fields/encrypted/boot.js +2 -1
  7. package/dist/fields/encrypted/boot.js.map +1 -1
  8. package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
  9. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  10. package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
  11. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  12. package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
  13. package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
  14. package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
  15. package/dist/fields/encrypted/components/ProtectedField.css +134 -39
  16. package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
  17. package/dist/fields/encrypted/components/ProtectedField.js +14 -0
  18. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  19. package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
  20. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
  21. package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
  22. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
  23. package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
  24. package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
  25. package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
  26. package/dist/fields/encrypted/crypto/wire.js +1 -1
  27. package/dist/fields/encrypted/encryptedField.js +63 -6
  28. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  29. package/dist/fields/encrypted/generateSecret.d.ts +10 -0
  30. package/dist/fields/encrypted/generateSecret.js +41 -0
  31. package/dist/fields/encrypted/generateSecret.js.map +1 -0
  32. package/dist/fields/encrypted/hint.js +67 -0
  33. package/dist/fields/encrypted/hint.js.map +1 -0
  34. package/dist/fields/encrypted/hooks.js +59 -31
  35. package/dist/fields/encrypted/hooks.js.map +1 -1
  36. package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
  37. package/dist/fields/encrypted/queryRewrite.js +34 -8
  38. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  39. package/dist/fields/encrypted/rawRead.d.ts +24 -0
  40. package/dist/fields/encrypted/rawRead.js +40 -0
  41. package/dist/fields/encrypted/rawRead.js.map +1 -0
  42. package/dist/fields/encrypted/scan.js +21 -4
  43. package/dist/fields/encrypted/scan.js.map +1 -1
  44. package/dist/fields/encrypted/types.d.ts +67 -2
  45. package/dist/fields/encrypted/types.js +8 -1
  46. package/dist/fields/encrypted/types.js.map +1 -1
  47. package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
  48. package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
  49. package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
  50. package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
  51. package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
  52. package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
  53. package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
  54. package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
  55. package/dist/index.js +2 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/translations/ar.js +51 -0
  58. package/dist/translations/ar.js.map +1 -0
  59. package/dist/translations/de.js +8 -1
  60. package/dist/translations/de.js.map +1 -1
  61. package/dist/translations/en.js +8 -1
  62. package/dist/translations/en.js.map +1 -1
  63. package/dist/translations/es.js +51 -0
  64. package/dist/translations/es.js.map +1 -0
  65. package/dist/translations/fr.js +51 -0
  66. package/dist/translations/fr.js.map +1 -0
  67. package/dist/translations/id.js +51 -0
  68. package/dist/translations/id.js.map +1 -0
  69. package/dist/translations/index.d.ts +10 -1
  70. package/dist/translations/index.js +19 -1
  71. package/dist/translations/index.js.map +1 -1
  72. package/dist/translations/keys.d.ts +8 -1
  73. package/dist/translations/keys.js +9 -2
  74. package/dist/translations/keys.js.map +1 -1
  75. package/dist/translations/ko.js +51 -0
  76. package/dist/translations/ko.js.map +1 -0
  77. package/dist/translations/pt.js +51 -0
  78. package/dist/translations/pt.js.map +1 -0
  79. package/dist/translations/ru.js +51 -0
  80. package/dist/translations/ru.js.map +1 -0
  81. package/dist/translations/uk.js +51 -0
  82. package/dist/translations/uk.js.map +1 -0
  83. package/dist/translations/zh.js +51 -0
  84. package/dist/translations/zh.js.map +1 -0
  85. package/package.json +5 -5
@@ -21,62 +21,106 @@
21
21
  color: var(--theme-elevation-800);
22
22
  }
23
23
 
24
- /* Attached eye segment, mirroring Payload's API-key toggle button. Background is
25
- the input's own --theme-input-bg (not an elevation step) so the segment reads
26
- as part of the input; the only seam is the input's right border, which the
27
- segment continues around its top, right, and bottom. Height is a literal 40px
28
- to match the native input: Payload compiles its formInput mixin to literal px,
29
- while var(--base) is rem-derived and shrinks below 1024px, so a base-derived
30
- height renders ~37px next to a 40px input. The doubled class outranks Payload's
31
- own `.btn { height: base(2) }`, which otherwise wins by cascade order. */
24
+ /* Attached action buttons (eye and write-only actions): borderless indicators
25
+ inside the bordered cluster wrap (below), react-select style, muted until
26
+ hovered. The doubled class outranks Payload's own `.btn { height: base(2) }`,
27
+ which otherwise wins by cascade order. */
32
28
  .tenx-protected-field__eye.tenx-protected-field__eye--attached {
33
- align-self: stretch;
34
- height: 40px;
35
- margin: 0 0 0 -1px;
29
+ height: 100%;
30
+ margin: 0;
36
31
  padding: 0 calc(var(--base) / 2);
37
- border: 1px solid var(--theme-elevation-150);
38
- border-left: 0;
39
- border-radius: var(--style-radius-s);
40
- border-top-left-radius: 0;
41
- border-bottom-left-radius: 0;
42
- background: var(--theme-input-bg);
32
+ border: 0;
33
+ border-radius: 0;
34
+ background: none;
43
35
  box-shadow: none;
44
- color: var(--theme-elevation-800);
45
- transition: border-color 100ms cubic-bezier(0, 0.2, 0.2, 1);
36
+ color: var(--theme-elevation-500);
37
+ transition: color 100ms cubic-bezier(0, 0.2, 0.2, 1);
46
38
  }
47
39
 
48
40
  .tenx-protected-field__eye--attached:hover {
49
- background: var(--theme-elevation-100);
41
+ background: none;
42
+ color: var(--theme-elevation-800);
50
43
  }
51
44
 
52
- /* Hover or focus lights the input and eye together, so the focus border never
53
- cuts off at the seam. Payload shifts an input border to elevation-250 on hover
54
- and elevation-400 on focus; mirror that onto the eye and drive both from the
55
- row, so focusing either half highlights the whole control as one. */
56
- .tenx-protected-field__attached-row:hover input,
57
- .tenx-protected-field__attached-row:hover .tenx-protected-field__eye--attached {
58
- border-color: var(--theme-elevation-250);
45
+ /* Neighbouring actions halve their facing paddings: icons sit close while
46
+ every pixel of the cluster stays clickable, the hit boundary just moves to
47
+ the midpoint. Outer edges keep the full padding. */
48
+ .tenx-protected-field__eye-wrap--attached .tenx-protected-field__eye:not(:first-child) {
49
+ padding-left: calc(var(--base) / 4);
59
50
  }
60
51
 
61
- .tenx-protected-field__attached-row:focus-within input,
62
- .tenx-protected-field__attached-row:focus-within .tenx-protected-field__eye--attached {
63
- border-color: var(--theme-elevation-400);
52
+ .tenx-protected-field__eye-wrap--attached .tenx-protected-field__eye:not(:last-child) {
53
+ padding-right: calc(var(--base) / 4);
54
+ }
55
+
56
+ /* The cluster is a plain flex container: no border, no background of its own.
57
+ ALL chrome lives on the row (below), so the icons literally sit inside the
58
+ input's box and no state can ever render them behind a different border. */
59
+ .tenx-protected-field__eye-wrap--attached {
60
+ display: flex;
61
+ align-self: stretch;
62
+ align-items: center;
64
63
  }
65
64
 
66
- /* Attached placement: input row with the eye appended as a flex segment. */
65
+ /* Attached placement: the ROW is the input. It carries the single border,
66
+ radius, background, shadow, and formInput's exact transition set; the
67
+ native input inside is stripped of all chrome (rule below), so there is
68
+ exactly one border around input text and action icons alike, and no
69
+ combination of states can ever make them differ. */
67
70
  .tenx-protected-field__attached-row {
68
71
  display: flex;
69
72
  align-items: center;
73
+ height: 40px;
74
+ border: 1px solid var(--theme-elevation-150);
75
+ border-radius: var(--style-radius-s);
76
+ background: var(--theme-input-bg);
77
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
78
+ transition-property: border, box-shadow, background-color;
79
+ transition-duration: 100ms, 100ms, 500ms;
80
+ transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
81
+ }
82
+
83
+ /* The row border follows the input's states, replicating formInput's own
84
+ precedence: hover lights it (the browser sets :hover on the input while
85
+ its <label> is hovered, and :has() reads that off the input, so hovering
86
+ an action never lights the border), focus outranks hover (declared later,
87
+ specificity flattened by :where), and focus-within keeps the control lit
88
+ while an action button holds focus, the way a clearable select keeps its
89
+ ring through an indicator click. The row's own shadow deepens on input
90
+ hover exactly as formInput's inputShadow does. */
91
+ .tenx-protected-field__attached-row:where(:has(input:hover)) {
92
+ border-color: var(--theme-elevation-250);
93
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
70
94
  }
71
95
 
96
+ .tenx-protected-field__attached-row:where(:focus-within) {
97
+ border-color: var(--theme-elevation-400);
98
+ }
99
+
100
+ /* The native input inside the row loses every piece of its own chrome; its
101
+ hover/focus/active styles from formInput now paint nothing, so they cannot
102
+ disagree with the row. height 100% (38px inside the bordered 40px row)
103
+ keeps the control at native input height. */
72
104
  .tenx-protected-field--attached .tenx-protected-field__attached-row input {
73
- border-top-right-radius: 0;
74
- border-bottom-right-radius: 0;
105
+ height: 100%;
106
+ border: 0;
107
+ border-radius: 0;
108
+ background: transparent;
109
+ box-shadow: none;
75
110
  }
76
111
 
77
- .tenx-protected-field__eye-wrap--attached {
78
- display: flex;
79
- align-self: stretch;
112
+ /* Validation error, mirrored from Payload's light/darkInputError mixins onto
113
+ the row (the input's own error chrome is stripped with the rest). Declared
114
+ last and more specific than the state rules, so error wins over hover and
115
+ focus exactly as it does on a native input. */
116
+ html[data-theme="light"] .tenx-protected-field--attached.error .tenx-protected-field__attached-row {
117
+ border-color: var(--theme-error-500);
118
+ background-color: var(--theme-error-50);
119
+ }
120
+
121
+ html[data-theme="dark"] .tenx-protected-field--attached.error .tenx-protected-field__attached-row {
122
+ border-color: var(--theme-error-400);
123
+ background-color: var(--theme-error-100);
80
124
  }
81
125
 
82
126
  /* Corner placement: eye pinned to the top-right of the textarea wrap. */
@@ -118,9 +162,60 @@
118
162
  display: none;
119
163
  }
120
164
 
121
- /* Concealed dots. */
165
+ /* Write-only: one always-editable input; a stored value is only a placeholder
166
+ (hint or dots), and every action is an attached segment or label-row icon,
167
+ so the field never grows past its native height. */
168
+ .tenx-protected-field__wo-input {
169
+ flex: 1 1 auto;
170
+ width: 100%;
171
+ /* Flex min-width:auto would refuse to shrink below the placeholder's width
172
+ and push the attached actions out of narrow containers. */
173
+ min-width: 0;
174
+ /* A rendered hint can be wider than a narrow field; browsers clip the
175
+ placeholder flush by default, which reads as a value that ends there.
176
+ On the input, not ::placeholder: that is where browsers read it from
177
+ for placeholder text. */
178
+ text-overflow: ellipsis;
179
+ }
180
+
181
+ /* With a stored value, the "placeholder" is not a prompt but the concealed
182
+ face of real data, so it renders in the input's TEXT color, exactly as
183
+ typed characters would. Only the unset state shows a true placeholder,
184
+ which keeps formInput's native muted styling untouched. */
185
+ .tenx-protected-field__wo-input--set::placeholder {
186
+ color: var(--theme-elevation-800);
187
+ font-size: 1rem;
188
+ letter-spacing: 0.15em;
189
+ }
190
+
191
+ /* Corner placement (textarea) rows its actions horizontally where the eye sits. */
192
+ .tenx-protected-field__actions--corner {
193
+ display: flex;
194
+ gap: 2px;
195
+ }
196
+
197
+ /* Staged-removal notice in the structural face: a prompt about a pending
198
+ action, so it carries placeholder tone, unmistakably distinct from the
199
+ text-colored concealed dots. */
200
+ .tenx-protected-field__wo-face-msg {
201
+ color: var(--theme-elevation-400);
202
+ }
203
+
204
+ /* Structural face box: an input-rhythm well the label-row dots sit in. */
205
+ .tenx-protected-field__wo-face-box {
206
+ display: flex;
207
+ align-items: center;
208
+ min-height: 40px;
209
+ padding: 0 calc(var(--base) * 0.75);
210
+ border: 1px solid var(--theme-elevation-150);
211
+ border-radius: var(--style-radius-s);
212
+ background: var(--theme-input-bg);
213
+ }
214
+
215
+ /* Concealed dots stand in for real stored data, so they carry the input's
216
+ text color, not a muted placeholder tone. */
122
217
  .tenx-protected-field__dots {
123
- color: var(--theme-elevation-500);
218
+ color: var(--theme-elevation-800);
124
219
  letter-spacing: 0.15em;
125
220
  user-select: none;
126
221
  white-space: nowrap;
@@ -128,7 +223,7 @@
128
223
 
129
224
  .tenx-protected-field__masked-input,
130
225
  .tenx-protected-field__masked-textarea {
131
- color: var(--theme-elevation-500);
226
+ color: var(--theme-elevation-800);
132
227
  letter-spacing: 0.15em;
133
228
  cursor: default;
134
229
  }
@@ -1,10 +1,13 @@
1
1
  import { EncryptedFieldPatch, EncryptedProtection } from "../types.js";
2
+ import { NormalizedGenerate } from "../generateSecret.js";
2
3
  import { TextFieldClientProps } from "payload";
3
4
  import React from "react";
4
5
  //#region src/fields/encrypted/components/ProtectedField.d.ts
5
6
  interface ProtectedFieldProps extends TextFieldClientProps {
7
+ clearable?: boolean;
6
8
  componentKey: string;
7
9
  fieldPatch: EncryptedFieldPatch;
10
+ generate?: NormalizedGenerate;
8
11
  maskDots?: number;
9
12
  protection: EncryptedProtection;
10
13
  }
@@ -4,6 +4,7 @@ import { EncryptedInput } from "./EncryptedInput.js";
4
4
  import { EncryptedTextarea } from "./EncryptedTextarea.js";
5
5
  import { placementFor } from "./placement.js";
6
6
  import { StructuralField } from "./StructuralField.js";
7
+ import { WriteOnlyField } from "./WriteOnlyField.js";
7
8
  import { CheckboxField, CodeField, DateTimeField, EmailField, JSONField, NumberField, PointField, RadioGroupField, SelectField, TextField, TextareaField, useFormFields } from "@payloadcms/ui";
8
9
  import { useMemo, useState } from "react";
9
10
  import { jsx } from "react/jsx-runtime";
@@ -66,6 +67,19 @@ const ProtectedField = (props) => {
66
67
  ...props,
67
68
  field: patchedField
68
69
  };
70
+ if (protection === "writeOnly") return /* @__PURE__ */ jsx(WriteOnlyField, {
71
+ clearable: props.clearable !== false,
72
+ componentKey,
73
+ field: patchedField,
74
+ generate: props.generate,
75
+ hintPath: `${path}_hint`,
76
+ maskDots,
77
+ Native,
78
+ nativeProps,
79
+ path,
80
+ placement: placementFor(componentKey, fieldPatch.hasMany === true),
81
+ setPath: `${path}_set`
82
+ });
69
83
  if (protection === "none" || startedEmpty) return /* @__PURE__ */ jsx(Native, { ...nativeProps });
70
84
  const faceField = patchedField;
71
85
  const placement = placementFor(componentKey, fieldPatch.hasMany === true);
@@ -1 +1 @@
1
- {"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAiCA,MAAM,SAA4C;CACjD,UAAU;CACV,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;CACP,QAAQ;CACR,MAAM;CACN,UAAU;AACX;;;;;;;AAeA,MAAM,gBAAgB,UAA4B;CACjD,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;CAER,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,QAAQ,IAAI;CAEhE,OAAO;AACR;;;;;;;;;;;;;;;;;AAkBA,MAAa,kBAAiD,UAAU;CACvE,MAAM,EAAE,cAAc,OAAO,YAAY,MAAM,eAAe;CAC9D,MAAM,WAAW,cAAc,MAAM,QAAQ;CAE7C,MAAM,CAAC,gBAAgB,SADC,eAAe,CAAC,YAAY,aAAa,SAAS,OAAO,KAAK,CACxC,CAAC;CAE/C,MAAM,eAAe,eACb;EACN,GAAG;EACH,GAAG;EACH,OAAO;GAAE,GAAG,MAAM;GAAO,GAAG,WAAW;EAAM;CAC9C,IACA,CAAC,OAAO,UAAU,CACnB;CAEA,MAAM,SAAS,OAAO,iBAAkB;CACxC,MAAM,cAAc;EAAE,GAAI;EAA8C,OAAO;CAAa;CAE5F,IAAI,eAAe,UAAU,cAC5B,OAAO,oBAAC,QAAD,EAAQ,GAAI,YAAc,CAAA;CAGlC,MAAM,YAAY;CAElB,MAAM,YAAY,aAAa,cADf,WAAW,YAAY,IACa;CAEpD,IAAI,cAAc,YACjB,OACC,oBAAC,gBAAD;EACC,OAAO;EACP,MAAM;EACI;EACJ;CACN,CAAA;CAIH,IAAI,cAAc,UACjB,OAAO,oBAAC,mBAAD;EAAmB,OAAO;EAAqB;EAAgB;CAAO,CAAA;CAG9E,OACC,oBAAC,iBAAD;EACe;EACd,OAAO;EACG;EACF;EACK;EACP;CACN,CAAA;AAEH"}
1
+ {"version":3,"file":"ProtectedField.js","names":[],"sources":["../../../../src/fields/encrypted/components/ProtectedField.tsx"],"sourcesContent":["'use client'\nimport {\n\tCheckboxField,\n\tCodeField,\n\tDateTimeField,\n\tEmailField,\n\tJSONField,\n\tNumberField,\n\tPointField,\n\tRadioGroupField,\n\tSelectField,\n\tTextareaField,\n\tTextField,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport type { NormalizedGenerate } from '../generateSecret'\nimport { clampMaskDots } from '../maskDots'\nimport type { EncryptedFieldPatch, EncryptedProtection } from '../types'\nimport { EncryptedInput } from './EncryptedInput'\nimport { EncryptedTextarea } from './EncryptedTextarea'\nimport type { EncryptedFieldConfig } from './placement'\nimport { placementFor } from './placement'\nimport { StructuralField } from './StructuralField'\nimport { WriteOnlyField } from './WriteOnlyField'\nimport './ProtectedField.css'\n\n/**\n * Native components accept per-type client props; dispatch is by runtime\n * componentKey, so the map is typed at the erased component boundary.\n */\ntype AnyFieldComponent = React.ComponentType<Record<string, unknown>>\n\nconst NATIVE: Record<string, AnyFieldComponent> = {\n\tcheckbox: CheckboxField as AnyFieldComponent,\n\tcode: CodeField as AnyFieldComponent,\n\tdate: DateTimeField as AnyFieldComponent,\n\temail: EmailField as AnyFieldComponent,\n\tjson: JSONField as AnyFieldComponent,\n\tnumber: NumberField as AnyFieldComponent,\n\tpoint: PointField as AnyFieldComponent,\n\tradio: RadioGroupField as AnyFieldComponent,\n\tselect: SelectField as AnyFieldComponent,\n\ttext: TextField as AnyFieldComponent,\n\ttextarea: TextareaField as AnyFieldComponent,\n}\n\nexport interface ProtectedFieldProps extends TextFieldClientProps {\n\tclearable?: boolean\n\tcomponentKey: string\n\tfieldPatch: EncryptedFieldPatch\n\tgenerate?: NormalizedGenerate\n\tmaskDots?: number\n\tprotection: EncryptedProtection\n}\n\n/**\n * A field with no stored content has nothing to conceal, so it renders unmasked\n * (the plain native control). Captured once at mount, so characters typed into a\n * field that started empty stay visible and the field never flips to masked\n * mid-entry; a field that already holds content is masked until revealed.\n */\nconst isEmptyValue = (value: unknown): boolean => {\n\tif (value == null || value === '') {\n\t\treturn true\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length === 0 || value.every((item) => item == null)\n\t}\n\treturn false\n}\n\n/**\n * Single admin dispatcher for scalar and structural encrypted fields (richText\n * is its own virtual-editor field pair, wired to ProtectedRichText). Each type\n * renders as its native variant with a fixed run of dots while concealed, and an\n * inline eye toggle that swaps to the real editable native component on reveal.\n * The fieldPatch restores type-specific config (options, hasMany, date admin) on\n * the revealed component.\n *\n * Masking is visual-only by design. afterRead decrypts server-side, so the\n * field's form value is already plaintext regardless of the mask, and no masked\n * facsimile binds to that value. Two accepted consequences: (a) the plaintext\n * reaches an authorized admin's browser, since that admin already has field read\n * access and masking only stops casual over-the-shoulder display; (b) saving an\n * unchanged document re-seals with a fresh IV (version churn), because the form\n * holds plaintext, not the stored ciphertext.\n */\nexport const ProtectedField: React.FC<ProtectedFieldProps> = (props) => {\n\tconst { componentKey, field, fieldPatch, path, protection } = props\n\tconst maskDots = clampMaskDots(props.maskDots)\n\tconst startedEmptyNow = useFormFields(([fields]) => isEmptyValue(fields?.[path]?.value))\n\tconst [startedEmpty] = useState(startedEmptyNow)\n\n\tconst patchedField = useMemo(\n\t\t() => ({\n\t\t\t...field,\n\t\t\t...fieldPatch,\n\t\t\tadmin: { ...field.admin, ...fieldPatch.admin },\n\t\t}),\n\t\t[field, fieldPatch]\n\t)\n\n\tconst Native = NATIVE[componentKey] ?? (TextField as AnyFieldComponent)\n\tconst nativeProps = { ...(props as unknown as Record<string, unknown>), field: patchedField }\n\n\tif (protection === 'writeOnly') {\n\t\treturn (\n\t\t\t<WriteOnlyField\n\t\t\t\tclearable={props.clearable !== false}\n\t\t\t\tcomponentKey={componentKey}\n\t\t\t\tfield={patchedField as unknown as EncryptedFieldConfig}\n\t\t\t\tgenerate={props.generate}\n\t\t\t\thintPath={`${path}_hint`}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tNative={Native}\n\t\t\t\tnativeProps={nativeProps}\n\t\t\t\tpath={path}\n\t\t\t\tplacement={placementFor(componentKey, fieldPatch.hasMany === true)}\n\t\t\t\tsetPath={`${path}_set`}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (protection === 'none' || startedEmpty) {\n\t\treturn <Native {...nativeProps} />\n\t}\n\n\tconst faceField = patchedField as unknown as EncryptedFieldConfig\n\tconst hasMany = fieldPatch.hasMany === true\n\tconst placement = placementFor(componentKey, hasMany)\n\n\tif (placement === 'attached') {\n\t\treturn (\n\t\t\t<EncryptedInput\n\t\t\t\tfield={faceField}\n\t\t\t\tkind={componentKey as 'email' | 'number' | 'text'}\n\t\t\t\tmaskDots={maskDots}\n\t\t\t\tpath={path}\n\t\t\t/>\n\t\t)\n\t}\n\n\tif (placement === 'corner') {\n\t\treturn <EncryptedTextarea field={faceField} maskDots={maskDots} path={path} />\n\t}\n\n\treturn (\n\t\t<StructuralField\n\t\t\tcomponentKey={componentKey}\n\t\t\tfield={faceField}\n\t\t\tmaskDots={maskDots}\n\t\t\tNative={Native}\n\t\t\tnativeProps={nativeProps}\n\t\t\tpath={path}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,MAAM,SAA4C;CACjD,UAAU;CACV,MAAM;CACN,MAAM;CACN,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;CACP,QAAQ;CACR,MAAM;CACN,UAAU;AACX;;;;;;;AAiBA,MAAM,gBAAgB,UAA4B;CACjD,IAAI,SAAS,QAAQ,UAAU,IAC9B,OAAO;CAER,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,QAAQ,IAAI;CAEhE,OAAO;AACR;;;;;;;;;;;;;;;;;AAkBA,MAAa,kBAAiD,UAAU;CACvE,MAAM,EAAE,cAAc,OAAO,YAAY,MAAM,eAAe;CAC9D,MAAM,WAAW,cAAc,MAAM,QAAQ;CAE7C,MAAM,CAAC,gBAAgB,SADC,eAAe,CAAC,YAAY,aAAa,SAAS,OAAO,KAAK,CACxC,CAAC;CAE/C,MAAM,eAAe,eACb;EACN,GAAG;EACH,GAAG;EACH,OAAO;GAAE,GAAG,MAAM;GAAO,GAAG,WAAW;EAAM;CAC9C,IACA,CAAC,OAAO,UAAU,CACnB;CAEA,MAAM,SAAS,OAAO,iBAAkB;CACxC,MAAM,cAAc;EAAE,GAAI;EAA8C,OAAO;CAAa;CAE5F,IAAI,eAAe,aAClB,OACC,oBAAC,gBAAD;EACC,WAAW,MAAM,cAAc;EACjB;EACd,OAAO;EACP,UAAU,MAAM;EAChB,UAAU,GAAG,KAAK;EACR;EACF;EACK;EACP;EACN,WAAW,aAAa,cAAc,WAAW,YAAY,IAAI;EACjE,SAAS,GAAG,KAAK;CACjB,CAAA;CAIH,IAAI,eAAe,UAAU,cAC5B,OAAO,oBAAC,QAAD,EAAQ,GAAI,YAAc,CAAA;CAGlC,MAAM,YAAY;CAElB,MAAM,YAAY,aAAa,cADf,WAAW,YAAY,IACa;CAEpD,IAAI,cAAc,YACjB,OACC,oBAAC,gBAAD;EACC,OAAO;EACP,MAAM;EACI;EACJ;CACN,CAAA;CAIH,IAAI,cAAc,UACjB,OAAO,oBAAC,mBAAD;EAAmB,OAAO;EAAqB;EAAgB;CAAO,CAAA;CAG9E,OACC,oBAAC,iBAAD;EACe;EACd,OAAO;EACG;EACF;EACK;EACP;CACN,CAAA;AAEH"}
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { Button } from "@payloadcms/ui";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/fields/encrypted/components/WriteOnlyActions.tsx
5
+ /**
6
+ * Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on
7
+ * (8, 6) so the mark sits in the middle of its clickable area, matching the
8
+ * eye beside which they render.
9
+ */
10
+ const GLYPHS = {
11
+ clear: /* @__PURE__ */ jsx("path", {
12
+ className: "stroke",
13
+ d: "M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5"
14
+ }),
15
+ edit: /* @__PURE__ */ jsx("path", {
16
+ className: "stroke",
17
+ d: "M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z",
18
+ strokeLinejoin: "round"
19
+ }),
20
+ generate: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
21
+ className: "stroke",
22
+ d: "M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2"
23
+ }), /* @__PURE__ */ jsx("path", {
24
+ className: "stroke",
25
+ d: "M4.5 0.8V3H6.7M11.5 11.2V9H9.3",
26
+ strokeLinejoin: "round"
27
+ })] }),
28
+ undo: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("path", {
29
+ className: "stroke",
30
+ d: "M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5"
31
+ }), /* @__PURE__ */ jsx("path", {
32
+ className: "stroke",
33
+ d: "M6 1.25L3.5 3.75L6 6.25",
34
+ strokeLinejoin: "round"
35
+ })] })
36
+ };
37
+ /**
38
+ * One write-only action, rendered with the same Button shell, icon canvas, and
39
+ * (for attached placement) input-segment chrome as the reveal eye, so a row of
40
+ * actions reads as part of the input and never changes the field's height.
41
+ */
42
+ const ActionButton = ({ attached, kind, label, onClick, pressed }) => /* @__PURE__ */ jsx(Button, {
43
+ "aria-label": label,
44
+ buttonStyle: "none",
45
+ className: [
46
+ "tenx-protected-field__eye",
47
+ attached ? "tenx-protected-field__eye--attached" : "tenx-protected-field__eye--floating",
48
+ "tenx-protected-field__action"
49
+ ].filter(Boolean).join(" "),
50
+ extraButtonProps: pressed === void 0 ? void 0 : { "aria-pressed": pressed },
51
+ icon: /* @__PURE__ */ jsx("svg", {
52
+ "aria-hidden": "true",
53
+ className: "tenx-protected-field__eye-icon",
54
+ viewBox: "0 0 16 12",
55
+ xmlns: "http://www.w3.org/2000/svg",
56
+ children: GLYPHS[kind]
57
+ }),
58
+ margin: false,
59
+ onClick,
60
+ tooltip: label
61
+ });
62
+ //#endregion
63
+ export { ActionButton };
64
+
65
+ //# sourceMappingURL=WriteOnlyActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteOnlyActions.js","names":[],"sources":["../../../../src/fields/encrypted/components/WriteOnlyActions.tsx"],"sourcesContent":["'use client'\nimport { Button } from '@payloadcms/ui'\nimport type React from 'react'\n\nexport type ActionKind = 'clear' | 'edit' | 'generate' | 'undo'\n\n/**\n * Thin-stroke glyphs on the eye's 16x12 canvas, each drawn centered on\n * (8, 6) so the mark sits in the middle of its clickable area, matching the\n * eye beside which they render.\n */\nconst GLYPHS: Record<ActionKind, React.ReactNode> = {\n\t// × matching react-select's clear indicator.\n\tclear: <path className=\"stroke\" d=\"M4.5 2.5L11.5 9.5M11.5 2.5L4.5 9.5\" />,\n\t// Pencil.\n\tedit: (\n\t\t<path\n\t\t\tclassName=\"stroke\"\n\t\t\td=\"M3.2 11.5L3.7 9L10.2 2.5C10.75 1.95 11.65 1.95 12.2 2.5C12.75 3.05 12.75 3.95 12.2 4.5L5.7 11L3.2 11.5Z\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t/>\n\t),\n\t// Circular arrows, the rotate/regenerate convention.\n\tgenerate: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M13 6A5 5 0 0 0 4.5 2.8M3 6A5 5 0 0 0 11.5 9.2\" />\n\t\t\t<path className=\"stroke\" d=\"M4.5 0.8V3H6.7M11.5 11.2V9H9.3\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n\t// Counter-clockwise undo arrow.\n\tundo: (\n\t\t<>\n\t\t\t<path className=\"stroke\" d=\"M3.5 3.75H9A3.5 3.5 0 0 1 9 10.75H5\" />\n\t\t\t<path className=\"stroke\" d=\"M6 1.25L3.5 3.75L6 6.25\" strokeLinejoin=\"round\" />\n\t\t</>\n\t),\n}\n\n/**\n * One write-only action, rendered with the same Button shell, icon canvas, and\n * (for attached placement) input-segment chrome as the reveal eye, so a row of\n * actions reads as part of the input and never changes the field's height.\n */\nexport const ActionButton: React.FC<{\n\tattached?: boolean\n\tkind: ActionKind\n\tlabel: string\n\tonClick: () => void\n\tpressed?: boolean\n}> = ({ attached, kind, label, onClick, pressed }) => (\n\t<Button\n\t\taria-label={label}\n\t\tbuttonStyle=\"none\"\n\t\tclassName={[\n\t\t\t'tenx-protected-field__eye',\n\t\t\tattached ? 'tenx-protected-field__eye--attached' : 'tenx-protected-field__eye--floating',\n\t\t\t'tenx-protected-field__action',\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(' ')}\n\t\textraButtonProps={pressed === undefined ? undefined : { 'aria-pressed': pressed }}\n\t\ticon={\n\t\t\t<svg\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName=\"tenx-protected-field__eye-icon\"\n\t\t\t\tviewBox=\"0 0 16 12\"\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t>\n\t\t\t\t{GLYPHS[kind]}\n\t\t\t</svg>\n\t\t}\n\t\tmargin={false}\n\t\tonClick={onClick}\n\t\ttooltip={label}\n\t/>\n)\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAA8C;CAEnD,OAAO,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAsC,CAAA;CAExE,MACC,oBAAC,QAAD;EACC,WAAU;EACV,GAAE;EACF,gBAAe;CACf,CAAA;CAGF,UACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAkD,CAAA,GAC7E,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAAiC,gBAAe;CAAS,CAAA,CACnF,EAAA,CAAA;CAGH,MACC,qBAAA,UAAA,EAAA,UAAA,CACC,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;CAAuC,CAAA,GAClE,oBAAC,QAAD;EAAM,WAAU;EAAS,GAAE;EAA0B,gBAAe;CAAS,CAAA,CAC5E,EAAA,CAAA;AAEJ;;;;;;AAOA,MAAa,gBAMP,EAAE,UAAU,MAAM,OAAO,SAAS,cACvC,oBAAC,QAAD;CACC,cAAY;CACZ,aAAY;CACZ,WAAW;EACV;EACA,WAAW,wCAAwC;EACnD;CACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;CACV,kBAAkB,YAAY,KAAA,IAAY,KAAA,IAAY,EAAE,gBAAgB,QAAQ;CAChF,MACC,oBAAC,OAAD;EACC,eAAY;EACZ,WAAU;EACV,SAAQ;EACR,OAAM;YAEL,OAAO;CACJ,CAAA;CAEN,QAAQ;CACC;CACT,SAAS;AACT,CAAA"}
@@ -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