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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @10x-media/fields
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ ### Patch Changes
6
+
7
+ - `colorField` no longer overflows its input border when squeezed by `admin.width` in a row. The chip, text entry, and format badge now live in a clipping region that fades out at the right edge when (and only when) the run actually overflows, and the clear control keeps its place inside the border at every width. The fade is a CSS mask rather than a background-colored overlay, so it renders correctly over the error, read-only, and hover backgrounds in both themes.
8
+
9
+ ## 0.1.0-beta.3
10
+
11
+ ### Minor Changes
12
+
13
+ - Linked color references carry opacity: `preset:<key>/<alpha>` stores a preset reference at 0-100 percent, and the picker's alpha slider rewrites the suffix instead of flattening the reference to a concrete color. Resolution applies the alpha in the field's configured format on both scheme members, the chip and list cell surface the percentage, `alpha: false` strips suffixes on commit, and the new `parsePresetReference` export (`/color` and `/color/utils`) parses stored references for presentation code.
14
+
3
15
  ## 0.1.0-beta.2
4
16
 
5
17
  ### Patch Changes
@@ -1,4 +1,5 @@
1
1
  import { ColorFormat, ColorSchemeValue } from "../types.js";
2
+ import { PresetReference, parsePresetReference } from "../fields/color/presetReference.js";
2
3
  import { FormatColorOptions, Hsl, Hsv, OklchColor, ParsedColor, RgbColor } from "../fields/color/engine/types.js";
3
4
  import { contrastRatio, relativeLuminance } from "../fields/color/engine/contrast.js";
4
5
  import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb } from "../fields/color/engine/convert.js";
@@ -7,4 +8,4 @@ import { namedColors } from "../fields/color/engine/namedColors.js";
7
8
  import { parseColor } from "../fields/color/engine/parse.js";
8
9
  import { salvageColor } from "../fields/color/engine/salvage.js";
