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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/exports/color-utils.d.ts +2 -1
  3. package/dist/exports/color-utils.js +2 -1
  4. package/dist/exports/color.d.ts +2 -1
  5. package/dist/exports/color.js +2 -1
  6. package/dist/fields/color/client/ColorField.js +45 -20
  7. package/dist/fields/color/client/ColorField.js.map +1 -1
  8. package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
  9. package/dist/fields/color/client/ColorPickerPanel.js +29 -4
  10. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  11. package/dist/fields/color/client/colorField.css +7 -0
  12. package/dist/fields/color/colorField.js +36 -8
  13. package/dist/fields/color/colorField.js.map +1 -1
  14. package/dist/fields/color/presetChip.js +10 -9
  15. package/dist/fields/color/presetChip.js.map +1 -1
  16. package/dist/fields/color/presetReference.d.ts +13 -0
  17. package/dist/fields/color/presetReference.js +94 -0
  18. package/dist/fields/color/presetReference.js.map +1 -0
  19. package/dist/fields/color/server/ColorCell.js +7 -1
  20. package/dist/fields/color/server/ColorCell.js.map +1 -1
  21. package/dist/fields/color/server/colorCell.css +5 -0
  22. package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
  23. package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
  24. package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
  25. package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
  26. package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
  27. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  28. package/dist/fields/icon/codegen/emit.js +2 -2
  29. package/dist/fields/icon/codegen/emit.js.map +1 -1
  30. package/package.json +2 -2
@@ -30,7 +30,7 @@ const EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
30
30
  */
