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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/exports/color-utils.d.ts +2 -1
  3. package/dist/exports/color-utils.js +2 -1
  4. package/dist/exports/color.d.ts +2 -1
  5. package/dist/exports/color.js +2 -1
  6. package/dist/fields/color/client/ColorField.js +45 -20
  7. package/dist/fields/color/client/ColorField.js.map +1 -1
  8. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  9. package/dist/fields/color/client/ColorPickerPanel.js +29 -4
  10. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  11. package/dist/fields/color/client/colorField.css +7 -0
  12. package/dist/fields/color/colorField.js +36 -8
  13. package/dist/fields/color/colorField.js.map +1 -1
  14. package/dist/fields/color/presetChip.js +10 -9
  15. package/dist/fields/color/presetChip.js.map +1 -1
  16. package/dist/fields/color/presetReference.d.ts +13 -0
  17. package/dist/fields/color/presetReference.js +94 -0
  18. package/dist/fields/color/presetReference.js.map +1 -0
  19. package/dist/fields/color/server/ColorCell.js +7 -1
  20. package/dist/fields/color/server/ColorCell.js.map +1 -1
  21. package/dist/fields/color/server/colorCell.css +5 -0
  22. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  23. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  24. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  25. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
  26. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  27. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  28. package/dist/fields/icon/codegen/emit.js +2 -2
  29. package/dist/fields/icon/codegen/emit.js.map +1 -1
  30. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\tPRESET_PREFIX,\n} from './options'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: { linked: boolean }): TextFieldValidation =>\n\t(value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tif (value.length === PRESET_PREFIX.length) {\n\t\t\t\t\treturn asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t\t}\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) return value\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst key = raw.slice(PRESET_PREFIX.length)\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn shape(match ? match.value : linkedFallback)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn shape(linkedFallback)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disableListColumn: true, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'text',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\n\treturn [field, resolvedField]\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,iBACJ,UACA,OAAO,SAAS;CAChB,IAAI,OAAO,UAAU,YAAY,UAAU;MACtC,KAAK,UAAU,MAAM,WAAA,SAAwB;OAC5C,MAAM,WAAA,GACT,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,aAAa;EAAA,OAE5C,IAAI,CAAC,WAAW,KAAK,GAC3B,OAAO,YAAY,KAAK,IAAI,CAAC,EAAE,KAAK,YAAY;CAAA;CAGlD,OAAO,KAAK,OAAO,IAAI;AACxB;AAED,MAAM,sBACJ,UACA,EAAE,KAAK,YAAY;CACnB,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,IAAI,KAAK,UAAU,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC3D,MAAM,SAAS,WAAW,KAAK;CAE/B,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,YAAY,QAAQ,mBAAmB,KAAK,QAAQ,GAAG,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;AACvF;AAgBD,SAAgB,WACf,UAA6B,CAAC,GACmB;CACjD,MAAM,EACL,OAAO,SACP,QAAQ,MACR,mBAAmB,MACnB,QACA,cAAc,MACd,OACA,QAAQ,eAAe,OACvB,WACA,WACA,SACA,cACA,aACG;CAEJ,MAAM,SAAS,iBAAiB;CAChC,MAAM,gBAAoC,OAAO,iBAAiB,WAAW,eAAe,CAAC;CAC7F,MAAM,iBAAiB,cAAc,YAAY;CACjD,MAAM,cAAc,cAAc,WAAW;CAC7C,MAAM,UA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AK,QAAQ;GAAQ,CAAC,GAChD,MAAM,WAAW,OAAO,QAAQ,GAAG;GACrD,OAAO,MAAM,QAAQ,MAAM,QAAQ,cAAc;EAClD,SAAS,OAAO;GAEf,IAAI,CAAC,eAAe,IAAI,GAAG,GAAG;IAC7B,eAAe,IAAI,GAAG;IACtB,MAAM,OAAO,YAAY,QAAQ,QAAQ,QAAQ;IACjD,IAAI,QAAQ,OAAO,MAClB,EAAE,KAAK,MAAM,GACb,yCAAyC,KAAK,GAAG,MAAM,MACxD;GACD;GACA,OAAO,MAAM,cAAc;EAC5B;CACD;CAEA,MAAM,gBAAgB;EAAE,mBAAmB;EAAM,QAAQ;CAAK;CAmB9D,OAAO,CAAC,OAhBP,gBAAgB,YACb;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,IACC;EACA,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,CAEyB;AAC7B"}
