@10x-media/fields 0.1.0-beta.1 → 0.1.0-beta.10
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 +120 -0
- package/README.md +7 -3
- package/dist/exports/client.d.ts +10 -1
- package/dist/exports/client.js +9 -1
- package/dist/exports/color-utils.d.ts +2 -1
- package/dist/exports/color-utils.js +2 -1
- package/dist/exports/color.d.ts +2 -1
- package/dist/exports/color.js +2 -1
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- package/dist/exports/measurement-utils.d.ts +9 -0
- package/dist/exports/measurement-utils.js +8 -0
- package/dist/exports/measurement.d.ts +11 -0
- package/dist/exports/measurement.js +10 -0
- package/dist/exports/phone-utils.d.ts +4 -0
- package/dist/exports/phone-utils.js +4 -0
- package/dist/exports/phone.d.ts +6 -0
- package/dist/exports/phone.js +3 -0
- package/dist/exports/rsc.d.ts +5 -1
- package/dist/exports/rsc.js +5 -1
- package/dist/exports/types.d.ts +3 -2
- package/dist/fields/color/client/ColorField.d.ts +2 -0
- package/dist/fields/color/client/ColorField.js +35 -293
- package/dist/fields/color/client/ColorField.js.map +1 -1
- package/dist/fields/color/client/ColorInput.d.ts +44 -0
- package/dist/fields/color/client/ColorInput.js +374 -0
- package/dist/fields/color/client/ColorInput.js.map +1 -0
- package/dist/fields/color/client/ColorPickerPanel.d.ts +3 -1
- package/dist/fields/color/client/ColorPickerPanel.js +29 -4
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +30 -0
- package/dist/fields/color/colorField.js +36 -8
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/presetChip.js +10 -9
- package/dist/fields/color/presetChip.js.map +1 -1
- package/dist/fields/color/presetReference.d.ts +13 -0
- package/dist/fields/color/presetReference.js +94 -0
- package/dist/fields/color/presetReference.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +7 -1
- package/dist/fields/color/server/ColorCell.js.map +1 -1
- package/dist/fields/color/server/colorCell.css +5 -0
- package/dist/fields/color/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- package/dist/fields/encrypted/boot.js +2 -1
- package/dist/fields/encrypted/boot.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedInput.js +4 -1
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
- package/dist/fields/encrypted/components/EncryptedTextarea.js +6 -2
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +15 -6
- package/dist/fields/encrypted/components/ProtectedCell.js +37 -8
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -1
- package/dist/fields/encrypted/components/ProtectedField.css +134 -39
- package/dist/fields/encrypted/components/ProtectedField.d.ts +3 -0
- package/dist/fields/encrypted/components/ProtectedField.js +14 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
- package/dist/fields/encrypted/components/WriteOnlyActions.js +65 -0
- package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js +286 -0
- package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js +69 -0
- package/dist/fields/encrypted/components/writeOnlyIntent.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +10 -1
- package/dist/fields/encrypted/crypto/wire.js +1 -1
- package/dist/fields/encrypted/encryptedField.js +63 -6
- package/dist/fields/encrypted/encryptedField.js.map +1 -1
- package/dist/fields/encrypted/generateSecret.d.ts +10 -0
- package/dist/fields/encrypted/generateSecret.js +41 -0
- package/dist/fields/encrypted/generateSecret.js.map +1 -0
- package/dist/fields/encrypted/hint.js +67 -0
- package/dist/fields/encrypted/hint.js.map +1 -0
- package/dist/fields/encrypted/hooks.js +59 -31
- package/dist/fields/encrypted/hooks.js.map +1 -1
- package/dist/fields/encrypted/queryRewrite.d.ts +10 -2
- package/dist/fields/encrypted/queryRewrite.js +34 -8
- package/dist/fields/encrypted/queryRewrite.js.map +1 -1
- package/dist/fields/encrypted/rawRead.d.ts +24 -0
- package/dist/fields/encrypted/rawRead.js +40 -0
- package/dist/fields/encrypted/rawRead.js.map +1 -0
- package/dist/fields/encrypted/scan.js +21 -4
- package/dist/fields/encrypted/scan.js.map +1 -1
- package/dist/fields/encrypted/types.d.ts +67 -2
- package/dist/fields/encrypted/types.js +8 -1
- package/dist/fields/encrypted/types.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptAllData.js +2 -2
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -1
- package/dist/fields/encrypted/utils/decryptFieldValue.d.ts +30 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js +56 -0
- package/dist/fields/encrypted/utils/decryptFieldValue.js.map +1 -0
- package/dist/fields/encrypted/utils/readEncryptedField.d.ts +51 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js +96 -0
- package/dist/fields/encrypted/utils/readEncryptedField.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -1
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
- package/dist/fields/icon/client/icon-field.css +4 -2
- package/dist/fields/icon/codegen/emit.js +2 -2
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
- package/dist/fields/icon/shared/iconLabel.js +1 -1
- package/dist/fields/icon/shared/iconLabel.js.map +1 -1
- package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
- package/dist/fields/measurement/client/MeasurementCell.js +47 -0
- package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementField.d.ts +13 -0
- package/dist/fields/measurement/client/MeasurementField.js +70 -0
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementInput.d.ts +42 -0
- package/dist/fields/measurement/client/MeasurementInput.js +327 -0
- package/dist/fields/measurement/client/MeasurementInput.js.map +1 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
- package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
- package/dist/fields/measurement/client/editModel.js +124 -0
- package/dist/fields/measurement/client/editModel.js.map +1 -0
- package/dist/fields/measurement/client/measurementCell.css +4 -0
- package/dist/fields/measurement/client/measurementField.css +215 -0
- package/dist/fields/measurement/client/useMeasurementModel.d.ts +19 -0
- package/dist/fields/measurement/client/useMeasurementModel.js +85 -0
- package/dist/fields/measurement/client/useMeasurementModel.js.map +1 -0
- package/dist/fields/measurement/engine/convert.d.ts +8 -0
- package/dist/fields/measurement/engine/convert.js +21 -0
- package/dist/fields/measurement/engine/convert.js.map +1 -0
- package/dist/fields/measurement/engine/format.d.ts +37 -0
- package/dist/fields/measurement/engine/format.js +156 -0
- package/dist/fields/measurement/engine/format.js.map +1 -0
- package/dist/fields/measurement/engine/locale.d.ts +25 -0
- package/dist/fields/measurement/engine/locale.js +79 -0
- package/dist/fields/measurement/engine/locale.js.map +1 -0
- package/dist/fields/measurement/engine/precision.d.ts +34 -0
- package/dist/fields/measurement/engine/precision.js +63 -0
- package/dist/fields/measurement/engine/precision.js.map +1 -0
- package/dist/fields/measurement/engine/registry.d.ts +55 -0
- package/dist/fields/measurement/engine/registry.js +117 -0
- package/dist/fields/measurement/engine/registry.js.map +1 -0
- package/dist/fields/measurement/engine/units.d.ts +178 -0
- package/dist/fields/measurement/engine/units.js +198 -0
- package/dist/fields/measurement/engine/units.js.map +1 -0
- package/dist/fields/measurement/measurementField.d.ts +17 -0
- package/dist/fields/measurement/measurementField.js +139 -0
- package/dist/fields/measurement/measurementField.js.map +1 -0
- package/dist/fields/measurement/options.d.ts +76 -0
- package/dist/fields/measurement/options.js +9 -0
- package/dist/fields/measurement/options.js.map +1 -0
- package/dist/fields/measurement/presets.d.ts +117 -0
- package/dist/fields/measurement/presets.js +136 -0
- package/dist/fields/measurement/presets.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
- package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
- package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
- package/dist/fields/measurement/server/getUserUnits.js +39 -0
- package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
- package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
- package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
- package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
- package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
- package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
- package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/client/editModel.js +86 -0
- package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
- package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
- package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
- package/dist/fields/phoneNumber/engine/countries.js +68 -0
- package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
- package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
- package/dist/fields/phoneNumber/engine/draft.js +72 -0
- package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
- package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
- package/dist/fields/phoneNumber/engine/metadata.js +32 -0
- package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
- package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
- package/dist/fields/phoneNumber/engine/phone.js +59 -0
- package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
- package/dist/fields/phoneNumber/options.d.ts +72 -0
- package/dist/fields/phoneNumber/options.js +37 -0
- package/dist/fields/phoneNumber/options.js.map +1 -0
- package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
- package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
- package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
- package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
- package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
- package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
- package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
- package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +62 -0
- package/dist/translations/ar.js.map +1 -0
- package/dist/translations/de.js +19 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +19 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +62 -0
- package/dist/translations/es.js.map +1 -0
- package/dist/translations/fr.js +62 -0
- package/dist/translations/fr.js.map +1 -0
- package/dist/translations/id.js +62 -0
- package/dist/translations/id.js.map +1 -0
- package/dist/translations/index.d.ts +10 -1
- package/dist/translations/index.js +19 -1
- package/dist/translations/index.js.map +1 -1
- package/dist/translations/keys.d.ts +19 -1
- package/dist/translations/keys.js +20 -2
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +62 -0
- package/dist/translations/ko.js.map +1 -0
- package/dist/translations/pt.js +62 -0
- package/dist/translations/pt.js.map +1 -0
- package/dist/translations/ru.js +62 -0
- package/dist/translations/ru.js.map +1 -0
- package/dist/translations/uk.js +62 -0
- package/dist/translations/uk.js.map +1 -0
- package/dist/translations/zh.js +62 -0
- package/dist/translations/zh.js.map +1 -0
- package/dist/types.d.ts +41 -1
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +28 -6
- package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { keys } from "../../../translations/keys.js";
|
|
3
3
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 { flatValue, swatchBackground } from "../schemeValue.js";
|
|
12
|
-
import { ColorPickerPanel } from "./ColorPickerPanel.js";
|
|
4
|
+
import { colorValueIssue } from "../valueIssue.js";
|
|
5
|
+
import { ColorInput } from "./ColorInput.js";
|
|
13
6
|
import { text } from "payload/shared";
|
|
14
|
-
import {
|
|
7
|
+
import { useField } from "@payloadcms/ui";
|
|
15
8
|
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
16
|
-
import { useCallback,
|
|
17
|
-
import { jsx
|
|
18
|
-
import "./colorField.css";
|
|
9
|
+
import { useCallback, useMemo } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
11
|
//#region src/fields/color/client/ColorField.tsx
|
|
20
|
-
const
|
|
12
|
+
const NO_PRESETS = [];
|
|
13
|
+
/** `ColorInput` bound to the document form through `useField`, with the field's validation. */
|
|
21
14
|
const ColorField = (props) => {
|
|
22
|
-
const { colorOptions, field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, name, required }, path: pathFromProps, presetsLabel, readOnly: readOnlyFromProps, resolvedPresets =
|
|
23
|
-
const {
|
|
15
|
+
const { colorOptions, field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, name, required }, path: pathFromProps, presetsLabel, readOnly: readOnlyFromProps, resolvedPresets = NO_PRESETS } = props;
|
|
16
|
+
const { linked } = colorOptions;
|
|
24
17
|
const { t } = useTranslation$1();
|
|
25
18
|
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({
|
|
26
19
|
potentiallyStalePath: pathFromProps,
|
|
27
20
|
validate: useCallback((value, options) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const issue = colorValueIssue(value, {
|
|
22
|
+
linked,
|
|
23
|
+
presets: resolvedPresets
|
|
24
|
+
});
|
|
25
|
+
if (issue) return t(keys[issue]);
|
|
33
26
|
return text(value, {
|
|
34
27
|
...options,
|
|
35
28
|
name,
|
|
@@ -40,284 +33,33 @@ const ColorField = (props) => {
|
|
|
40
33
|
linked,
|
|
41
34
|
name,
|
|
42
35
|
required,
|
|
36
|
+
resolvedPresets,
|
|
43
37
|
t
|
|
44
38
|
])
|
|
45
39
|
});
|
|
46
40
|
const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
|
|
47
|
-
const stringValue = typeof value === "string" ? value : "";
|
|
48
|
-
const presetKey = linked && stringValue.startsWith("preset:") ? stringValue.slice(PRESET_PREFIX.length) : null;
|
|
49
|
-
const activePreset = presetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : void 0;
|
|
50
|
-
const presetMissing = presetKey !== null && !activePreset;
|
|
51
|
-
const rawValue = presetKey !== null ? activePreset?.value ?? linkedFallback : stringValue || null;
|
|
52
|
-
const cssValue = flatValue(rawValue);
|
|
53
|
-
const parsed = useMemo(() => cssValue ? parseColor(cssValue) : null, [cssValue]);
|
|
54
|
-
const [displayFormat, setDisplayFormat] = useState(format);
|
|
55
|
-
const displayValue = useMemo(() => {
|
|
56
|
-
if (presetKey !== null || !parsed || displayFormat === format) return stringValue;
|
|
57
|
-
return formatColor(parsed, displayFormat, { alpha });
|
|
58
|
-
}, [
|
|
59
|
-
alpha,
|
|
60
|
-
displayFormat,
|
|
61
|
-
format,
|
|
62
|
-
parsed,
|
|
63
|
-
presetKey,
|
|
64
|
-
stringValue
|
|
65
|
-
]);
|
|
66
|
-
const [draft, setDraft] = useState(displayValue);
|
|
67
|
-
const editingRef = useRef(false);
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (!editingRef.current) setDraft(displayValue);
|
|
70
|
-
}, [displayValue]);
|
|
71
|
-
const [chipDismissed, setChipDismissed] = useState(false);
|
|
72
|
-
const chip = useMemo(() => derivePresetChip({
|
|
73
|
-
editing: chipDismissed,
|
|
74
|
-
linked,
|
|
75
|
-
presets: resolvedPresets,
|
|
76
|
-
value: stringValue
|
|
77
|
-
}), [
|
|
78
|
-
chipDismissed,
|
|
79
|
-
linked,
|
|
80
|
-
resolvedPresets,
|
|
81
|
-
stringValue
|
|
82
|
-
]);
|
|
83
|
-
const debounceRef = useRef(null);
|
|
84
|
-
useEffect(() => () => {
|
|
85
|
-
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
86
|
-
}, []);
|
|
87
|
-
const lastValidRef = useRef(null);
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (stringValue === "") return;
|
|
90
|
-
if (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue;
|
|
91
|
-
}, [presetKey, stringValue]);
|
|
92
|
-
const commitText = useCallback((raw) => {
|
|
93
|
-
let normalized = null;
|
|
94
|
-
if (linked && raw.startsWith("preset:")) {
|
|
95
|
-
if (raw.length > 7) normalized = raw;
|
|
96
|
-
} else {
|
|
97
|
-
const parsedRaw = parseColor(raw);
|
|
98
|
-
if (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha });
|
|
99
|
-
}
|
|
100
|
-
const resolution = resolveCommitValue({
|
|
101
|
-
draft: raw,
|
|
102
|
-
isClearable,
|
|
103
|
-
lastValid: lastValidRef.current,
|
|
104
|
-
parsed: normalized
|
|
105
|
-
});
|
|
106
|
-
lastValidRef.current = resolution.lastValid;
|
|
107
|
-
setValue(resolution.value);
|
|
108
|
-
return resolution.reverted;
|
|
109
|
-
}, [
|
|
110
|
-
alpha,
|
|
111
|
-
format,
|
|
112
|
-
isClearable,
|
|
113
|
-
linked,
|
|
114
|
-
setValue
|
|
115
|
-
]);
|
|
116
|
-
const onTextChange = useCallback((event) => {
|
|
117
|
-
const raw = event.target.value;
|
|
118
|
-
editingRef.current = true;
|
|
119
|
-
setChipDismissed(true);
|
|
120
|
-
setDraft(raw);
|
|
121
|
-
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
122
|
-
debounceRef.current = setTimeout(() => commitText(raw), 250);
|
|
123
|
-
}, [commitText]);
|
|
124
|
-
const onTextBlur = useCallback(() => {
|
|
125
|
-
if (debounceRef.current) {
|
|
126
|
-
clearTimeout(debounceRef.current);
|
|
127
|
-
debounceRef.current = null;
|
|
128
|
-
}
|
|
129
|
-
if (editingRef.current) {
|
|
130
|
-
editingRef.current = false;
|
|
131
|
-
const salvaged = !(linked && draft.startsWith("preset:")) && draft.trim() !== "" && !parseColor(draft) ? salvageColor(draft) : null;
|
|
132
|
-
if (commitText(salvaged ?? draft)) setDraft(displayValue);
|
|
133
|
-
else if (salvaged !== null) {
|
|
134
|
-
const parsedSalvaged = parseColor(salvaged);
|
|
135
|
-
setDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
setChipDismissed(false);
|
|
139
|
-
}, [
|
|
140
|
-
alpha,
|
|
141
|
-
commitText,
|
|
142
|
-
displayFormat,
|
|
143
|
-
displayValue,
|
|
144
|
-
draft,
|
|
145
|
-
linked
|
|
146
|
-
]);
|
|
147
|
-
const onTextKeyDown = useCallback((event) => {
|
|
148
|
-
if (!chip || isReadOnly) return;
|
|
149
|
-
if (event.key === "Backspace" || event.key === "Delete") {
|
|
150
|
-
event.preventDefault();
|
|
151
|
-
setDraft("");
|
|
152
|
-
if (isClearable) setValue(null);
|
|
153
|
-
else {
|
|
154
|
-
editingRef.current = true;
|
|
155
|
-
setChipDismissed(true);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}, [
|
|
159
|
-
chip,
|
|
160
|
-
isClearable,
|
|
161
|
-
isReadOnly,
|
|
162
|
-
setValue
|
|
163
|
-
]);
|
|
164
|
-
const commitCss = useCallback((css) => {
|
|
165
|
-
const parsedCss = parseColor(css);
|
|
166
|
-
if (parsedCss) setValue(formatColor(parsedCss, format, { alpha }));
|
|
167
|
-
}, [
|
|
168
|
-
alpha,
|
|
169
|
-
format,
|
|
170
|
-
setValue
|
|
171
|
-
]);
|
|
172
|
-
const initialHsva = useMemo(() => {
|
|
173
|
-
if (!parsed) return null;
|
|
174
|
-
const rgb = toRgb(parsed);
|
|
175
|
-
const hsv = rgbToHsv(rgb);
|
|
176
|
-
return {
|
|
177
|
-
a: rgb.alpha,
|
|
178
|
-
h: hsv.h,
|
|
179
|
-
s: hsv.s,
|
|
180
|
-
v: hsv.v
|
|
181
|
-
};
|
|
182
|
-
}, [parsed]);
|
|
183
41
|
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
className: [
|
|
204
|
-
fieldBaseClass,
|
|
205
|
-
baseClass,
|
|
206
|
-
className,
|
|
207
|
-
showError && "error",
|
|
208
|
-
isReadOnly && "read-only"
|
|
209
|
-
].filter(Boolean).join(" "),
|
|
42
|
+
return /* @__PURE__ */ jsx(ColorInput, {
|
|
43
|
+
AfterInput,
|
|
44
|
+
BeforeInput,
|
|
45
|
+
className,
|
|
46
|
+
Description,
|
|
47
|
+
description,
|
|
48
|
+
Error: ErrorComponent,
|
|
49
|
+
Label,
|
|
50
|
+
label,
|
|
51
|
+
localized,
|
|
52
|
+
onChange: setValue,
|
|
53
|
+
options: colorOptions,
|
|
54
|
+
path,
|
|
55
|
+
placeholder: typeof placeholder === "string" ? placeholder : void 0,
|
|
56
|
+
presets: resolvedPresets,
|
|
57
|
+
presetsLabel,
|
|
58
|
+
readOnly: isReadOnly,
|
|
59
|
+
required,
|
|
60
|
+
showError,
|
|
210
61
|
style: styles,
|
|
211
|
-
|
|
212
|
-
CustomComponent: Label,
|
|
213
|
-
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
214
|
-
label,
|
|
215
|
-
localized,
|
|
216
|
-
path,
|
|
217
|
-
required
|
|
218
|
-
})
|
|
219
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
220
|
-
className: `${fieldBaseClass}__wrap`,
|
|
221
|
-
children: [
|
|
222
|
-
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
223
|
-
CustomComponent: ErrorComponent,
|
|
224
|
-
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
225
|
-
path,
|
|
226
|
-
showError
|
|
227
|
-
})
|
|
228
|
-
}),
|
|
229
|
-
BeforeInput,
|
|
230
|
-
/* @__PURE__ */ jsxs("div", {
|
|
231
|
-
className: `${baseClass}__container`,
|
|
232
|
-
children: [
|
|
233
|
-
isReadOnly ? /* @__PURE__ */ jsx("span", {
|
|
234
|
-
className: `${baseClass}__swatch-button ${baseClass}__swatch-button--static`,
|
|
235
|
-
children: swatch
|
|
236
|
-
}) : /* @__PURE__ */ jsx(Popup, {
|
|
237
|
-
button: swatch,
|
|
238
|
-
buttonClassName: `${baseClass}__swatch-button`,
|
|
239
|
-
buttonType: "custom",
|
|
240
|
-
caret: false,
|
|
241
|
-
className: `${baseClass}__popup`,
|
|
242
|
-
horizontalAlign: "left",
|
|
243
|
-
render: ({ close }) => /* @__PURE__ */ jsx(ColorPickerPanel, {
|
|
244
|
-
activePresetKey: activePreset?.key ?? null,
|
|
245
|
-
alphaEnabled: alpha,
|
|
246
|
-
close,
|
|
247
|
-
displayFormat,
|
|
248
|
-
enableEyedropper,
|
|
249
|
-
initial: initialHsva,
|
|
250
|
-
onPickCss: commitCss,
|
|
251
|
-
onPickPreset: (preset) => {
|
|
252
|
-
if (linked) setValue(`${PRESET_PREFIX}${preset.key}`);
|
|
253
|
-
else {
|
|
254
|
-
const flat = flatValue(preset.value);
|
|
255
|
-
if (flat) commitCss(flat);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
presetMissing,
|
|
259
|
-
presets: resolvedPresets,
|
|
260
|
-
presetsLabel: presetsLabel ?? t(keys.presets),
|
|
261
|
-
setDisplayFormat
|
|
262
|
-
}),
|
|
263
|
-
size: "fit-content",
|
|
264
|
-
verticalAlign: "bottom"
|
|
265
|
-
}),
|
|
266
|
-
chip ? /* @__PURE__ */ jsxs("span", {
|
|
267
|
-
className: `${baseClass}__chip`,
|
|
268
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
269
|
-
className: `${baseClass}__chip-swatch ${baseClass}__checker`,
|
|
270
|
-
children: [swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
271
|
-
className: `${baseClass}__chip-color`,
|
|
272
|
-
style: { background: swatchCss }
|
|
273
|
-
}) : null, chip.missing && !swatchCss ? /* @__PURE__ */ jsx("span", {
|
|
274
|
-
className: `${baseClass}__chip-color`,
|
|
275
|
-
"data-missing": "true"
|
|
276
|
-
}) : null]
|
|
277
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
278
|
-
className: `${baseClass}__chip-label`,
|
|
279
|
-
children: chip.label
|
|
280
|
-
})]
|
|
281
|
-
}) : null,
|
|
282
|
-
/* @__PURE__ */ jsx("input", {
|
|
283
|
-
className: `${baseClass}__input`,
|
|
284
|
-
id: `field-${path?.replace(/\./g, "__")}`,
|
|
285
|
-
name: path,
|
|
286
|
-
onBlur: onTextBlur,
|
|
287
|
-
onChange: onTextChange,
|
|
288
|
-
onKeyDown: onTextKeyDown,
|
|
289
|
-
placeholder: chip || typeof placeholder !== "string" ? void 0 : placeholder,
|
|
290
|
-
readOnly: isReadOnly,
|
|
291
|
-
type: "text",
|
|
292
|
-
value: chip ? "" : draft
|
|
293
|
-
}),
|
|
294
|
-
/* @__PURE__ */ jsx("span", {
|
|
295
|
-
"aria-hidden": "true",
|
|
296
|
-
className: `${baseClass}__badge`,
|
|
297
|
-
children: chip ? t(keys.preset) : displayFormat
|
|
298
|
-
}),
|
|
299
|
-
isClearable && !required && !isReadOnly && stringValue !== "" ? /* @__PURE__ */ jsx("button", {
|
|
300
|
-
"aria-label": t(keys.clearColor),
|
|
301
|
-
className: `${baseClass}__clear`,
|
|
302
|
-
onClick: () => {
|
|
303
|
-
setDraft("");
|
|
304
|
-
setValue(null);
|
|
305
|
-
},
|
|
306
|
-
type: "button",
|
|
307
|
-
children: /* @__PURE__ */ jsx(XIcon, {})
|
|
308
|
-
}) : null
|
|
309
|
-
]
|
|
310
|
-
}),
|
|
311
|
-
AfterInput,
|
|
312
|
-
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
313
|
-
CustomComponent: Description,
|
|
314
|
-
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
315
|
-
description,
|
|
316
|
-
path
|
|
317
|
-
})
|
|
318
|
-
})
|
|
319
|
-
]
|
|
320
|
-
})]
|
|
62
|
+
value
|
|
321
63
|
});
|
|
322
64
|
};
|
|
323
65
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tuseField,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFormat } from '../../../types'\nimport { resolveCommitValue } from '../commitValue'\nimport { formatColor, parseColor, rgbToHsv, salvageColor, toRgb } from '../engine'\nimport { type ColorFieldClientOptions, PRESET_PREFIX, type ResolvedColorPreset } from '../options'\nimport { derivePresetChip } from '../presetChip'\nimport { flatValue, swatchBackground } from '../schemeValue'\nimport { ColorPickerPanel, type Hsva } from './ColorPickerPanel'\nimport './colorField.css'\n\nconst baseClass = 'fields-color'\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = [],\n\t} = props\n\tconst { alpha, enableEyedropper, format, isClearable, linked, linkedFallback } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'string' && value !== '') {\n\t\t\t\tif (linked && value.startsWith(PRESET_PREFIX)) {\n\t\t\t\t\tif (value.length === PRESET_PREFIX.length) return t(keys.missingPreset)\n\t\t\t\t} else if (!parseColor(value)) {\n\t\t\t\t\treturn t(keys.invalidColor)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, t]\n\t)\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, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\n\tconst stringValue = typeof value === 'string' ? value : ''\n\tconst presetKey =\n\t\tlinked && stringValue.startsWith(PRESET_PREFIX) ? stringValue.slice(PRESET_PREFIX.length) : null\n\tconst activePreset =\n\t\tpresetKey !== null ? resolvedPresets.find((preset) => preset.key === presetKey) : undefined\n\tconst presetMissing = presetKey !== null && !activePreset\n\tconst rawValue: unknown =\n\t\tpresetKey !== null ? (activePreset?.value ?? linkedFallback) : stringValue || null\n\tconst cssValue = flatValue(rawValue)\n\tconst parsed = useMemo(() => (cssValue ? parseColor(cssValue) : null), [cssValue])\n\n\tconst [displayFormat, setDisplayFormat] = useState<ColorFormat>(format)\n\tconst displayValue = useMemo(() => {\n\t\tif (presetKey !== null || !parsed || displayFormat === format) return stringValue\n\t\treturn formatColor(parsed, displayFormat, { alpha })\n\t}, [alpha, displayFormat, format, parsed, presetKey, stringValue])\n\n\tconst [draft, setDraft] = useState(displayValue)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(displayValue)\n\t}, [displayValue])\n\n\t// Typing dismisses the chip into plain text entry; blur re-derives it from the committed value\n\tconst [chipDismissed, setChipDismissed] = useState(false)\n\tconst chip = useMemo(\n\t\t() =>\n\t\t\tderivePresetChip({\n\t\t\t\tediting: chipDismissed,\n\t\t\t\tlinked,\n\t\t\t\tpresets: resolvedPresets,\n\t\t\t\tvalue: stringValue,\n\t\t\t}),\n\t\t[chipDismissed, linked, resolvedPresets, stringValue]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t},\n\t\t[]\n\t)\n\n\t// Revert target for non-clearable commits; tracked from committed values so\n\t// picker commits, preset picks, and the initially loaded value all count\n\tconst lastValidRef = useRef<null | string>(null)\n\tuseEffect(() => {\n\t\tif (stringValue === '') return\n\t\tif (presetKey ? true : parseColor(stringValue) !== null) lastValidRef.current = stringValue\n\t}, [presetKey, stringValue])\n\n\t// Commits to the form without touching editingRef: the debounced path must not let the draft resync mid-typing.\n\t// Returns true when a non-clearable empty or unparseable draft was reverted to the last valid value.\n\tconst commitText = useCallback(\n\t\t(raw: string): boolean => {\n\t\t\tlet normalized: null | string = null\n\t\t\tif (linked && raw.startsWith(PRESET_PREFIX)) {\n\t\t\t\tif (raw.length > PRESET_PREFIX.length) normalized = raw\n\t\t\t} else {\n\t\t\t\tconst parsedRaw = parseColor(raw)\n\t\t\t\t// Unparseable input commits raw so validation surfaces the error\n\t\t\t\tif (parsedRaw) normalized = formatColor(parsedRaw, format, { alpha })\n\t\t\t}\n\t\t\tconst resolution = resolveCommitValue({\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tparsed: normalized,\n\t\t\t})\n\t\t\tlastValidRef.current = resolution.lastValid\n\t\t\tsetValue(resolution.value)\n\t\t\treturn resolution.reverted\n\t\t},\n\t\t[alpha, format, isClearable, linked, setValue]\n\t)\n\n\tconst onTextChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst raw = event.target.value\n\t\t\teditingRef.current = true\n\t\t\tsetChipDismissed(true)\n\t\t\tsetDraft(raw)\n\t\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = setTimeout(() => commitText(raw), 250)\n\t\t},\n\t\t[commitText]\n\t)\n\n\tconst onTextBlur = useCallback(() => {\n\t\tif (debounceRef.current) {\n\t\t\tclearTimeout(debounceRef.current)\n\t\t\tdebounceRef.current = null\n\t\t}\n\t\tif (editingRef.current) {\n\t\t\teditingRef.current = false\n\t\t\t// Blur-only salvage: recover the first valid color from dirty input\n\t\t\t// (double pastes, stray junk) before the normal commit pipeline\n\t\t\tconst isPresetDraft = linked && draft.startsWith(PRESET_PREFIX)\n\t\t\tconst salvaged =\n\t\t\t\t!isPresetDraft && draft.trim() !== '' && !parseColor(draft) ? salvageColor(draft) : null\n\t\t\tif (commitText(salvaged ?? draft)) {\n\t\t\t\t// A reverted commit usually leaves the form value unchanged, so the\n\t\t\t\t// displayValue resync effect never fires; restore the draft here\n\t\t\t\tsetDraft(displayValue)\n\t\t\t} else if (salvaged !== null) {\n\t\t\t\t// A salvaged commit can store the same value as before (double paste of\n\t\t\t\t// the current color), which also skips the resync; clean the draft here\n\t\t\t\tconst parsedSalvaged = parseColor(salvaged)\n\t\t\t\tsetDraft(parsedSalvaged ? formatColor(parsedSalvaged, displayFormat, { alpha }) : salvaged)\n\t\t\t}\n\t\t}\n\t\tsetChipDismissed(false)\n\t}, [alpha, commitText, displayFormat, displayValue, draft, linked])\n\n\t// Backspace/Delete on the empty chip input never fires a change event, so clear here\n\tconst onTextKeyDown = useCallback(\n\t\t(event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\t\tif (!chip || isReadOnly) return\n\t\t\tif (event.key === 'Backspace' || event.key === 'Delete') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tsetDraft('')\n\t\t\t\tif (isClearable) {\n\t\t\t\t\tsetValue(null)\n\t\t\t\t} else {\n\t\t\t\t\t// Keep the stored ref; the emptied draft reverts or gets replaced at commit\n\t\t\t\t\teditingRef.current = true\n\t\t\t\t\tsetChipDismissed(true)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[chip, isClearable, isReadOnly, setValue]\n\t)\n\n\tconst commitCss = useCallback(\n\t\t(css: string) => {\n\t\t\tconst parsedCss = parseColor(css)\n\t\t\tif (parsedCss) setValue(formatColor(parsedCss, format, { alpha }))\n\t\t},\n\t\t[alpha, format, setValue]\n\t)\n\n\tconst initialHsva = useMemo<Hsva | null>(() => {\n\t\tif (!parsed) return null\n\t\tconst rgb = toRgb(parsed)\n\t\tconst hsv = rgbToHsv(rgb)\n\t\treturn { a: rgb.alpha, h: hsv.h, s: hsv.s, v: hsv.v }\n\t}, [parsed])\n\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\tconst swatchCss = swatchBackground(rawValue)\n\n\tconst swatch = (\n\t\t<span className={`${baseClass}__swatch ${baseClass}__checker`}>\n\t\t\t{swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} style={{ background: swatchCss }} />\n\t\t\t) : null}\n\t\t\t{presetMissing && !swatchCss ? (\n\t\t\t\t<span className={`${baseClass}__swatch-color`} data-missing=\"true\" />\n\t\t\t) : null}\n\t\t\t{isReadOnly ? null : <span className={`${baseClass}__sr-only`}>{t(keys.pickColor)}</span>}\n\t\t</span>\n\t)\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\tshowError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\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={`${baseClass}__container`}>\n\t\t\t\t\t{isReadOnly ? (\n\t\t\t\t\t\t<span className={`${baseClass}__swatch-button ${baseClass}__swatch-button--static`}>\n\t\t\t\t\t\t\t{swatch}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Popup\n\t\t\t\t\t\t\tbutton={swatch}\n\t\t\t\t\t\t\tbuttonClassName={`${baseClass}__swatch-button`}\n\t\t\t\t\t\t\tbuttonType=\"custom\"\n\t\t\t\t\t\t\tcaret={false}\n\t\t\t\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\t\t\t\thorizontalAlign=\"left\"\n\t\t\t\t\t\t\trender={({ close }) => (\n\t\t\t\t\t\t\t\t<ColorPickerPanel\n\t\t\t\t\t\t\t\t\tactivePresetKey={activePreset?.key ?? null}\n\t\t\t\t\t\t\t\t\talphaEnabled={alpha}\n\t\t\t\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\t\t\t\tdisplayFormat={displayFormat}\n\t\t\t\t\t\t\t\t\tenableEyedropper={enableEyedropper}\n\t\t\t\t\t\t\t\t\tinitial={initialHsva}\n\t\t\t\t\t\t\t\t\tonPickCss={commitCss}\n\t\t\t\t\t\t\t\t\tonPickPreset={(preset) => {\n\t\t\t\t\t\t\t\t\t\tif (linked) setValue(`${PRESET_PREFIX}${preset.key}`)\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t// A text column holds one color, so a scheme preset stores its light member\n\t\t\t\t\t\t\t\t\t\t\tconst flat = flatValue(preset.value)\n\t\t\t\t\t\t\t\t\t\t\tif (flat) commitCss(flat)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tpresetMissing={presetMissing}\n\t\t\t\t\t\t\t\t\tpresets={resolvedPresets}\n\t\t\t\t\t\t\t\t\tpresetsLabel={presetsLabel ?? t(keys.presets)}\n\t\t\t\t\t\t\t\t\tsetDisplayFormat={setDisplayFormat}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tsize=\"fit-content\"\n\t\t\t\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t\t{chip ? (\n\t\t\t\t\t\t<span className={`${baseClass}__chip`}>\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip-swatch ${baseClass}__checker`}>\n\t\t\t\t\t\t\t\t{swatchCss ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} style={{ background: swatchCss }} />\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t{chip.missing && !swatchCss ? (\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__chip-color`} data-missing=\"true\" />\n\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className={`${baseClass}__chip-label`}>{chip.label}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<input\n\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\tid={`field-${path?.replace(/\\./g, '__')}`}\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonBlur={onTextBlur}\n\t\t\t\t\t\tonChange={onTextChange}\n\t\t\t\t\t\tonKeyDown={onTextKeyDown}\n\t\t\t\t\t\tplaceholder={chip || typeof placeholder !== 'string' ? undefined : placeholder}\n\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tvalue={chip ? '' : draft}\n\t\t\t\t\t/>\n\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__badge`}>\n\t\t\t\t\t\t{chip ? t(keys.preset) : displayFormat}\n\t\t\t\t\t</span>\n\t\t\t\t\t{isClearable && !required && !isReadOnly && stringValue !== '' ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearColor)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetDraft('')\n\t\t\t\t\t\t\t\tsetValue(null)\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}\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B,WAAW,KAAA,IAAY;OACnE,UAAU;OACV,MAAK;OACL,OAAO,OAAO,KAAK;MACnB,CAAA;MACD,oBAAC,QAAD;OAAM,eAAY;OAAO,WAAW,GAAG,UAAU;iBAC/C,OAAO,EAAE,KAAK,MAAM,IAAI;MACpB,CAAA;MACL,eAAe,CAAC,YAAY,CAAC,cAAc,gBAAgB,KAC3D,oBAAC,UAAD;OACC,cAAY,EAAE,KAAK,UAAU;OAC7B,WAAW,GAAG,UAAU;OACxB,eAAe;QACd,SAAS,EAAE;QACX,SAAS,IAAI;OACd;OACA,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"ColorField.js","names":["useTranslation"],"sources":["../../../../src/fields/color/client/ColorField.tsx"],"sourcesContent":["'use client'\nimport { useField } from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { TextFieldClientProps, Validate } from 'payload'\nimport { text } from 'payload/shared'\nimport type React from 'react'\nimport { useCallback, useMemo } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { ColorFieldClientOptions, ResolvedColorPreset } from '../options'\nimport { colorValueIssue } from '../valueIssue'\nimport { ColorInput } from './ColorInput'\n\nconst NO_PRESETS: ResolvedColorPreset[] = []\n\nexport type ColorFieldProps = {\n\tcolorOptions: ColorFieldClientOptions\n\tpresetsLabel?: string\n\tresolvedPresets?: ResolvedColorPreset[]\n} & TextFieldClientProps\n\n/** `ColorInput` bound to the document form through `useField`, with the field's validation. */\nexport const ColorField: React.FC<ColorFieldProps> = (props) => {\n\tconst {\n\t\tcolorOptions,\n\t\tfield,\n\t\tfield: {\n\t\t\tadmin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},\n\t\t\tlabel,\n\t\t\tlocalized,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tpath: pathFromProps,\n\t\tpresetsLabel,\n\t\treadOnly: readOnlyFromProps,\n\t\tresolvedPresets = NO_PRESETS,\n\t} = props\n\tconst { linked } = colorOptions\n\tconst { t } = useTranslation()\n\n\tconst memoizedValidate = useCallback<Validate<string>>(\n\t\t(value, options) => {\n\t\t\tconst issue = colorValueIssue(value, { linked, presets: resolvedPresets })\n\t\t\tif (issue) return t(keys[issue])\n\t\t\treturn text(value, { ...options, name, required, type: 'text' })\n\t\t},\n\t\t[linked, name, required, resolvedPresets, t]\n\t)\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, validate: memoizedValidate })\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly\n\t// reaches custom Field components solely via clientField.admin (native fields get\n\t// it merged client-side in RenderFields, a path custom components bypass)\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<ColorInput\n\t\t\tAfterInput={AfterInput}\n\t\t\tBeforeInput={BeforeInput}\n\t\t\tclassName={className}\n\t\t\tDescription={Description}\n\t\t\tdescription={description}\n\t\t\tError={ErrorComponent}\n\t\t\tLabel={Label}\n\t\t\tlabel={label}\n\t\t\tlocalized={localized}\n\t\t\tonChange={setValue}\n\t\t\toptions={colorOptions}\n\t\t\tpath={path}\n\t\t\tplaceholder={typeof placeholder === 'string' ? placeholder : undefined}\n\t\t\tpresets={resolvedPresets}\n\t\t\tpresetsLabel={presetsLabel}\n\t\t\treadOnly={isReadOnly}\n\t\t\trequired={required}\n\t\t\tshowError={showError}\n\t\t\tstyle={styles}\n\t\t\tvalue={value}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,aAAoC,CAAC;;AAS3C,MAAa,cAAyC,UAAU;CAC/D,MAAM,EACL,cACA,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,MACA,YAED,MAAM,eACN,cACA,UAAU,mBACV,kBAAkB,eACf;CACJ,MAAM,EAAE,WAAW;CACnB,MAAM,EAAE,MAAMA,iBAAe;CAW7B,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAiB;EAAE,sBAAsB;EAAe,UAhBnC,aACvB,OAAO,YAAY;GACnB,MAAM,QAAQ,gBAAgB,OAAO;IAAE;IAAQ,SAAS;GAAgB,CAAC;GACzE,IAAI,OAAO,OAAO,EAAE,KAAK,MAAM;GAC/B,OAAO,KAAK,OAAO;IAAE,GAAG;IAAS;IAAM;IAAU,MAAM;GAAO,CAAC;EAChE,GACA;GAAC;GAAQ;GAAM;GAAU;GAAiB;EAAC,CAUyC;CAAE,CAAC;CAKxF,MAAM,aAAa,QAAQ,qBAAqB,YAAY,iBAAiB;CAC7E,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,oBAAC,YAAD;EACa;EACC;EACF;EACE;EACA;EACb,OAAO;EACA;EACA;EACI;EACX,UAAU;EACV,SAAS;EACH;EACN,aAAa,OAAO,gBAAgB,WAAW,cAAc,KAAA;EAC7D,SAAS;EACK;EACd,UAAU;EACA;EACC;EACX,OAAO;EACA;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ColorFieldClientOptions, ResolvedColorPreset } from "../options.js";
|
|
2
|
+
import { StaticDescription, StaticLabel } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/color/client/ColorInput.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the form-free color input. `value` and `onChange` carry the stored string
|
|
7
|
+
* exactly as `colorField` would persist it: normalized to `options.format` on commit,
|
|
8
|
+
* or a `preset:<key>` reference when `options.linked` is on.
|
|
9
|
+
*/
|
|
10
|
+
type ColorInputProps = {
|
|
11
|
+
value: null | string | undefined; /** Fires at commit boundaries (debounced typing, blur, picker, preset, clear), never per keystroke. */
|
|
12
|
+
onChange: (value: null | string) => void; /** Any option left out takes `colorField`'s default (hex, alpha on, clearable, eyedropper, unlinked). */
|
|
13
|
+
options?: Partial<ColorFieldClientOptions>; /** Already resolved presets; labels are plain strings in the viewer's language. */
|
|
14
|
+
presets?: ResolvedColorPreset[];
|
|
15
|
+
presetsLabel?: string; /** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */
|
|
16
|
+
path?: string;
|
|
17
|
+
label?: StaticLabel;
|
|
18
|
+
description?: StaticDescription;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
localized?: boolean;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Message shown in the error tooltip. Left unset, the input reports its own
|
|
25
|
+
* malformed-color and missing-preset errors.
|
|
26
|
+
*/
|
|
27
|
+
error?: string; /** Forces the error state on or off. Left unset, it follows `error` and the input's own check. */
|
|
28
|
+
showError?: boolean;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
Label?: React.ReactNode;
|
|
32
|
+
Error?: React.ReactNode;
|
|
33
|
+
Description?: React.ReactNode;
|
|
34
|
+
BeforeInput?: React.ReactNode;
|
|
35
|
+
AfterInput?: React.ReactNode;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The color field's row, picker, preset chip and commit pipeline with no form behind
|
|
39
|
+
* it, for custom admin views and components. `ColorField` is this plus `useField`.
|
|
40
|
+
*/
|
|
41
|
+
declare const ColorInput: React.FC<ColorInputProps>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ColorInput, ColorInputProps };
|
|
44
|
+
//# sourceMappingURL=ColorInput.d.ts.map
|