@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.
- package/CHANGELOG.md +53 -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/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/nodes.js +3625 -0
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
- 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 +3 -2
- 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
|
@@ -2,29 +2,46 @@
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/fields/icon/client/DrawerGlyph.tsx
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const DEFAULT_CANVAS = {
|
|
6
|
+
fill: "none",
|
|
7
|
+
stroke: "currentColor",
|
|
8
|
+
strokeLinecap: "round",
|
|
9
|
+
strokeLinejoin: "round",
|
|
10
|
+
strokeWidth: 2,
|
|
11
|
+
viewBox: "0 0 24 24"
|
|
12
|
+
};
|
|
13
|
+
const renderNodes = (nodes) => nodes.map(([tag, attrs, children], index) => React.createElement(tag, {
|
|
14
|
+
key: index,
|
|
15
|
+
...attrs
|
|
16
|
+
}, children ? renderNodes(children) : void 0));
|
|
7
17
|
/**
|
|
8
18
|
* Renders one glyph as inline SVG from bulk node-data, matching lucide-react's
|
|
9
19
|
* `iconNode.map(([tag, attrs]) => createElement(tag, attrs))`. The drawer loads a
|
|
10
20
|
* library's node-data once, so a grid cell costs a cheap element tree instead of
|
|
11
21
|
* the per-icon dynamic import that made large libraries scroll poorly.
|
|
22
|
+
*
|
|
23
|
+
* The canvas is declared per layer rather than hardcoded, so a filled 15x15 set is as
|
|
24
|
+
* renderable here as a 24x24 stroked one. Nodes may nest, which a flat list cannot
|
|
25
|
+
* express and which arbitrary SVG needs.
|
|
12
26
|
*/
|
|
13
|
-
const DrawerGlyph = React.memo(({ nodes, size }) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const DrawerGlyph = React.memo(({ canvas, nodes, size }) => {
|
|
28
|
+
const resolved = canvas ? {
|
|
29
|
+
...DEFAULT_CANVAS,
|
|
30
|
+
...canvas
|
|
31
|
+
} : DEFAULT_CANVAS;
|
|
32
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
fill: resolved.fill,
|
|
35
|
+
height: size,
|
|
36
|
+
stroke: resolved.stroke,
|
|
37
|
+
strokeLinecap: resolved.strokeLinecap,
|
|
38
|
+
strokeLinejoin: resolved.strokeLinejoin,
|
|
39
|
+
strokeWidth: resolved.strokeWidth,
|
|
40
|
+
viewBox: resolved.viewBox,
|
|
41
|
+
width: size,
|
|
42
|
+
children: renderNodes(nodes)
|
|
43
|
+
});
|
|
44
|
+
});
|
|
28
45
|
DrawerGlyph.displayName = "DrawerGlyph";
|
|
29
46
|
//#endregion
|
|
30
47
|
export { DrawerGlyph };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawerGlyph.js","names":[],"sources":["../../../../src/fields/icon/client/DrawerGlyph.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport type { IconNode } from '../../../types'\n\n// lucide and tabler share a 24x24 outline canvas; these are lucide-react's own\n// defaultAttributes, so a glyph rendered here is pixel-identical to the per-icon\n// component.
|
|
1
|
+
{"version":3,"file":"DrawerGlyph.js","names":[],"sources":["../../../../src/fields/icon/client/DrawerGlyph.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport type { IconCanvas, IconNode } from '../../../types'\n\n// lucide and tabler share a 24x24 outline canvas; these are lucide-react's own\n// defaultAttributes, so a glyph rendered here is pixel-identical to the per-icon\n// component. They stay the defaults, which is what keeps every library declaring no\n// canvas rendering exactly as it always has.\nconst DEFAULT_CANVAS: Required<IconCanvas> = {\n\tfill: 'none',\n\tstroke: 'currentColor',\n\tstrokeLinecap: 'round',\n\tstrokeLinejoin: 'round',\n\tstrokeWidth: 2,\n\tviewBox: '0 0 24 24',\n}\n\nexport type DrawerGlyphProps = {\n\t/** Layer-declared canvas; omitted fields fall back to the lucide outline convention. */\n\tcanvas?: IconCanvas\n\tnodes: IconNode[]\n\tsize: number\n}\n\nconst renderNodes = (nodes: IconNode[]): React.ReactNode[] =>\n\tnodes.map(([tag, attrs, children], index) =>\n\t\tReact.createElement(tag, { key: index, ...attrs }, children ? renderNodes(children) : undefined)\n\t)\n\n/**\n * Renders one glyph as inline SVG from bulk node-data, matching lucide-react's\n * `iconNode.map(([tag, attrs]) => createElement(tag, attrs))`. The drawer loads a\n * library's node-data once, so a grid cell costs a cheap element tree instead of\n * the per-icon dynamic import that made large libraries scroll poorly.\n *\n * The canvas is declared per layer rather than hardcoded, so a filled 15x15 set is as\n * renderable here as a 24x24 stroked one. Nodes may nest, which a flat list cannot\n * express and which arbitrary SVG needs.\n */\nexport const DrawerGlyph: React.FC<DrawerGlyphProps> = React.memo(({ canvas, nodes, size }) => {\n\tconst resolved = canvas ? { ...DEFAULT_CANVAS, ...canvas } : DEFAULT_CANVAS\n\treturn (\n\t\t<svg\n\t\t\taria-hidden=\"true\"\n\t\t\tfill={resolved.fill}\n\t\t\theight={size}\n\t\t\tstroke={resolved.stroke}\n\t\t\tstrokeLinecap={resolved.strokeLinecap}\n\t\t\tstrokeLinejoin={resolved.strokeLinejoin}\n\t\t\tstrokeWidth={resolved.strokeWidth}\n\t\t\tviewBox={resolved.viewBox}\n\t\t\twidth={size}\n\t\t>\n\t\t\t{renderNodes(nodes)}\n\t\t</svg>\n\t)\n})\nDrawerGlyph.displayName = 'DrawerGlyph'\n"],"mappings":";;;;AASA,MAAM,iBAAuC;CAC5C,MAAM;CACN,QAAQ;CACR,eAAe;CACf,gBAAgB;CAChB,aAAa;CACb,SAAS;AACV;AASA,MAAM,eAAe,UACpB,MAAM,KAAK,CAAC,KAAK,OAAO,WAAW,UAClC,MAAM,cAAc,KAAK;CAAE,KAAK;CAAO,GAAG;AAAM,GAAG,WAAW,YAAY,QAAQ,IAAI,KAAA,CAAS,CAChG;;;;;;;;;;;AAYD,MAAa,cAA0C,MAAM,MAAM,EAAE,QAAQ,OAAO,WAAW;CAC9F,MAAM,WAAW,SAAS;EAAE,GAAG;EAAgB,GAAG;CAAO,IAAI;CAC7D,OACC,oBAAC,OAAD;EACC,eAAY;EACZ,MAAM,SAAS;EACf,QAAQ;EACR,QAAQ,SAAS;EACjB,eAAe,SAAS;EACxB,gBAAgB,SAAS;EACzB,aAAa,SAAS;EACtB,SAAS,SAAS;EAClB,OAAO;YAEN,YAAY,KAAK;CACd,CAAA;AAEP,CAAC;AACD,YAAY,cAAc"}
|
|
@@ -1,57 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { keys } from "../../../translations/keys.js";
|
|
3
3
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
-
import { formatIconLabel } from "../shared/formatIconLabel.js";
|
|
5
4
|
import { buildIconSearchIndex, searchIcons } from "../shared/search.js";
|
|
6
|
-
import {
|
|
5
|
+
import { IconGridCell } from "./IconGridCell.js";
|
|
7
6
|
import { useRecentIcons } from "./useRecentIcons.js";
|
|
8
|
-
import { ReactSelect, SearchIcon
|
|
9
|
-
import
|
|
7
|
+
import { ReactSelect, SearchIcon } from "@payloadcms/ui";
|
|
8
|
+
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from "react";
|
|
10
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
10
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
12
11
|
//#region src/fields/icon/client/IconDrawerContent.tsx
|
|
13
12
|
const CELL_SIZE = 64;
|
|
14
13
|
const RECENT = "__recent__";
|
|
15
14
|
const ALL = "__all__";
|
|
16
|
-
const IconGridCell = React.memo(({ entry, focused, icon, index, isSelected, nodes, onSelect, registerRef }) => {
|
|
17
|
-
const [showTooltip, setShowTooltip] = useState(false);
|
|
18
|
-
const label = formatIconLabel(icon.name);
|
|
19
|
-
return /* @__PURE__ */ jsx("div", {
|
|
20
|
-
className: "tenx-icon-drawer__cell",
|
|
21
|
-
role: "presentation",
|
|
22
|
-
children: /* @__PURE__ */ jsxs("button", {
|
|
23
|
-
"aria-label": label,
|
|
24
|
-
"aria-selected": isSelected,
|
|
25
|
-
className: isSelected ? "tenx-icon-drawer__cell-button tenx-icon-drawer__cell-button--selected" : "tenx-icon-drawer__cell-button",
|
|
26
|
-
onBlur: () => setShowTooltip(false),
|
|
27
|
-
onClick: () => onSelect(icon.name),
|
|
28
|
-
onFocus: () => setShowTooltip(true),
|
|
29
|
-
onMouseEnter: () => setShowTooltip(true),
|
|
30
|
-
onMouseLeave: () => setShowTooltip(false),
|
|
31
|
-
ref: (element) => registerRef(index, element),
|
|
32
|
-
role: "option",
|
|
33
|
-
tabIndex: focused ? 0 : -1,
|
|
34
|
-
type: "button",
|
|
35
|
-
children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
36
|
-
show: showTooltip,
|
|
37
|
-
staticPositioning: true,
|
|
38
|
-
children: label
|
|
39
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
40
|
-
className: "tenx-icon-drawer__glyph",
|
|
41
|
-
children: nodes ? /* @__PURE__ */ jsx(DrawerGlyph, {
|
|
42
|
-
nodes,
|
|
43
|
-
size: 24
|
|
44
|
-
}) : entry ? /* @__PURE__ */ jsx(entry.Icon, {
|
|
45
|
-
name: icon.name,
|
|
46
|
-
size: 24
|
|
47
|
-
}) : null
|
|
48
|
-
})]
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
IconGridCell.displayName = "IconGridCell";
|
|
53
15
|
const IconDrawerContent = ({ activeLibrary, adapterComponents, adapters, onLibraryChange, onSelect, selected, slugPrefix }) => {
|
|
54
|
-
const { t } = useTranslation$1();
|
|
16
|
+
const { i18n, t } = useTranslation$1();
|
|
55
17
|
const [manifests, setManifests] = useState(() => /* @__PURE__ */ new Map());
|
|
56
18
|
const [nodeMaps, setNodeMaps] = useState(() => /* @__PURE__ */ new Map());
|
|
57
19
|
const [query, setQuery] = useState("");
|
|
@@ -142,9 +104,9 @@ const IconDrawerContent = ({ activeLibrary, adapterComponents, adapters, onLibra
|
|
|
142
104
|
focusIndex,
|
|
143
105
|
visible.length
|
|
144
106
|
]);
|
|
145
|
-
const handleSelect = useCallback((
|
|
146
|
-
addRecent(name);
|
|
147
|
-
onSelect(activeLibrary,
|
|
107
|
+
const handleSelect = useCallback((icon) => {
|
|
108
|
+
addRecent(icon.name);
|
|
109
|
+
onSelect(activeLibrary, icon);
|
|
148
110
|
}, [
|
|
149
111
|
activeLibrary,
|
|
150
112
|
addRecent,
|
|
@@ -265,11 +227,13 @@ const IconDrawerContent = ({ activeLibrary, adapterComponents, adapters, onLibra
|
|
|
265
227
|
children: visible.slice(row.index * columns, row.index * columns + columns).map((icon, columnIndex) => {
|
|
266
228
|
const cellIndex = row.index * columns + columnIndex;
|
|
267
229
|
return /* @__PURE__ */ jsx(IconGridCell, {
|
|
230
|
+
canvas: entry?.canvas,
|
|
268
231
|
entry,
|
|
269
232
|
focused: cellIndex === focusIndex,
|
|
270
233
|
icon,
|
|
271
234
|
index: cellIndex,
|
|
272
235
|
isSelected: selected?.library === activeLibrary && selected.name === icon.name,
|
|
236
|
+
language: i18n.language,
|
|
273
237
|
nodes: NodesLoader ? nodeMap?.[icon.name] : void 0,
|
|
274
238
|
onSelect: handleSelect,
|
|
275
239
|
registerRef
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconDrawerContent.js","names":["useTranslation"],"sources":["../../../../src/fields/icon/client/IconDrawerContent.tsx"],"sourcesContent":["'use client'\n\nimport { ReactSelect, SearchIcon, Tooltip } from '@payloadcms/ui'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport React, { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { IconManifest, IconMeta, IconNode, IconNodeMap } from '../../../types'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { formatIconLabel } from '../shared/formatIconLabel'\nimport { buildIconSearchIndex, searchIcons } from '../shared/search'\nimport { DrawerGlyph } from './DrawerGlyph'\nimport { useRecentIcons } from './useRecentIcons'\n\n// One fixed size drives both the column count and the virtualizer row height. With no\n// in-flow label to vary a cell's height, every cell is an identical square and the grid\n// stays aligned regardless of icon name length.\nconst CELL_SIZE = 64\nconst RECENT = '__recent__'\nconst ALL = '__all__'\n\nexport type IconDrawerContentProps = {\n\tactiveLibrary: string\n\tadapterComponents: Record<string, AdapterComponentsEntry>\n\t/** Libraries available for selection: registered adapters already intersected with `available`. */\n\tadapters: { label: string; slug: string }[]\n\tonLibraryChange: (slug: string) => void\n\tonSelect: (library: string, name: string) => void\n\tselected: { library: string; name: string } | null\n\tslugPrefix: string\n}\n\ntype CellProps = {\n\tentry: AdapterComponentsEntry | undefined\n\tfocused: boolean\n\ticon: IconMeta\n\tindex: number\n\tisSelected: boolean\n\t/** Bulk glyph data for inline rendering; when absent the cell falls back to the per-icon Icon. */\n\tnodes: IconNode[] | undefined\n\tonSelect: (name: string) => void\n\tregisterRef: (index: number, element: HTMLButtonElement | null) => void\n}\n\nconst IconGridCell: React.FC<CellProps> = React.memo(\n\t({ entry, focused, icon, index, isSelected, nodes, onSelect, registerRef }) => {\n\t\tconst [showTooltip, setShowTooltip] = useState(false)\n\t\t// The name is not rendered in-flow (that variance broke grid alignment); it lives on\n\t\t// the accessible name and a hover/focus tooltip, sentence-cased for readability.\n\t\tconst label = formatIconLabel(icon.name)\n\t\treturn (\n\t\t\t<div className=\"tenx-icon-drawer__cell\" role=\"presentation\">\n\t\t\t\t<button\n\t\t\t\t\taria-label={label}\n\t\t\t\t\taria-selected={isSelected}\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t? 'tenx-icon-drawer__cell-button tenx-icon-drawer__cell-button--selected'\n\t\t\t\t\t\t\t: 'tenx-icon-drawer__cell-button'\n\t\t\t\t\t}\n\t\t\t\t\tonBlur={() => setShowTooltip(false)}\n\t\t\t\t\tonClick={() => onSelect(icon.name)}\n\t\t\t\t\tonFocus={() => setShowTooltip(true)}\n\t\t\t\t\tonMouseEnter={() => setShowTooltip(true)}\n\t\t\t\t\tonMouseLeave={() => setShowTooltip(false)}\n\t\t\t\t\tref={(element) => registerRef(index, element)}\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\ttabIndex={focused ? 0 : -1}\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t>\n\t\t\t\t\t<Tooltip show={showTooltip} staticPositioning>\n\t\t\t\t\t\t{label}\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t<span className=\"tenx-icon-drawer__glyph\">\n\t\t\t\t\t\t{nodes ? (\n\t\t\t\t\t\t\t<DrawerGlyph nodes={nodes} size={24} />\n\t\t\t\t\t\t) : entry ? (\n\t\t\t\t\t\t\t<entry.Icon name={icon.name} size={24} />\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t)\n\t}\n)\nIconGridCell.displayName = 'IconGridCell'\n\nconst IconDrawerContent: React.FC<IconDrawerContentProps> = ({\n\tactiveLibrary,\n\tadapterComponents,\n\tadapters,\n\tonLibraryChange,\n\tonSelect,\n\tselected,\n\tslugPrefix,\n}) => {\n\tconst { t } = useTranslation()\n\tconst [manifests, setManifests] = useState<Map<string, IconManifest>>(() => new Map())\n\tconst [nodeMaps, setNodeMaps] = useState<Map<string, IconNodeMap>>(() => new Map())\n\tconst [query, setQuery] = useState('')\n\tconst deferredQuery = useDeferredValue(query)\n\tconst [category, setCategory] = useState<string>(ALL)\n\tconst { addRecent, recent } = useRecentIcons(activeLibrary)\n\n\tconst manifest = manifests.get(activeLibrary)\n\tconst entry = adapterComponents[activeLibrary]\n\tconst Assets = entry?.Assets\n\tconst NodesLoader = entry?.Nodes\n\tconst nodeMap = nodeMaps.get(activeLibrary)\n\t// Libraries with a Nodes loader render the grid from bulk node-data; the grid\n\t// waits for that data before showing cells, others (radix) render immediately.\n\tconst nodesPending = Boolean(NodesLoader) && !nodeMap\n\tconst loading = !manifest || nodesPending\n\n\tconst handleManifest = useCallback(\n\t\t(loaded: IconManifest) => {\n\t\t\tsetManifests((previous) => new Map(previous).set(activeLibrary, loaded))\n\t\t},\n\t\t[activeLibrary]\n\t)\n\n\tconst handleNodes = useCallback(\n\t\t(loaded: IconNodeMap) => {\n\t\t\tsetNodeMaps((previous) => new Map(previous).set(activeLibrary, loaded))\n\t\t},\n\t\t[activeLibrary]\n\t)\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: activeLibrary is the trigger; the effect resets category and search when it changes\n\tuseEffect(() => {\n\t\tsetCategory(ALL)\n\t\tsetQuery('')\n\t}, [activeLibrary])\n\n\tconst byName = useMemo(\n\t\t() => new Map((manifest?.icons ?? []).map((icon) => [icon.name, icon])),\n\t\t[manifest]\n\t)\n\n\tconst categoryIcons = useMemo((): IconMeta[] => {\n\t\tif (!manifest) return []\n\t\tif (category === ALL) return manifest.icons\n\t\tif (category === RECENT) {\n\t\t\treturn recent\n\t\t\t\t.map((name) => byName.get(name))\n\t\t\t\t.filter((icon): icon is IconMeta => Boolean(icon))\n\t\t}\n\t\treturn manifest.icons.filter((icon) => icon.categories.includes(category))\n\t}, [byName, category, manifest, recent])\n\n\tconst index = useMemo(() => buildIconSearchIndex(categoryIcons), [categoryIcons])\n\tconst visible = useMemo(() => searchIcons(index, deferredQuery), [deferredQuery, index])\n\n\tconst gridRef = useRef<HTMLDivElement>(null)\n\tconst [gridWidth, setGridWidth] = useState(0)\n\tuseEffect(() => {\n\t\tconst element = gridRef.current\n\t\tif (!element) return\n\t\tconst observer = new ResizeObserver(() => setGridWidth(element.offsetWidth))\n\t\tobserver.observe(element)\n\t\tsetGridWidth(element.offsetWidth)\n\t\treturn () => observer.disconnect()\n\t}, [])\n\tconst columns = Math.max(3, Math.floor(gridWidth / CELL_SIZE))\n\tconst rowCount = Math.ceil(visible.length / columns)\n\t// Cell-box span of a full row (columns * CELL_SIZE), published to CSS as a custom property.\n\t// The header row and banner derive their width from this (inset to the button outlines in\n\t// icon-field.css) so the search, switcher, banner, and visible grid share one left and one\n\t// right edge. Sized only from CELL_SIZE.\n\tconst mainStyle = {\n\t\t'--tenx-icon-grid-width': `${columns * CELL_SIZE}px`,\n\t} as React.CSSProperties\n\n\tconst virtualizer = useVirtualizer({\n\t\tcount: rowCount,\n\t\testimateSize: () => CELL_SIZE,\n\t\tgetScrollElement: () => gridRef.current,\n\t\t// Cells are cheap inline SVG now, so a deeper overscan buys smoother fast scrolls.\n\t\toverscan: 8,\n\t})\n\n\tconst [focusIndex, setFocusIndex] = useState(0)\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: reset focus whenever the visible set changes\n\tuseEffect(() => setFocusIndex(0), [activeLibrary, category, deferredQuery])\n\tconst cellRefs = useRef(new Map<number, HTMLButtonElement>())\n\tconst registerRef = useCallback((cellIndex: number, element: HTMLButtonElement | null) => {\n\t\tif (element) cellRefs.current.set(cellIndex, element)\n\t\telse cellRefs.current.delete(cellIndex)\n\t}, [])\n\n\tconst focusCell = useCallback(\n\t\t(cellIndex: number) => {\n\t\t\tvirtualizer.scrollToIndex(Math.floor(cellIndex / columns))\n\t\t\trequestAnimationFrame(() => cellRefs.current.get(cellIndex)?.focus())\n\t\t},\n\t\t[columns, virtualizer]\n\t)\n\n\tconst handleGridKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tconst max = visible.length - 1\n\t\t\tif (max < 0) return\n\t\t\tlet next: number | null = null\n\t\t\tif (event.key === 'ArrowRight') next = Math.min(focusIndex + 1, max)\n\t\t\telse if (event.key === 'ArrowLeft') next = Math.max(focusIndex - 1, 0)\n\t\t\telse if (event.key === 'ArrowDown') next = Math.min(focusIndex + columns, max)\n\t\t\telse if (event.key === 'ArrowUp') next = Math.max(focusIndex - columns, 0)\n\t\t\telse if (event.key === 'Home') next = 0\n\t\t\telse if (event.key === 'End') next = max\n\t\t\tif (next === null) return\n\t\t\tevent.preventDefault()\n\t\t\tsetFocusIndex(next)\n\t\t\tfocusCell(next)\n\t\t},\n\t\t[columns, focusCell, focusIndex, visible.length]\n\t)\n\n\tconst handleSelect = useCallback(\n\t\t(name: string) => {\n\t\t\taddRecent(name)\n\t\t\tonSelect(activeLibrary, name)\n\t\t},\n\t\t[activeLibrary, addRecent, onSelect]\n\t)\n\n\tconst railItems = useMemo(\n\t\t(): { key: string; label: string }[] => [\n\t\t\t{ key: ALL, label: t(keys.allIcons) },\n\t\t\t{ key: RECENT, label: t(keys.recent) },\n\t\t\t...(manifest?.categories ?? []).map((name) => ({ key: name, label: name })),\n\t\t],\n\t\t[manifest, t]\n\t)\n\n\tconst libraryOptions = useMemo(\n\t\t() => adapters.map((adapter) => ({ label: adapter.label, value: adapter.slug })),\n\t\t[adapters]\n\t)\n\tconst librarySelectId = `${slugPrefix}-library`\n\n\t// The stored value points at a library that is no longer offered for selection; the\n\t// full explanation lives here, the trigger only carries a compact marker.\n\tconst selectedUnavailable =\n\t\tselected !== null && !adapters.some((adapter) => adapter.slug === selected.library)\n\n\t// A listbox must own option children, so the grid only claims role=\"listbox\" (with\n\t// its keyboard nav and label) once cells exist. While loading it is an aria-busy\n\t// container; when empty it is a plain container holding the \"no icons\" message.\n\tconst gridPopulated = !loading && visible.length > 0\n\tconst gridA11y: React.HTMLAttributes<HTMLDivElement> = gridPopulated\n\t\t? { 'aria-label': t(keys.iconGrid), onKeyDown: handleGridKeyDown, role: 'listbox' }\n\t\t: { 'aria-busy': loading || undefined }\n\n\treturn (\n\t\t<div className=\"tenx-icon-drawer\">\n\t\t\t{/* Sibling loaders keyed distinctly per library: a shared key collides (\"two children\n\t\t\t with the same key\") when both mount on open, while distinct keys keep the per-library remount. */}\n\t\t\t{Assets && !manifest ? (\n\t\t\t\t<Assets key={`assets-${activeLibrary}`} onReady={handleManifest} />\n\t\t\t) : null}\n\t\t\t{NodesLoader && !nodeMap ? (\n\t\t\t\t<NodesLoader key={`nodes-${activeLibrary}`} onReady={handleNodes} />\n\t\t\t) : null}\n\t\t\t<div className=\"tenx-icon-drawer__body\">\n\t\t\t\t<nav aria-label={t(keys.iconCategories)} className=\"tenx-icon-drawer__rail\">\n\t\t\t\t\t{railItems.map((item) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tcategory === item.key\n\t\t\t\t\t\t\t\t\t? 'tenx-icon-drawer__rail-item tenx-icon-drawer__rail-item--active'\n\t\t\t\t\t\t\t\t\t: 'tenx-icon-drawer__rail-item'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tkey={item.key}\n\t\t\t\t\t\t\tonClick={() => setCategory(item.key)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{item.label}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</nav>\n\t\t\t\t<div className=\"tenx-icon-drawer__main\" style={mainStyle}>\n\t\t\t\t\t{selectedUnavailable ? (\n\t\t\t\t\t\t<div className=\"tenx-icon-drawer__banner\" role=\"status\">\n\t\t\t\t\t\t\t{t(keys.libraryUnavailable)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className=\"tenx-icon-drawer__header\">\n\t\t\t\t\t\t{/* Bordered control mirrors Payload's list-view search: SearchIcon inside-left, borderless input. */}\n\t\t\t\t\t\t<div className=\"tenx-icon-drawer__search\">\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" className=\"tenx-icon-drawer__search-icon\">\n\t\t\t\t\t\t\t\t<SearchIcon />\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\taria-label={t(keys.searchIcons)}\n\t\t\t\t\t\t\t\tclassName=\"tenx-icon-drawer__search-input\"\n\t\t\t\t\t\t\t\tonChange={(event: React.ChangeEvent<HTMLInputElement>) =>\n\t\t\t\t\t\t\t\t\tsetQuery(event.target.value)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tplaceholder={t(keys.searchIcons)}\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tvalue={query}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/* adapters is the available-filtered set; the switcher shows only with 2+ libraries, fixed width beside the growing search */}\n\t\t\t\t\t\t{adapters.length > 1 ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__switcher\">\n\t\t\t\t\t\t\t\t<label className=\"tenx-icon-drawer__sr-only\" htmlFor={librarySelectId}>\n\t\t\t\t\t\t\t\t\t{t(keys.fieldIconLibraryLabel)}\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t<ReactSelect\n\t\t\t\t\t\t\t\t\tinputId={librarySelectId}\n\t\t\t\t\t\t\t\t\tisClearable={false}\n\t\t\t\t\t\t\t\t\tonChange={(option) => {\n\t\t\t\t\t\t\t\t\t\tconst single = Array.isArray(option) ? option[0] : option\n\t\t\t\t\t\t\t\t\t\tif (single && typeof single.value === 'string') onLibraryChange(single.value)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\toptions={libraryOptions}\n\t\t\t\t\t\t\t\t\tvalue={libraryOptions.find((option) => option.value === activeLibrary)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className=\"tenx-icon-drawer__grid\" ref={gridRef} {...gridA11y}>\n\t\t\t\t\t\t{loading ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__loading\">\n\t\t\t\t\t\t\t\t{Array.from({ length: 24 }, (_, skeletonIndex) => (\n\t\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noArrayIndexKey: fixed-count static placeholders that never reorder\n\t\t\t\t\t\t\t\t\t<span className=\"tenx-icon-placeholder\" key={`skeleton-${skeletonIndex}`} />\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : visible.length === 0 ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__empty\">{t(keys.noIconsFound)}</div>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\tstyle={{ height: virtualizer.getTotalSize(), position: 'relative', width: '100%' }}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{virtualizer.getVirtualItems().map((row) => (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tclassName=\"tenx-icon-drawer__row\"\n\t\t\t\t\t\t\t\t\t\tdata-index={row.index}\n\t\t\t\t\t\t\t\t\t\tkey={row.key}\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\t\tleft: 0,\n\t\t\t\t\t\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\t\t\t\t\t\ttransform: `translateY(${row.start}px)`,\n\t\t\t\t\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{visible\n\t\t\t\t\t\t\t\t\t\t\t.slice(row.index * columns, row.index * columns + columns)\n\t\t\t\t\t\t\t\t\t\t\t.map((icon, columnIndex) => {\n\t\t\t\t\t\t\t\t\t\t\t\tconst cellIndex = row.index * columns + columnIndex\n\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t<IconGridCell\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tentry={entry}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfocused={cellIndex === focusIndex}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ticon={icon}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tindex={cellIndex}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tisSelected={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tselected?.library === activeLibrary && selected.name === icon.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={icon.name}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnodes={NodesLoader ? nodeMap?.[icon.name] : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonSelect={handleSelect}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tregisterRef={registerRef}\n\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t<div className=\"tenx-icon-drawer__footer\">\n\t\t\t\t{t(keys.resultsCount, { count: visible.length })}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\nexport default IconDrawerContent\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,YAAY;AAClB,MAAM,SAAS;AACf,MAAM,MAAM;AAyBZ,MAAM,eAAoC,MAAM,MAC9C,EAAE,OAAO,SAAS,MAAM,OAAO,YAAY,OAAO,UAAU,kBAAkB;CAC9E,MAAM,CAAC,aAAa,kBAAkB,SAAS,KAAK;CAGpD,MAAM,QAAQ,gBAAgB,KAAK,IAAI;CACvC,OACC,oBAAC,OAAD;EAAK,WAAU;EAAyB,MAAK;YAC5C,qBAAC,UAAD;GACC,cAAY;GACZ,iBAAe;GACf,WACC,aACG,0EACA;GAEJ,cAAc,eAAe,KAAK;GAClC,eAAe,SAAS,KAAK,IAAI;GACjC,eAAe,eAAe,IAAI;GAClC,oBAAoB,eAAe,IAAI;GACvC,oBAAoB,eAAe,KAAK;GACxC,MAAM,YAAY,YAAY,OAAO,OAAO;GAC5C,M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ACnC,OAAO;SACR;mBAEC,QACC,MAAM,IAAI,QAAQ,SAAS,IAAI,QAAQ,UAAU,OAAO,EACxD,KAAK,MAAM,gBAAgB;UAC3B,MAAM,YAAY,IAAI,QAAQ,UAAU;UACxC,OACC,oBAAC,cAAD;WACQ;WACP,SAAS,cAAc;WACjB;WACN,OAAO;WACP,YACC,UAAU,YAAY,iBAAiB,SAAS,SAAS,KAAK;WAG/D,OAAO,cAAc,UAAU,KAAK,QAAQ,KAAA;WAC5C,UAAU;WACG;UACb,GAJK,KAAK,IAIV;SAEH,CAAC;QACE,GA9BC,IAAI,GA8BL,CACL;OACG,CAAA;MAEF,CAAA;KACD;MACD;;GACL,oBAAC,OAAD;IAAK,WAAU;cACb,EAAE,KAAK,cAAc,EAAE,OAAO,QAAQ,OAAO,CAAC;GAC3C,CAAA;EACD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"IconDrawerContent.js","names":["useTranslation"],"sources":["../../../../src/fields/icon/client/IconDrawerContent.tsx"],"sourcesContent":["'use client'\n\nimport { ReactSelect, SearchIcon } from '@payloadcms/ui'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport type React from 'react'\nimport { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { IconManifest, IconMeta, IconNodeMap } from '../../../types'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { buildIconSearchIndex, searchIcons } from '../shared/search'\nimport { IconGridCell } from './IconGridCell'\nimport { useRecentIcons } from './useRecentIcons'\n\n// One fixed size drives both the column count and the virtualizer row height. With no\n// in-flow label to vary a cell's height, every cell is an identical square and the grid\n// stays aligned regardless of icon name length.\nconst CELL_SIZE = 64\nconst RECENT = '__recent__'\nconst ALL = '__all__'\n\nexport type IconDrawerContentProps = {\n\tactiveLibrary: string\n\tadapterComponents: Record<string, AdapterComponentsEntry>\n\t/** Libraries available for selection: registered adapters already intersected with `available`. */\n\tadapters: { label: string; slug: string }[]\n\tonLibraryChange: (slug: string) => void\n\tonSelect: (library: string, icon: IconMeta) => void\n\tselected: { library: string; name: string } | null\n\tslugPrefix: string\n}\n\nconst IconDrawerContent: React.FC<IconDrawerContentProps> = ({\n\tactiveLibrary,\n\tadapterComponents,\n\tadapters,\n\tonLibraryChange,\n\tonSelect,\n\tselected,\n\tslugPrefix,\n}) => {\n\tconst { i18n, t } = useTranslation()\n\tconst [manifests, setManifests] = useState<Map<string, IconManifest>>(() => new Map())\n\tconst [nodeMaps, setNodeMaps] = useState<Map<string, IconNodeMap>>(() => new Map())\n\tconst [query, setQuery] = useState('')\n\tconst deferredQuery = useDeferredValue(query)\n\tconst [category, setCategory] = useState<string>(ALL)\n\tconst { addRecent, recent } = useRecentIcons(activeLibrary)\n\n\tconst manifest = manifests.get(activeLibrary)\n\tconst entry = adapterComponents[activeLibrary]\n\tconst Assets = entry?.Assets\n\tconst NodesLoader = entry?.Nodes\n\tconst nodeMap = nodeMaps.get(activeLibrary)\n\t// Libraries with a Nodes loader render the grid from bulk node-data; the grid\n\t// waits for that data before showing cells, others (radix) render immediately.\n\tconst nodesPending = Boolean(NodesLoader) && !nodeMap\n\tconst loading = !manifest || nodesPending\n\n\tconst handleManifest = useCallback(\n\t\t(loaded: IconManifest) => {\n\t\t\tsetManifests((previous) => new Map(previous).set(activeLibrary, loaded))\n\t\t},\n\t\t[activeLibrary]\n\t)\n\n\tconst handleNodes = useCallback(\n\t\t(loaded: IconNodeMap) => {\n\t\t\tsetNodeMaps((previous) => new Map(previous).set(activeLibrary, loaded))\n\t\t},\n\t\t[activeLibrary]\n\t)\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: activeLibrary is the trigger; the effect resets category and search when it changes\n\tuseEffect(() => {\n\t\tsetCategory(ALL)\n\t\tsetQuery('')\n\t}, [activeLibrary])\n\n\tconst byName = useMemo(\n\t\t() => new Map((manifest?.icons ?? []).map((icon) => [icon.name, icon])),\n\t\t[manifest]\n\t)\n\n\tconst categoryIcons = useMemo((): IconMeta[] => {\n\t\tif (!manifest) return []\n\t\tif (category === ALL) return manifest.icons\n\t\tif (category === RECENT) {\n\t\t\treturn recent\n\t\t\t\t.map((name) => byName.get(name))\n\t\t\t\t.filter((icon): icon is IconMeta => Boolean(icon))\n\t\t}\n\t\treturn manifest.icons.filter((icon) => icon.categories.includes(category))\n\t}, [byName, category, manifest, recent])\n\n\tconst index = useMemo(() => buildIconSearchIndex(categoryIcons), [categoryIcons])\n\tconst visible = useMemo(() => searchIcons(index, deferredQuery), [deferredQuery, index])\n\n\tconst gridRef = useRef<HTMLDivElement>(null)\n\tconst [gridWidth, setGridWidth] = useState(0)\n\tuseEffect(() => {\n\t\tconst element = gridRef.current\n\t\tif (!element) return\n\t\tconst observer = new ResizeObserver(() => setGridWidth(element.offsetWidth))\n\t\tobserver.observe(element)\n\t\tsetGridWidth(element.offsetWidth)\n\t\treturn () => observer.disconnect()\n\t}, [])\n\tconst columns = Math.max(3, Math.floor(gridWidth / CELL_SIZE))\n\tconst rowCount = Math.ceil(visible.length / columns)\n\t// Cell-box span of a full row (columns * CELL_SIZE), published to CSS as a custom property.\n\t// The header row and banner derive their width from this (inset to the button outlines in\n\t// icon-field.css) so the search, switcher, banner, and visible grid share one left and one\n\t// right edge. Sized only from CELL_SIZE.\n\tconst mainStyle = {\n\t\t'--tenx-icon-grid-width': `${columns * CELL_SIZE}px`,\n\t} as React.CSSProperties\n\n\tconst virtualizer = useVirtualizer({\n\t\tcount: rowCount,\n\t\testimateSize: () => CELL_SIZE,\n\t\tgetScrollElement: () => gridRef.current,\n\t\t// Cells are cheap inline SVG now, so a deeper overscan buys smoother fast scrolls.\n\t\toverscan: 8,\n\t})\n\n\tconst [focusIndex, setFocusIndex] = useState(0)\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: reset focus whenever the visible set changes\n\tuseEffect(() => setFocusIndex(0), [activeLibrary, category, deferredQuery])\n\tconst cellRefs = useRef(new Map<number, HTMLButtonElement>())\n\tconst registerRef = useCallback((cellIndex: number, element: HTMLButtonElement | null) => {\n\t\tif (element) cellRefs.current.set(cellIndex, element)\n\t\telse cellRefs.current.delete(cellIndex)\n\t}, [])\n\n\tconst focusCell = useCallback(\n\t\t(cellIndex: number) => {\n\t\t\tvirtualizer.scrollToIndex(Math.floor(cellIndex / columns))\n\t\t\trequestAnimationFrame(() => cellRefs.current.get(cellIndex)?.focus())\n\t\t},\n\t\t[columns, virtualizer]\n\t)\n\n\tconst handleGridKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLDivElement>) => {\n\t\t\tconst max = visible.length - 1\n\t\t\tif (max < 0) return\n\t\t\tlet next: number | null = null\n\t\t\tif (event.key === 'ArrowRight') next = Math.min(focusIndex + 1, max)\n\t\t\telse if (event.key === 'ArrowLeft') next = Math.max(focusIndex - 1, 0)\n\t\t\telse if (event.key === 'ArrowDown') next = Math.min(focusIndex + columns, max)\n\t\t\telse if (event.key === 'ArrowUp') next = Math.max(focusIndex - columns, 0)\n\t\t\telse if (event.key === 'Home') next = 0\n\t\t\telse if (event.key === 'End') next = max\n\t\t\tif (next === null) return\n\t\t\tevent.preventDefault()\n\t\t\tsetFocusIndex(next)\n\t\t\tfocusCell(next)\n\t\t},\n\t\t[columns, focusCell, focusIndex, visible.length]\n\t)\n\n\tconst handleSelect = useCallback(\n\t\t(icon: IconMeta) => {\n\t\t\taddRecent(icon.name)\n\t\t\tonSelect(activeLibrary, icon)\n\t\t},\n\t\t[activeLibrary, addRecent, onSelect]\n\t)\n\n\tconst railItems = useMemo(\n\t\t(): { key: string; label: string }[] => [\n\t\t\t{ key: ALL, label: t(keys.allIcons) },\n\t\t\t{ key: RECENT, label: t(keys.recent) },\n\t\t\t...(manifest?.categories ?? []).map((name) => ({ key: name, label: name })),\n\t\t],\n\t\t[manifest, t]\n\t)\n\n\tconst libraryOptions = useMemo(\n\t\t() => adapters.map((adapter) => ({ label: adapter.label, value: adapter.slug })),\n\t\t[adapters]\n\t)\n\tconst librarySelectId = `${slugPrefix}-library`\n\n\t// The stored value points at a library that is no longer offered for selection; the\n\t// full explanation lives here, the trigger only carries a compact marker.\n\tconst selectedUnavailable =\n\t\tselected !== null && !adapters.some((adapter) => adapter.slug === selected.library)\n\n\t// A listbox must own option children, so the grid only claims role=\"listbox\" (with\n\t// its keyboard nav and label) once cells exist. While loading it is an aria-busy\n\t// container; when empty it is a plain container holding the \"no icons\" message.\n\tconst gridPopulated = !loading && visible.length > 0\n\tconst gridA11y: React.HTMLAttributes<HTMLDivElement> = gridPopulated\n\t\t? { 'aria-label': t(keys.iconGrid), onKeyDown: handleGridKeyDown, role: 'listbox' }\n\t\t: { 'aria-busy': loading || undefined }\n\n\treturn (\n\t\t<div className=\"tenx-icon-drawer\">\n\t\t\t{/* Sibling loaders keyed distinctly per library: a shared key collides (\"two children\n\t\t\t with the same key\") when both mount on open, while distinct keys keep the per-library remount. */}\n\t\t\t{Assets && !manifest ? (\n\t\t\t\t<Assets key={`assets-${activeLibrary}`} onReady={handleManifest} />\n\t\t\t) : null}\n\t\t\t{NodesLoader && !nodeMap ? (\n\t\t\t\t<NodesLoader key={`nodes-${activeLibrary}`} onReady={handleNodes} />\n\t\t\t) : null}\n\t\t\t<div className=\"tenx-icon-drawer__body\">\n\t\t\t\t<nav aria-label={t(keys.iconCategories)} className=\"tenx-icon-drawer__rail\">\n\t\t\t\t\t{railItems.map((item) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\tcategory === item.key\n\t\t\t\t\t\t\t\t\t? 'tenx-icon-drawer__rail-item tenx-icon-drawer__rail-item--active'\n\t\t\t\t\t\t\t\t\t: 'tenx-icon-drawer__rail-item'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tkey={item.key}\n\t\t\t\t\t\t\tonClick={() => setCategory(item.key)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{item.label}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</nav>\n\t\t\t\t<div className=\"tenx-icon-drawer__main\" style={mainStyle}>\n\t\t\t\t\t{selectedUnavailable ? (\n\t\t\t\t\t\t<div className=\"tenx-icon-drawer__banner\" role=\"status\">\n\t\t\t\t\t\t\t{t(keys.libraryUnavailable)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div className=\"tenx-icon-drawer__header\">\n\t\t\t\t\t\t{/* Bordered control mirrors Payload's list-view search: SearchIcon inside-left, borderless input. */}\n\t\t\t\t\t\t<div className=\"tenx-icon-drawer__search\">\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" className=\"tenx-icon-drawer__search-icon\">\n\t\t\t\t\t\t\t\t<SearchIcon />\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\taria-label={t(keys.searchIcons)}\n\t\t\t\t\t\t\t\tclassName=\"tenx-icon-drawer__search-input\"\n\t\t\t\t\t\t\t\tonChange={(event: React.ChangeEvent<HTMLInputElement>) =>\n\t\t\t\t\t\t\t\t\tsetQuery(event.target.value)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tplaceholder={t(keys.searchIcons)}\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tvalue={query}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/* adapters is the available-filtered set; the switcher shows only with 2+ libraries, fixed width beside the growing search */}\n\t\t\t\t\t\t{adapters.length > 1 ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__switcher\">\n\t\t\t\t\t\t\t\t<label className=\"tenx-icon-drawer__sr-only\" htmlFor={librarySelectId}>\n\t\t\t\t\t\t\t\t\t{t(keys.fieldIconLibraryLabel)}\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t<ReactSelect\n\t\t\t\t\t\t\t\t\tinputId={librarySelectId}\n\t\t\t\t\t\t\t\t\tisClearable={false}\n\t\t\t\t\t\t\t\t\tonChange={(option) => {\n\t\t\t\t\t\t\t\t\t\tconst single = Array.isArray(option) ? option[0] : option\n\t\t\t\t\t\t\t\t\t\tif (single && typeof single.value === 'string') onLibraryChange(single.value)\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\toptions={libraryOptions}\n\t\t\t\t\t\t\t\t\tvalue={libraryOptions.find((option) => option.value === activeLibrary)}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className=\"tenx-icon-drawer__grid\" ref={gridRef} {...gridA11y}>\n\t\t\t\t\t\t{loading ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__loading\">\n\t\t\t\t\t\t\t\t{Array.from({ length: 24 }, (_, skeletonIndex) => (\n\t\t\t\t\t\t\t\t\t// biome-ignore lint/suspicious/noArrayIndexKey: fixed-count static placeholders that never reorder\n\t\t\t\t\t\t\t\t\t<span className=\"tenx-icon-placeholder\" key={`skeleton-${skeletonIndex}`} />\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : visible.length === 0 ? (\n\t\t\t\t\t\t\t<div className=\"tenx-icon-drawer__empty\">{t(keys.noIconsFound)}</div>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\tstyle={{ height: virtualizer.getTotalSize(), position: 'relative', width: '100%' }}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{virtualizer.getVirtualItems().map((row) => (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tclassName=\"tenx-icon-drawer__row\"\n\t\t\t\t\t\t\t\t\t\tdata-index={row.index}\n\t\t\t\t\t\t\t\t\t\tkey={row.key}\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\t\tleft: 0,\n\t\t\t\t\t\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\t\t\t\t\t\ttransform: `translateY(${row.start}px)`,\n\t\t\t\t\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{visible\n\t\t\t\t\t\t\t\t\t\t\t.slice(row.index * columns, row.index * columns + columns)\n\t\t\t\t\t\t\t\t\t\t\t.map((icon, columnIndex) => {\n\t\t\t\t\t\t\t\t\t\t\t\tconst cellIndex = row.index * columns + columnIndex\n\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t<IconGridCell\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcanvas={entry?.canvas}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tentry={entry}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfocused={cellIndex === focusIndex}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ticon={icon}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tindex={cellIndex}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tisSelected={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tselected?.library === activeLibrary && selected.name === icon.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={icon.name}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlanguage={i18n.language}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnodes={NodesLoader ? nodeMap?.[icon.name] : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tonSelect={handleSelect}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tregisterRef={registerRef}\n\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t<div className=\"tenx-icon-drawer__footer\">\n\t\t\t\t{t(keys.resultsCount, { count: visible.length })}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\nexport default IconDrawerContent\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,YAAY;AAClB,MAAM,SAAS;AACf,MAAM,MAAM;AAaZ,MAAM,qBAAuD,EAC5D,eACA,mBACA,UACA,iBACA,UACA,UACA,iBACK;CACL,MAAM,EAAE,MAAM,MAAMA,iBAAe;CACnC,MAAM,CAAC,WAAW,gBAAgB,+BAA0C,IAAI,IAAI,CAAC;CACrF,MAAM,CAAC,UAAU,eAAe,+BAAyC,IAAI,IAAI,CAAC;CAClF,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,gBAAgB,iBAAiB,KAAK;CAC5C,MAAM,CAAC,UAAU,eAAe,SAAiB,GAAG;CACpD,MAAM,EAAE,WAAW,WAAW,eAAe,aAAa;CAE1D,MAAM,WAAW,UAAU,IAAI,aAAa;CAC5C,MAAM,QAAQ,kBAAkB;CAChC,MAAM,SAAS,OAAO;CACtB,MAAM,cAAc,OAAO;CAC3B,MAAM,UAAU,SAAS,IAAI,aAAa;CAI1C,MAAM,UAAU,CAAC,YADI,QAAQ,WAAW,KAAK,CAAC;CAG9C,MAAM,iBAAiB,aACrB,WAAyB;EACzB,cAAc,aAAa,IAAI,IAAI,QAAQ,EAAE,IAAI,eAAe,MAAM,CAAC;CACxE,GACA,CAAC,aAAa,CACf;CAEA,MAAM,cAAc,aAClB,WAAwB;EACxB,aAAa,aAAa,IAAI,IAAI,QAAQ,EAAE,IAAI,eAAe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WAAU;SACV,cAAY,IAAI;SAEhB,MAAK;SACL,OAAO;UACN,MAAM;UACN,UAAU;UACV,KAAK;UACL,WAAW,cAAc,IAAI,MAAM;UACnC,OAAO;SACR;mBAEC,QACC,MAAM,IAAI,QAAQ,SAAS,IAAI,QAAQ,UAAU,OAAO,EACxD,KAAK,MAAM,gBAAgB;UAC3B,MAAM,YAAY,IAAI,QAAQ,UAAU;UACxC,OACC,oBAAC,cAAD;WACC,QAAQ,OAAO;WACR;WACP,SAAS,cAAc;WACjB;WACN,OAAO;WACP,YACC,UAAU,YAAY,iBAAiB,SAAS,SAAS,KAAK;WAG/D,UAAU,KAAK;WACf,OAAO,cAAc,UAAU,KAAK,QAAQ,KAAA;WAC5C,UAAU;WACG;UACb,GALK,KAAK,IAKV;SAEH,CAAC;QACE,GAhCC,IAAI,GAgCL,CACL;OACG,CAAA;MAEF,CAAA;KACD;MACD;;GACL,oBAAC,OAAD;IAAK,WAAU;cACb,EAAE,KAAK,cAAc,EAAE,OAAO,QAAQ,OAAO,CAAC;GAC3C,CAAA;EACD;;AAEP"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IconMeta } from "../../../types.js";
|
|
1
2
|
import { AdapterComponentsEntry } from "../shared/adapterComponents.js";
|
|
2
3
|
import { TextFieldClientProps } from "payload";
|
|
3
4
|
import React from "react";
|
|
@@ -10,6 +11,12 @@ type IconFieldClientExtraProps = {
|
|
|
10
11
|
}[];
|
|
11
12
|
available: string[];
|
|
12
13
|
defaultLibrary: string;
|
|
14
|
+
/**
|
|
15
|
+
* Manifest entry for the value this field rendered with, resolved server-side.
|
|
16
|
+
* The trigger has only a stored value, so without this a library-supplied label
|
|
17
|
+
* could not appear until the editor opened the drawer.
|
|
18
|
+
*/
|
|
19
|
+
selectedMeta?: IconMeta | null;
|
|
13
20
|
showTextInput: boolean;
|
|
14
21
|
};
|
|
15
22
|
type IconFieldClientProps = IconFieldClientExtraProps & TextFieldClientProps;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { keys } from "../../../translations/keys.js";
|
|
3
3
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveIconDisplay } from "../shared/iconLabel.js";
|
|
5
5
|
import { formatIconValue, resolveIconValue } from "../shared/value.js";
|
|
6
6
|
import { filterAvailableLibraries, pickInitialLibrary } from "./availableLibraries.js";
|
|
7
7
|
import { Drawer, FieldDescription, FieldError, FieldLabel, RenderCustomComponent, XIcon, fieldBaseClass, formatDrawerSlug, useEditDepth, useField, useModal } from "@payloadcms/ui";
|
|
8
8
|
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
9
|
-
import React, { Suspense, useCallback, useMemo, useState } from "react";
|
|
9
|
+
import React, { Suspense, useCallback, useMemo, useRef, useState } from "react";
|
|
10
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import "./icon-field.css";
|
|
12
12
|
//#region src/fields/icon/client/IconFieldClient.tsx
|
|
@@ -77,8 +77,8 @@ const WarningIcon = () => /* @__PURE__ */ jsxs("svg", {
|
|
|
77
77
|
]
|
|
78
78
|
});
|
|
79
79
|
const IconField = (props) => {
|
|
80
|
-
const { adapterComponents, adapters, available, defaultLibrary, field, path: pathFromProps, readOnly, showTextInput } = props;
|
|
81
|
-
const { t } = useTranslation$1();
|
|
80
|
+
const { adapterComponents, adapters, available, defaultLibrary, field, path: pathFromProps, readOnly, selectedMeta, showTextInput } = props;
|
|
81
|
+
const { i18n, t } = useTranslation$1();
|
|
82
82
|
const editDepth = useEditDepth();
|
|
83
83
|
const { closeModal, isModalOpen, openModal } = useModal();
|
|
84
84
|
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
@@ -93,7 +93,13 @@ const IconField = (props) => {
|
|
|
93
93
|
const isUnavailable = resolved !== null && (!registeredSlugs.has(resolved.library) || !available.includes(resolved.library));
|
|
94
94
|
const previewEntry = resolved ? adapterComponents[resolved.library] : void 0;
|
|
95
95
|
const hasGlyph = Boolean(resolved && previewEntry);
|
|
96
|
-
const
|
|
96
|
+
const knownMeta = useRef(/* @__PURE__ */ new Map());
|
|
97
|
+
if (value && selectedMeta && !knownMeta.current.has(value)) knownMeta.current.set(value, selectedMeta);
|
|
98
|
+
const displayLabel = resolved ? resolveIconDisplay({
|
|
99
|
+
language: i18n.language,
|
|
100
|
+
meta: value ? knownMeta.current.get(value) : void 0,
|
|
101
|
+
name: resolved.name
|
|
102
|
+
}).label : "";
|
|
97
103
|
const availableAdapters = useMemo(() => filterAvailableLibraries(adapters, available), [adapters, available]);
|
|
98
104
|
const [activeLibrary, setActiveLibrary] = useState(() => pickInitialLibrary({
|
|
99
105
|
available,
|
|
@@ -101,8 +107,10 @@ const IconField = (props) => {
|
|
|
101
107
|
selectedLibrary: resolved?.library ?? null
|
|
102
108
|
}));
|
|
103
109
|
const [editing, setEditing] = useState(false);
|
|
104
|
-
const handleSelect = useCallback((library,
|
|
105
|
-
|
|
110
|
+
const handleSelect = useCallback((library, icon) => {
|
|
111
|
+
const next = formatIconValue(library, icon.name);
|
|
112
|
+
knownMeta.current.set(next, icon);
|
|
113
|
+
setValue(next);
|
|
106
114
|
closeModal(drawerSlug);
|
|
107
115
|
}, [
|
|
108
116
|
closeModal,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconFieldClient.js","names":["useTranslation"],"sources":["../../../../src/fields/icon/client/IconFieldClient.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tDrawer,\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tformatDrawerSlug,\n\tRenderCustomComponent,\n\tuseEditDepth,\n\tuseField,\n\tuseModal,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport React, { Suspense, useCallback, useMemo, useState } from 'react'\nimport { keys } from '../../../translations'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { formatIconLabel } from '../shared/formatIconLabel'\nimport { formatIconValue, resolveIconValue } from '../shared/value'\nimport { filterAvailableLibraries, pickInitialLibrary } from './availableLibraries'\nimport './icon-field.css'\n\nconst IconDrawerContent = React.lazy(() => import('./IconDrawerContent'))\n\n/** Muted grid glyph shown in the square when the field has no value: a picker affordance, not a value. */\nconst PlaceholderGlyph: React.FC = () => (\n\t<svg aria-hidden=\"true\" fill=\"currentColor\" height={20} viewBox=\"0 0 20 20\" width={20}>\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"3\" y=\"3\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"11\" y=\"3\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"3\" y=\"11\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"11\" y=\"11\" />\n\t</svg>\n)\n\nconst WarningIcon: React.FC = () => (\n\t<svg aria-hidden=\"true\" fill=\"none\" height={16} viewBox=\"0 0 16 16\" width={16}>\n\t\t<path d=\"M8 1.75 15 14H1z\" stroke=\"currentColor\" strokeLinejoin=\"round\" strokeWidth=\"1.4\" />\n\t\t<path d=\"M8 6.25v3.5\" stroke=\"currentColor\" strokeLinecap=\"round\" strokeWidth=\"1.4\" />\n\t\t<circle cx=\"8\" cy=\"11.75\" fill=\"currentColor\" r=\"0.85\" />\n\t</svg>\n)\n\nexport type IconFieldClientExtraProps = {\n\tadapterComponents: Record<string, AdapterComponentsEntry>\n\tadapters: { label: string; slug: string }[]\n\tavailable: string[]\n\tdefaultLibrary: string\n\tshowTextInput: boolean\n}\n\nexport type IconFieldClientProps = IconFieldClientExtraProps & TextFieldClientProps\n\nexport const IconField: React.FC<IconFieldClientProps> = (props) => {\n\tconst {\n\t\tadapterComponents,\n\t\tadapters,\n\t\tavailable,\n\t\tdefaultLibrary,\n\t\tfield,\n\t\tpath: pathFromProps,\n\t\treadOnly,\n\t\tshowTextInput,\n\t} = props\n\tconst { t } = useTranslation()\n\tconst editDepth = useEditDepth()\n\tconst { closeModal, isModalOpen, openModal } = useModal()\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps })\n\n\tconst drawerSlug = formatDrawerSlug({ slug: `fields-icon-${path}`, depth: editDepth })\n\tconst isDisabled = Boolean(readOnly || disabled || field.admin?.readOnly)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst resolved = value ? resolveIconValue(value, defaultLibrary) : null\n\tconst registeredSlugs = useMemo(\n\t\t() => new Set(adapters.map((adapter) => adapter.slug)),\n\t\t[adapters]\n\t)\n\tconst isUnavailable =\n\t\tresolved !== null &&\n\t\t(!registeredSlugs.has(resolved.library) || !available.includes(resolved.library))\n\tconst previewEntry = resolved ? adapterComponents[resolved.library] : undefined\n\tconst hasGlyph = Boolean(resolved && previewEntry)\n\tconst displayLabel = resolved ? formatIconLabel(resolved.name) : ''\n\n\tconst availableAdapters = useMemo(\n\t\t() => filterAvailableLibraries(adapters, available),\n\t\t[adapters, available]\n\t)\n\tconst [activeLibrary, setActiveLibrary] = useState(() =>\n\t\tpickInitialLibrary({ available, defaultLibrary, selectedLibrary: resolved?.library ?? null })\n\t)\n\n\t// Text-input mode shows the raw `library:name` while focused for editing and the\n\t// formatted label otherwise, so the editor never has to read a colon-prefixed value.\n\tconst [editing, setEditing] = useState(false)\n\n\tconst handleSelect = useCallback(\n\t\t(library: string, name: string) => {\n\t\t\tsetValue(formatIconValue(library, name))\n\t\t\tcloseModal(drawerSlug)\n\t\t},\n\t\t[closeModal, drawerSlug, setValue]\n\t)\n\n\tconst triggerDisabled = isDisabled || availableAdapters.length === 0\n\tconst glyphClass = `tenx-icon-field__glyph${hasGlyph ? '' : ' tenx-icon-field__glyph--empty'}`\n\tconst glyph =\n\t\tresolved && previewEntry ? (\n\t\t\t<previewEntry.Icon name={resolved.name} size={20} />\n\t\t) : (\n\t\t\t<PlaceholderGlyph />\n\t\t)\n\n\tconst wrapperClasses = [\n\t\tfieldBaseClass,\n\t\t'tenx-icon-field',\n\t\tfield.admin?.className,\n\t\tshowError ? 'error' : null,\n\t\tisDisabled ? 'read-only' : null,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ')\n\n\tconst controlClasses = `tenx-icon-field__control${isUnavailable ? ' tenx-icon-field__control--warning' : ''}`\n\n\treturn (\n\t\t<div className={wrapperClasses} id={`field-${path.replace(/\\./g, '__')}`} style={styles}>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\tlabel={field.label}\n\t\t\t\t\t\tlocalized={field.localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={field.required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={controlClasses}>\n\t\t\t\t\t{showTextInput ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-expanded={isModalOpen(drawerSlug)}\n\t\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t\t\taria-label={t(keys.selectIcon)}\n\t\t\t\t\t\t\t\tclassName={glyphClass}\n\t\t\t\t\t\t\t\tdisabled={triggerDisabled}\n\t\t\t\t\t\t\t\tonClick={() => openModal(drawerSlug)}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{glyph}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\taria-label={t(keys.fieldIconLabel)}\n\t\t\t\t\t\t\t\tclassName=\"tenx-icon-field__value tenx-icon-field__value--input\"\n\t\t\t\t\t\t\t\tonBlur={() => setEditing(false)}\n\t\t\t\t\t\t\t\tonChange={(event) => setValue(event.target.value || null)}\n\t\t\t\t\t\t\t\tonFocus={() => setEditing(true)}\n\t\t\t\t\t\t\t\tplaceholder={t(keys.textInputPlaceholder)}\n\t\t\t\t\t\t\t\treadOnly={isDisabled}\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tvalue={editing ? (value ?? '') : displayLabel}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-expanded={isModalOpen(drawerSlug)}\n\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t\tclassName=\"tenx-icon-field__open\"\n\t\t\t\t\t\t\tdisabled={triggerDisabled}\n\t\t\t\t\t\t\tonClick={() => openModal(drawerSlug)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" className={glyphClass}>\n\t\t\t\t\t\t\t\t{glyph}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className=\"tenx-icon-field__value\">\n\t\t\t\t\t\t\t\t{resolved ? (\n\t\t\t\t\t\t\t\t\tdisplayLabel\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<span className=\"tenx-icon-field__placeholder\">{t(keys.selectIcon)}</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t)}\n\t\t\t\t\t{isUnavailable ? (\n\t\t\t\t\t\t<span className=\"tenx-icon-field__marker\" title={t(keys.iconUnavailable)}>\n\t\t\t\t\t\t\t<WarningIcon />\n\t\t\t\t\t\t\t<span className=\"tenx-icon-field__sr-only\">{t(keys.iconUnavailable)}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t\t{value && !field.required && !isDisabled ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearIcon)}\n\t\t\t\t\t\t\tclassName=\"tenx-icon-field__clear\"\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t\tsetEditing(false)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={field.admin?.description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<Drawer className=\"tenx-icon-drawer-modal\" slug={drawerSlug} title={t(keys.selectIcon)}>\n\t\t\t\t<Suspense fallback={<div className=\"tenx-icon-drawer__loading\" />}>\n\t\t\t\t\t<IconDrawerContent\n\t\t\t\t\t\tactiveLibrary={activeLibrary}\n\t\t\t\t\t\tadapterComponents={adapterComponents}\n\t\t\t\t\t\tadapters={availableAdapters}\n\t\t\t\t\t\tonLibraryChange={setActiveLibrary}\n\t\t\t\t\t\tonSelect={handleSelect}\n\t\t\t\t\t\tselected={resolved}\n\t\t\t\t\t\tslugPrefix={drawerSlug}\n\t\t\t\t\t/>\n\t\t\t\t</Suspense>\n\t\t\t</Drawer>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAM,oBAAoB,MAAM,W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AA,CACC;;OAER,gBACA,qBAAC,QAAD;QAAM,WAAU;QAA0B,OAAO,EAAE,KAAK,eAAe;kBAAvE,CACC,oBAAC,aAAD,CAAc,CAAA,GACd,oBAAC,QAAD;SAAM,WAAU;mBAA4B,EAAE,KAAK,eAAe;QAAQ,CAAA,CACrE;YACH;OACH,SAAS,CAAC,MAAM,YAAY,CAAC,aAC7B,oBAAC,UAAD;QACC,cAAY,EAAE,KAAK,SAAS;QAC5B,WAAU;QACV,eAAe;SACd,SAAS,IAAI;SACb,WAAW,KAAK;QACjB;QACA,MAAK;kBAEL,oBAAC,OAAD,CAAQ,CAAA;OACD,CAAA,IACL;MACA;;KACJ;KACD,oBAAC,uBAAD;MACC,iBAAiB;MACjB,UAAU,oBAAC,kBAAD;OAAkB,aAAa,MAAM,OAAO;OAAmB;MAAO,CAAA;KAChF,CAAA;IACG;;GACL,oBAAC,QAAD;IAAQ,WAAU;IAAyB,MAAM;IAAY,OAAO,EAAE,KAAK,UAAU;cACpF,oBAAC,UAAD;KAAU,UAAU,oBAAC,OAAD,EAAK,WAAU,4BAA6B,CAAA;eAC/D,oBAAC,mBAAD;MACgB;MACI;MACnB,UAAU;MACV,iBAAiB;MACjB,UAAU;MACV,UAAU;MACV,YAAY;KACZ,CAAA;IACQ,CAAA;GACH,CAAA;EACJ;;AAEP"}
|
|
1
|
+
{"version":3,"file":"IconFieldClient.js","names":["useTranslation"],"sources":["../../../../src/fields/icon/client/IconFieldClient.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tDrawer,\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tformatDrawerSlug,\n\tRenderCustomComponent,\n\tuseEditDepth,\n\tuseField,\n\tuseModal,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps } from 'payload'\nimport React, { Suspense, useCallback, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { IconMeta } from '../../../types'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveIconDisplay } from '../shared/iconLabel'\nimport { formatIconValue, resolveIconValue } from '../shared/value'\nimport { filterAvailableLibraries, pickInitialLibrary } from './availableLibraries'\nimport './icon-field.css'\n\nconst IconDrawerContent = React.lazy(() => import('./IconDrawerContent'))\n\n/** Muted grid glyph shown in the square when the field has no value: a picker affordance, not a value. */\nconst PlaceholderGlyph: React.FC = () => (\n\t<svg aria-hidden=\"true\" fill=\"currentColor\" height={20} viewBox=\"0 0 20 20\" width={20}>\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"3\" y=\"3\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"11\" y=\"3\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"3\" y=\"11\" />\n\t\t<rect height=\"6\" rx=\"1.5\" width=\"6\" x=\"11\" y=\"11\" />\n\t</svg>\n)\n\nconst WarningIcon: React.FC = () => (\n\t<svg aria-hidden=\"true\" fill=\"none\" height={16} viewBox=\"0 0 16 16\" width={16}>\n\t\t<path d=\"M8 1.75 15 14H1z\" stroke=\"currentColor\" strokeLinejoin=\"round\" strokeWidth=\"1.4\" />\n\t\t<path d=\"M8 6.25v3.5\" stroke=\"currentColor\" strokeLinecap=\"round\" strokeWidth=\"1.4\" />\n\t\t<circle cx=\"8\" cy=\"11.75\" fill=\"currentColor\" r=\"0.85\" />\n\t</svg>\n)\n\nexport type IconFieldClientExtraProps = {\n\tadapterComponents: Record<string, AdapterComponentsEntry>\n\tadapters: { label: string; slug: string }[]\n\tavailable: string[]\n\tdefaultLibrary: string\n\t/**\n\t * Manifest entry for the value this field rendered with, resolved server-side.\n\t * The trigger has only a stored value, so without this a library-supplied label\n\t * could not appear until the editor opened the drawer.\n\t */\n\tselectedMeta?: IconMeta | null\n\tshowTextInput: boolean\n}\n\nexport type IconFieldClientProps = IconFieldClientExtraProps & TextFieldClientProps\n\nexport const IconField: React.FC<IconFieldClientProps> = (props) => {\n\tconst {\n\t\tadapterComponents,\n\t\tadapters,\n\t\tavailable,\n\t\tdefaultLibrary,\n\t\tfield,\n\t\tpath: pathFromProps,\n\t\treadOnly,\n\t\tselectedMeta,\n\t\tshowTextInput,\n\t} = props\n\tconst { i18n, t } = useTranslation()\n\tconst editDepth = useEditDepth()\n\tconst { closeModal, isModalOpen, openModal } = useModal()\n\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\tpath,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<string>({ potentiallyStalePath: pathFromProps })\n\n\tconst drawerSlug = formatDrawerSlug({ slug: `fields-icon-${path}`, depth: editDepth })\n\tconst isDisabled = Boolean(readOnly || disabled || field.admin?.readOnly)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst resolved = value ? resolveIconValue(value, defaultLibrary) : null\n\tconst registeredSlugs = useMemo(\n\t\t() => new Set(adapters.map((adapter) => adapter.slug)),\n\t\t[adapters]\n\t)\n\tconst isUnavailable =\n\t\tresolved !== null &&\n\t\t(!registeredSlugs.has(resolved.library) || !available.includes(resolved.library))\n\tconst previewEntry = resolved ? adapterComponents[resolved.library] : undefined\n\tconst hasGlyph = Boolean(resolved && previewEntry)\n\n\t// Manifest entries by stored value, seeded with the server's answer for the value\n\t// this field rendered with and extended whenever the editor picks. A pick has to\n\t// relabel the trigger immediately, and the manifest only lives inside the drawer.\n\tconst knownMeta = useRef(new Map<string, IconMeta>())\n\tif (value && selectedMeta && !knownMeta.current.has(value)) {\n\t\tknownMeta.current.set(value, selectedMeta)\n\t}\n\tconst displayLabel = resolved\n\t\t? resolveIconDisplay({\n\t\t\t\tlanguage: i18n.language,\n\t\t\t\tmeta: value ? knownMeta.current.get(value) : undefined,\n\t\t\t\tname: resolved.name,\n\t\t\t}).label\n\t\t: ''\n\n\tconst availableAdapters = useMemo(\n\t\t() => filterAvailableLibraries(adapters, available),\n\t\t[adapters, available]\n\t)\n\tconst [activeLibrary, setActiveLibrary] = useState(() =>\n\t\tpickInitialLibrary({ available, defaultLibrary, selectedLibrary: resolved?.library ?? null })\n\t)\n\n\t// Text-input mode shows the raw `library:name` while focused for editing and the\n\t// formatted label otherwise, so the editor never has to read a colon-prefixed value.\n\tconst [editing, setEditing] = useState(false)\n\n\tconst handleSelect = useCallback(\n\t\t(library: string, icon: IconMeta) => {\n\t\t\tconst next = formatIconValue(library, icon.name)\n\t\t\tknownMeta.current.set(next, icon)\n\t\t\tsetValue(next)\n\t\t\tcloseModal(drawerSlug)\n\t\t},\n\t\t[closeModal, drawerSlug, setValue]\n\t)\n\n\tconst triggerDisabled = isDisabled || availableAdapters.length === 0\n\tconst glyphClass = `tenx-icon-field__glyph${hasGlyph ? '' : ' tenx-icon-field__glyph--empty'}`\n\tconst glyph =\n\t\tresolved && previewEntry ? (\n\t\t\t<previewEntry.Icon name={resolved.name} size={20} />\n\t\t) : (\n\t\t\t<PlaceholderGlyph />\n\t\t)\n\n\tconst wrapperClasses = [\n\t\tfieldBaseClass,\n\t\t'tenx-icon-field',\n\t\tfield.admin?.className,\n\t\tshowError ? 'error' : null,\n\t\tisDisabled ? 'read-only' : null,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(' ')\n\n\tconst controlClasses = `tenx-icon-field__control${isUnavailable ? ' tenx-icon-field__control--warning' : ''}`\n\n\treturn (\n\t\t<div className={wrapperClasses} id={`field-${path.replace(/\\./g, '__')}`} style={styles}>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel\n\t\t\t\t\t\tlabel={field.label}\n\t\t\t\t\t\tlocalized={field.localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={field.required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={controlClasses}>\n\t\t\t\t\t{showTextInput ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\taria-expanded={isModalOpen(drawerSlug)}\n\t\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t\t\taria-label={t(keys.selectIcon)}\n\t\t\t\t\t\t\t\tclassName={glyphClass}\n\t\t\t\t\t\t\t\tdisabled={triggerDisabled}\n\t\t\t\t\t\t\t\tonClick={() => openModal(drawerSlug)}\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{glyph}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\taria-label={t(keys.fieldIconLabel)}\n\t\t\t\t\t\t\t\tclassName=\"tenx-icon-field__value tenx-icon-field__value--input\"\n\t\t\t\t\t\t\t\tonBlur={() => setEditing(false)}\n\t\t\t\t\t\t\t\tonChange={(event) => setValue(event.target.value || null)}\n\t\t\t\t\t\t\t\tonFocus={() => setEditing(true)}\n\t\t\t\t\t\t\t\tplaceholder={t(keys.textInputPlaceholder)}\n\t\t\t\t\t\t\t\treadOnly={isDisabled}\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tvalue={editing ? (value ?? '') : displayLabel}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-expanded={isModalOpen(drawerSlug)}\n\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t\tclassName=\"tenx-icon-field__open\"\n\t\t\t\t\t\t\tdisabled={triggerDisabled}\n\t\t\t\t\t\t\tonClick={() => openModal(drawerSlug)}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span aria-hidden=\"true\" className={glyphClass}>\n\t\t\t\t\t\t\t\t{glyph}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className=\"tenx-icon-field__value\">\n\t\t\t\t\t\t\t\t{resolved ? (\n\t\t\t\t\t\t\t\t\tdisplayLabel\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<span className=\"tenx-icon-field__placeholder\">{t(keys.selectIcon)}</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t)}\n\t\t\t\t\t{isUnavailable ? (\n\t\t\t\t\t\t<span className=\"tenx-icon-field__marker\" title={t(keys.iconUnavailable)}>\n\t\t\t\t\t\t\t<WarningIcon />\n\t\t\t\t\t\t\t<span className=\"tenx-icon-field__sr-only\">{t(keys.iconUnavailable)}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t\t{value && !field.required && !isDisabled ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearIcon)}\n\t\t\t\t\t\t\tclassName=\"tenx-icon-field__clear\"\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetValue(null)\n\t\t\t\t\t\t\t\tsetEditing(false)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={field.admin?.description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<Drawer className=\"tenx-icon-drawer-modal\" slug={drawerSlug} title={t(keys.selectIcon)}>\n\t\t\t\t<Suspense fallback={<div className=\"tenx-icon-drawer__loading\" />}>\n\t\t\t\t\t<IconDrawerContent\n\t\t\t\t\t\tactiveLibrary={activeLibrary}\n\t\t\t\t\t\tadapterComponents={adapterComponents}\n\t\t\t\t\t\tadapters={availableAdapters}\n\t\t\t\t\t\tonLibraryChange={setActiveLibrary}\n\t\t\t\t\t\tonSelect={handleSelect}\n\t\t\t\t\t\tselected={resolved}\n\t\t\t\t\t\tslugPrefix={drawerSlug}\n\t\t\t\t\t/>\n\t\t\t\t</Suspense>\n\t\t\t</Drawer>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,oBAAoB,MAAM,WAAW,OAAO,yBAAsB;;AAGxE,MAAM,yBACL,qBAAC,OAAD;CAAK,eAAY;CAAO,MAAK;CAAe,QAAQ;CAAI,SAAQ;CAAY,OAAO;WAAnF;EACC,oBAAC,QAAD;GAAM,QAAO;GAAI,IAAG;GAAM,OAAM;GAAI,GAAE;GAAI,GAAE;EAAK,CAAA;EACjD,oBAAC,QAAD;GAAM,QAAO;GAAI,IAAG;GAAM,OAAM;GAAI,GAAE;GAAK,GAAE;EAAK,CAAA;EAClD,oBAAC,QAAD;GAAM,QAAO;GAAI,IAAG;GAAM,OAAM;GAAI,GAAE;GAAI,GAAE;EAAM,CAAA;EAClD,oBAAC,QAAD;GAAM,QAAO;GAAI,IAAG;GAAM,OAAM;GAAI,GAAE;GAAK,GAAE;EAAM,CAAA;CAC/C;;AAGN,MAAM,oBACL,qBAAC,OAAD;CAAK,eAAY;CAAO,MAAK;CAAO,QAAQ;CAAI,SAAQ;CAAY,OAAO;WAA3E;EACC,oBAAC,QAAD;GAAM,GAAE;GAAmB,QAAO;GAAe,gBAAe;GAAQ,aAAY;EAAO,CAAA;EAC3F,oBAAC,QAAD;GAAM,GAAE;GAAc,QAAO;GAAe,eAAc;GAAQ,aAAY;EAAO,CA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B;MACjB,UAAU,oBAAC,kBAAD;OAAkB,aAAa,MAAM,OAAO;OAAmB;MAAO,CAAA;KAChF,CAAA;IACG;;GACL,oBAAC,QAAD;IAAQ,WAAU;IAAyB,MAAM;IAAY,OAAO,EAAE,KAAK,UAAU;cACpF,oBAAC,UAAD;KAAU,UAAU,oBAAC,OAAD,EAAK,WAAU,4BAA6B,CAAA;eAC/D,oBAAC,mBAAD;MACgB;MACI;MACnB,UAAU;MACV,iBAAiB;MACjB,UAAU;MACV,UAAU;MACV,YAAY;KACZ,CAAA;IACQ,CAAA;GACH,CAAA;EACJ;;AAEP"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { resolveIconDisplay } from "../shared/iconLabel.js";
|
|
3
|
+
import { DrawerGlyph } from "./DrawerGlyph.js";
|
|
4
|
+
import { Tooltip } from "@payloadcms/ui";
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/fields/icon/client/IconGridCell.tsx
|
|
8
|
+
/**
|
|
9
|
+
* One square in the icon grid. The name is not rendered in-flow, because that
|
|
10
|
+
* variance broke grid alignment; it lives on the accessible name and a
|
|
11
|
+
* hover/focus tooltip.
|
|
12
|
+
*
|
|
13
|
+
* Those two deliberately differ. The accessible name carries the label alone, so
|
|
14
|
+
* a screen reader browsing a country library announces "Hungary" rather than
|
|
15
|
+
* "Hungary HUN" 215 times. The tooltip carries the raw name alongside it, because
|
|
16
|
+
* it is the only surface where an editor can discover that "Hungary" stores as
|
|
17
|
+
* `HUN`, which they need in order to write frontend code against the value.
|
|
18
|
+
*/
|
|
19
|
+
const IconGridCell = React.memo(({ canvas, entry, focused, icon, index, isSelected, language, nodes, onSelect, registerRef }) => {
|
|
20
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
21
|
+
const display = resolveIconDisplay({
|
|
22
|
+
language,
|
|
23
|
+
meta: icon,
|
|
24
|
+
name: icon.name
|
|
25
|
+
});
|
|
26
|
+
return /* @__PURE__ */ jsx("div", {
|
|
27
|
+
className: "tenx-icon-drawer__cell",
|
|
28
|
+
role: "presentation",
|
|
29
|
+
children: /* @__PURE__ */ jsxs("button", {
|
|
30
|
+
"aria-label": display.label,
|
|
31
|
+
"aria-selected": isSelected,
|
|
32
|
+
className: isSelected ? "tenx-icon-drawer__cell-button tenx-icon-drawer__cell-button--selected" : "tenx-icon-drawer__cell-button",
|
|
33
|
+
onBlur: () => setShowTooltip(false),
|
|
34
|
+
onClick: () => onSelect(icon),
|
|
35
|
+
onFocus: () => setShowTooltip(true),
|
|
36
|
+
onMouseEnter: () => setShowTooltip(true),
|
|
37
|
+
onMouseLeave: () => setShowTooltip(false),
|
|
38
|
+
ref: (element) => registerRef(index, element),
|
|
39
|
+
role: "option",
|
|
40
|
+
tabIndex: focused ? 0 : -1,
|
|
41
|
+
type: "button",
|
|
42
|
+
children: [/* @__PURE__ */ jsxs(Tooltip, {
|
|
43
|
+
show: showTooltip,
|
|
44
|
+
staticPositioning: true,
|
|
45
|
+
children: [display.label, display.code ? /* @__PURE__ */ jsx("span", {
|
|
46
|
+
className: "tenx-icon-drawer__cell-code",
|
|
47
|
+
children: display.code
|
|
48
|
+
}) : null]
|
|
49
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
50
|
+
className: "tenx-icon-drawer__glyph",
|
|
51
|
+
children: nodes ? /* @__PURE__ */ jsx(DrawerGlyph, {
|
|
52
|
+
canvas,
|
|
53
|
+
nodes,
|
|
54
|
+
size: 24
|
|
55
|
+
}) : entry ? /* @__PURE__ */ jsx(entry.Icon, {
|
|
56
|
+
name: icon.name,
|
|
57
|
+
size: 24
|
|
58
|
+
}) : null
|
|
59
|
+
})]
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
IconGridCell.displayName = "IconGridCell";
|
|
64
|
+
//#endregion
|
|
65
|
+
export { IconGridCell };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=IconGridCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconGridCell.js","names":[],"sources":["../../../../src/fields/icon/client/IconGridCell.tsx"],"sourcesContent":["'use client'\n\nimport { Tooltip } from '@payloadcms/ui'\nimport React, { useState } from 'react'\nimport type { IconCanvas, IconMeta, IconNode } from '../../../types'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveIconDisplay } from '../shared/iconLabel'\nimport { DrawerGlyph } from './DrawerGlyph'\n\nexport type IconGridCellProps = {\n\t/** Canvas the library's bulk glyphs draw on; absent means the outline default. */\n\tcanvas?: IconCanvas\n\tentry: AdapterComponentsEntry | undefined\n\tfocused: boolean\n\ticon: IconMeta\n\tindex: number\n\tisSelected: boolean\n\t/** Admin language, so a per-locale library label resolves in the cell. */\n\tlanguage: string\n\t/** Bulk glyph data for inline rendering; when absent the cell falls back to the per-icon Icon. */\n\tnodes: IconNode[] | undefined\n\tonSelect: (icon: IconMeta) => void\n\tregisterRef: (index: number, element: HTMLButtonElement | null) => void\n}\n\n/**\n * One square in the icon grid. The name is not rendered in-flow, because that\n * variance broke grid alignment; it lives on the accessible name and a\n * hover/focus tooltip.\n *\n * Those two deliberately differ. The accessible name carries the label alone, so\n * a screen reader browsing a country library announces \"Hungary\" rather than\n * \"Hungary HUN\" 215 times. The tooltip carries the raw name alongside it, because\n * it is the only surface where an editor can discover that \"Hungary\" stores as\n * `HUN`, which they need in order to write frontend code against the value.\n */\nexport const IconGridCell: React.FC<IconGridCellProps> = React.memo(\n\t({ canvas, entry, focused, icon, index, isSelected, language, nodes, onSelect, registerRef }) => {\n\t\tconst [showTooltip, setShowTooltip] = useState(false)\n\t\tconst display = resolveIconDisplay({ language, meta: icon, name: icon.name })\n\t\treturn (\n\t\t\t<div className=\"tenx-icon-drawer__cell\" role=\"presentation\">\n\t\t\t\t<button\n\t\t\t\t\taria-label={display.label}\n\t\t\t\t\taria-selected={isSelected}\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisSelected\n\t\t\t\t\t\t\t? 'tenx-icon-drawer__cell-button tenx-icon-drawer__cell-button--selected'\n\t\t\t\t\t\t\t: 'tenx-icon-drawer__cell-button'\n\t\t\t\t\t}\n\t\t\t\t\tonBlur={() => setShowTooltip(false)}\n\t\t\t\t\tonClick={() => onSelect(icon)}\n\t\t\t\t\tonFocus={() => setShowTooltip(true)}\n\t\t\t\t\tonMouseEnter={() => setShowTooltip(true)}\n\t\t\t\t\tonMouseLeave={() => setShowTooltip(false)}\n\t\t\t\t\tref={(element) => registerRef(index, element)}\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\ttabIndex={focused ? 0 : -1}\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t>\n\t\t\t\t\t<Tooltip show={showTooltip} staticPositioning>\n\t\t\t\t\t\t{display.label}\n\t\t\t\t\t\t{display.code ? (\n\t\t\t\t\t\t\t<span className=\"tenx-icon-drawer__cell-code\">{display.code}</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t<span className=\"tenx-icon-drawer__glyph\">\n\t\t\t\t\t\t{nodes ? (\n\t\t\t\t\t\t\t<DrawerGlyph canvas={canvas} nodes={nodes} size={24} />\n\t\t\t\t\t\t) : entry ? (\n\t\t\t\t\t\t\t<entry.Icon name={icon.name} size={24} />\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t)\n\t}\n)\nIconGridCell.displayName = 'IconGridCell'\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoCA,MAAa,eAA4C,MAAM,MAC7D,EAAE,QAAQ,OAAO,SAAS,MAAM,OAAO,YAAY,UAAU,OAAO,UAAU,kBAAkB;CAChG,MAAM,CAAC,aAAa,kBAAkB,SAAS,KAAK;CACpD,MAAM,UAAU,mBAAmB;EAAE;EAAU,MAAM;EAAM,MAAM,KAAK;CAAK,CAAC;CAC5E,OACC,oBAAC,OAAD;EAAK,WAAU;EAAyB,MAAK;YAC5C,qBAAC,UAAD;GACC,cAAY,QAAQ;GACpB,iBAAe;GACf,WACC,aACG,0EACA;GAEJ,cAAc,eAAe,KAAK;GAClC,eAAe,SAAS,IAAI;GAC5B,eAAe,eAAe,IAAI;GAClC,oBAAoB,eAAe,IAAI;GACvC,oBAAoB,eAAe,KAAK;GACxC,MAAM,YAAY,YAAY,OAAO,OAAO;GAC5C,MAAK;GACL,UAAU,UAAU,IAAI;GACxB,MAAK;aAhBN,CAkBC,qBAAC,SAAD;IAAS,MAAM;IAAa,mBAAA;cAA5B,CACE,QAAQ,OACR,QAAQ,OACR,oBAAC,QAAD;KAAM,WAAU;eAA+B,QAAQ;IAAW,CAAA,IAC/D,IACI;OACT,oBAAC,QAAD;IAAM,WAAU;cACd,QACA,oBAAC,aAAD;KAAqB;KAAe;KAAO,MAAM;IAAK,CAAA,IACnD,QACH,oBAAC,MAAM,MAAP;KAAY,MAAM,KAAK;KAAM,MAAM;IAAK,CAAA,IACrC;GACC,CAAA,CACC;;CACJ,CAAA;AAEP,CACD;AACA,aAAa,cAAc"}
|
|
@@ -453,6 +453,14 @@ html[data-theme="dark"] .tenx-icon-drawer__banner {
|
|
|
453
453
|
height: var(--tenx-icon-cell-size);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
/* Raw icon name beside a library-supplied label: the only place an editor can see that
|
|
457
|
+
"Hungary" stores as HUN. Muted and secondary, and deliberately absent from the
|
|
458
|
+
accessible name so a screen reader announces the label alone. */
|
|
459
|
+
.tenx-icon-drawer__cell-code {
|
|
460
|
+
margin-left: 0.5ch;
|
|
461
|
+
opacity: 0.65;
|
|
462
|
+
}
|
|
463
|
+
|
|
456
464
|
.tenx-icon-drawer__cell-button {
|
|
457
465
|
position: relative;
|
|
458
466
|
display: flex;
|
|
@@ -25,8 +25,8 @@ const EXPORT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
25
25
|
/**
|
|
26
26
|
* The complete set of characters that can escape a single-quoted JS string:
|
|
27
27
|
* the quote, the escape character, and the four line terminators. Specifiers
|
|
28
|
-
* are validated rather than escaped so a bad one fails generation
|
|
29
|
-
* instead of emitting a module that only breaks at import time.
|
|
28
|
+
* and icon names are validated rather than escaped so a bad one fails generation
|
|
29
|
+
* loudly instead of emitting a module that only breaks at import time.
|
|
30
30
|
*/
|
|
31
31
|
const UNSAFE_IN_SPECIFIER = /['\\\n\r\u2028\u2029]/;
|
|
32
32
|
const emitManifestModule = (icons, categories, header = GENERATED_HEADER) => {
|
|
@@ -45,6 +45,7 @@ const emitImportsModule = (icons, importFor, header = GENERATED_HEADER) => {
|
|
|
45
45
|
"const map = {"
|
|
46
46
|
];
|
|
47
47
|
for (const icon of icons) {
|
|
48
|
+
if (UNSAFE_IN_SPECIFIER.test(icon.name)) throw new Error(`unsafe icon name for an emitted key: ${icon.name}`);
|
|
48
49
|
const spec = importFor(icon);
|
|
49
50
|
if (UNSAFE_IN_SPECIFIER.test(spec.module)) throw new Error(`icon "${icon.name}": unsafe module specifier: ${spec.module}`);
|
|
50
51
|
if (spec.exportName !== void 0 && !EXPORT_NAME.test(spec.exportName)) throw new Error(`icon "${icon.name}": export name is not an identifier: ${spec.exportName}`);
|
|
@@ -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 * are validated rather than escaped so a bad one fails generation
|
|
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,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,sBACZ,OACA,YACA,SAAiB,qBACL;CAEZ,OAAO,GAAG,OAAO,2HADJ,KAAK,UAAU;EAAE;EAAO;CAAW,GAAG,MAAM,GACsF,EAAE;AAClJ;AAEA,MAAa,qBACZ,OACA,WACA,SAAiB,qBACL;CACZ,MAAM,QAAkB;EACvB;EACA;EACA;EACA;EACA;EACA;CACD;CACA,KAAK,MAAM,QAAQ,OAAO;EAIz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