@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
@@ -0,0 +1,12 @@
1
+ //#region src/fields/color/engine/scheme.ts
2
+ /** Narrows the preset and resolved-value unions to a scheme-aware color. */
3
+ const isColorSchemeValue = (value) => typeof value === "object" && value !== null && typeof value.light === "string" && typeof value.dark === "string";
4
+ /**
5
+ * CSS for a scheme-aware color. Flat strings pass through unchanged. The
6
+ * two-argument form needs `color-scheme` set on the element to resolve.
7
+ */
8
+ const lightDark = (value) => isColorSchemeValue(value) ? `light-dark(${value.light}, ${value.dark})` : value;
9
+ //#endregion
10
+ export { isColorSchemeValue, lightDark };
11
+
12
+ //# sourceMappingURL=scheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheme.js","names":[],"sources":["../../../../src/fields/color/engine/scheme.ts"],"sourcesContent":["import type { ColorSchemeValue } from '../../../types'\n\n/** Narrows the preset and resolved-value unions to a scheme-aware color. */\nexport const isColorSchemeValue = (value: unknown): value is ColorSchemeValue =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\ttypeof (value as Partial<ColorSchemeValue>).light === 'string' &&\n\ttypeof (value as Partial<ColorSchemeValue>).dark === 'string'\n\n/**\n * CSS for a scheme-aware color. Flat strings pass through unchanged. The\n * two-argument form needs `color-scheme` set on the element to resolve.\n */\nexport const lightDark = (value: ColorSchemeValue | string): string =>\n\tisColorSchemeValue(value) ? `light-dark(${value.light}, ${value.dark})` : value\n"],"mappings":";;AAGA,MAAa,sBAAsB,UAClC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAoC,UAAU,YACtD,OAAQ,MAAoC,SAAS;;;;;AAMtD,MAAa,aAAa,UACzB,mBAAmB,KAAK,IAAI,cAAc,MAAM,MAAM,IAAI,MAAM,KAAK,KAAK"}
@@ -1,4 +1,4 @@
1
- import { ColorFormat, ColorPreset, FieldsResolverArgs } from "../../types.js";
1
+ import { ColorFormat, ColorPreset, ColorSchemeValue, FieldsResolverArgs } from "../../types.js";
2
2
  import { StaticLabel, TextField } from "payload";
3
3
 
4
4
  //#region src/fields/color/options.d.ts
@@ -8,7 +8,8 @@ declare const COLOR_CUSTOM_KEY = "@10x-media/fields";
8
8
  type ColorPresetsResolver = (args: FieldsResolverArgs) => Promise<ColorPreset[]>;
9
9
  type ColorPresetsSource = ColorPreset[] | ColorPresetsResolver;
10
10
  type ColorLinkedOptions = {
11
- /** Resolved value when a stored preset reference no longer exists. Defaults to null. */fallback?: null | string;
11
+ /** Resolved value when a stored preset reference no longer exists. Defaults to null. */fallback?: null | string | ColorSchemeValue; /** Shape of the virtual sibling. 'value' emits text, 'schemes' emits json. Defaults to 'value'. */
12
+ resolve?: 'schemes' | 'value';
12
13
  };
