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

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 (109) hide show
  1. package/CHANGELOG.md +53 -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/radix/adapter.js +7 -0
  43. package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
  44. package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
  45. package/dist/fields/icon/adapters/radix/client.js +3 -2
  46. package/dist/fields/icon/adapters/radix/client.js.map +1 -1
  47. package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
  48. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
  49. package/dist/fields/icon/client/DrawerGlyph.js +34 -17
  50. package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
  51. package/dist/fields/icon/client/IconDrawerContent.js +9 -45
  52. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  53. package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
  54. package/dist/fields/icon/client/IconFieldClient.js +15 -7
  55. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  56. package/dist/fields/icon/client/IconGridCell.js +67 -0
  57. package/dist/fields/icon/client/IconGridCell.js.map +1 -0
  58. package/dist/fields/icon/client/icon-field.css +8 -0
  59. package/dist/fields/icon/codegen/emit.js +3 -2
  60. package/dist/fields/icon/codegen/emit.js.map +1 -1
  61. package/dist/fields/icon/codegen/generate.js +32 -6
  62. package/dist/fields/icon/codegen/generate.js.map +1 -1
  63. package/dist/fields/icon/layers/coalesce.js +41 -0
  64. package/dist/fields/icon/layers/coalesce.js.map +1 -0
  65. package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
  66. package/dist/fields/icon/layers/manifestCache.js +49 -0
  67. package/dist/fields/icon/layers/manifestCache.js.map +1 -0
  68. package/dist/fields/icon/layers/resolve.d.ts +20 -0
  69. package/dist/fields/icon/layers/resolve.js +63 -0
  70. package/dist/fields/icon/layers/resolve.js.map +1 -0
  71. package/dist/fields/icon/layers/upload.d.ts +52 -0
  72. package/dist/fields/icon/layers/upload.js +116 -0
  73. package/dist/fields/icon/layers/upload.js.map +1 -0
  74. package/dist/fields/icon/plugin.js +24 -0
  75. package/dist/fields/icon/plugin.js.map +1 -1
  76. package/dist/fields/icon/react/createIcon.d.ts +5 -0
  77. package/dist/fields/icon/react/createIcon.js +22 -4
  78. package/dist/fields/icon/react/createIcon.js.map +1 -1
  79. package/dist/fields/icon/react/createRscIcon.js +22 -1
  80. package/dist/fields/icon/react/createRscIcon.js.map +1 -1
  81. package/dist/fields/icon/react/resolveRendered.js +21 -0
  82. package/dist/fields/icon/react/resolveRendered.js.map +1 -0
  83. package/dist/fields/icon/react/types.d.ts +15 -1
  84. package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
  85. package/dist/fields/icon/rsc/IconCell.js +12 -5
  86. package/dist/fields/icon/rsc/IconCell.js.map +1 -1
  87. package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
  88. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  89. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  90. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  91. package/dist/fields/icon/server/endpoint.d.ts +12 -0
  92. package/dist/fields/icon/server/endpoint.js +52 -0
  93. package/dist/fields/icon/server/endpoint.js.map +1 -0
  94. package/dist/fields/icon/server/manifestCache.js +9 -4
  95. package/dist/fields/icon/server/manifestCache.js.map +1 -1
  96. package/dist/fields/icon/server/resolveIconMeta.js +31 -0
  97. package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
  98. package/dist/fields/icon/server/validate.js +5 -2
  99. package/dist/fields/icon/server/validate.js.map +1 -1
  100. package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
  101. package/dist/fields/icon/shared/iconLabel.js +26 -0
  102. package/dist/fields/icon/shared/iconLabel.js.map +1 -0
  103. package/dist/fields/icon/{rsc → shared}/resolveStaticLabel.js +1 -1
  104. package/dist/fields/icon/shared/resolveStaticLabel.js.map +1 -0
  105. package/dist/index.d.ts +2 -2
  106. package/dist/index.js.map +1 -1
  107. package/dist/types.d.ts +125 -8
  108. package/package.json +9 -7
  109. package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, KeysConfig } from "./types.js";
