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

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 (114) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +1 -1
  3. package/dist/exports/color-utils.d.ts +3 -2
  4. package/dist/exports/color-utils.js +2 -1
  5. package/dist/exports/color.d.ts +4 -2
  6. package/dist/exports/color.js +3 -1
  7. package/dist/exports/icon-adapters/radix.d.ts +2 -2
  8. package/dist/exports/icon-adapters/radix.js +2 -2
  9. package/dist/exports/icon-react.d.ts +2 -2
  10. package/dist/exports/icon.d.ts +6 -2
  11. package/dist/exports/icon.js +6 -2
  12. package/dist/fields/color/client/ColorField.js +8 -3
  13. package/dist/fields/color/client/ColorField.js.map +1 -1
  14. package/dist/fields/color/client/ColorPickerPanel.js +2 -1
  15. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  16. package/dist/fields/color/colorField.d.ts +9 -2
  17. package/dist/fields/color/colorField.js +34 -9
  18. package/dist/fields/color/colorField.js.map +1 -1
  19. package/dist/fields/color/engine/index.d.ts +2 -1
  20. package/dist/fields/color/engine/scheme.d.ts +13 -0
  21. package/dist/fields/color/engine/scheme.js +12 -0
  22. package/dist/fields/color/engine/scheme.js.map +1 -0
  23. package/dist/fields/color/options.d.ts +5 -4
  24. package/dist/fields/color/options.js.map +1 -1
  25. package/dist/fields/color/paths.d.ts +1 -0
  26. package/dist/fields/color/paths.js +32 -0
  27. package/dist/fields/color/paths.js.map +1 -0
  28. package/dist/fields/color/presetChip.js.map +1 -1
  29. package/dist/fields/color/presetsFromArray.d.ts +30 -0
  30. package/dist/fields/color/presetsFromArray.js +58 -0
  31. package/dist/fields/color/presetsFromArray.js.map +1 -0
  32. package/dist/fields/color/presetsFromDoc.js +1 -23
  33. package/dist/fields/color/presetsFromDoc.js.map +1 -1
  34. package/dist/fields/color/resolvePresets.d.ts +2 -2
  35. package/dist/fields/color/resolvePresets.js +38 -8
  36. package/dist/fields/color/resolvePresets.js.map +1 -1
  37. package/dist/fields/color/schemeValue.js +30 -0
  38. package/dist/fields/color/schemeValue.js.map +1 -0
  39. package/dist/fields/color/server/ColorCell.js +2 -2
  40. package/dist/fields/color/server/ColorCell.js.map +1 -1
  41. package/dist/fields/encrypted/queryRewrite.d.ts +1 -1
  42. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  43. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  44. package/dist/fields/icon/adapters/radix/adapter.js +7 -0
  45. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
  46. package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
  47. package/dist/fields/icon/adapters/radix/client.js +3 -2
  48. package/dist/fields/icon/adapters/radix/client.js.map +1 -1
  49. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  50. package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
  51. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
  52. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  53. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  54. package/dist/fields/icon/client/DrawerGlyph.js +34 -17
  55. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
  56. package/dist/fields/icon/client/IconDrawerContent.js +9 -45
  57. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  58. package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
  59. package/dist/fields/icon/client/IconFieldClient.js +15 -7
  60. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  61. package/dist/fields/icon/client/IconGridCell.js +67 -0
  62. package/dist/fields/icon/client/IconGridCell.js.map +1 -0
  63. package/dist/fields/icon/client/icon-field.css +8 -0
  64. package/dist/fields/icon/codegen/emit.js +5 -4
  65. package/dist/fields/icon/codegen/emit.js.map +1 -1
  66. package/dist/fields/icon/codegen/generate.js +32 -6
  67. package/dist/fields/icon/codegen/generate.js.map +1 -1
  68. package/dist/fields/icon/layers/coalesce.js +41 -0
  69. package/dist/fields/icon/layers/coalesce.js.map +1 -0
  70. package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
  71. package/dist/fields/icon/layers/manifestCache.js +49 -0
  72. package/dist/fields/icon/layers/manifestCache.js.map +1 -0
  73. package/dist/fields/icon/layers/resolve.d.ts +20 -0
  74. package/dist/fields/icon/layers/resolve.js +63 -0
  75. package/dist/fields/icon/layers/resolve.js.map +1 -0
  76. package/dist/fields/icon/layers/upload.d.ts +52 -0
  77. package/dist/fields/icon/layers/upload.js +116 -0
  78. package/dist/fields/icon/layers/upload.js.map +1 -0
  79. package/dist/fields/icon/plugin.js +24 -0
  80. package/dist/fields/icon/plugin.js.map +1 -1
  81. package/dist/fields/icon/react/createIcon.d.ts +5 -0
  82. package/dist/fields/icon/react/createIcon.js +22 -4
  83. package/dist/fields/icon/react/createIcon.js.map +1 -1
  84. package/dist/fields/icon/react/createRscIcon.js +22 -1
  85. package/dist/fields/icon/react/createRscIcon.js.map +1 -1
  86. package/dist/fields/icon/react/resolveRendered.js +21 -0
  87. package/dist/fields/icon/react/resolveRendered.js.map +1 -0
  88. package/dist/fields/icon/react/types.d.ts +15 -1
  89. package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
  90. package/dist/fields/icon/rsc/IconCell.js +12 -5
  91. package/dist/fields/icon/rsc/IconCell.js.map +1 -1
  92. package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
  93. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  94. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  95. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  96. package/dist/fields/icon/server/endpoint.d.ts +12 -0
  97. package/dist/fields/icon/server/endpoint.js +52 -0
  98. package/dist/fields/icon/server/endpoint.js.map +1 -0
  99. package/dist/fields/icon/server/manifestCache.js +9 -4
  100. package/dist/fields/icon/server/manifestCache.js.map +1 -1
  101. package/dist/fields/icon/server/resolveIconMeta.js +31 -0
  102. package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
  103. package/dist/fields/icon/server/validate.js +5 -2
  104. package/dist/fields/icon/server/validate.js.map +1 -1
  105. package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
  106. package/dist/fields/icon/shared/iconLabel.js +26 -0
  107. package/dist/fields/icon/shared/iconLabel.js.map +1 -0
  108. package/dist/fields/icon/{rsc → shared}/resolveStaticLabel.js +1 -1
  109. package/dist/fields/icon/shared/resolveStaticLabel.js.map +1 -0
  110. package/dist/index.d.ts +2 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/types.d.ts +125 -8
  113. package/package.json +9 -7
  114. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @10x-media/fields