1
+ {"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, JSONField, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat, ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\nimport {\n\tCOLOR_CUSTOM_KEY,\n\ttype ColorFieldCustom,\n\ttype ColorFieldOptions,\n\ttype ColorFieldServerOptions,\n\ttype ColorLinkedOptions,\n\ttype ColorPresetsSource,\n\tPRESET_PREFIX,\n} from './options'\nimport {\n\tapplyReferenceAlpha,\n\tformatPresetReference,\n\tparsePresetReference,\n\tpresetReferenceIssue,\n\tpresetReferenceParts,\n} from './presetReference'\nimport { resolveColorFormat } from './resolveFormat'\nimport { resolvePresets } from './resolvePresets'\nimport { flatValue } from './schemeValue'\n\nconst buildValidate =\n\t(opts: {\n\t\tlinked: boolean\n\t\tmemoKey: symbol\n\t\tpresets: ColorPresetsSource | undefined\n\t}): TextFieldValidation =>\n\tasync (value, args) => {\n\t\tif (typeof value === 'string' && value !== '') {\n\t\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\tlet hasKey: ((key: string) => boolean) | null = null\n\t\t\t\tif (presetReferenceParts(value)?.explicit) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst all = await resolvePresets({\n\t\t\t\t\t\t\tmemoKey: opts.memoKey,\n\t\t\t\t\t\t\treq: args.req,\n\t\t\t\t\t\t\tsource: opts.presets,\n\t\t\t\t\t\t})\n\t\t\t\t\t\t// An empty list means no presets are configured (or none resolved);\n\t\t\t\t\t\t// skip the existence check rather than rejecting every reference\n\t\t\t\t\t\tif (all.length > 0) hasKey = (key) => all.some((preset) => preset.key === key)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// A broken resolver must not block writes; reads degrade and log separately\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst issue = presetReferenceIssue(value, hasKey)\n\t\t\t\tif (issue === 'invalidAlpha') return asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t\tif (issue !== null) return asTranslate(args.req.t)(keys.missingPreset)\n\t\t\t} else if (!parseColor(value)) {\n\t\t\t\treturn asTranslate(args.req.t)(keys.invalidColor)\n\t\t\t}\n\t\t}\n\t\treturn text(value, args)\n\t}\n\nconst buildNormalizeHook =\n\t(opts: { alpha: boolean; format: ColorFormat | undefined; linked: boolean }): FieldHook =>\n\t({ req, value }) => {\n\t\tif (typeof value !== 'string' || value === '') return value\n\t\tif (opts.linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\tconst parts = presetReferenceParts(value)\n\t\t\t// Empty keys pass through so validate rejects them with a proper message\n\t\t\tif (!parts) return value\n\t\t\treturn formatPresetReference(parts.key, opts.alpha ? parts.alpha : 100)\n\t\t}\n\t\tconst parsed = parseColor(value)\n\t\t// Unparseable input passes through so validate rejects it with a proper message\n\t\tif (!parsed) return value\n\t\treturn formatColor(parsed, resolveColorFormat(opts.format, req), { alpha: opts.alpha })\n\t}\n\n/**\n * Text-backed color field storing a CSS string in the configured format.\n * Linked mode returns a tuple: the field plus a hidden virtual sibling\n * `${name}Resolved` populated on read (spread it into `fields`). The sibling\n * keeps the stored `preset:<key>` reference round-trip safe in the admin form\n * while consumers read the resolved CSS value.\n */\nexport function colorField(options?: ColorFieldOptions & { linked?: false }): TextField\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: (ColorLinkedOptions & { resolve?: 'value' }) | true }\n): [TextField, TextField]\nexport function colorField(\n\toptions: ColorFieldOptions & { linked: ColorLinkedOptions & { resolve: 'schemes' } }\n): [TextField, JSONField]\nexport function colorField(\n\toptions: ColorFieldOptions = {}\n): TextField | [TextField, JSONField | TextField] {\n\tconst {\n\t\tname = 'color',\n\t\talpha = true,\n\t\tenableEyedropper = true,\n\t\tformat,\n\t\tisClearable = true,\n\t\tlabel,\n\t\tlinked: linkedOption = false,\n\t\tlocalized,\n\t\toverrides,\n\t\tpresets,\n\t\tpresetsLabel,\n\t\trequired,\n\t} = options\n\n\tconst linked = linkedOption !== false\n\tconst linkedOptions: ColorLinkedOptions = typeof linkedOption === 'object' ? linkedOption : {}\n\tconst linkedFallback = linkedOptions.fallback ?? null\n\tconst resolveMode = linkedOptions.resolve ?? 'value'\n\tconst memoKey = Symbol(`colorField:${name}`)\n\n\t// format stays possibly-undefined here; ColorFieldServer resolves the effective\n\t// format (field-level, else plugin registry, else hex) per request for the client.\n\tconst clientOptions: ColorFieldServerOptions = {\n\t\talpha,\n\t\tenableEyedropper,\n\t\tformat,\n\t\tisClearable,\n\t\tlinked,\n\t\tlinkedFallback,\n\t}\n\n\tconst custom: ColorFieldCustom = { memoKey, presets, presetsLabel }\n\n\tconst base: TextField = {\n\t\tname,\n\t\ttype: 'text',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: { path: '@10x-media/fields/rsc#ColorCell' },\n\t\t\t\tField: {\n\t\t\t\t\tclientProps: { colorOptions: clientOptions },\n\t\t\t\t\tpath: '@10x-media/fields/rsc#ColorFieldServer',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcustom: { [COLOR_CUSTOM_KEY]: custom },\n\t\thooks: { beforeValidate: [buildNormalizeHook({ alpha, format, linked })] },\n\t\tvalidate: buildValidate({ linked, memoKey, presets }),\n\t}\n\n\tconst field = typeof overrides === 'function' ? overrides({ field: base }) : base\n\n\tif (!linked) return field\n\n\tconst loggedRequests = new WeakSet<PayloadRequest>()\n\n\t/**\n\t * Shapes a resolved value for the configured sibling. 'value' flattens a\n\t * scheme to its light member so a field configured before schemes existed\n\t * keeps working when its resolver starts returning them; 'schemes' inflates\n\t * a flat color so consumers never branch on the shape.\n\t */\n\tconst shape = (value: null | string | ColorSchemeValue): null | string | ColorSchemeValue => {\n\t\tif (value === null) return null\n\t\tif (resolveMode === 'value') return flatValue(value)\n\t\treturn isColorSchemeValue(value) ? value : { dark: value, light: value }\n\t}\n\n\t/** The stored reference alpha, applied to whatever the reference resolved to. */\n\tconst withAlpha = (\n\t\tresolved: null | string | ColorSchemeValue,\n\t\trefAlpha: number,\n\t\treq: PayloadRequest\n\t): null | string | ColorSchemeValue => {\n\t\tconst effective = alpha ? refAlpha : 100\n\t\tif (resolved === null || effective === 100) return resolved\n\t\treturn applyReferenceAlpha(resolved, effective, resolveColorFormat(format, req))\n\t}\n\n\tconst resolveHook: FieldHook = async ({ collection, global, req, siblingData }) => {\n\t\tconst raw = siblingData?.[field.name]\n\t\tif (typeof raw !== 'string' || raw === '') return null\n\t\tif (!raw.startsWith(PRESET_PREFIX)) return shape(raw)\n\t\tconst ref = parsePresetReference(raw)\n\t\tconst key = ref?.key ?? raw.slice(PRESET_PREFIX.length)\n\t\tconst refAlpha = ref?.alpha ?? 100\n\t\ttry {\n\t\t\tconst all = await resolvePresets({ memoKey, req, source: presets })\n\t\t\tconst match = all.find((preset) => preset.key === key)\n\t\t\treturn withAlpha(shape(match ? match.value : linkedFallback), refAlpha, req)\n\t\t} catch (error) {\n\t\t\t// A broken resolver must not take down reads; degrade like a missing preset\n\t\t\tif (!loggedRequests.has(req)) {\n\t\t\t\tloggedRequests.add(req)\n\t\t\t\tconst slug = collection?.slug ?? global?.slug ?? 'unknown'\n\t\t\t\treq.payload.logger.error(\n\t\t\t\t\t{ err: error },\n\t\t\t\t\t`colorField preset resolver failed for ${slug}.${field.name}`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn withAlpha(shape(linkedFallback), refAlpha, req)\n\t\t}\n\t}\n\n\tconst resolvedAdmin = { disableListColumn: true, hidden: true } as const\n\n\tconst resolvedField: JSONField | TextField =\n\t\tresolveMode === 'schemes'\n\t\t\t? {\n\t\t\t\t\tname: `${field.name}Resolved`,\n\t\t\t\t\ttype: 'json',\n\t\t\t\t\tadmin: resolvedAdmin,\n\t\t\t\t\thooks: { afterRead: [resolveHook] },\n\t\t\t\t\tvirtual: true,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tname: `${field.name}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,SA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AAQ,IAAI,OAAO;EAClD,IAAI,CAAC,IAAI,WAAA,SAAwB,GAAG,OAAO,MAAM,GAAG;EACpD,MAAM,MAAM,qBAAqB,GAAG;EACpC,MAAM,MAAM,KAAK,OAAO,IAAI,MAAA,CAA0B;EACtD,MAAM,WAAW,KAAK,SAAS;EAC/B,IAAI;GAEH,MAAM,SAAQ,MADI,eAAe;IAAE;IAAS;IAAK,QAAQ;GAAQ,CAAC,GAChD,MAAM,WAAW,OAAO,QAAQ,GAAG;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: applyToCss(value.light, alpha, format),\n\t\t}\n\t}\n\treturn applyToCss(value, alpha, format)\n}\n"],"mappings":";;;;;AAUA,MAAM,eAAe;AACrB,MAAM,aAAa;;;;;;;AAQnB,MAAa,wBAAwB,UAA+C;CACnF,IAAI,CAAC,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC7C,MAAM,YAAY,MAAM,MAAM,cAAc,MAAM;CAClD,IAAI,cAAc,IAAI,OAAO;CAC7B,MAAM,QAAQ,UAAU,YAAY,GAAG;CACvC,IAAI,UAAU,MAAM,aAAa,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC,GAAG;EAClE,MAAM,MAAM,UAAU,MAAM,GAAG,KAAK;EACpC,IAAI,QAAQ,IAAI,OAAO;EACvB,OAAO;GAAE,OAAO,OAAO,UAAU,MAAM,QAAQ,CAAC,CAAC;GAAG,UAAU;GAAM;EAAI;CACzE;CACA,OAAO;EAAE,OAAO;EAAK,UAAU;EAAO,KAAK;CAAU;AACtD;;;;;AAMA,MAAa,wBAAwB,UAA0C;CAC9E,MAAM,QAAQ,qBAAqB,KAAK;CACxC,OAAO,QAAQ;EAAE,OAAO,MAAM;EAAO,KAAK,MAAM;CAAI,IAAI;AACzD;;AAGA,MAAa,yBAAyB,KAAa,QAAQ,QAAgB;CAC1E,MAAM,UAAU,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC;CAC5D,OAAO,YAAY,MAAM,GAAG,gBAAgB,QAAQ,GAAG,gBAAgB,IAAI,GAAG;AAC/E;;;;;;;;;AAUA,MAAa,wBACZ,OACA,WACiC;CACjC,MAAM,QAAQ,qBAAqB,KAAK;CACxC,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,CAAC,MAAM,UAAU;EACpB,MAAM,QAAQ,MAAM,IAAI,YAAY,GAAG;EACvC,MAAM,OAAO,UAAU,KAAK,KAAK,MAAM,IAAI,MAAM,QAAQ,CAAC;EAC1D,IAAI,SAAS,MAAM,WAAW,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;