@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
@@ -2,24 +2,40 @@ import { keys } from "../../translations/keys.js";
2
2
  import { parseColor } from "./engine/parse.js";
3
3
  import { formatColor } from "./engine/format.js";
4
4
  import { isColorSchemeValue } from "./engine/scheme.js";
5
- import { COLOR_CUSTOM_KEY, PRESET_PREFIX } from "./options.js";
5
+ import { COLOR_CUSTOM_KEY } from "./options.js";
6
+ import { applyReferenceAlpha, formatPresetReference, parsePresetReference, presetReferenceIssue, presetReferenceParts } from "./presetReference.js";
6
7
  import { flatValue } from "./schemeValue.js";
7
8
  import { asTranslate } from "../../translations/server.js";
8
9
  import { resolveColorFormat } from "./resolveFormat.js";
9
10
  import { resolvePresets } from "./resolvePresets.js";
10
11
  import { text } from "payload/shared";
11
12
  //#region src/fields/color/colorField.ts
12
- const buildValidate = (opts) => (value, args) => {
13
+ const buildValidate = (opts) => async (value, args) => {
13
14
  if (typeof value === "string" && value !== "") {
14
15
  if (opts.linked && value.startsWith("preset:")) {
15
- if (value.length === 7) return asTranslate(args.req.t)(keys.missingPreset);
16
+ let hasKey = null;
17
+ if (presetReferenceParts(value)?.explicit) try {
18
+ const all = await resolvePresets({
19
+ memoKey: opts.memoKey,
20
+ req: args.req,
21
+ source: opts.presets
22
+ });
23
+ if (all.length > 0) hasKey = (key) => all.some((preset) => preset.key === key);
24
+ } catch {}
25
+ const issue = presetReferenceIssue(value, hasKey);
26
+ if (issue === "invalidAlpha") return asTranslate(args.req.t)(keys.invalidColor);
27
+ if (issue !== null) return asTranslate(args.req.t)(keys.missingPreset);
16
28
  } else if (!parseColor(value)) return asTranslate(args.req.t)(keys.invalidColor);
17
29
  }
18
30
  return text(value, args);
19
31
  };
20
32
  const buildNormalizeHook = (opts) => ({ req, value }) => {
21
33
  if (typeof value !== "string" || value === "") return value;
22
- if (opts.linked && value.startsWith("preset:")) return value;
34
+ if (opts.linked && value.startsWith("preset:")) {
35
+ const parts = presetReferenceParts(value);
36
+ if (!parts) return value;
37
+ return formatPresetReference(parts.key, opts.alpha ? parts.alpha : 100);
38
+ }
23
39
  const parsed = parseColor(value);
24
40
  if (!parsed) return value;
25
41
  return formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha });
@@ -63,7 +79,11 @@ function colorField(options = {}) {
63
79
  format,
64
80
  linked
65
81
  })] },
66
- validate: buildValidate({ linked })
82
+ validate: buildValidate({
83
+ linked,
84
+ memoKey,
85
+ presets
86
+ })
67
87
  };
68
88
  const field = typeof overrides === "function" ? overrides({ field: base }) : base;
69
89
  if (!linked) return field;
@@ -82,25 +102,33 @@ function colorField(options = {}) {
82
102
  light: value
83
103
  };
84
104
  };
105
+ /** The stored reference alpha, applied to whatever the reference resolved to. */
106
+ const withAlpha = (resolved, refAlpha, req) => {
107
+ const effective = alpha ? refAlpha : 100;
108
+ if (resolved === null || effective === 100) return resolved;
109
+ return applyReferenceAlpha(resolved, effective, resolveColorFormat(format, req));
110
+ };
85
111
  const resolveHook = async ({ collection, global, req, siblingData }) => {
86
112
  const raw = siblingData?.[field.name];
87
113
  if (typeof raw !== "string" || raw === "") return null;
88
114
  if (!raw.startsWith("preset:")) return shape(raw);
89
- const key = raw.slice(PRESET_PREFIX.length);
115
+ const ref = parsePresetReference(raw);
116
+ const key = ref?.key ?? raw.slice(7);
117
+ const refAlpha = ref?.alpha ?? 100;
90
118
  try {
91
119
  const match = (await resolvePresets({
92
120
  memoKey,
93
121
  req,
94
122
  source: presets
95
123
  })).find((preset) => preset.key === key);
96
- return shape(match ? match.value : linkedFallback);
124
+ return withAlpha(shape(match ? match.value : linkedFallback), refAlpha, req);
97
125
  } catch (error) {
98
126
  if (!loggedRequests.has(req)) {
99
127
  loggedRequests.add(req);
100
128
  const slug = collection?.slug ?? global?.slug ?? "unknown";
101
129
  req.payload.logger.error({ err: error }, `colorField preset resolver failed for ${slug}.${field.name}`);
102
130
  }
103
- return shape(linkedFallback);
131
+ return withAlpha(shape(linkedFallback), refAlpha, req);
104
132
  }
105
133
  };