2
2
 
3
+ ## 0.1.0-beta.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix generated icon manifests whose data disagreed with their own type annotation.
8
+
9
+ `generateIconManifest` emitted `label` in the manifest data but the emitted annotation
10
+ still described the pre-label shape, so a manifest that used the field produced one TS2353
11
+ per labelled icon in a strict consumer. The nodes module had the same latent mismatch one
12
+ field over: its annotation only allowed flat tuples while glyph nodes may nest children.
13
+
14
+ Both annotations now mirror the full contract, and the emitters are covered by tests that
15
+ typecheck their own output with the compiler rather than inspecting strings. Regenerate
16
+ your manifests to pick up the corrected annotations; the data is unchanged.
17
+
18
+ ## 0.1.0-beta.1
19
+
20
+ ### Minor Changes
21
+
22
+ - `colorField` presets can carry a light/dark pair, so one linked reference stays mode-responsive wherever it renders.
23
+
24
+ - `ColorSchemeValue` widens a preset's `value` to `string | { light, dark }`. Flat and scheme presets mix freely in one palette; a pair with one member filled in behaves as that color in both schemes.
25
+ - `linked.resolve` chooses the virtual sibling's shape: `'value'` (default) keeps it a text field, `'schemes'` makes it a JSON field carrying the pair. `linked.fallback` accepts a pair too. A field configured before this release is unaffected, and flattens to `light` if its resolver starts returning pairs.
26
+ - `presetsFromArray()` builds presets from a repeatable array field, one row per color, with flat or paired value columns.
27
+ - `lightDark()` and `isColorSchemeValue()` ship from `./color` and `./color/utils` for rendering and narrowing a resolved value.
28
+ - Scheme presets render as a diagonal split swatch in the picker, the chip, and the list cell. A non-linked field stores a scheme preset's `light` member, since a text column holds one color.
29
+ - Fixed: a list cell showed no swatch and falsely reported a missing preset whenever the resolved sibling was not a plain string.
30
+
31
+ - Icon field: library-supplied labels, fallback parity, and layered libraries.
32
+
33
+ **Fixes**
34
+
35
+ - `createIcon` rendered nothing when an adapter resolved an icon to `null`, while
36
+ `createRscIcon` returned the caller's `fallback`. The documented contract is the latter,
37
+ so both factories now honour it.
38
+ - An icon's display label could only be derived from its name, so a library keyed by code
39
+ showed `HUN` as `Hun` and a screen reader announced that for every cell.
40
+
41
+ **Added**
42
+
43
+ - `IconMeta.label` (optional, accepts a per-locale record) replaces the derived label.
44
+ Where a library supplies one, the accessible name carries the label alone and the tooltip
45
+ shows the raw name beside it, so an editor can still discover the stored value.
46
+ - `IconAdapter.resolveMeta` / `resolveMetaMany`: one exact lookup serving validation and
47
+ labels, never cached, so a runtime-backed library stays correct where a cached manifest
48
+ cannot. Lookups issued in a tick coalesce into a single batched call.
49
+ - `IconAdapter.layers`: ordered sources under one slug, later winning by name, each
50
+ declaring its own render strategy and cache policy.
51
+ - Render strategies `nodes` (with a declarable canvas), `svg` (sanitised and sprited
52
+ client-side), `url`, and `component`. `IconNode` accepts nested children.
53
+ - `uploadIconLayer`, backing a library with a Payload upload collection so editors can add
54
+ icons without a deploy. Defaults to the `url` strategy, which is inert; inlining uploaded
55
+ SVG is opt-in.
56
+ - A plugin-registered manifest endpoint at `/10x-fields/icon-manifest/:slug`, mounted only
57
+ when a server layer exists, auth-gated and availability-filtered.
58
+ - `IconRendererAdapter.layers` for frontend override resolution.
59
+ - Radix now renders from bulk node-data in the drawer instead of a dynamic import per icon.
60
+
61
+ **Possible breaking change for third-party manifests**
62
+
63
+ `generateIconManifest` no longer requires kebab-case names, which unblocks libraries keyed
64
+ by code. It does now reject two names differing only by case, because drawer search
65
+ normalises case and an editor cannot tell them apart. A hand-written manifest holding such
66
+ a pair will fail generation until one is renamed. The bundled libraries are unaffected.
67
+
68
+ Everything else is additive. An adapter that sets none of the new fields behaves exactly as
69
+ before, verified by characterization hashes over every glyph in all three bundled libraries.
70
+
3
71
  ## 0.1.0-beta.0
