@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,245 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { formatIconLabel } from "../shared/formatIconLabel.js";
|
|
5
|
+
import { formatIconValue, resolveIconValue } from "../shared/value.js";
|
|
6
|
+
import { filterAvailableLibraries, pickInitialLibrary } from "./availableLibraries.js";
|
|
7
|
+
import { Drawer, FieldDescription, FieldError, FieldLabel, RenderCustomComponent, XIcon, fieldBaseClass, formatDrawerSlug, useEditDepth, useField, useModal } from "@payloadcms/ui";
|
|
8
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
9
|
+
import React, { Suspense, useCallback, useMemo, useState } from "react";
|
|
10
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import "./icon-field.css";
|
|
12
|
+
//#region src/fields/icon/client/IconFieldClient.tsx
|
|
13
|
+
const IconDrawerContent = React.lazy(() => import("./IconDrawerContent.js"));
|
|
14
|
+
/** Muted grid glyph shown in the square when the field has no value: a picker affordance, not a value. */
|
|
15
|
+
const PlaceholderGlyph = () => /* @__PURE__ */ jsxs("svg", {
|
|
16
|
+
"aria-hidden": "true",
|
|
17
|
+
fill: "currentColor",
|
|
18
|
+
height: 20,
|
|
19
|
+
viewBox: "0 0 20 20",
|
|
20
|
+
width: 20,
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsx("rect", {
|
|
23
|
+
height: "6",
|
|
24
|
+
rx: "1.5",
|
|
25
|
+
width: "6",
|
|
26
|
+
x: "3",
|
|
27
|
+
y: "3"
|
|
28
|
+
}),
|
|
29
|
+
/* @__PURE__ */ jsx("rect", {
|
|
30
|
+
height: "6",
|
|
31
|
+
rx: "1.5",
|
|
32
|
+
width: "6",
|
|
33
|
+
x: "11",
|
|
34
|
+
y: "3"
|
|
35
|
+
}),
|
|
36
|
+
/* @__PURE__ */ jsx("rect", {
|
|
37
|
+
height: "6",
|
|
38
|
+
rx: "1.5",
|
|
39
|
+
width: "6",
|
|
40
|
+
x: "3",
|
|
41
|
+
y: "11"
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx("rect", {
|
|
44
|
+
height: "6",
|
|
45
|
+
rx: "1.5",
|
|
46
|
+
width: "6",
|
|
47
|
+
x: "11",
|
|
48
|
+
y: "11"
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const WarningIcon = () => /* @__PURE__ */ jsxs("svg", {
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
fill: "none",
|
|
55
|
+
height: 16,
|
|
56
|
+
viewBox: "0 0 16 16",
|
|
57
|
+
width: 16,
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx("path", {
|
|
60
|
+
d: "M8 1.75 15 14H1z",
|
|
61
|
+
stroke: "currentColor",
|
|
62
|
+
strokeLinejoin: "round",
|
|
63
|
+
strokeWidth: "1.4"
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ jsx("path", {
|
|
66
|
+
d: "M8 6.25v3.5",
|
|
67
|
+
stroke: "currentColor",
|
|
68
|
+
strokeLinecap: "round",
|
|
69
|
+
strokeWidth: "1.4"
|
|
70
|
+
}),
|
|
71
|
+
/* @__PURE__ */ jsx("circle", {
|
|
72
|
+
cx: "8",
|
|
73
|
+
cy: "11.75",
|
|
74
|
+
fill: "currentColor",
|
|
75
|
+
r: "0.85"
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
const IconField = (props) => {
|
|
80
|
+
const { adapterComponents, adapters, available, defaultLibrary, field, path: pathFromProps, readOnly, showTextInput } = props;
|
|
81
|
+
const { t } = useTranslation$1();
|
|
82
|
+
const editDepth = useEditDepth();
|
|
83
|
+
const { closeModal, isModalOpen, openModal } = useModal();
|
|
84
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
85
|
+
const drawerSlug = formatDrawerSlug({
|
|
86
|
+
slug: `fields-icon-${path}`,
|
|
87
|
+
depth: editDepth
|
|
88
|
+
});
|
|
89
|
+
const isDisabled = Boolean(readOnly || disabled || field.admin?.readOnly);
|
|
90
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
91
|
+
const resolved = value ? resolveIconValue(value, defaultLibrary) : null;
|
|
92
|
+
const registeredSlugs = useMemo(() => new Set(adapters.map((adapter) => adapter.slug)), [adapters]);
|
|
93
|
+
const isUnavailable = resolved !== null && (!registeredSlugs.has(resolved.library) || !available.includes(resolved.library));
|
|
94
|
+
const previewEntry = resolved ? adapterComponents[resolved.library] : void 0;
|
|
95
|
+
const hasGlyph = Boolean(resolved && previewEntry);
|
|
96
|
+
const displayLabel = resolved ? formatIconLabel(resolved.name) : "";
|
|
97
|
+
const availableAdapters = useMemo(() => filterAvailableLibraries(adapters, available), [adapters, available]);
|
|
98
|
+
const [activeLibrary, setActiveLibrary] = useState(() => pickInitialLibrary({
|
|
99
|
+
available,
|
|
100
|
+
defaultLibrary,
|
|
101
|
+
selectedLibrary: resolved?.library ?? null
|
|
102
|
+
}));
|
|
103
|
+
const [editing, setEditing] = useState(false);
|
|
104
|
+
const handleSelect = useCallback((library, name) => {
|
|
105
|
+
setValue(formatIconValue(library, name));
|
|
106
|
+
closeModal(drawerSlug);
|
|
107
|
+
}, [
|
|
108
|
+
closeModal,
|
|
109
|
+
drawerSlug,
|
|
110
|
+
setValue
|
|
111
|
+
]);
|
|
112
|
+
const triggerDisabled = isDisabled || availableAdapters.length === 0;
|
|
113
|
+
const glyphClass = `tenx-icon-field__glyph${hasGlyph ? "" : " tenx-icon-field__glyph--empty"}`;
|
|
114
|
+
const glyph = resolved && previewEntry ? /* @__PURE__ */ jsx(previewEntry.Icon, {
|
|
115
|
+
name: resolved.name,
|
|
116
|
+
size: 20
|
|
117
|
+
}) : /* @__PURE__ */ jsx(PlaceholderGlyph, {});
|
|
118
|
+
const wrapperClasses = [
|
|
119
|
+
fieldBaseClass,
|
|
120
|
+
"tenx-icon-field",
|
|
121
|
+
field.admin?.className,
|
|
122
|
+
showError ? "error" : null,
|
|
123
|
+
isDisabled ? "read-only" : null
|
|
124
|
+
].filter(Boolean).join(" ");
|
|
125
|
+
const controlClasses = `tenx-icon-field__control${isUnavailable ? " tenx-icon-field__control--warning" : ""}`;
|
|
126
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
127
|
+
className: wrapperClasses,
|
|
128
|
+
id: `field-${path.replace(/\./g, "__")}`,
|
|
129
|
+
style: styles,
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
132
|
+
CustomComponent: Label,
|
|
133
|
+
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
134
|
+
label: field.label,
|
|
135
|
+
localized: field.localized,
|
|
136
|
+
path,
|
|
137
|
+
required: field.required
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
/* @__PURE__ */ jsxs("div", {
|
|
141
|
+
className: `${fieldBaseClass}__wrap`,
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
144
|
+
CustomComponent: ErrorComponent,
|
|
145
|
+
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
146
|
+
path,
|
|
147
|
+
showError
|
|
148
|
+
})
|
|
149
|
+
}),
|
|
150
|
+
BeforeInput,
|
|
151
|
+
/* @__PURE__ */ jsxs("div", {
|
|
152
|
+
className: controlClasses,
|
|
153
|
+
children: [
|
|
154
|
+
showTextInput ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
|
|
155
|
+
"aria-expanded": isModalOpen(drawerSlug),
|
|
156
|
+
"aria-haspopup": "dialog",
|
|
157
|
+
"aria-label": t(keys.selectIcon),
|
|
158
|
+
className: glyphClass,
|
|
159
|
+
disabled: triggerDisabled,
|
|
160
|
+
onClick: () => openModal(drawerSlug),
|
|
161
|
+
type: "button",
|
|
162
|
+
children: glyph
|
|
163
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
164
|
+
"aria-label": t(keys.fieldIconLabel),
|
|
165
|
+
className: "tenx-icon-field__value tenx-icon-field__value--input",
|
|
166
|
+
onBlur: () => setEditing(false),
|
|
167
|
+
onChange: (event) => setValue(event.target.value || null),
|
|
168
|
+
onFocus: () => setEditing(true),
|
|
169
|
+
placeholder: t(keys.textInputPlaceholder),
|
|
170
|
+
readOnly: isDisabled,
|
|
171
|
+
type: "text",
|
|
172
|
+
value: editing ? value ?? "" : displayLabel
|
|
173
|
+
})] }) : /* @__PURE__ */ jsxs("button", {
|
|
174
|
+
"aria-expanded": isModalOpen(drawerSlug),
|
|
175
|
+
"aria-haspopup": "dialog",
|
|
176
|
+
className: "tenx-icon-field__open",
|
|
177
|
+
disabled: triggerDisabled,
|
|
178
|
+
onClick: () => openModal(drawerSlug),
|
|
179
|
+
type: "button",
|
|
180
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
181
|
+
"aria-hidden": "true",
|
|
182
|
+
className: glyphClass,
|
|
183
|
+
children: glyph
|
|
184
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
185
|
+
className: "tenx-icon-field__value",
|
|
186
|
+
children: resolved ? displayLabel : /* @__PURE__ */ jsx("span", {
|
|
187
|
+
className: "tenx-icon-field__placeholder",
|
|
188
|
+
children: t(keys.selectIcon)
|
|
189
|
+
})
|
|
190
|
+
})]
|
|
191
|
+
}),
|
|
192
|
+
isUnavailable ? /* @__PURE__ */ jsxs("span", {
|
|
193
|
+
className: "tenx-icon-field__marker",
|
|
194
|
+
title: t(keys.iconUnavailable),
|
|
195
|
+
children: [/* @__PURE__ */ jsx(WarningIcon, {}), /* @__PURE__ */ jsx("span", {
|
|
196
|
+
className: "tenx-icon-field__sr-only",
|
|
197
|
+
children: t(keys.iconUnavailable)
|
|
198
|
+
})]
|
|
199
|
+
}) : null,
|
|
200
|
+
value && !field.required && !isDisabled ? /* @__PURE__ */ jsx("button", {
|
|
201
|
+
"aria-label": t(keys.clearIcon),
|
|
202
|
+
className: "tenx-icon-field__clear",
|
|
203
|
+
onClick: () => {
|
|
204
|
+
setValue(null);
|
|
205
|
+
setEditing(false);
|
|
206
|
+
},
|
|
207
|
+
type: "button",
|
|
208
|
+
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
209
|
+
}) : null
|
|
210
|
+
]
|
|
211
|
+
}),
|
|
212
|
+
AfterInput,
|
|
213
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
214
|
+
CustomComponent: Description,
|
|
215
|
+
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
216
|
+
description: field.admin?.description,
|
|
217
|
+
path
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ jsx(Drawer, {
|
|
223
|
+
className: "tenx-icon-drawer-modal",
|
|
224
|
+
slug: drawerSlug,
|
|
225
|
+
title: t(keys.selectIcon),
|
|
226
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
227
|
+
fallback: /* @__PURE__ */ jsx("div", { className: "tenx-icon-drawer__loading" }),
|
|
228
|
+
children: /* @__PURE__ */ jsx(IconDrawerContent, {
|
|
229
|
+
activeLibrary,
|
|
230
|
+
adapterComponents,
|
|
231
|
+
adapters: availableAdapters,
|
|
232
|
+
onLibraryChange: setActiveLibrary,
|
|
233
|
+
onSelect: handleSelect,
|
|
234
|
+
selected: resolved,
|
|
235
|
+
slugPrefix: drawerSlug
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { IconField };
|
|
244
|
+
|
|
245
|
+
//# sourceMappingURL=IconFieldClient.js.map
|
|
@@ -0,0 +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,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;WAA3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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,14 @@
|
|
|
1
|
+
import { TextFieldClientProps } from "payload";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/icon/client/IconLibrarySelect.d.ts
|
|
5
|
+
type IconLibrarySelectProps = TextFieldClientProps & {
|
|
6
|
+
options: {
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
declare const IconLibrarySelect: React.FC<IconLibrarySelectProps>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { IconLibrarySelect };
|
|
14
|
+
//# sourceMappingURL=IconLibrarySelect.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SelectInput, fieldBaseClass, useField } from "@payloadcms/ui";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/fields/icon/client/IconLibrarySelect.tsx
|
|
6
|
+
const IconLibrarySelect = (props) => {
|
|
7
|
+
const { field, options, path: pathFromProps, readOnly } = props;
|
|
8
|
+
const hasMany = "hasMany" in field && field.hasMany === true;
|
|
9
|
+
const { disabled, path, setValue, showError, value } = useField({ potentiallyStalePath: pathFromProps });
|
|
10
|
+
const handleChange = useCallback((option) => {
|
|
11
|
+
if (Array.isArray(option)) setValue(option.map((entry) => entry.value));
|
|
12
|
+
else if (option && typeof option === "object" && "value" in option) setValue(option.value);
|
|
13
|
+
else setValue(hasMany ? [] : null);
|
|
14
|
+
}, [hasMany, setValue]);
|
|
15
|
+
return /* @__PURE__ */ jsx("div", {
|
|
16
|
+
className: [fieldBaseClass, "tenx-icon-library-field"].filter(Boolean).join(" "),
|
|
17
|
+
children: /* @__PURE__ */ jsx(SelectInput, {
|
|
18
|
+
hasMany,
|
|
19
|
+
isClearable: !field.required,
|
|
20
|
+
label: field.label,
|
|
21
|
+
localized: field.localized,
|
|
22
|
+
name: field.name,
|
|
23
|
+
onChange: handleChange,
|
|
24
|
+
options,
|
|
25
|
+
path,
|
|
26
|
+
readOnly: Boolean(readOnly || disabled || field.admin?.readOnly),
|
|
27
|
+
required: field.required,
|
|
28
|
+
showError,
|
|
29
|
+
value
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { IconLibrarySelect };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=IconLibrarySelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconLibrarySelect.js","names":[],"sources":["../../../../src/fields/icon/client/IconLibrarySelect.tsx"],"sourcesContent":["'use client'\n\nimport { fieldBaseClass, SelectInput, useField } from '@payloadcms/ui'\nimport type { TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useCallback } from 'react'\n\nexport type IconLibrarySelectProps = TextFieldClientProps & {\n\toptions: { label: string; value: string }[]\n}\n\nexport const IconLibrarySelect: React.FC<IconLibrarySelectProps> = (props) => {\n\tconst { field, options, path: pathFromProps, readOnly } = props\n\tconst hasMany = 'hasMany' in field && field.hasMany === true\n\tconst { disabled, path, setValue, showError, value } = useField<string | string[]>({\n\t\tpotentiallyStalePath: pathFromProps,\n\t})\n\n\tconst handleChange = useCallback(\n\t\t(option: unknown) => {\n\t\t\tif (Array.isArray(option)) {\n\t\t\t\tsetValue(option.map((entry) => (entry as { value: string }).value))\n\t\t\t} else if (option && typeof option === 'object' && 'value' in option) {\n\t\t\t\tsetValue((option as { value: string }).value)\n\t\t\t} else {\n\t\t\t\tsetValue(hasMany ? [] : null)\n\t\t\t}\n\t\t},\n\t\t[hasMany, setValue]\n\t)\n\n\treturn (\n\t\t<div className={[fieldBaseClass, 'tenx-icon-library-field'].filter(Boolean).join(' ')}>\n\t\t\t<SelectInput\n\t\t\t\thasMany={hasMany}\n\t\t\t\tisClearable={!field.required}\n\t\t\t\tlabel={field.label}\n\t\t\t\tlocalized={field.localized}\n\t\t\t\tname={field.name}\n\t\t\t\tonChange={handleChange}\n\t\t\t\toptions={options}\n\t\t\t\tpath={path}\n\t\t\t\treadOnly={Boolean(readOnly || disabled || field.admin?.readOnly)}\n\t\t\t\trequired={field.required}\n\t\t\t\tshowError={showError}\n\t\t\t\tvalue={value}\n\t\t\t/>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;AAWA,MAAa,qBAAuD,UAAU;CAC7E,MAAM,EAAE,OAAO,SAAS,MAAM,eAAe,aAAa;CAC1D,MAAM,UAAU,aAAa,SAAS,MAAM,YAAY;CACxD,MAAM,EAAE,UAAU,MAAM,UAAU,WAAW,UAAU,SAA4B,EAClF,sBAAsB,cACvB,CAAC;CAED,MAAM,eAAe,aACnB,WAAoB;EACpB,IAAI,MAAM,QAAQ,MAAM,GACvB,SAAS,OAAO,KAAK,UAAW,MAA4B,KAAK,CAAC;OAC5D,IAAI,UAAU,OAAO,WAAW,YAAY,WAAW,QAC7D,SAAU,OAA6B,KAAK;OAE5C,SAAS,UAAU,CAAC,IAAI,IAAI;CAE9B,GACA,CAAC,SAAS,QAAQ,CACnB;CAEA,OACC,oBAAC,OAAD;EAAK,WAAW,CAAC,gBAAgB,yBAAyB,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;YACnF,oBAAC,aAAD;GACU;GACT,aAAa,CAAC,MAAM;GACpB,OAAO,MAAM;GACb,WAAW,MAAM;GACjB,MAAM,MAAM;GACZ,UAAU;GACD;GACH;GACN,UAAU,QAAQ,YAAY,YAAY,MAAM,OAAO,QAAQ;GAC/D,UAAU,MAAM;GACL;GACJ;EACP,CAAA;CACG,CAAA;AAEP"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/fields/icon/client/availableLibraries.ts
|
|
2
|
+
/**
|
|
3
|
+
* Libraries offered for selection: the registered adapters intersected with the
|
|
4
|
+
* `available` slugs the server resolved for this request. Selection is restricted to
|
|
5
|
+
* these; rendering a stored value still works through any registered adapter.
|
|
6
|
+
*/
|
|
7
|
+
const filterAvailableLibraries = (adapters, available) => {
|
|
8
|
+
const allowed = new Set(available);
|
|
9
|
+
return adapters.filter((adapter) => allowed.has(adapter.slug));
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Library the drawer opens on: the stored value's library when it is still available,
|
|
13
|
+
* otherwise the configured default when available, otherwise the first available
|
|
14
|
+
* library. Never opens on a library the editor cannot pick from.
|
|
15
|
+
*/
|
|
16
|
+
const pickInitialLibrary = (args) => {
|
|
17
|
+
const { available, defaultLibrary, selectedLibrary } = args;
|
|
18
|
+
if (selectedLibrary !== null && available.includes(selectedLibrary)) return selectedLibrary;
|
|
19
|
+
if (available.includes(defaultLibrary)) return defaultLibrary;
|
|
20
|
+
return available[0] ?? defaultLibrary;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { filterAvailableLibraries, pickInitialLibrary };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=availableLibraries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availableLibraries.js","names":[],"sources":["../../../../src/fields/icon/client/availableLibraries.ts"],"sourcesContent":["export type LibraryOption = { label: string; slug: string }\n\n/**\n * Libraries offered for selection: the registered adapters intersected with the\n * `available` slugs the server resolved for this request. Selection is restricted to\n * these; rendering a stored value still works through any registered adapter.\n */\nexport const filterAvailableLibraries = (\n\tadapters: LibraryOption[],\n\tavailable: string[]\n): LibraryOption[] => {\n\tconst allowed = new Set(available)\n\treturn adapters.filter((adapter) => allowed.has(adapter.slug))\n}\n\n/**\n * Library the drawer opens on: the stored value's library when it is still available,\n * otherwise the configured default when available, otherwise the first available\n * library. Never opens on a library the editor cannot pick from.\n */\nexport const pickInitialLibrary = (args: {\n\tavailable: string[]\n\tdefaultLibrary: string\n\tselectedLibrary: null | string\n}): string => {\n\tconst { available, defaultLibrary, selectedLibrary } = args\n\tif (selectedLibrary !== null && available.includes(selectedLibrary)) return selectedLibrary\n\tif (available.includes(defaultLibrary)) return defaultLibrary\n\treturn available[0] ?? defaultLibrary\n}\n"],"mappings":";;;;;;AAOA,MAAa,4BACZ,UACA,cACqB;CACrB,MAAM,UAAU,IAAI,IAAI,SAAS;CACjC,OAAO,SAAS,QAAQ,YAAY,QAAQ,IAAI,QAAQ,IAAI,CAAC;AAC9D;;;;;;AAOA,MAAa,sBAAsB,SAIrB;CACb,MAAM,EAAE,WAAW,gBAAgB,oBAAoB;CACvD,IAAI,oBAAoB,QAAQ,UAAU,SAAS,eAAe,GAAG,OAAO;CAC5E,IAAI,UAAU,SAAS,cAAc,GAAG,OAAO;CAC/C,OAAO,UAAU,MAAM;AACxB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { Suspense, useEffect, useRef } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/fields/icon/client/generatedAdapter.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Builds an `AdapterNodesProps` component that lazily imports a library's bulk
|
|
7
|
+
* node-data once and hands it back through `onReady`. The drawer renders every
|
|
8
|
+
* cell from this data as inline SVG, so scrolling a large library never triggers
|
|
9
|
+
* the per-icon dynamic imports the `Icon` component would. The import lives
|
|
10
|
+
* inside this factory, keeping the node-data off every static bundle graph.
|
|
11
|
+
*/
|
|
12
|
+
const createNodesLoader = (loadNodes) => {
|
|
13
|
+
const Nodes = ({ onReady }) => {
|
|
14
|
+
const onReadyRef = useRef(onReady);
|
|
15
|
+
onReadyRef.current = onReady;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
let live = true;
|
|
18
|
+
loadNodes().then((nodes) => {
|
|
19
|
+
if (live) onReadyRef.current(nodes);
|
|
20
|
+
});
|
|
21
|
+
return () => {
|
|
22
|
+
live = false;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
return Nodes;
|
|
28
|
+
};
|
|
29
|
+
const Empty = () => null;
|
|
30
|
+
/**
|
|
31
|
+
* Builds the `Icon`/`Assets` pair for an adapter whose glyphs come from a
|
|
32
|
+
* generated import map. Every icon is its own lazy chunk, so an admin bundle
|
|
33
|
+
* only ever downloads the glyphs it renders. Adapters differ solely in how they
|
|
34
|
+
* take size, hence `iconProps`.
|
|
35
|
+
*/
|
|
36
|
+
const createGeneratedAdapterComponents = ({ iconProps, loadImports, loadManifest }) => {
|
|
37
|
+
const cache = /* @__PURE__ */ new Map();
|
|
38
|
+
const lazyFor = (name) => {
|
|
39
|
+
let component = cache.get(name);
|
|
40
|
+
if (!component) {
|
|
41
|
+
component = React.lazy(async () => {
|
|
42
|
+
const load = (await loadImports())[name];
|
|
43
|
+
return load ? await load() : { default: Empty };
|
|
44
|
+
});
|
|
45
|
+
cache.set(name, component);
|
|
46
|
+
}
|
|
47
|
+
return component;
|
|
48
|
+
};
|
|
49
|
+
const Icon = ({ className, name, size = 20 }) => {
|
|
50
|
+
const Component = lazyFor(name);
|
|
51
|
+
return /* @__PURE__ */ jsx(Suspense, {
|
|
52
|
+
fallback: /* @__PURE__ */ jsx("span", {
|
|
53
|
+
"aria-hidden": true,
|
|
54
|
+
className: "tenx-icon-placeholder",
|
|
55
|
+
style: {
|
|
56
|
+
height: size,
|
|
57
|
+
width: size
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
children: /* @__PURE__ */ jsx(Component, { ...iconProps({
|
|
61
|
+
className,
|
|
62
|
+
size
|
|
63
|
+
}) })
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const Assets = ({ onReady }) => {
|
|
67
|
+
const onReadyRef = useRef(onReady);
|
|
68
|
+
onReadyRef.current = onReady;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let live = true;
|
|
71
|
+
loadManifest().then((manifest) => {
|
|
72
|
+
if (live) onReadyRef.current(manifest);
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
live = false;
|
|
76
|
+
};
|
|
77
|
+
}, []);
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
Assets,
|
|
82
|
+
Icon
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { createGeneratedAdapterComponents, createNodesLoader };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=generatedAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generatedAdapter.js","names":[],"sources":["../../../../src/fields/icon/client/generatedAdapter.tsx"],"sourcesContent":["'use client'\n\nimport type { ComponentType, CSSProperties } from 'react'\nimport React, { Suspense, useEffect, useRef } from 'react'\nimport type { IconManifest, IconNodeMap } from '../../../types'\nimport type {\n\tAdapterAssetsProps,\n\tAdapterIconProps,\n\tAdapterNodesProps,\n} from '../shared/adapterComponents'\n\n/**\n * Builds an `AdapterNodesProps` component that lazily imports a library's bulk\n * node-data once and hands it back through `onReady`. The drawer renders every\n * cell from this data as inline SVG, so scrolling a large library never triggers\n * the per-icon dynamic imports the `Icon` component would. The import lives\n * inside this factory, keeping the node-data off every static bundle graph.\n */\nexport const createNodesLoader = (\n\tloadNodes: () => Promise<IconNodeMap>\n): ComponentType<AdapterNodesProps> => {\n\tconst Nodes: ComponentType<AdapterNodesProps> = ({ onReady }) => {\n\t\tconst onReadyRef = useRef(onReady)\n\t\tonReadyRef.current = onReady\n\t\tuseEffect(() => {\n\t\t\tlet live = true\n\t\t\tvoid loadNodes().then((nodes) => {\n\t\t\t\tif (live) {\n\t\t\t\t\tonReadyRef.current(nodes)\n\t\t\t\t}\n\t\t\t})\n\t\t\treturn () => {\n\t\t\t\tlive = false\n\t\t\t}\n\t\t}, [])\n\t\treturn null\n\t}\n\treturn Nodes\n}\n\n/** The prop surface the codegen'd import maps expose, widened by `style` for libraries sized through CSS. */\ntype GeneratedIconProps = { className?: string; size?: number | string; style?: CSSProperties }\n\ntype GeneratedIconComponent = ComponentType<GeneratedIconProps>\n\ntype CreateArgs = {\n\tloadManifest: () => Promise<IconManifest>\n\tloadImports: () => Promise<Record<string, () => Promise<{ default: GeneratedIconComponent }>>>\n\ticonProps: (args: { className?: string; size: number }) => GeneratedIconProps\n}\n\nconst Empty: GeneratedIconComponent = () => null\n\n/**\n * Builds the `Icon`/`Assets` pair for an adapter whose glyphs come from a\n * generated import map. Every icon is its own lazy chunk, so an admin bundle\n * only ever downloads the glyphs it renders. Adapters differ solely in how they\n * take size, hence `iconProps`.\n */\nexport const createGeneratedAdapterComponents = ({\n\ticonProps,\n\tloadImports,\n\tloadManifest,\n}: CreateArgs): {\n\tAssets: ComponentType<AdapterAssetsProps>\n\tIcon: ComponentType<AdapterIconProps>\n} => {\n\tconst cache = new Map<string, GeneratedIconComponent>()\n\n\tconst lazyFor = (name: string): GeneratedIconComponent => {\n\t\tlet component = cache.get(name)\n\t\tif (!component) {\n\t\t\tcomponent = React.lazy(async () => {\n\t\t\t\tconst imports = await loadImports()\n\t\t\t\tconst load = imports[name]\n\t\t\t\treturn load ? await load() : { default: Empty }\n\t\t\t})\n\t\t\tcache.set(name, component)\n\t\t}\n\t\treturn component\n\t}\n\n\tconst Icon: ComponentType<AdapterIconProps> = ({ className, name, size = 20 }) => {\n\t\tconst Component = lazyFor(name)\n\t\treturn (\n\t\t\t<Suspense\n\t\t\t\tfallback={\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tclassName=\"tenx-icon-placeholder\"\n\t\t\t\t\t\tstyle={{ height: size, width: size }}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<Component {...iconProps({ className, size })} />\n\t\t\t</Suspense>\n\t\t)\n\t}\n\n\tconst Assets: ComponentType<AdapterAssetsProps> = ({ onReady }) => {\n\t\tconst onReadyRef = useRef(onReady)\n\t\tonReadyRef.current = onReady\n\t\tuseEffect(() => {\n\t\t\tlet live = true\n\t\t\tvoid loadManifest().then((manifest) => {\n\t\t\t\tif (live) {\n\t\t\t\t\tonReadyRef.current(manifest)\n\t\t\t\t}\n\t\t\t})\n\t\t\treturn () => {\n\t\t\t\tlive = false\n\t\t\t}\n\t\t}, [])\n\t\treturn null\n\t}\n\n\treturn { Assets, Icon }\n}\n"],"mappings":";;;;;;;;;;;AAkBA,MAAa,qBACZ,cACsC;CACtC,MAAM,SAA2C,EAAE,cAAc;EAChE,MAAM,aAAa,OAAO,OAAO;EACjC,WAAW,UAAU;EACrB,gBAAgB;GACf,IAAI,OAAO;GACX,UAAe,EAAE,MAAM,UAAU;IAChC,IAAI,MACH,WAAW,QAAQ,KAAK;GAE1B,CAAC;GACD,aAAa;IACZ,OAAO;GACR;EACD,GAAG,CAAC,CAAC;EACL,OAAO;CACR;CACA,OAAO;AACR;AAaA,MAAM,cAAsC;;;;;;;AAQ5C,MAAa,oCAAoC,EAChD,WACA,aACA,mBAII;CACJ,MAAM,wBAAQ,IAAI,IAAoC;CAEtD,MAAM,WAAW,SAAyC;EACzD,IAAI,YAAY,MAAM,IAAI,IAAI;EAC9B,IAAI,CAAC,WAAW;GACf,YAAY,MAAM,KAAK,YAAY;IAElC,MAAM,QAAO,MADS,YAAY,GACb;IACrB,OAAO,OAAO,MAAM,KAAK,IAAI,EAAE,SAAS,MAAM;GAC/C,CAAC;GACD,MAAM,IAAI,MAAM,SAAS;EAC1B;EACA,OAAO;CACR;CAEA,MAAM,QAAyC,EAAE,WAAW,MAAM,OAAO,SAAS;EACjF,MAAM,YAAY,QAAQ,IAAI;EAC9B,OACC,oBAAC,UAAD;GACC,UACC,oBAAC,QAAD;IACC,eAAA;IACA,WAAU;IACV,OAAO;KAAE,QAAQ;KAAM,OAAO;IAAK;GACnC,CAAA;a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