1
+ import { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconCanvas, IconGlobalConfig, IconLayer, IconLayerCache, IconLayerContext, IconManifest, IconMeta, IconRenderStrategy, KeysConfig } from "./types.js";
2
2
  import { TranslationsOption } from "./translations/index.js";
3
3
  import { getFieldsRegistry } from "./plugin/registry.js";
4
4
 
@@ -35,5 +35,5 @@ declare module 'payload' {
35
35
  */
36
36
  declare const fields: (options: FieldsPluginOptions) => import("payload").Plugin;
37
37
  //#endregion
38
- export { type ColorFormat, type ColorGlobalConfig, type ColorPreset, type DecryptFailurePolicy, type EncryptedGlobalConfig, FieldsPluginOptions, type FieldsPluginOptions as PluginOptions, type FieldsPluginRegistry, type FieldsResolverArgs, type IconAdapter, type IconGlobalConfig, type IconManifest, type IconMeta, type KeysConfig, fields, getFieldsRegistry };
38
+ export { type ColorFormat, type ColorGlobalConfig, type ColorPreset, type DecryptFailurePolicy, type EncryptedGlobalConfig, FieldsPluginOptions, type FieldsPluginOptions as PluginOptions, type FieldsPluginRegistry, type FieldsResolverArgs, type IconAdapter, type IconCanvas, type IconGlobalConfig, type IconLayer, type IconLayerCache, type IconLayerContext, type IconManifest, type IconMeta, type IconRenderStrategy, type KeysConfig, fields, getFieldsRegistry };
39
39
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type Config, definePlugin } from 'payload'\n\nimport { validateEncryptedBoot } from './fields/encrypted/boot'\nimport { withEncryptedQueryRewrite } from './fields/encrypted/queryRewrite'\nimport { registerIcon } from './fields/icon/plugin'\nimport { registerTranslations } from './plugin/registerTranslations'\nimport { setFieldsRegistry } from './plugin/registry'\nimport type { TranslationsOption } from './translations'\nimport type {\n\tColorGlobalConfig,\n\tEncryptedGlobalConfig,\n\tFieldsPluginRegistry,\n\tIconGlobalConfig,\n} from './types'\n\nexport type FieldsPluginOptions = {\n\t/**\n\t * Disable the plugin entirely (incoming config returned untouched).\n\t * Useful for opting out per environment without removing the plugin call.\n\t */\n\tdisabled?: boolean\n\t/**\n\t * Per-locale overrides for this plugin's UI strings, keyed by the typed\n\t * translation keys exported from `@10x-media/fields/i18n`. Values win over\n\t * the built-in locales key-by-key; locales the plugin does not ship are\n\t * added whole. App-level `i18n.translations` still wins over both.\n\t */\n\ttranslations?: TranslationsOption\n\t/** Global defaults for colorField(). Per-field options always win. */\n\tcolor?: ColorGlobalConfig\n\t/** Global defaults for iconField(). Per-field options always win. */\n\ticon?: IconGlobalConfig\n\t/** Global defaults for encryptedField(). Per-field options always win. */\n\tencrypted?: EncryptedGlobalConfig\n}\n\ndeclare module 'payload' {\n\tinterface RegisteredPlugins {\n\t\t'@10x-media/fields': FieldsPluginOptions\n\t}\n}\n\nconst normalizeRegistry = (options: FieldsPluginOptions): FieldsPluginRegistry => {\n\tconst registry: FieldsPluginRegistry = {}\n\tif (options.color) {\n\t\tregistry.color = options.color\n\t}\n\t// registry.icon is owned solely by registerIcon, which validates adapter\n\t// slugs and the default library before writing the normalized slice.\n\tif (options.encrypted) {\n\t\tregistry.encrypted = options.encrypted\n\t}\n\treturn registry\n}\n\n/**\n * Fields plugin for Payload v3. Registers translations and writes global field\n * defaults to `config.custom['@10x-media/fields']` for factories, hooks, and\n * server components to read at runtime via `getFieldsRegistry`. Every field\n * factory also works without this plugin; per-field options always override\n * these defaults. Authored with `definePlugin` so sibling plugins can detect\n * it by slug.\n */\nexport const fields = definePlugin<FieldsPluginOptions>({\n\tslug: '@10x-media/fields',\n\tplugin: ({ config, plugins: _plugins, ...options }): Config => {\n\t\tif (options.disabled === true) {\n\t\t\treturn config\n\t\t}\n\t\tregisterTranslations(config, options.translations)\n\t\tsetFieldsRegistry(config, normalizeRegistry(options))\n\t\t// Sole owner of registry.icon: validates adapters + default library and\n\t\t// registers their client components in admin.dependencies. A no-op when no\n\t\t// adapters are configured, leaving registry.icon unset.\n\t\tregisterIcon(config, options.icon)\n\t\t// Transparently rewrite equals/in on queryable encrypted fields to their\n\t\t// blind-index siblings; a no-op for collections that have none.\n\t\tconfig.collections = (config.collections ?? []).map(withEncryptedQueryRewrite)\n\t\t// Validate encrypted key material at boot, before any prior onInit runs, so\n\t\t// missing secrets or broken providers fail fast instead of on first write.\n\t\tconst priorOnInit = config.onInit\n\t\tconfig.onInit = async (payload) => {\n\t\t\tawait validateEncryptedBoot(payload, options.encrypted?.keys)\n\t\t\tawait priorOnInit?.(payload)\n\t\t}\n\t\treturn config\n\t},\n})\n\nexport { getFieldsRegistry } from './plugin/registry'\nexport type {\n\tColorFormat,\n\tColorGlobalConfig,\n\tColorPreset,\n\tDecryptFailurePolicy,\n\tEncryptedGlobalConfig,\n\tFieldsPluginRegistry,\n\tFieldsResolverArgs,\n\tIconAdapter,\n\tIconGlobalConfig,\n\tIconManifest,\n\tIconMeta,\n\tKeysConfig,\n} from './types'\nexport type { FieldsPluginOptions as PluginOptions }\n"],"mappings":";;;;;;;AA0CA,MAAM,qBAAqB,YAAuD;CACjF,MAAM,WAAiC,CAAC;CACxC,IAAI,QAAQ,OACX,SAAS,QAAQ,QAAQ;CAI1B,IAAI,QAAQ,WACX,SAAS,YAAY,QAAQ;CAE9B,OAAO;AACR;;;;;;;;;AAUA,MAAa,SAAS,aAAkC;CACvD,MAAM;CACN,SAAS,EAAE,QAAQ,SAAS,UAAU,GAAG,cAAsB;EAC9D,IAAI,QAAQ,aAAa,MACxB,OAAO;EAER,qBAAqB,QAAQ,QAAQ,YAAY;EACjD,kBAAkB,QAAQ,kBAAkB,OAAO,CAAC;EAIpD,aAAa,QAAQ,QAAQ,IAAI;EAGjC,OAAO,eAAe,OAAO,eAAe,CAAC,GAAG,IAAI,yBAAyB;EAG7E,MAAM,cAAc,OAAO;EAC3B,OAAO,SAAS,OAAO,YAAY;GAClC,MAAM,sBAAsB,SAAS,QAAQ,WAAW,IAAI;GAC5D,MAAM,cAAc,OAAO;EAC5B;EACA,OAAO;CACR;AACD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { type Config, definePlugin } from 'payload'\n\nimport { validateEncryptedBoot } from './fields/encrypted/boot'\nimport { withEncryptedQueryRewrite } from './fields/encrypted/queryRewrite'\nimport { registerIcon } from './fields/icon/plugin'\nimport { registerTranslations } from './plugin/registerTranslations'\nimport { setFieldsRegistry } from './plugin/registry'\nimport type { TranslationsOption } from './translations'\nimport type {\n\tColorGlobalConfig,\n\tEncryptedGlobalConfig,\n\tFieldsPluginRegistry,\n\tIconGlobalConfig,\n} from './types'\n\nexport type FieldsPluginOptions = {\n\t/**\n\t * Disable the plugin entirely (incoming config returned untouched).\n\t * Useful for opting out per environment without removing the plugin call.\n\t */\n\tdisabled?: boolean\n\t/**\n\t * Per-locale overrides for this plugin's UI strings, keyed by the typed\n\t * translation keys exported from `@10x-media/fields/i18n`. Values win over\n\t * the built-in locales key-by-key; locales the plugin does not ship are\n\t * added whole. App-level `i18n.translations` still wins over both.\n\t */\n\ttranslations?: TranslationsOption\n\t/** Global defaults for colorField(). Per-field options always win. */\n\tcolor?: ColorGlobalConfig\n\t/** Global defaults for iconField(). Per-field options always win. */\n\ticon?: IconGlobalConfig\n\t/** Global defaults for encryptedField(). Per-field options always win. */\n\tencrypted?: EncryptedGlobalConfig\n}\n\ndeclare module 'payload' {\n\tinterface RegisteredPlugins {\n\t\t'@10x-media/fields': FieldsPluginOptions\n\t}\n}\n\nconst normalizeRegistry = (options: FieldsPluginOptions): FieldsPluginRegistry => {\n\tconst registry: FieldsPluginRegistry = {}\n\tif (options.color) {\n\t\tregistry.color = options.color\n\t}\n\t// registry.icon is owned solely by registerIcon, which validates adapter\n\t// slugs and the default library before writing the normalized slice.\n\tif (options.encrypted) {\n\t\tregistry.encrypted = options.encrypted\n\t}\n\treturn registry\n}\n\n/**\n * Fields plugin for Payload v3. Registers translations and writes global field\n * defaults to `config.custom['@10x-media/fields']` for factories, hooks, and\n * server components to read at runtime via `getFieldsRegistry`. Every field\n * factory also works without this plugin; per-field options always override\n * these defaults. Authored with `definePlugin` so sibling plugins can detect\n * it by slug.\n */\nexport const fields = definePlugin<FieldsPluginOptions>({\n\tslug: '@10x-media/fields',\n\tplugin: ({ config, plugins: _plugins, ...options }): Config => {\n\t\tif (options.disabled === true) {\n\t\t\treturn config\n\t\t}\n\t\tregisterTranslations(config, options.translations)\n\t\tsetFieldsRegistry(config, normalizeRegistry(options))\n\t\t// Sole owner of registry.icon: validates adapters + default library and\n\t\t// registers their client components in admin.dependencies. A no-op when no\n\t\t// adapters are configured, leaving registry.icon unset.\n\t\tregisterIcon(config, options.icon)\n\t\t// Transparently rewrite equals/in on queryable encrypted fields to their\n\t\t// blind-index siblings; a no-op for collections that have none.\n\t\tconfig.collections = (config.collections ?? []).map(withEncryptedQueryRewrite)\n\t\t// Validate encrypted key material at boot, before any prior onInit runs, so\n\t\t// missing secrets or broken providers fail fast instead of on first write.\n\t\tconst priorOnInit = config.onInit\n\t\tconfig.onInit = async (payload) => {\n\t\t\tawait validateEncryptedBoot(payload, options.encrypted?.keys)\n\t\t\tawait priorOnInit?.(payload)\n\t\t}\n\t\treturn config\n\t},\n})\n\nexport { getFieldsRegistry } from './plugin/registry'\nexport type {\n\tColorFormat,\n\tColorGlobalConfig,\n\tColorPreset,\n\tDecryptFailurePolicy,\n\tEncryptedGlobalConfig,\n\tFieldsPluginRegistry,\n\tFieldsResolverArgs,\n\tIconAdapter,\n\tIconCanvas,\n\tIconGlobalConfig,\n\tIconLayer,\n\tIconLayerCache,\n\tIconLayerContext,\n\tIconManifest,\n\tIconMeta,\n\tIconRenderStrategy,\n\tKeysConfig,\n} from './types'\nexport type { FieldsPluginOptions as PluginOptions }\n"],"mappings":";;;;;;;AA0CA,MAAM,qBAAqB,YAAuD;CACjF,MAAM,WAAiC,CAAC;CACxC,IAAI,QAAQ,OACX,SAAS,QAAQ,QAAQ;CAI1B,IAAI,QAAQ,WACX,SAAS,YAAY,QAAQ;CAE9B,OAAO;AACR;;;;;;;;;AAUA,MAAa,SAAS,aAAkC;CACvD,MAAM;CACN,SAAS,EAAE,QAAQ,SAAS,UAAU,GAAG,cAAsB;EAC9D,IAAI,QAAQ,aAAa,MACxB,OAAO;EAER,qBAAqB,QAAQ,QAAQ,YAAY;EACjD,kBAAkB,QAAQ,kBAAkB,OAAO,CAAC;EAIpD,aAAa,QAAQ,QAAQ,IAAI;EAGjC,OAAO,eAAe,OAAO,eAAe,CAAC,GAAG,IAAI,yBAAyB;EAG7E,MAAM,cAAc,OAAO;EAC3B,OAAO,SAAS,OAAO,YAAY;GAClC,MAAM,sBAAsB,SAAS,QAAQ,WAAW,IAAI;GAC5D,MAAM,cAAc,OAAO;EAC5B;EACA,OAAO;CACR;AACD,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PayloadRequest, StaticLabel } from "payload";
1
+ import { Payload, PayloadRequest, StaticLabel } from "payload";
2
2
 
3
3
  //#region src/types.d.ts
4
4
  /** Args passed to async per-document resolvers (color presets, icon availability). */
@@ -7,10 +7,18 @@ type FieldsResolverArgs = {
7
7
  data?: Record<string, unknown>;
8
8
  siblingData?: Record<string, unknown>;
9
9
  };
10
+ /**
11
+ * A color that varies by color scheme. Consumers read members individually, so
12
+ * an optional third scheme stays a non-breaking addition.
13
+ */
14
+ type ColorSchemeValue = {
15
+ light: string;
16
+ dark: string;
17
+ };
10
18
  /** A color preset: bare CSS string, or a keyed entry usable in linked mode. */
11
19
  type ColorPreset = string | {
12
20
  key: string;
13
- value: string;
21
+ value: string | ColorSchemeValue;
14
22
  label?: StaticLabel;
15
23
  };
16
24
  /** Stored CSS color format for colorField(). */
@@ -20,16 +28,103 @@ type IconMeta = {
20
28
  name: string;
21
29
  tags: string[];
22
30
  categories: string[];
31
+ /**
32
+ * Human-readable name shown to editors, replacing the one derived from `name`.
33
+ * Supply it wherever the name is a code rather than words: `HUN` reads as `Hun`
34
+ * without one, and a screen reader announces that. Omit it and every existing
35
+ * manifest keeps its derived label unchanged.
36
+ */
37
+ label?: StaticLabel;
38
+ };
39
+ /**
40
+ * What an icon adapter's async resolvers receive. `req` is optional because Payload
41
+ * renders list cells without one (`DefaultServerCellComponentProps` carries `payload`
42
+ * and `i18n` only), so a resolver must not depend on it being present.
43
+ */
44
+ type IconLayerContext = {
45
+ payload: Payload;
46
+ req?: PayloadRequest;
23
47
  };
24
48
  /** Lazily loaded icon library manifest. */
25
49
  type IconManifest = {
26
50
  icons: IconMeta[];
27
51
  categories: string[];
28
52
  };
29
- /** One SVG child of a glyph: an element tag and its attribute map, matching lucide-static's icon-nodes shape. */
30
- type IconNode = [tag: string, attrs: Record<string, string>];
53
+ /**
54
+ * One SVG child of a glyph: an element tag and its attribute map, matching lucide-static's
55
+ * icon-nodes shape. An optional third element carries children, so a glyph needing `<g>`
56
+ * or `<defs>` is expressible; the two-element form every generated manifest already uses
57
+ * keeps parsing exactly as before.
58
+ */
59
+ type IconNode = [tag: string, attrs: Record<string, string>] | [tag: string, attrs: Record<string, string>, children: IconNode[]];
31
60
  /** An icon library's glyphs keyed by name, so the drawer renders inline SVG in bulk instead of per-icon imports. */
32
61
  type IconNodeMap = Record<string, IconNode[]>;
62
+ /**
63
+ * How a layer's glyphs paint in the admin. Every variant carries importMap path
64
+ * strings, so a layer stays serializable inside a field config.
65
+ */
66
+ type IconRenderStrategy = /** Bulk node-data rendered as inline SVG. `load` resolves `() => Promise<IconNodeMap>`. */{
67
+ type: 'nodes';
68
+ canvas?: IconCanvas;
69
+ load: string;
70
+ } /** Bulk raw SVG, sprited once client-side. `load` resolves `() => Promise<Record<string, string>>`. */ | {
71
+ type: 'svg';
72
+ load: string;
73
+ } /** One image per icon. `resolve` resolves `(name: string) => null | string`. */ | {
74
+ type: 'url';
75
+ resolve: string;
76
+ } /** A component per icon, for libraries that ship their own lazy glyph components. */ | {
77
+ type: 'component';
78
+ Icon: string;
79
+ };
80
+ /**
81
+ * The SVG canvas a library's glyphs are drawn on. Defaults are lucide's outline
82
+ * convention, which is what the drawer hardcoded before layers existed, so a layer
83
+ * that declares nothing renders exactly as lucide and tabler always have.
84
+ */
85
+ type IconCanvas = {
86
+ viewBox?: string;
87
+ fill?: string;
88
+ stroke?: string;
89
+ strokeWidth?: number | string;
90
+ strokeLinecap?: 'butt' | 'round' | 'square'; /** SVG2's `arcs` and `miter-clip` are omitted: React does not type them and browsers barely support them. */
91
+ strokeLinejoin?: 'bevel' | 'miter' | 'round';
92
+ };
93
+ /**
94
+ * How long a layer's manifest listing may be reused. `'forever'` is the default and
95
+ * matches how a static build artifact has always been cached. A `ttl` in milliseconds
96
+ * suits a layer whose contents change at runtime.
97
+ *
98
+ * Note this governs the drawer *listing* only. Validation goes through `resolveMeta`,
99
+ * which is never cached, so an icon added at runtime is valid immediately regardless.
100
+ */
101
+ type IconLayerCache = 'forever' | {
102
+ ttl: number;
103
+ };
104
+ /**
105
+ * One source within a library. Layers are ordered and later ones win by name, so a
106
+ * static base set can be overridden by a runtime-backed layer under a single slug.
107
+ */
108
+ type IconLayer = {
109
+ /** Diagnostic identity, unique within the adapter. Never part of a stored value. */id: string; /** Lists this layer's icons for the drawer. */
110
+ loadManifest: (ctx: IconLayerContext) => Promise<IconManifest>; /** Exact single-name lookup, serving validation and label resolution. Never cached. */
111
+ resolveMeta?: (name: string, ctx: IconLayerContext) => Promise<IconMeta | null>;
112
+ /**
113
+ * Batched `resolveMeta`. Lookups issued in one microtask are coalesced into a single
114
+ * call, which is what turns a document holding eight icon fields, or a fifty-row list,
115
+ * into one query instead of eight or fifty.
116
+ */
117
+ resolveMetaMany?: (names: string[], ctx: IconLayerContext) => Promise<Map<string, IconMeta>>; /** Cache policy for `loadManifest`. Defaults to `'forever'`. */
118
+ cache?: IconLayerCache;
119
+ /**
120
+ * Extra cache-key segment derived from the request. A layer whose listing differs per
121
+ * tenant, locale or user MUST supply this, or one caller's manifest is served to
122
+ * another: the cache is otherwise keyed by adapter slug and layer id alone, which are
123
+ * identical across tenants by construction.
124
+ */
125
+ cacheKey?: (ctx: IconLayerContext) => string; /** How this layer's glyphs paint. */
126
+ render: IconRenderStrategy;
127
+ };
33
128
  /**
34
129
  * An icon library adapter. `Icon`, `Assets`, and `Nodes` are importMap component
35
130
  * path strings so adapters stay serializable inside field configs.
@@ -37,15 +132,37 @@ type IconNodeMap = Record<string, IconNode[]>;
37
132
  type IconAdapter = {
38
133
  slug: string;
39
134
  label: StaticLabel; /** Lazy manifest loader; used server-side for validation and never bundled eagerly. */
40
- loadManifest: () => Promise<IconManifest>; /** importMap path of a client component rendering one icon by name, e.g. '@10x-media/fields/icon/adapters/lucide#LucideAdapterIcon'. */
135
+ loadManifest: () => Promise<IconManifest>;
136
+ /**
137
+ * Exact single-name lookup, serving validation (non-null means the name exists)
138
+ * and label resolution from one query. Supply it for a library whose contents
139
+ * change at runtime: it stays correct where a cached manifest snapshot cannot,
140
+ * and it answers without materialising the whole manifest. Omit it and the
141
+ * cached manifest index answers both.
142
+ */
143
+ resolveMeta?: (name: string, ctx: IconLayerContext) => Promise<IconMeta | null>; /** Batched `resolveMeta`; see `IconLayer.resolveMetaMany`. */
144
+ resolveMetaMany?: (names: string[], ctx: IconLayerContext) => Promise<Map<string, IconMeta>>;
145
+ /**
146
+ * Ordered sources composing this library, later winning by name. Omit for a
147
+ * single-source library, which is every adapter written before layers existed:
148
+ * `loadManifest`, `resolveMeta`, `Icon`, `Assets` and `Nodes` then drive everything
149
+ * exactly as they did.
150
+ */
151
+ layers?: IconLayer[]; /** importMap path of a client component rendering one icon by name, e.g. '@10x-media/fields/icon/adapters/lucide#LucideAdapterIcon'. */
41
152
  Icon: string; /** importMap path of a client component that loads the manifest for the admin drawer. */
42
153
  Assets: string;
43
154
  /**
44
155
  * importMap path of a client component that loads this library's bulk node-data
45
- * for fast drawer rendering. Omit for libraries that ship a single shared module
46
- * (e.g. radix); the drawer then falls back to the per-icon `Icon` component.
156
+ * for fast drawer rendering. Omit for a library with no node-data; the drawer then
157
+ * falls back to the per-icon `Icon` component.
47
158
  */
48
159
  Nodes?: string;
160
+ /**
161
+ * Canvas its `Nodes` glyphs are drawn on. Omitted means lucide's outline convention,
162
+ * which is what the drawer assumed before this existed, so every library that shipped
163
+ * without one is unaffected. A filled set must declare its own or it inherits a stroke.
164
+ */
165
+ canvas?: IconCanvas;
49
166
  version: 1;
50
167
  };