4
72
 
5
73
  ### Minor Changes
package/README.md CHANGED
@@ -9,7 +9,7 @@ Part of the [@10x-media Payload plugins](https://github.com/10x-media/payload-pl
9
9
  ## Features
10
10
 
11
11
  - **Color field**: saturation/hue/alpha picker, eyedropper, preset palettes (static or resolved from your data), any CSS color as input, one configured stored format (`hex`/`rgb`/`hsl`/`oklch`), and an opt-in linked mode that stores preset references so palette changes propagate everywhere.
12
- - **Icon field**: drawer browser with search, category rail, and keyboard navigation; Lucide, Radix, and Tabler adapters first-party; `defineIconAdapter()` plus codegen for any other library; per-icon lazy loading so no icon dataset ever enters an eager bundle; client and RSC frontend renderers.
12
+ - **Icon field**: drawer browser with search, category rail, and keyboard navigation; Lucide, Radix, and Tabler adapters first-party; `defineIconAdapter()` plus codegen for any other library; per-icon lazy loading so no icon dataset ever enters an eager bundle; client and RSC frontend renderers; library-supplied labels for sets keyed by code; and layered libraries composing a package with a Payload upload collection editors can add to, each layer declaring its own render strategy and caching.
13
13
  - **Encrypted fields**: AES-256-GCM with authenticated field binding, for twelve field types including `richText` and `point`; zero-config keys derived from `PAYLOAD_SECRET` or explicit multi-key config with async providers and online rotation; opt-in blind-index querying (`equals`/`in`/`unique`); masked admin UX with reveal toggle.
14
14
  - **Native by construction**: 40px rows, Payload tokens, full `admin` prop contract, typed translations (en, de), function-form `overrides` on every factory.
15
15
  - **Isolated bundles**: each family behind its own subpath export, isolation asserted on the built output in CI.
@@ -1,4 +1,4 @@
1
- import { ColorFormat } from "../types.js";
1
+ import { ColorFormat, ColorSchemeValue } from "../types.js";
2
2
  import { FormatColorOptions, Hsl, Hsv, OklchColor, ParsedColor, RgbColor } from "../fields/color/engine/types.js";
3
3
  import { contrastRatio, relativeLuminance } from "../fields/color/engine/contrast.js";
4
4
  import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb } from "../fields/color/engine/convert.js";
