@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @10x-media/fields
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Initial release: a library of Payload v3 fields that look and behave native.
|
|
8
|
+
|
|
9
|
+
- **Color field**: full picker in a constant-height row (saturation/hue/alpha, eyedropper, presets), accepts any CSS color as input, stores one configured format (`hex`/`rgb`/`hsl`/`oklch`). Presets can be static or resolved from your data per request, and linked mode stores `preset:<key>` references with a resolved virtual sibling so palette changes propagate on read. Zero-dependency color utilities exported at `./color/utils`.
|
|
10
|
+
- **Icon field**: drawer browser with search, category rail, recents, and full keyboard navigation over pluggable icon libraries. Lucide, Radix, and Tabler adapters ship first-party (optional peers); `defineIconAdapter()` and `./icon/codegen` cover any other library or SVG set. Values are stable `library:name` strings; per-icon lazy loading keeps icon datasets out of every eager bundle; `createIcon()` and `createRscIcon()` render stored values on your frontend as a client component or RSC. Multi-tenant selection restriction via `resolveAvailable` with graceful degradation for disabled libraries.
|
|
11
|
+
- **Encrypted fields**: AES-256-GCM at rest with authenticated binding to collection and field, for text, textarea, email, number, checkbox, date, select/radio (incl. `hasMany`), code, json, point, and richText. Keys derive from `PAYLOAD_SECRET` by default or come from explicit multi-key config with async providers; rotation runs online via `rotateEncryptedFields`. Opt-in blind indexing restores `equals`/`in` queries and `unique`. Masked admin UX with reveal toggle; masked fields never expose plaintext in list cells. Adoption and removal utilities included.
|
|
12
|
+
- Optional `fields()` plugin for app-wide defaults; every factory also works standalone. Typed translations (en, de). Per-family bundle isolation verified on the built output.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 10x Media GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @10x-media/fields
|
|
2
|
+
|
|
3
|
+
Reusable fields for Payload v3 that look and behave native: a full color picker in a constant-height row, a searchable icon picker over pluggable icon libraries, and encrypted fields with key rotation and opt-in exact-match querying. Built from `@payloadcms/ui` primitives on Payload design tokens, indistinguishable from Payload's own fields.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@10x-media/fields)
|
|
6
|
+
|
|
7
|
+
Part of the [@10x-media Payload plugins](https://github.com/10x-media/payload-plugins) collection. In beta: published under the `beta` dist-tag until a stable 1.0.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Color field**: saturation/hue/alpha picker, eyedropper, preset palettes (static or resolved from your data), any CSS color as input, one configured stored format (`hex`/`rgb`/`hsl`/`oklch`), and an opt-in linked mode that stores preset references so palette changes propagate everywhere.
|
|
12
|
+
- **Icon field**: drawer browser with search, category rail, and keyboard navigation; Lucide, Radix, and Tabler adapters first-party; `defineIconAdapter()` plus codegen for any other library; per-icon lazy loading so no icon dataset ever enters an eager bundle; client and RSC frontend renderers.
|
|
13
|
+
- **Encrypted fields**: AES-256-GCM with authenticated field binding, for twelve field types including `richText` and `point`; zero-config keys derived from `PAYLOAD_SECRET` or explicit multi-key config with async providers and online rotation; opt-in blind-index querying (`equals`/`in`/`unique`); masked admin UX with reveal toggle.
|
|
14
|
+
- **Native by construction**: 40px rows, Payload tokens, full `admin` prop contract, typed translations (en, de), function-form `overrides` on every factory.
|
|
15
|
+
- **Isolated bundles**: each family behind its own subpath export, isolation asserted on the built output in CI.
|
|
16
|
+
- **Plugin optional**: every factory works standalone; the `fields()` plugin adds app-wide defaults that per-field options override.
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @10x-media/fields
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// collections/Brands.ts
|
|
26
|
+
import { colorField } from '@10x-media/fields/color'
|
|
27
|
+
import { iconField } from '@10x-media/fields/icon'
|
|
28
|
+
import { lucideAdapter } from '@10x-media/fields/icon/adapters/lucide'
|
|
29
|
+
import { encryptedField } from '@10x-media/fields/encrypted'
|
|
30
|
+
|
|
31
|
+
fields: [
|
|
32
|
+
colorField({ name: 'primaryColor', required: true }),
|
|
33
|
+
iconField({ name: 'icon', adapters: [lucideAdapter()] }),
|
|
34
|
+
...encryptedField({ name: 'apiToken', type: 'text' }),
|
|
35
|
+
]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Render stored icons on your frontend:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { createIcon } from '@10x-media/fields/icon/react'
|
|
42
|
+
import { lucideRenderer } from '@10x-media/fields/icon/adapters/lucide'
|
|
43
|
+
|
|
44
|
+
const Icon = createIcon({ adapters: [lucideRenderer()] })
|
|
45
|
+
// <Icon icon={doc.icon} size={20} />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
Full documentation at [docs.10xmedia.de](https://docs.10xmedia.de/fields):
|
|
51
|
+
|
|
52
|
+
- [Overview](https://docs.10xmedia.de/fields)
|
|
53
|
+
- [Quick start](https://docs.10xmedia.de/fields/quick-start)
|
|
54
|
+
- [Color field](https://docs.10xmedia.de/fields/color)
|
|
55
|
+
- [Icon field](https://docs.10xmedia.de/fields/icon)
|
|
56
|
+
- [Encrypted fields](https://docs.10xmedia.de/fields/encrypted)
|
|
57
|
+
- [Key management](https://docs.10xmedia.de/fields/encrypted/key-management)
|
|
58
|
+
- [Building your own](https://docs.10xmedia.de/fields/building-your-own)
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
[MIT](./LICENSE). Copyright 10x Media GmbH.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ColorField, ColorFieldProps } from "../fields/color/client/ColorField.js";
|
|
2
|
+
import { ColorPickerPanel } from "../fields/color/client/ColorPickerPanel.js";
|
|
3
|
+
import { ProtectedField } from "../fields/encrypted/components/ProtectedField.js";
|
|
4
|
+
import { RichTextRevealGate } from "../fields/encrypted/components/RichTextRevealGate.js";
|
|
5
|
+
import { IconField } from "../fields/icon/client/IconFieldClient.js";
|
|
6
|
+
import { IconLibrarySelect } from "../fields/icon/client/IconLibrarySelect.js";
|
|
7
|
+
export { ColorField, type ColorFieldProps, ColorPickerPanel, IconField, IconLibrarySelect, ProtectedField, RichTextRevealGate };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ColorPickerPanel } from "../fields/color/client/ColorPickerPanel.js";
|
|
3
|
+
import { ColorField } from "../fields/color/client/ColorField.js";
|
|
4
|
+
import { ProtectedField } from "../fields/encrypted/components/ProtectedField.js";
|
|
5
|
+
import { RichTextRevealGate } from "../fields/encrypted/components/RichTextRevealGate.js";
|
|
6
|
+
import { IconField } from "../fields/icon/client/IconFieldClient.js";
|
|
7
|
+
import { IconLibrarySelect } from "../fields/icon/client/IconLibrarySelect.js";
|
|
8
|
+
export { ColorField, ColorPickerPanel, IconField, IconLibrarySelect, ProtectedField, RichTextRevealGate };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ColorFormat } from "../types.js";
|
|
2
|
+
import { FormatColorOptions, Hsl, Hsv, OklchColor, ParsedColor, RgbColor } from "../fields/color/engine/types.js";
|
|
3
|
+
import { contrastRatio, relativeLuminance } from "../fields/color/engine/contrast.js";
|
|
4
|
+
import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb } from "../fields/color/engine/convert.js";
|
|
5
|
+
import { convertColor, formatColor } from "../fields/color/engine/format.js";
|
|
6
|
+
import { namedColors } from "../fields/color/engine/namedColors.js";
|
|
7
|
+
import { parseColor } from "../fields/color/engine/parse.js";
|
|
8
|
+
import { salvageColor } from "../fields/color/engine/salvage.js";
|
|
9
|
+
export { type ColorFormat, type FormatColorOptions, type Hsl, type Hsv, type OklchColor, type ParsedColor, type RgbColor, contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isInSrgbGamut, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb } from "../fields/color/engine/convert.js";
|
|
2
|
+
import { namedColors } from "../fields/color/engine/namedColors.js";
|
|
3
|
+
import { parseColor } from "../fields/color/engine/parse.js";
|
|
4
|
+
import { contrastRatio, relativeLuminance } from "../fields/color/engine/contrast.js";
|
|
5
|
+
import { convertColor, formatColor } from "../fields/color/engine/format.js";
|
|
6
|
+
import { salvageColor } from "../fields/color/engine/salvage.js";
|
|
7
|
+
export { contrastRatio, convertColor, formatColor, hslToRgb, hsvToRgb, isInSrgbGamut, namedColors, oklchToRgb, parseColor, relativeLuminance, rgbToHsl, rgbToHsv, rgbToOklch, salvageColor, toOklch, toRgb };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ColorFormat, ColorGlobalConfig, ColorPreset } from "../types.js";
|
|
2
|
+
import { COLOR_CUSTOM_KEY, ColorFieldClientOptions, ColorFieldOptions, ColorLinkedOptions, ColorPresetsResolver, ColorPresetsSource, PRESET_PREFIX, ResolvedColorPreset } from "../fields/color/options.js";
|
|
3
|
+
import { colorField } from "../fields/color/colorField.js";
|
|
4
|
+
import { PresetsFromDocArgs, presetsFromDoc } from "../fields/color/presetsFromDoc.js";
|
|
5
|
+
import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
|
|
6
|
+
export { COLOR_CUSTOM_KEY, type ColorFieldClientOptions, type ColorFieldOptions, type ColorFormat, type ColorGlobalConfig, type ColorLinkedOptions, type ColorPreset, type ColorPresetsResolver, type ColorPresetsSource, PRESET_PREFIX, type PresetsFromDocArgs, type ResolvedColorPreset, colorField, normalizePresets, presetsFromDoc, resolvePresets };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { COLOR_CUSTOM_KEY, PRESET_PREFIX } from "../fields/color/options.js";
|
|
2
|
+
import { normalizePresets, resolvePresets } from "../fields/color/resolvePresets.js";
|
|
3
|
+
import { colorField } from "../fields/color/colorField.js";
|
|
4
|
+
import { presetsFromDoc } from "../fields/color/presetsFromDoc.js";
|
|
5
|
+
export { COLOR_CUSTOM_KEY, PRESET_PREFIX, colorField, normalizePresets, presetsFromDoc, resolvePresets };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DecryptFailurePolicy, EncryptedGlobalConfig, KeysConfig } from "../types.js";
|
|
2
|
+
import { EncryptedFieldOptions, EncryptedProtection, EncryptedSourceField } from "../fields/encrypted/types.js";
|
|
3
|
+
import { DEFAULT_KEY_ID, InvalidKeysConfigError } from "../fields/encrypted/crypto/keys.js";
|
|
4
|
+
import { validateEncryptedBoot } from "../fields/encrypted/boot.js";
|
|
5
|
+
import { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed } from "../fields/encrypted/crypto/wire.js";
|
|
6
|
+
import { encryptedField } from "../fields/encrypted/encryptedField.js";
|
|
7
|
+
import { DecryptFailedError } from "../fields/encrypted/hooks.js";
|
|
8
|
+
import { withEncryptedQueryRewrite } from "../fields/encrypted/queryRewrite.js";
|
|
9
|
+
import { rotateEncryptedFields } from "../fields/encrypted/utils/rotateEncryptedFields.js";
|
|
10
|
+
import { decryptAllData } from "../fields/encrypted/utils/decryptAllData.js";
|
|
11
|
+
import { encryptExistingData } from "../fields/encrypted/utils/encryptExistingData.js";
|
|
12
|
+
export { AuthenticationFailedError, DEFAULT_KEY_ID, DecryptFailedError, type DecryptFailurePolicy, type EncryptedFieldOptions, type EncryptedGlobalConfig, type EncryptedProtection, type EncryptedSourceField, InvalidKeysConfigError, type KeysConfig, MalformedCiphertextError, UnknownKeyIdError, decryptAllData, encryptExistingData, encryptedField, isSealed, rotateEncryptedFields, validateEncryptedBoot, withEncryptedQueryRewrite };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DEFAULT_KEY_ID, InvalidKeysConfigError } from "../fields/encrypted/crypto/keys.js";
|
|
2
|
+
import { validateEncryptedBoot } from "../fields/encrypted/boot.js";
|
|
3
|
+
import { AuthenticationFailedError, MalformedCiphertextError, UnknownKeyIdError, isSealed } from "../fields/encrypted/crypto/wire.js";
|
|
4
|
+
import { DecryptFailedError } from "../fields/encrypted/hooks.js";
|
|
5
|
+
import { withEncryptedQueryRewrite } from "../fields/encrypted/queryRewrite.js";
|
|
6
|
+
import { encryptedField } from "../fields/encrypted/encryptedField.js";
|
|
7
|
+
import { decryptAllData } from "../fields/encrypted/utils/decryptAllData.js";
|
|
8
|
+
import { encryptExistingData } from "../fields/encrypted/utils/encryptExistingData.js";
|
|
9
|
+
import { rotateEncryptedFields } from "../fields/encrypted/utils/rotateEncryptedFields.js";
|
|
10
|
+
export { AuthenticationFailedError, DEFAULT_KEY_ID, DecryptFailedError, InvalidKeysConfigError, MalformedCiphertextError, UnknownKeyIdError, decryptAllData, encryptExistingData, encryptedField, isSealed, rotateEncryptedFields, validateEncryptedBoot, withEncryptedQueryRewrite };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IconAdapter } from "../../types.js";
|
|
2
|
+
import { lucideAdapter } from "../../fields/icon/adapters/lucide/adapter.js";
|
|
3
|
+
import { LucideAdapterAssets, LucideAdapterIcon, LucideAdapterNodes } from "../../fields/icon/adapters/lucide/client.js";
|
|
4
|
+
import { lucideRenderer } from "../../fields/icon/adapters/lucide/renderer.js";
|
|
5
|
+
export { type IconAdapter, LucideAdapterAssets, LucideAdapterIcon, LucideAdapterNodes, lucideAdapter, lucideRenderer };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { lucideAdapter } from "../../fields/icon/adapters/lucide/adapter.js";
|
|
2
|
+
import { LucideAdapterAssets, LucideAdapterIcon, LucideAdapterNodes } from "../../fields/icon/adapters/lucide/client.js";
|
|
3
|
+
import { lucideRenderer } from "../../fields/icon/adapters/lucide/renderer.js";
|
|
4
|
+
export { LucideAdapterAssets, LucideAdapterIcon, LucideAdapterNodes, lucideAdapter, lucideRenderer };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IconAdapter } from "../../types.js";
|
|
2
|
+
import { radixAdapter } from "../../fields/icon/adapters/radix/adapter.js";
|
|
3
|
+
import { RadixAdapterAssets, RadixAdapterIcon } from "../../fields/icon/adapters/radix/client.js";
|
|
4
|
+
import { radixRenderer } from "../../fields/icon/adapters/radix/renderer.js";
|
|
5
|
+
export { type IconAdapter, RadixAdapterAssets, RadixAdapterIcon, radixAdapter, radixRenderer };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { radixAdapter } from "../../fields/icon/adapters/radix/adapter.js";
|
|
2
|
+
import { RadixAdapterAssets, RadixAdapterIcon } from "../../fields/icon/adapters/radix/client.js";
|
|
3
|
+
import { radixRenderer } from "../../fields/icon/adapters/radix/renderer.js";
|
|
4
|
+
export { RadixAdapterAssets, RadixAdapterIcon, radixAdapter, radixRenderer };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IconAdapter } from "../../types.js";
|
|
2
|
+
import { tablerAdapter } from "../../fields/icon/adapters/tabler/adapter.js";
|
|
3
|
+
import { TablerAdapterAssets, TablerAdapterIcon, TablerAdapterNodes } from "../../fields/icon/adapters/tabler/client.js";
|
|
4
|
+
import { tablerRenderer } from "../../fields/icon/adapters/tabler/renderer.js";
|
|
5
|
+
export { type IconAdapter, TablerAdapterAssets, TablerAdapterIcon, TablerAdapterNodes, tablerAdapter, tablerRenderer };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { tablerAdapter } from "../../fields/icon/adapters/tabler/adapter.js";
|
|
2
|
+
import { TablerAdapterAssets, TablerAdapterIcon, TablerAdapterNodes } from "../../fields/icon/adapters/tabler/client.js";
|
|
3
|
+
import { tablerRenderer } from "../../fields/icon/adapters/tabler/renderer.js";
|
|
4
|
+
export { TablerAdapterAssets, TablerAdapterIcon, TablerAdapterNodes, tablerAdapter, tablerRenderer };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IconManifest, IconMeta } from "../types.js";
|
|
2
|
+
import { CustomIconSource, GenerateIconManifestOptions, IconImportSpec, IconManifestSource } from "../fields/icon/codegen/types.js";
|
|
3
|
+
import { generateIconManifest } from "../fields/icon/codegen/generate.js";
|
|
4
|
+
export { type CustomIconSource, type GenerateIconManifestOptions, type IconImportSpec, type IconManifest, type IconManifestSource, type IconMeta, generateIconManifest };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IconProps, IconRenderProps, IconRendererAdapter } from "../fields/icon/react/types.js";
|
|
2
|
+
import { createIcon } from "../fields/icon/react/createIcon.js";
|
|
3
|
+
import { createRscIcon } from "../fields/icon/react/createRscIcon.js";
|
|
4
|
+
export { type IconProps, type IconRenderProps, type IconRendererAdapter, createIcon, createRscIcon };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IconAdapter, IconAvailabilityResolver, IconGlobalConfig, IconManifest, IconMeta } from "../types.js";
|
|
2
|
+
import { defineIconAdapter } from "../fields/icon/defineIconAdapter.js";
|
|
3
|
+
import { resolveAvailableLibraries } from "../fields/icon/server/availability.js";
|
|
4
|
+
import { IconFieldOptions, iconField } from "../fields/icon/server/iconField.js";
|
|
5
|
+
import { IconLibraryFieldOptions, iconLibraryField } from "../fields/icon/server/iconLibraryField.js";
|
|
6
|
+
import { getIconLibraryOptions } from "../fields/icon/server/libraryOptions.js";
|
|
7
|
+
import { formatIconValue, parseIconValue, resolveIconValue } from "../fields/icon/shared/value.js";
|
|
8
|
+
export { type IconAdapter, type IconAvailabilityResolver, type IconFieldOptions, type IconGlobalConfig, type IconLibraryFieldOptions, type IconManifest, type IconMeta, defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, parseIconValue, resolveAvailableLibraries, resolveIconValue };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { formatIconValue, parseIconValue, resolveIconValue } from "../fields/icon/shared/value.js";
|
|
2
|
+
import { resolveAvailableLibraries } from "../fields/icon/server/availability.js";
|
|
3
|
+
import { getIconLibraryOptions } from "../fields/icon/server/libraryOptions.js";
|
|
4
|
+
import { defineIconAdapter } from "../fields/icon/defineIconAdapter.js";
|
|
5
|
+
import { iconField } from "../fields/icon/server/iconField.js";
|
|
6
|
+
import { iconLibraryField } from "../fields/icon/server/iconLibraryField.js";
|
|
7
|
+
export { defineIconAdapter, formatIconValue, getIconLibraryOptions, iconField, iconLibraryField, parseIconValue, resolveAvailableLibraries, resolveIconValue };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FieldsPluginRegistry } from "../types.js";
|
|
2
|
+
import { createRscIcon } from "../fields/icon/react/createRscIcon.js";
|
|
3
|
+
import { ColorCell } from "../fields/color/server/ColorCell.js";
|
|
4
|
+
import { ColorFieldServer } from "../fields/color/server/ColorFieldServer.js";
|
|
5
|
+
import { ProtectedCell } from "../fields/encrypted/components/ProtectedCell.js";
|
|
6
|
+
import { ProtectedRichText } from "../fields/encrypted/components/ProtectedRichText.js";
|
|
7
|
+
import { IconCell } from "../fields/icon/rsc/IconCell.js";
|
|
8
|
+
import { IconFieldServer } from "../fields/icon/rsc/IconFieldServer.js";
|
|
9
|
+
import { IconLibrarySelectServer } from "../fields/icon/rsc/IconLibrarySelectServer.js";
|
|
10
|
+
export { ColorCell, ColorFieldServer, type FieldsPluginRegistry, IconCell, IconFieldServer, IconLibrarySelectServer, ProtectedCell, ProtectedRichText, createRscIcon };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ColorCell } from "../fields/color/server/ColorCell.js";
|
|
2
|
+
import { ColorFieldServer } from "../fields/color/server/ColorFieldServer.js";
|
|
3
|
+
import { ProtectedCell } from "../fields/encrypted/components/ProtectedCell.js";
|
|
4
|
+
import { ProtectedRichText } from "../fields/encrypted/components/ProtectedRichText.js";
|
|
5
|
+
import { createRscIcon } from "../fields/icon/react/createRscIcon.js";
|
|
6
|
+
import { IconCell } from "../fields/icon/rsc/IconCell.js";
|
|
7
|
+
import { IconFieldServer } from "../fields/icon/rsc/IconFieldServer.js";
|
|
8
|
+
import { IconLibrarySelectServer } from "../fields/icon/rsc/IconLibrarySelectServer.js";
|
|
9
|
+
export { ColorCell, ColorFieldServer, IconCell, IconFieldServer, IconLibrarySelectServer, ProtectedCell, ProtectedRichText, createRscIcon };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig } from "../types.js";
|
|
2
|
+
import { ColorFieldClientOptions, ColorFieldOptions, ColorLinkedOptions, ColorPresetsResolver, ColorPresetsSource, ResolvedColorPreset } from "../fields/color/options.js";
|
|
3
|
+
import { FieldsPluginOptions } from "../index.js";
|
|
4
|
+
export type { ColorFieldClientOptions, ColorFieldOptions, ColorFormat, ColorGlobalConfig, ColorLinkedOptions, ColorPreset, ColorPresetsResolver, ColorPresetsSource, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginOptions, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig, ResolvedColorPreset };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ColorFieldClientOptions, ResolvedColorPreset } from "../options.js";
|
|
2
|
+
import { TextFieldClientProps } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/color/client/ColorField.d.ts
|
|
5
|
+
type ColorFieldProps = {
|
|
6
|
+
colorOptions: ColorFieldClientOptions;
|
|
7
|
+
presetsLabel?: string;
|
|
8
|
+
resolvedPresets?: ResolvedColorPreset[];
|
|
9
|
+
} & TextFieldClientProps;
|
|
10
|
+
declare const ColorField: React.FC<ColorFieldProps>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ColorField, ColorFieldProps };
|
|
13
|
+
//# sourceMappingURL=ColorField.d.ts.map
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { resolveCommitValue } from "../commitValue.js";
|
|
5
|
+
import { rgbToHsv, toRgb } from "../engine/convert.js";
|
|
6
|
+
import { parseColor } from "../engine/parse.js";
|
|
7
|
+
import { formatColor } from "../engine/format.js";
|
|
8
|
+
import { salvageColor } from "../engine/salvage.js";
|
|
9
|
+
import { PRESET_PREFIX } from "../options.js";
|
|
10
|
+
import { derivePresetChip } from "../presetChip.js";
|
|
11
|
+
import { ColorPickerPanel } from "./ColorPickerPanel.js";
|
|
12
|
+
import { text } from "payload/shared";
|
|
13
|
+
import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, XIcon, fieldBaseClass, useField } from "@payloadcms/ui";
|
|
14
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
15
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
import "./colorField.css";
|
|
18
|
+
//#region src/fields/color/client/ColorField.tsx
|
|
19
|
+
const baseClass = "fields-color";
|
|
20
|
+
const ColorField = (props) => {
|
|
21
|
+
const { colorOptions, field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, name, required }, path: pathFromProps, presetsLabel, readOnly: readOnlyFromProps, resolvedPresets = [] } = props;
|
|
22
|
+
const { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = colorOptions;
|
|
23
|
+
const { t } = useTranslation$1();
|
|
24
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({
|
|
25
|
+
potentiallyStalePath: pathFromProps,
|
|
26
|
+
validate: useCallback((value, options) => {
|
|
27
|
+
if (typeof value === "string" && value !== "") {
|
|
28
|
+
if (linked && value.startsWith("preset:")) {
|
|
29
|
+
if (value.length === 7) return t(keys.missingPreset);
|
|
30
|
+
} else if (!parseColor(value)) return t(keys.invalidColor);
|
|
31
|
+
}
|
|
32
|
+
return text(value, {
|
|
33
|
+
...options,
|
|
34
|
+
name,
|
|
35
|
+
required,
|
|
36
|
+
type: "text"
|
|
37
|
+
});
|
|
38
|
+
}, [
|
|
39
|
+
linked,
|
|
40
|
+
name,
|
|
41
|
+
required,
|
|
42
|
+
t
|
|
43
|
+
])
|
|
44
|
+
});
|
|
45
|
+
const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
|
|
46
|
+
const stringValue = typeof value === "string" ? value : "";
|
|
47
|
+
const presetKey = linked && stringValue.startsWith("preset:") ? stringValue.slice(PRESET_PREFIX.length) : null;
|
|
48
|
+
const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
|
|
49
|
+
const presetMissing = presetKey !== null && !activePreset;
|
|
50
|
+
const cssValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
|
|
51
|
+
const parsed = useMemo(() => cssValue ? parseColor(cssValue) : null, [cssValue]);
|
|
52
|
+
const [displayFormat, setDisplayFormat] = useState(format);
|
|
53
|
+
const displayValue = useMemo(() => {
|
|
54
|
+
if (presetKey !== null || !parsed || displayFormat === format) return stringValue;
|
|
55
|
+
return formatColor(parsed, displayFormat, { alpha });
|
|
56
|
+
}, [
|
|
57
|
+
alpha,
|
|
58
|
+
displayFormat,
|
|
59
|
+
format,
|
|
60
|
+
parsed,
|
|
61
|
+
presetKey,
|
|
62
|
+
stringValue
|
|
63
|
+
]);
|
|
64
|
+
const [draft, setDraft] = useState(displayValue);
|
|
65
|
+
const editingRef = useRef(false);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!editingRef.current) setDraft(displayValue);
|
|
68
|
+
}, [displayValue]);
|
|
69
|
+
const [chipDismissed, setChipDismissed] = useState(false);
|
|
70
|
+
const chip = useMemo(() => derivePresetChip({
|
|
71
|
+
editing: chipDismissed,
|
|
72
|
+
linked,
|
|
73
|
+
presets: resolvedPresets,
|
|
74
|
+
value: stringValue
|
|
75
|
+
}), [
|
|
76
|
+
chipDismissed,
|
|
77
|
+
linked,
|
|
78
|
+
resolvedPresets,
|
|
79
|
+
stringValue
|
|
80
|
+
]);
|
|
81
|
+
const debounceRef = useRef(null);
|
|
82
|
+
useEffect(() => () => {
|
|
83
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
84
|
+
}, []);
|
|
85
|
+
const lastValidRef = useRef(null);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (stringValue === "") return;
|
|
88
|
+
if (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue;
|
|
89
|
+
}, [presetKey, stringValue]);
|
|
90
|
+
const commitText = useCallback((raw) => {
|
|
91
|
+
let normalized = null;
|
|
92
|
+
if (linked && raw.startsWith("preset:")) {
|
|
93
|
+
if (raw.length > 7) normalized = raw;
|
|
94
|
+
} else {
|
|
95
|
+
const parsedRaw = parseColor(raw);
|
|
96
|
+
if (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha });
|
|
97
|
+
}
|
|
98
|
+
const resolution = resolveCommitValue({
|
|
99
|
+
draft: raw,
|
|
100
|
+
isClearable,
|
|
101
|
+
lastValid: lastValidRef.current,
|
|
102
|
+
parsed: normalized
|
|
103
|
+
});
|
|
104
|
+
lastValidRef.current = resolution.lastValid;
|
|
105
|
+
setValue(resolution.value);
|
|
106
|
+
return resolution.reverted;
|
|
107
|
+
}, [
|
|
108
|
+
alpha,
|
|
109
|
+
format,
|
|
110
|
+
isClearable,
|
|
111
|
+
linked,
|
|
112
|
+
setValue
|
|
113
|
+
]);
|
|
114
|
+
const onTextChange = useCallback((event) => {
|
|
115
|
+
const raw = event.target.value;
|
|
116
|
+
editingRef.current = true;
|
|
117
|
+
setChipDismissed(true);
|
|
118
|
+
setDraft(raw);
|
|
119
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
120
|
+
debounceRef.current = setTimeout(() => commitText(raw), 250);
|
|
121
|
+
}, [commitText]);
|
|
122
|
+
const onTextBlur = useCallback(() => {
|
|
123
|
+
if (debounceRef.current) {
|
|
124
|
+
clearTimeout(debounceRef.current);
|
|
125
|
+
debounceRef.current = null;
|
|
126
|
+
}
|
|
127
|
+
if (editingRef.current) {
|
|
128
|
+
editingRef.current = false;
|
|
129
|
+
const salvaged = !(linked && draft.startsWith("preset:")) && draft.trim() !== "" && !parseColor(draft) ? salvageColor(draft) : null;
|
|
130
|
+
if (commitText(salvaged ?? draft)) setDraft(displayValue);
|
|
131
|
+
else if (salvaged !== null) {
|
|
132
|
+
const parsedSalvaged = parseColor(salvaged);
|
|
133
|
+
setDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
setChipDismissed(false);
|
|
137
|
+
}, [
|
|
138
|
+
alpha,
|
|
139
|
+
commitText,
|
|
140
|
+
displayFormat,
|
|
141
|
+
displayValue,
|
|
142
|
+
draft,
|
|
143
|
+
linked
|
|
144
|
+
]);
|
|
145
|
+
const onTextKeyDown = useCallback((event) => {
|
|
146
|
+
if (!chip || isReadOnly) return;
|
|
147
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
setDraft("");
|
|
150
|
+
if (isClearable) setValue(null);
|
|
151
|
+
else {
|
|
152
|
+
editingRef.current = true;
|
|
153
|
+
setChipDismissed(true);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, [
|
|
157
|
+
chip,
|
|
158
|
+
isClearable,
|
|
159
|
+
isReadOnly,
|
|
160
|
+
setValue
|
|
161
|
+
]);
|
|
162
|
+
const commitCss = useCallback((css) => {
|
|
163
|
+
const parsedCss = parseColor(css);
|
|
164
|
+
if (parsedCss) setValue(formatColor(parsedCss, format, { alpha }));
|
|
165
|
+
}, [
|
|
166
|
+
alpha,
|
|
167
|
+
format,
|
|
168
|
+
setValue
|
|
169
|
+
]);
|
|
170
|
+
const initialHsva = useMemo(() => {
|
|
171
|
+
if (!parsed) return null;
|
|
172
|
+
const rgb = toRgb(parsed);
|
|
173
|
+
const hsv = rgbToHsv(rgb);
|
|
174
|
+
return {
|
|
175
|
+
a: rgb.alpha,
|
|
176
|
+
h: hsv.h,
|
|
177
|
+
s: hsv.s,
|
|
178
|
+
v: hsv.v
|
|
179
|
+
};
|
|
180
|
+
}, [parsed]);
|
|
181
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
182
|
+
const swatchCss = parsed ? formatColor(parsed, "rgb") : null;
|
|
183
|
+
const swatch = /* @__PURE__ */ jsxs("span", {
|
|
184
|
+
className: `${baseClass}__swatch ${baseClass}__checker`,
|
|
185
|
+
children: [
|
|
186
|
+
swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
187
|
+
className: `${baseClass}__swatch-color`,
|
|
188
|
+
style: { background: swatchCss }
|
|
189
|
+
}) : null,
|
|
190
|
+
presetMissing && !swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
191
|
+
className: `${baseClass}__swatch-color`,
|
|
192
|
+
"data-missing": "true"
|
|
193
|
+
}) : null,
|
|
194
|
+
isReadOnly ? null : /* @__PURE__ */ jsx("span", {
|
|
195
|
+
className: `${baseClass}__sr-only`,
|
|
196
|
+
children: t(keys.pickColor)
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
});
|
|
200
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
201
|
+
className: [
|
|
202
|
+
fieldBaseClass,
|
|
203
|
+
baseClass,
|
|
204
|
+
className,
|
|
205
|
+
showError && "error",
|
|
206
|
+
isReadOnly && "read-only"
|
|
207
|
+
].filter(Boolean).join(" "),
|
|
208
|
+
style: styles,
|
|
209
|
+
children: [/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
210
|
+
CustomComponent: Label,
|
|
211
|
+
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
212
|
+
label,
|
|
213
|
+
localized,
|
|
214
|
+
path,
|
|
215
|
+
required
|
|
216
|
+
})
|
|
217
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
218
|
+
className: `${fieldBaseClass}__wrap`,
|
|
219
|
+
children: [
|
|
220
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
221
|
+
CustomComponent: ErrorComponent,
|
|
222
|
+
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
223
|
+
path,
|
|
224
|
+
showError
|
|
225
|
+
})
|
|
226
|
+
}),
|
|
227
|
+
BeforeInput,
|
|
228
|
+
/* @__PURE__ */ jsxs("div", {
|
|
229
|
+
className: `${baseClass}__container`,
|
|
230
|
+
children: [
|
|
231
|
+
isReadOnly ? /* @__PURE__ */ jsx("span", {
|
|
232
|
+
className: `${baseClass}__swatch-button ${baseClass}__swatch-button--static`,
|
|
233
|
+
children: swatch
|
|
234
|
+
}) : /* @__PURE__ */ jsx(Popup, {
|
|
235
|
+
button: swatch,
|
|
236
|
+
buttonClassName: `${baseClass}__swatch-button`,
|
|
237
|
+
buttonType: "custom",
|
|
238
|
+
caret: false,
|
|
239
|
+
className: `${baseClass}__popup`,
|
|
240
|
+
horizontalAlign: "left",
|
|
241
|
+
render: ({ close }) => /* @__PURE__ */ jsx(ColorPickerPanel, {
|
|
242
|
+
activePresetKey: activePreset?.key ?? null,
|
|
243
|
+
alphaEnabled: alpha,
|
|
244
|
+
close,
|
|
245
|
+
displayFormat,
|
|
246
|
+
enableEyedropper,
|
|
247
|
+
initial: initialHsva,
|
|
248
|
+
onPickCss: commitCss,
|
|
249
|
+
onPickPreset: (preset) => {
|
|
250
|
+
if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
|
|
251
|
+
else commitCss(preset.value);
|
|
252
|
+
},
|
|
253
|
+
presetMissing,
|
|
254
|
+
presets: resolvedPresets,
|
|
255
|
+
presetsLabel: presetsLabel ?? t(keys.presets),
|
|
256
|
+
setDisplayFormat
|
|
257
|
+
}),
|
|
258
|
+
size: "fit-content",
|
|
259
|
+
verticalAlign: "bottom"
|
|
260
|
+
}),
|
|
261
|
+
chip ? /* @__PURE__ */ jsxs("span", {
|
|
262
|
+
className: `${baseClass}__chip`,
|
|
263
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
264
|
+
className: `${baseClass}__chip-swatch ${baseClass}__checker`,
|
|
265
|
+
children: [swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
266
|
+
className: `${baseClass}__chip-color`,
|
|
267
|
+
style: { background: swatchCss }
|
|
268
|
+
}) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
269
|
+
className: `${baseClass}__chip-color`,
|
|
270
|
+
"data-missing": "true"
|
|
271
|
+
}) : null]
|
|
272
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
273
|
+
className: `${baseClass}__chip-label`,
|
|
274
|
+
children: chip.label
|
|
275
|
+
})]
|
|
276
|
+
}) : null,
|
|
277
|
+
/* @__PURE__ */ jsx("input", {
|
|
278
|
+
className: `${baseClass}__input`,
|
|
279
|
+
id: `field-${path?.replace(/\./g, "__")}`,
|
|
280
|
+
name: path,
|
|
281
|
+
onBlur: onTextBlur,
|
|
282
|
+
onChange: onTextChange,
|
|
283
|
+
onKeyDown: onTextKeyDown,
|
|
284
|
+
placeholder: chip || typeof placeholder !== "string" ? void 0 : placeholder,
|
|
285
|
+
readOnly: isReadOnly,
|
|
286
|
+
type: "text",
|
|
287
|
+
value: chip ? "" : draft
|
|
288
|
+
}),
|
|
289
|
+
/* @__PURE__ */ jsx("span", {
|
|
290
|
+
"aria-hidden": "true",
|
|
291
|
+
className: `${baseClass}__badge`,
|
|
292
|
+
children: chip ? t(keys.preset) : displayFormat
|
|
293
|
+
}),
|
|
294
|
+
isClearable && !required && !isReadOnly && stringValue !== "" ? /* @__PURE__ */ jsx("button", {
|
|
295
|
+
"aria-label": t(keys.clearColor),
|
|
296
|
+
className: `${baseClass}__clear`,
|
|
297
|
+
onClick: () => {
|
|
298
|
+
setDraft("");
|
|
299
|
+
setValue(null);
|
|
300
|
+
},
|
|
301
|
+
type: "button",
|
|
302
|
+
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
303
|
+
}) : null
|
|
304
|
+
]
|
|
305
|
+
}),
|
|
306
|
+
AfterInput,
|
|
307
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
308
|
+
CustomComponent: Description,
|
|
309
|
+
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
310
|
+
description,
|
|
311
|
+
path
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
]
|
|
315
|
+
})]
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
//#endregion
|
|
319
|
+
export { ColorField };
|
|
320
|
+
|
|
321
|
+
//# sourceMappingURL=ColorField.js.map
|