31
31
  const UNSAFE_IN_SPECIFIER = /['\\\n\r\u2028\u2029]/;
32
32
  const emitManifestModule = (icons, categories, header = GENERATED_HEADER) => {
33
- return `${header}export const manifest: {\n\ticons: { name: string; tags: string[]; categories: string[] }[]\n\tcategories: string[]\n} = ${JSON.stringify({
33
+ return `${header}export const manifest: {\n\ticons: {\n\t\tname: string\n\t\ttags: string[]\n\t\tcategories: string[]\n\t\tlabel?: string | Record<string, string>\n\t}[]\n\tcategories: string[]\n} = ${JSON.stringify({
34
34
  icons,
35
35
  categories
36
36
  }, null, " ")}\n`;
@@ -74,7 +74,7 @@ const emitNodesModule = (icons, nodes, header = GENERATED_HEADER) => {
74
74
  for (const [tag] of glyph) if (!SVG_NODE_TAGS.has(tag)) throw new Error(`icon "${icon.name}": unexpected SVG node tag "${tag}"`);
75
75
  ordered[icon.name] = glyph;
76
76
  }
77
- return `${header}export const nodes: Record<string, [string, Record<string, string>][]> = ${JSON.stringify(ordered)}\n`;
77
+ return `${header}type GeneratedIconNode =\n\t| [string, Record<string, string>]\n\t| [string, Record<string, string>, GeneratedIconNode[]]\n\nexport const nodes: Record<string, GeneratedIconNode[]> = ${JSON.stringify(ordered)}\n`;
78
78
  };
79
79
  //#endregion
80
80
  export { emitImportsModule, emitManifestModule, emitNodesModule, generatedHeader };
@@ -1 +1 @@
1
- {"version":3,"file":"emit.js","names":[],"sources":["../../../../src/fields/icon/codegen/emit.ts"],"sourcesContent":["import type { IconMeta, IconNodeMap } from '../../../types'\nimport type { IconImportSpec } from './types'\n\n/** Regen command named in the generated-file header when a source does not override it. */\nconst DEFAULT_REGEN_COMMAND = 'pnpm generate:manifests'\n\n/** Header line telling a reader the file is generated and which command re-emits it. */\nexport const generatedHeader = (regenCommand: string = DEFAULT_REGEN_COMMAND): string =>\n\t`/* GENERATED by @10x-media/fields icon codegen. Do not edit; run \\`${regenCommand}\\`. */\\n`\n\nexport const GENERATED_HEADER = generatedHeader()\n\n/**\n * Node-data renders straight into the DOM via createElement(tag, attrs), so the\n * tag is restricted to the SVG shape elements lucide and tabler actually emit. An\n * unexpected tag means the upstream node shape changed; fail generation loudly\n * rather than commit data the drawer would render as an unknown element.\n */\nconst SVG_NODE_TAGS = new Set([\n\t'circle',\n\t'ellipse',\n\t'g',\n\t'line',\n\t'path',\n\t'polygon',\n\t'polyline',\n\t'rect',\n])\n\n/** Interpolated bare into `m.<exportName>`, so nothing but an identifier is safe. */\nconst EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * The complete set of characters that can escape a single-quoted JS string:\n * the quote, the escape character, and the four line terminators. Specifiers\n * and icon names are validated rather than escaped so a bad one fails generation\n * loudly instead of emitting a module that only breaks at import time.\n */\nconst UNSAFE_IN_SPECIFIER = /['\\\\\\n\\r\\u2028\\u2029]/\n\nexport const emitManifestModule = (\n\ticons: IconMeta[],\n\tcategories: string[],\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst data = JSON.stringify({ icons, categories }, null, '\\t')\n\treturn `${header}export const manifest: {\\n\\ticons: { name: string; tags: string[]; categories: string[] }[]\\n\\tcategories: string[]\\n} = ${data}\\n`\n}\n\nexport const emitImportsModule = (\n\ticons: IconMeta[],\n\timportFor: (icon: IconMeta) => IconImportSpec,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst lines: string[] = [\n\t\theader,\n\t\t`import type { ComponentType } from 'react'`,\n\t\t'',\n\t\t`export type GeneratedIconModule = { default: ComponentType<{ className?: string; size?: number | string }> }`,\n\t\t'',\n\t\t'const map = {',\n\t]\n\tfor (const icon of icons) {\n\t\t// The name is interpolated bare as the map key, so it needs the same guard the\n\t\t// specifier gets. `generate` rejects these too; this is the emitter standing on\n\t\t// its own, since it is exported and callable directly.\n\t\tif (UNSAFE_IN_SPECIFIER.test(icon.name)) {\n\t\t\tthrow new Error(`unsafe icon name for an emitted key: ${icon.name}`)\n\t\t}\n\t\tconst spec = importFor(icon)\n\t\tif (UNSAFE_IN_SPECIFIER.test(spec.module)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": unsafe module specifier: ${spec.module}`)\n\t\t}\n\t\tif (spec.exportName !== undefined && !EXPORT_NAME.test(spec.exportName)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": export name is not an identifier: ${spec.exportName}`)\n\t\t}\n\t\tif (spec.exportName) {\n\t\t\tlines.push(\n\t\t\t\t`\\t'${icon.name}': () => import('${spec.module}').then((m) => ({ default: m.${spec.exportName} })),`\n\t\t\t)\n\t\t} else {\n\t\t\tlines.push(`\\t'${icon.name}': () => import('${spec.module}'),`)\n\t\t}\n\t}\n\tlines.push('}')\n\tlines.push('')\n\tlines.push(\n\t\t'export const iconImports = map as unknown as Record<string, () => Promise<GeneratedIconModule>>'\n\t)\n\tlines.push('')\n\treturn lines.join('\\n')\n}\n\n/**\n * Emits a library's bulk glyph node-data, keyed by icon name in the same sorted\n * order as the manifest so a regeneration is byte-stable. The drawer lazily\n * imports this once per library and renders each glyph as inline SVG, which\n * replaces the per-icon dynamic imports that made large libraries scroll poorly.\n * Compact JSON keeps the committed file (thousands of glyphs) as small as the\n * source; the module is admin-only and never enters a frontend bundle.\n */\nexport const emitNodesModule = (\n\ticons: IconMeta[],\n\tnodes: IconNodeMap,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst ordered: IconNodeMap = {}\n\tfor (const icon of icons) {\n\t\tconst glyph = nodes[icon.name]\n\t\tif (!glyph) throw new Error(`icon \"${icon.name}\": no node-data for this manifest entry`)\n\t\tfor (const [tag] of glyph) {\n\t\t\tif (!SVG_NODE_TAGS.has(tag)) {\n\t\t\t\tthrow new Error(`icon \"${icon.name}\": unexpected SVG node tag \"${tag}\"`)\n\t\t\t}\n\t\t}\n\t\tordered[icon.name] = glyph\n\t}\n\tconst data = JSON.stringify(ordered)\n\treturn `${header}export const nodes: Record<string, [string, Record<string, string>][]> = ${data}\\n`\n}\n"],"mappings":";;AAIA,MAAM,wBAAwB;;AAG9B,MAAa,mBAAmB,eAAuB,0B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,KAAK;EACzB,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,wCAAwC;EACvF,KAAK,MAAM,CAAC,QAAQ,OACnB,IAAI,CAAC,cAAc,IAAI,GAAG,GACzB,MAAM,IAAI,MAAM,SAAS,KAAK,KAAK,8BAA8B,IAAI,EAAE;EAGzE,QAAQ,KAAK,QAAQ;CACtB;CAEA,OAAO,GAAG,OAAO,2EADJ,KAAK,UAAU,OACmE,EAAE;AAClG"}
1
+ {"version":3,"file":"emit.js","names":[],"sources":["../../../../src/fields/icon/codegen/emit.ts"],"sourcesContent":["import type { IconMeta, IconNodeMap } from '../../../types'\nimport type { IconImportSpec } from './types'\n\n/** Regen command named in the generated-file header when a source does not override it. */\nconst DEFAULT_REGEN_COMMAND = 'pnpm generate:manifests'\n\n/** Header line telling a reader the file is generated and which command re-emits it. */\nexport const generatedHeader = (regenCommand: string = DEFAULT_REGEN_COMMAND): string =>\n\t`/* GENERATED by @10x-media/fields icon codegen. Do not edit; run \\`${regenCommand}\\`. */\\n`\n\nexport const GENERATED_HEADER = generatedHeader()\n\n/**\n * Node-data renders straight into the DOM via createElement(tag, attrs), so the\n * tag is restricted to the SVG shape elements lucide and tabler actually emit. An\n * unexpected tag means the upstream node shape changed; fail generation loudly\n * rather than commit data the drawer would render as an unknown element.\n */\nconst SVG_NODE_TAGS = new Set([\n\t'circle',\n\t'ellipse',\n\t'g',\n\t'line',\n\t'path',\n\t'polygon',\n\t'polyline',\n\t'rect',\n])\n\n/** Interpolated bare into `m.<exportName>`, so nothing but an identifier is safe. */\nconst EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * The complete set of characters that can escape a single-quoted JS string:\n * the quote, the escape character, and the four line terminators. Specifiers\n * and icon names are validated rather than escaped so a bad one fails generation\n * loudly instead of emitting a module that only breaks at import time.\n */\nconst UNSAFE_IN_SPECIFIER = /['\\\\\\n\\r\\u2028\\u2029]/\n\nexport const emitManifestModule = (\n\ticons: IconMeta[],\n\tcategories: string[],\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst data = JSON.stringify({ icons, categories }, null, '\\t')\n\t// The annotation mirrors IconMeta by hand because the generated file must stand alone\n\t// with no import. Anything the data can carry must be annotated, or a consumer whose\n\t// manifest uses an optional field fails strict typecheck against our own output.\n\treturn `${header}export const manifest: {\\n\\ticons: {\\n\\t\\tname: string\\n\\t\\ttags: string[]\\n\\t\\tcategories: string[]\\n\\t\\tlabel?: string | Record<string, string>\\n\\t}[]\\n\\tcategories: string[]\\n} = ${data}\\n`\n}\n\nexport const emitImportsModule = (\n\ticons: IconMeta[],\n\timportFor: (icon: IconMeta) => IconImportSpec,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst lines: string[] = [\n\t\theader,\n\t\t`import type { ComponentType } from 'react'`,\n\t\t'',\n\t\t`export type GeneratedIconModule = { default: ComponentType<{ className?: string; size?: number | string }> }`,\n\t\t'',\n\t\t'const map = {',\n\t]\n\tfor (const icon of icons) {\n\t\t// The name is interpolated bare as the map key, so it needs the same guard the\n\t\t// specifier gets. `generate` rejects these too; this is the emitter standing on\n\t\t// its own, since it is exported and callable directly.\n\t\tif (UNSAFE_IN_SPECIFIER.test(icon.name)) {\n\t\t\tthrow new Error(`unsafe icon name for an emitted key: ${icon.name}`)\n\t\t}\n\t\tconst spec = importFor(icon)\n\t\tif (UNSAFE_IN_SPECIFIER.test(spec.module)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": unsafe module specifier: ${spec.module}`)\n\t\t}\n\t\tif (spec.exportName !== undefined && !EXPORT_NAME.test(spec.exportName)) {\n\t\t\tthrow new Error(`icon \"${icon.name}\": export name is not an identifier: ${spec.exportName}`)\n\t\t}\n\t\tif (spec.exportName) {\n\t\t\tlines.push(\n\t\t\t\t`\\t'${icon.name}': () => import('${spec.module}').then((m) => ({ default: m.${spec.exportName} })),`\n\t\t\t)\n\t\t} else {\n\t\t\tlines.push(`\\t'${icon.name}': () => import('${spec.module}'),`)\n\t\t}\n\t}\n\tlines.push('}')\n\tlines.push('')\n\tlines.push(\n\t\t'export const iconImports = map as unknown as Record<string, () => Promise<GeneratedIconModule>>'\n\t)\n\tlines.push('')\n\treturn lines.join('\\n')\n}\n\n/**\n * Emits a library's bulk glyph node-data, keyed by icon name in the same sorted\n * order as the manifest so a regeneration is byte-stable. The drawer lazily\n * imports this once per library and renders each glyph as inline SVG, which\n * replaces the per-icon dynamic imports that made large libraries scroll poorly.\n * Compact JSON keeps the committed file (thousands of glyphs) as small as the\n * source; the module is admin-only and never enters a frontend bundle.\n */\nexport const emitNodesModule = (\n\ticons: IconMeta[],\n\tnodes: IconNodeMap,\n\theader: string = GENERATED_HEADER\n): string => {\n\tconst ordered: IconNodeMap = {}\n\tfor (const icon of icons) {\n\t\tconst glyph = nodes[icon.name]\n\t\tif (!glyph) throw new Error(`icon \"${icon.name}\": no node-data for this manifest entry`)\n\t\tfor (const [tag] of glyph) {\n\t\t\tif (!SVG_NODE_TAGS.has(tag)) {\n\t\t\t\tthrow new Error(`icon \"${icon.name}\": unexpected SVG node tag \"${tag}\"`)\n\t\t\t}\n\t\t}\n\t\tordered[icon.name] = glyph\n\t}\n\tconst data = JSON.stringify(ordered)\n\t// Recursive alias mirroring IconNode, since a glyph may nest children under <g> or\n\t// <defs> and a flat tuple annotation would reject the module's own data.\n\treturn `${header}type GeneratedIconNode =\\n\\t| [string, Record<string, string>]\\n\\t| [string, Record<string, string>, GeneratedIconNode[]]\\n\\nexport const nodes: Record<string, GeneratedIconNode[]> = ${data}\\n`\n}\n"],"mappings":";;AAIA,MAAM,wBAAwB;;AAG9B,MAAa,mBAAmB,eAAuB,0BACtD,sEAAsE,aAAa;AAEpF,MAAa,mBAAmB,gBAAgB;;;;;;;AAQhD,MAAM,gBAAgB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAM,cAAc;;;;;;;AAQpB,MAAM,sBAAsB;AAE5B,MAAa,sB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E;EAGzE,QAAQ,KAAK,QAAQ;CACtB;CAIA,OAAO,GAAG,OAAO,yLAHJ,KAAK,UAAU,OAGiL,EAAE;AAChN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10x-media/fields",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Reusable admin fields for Payload: color picker, icon picker, encrypted fields, and more",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -160,8 +160,8 @@
160
160
  "typescript": "5.9.3",
161
161
  "vitest": "4.1.7",
162
162
  "@10x-media/payload-test-harness": "0.0.0",
163
- "@10x-media/vitest-config": "0.0.0",
164
163
  "@10x-media/tsdown-config": "0.0.0",
164
+ "@10x-media/vitest-config": "0.0.0",
165
165
  "@10x-media/tsconfig": "0.0.0"
166
166
  },
167
167
  "publishConfig": {