@@ -6,4 +6,5 @@ import { convertColor, formatColor } from "../fields/color/engine/format.js";
6
6
  import { namedColors } from "../fields/color/engine/namedColors.js";
7
7
  import { parseColor } from "../fields/color/engine/parse.js";
8
8
  import { salvageColor } from "../fields/color/engine/salvage.js";
9
- export { type ColorFormat, type FormatColorOptions, type Hsl, type Hsv, type OklchColor, type ParsedColor, type RgbColor, contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isInSrgbGamut, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
9
+ 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 };
@@ -4,4 +4,5 @@ import { parseColor } from "../fields/color/engine/parse.js";
4
4
  import { contrastRatio, relativeLuminance } from "../fields/color/engine/contrast.js";
5
5
  import { convertColor, formatColor } from "../fields/color/engine/format.js";
6
6
  import { salvageColor } from "../fields/color/engine/salvage.js";
7
- export { contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isInSrgbGamut, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
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 };
@@ -1,6 +1,8 @@
1
- import { ColorFormat, ColorGlobalConfig, ColorPreset } from "../types.js";
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 { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
3
4
  import { colorField } from "../fields/color/colorField.js";
5
+ import { PresetsFromArrayArgs, presetsFromArray } from "../fields/color/presetsFromArray.js";
4
6
  import { PresetsFromDocArgs, presetsFromDoc } from "../fields/color/presetsFromDoc.js";
5
7
  import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
6
- export { COLOR_CUSTOM_KEY, type ColorFieldClientOptions, type ColorFieldOptions, type ColorFormat, type ColorGlobalConfig, type ColorLinkedOptions, type ColorPreset, type ColorPresetsResolver, type ColorPresetsSource, PRESET_PREFIX, type PresetsFromDocArgs, type ResolvedColorPreset, colorField, normalizePresets, presetsFromDoc, resolvePresets };
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 };
@@ -1,5 +1,7 @@
1
+ import { isColorSchemeValue, lightDark } from "../fields/color/engine/scheme.js";
1
2
  import { COLOR_CUSTOM_KEY, PRESET_PREFIX } from "../fields/color/options.js";
2
3
  import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
3
4
  import { colorField } from "../fields/color/colorField.js";
5
+ import { presetsFromArray } from "../fields/color/presetsFromArray.js";
4
6
  import { presetsFromDoc } from "../fields/color/presetsFromDoc.js";
5
- export { COLOR_CUSTOM_KEY, PRESET_PREFIX, colorField, normalizePresets, presetsFromDoc, resolvePresets };
7
+ export { COLOR_CUSTOM_KEY, PRESET_PREFIX, colorField, isColorSchemeValue, lightDark, normalizePresets, presetsFromArray, presetsFromDoc, resolvePresets };
@@ -1,5 +1,5 @@
1
1
  import { IconAdapter } from "../../types.js";
2
2
  import { radixAdapter } from "../../fields/icon/adapters/radix/adapter.js";
3
- import { RadixAdapterAssets, RadixAdapterIcon } from "../../fields/icon/adapters/radix/client.js";
3
+ import { RadixAdapterAssets, RadixAdapterIcon, RadixAdapterNodes } from "../../fields/icon/adapters/radix/client.js";
4
4
  import { radixRenderer } from "../../fields/icon/adapters/radix/renderer.js";
5
- export { type IconAdapter, RadixAdapterAssets, RadixAdapterIcon, radixAdapter, radixRenderer };
5
+ export { type IconAdapter, RadixAdapterAssets, RadixAdapterIcon, RadixAdapterNodes, radixAdapter, radixRenderer };
@@ -1,4 +1,4 @@
1
1
  import { radixAdapter } from "../../fields/icon/adapters/radix/adapter.js";
2
- import { RadixAdapterAssets, RadixAdapterIcon } from "../../fields/icon/adapters/radix/client.js";
2
+ import { RadixAdapterAssets, RadixAdapterIcon, RadixAdapterNodes } from "../../fields/icon/adapters/radix/client.js";
3
3
  import { radixRenderer } from "../../fields/icon/adapters/radix/renderer.js";
4
- export { RadixAdapterAssets, RadixAdapterIcon, radixAdapter, radixRenderer };
4
+ export { RadixAdapterAssets, RadixAdapterIcon, RadixAdapterNodes, radixAdapter, radixRenderer };
@@ -1,4 +1,4 @@
1
- import { IconProps, IconRenderProps, IconRendererAdapter } from "../fields/icon/react/types.js";
1
+ import { IconProps, IconRenderProps, IconRendererAdapter, IconRendererLayer } from "../fields/icon/react/types.js";
2
2
  import { createIcon } from "../fields/icon/react/createIcon.js";