106
134
  const resolvedAdmin = {
@@ -1 +1 @@
1
- {"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\tPRESET_PREFIX,\n} from './options'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: { linked: boolean }): TextFieldValidation =>\n\t(value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tif (value.length === PRESET_PREFIX.length) {\n\t\t\t\t\treturn asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t\t}\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) return value\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst key = raw.slice(PRESET_PREFIX.length)\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn shape(match ? match.value : linkedFallback)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn shape(linkedFallback)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disableListColumn: true, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\n\treturn [field, resolvedField]\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,iBACJ,UACA,OAAO,SAAS;CAChB,IAAI,OAAO,UAAU,YAAY,UAAU;MACtC,KAAK,UAAU,MAAM,WAAA,SAAwB;OAC5C,MAAM,WAAA,GACT,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,aAAa;EAAA,OAE5C,IAAI,CAAC,WAAW,KAAK,GAC3B,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,YAAY;CAAA;CAGlD,OAAO,KAAK,OAAO,IAAI;AACxB;AAED,MAAM,sBACJ,UACA,EAAE,KAAK,YAAY;CACnB,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,IAAI,KAAK,UAAU,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC3D,MAAM,SAAS,WAAW,KAAK;CAE/B,IAAI,CAAC,QAAQ,OAAO;CACpB,OAA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,SAAS,OAAO,UAAU,KAAK;EACnD,OAAO,mBAAmB,KAAK,IAAI,QAAQ;GAAE,MAAM;GAAO,OAAO;EAAM;CACxE;CAEA,MAAM,cAAyB,OAAO,EAAE,YAAY,QAAQ,KAAK,kBAAkB;EAClF,MAAM,MAAM,cAAc,MAAM;EAChC,IAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI,OAAO;EAClD,IAAI,CAAC,IAAI,WAAA,SAAwB,GAAG,OAAO,MAAM,GAAG;EACpD,MAAM,MAAM,IAAI,MAAM,cAAc,MAAM;EAC1C,IAAI;GAEH,MAAM,SAAQ,MADI,eAAe;IAAE;IAAS;IAAK,QAAQ;GAAQ,CAAC,GAChD,MAAM,WAAW,OAAO,QAAQ,GAAG;GACrD,OAAO,MAAM,QAAQ,MAAM,QAAQ,cAAc;EAClD,SAAS,OAAO;GAEf,IAAI,CAAC,eAAe,IAAI,GAAG,GAAG;IAC7B,eAAe,IAAI,GAAG;IACtB,MAAM,OAAO,YAAY,QAAQ,QAAQ,QAAQ;IACjD,IAAI,QAAQ,OAAO,MAClB,EAAE,KAAK,MAAM,GACb,yCAAyC,KAAK,GAAG,MAAM,MACxD;GACD;GACA,OAAO,MAAM,cAAc;EAC5B;CACD;CAEA,MAAM,gBAAgB;EAAE,mBAAmB;EAAM,QAAQ;CAAK;CAmB9D,OAAO,CAAC,OAhBP,gBAAgB,YACb;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,IACC;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,CAEyB;AAC7B"}
1
+ {"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\ttype ColorPresetsSource,\n\tPRESET_PREFIX,\n} from './options'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from './presetReference'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: {\n\t\tlinked: boolean\n\t\tmemoKey: symbol\n\t\tpresets: ColorPresetsSource | undefined\n\t}): TextFieldValidation =>\n\tasync (value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tlet hasKey: ((key: string) => boolean) | null = null\n\t\t\t\tif (presetReferenceParts(value)?.explicit) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst all = await resolvePresets({\n\t\t\t\t\t\t\tmemoKey: opts.memoKey,\n\t\t\t\t\t\t\treq: args.req,\n\t\t\t\t\t\t\tsource: opts.presets,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// An empty list means no presets are configured (or none resolved);\n\t\t\t\t\t\t// skip the existence check rather than rejecting every reference\n\t\t\t\t\t\tif (all.length > 0) hasKey = (key) => all.some((preset) => preset.key === key)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// A broken resolver must not block writes; reads degrade and log separately\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\tif (issue === 'invalidAlpha') return asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t\tif (issue !== null) return asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\tconst parts = presetReferenceParts(value)\n\t\t\t// Empty keys pass through so validate rejects them with a proper message\n\t\t\tif (!parts) return value\n\t\t\treturn formatPresetReference(parts.key, opts.alpha ? parts.alpha : 100)\n\t\t}\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked, memoKey, presets }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\t/** The stored reference alpha, applied to whatever the reference resolved to. */\n\tconst withAlpha = (\n\t\tresolved: null | string | ColorSchemeValue,\n\t\trefAlpha: number,\n\t\treq: PayloadRequest\n\t): null | string | ColorSchemeValue => {\n\t\tconst effective = alpha ? refAlpha : 100\n\t\tif (resolved === null || effective === 100) return resolved\n\t\treturn applyReferenceAlpha(resolved, effective, resolveColorFormat(format, req))\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst ref = parsePresetReference(raw)\n\t\tconst key = ref?.key ?? raw.slice(PRESET_PREFIX.length)\n\t\tconst refAlpha = ref?.alpha ?? 100\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn withAlpha(shape(match ? match.value : linkedFallback), refAlpha, req)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn withAlpha(shape(linkedFallback), refAlpha, req)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disableListColumn: true, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}Resol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CAAC,WAAW,EAAE;EAClC,SAAS;CACV,IACC;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,CAEyB;AAC7B"}
@@ -1,8 +1,8 @@
1
- import { PRESET_PREFIX } from "./options.js";
1
+ import { parsePresetReference } from "./presetReference.js";
2
2
  //#region src/fields/color/presetChip.ts
3
3
  /**
4
- * Derives the chip shown in place of a raw `preset:<key>` ref in the color
5
- * input. Returns null outside chip mode: non-linked fields, active text
4
+ * Derives the chip shown in place of a raw `preset:<key>[/<alpha>]` ref in the
5
+ * color input. Returns null outside chip mode: non-linked fields, active text
6
6
  * editing, non-ref values, or an empty key (which validate rejects anyway).
7
7
  * A ref whose key no longer resolves still chips (missing: true, label falls
8
8
  * back to the key) so the stored ref stays visible without leaking raw text.
@@ -10,13 +10,14 @@ import { PRESET_PREFIX } from "./options.js";
10
10
  const derivePresetChip = (args) => {
11
11
  const { editing, linked, presets, value } = args;
12
12
  if (!linked || editing) return null;
13
- if (typeof value !== "string" || !value.startsWith("preset:")) return null;
14
- const key = value.slice(PRESET_PREFIX.length);
15
- if (key === "") return null;
16
- const preset = presets.find((entry) => entry.key === key);
13
+ if (typeof value !== "string") return null;
14
+ const ref = parsePresetReference(value);
15
+ if (!ref) return null;
16
+ const preset = presets.find((entry) => entry.key === ref.key);
17
17
  return {
18
- key,
19
- label: preset?.label ?? key,
18
+ alpha: ref.alpha,
19
+ key: ref.key,
20
+ label: preset?.label ?? ref.key,
20
21
  missing: !preset,
21
22
  value: preset?.value ?? null
22
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"presetChip.js","names":[],"sources":["../../../src/fields/color/presetChip.ts"],"sourcesContent":["import type { ColorSchemeValue } from '../../types'\nimport { PRESET_PREFIX, type ResolvedColorPreset } from './options'\n\nexport type PresetChip = {\n\tkey: string\n\tlabel: string\n\tmissing: boolean\n\tvalue: null | string | ColorSchemeValue\n}\n\n/**\n * Derives the chip shown in place of a raw `preset:<key>` ref in the color\n * input. Returns null outside chip mode: non-linked fields, active text\n * editing, non-ref values, or an empty key (which validate rejects anyway).\n * A ref whose key no longer resolves still chips (missing: true, label falls\n * back to the key) so the stored ref stays visible without leaking raw text.\n */\nexport const derivePresetChip = (args: {\n\tediting: boolean\n\tlinked: boolean\n\tpresets: ResolvedColorPreset[]\n\tvalue: unknown\n}): null | PresetChip => {\n\tconst { editing, linked, presets, value } = args\n\tif (!linked || editing) return null\n\tif (typeof value !== 'string' || !value.startsWith(PRESET_PREFIX)) return null\n\tconst key = value.slice(PRESET_PREFIX.length)\n\tif (key === '') return null\n\tconst preset = presets.find((entry) => entry.key === key)\n\treturn {\n\t\tkey,\n\t\tlabel: preset?.label ?? key,\n\t\tmissing: !preset,\n\t\tvalue: preset?.value ?? null,\n\t}\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAa,oBAAoB,SAKR;CACxB,MAAM,EAAE,SAAS,QAAQ,SAAS,UAAU;CAC5C,IAAI,CAAC,UAAU,SAAS,OAAO;CAC/B,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC1E,MAAM,MAAM,MAAM,MAAM,cAAc,MAAM;CAC5C,IAAI,QAAQ,IAAI,OAAO;CACvB,MAAM,SAAS,QAAQ,MAAM,UAAU,MAAM,QAAQ,GAAG;CACxD,OAAO;EACN;EACA,OAAO,QAAQ,SAAS;EACxB,SAAS,CAAC;EACV,OAAO,QAAQ,SAAS;CACzB;AACD"}
1
+ {"version":3,"file":"presetChip.js","names":[],"sources":["../../../src/fields/color/presetChip.ts"],"sourcesContent":["import type { ColorSchemeValue } from '../../types'\nimport type { ResolvedColorPreset } from './options'\nimport { parsePresetReference } from './presetReference'\n\nexport type PresetChip = {\n\talpha: number\n\tkey: string\n\tlabel: string\n\tmissing: boolean\n\tvalue: null | string | ColorSchemeValue\n}\n\n/**\n * Derives the chip shown in place of a raw `preset:<key>[/<alpha>]` ref in the\n * color input. Returns null outside chip mode: non-linked fields, active text\n * editing, non-ref values, or an empty key (which validate rejects anyway).\n * A ref whose key no longer resolves still chips (missing: true, label falls\n * back to the key) so the stored ref stays visible without leaking raw text.\n */\nexport const derivePresetChip = (args: {\n\tediting: boolean\n\tlinked: boolean\n\tpresets: ResolvedColorPreset[]\n\tvalue: unknown\n}): null | PresetChip => {\n\tconst { editing, linked, presets, value } = args\n\tif (!linked || editing) return null\n\tif (typeof value !== 'string') return null\n\tconst ref = parsePresetReference(value)\n\tif (!ref) return null\n\tconst preset = presets.find((entry) => entry.key === ref.key)\n\treturn {\n\t\talpha: ref.alpha,\n\t\tkey: ref.key,\n\t\tlabel: preset?.label ?? ref.key,\n\t\tmissing: !preset,\n\t\tvalue: preset?.value ?? null,\n\t}\n}\n"],"mappings":";;;;;;;;;AAmBA,MAAa,oBAAoB,SAKR;CACxB,MAAM,EAAE,SAAS,QAAQ,SAAS,UAAU;CAC5C,IAAI,CAAC,UAAU,SAAS,OAAO;CAC/B,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,MAAM,qBAAqB,KAAK;CACtC,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,SAAS,QAAQ,MAAM,UAAU,MAAM,QAAQ,IAAI,GAAG;CAC5D,OAAO;EACN,OAAO,IAAI;EACX,KAAK,IAAI;EACT,OAAO,QAAQ,SAAS,IAAI;EAC5B,SAAS,CAAC;EACV,OAAO,QAAQ,SAAS;CACzB;AACD"}
@@ -0,0 +1,13 @@
1
+ //#region src/fields/color/presetReference.d.ts
2
+ type PresetReference = {
3
+ alpha: number;
4
+ key: string;
5
+ };
6
+ /**
7
+ * Client-safe parser for stored preset references. Returns null when the value
8
+ * is not a reference; alpha defaults to 100 when no suffix is present.
9
+ */
10
+ declare const parsePresetReference: (value: string) => null | PresetReference;
11
+ //#endregion
12
+ export { PresetReference, parsePresetReference };
13
+ //# sourceMappingURL=presetReference.d.ts.map
@@ -0,0 +1,94 @@
1
+ import { parseColor } from "./engine/parse.js";
2
+ import { formatColor } from "./engine/format.js";
3
+ import { isColorSchemeValue } from "./engine/scheme.js";
4
+ import { PRESET_PREFIX } from "./options.js";
5
+ //#region src/fields/color/presetReference.ts
6
+ const ALPHA_SUFFIX = /^(100|[1-9]?[0-9])$/;
7
+ const ALPHA_LIKE = /^[0-9.]+$/;
8
+ /**
9
+ * Splits a `preset:<key>[/<alpha>]` string into key and alpha, tracking whether
10
+ * the alpha was written out. The suffix is read off the last slash and counts
11
+ * as alpha only when it matches the integer grammar 0-100; anything else stays
12
+ * part of the key, so slash-containing keys keep working.
13
+ */
14
+ const presetReferenceParts = (value) => {
15
+ if (!value.startsWith("preset:")) return null;
16
+ const remainder = value.slice(PRESET_PREFIX.length);
17
+ if (remainder === "") return null;
18
+ const slash = remainder.lastIndexOf("/");
19
+ if (slash !== -1 && ALPHA_SUFFIX.test(remainder.slice(slash + 1))) {
20
+ const key = remainder.slice(0, slash);
21
+ if (key === "") return null;
22
+ return {
23
+ alpha: Number(remainder.slice(slash + 1)),
24
+ explicit: true,
25
+ key
26
+ };
27
+ }
28
+ return {
29
+ alpha: 100,
30
+ explicit: false,
31
+ key: remainder
32
+ };
33
+ };
34
+ /**
35
+ * Client-safe parser for stored preset references. Returns null when the value
36
+ * is not a reference; alpha defaults to 100 when no suffix is present.
37
+ */
38
+ const parsePresetReference = (value) => {
39
+ const parts = presetReferenceParts(value);
40
+ return parts ? {
41
+ alpha: parts.alpha,
42
+ key: parts.key
43
+ } : null;
44
+ };
45
+ /** Canonical stored form: bare reference at alpha 100, `/<alpha>` suffix below. */
46
+ const formatPresetReference = (key, alpha = 100) => {
47
+ const bounded = Math.min(100, Math.max(0, Math.round(alpha)));
48
+ return bounded === 100 ? `${PRESET_PREFIX}${key}` : `${PRESET_PREFIX}${key}/${bounded}`;
49
+ };
50
+ /**
51
+ * Validation triage for a linked value starting with `preset:`. Bare references
52
+ * stay lenient (a stale key degrades to the fallback at read time), but an
53
+ * explicit alpha suffix requires the key to exist, and a numeric-looking
54
+ * suffix outside the 0-100 grammar is rejected as an attempted alpha rather
55
+ * than silently treated as a key. Pass `hasKey: null` to skip the existence
56
+ * check (no presets available, or the resolver failed).
57
+ */
58
+ const presetReferenceIssue = (value, hasKey) => {
59
+ const parts = presetReferenceParts(value);
60
+ if (!parts) return "missingKey";
61
+ if (!parts.explicit) {
62
+ const slash = parts.key.lastIndexOf("/");
63
+ const tail = slash === -1 ? "" : parts.key.slice(slash + 1);
64
+ if (tail !== "" && ALPHA_LIKE.test(tail)) return "invalidAlpha";
65
+ return null;
66
+ }
67
+ if (hasKey && !hasKey(parts.key)) return "unknownKey";
68
+ return null;
69
+ };
70
+ const applyToCss = (css, alpha, format) => {
71
+ const parsed = parseColor(css);
72
+ if (!parsed) return css;
73
+ const base = Number.isFinite(parsed.alpha) ? parsed.alpha : 1;
74
+ return formatColor({
75
+ ...parsed,
76
+ alpha: base * (alpha / 100)
77
+ }, format);
78
+ };
79
+ /**
80
+ * Applies a reference alpha to a resolved preset value, multiplying into any
81
+ * alpha the color already carries (matching CSS `color-mix` toward
82
+ * transparent). Unparseable members pass through untouched.
83
+ */
84
+ const applyReferenceAlpha = (value, alpha, format) => {
85
+ if (isColorSchemeValue(value)) return {
86
+ dark: applyToCss(value.dark, alpha, format),
87
+ light: applyToCss(value.light, alpha, format)
88
+ };
89
+ return applyToCss(value, alpha, format);
90
+ };
91
+ //#endregion
92
+ export { applyReferenceAlpha, formatPresetReference, parsePresetReference, presetReferenceIssue, presetReferenceParts };
93
+
94
+ //# sourceMappingURL=presetReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presetReference.js","names":[],"sources":["../../../src/fields/color/presetReference.ts"],"sourcesContent":["import type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport { PRESET_PREFIX } from './options'\n\nexport type PresetReference = { alpha: number; key: string }\n\nexport type PresetReferenceParts = PresetReference & { explicit: boolean }\n\nexport type PresetReferenceIssue = 'invalidAlpha' | 'missingKey' | 'unknownKey'\n\nconst ALPHA_SUFFIX = /^(100|[1-9]?[0-9])$/\nconst ALPHA_LIKE = /^[0-9.]+$/\n\n/**\n * Splits a `preset:<key>[/<alpha>]` string into key and alpha, tracking whether\n * the alpha was written out. The suffix is read off the last slash and counts\n * as alpha only when it matches the integer grammar 0-100; anything else stays\n * part of the key, so slash-containing keys keep working.\n */\nexport const presetReferenceParts = (value: string): null | PresetReferenceParts => {\n\tif (!value.startsWith(PRESET_PREFIX)) return null\n\tconst remainder = value.slice(PRESET_PREFIX.length)\n\tif (remainder === '') return null\n\tconst slash = remainder.lastIndexOf('/')\n\tif (slash !== -1 && ALPHA_SUFFIX.test(remainder.slice(slash + 1))) {\n\t\tconst key = remainder.slice(0, slash)\n\t\tif (key === '') return null\n\t\treturn { alpha: Number(remainder.slice(slash + 1)), explicit: true, key }\n\t}\n\treturn { alpha: 100, explicit: false, key: remainder }\n}\n\n/**\n * Client-safe parser for stored preset references. Returns null when the value\n * is not a reference; alpha defaults to 100 when no suffix is present.\n */\nexport const parsePresetReference = (value: string): null | PresetReference => {\n\tconst parts = presetReferenceParts(value)\n\treturn parts ? { alpha: parts.alpha, key: parts.key } : null\n}\n\n/** Canonical stored form: bare reference at alpha 100, `/<alpha>` suffix below. */\nexport const formatPresetReference = (key: string, alpha = 100): string => {\n\tconst bounded = Math.min(100, Math.max(0, Math.round(alpha)))\n\treturn bounded === 100 ? `${PRESET_PREFIX}${key}` : `${PRESET_PREFIX}${key}/${bounded}`\n}\n\n/**\n * Validation triage for a linked value starting with `preset:`. Bare references\n * stay lenient (a stale key degrades to the fallback at read time), but an\n * explicit alpha suffix requires the key to exist, and a numeric-looking\n * suffix outside the 0-100 grammar is rejected as an attempted alpha rather\n * than silently treated as a key. Pass `hasKey: null` to skip the existence\n * check (no presets available, or the resolver failed).\n */\nexport const presetReferenceIssue = (\n\tvalue: string,\n\thasKey: ((key: string) => boolean) | null\n): null | PresetReferenceIssue => {\n\tconst parts = presetReferenceParts(value)\n\tif (!parts) return 'missingKey'\n\tif (!parts.explicit) {\n\t\tconst slash = parts.key.lastIndexOf('/')\n\t\tconst tail = slash === -1 ? '' : parts.key.slice(slash + 1)\n\t\tif (tail !== '' && ALPHA_LIKE.test(tail)) return 'invalidAlpha'\n\t\treturn null\n\t}\n\tif (hasKey && !hasKey(parts.key)) return 'unknownKey'\n\treturn null\n}\n\nconst applyToCss = (css: string, alpha: number, format: ColorFormat): string => {\n\tconst parsed = parseColor(css)\n\tif (!parsed) return css\n\tconst base = Number.isFinite(parsed.alpha) ? parsed.alpha : 1\n\treturn formatColor({ ...parsed, alpha: base * (alpha / 100) }, format)\n}\n\n/**\n * Applies a reference alpha to a resolved preset value, multiplying into any\n * alpha the color already carries (matching CSS `color-mix` toward\n * transparent). Unparseable members pass through untouched.\n */\nexport const applyReferenceAlpha = (\n\tvalue: string | ColorSchemeValue,\n\talpha: number,\n\tformat: ColorFormat\n): string | ColorSchemeValue => {\n\tif (isColorSchemeValue(value)) {\n\t\treturn {\n\t\t\tdark: applyToCss(value.dark, alpha, format),\n\t\t\tlight: applyToCss(value.light, alpha, format),\n\t\t}\n\t}\n\treturn applyToCss(value, alpha, format)\n}\n"],"mappings":";;;;;AAUA,MAAM,eAAe;AACrB,MAAM,aAAa;;;;;;;AAQnB,MAAa,wBAAwB,UAA+C;CACnF,IAAI,CAAC,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC7C,MAAM,YAAY,MAAM,MAAM,cAAc,MAAM;CAClD,IAAI,cAAc,IAAI,OAAO;CAC7B,MAAM,QAAQ,UAAU,YAAY,GAAG;CACvC,IAAI,UAAU,MAAM,aAAa,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC,GAAG;EAClE,MAAM,MAAM,UAAU,MAAM,GAAG,KAAK;EACpC,IAAI,QAAQ,IAAI,OAAO;EACvB,OAAO;GAAE,OAAO,OAAO,UAAU,MAAM,QAAQ,CAAC,CAAC;GAAG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CAC7C;CAED,OAAO,WAAW,OAAO,OAAO,MAAM;AACvC"}
@@ -1,5 +1,6 @@
1
1
  import { keys } from "../../../translations/keys.js";
2
2
  import { PRESET_PREFIX } from "../options.js";
3
+ import { parsePresetReference } from "../presetReference.js";
3
4
  import { swatchBackground } from "../schemeValue.js";
4
5
  import { asTranslate } from "../../../translations/server.js";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -11,7 +12,8 @@ const ColorCell = (props) => {
11
12
  const isPreset = cellData.startsWith(PRESET_PREFIX);
12
13
  const name = "name" in field ? String(field.name) : "";
13
14
  const swatch = swatchBackground(isPreset ? rowData?.[`${name}Resolved`] : cellData);
14
- const label = isPreset ? cellData.slice(PRESET_PREFIX.length) : cellData;
15
+ const ref = isPreset ? parsePresetReference(cellData) : null;
16
+ const label = isPreset ? ref?.key ?? cellData.slice(7) : cellData;
15
17
  return /* @__PURE__ */ jsxs("span", {
16
18
  className: "fields-color-cell",
17
19
  children: [
@@ -21,6 +23,10 @@ const ColorCell = (props) => {
21
23
  children: swatch ? /* @__PURE__ */ jsx("span", { style: { background: swatch } }) : null
22
24
  }),
23
25
  /* @__PURE__ */ jsx("span", { children: label }),
26
+ ref && ref.alpha !== 100 ? /* @__PURE__ */ jsxs("span", {
27
+ className: "fields-color-cell__alpha",
28
+ children: [ref.alpha, "%"]
29
+ }) : null,
24
30
  isPreset && !swatch ? /* @__PURE__ */ jsx("span", {
25
31
  className: "fields-color-cell__missing",
26
32
  children: asTranslate(i18n.t)(keys.missingPreset)
@@ -1 +1 @@
1
- {"version":3,"file":"ColorCell.js","names":[],"sources":["../../../../src/fields/color/server/ColorCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { PRESET_PREFIX } from '../options'\nimport { swatchBackground } from '../schemeValue'\nimport './colorCell.css'\n\nexport const ColorCell = (props: DefaultServerCellComponentProps) => {\n\tconst { cellData, field, i18n, rowData } = props\n\tif (typeof cellData !== 'string' || cellData === '') return null\n\tconst isPreset = cellData.startsWith(PRESET_PREFIX)\n\tconst name = 'name' in field ? String(field.name) : ''\n\tconst resolvedRaw = isPreset\n\t\t? (rowData as Record<string, unknown>)?.[`${name}Resolved`]\n\t\t: cellData\n\tconst swatch = swatchBackground(resolvedRaw)\n\tconst label = isPreset ? cellData.slice(PRESET_PREFIX.length) : cellData\n\treturn (\n\t\t<span className=\"fields-color-cell\">\n\t\t\t<span aria-hidden=\"true\" className=\"fields-color-cell__swatch\">\n\t\t\t\t{swatch ? <span style={{ background: swatch }} /> : null}\n\t\t\t</span>\n\t\t\t<span>{label}</span>\n\t\t\t{isPreset && !swatch ? (\n\t\t\t\t<span className=\"fields-color-cell__missing\">\n\t\t\t\t\t{asTranslate(i18n.t)(keys.missingPreset)}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;AAOA,MAAa,aAAa,UAA2C;CACpE,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY;CAC3C,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,OAAO;CAC5D,MAAM,WAAW,SAAS,WAAW,aAAa;CAClD,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,IAAI,IAAI;CAIpD,MAAM,SAAS,iBAHK,WAChB,UAAsC,GAAG,KAAK,aAC/C,QACwC;CAC3C,MAAM,QAAQ,WAAW,SAAS,MAAM,cAAc,MAAM,IAAI;CAChE,OACC,qBAAC,QAAD;EAAM,WAAU;YAAhB;GACC,oBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;cACjC,SAAS,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,OAAO,EAAI,CAAA,IAAI;GAC/C,CAAA;GACN,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA;GAClB,YAAY,CAAC,SACb,oBAAC,QAAD;IAAM,WAAU;cACd,YAAY,KAAK,CAAC,EAAE,KAAK,aAAa;GAClC,CAAA,IACH;EACC;;AAER"}
1
+ {"version":3,"file":"ColorCell.js","names":[],"sources":["../../../../src/fields/color/server/ColorCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { PRESET_PREFIX } from '../options'\nimport { parsePresetReference } from '../presetReference'\nimport { swatchBackground } from '../schemeValue'\nimport './colorCell.css'\n\nexport const ColorCell = (props: DefaultServerCellComponentProps) => {\n\tconst { cellData, field, i18n, rowData } = props\n\tif (typeof cellData !== 'string' || cellData === '') return null\n\tconst isPreset = cellData.startsWith(PRESET_PREFIX)\n\tconst name = 'name' in field ? String(field.name) : ''\n\t// The resolved sibling already carries the reference alpha, so the swatch\n\t// renders at the stored opacity without reapplying it here\n\tconst resolvedRaw = isPreset\n\t\t? (rowData as Record<string, unknown>)?.[`${name}Resolved`]\n\t\t: cellData\n\tconst swatch = swatchBackground(resolvedRaw)\n\tconst ref = isPreset ? parsePresetReference(cellData) : null\n\tconst label = isPreset ? (ref?.key ?? cellData.slice(PRESET_PREFIX.length)) : cellData\n\treturn (\n\t\t<span className=\"fields-color-cell\">\n\t\t\t<span aria-hidden=\"true\" className=\"fields-color-cell__swatch\">\n\t\t\t\t{swatch ? <span style={{ background: swatch }} /> : null}\n\t\t\t</span>\n\t\t\t<span>{label}</span>\n\t\t\t{ref && ref.alpha !== 100 ? (\n\t\t\t\t<span className=\"fields-color-cell__alpha\">{ref.alpha}%</span>\n\t\t\t) : null}\n\t\t\t{isPreset && !swatch ? (\n\t\t\t\t<span className=\"fields-color-cell__missing\">\n\t\t\t\t\t{asTranslate(i18n.t)(keys.missingPreset)}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,aAAa,UAA2C;CACpE,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY;CAC3C,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,OAAO;CAC5D,MAAM,WAAW,SAAS,WAAW,aAAa;CAClD,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,IAAI,IAAI;CAMpD,MAAM,SAAS,iBAHK,WAChB,UAAsC,GAAG,KAAK,aAC/C,QACwC;CAC3C,MAAM,MAAM,WAAW,qBAAqB,QAAQ,IAAI;CACxD,MAAM,QAAQ,WAAY,KAAK,OAAO,SAAS,MAAA,CAA0B,IAAK;CAC9E,OACC,qBAAC,QAAD;EAAM,WAAU;YAAhB;GACC,oBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;cACjC,SAAS,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,OAAO,EAAI,CAAA,IAAI;GAC/C,CAAA;GACN,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA;GAClB,OAAO,IAAI,UAAU,MACrB,qBAAC,QAAD;IAAM,WAAU;cAAhB,CAA4C,IAAI,OAAM,GAAO;QAC1D;GACH,YAAY,CAAC,SACb,oBAAC,QAAD;IAAM,WAAU;cACd,YAAY,KAAK,CAAC,EAAE,KAAK,aAAa;GAClC,CAAA,IACH;EACC;;AAER"}
@@ -26,6 +26,11 @@
26
26
  display: block;
27
27
  }
28
28
 
29
+ .fields-color-cell__alpha {
30
+ color: var(--theme-elevation-500);
31
+ font-size: 0.75rem;
32
+ }
33
+
29
34
  .fields-color-cell__missing {
30
35
  color: var(--theme-error-500);
31
36
  font-size: 0.75rem;
@@ -0,0 +1,23 @@
1
+ import { parseColor } from "./engine/parse.js";
2
+ import "./options.js";
3
+ import { presetReferenceIssue } from "./presetReference.js";
4
+ //#region src/fields/color/valueIssue.ts
5
+ /**
6
+ * Format-level problem with a stored or typed color value, shared by the form-bound
7
+ * field's validate and the standalone input's own error display. Empty values have
8
+ * no issue here; `required` is the caller's concern.
9
+ */
10
+ const colorValueIssue = (value, args) => {
11
+ if (typeof value !== "string" || value === "") return null;
12
+ const { linked, presets } = args;
13
+ if (linked && value.startsWith("preset:")) {
14
+ const issue = presetReferenceIssue(value, presets.length > 0 ? (key) => presets.some((preset) => preset.key === key) : null);
15
+ if (issue === "invalidAlpha") return "invalidColor";
16
+ return issue === null ? null : "missingPreset";
17
+ }
18
+ return parseColor(value) ? null : "invalidColor";
19
+ };
20
+ //#endregion
21
+ export { colorValueIssue };
22
+
23
+ //# sourceMappingURL=valueIssue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valueIssue.js","names":[],"sources":["../../../src/fields/color/valueIssue.ts"],"sourcesContent":["import { parseColor } from './engine'\nimport { PRESET_PREFIX, type ResolvedColorPreset } from './options'\nimport { presetReferenceIssue } from './presetReference'\n\nexport type ColorValueIssue = 'invalidColor' | 'missingPreset'\n\n/**\n * Format-level problem with a stored or typed color value, shared by the form-bound\n * field's validate and the standalone input's own error display. Empty values have\n * no issue here; `required` is the caller's concern.\n */\nexport const colorValueIssue = (\n\tvalue: unknown,\n\targs: { linked: boolean; presets: readonly ResolvedColorPreset[] }\n): ColorValueIssue | null => {\n\tif (typeof value !== 'string' || value === '') return null\n\tconst { linked, presets } = args\n\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\tconst hasKey =\n\t\t\tpresets.length > 0 ? (key: string) => presets.some((preset) => preset.key === key) : null\n\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\tif (issue === 'invalidAlpha') return 'invalidColor'\n\t\treturn issue === null ? null : 'missingPreset'\n\t}\n\treturn parseColor(value) ? null : 'invalidColor'\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,mBACZ,OACA,SAC4B;CAC5B,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,MAAM,EAAE,QAAQ,YAAY;CAC5B,IAAI,UAAU,MAAM,WAAA,SAAwB,GAAG;EAG9C,MAAM,QAAQ,qBAAqB,OADlC,QAAQ,SAAS,KAAK,QAAgB,QAAQ,MAAM,WAAW,OAAO,QAAQ,GAAG,IAAI,IACtC;EAChD,IAAI,UAAU,gBAAgB,OAAO;EACrC,OAAO,UAAU,OAAO,OAAO;CAChC;CACA,OAAO,WAAW,KAAK,IAAI,OAAO;AACnC"}
@@ -11,7 +11,8 @@ const validateEncryptedBoot = async (payload, pluginKeys) => {
11
11
  const configs = /* @__PURE__ */ new Set();
12
12
  if (pluginKeys) configs.add(pluginKeys);
13
13
  let usesDefault = false;
14
- for (const collection of payload.config.collections) for (const [, marker] of scanEncryptedFields(collection.fields)) if (marker.keys) configs.add(marker.keys);
14
+ const fieldSets = [...payload.config.collections.map((collection) => collection.fields), ...payload.config.globals.map((global) => global.fields)];
15
+ for (const fields of fieldSets) for (const [, marker] of scanEncryptedFields(fields)) if (marker.keys) configs.add(marker.keys);
15
16
  else if (!pluginKeys) usesDefault = true;
16
17
  await Promise.all([...configs].map((config) => resolveKeys(config, payload.config.secret)));
17
18
  if (usesDefault) await resolveKeys(void 0, payload.config.secret);
@@ -1 +1 @@
1
- {"version":3,"file":"boot.js","names":[],"sources":["../../../src/fields/encrypted/boot.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { resolveKeys } from './crypto/keys'\nimport { scanEncryptedFields } from './scan'\n\n/**\n * Fail-fast key validation at boot: resolves every distinct KeysConfig used by\n * encrypted fields (plus the default ring when any field falls back to it) so\n * missing secrets, broken providers, and empty material surface as startup\n * errors, not as runtime surprises on first write.\n */\nexport const validateEncryptedBoot = async (\n\tpayload: Payload,\n\tpluginKeys?: Parameters<typeof resolveKeys>[0]\n): Promise<void> => {\n\tconst configs = new Set<NonNullable<Parameters<typeof resolveKeys>[0]>>()\n\tif (pluginKeys) {\n\t\tconfigs.add(pluginKeys)\n\t}\n\t// The default ring is only reached when a field has no per-field keys AND the\n\t// plugin declared no keys; ringForRequest resolves marker.keys ?? pluginKeys\n\t// and falls back to the secret-derived ring only when both are absent.\n\tlet usesDefault = false\n\tfor (const collection of payload.config.collections) {\n\t\tfor (const [, marker] of scanEncryptedFields(collection.fields)) {\n\t\t\tif (marker.keys) {\n\t\t\t\tconfigs.add(marker.keys)\n\t\t\t} else if (!pluginKeys) {\n\t\t\t\tusesDefault = true\n\t\t\t}\n\t\t}\n\t}\n\tawait Promise.all([...configs].map((config) => resolveKeys(config, payload.config.secret)))\n\tif (usesDefault) {\n\t\tawait resolveKeys(undefined, payload.config.secret)\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,wBAAwB,OACpC,SACA,eACmB;CACnB,MAAM,0BAAU,IAAI,IAAoD;CACxE,IAAI,YACH,QAAQ,IAAI,UAAU;CAKvB,IAAI,cAAc;CAClB,KAAK,MAAM,cAAc,QAAQ,OAAO,aACvC,KAAK,MAAM,GAAG,WAAW,oBAAoB,WAAW,MAAM,GAC7D,IAAI,OAAO,MACV,QAAQ,IAAI,OAAO,IAAI;MACjB,IAAI,CAAC,YACX,cAAc;CAIjB,MAAM,QAAQ,IAAI,CAAC,GAAG,OAAO,EAAE,KAAK,WAAW,YAAY,QAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC;CAC1F,IAAI,aACH,MAAM,YAAY,KAAA,GAAW,QAAQ,OAAO,MAAM;AAEpD"}
1
+ {"version":3,"file":"boot.js","names":[],"sources":["../../../src/fields/encrypted/boot.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport { resolveKeys } from './crypto/keys'\nimport { scanEncryptedFields } from './scan'\n\n/**\n * Fail-fast key validation at boot: resolves every distinct KeysConfig used by\n * encrypted fields (plus the default ring when any field falls back to it) so\n * missing secrets, broken providers, and empty material surface as startup\n * errors, not as runtime surprises on first write.\n */\nexport const validateEncryptedBoot = async (\n\tpayload: Payload,\n\tpluginKeys?: Parameters<typeof resolveKeys>[0]\n): Promise<void> => {\n\tconst configs = new Set<NonNullable<Parameters<typeof resolveKeys>[0]>>()\n\tif (pluginKeys) {\n\t\tconfigs.add(pluginKeys)\n\t}\n\t// The default ring is only reached when a field has no per-field keys AND the\n\t// plugin declared no keys; ringForRequest resolves marker.keys ?? pluginKeys\n\t// and falls back to the secret-derived ring only when both are absent.\n\tlet usesDefault = false\n\tconst fieldSets = [\n\t\t...payload.config.collections.map((collection) => collection.fields),\n\t\t...payload.config.globals.map((global) => global.fields),\n\t]\n\tfor (const fields of fieldSets) {\n\t\tfor (const [, marker] of scanEncryptedFields(fields)) {\n\t\t\tif (marker.keys) {\n\t\t\t\tconfigs.add(marker.keys)\n\t\t\t} else if (!pluginKeys) {\n\t\t\t\tusesDefault = true\n\t\t\t}\n\t\t}\n\t}\n\tawait Promise.all([...configs].map((config) => resolveKeys(config, payload.config.secret)))\n\tif (usesDefault) {\n\t\tawait resolveKeys(undefined, payload.config.secret)\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,wBAAwB,OACpC,SACA,eACmB;CACnB,MAAM,0BAAU,IAAI,IAAoD;CACxE,IAAI,YACH,QAAQ,IAAI,UAAU;CAKvB,IAAI,cAAc;CAClB,MAAM,YAAY,CACjB,GAAG,QAAQ,OAAO,YAAY,KAAK,eAAe,WAAW,MAAM,GACnE,GAAG,QAAQ,OAAO,QAAQ,KAAK,WAAW,OAAO,MAAM,CACxD;CACA,KAAK,MAAM,UAAU,WACpB,KAAK,MAAM,GAAG,WAAW,oBAAoB,MAAM,GAClD,IAAI,OAAO,MACV,QAAQ,IAAI,OAAO,IAAI;MACjB,IAAI,CAAC,YACX,cAAc;CAIjB,MAAM,QAAQ,IAAI,CAAC,GAAG,OAAO,EAAE,KAAK,WAAW,YAAY,QAAQ,QAAQ,OAAO,MAAM,CAAC,CAAC;CAC1F,IAAI,aACH,MAAM,YAAY,KAAA,GAAW,QAAQ,OAAO,MAAM;AAEpD"}
@@ -2,7 +2,8 @@
2
2
  import { EyeToggle } from "./EyeToggle.js";
3
3
  import { dotString } from "./MaskDots.js";
4
4
  import { FieldDescription, FieldError, FieldLabel, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
5
- import { useCallback, useState } from "react";
5
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
6
+ import { useCallback, useMemo, useState } from "react";
6
7
  import { jsx, jsxs } from "react/jsx-runtime";
7
8
  //#region src/fields/encrypted/components/EncryptedInput.tsx
8
9
  /**
@@ -33,6 +34,7 @@ const EncryptedInput = ({ field, kind, maskDots, path }) => {
33
34
  setValue(event.target.value);
34
35
  };
35
36
  const revealedValue = isNumber ? typeof value === "number" ? value : "" : typeof value === "string" ? value : "";
37
+ const styles = useMemo(() => mergeFieldStyles(field), [field]);
36
38
  return /* @__PURE__ */ jsxs("div", {
37
39
  className: [
38
40
  "field-type",
@@ -41,6 +43,7 @@ const EncryptedInput = ({ field, kind, maskDots, path }) => {
41
43
  "tenx-protected-field",
42
44
  "tenx-protected-field--attached"
43
45
  ].filter(Boolean).join(" "),
46
+ style: styles,
44
47
  children: [/* @__PURE__ */ jsx(FieldLabel, {
45
48
  label: field.label,
46
49
  localized: field.localized,
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptedInput.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport type React from 'react'\nimport { useCallback, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ntype InputKind = 'email' | 'number' | 'text'\n\ninterface EncryptedInputProps {\n\tfield: EncryptedFieldConfig\n\tkind: InputKind\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * Attached-placement field for single text, email, and number. One input is\n * mounted in both states and only morphs on toggle: a readOnly dots facsimile\n * while concealed, the bound editable input while revealed. Reusing the same\n * element means revealing never remounts the control and never shifts layout.\n * Concealed, the input is readOnly and its value is the dot run, so the decrypted\n * plaintext (already in form state from afterRead) never reaches the DOM and\n * masking cannot mutate form state; setValue only runs while revealed. The eye is\n * a sibling flex segment that stays put across toggles.\n */\nexport const EncryptedInput: React.FC<EncryptedInputProps> = ({ field, kind, maskDots, path }) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst { setValue, showError, value } = useField<number | string>({ path })\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showFieldError = submitted && invalid\n\tconst toggle = useCallback(() => setRevealed((prev) => !prev), [])\n\tconst inputId = `field-${path.replace(/\\./g, '__')}`\n\tconst isNumber = kind === 'number'\n\n\tconst handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\tif (isNumber) {\n\t\t\tconst parsed = Number.parseFloat(event.target.value)\n\t\t\tsetValue(Number.isNaN(parsed) ? null : parsed)\n\t\t\treturn\n\t\t}\n\t\tsetValue(event.target.value)\n\t}\n\n\tconst revealedValue = isNumber\n\t\t? typeof value === 'number'\n\t\t\t? value\n\t\t\t: ''\n\t\t: typeof value === 'string'\n\t\t\t? value\n\t\t\t: ''\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\tkind,\n\t\t\t\tshowFieldError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\t'tenx-protected-field--attached',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\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<div className=\"tenx-protected-field__attached-row\">\n\t\t\t\t\t<input\n\t\t\t\t\t\taria-invalid={revealed ? showError : undefined}\n\t\t\t\t\t\tautoComplete={revealed && !isNumber ? field.admin?.autoComplete : undefined}\n\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\trevealed\n\t\t\t\t\t\t\t\t? 'tenx-protected-field__revealed-input'\n\t\t\t\t\t\t\t\t: 'tenx-protected-field__masked-input'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\tinputMode={revealed && isNumber ? 'decimal' : undefined}\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonChange={revealed ? handleChange : undefined}\n\t\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t\trevealed && !isNumber && typeof field.admin?.placeholder === 'string'\n\t\t\t\t\t\t\t\t? field.admin.placeholder\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treadOnly={!revealed}\n\t\t\t\t\t\tstep={revealed && isNumber ? field.admin?.step : undefined}\n\t\t\t\t\t\ttabIndex={revealed ? undefined : -1}\n\t\t\t\t\t\ttype={revealed ? (isNumber ? 'number' : kind === 'email' ? 'email' : 'text') : 'text'}\n\t\t\t\t\t\tvalue={revealed ? revealedValue : dotString(maskDots)}\n\t\t\t\t\t/>\n\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<EyeToggle\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--attached\"\n\t\t\t\t\t\t\tonToggle={toggle}\n\t\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\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"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,MAAa,kBAAiD,EAAE,OAAO,MAAM,UAAU,WAAW;CACjG,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,EAAE,UAAU,WAAW,UAAU,SAA0B,EAAE,KAAK,CAAC;CACzE,MAAM,YAAY,iBAAiB;CACnC,MAAM,UAAU,eAAe,CAAC,YAAY,SAAS,OAAO,UAAU,KAAK;CAC3E,MAAM,iBAAiB,aAAa;CACpC,MAAM,SAAS,kBAAkB,aAAa,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;CACjE,MAAM,UAAU,SAAS,KAAK,QAAQ,OAAO,IAA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KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
1
+ {"version":3,"file":"EncryptedInput.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useCallback, useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ntype InputKind = 'email' | 'number' | 'text'\n\ninterface EncryptedInputProps {\n\tfield: EncryptedFieldConfig\n\tkind: InputKind\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * Attached-placement field for single text, email, and number. One input is\n * mounted in both states and only morphs on toggle: a readOnly dots facsimile\n * while concealed, the bound editable input while revealed. Reusing the same\n * element means revealing never remounts the control and never shifts layout.\n * Concealed, the input is readOnly and its value is the dot run, so the decrypted\n * plaintext (already in form state from afterRead) never reaches the DOM and\n * masking cannot mutate form state; setValue only runs while revealed. The eye is\n * a sibling flex segment that stays put across toggles.\n */\nexport const EncryptedInput: React.FC<EncryptedInputProps> = ({ field, kind, maskDots, path }) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst { setValue, showError, value } = useField<number | string>({ path })\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showFieldError = submitted && invalid\n\tconst toggle = useCallback(() => setRevealed((prev) => !prev), [])\n\tconst inputId = `field-${path.replace(/\\./g, '__')}`\n\tconst isNumber = kind === 'number'\n\n\tconst handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\tif (isNumber) {\n\t\t\tconst parsed = Number.parseFloat(event.target.value)\n\t\t\tsetValue(Number.isNaN(parsed) ? null : parsed)\n\t\t\treturn\n\t\t}\n\t\tsetValue(event.target.value)\n\t}\n\n\tconst revealedValue = isNumber\n\t\t? typeof value === 'number'\n\t\t\t? value\n\t\t\t: ''\n\t\t: typeof value === 'string'\n\t\t\t? value\n\t\t\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\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\tkind,\n\t\t\t\tshowFieldError && 'error',\n\t\t\t\t'tenx-protected-field',\n\t\t\t\t'tenx-protected-field--attached',\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<div className=\"tenx-protected-field__attached-row\">\n\t\t\t\t\t<input\n\t\t\t\t\t\taria-invalid={revealed ? showError : undefined}\n\t\t\t\t\t\tautoComplete={revealed && !isNumber ? field.admin?.autoComplete : undefined}\n\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\trevealed\n\t\t\t\t\t\t\t\t? 'tenx-protected-field__revealed-input'\n\t\t\t\t\t\t\t\t: 'tenx-protected-field__masked-input'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\tinputMode={revealed && isNumber ? 'decimal' : undefined}\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonChange={revealed ? handleChange : undefined}\n\t\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t\trevealed && !isNumber && typeof field.admin?.placeholder === 'string'\n\t\t\t\t\t\t\t\t? field.admin.placeholder\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treadOnly={!revealed}\n\t\t\t\t\t\tstep={revealed && isNumber ? field.admin?.step : undefined}\n\t\t\t\t\t\ttabIndex={revealed ? undefined : -1}\n\t\t\t\t\t\ttype={revealed ? (isNumber ? 'number' : kind === 'email' ? 'email' : 'text') : 'text'}\n\t\t\t\t\t\tvalue={revealed ? revealedValue : dotString(maskDots)}\n\t\t\t\t\t/>\n\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<EyeToggle\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--attached\"\n\t\t\t\t\t\t\tonToggle={toggle}\n\t\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\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"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,MAAa,kBAAiD,EAAE,OAAO,MAAM,UAAU,WAAW;CACjG,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,EAAE,UAAU,WAAW,UAAU,SAA0B,EAAE,KAAK,CAAC;CACzE,MAAM,YAAY,iBAAiB;CACnC,MAAM,UAAU,eAAe,CAAC,YAAY,SAAS,OAAO,UAAU,KAAK;CAC3E,MAAM,iBAAiB,aAAa;CACpC,MAAM,SAAS,kBAAkB,aAAa,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;CACjE,MAAM,UAAU,SAAS,KAAK,QAAQ,OAAO,IAAI;CACjD,MAAM,WAAW,SAAS;CAE1B,MAAM,gBAAgB,UAA+C;EACpE,IAAI,UAAU;GACb,MAAM,SAAS,OAAO,WAAW,MAAM,OAAO,KAAK;GACnD,SAAS,OAAO,MAAM,MAAM,IAAI,OAAO,MAAM;GAC7C;EACD;EACA,SAAS,MAAM,OAAO,KAAK;CAC5B;CAEA,MAAM,gBAAgB,WACnB,OAAO,UAAU,WAChB,QACA,KACD,OAAO,UAAU,WAChB,QACA;CAIJ,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,qBAAC,OAAD;EACC,WAAW;GACV;GACA;GACA,kBAAkB;GAClB;GACA;EACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;EACV,OAAO;YAVR,CAYC,oBAAC,YAAD;GACC,OAAO,MAAM;GACb,WAAW,MAAM;GACX;GACN,UAAU,MAAM;EAChB,CAAA,GACD,qBAAC,OAAD;GAAK,WAAU;aAAf;IACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;IACzB,qBAAC,OAAD;KAAK,WAAU;eAAf,CACC,oBAAC,SAAD;MACC,gBAAc,WAAW,YAAY,KAAA;MACrC,cAAc,YAAY,CAAC,WAAW,MAAM,OAAO,eAAe,KAAA;MAClE,WACC,WACG,yCACA;MAEJ,IAAI;MACJ,WAAW,YAAY,WAAW,YAAY,KAAA;MAC9C,MAAM;MACN,UAAU,WAAW,eAAe,KAAA;MACpC,aACC,YAAY,CAAC,YAAY,OAAO,MAAM,OAAO,gBAAgB,WAC1D,MAAM,MAAM,cACZ,KAAA;MAEJ,UAAU,CAAC;MACX,MAAM,YAAY,WAAW,MAAM,OAAO,OAAO,KAAA;MACjD,UAAU,WAAW,KAAA,IAAY;MACjC,MAAM,WAAY,WAAW,WAAW,SAAS,UAAU,UAAU,SAAU;MAC/E,OAAO,WAAW,gBAAgB,UAAU,QAAQ;KACpD,CAAA,GACD,oBAAC,OAAD;MAAK,WAAU;gBACd,oBAAC,WAAD;OACC,WAAU;OACV,UAAU;OACA;MACV,CAAA;KACG,CAAA,CACD;;IACL,oBAAC,kBAAD;KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
@@ -2,7 +2,8 @@
2
2
  import { EyeToggle } from "./EyeToggle.js";
3
3
  import { dotString } from "./MaskDots.js";
4
4
  import { FieldDescription, FieldError, FieldLabel, useField, useFormFields, useFormSubmitted } from "@payloadcms/ui";
5
- import { useState } from "react";
5
+ import { mergeFieldStyles } from "@payloadcms/ui/shared";
6
+ import { useMemo, useState } from "react";
6
7
  import { jsx, jsxs } from "react/jsx-runtime";
7
8
  //#region src/fields/encrypted/components/EncryptedTextarea.tsx
8
9
  /**
@@ -34,14 +35,17 @@ const EncryptedTextarea = ({ field, maskDots, path }) => {
34
35
  const [revealed, setRevealed] = useState(false);
35
36
  const submitted = useFormSubmitted();
36
37
  const invalid = useFormFields(([fields]) => fields?.[path]?.valid === false);
38
+ const showError = submitted && invalid;
39
+ const styles = useMemo(() => mergeFieldStyles(field), [field]);
37
40
  return /* @__PURE__ */ jsxs("div", {
38
41
  className: [
39
42
  "field-type",
40
43
  "textarea",
41
- submitted && invalid && "error",
44
+ showError && "error",
42
45
  "tenx-protected-field",
43
46
  "tenx-protected-field--corner"
44
47
  ].filter(Boolean).join(" "),
48
+ style: styles,
45
49
  children: [/* @__PURE__ */ jsx(FieldLabel, {
46
50
  label: field.label,
47
51
  localized: field.localized,
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptedTextarea.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedTextarea.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport type React from 'react'\nimport { useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ninterface EncryptedTextareaProps {\n\tfield: EncryptedFieldConfig\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * The revealed, bound textarea. The only part that calls `useField`; the\n * concealed state renders a readOnly dots textarea instead, so masking cannot\n * write form state. Validation stays server-side.\n */\nconst BoundTextarea: React.FC<{ field: EncryptedFieldConfig; path: string }> = ({\n\tfield,\n\tpath,\n}) => {\n\tconst { setValue, value } = useField<string>({ path })\n\treturn (\n\t\t<div className=\"textarea-outer\">\n\t\t\t<textarea\n\t\t\t\tclassName=\"tenx-protected-field__revealed-textarea\"\n\t\t\t\tid={`field-${path.replace(/\\./g, '__')}`}\n\t\t\t\tname={path}\n\t\t\t\tonChange={(event) => setValue(event.target.value)}\n\t\t\t\trows={field.admin?.rows}\n\t\t\t\tvalue={typeof value === 'string' ? value : ''}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n\n/**\n * Corner-placement wrapper for textarea. Renders the stable native chrome with\n * the eye pinned to the top-right corner of the field wrap; only the textarea\n * swaps between the concealed dots facsimile and the bound textarea. The wrapper\n * only reads form state (no `useField`, no `setValue`).\n */\nexport const EncryptedTextarea: React.FC<EncryptedTextareaProps> = ({ field, maskDots, path }) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showError = submitted && invalid\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\t'textarea',\n\t\t\t\tshowError && 'error',\n\t\t\t\t'tenx-protected-field',\n\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>\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{revealed ? (\n\t\t\t\t\t<BoundTextarea field={field} path={path} />\n\t\t\t\t) : (\n\t\t\t\t\t<div className=\"textarea-outer\">\n\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__masked-textarea\"\n\t\t\t\t\t\t\treadOnly\n\t\t\t\t\t\t\trows={field.admin?.rows}\n\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\tvalue={dotString(maskDots)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner\">\n\t\t\t\t\t<EyeToggle\n\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--floating\"\n\t\t\t\t\t\tonToggle={() => setRevealed((prev) => !prev)}\n\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t/>\n\t\t\t\t</div>\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"],"mappings":";;;;;;;;;;;;AA0BA,MAAM,iBAA0E,EAC/E,OACA,WACK;CACL,MAAM,EAAE,UAAU,UAAU,SAAiB,EAAE,KAAK,CAAC;CACrD,OACC,oBAAC,OAAD;EAAK,WAAU;YACd,oBAAC,YAAD;GACC,WAAU;GACV,IAAI,SAAS,KAAK,QAAQ,OAAO,IAAI;GACrC,MAAM;GACN,WAAW,UAAU,SAAS,MAAM,OAAO,KAAK;GAChD,MAAM,MAAM,OAAO;GACnB,OAAO,OAAO,UAAU,WAAW,QAAQ;EAC3C,CAAA;CACG,CAAA;AAEP;;;;;;;AAQA,MAAa,qBAAuD,EAAE,OAAO,UAAU,WAAW;CACjG,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,YAAY,iBAAiB;CACnC,MAAM,UAAU,eAAe,CAAC,YAAY,SAAS,OAAO,UAAU,KAAK;CAE3E,OACC,qBAAC,OAAD;EACC,WAAW;GACV;GACA;GALe,aAAa,WAMf;GACb;GACA;EACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;YATX,CAWC,oBAAC,YAAD;GACC,OAAO,MAAM;GACb,WAAW,MAAM;GACX;GACN,UAAU,MAAM;EAChB,CAAA,GACD,qBAAC,OAAD;GAAK,WAAU;aAAf;IACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;IACxB,WACA,oBAAC,eAAD;KAAsB;KAAa;IAAO,CAAA,IAE1C,oBAAC,OAAD;KAAK,WAAU;eACd,oBAAC,YAAD;MACC,WAAU;MACV,UAAA;MACA,MAAM,MAAM,OAAO;MACnB,UAAU;MACV,OAAO,UAAU,QAAQ;KACzB,CAAA;IACG,CAAA;IAEN,oBAAC,OAAD;KAAK,WAAU;eACd,oBAAC,WAAD;MACC,WAAU;MACV,gBAAgB,aAAa,SAAS,CAAC,IAAI;MACjC;KACV,CAAA;IACG,CAAA;IACL,oBAAC,kBAAD;KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
1
+ {"version":3,"file":"EncryptedTextarea.js","names":[],"sources":["../../../../src/fields/encrypted/components/EncryptedTextarea.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tuseField,\n\tuseFormFields,\n\tuseFormSubmitted,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type React from 'react'\nimport { useMemo, useState } from 'react'\nimport { EyeToggle } from './EyeToggle'\nimport { dotString } from './MaskDots'\nimport type { EncryptedFieldConfig } from './placement'\n\ninterface EncryptedTextareaProps {\n\tfield: EncryptedFieldConfig\n\tmaskDots: number\n\tpath: string\n}\n\n/**\n * The revealed, bound textarea. The only part that calls `useField`; the\n * concealed state renders a readOnly dots textarea instead, so masking cannot\n * write form state. Validation stays server-side.\n */\nconst BoundTextarea: React.FC<{ field: EncryptedFieldConfig; path: string }> = ({\n\tfield,\n\tpath,\n}) => {\n\tconst { setValue, value } = useField<string>({ path })\n\treturn (\n\t\t<div className=\"textarea-outer\">\n\t\t\t<textarea\n\t\t\t\tclassName=\"tenx-protected-field__revealed-textarea\"\n\t\t\t\tid={`field-${path.replace(/\\./g, '__')}`}\n\t\t\t\tname={path}\n\t\t\t\tonChange={(event) => setValue(event.target.value)}\n\t\t\t\trows={field.admin?.rows}\n\t\t\t\tvalue={typeof value === 'string' ? value : ''}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n\n/**\n * Corner-placement wrapper for textarea. Renders the stable native chrome with\n * the eye pinned to the top-right corner of the field wrap; only the textarea\n * swaps between the concealed dots facsimile and the bound textarea. The wrapper\n * only reads form state (no `useField`, no `setValue`).\n */\nexport const EncryptedTextarea: React.FC<EncryptedTextareaProps> = ({ field, maskDots, path }) => {\n\tconst [revealed, setRevealed] = useState(false)\n\tconst submitted = useFormSubmitted()\n\tconst invalid = useFormFields(([fields]) => fields?.[path]?.valid === false)\n\tconst showError = submitted && invalid\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\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\t'field-type',\n\t\t\t\t'textarea',\n\t\t\t\tshowError && 'error',\n\t\t\t\t'tenx-protected-field',\n\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{revealed ? (\n\t\t\t\t\t<BoundTextarea field={field} path={path} />\n\t\t\t\t) : (\n\t\t\t\t\t<div className=\"textarea-outer\">\n\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\tclassName=\"tenx-protected-field__masked-textarea\"\n\t\t\t\t\t\t\treadOnly\n\t\t\t\t\t\t\trows={field.admin?.rows}\n\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\tvalue={dotString(maskDots)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<div className=\"tenx-protected-field__eye-wrap tenx-protected-field__eye-wrap--corner\">\n\t\t\t\t\t<EyeToggle\n\t\t\t\t\t\tclassName=\"tenx-protected-field__eye--floating\"\n\t\t\t\t\t\tonToggle={() => setRevealed((prev) => !prev)}\n\t\t\t\t\t\trevealed={revealed}\n\t\t\t\t\t/>\n\t\t\t\t</div>\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"],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,iBAA0E,EAC/E,OACA,WACK;CACL,MAAM,EAAE,UAAU,UAAU,SAAiB,EAAE,KAAK,CAAC;CACrD,OACC,oBAAC,OAAD;EAAK,WAAU;YACd,oBAAC,YAAD;GACC,WAAU;GACV,IAAI,SAAS,KAAK,QAAQ,OAAO,IAAI;GACrC,MAAM;GACN,WAAW,UAAU,SAAS,MAAM,OAAO,KAAK;GAChD,MAAM,MAAM,OAAO;GACnB,OAAO,OAAO,UAAU,WAAW,QAAQ;EAC3C,CAAA;CACG,CAAA;AAEP;;;;;;;AAQA,MAAa,qBAAuD,EAAE,OAAO,UAAU,WAAW;CACjG,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,YAAY,iBAAiB;CACnC,MAAM,UAAU,eAAe,CAAC,YAAY,SAAS,OAAO,UAAU,KAAK;CAC3E,MAAM,YAAY,aAAa;CAG/B,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,qBAAC,OAAD;EACC,WAAW;GACV;GACA;GACA,aAAa;GACb;GACA;EACD,EACE,OAAO,OAAO,EACd,KAAK,GAAG;EACV,OAAO;YAVR,CAYC,oBAAC,YAAD;GACC,OAAO,MAAM;GACb,WAAW,MAAM;GACX;GACN,UAAU,MAAM;EAChB,CAAA,GACD,qBAAC,OAAD;GAAK,WAAU;aAAf;IACC,oBAAC,YAAD,EAAkB,KAAO,CAAA;IACxB,WACA,oBAAC,eAAD;KAAsB;KAAa;IAAO,CAAA,IAE1C,oBAAC,OAAD;KAAK,WAAU;eACd,oBAAC,YAAD;MACC,WAAU;MACV,UAAA;MACA,MAAM,MAAM,OAAO;MACnB,UAAU;MACV,OAAO,UAAU,QAAQ;KACzB,CAAA;IACG,CAAA;IAEN,oBAAC,OAAD;KAAK,WAAU;eACd,oBAAC,WAAD;MACC,WAAU;MACV,gBAAgB,aAAa,SAAS,CAAC,IAAI;MACjC;KACV,CAAA;IACG,CAAA;IACL,oBAAC,kBAAD;KAAkB,aAAa,MAAM,OAAO;KAAmB;IAAO,CAAA;GAClE;IACD;;AAEP"}
@@ -2,17 +2,26 @@ import { DefaultServerCellComponentProps } from "payload";
2
2
 
3
3
  //#region src/fields/encrypted/components/ProtectedCell.d.ts
4
4
  /**
5
- * List cell for masked encrypted fields. Never renders cellData: list data has
6
- * been decrypted by afterRead, and the list surface must not leak it. Server
7
- * cell, so it translates the accessible label per the admin's locale. The dot
8
- * count mirrors the field's `maskDots` (forwarded via clientProps) for list
9
- * consistency, defaulting to the same 8 as the field.
5
+ * List cell for masked and write-only encrypted fields. Never renders cellData:
6
+ * list data has been decrypted by afterRead (masked) or stripped (write-only),
7
+ * and the list surface must not leak it. Server cell, so it translates the
8
+ * accessible label per the admin's locale. The dot count mirrors the field's
9
+ * `maskDots` (forwarded via clientProps) for list consistency, defaulting to
10
+ * the same 8 as the field. `setName` (write-only fields) points at the virtual
11
+ * set-indicator sibling in rowData; an unset secret renders an em dash instead
12
+ * of dots that would imply a stored value. `hintName` points at the stored
13
+ * identification hint, which replaces the dots when present.
10
14
  */
11
15
  declare const ProtectedCell: ({
16
+ hintName,
12
17
  i18n,
13
- maskDots
18
+ maskDots,
19
+ rowData,
20
+ setName
14
21
  }: DefaultServerCellComponentProps & {
22
+ hintName?: string;
15
23
  maskDots?: number;
24
+ setName?: string;
16
25
  }) => import("react/jsx-runtime").JSX.Element;
17
26
  //#endregion
18
27
  export { ProtectedCell };