13
14
  type ColorFieldOptions = {
14
15
  name?: string;
@@ -33,7 +34,7 @@ type ColorFieldClientOptions = {
33
34
  format: ColorFormat;
34
35
  isClearable: boolean;
35
36
  linked: boolean;
36
- linkedFallback: null | string;
37
+ linkedFallback: null | string | ColorSchemeValue;
37
38
  };
38
39
  /**
39
40
  * clientProps shape the factory hands to `ColorFieldServer`. `format` stays the
@@ -48,7 +49,7 @@ type ColorFieldServerOptions = Omit<ColorFieldClientOptions, 'format'> & {
48
49
  type ResolvedColorPreset = {
49
50
  key: string;
50
51
  label: string;
51
- value: string;
52
+ value: string | ColorSchemeValue;
52
53
  };
53
54
  //#endregion
54
55
  export { COLOR_CUSTOM_KEY, ColorFieldClientOptions, ColorFieldOptions, ColorFieldServerOptions, ColorLinkedOptions, ColorPresetsResolver, ColorPresetsSource, PRESET_PREFIX, ResolvedColorPreset };
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","names":[],"sources":["../../../src/fields/color/options.ts"],"sourcesContent":["import type { StaticLabel, TextField } from 'payload'\nimport type { ColorFormat, ColorPreset, FieldsResolverArgs } from '../../types'\n\nexport const PRESET_PREFIX = 'preset:'\n\n/** Key under `field.custom` carrying server-only color config (may contain functions). */\nexport const COLOR_CUSTOM_KEY = '@10x-media/fields'\n\nexport type ColorPresetsResolver = (args: FieldsResolverArgs) => Promise<ColorPreset[]>\nexport type ColorPresetsSource = ColorPreset[] | ColorPresetsResolver\n\nexport type ColorLinkedOptions = {\n\t/** Resolved value when a stored preset reference no longer exists. Defaults to null. */\n\tfallback?: null | string\n}\n\nexport type ColorFieldOptions = {\n\tname?: string\n\tlabel?: TextField['label']\n\trequired?: boolean\n\tlocalized?: boolean\n\t/** Stored format. Any parseable CSS input is normalized to this. Default 'hex'. */\n\tformat?: ColorFormat\n\t/** Default true. False hides the opacity slider and strips alpha on write. */\n\talpha?: boolean\n\tpresets?: ColorPresetsSource\n\tpresetsLabel?: StaticLabel\n\tlinked?: boolean | ColorLinkedOptions\n\t/** Default true. False removes the inline clear control; required fields never render it. */\n\tisClearable?: boolean\n\t/** Default true. Chromium EyeDropper API, feature-detected at runtime. */\n\tenableEyedropper?: boolean\n\toverrides?: (args: { field: TextField }) => TextField\n}\n\n/** Serializable subset shipped to the admin client via clientProps. */\nexport type ColorFieldClientOptions = {\n\talpha: boolean\n\tenableEyedropper: boolean\n\tformat: ColorFormat\n\tisClearable: boolean\n\tlinked: boolean\n\tlinkedFallback: null | string\n}\n\n/**\n * clientProps shape the factory hands to `ColorFieldServer`. `format` stays the\n * field-level value (possibly unset) so the server can resolve the effective\n * format against the plugin registry per request before handing the client a\n * concrete `ColorFieldClientOptions`.\n */\nexport type ColorFieldServerOptions = Omit<ColorFieldClientOptions, 'format'> & {\n\tformat?: ColorFormat\n}\n\n/** Preset with its label resolved to a plain string, safe for clientProps. */\nexport type ResolvedColorPreset = { key: string; label: string; value: string }\n\nexport type ColorFieldCustom = {\n\tmemoKey: symbol\n\tpresets?: ColorPresetsSource\n\tpresetsLabel?: StaticLabel\n}\n"],"mappings":";AAGA,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB"}
1
+ {"version":3,"file":"options.js","names":[],"sources":["../../../src/fields/color/options.ts"],"sourcesContent":["import type { StaticLabel, TextField } from 'payload'\nimport type { ColorFormat, ColorPreset, ColorSchemeValue, FieldsResolverArgs } from '../../types'\n\nexport const PRESET_PREFIX = 'preset:'\n\n/** Key under `field.custom` carrying server-only color config (may contain functions). */\nexport const COLOR_CUSTOM_KEY = '@10x-media/fields'\n\nexport type ColorPresetsResolver = (args: FieldsResolverArgs) => Promise<ColorPreset[]>\nexport type ColorPresetsSource = ColorPreset[] | ColorPresetsResolver\n\nexport type ColorLinkedOptions = {\n\t/** Resolved value when a stored preset reference no longer exists. Defaults to null. */\n\tfallback?: null | string | ColorSchemeValue\n\t/** Shape of the virtual sibling. 'value' emits text, 'schemes' emits json. Defaults to 'value'. */\n\tresolve?: 'schemes' | 'value'\n}\n\nexport type ColorFieldOptions = {\n\tname?: string\n\tlabel?: TextField['label']\n\trequired?: boolean\n\tlocalized?: boolean\n\t/** Stored format. Any parseable CSS input is normalized to this. Default 'hex'. */\n\tformat?: ColorFormat\n\t/** Default true. False hides the opacity slider and strips alpha on write. */\n\talpha?: boolean\n\tpresets?: ColorPresetsSource\n\tpresetsLabel?: StaticLabel\n\tlinked?: boolean | ColorLinkedOptions\n\t/** Default true. False removes the inline clear control; required fields never render it. */\n\tisClearable?: boolean\n\t/** Default true. Chromium EyeDropper API, feature-detected at runtime. */\n\tenableEyedropper?: boolean\n\toverrides?: (args: { field: TextField }) => TextField\n}\n\n/** Serializable subset shipped to the admin client via clientProps. */\nexport type ColorFieldClientOptions = {\n\talpha: boolean\n\tenableEyedropper: boolean\n\tformat: ColorFormat\n\tisClearable: boolean\n\tlinked: boolean\n\tlinkedFallback: null | string | ColorSchemeValue\n}\n\n/**\n * clientProps shape the factory hands to `ColorFieldServer`. `format` stays the\n * field-level value (possibly unset) so the server can resolve the effective\n * format against the plugin registry per request before handing the client a\n * concrete `ColorFieldClientOptions`.\n */\nexport type ColorFieldServerOptions = Omit<ColorFieldClientOptions, 'format'> & {\n\tformat?: ColorFormat\n}\n\n/** Preset with its label resolved to a plain string, safe for clientProps. */\nexport type ResolvedColorPreset = { key: string; label: string; value: string | ColorSchemeValue }\n\nexport type ColorFieldCustom = {\n\tmemoKey: symbol\n\tpresets?: ColorPresetsSource\n\tpresetsLabel?: StaticLabel\n}\n"],"mappings":";AAGA,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,32 @@
1
+ //#region src/fields/color/paths.ts
2
+ /**
3
+ * Rows, collapsibles, and unnamed tabs are already inlined by Payload's
4
+ * flattening, so each dot segment only ever names a data field or a named
5
+ * container (group, named tab, array) carrying nested flattenedFields.
6
+ */
7
+ const findNamedField = (fields, path) => {
8
+ let scope = fields;
9
+ let found;
10
+ for (const segment of path.split(".")) {
11
+ found = scope?.find((field) => field.name === segment);
12
+ if (!found) return void 0;
13
+ scope = "flattenedFields" in found ? found.flattenedFields : void 0;
14
+ }
15
+ return found;
16
+ };
17
+ /**
18
+ * Walks a dot path over doc data. The array guard rejects indexing *into* an
19
+ * array, so a path ending at an array field still returns the array itself.
20
+ */
21
+ const readPath = (doc, path) => {
22
+ let value = doc;
23
+ for (const segment of path.split(".")) {
24
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
25
+ value = value[segment];
26
+ }
27
+ return value;
28
+ };
29
+ //#endregion
30
+ export { findNamedField, readPath };
31
+
32
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","names":[],"sources":["../../../src/fields/color/paths.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\n/**\n * Rows, collapsibles, and unnamed tabs are already inlined by Payload's\n * flattening, so each dot segment only ever names a data field or a named\n * container (group, named tab, array) carrying nested flattenedFields.\n */\nexport const findNamedField = (\n\tfields: FlattenedField[] | undefined,\n\tpath: string\n): FlattenedField | undefined => {\n\tlet scope = fields\n\tlet found: FlattenedField | undefined\n\tfor (const segment of path.split('.')) {\n\t\tfound = scope?.find((field) => field.name === segment)\n\t\tif (!found) return undefined\n\t\tscope = 'flattenedFields' in found ? found.flattenedFields : undefined\n\t}\n\treturn found\n}\n\n/**\n * Walks a dot path over doc data. The array guard rejects indexing *into* an\n * array, so a path ending at an array field still returns the array itself.\n */\nexport const readPath = (doc: Record<string, unknown>, path: string): unknown => {\n\tlet value: unknown = doc\n\tfor (const segment of path.split('.')) {\n\t\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n\t\tvalue = (value as Record<string, unknown>)[segment]\n\t}\n\treturn value\n}\n"],"mappings":";;;;;;AAOA,MAAa,kBACZ,QACA,SACgC;CAChC,IAAI,QAAQ;CACZ,IAAI;CACJ,KAAK,MAAM,WAAW,KAAK,MAAM,GAAG,GAAG;EACtC,QAAQ,OAAO,MAAM,UAAU,MAAM,SAAS,OAAO;EACrD,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,QAAQ,qBAAqB,QAAQ,MAAM,kBAAkB,KAAA;CAC9D;CACA,OAAO;AACR;;;;;AAMA,MAAa,YAAY,KAA8B,SAA0B;CAChF,IAAI,QAAiB;CACrB,KAAK,MAAM,WAAW,KAAK,MAAM,GAAG,GAAG;EACtC,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO,KAAA;EAChF,QAAS,MAAkC;CAC5C;CACA,OAAO;AACR"}
@@ -1 +1 @@
1
- {"version":3,"file":"presetChip.js","names":[],"sources":["../../../src/fields/color/presetChip.ts"],"sourcesContent":["import { PRESET_PREFIX, type ResolvedColorPreset } from './options'\n\nexport type PresetChip = {\n\tkey: string\n\tlabel: string\n\tmissing: boolean\n\tvalue: null | string\n}\n\n/**\n * Derives the chip shown in place of a raw `preset:<key>` ref in the color\n * input. Returns null outside chip mode: non-linked fields, active text\n * editing, non-ref values, or an empty key (which validate rejects anyway).\n * A ref whose key no longer resolves still chips (missing: true, label falls\n * back to the key) so the stored ref stays visible without leaking raw text.\n */\nexport const derivePresetChip = (args: {\n\tediting: boolean\n\tlinked: boolean\n\tpresets: ResolvedColorPreset[]\n\tvalue: unknown\n}): null | PresetChip => {\n\tconst { editing, linked, presets, value } = args\n\tif (!linked || editing) return null\n\tif (typeof value !== 'string' || !value.startsWith(PRESET_PREFIX)) return null\n\tconst key = value.slice(PRESET_PREFIX.length)\n\tif (key === '') return null\n\tconst preset = presets.find((entry) => entry.key === key)\n\treturn {\n\t\tkey,\n\t\tlabel: preset?.label ?? key,\n\t\tmissing: !preset,\n\t\tvalue: preset?.value ?? null,\n\t}\n}\n"],"mappings":";;;;;;;;;AAgBA,MAAa,oBAAoB,SAKR;CACxB,MAAM,EAAE,SAAS,QAAQ,SAAS,UAAU;CAC5C,IAAI,CAAC,UAAU,SAAS,OAAO;CAC/B,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC1E,MAAM,MAAM,MAAM,MAAM,cAAc,MAAM;CAC5C,IAAI,QAAQ,IAAI,OAAO;CACvB,MAAM,SAAS,QAAQ,MAAM,UAAU,MAAM,QAAQ,GAAG;CACxD,OAAO;EACN;EACA,OAAO,QAAQ,SAAS;EACxB,SAAS,CAAC;EACV,OAAO,QAAQ,SAAS;CACzB;AACD"}
1
+ {"version":3,"file":"presetChip.js","names":[],"sources":["../../../src/fields/color/presetChip.ts"],"sourcesContent":["import type { ColorSchemeValue } from '../../types'\nimport { PRESET_PREFIX, type ResolvedColorPreset } from './options'\n\nexport type PresetChip = {\n\tkey: string\n\tlabel: string\n\tmissing: boolean\n\tvalue: null | string | ColorSchemeValue\n}\n\n/**\n * Derives the chip shown in place of a raw `preset:<key>` ref in the color\n * input. Returns null outside chip mode: non-linked fields, active text\n * editing, non-ref values, or an empty key (which validate rejects anyway).\n * A ref whose key no longer resolves still chips (missing: true, label falls\n * back to the key) so the stored ref stays visible without leaking raw text.\n */\nexport const derivePresetChip = (args: {\n\tediting: boolean\n\tlinked: boolean\n\tpresets: ResolvedColorPreset[]\n\tvalue: unknown\n}): null | PresetChip => {\n\tconst { editing, linked, presets, value } = args\n\tif (!linked || editing) return null\n\tif (typeof value !== 'string' || !value.startsWith(PRESET_PREFIX)) return null\n\tconst key = value.slice(PRESET_PREFIX.length)\n\tif (key === '') return null\n\tconst preset = presets.find((entry) => entry.key === key)\n\treturn {\n\t\tkey,\n\t\tlabel: preset?.label ?? key,\n\t\tmissing: !preset,\n\t\tvalue: preset?.value ?? null,\n\t}\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAa,oBAAoB,SAKR;CACxB,MAAM,EAAE,SAAS,QAAQ,SAAS,UAAU;CAC5C,IAAI,CAAC,UAAU,SAAS,OAAO;CAC/B,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAA,SAAwB,GAAG,OAAO;CAC1E,MAAM,MAAM,MAAM,MAAM,cAAc,MAAM;CAC5C,IAAI,QAAQ,IAAI,OAAO;CACvB,MAAM,SAAS,QAAQ,MAAM,UAAU,MAAM,QAAQ,GAAG;CACxD,OAAO;EACN;EACA,OAAO,QAAQ,SAAS;EACxB,SAAS,CAAC;EACV,OAAO,QAAQ,SAAS;CACzB;AACD"}
@@ -0,0 +1,30 @@
1
+ import { ColorPreset } from "../../types.js";
2
+
3
+ //#region src/fields/color/presetsFromArray.d.ts
4
+ type PresetsFromArrayArgs = {
5
+ /** The fetched doc holding the array. */doc: Record<string, unknown>; /** Row field holding the stable key. */
6
+ key: string; /** Prepended to every preset key, e.g. `${tenant.slug}/` to namespace per doc. */
7
+ keyPrefix?: string; /** Row field holding the label. Falls back to the unprefixed key. */
8
+ label?: string; /** Dot path to the array field. Reaches into groups and named tabs. */
9
+ path: string; /** Row field holding the value, or the pair of row fields holding light and dark. */
10
+ value: string | {
11
+ light: string;
12
+ dark: string;
13
+ };
14
+ };
15
+ /**
16
+ * Lifts an array field's rows into linked-mode presets, which is how a
17
+ * repeatable brand palette is authored. Unlike `presetsFromDoc` it needs no
18
+ * `req` or `collection`: keys and labels come from row data rather than field
19
+ * config, so there is nothing to look up or localize.
20
+ *
21
+ * Rows are skipped when the key is missing, non-string or empty, when the value
22
+ * fields yield nothing usable, and when a value already carries `PRESET_PREFIX`.
23
+ * A scheme pair with one member present becomes that color in both schemes,
24
+ * matching how every other layer treats a half-filled value. On duplicate keys
25
+ * the first row wins, so callers generating keys must keep them unique.
26
+ */
27
+ declare const presetsFromArray: (args: PresetsFromArrayArgs) => ColorPreset[];
28
+ //#endregion
29
+ export { PresetsFromArrayArgs, presetsFromArray };
30
+ //# sourceMappingURL=presetsFromArray.d.ts.map
@@ -0,0 +1,58 @@
1
+ import "./options.js";
2
+ import { readPath } from "./paths.js";
3
+ //#region src/fields/color/presetsFromArray.ts
4
+ const rowString = (row, field) => {
5
+ const value = row[field];
6
+ if (typeof value !== "string" || value === "" || value.startsWith("preset:")) return null;
7
+ return value;
8
+ };
9
+ /**
10
+ * Lifts an array field's rows into linked-mode presets, which is how a
11
+ * repeatable brand palette is authored. Unlike `presetsFromDoc` it needs no
12
+ * `req` or `collection`: keys and labels come from row data rather than field
13
+ * config, so there is nothing to look up or localize.
14
+ *
15
+ * Rows are skipped when the key is missing, non-string or empty, when the value
16
+ * fields yield nothing usable, and when a value already carries `PRESET_PREFIX`.
17
+ * A scheme pair with one member present becomes that color in both schemes,
18
+ * matching how every other layer treats a half-filled value. On duplicate keys
19
+ * the first row wins, so callers generating keys must keep them unique.
20
+ */
21
+ const presetsFromArray = (args) => {
22
+ const { doc, key, keyPrefix = "", label, path, value } = args;
23
+ const rows = readPath(doc, path);
24
+ if (!Array.isArray(rows)) return [];
25
+ const presets = [];
26
+ const seen = /* @__PURE__ */ new Set();
27
+ for (const entry of rows) {
28
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) continue;
29
+ const row = entry;
30
+ const rawKey = row[key];
31
+ if (typeof rawKey !== "string" || rawKey === "") continue;
32
+ const presetKey = `${keyPrefix}${rawKey}`;
33
+ if (seen.has(presetKey)) continue;
34
+ let presetValue;
35
+ if (typeof value === "string") presetValue = rowString(row, value) ?? void 0;
36
+ else {
37
+ const light = rowString(row, value.light);
38
+ const dark = rowString(row, value.dark);
39
+ if (light || dark) presetValue = {
40
+ dark: dark ?? light,
41
+ light: light ?? dark
42
+ };
43
+ }
44
+ if (presetValue === void 0) continue;
45
+ seen.add(presetKey);
46
+ const rowLabel = label === void 0 ? void 0 : row[label];
47
+ presets.push({
48
+ key: presetKey,
49
+ label: typeof rowLabel === "string" && rowLabel !== "" ? rowLabel : rawKey,
50
+ value: presetValue
51
+ });
52
+ }
53
+ return presets;
54
+ };
55
+ //#endregion
56
+ export { presetsFromArray };
57
+
58
+ //# sourceMappingURL=presetsFromArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presetsFromArray.js","names":[],"sources":["../../../src/fields/color/presetsFromArray.ts"],"sourcesContent":["import type { ColorPreset } from '../../types'\nimport { PRESET_PREFIX } from './options'\nimport { readPath } from './paths'\n\nexport type PresetsFromArrayArgs = {\n\t/** The fetched doc holding the array. */\n\tdoc: Record<string, unknown>\n\t/** Row field holding the stable key. */\n\tkey: string\n\t/** Prepended to every preset key, e.g. `${tenant.slug}/` to namespace per doc. */\n\tkeyPrefix?: string\n\t/** Row field holding the label. Falls back to the unprefixed key. */\n\tlabel?: string\n\t/** Dot path to the array field. Reaches into groups and named tabs. */\n\tpath: string\n\t/** Row field holding the value, or the pair of row fields holding light and dark. */\n\tvalue: string | { light: string; dark: string }\n}\n\nconst rowString = (row: Record<string, unknown>, field: string): null | string => {\n\tconst value = row[field]\n\tif (typeof value !== 'string' || value === '' || value.startsWith(PRESET_PREFIX)) return null\n\treturn value\n}\n\n/**\n * Lifts an array field's rows into linked-mode presets, which is how a\n * repeatable brand palette is authored. Unlike `presetsFromDoc` it needs no\n * `req` or `collection`: keys and labels come from row data rather than field\n * config, so there is nothing to look up or localize.\n *\n * Rows are skipped when the key is missing, non-string or empty, when the value\n * fields yield nothing usable, and when a value already carries `PRESET_PREFIX`.\n * A scheme pair with one member present becomes that color in both schemes,\n * matching how every other layer treats a half-filled value. On duplicate keys\n * the first row wins, so callers generating keys must keep them unique.\n */\nexport const presetsFromArray = (args: PresetsFromArrayArgs): ColorPreset[] => {\n\tconst { doc, key, keyPrefix = '', label, path, value } = args\n\tconst rows = readPath(doc, path)\n\tif (!Array.isArray(rows)) return []\n\n\tconst presets: ColorPreset[] = []\n\tconst seen = new Set<string>()\n\n\tfor (const entry of rows) {\n\t\tif (entry === null || typeof entry !== 'object' || Array.isArray(entry)) continue\n\t\tconst row = entry as Record<string, unknown>\n\n\t\tconst rawKey = row[key]\n\t\tif (typeof rawKey !== 'string' || rawKey === '') continue\n\t\tconst presetKey = `${keyPrefix}${rawKey}`\n\t\tif (seen.has(presetKey)) continue\n\n\t\tlet presetValue: undefined | string | { dark: string; light: string }\n\t\tif (typeof value === 'string') {\n\t\t\tpresetValue = rowString(row, value) ?? undefined\n\t\t} else {\n\t\t\tconst light = rowString(row, value.light)\n\t\t\tconst dark = rowString(row, value.dark)\n\t\t\tif (light || dark) {\n\t\t\t\tpresetValue = { dark: dark ?? (light as string), light: light ?? (dark as string) }\n\t\t\t}\n\t\t}\n\t\tif (presetValue === undefined) continue\n\n\t\tseen.add(presetKey)\n\t\tconst rowLabel = label === undefined ? undefined : row[label]\n\t\tpresets.push({\n\t\t\tkey: presetKey,\n\t\t\tlabel: typeof rowLabel === 'string' && rowLabel !== '' ? rowLabel : rawKey,\n\t\t\tvalue: presetValue,\n\t\t})\n\t}\n\n\treturn presets\n}\n"],"mappings":";;;AAmBA,MAAM,aAAa,KAA8B,UAAiC;CACjF,MAAM,QAAQ,IAAI;CAClB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,WAAA,SAAwB,GAAG,OAAO;CACzF,OAAO;AACR;;;;;;;;;;;;;AAcA,MAAa,oBAAoB,SAA8C;CAC9E,MAAM,EAAE,KAAK,KAAK,YAAY,IAAI,OAAO,MAAM,UAAU;CACzD,MAAM,OAAO,SAAS,KAAK,IAAI;CAC/B,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO,CAAC;CAElC,MAAM,UAAyB,CAAC;CAChC,MAAM,uBAAO,IAAI,IAAY;CAE7B,KAAK,MAAM,SAAS,MAAM;EACzB,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;EACzE,MAAM,MAAM;EAEZ,MAAM,SAAS,IAAI;EACnB,IAAI,OAAO,WAAW,YAAY,WAAW,IAAI;EACjD,MAAM,YAAY,GAAG,YAAY;EACjC,IAAI,KAAK,IAAI,SAAS,GAAG;EAEzB,IAAI;EACJ,IAAI,OAAO,UAAU,UACpB,cAAc,UAAU,KAAK,KAAK,KAAK,KAAA;OACjC;GACN,MAAM,QAAQ,UAAU,KAAK,MAAM,KAAK;GACxC,MAAM,OAAO,UAAU,KAAK,MAAM,IAAI;GACtC,IAAI,SAAS,MACZ,cAAc;IAAE,MAAM,QAAS;IAAkB,OAAO,SAAU;GAAgB;EAEpF;EACA,IAAI,gBAAgB,KAAA,GAAW;EAE/B,KAAK,IAAI,SAAS;EAClB,MAAM,WAAW,UAAU,KAAA,IAAY,KAAA,IAAY,IAAI;EACvD,QAAQ,KAAK;GACZ,KAAK;GACL,OAAO,OAAO,aAAa,YAAY,aAAa,KAAK,WAAW;GACpE,OAAO;EACR,CAAC;CACF;CAEA,OAAO;AACR"}
@@ -1,29 +1,7 @@
1
1
  import "./options.js";
2
+ import { findNamedField, readPath } from "./paths.js";
2
3
  //#region src/fields/color/presetsFromDoc.ts
3
4
  /**
4
- * Rows, collapsibles, and unnamed tabs are already inlined by Payload's
5
- * flattening, so each dot segment only ever names a data field or a named
6
- * container (group, named tab, array) carrying nested flattenedFields.
7
- */
8
- const findNamedField = (fields, path) => {
9
- let scope = fields;
10
- let found;
11
- for (const segment of path.split(".")) {
12
- found = scope?.find((field) => field.name === segment);
13
- if (!found) return void 0;
14
- scope = "flattenedFields" in found ? found.flattenedFields : void 0;
15
- }
16
- return found;
17
- };
18
- const readPath = (doc, path) => {
19
- let value = doc;
20
- for (const segment of path.split(".")) {
21
- if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
22
- value = value[segment];
23
- }
24
- return value;
25
- };
26
- /**
27
5
  * Function labels resolve here with the same args Payload's own
28
6
  * `getTranslation` passes (`{ i18n, t }` from the request), since the
29
7
  * resulting preset must be a plain value. Static labels pass through untouched
@@ -1 +1 @@
1
- {"version":3,"file":"presetsFromDoc.js","names":[],"sources":["../../../src/fields/color/presetsFromDoc.ts"],"sourcesContent":["import type {\n\tCollectionSlug,\n\tFlattenedField,\n\tLabelFunction,\n\tPayloadRequest,\n\tStaticLabel,\n} from 'payload'\nimport type { ColorPreset } from '../../types'\nimport { PRESET_PREFIX } from './options'\n\nexport type PresetsFromDocArgs = {\n\t/** Collection whose sanitized field configs supply the labels. */\n\tcollection: CollectionSlug\n\t/** The fetched doc holding the color values. */\n\tdoc: Record<string, unknown>\n\t/** Field names to lift; dot paths reach into groups and named tabs. */\n\tfields: string[]\n\t/** Prepended to every preset key, e.g. `${tenant.slug}/` to namespace per doc. */\n\tkeyPrefix?: string\n\treq: PayloadRequest\n}\n\n/**\n * Rows, collapsibles, and unnamed tabs are already inlined by Payload's\n * flattening, so each dot segment only ever names a data field or a named\n * container (group, named tab, array) carrying nested flattenedFields.\n */\nexport const findNamedField = (\n\tfields: FlattenedField[] | undefined,\n\tpath: string\n): FlattenedField | undefined => {\n\tlet scope = fields\n\tlet found: FlattenedField | undefined\n\tfor (const segment of path.split('.')) {\n\t\tfound = scope?.find((field) => field.name === segment)\n\t\tif (!found) return undefined\n\t\tscope = 'flattenedFields' in found ? found.flattenedFields : undefined\n\t}\n\treturn found\n}\n\nconst readPath = (doc: Record<string, unknown>, path: string): unknown => {\n\tlet value: unknown = doc\n\tfor (const segment of path.split('.')) {\n\t\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n\t\tvalue = (value as Record<string, unknown>)[segment]\n\t}\n\treturn value\n}\n\n/**\n * Function labels resolve here with the same args Payload's own\n * `getTranslation` passes (`{ i18n, t }` from the request), since the\n * resulting preset must be a plain value. Static labels pass through untouched\n * so the admin localizes records per request language at render time.\n */\nconst labelForField = (field: FlattenedField, req: PayloadRequest): StaticLabel => {\n\tconst label = field.label\n\tif (typeof label === 'function') {\n\t\treturn label({ i18n: req.i18n, t: req.i18n.t } as Parameters<LabelFunction>[0])\n\t}\n\tif (label === undefined || label === false) return field.name\n\treturn label\n}\n\n/**\n * Lifts individual color fields off a fetched doc into linked-mode presets, so\n * a fixed set of brand colors can live as plain fields instead of an\n * array/repeater. Each preset reuses the field's admin identity: key is\n * `keyPrefix + fieldPath` and the label is the field config's own label\n * (localized records untouched, functions resolved via `req.i18n`), keeping\n * picker chips consistent with the source document's edit view. Sanitized\n * configs humanize missing labels already, so the raw-name fallback only\n * fires for `label: false`. Missing fields and empty, non-string, or\n * `preset:` values are skipped rather than thrown so partial docs degrade to\n * fewer presets.\n */\nexport const presetsFromDoc = (args: PresetsFromDocArgs): ColorPreset[] => {\n\tconst { collection, doc, fields, keyPrefix = '', req } = args\n\tconst config = req.payload.collections[collection]?.config\n\tif (!config) {\n\t\tthrow new Error(`presetsFromDoc: unknown collection \"${collection}\"`)\n\t}\n\tconst presets: ColorPreset[] = []\n\tfor (const name of fields) {\n\t\tconst field = findNamedField(config.flattenedFields, name)\n\t\tif (!field) continue\n\t\tconst value = readPath(doc, name)\n\t\tif (typeof value !== 'string' || value === '' || value.startsWith(PRESET_PREFIX)) continue\n\t\tpresets.push({ key: `${keyPrefix}${name}`, label: labelForField(field, req), value })\n\t}\n\treturn presets\n}\n"],"mappings":";;;;;;;AA2BA,MAAa,kBACZ,QACA,SACgC;CAChC,IAAI,QAAQ;CACZ,IAAI;CACJ,KAAK,MAAM,WAAW,KAAK,MAAM,GAAG,GAAG;EACtC,QAAQ,OAAO,MAAM,UAAU,MAAM,SAAS,OAAO;EACrD,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,QAAQ,qBAAqB,QAAQ,MAAM,kBAAkB,KAAA;CAC9D;CACA,OAAO;AACR;AAEA,MAAM,YAAY,KAA8B,SAA0B;CACzE,IAAI,QAAiB;CACrB,KAAK,MAAM,WAAW,KAAK,MAAM,GAAG,GAAG;EACtC,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO,KAAA;EAChF,QAAS,MAAkC;CAC5C;CACA,OAAO;AACR;;;;;;;AAQA,MAAM,iBAAiB,OAAuB,QAAqC;CAClF,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YACpB,OAAO,MAAM;EAAE,MAAM,IAAI;EAAM,GAAG,IAAI,KAAK;CAAE,CAAiC;CAE/E,IAAI,UAAU,KAAA,KAAa,UAAU,OAAO,OAAO,MAAM;CACzD,OAAO;AACR;;;;;;;;;;;;;AAcA,MAAa,kBAAkB,SAA4C;CAC1E,MAAM,EAAE,YAAY,KAAK,QAAQ,YAAY,IAAI,QAAQ;CACzD,MAAM,SAAS,IAAI,QAAQ,YAAY,aAAa;CACpD,IAAI,CAAC,QACJ,MAAM,IAAI,MAAM,uCAAuC,WAAW,EAAE;CAErE,MAAM,UAAyB,CAAC;CAChC,KAAK,MAAM,QAAQ,QAAQ;EAC1B,MAAM,QAAQ,eAAe,OAAO,iBAAiB,IAAI;EACzD,IAAI,CAAC,OAAO;EACZ,MAAM,QAAQ,SAAS,KAAK,IAAI;EAChC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,WAAA,SAAwB,GAAG;EAClF,QAAQ,KAAK;GAAE,KAAK,GAAG,YAAY;GAAQ,OAAO,cAAc,OAAO,GAAG;GAAG;EAAM,CAAC;CACrF;CACA,OAAO;AACR"}
1
+ {"version":3,"file":"presetsFromDoc.js","names":[],"sources":["../../../src/fields/color/presetsFromDoc.ts"],"sourcesContent":["import type {\n\tCollectionSlug,\n\tFlattenedField,\n\tLabelFunction,\n\tPayloadRequest,\n\tStaticLabel,\n} from 'payload'\nimport type { ColorPreset } from '../../types'\nimport { PRESET_PREFIX } from './options'\nimport { findNamedField, readPath } from './paths'\n\nexport type PresetsFromDocArgs = {\n\t/** Collection whose sanitized field configs supply the labels. */\n\tcollection: CollectionSlug\n\t/** The fetched doc holding the color values. */\n\tdoc: Record<string, unknown>\n\t/** Field names to lift; dot paths reach into groups and named tabs. */\n\tfields: string[]\n\t/** Prepended to every preset key, e.g. `${tenant.slug}/` to namespace per doc. */\n\tkeyPrefix?: string\n\treq: PayloadRequest\n}\n\nexport { findNamedField } from './paths'\n\n/**\n * Function labels resolve here with the same args Payload's own\n * `getTranslation` passes (`{ i18n, t }` from the request), since the\n * resulting preset must be a plain value. Static labels pass through untouched\n * so the admin localizes records per request language at render time.\n */\nconst labelForField = (field: FlattenedField, req: PayloadRequest): StaticLabel => {\n\tconst label = field.label\n\tif (typeof label === 'function') {\n\t\treturn label({ i18n: req.i18n, t: req.i18n.t } as Parameters<LabelFunction>[0])\n\t}\n\tif (label === undefined || label === false) return field.name\n\treturn label\n}\n\n/**\n * Lifts individual color fields off a fetched doc into linked-mode presets, so\n * a fixed set of brand colors can live as plain fields instead of an\n * array/repeater. Each preset reuses the field's admin identity: key is\n * `keyPrefix + fieldPath` and the label is the field config's own label\n * (localized records untouched, functions resolved via `req.i18n`), keeping\n * picker chips consistent with the source document's edit view. Sanitized\n * configs humanize missing labels already, so the raw-name fallback only\n * fires for `label: false`. Missing fields and empty, non-string, or\n * `preset:` values are skipped rather than thrown so partial docs degrade to\n * fewer presets.\n */\nexport const presetsFromDoc = (args: PresetsFromDocArgs): ColorPreset[] => {\n\tconst { collection, doc, fields, keyPrefix = '', req } = args\n\tconst config = req.payload.collections[collection]?.config\n\tif (!config) {\n\t\tthrow new Error(`presetsFromDoc: unknown collection \"${collection}\"`)\n\t}\n\tconst presets: ColorPreset[] = []\n\tfor (const name of fields) {\n\t\tconst field = findNamedField(config.flattenedFields, name)\n\t\tif (!field) continue\n\t\tconst value = readPath(doc, name)\n\t\tif (typeof value !== 'string' || value === '' || value.startsWith(PRESET_PREFIX)) continue\n\t\tpresets.push({ key: `${keyPrefix}${name}`, label: labelForField(field, req), value })\n\t}\n\treturn presets\n}\n"],"mappings":";;;;;;;;;AA+BA,MAAM,iBAAiB,OAAuB,QAAqC;CAClF,MAAM,QAAQ,MAAM;CACpB,IAAI,OAAO,UAAU,YACpB,OAAO,MAAM;EAAE,MAAM,IAAI;EAAM,GAAG,IAAI,KAAK;CAAE,CAAiC;CAE/E,IAAI,UAAU,KAAA,KAAa,UAAU,OAAO,OAAO,MAAM;CACzD,OAAO;AACR;;;;;;;;;;;;;AAcA,MAAa,kBAAkB,SAA4C;CAC1E,MAAM,EAAE,YAAY,KAAK,QAAQ,YAAY,IAAI,QAAQ;CACzD,MAAM,SAAS,IAAI,QAAQ,YAAY,aAAa;CACpD,IAAI,CAAC,QACJ,MAAM,IAAI,MAAM,uCAAuC,WAAW,EAAE;CAErE,MAAM,UAAyB,CAAC;CAChC,KAAK,MAAM,QAAQ,QAAQ;EAC1B,MAAM,QAAQ,eAAe,OAAO,iBAAiB,IAAI;EACzD,IAAI,CAAC,OAAO;EACZ,MAAM,QAAQ,SAAS,KAAK,IAAI;EAChC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,WAAA,SAAwB,GAAG;EAClF,QAAQ,KAAK;GAAE,KAAK,GAAG,YAAY;GAAQ,OAAO,cAAc,OAAO,GAAG;GAAG;EAAM,CAAC;CACrF;CACA,OAAO;AACR"}
@@ -1,4 +1,4 @@
1
- import { ColorPreset } from "../../types.js";
1
+ import { ColorPreset, ColorSchemeValue } from "../../types.js";
2
2
  import { ColorPresetsSource } from "./options.js";
3
3
  import { PayloadRequest, StaticLabel } from "payload";
4
4
 
@@ -6,7 +6,7 @@ import { PayloadRequest, StaticLabel } from "payload";
6
6
  type NormalizedColorPreset = {
7
7
  key: string;
8
8
  label?: StaticLabel;
9
- value: string;
9
+ value: string | ColorSchemeValue;
10
10
  };
11
11
  /** String presets use the CSS value as both key and value; linked mode should prefer object presets. */
12
12
  declare const normalizePresets: (presets: ColorPreset[]) => NormalizedColorPreset[];
@@ -1,15 +1,45 @@
1
1
  import { getFieldsRegistry } from "../../plugin/registry.js";
2
2
  import { memoForRequest } from "../../utils/memoForRequest.js";
3
3
  //#region src/fields/color/resolvePresets.ts
4
+ /**
5
+ * One value rule for every layer: a scheme value with one member present is
6
+ * that color in both schemes; with neither it is not a preset. Filling rather
7
+ * than dropping keeps a mid-authored palette row pickable, and matches what a
8
+ * plain string preset already resolves to under `resolve: 'schemes'`.
9
+ */
10
+ const normalizeValue = (value) => {
11
+ if (typeof value === "string") return value === "" ? null : value;
12
+ if (typeof value !== "object" || value === null) return null;
13
+ const { dark, light } = value;
14
+ const usableLight = typeof light === "string" && light !== "" ? light : null;
15
+ const usableDark = typeof dark === "string" && dark !== "" ? dark : null;
16
+ if (!usableLight && !usableDark) return null;
17
+ return {
18
+ dark: usableDark ?? usableLight,
19
+ light: usableLight ?? usableDark
20
+ };
21
+ };
4
22
  /** String presets use the CSS value as both key and value; linked mode should prefer object presets. */
5
- const normalizePresets = (presets) => presets.map((preset) => typeof preset === "string" ? {
6
- key: preset,
7
- value: preset
8
- } : {
9
- key: preset.key,
10
- label: preset.label,
11
- value: preset.value
12
- });
23
+ const normalizePresets = (presets) => {
24
+ const normalized = [];
25
+ for (const preset of presets) {
26
+ if (typeof preset === "string") {
27
+ if (preset !== "") normalized.push({
28
+ key: preset,
29
+ value: preset
30
+ });
31
+ continue;
32
+ }
33
+ const value = normalizeValue(preset.value);
34
+ if (value === null) continue;
35
+ normalized.push({
36
+ key: preset.key,
37
+ label: preset.label,
38
+ value
39
+ });
40
+ }
41
+ return normalized;
42
+ };
13
43
  /**
14
44
  * Resolves a field's preset source. Falls back to the plugin registry
15
45
  * (static `presets` wins over `resolvePresets`) when the field has none.
@@ -1 +1 @@
1
- {"version":3,"file":"resolvePresets.js","names":[],"sources":["../../../src/fields/color/resolvePresets.ts"],"sourcesContent":["import type { PayloadRequest, StaticLabel } from 'payload'\nimport { getFieldsRegistry } from '../../plugin/registry'\nimport type { ColorPreset } from '../../types'\nimport { memoForRequest } from '../../utils/memoForRequest'\nimport type { ColorPresetsSource } from './options'\n\nexport type NormalizedColorPreset = { key: string; label?: StaticLabel; value: string }\n\n/** String presets use the CSS value as both key and value; linked mode should prefer object presets. */\nexport const normalizePresets = (presets: ColorPreset[]): NormalizedColorPreset[] =>\n\tpresets.map((preset) =>\n\t\ttypeof preset === 'string'\n\t\t\t? { key: preset, value: preset }\n\t\t\t: { key: preset.key, label: preset.label, value: preset.value }\n\t)\n\n/**\n * Resolves a field's preset source. Falls back to the plugin registry\n * (static `presets` wins over `resolvePresets`) when the field has none.\n * Resolver calls are memoized per request via `memoKey`, so a find across\n * many docs resolves once; resolvers must therefore derive from `req`,\n * not per-doc data (documented limitation).\n */\nexport const resolvePresets = async (args: {\n\tdata?: Record<string, unknown>\n\tmemoKey: symbol\n\treq: PayloadRequest\n\tsiblingData?: Record<string, unknown>\n\tsource?: ColorPresetsSource\n}): Promise<NormalizedColorPreset[]> => {\n\tconst { data, memoKey, req, siblingData } = args\n\tlet source = args.source\n\tif (!source) {\n\t\tconst registry = getFieldsRegistry(req.payload.config)?.color\n\t\tsource = registry?.presets ?? registry?.resolvePresets\n\t}\n\tif (!source) return []\n\tif (Array.isArray(source)) return normalizePresets(source)\n\tconst resolver = source\n\tconst resolved = await memoForRequest(req, memoKey, () => resolver({ data, req, siblingData }))\n\treturn normalizePresets(resolved)\n}\n"],"mappings":";;;;AASA,MAAa,oBAAoB,YAChC,QAAQ,KAAK,WACZ,OAAO,WAAW,WACf;CAAE,KAAK;CAAQ,OAAO;AAAO,IAC7B;CAAE,KAAK,OAAO;CAAK,OAAO,OAAO;CAAO,OAAO,OAAO;AAAM,CAChE;;;;;;;;AASD,MAAa,iBAAiB,OAAO,SAMG;CACvC,MAAM,EAAE,MAAM,SAAS,KAAK,gBAAgB;CAC5C,IAAI,SAAS,KAAK;CAClB,IAAI,CAAC,QAAQ;EACZ,MAAM,WAAW,kBAAkB,IAAI,QAAQ,MAAM,GAAG;EACxD,SAAS,UAAU,WAAW,UAAU;CACzC;CACA,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,iBAAiB,MAAM;CACzD,MAAM,WAAW;CAEjB,OAAO,iBAAiB,MADD,eAAe,KAAK,eAAe,SAAS;EAAE;EAAM;EAAK;CAAY,CAAC,CAAC,CAC9D;AACjC"}
1
+ {"version":3,"file":"resolvePresets.js","names":[],"sources":["../../../src/fields/color/resolvePresets.ts"],"sourcesContent":["import type { PayloadRequest, StaticLabel } from 'payload'\nimport { getFieldsRegistry } from '../../plugin/registry'\nimport type { ColorPreset, ColorSchemeValue } from '../../types'\nimport { memoForRequest } from '../../utils/memoForRequest'\nimport type { ColorPresetsSource } from './options'\n\nexport type NormalizedColorPreset = {\n\tkey: string\n\tlabel?: StaticLabel\n\tvalue: string | ColorSchemeValue\n}\n\n/**\n * One value rule for every layer: a scheme value with one member present is\n * that color in both schemes; with neither it is not a preset. Filling rather\n * than dropping keeps a mid-authored palette row pickable, and matches what a\n * plain string preset already resolves to under `resolve: 'schemes'`.\n */\nconst normalizeValue = (value: unknown): null | string | ColorSchemeValue => {\n\tif (typeof value === 'string') return value === '' ? null : value\n\tif (typeof value !== 'object' || value === null) return null\n\tconst { dark, light } = value as Partial<ColorSchemeValue>\n\tconst usableLight = typeof light === 'string' && light !== '' ? light : null\n\tconst usableDark = typeof dark === 'string' && dark !== '' ? dark : null\n\tif (!usableLight && !usableDark) return null\n\treturn {\n\t\tdark: usableDark ?? (usableLight as string),\n\t\tlight: usableLight ?? (usableDark as string),\n\t}\n}\n\n/** String presets use the CSS value as both key and value; linked mode should prefer object presets. */\nexport const normalizePresets = (presets: ColorPreset[]): NormalizedColorPreset[] => {\n\tconst normalized: NormalizedColorPreset[] = []\n\tfor (const preset of presets) {\n\t\tif (typeof preset === 'string') {\n\t\t\tif (preset !== '') normalized.push({ key: preset, value: preset })\n\t\t\tcontinue\n\t\t}\n\t\tconst value = normalizeValue(preset.value)\n\t\tif (value === null) continue\n\t\tnormalized.push({ key: preset.key, label: preset.label, value })\n\t}\n\treturn normalized\n}\n\n/**\n * Resolves a field's preset source. Falls back to the plugin registry\n * (static `presets` wins over `resolvePresets`) when the field has none.\n * Resolver calls are memoized per request via `memoKey`, so a find across\n * many docs resolves once; resolvers must therefore derive from `req`,\n * not per-doc data (documented limitation).\n */\nexport const resolvePresets = async (args: {\n\tdata?: Record<string, unknown>\n\tmemoKey: symbol\n\treq: PayloadRequest\n\tsiblingData?: Record<string, unknown>\n\tsource?: ColorPresetsSource\n}): Promise<NormalizedColorPreset[]> => {\n\tconst { data, memoKey, req, siblingData } = args\n\tlet source = args.source\n\tif (!source) {\n\t\tconst registry = getFieldsRegistry(req.payload.config)?.color\n\t\tsource = registry?.presets ?? registry?.resolvePresets\n\t}\n\tif (!source) return []\n\tif (Array.isArray(source)) return normalizePresets(source)\n\tconst resolver = source\n\tconst resolved = await memoForRequest(req, memoKey, () => resolver({ data, req, siblingData }))\n\treturn normalizePresets(resolved)\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,kBAAkB,UAAqD;CAC5E,IAAI,OAAO,UAAU,UAAU,OAAO,UAAU,KAAK,OAAO;CAC5D,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,cAAc,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ;CACxE,MAAM,aAAa,OAAO,SAAS,YAAY,SAAS,KAAK,OAAO;CACpE,IAAI,CAAC,eAAe,CAAC,YAAY,OAAO;CACxC,OAAO;EACN,MAAM,cAAe;EACrB,OAAO,eAAgB;CACxB;AACD;;AAGA,MAAa,oBAAoB,YAAoD;CACpF,MAAM,aAAsC,CAAC;CAC7C,KAAK,MAAM,UAAU,SAAS;EAC7B,IAAI,OAAO,WAAW,UAAU;GAC/B,IAAI,WAAW,IAAI,WAAW,KAAK;IAAE,KAAK;IAAQ,OAAO;GAAO,CAAC;GACjE;EACD;EACA,MAAM,QAAQ,eAAe,OAAO,KAAK;EACzC,IAAI,UAAU,MAAM;EACpB,WAAW,KAAK;GAAE,KAAK,OAAO;GAAK,OAAO,OAAO;GAAO;EAAM,CAAC;CAChE;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,iBAAiB,OAAO,SAMG;CACvC,MAAM,EAAE,MAAM,SAAS,KAAK,gBAAgB;CAC5C,IAAI,SAAS,KAAK;CAClB,IAAI,CAAC,QAAQ;EACZ,MAAM,WAAW,kBAAkB,IAAI,QAAQ,MAAM,GAAG;EACxD,SAAS,UAAU,WAAW,UAAU;CACzC;CACA,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,iBAAiB,MAAM;CACzD,MAAM,WAAW;CAEjB,OAAO,iBAAiB,MADD,eAAe,KAAK,eAAe,SAAS;EAAE;EAAM;EAAK;CAAY,CAAC,CAAC,CAC9D;AACjC"}
@@ -0,0 +1,30 @@
1
+ import { parseColor } from "./engine/parse.js";
2
+ import { formatColor } from "./engine/format.js";
3
+ import { isColorSchemeValue } from "./engine/scheme.js";
4
+ //#region src/fields/color/schemeValue.ts
5
+ /** The single color a flat context uses for a scheme value. */
6
+ const flatValue = (value) => {
7
+ if (isColorSchemeValue(value)) return value.light;
8
+ if (typeof value !== "string" || value === "") return null;
9
+ return value;
10
+ };
11
+ const normalizedCss = (value) => {
12
+ const parsed = parseColor(value);
13
+ return parsed ? formatColor(parsed, "rgb") : value;
14
+ };
15
+ /**
16
+ * Background for a swatch. A scheme value renders as a diagonal split so an
17
+ * editor sees the color is mode-responsive without visiting the site.
18
+ */
19
+ const swatchBackground = (value) => {
20
+ if (isColorSchemeValue(value)) {
21
+ const { dark, light } = value;
22
+ return `linear-gradient(135deg, ${normalizedCss(light)} 0 50%, ${normalizedCss(dark)} 50% 100%)`;
23
+ }
24
+ const flat = flatValue(value);
25
+ return flat === null ? null : normalizedCss(flat);
26
+ };
27
+ //#endregion
28
+ export { flatValue, swatchBackground };
29
+
30
+ //# sourceMappingURL=schemeValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemeValue.js","names":[],"sources":["../../../src/fields/color/schemeValue.ts"],"sourcesContent":["import type { ColorSchemeValue } from '../../types'\nimport { formatColor, isColorSchemeValue, parseColor } from './engine'\n\n/** The single color a flat context uses for a scheme value. */\nexport const flatValue = (value: unknown): null | string => {\n\tif (isColorSchemeValue(value)) return value.light\n\tif (typeof value !== 'string' || value === '') return null\n\treturn value\n}\n\nconst normalizedCss = (value: string): string => {\n\tconst parsed = parseColor(value)\n\treturn parsed ? formatColor(parsed, 'rgb') : value\n}\n\n/**\n * Background for a swatch. A scheme value renders as a diagonal split so an\n * editor sees the color is mode-responsive without visiting the site.\n */\nexport const swatchBackground = (value: unknown): null | string => {\n\tif (isColorSchemeValue(value)) {\n\t\tconst { dark, light } = value as ColorSchemeValue\n\t\treturn `linear-gradient(135deg, ${normalizedCss(light)} 0 50%, ${normalizedCss(dark)} 50% 100%)`\n\t}\n\tconst flat = flatValue(value)\n\treturn flat === null ? null : normalizedCss(flat)\n}\n"],"mappings":";;;;;AAIA,MAAa,aAAa,UAAkC;CAC3D,IAAI,mBAAmB,KAAK,GAAG,OAAO,MAAM;CAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,IAAI,OAAO;CACtD,OAAO;AACR;AAEA,MAAM,iBAAiB,UAA0B;CAChD,MAAM,SAAS,WAAW,KAAK;CAC/B,OAAO,SAAS,YAAY,QAAQ,KAAK,IAAI;AAC9C;;;;;AAMA,MAAa,oBAAoB,UAAkC;CAClE,IAAI,mBAAmB,KAAK,GAAG;EAC9B,MAAM,EAAE,MAAM,UAAU;EACxB,OAAO,2BAA2B,cAAc,KAAK,EAAE,UAAU,cAAc,IAAI,EAAE;CACtF;CACA,MAAM,OAAO,UAAU,KAAK;CAC5B,OAAO,SAAS,OAAO,OAAO,cAAc,IAAI;AACjD"}
@@ -1,5 +1,6 @@
1
1
  import { keys } from "../../../translations/keys.js";
2
2
  import { PRESET_PREFIX } from "../options.js";
3
+ import { swatchBackground } from "../schemeValue.js";
3
4
  import { asTranslate } from "../../../translations/server.js";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
6
  import "./colorCell.css";
@@ -9,8 +10,7 @@ const ColorCell = (props) => {
9
10
  if (typeof cellData !== "string" || cellData === "") return null;
10
11
  const isPreset = cellData.startsWith(PRESET_PREFIX);
11
12
  const name = "name" in field ? String(field.name) : "";
12
- const resolvedRaw = isPreset ? rowData?.[`${name}Resolved`] : cellData;
13
- const swatch = typeof resolvedRaw === "string" && resolvedRaw !== "" ? resolvedRaw : null;
13
+ const swatch = swatchBackground(isPreset ? rowData?.[`${name}Resolved`] : cellData);
14
14
  const label = isPreset ? cellData.slice(PRESET_PREFIX.length) : cellData;
15
15
  return /* @__PURE__ */ jsxs("span", {
16
16
  className: "fields-color-cell",
@@ -1 +1 @@
1
- {"version":3,"file":"ColorCell.js","names":[],"sources":["../../../../src/fields/color/server/ColorCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { PRESET_PREFIX } from '../options'\nimport './colorCell.css'\n\nexport const ColorCell = (props: DefaultServerCellComponentProps) => {\n\tconst { cellData, field, i18n, rowData } = props\n\tif (typeof cellData !== 'string' || cellData === '') return null\n\tconst isPreset = cellData.startsWith(PRESET_PREFIX)\n\tconst name = 'name' in field ? String(field.name) : ''\n\tconst resolvedRaw = isPreset\n\t\t? (rowData as Record<string, unknown>)?.[`${name}Resolved`]\n\t\t: cellData\n\tconst swatch = typeof resolvedRaw === 'string' && resolvedRaw !== '' ? resolvedRaw : null\n\tconst label = isPreset ? cellData.slice(PRESET_PREFIX.length) : cellData\n\treturn (\n\t\t<span className=\"fields-color-cell\">\n\t\t\t<span aria-hidden=\"true\" className=\"fields-color-cell__swatch\">\n\t\t\t\t{swatch ? <span style={{ background: swatch }} /> : null}\n\t\t\t</span>\n\t\t\t<span>{label}</span>\n\t\t\t{isPreset && !swatch ? (\n\t\t\t\t<span className=\"fields-color-cell__missing\">\n\t\t\t\t\t{asTranslate(i18n.t)(keys.missingPreset)}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;AAMA,MAAa,aAAa,UAA2C;CACpE,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY;CAC3C,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,OAAO;CAC5D,MAAM,WAAW,SAAS,WAAW,aAAa;CAClD,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,IAAI,IAAI;CACpD,MAAM,cAAc,WAChB,UAAsC,GAAG,KAAK,aAC/C;CACH,MAAM,SAAS,OAAO,gBAAgB,YAAY,gBAAgB,KAAK,cAAc;CACrF,MAAM,QAAQ,WAAW,SAAS,MAAM,cAAc,MAAM,IAAI;CAChE,OACC,qBAAC,QAAD;EAAM,WAAU;YAAhB;GACC,oBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;cACjC,SAAS,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,OAAO,EAAI,CAAA,IAAI;GAC/C,CAAA;GACN,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA;GAClB,YAAY,CAAC,SACb,oBAAC,QAAD;IAAM,WAAU;cACd,YAAY,KAAK,CAAC,EAAE,KAAK,aAAa;GAClC,CAAA,IACH;EACC;;AAER"}
1
+ {"version":3,"file":"ColorCell.js","names":[],"sources":["../../../../src/fields/color/server/ColorCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport { PRESET_PREFIX } from '../options'\nimport { swatchBackground } from '../schemeValue'\nimport './colorCell.css'\n\nexport const ColorCell = (props: DefaultServerCellComponentProps) => {\n\tconst { cellData, field, i18n, rowData } = props\n\tif (typeof cellData !== 'string' || cellData === '') return null\n\tconst isPreset = cellData.startsWith(PRESET_PREFIX)\n\tconst name = 'name' in field ? String(field.name) : ''\n\tconst resolvedRaw = isPreset\n\t\t? (rowData as Record<string, unknown>)?.[`${name}Resolved`]\n\t\t: cellData\n\tconst swatch = swatchBackground(resolvedRaw)\n\tconst label = isPreset ? cellData.slice(PRESET_PREFIX.length) : cellData\n\treturn (\n\t\t<span className=\"fields-color-cell\">\n\t\t\t<span aria-hidden=\"true\" className=\"fields-color-cell__swatch\">\n\t\t\t\t{swatch ? <span style={{ background: swatch }} /> : null}\n\t\t\t</span>\n\t\t\t<span>{label}</span>\n\t\t\t{isPreset && !swatch ? (\n\t\t\t\t<span className=\"fields-color-cell__missing\">\n\t\t\t\t\t{asTranslate(i18n.t)(keys.missingPreset)}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;AAOA,MAAa,aAAa,UAA2C;CACpE,MAAM,EAAE,UAAU,OAAO,MAAM,YAAY;CAC3C,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,OAAO;CAC5D,MAAM,WAAW,SAAS,WAAW,aAAa;CAClD,MAAM,OAAO,UAAU,QAAQ,OAAO,MAAM,IAAI,IAAI;CAIpD,MAAM,SAAS,iBAHK,WAChB,UAAsC,GAAG,KAAK,aAC/C,QACwC;CAC3C,MAAM,QAAQ,WAAW,SAAS,MAAM,cAAc,MAAM,IAAI;CAChE,OACC,qBAAC,QAAD;EAAM,WAAU;YAAhB;GACC,oBAAC,QAAD;IAAM,eAAY;IAAO,WAAU;cACjC,SAAS,oBAAC,QAAD,EAAM,OAAO,EAAE,YAAY,OAAO,EAAI,CAAA,IAAI;GAC/C,CAAA;GACN,oBAAC,QAAD,EAAA,UAAO,MAAY,CAAA;GAClB,YAAY,CAAC,SACb,oBAAC,QAAD;IAAM,WAAU;cACd,YAAY,KAAK,CAAC,EAAE,KAAK,aAAa;GAClC,CAAA,IACH;EACC;;AAER"}
@@ -1,4 +1,4 @@
1
- import { CollectionConfig } from "payload";
1
+ import { CollectionConfig, Where } from "payload";
2
2
 
3
3
  //#region src/fields/encrypted/queryRewrite.d.ts
4
4
  /**