3
3
  import { createRscIcon } from "../fields/icon/react/createRscIcon.js";
4
- export { type IconProps, type IconRenderProps, type IconRendererAdapter, createIcon, createRscIcon };
4
+ export { type IconProps, type IconRenderProps, type IconRendererAdapter, type IconRendererLayer, createIcon, createRscIcon };
@@ -1,8 +1,12 @@
1
- import { IconAdapter, IconAvailabilityResolver, IconGlobalConfig, IconManifest, IconMeta } from "../types.js";
1
+ import { IconAdapter, IconAvailabilityResolver, IconCanvas, IconGlobalConfig, IconLayer, IconLayerCache, IconLayerContext, IconManifest, IconMeta, IconRenderStrategy } from "../types.js";
2
2
  import { defineIconAdapter } from "../fields/icon/defineIconAdapter.js";
3
+ import { invalidateLayerManifests } from "../fields/icon/layers/manifestCache.js";
4
+ import { loadLayeredManifest, resolveLayeredMeta } from "../fields/icon/layers/resolve.js";
5
+ import { UploadIconLayerOptions, uploadIconLayer } from "../fields/icon/layers/upload.js";
3
6
  import { resolveAvailableLibraries } from "../fields/icon/server/availability.js";
7
+ import { ICON_MANIFEST_PATH } from "../fields/icon/server/endpoint.js";
4
8
  import { IconFieldOptions, iconField } from "../fields/icon/server/iconField.js";
5
9
  import { IconLibraryFieldOptions, iconLibraryField } from "../fields/icon/server/iconLibraryField.js";
6
10
  import { getIconLibraryOptions } from "../fields/icon/server/libraryOptions.js";
7
11
  import { formatIconValue, parseIconValue, resolveIconValue } from "../fields/icon/shared/value.js";
8
- export { type IconAdapter, type IconAvailabilityResolver, type IconFieldOptions, type IconGlobalConfig, type IconLibraryFieldOptions, type IconManifest, type IconMeta, defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, parseIconValue, resolveAvailableLibraries, resolveIconValue };
12
+ export { ICON_MANIFEST_PATH, type IconAdapter, type IconAvailabilityResolver, type IconCanvas, type IconFieldOptions, type IconGlobalConfig, type IconLayer, type IconLayerCache, type IconLayerContext, type IconLibraryFieldOptions, type IconManifest, type IconMeta, type IconRenderStrategy, type UploadIconLayerOptions, defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, invalidateLayerManifests, loadLayeredManifest, parseIconValue, resolveAvailableLibraries, resolveIconValue, resolveLayeredMeta, uploadIconLayer };
@@ -1,7 +1,11 @@
1
- import { formatIconValue, parseIconValue, resolveIconValue } from "../fields/icon/shared/value.js";
1
+ import { invalidateLayerManifests } from "../fields/icon/layers/manifestCache.js";
2
+ import { loadLayeredManifest, resolveLayeredMeta } from "../fields/icon/layers/resolve.js";
2
3
  import { resolveAvailableLibraries } from "../fields/icon/server/availability.js";
4
+ import { ICON_MANIFEST_PATH } from "../fields/icon/server/endpoint.js";
5
+ import { formatIconValue, parseIconValue, resolveIconValue } from "../fields/icon/shared/value.js";
3
6
  import { getIconLibraryOptions } from "../fields/icon/server/libraryOptions.js";
4
7
  import { defineIconAdapter } from "../fields/icon/defineIconAdapter.js";
8
+ import { uploadIconLayer } from "../fields/icon/layers/upload.js";
5
9
  import { iconField } from "../fields/icon/server/iconField.js";
6
10
  import { iconLibraryField } from "../fields/icon/server/iconLibraryField.js";
7
- export { defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, parseIconValue, resolveAvailableLibraries, resolveIconValue };
11
+ export { ICON_MANIFEST_PATH, defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, invalidateLayerManifests, loadLayeredManifest, parseIconValue, resolveAvailableLibraries, resolveIconValue, resolveLayeredMeta, uploadIconLayer };
@@ -8,6 +8,7 @@ import { formatColor } from "../engine/format.js";
8
8
  import { salvageColor } from "../engine/salvage.js";
9
9
  import { PRESET_PREFIX } from "../options.js";