51
168
  /** Resolves which library slugs a request may pick from. */
@@ -101,5 +218,5 @@ type FieldsPluginRegistry = {
101
218
  encrypted?: EncryptedGlobalConfig;
102
219
  };
103
220
  //#endregion
104
- export { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconAvailabilityResolver, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig };
221
+ export { ColorFormat, ColorGlobalConfig, ColorPreset, ColorSchemeValue, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconAvailabilityResolver, IconCanvas, IconGlobalConfig, IconLayer, IconLayerCache, IconLayerContext, IconManifest, IconMeta, IconNode, IconNodeMap, IconRenderStrategy, KeysConfig };
105
222
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10x-media/fields",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Reusable admin fields for Payload: color picker, icon picker, encrypted fields, and more",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -128,7 +128,8 @@
128
128
  }
129
129
  },
130
130
  "dependencies": {
131
- "@tanstack/react-virtual": "^3.13.0"
131
+ "@tanstack/react-virtual": "^3.13.0",
132
+ "dompurify": "^3.2.7"
132
133
  },
133
134
  "devDependencies": {
134
135
  "@axe-core/playwright": "^4.11.3",
@@ -141,6 +142,7 @@
141
142
  "@tabler/icons": "3.31.0",
142
143
  "@tabler/icons-react": "3.31.0",
143
144
  "@testing-library/react": "^16.1.0",
145
+ "@types/jsdom": "^21.1.7",
144
146
  "@types/json-schema": "^7.0.15",
145
147
  "@types/node": "22.19.19",
146
148
  "@types/react": "19.2.15",
@@ -157,10 +159,10 @@
157
159
  "tsx": "^4.19.2",
158
160
  "typescript": "5.9.3",
159
161
  "vitest": "4.1.7",
160
- "@10x-media/tsconfig": "0.0.0",
161
- "@10x-media/vitest-config": "0.0.0",
162
162
  "@10x-media/payload-test-harness": "0.0.0",
163
- "@10x-media/tsdown-config": "0.0.0"
163
+ "@10x-media/vitest-config": "0.0.0",
164
+ "@10x-media/tsdown-config": "0.0.0",
165
+ "@10x-media/tsconfig": "0.0.0"
164
166
  },
