@10x-media/fields 0.1.0-beta.0
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 +12 -0
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/exports/client.d.ts +7 -0
- package/dist/exports/client.js +8 -0
- package/dist/exports/color-utils.d.ts +9 -0
- package/dist/exports/color-utils.js +7 -0
- package/dist/exports/color.d.ts +6 -0
- package/dist/exports/color.js +5 -0
- package/dist/exports/encrypted.d.ts +12 -0
- package/dist/exports/encrypted.js +10 -0
- package/dist/exports/i18n.d.ts +3 -0
- package/dist/exports/i18n.js +3 -0
- package/dist/exports/icon-adapters/lucide.d.ts +5 -0
- package/dist/exports/icon-adapters/lucide.js +4 -0
- package/dist/exports/icon-adapters/radix.d.ts +5 -0
- package/dist/exports/icon-adapters/radix.js +4 -0
- package/dist/exports/icon-adapters/tabler.d.ts +5 -0
- package/dist/exports/icon-adapters/tabler.js +4 -0
- package/dist/exports/icon-codegen.d.ts +4 -0
- package/dist/exports/icon-codegen.js +2 -0
- package/dist/exports/icon-react.d.ts +4 -0
- package/dist/exports/icon-react.js +3 -0
- package/dist/exports/icon.d.ts +8 -0
- package/dist/exports/icon.js +7 -0
- package/dist/exports/rsc.d.ts +10 -0
- package/dist/exports/rsc.js +9 -0
- package/dist/exports/types.d.ts +4 -0
- package/dist/exports/types.js +1 -0
- package/dist/fields/color/client/ColorField.d.ts +13 -0
- package/dist/fields/color/client/ColorField.js +321 -0
- package/dist/fields/color/client/ColorField.js.map +1 -0
- package/dist/fields/color/client/ColorPickerPanel.d.ts +29 -0
- package/dist/fields/color/client/ColorPickerPanel.js +233 -0
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -0
- package/dist/fields/color/client/colorField.css +411 -0
- package/dist/fields/color/client/icons.js +38 -0
- package/dist/fields/color/client/icons.js.map +1 -0
- package/dist/fields/color/colorField.d.ts +20 -0
- package/dist/fields/color/colorField.js +102 -0
- package/dist/fields/color/colorField.js.map +1 -0
- package/dist/fields/color/commitValue.js +29 -0
- package/dist/fields/color/commitValue.js.map +1 -0
- package/dist/fields/color/engine/contrast.d.ts +10 -0
- package/dist/fields/color/engine/contrast.js +25 -0
- package/dist/fields/color/engine/contrast.js.map +1 -0
- package/dist/fields/color/engine/convert.d.ts +28 -0
- package/dist/fields/color/engine/convert.js +232 -0
- package/dist/fields/color/engine/convert.js.map +1 -0
- package/dist/fields/color/engine/format.d.ts +15 -0
- package/dist/fields/color/engine/format.js +53 -0
- package/dist/fields/color/engine/format.js.map +1 -0
- package/dist/fields/color/engine/index.d.ts +8 -0
- package/dist/fields/color/engine/namedColors.d.ts +9 -0
- package/dist/fields/color/engine/namedColors.js +159 -0
- package/dist/fields/color/engine/namedColors.js.map +1 -0
- package/dist/fields/color/engine/parse.d.ts +12 -0
- package/dist/fields/color/engine/parse.js +151 -0
- package/dist/fields/color/engine/parse.js.map +1 -0
- package/dist/fields/color/engine/salvage.d.ts +13 -0
- package/dist/fields/color/engine/salvage.js +75 -0
- package/dist/fields/color/engine/salvage.js.map +1 -0
- package/dist/fields/color/engine/types.d.ts +34 -0
- package/dist/fields/color/options.d.ts +55 -0
- package/dist/fields/color/options.js +8 -0
- package/dist/fields/color/options.js.map +1 -0
- package/dist/fields/color/presetChip.js +27 -0
- package/dist/fields/color/presetChip.js.map +1 -0
- package/dist/fields/color/presetsFromDoc.d.ts +27 -0
- package/dist/fields/color/presetsFromDoc.js +74 -0
- package/dist/fields/color/presetsFromDoc.js.map +1 -0
- package/dist/fields/color/resolveFormat.js +16 -0
- package/dist/fields/color/resolveFormat.js.map +1 -0
- package/dist/fields/color/resolvePresets.d.ts +29 -0
- package/dist/fields/color/resolvePresets.js +39 -0
- package/dist/fields/color/resolvePresets.js.map +1 -0
- package/dist/fields/color/server/ColorCell.d.ts +6 -0
- package/dist/fields/color/server/ColorCell.js +34 -0
- package/dist/fields/color/server/ColorCell.js.map +1 -0
- package/dist/fields/color/server/ColorFieldServer.d.ts +18 -0
- package/dist/fields/color/server/ColorFieldServer.js +69 -0
- package/dist/fields/color/server/ColorFieldServer.js.map +1 -0
- package/dist/fields/color/server/colorCell.css +32 -0
- package/dist/fields/encrypted/boot.d.ts +14 -0
- package/dist/fields/encrypted/boot.js +22 -0
- package/dist/fields/encrypted/boot.js.map +1 -0
- package/dist/fields/encrypted/components/EncryptedInput.js +89 -0
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -0
- package/dist/fields/encrypted/components/EncryptedTextarea.js +86 -0
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -0
- package/dist/fields/encrypted/components/EyeToggle.js +51 -0
- package/dist/fields/encrypted/components/EyeToggle.js.map +1 -0
- package/dist/fields/encrypted/components/MaskDots.js +20 -0
- package/dist/fields/encrypted/components/MaskDots.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +19 -0
- package/dist/fields/encrypted/components/ProtectedCell.js +44 -0
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedField.css +180 -0
- package/dist/fields/encrypted/components/ProtectedField.d.ts +30 -0
- package/dist/fields/encrypted/components/ProtectedField.js +95 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedRichText.d.ts +21 -0
- package/dist/fields/encrypted/components/ProtectedRichText.js +35 -0
- package/dist/fields/encrypted/components/ProtectedRichText.js.map +1 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.d.ts +24 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.js +87 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -0
- package/dist/fields/encrypted/components/StructuralField.js +64 -0
- package/dist/fields/encrypted/components/StructuralField.js.map +1 -0
- package/dist/fields/encrypted/components/facsimiles.js +219 -0
- package/dist/fields/encrypted/components/facsimiles.js.map +1 -0
- package/dist/fields/encrypted/components/placement.js +21 -0
- package/dist/fields/encrypted/components/placement.js.map +1 -0
- package/dist/fields/encrypted/crypto/aad.js +29 -0
- package/dist/fields/encrypted/crypto/aad.js.map +1 -0
- package/dist/fields/encrypted/crypto/bidx.js +26 -0
- package/dist/fields/encrypted/crypto/bidx.js.map +1 -0
- package/dist/fields/encrypted/crypto/keys.d.ts +31 -0
- package/dist/fields/encrypted/crypto/keys.js +113 -0
- package/dist/fields/encrypted/crypto/keys.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +23 -0
- package/dist/fields/encrypted/crypto/wire.js +135 -0
- package/dist/fields/encrypted/crypto/wire.js.map +1 -0
- package/dist/fields/encrypted/encryptedField.d.ts +15 -0
- package/dist/fields/encrypted/encryptedField.js +187 -0
- package/dist/fields/encrypted/encryptedField.js.map +1 -0
- package/dist/fields/encrypted/hooks.d.ts +21 -0
- package/dist/fields/encrypted/hooks.js +326 -0
- package/dist/fields/encrypted/hooks.js.map +1 -0
- package/dist/fields/encrypted/maskDots.js +16 -0
- package/dist/fields/encrypted/maskDots.js.map +1 -0
- package/dist/fields/encrypted/plaintextStash.js +57 -0
- package/dist/fields/encrypted/plaintextStash.js.map +1 -0
- package/dist/fields/encrypted/queryRewrite.d.ts +12 -0
- package/dist/fields/encrypted/queryRewrite.js +134 -0
- package/dist/fields/encrypted/queryRewrite.js.map +1 -0
- package/dist/fields/encrypted/scan.js +36 -0
- package/dist/fields/encrypted/scan.js.map +1 -0
- package/dist/fields/encrypted/types.d.ts +35 -0
- package/dist/fields/encrypted/types.js +12 -0
- package/dist/fields/encrypted/types.js.map +1 -0
- package/dist/fields/encrypted/typescriptSchema.js +41 -0
- package/dist/fields/encrypted/typescriptSchema.js.map +1 -0
- package/dist/fields/encrypted/utils/decryptAllData.d.ts +17 -0
- package/dist/fields/encrypted/utils/decryptAllData.js +98 -0
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -0
- package/dist/fields/encrypted/utils/encryptExistingData.d.ts +14 -0
- package/dist/fields/encrypted/utils/encryptExistingData.js +72 -0
- package/dist/fields/encrypted/utils/encryptExistingData.js.map +1 -0
- package/dist/fields/encrypted/utils/pageThrough.js +42 -0
- package/dist/fields/encrypted/utils/pageThrough.js.map +1 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.d.ts +27 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.js +92 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.js.map +1 -0
- package/dist/fields/encrypted/validators.js +111 -0
- package/dist/fields/encrypted/validators.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/lucide/adapter.js +15 -0
- package/dist/fields/icon/adapters/lucide/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/client.d.ts +10 -0
- package/dist/fields/icon/adapters/lucide/client.js +41 -0
- package/dist/fields/icon/adapters/lucide/client.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js +23338 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/nodes.js +14296 -0
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/lucide/renderer.js +13 -0
- package/dist/fields/icon/adapters/lucide/renderer.js.map +1 -0
- package/dist/fields/icon/adapters/radix/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/radix/adapter.js +14 -0
- package/dist/fields/icon/adapters/radix/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/radix/client.d.ts +8 -0
- package/dist/fields/icon/adapters/radix/client.js +20 -0
- package/dist/fields/icon/adapters/radix/client.js.map +1 -0
- package/dist/fields/icon/adapters/radix/generated/imports.js +324 -0
- package/dist/fields/icon/adapters/radix/generated/imports.js.map +1 -0
- package/dist/fields/icon/adapters/radix/generated/manifest.js +1805 -0
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/radix/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/radix/renderer.js +23 -0
- package/dist/fields/icon/adapters/radix/renderer.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/tabler/adapter.js +15 -0
- package/dist/fields/icon/adapters/tabler/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/client.d.ts +9 -0
- package/dist/fields/icon/adapters/tabler/client.js +18 -0
- package/dist/fields/icon/adapters/tabler/client.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/imports.js +4942 -0
- package/dist/fields/icon/adapters/tabler/generated/imports.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js +61269 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/nodes.js +26749 -0
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/tabler/renderer.js +13 -0
- package/dist/fields/icon/adapters/tabler/renderer.js.map +1 -0
- package/dist/fields/icon/client/DrawerGlyph.js +32 -0
- package/dist/fields/icon/client/DrawerGlyph.js.map +1 -0
- package/dist/fields/icon/client/IconDrawerContent.js +294 -0
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -0
- package/dist/fields/icon/client/IconFieldClient.d.ts +19 -0
- package/dist/fields/icon/client/IconFieldClient.js +245 -0
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -0
- package/dist/fields/icon/client/IconLibrarySelect.d.ts +14 -0
- package/dist/fields/icon/client/IconLibrarySelect.js +36 -0
- package/dist/fields/icon/client/IconLibrarySelect.js.map +1 -0
- package/dist/fields/icon/client/availableLibraries.js +25 -0
- package/dist/fields/icon/client/availableLibraries.js.map +1 -0
- package/dist/fields/icon/client/generatedAdapter.js +88 -0
- package/dist/fields/icon/client/generatedAdapter.js.map +1 -0
- package/dist/fields/icon/client/icon-field.css +524 -0
- package/dist/fields/icon/client/useRecentIcons.js +32 -0
- package/dist/fields/icon/client/useRecentIcons.js.map +1 -0
- package/dist/fields/icon/codegen/emit.js +81 -0
- package/dist/fields/icon/codegen/emit.js.map +1 -0
- package/dist/fields/icon/codegen/generate.d.ts +10 -0
- package/dist/fields/icon/codegen/generate.js +59 -0
- package/dist/fields/icon/codegen/generate.js.map +1 -0
- package/dist/fields/icon/codegen/sources/lucide.js +52 -0
- package/dist/fields/icon/codegen/sources/lucide.js.map +1 -0
- package/dist/fields/icon/codegen/sources/radix.js +33 -0
- package/dist/fields/icon/codegen/sources/radix.js.map +1 -0
- package/dist/fields/icon/codegen/sources/tabler.js +31 -0
- package/dist/fields/icon/codegen/sources/tabler.js.map +1 -0
- package/dist/fields/icon/codegen/types.d.ts +36 -0
- package/dist/fields/icon/defineIconAdapter.d.ts +8 -0
- package/dist/fields/icon/defineIconAdapter.js +10 -0
- package/dist/fields/icon/defineIconAdapter.js.map +1 -0
- package/dist/fields/icon/plugin.js +55 -0
- package/dist/fields/icon/plugin.js.map +1 -0
- package/dist/fields/icon/react/createIcon.d.ts +15 -0
- package/dist/fields/icon/react/createIcon.js +47 -0
- package/dist/fields/icon/react/createIcon.js.map +1 -0
- package/dist/fields/icon/react/createRscIcon.d.ts +12 -0
- package/dist/fields/icon/react/createRscIcon.js +27 -0
- package/dist/fields/icon/react/createRscIcon.js.map +1 -0
- package/dist/fields/icon/react/types.d.ts +24 -0
- package/dist/fields/icon/rsc/IconCell.d.ts +14 -0
- package/dist/fields/icon/rsc/IconCell.js +32 -0
- package/dist/fields/icon/rsc/IconCell.js.map +1 -0
- package/dist/fields/icon/rsc/IconFieldServer.d.ts +24 -0
- package/dist/fields/icon/rsc/IconFieldServer.js +74 -0
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.d.ts +13 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +24 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -0
- package/dist/fields/icon/rsc/resolveStaticLabel.js +16 -0
- package/dist/fields/icon/rsc/resolveStaticLabel.js.map +1 -0
- package/dist/fields/icon/server/availability.d.ts +32 -0
- package/dist/fields/icon/server/availability.js +58 -0
- package/dist/fields/icon/server/availability.js.map +1 -0
- package/dist/fields/icon/server/iconField.d.ts +32 -0
- package/dist/fields/icon/server/iconField.js +48 -0
- package/dist/fields/icon/server/iconField.js.map +1 -0
- package/dist/fields/icon/server/iconLibraryField.d.ts +23 -0
- package/dist/fields/icon/server/iconLibraryField.js +50 -0
- package/dist/fields/icon/server/iconLibraryField.js.map +1 -0
- package/dist/fields/icon/server/libraryOptions.d.ts +12 -0
- package/dist/fields/icon/server/libraryOptions.js +13 -0
- package/dist/fields/icon/server/libraryOptions.js.map +1 -0
- package/dist/fields/icon/server/manifestCache.js +17 -0
- package/dist/fields/icon/server/manifestCache.js.map +1 -0
- package/dist/fields/icon/server/validate.js +37 -0
- package/dist/fields/icon/server/validate.js.map +1 -0
- package/dist/fields/icon/shared/adapterComponents.d.ts +23 -0
- package/dist/fields/icon/shared/formatIconLabel.js +16 -0
- package/dist/fields/icon/shared/formatIconLabel.js.map +1 -0
- package/dist/fields/icon/shared/search.js +58 -0
- package/dist/fields/icon/shared/search.js.map +1 -0
- package/dist/fields/icon/shared/value.d.ts +16 -0
- package/dist/fields/icon/shared/value.js +27 -0
- package/dist/fields/icon/shared/value.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/plugin/registry.d.ts +9 -0
- package/dist/plugin/registry.js +14 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/translations/de.js +49 -0
- package/dist/translations/de.js.map +1 -0
- package/dist/translations/en.js +49 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +15 -0
- package/dist/translations/index.js +30 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +48 -0
- package/dist/translations/keys.js +48 -0
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/server.js +13 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/utils/memoForRequest.js +25 -0
- package/dist/utils/memoForRequest.js.map +1 -0
- package/package.json +196 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
+
import { IconField } from "../client/IconFieldClient.js";
|
|
3
|
+
import { resolveAvailableLibraries, unionAlwaysAvailable } from "../server/availability.js";
|
|
4
|
+
import { resolveStaticLabel } from "./resolveStaticLabel.js";
|
|
5
|
+
import { getFromImportMap } from "payload/shared";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/fields/icon/rsc/IconFieldServer.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Resolves adapters (inline beats registry), availability (memoized per request,
|
|
10
|
+
* fails open), and adapter client components from the importMap, then renders the
|
|
11
|
+
* client field with those component references as props. A missing importMap entry
|
|
12
|
+
* degrades to no glyph for that library rather than throwing, so the edit view
|
|
13
|
+
* never 500s over a mis-registered adapter.
|
|
14
|
+
*/
|
|
15
|
+
const IconFieldServer = async (props) => {
|
|
16
|
+
const { clientField, data, i18n, path, payload, permissions, readOnly, req, schemaPath, siblingData } = props;
|
|
17
|
+
const registryIcon = getFieldsRegistry(payload.config)?.icon;
|
|
18
|
+
const adapters = props.adapters ?? registryIcon?.adapters ?? [];
|
|
19
|
+
const defaultLibrary = props.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? "";
|
|
20
|
+
const resolver = props.resolveAvailable ?? registryIcon?.resolveAvailable;
|
|
21
|
+
const available = await resolveAvailableLibraries({
|
|
22
|
+
adapters,
|
|
23
|
+
alwaysAvailable: unionAlwaysAvailable(props.alwaysAvailable, registryIcon?.alwaysAvailable),
|
|
24
|
+
data,
|
|
25
|
+
req,
|
|
26
|
+
resolver,
|
|
27
|
+
siblingData
|
|
28
|
+
});
|
|
29
|
+
const adapterComponents = {};
|
|
30
|
+
for (const adapter of adapters) {
|
|
31
|
+
const Icon = getFromImportMap({
|
|
32
|
+
importMap: payload.importMap,
|
|
33
|
+
PayloadComponent: adapter.Icon,
|
|
34
|
+
schemaPath: `${schemaPath ?? path}.icon-adapter`,
|
|
35
|
+
silent: true
|
|
36
|
+
});
|
|
37
|
+
const Assets = getFromImportMap({
|
|
38
|
+
importMap: payload.importMap,
|
|
39
|
+
PayloadComponent: adapter.Assets,
|
|
40
|
+
schemaPath: `${schemaPath ?? path}.icon-adapter`,
|
|
41
|
+
silent: true
|
|
42
|
+
});
|
|
43
|
+
const Nodes = adapter.Nodes ? getFromImportMap({
|
|
44
|
+
importMap: payload.importMap,
|
|
45
|
+
PayloadComponent: adapter.Nodes,
|
|
46
|
+
schemaPath: `${schemaPath ?? path}.icon-adapter`,
|
|
47
|
+
silent: true
|
|
48
|
+
}) : void 0;
|
|
49
|
+
if (Icon && Assets) adapterComponents[adapter.slug] = {
|
|
50
|
+
Assets,
|
|
51
|
+
Icon,
|
|
52
|
+
Nodes
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ jsx(IconField, {
|
|
56
|
+
adapterComponents,
|
|
57
|
+
adapters: adapters.map((adapter) => ({
|
|
58
|
+
label: resolveStaticLabel(adapter.label, i18n.language) ?? adapter.slug,
|
|
59
|
+
slug: adapter.slug
|
|
60
|
+
})),
|
|
61
|
+
available,
|
|
62
|
+
defaultLibrary,
|
|
63
|
+
field: clientField,
|
|
64
|
+
path,
|
|
65
|
+
permissions,
|
|
66
|
+
readOnly,
|
|
67
|
+
schemaPath,
|
|
68
|
+
showTextInput: props.showTextInput === true
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { IconFieldServer };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=IconFieldServer.js.map
|
|
@@ -0,0 +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 './resolveStaticLabel'\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) adapterComponents[adapter.slug] = { Assets, Icon, Nodes }\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\tshowTextInput={props.showTextInput === true}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,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,QAAQ,kBAAkB,QAAQ,QAAQ;GAAE;GAAQ;GAAM;EAAM;CAC7E;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;EACZ,eAAe,MAAM,kBAAkB;CACvC,CAAA;AAEH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IconAdapter } from "../../../types.js";
|
|
2
|
+
import { TextFieldServerProps } from "payload";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/fields/icon/rsc/IconLibrarySelectServer.d.ts
|
|
6
|
+
type ServerProps = {
|
|
7
|
+
adapters?: IconAdapter[];
|
|
8
|
+
} & TextFieldServerProps;
|
|
9
|
+
/** Resolves selectable library options (inline beats registry) and renders the client select. */
|
|
10
|
+
declare const IconLibrarySelectServer: (props: ServerProps) => ReactNode;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { IconLibrarySelectServer };
|
|
13
|
+
//# sourceMappingURL=IconLibrarySelectServer.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IconLibrarySelect } from "../client/IconLibrarySelect.js";
|
|
2
|
+
import { resolveStaticLabel } from "./resolveStaticLabel.js";
|
|
3
|
+
import { getIconLibraryOptions } from "../server/libraryOptions.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/fields/icon/rsc/IconLibrarySelectServer.tsx
|
|
6
|
+
/** Resolves selectable library options (inline beats registry) and renders the client select. */
|
|
7
|
+
const IconLibrarySelectServer = (props) => {
|
|
8
|
+
const { clientField, i18n, path, payload, permissions, readOnly, schemaPath } = props;
|
|
9
|
+
return /* @__PURE__ */ jsx(IconLibrarySelect, {
|
|
10
|
+
field: clientField,
|
|
11
|
+
options: getIconLibraryOptions(payload.config, props.adapters).map((option) => ({
|
|
12
|
+
label: resolveStaticLabel(option.label, i18n.language) ?? option.value,
|
|
13
|
+
value: option.value
|
|
14
|
+
})),
|
|
15
|
+
path,
|
|
16
|
+
permissions,
|
|
17
|
+
readOnly,
|
|
18
|
+
schemaPath
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { IconLibrarySelectServer };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=IconLibrarySelectServer.js.map
|
|
@@ -0,0 +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 './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,16 @@
|
|
|
1
|
+
//#region src/fields/icon/rsc/resolveStaticLabel.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a StaticLabel to a plain string for the requested language. Adapter
|
|
4
|
+
* and library-option labels reach the client as strings, so they must be
|
|
5
|
+
* flattened server-side. Done here rather than via `@payloadcms/translations`
|
|
6
|
+
* because this package does not depend on it (same reason colorField resolves
|
|
7
|
+
* its own labels).
|
|
8
|
+
*/
|
|
9
|
+
const resolveStaticLabel = (label, language) => {
|
|
10
|
+
if (label === void 0 || typeof label === "string") return label;
|
|
11
|
+
return label[language] ?? label.en ?? Object.values(label)[0];
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { resolveStaticLabel };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=resolveStaticLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveStaticLabel.js","names":[],"sources":["../../../../src/fields/icon/rsc/resolveStaticLabel.ts"],"sourcesContent":["import type { StaticLabel } from 'payload'\n\n/**\n * Resolves a StaticLabel to a plain string for the requested language. Adapter\n * and library-option labels reach the client as strings, so they must be\n * flattened server-side. Done here rather than via `@payloadcms/translations`\n * because this package does not depend on it (same reason colorField resolves\n * its own labels).\n */\nexport const resolveStaticLabel = (\n\tlabel: StaticLabel | undefined,\n\tlanguage: string\n): string | undefined => {\n\tif (label === undefined || typeof label === 'string') return label\n\treturn label[language] ?? label.en ?? Object.values(label)[0]\n}\n"],"mappings":";;;;;;;;AASA,MAAa,sBACZ,OACA,aACwB;CACxB,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAU,OAAO;CAC7D,OAAO,MAAM,aAAa,MAAM,MAAM,OAAO,OAAO,KAAK,EAAE;AAC5D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IconAdapter, IconAvailabilityResolver } from "../../../types.js";
|
|
2
|
+
import { PayloadRequest } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/server/availability.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Availability restricts SELECTION only; rendering stored values always works
|
|
7
|
+
* through any registered adapter. Memoized per request per resolver, which is
|
|
8
|
+
* safe because Field server components render one document per request.
|
|
9
|
+
*
|
|
10
|
+
* Fails open: a throwing resolver (e.g. a tenant lookup that errors) degrades to
|
|
11
|
+
* all registered libraries and logs once, so it never 500s the edit view.
|
|
12
|
+
* Availability gates selection, not data access, so all-registered is safe. The
|
|
13
|
+
* catch lives inside the memo callback, so the rejection is never cached and a
|
|
14
|
+
* later request retries.
|
|
15
|
+
*
|
|
16
|
+
* `alwaysAvailable` slugs stay selectable regardless of the resolver, unioned in
|
|
17
|
+
* after the memo so fields sharing a resolver can still force different libraries.
|
|
18
|
+
* The final registered-adapter filter both preserves adapter registration order
|
|
19
|
+
* and silently drops any forced slug with no registered adapter.
|
|
20
|
+
*/
|
|
21
|
+
declare const resolveAvailableLibraries: (args: {
|
|
22
|
+
adapters: IconAdapter[]; /** Library slugs always offered for selection, even when the resolver omits them. */
|
|
23
|
+
alwaysAvailable?: string[];
|
|
24
|
+
data?: Record<string, unknown>; /** Field identifier for the failure log, e.g. `${collectionSlug}.${fieldName}`. */
|
|
25
|
+
fieldPath?: string;
|
|
26
|
+
req: PayloadRequest;
|
|
27
|
+
resolver?: IconAvailabilityResolver;
|
|
28
|
+
siblingData?: Record<string, unknown>;
|
|
29
|
+
}) => Promise<string[]>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { resolveAvailableLibraries };
|
|
32
|
+
//# sourceMappingURL=availability.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { memoForRequest } from "../../../utils/memoForRequest.js";
|
|
2
|
+
//#region src/fields/icon/server/availability.ts
|
|
3
|
+
const memoKeys = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
const keyFor = (resolver) => {
|
|
5
|
+
let key = memoKeys.get(resolver);
|
|
6
|
+
if (!key) {
|
|
7
|
+
key = Symbol("fields:icon-availability");
|
|
8
|
+
memoKeys.set(resolver, key);
|
|
9
|
+
}
|
|
10
|
+
return key;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Merge rule for forced libraries: UNION. A per-field `alwaysAvailable` ADDS to
|
|
14
|
+
* the global one rather than replacing it, because forcing a library is additive
|
|
15
|
+
* (a field-level forced brand set should not erase a plugin-wide one, and vice
|
|
16
|
+
* versa). This differs from `resolveAvailable`, which replaces because a resolver
|
|
17
|
+
* is a single decision function where one must win.
|
|
18
|
+
*/
|
|
19
|
+
const unionAlwaysAvailable = (perField, global) => [...new Set([...perField ?? [], ...global ?? []])];
|
|
20
|
+
/**
|
|
21
|
+
* Availability restricts SELECTION only; rendering stored values always works
|
|
22
|
+
* through any registered adapter. Memoized per request per resolver, which is
|
|
23
|
+
* safe because Field server components render one document per request.
|
|
24
|
+
*
|
|
25
|
+
* Fails open: a throwing resolver (e.g. a tenant lookup that errors) degrades to
|
|
26
|
+
* all registered libraries and logs once, so it never 500s the edit view.
|
|
27
|
+
* Availability gates selection, not data access, so all-registered is safe. The
|
|
28
|
+
* catch lives inside the memo callback, so the rejection is never cached and a
|
|
29
|
+
* later request retries.
|
|
30
|
+
*
|
|
31
|
+
* `alwaysAvailable` slugs stay selectable regardless of the resolver, unioned in
|
|
32
|
+
* after the memo so fields sharing a resolver can still force different libraries.
|
|
33
|
+
* The final registered-adapter filter both preserves adapter registration order
|
|
34
|
+
* and silently drops any forced slug with no registered adapter.
|
|
35
|
+
*/
|
|
36
|
+
const resolveAvailableLibraries = async (args) => {
|
|
37
|
+
const allSlugs = () => args.adapters.map((adapter) => adapter.slug);
|
|
38
|
+
const resolver = args.resolver;
|
|
39
|
+
if (!resolver) return allSlugs();
|
|
40
|
+
const resolved = await memoForRequest(args.req, keyFor(resolver), async () => {
|
|
41
|
+
try {
|
|
42
|
+
return await resolver({
|
|
43
|
+
data: args.data,
|
|
44
|
+
req: args.req,
|
|
45
|
+
siblingData: args.siblingData
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
args.req.payload.logger.error({ err: error }, `[fields] icon availability resolver failed${args.fieldPath ? ` for ${args.fieldPath}` : ""}; allowing all registered libraries`);
|
|
49
|
+
return allSlugs();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const allowed = new Set([...args.alwaysAvailable ?? [], ...resolved]);
|
|
53
|
+
return args.adapters.filter((adapter) => allowed.has(adapter.slug)).map((adapter) => adapter.slug);
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { resolveAvailableLibraries, unionAlwaysAvailable };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=availability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availability.js","names":[],"sources":["../../../../src/fields/icon/server/availability.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { memoForRequest } from '../../../utils/memoForRequest'\n\nconst memoKeys = new WeakMap<IconAvailabilityResolver, symbol>()\n\nconst keyFor = (resolver: IconAvailabilityResolver): symbol => {\n\tlet key = memoKeys.get(resolver)\n\tif (!key) {\n\t\tkey = Symbol('fields:icon-availability')\n\t\tmemoKeys.set(resolver, key)\n\t}\n\treturn key\n}\n\n/**\n * Merge rule for forced libraries: UNION. A per-field `alwaysAvailable` ADDS to\n * the global one rather than replacing it, because forcing a library is additive\n * (a field-level forced brand set should not erase a plugin-wide one, and vice\n * versa). This differs from `resolveAvailable`, which replaces because a resolver\n * is a single decision function where one must win.\n */\nexport const unionAlwaysAvailable = (\n\tperField: string[] | undefined,\n\tglobal: string[] | undefined\n): string[] => [...new Set([...(perField ?? []), ...(global ?? [])])]\n\n/**\n * Availability restricts SELECTION only; rendering stored values always works\n * through any registered adapter. Memoized per request per resolver, which is\n * safe because Field server components render one document per request.\n *\n * Fails open: a throwing resolver (e.g. a tenant lookup that errors) degrades to\n * all registered libraries and logs once, so it never 500s the edit view.\n * Availability gates selection, not data access, so all-registered is safe. The\n * catch lives inside the memo callback, so the rejection is never cached and a\n * later request retries.\n *\n * `alwaysAvailable` slugs stay selectable regardless of the resolver, unioned in\n * after the memo so fields sharing a resolver can still force different libraries.\n * The final registered-adapter filter both preserves adapter registration order\n * and silently drops any forced slug with no registered adapter.\n */\nexport const resolveAvailableLibraries = async (args: {\n\tadapters: IconAdapter[]\n\t/** Library slugs always offered for selection, even when the resolver omits them. */\n\talwaysAvailable?: string[]\n\tdata?: Record<string, unknown>\n\t/** Field identifier for the failure log, e.g. `${collectionSlug}.${fieldName}`. */\n\tfieldPath?: string\n\treq: PayloadRequest\n\tresolver?: IconAvailabilityResolver\n\tsiblingData?: Record<string, unknown>\n}): Promise<string[]> => {\n\tconst allSlugs = (): string[] => args.adapters.map((adapter) => adapter.slug)\n\tconst resolver = args.resolver\n\tif (!resolver) {\n\t\treturn allSlugs()\n\t}\n\tconst resolved = await memoForRequest(args.req, keyFor(resolver), async () => {\n\t\ttry {\n\t\t\treturn await resolver({ data: args.data, req: args.req, siblingData: args.siblingData })\n\t\t} catch (error) {\n\t\t\targs.req.payload.logger.error(\n\t\t\t\t{ err: error },\n\t\t\t\t`[fields] icon availability resolver failed${args.fieldPath ? ` for ${args.fieldPath}` : ''}; allowing all registered libraries`\n\t\t\t)\n\t\t\treturn allSlugs()\n\t\t}\n\t})\n\tconst allowed = new Set([...(args.alwaysAvailable ?? []), ...resolved])\n\treturn args.adapters.filter((adapter) => allowed.has(adapter.slug)).map((adapter) => adapter.slug)\n}\n"],"mappings":";;AAIA,MAAM,2BAAW,IAAI,QAA0C;AAE/D,MAAM,UAAU,aAA+C;CAC9D,IAAI,MAAM,SAAS,IAAI,QAAQ;CAC/B,IAAI,CAAC,KAAK;EACT,MAAM,OAAO,0BAA0B;EACvC,SAAS,IAAI,UAAU,GAAG;CAC3B;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,wBACZ,UACA,WACc,CAAC,GAAG,IAAI,IAAI,CAAC,GAAI,YAAY,CAAC,GAAI,GAAI,UAAU,CAAC,CAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;AAkBpE,MAAa,4BAA4B,OAAO,SAUvB;CACxB,MAAM,iBAA2B,KAAK,SAAS,KAAK,YAAY,QAAQ,IAAI;CAC5E,MAAM,WAAW,KAAK;CACtB,IAAI,CAAC,UACJ,OAAO,SAAS;CAEjB,MAAM,WAAW,MAAM,eAAe,KAAK,KAAK,OAAO,QAAQ,GAAG,YAAY;EAC7E,IAAI;GACH,OAAO,MAAM,SAAS;IAAE,MAAM,KAAK;IAAM,KAAK,KAAK;IAAK,aAAa,KAAK;GAAY,CAAC;EACxF,SAAS,OAAO;GACf,KAAK,IAAI,QAAQ,OAAO,MACvB,EAAE,KAAK,MAAM,GACb,6CAA6C,KAAK,YAAY,QAAQ,KAAK,cAAc,GAAG,oCAC7F;GACA,OAAO,SAAS;EACjB;CACD,CAAC;CACD,MAAM,UAAU,IAAI,IAAI,CAAC,GAAI,KAAK,mBAAmB,CAAC,GAAI,GAAG,QAAQ,CAAC;CACtE,OAAO,KAAK,SAAS,QAAQ,YAAY,QAAQ,IAAI,QAAQ,IAAI,CAAC,EAAE,KAAK,YAAY,QAAQ,IAAI;AAClG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IconAdapter, IconAvailabilityResolver } from "../../../types.js";
|
|
2
|
+
import { TextField } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/server/iconField.d.ts
|
|
5
|
+
type IconFieldOptions = {
|
|
6
|
+
name?: string;
|
|
7
|
+
label?: TextField['label'];
|
|
8
|
+
required?: boolean;
|
|
9
|
+
localized?: boolean; /** Inline adapters; omit to use the plugin-registered set at runtime. */
|
|
10
|
+
adapters?: IconAdapter[];
|
|
11
|
+
defaultLibrary?: string; /** Restricts selection only; stored values keep rendering through any registered adapter. */
|
|
12
|
+
resolveAvailable?: IconAvailabilityResolver;
|
|
13
|
+
/**
|
|
14
|
+
* Library slugs always offered for selection regardless of `resolveAvailable`.
|
|
15
|
+
* Unions with the plugin's global `alwaysAvailable`; unregistered slugs drop.
|
|
16
|
+
*/
|
|
17
|
+
alwaysAvailable?: string[]; /** Show a free-text input next to the trigger for typing `library:icon-name` directly. Default false. */
|
|
18
|
+
showTextInput?: boolean;
|
|
19
|
+
overrides?: (args: {
|
|
20
|
+
field: TextField;
|
|
21
|
+
}) => TextField;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Text-backed icon field storing `<library>:<icon-name>`. Bare legacy names read
|
|
25
|
+
* as the default library. Without the plugin, pass `adapters` inline; the admin
|
|
26
|
+
* then also needs the adapters' components in `admin.dependencies` to render
|
|
27
|
+
* glyphs (the plugin writes those itself).
|
|
28
|
+
*/
|
|
29
|
+
declare const iconField: (options?: IconFieldOptions) => TextField;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { IconFieldOptions, iconField };
|
|
32
|
+
//# sourceMappingURL=iconField.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { keys } from "../../../translations/keys.js";
|
|
2
|
+
import { labelForKey } from "../../../translations/server.js";
|
|
3
|
+
import { createIconValidate } from "./validate.js";
|
|
4
|
+
//#region src/fields/icon/server/iconField.ts
|
|
5
|
+
/**
|
|
6
|
+
* Text-backed icon field storing `<library>:<icon-name>`. Bare legacy names read
|
|
7
|
+
* as the default library. Without the plugin, pass `adapters` inline; the admin
|
|
8
|
+
* then also needs the adapters' components in `admin.dependencies` to render
|
|
9
|
+
* glyphs (the plugin writes those itself).
|
|
10
|
+
*/
|
|
11
|
+
const iconField = (options = {}) => {
|
|
12
|
+
const field = {
|
|
13
|
+
name: options.name ?? "icon",
|
|
14
|
+
type: "text",
|
|
15
|
+
label: options.label ?? labelForKey(keys.fieldIconLabel),
|
|
16
|
+
...options.localized === true ? { localized: true } : {},
|
|
17
|
+
...options.required === true ? { required: true } : {},
|
|
18
|
+
validate: createIconValidate({
|
|
19
|
+
adapters: options.adapters,
|
|
20
|
+
defaultLibrary: options.defaultLibrary,
|
|
21
|
+
required: options.required === true
|
|
22
|
+
}),
|
|
23
|
+
admin: { components: {
|
|
24
|
+
Cell: {
|
|
25
|
+
path: "@10x-media/fields/rsc#IconCell",
|
|
26
|
+
serverProps: {
|
|
27
|
+
adapters: options.adapters,
|
|
28
|
+
defaultLibrary: options.defaultLibrary
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
Field: {
|
|
32
|
+
path: "@10x-media/fields/rsc#IconFieldServer",
|
|
33
|
+
serverProps: {
|
|
34
|
+
adapters: options.adapters,
|
|
35
|
+
alwaysAvailable: options.alwaysAvailable,
|
|
36
|
+
defaultLibrary: options.defaultLibrary,
|
|
37
|
+
resolveAvailable: options.resolveAvailable,
|
|
38
|
+
showTextInput: options.showTextInput === true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} }
|
|
42
|
+
};
|
|
43
|
+
return options.overrides ? options.overrides({ field }) : field;
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { iconField };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=iconField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iconField.js","names":[],"sources":["../../../../src/fields/icon/server/iconField.ts"],"sourcesContent":["import type { TextField } from 'payload'\nimport { keys } from '../../../translations/keys'\nimport { labelForKey } from '../../../translations/server'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { createIconValidate } from './validate'\n\nexport type IconFieldOptions = {\n\tname?: string\n\tlabel?: TextField['label']\n\trequired?: boolean\n\tlocalized?: boolean\n\t/** Inline adapters; omit to use the plugin-registered set at runtime. */\n\tadapters?: IconAdapter[]\n\tdefaultLibrary?: string\n\t/** Restricts selection only; stored values keep rendering through any registered adapter. */\n\tresolveAvailable?: IconAvailabilityResolver\n\t/**\n\t * Library slugs always offered for selection regardless of `resolveAvailable`.\n\t * Unions with the plugin's global `alwaysAvailable`; unregistered slugs drop.\n\t */\n\talwaysAvailable?: string[]\n\t/** Show a free-text input next to the trigger for typing `library:icon-name` directly. Default false. */\n\tshowTextInput?: boolean\n\toverrides?: (args: { field: TextField }) => TextField\n}\n\n/**\n * Text-backed icon field storing `<library>:<icon-name>`. Bare legacy names read\n * as the default library. Without the plugin, pass `adapters` inline; the admin\n * then also needs the adapters' components in `admin.dependencies` to render\n * glyphs (the plugin writes those itself).\n */\nexport const iconField = (options: IconFieldOptions = {}): TextField => {\n\tconst field: TextField = {\n\t\tname: options.name ?? 'icon',\n\t\ttype: 'text',\n\t\tlabel: options.label ?? labelForKey(keys.fieldIconLabel),\n\t\t...(options.localized === true ? { localized: true } : {}),\n\t\t...(options.required === true ? { required: true } : {}),\n\t\tvalidate: createIconValidate({\n\t\t\tadapters: options.adapters,\n\t\t\tdefaultLibrary: options.defaultLibrary,\n\t\t\trequired: options.required === true,\n\t\t}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tCell: {\n\t\t\t\t\tpath: '@10x-media/fields/rsc#IconCell',\n\t\t\t\t\tserverProps: {\n\t\t\t\t\t\tadapters: options.adapters,\n\t\t\t\t\t\tdefaultLibrary: options.defaultLibrary,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tField: {\n\t\t\t\t\tpath: '@10x-media/fields/rsc#IconFieldServer',\n\t\t\t\t\tserverProps: {\n\t\t\t\t\t\tadapters: options.adapters,\n\t\t\t\t\t\talwaysAvailable: options.alwaysAvailable,\n\t\t\t\t\t\tdefaultLibrary: options.defaultLibrary,\n\t\t\t\t\t\tresolveAvailable: options.resolveAvailable,\n\t\t\t\t\t\tshowTextInput: options.showTextInput === true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\treturn options.overrides ? options.overrides({ field }) : field\n}\n"],"mappings":";;;;;;;;;;AAgCA,MAAa,aAAa,UAA4B,CAAC,MAAiB;CACvE,MAAM,QAAmB;EACxB,MAAM,QAAQ,QAAQ;EACtB,MAAM;EACN,OAAO,QAAQ,SAAS,YAAY,KAAK,cAAc;EACvD,GAAI,QAAQ,cAAc,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;EACxD,GAAI,QAAQ,aAAa,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;EACtD,UAAU,mBAAmB;GAC5B,UAAU,QAAQ;GAClB,gBAAgB,QAAQ;GACxB,UAAU,QAAQ,aAAa;EAChC,CAAC;EACD,OAAO,EACN,YAAY;GACX,MAAM;IACL,MAAM;IACN,aAAa;KACZ,UAAU,QAAQ;KAClB,gBAAgB,QAAQ;IACzB;GACD;GACA,OAAO;IACN,MAAM;IACN,aAAa;KACZ,UAAU,QAAQ;KAClB,iBAAiB,QAAQ;KACzB,gBAAgB,QAAQ;KACxB,kBAAkB,QAAQ;KAC1B,eAAe,QAAQ,kBAAkB;IAC1C;GACD;EACD,EACD;CACD;CACA,OAAO,QAAQ,YAAY,QAAQ,UAAU,EAAE,MAAM,CAAC,IAAI;AAC3D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IconAdapter } from "../../../types.js";
|
|
2
|
+
import { TextField } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/server/iconLibraryField.d.ts
|
|
5
|
+
type IconLibraryFieldOptions = {
|
|
6
|
+
name?: string;
|
|
7
|
+
label?: TextField['label'];
|
|
8
|
+
required?: boolean;
|
|
9
|
+
hasMany?: boolean; /** Inline adapters; omit to derive options from the plugin registry at runtime. */
|
|
10
|
+
adapters?: IconAdapter[];
|
|
11
|
+
overrides?: (args: {
|
|
12
|
+
field: TextField;
|
|
13
|
+
}) => TextField;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Text-backed picker for one or more registered icon library slugs. Pairs with
|
|
17
|
+
* `iconField()` when a document chooses its own library, and is validated
|
|
18
|
+
* against the same adapter set.
|
|
19
|
+
*/
|
|
20
|
+
declare const iconLibraryField: (options?: IconLibraryFieldOptions) => TextField;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { IconLibraryFieldOptions, iconLibraryField };
|
|
23
|
+
//# sourceMappingURL=iconLibraryField.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { asTranslate, labelForKey } from "../../../translations/server.js";
|
|
4
|
+
import { text } from "payload/shared";
|
|
5
|
+
//#region src/fields/icon/server/iconLibraryField.ts
|
|
6
|
+
const createLibraryValidate = (args) => (value, options) => {
|
|
7
|
+
const values = value == null ? [] : Array.isArray(value) ? value : [value];
|
|
8
|
+
if (values.length > 0) {
|
|
9
|
+
const registered = new Set((args.adapters ?? getFieldsRegistry(options.req.payload.config)?.icon?.adapters ?? []).map((adapter) => adapter.slug));
|
|
10
|
+
for (const candidate of values) if (typeof candidate !== "string" || !registered.has(candidate)) return asTranslate(options.req.t)(keys.invalidIconLibraryValue, { value: String(candidate) });
|
|
11
|
+
}
|
|
12
|
+
return text(value, {
|
|
13
|
+
...options,
|
|
14
|
+
required: options.required ?? args.required
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Text-backed picker for one or more registered icon library slugs. Pairs with
|
|
19
|
+
* `iconField()` when a document chooses its own library, and is validated
|
|
20
|
+
* against the same adapter set.
|
|
21
|
+
*/
|
|
22
|
+
const iconLibraryField = (options = {}) => {
|
|
23
|
+
const validate = createLibraryValidate({
|
|
24
|
+
adapters: options.adapters,
|
|
25
|
+
required: options.required === true
|
|
26
|
+
});
|
|
27
|
+
const base = {
|
|
28
|
+
name: options.name ?? "iconLibrary",
|
|
29
|
+
type: "text",
|
|
30
|
+
label: options.label ?? labelForKey(keys.fieldIconLibraryLabel),
|
|
31
|
+
...options.required === true ? { required: true } : {},
|
|
32
|
+
admin: { components: { Field: {
|
|
33
|
+
path: "@10x-media/fields/rsc#IconLibrarySelectServer",
|
|
34
|
+
serverProps: { adapters: options.adapters }
|
|
35
|
+
} } }
|
|
36
|
+
};
|
|
37
|
+
const field = options.hasMany === true ? {
|
|
38
|
+
...base,
|
|
39
|
+
hasMany: true,
|
|
40
|
+
validate
|
|
41
|
+
} : {
|
|
42
|
+
...base,
|
|
43
|
+
validate
|
|
44
|
+
};
|
|
45
|
+
return options.overrides ? options.overrides({ field }) : field;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { iconLibraryField };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=iconLibraryField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iconLibraryField.js","names":[],"sources":["../../../../src/fields/icon/server/iconLibraryField.ts"],"sourcesContent":["import type {\n\tTextField,\n\tTextFieldManyValidation,\n\tTextFieldSingleValidation,\n\tTextFieldValidation,\n} from 'payload'\nimport { text } from 'payload/shared'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport { keys } from '../../../translations/keys'\nimport { asTranslate, labelForKey } from '../../../translations/server'\nimport type { IconAdapter } from '../../../types'\n\nexport type IconLibraryFieldOptions = {\n\tname?: string\n\tlabel?: TextField['label']\n\trequired?: boolean\n\thasMany?: boolean\n\t/** Inline adapters; omit to derive options from the plugin registry at runtime. */\n\tadapters?: IconAdapter[]\n\toverrides?: (args: { field: TextField }) => TextField\n}\n\ntype ValidateOptions = Parameters<TextFieldValidation>[1]\ntype ValidateResult = ReturnType<TextFieldValidation>\n\nconst createLibraryValidate =\n\t(args: { adapters?: IconAdapter[]; required: boolean }) =>\n\t(value: unknown, options: ValidateOptions): ValidateResult => {\n\t\tconst values = value == null ? [] : Array.isArray(value) ? value : [value]\n\t\tif (values.length > 0) {\n\t\t\tconst registered = new Set(\n\t\t\t\t(args.adapters ?? getFieldsRegistry(options.req.payload.config)?.icon?.adapters ?? []).map(\n\t\t\t\t\t(adapter) => adapter.slug\n\t\t\t\t)\n\t\t\t)\n\t\t\tfor (const candidate of values) {\n\t\t\t\tif (typeof candidate !== 'string' || !registered.has(candidate)) {\n\t\t\t\t\treturn asTranslate(options.req.t)(keys.invalidIconLibraryValue, {\n\t\t\t\t\t\tvalue: String(candidate),\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Payload's own text validator takes both the single and hasMany shapes at\n\t\t// runtime; core sanitization assigns this same string-typed validator to\n\t\t// hasMany text fields.\n\t\treturn text(value as null | string | undefined, {\n\t\t\t...options,\n\t\t\trequired: options.required ?? args.required,\n\t\t})\n\t}\n\n/**\n * Text-backed picker for one or more registered icon library slugs. Pairs with\n * `iconField()` when a document chooses its own library, and is validated\n * against the same adapter set.\n */\nexport const iconLibraryField = (options: IconLibraryFieldOptions = {}): TextField => {\n\t// One validator handles both shapes; each branch casts it to that branch's\n\t// signature, because Payload's TextField discriminates validate on hasMany.\n\tconst validate = createLibraryValidate({\n\t\tadapters: options.adapters,\n\t\trequired: options.required === true,\n\t})\n\tconst base = {\n\t\tname: options.name ?? 'iconLibrary',\n\t\ttype: 'text' as const,\n\t\tlabel: options.label ?? labelForKey(keys.fieldIconLibraryLabel),\n\t\t...(options.required === true ? { required: true as const } : {}),\n\t\tadmin: {\n\t\t\tcomponents: {\n\t\t\t\tField: {\n\t\t\t\t\tpath: '@10x-media/fields/rsc#IconLibrarySelectServer',\n\t\t\t\t\tserverProps: { adapters: options.adapters },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\tconst field: TextField =\n\t\toptions.hasMany === true\n\t\t\t? { ...base, hasMany: true, validate: validate as TextFieldManyValidation }\n\t\t\t: { ...base, validate: validate as TextFieldSingleValidation }\n\treturn options.overrides ? options.overrides({ field }) : field\n}\n"],"mappings":";;;;;AAyBA,MAAM,yBACJ,UACA,OAAgB,YAA6C;CAC7D,MAAM,SAAS,SAAS,OAAO,CAAC,IAAI,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;CACzE,IAAI,OAAO,SAAS,GAAG;EACtB,MAAM,aAAa,IAAI,KACrB,KAAK,YAAY,kBAAkB,QAAQ,IAAI,QAAQ,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,KACrF,YAAY,QAAQ,IACtB,CACD;EACA,KAAK,MAAM,aAAa,QACvB,IAAI,OAAO,cAAc,YAAY,CAAC,WAAW,IAAI,SAAS,GAC7D,OAAO,YAAY,QAAQ,IAAI,CAAC,EAAE,KAAK,yBAAyB,EAC/D,OAAO,OAAO,SAAS,EACxB,CAAC;CAGJ;CAIA,OAAO,KAAK,OAAoC;EAC/C,GAAG;EACH,UAAU,QAAQ,YAAY,KAAK;CACpC,CAAC;AACF;;;;;;AAOD,MAAa,oBAAoB,UAAmC,CAAC,MAAiB;CAGrF,MAAM,WAAW,sBAAsB;EACtC,UAAU,QAAQ;EAClB,UAAU,QAAQ,aAAa;CAChC,CAAC;CACD,MAAM,OAAO;EACZ,MAAM,QAAQ,QAAQ;EACtB,MAAM;EACN,OAAO,QAAQ,SAAS,YAAY,KAAK,qBAAqB;EAC9D,GAAI,QAAQ,aAAa,OAAO,EAAE,UAAU,KAAc,IAAI,CAAC;EAC/D,OAAO,EACN,YAAY,EACX,OAAO;GACN,MAAM;GACN,aAAa,EAAE,UAAU,QAAQ,SAAS;EAC3C,EACD,EACD;CACD;CACA,MAAM,QACL,QAAQ,YAAY,OACjB;EAAE,GAAG;EAAM,SAAS;EAAgB;CAAoC,IACxE;EAAE,GAAG;EAAgB;CAAsC;CAC/D,OAAO,QAAQ,YAAY,QAAQ,UAAU,EAAE,MAAM,CAAC,IAAI;AAC3D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IconAdapter } from "../../../types.js";
|
|
2
|
+
import { SanitizedConfig, StaticLabel } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/server/libraryOptions.d.ts
|
|
5
|
+
/** Selectable libraries for `iconLibraryField()`, from inline adapters or the plugin registry. */
|
|
6
|
+
declare const getIconLibraryOptions: (config: SanitizedConfig, inline?: IconAdapter[]) => {
|
|
7
|
+
label: StaticLabel;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getIconLibraryOptions };
|
|
12
|
+
//# sourceMappingURL=libraryOptions.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
+
//#region src/fields/icon/server/libraryOptions.ts
|
|
3
|
+
/** Selectable libraries for `iconLibraryField()`, from inline adapters or the plugin registry. */
|
|
4
|
+
const getIconLibraryOptions = (config, inline) => {
|
|
5
|
+
return (inline ?? getFieldsRegistry(config)?.icon?.adapters ?? []).map((adapter) => ({
|
|
6
|
+
label: adapter.label,
|
|
7
|
+
value: adapter.slug
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getIconLibraryOptions };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=libraryOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libraryOptions.js","names":[],"sources":["../../../../src/fields/icon/server/libraryOptions.ts"],"sourcesContent":["import type { SanitizedConfig, StaticLabel } from 'payload'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter } from '../../../types'\n\n/** Selectable libraries for `iconLibraryField()`, from inline adapters or the plugin registry. */\nexport const getIconLibraryOptions = (\n\tconfig: SanitizedConfig,\n\tinline?: IconAdapter[]\n): { label: StaticLabel; value: string }[] => {\n\tconst adapters = inline ?? getFieldsRegistry(config)?.icon?.adapters ?? []\n\treturn adapters.map((adapter) => ({ label: adapter.label, value: adapter.slug }))\n}\n"],"mappings":";;;AAKA,MAAa,yBACZ,QACA,WAC6C;CAE7C,QADiB,UAAU,kBAAkB,MAAM,GAAG,MAAM,YAAY,CAAC,GACzD,KAAK,aAAa;EAAE,OAAO,QAAQ;EAAO,OAAO,QAAQ;CAAK,EAAE;AACjF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/fields/icon/server/manifestCache.ts
|
|
2
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3
|
+
/** Name sets cached per adapter slug+version for the process lifetime; manifests are static build artifacts. */
|
|
4
|
+
const loadManifestNames = (adapter) => {
|
|
5
|
+
const key = `${adapter.slug}@${adapter.version}`;
|
|
6
|
+
let entry = cache.get(key);
|
|
7
|
+
if (!entry) {
|
|
8
|
+
entry = adapter.loadManifest().then((manifest) => new Set(manifest.icons.map((icon) => icon.name)));
|
|
9
|
+
cache.set(key, entry);
|
|
10
|
+
entry.catch(() => cache.delete(key));
|
|
11
|
+
}
|
|
12
|
+
return entry;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { loadManifestNames };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=manifestCache.js.map
|
|
@@ -0,0 +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<Set<string>>>()\n\n/** Name sets cached per adapter slug+version for the process lifetime; manifests are static build artifacts. */\nexport const loadManifestNames = (adapter: IconAdapter): Promise<Set<string>> => {\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 Set(manifest.icons.map((icon) => icon.name)))\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,IAAkC;;AAGpD,MAAa,qBAAqB,YAA+C;CAChF,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,KAAK,IAAI,CAAC,CAAC;EACrE,MAAM,IAAI,KAAK,KAAK;EAGpB,MAAW,YAAY,MAAM,OAAO,GAAG,CAAC;CACzC;CACA,OAAO;AACR"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getFieldsRegistry } from "../../../plugin/registry.js";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { resolveIconValue } from "../shared/value.js";
|
|
4
|
+
import { asTranslate } from "../../../translations/server.js";
|
|
5
|
+
import { loadManifestNames } from "./manifestCache.js";
|
|
6
|
+
import { text } from "payload/shared";
|
|
7
|
+
//#region src/fields/icon/server/validate.ts
|
|
8
|
+
/**
|
|
9
|
+
* Unregistered library or unknown name in a known library: error only for
|
|
10
|
+
* changed values, so a stored doc stays saveable after its library is dropped
|
|
11
|
+
* or an icon-set upgrade removes a glyph. Changing TO an unknown value errors.
|
|
12
|
+
*/
|
|
13
|
+
const createIconValidate = (args) => async (value, options) => {
|
|
14
|
+
const required = options.required ?? args.required;
|
|
15
|
+
if (value != null && value !== "") {
|
|
16
|
+
const registry = getFieldsRegistry(options.req.payload.config);
|
|
17
|
+
const registered = args.adapters ?? registry?.icon?.adapters ?? [];
|
|
18
|
+
const { library, name } = resolveIconValue(value, args.defaultLibrary ?? registry?.icon?.defaultLibrary ?? registered[0]?.slug ?? "");
|
|
19
|
+
const adapter = registered.find((candidate) => candidate.slug === library);
|
|
20
|
+
const t = asTranslate(options.req.t);
|
|
21
|
+
if (value !== options.previousValue) {
|
|
22
|
+
if (!adapter) return t(keys.invalidIconLibrary, { library });
|
|
23
|
+
if (!(await loadManifestNames(adapter)).has(name)) return t(keys.invalidIconName, {
|
|
24
|
+
library,
|
|
25
|
+
name
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return text(value, {
|
|
30
|
+
...options,
|
|
31
|
+
required
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { createIconValidate };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +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 { loadManifestNames } from './manifestCache'\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 names = await loadManifestNames(adapter)\n\t\t\t\tif (!names.has(name)) {\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;GAG9C,IAAI,EAAC,MADe,kBAAkB,OAAO,GAClC,IAAI,IAAI,GAClB,OAAO,EAAE,KAAK,iBAAiB;IAAE;IAAS;GAAK,CAAC;EAElD;CACD;CACA,OAAO,KAAK,OAAO;EAAE,GAAG;EAAS;CAAS,CAAC;AAC5C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IconManifest, IconNodeMap } from "../../../types.js";
|
|
2
|
+
import { ComponentType } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/shared/adapterComponents.d.ts
|
|
5
|
+
type AdapterIconProps = {
|
|
6
|
+
className?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
type AdapterAssetsProps = {
|
|
11
|
+
onReady: (manifest: IconManifest) => void;
|
|
12
|
+
};
|
|
13
|
+
type AdapterNodesProps = {
|
|
14
|
+
onReady: (nodes: IconNodeMap) => void;
|
|
15
|
+
};
|
|
16
|
+
type AdapterComponentsEntry = {
|
|
17
|
+
Assets: ComponentType<AdapterAssetsProps>;
|
|
18
|
+
Icon: ComponentType<AdapterIconProps>; /** Loads bulk glyph node-data for fast drawer rendering; absent for per-icon libraries (radix). */
|
|
19
|
+
Nodes?: ComponentType<AdapterNodesProps>;
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { AdapterAssetsProps, AdapterComponentsEntry, AdapterIconProps, AdapterNodesProps };
|
|
23
|
+
//# sourceMappingURL=adapterComponents.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/fields/icon/shared/formatIconLabel.ts
|
|
2
|
+
/**
|
|
3
|
+
* Kebab icon name to a sentence-cased, spaced label: `align-horizontal-distribute-center`
|
|
4
|
+
* becomes `Align horizontal distribute center`, `ambulance` becomes `Ambulance`. Used
|
|
5
|
+
* wherever a stored `library:name` value is surfaced to an editor (the trigger label, the
|
|
6
|
+
* drawer hover tooltip, the list cell); the raw `library:name` is never shown to a user.
|
|
7
|
+
*/
|
|
8
|
+
const formatIconLabel = (name) => {
|
|
9
|
+
const spaced = name.replace(/[-\s]+/g, " ").trim();
|
|
10
|
+
if (spaced === "") return "";
|
|
11
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1).toLowerCase();
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formatIconLabel };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=formatIconLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatIconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/formatIconLabel.ts"],"sourcesContent":["/**\n * Kebab icon name to a sentence-cased, spaced label: `align-horizontal-distribute-center`\n * becomes `Align horizontal distribute center`, `ambulance` becomes `Ambulance`. Used\n * wherever a stored `library:name` value is surfaced to an editor (the trigger label, the\n * drawer hover tooltip, the list cell); the raw `library:name` is never shown to a user.\n */\nexport const formatIconLabel = (name: string): string => {\n\tconst spaced = name.replace(/[-\\s]+/g, ' ').trim()\n\tif (spaced === '') return ''\n\treturn spaced.charAt(0).toUpperCase() + spaced.slice(1).toLowerCase()\n}\n"],"mappings":";;;;;;;AAMA,MAAa,mBAAmB,SAAyB;CACxD,MAAM,SAAS,KAAK,QAAQ,WAAW,GAAG,EAAE,KAAK;CACjD,IAAI,WAAW,IAAI,OAAO;CAC1B,OAAO,OAAO,OAAO,CAAC,EAAE,YAAY,IAAI,OAAO,MAAM,CAAC,EAAE,YAAY;AACrE"}
|