9
10
  import { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
10
- export { type ColorFormat, type ColorSchemeValue, type FormatColorOptions, type Hsl, type Hsv, type OklchColor, type ParsedColor, type RgbColor, contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isColorSchemeValue, isInSrgbGamut, lightDark, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
11
+ export { type ColorFormat, type ColorSchemeValue, type FormatColorOptions, type Hsl, type Hsv, type OklchColor, type ParsedColor, type PresetReference, type RgbColor, contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isColorSchemeValue, isInSrgbGamut, lightDark, namedColors, oklchToRgb, parseColor, parsePresetReference, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
@@ -5,4 +5,5 @@ import { contrastRatio, relativeLuminance } from "../fields/color/engine/contras
5
5
  import { convertColor, formatColor } from "../fields/color/engine/format.js";
6
6
  import { salvageColor } from "../fields/color/engine/salvage.js";
7
7
  import { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
8
- export { contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isColorSchemeValue, isInSrgbGamut, lightDark, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
8
+ import { parsePresetReference } from "../fields/color/presetReference.js";
9
+ export { contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isColorSchemeValue, isInSrgbGamut, lightDark, namedColors, oklchToRgb, parseColor, parsePresetReference, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
@@ -1,8 +1,9 @@
1
1
  import { ColorFormat, ColorGlobalConfig, ColorPreset, ColorSchemeValue } from "../types.js";
2
2
  import { COLOR_CUSTOM_KEY, ColorFieldClientOptions, ColorFieldOptions, ColorLinkedOptions, ColorPresetsResolver, ColorPresetsSource, PRESET_PREFIX, ResolvedColorPreset } from "../fields/color/options.js";
3
+ import { PresetReference, parsePresetReference } from "../fields/color/presetReference.js";
3
4
  import { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
4
5
  import { colorField } from "../fields/color/colorField.js";
5
6
  import { PresetsFromArrayArgs, presetsFromArray } from "../fields/color/presetsFromArray.js";
6
7
  import { PresetsFromDocArgs, presetsFromDoc } from "../fields/color/presetsFromDoc.js";
7
8
  import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
8
- export { COLOR_CUSTOM_KEY, type ColorFieldClientOptions, type ColorFieldOptions, type ColorFormat, type ColorGlobalConfig, type ColorLinkedOptions, type ColorPreset, type ColorPresetsResolver, type ColorPresetsSource, type ColorSchemeValue, PRESET_PREFIX, type PresetsFromArrayArgs, type PresetsFromDocArgs, type ResolvedColorPreset, colorField, isColorSchemeValue, lightDark, normalizePresets, presetsFromArray, presetsFromDoc, resolvePresets };
9
+ export { COLOR_CUSTOM_KEY, type ColorFieldClientOptions, type ColorFieldOptions, type ColorFormat, type ColorGlobalConfig, type ColorLinkedOptions, type ColorPreset, type ColorPresetsResolver, type ColorPresetsSource, type ColorSchemeValue, PRESET_PREFIX, type PresetReference, type PresetsFromArrayArgs, type PresetsFromDocArgs, type ResolvedColorPreset, colorField, isColorSchemeValue, lightDark, normalizePresets, parsePresetReference, presetsFromArray, presetsFromDoc, resolvePresets };
@@ -1,7 +1,8 @@
1
1
  import { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
2
2
  import { COLOR_CUSTOM_KEY, PRESET_PREFIX } from "../fields/color/options.js";
3
+ import { parsePresetReference } from "../fields/color/presetReference.js";
3
4
  import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
4
5
  import { colorField } from "../fields/color/colorField.js";
5
6
  import { presetsFromArray } from "../fields/color/presetsFromArray.js";
6
7
  import { presetsFromDoc } from "../fields/color/presetsFromDoc.js";
7
- export { COLOR_CUSTOM_KEY, PRESET_PREFIX, colorField, isColorSchemeValue, lightDark, normalizePresets, presetsFromArray, presetsFromDoc, resolvePresets };
8
+ export { COLOR_CUSTOM_KEY, PRESET_PREFIX, colorField, isColorSchemeValue, lightDark, normalizePresets, parsePresetReference, presetsFromArray, presetsFromDoc, resolvePresets };
@@ -6,7 +6,9 @@ import { rgbToHsv, toRgb } from "../engine/convert.js";
6
6
  import { parseColor } from "../engine/parse.js";
7
7
  import { formatColor } from "../engine/format.js";
8
8
  import { salvageColor } from "../engine/salvage.js";
9
+ import { isColorSchemeValue } from "../engine/scheme.js";
9
10
  import { PRESET_PREFIX } from "../options.js";
11
+ import { applyReferenceAlpha, formatPresetReference, parsePresetReference, presetReferenceIssue, presetReferenceParts } from "../presetReference.js";
10
12
  import { derivePresetChip } from "../presetChip.js";
11
13
  import { flatValue, swatchBackground } from "../schemeValue.js";
12
14
  import { ColorPickerPanel } from "./ColorPickerPanel.js";
@@ -27,7 +29,9 @@ const ColorField = (props) => {
27
29
  validate: useCallback((value, options) => {
28
30
  if (typeof value === "string" && value !== "") {
29
31
  if (linked && value.startsWith("preset:")) {
30
- if (value.length === 7) return t(keys.missingPreset);
32
+ const issue = presetReferenceIssue(value, resolvedPresets.length > 0 ? (key) => resolvedPresets.some((preset) => preset.key === key) : null);
33
+ if (issue === "invalidAlpha") return t(keys.invalidColor);
34
+ if (issue !== null) return t(keys.missingPreset);
31
35
  } else if (!parseColor(value)) return t(keys.invalidColor);
32
36
  }
33
37
  return text(value, {
@@ -40,12 +44,15 @@ const ColorField = (props) => {
40
44
  linked,
41
45
  name,
42
46
  required,
47
+ resolvedPresets,
43
48
  t
44
49
  ])
45
50
  });
46
51
  const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
47
52
  const stringValue = typeof value === "string" ? value : "";
48
- const presetKey = linked && stringValue.startsWith("preset:") ? stringValue.slice(PRESET_PREFIX.length) : null;
53
+ const reference = linked ? parsePresetReference(stringValue) : null;
54
+ const presetKey = reference?.key ?? null;
55
+ const referenceAlpha = alpha ? reference?.alpha ?? 100 : 100;
49
56
  const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
50
57
  const presetMissing = presetKey !== null && !activePreset;
51
58
  const rawValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
@@ -92,7 +99,9 @@ const ColorField = (props) => {
92
99
  const commitText = useCallback((raw) => {
93
100
  let normalized = null;
94
101
  if (linked && raw.startsWith("preset:")) {
95
- if (raw.length > 7) normalized = raw;
102
+ const parts = presetReferenceParts(raw);
103
+ if (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100);
104
+ else if (raw.length > 7) normalized = raw;
96
105
  } else {
97
106
  const parsedRaw = parseColor(raw);
98
107
  if (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha });
@@ -174,14 +183,36 @@ const ColorField = (props) => {
174
183
  const rgb = toRgb(parsed);
175
184
  const hsv = rgbToHsv(rgb);
176
185
  return {
177
- a: rgb.alpha,
186
+ a: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,
178
187
  h: hsv.h,
179
188
  s: hsv.s,
180
189
  v: hsv.v
181
190
  };
182
- }, [parsed]);
191
+ }, [
192
+ parsed,
193
+ presetKey,
194
+ referenceAlpha
195
+ ]);
196
+ const commitReferenceAlpha = useCallback((alpha100) => {
197
+ if (presetKey === null) return;
198
+ setValue(formatPresetReference(presetKey, alpha100));
199
+ }, [presetKey, setValue]);
200
+ const contentRef = useRef(null);
201
+ const [contentClipped, setContentClipped] = useState(false);
202
+ const measureClip = useCallback(() => {
203
+ const el = contentRef.current;
204
+ if (el) setContentClipped(el.scrollWidth > el.clientWidth + 1);
205
+ }, []);
206
+ useEffect(measureClip);
207
+ useEffect(() => {
208
+ const el = contentRef.current;
209
+ if (!el) return;
210
+ const observer = new ResizeObserver(measureClip);
211
+ observer.observe(el);
212
+ return () => observer.disconnect();
213
+ }, [measureClip]);
183
214
  const styles = useMemo(() => mergeFieldStyles(field), [field]);
184
- const swatchCss = swatchBackground(rawValue);
215
+ const swatchCss = swatchBackground(referenceAlpha !== 100 && (typeof rawValue === "string" || isColorSchemeValue(rawValue)) ? applyReferenceAlpha(rawValue, referenceAlpha, "rgb") : rawValue);
185
216
  const swatch = /* @__PURE__ */ jsxs("span", {
186
217
  className: `${baseClass}__swatch ${baseClass}__checker`,
187
218
  children: [
@@ -241,12 +272,13 @@ const ColorField = (props) => {
241
272
  className: `${baseClass}__popup`,
242
273
  horizontalAlign: "left",
243
274
  render: ({ close }) => /* @__PURE__ */ jsx(ColorPickerPanel, {
244
- activePresetKey: activePreset?.key ?? null,
275
+ activeReference: reference,
245
276
  alphaEnabled: alpha,
246
277
  close,
247
278
  displayFormat,
248
279
  enableEyedropper,
249
280
  initial: initialHsva,
281
+ onPickAlpha: commitReferenceAlpha,
250
282
  onPickCss: commitCss,
251
283
  onPickPreset: (preset) => {
252
284
  if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
@@ -263,38 +295,51 @@ const ColorField = (props) => {
263
295
  size: "fit-content",
264
296
  verticalAlign: "bottom"
265
297
  }),
266
- chip ? /* @__PURE__ */ jsxs("span", {
267
- className: `${baseClass}__chip`,
268
- children: [/* @__PURE__ */ jsxs("span", {
269
- className: `${baseClass}__chip-swatch ${baseClass}__checker`,
270
- children: [swatchCss ? /* @__PURE__ */ jsx("span", {
271
- className: `${baseClass}__chip-color`,
272
- style: { background: swatchCss }
273
- }) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
274
- className: `${baseClass}__chip-color`,
275
- "data-missing": "true"
276
- }) : null]
277
- }), /* @__PURE__ */ jsx("span", {
278
- className: `${baseClass}__chip-label`,
279
- children: chip.label
280
- })]
281
- }) : null,
282
- /* @__PURE__ */ jsx("input", {
283
- className: `${baseClass}__input`,
284
- id: `field-${path?.replace(/\./g, "__")}`,
285
- name: path,
286
- onBlur: onTextBlur,
287
- onChange: onTextChange,
288
- onKeyDown: onTextKeyDown,
289
- placeholder: chip || typeof placeholder !== "string" ? void 0 : placeholder,
290
- readOnly: isReadOnly,
291
- type: "text",
292
- value: chip ? "" : draft
293
- }),
294
- /* @__PURE__ */ jsx("span", {
295
- "aria-hidden": "true",
296
- className: `${baseClass}__badge`,
297
- children: chip ? t(keys.preset) : displayFormat
298
+ /* @__PURE__ */ jsxs("div", {
299
+ className: [`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`].filter(Boolean).join(" "),
300
+ ref: contentRef,
301
+ children: [
302
+ chip ? /* @__PURE__ */ jsxs("span", {
303
+ className: `${baseClass}__chip`,
304
+ children: [
305
+ /* @__PURE__ */ jsxs("span", {
306
+ className: `${baseClass}__chip-swatch ${baseClass}__checker`,
307
+ children: [swatchCss ? /* @__PURE__ */ jsx("span", {
308
+ className: `${baseClass}__chip-color`,
309
+ style: { background: swatchCss }
310
+ }) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
311
+ className: `${baseClass}__chip-color`,
312
+ "data-missing": "true"
313
+ }) : null]
314
+ }),
315
+ /* @__PURE__ */ jsx("span", {
316
+ className: `${baseClass}__chip-label`,
317
+ children: chip.label
318
+ }),
319
+ alpha && chip.alpha !== 100 ? /* @__PURE__ */ jsxs("span", {
320
+ className: `${baseClass}__chip-alpha`,
321
+ children: [chip.alpha, "%"]
322
+ }) : null
323
+ ]
324
+ }) : null,
325
+ /* @__PURE__ */ jsx("input", {
326
+ className: `${baseClass}__input`,
327
+ id: `field-${path?.replace(/\./g, "__")}`,
328
+ name: path,
329
+ onBlur: onTextBlur,
330
+ onChange: onTextChange,
331
+ onKeyDown: onTextKeyDown,
332
+ placeholder: chip || typeof placeholder !== "string" ? void 0 : placeholder,
333
+ readOnly: isReadOnly,
334
+ type: "text",
335
+ value: chip ? "" : draft
336
+ }),
337
+ /* @__PURE__ */ jsx("span", {
338
+ "aria-hidden": "true",
339
+ className: `${baseClass}__badge`,
340
+ children: chip ? t(keys.preset) : displayFormat
341
+ })
342
+ ]
298
343
  }),
299
344
  isClearable && !required && !isReadOnly && stringValue !== "" ? /* @__PURE__ */ jsx("button", {
300
345
  "aria-label": t(keys.clearColor),
@@ -1 +1 @@
1
- {"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tuseField,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport { formatColor, parseColor, rgbToHsv, salvageColor, toRgb } from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = [],\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'string' && value !== '') {\n\t\t\t\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\t\tif (value.length === PRESET_PREFIX.length) return t(keys.missingPreset)\n\t\t\t\t} else if (!parseColor(value)) {\n\t\t\t\t\treturn t(keys.invalidColor)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, t]\n\t)\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst presetKey =\n\t\tlinked && stringValue.startsWith(PRESET_PREFIX) ? stringValue.slice(PRESET_PREFIX.length) : null\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits to the form without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tif (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the form value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn { a: rgb.alpha, h: hsv.h, s: hsv.s, v: hsv.v }\n\t}, [parsed])\n\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst swatchCss = swatchBackground(rawValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\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<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactivePresetKey={activePreset?.key ?? null}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} style={{ background: swatchCss }} />\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<input\n\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\tid={`field-${path?.replace(/\\./g, '__')}`}\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\tplaceholder={chip || typeof placeholder !== 'string' ? undefined : placeholder}\n\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t/>\n\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t</span>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,MAAM,YAAY;AAQlB,MAAa,cAAyC,UAAU;CAC/D,MAAM,EACL,cACA,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,MACA,YAED,MAAM,eACN,cACA,UAAU,mBACV,kBAAkB,CAAC,MAChB;CACJ,MAAM,EAAE,OAAO,kBAAkB,QAAQ,aAAa,QAAQ,mBAAmB;CACjF,MAAM,EAAE,MAAMA,iBAAe;CAgB7B,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB;EAAE,sBAAsB;EAAe,UArBnC,aACvB,OAAO,YAAY;GACnB,IAAI,OAA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E,KAAK,OAAO;QAC1B;OAClB,CAAA;OAEF,MAAK;OACL,eAAc;MACd,CAAA;MAED,OACA,qBAAC,QAAD;OAAM,WAAW,GAAG,UAAU;iBAA9B,CACC,qBAAC,QAAD;QAAM,WAAW,GAAG,UAAU,gBAAgB,UAAU;kBAAxD,CACE,YACA,oBAAC,QAAD;SAAM,WAAW,GAAG,UAAU;SAAe,OAAO,EAAE,YAAY,UAAU;QAAI,CAAA,IAC7E,MACH,KAAK,WAAW,CAAC,YACjB,oBAAC,QAAD;SAAM,WAAW,GAAG,UAAU;SAAe,gBAAa;QAAQ,CAAA,IAC/D,IACC;WACN,oBAAC,QAAD;QAAM,WAAW,GAAG,UAAU;kBAAgB,KAAK;OAAY,CAAA,CAC1D;WACH;MACJ,oBAAC,SAAD;OACC,WAAW,GAAG,UAAU;OACxB,IAAI,SAAS,MAAM,QAAQ,OAAO,IAAI;OACtC,MAAM;OACN,QAAQ;OACR,UAAU;OACV,WAAW;OACX,aAAa,QAAQ,OAAO,gBAAgB,WAAW,KAAA,IAAY;OACnE,UAAU;OACV,MAAK;OACL,OAAO,OAAO,KAAK;MACnB,CAAA;MACD,oBAAC,QAAD;OAAM,eAAY;OAAO,WAAW,GAAG,UAAU;iBAC/C,OAAO,EAAE,KAAK,MAAM,IAAI;MACpB,CAAA;MACL,eAAe,CAAC,YAAY,CAAC,cAAc,gBAAgB,KAC3D,oBAAC,UAAD;OACC,cAAY,EAAE,KAAK,UAAU;OAC7B,WAAW,GAAG,UAAU;OACxB,eAAe;QACd,SAAS,EAAE;QACX,SAAS,IAAI;OACd;OACA,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
1
+ {"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tuseField,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport {\n\tformatColor,\n\tisColorSchemeValue,\n\tparseColor,\n\trgbToHsv,\n\tsalvageColor,\n\ttoRgb,\n} from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from '../presetReference'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = [],\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'string' && value !== '') {\n\t\t\t\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\t\tconst hasKey =\n\t\t\t\t\t\tresolvedPresets.length > 0\n\t\t\t\t\t\t\t? (key: string) => resolvedPresets.some((preset) => preset.key === key)\n\t\t\t\t\t\t\t: null\n\t\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\t\tif (issue === 'invalidAlpha') return t(keys.invalidColor)\n\t\t\t\t\tif (issue !== null) return t(keys.missingPreset)\n\t\t\t\t} else if (!parseColor(value)) {\n\t\t\t\t\treturn t(keys.invalidColor)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, resolvedPresets, t]\n\t)\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst reference = linked ? parsePresetReference(stringValue) : null\n\tconst presetKey = reference?.key ?? null\n\t// With alpha disabled a stored suffix still parses, but renders at full\n\t// opacity so the field matches server resolution until commit strips it\n\tconst referenceAlpha = alpha ? (reference?.alpha ?? 100) : 100\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits to the form without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tconst parts = presetReferenceParts(raw)\n\t\t\t\t// Canonical form: /100 collapses to the bare reference, and a disabled\n\t\t\t\t// alpha channel strips any hand-typed suffix. Empty keys commit raw so\n\t\t\t\t// validation surfaces the missing-preset error.\n\t\t\t\tif (parts) normalized = formatPresetReference(parts.key, alpha ? parts.alpha : 100)\n\t\t\t\telse if (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the form value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\t// With a reference active the slider represents the reference alpha, not the\n\t// resolved color's own channel, so returning it to 100 restores the bare ref\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn {\n\t\t\ta: presetKey !== null ? referenceAlpha / 100 : rgb.alpha,\n\t\t\th: hsv.h,\n\t\t\ts: hsv.s,\n\t\t\tv: hsv.v,\n\t\t}\n\t}, [parsed, presetKey, referenceAlpha])\n\n\tconst commitReferenceAlpha = useCallback(\n\t\t(alpha100: number) => {\n\t\t\tif (presetKey === null) return\n\t\t\tsetValue(formatPresetReference(presetKey, alpha100))\n\t\t},\n\t\t[presetKey, setValue]\n\t)\n\n\t// The fade must track real overflow, not chip presence: the badge always hugs\n\t// the content run's right edge (the input's flex-grow pushes it there), so an\n\t// unconditional mask would fade it even in a full-width field with room to spare\n\tconst contentRef = useRef<HTMLDivElement>(null)\n\tconst [contentClipped, setContentClipped] = useState(false)\n\tconst measureClip = useCallback(() => {\n\t\tconst el = contentRef.current\n\t\t// +1 absorbs subpixel rounding between scrollWidth (int) and clientWidth\n\t\tif (el) setContentClipped(el.scrollWidth > el.clientWidth + 1)\n\t}, [])\n\t// No dependency array on purpose: chip mount and label changes alter\n\t// scrollWidth without resizing the observed box, so re-measure every render\n\tuseEffect(measureClip)\n\tuseEffect(() => {\n\t\tconst el = contentRef.current\n\t\tif (!el) return\n\t\tconst observer = new ResizeObserver(measureClip)\n\t\tobserver.observe(el)\n\t\treturn () => observer.disconnect()\n\t}, [measureClip])\n\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst swatchValue =\n\t\treferenceAlpha !== 100 && (typeof rawValue === 'string' || isColorSchemeValue(rawValue))\n\t\t\t? applyReferenceAlpha(rawValue, referenceAlpha, 'rgb')\n\t\t\t: rawValue\n\tconst swatchCss = swatchBackground(swatchValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\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<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactiveReference={reference}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickAlpha={commitReferenceAlpha}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={[`${baseClass}__content`, contentClipped && `${baseClass}__content--fade`]\n\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t.join(' ')}\n\t\t\t\t\t\tref={contentRef}\n\t\t\t\t\t>\n\t\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__chip-color`}\n\t\t\t\t\t\t\t\t\t\t\tstyle={{ background: swatchCss }}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t\t\t{alpha && chip.alpha !== 100 ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-alpha`}>{chip.alpha}%</span>\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\tid={`field-${path?.replace(/\\./g, '__')}`}\n\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\t\tplaceholder={chip || typeof placeholder !== 'string' ? undefined : placeholder}\n\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,YAAY;AAQlB,MAAa,cAAyC,UAAU;CAC/D,MAAM,EACL,cACA,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,MACA,YAED,MAAM,eACN,cACA,UAAU,mBACV,kBAAkB,CAAC,MAChB;CACJ,MAAM,EAAE,OAAO,kBAAkB,QAAQ,aAAa,QAAQ,mBAAmB;CACjF,MAAM,EAAE,MAAMA,iBAAe;CAsB7B,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB;EAAE,sBAAsB;EAAe,UA3BnC,aACvB,OAAO,YAAY;GACnB,IAAI,OAAO,UAAU,YAAY,UAAU;QACtC,UAAU,MAAM,WAAA,SAAwB,GAAG;KAK9C,MAAM,QAAQ,qBAAqB,OAHlC,gBAAgB,SAAS,KACrB,QAAgB,gBAAgB,MAAM,WAAW,OAAO,QAAQ,GAAG,IACpE,IAC4C;KAChD,IAAI,UAAU,gBAAgB,OAAO,EAAE,KAAK,YAAY;KACxD,IAAI,UAAU,MAAM,OAAO,EAAE,KAAK,aAAa;IAChD,OAAO,IAAI,CAAC,WAAW,KAAK,GAC3B,OAAO,EAAE,KAAK,YAAY;GAAA;GAG5B,OAAO,KAAK,OAAO;IAAE,GAAG;IAAS;IAAM;IAAU,MAAM;GAAO,CAAC;EAChE,GACA;GAAC;GAAQ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AA9B,CAA8C,KAAK,OAAM,GAAO;eAC7D;SACC;aACH;QACJ,oBAAC,SAAD;SACC,WAAW,GAAG,UAAU;SACxB,IAAI,SAAS,MAAM,QAAQ,OAAO,IAAI;SACtC,MAAM;SACN,QAAQ;SACR,UAAU;SACV,WAAW;SACX,aAAa,QAAQ,OAAO,gBAAgB,WAAW,KAAA,IAAY;SACnE,UAAU;SACV,MAAK;SACL,OAAO,OAAO,KAAK;QACnB,CAAA;QACD,oBAAC,QAAD;SAAM,eAAY;SAAO,WAAW,GAAG,UAAU;mBAC/C,OAAO,EAAE,KAAK,MAAM,IAAI;QACpB,CAAA;OACF;;MACJ,eAAe,CAAC,YAAY,CAAC,cAAc,gBAAgB,KAC3D,oBAAC,UAAD;OACC,cAAY,EAAE,KAAK,UAAU;OAC7B,WAAW,GAAG,UAAU;OACxB,eAAe;QACd,SAAS,EAAE;QACX,SAAS,IAAI;OACd;OACA,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
@@ -1,5 +1,6 @@
1
1
  import { ColorFormat } from "../../../types.js";
2
2
  import { ResolvedColorPreset } from "../options.js";
3
+ import { PresetReference } from "../presetReference.js";
3
4
  import React from "react";
4
5
 
5
6
  //#region src/fields/color/client/ColorPickerPanel.d.ts
@@ -10,12 +11,13 @@ type Hsva = {
10
11
  v: number;
11
12
  };
12
13
  type ColorPickerPanelProps = {
13
- activePresetKey: null | string;
14
+ /** The stored preset reference when one is active; alpha edits then keep the reference. */activeReference: null | PresetReference;
14
15
  alphaEnabled: boolean;
15
16
  close: () => void;
16
17
  displayFormat: ColorFormat;
17
18
  enableEyedropper: boolean;
18
19
  initial: Hsva | null;
20
+ onPickAlpha: (alpha: number) => void;
19
21
  onPickCss: (css: string) => void;
20
22
  onPickPreset: (preset: ResolvedColorPreset) => void;
21
23
  presetMissing: boolean;
@@ -21,10 +21,10 @@ const getEyeDropper = () => {
21
21
  };
22
22
  const clamp01 = (value) => Math.min(1, Math.max(0, value));
23
23
  const ColorPickerPanel = (props) => {
24
- const { activePresetKey, alphaEnabled, close, displayFormat, enableEyedropper, initial, onPickCss, onPickPreset, presetMissing, presets, presetsLabel, setDisplayFormat } = props;
24
+ const { activeReference, alphaEnabled, close, displayFormat, enableEyedropper, initial, onPickAlpha, onPickCss, onPickPreset, presetMissing, presets, presetsLabel, setDisplayFormat } = props;
25
25
  const { t } = useTranslation();
26
26
  const [hsva, setHsva] = useState(initial ?? {
27
- a: 1,
27
+ a: activeReference ? activeReference.alpha / 100 : 1,
28
28
  h: 0,
29
29
  s: 1,
30
30
  v: 1
@@ -51,8 +51,11 @@ const ColorPickerPanel = (props) => {
51
51
  if (skip) return;
52
52
  setHsva(initial);
53
53
  }, [initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ""]);
54
+ const alphaRafRef = useRef(null);
55
+ const pendingAlphaRef = useRef(100);
54
56
  useEffect(() => () => {
55
57
  if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
58
+ if (alphaRafRef.current !== null) cancelAnimationFrame(alphaRafRef.current);
56
59
  }, []);
57
60
  const commit = useCallback((next) => {
58
61
  pendingRef.current = next;
@@ -81,6 +84,21 @@ const ColorPickerPanel = (props) => {
81
84
  setHsva(next);
82
85
  commit(next);
83
86
  }, [commit]);
87
+ const commitReferenceAlpha = useCallback((next) => {
88
+ setHsva(next);
89
+ pendingAlphaRef.current = Math.round(next.a * 100);
90
+ if (alphaRafRef.current !== null) return;
91
+ alphaRafRef.current = requestAnimationFrame(() => {
92
+ alphaRafRef.current = null;
93
+ const current = hsvaRef.current;
94
+ lastEmittedRef.current = formatColor(hsvToRgb({
95
+ h: current.h,
96
+ s: current.s,
97
+ v: current.v
98
+ }, 1), "rgb");
99
+ onPickAlpha(pendingAlphaRef.current);
100
+ });
101
+ }, [onPickAlpha]);
84
102
  const svPointer = useCallback((event) => {
85
103
  const rect = svRef.current?.getBoundingClientRect();
86
104
  if (!rect) return;
@@ -163,7 +181,14 @@ const ColorPickerPanel = (props) => {
163
181
  className: `${baseClass}__slider ${baseClass}__slider--alpha`,
164
182
  max: 100,
165
183
  min: 0,
166
- onChange: (event) => applyPartial({ a: Number(event.target.value) / 100 }),
184
+ onChange: (event) => {
185
+ const a = Number(event.target.value) / 100;
186
+ if (activeReference) commitReferenceAlpha({
187
+ ...hsvaRef.current,
188
+ a
189
+ });
190
+ else applyPartial({ a });
191
+ },
167
192
  onKeyDown: stopArrowKeys,
168
193
  onLostPointerCapture: endDrag,
169
194
  step: 1,
@@ -212,7 +237,7 @@ const ColorPickerPanel = (props) => {
212
237
  className: `${baseClass}__presets-grid`,
213
238
  children: presets.map((preset) => /* @__PURE__ */ jsx("button", {
214
239
  "aria-label": preset.label,
215
- "aria-pressed": preset.key === activePresetKey,
240
+ "aria-pressed": preset.key === activeReference?.key,
216
241
  className: `${baseClass}__preset ${baseClass}__checker`,
217
242
  onClick: () => {
218
243
  onPickPreset(preset);
@@ -1 +1 @@
1
- {"version":3,"file":"ColorPickerPanel.js","names":[],"sources":["../../../../src/fields/color/client/ColorPickerPanel.tsx"],"sourcesContent":["'use client'\nimport type React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { formatColor, hsvToRgb } from '../engine'\nimport type { ResolvedColorPreset } from '../options'\nimport { swatchBackground } from '../schemeValue'\nimport { EyedropperIcon } from './icons'\n\nconst baseClass = 'fields-color'\nconst FORMATS: ColorFormat[] = ['hex', 'rgb', 'hsl', 'oklch']\n\nexport type Hsva = { a: number; h: number; s: number; v: number }\n\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nconst getEyeDropper = (): EyeDropperConstructor | null => {\n\tif (typeof window === 'undefined') return null\n\treturn (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n\nconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value))\n\nexport type ColorPickerPanelProps = {\n\tactivePresetKey: null | string\n\talphaEnabled: boolean\n\tclose: () => void\n\tdisplayFormat: ColorFormat\n\tenableEyedropper: boolean\n\tinitial: Hsva | null\n\tonPickCss: (css: string) => void\n\tonPickPreset: (preset: ResolvedColorPreset) => void\n\tpresetMissing: boolean\n\tpresets: ResolvedColorPreset[]\n\tpresetsLabel: string\n\tsetDisplayFormat: (format: ColorFormat) => void\n}\n\nexport const ColorPickerPanel: React.FC<ColorPickerPanelProps> = (props) => {\n\tconst {\n\t\tactivePresetKey,\n\t\talphaEnabled,\n\t\tclose,\n\t\tdisplayFormat,\n\t\tenableEyedropper,\n\t\tinitial,\n\t\tonPickCss,\n\t\tonPickPreset,\n\t\tpresetMissing,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\tsetDisplayFormat,\n\t} = props\n\tconst { t } = useTranslation()\n\n\tconst [hsva, setHsva] = useState<Hsva>(initial ?? { a: 1, h: 0, s: 1, v: 1 })\n\tconst hsvaRef = useRef(hsva)\n\thsvaRef.current = hsva\n\tconst draggingRef = useRef(false)\n\tconst svRef = useRef<HTMLDivElement>(null)\n\tconst rafRef = useRef<null | number>(null)\n\tconst pendingRef = useRef<Hsva | null>(null)\n\tconst lastEmittedRef = useRef<null | string>(null)\n\n\tconst initialKey = initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ''\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: resync only when the committed color changes, not on every initial object identity change\n\tuseEffect(() => {\n\t\tif (!initial) {\n\t\t\tlastEmittedRef.current = null\n\t\t\treturn\n\t\t}\n\t\tif (draggingRef.current) return\n\t\t// Skip echoes of our own commit: achromatic values round-trip with h/s zeroed and would clobber the local hue/saturation.\n\t\t// Compared opaque (alpha quantizes through hex storage) and one-shot (a stale ref must not suppress a later genuine match)\n\t\tconst incomingCss = formatColor(\n\t\t\thsvToRgb({ h: initial.h, s: initial.s, v: initial.v }, 1),\n\t\t\t'rgb'\n\t\t)\n\t\tconst skip = incomingCss === lastEmittedRef.current\n\t\tlastEmittedRef.current = null\n\t\tif (skip) return\n\t\tsetHsva(initial)\n\t}, [initialKey])\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Commits are rAF-throttled: pointermove floods would otherwise dispatch a form update per event\n\tconst commit = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tpendingRef.current = next\n\t\t\tif (rafRef.current !== null) return\n\t\t\trafRef.current = requestAnimationFrame(() => {\n\t\t\t\trafRef.current = null\n\t\t\t\tconst pending = pendingRef.current\n\t\t\t\tif (!pending) return\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickCss(\n\t\t\t\t\tformatColor(\n\t\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, alphaEnabled ? pending.a : 1),\n\t\t\t\t\t\t'rgb'\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[alphaEnabled, onPickCss]\n\t)\n\n\tconst applyPartial = useCallback(\n\t\t(patch: Partial<Hsva>) => {\n\t\t\tconst next = { ...hsvaRef.current, ...patch }\n\t\t\tsetHsva(next)\n\t\t\tcommit(next)\n\t\t},\n\t\t[commit]\n\t)\n\n\tconst svPointer = useCallback(\n\t\t(event: React.PointerEvent<HTMLDivElement>) => {\n\t\t\tconst rect = svRef.current?.getBoundingClientRect()\n\t\t\tif (!rect) return\n\t\t\tapplyPartial({\n\t\t\t\ts: clamp01((event.clientX - rect.left) / rect.width),\n\t\t\t\tv: clamp01(1 - (event.clientY - rect.top) / rect.height),\n\t\t\t})\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\tconst onSvKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tif (!event.key.startsWith('Arrow')) return\n\t\t\t// Popup preventDefaults ArrowUp/ArrowDown at document level for focus cycling; consume first\n\t\t\tevent.stopPropagation()\n\t\t\tevent.preventDefault()\n\t\t\tconst step = event.shiftKey ? 0.1 : 0.01\n\t\t\tconst current = hsvaRef.current\n\t\t\tif (event.key === 'ArrowLeft') applyPartial({ s: clamp01(current.s - step) })\n\t\t\tif (event.key === 'ArrowRight') applyPartial({ s: clamp01(current.s + step) })\n\t\t\tif (event.key === 'ArrowUp') applyPartial({ v: clamp01(current.v + step) })\n\t\t\tif (event.key === 'ArrowDown') applyPartial({ v: clamp01(current.v - step) })\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\t// Without this the Popup's document keydown handler preventDefaults native range stepping\n\tconst stopArrowKeys = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key.startsWith('Arrow')) event.stopPropagation()\n\t}, [])\n\n\t// Fires after pointerup AND pointercancel, so an interrupted drag never leaves draggingRef stuck\n\tconst endDrag = useCallback(() => {\n\t\tdraggingRef.current = false\n\t}, [])\n\n\tconst opaqueCss = formatColor(hsvToRgb({ h: hsva.h, s: hsva.s, v: hsva.v }, 1), 'rgb')\n\tconst eyeDropperCtor = enableEyedropper ? getEyeDropper() : null\n\n\treturn (\n\t\t<div className={`${baseClass}__panel`} data-popup-prevent-close>\n\t\t\t<div\n\t\t\t\taria-label={t(keys.saturationBrightness)}\n\t\t\t\taria-valuemax={100}\n\t\t\t\taria-valuemin={0}\n\t\t\t\taria-valuenow={Math.round(hsva.v * 100)}\n\t\t\t\taria-valuetext={`${Math.round(hsva.s * 100)}% / ${Math.round(hsva.v * 100)}%`}\n\t\t\t\tclassName={`${baseClass}__sv`}\n\t\t\t\tonKeyDown={onSvKeyDown}\n\t\t\t\tonPointerDown={(event) => {\n\t\t\t\t\tdraggingRef.current = true\n\t\t\t\t\tevent.currentTarget.setPointerCapture(event.pointerId)\n\t\t\t\t\tsvPointer(event)\n\t\t\t\t}}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tonPointerMove={(event) => {\n\t\t\t\t\tif (draggingRef.current) svPointer(event)\n\t\t\t\t}}\n\t\t\t\tonPointerUp={endDrag}\n\t\t\t\tref={svRef}\n\t\t\t\trole=\"slider\"\n\t\t\t\tstyle={{ backgroundColor: `hsl(${Math.round(hsva.h)} 100% 50%)` }}\n\t\t\t\ttabIndex={0}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\tclassName={`${baseClass}__sv-thumb`}\n\t\t\t\t\tstyle={{ left: `${hsva.s * 100}%`, top: `${(1 - hsva.v) * 100}%` }}\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t<input\n\t\t\t\taria-label={t(keys.hue)}\n\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--hue`}\n\t\t\t\tmax={360}\n\t\t\t\tmin={0}\n\t\t\t\tonChange={(event) => applyPartial({ h: Number(event.target.value) })}\n\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tstep={1}\n\t\t\t\ttype=\"range\"\n\t\t\t\tvalue={Math.round(hsva.h)}\n\t\t\t/>\n\n\t\t\t{alphaEnabled ? (\n\t\t\t\t<input\n\t\t\t\t\taria-label={t(keys.opacity)}\n\t\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--alpha`}\n\t\t\t\t\tmax={100}\n\t\t\t\t\tmin={0}\n\t\t\t\t\tonChange={(event) => applyPartial({ a: Number(event.target.value) / 100 })}\n\t\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\t\tstep={1}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundImage: `linear-gradient(to right, transparent, ${opaqueCss}), conic-gradient(var(--theme-elevation-150) 0 25%, transparent 0 50%, var(--theme-elevation-150) 0 75%, transparent 0)`,\n\t\t\t\t\t\tbackgroundSize: '100% 100%, 8px 8px',\n\t\t\t\t\t}}\n\t\t\t\t\ttype=\"range\"\n\t\t\t\t\tvalue={Math.round(hsva.a * 100)}\n\t\t\t\t/>\n\t\t\t) : null}\n\n\t\t\t<div className={`${baseClass}__controls`}>\n\t\t\t\t{/* biome-ignore lint/a11y/useSemanticElements: fieldset breaks flex layout in Safari; this is a toggle-button group, not a form fieldset */}\n\t\t\t\t<div aria-label={t(keys.format)} className={`${baseClass}__formats`} role=\"group\">\n\t\t\t\t\t{FORMATS.map((entry) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-pressed={entry === displayFormat}\n\t\t\t\t\t\t\tclassName={`${baseClass}__format`}\n\t\t\t\t\t\t\tkey={entry}\n\t\t\t\t\t\t\tonClick={() => setDisplayFormat(entry)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{entry}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t\t{eyeDropperCtor ? (\n\t\t\t\t\t<button\n\t\t\t\t\t\taria-label={t(keys.eyedropperPick)}\n\t\t\t\t\t\tclassName={`${baseClass}__eyedropper`}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tvoid new eyeDropperCtor().open().then(\n\t\t\t\t\t\t\t\t(result) => onPickCss(result.sRGBHex),\n\t\t\t\t\t\t\t\t// open() rejects when the user presses Escape; nothing to do\n\t\t\t\t\t\t\t\t() => undefined\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<EyedropperIcon />\n\t\t\t\t\t</button>\n\t\t\t\t) : null}\n\t\t\t</div>\n\n\t\t\t{presets.length > 0 ? (\n\t\t\t\t<div className={`${baseClass}__presets`}>\n\t\t\t\t\t<div className={`${baseClass}__presets-label`}>{presetsLabel}</div>\n\t\t\t\t\t{presetMissing ? (\n\t\t\t\t\t\t<p className={`${baseClass}__missing`}>{t(keys.missingPresetHint)}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className={`${baseClass}__presets-grid`}>\n\t\t\t\t\t\t{presets.map((preset) => (\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-label={preset.label}\n\t\t\t\t\t\t\t\taria-pressed={preset.key === activePresetKey}\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__preset ${baseClass}__checker`}\n\t\t\t\t\t\t\t\tkey={preset.key}\n\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\tonPickPreset(preset)\n\t\t\t\t\t\t\t\t\tclose()\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\ttitle={preset.label}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span style={{ background: swatchBackground(preset.value) ?? undefined }} />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,YAAY;AAClB,MAAM,UAAyB;CAAC;CAAO;CAAO;CAAO;AAAO;AAM5D,MAAM,sBAAoD;CACzD,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,OAAQ,OAA2D,cAAc;AAClF;AAEA,MAAM,WAAW,UAA0B,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;AAiBzE,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EACL,iBACA,cACA,OACA,eACA,kBACA,SACA,WACA,cACA,eACA,SACA,cACA,qBACG;CACJ,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,CAAC,MAAM,WAAW,SAAe,WAAW;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;EA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M,OAAO,EAAE,YAAY,iBAAiB,OAAO,KAAK,KAAK,KAAA,EAAU,EAAI,CAAA;MACpE,GATF,OAAO,GASL,CACR;KACG,CAAA;IACD;QACF;EACA;;AAEP"}
1
+ {"version":3,"file":"ColorPickerPanel.js","names":[],"sources":["../../../../src/fields/color/client/ColorPickerPanel.tsx"],"sourcesContent":["'use client'\nimport type React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { formatColor, hsvToRgb } from '../engine'\nimport type { ResolvedColorPreset } from '../options'\nimport type { PresetReference } from '../presetReference'\nimport { swatchBackground } from '../schemeValue'\nimport { EyedropperIcon } from './icons'\n\nconst baseClass = 'fields-color'\nconst FORMATS: ColorFormat[] = ['hex', 'rgb', 'hsl', 'oklch']\n\nexport type Hsva = { a: number; h: number; s: number; v: number }\n\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nconst getEyeDropper = (): EyeDropperConstructor | null => {\n\tif (typeof window === 'undefined') return null\n\treturn (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n\nconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value))\n\nexport type ColorPickerPanelProps = {\n\t/** The stored preset reference when one is active; alpha edits then keep the reference. */\n\tactiveReference: null | PresetReference\n\talphaEnabled: boolean\n\tclose: () => void\n\tdisplayFormat: ColorFormat\n\tenableEyedropper: boolean\n\tinitial: Hsva | null\n\tonPickAlpha: (alpha: number) => void\n\tonPickCss: (css: string) => void\n\tonPickPreset: (preset: ResolvedColorPreset) => void\n\tpresetMissing: boolean\n\tpresets: ResolvedColorPreset[]\n\tpresetsLabel: string\n\tsetDisplayFormat: (format: ColorFormat) => void\n}\n\nexport const ColorPickerPanel: React.FC<ColorPickerPanelProps> = (props) => {\n\tconst {\n\t\tactiveReference,\n\t\talphaEnabled,\n\t\tclose,\n\t\tdisplayFormat,\n\t\tenableEyedropper,\n\t\tinitial,\n\t\tonPickAlpha,\n\t\tonPickCss,\n\t\tonPickPreset,\n\t\tpresetMissing,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\tsetDisplayFormat,\n\t} = props\n\tconst { t } = useTranslation()\n\n\t// A missing preset resolves no color (initial is null) but its stored alpha\n\t// must still seed the slider so dragging it edits the reference in place\n\tconst [hsva, setHsva] = useState<Hsva>(\n\t\tinitial ?? { a: activeReference ? activeReference.alpha / 100 : 1, h: 0, s: 1, v: 1 }\n\t)\n\tconst hsvaRef = useRef(hsva)\n\thsvaRef.current = hsva\n\tconst draggingRef = useRef(false)\n\tconst svRef = useRef<HTMLDivElement>(null)\n\tconst rafRef = useRef<null | number>(null)\n\tconst pendingRef = useRef<Hsva | null>(null)\n\tconst lastEmittedRef = useRef<null | string>(null)\n\n\tconst initialKey = initial ? `${initial.h}|${initial.s}|${initial.v}|${initial.a}` : ''\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: resync only when the committed color changes, not on every initial object identity change\n\tuseEffect(() => {\n\t\tif (!initial) {\n\t\t\tlastEmittedRef.current = null\n\t\t\treturn\n\t\t}\n\t\tif (draggingRef.current) return\n\t\t// Skip echoes of our own commit: achromatic values round-trip with h/s zeroed and would clobber the local hue/saturation.\n\t\t// Compared opaque (alpha quantizes through hex storage) and one-shot (a stale ref must not suppress a later genuine match)\n\t\tconst incomingCss = formatColor(\n\t\t\thsvToRgb({ h: initial.h, s: initial.s, v: initial.v }, 1),\n\t\t\t'rgb'\n\t\t)\n\t\tconst skip = incomingCss === lastEmittedRef.current\n\t\tlastEmittedRef.current = null\n\t\tif (skip) return\n\t\tsetHsva(initial)\n\t}, [initialKey])\n\n\tconst alphaRafRef = useRef<null | number>(null)\n\tconst pendingAlphaRef = useRef(100)\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (rafRef.current !== null) cancelAnimationFrame(rafRef.current)\n\t\t\tif (alphaRafRef.current !== null) cancelAnimationFrame(alphaRafRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Commits are rAF-throttled: pointermove floods would otherwise dispatch a form update per event\n\tconst commit = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tpendingRef.current = next\n\t\t\tif (rafRef.current !== null) return\n\t\t\trafRef.current = requestAnimationFrame(() => {\n\t\t\t\trafRef.current = null\n\t\t\t\tconst pending = pendingRef.current\n\t\t\t\tif (!pending) return\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickCss(\n\t\t\t\t\tformatColor(\n\t\t\t\t\t\thsvToRgb({ h: pending.h, s: pending.s, v: pending.v }, alphaEnabled ? pending.a : 1),\n\t\t\t\t\t\t'rgb'\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t})\n\t\t},\n\t\t[alphaEnabled, onPickCss]\n\t)\n\n\tconst applyPartial = useCallback(\n\t\t(patch: Partial<Hsva>) => {\n\t\t\tconst next = { ...hsvaRef.current, ...patch }\n\t\t\tsetHsva(next)\n\t\t\tcommit(next)\n\t\t},\n\t\t[commit]\n\t)\n\n\t// Reference-preserving alpha path: while a preset is active, the slider\n\t// rewrites the stored `/<alpha>` suffix instead of committing a concrete\n\t// color. Same rAF throttling and echo suppression as the concrete path\n\t// (the opaque css is unchanged by alpha, so the resync effect skips it).\n\tconst commitReferenceAlpha = useCallback(\n\t\t(next: Hsva) => {\n\t\t\tsetHsva(next)\n\t\t\tpendingAlphaRef.current = Math.round(next.a * 100)\n\t\t\tif (alphaRafRef.current !== null) return\n\t\t\talphaRafRef.current = requestAnimationFrame(() => {\n\t\t\t\talphaRafRef.current = null\n\t\t\t\tconst current = hsvaRef.current\n\t\t\t\tlastEmittedRef.current = formatColor(\n\t\t\t\t\thsvToRgb({ h: current.h, s: current.s, v: current.v }, 1),\n\t\t\t\t\t'rgb'\n\t\t\t\t)\n\t\t\t\tonPickAlpha(pendingAlphaRef.current)\n\t\t\t})\n\t\t},\n\t\t[onPickAlpha]\n\t)\n\n\tconst svPointer = useCallback(\n\t\t(event: React.PointerEvent<HTMLDivElement>) => {\n\t\t\tconst rect = svRef.current?.getBoundingClientRect()\n\t\t\tif (!rect) return\n\t\t\tapplyPartial({\n\t\t\t\ts: clamp01((event.clientX - rect.left) / rect.width),\n\t\t\t\tv: clamp01(1 - (event.clientY - rect.top) / rect.height),\n\t\t\t})\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\tconst onSvKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tif (!event.key.startsWith('Arrow')) return\n\t\t\t// Popup preventDefaults ArrowUp/ArrowDown at document level for focus cycling; consume first\n\t\t\tevent.stopPropagation()\n\t\t\tevent.preventDefault()\n\t\t\tconst step = event.shiftKey ? 0.1 : 0.01\n\t\t\tconst current = hsvaRef.current\n\t\t\tif (event.key === 'ArrowLeft') applyPartial({ s: clamp01(current.s - step) })\n\t\t\tif (event.key === 'ArrowRight') applyPartial({ s: clamp01(current.s + step) })\n\t\t\tif (event.key === 'ArrowUp') applyPartial({ v: clamp01(current.v + step) })\n\t\t\tif (event.key === 'ArrowDown') applyPartial({ v: clamp01(current.v - step) })\n\t\t},\n\t\t[applyPartial]\n\t)\n\n\t// Without this the Popup's document keydown handler preventDefaults native range stepping\n\tconst stopArrowKeys = useCallback((event: React.KeyboardEvent) => {\n\t\tif (event.key.startsWith('Arrow')) event.stopPropagation()\n\t}, [])\n\n\t// Fires after pointerup AND pointercancel, so an interrupted drag never leaves draggingRef stuck\n\tconst endDrag = useCallback(() => {\n\t\tdraggingRef.current = false\n\t}, [])\n\n\tconst opaqueCss = formatColor(hsvToRgb({ h: hsva.h, s: hsva.s, v: hsva.v }, 1), 'rgb')\n\tconst eyeDropperCtor = enableEyedropper ? getEyeDropper() : null\n\n\treturn (\n\t\t<div className={`${baseClass}__panel`} data-popup-prevent-close>\n\t\t\t<div\n\t\t\t\taria-label={t(keys.saturationBrightness)}\n\t\t\t\taria-valuemax={100}\n\t\t\t\taria-valuemin={0}\n\t\t\t\taria-valuenow={Math.round(hsva.v * 100)}\n\t\t\t\taria-valuetext={`${Math.round(hsva.s * 100)}% / ${Math.round(hsva.v * 100)}%`}\n\t\t\t\tclassName={`${baseClass}__sv`}\n\t\t\t\tonKeyDown={onSvKeyDown}\n\t\t\t\tonPointerDown={(event) => {\n\t\t\t\t\tdraggingRef.current = true\n\t\t\t\t\tevent.currentTarget.setPointerCapture(event.pointerId)\n\t\t\t\t\tsvPointer(event)\n\t\t\t\t}}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tonPointerMove={(event) => {\n\t\t\t\t\tif (draggingRef.current) svPointer(event)\n\t\t\t\t}}\n\t\t\t\tonPointerUp={endDrag}\n\t\t\t\tref={svRef}\n\t\t\t\trole=\"slider\"\n\t\t\t\tstyle={{ backgroundColor: `hsl(${Math.round(hsva.h)} 100% 50%)` }}\n\t\t\t\ttabIndex={0}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\tclassName={`${baseClass}__sv-thumb`}\n\t\t\t\t\tstyle={{ left: `${hsva.s * 100}%`, top: `${(1 - hsva.v) * 100}%` }}\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t<input\n\t\t\t\taria-label={t(keys.hue)}\n\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--hue`}\n\t\t\t\tmax={360}\n\t\t\t\tmin={0}\n\t\t\t\tonChange={(event) => applyPartial({ h: Number(event.target.value) })}\n\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\tstep={1}\n\t\t\t\ttype=\"range\"\n\t\t\t\tvalue={Math.round(hsva.h)}\n\t\t\t/>\n\n\t\t\t{alphaEnabled ? (\n\t\t\t\t<input\n\t\t\t\t\taria-label={t(keys.opacity)}\n\t\t\t\t\tclassName={`${baseClass}__slider ${baseClass}__slider--alpha`}\n\t\t\t\t\tmax={100}\n\t\t\t\t\tmin={0}\n\t\t\t\t\tonChange={(event) => {\n\t\t\t\t\t\tconst a = Number(event.target.value) / 100\n\t\t\t\t\t\tif (activeReference) commitReferenceAlpha({ ...hsvaRef.current, a })\n\t\t\t\t\t\telse applyPartial({ a })\n\t\t\t\t\t}}\n\t\t\t\t\tonKeyDown={stopArrowKeys}\n\t\t\t\t\tonLostPointerCapture={endDrag}\n\t\t\t\t\tstep={1}\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tbackgroundImage: `linear-gradient(to right, transparent, ${opaqueCss}), conic-gradient(var(--theme-elevation-150) 0 25%, transparent 0 50%, var(--theme-elevation-150) 0 75%, transparent 0)`,\n\t\t\t\t\t\tbackgroundSize: '100% 100%, 8px 8px',\n\t\t\t\t\t}}\n\t\t\t\t\ttype=\"range\"\n\t\t\t\t\tvalue={Math.round(hsva.a * 100)}\n\t\t\t\t/>\n\t\t\t) : null}\n\n\t\t\t<div className={`${baseClass}__controls`}>\n\t\t\t\t{/* biome-ignore lint/a11y/useSemanticElements: fieldset breaks flex layout in Safari; this is a toggle-button group, not a form fieldset */}\n\t\t\t\t<div aria-label={t(keys.format)} className={`${baseClass}__formats`} role=\"group\">\n\t\t\t\t\t{FORMATS.map((entry) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-pressed={entry === displayFormat}\n\t\t\t\t\t\t\tclassName={`${baseClass}__format`}\n\t\t\t\t\t\t\tkey={entry}\n\t\t\t\t\t\t\tonClick={() => setDisplayFormat(entry)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{entry}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t\t{eyeDropperCtor ? (\n\t\t\t\t\t<button\n\t\t\t\t\t\taria-label={t(keys.eyedropperPick)}\n\t\t\t\t\t\tclassName={`${baseClass}__eyedropper`}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tvoid new eyeDropperCtor().open().then(\n\t\t\t\t\t\t\t\t(result) => onPickCss(result.sRGBHex),\n\t\t\t\t\t\t\t\t// open() rejects when the user presses Escape; nothing to do\n\t\t\t\t\t\t\t\t() => undefined\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}}\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<EyedropperIcon />\n\t\t\t\t\t</button>\n\t\t\t\t) : null}\n\t\t\t</div>\n\n\t\t\t{presets.length > 0 ? (\n\t\t\t\t<div className={`${baseClass}__presets`}>\n\t\t\t\t\t<div className={`${baseClass}__presets-label`}>{presetsLabel}</div>\n\t\t\t\t\t{presetMissing ? (\n\t\t\t\t\t\t<p className={`${baseClass}__missing`}>{t(keys.missingPresetHint)}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className={`${baseClass}__presets-grid`}>\n\t\t\t\t\t\t{presets.map((preset) => (\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-label={preset.label}\n\t\t\t\t\t\t\t\taria-pressed={preset.key === activeReference?.key}\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__preset ${baseClass}__checker`}\n\t\t\t\t\t\t\t\tkey={preset.key}\n\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\tonPickPreset(preset)\n\t\t\t\t\t\t\t\t\tclose()\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\ttitle={preset.label}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span style={{ background: swatchBackground(preset.value) ?? undefined }} />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,YAAY;AAClB,MAAM,UAAyB;CAAC;CAAO;CAAO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C,OAAD;IAAK,WAAW,GAAG,UAAU;cAA7B,CAEC,oBAAC,OAAD;KAAK,cAAY,EAAE,KAAK,MAAM;KAAG,WAAW,GAAG,UAAU;KAAY,MAAK;eACxE,QAAQ,KAAK,UACb,oBAAC,UAAD;MACC,gBAAc,UAAU;MACxB,WAAW,GAAG,UAAU;MAExB,eAAe,iBAAiB,KAAK;MACrC,MAAK;gBAEJ;KACM,GALF,KAKE,CACR;IACG,CAAA,GACJ,iBACA,oBAAC,UAAD;KACC,cAAY,EAAE,KAAK,cAAc;KACjC,WAAW,GAAG,UAAU;KACxB,eAAe;MACd,IAAS,eAAe,EAAE,KAAK,EAAE,MAC/B,WAAW,UAAU,OAAO,OAAO,SAE9B,KAAA,CACP;KACD;KACA,MAAK;eAEL,oBAAC,gBAAD,CAAiB,CAAA;IACV,CAAA,IACL,IACA;;GAEJ,QAAQ,SAAS,IACjB,qBAAC,OAAD;IAAK,WAAW,GAAG,UAAU;cAA7B;KACC,oBAAC,OAAD;MAAK,WAAW,GAAG,UAAU;gBAAmB;KAAkB,CAAA;KACjE,gBACA,oBAAC,KAAD;MAAG,WAAW,GAAG,UAAU;gBAAa,EAAE,KAAK,iBAAiB;KAAK,CAAA,IAClE;KACJ,oBAAC,OAAD;MAAK,WAAW,GAAG,UAAU;gBAC3B,QAAQ,KAAK,WACb,oBAAC,UAAD;OACC,cAAY,OAAO;OACnB,gBAAc,OAAO,QAAQ,iBAAiB;OAC9C,WAAW,GAAG,UAAU,WAAW,UAAU;OAE7C,eAAe;QACd,aAAa,MAAM;QACnB,MAAM;OACP;OACA,OAAO,OAAO;OACd,MAAK;iBAEL,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,iBAAiB,OAAO,KAAK,KAAK,KAAA,EAAU,EAAI,CAAA;MACpE,GATF,OAAO,GASL,CACR;KACG,CAAA;IACD;QACF;EACA;;AAEP"}
@@ -131,6 +131,29 @@ html[data-theme="dark"] .fields-color.error .fields-color__container:hover {
131
131
  filter: none;
132
132
  }
133
133
 
134
+ /* Clips the chip/input/badge run so fixed-size flex items can never escape the
135
+ container at narrow widths; the swatch and clear button stay outside it, so
136
+ the clear control keeps its place at the right edge. The fade is a mask, not
137
+ a background-colored gradient overlay, so it stays correct over every
138
+ container background (error, read-only, hover transitions, both themes).
139
+ The modifier is toggled from a measured scrollWidth overflow, never applied
140
+ statically: the badge always sits at the run's right edge, so a static mask
141
+ would fade it even with room to spare. */
142
+ .fields-color__content {
143
+ display: flex;
144
+ flex: 1 1 auto;
145
+ min-width: 0;
146
+ align-items: center;
147
+ gap: 7px;
148
+ height: 100%;
149
+ overflow: hidden;
150
+ }
151
+
152
+ .fields-color__content--fade {
153
+ -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
154
+ mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
155
+ }
156
+
134
157
  /* The sibling input's width: 100% basis would otherwise squeeze the chip to nothing;
135
158
  the max-width keeps runaway labels ellipsizing instead of overflowing */
136
159
  .fields-color__chip {
@@ -173,6 +196,13 @@ html[data-theme="dark"] .fields-color.error .fields-color__container:hover {
173
196
  text-overflow: ellipsis;
174
197
  }
175
198
 
199
+ .fields-color__chip-alpha {
200
+ flex-shrink: 0;
201
+ color: var(--theme-elevation-500);
202
+ font-size: 0.75rem;
203
+ line-height: 1;
204
+ }
205
+
176
206
  .fields-color__input {
177
207
  flex: 1 1 auto;
178
208
  width: 100%;
@@ -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,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AAG,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}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":";;;;;;;;;;;;AA0BA,MAAM,iBACJ,SAKD,OAAO,OAAO,SAAS;CACtB,IAAI,OAAO,UAAU,YAAY,UAAU;MACtC,KAAK,UAAU,MAAM,WAAA,SAAwB,GAAG;GACnD,IAAI,SAA4C;GAChD,IAAI,qBAAqB,KAAK,GAAG,UAChC,IAAI;IACH,MAAM,MAAM,MAAM,eAAe;KAChC,SAAS,KAAK;KACd,KAAK,KAAK;KACV,QAAQ,KAAK;IACd,CAAC;IAGD,IAAI,IAAI,SAAS,GAAG,UAAU,QAAQ,IAAI,MAAM,WAAW,OAAO,QAAQ,GAAG;GAC9E,QAAQ,CAER;GAED,MAAM,QAAQ,qBAAqB,OAAO,MAAM;GAChD,IAAI,UAAU,gBAAgB,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,YAAY;GAC9E,IAAI,UAAU,MAAM,OAAO,YAAY,K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AG;GACrD,OAAO,UAAU,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,UAAU,GAAG;EAC5E,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,UAAU,MAAM,cAAc,GAAG,UAAU,GAAG;EACtD;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,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: appl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KAAK,IAAI,GAAG,OAAO;EACjD,OAAO;CACR;CACA,IAAI,UAAU,CAAC,OAAO,MAAM,GAAG,GAAG,OAAO;CACzC,OAAO;AACR;AAEA,MAAM,cAAc,KAAa,OAAe,WAAgC;CAC/E,MAAM,SAAS,WAAW,GAAG;CAC7B,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,OAAO,OAAO,SAAS,OAAO,KAAK,IAAI,OAAO,QAAQ;CAC5D,OAAO,YAAY;EAAE,GAAG;EAAQ,OAAO,QAAQ,QAAQ;CAAK,GAAG,MAAM;AACtE;;;;;;AAOA,MAAa,uBACZ,OACA,OACA,WAC+B;CAC/B,IAAI,mBAAmB,KAAK,GAC3B,OAAO;EACN,MAAM,WAAW,MAAM,MAAM,OAAO,MAAM;EAC1C,OAAO,WAAW,MAAM,OAAO,OAAO,MAAM;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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10x-media/fields",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Reusable admin fields for Payload: color picker, icon picker, encrypted fields, and more",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -159,10 +159,10 @@
159
159
  "tsx": "^4.19.2",
160
160
  "typescript": "5.9.3",
161
161
  "vitest": "4.1.7",
162
- "@10x-media/tsdown-config": "0.0.0",
163
- "@10x-media/payload-test-harness": "0.0.0",
162
+ "@10x-media/tsconfig": "0.0.0",
164
163
  "@10x-media/vitest-config": "0.0.0",
165
- "@10x-media/tsconfig": "0.0.0"
164
+ "@10x-media/tsdown-config": "0.0.0",
165
+ "@10x-media/payload-test-harness": "0.0.0"
166
166
  },
167
167
  "publishConfig": {
168
168
  "access": "public"