165
167
  "publishConfig": {
166
168
  "access": "public"
@@ -174,8 +176,8 @@
174
176
  "test:unit": "vitest run src",
175
177
  "test:int": "vitest run tests/int",
176
178
  "test:dist": "REQUIRE_DIST=1 vitest run --passWithNoTests=false tests/dist",
177
- "test:matrix": "DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts && DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts",
178
- "test:container": "TEST_DB=container DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts && TEST_DB=container DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts",
179
+ "test:matrix": "DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-schemes.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts && DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-schemes.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts",
180
+ "test:container": "TEST_DB=container DB_MATRIX=mongo vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-schemes.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts && TEST_DB=container DB_MATRIX=postgres vitest run tests/int/matrix.int.spec.ts tests/int/color.int.spec.ts tests/int/color-schemes.int.spec.ts tests/int/color-format.int.spec.ts tests/int/icon.int.spec.ts tests/int/encrypted.int.spec.ts tests/int/encrypted-query.int.spec.ts",
179
181
  "test:e2e": "bash scripts/e2e.sh",
180
182
  "dev": "pnpm --filter @10x-media/fields-dev dev",
181
183
  "start": "pnpm --filter @10x-media/fields-dev start",
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveStaticLabel.js","names":[],"sources":["../../../../src/fields/icon/rsc/resolveStaticLabel.ts"],"sourcesContent":["import type { StaticLabel } from 'payload'\n\n/**\n * Resolves a StaticLabel to a plain string for the requested language. Adapter\n * and library-option labels reach the client as strings, so they must be\n * flattened server-side. Done here rather than via `@payloadcms/translations`\n * because this package does not depend on it (same reason colorField resolves\n * its own labels).\n */\nexport const resolveStaticLabel = (\n\tlabel: StaticLabel | undefined,\n\tlanguage: string\n): string | undefined => {\n\tif (label === undefined || typeof label === 'string') return label\n\treturn label[language] ?? label.en ?? Object.values(label)[0]\n}\n"],"mappings":";;;;;;;;AASA,MAAa,sBACZ,OACA,aACwB;CACxB,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAU,OAAO;CAC7D,OAAO,MAAM,aAAa,MAAM,MAAM,OAAO,OAAO,KAAK,EAAE;AAC5D"}