@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.
- package/CHANGELOG.md +68 -0
- package/README.md +1 -1
- package/dist/exports/color-utils.d.ts +3 -2
- package/dist/exports/color-utils.js +2 -1
- package/dist/exports/color.d.ts +4 -2
- package/dist/exports/color.js +3 -1
- package/dist/exports/icon-adapters/radix.d.ts +2 -2
- package/dist/exports/icon-adapters/radix.js +2 -2
- package/dist/exports/icon-react.d.ts +2 -2
- package/dist/exports/icon.d.ts +6 -2
- package/dist/exports/icon.js +6 -2
- package/dist/fields/color/client/ColorField.js +8 -3
- package/dist/fields/color/client/ColorField.js.map +1 -1
- package/dist/fields/color/client/ColorPickerPanel.js +2 -1
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/colorField.d.ts +9 -2
- package/dist/fields/color/colorField.js +34 -9
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/engine/index.d.ts +2 -1
- package/dist/fields/color/engine/scheme.d.ts +13 -0
- package/dist/fields/color/engine/scheme.js +12 -0
- package/dist/fields/color/engine/scheme.js.map +1 -0
- package/dist/fields/color/options.d.ts +5 -4
- package/dist/fields/color/options.js.map +1 -1
- package/dist/fields/color/paths.d.ts +1 -0
- package/dist/fields/color/paths.js +32 -0
- package/dist/fields/color/paths.js.map +1 -0
- package/dist/fields/color/presetChip.js.map +1 -1
- package/dist/fields/color/presetsFromArray.d.ts +30 -0
- package/dist/fields/color/presetsFromArray.js +58 -0
- package/dist/fields/color/presetsFromArray.js.map +1 -0
- package/dist/fields/color/presetsFromDoc.js +1 -23
- package/dist/fields/color/presetsFromDoc.js.map +1 -1
- package/dist/fields/color/resolvePresets.d.ts +2 -2
- package/dist/fields/color/resolvePresets.js +38 -8
- package/dist/fields/color/resolvePresets.js.map +1 -1
- package/dist/fields/color/schemeValue.js +30 -0
- package/dist/fields/color/schemeValue.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +2 -2
- package/dist/fields/color/server/ColorCell.js.map +1 -1
- package/dist/fields/encrypted/queryRewrite.d.ts +1 -1
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/radix/adapter.js +7 -0
- package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
- package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
- package/dist/fields/icon/adapters/radix/client.js +3 -2
- package/dist/fields/icon/adapters/radix/client.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/nodes.js +3625 -0
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/DrawerGlyph.js +34 -17
- package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
- package/dist/fields/icon/client/IconDrawerContent.js +9 -45
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
- package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
- package/dist/fields/icon/client/IconFieldClient.js +15 -7
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
- package/dist/fields/icon/client/IconGridCell.js +67 -0
- package/dist/fields/icon/client/IconGridCell.js.map +1 -0
- package/dist/fields/icon/client/icon-field.css +8 -0
- package/dist/fields/icon/codegen/emit.js +5 -4
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- package/dist/fields/icon/codegen/generate.js +32 -6
- package/dist/fields/icon/codegen/generate.js.map +1 -1
- package/dist/fields/icon/layers/coalesce.js +41 -0
- package/dist/fields/icon/layers/coalesce.js.map +1 -0
- package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
- package/dist/fields/icon/layers/manifestCache.js +49 -0
- package/dist/fields/icon/layers/manifestCache.js.map +1 -0
- package/dist/fields/icon/layers/resolve.d.ts +20 -0
- package/dist/fields/icon/layers/resolve.js +63 -0
- package/dist/fields/icon/layers/resolve.js.map +1 -0
- package/dist/fields/icon/layers/upload.d.ts +52 -0
- package/dist/fields/icon/layers/upload.js +116 -0
- package/dist/fields/icon/layers/upload.js.map +1 -0
- package/dist/fields/icon/plugin.js +24 -0
- package/dist/fields/icon/plugin.js.map +1 -1
- package/dist/fields/icon/react/createIcon.d.ts +5 -0
- package/dist/fields/icon/react/createIcon.js +22 -4
- package/dist/fields/icon/react/createIcon.js.map +1 -1
- package/dist/fields/icon/react/createRscIcon.js +22 -1
- package/dist/fields/icon/react/createRscIcon.js.map +1 -1
- package/dist/fields/icon/react/resolveRendered.js +21 -0
- package/dist/fields/icon/react/resolveRendered.js.map +1 -0
- package/dist/fields/icon/react/types.d.ts +15 -1
- package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
- package/dist/fields/icon/rsc/IconCell.js +12 -5
- package/dist/fields/icon/rsc/IconCell.js.map +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
- package/dist/fields/icon/server/endpoint.d.ts +12 -0
- package/dist/fields/icon/server/endpoint.js +52 -0
- package/dist/fields/icon/server/endpoint.js.map +1 -0
- package/dist/fields/icon/server/manifestCache.js +9 -4
- package/dist/fields/icon/server/manifestCache.js.map +1 -1
- package/dist/fields/icon/server/resolveIconMeta.js +31 -0
- package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
- package/dist/fields/icon/server/validate.js +5 -2
- package/dist/fields/icon/server/validate.js.map +1 -1
- package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
- package/dist/fields/icon/shared/iconLabel.js +26 -0
- package/dist/fields/icon/shared/iconLabel.js.map +1 -0
- package/dist/fields/icon/{rsc → shared}/resolveStaticLabel.js +1 -1
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +125 -8
- package/package.json +9 -7
- package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { resolveIconValue } from "../shared/value.js";
|
|
3
|
-
import
|
|
3
|
+
import { resolveRenderedIcon } from "./resolveRendered.js";
|
|
4
|
+
import React, { Suspense, createContext, useContext } from "react";
|
|
4
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
5
6
|
//#region src/fields/icon/react/createIcon.tsx
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Carries the caller's `fallback` down to the cached lazy component. The lazy is
|
|
9
|
+
* cached module-wide on `library:name` so a repeated value loads its chunk once,
|
|
10
|
+
* which means it cannot close over any one caller's prop. Context is how a shared
|
|
11
|
+
* component reads a per-subtree value without giving up that cache.
|
|
12
|
+
*/
|
|
13
|
+
const FallbackContext = createContext(null);
|
|
14
|
+
/** Stands in for an icon the adapter resolved to null, so a miss renders the caller's fallback. */
|
|
15
|
+
const MissingIcon = () => /* @__PURE__ */ jsx(Fragment$1, { children: useContext(FallbackContext) });
|
|
7
16
|
/**
|
|
8
17
|
* Client dispatcher: per-value React.lazy components cached module-wide so a
|
|
9
18
|
* value renders one stable lazy component (per-icon chunks, loaded once).
|
|
19
|
+
*
|
|
20
|
+
* A rejected load stays cached, because React.lazy caches its own rejection.
|
|
21
|
+
* That is deliberate: retrying would re-request a failing icon on every render
|
|
22
|
+
* against an endpoint already struggling. `createRscIcon` evicts instead, because
|
|
23
|
+
* a server render has no equivalent re-render pressure.
|
|
10
24
|
*/
|
|
11
25
|
const createIcon = (args) => {
|
|
12
26
|
const bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]));
|
|
@@ -18,7 +32,7 @@ const createIcon = (args) => {
|
|
|
18
32
|
const key = `${library}:${name}`;
|
|
19
33
|
let component = cache.get(key);
|
|
20
34
|
if (!component) {
|
|
21
|
-
component = React.lazy(async () => ({ default: await adapter
|
|
35
|
+
component = React.lazy(async () => ({ default: await resolveRenderedIcon(adapter, name) ?? MissingIcon }));
|
|
22
36
|
cache.set(key, component);
|
|
23
37
|
}
|
|
24
38
|
return component;
|
|
@@ -28,7 +42,7 @@ const createIcon = (args) => {
|
|
|
28
42
|
const { library, name } = resolveIconValue(icon, defaultLibrary);
|
|
29
43
|
const Component = lazyFor(library, name);
|
|
30
44
|
if (!Component) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback });
|
|
31
|
-
|
|
45
|
+
const tree = /* @__PURE__ */ jsx(Suspense, {
|
|
32
46
|
fallback,
|
|
33
47
|
children: /* @__PURE__ */ jsx(Component, {
|
|
34
48
|
"aria-hidden": label ? void 0 : true,
|
|
@@ -38,6 +52,10 @@ const createIcon = (args) => {
|
|
|
38
52
|
size
|
|
39
53
|
})
|
|
40
54
|
});
|
|
55
|
+
return fallback == null ? tree : /* @__PURE__ */ jsx(FallbackContext.Provider, {
|
|
56
|
+
value: fallback,
|
|
57
|
+
children: tree
|
|
58
|
+
});
|
|
41
59
|
};
|
|
42
60
|
return Icon;
|
|
43
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createIcon.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentType } from 'react'\nimport React, { Suspense } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport type { IconProps, IconRendererAdapter, IconRenderProps } from './types'\n\nconst
|
|
1
|
+
{"version":3,"file":"createIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createIcon.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentType, ReactNode } from 'react'\nimport React, { createContext, Suspense, useContext } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport { resolveRenderedIcon } from './resolveRendered'\nimport type { IconProps, IconRendererAdapter, IconRenderProps } from './types'\n\n/**\n * Carries the caller's `fallback` down to the cached lazy component. The lazy is\n * cached module-wide on `library:name` so a repeated value loads its chunk once,\n * which means it cannot close over any one caller's prop. Context is how a shared\n * component reads a per-subtree value without giving up that cache.\n */\nconst FallbackContext = createContext<ReactNode>(null)\n\n/** Stands in for an icon the adapter resolved to null, so a miss renders the caller's fallback. */\nconst MissingIcon: ComponentType<IconRenderProps> = () => <>{useContext(FallbackContext)}</>\n\n/**\n * Client dispatcher: per-value React.lazy components cached module-wide so a\n * value renders one stable lazy component (per-icon chunks, loaded once).\n *\n * A rejected load stays cached, because React.lazy caches its own rejection.\n * That is deliberate: retrying would re-request a failing icon on every render\n * against an endpoint already struggling. `createRscIcon` evicts instead, because\n * a server render has no equivalent re-render pressure.\n */\nexport const createIcon = (args: {\n\tadapters: IconRendererAdapter[]\n\tdefaultLibrary?: string\n}): React.FC<IconProps> => {\n\tconst bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]))\n\tconst defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? ''\n\tconst cache = new Map<string, ComponentType<IconRenderProps>>()\n\n\tconst lazyFor = (library: string, name: string): ComponentType<IconRenderProps> | null => {\n\t\tconst adapter = bySlug.get(library)\n\t\tif (!adapter) return null\n\t\tconst key = `${library}:${name}`\n\t\tlet component = cache.get(key)\n\t\tif (!component) {\n\t\t\tcomponent = React.lazy(async () => ({\n\t\t\t\tdefault: (await resolveRenderedIcon(adapter, name)) ?? MissingIcon,\n\t\t\t})) as unknown as ComponentType<IconRenderProps>\n\t\t\tcache.set(key, component)\n\t\t}\n\t\treturn component\n\t}\n\n\tconst Icon: React.FC<IconProps> = ({ className, fallback = null, icon, label, size = 20 }) => {\n\t\tif (!icon) return <>{fallback}</>\n\t\tconst { library, name } = resolveIconValue(icon, defaultLibrary)\n\t\tconst Component = lazyFor(library, name)\n\t\tif (!Component) return <>{fallback}</>\n\t\tconst tree = (\n\t\t\t<Suspense fallback={fallback}>\n\t\t\t\t<Component\n\t\t\t\t\taria-hidden={label ? undefined : true}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tclassName={className}\n\t\t\t\t\trole={label ? 'img' : undefined}\n\t\t\t\t\tsize={size}\n\t\t\t\t/>\n\t\t\t</Suspense>\n\t\t)\n\t\t// Provider only where there is something to carry, so the common decorative\n\t\t// call renders exactly the tree it always did.\n\t\treturn fallback == null ? (\n\t\t\ttree\n\t\t) : (\n\t\t\t<FallbackContext.Provider value={fallback}>{tree}</FallbackContext.Provider>\n\t\t)\n\t}\n\treturn Icon\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,kBAAkB,cAAyB,IAAI;;AAGrD,MAAM,oBAAoD,oBAAA,YAAA,EAAA,UAAG,WAAW,eAAe,EAAI,CAAA;;;;;;;;;;AAW3F,MAAa,cAAc,SAGA;CAC1B,MAAM,SAAS,IAAI,IAAI,KAAK,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC;CAC9E,MAAM,iBAAiB,KAAK,kBAAkB,KAAK,SAAS,IAAI,QAAQ;CACxE,MAAM,wBAAQ,IAAI,IAA4C;CAE9D,MAAM,WAAW,SAAiB,SAAwD;EACzF,MAAM,UAAU,OAAO,IAAI,OAAO;EAClC,IAAI,CAAC,SAAS,OAAO;EACrB,MAAM,MAAM,GAAG,QAAQ,GAAG;EAC1B,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACf,YAAY,MAAM,KAAK,aAAa,EACnC,SAAU,MAAM,oBAAoB,SAAS,IAAI,KAAM,YACxD,EAAE;GACF,MAAM,IAAI,KAAK,SAAS;EACzB;EACA,OAAO;CACR;CAEA,MAAM,QAA6B,EAAE,WAAW,WAAW,MAAM,MAAM,OAAO,OAAO,SAAS;EAC7F,IAAI,CAAC,MAAM,OAAO,oBAAA,YAAA,EAAA,UAAG,SAAW,CAAA;EAChC,MAAM,EAAE,SAAS,SAAS,iBAAiB,MAAM,cAAc;EAC/D,MAAM,YAAY,QAAQ,SAAS,IAAI;EACvC,IAAI,CAAC,WAAW,OAAO,oBAAA,YAAA,EAAA,UAAG,SAAW,CAAA;EACrC,MAAM,OACL,oBAAC,UAAD;GAAoB;aACnB,oBAAC,WAAD;IACC,eAAa,QAAQ,KAAA,IAAY;IACjC,cAAY;IACD;IACX,MAAM,QAAQ,QAAQ,KAAA;IAChB;GACN,CAAA;EACQ,CAAA;EAIX,OAAO,YAAY,OAClB,OAEA,oBAAC,gBAAgB,UAAjB;GAA0B,OAAO;aAAW;EAA+B,CAAA;CAE7E;CACA,OAAO;AACR"}
|
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
import { resolveIconValue } from "../shared/value.js";
|
|
2
|
+
import { resolveRenderedIcon } from "./resolveRendered.js";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
//#region src/fields/icon/react/createRscIcon.tsx
|
|
4
5
|
/** Async server component factory: the per-icon import is awaited server-side and the SVG streams with zero client JS. */
|
|
5
6
|
const createRscIcon = (args) => {
|
|
6
7
|
const bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]));
|
|
7
8
|
const defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? "";
|
|
9
|
+
/**
|
|
10
|
+
* Per-value resolution cache. A static `loadIcon` already rides the module
|
|
11
|
+
* cache, so this only earns its keep for an adapter that fetches, where it
|
|
12
|
+
* turns one request per render into one per process.
|
|
13
|
+
*
|
|
14
|
+
* Unconditionally permanent, which is safe only while every renderer adapter
|
|
15
|
+
* is a single static source. Revisit alongside per-layer cache policy; a
|
|
16
|
+
* dynamic layer against a permanent cache would serve a stale glyph forever.
|
|
17
|
+
*/
|
|
18
|
+
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const resolve = (adapter, name) => {
|
|
20
|
+
const key = `${adapter.slug}:${name}`;
|
|
21
|
+
let entry = cache.get(key);
|
|
22
|
+
if (!entry) {
|
|
23
|
+
entry = resolveRenderedIcon(adapter, name);
|
|
24
|
+
cache.set(key, entry);
|
|
25
|
+
entry.catch(() => cache.delete(key));
|
|
26
|
+
}
|
|
27
|
+
return entry;
|
|
28
|
+
};
|
|
8
29
|
return async ({ className, fallback = null, icon, label, size = 20 }) => {
|
|
9
30
|
if (!icon) return fallback;
|
|
10
31
|
const { library, name } = resolveIconValue(icon, defaultLibrary);
|
|
11
32
|
const adapter = bySlug.get(library);
|
|
12
33
|
if (!adapter) return fallback;
|
|
13
|
-
const Component = await adapter
|
|
34
|
+
const Component = await resolve(adapter, name);
|
|
14
35
|
if (!Component) return fallback;
|
|
15
36
|
return /* @__PURE__ */ jsx(Component, {
|
|
16
37
|
"aria-hidden": label ? void 0 : true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRscIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createRscIcon.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport type { IconProps, IconRendererAdapter } from './types'\n\n/** Async server component factory: the per-icon import is awaited server-side and the SVG streams with zero client JS. */\nexport const createRscIcon = (args: {\n\tadapters: IconRendererAdapter[]\n\tdefaultLibrary?: string\n}): ((props: IconProps) => Promise<ReactNode>) => {\n\tconst bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]))\n\tconst defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? ''\n\n\treturn async ({ className, fallback = null, icon, label, size = 20 }: IconProps) => {\n\t\tif (!icon) return fallback\n\t\tconst { library, name } = resolveIconValue(icon, defaultLibrary)\n\t\tconst adapter = bySlug.get(library)\n\t\tif (!adapter) return fallback\n\t\tconst Component = await adapter
|
|
1
|
+
{"version":3,"file":"createRscIcon.js","names":[],"sources":["../../../../src/fields/icon/react/createRscIcon.tsx"],"sourcesContent":["import type { ComponentType, ReactNode } from 'react'\nimport { resolveIconValue } from '../shared/value'\nimport { resolveRenderedIcon } from './resolveRendered'\nimport type { IconProps, IconRendererAdapter, IconRenderProps } from './types'\n\n/** Async server component factory: the per-icon import is awaited server-side and the SVG streams with zero client JS. */\nexport const createRscIcon = (args: {\n\tadapters: IconRendererAdapter[]\n\tdefaultLibrary?: string\n}): ((props: IconProps) => Promise<ReactNode>) => {\n\tconst bySlug = new Map(args.adapters.map((adapter) => [adapter.slug, adapter]))\n\tconst defaultLibrary = args.defaultLibrary ?? args.adapters[0]?.slug ?? ''\n\t/**\n\t * Per-value resolution cache. A static `loadIcon` already rides the module\n\t * cache, so this only earns its keep for an adapter that fetches, where it\n\t * turns one request per render into one per process.\n\t *\n\t * Unconditionally permanent, which is safe only while every renderer adapter\n\t * is a single static source. Revisit alongside per-layer cache policy; a\n\t * dynamic layer against a permanent cache would serve a stale glyph forever.\n\t */\n\tconst cache = new Map<string, Promise<ComponentType<IconRenderProps> | null>>()\n\n\tconst resolve = (\n\t\tadapter: IconRendererAdapter,\n\t\tname: string\n\t): Promise<ComponentType<IconRenderProps> | null> => {\n\t\tconst key = `${adapter.slug}:${name}`\n\t\tlet entry = cache.get(key)\n\t\tif (!entry) {\n\t\t\tentry = resolveRenderedIcon(adapter, name)\n\t\t\tcache.set(key, entry)\n\t\t\t// A rejected load must not poison the icon for the process lifetime; evict\n\t\t\t// so the next render retries. Same contract as the manifest cache, and the\n\t\t\t// reason this cache is safe for a network-backed adapter at all.\n\t\t\tvoid entry.catch(() => cache.delete(key))\n\t\t}\n\t\treturn entry\n\t}\n\n\treturn async ({ className, fallback = null, icon, label, size = 20 }: IconProps) => {\n\t\tif (!icon) return fallback\n\t\tconst { library, name } = resolveIconValue(icon, defaultLibrary)\n\t\tconst adapter = bySlug.get(library)\n\t\tif (!adapter) return fallback\n\t\tconst Component = await resolve(adapter, name)\n\t\tif (!Component) return fallback\n\t\treturn (\n\t\t\t<Component\n\t\t\t\taria-hidden={label ? undefined : true}\n\t\t\t\taria-label={label}\n\t\t\t\tclassName={className}\n\t\t\t\trole={label ? 'img' : undefined}\n\t\t\t\tsize={size}\n\t\t\t/>\n\t\t)\n\t}\n}\n"],"mappings":";;;;;AAMA,MAAa,iBAAiB,SAGoB;CACjD,MAAM,SAAS,IAAI,IAAI,KAAK,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC;CAC9E,MAAM,iBAAiB,KAAK,kBAAkB,KAAK,SAAS,IAAI,QAAQ;;;;;;;;;;CAUxE,MAAM,wBAAQ,IAAI,IAA4D;CAE9E,MAAM,WACL,SACA,SACoD;EACpD,MAAM,MAAM,GAAG,QAAQ,KAAK,GAAG;EAC/B,IAAI,QAAQ,MAAM,IAAI,GAAG;EACzB,IAAI,CAAC,OAAO;GACX,QAAQ,oBAAoB,SAAS,IAAI;GACzC,MAAM,IAAI,KAAK,KAAK;GAIpB,MAAW,YAAY,MAAM,OAAO,GAAG,CAAC;EACzC;EACA,OAAO;CACR;CAEA,OAAO,OAAO,EAAE,WAAW,WAAW,MAAM,MAAM,OAAO,OAAO,SAAoB;EACnF,IAAI,CAAC,MAAM,OAAO;EAClB,MAAM,EAAE,SAAS,SAAS,iBAAiB,MAAM,cAAc;EAC/D,MAAM,UAAU,OAAO,IAAI,OAAO;EAClC,IAAI,CAAC,SAAS,OAAO;EACrB,MAAM,YAAY,MAAM,QAAQ,SAAS,IAAI;EAC7C,IAAI,CAAC,WAAW,OAAO;EACvB,OACC,oBAAC,WAAD;GACC,eAAa,QAAQ,KAAA,IAAY;GACjC,cAAY;GACD;GACX,MAAM,QAAQ,QAAQ,KAAA;GAChB;EACN,CAAA;CAEH;AACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/fields/icon/react/resolveRendered.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves one icon through an adapter's layers, newest first, so an override wins and an
|
|
4
|
+
* older layer still answers names the newer one lacks. An adapter with no layers falls
|
|
5
|
+
* back to `loadIcon`, which is every renderer written before layers existed.
|
|
6
|
+
*/
|
|
7
|
+
const resolveRenderedIcon = async (adapter, name) => {
|
|
8
|
+
const layers = adapter.layers;
|
|
9
|
+
if (layers && layers.length > 0) {
|
|
10
|
+
for (let index = layers.length - 1; index >= 0; index -= 1) {
|
|
11
|
+
const resolved = await layers[index]?.loadIcon(name);
|
|
12
|
+
if (resolved) return resolved;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return adapter.loadIcon(name);
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { resolveRenderedIcon };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=resolveRendered.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveRendered.js","names":[],"sources":["../../../../src/fields/icon/react/resolveRendered.ts"],"sourcesContent":["import type { ComponentType } from 'react'\nimport type { IconRendererAdapter, IconRenderProps } from './types'\n\n/**\n * Resolves one icon through an adapter's layers, newest first, so an override wins and an\n * older layer still answers names the newer one lacks. An adapter with no layers falls\n * back to `loadIcon`, which is every renderer written before layers existed.\n */\nexport const resolveRenderedIcon = async (\n\tadapter: IconRendererAdapter,\n\tname: string\n): Promise<ComponentType<IconRenderProps> | null> => {\n\tconst layers = adapter.layers\n\tif (layers && layers.length > 0) {\n\t\tfor (let index = layers.length - 1; index >= 0; index -= 1) {\n\t\t\tconst resolved = await layers[index]?.loadIcon(name)\n\t\t\tif (resolved) return resolved\n\t\t}\n\t\treturn null\n\t}\n\treturn adapter.loadIcon(name)\n}\n"],"mappings":";;;;;;AAQA,MAAa,sBAAsB,OAClC,SACA,SACoD;CACpD,MAAM,SAAS,QAAQ;CACvB,IAAI,UAAU,OAAO,SAAS,GAAG;EAChC,KAAK,IAAI,QAAQ,OAAO,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG;GAC3D,MAAM,WAAW,MAAM,OAAO,QAAQ,SAAS,IAAI;GACnD,IAAI,UAAU,OAAO;EACtB;EACA,OAAO;CACR;CACA,OAAO,QAAQ,SAAS,IAAI;AAC7B"}
|
|
@@ -8,9 +8,23 @@ type IconRenderProps = {
|
|
|
8
8
|
role?: string;
|
|
9
9
|
size?: number | string;
|
|
10
10
|
};
|
|
11
|
+
/** One frontend source within a library. Later layers win, matching the admin-side order. */
|
|
12
|
+
type IconRendererLayer = {
|
|
13
|
+
loadIcon: (name: string) => Promise<ComponentType<IconRenderProps> | null>;
|
|
14
|
+
};
|
|
11
15
|
type IconRendererAdapter = {
|
|
12
16
|
slug: string; /** Resolves one icon component by name, or null when unknown. Must import per icon (or per library where the package is single-module). */
|
|
13
17
|
loadIcon: (name: string) => Promise<ComponentType<IconRenderProps> | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Ordered sources, later winning, for a library whose frontend glyphs come from more
|
|
20
|
+
* than one place: a static package plus overrides, say. Each is asked in turn until one
|
|
21
|
+
* resolves, so an older layer still serves names a newer one lacks. Omit it and
|
|
22
|
+
* `loadIcon` drives everything, which is every renderer written before layers existed.
|
|
23
|
+
*
|
|
24
|
+
* Kept separate from the admin `IconAdapter` on purpose: merging them would drag
|
|
25
|
+
* manifest and drawer code into a frontend bundle.
|
|
26
|
+
*/
|
|
27
|
+
layers?: IconRendererLayer[];
|
|
14
28
|
};
|
|
15
29
|
type IconProps = {
|
|
16
30
|
className?: string;
|
|
@@ -20,5 +34,5 @@ type IconProps = {
|
|
|
20
34
|
size?: number | string;
|
|
21
35
|
};
|
|
22
36
|
//#endregion
|
|
23
|
-
export { IconProps, IconRenderProps, IconRendererAdapter };
|
|
37
|
+
export { IconProps, IconRenderProps, IconRendererAdapter, IconRendererLayer };
|
|
24
38
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -7,8 +7,8 @@ type IconCellProps = {
|
|
|
7
7
|
adapters?: IconAdapter[];
|
|
8
8
|
defaultLibrary?: string;
|
|
9
9
|
} & DefaultServerCellComponentProps;
|
|
10
|
-
/** List cell: the selected glyph plus its
|
|
11
|
-
declare const IconCell: (props: IconCellProps) => ReactNode
|
|
10
|
+
/** List cell: the selected glyph plus its label, degrading to name-only for unavailable or removed libraries. */
|
|
11
|
+
declare const IconCell: (props: IconCellProps) => Promise<ReactNode>;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { IconCell };
|
|
14
14
|
//# sourceMappingURL=IconCell.d.ts.map
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveIconDisplay } from "../shared/iconLabel.js";
|
|
3
3
|
import { resolveIconValue } from "../shared/value.js";
|
|
4
|
+
import { resolveIconMeta } from "../server/resolveIconMeta.js";
|
|
4
5
|
import { getFromImportMap } from "payload/shared";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
//#region src/fields/icon/rsc/IconCell.tsx
|
|
7
|
-
/** List cell: the selected glyph plus its
|
|
8
|
-
const IconCell = (props) => {
|
|
9
|
-
const { cellData, payload } = props;
|
|
8
|
+
/** List cell: the selected glyph plus its label, degrading to name-only for unavailable or removed libraries. */
|
|
9
|
+
const IconCell = async (props) => {
|
|
10
|
+
const { cellData, i18n, payload } = props;
|
|
10
11
|
if (typeof cellData !== "string" || cellData === "") return null;
|
|
11
12
|
const registryIcon = getFieldsRegistry(payload.config)?.icon;
|
|
12
13
|
const adapters = props.adapters ?? registryIcon?.adapters ?? [];
|
|
@@ -18,12 +19,18 @@ const IconCell = (props) => {
|
|
|
18
19
|
schemaPath: "fields-icon-cell",
|
|
19
20
|
silent: true
|
|
20
21
|
}) : null;
|
|
22
|
+
const meta = adapter ? await resolveIconMeta(adapter, name, { payload }) : null;
|
|
23
|
+
const display = resolveIconDisplay({
|
|
24
|
+
language: i18n.language,
|
|
25
|
+
meta,
|
|
26
|
+
name
|
|
27
|
+
});
|
|
21
28
|
return /* @__PURE__ */ jsxs("span", {
|
|
22
29
|
className: "tenx-icon-cell",
|
|
23
30
|
children: [Icon ? /* @__PURE__ */ jsx(Icon, {
|
|
24
31
|
name,
|
|
25
32
|
size: 16
|
|
26
|
-
}) : null, /* @__PURE__ */ jsx("span", { children:
|
|
33
|
+
}) : null, /* @__PURE__ */ jsx("span", { children: display.label })]
|
|
27
34
|
});
|
|
28
35
|
};
|
|
29
36
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconCell.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter } from '../../../types'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport {
|
|
1
|
+
{"version":3,"file":"IconCell.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconCell.tsx"],"sourcesContent":["import type { DefaultServerCellComponentProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter } from '../../../types'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveIconDisplay } from '../shared/iconLabel'\nimport { resolveIconValue } from '../shared/value'\n\ntype IconCellProps = {\n\tadapters?: IconAdapter[]\n\tdefaultLibrary?: string\n} & DefaultServerCellComponentProps\n\n/** List cell: the selected glyph plus its label, degrading to name-only for unavailable or removed libraries. */\nexport const IconCell = async (props: IconCellProps): Promise<ReactNode> => {\n\tconst { cellData, i18n, payload } = props\n\tif (typeof cellData !== 'string' || cellData === '') return null\n\tconst registryIcon = getFieldsRegistry(payload.config)?.icon\n\tconst adapters = props.adapters ?? registryIcon?.adapters ?? []\n\tconst defaultLibrary =\n\t\tprops.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? ''\n\tconst { library, name } = resolveIconValue(cellData, defaultLibrary)\n\tconst adapter = adapters.find((candidate) => candidate.slug === library)\n\tconst Icon = adapter\n\t\t? getFromImportMap<AdapterComponentsEntry['Icon']>({\n\t\t\t\timportMap: payload.importMap,\n\t\t\t\tPayloadComponent: adapter.Icon,\n\t\t\t\tschemaPath: 'fields-icon-cell',\n\t\t\t\tsilent: true,\n\t\t\t})\n\t\t: null\n\t// A cached manifest index makes this a map hit for a static library, so a long list\n\t// costs nothing extra. Payload renders cells without a request, hence no `req`.\n\tconst meta = adapter ? await resolveIconMeta(adapter, name, { payload }) : null\n\tconst display = resolveIconDisplay({ language: i18n.language, meta, name })\n\treturn (\n\t\t<span className=\"tenx-icon-cell\">\n\t\t\t{Icon ? <Icon name={name} size={16} /> : null}\n\t\t\t<span>{display.label}</span>\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;;AAgBA,MAAa,WAAW,OAAO,UAA6C;CAC3E,MAAM,EAAE,UAAU,MAAM,YAAY;CACpC,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,OAAO;CAC5D,MAAM,eAAe,kBAAkB,QAAQ,MAAM,GAAG;CACxD,MAAM,WAAW,MAAM,YAAY,cAAc,YAAY,CAAC;CAG9D,MAAM,EAAE,SAAS,SAAS,iBAAiB,UAD1C,MAAM,kBAAkB,cAAc,kBAAkB,SAAS,IAAI,QAAQ,EACX;CACnE,MAAM,UAAU,SAAS,MAAM,cAAc,UAAU,SAAS,OAAO;CACvE,MAAM,OAAO,UACV,iBAAiD;EACjD,WAAW,QAAQ;EACnB,kBAAkB,QAAQ;EAC1B,YAAY;EACZ,QAAQ;CACT,CAAC,IACA;CAGH,MAAM,OAAO,UAAU,MAAM,gBAAgB,SAAS,MAAM,EAAE,QAAQ,CAAC,IAAI;CAC3E,MAAM,UAAU,mBAAmB;EAAE,UAAU,KAAK;EAAU;EAAM;CAAK,CAAC;CAC1E,OACC,qBAAC,QAAD;EAAM,WAAU;YAAhB,CACE,OAAO,oBAAC,MAAD;GAAY;GAAM,MAAM;EAAK,CAAA,IAAI,MACzC,oBAAC,QAAD,EAAA,UAAO,QAAQ,MAAY,CAAA,CACtB;;AAER"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
-
import { IconField } from "../client/IconFieldClient.js";
|
|
3
2
|
import { resolveAvailableLibraries, unionAlwaysAvailable } from "../server/availability.js";
|
|
4
|
-
import { resolveStaticLabel } from "
|
|
3
|
+
import { resolveStaticLabel } from "../shared/resolveStaticLabel.js";
|
|
4
|
+
import { resolveIconValue } from "../shared/value.js";
|
|
5
|
+
import { IconField } from "../client/IconFieldClient.js";
|
|
6
|
+
import { resolveIconMeta } from "../server/resolveIconMeta.js";
|
|
5
7
|
import { getFromImportMap } from "payload/shared";
|
|
6
8
|
import { jsx } from "react/jsx-runtime";
|
|
7
9
|
//#region src/fields/icon/rsc/IconFieldServer.tsx
|
|
@@ -48,10 +50,21 @@ const IconFieldServer = async (props) => {
|
|
|
48
50
|
}) : void 0;
|
|
49
51
|
if (Icon && Assets) adapterComponents[adapter.slug] = {
|
|
50
52
|
Assets,
|
|
53
|
+
canvas: adapter.canvas,
|
|
51
54
|
Icon,
|
|
52
55
|
Nodes
|
|
53
56
|
};
|
|
54
57
|
}
|
|
58
|
+
const storedValue = typeof siblingData?.[String(clientField.name)] === "string" ? siblingData[String(clientField.name)] : null;
|
|
59
|
+
let selectedMeta = null;
|
|
60
|
+
if (storedValue !== null && storedValue !== "") {
|
|
61
|
+
const { library, name } = resolveIconValue(storedValue, defaultLibrary);
|
|
62
|
+
const adapter = adapters.find((candidate) => candidate.slug === library);
|
|
63
|
+
if (adapter) selectedMeta = await resolveIconMeta(adapter, name, {
|
|
64
|
+
payload,
|
|
65
|
+
req
|
|
66
|
+
});
|
|
67
|
+
}
|
|
55
68
|
return /* @__PURE__ */ jsx(IconField, {
|
|
56
69
|
adapterComponents,
|
|
57
70
|
adapters: adapters.map((adapter) => ({
|
|
@@ -65,6 +78,7 @@ const IconFieldServer = async (props) => {
|
|
|
65
78
|
permissions,
|
|
66
79
|
readOnly,
|
|
67
80
|
schemaPath,
|
|
81
|
+
selectedMeta,
|
|
68
82
|
showTextInput: props.showTextInput === true
|
|
69
83
|
});
|
|
70
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveStaticLabel } from '
|
|
1
|
+
{"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveStaticLabel } from '../shared/resolveStaticLabel'\nimport { resolveIconValue } from '../shared/value'\n\ntype IconFieldServerExtraProps = {\n\tadapters?: IconAdapter[]\n\talwaysAvailable?: string[]\n\tdefaultLibrary?: string\n\tresolveAvailable?: IconAvailabilityResolver\n\tshowTextInput?: boolean\n}\n\ntype ServerProps = IconFieldServerExtraProps & TextFieldServerProps\n\n/**\n * Resolves adapters (inline beats registry), availability (memoized per request,\n * fails open), and adapter client components from the importMap, then renders the\n * client field with those component references as props. A missing importMap entry\n * degrades to no glyph for that library rather than throwing, so the edit view\n * never 500s over a mis-registered adapter.\n */\nexport const IconFieldServer = async (props: ServerProps): Promise<ReactNode> => {\n\tconst {\n\t\tclientField,\n\t\tdata,\n\t\ti18n,\n\t\tpath,\n\t\tpayload,\n\t\tpermissions,\n\t\treadOnly,\n\t\treq,\n\t\tschemaPath,\n\t\tsiblingData,\n\t} = props\n\tconst registryIcon = getFieldsRegistry(payload.config)?.icon\n\tconst adapters = props.adapters ?? registryIcon?.adapters ?? []\n\tconst defaultLibrary =\n\t\tprops.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? ''\n\tconst resolver = props.resolveAvailable ?? registryIcon?.resolveAvailable\n\tconst alwaysAvailable = unionAlwaysAvailable(props.alwaysAvailable, registryIcon?.alwaysAvailable)\n\n\tconst available = await resolveAvailableLibraries({\n\t\tadapters,\n\t\talwaysAvailable,\n\t\tdata: data as Record<string, unknown> | undefined,\n\t\treq,\n\t\tresolver,\n\t\tsiblingData: siblingData as Record<string, unknown> | undefined,\n\t})\n\n\tconst adapterComponents: Record<string, AdapterComponentsEntry> = {}\n\tfor (const adapter of adapters) {\n\t\tconst Icon = getFromImportMap<AdapterComponentsEntry['Icon']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Icon,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\tconst Assets = getFromImportMap<AdapterComponentsEntry['Assets']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Assets,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\t// Optional: libraries with bulk node-data (lucide, tabler) resolve a Nodes\n\t\t// loader so the drawer renders glyphs inline; radix omits it and falls back\n\t\t// to the per-icon Icon component.\n\t\tconst Nodes = adapter.Nodes\n\t\t\t? getFromImportMap<NonNullable<AdapterComponentsEntry['Nodes']>>({\n\t\t\t\t\timportMap: payload.importMap,\n\t\t\t\t\tPayloadComponent: adapter.Nodes,\n\t\t\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\t\t\tsilent: true,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tif (Icon && Assets)\n\t\t\tadapterComponents[adapter.slug] = { Assets, canvas: adapter.canvas, Icon, Nodes }\n\t}\n\n\t// The trigger renders from a stored value alone, so a library-supplied label has to\n\t// arrive with it. A miss is not an error here: an unknown or removed icon still\n\t// renders, falling back to the name-derived label exactly as before.\n\tconst storedValue =\n\t\ttypeof siblingData?.[String(clientField.name)] === 'string'\n\t\t\t? (siblingData[String(clientField.name)] as string)\n\t\t\t: null\n\tlet selectedMeta = null\n\tif (storedValue !== null && storedValue !== '') {\n\t\tconst { library, name } = resolveIconValue(storedValue, defaultLibrary)\n\t\tconst adapter = adapters.find((candidate) => candidate.slug === library)\n\t\tif (adapter) selectedMeta = await resolveIconMeta(adapter, name, { payload, req })\n\t}\n\n\treturn (\n\t\t<IconField\n\t\t\tadapterComponents={adapterComponents}\n\t\t\tadapters={adapters.map((adapter) => ({\n\t\t\t\tlabel: resolveStaticLabel(adapter.label, i18n.language) ?? adapter.slug,\n\t\t\t\tslug: adapter.slug,\n\t\t\t}))}\n\t\t\tavailable={available}\n\t\t\tdefaultLibrary={defaultLibrary}\n\t\t\tfield={clientField}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t\tselectedMeta={selectedMeta}\n\t\t\tshowTextInput={props.showTextInput === true}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,MAAa,kBAAkB,OAAO,UAA2C;CAChF,MAAM,EACL,aACA,MACA,MACA,MACA,SACA,aACA,UACA,KACA,YACA,gBACG;CACJ,MAAM,eAAe,kBAAkB,QAAQ,MAAM,GAAG;CACxD,MAAM,WAAW,MAAM,YAAY,cAAc,YAAY,CAAC;CAC9D,MAAM,iBACL,MAAM,kBAAkB,cAAc,kBAAkB,SAAS,IAAI,QAAQ;CAC9E,MAAM,WAAW,MAAM,oBAAoB,cAAc;CAGzD,MAAM,YAAY,MAAM,0BAA0B;EACjD;EACA,iBAJuB,qBAAqB,MAAM,iBAAiB,cAAc,eAInE;EACR;EACN;EACA;EACa;CACd,CAAC;CAED,MAAM,oBAA4D,CAAC;CACnE,KAAK,MAAM,WAAW,UAAU;EAC/B,MAAM,OAAO,iBAAiD;GAC7D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EACD,MAAM,SAAS,iBAAmD;GACjE,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EAID,MAAM,QAAQ,QAAQ,QACnB,iBAA+D;GAC/D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC,IACA,KAAA;EACH,IAAI,QAAQ,QACX,kBAAkB,QAAQ,QAAQ;GAAE;GAAQ,QAAQ,QAAQ;GAAQ;GAAM;EAAM;CAClF;CAKA,MAAM,cACL,OAAO,cAAc,OAAO,YAAY,IAAI,OAAO,WAC/C,YAAY,OAAO,YAAY,IAAI,KACpC;CACJ,IAAI,eAAe;CACnB,IAAI,gBAAgB,QAAQ,gBAAgB,IAAI;EAC/C,MAAM,EAAE,SAAS,SAAS,iBAAiB,aAAa,cAAc;EACtE,MAAM,UAAU,SAAS,MAAM,cAAc,UAAU,SAAS,OAAO;EACvE,IAAI,SAAS,eAAe,MAAM,gBAAgB,SAAS,MAAM;GAAE;GAAS;EAAI,CAAC;CAClF;CAEA,OACC,oBAAC,WAAD;EACoB;EACnB,UAAU,SAAS,KAAK,aAAa;GACpC,OAAO,mBAAmB,QAAQ,OAAO,KAAK,QAAQ,KAAK,QAAQ;GACnE,MAAM,QAAQ;EACf,EAAE;EACS;EACK;EAChB,OAAO;EACD;EACO;EACH;EACE;EACE;EACd,eAAe,MAAM,kBAAkB;CACvC,CAAA;AAEH"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { resolveStaticLabel } from "../shared/resolveStaticLabel.js";
|
|
1
2
|
import { IconLibrarySelect } from "../client/IconLibrarySelect.js";
|
|
2
|
-
import { resolveStaticLabel } from "./resolveStaticLabel.js";
|
|
3
3
|
import { getIconLibraryOptions } from "../server/libraryOptions.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/fields/icon/rsc/IconLibrarySelectServer.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport { IconLibrarySelect } from '../client/IconLibrarySelect'\nimport { getIconLibraryOptions } from '../server/libraryOptions'\nimport { resolveStaticLabel } from '
|
|
1
|
+
{"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport { IconLibrarySelect } from '../client/IconLibrarySelect'\nimport { getIconLibraryOptions } from '../server/libraryOptions'\nimport { resolveStaticLabel } from '../shared/resolveStaticLabel'\n\ntype ServerProps = { adapters?: IconAdapter[] } & TextFieldServerProps\n\n/** Resolves selectable library options (inline beats registry) and renders the client select. */\nexport const IconLibrarySelectServer = (props: ServerProps): ReactNode => {\n\tconst { clientField, i18n, path, payload, permissions, readOnly, schemaPath } = props\n\tconst options = getIconLibraryOptions(payload.config, props.adapters).map((option) => ({\n\t\tlabel: resolveStaticLabel(option.label, i18n.language) ?? option.value,\n\t\tvalue: option.value,\n\t}))\n\treturn (\n\t\t<IconLibrarySelect\n\t\t\tfield={clientField}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;AAUA,MAAa,2BAA2B,UAAkC;CACzE,MAAM,EAAE,aAAa,MAAM,MAAM,SAAS,aAAa,UAAU,eAAe;CAKhF,OACC,oBAAC,mBAAD;EACC,OAAO;EACP,SAPc,sBAAsB,QAAQ,QAAQ,MAAM,QAAQ,EAAE,KAAK,YAAY;GACtF,OAAO,mBAAmB,OAAO,OAAO,KAAK,QAAQ,KAAK,OAAO;GACjE,OAAO,OAAO;EACf,EAIiB;EACT;EACO;EACH;EACE;CACZ,CAAA;AAEH"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PayloadRequest } from "payload";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/icon/server/endpoint.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Namespaced so it cannot collide with a consumer's own routes. The slug is a path
|
|
6
|
+
* parameter rather than a query so an unknown library is a 404 rather than a 200 holding
|
|
7
|
+
* nothing.
|
|
8
|
+
*/
|
|
9
|
+
declare const ICON_MANIFEST_PATH = "/10x-fields/icon-manifest/:slug";
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ICON_MANIFEST_PATH };
|
|
12
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { loadLayeredManifest } from "../layers/resolve.js";
|
|
2
|
+
import { unionAlwaysAvailable } from "./availability.js";
|
|
3
|
+
//#region src/fields/icon/server/endpoint.ts
|
|
4
|
+
/**
|
|
5
|
+
* Namespaced so it cannot collide with a consumer's own routes. The slug is a path
|
|
6
|
+
* parameter rather than a query so an unknown library is a 404 rather than a 200 holding
|
|
7
|
+
* nothing.
|
|
8
|
+
*/
|
|
9
|
+
const ICON_MANIFEST_PATH = "/10x-fields/icon-manifest/:slug";
|
|
10
|
+
const json = (body, status) => new Response(JSON.stringify(body), {
|
|
11
|
+
headers: {
|
|
12
|
+
"Cache-Control": "private, no-store",
|
|
13
|
+
"Content-Type": "application/json"
|
|
14
|
+
},
|
|
15
|
+
status
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Serves a library's merged manifest to the admin drawer.
|
|
19
|
+
*
|
|
20
|
+
* This exists so a layer whose data lives on the server is written once, server-side, with
|
|
21
|
+
* `req` in hand. Without it every consumer with a database-backed library would hand-roll
|
|
22
|
+
* an endpoint and invent their own auth and caching story.
|
|
23
|
+
*/
|
|
24
|
+
const createIconManifestHandler = (args) => async (req) => {
|
|
25
|
+
if (!req.user) return json({ message: "Forbidden" }, 403);
|
|
26
|
+
const slug = String(req.routeParams?.slug ?? "");
|
|
27
|
+
const adapter = args.adapters.find((candidate) => candidate.slug === slug);
|
|
28
|
+
if (!adapter) return json({ message: `Unknown icon library: ${slug}` }, 404);
|
|
29
|
+
const always = unionAlwaysAvailable(args.alwaysAvailable, void 0);
|
|
30
|
+
const resolved = args.resolveAvailable ? await args.resolveAvailable({
|
|
31
|
+
req,
|
|
32
|
+
data: void 0,
|
|
33
|
+
siblingData: void 0
|
|
34
|
+
}) : args.adapters.map((candidate) => candidate.slug);
|
|
35
|
+
if (!new Set([...resolved, ...always]).has(slug)) return json({ message: "Forbidden" }, 403);
|
|
36
|
+
try {
|
|
37
|
+
return json(await loadLayeredManifest(adapter, {
|
|
38
|
+
payload: req.payload,
|
|
39
|
+
req
|
|
40
|
+
}), 200);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
req.payload?.logger?.error?.({
|
|
43
|
+
err: error,
|
|
44
|
+
msg: `[fields] icon manifest failed for library "${slug}"`
|
|
45
|
+
});
|
|
46
|
+
return json({ message: "Failed to load icon manifest" }, 500);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ICON_MANIFEST_PATH, createIconManifestHandler };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.js","names":[],"sources":["../../../../src/fields/icon/server/endpoint.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { loadLayeredManifest } from '../layers/resolve'\nimport { unionAlwaysAvailable } from './availability'\n\n/**\n * Namespaced so it cannot collide with a consumer's own routes. The slug is a path\n * parameter rather than a query so an unknown library is a 404 rather than a 200 holding\n * nothing.\n */\nexport const ICON_MANIFEST_PATH = '/10x-fields/icon-manifest/:slug'\n\nconst json = (body: unknown, status: number): Response =>\n\tnew Response(JSON.stringify(body), {\n\t\theaders: {\n\t\t\t// A runtime-backed library changes between requests, so a browser must never\n\t\t\t// reuse a listing. The server-side per-layer cache is what makes that affordable.\n\t\t\t'Cache-Control': 'private, no-store',\n\t\t\t'Content-Type': 'application/json',\n\t\t},\n\t\tstatus,\n\t})\n\nexport type IconManifestHandlerArgs = {\n\tadapters: IconAdapter[]\n\talwaysAvailable?: string[]\n\tresolveAvailable?: IconAvailabilityResolver\n}\n\n/**\n * Serves a library's merged manifest to the admin drawer.\n *\n * This exists so a layer whose data lives on the server is written once, server-side, with\n * `req` in hand. Without it every consumer with a database-backed library would hand-roll\n * an endpoint and invent their own auth and caching story.\n */\nexport const createIconManifestHandler =\n\t(args: IconManifestHandlerArgs) =>\n\tasync (req: PayloadRequest): Promise<Response> => {\n\t\tif (!req.user) return json({ message: 'Forbidden' }, 403)\n\t\tconst slug = String((req.routeParams as { slug?: unknown } | undefined)?.slug ?? '')\n\t\tconst adapter = args.adapters.find((candidate) => candidate.slug === slug)\n\t\tif (!adapter) return json({ message: `Unknown icon library: ${slug}` }, 404)\n\n\t\t// Availability gates every other surface, so the endpoint honours the same rule,\n\t\t// including the alwaysAvailable union. Skipping that union would leave a globally\n\t\t// offered library pickable in the field and unreachable here.\n\t\tconst always = unionAlwaysAvailable(args.alwaysAvailable, undefined)\n\t\tconst resolved = args.resolveAvailable\n\t\t\t? await args.resolveAvailable({ req, data: undefined, siblingData: undefined })\n\t\t\t: args.adapters.map((candidate) => candidate.slug)\n\t\tconst available = new Set([...resolved, ...always])\n\t\tif (!available.has(slug)) return json({ message: 'Forbidden' }, 403)\n\n\t\ttry {\n\t\t\tconst manifest = await loadLayeredManifest(adapter, { payload: req.payload, req })\n\t\t\treturn json(manifest, 200)\n\t\t} catch (error) {\n\t\t\treq.payload?.logger?.error?.({\n\t\t\t\terr: error,\n\t\t\t\tmsg: `[fields] icon manifest failed for library \"${slug}\"`,\n\t\t\t})\n\t\t\t// A failed layer must not read as an empty library: the drawer would show \"no\n\t\t\t// icons found\" and an editor would believe the library was empty.\n\t\t\treturn json({ message: 'Failed to load icon manifest' }, 500)\n\t\t}\n\t}\n"],"mappings":";;;;;;;;AAUA,MAAa,qBAAqB;AAElC,MAAM,QAAQ,MAAe,WAC5B,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;CAClC,SAAS;EAGR,iBAAiB;EACjB,gBAAgB;CACjB;CACA;AACD,CAAC;;;;;;;;AAeF,MAAa,6BACX,SACD,OAAO,QAA2C;CACjD,IAAI,CAAC,IAAI,MAAM,OAAO,KAAK,EAAE,SAAS,YAAY,GAAG,GAAG;CACxD,MAAM,OAAO,OAAQ,IAAI,aAAgD,QAAQ,EAAE;CACnF,MAAM,UAAU,KAAK,SAAS,MAAM,cAAc,UAAU,SAAS,IAAI;CACzE,IAAI,CAAC,SAAS,OAAO,KAAK,EAAE,SAAS,yBAAyB,OAAO,GAAG,GAAG;CAK3E,MAAM,SAAS,qBAAqB,KAAK,iBAAiB,KAAA,CAAS;CACnE,MAAM,WAAW,KAAK,mBACnB,MAAM,KAAK,iBAAiB;EAAE;EAAK,MAAM,KAAA;EAAW,aAAa,KAAA;CAAU,CAAC,IAC5E,KAAK,SAAS,KAAK,cAAc,UAAU,IAAI;CAElD,IAAI,CAAC,IADiB,IAAI,CAAC,GAAG,UAAU,GAAG,MAAM,CACpC,EAAE,IAAI,IAAI,GAAG,OAAO,KAAK,EAAE,SAAS,YAAY,GAAG,GAAG;CAEnE,IAAI;EAEH,OAAO,KAAK,MADW,oBAAoB,SAAS;GAAE,SAAS,IAAI;GAAS;EAAI,CAAC,GAC3D,GAAG;CAC1B,SAAS,OAAO;EACf,IAAI,SAAS,QAAQ,QAAQ;GAC5B,KAAK;GACL,KAAK,8CAA8C,KAAK;EACzD,CAAC;EAGD,OAAO,KAAK,EAAE,SAAS,+BAA+B,GAAG,GAAG;CAC7D;AACD"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
//#region src/fields/icon/server/manifestCache.ts
|
|
2
2
|
const cache = /* @__PURE__ */ new Map();
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Manifest entries keyed by name, cached per adapter slug+version for the process
|
|
5
|
+
* lifetime; manifests are static build artifacts. Existence checks read `has` and
|
|
6
|
+
* label lookups read `get`, because "is this name real" and "what is it called" are
|
|
7
|
+
* the same question of the same manifest.
|
|
8
|
+
*/
|
|
9
|
+
const loadManifestIndex = (adapter) => {
|
|
5
10
|
const key = `${adapter.slug}@${adapter.version}`;
|
|
6
11
|
let entry = cache.get(key);
|
|
7
12
|
if (!entry) {
|
|
8
|
-
entry = adapter.loadManifest().then((manifest) => new
|
|
13
|
+
entry = adapter.loadManifest().then((manifest) => new Map(manifest.icons.map((icon) => [icon.name, icon])));
|
|
9
14
|
cache.set(key, entry);
|
|
10
15
|
entry.catch(() => cache.delete(key));
|
|
11
16
|
}
|
|
12
17
|
return entry;
|
|
13
18
|
};
|
|
14
19
|
//#endregion
|
|
15
|
-
export {
|
|
20
|
+
export { loadManifestIndex };
|
|
16
21
|
|
|
17
22
|
//# sourceMappingURL=manifestCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifestCache.js","names":[],"sources":["../../../../src/fields/icon/server/manifestCache.ts"],"sourcesContent":["import type { IconAdapter } from '../../../types'\n\nconst cache = new Map<string, Promise<
|
|
1
|
+
{"version":3,"file":"manifestCache.js","names":[],"sources":["../../../../src/fields/icon/server/manifestCache.ts"],"sourcesContent":["import type { IconAdapter, IconMeta } from '../../../types'\n\nconst cache = new Map<string, Promise<Map<string, IconMeta>>>()\n\n/**\n * Manifest entries keyed by name, cached per adapter slug+version for the process\n * lifetime; manifests are static build artifacts. Existence checks read `has` and\n * label lookups read `get`, because \"is this name real\" and \"what is it called\" are\n * the same question of the same manifest.\n */\nexport const loadManifestIndex = (adapter: IconAdapter): Promise<Map<string, IconMeta>> => {\n\tconst key = `${adapter.slug}@${adapter.version}`\n\tlet entry = cache.get(key)\n\tif (!entry) {\n\t\tentry = adapter\n\t\t\t.loadManifest()\n\t\t\t.then((manifest) => new Map(manifest.icons.map((icon) => [icon.name, icon])))\n\t\tcache.set(key, entry)\n\t\t// A rejected load must not poison the cache for the process lifetime; evict it so\n\t\t// the next call retries (a BYO adapter may load its manifest over a flaky network).\n\t\tvoid entry.catch(() => cache.delete(key))\n\t}\n\treturn entry\n}\n"],"mappings":";AAEA,MAAM,wBAAQ,IAAI,IAA4C;;;;;;;AAQ9D,MAAa,qBAAqB,YAAyD;CAC1F,MAAM,MAAM,GAAG,QAAQ,KAAK,GAAG,QAAQ;CACvC,IAAI,QAAQ,MAAM,IAAI,GAAG;CACzB,IAAI,CAAC,OAAO;EACX,QAAQ,QACN,aAAa,EACb,MAAM,aAAa,IAAI,IAAI,SAAS,MAAM,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC;EAC7E,MAAM,IAAI,KAAK,KAAK;EAGpB,MAAW,YAAY,MAAM,OAAO,GAAG,CAAC;CACzC;CACA,OAAO;AACR"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { coalesceResolveMany } from "../layers/coalesce.js";
|
|
2
|
+
import { resolveLayeredMeta } from "../layers/resolve.js";
|
|
3
|
+
import { loadManifestIndex } from "./manifestCache.js";
|
|
4
|
+
//#region src/fields/icon/server/resolveIconMeta.ts
|
|
5
|
+
/**
|
|
6
|
+
* One icon's manifest entry, or null when the library does not have it.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order, first hit winning: the adapter's layers (newest first), then the
|
|
9
|
+
* adapter's own resolver, then the cached manifest index. A runtime-backed library
|
|
10
|
+
* answers from live data rather than a cached snapshot, which is what keeps validation
|
|
11
|
+
* exact for a library an editor can add to. A static library's answer is a map hit on an
|
|
12
|
+
* already-loaded manifest and costs nothing.
|
|
13
|
+
*/
|
|
14
|
+
const resolveIconMeta = async (adapter, name, ctx) => {
|
|
15
|
+
if (adapter.layers && adapter.layers.length > 0) {
|
|
16
|
+
const fromLayer = await resolveLayeredMeta(adapter, name, ctx);
|
|
17
|
+
if (fromLayer) return fromLayer;
|
|
18
|
+
}
|
|
19
|
+
if (adapter.resolveMetaMany) return (await coalesceResolveMany({
|
|
20
|
+
ctx,
|
|
21
|
+
key: `adapter::${adapter.slug}`,
|
|
22
|
+
name,
|
|
23
|
+
resolveMetaMany: adapter.resolveMetaMany
|
|
24
|
+
})).get(name) ?? null;
|
|
25
|
+
if (adapter.resolveMeta) return adapter.resolveMeta(name, ctx);
|
|
26
|
+
return (await loadManifestIndex(adapter)).get(name) ?? null;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { resolveIconMeta };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=resolveIconMeta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveIconMeta.js","names":[],"sources":["../../../../src/fields/icon/server/resolveIconMeta.ts"],"sourcesContent":["import type { IconAdapter, IconLayerContext, IconMeta } from '../../../types'\nimport { coalesceResolveMany } from '../layers/coalesce'\nimport { resolveLayeredMeta } from '../layers/resolve'\nimport { loadManifestIndex } from './manifestCache'\n\n/**\n * One icon's manifest entry, or null when the library does not have it.\n *\n * Resolution order, first hit winning: the adapter's layers (newest first), then the\n * adapter's own resolver, then the cached manifest index. A runtime-backed library\n * answers from live data rather than a cached snapshot, which is what keeps validation\n * exact for a library an editor can add to. A static library's answer is a map hit on an\n * already-loaded manifest and costs nothing.\n */\nexport const resolveIconMeta = async (\n\tadapter: IconAdapter,\n\tname: string,\n\tctx: IconLayerContext\n): Promise<IconMeta | null> => {\n\tif (adapter.layers && adapter.layers.length > 0) {\n\t\tconst fromLayer = await resolveLayeredMeta(adapter, name, ctx)\n\t\tif (fromLayer) return fromLayer\n\t}\n\tif (adapter.resolveMetaMany) {\n\t\tconst batch = await coalesceResolveMany({\n\t\t\tctx,\n\t\t\tkey: `adapter::${adapter.slug}`,\n\t\t\tname,\n\t\t\tresolveMetaMany: adapter.resolveMetaMany,\n\t\t})\n\t\treturn batch.get(name) ?? null\n\t}\n\tif (adapter.resolveMeta) return adapter.resolveMeta(name, ctx)\n\treturn (await loadManifestIndex(adapter)).get(name) ?? null\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,kBAAkB,OAC9B,SACA,MACA,QAC8B;CAC9B,IAAI,QAAQ,UAAU,QAAQ,OAAO,SAAS,GAAG;EAChD,MAAM,YAAY,MAAM,mBAAmB,SAAS,MAAM,GAAG;EAC7D,IAAI,WAAW,OAAO;CACvB;CACA,IAAI,QAAQ,iBAOX,QAAO,MANa,oBAAoB;EACvC;EACA,KAAK,YAAY,QAAQ;EACzB;EACA,iBAAiB,QAAQ;CAC1B,CAAC,GACY,IAAI,IAAI,KAAK;CAE3B,IAAI,QAAQ,aAAa,OAAO,QAAQ,YAAY,MAAM,GAAG;CAC7D,QAAQ,MAAM,kBAAkB,OAAO,GAAG,IAAI,IAAI,KAAK;AACxD"}
|
|
@@ -2,7 +2,7 @@ import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
|
2
2
|
import { keys } from "../../../translations/keys.js";
|
|
3
3
|
import { resolveIconValue } from "../shared/value.js";
|
|
4
4
|
import { asTranslate } from "../../../translations/server.js";
|
|
5
|
-
import {
|
|
5
|
+
import { resolveIconMeta } from "./resolveIconMeta.js";
|
|
6
6
|
import { text } from "payload/shared";
|
|
7
7
|
//#region src/fields/icon/server/validate.ts
|
|
8
8
|
/**
|
|
@@ -20,7 +20,10 @@ const createIconValidate = (args) => async (value, options) => {
|
|
|
20
20
|
const t = asTranslate(options.req.t);
|
|
21
21
|
if (value !== options.previousValue) {
|
|
22
22
|
if (!adapter) return t(keys.invalidIconLibrary, { library });
|
|
23
|
-
if (!
|
|
23
|
+
if (!await resolveIconMeta(adapter, name, {
|
|
24
|
+
payload: options.req.payload,
|
|
25
|
+
req: options.req
|
|
26
|
+
})) return t(keys.invalidIconName, {
|
|
24
27
|
library,
|
|
25
28
|
name
|
|
26
29
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":[],"sources":["../../../../src/fields/icon/server/validate.ts"],"sourcesContent":["import type { TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport type { IconAdapter } from '../../../types'\nimport { resolveIconValue } from '../shared/value'\nimport {
|
|
1
|
+
{"version":3,"file":"validate.js","names":[],"sources":["../../../../src/fields/icon/server/validate.ts"],"sourcesContent":["import type { TextFieldValidation } from 'payload'\nimport { text } from 'payload/shared'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate } from '../../../translations/server'\nimport type { IconAdapter } from '../../../types'\nimport { resolveIconValue } from '../shared/value'\nimport { resolveIconMeta } from './resolveIconMeta'\n\nexport type CreateIconValidateArgs = {\n\tadapters?: IconAdapter[]\n\tdefaultLibrary?: string\n\trequired: boolean\n}\n\n/**\n * Unregistered library or unknown name in a known library: error only for\n * changed values, so a stored doc stays saveable after its library is dropped\n * or an icon-set upgrade removes a glyph. Changing TO an unknown value errors.\n */\nexport const createIconValidate =\n\t(args: CreateIconValidateArgs): TextFieldValidation =>\n\tasync (value, options) => {\n\t\t// The sanitized field is spread into the options, so a `required` added\n\t\t// through `overrides` wins over the flag captured when the factory ran.\n\t\tconst required = options.required ?? args.required\n\t\tif (value != null && value !== '') {\n\t\t\tconst registry = getFieldsRegistry(options.req.payload.config)\n\t\t\tconst registered = args.adapters ?? registry?.icon?.adapters ?? []\n\t\t\tconst defaultLibrary =\n\t\t\t\targs.defaultLibrary ?? registry?.icon?.defaultLibrary ?? registered[0]?.slug ?? ''\n\t\t\tconst { library, name } = resolveIconValue(value, defaultLibrary)\n\t\t\tconst adapter = registered.find((candidate) => candidate.slug === library)\n\t\t\tconst t = asTranslate(options.req.t)\n\t\t\tif (value !== options.previousValue) {\n\t\t\t\tif (!adapter) {\n\t\t\t\t\treturn t(keys.invalidIconLibrary, { library })\n\t\t\t\t}\n\t\t\t\tconst meta = await resolveIconMeta(adapter, name, {\n\t\t\t\t\tpayload: options.req.payload,\n\t\t\t\t\treq: options.req,\n\t\t\t\t})\n\t\t\t\tif (!meta) {\n\t\t\t\t\treturn t(keys.invalidIconName, { library, name })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn text(value, { ...options, required })\n\t}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,sBACX,SACD,OAAO,OAAO,YAAY;CAGzB,MAAM,WAAW,QAAQ,YAAY,KAAK;CAC1C,IAAI,SAAS,QAAQ,UAAU,IAAI;EAClC,MAAM,WAAW,kBAAkB,QAAQ,IAAI,QAAQ,MAAM;EAC7D,MAAM,aAAa,KAAK,YAAY,UAAU,MAAM,YAAY,CAAC;EAGjE,MAAM,EAAE,SAAS,SAAS,iBAAiB,OAD1C,KAAK,kBAAkB,UAAU,MAAM,kBAAkB,WAAW,IAAI,QAAQ,EACjB;EAChE,MAAM,UAAU,WAAW,MAAM,cAAc,UAAU,SAAS,OAAO;EACzE,MAAM,IAAI,YAAY,QAAQ,IAAI,CAAC;EACnC,IAAI,UAAU,QAAQ,eAAe;GACpC,IAAI,CAAC,SACJ,OAAO,EAAE,KAAK,oBAAoB,EAAE,QAAQ,CAAC;GAM9C,IAAI,CAAC,MAJc,gBAAgB,SAAS,MAAM;IACjD,SAAS,QAAQ,IAAI;IACrB,KAAK,QAAQ;GACd,CAAC,GAEA,OAAO,EAAE,KAAK,iBAAiB;IAAE;IAAS;GAAK,CAAC;EAElD;CACD;CACA,OAAO,KAAK,OAAO;EAAE,GAAG;EAAS;CAAS,CAAC;AAC5C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IconManifest, IconNodeMap } from "../../../types.js";
|
|
1
|
+
import { IconCanvas, IconManifest, IconNodeMap } from "../../../types.js";
|
|
2
2
|
import { ComponentType } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/fields/icon/shared/adapterComponents.d.ts
|
|
@@ -14,7 +14,8 @@ type AdapterNodesProps = {
|
|
|
14
14
|
onReady: (nodes: IconNodeMap) => void;
|
|
15
15
|
};
|
|
16
16
|
type AdapterComponentsEntry = {
|
|
17
|
-
Assets: ComponentType<AdapterAssetsProps>;
|
|
17
|
+
Assets: ComponentType<AdapterAssetsProps>; /** Canvas this library's bulk glyphs draw on; absent means the outline default. */
|
|
18
|
+
canvas?: IconCanvas;
|
|
18
19
|
Icon: ComponentType<AdapterIconProps>; /** Loads bulk glyph node-data for fast drawer rendering; absent for per-icon libraries (radix). */
|
|
19
20
|
Nodes?: ComponentType<AdapterNodesProps>;
|
|
20
21
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { formatIconLabel } from "./formatIconLabel.js";
|
|
2
|
+
import { resolveStaticLabel } from "./resolveStaticLabel.js";
|
|
3
|
+
//#region src/fields/icon/shared/iconLabel.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the display text for one icon. A library-supplied `label` wins; otherwise
|
|
6
|
+
* the name is sentence-cased as before, so every existing manifest is unaffected.
|
|
7
|
+
*
|
|
8
|
+
* `code` carries the raw name for surfaces that can show it alongside the label. It is
|
|
9
|
+
* the only place an editor can learn that "Hungary" stores as `HUN`, which they need to
|
|
10
|
+
* write frontend code, and it is deliberately kept out of the accessible name: a screen
|
|
11
|
+
* reader announcing "Hungary HUN" across 215 cells is the defect this fixes.
|
|
12
|
+
*/
|
|
13
|
+
const resolveIconDisplay = (args) => {
|
|
14
|
+
const derived = formatIconLabel(args.name);
|
|
15
|
+
const supplied = resolveStaticLabel(args.meta?.label, args.language);
|
|
16
|
+
if (!supplied) return { label: derived };
|
|
17
|
+
if (supplied === args.name || supplied === derived) return { label: supplied };
|
|
18
|
+
return {
|
|
19
|
+
code: args.name,
|
|
20
|
+
label: supplied
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { resolveIconDisplay };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=iconLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport { formatIconLabel } from './formatIconLabel'\nimport { resolveStaticLabel } from './resolveStaticLabel'\n\n/** What an editor sees for one icon: its accessible name, plus the raw name where that adds information. */\nexport type IconDisplayLabel = { code?: string; label: string }\n\n/**\n * Resolves the display text for one icon. A library-supplied `label` wins; otherwise\n * the name is sentence-cased as before, so every existing manifest is unaffected.\n *\n * `code` carries the raw name for surfaces that can show it alongside the label. It is\n * the only place an editor can learn that \"Hungary\" stores as `HUN`, which they need to\n * write frontend code, and it is deliberately kept out of the accessible name: a screen\n * reader announcing \"Hungary HUN\" across 215 cells is the defect this fixes.\n */\nexport const resolveIconDisplay = (args: {\n\tlanguage: string\n\tmeta?: IconMeta | null\n\tname: string\n}): IconDisplayLabel => {\n\tconst derived = formatIconLabel(args.name)\n\tconst supplied = resolveStaticLabel(args.meta?.label, args.language)\n\tif (!supplied) return { label: derived }\n\t// A code only earns its place when the label hides it. A label matching the name, or\n\t// matching what the name would have derived anyway, tells the editor nothing new.\n\tif (supplied === args.name || supplied === derived) return { label: supplied }\n\treturn { code: args.name, label: supplied }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAIX;CACvB,MAAM,UAAU,gBAAgB,KAAK,IAAI;CACzC,MAAM,WAAW,mBAAmB,KAAK,MAAM,OAAO,KAAK,QAAQ;CACnE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,QAAQ;CAGvC,IAAI,aAAa,KAAK,QAAQ,aAAa,SAAS,OAAO,EAAE,OAAO,SAAS;CAC7E,OAAO;EAAE,MAAM,KAAK;EAAM,OAAO;CAAS;AAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStaticLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/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"}
|