10
10
  import { derivePresetChip } from "../presetChip.js";
11
+ import { flatValue, swatchBackground } from "../schemeValue.js";
11
12
  import { ColorPickerPanel } from "./ColorPickerPanel.js";
12
13
  import { text } from "payload/shared";
13
14
  import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, XIcon, fieldBaseClass, useField } from "@payloadcms/ui";
@@ -47,7 +48,8 @@ const ColorField = (props) => {
47
48
  const presetKey = linked && stringValue.startsWith("preset:") ? stringValue.slice(PRESET_PREFIX.length) : null;
48
49
  const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
49
50
  const presetMissing = presetKey !== null && !activePreset;
50
- const cssValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
51
+ const rawValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
52
+ const cssValue = flatValue(rawValue);
51
53
  const parsed = useMemo(() => cssValue ? parseColor(cssValue) : null, [cssValue]);
52
54
  const [displayFormat, setDisplayFormat] = useState(format);
53
55
  const displayValue = useMemo(() => {
@@ -179,7 +181,7 @@ const ColorField = (props) => {
179
181
  };
180
182
  }, [parsed]);
181
183
  const styles = useMemo(() => mergeFieldStyles(field), [field]);
182
- const swatchCss = parsed ? formatColor(parsed, "rgb") : null;
184
+ const swatchCss = swatchBackground(rawValue);
183
185
  const swatch = /* @__PURE__ */ jsxs("span", {
184
186
  className: `${baseClass}__swatch ${baseClass}__checker`,
185
187
  children: [
@@ -248,7 +250,10 @@ const ColorField = (props) => {
248
250
  onPickCss: commitCss,
249
251
  onPickPreset: (preset) => {
250
252
  if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
251
- else commitCss(preset.value);
253
+ else {
254
+ const flat = flatValue(preset.value);
255
+ if (flat) commitCss(flat);
256
+ }
252
257
  },
253
258
  presetMissing,
254
259
  presets: resolvedPresets,
@@ -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 { 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 cssValue =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\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 = parsed ? formatColor(parsed, 'rgb') : null\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 commitCss(preset.value)\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":";;;;;;;;;;;;;;;;;;AA0BA,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,OAAO,UAAU,YAAY,UAAU;QACtC,UAAU,MAAM,WAAA,SAAwB;SACvC,MAAM,WAAA,GAAiC,OAAO,EAAE,KAAK,aAAa;IAAA,OAChE,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;GAAM;GAAU;EAAC,CAU0D;CAAE,CAAC;CAKxF,MAAM,aAAa,QAAQ,qBAAqB,YAAY,iBAAiB;CAE7E,MAAM,cAAc,OAAO,UAAU,WAAW,QAAQ;CACxD,MAAM,YACL,UAAU,YAAY,WAAA,SAAwB,IAAI,YAAY,MAAM,cAAc,MAAM,IAAI;CAC7F,MAAM,eACL,cAAc,OAAO,gB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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 { 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/>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,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"}
@@ -3,6 +3,7 @@ import { keys } from "../../../translations/keys.js";
3
3
  import { useTranslation } from "../../../translations/useTranslation.js";
4
4
  import { hsvToRgb } from "../engine/convert.js";
5
5
  import { formatColor } from "../engine/format.js";
6
+ import { swatchBackground } from "../schemeValue.js";
6
7
  import { EyedropperIcon } from "./icons.js";
7
8
  import { useCallback, useEffect, useRef, useState } from "react";
8
9
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -219,7 +220,7 @@ const ColorPickerPanel = (props) => {
219
220
  },
220
221
  title: preset.label,
221
222
  type: "button",
222
- children: /* @__PURE__ */ jsx("span", { style: { background: preset.value } })
223
+ children: /* @__PURE__ */ jsx("span", { style: { background: swatchBackground(preset.value) ?? void 0 } })
223
224
  }, preset.key))
224
225
  })
225
226
  ]
@@ -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 { 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: preset.value }} />\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":";;;;;;;;;AAUA,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,CAA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AU;gBAC3B,QAAQ,KAAK,WACb,oBAAC,UAAD;OACC,cAAY,OAAO;OACnB,gBAAc,OAAO,QAAQ;OAC7B,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,OAAO,MAAM,EAAI,CAAA;MACrC,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 { 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;EAAG,GAAG;CAAE,CAAC;CAC5E,MAAM,UAAU,OAAO,IAAI;CAC3B,QAAQ,UAAU;CAClB,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,QAAQ,OAAuB,IAAI;CACzC,MAAM,SAAS,OAAsB,IAAI;CACzC,MAAM,aAAa,OAAoB,IAAI;CAC3C,MAAM,iBAAiB,OAAsB,IAAI;CAIjD,gBAAgB;EACf,IAAI,CAAC,SAAS;GACb,eAAe,UAAU;GACzB;EACD;EACA,IAAI,YAAY,SAAS;EAOzB,MAAM,OAJc,YACnB,SAAS;GAAE,GAAG,QAAQ;GAAG,GAAG,QAA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AU;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;OAC7B,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"}
@@ -1,5 +1,5 @@
1
1
  import { ColorFieldOptions, ColorLinkedOptions } from "./options.js";
2
- import { TextField } from "payload";
2
+ import { JSONField, TextField } from "payload";
3
3
 
4
4
  //#region src/fields/color/colorField.d.ts
5
5
  /**
@@ -13,8 +13,15 @@ declare function colorField(options?: ColorFieldOptions & {
13
13
  linked?: false;
14
14
  }): TextField;
15
15
  declare function colorField(options: ColorFieldOptions & {
16
- linked: ColorLinkedOptions | true;
16
+ linked: (ColorLinkedOptions & {
17
+ resolve?: 'value';
18
+ }) | true;
17
19
  }): [TextField, TextField];
20
+ declare function colorField(options: ColorFieldOptions & {
21
+ linked: ColorLinkedOptions & {
22
+ resolve: 'schemes';
23
+ };
24
+ }): [TextField, JSONField];
18
25
  //#endregion
19
26
  export { colorField };
20
27
  //# sourceMappingURL=colorField.d.ts.map
@@ -1,7 +1,9 @@
1
1
  import { keys } from "../../translations/keys.js";
2
2
  import { parseColor } from "./engine/parse.js";
3
3
  import { formatColor } from "./engine/format.js";
4
+ import { isColorSchemeValue } from "./engine/scheme.js";
4
5
  import { COLOR_CUSTOM_KEY, PRESET_PREFIX } from "./options.js";
6
+ import { flatValue } from "./schemeValue.js";
5
7
  import { asTranslate } from "../../translations/server.js";
6
8
  import { resolveColorFormat } from "./resolveFormat.js";
7
9
  import { resolvePresets } from "./resolvePresets.js";
@@ -25,7 +27,9 @@ const buildNormalizeHook = (opts) => ({ req, value }) => {
25
27
  function colorField(options = {}) {
26
28
  const { name = "color", alpha = true, enableEyedropper = true, format, isClearable = true, label, linked: linkedOption = false, localized, overrides, presets, presetsLabel, required } = options;
27
29
  const linked = linkedOption !== false;
28
- const linkedFallback = typeof linkedOption === "object" ? linkedOption.fallback ?? null : null;
30
+ const linkedOptions = typeof linkedOption === "object" ? linkedOption : {};
31
+ const linkedFallback = linkedOptions.fallback ?? null;
32
+ const resolveMode = linkedOptions.resolve ?? "value";
29
33
  const memoKey = Symbol(`colorField:${name}`);
30
34
  const clientOptions = {
31
35
  alpha,
@@ -64,10 +68,24 @@ function colorField(options = {}) {
64
68
  const field = typeof overrides === "function" ? overrides({ field: base }) : base;
65
69
  if (!linked) return field;
66
70
  const loggedRequests = /* @__PURE__ */ new WeakSet();
71
+ /**
72
+ * Shapes a resolved value for the configured sibling. 'value' flattens a
73
+ * scheme to its light member so a field configured before schemes existed
74
+ * keeps working when its resolver starts returning them; 'schemes' inflates
75
+ * a flat color so consumers never branch on the shape.
76
+ */
77
+ const shape = (value) => {
78
+ if (value === null) return null;
79
+ if (resolveMode === "value") return flatValue(value);
80
+ return isColorSchemeValue(value) ? value : {
81
+ dark: value,
82
+ light: value
83
+ };
84
+ };
67
85
  const resolveHook = async ({ collection, global, req, siblingData }) => {
68
86
  const raw = siblingData?.[field.name];
69
87
  if (typeof raw !== "string" || raw === "") return null;
70
- if (!raw.startsWith("preset:")) return raw;
88
+ if (!raw.startsWith("preset:")) return shape(raw);
71
89
  const key = raw.slice(PRESET_PREFIX.length);
72
90
  try {
73
91
  const match = (await resolvePresets({
@@ -75,23 +93,30 @@ function colorField(options = {}) {
75
93
  req,
76
94
  source: presets
77
95
  })).find((preset) => preset.key === key);
78
- return match ? match.value : linkedFallback;
96
+ return shape(match ? match.value : linkedFallback);
79
97
  } catch (error) {
80
98
  if (!loggedRequests.has(req)) {
81
99
  loggedRequests.add(req);
82
100
  const slug = collection?.slug ?? global?.slug ?? "unknown";
83
101
  req.payload.logger.error({ err: error }, `colorField preset resolver failed for ${slug}.${field.name}`);
84
102
  }
85
- return linkedFallback;
103
+ return shape(linkedFallback);
86
104
  }
87
105
  };
88
- return [field, {
106
+ const resolvedAdmin = {
107
+ disableListColumn: true,
108
+ hidden: true
109
+ };
110
+ return [field, resolveMode === "schemes" ? {
111
+ name: `${field.name}Resolved`,
112
+ type: "json",
113
+ admin: resolvedAdmin,
114
+ hooks: { afterRead: [resolveHook] },
115
+ virtual: true
116
+ } : {
89
117
  name: `${field.name}Resolved`,
90
118
  type: "text",
91
- admin: {
92
- disableListColumn: true,
93
- hidden: true
94
- },
119
+ admin: resolvedAdmin,
95
120
  hooks: { afterRead: [resolveHook] },
96
121
  virtual: true
97
122
  }];
@@ -1 +1 @@
1
- {"version":3,"file":"colorField.js","names":[],"sources":["../../../src/fields/color/colorField.ts"],"sourcesContent":["import type { FieldHook, PayloadRequest, TextField, TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport type { ColorFormat } from '../../types'\nimport { formatColor, 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'\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 | true }\n): [TextField, TextField]\nexport function colorField(options: ColorFieldOptions = {}): TextField | [TextField, 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 linkedFallback = typeof linkedOption === 'object' ? (linkedOption.fallback ?? null) : null\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\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 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 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 linkedFallback\n\t\t}\n\t}\n\n\tconst resolvedField: TextField = {\n\t\tname: `${field.name}Resolved`,\n\t\ttype: 'text',\n\t\tadmin: { disableListColumn: true, hidden: true },\n\t\thooks: { afterRead: [resolveHook] },\n\t\tvirtual: true,\n\t}\n\n\treturn [field, resolvedField]\n}\n"],"mappings":";;;;;;;;;AAiBA,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;AA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MAAM;EAC1C,IAAI;GAEH,MAAM,SAAQ,MADI,eAAe;IAAE;IAAS;IAAK,QAAQ;GAAQ,CAAC,GAChD,MAAM,WAAW,OAAO,QAAQ,GAAG;GACrD,OAAO,QAAQ,MAAM,QAAQ;EAC9B,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;EACR;CACD;CAUA,OAAO,CAAC,OAAO;EAPd,MAAM,GAAG,MAAM,KAAK;EACpB,MAAM;EACN,OAAO;GAAE,mBAAmB;GAAM,QAAQ;EAAK;EAC/C,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CAGiB,CAAC;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\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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M,KAAK;EACpB,MAAM;EACN,OAAO;EACP,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE;EAClC,SAAS;CACV,CAEyB;AAC7B"}
@@ -5,4 +5,5 @@ import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbT
5
5
  import { convertColor, formatColor } from "./format.js";
6
6
  import { namedColors } from "./namedColors.js";
7
7
  import { parseColor } from "./parse.js";
8
- import { salvageColor } from "./salvage.js";
8
+ import { salvageColor } from "./salvage.js";
9
+ import { isColorSchemeValue, lightDark } from "./scheme.js";
@@ -0,0 +1,13 @@
1
+ import { ColorSchemeValue } from "../../../types.js";
2
+
3
+ //#region src/fields/color/engine/scheme.d.ts
4
+ /** Narrows the preset and resolved-value unions to a scheme-aware color. */
5
+ declare const isColorSchemeValue: (value: unknown) => value is ColorSchemeValue;
6
+ /**
7
+ * CSS for a scheme-aware color. Flat strings pass through unchanged. The
8
+ * two-argument form needs `color-scheme` set on the element to resolve.
9
+ */
10
+ declare const lightDark: (value: ColorSchemeValue | string) => string;
11
+ //#endregion
12
+ export { isColorSchemeValue, lightDark };
13
+ //# sourceMappingURL=scheme.d.ts.map