@10x-media/fields 0.1.0-beta.7 → 0.1.0-beta.9
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 +21 -0
- package/LICENSE +21 -21
- package/dist/exports/client.d.ts +7 -1
- package/dist/exports/client.js +6 -1
- 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 +3 -1
- package/dist/exports/rsc.js +3 -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 +34 -337
- 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/valueIssue.js +23 -0
- package/dist/fields/color/valueIssue.js.map +1 -0
- 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/MeasurementField.d.ts +2 -0
- package/dist/fields/measurement/client/MeasurementField.js +29 -345
- package/dist/fields/measurement/client/MeasurementField.js.map +1 -1
- 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/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/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 +4 -3
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +9 -1
- package/dist/translations/ar.js.map +1 -1
- package/dist/translations/de.js +9 -1
- package/dist/translations/de.js.map +1 -1
- package/dist/translations/en.js +9 -1
- package/dist/translations/en.js.map +1 -1
- package/dist/translations/es.js +9 -1
- package/dist/translations/es.js.map +1 -1
- package/dist/translations/fr.js +9 -1
- package/dist/translations/fr.js.map +1 -1
- package/dist/translations/id.js +9 -1
- package/dist/translations/id.js.map +1 -1
- package/dist/translations/keys.d.ts +8 -0
- package/dist/translations/keys.js +9 -1
- package/dist/translations/keys.js.map +1 -1
- package/dist/translations/ko.js +9 -1
- package/dist/translations/ko.js.map +1 -1
- package/dist/translations/pt.js +9 -1
- package/dist/translations/pt.js.map +1 -1
- package/dist/translations/ru.js +9 -1
- package/dist/translations/ru.js.map +1 -1
- package/dist/translations/uk.js +9 -1
- package/dist/translations/uk.js.map +1 -1
- package/dist/translations/zh.js +9 -1
- package/dist/translations/zh.js.map +1 -1
- package/dist/types.d.ts +22 -1
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +16 -4
- package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport {
|
|
1
|
+
{"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { formatIconLabel } from './formatIconLabel'\n\n/** What an editor sees for one icon: its accessible name, plus the raw name where that adds information. */\nexport type IconDisplayLabel = { code?: string; label: string }\n\n/**\n * Resolves the display text for one icon. A library-supplied `label` wins; otherwise\n * the name is sentence-cased as before, so every existing manifest is unaffected.\n *\n * `code` carries the raw name for surfaces that can show it alongside the label. It is\n * the only place an editor can learn that \"Hungary\" stores as `HUN`, which they need to\n * write frontend code, and it is deliberately kept out of the accessible name: a screen\n * reader announcing \"Hungary HUN\" across 215 cells is the defect this fixes.\n */\nexport const resolveIconDisplay = (args: {\n\tlanguage: string\n\tmeta?: IconMeta | null\n\tname: string\n}): IconDisplayLabel => {\n\tconst derived = formatIconLabel(args.name)\n\tconst supplied = resolveStaticLabel(args.meta?.label, args.language)\n\tif (!supplied) return { label: derived }\n\t// A code only earns its place when the label hides it. A label matching the name, or\n\t// matching what the name would have derived anyway, tells the editor nothing new.\n\tif (supplied === args.name || supplied === derived) return { label: supplied }\n\treturn { code: args.name, label: supplied }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAIX;CACvB,MAAM,UAAU,gBAAgB,KAAK,IAAI;CACzC,MAAM,WAAW,mBAAmB,KAAK,MAAM,OAAO,KAAK,QAAQ;CACnE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,QAAQ;CAGvC,IAAI,aAAa,KAAK,QAAQ,aAAa,SAAS,OAAO,EAAE,OAAO,SAAS;CAC7E,OAAO;EAAE,MAAM,KAAK;EAAM,OAAO;CAAS;AAC3C"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
2
2
|
import { NumberFieldClientProps } from "payload";
|
|
3
3
|
import React from "react";
|
|
4
|
+
|
|
4
5
|
//#region src/fields/measurement/client/MeasurementField.d.ts
|
|
5
6
|
type MeasurementFieldProps = {
|
|
6
7
|
measurementOptions: MeasurementResolvedClientOptions;
|
|
7
8
|
} & NumberFieldClientProps;
|
|
9
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
8
10
|
declare const MeasurementField: React.FC<MeasurementFieldProps>;
|
|
9
11
|
//#endregion
|
|
10
12
|
export { MeasurementField, MeasurementFieldProps };
|
|
@@ -1,106 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { COMPOUNDS } from "../engine/units.js";
|
|
3
|
-
import { exactModePrecisionOverride, resolvePrecision } from "../engine/precision.js";
|
|
4
2
|
import { keys } from "../../../translations/keys.js";
|
|
5
3
|
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { commitDrafts, draftsFor } from "./editModel.js";
|
|
9
|
-
import { useMeasurementUnits } from "./MeasurementUnitsProvider.js";
|
|
4
|
+
import { useMeasurementModel } from "./useMeasurementModel.js";
|
|
5
|
+
import { MeasurementInputView } from "./MeasurementInput.js";
|
|
10
6
|
import { number } from "payload/shared";
|
|
11
|
-
import {
|
|
7
|
+
import { useField } from "@payloadcms/ui";
|
|
12
8
|
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
13
|
-
import { useCallback,
|
|
14
|
-
import {
|
|
15
|
-
import "./measurementField.css";
|
|
9
|
+
import { useCallback, useMemo } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
16
11
|
//#region src/fields/measurement/client/MeasurementField.tsx
|
|
17
|
-
|
|
18
|
-
/** MeasurementFieldServer always resolves and threads precision; this only covers a hand-authored Field with no server wrapper. */
|
|
19
|
-
const DEFAULT_PRECISION = resolvePrecision([]);
|
|
20
|
-
const CLEAN = {
|
|
21
|
-
minor: false,
|
|
22
|
-
primary: false
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Every value input sizes to its content so "5 ft 11 in" (or a lone scalar)
|
|
26
|
-
* reads as one left-aligned phrase. The half-ch keeps the caret off the edge;
|
|
27
|
-
* the clamp keeps an empty input clickable and a runaway draft from pushing
|
|
28
|
-
* the row into overflow.
|
|
29
|
-
*/
|
|
30
|
-
const draftWidth = (draft) => ({ width: `${Math.min(Math.max(draft.length, 2), 12) + .5}ch` });
|
|
31
|
-
const unitKebab = /* @__PURE__ */ jsxs("svg", {
|
|
32
|
-
"aria-hidden": "true",
|
|
33
|
-
className: `${baseClass}__kebab`,
|
|
34
|
-
focusable: "false",
|
|
35
|
-
viewBox: "0 0 4 16",
|
|
36
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
37
|
-
children: [
|
|
38
|
-
/* @__PURE__ */ jsx("circle", {
|
|
39
|
-
cx: "2",
|
|
40
|
-
cy: "2",
|
|
41
|
-
fill: "currentColor",
|
|
42
|
-
r: "1.6"
|
|
43
|
-
}),
|
|
44
|
-
/* @__PURE__ */ jsx("circle", {
|
|
45
|
-
cx: "2",
|
|
46
|
-
cy: "8",
|
|
47
|
-
fill: "currentColor",
|
|
48
|
-
r: "1.6"
|
|
49
|
-
}),
|
|
50
|
-
/* @__PURE__ */ jsx("circle", {
|
|
51
|
-
cx: "2",
|
|
52
|
-
cy: "14",
|
|
53
|
-
fill: "currentColor",
|
|
54
|
-
r: "1.6"
|
|
55
|
-
})
|
|
56
|
-
]
|
|
57
|
-
});
|
|
12
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
58
13
|
const MeasurementField = (props) => {
|
|
59
14
|
const { field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, max, min, name, required }, measurementOptions, path: pathFromProps, readOnly: readOnlyFromProps } = props;
|
|
60
|
-
const {
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const engine = useMemo(() => custom ? createEngine(custom) : defaultEngine, [custom]);
|
|
64
|
-
const context = useMeasurementUnits();
|
|
65
|
-
const [localUnit, setLocalUnit] = useState(initialUnit ?? null);
|
|
66
|
-
const [system, setSystem] = useState(null);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
setSystem(systemForLocale(navigator.language));
|
|
69
|
-
}, []);
|
|
70
|
-
const displayUnit = resolveDisplayUnit({
|
|
71
|
-
dimension,
|
|
72
|
-
fallbackUnit,
|
|
73
|
-
localeDefaults,
|
|
74
|
-
preferenceUnit: context ? context.units[preferenceKey] ?? (context.ready ? null : initialUnit ?? null) : localUnit,
|
|
75
|
-
registryDefault,
|
|
76
|
-
system,
|
|
77
|
-
units
|
|
78
|
-
});
|
|
79
|
-
const resolvedPrecision = precision ?? DEFAULT_PRECISION;
|
|
80
|
-
const displayPrecision = useMemo(() => exactModePrecisionOverride(resolvedPrecision, displayUnit), [resolvedPrecision, displayUnit]);
|
|
81
|
-
const fmtBound = useCallback((bound) => {
|
|
82
|
-
try {
|
|
83
|
-
return engine.formatMeasurement(bound, {
|
|
84
|
-
displayUnit,
|
|
85
|
-
locale: `${locale}-u-nu-latn`,
|
|
86
|
-
precision: displayPrecision,
|
|
87
|
-
storageUnit
|
|
88
|
-
});
|
|
89
|
-
} catch {
|
|
90
|
-
return engine.formatMeasurement(bound, {
|
|
91
|
-
displayUnit,
|
|
92
|
-
locale,
|
|
93
|
-
precision: displayPrecision,
|
|
94
|
-
storageUnit
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}, [
|
|
98
|
-
displayUnit,
|
|
99
|
-
engine,
|
|
100
|
-
locale,
|
|
101
|
-
displayPrecision,
|
|
102
|
-
storageUnit
|
|
103
|
-
]);
|
|
15
|
+
const { t } = useTranslation$1();
|
|
16
|
+
const model = useMeasurementModel(measurementOptions);
|
|
17
|
+
const { fmtBound } = model;
|
|
104
18
|
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({
|
|
105
19
|
potentiallyStalePath: pathFromProps,
|
|
106
20
|
validate: useCallback((value, options) => {
|
|
@@ -126,258 +40,28 @@ const MeasurementField = (props) => {
|
|
|
126
40
|
])
|
|
127
41
|
});
|
|
128
42
|
const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
|
|
129
|
-
const numericValue = typeof value === "number" && !Number.isNaN(value) ? value : null;
|
|
130
|
-
const draftOpts = useMemo(() => ({
|
|
131
|
-
displayUnit,
|
|
132
|
-
draft: resolvedPrecision.draft,
|
|
133
|
-
engine,
|
|
134
|
-
precision: displayPrecision,
|
|
135
|
-
storageDigits: resolvedPrecision.storage,
|
|
136
|
-
storageUnit
|
|
137
|
-
}), [
|
|
138
|
-
displayUnit,
|
|
139
|
-
engine,
|
|
140
|
-
displayPrecision,
|
|
141
|
-
resolvedPrecision,
|
|
142
|
-
storageUnit
|
|
143
|
-
]);
|
|
144
|
-
const boundsMessage = useMemo(() => {
|
|
145
|
-
if (numericValue === null) return void 0;
|
|
146
|
-
if (typeof min === "number" && numericValue < min) return t(keys.measurementBelowMin, { min: fmtBound(min) });
|
|
147
|
-
if (typeof max === "number" && numericValue > max) return t(keys.measurementAboveMax, { max: fmtBound(max) });
|
|
148
|
-
}, [
|
|
149
|
-
numericValue,
|
|
150
|
-
min,
|
|
151
|
-
max,
|
|
152
|
-
fmtBound,
|
|
153
|
-
t
|
|
154
|
-
]);
|
|
155
|
-
const editingRef = useRef(false);
|
|
156
|
-
const [drafts, setDrafts] = useState(() => draftsFor(numericValue, draftOpts));
|
|
157
|
-
const paintedDraftsRef = useRef(drafts);
|
|
158
|
-
const paintedStoredRef = useRef(numericValue);
|
|
159
|
-
const [dirty, setDirty] = useState(CLEAN);
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
if (!editingRef.current) {
|
|
162
|
-
const resynced = draftsFor(numericValue, draftOpts);
|
|
163
|
-
setDrafts(resynced);
|
|
164
|
-
paintedDraftsRef.current = resynced;
|
|
165
|
-
paintedStoredRef.current = numericValue;
|
|
166
|
-
setDirty(CLEAN);
|
|
167
|
-
}
|
|
168
|
-
}, [numericValue, draftOpts]);
|
|
169
|
-
const onDraftChange = useCallback((part) => (event) => {
|
|
170
|
-
editingRef.current = true;
|
|
171
|
-
const next = {
|
|
172
|
-
...drafts,
|
|
173
|
-
[part]: event.target.value
|
|
174
|
-
};
|
|
175
|
-
const nextDirty = {
|
|
176
|
-
...dirty,
|
|
177
|
-
[part]: true
|
|
178
|
-
};
|
|
179
|
-
setDrafts(next);
|
|
180
|
-
setDirty(nextDirty);
|
|
181
|
-
setValue(commitDrafts(next, {
|
|
182
|
-
...draftOpts,
|
|
183
|
-
dirty: nextDirty,
|
|
184
|
-
entry: resolvedPrecision.entry,
|
|
185
|
-
paintedDrafts: paintedDraftsRef.current,
|
|
186
|
-
storedValue: paintedStoredRef.current
|
|
187
|
-
}));
|
|
188
|
-
}, [
|
|
189
|
-
dirty,
|
|
190
|
-
drafts,
|
|
191
|
-
draftOpts,
|
|
192
|
-
resolvedPrecision.entry,
|
|
193
|
-
setValue
|
|
194
|
-
]);
|
|
195
|
-
const onBlur = useCallback(() => {
|
|
196
|
-
editingRef.current = false;
|
|
197
|
-
const resynced = draftsFor(numericValue, draftOpts);
|
|
198
|
-
setDrafts(resynced);
|
|
199
|
-
paintedDraftsRef.current = resynced;
|
|
200
|
-
paintedStoredRef.current = numericValue;
|
|
201
|
-
setDirty(CLEAN);
|
|
202
|
-
}, [numericValue, draftOpts]);
|
|
203
|
-
const selectUnit = useCallback((unit) => {
|
|
204
|
-
editingRef.current = false;
|
|
205
|
-
setDirty(CLEAN);
|
|
206
|
-
if (context) context.setUnit(preferenceKey, unit);
|
|
207
|
-
else setLocalUnit(unit);
|
|
208
|
-
}, [context, preferenceKey]);
|
|
209
|
-
const isCompound = engine.isCompoundUnit(displayUnit);
|
|
210
|
-
const compoundDef = isCompound ? COMPOUNDS[displayUnit] : null;
|
|
211
|
-
const inputId = `field-${path?.replace(/\./g, "__")}`;
|
|
212
43
|
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (distance < nearestDistance) {
|
|
233
|
-
nearestDistance = distance;
|
|
234
|
-
nearest = input;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
nearest.focus();
|
|
238
|
-
}, []);
|
|
239
|
-
const isUnitInteractive = units.length > 1 && !isReadOnly;
|
|
240
|
-
const placeholderText = typeof placeholder === "string" ? placeholder : void 0;
|
|
241
|
-
const renderUnitPanel = ({ close }) => /* @__PURE__ */ jsx("div", {
|
|
242
|
-
"aria-label": t(keys.selectUnit),
|
|
243
|
-
className: `${baseClass}__unit-panel`,
|
|
244
|
-
role: "listbox",
|
|
245
|
-
children: units.map((unit) => /* @__PURE__ */ jsxs("button", {
|
|
246
|
-
"aria-selected": unit === displayUnit,
|
|
247
|
-
className: `${baseClass}__unit-option`,
|
|
248
|
-
onClick: () => {
|
|
249
|
-
selectUnit(unit);
|
|
250
|
-
close();
|
|
251
|
-
},
|
|
252
|
-
role: "option",
|
|
253
|
-
type: "button",
|
|
254
|
-
children: [/* @__PURE__ */ jsx("span", { children: engine.unitLabel(unit, locale, "long") }), /* @__PURE__ */ jsx("span", {
|
|
255
|
-
className: `${baseClass}__unit-symbol`,
|
|
256
|
-
children: engine.unitLabel(unit, locale, "short")
|
|
257
|
-
})]
|
|
258
|
-
}, unit))
|
|
259
|
-
});
|
|
260
|
-
const renderUnitSuffix = (unit) => /* @__PURE__ */ jsx("span", {
|
|
261
|
-
className: `${baseClass}__unit-static`,
|
|
262
|
-
children: engine.unitLabel(unit, locale, "short")
|
|
263
|
-
});
|
|
264
|
-
const renderMenuTrigger = () => {
|
|
265
|
-
if (!isUnitInteractive) return null;
|
|
266
|
-
const shortLabel = engine.unitLabel(displayUnit, locale, "short");
|
|
267
|
-
return /* @__PURE__ */ jsx(Popup, {
|
|
268
|
-
button: /* @__PURE__ */ jsxs(Fragment$1, { children: [unitKebab, /* @__PURE__ */ jsxs("span", {
|
|
269
|
-
className: `${baseClass}__sr-only`,
|
|
270
|
-
children: [
|
|
271
|
-
t(keys.selectUnit),
|
|
272
|
-
": ",
|
|
273
|
-
shortLabel
|
|
274
|
-
]
|
|
275
|
-
})] }),
|
|
276
|
-
buttonClassName: `${baseClass}__unit-trigger`,
|
|
277
|
-
buttonType: "default",
|
|
278
|
-
caret: false,
|
|
279
|
-
className: `${baseClass}__popup`,
|
|
280
|
-
horizontalAlign: "right",
|
|
281
|
-
render: renderUnitPanel,
|
|
282
|
-
size: "fit-content",
|
|
283
|
-
verticalAlign: "bottom"
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
287
|
-
className: [
|
|
288
|
-
fieldBaseClass,
|
|
289
|
-
baseClass,
|
|
290
|
-
className,
|
|
291
|
-
showError && "error",
|
|
292
|
-
isReadOnly && "read-only"
|
|
293
|
-
].filter(Boolean).join(" "),
|
|
44
|
+
return /* @__PURE__ */ jsx(MeasurementInputView, {
|
|
45
|
+
AfterInput,
|
|
46
|
+
BeforeInput,
|
|
47
|
+
className,
|
|
48
|
+
Description,
|
|
49
|
+
description,
|
|
50
|
+
Error: ErrorComponent,
|
|
51
|
+
Label,
|
|
52
|
+
label,
|
|
53
|
+
localized,
|
|
54
|
+
max,
|
|
55
|
+
min,
|
|
56
|
+
model,
|
|
57
|
+
onChange: setValue,
|
|
58
|
+
path,
|
|
59
|
+
placeholder: typeof placeholder === "string" ? placeholder : void 0,
|
|
60
|
+
readOnly: isReadOnly,
|
|
61
|
+
required,
|
|
62
|
+
showError,
|
|
294
63
|
style: styles,
|
|
295
|
-
|
|
296
|
-
CustomComponent: Label,
|
|
297
|
-
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
298
|
-
label,
|
|
299
|
-
localized,
|
|
300
|
-
path,
|
|
301
|
-
required
|
|
302
|
-
})
|
|
303
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
304
|
-
className: `${fieldBaseClass}__wrap`,
|
|
305
|
-
children: [
|
|
306
|
-
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
307
|
-
CustomComponent: ErrorComponent,
|
|
308
|
-
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
309
|
-
message: boundsMessage,
|
|
310
|
-
path,
|
|
311
|
-
showError
|
|
312
|
-
})
|
|
313
|
-
}),
|
|
314
|
-
BeforeInput,
|
|
315
|
-
/* @__PURE__ */ jsxs("div", {
|
|
316
|
-
className: `${baseClass}__container`,
|
|
317
|
-
onMouseDown: focusNearestInput,
|
|
318
|
-
children: [isCompound && compoundDef ? /* @__PURE__ */ jsxs("span", {
|
|
319
|
-
className: `${baseClass}__compound`,
|
|
320
|
-
onMouseDown: focusNearestInput,
|
|
321
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
322
|
-
className: `${baseClass}__part`,
|
|
323
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
324
|
-
className: `${baseClass}__input`,
|
|
325
|
-
id: inputId,
|
|
326
|
-
inputMode: "decimal",
|
|
327
|
-
name: path,
|
|
328
|
-
onBlur,
|
|
329
|
-
onChange: onDraftChange("primary"),
|
|
330
|
-
readOnly: isReadOnly,
|
|
331
|
-
ref: primaryInputRef,
|
|
332
|
-
step: "any",
|
|
333
|
-
style: draftWidth(drafts.primary),
|
|
334
|
-
type: "number",
|
|
335
|
-
value: drafts.primary
|
|
336
|
-
}), renderUnitSuffix(compoundDef.major)]
|
|
337
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
338
|
-
className: `${baseClass}__part`,
|
|
339
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
340
|
-
"aria-label": engine.unitLabel(compoundDef.minor, locale, "long"),
|
|
341
|
-
className: `${baseClass}__input`,
|
|
342
|
-
inputMode: "decimal",
|
|
343
|
-
max: compoundDef.ratio - .001,
|
|
344
|
-
min: 0,
|
|
345
|
-
onBlur,
|
|
346
|
-
onChange: onDraftChange("minor"),
|
|
347
|
-
readOnly: isReadOnly,
|
|
348
|
-
ref: minorInputRef,
|
|
349
|
-
step: "any",
|
|
350
|
-
style: draftWidth(drafts.minor),
|
|
351
|
-
type: "number",
|
|
352
|
-
value: drafts.minor
|
|
353
|
-
}), renderUnitSuffix(compoundDef.minor)]
|
|
354
|
-
})]
|
|
355
|
-
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("input", {
|
|
356
|
-
className: `${baseClass}__input`,
|
|
357
|
-
id: inputId,
|
|
358
|
-
inputMode: "decimal",
|
|
359
|
-
name: path,
|
|
360
|
-
onBlur,
|
|
361
|
-
onChange: onDraftChange("primary"),
|
|
362
|
-
placeholder: placeholderText,
|
|
363
|
-
readOnly: isReadOnly,
|
|
364
|
-
ref: primaryInputRef,
|
|
365
|
-
step: "any",
|
|
366
|
-
style: draftWidth(drafts.primary || placeholderText || ""),
|
|
367
|
-
type: "number",
|
|
368
|
-
value: drafts.primary
|
|
369
|
-
}), renderUnitSuffix(displayUnit)] }), renderMenuTrigger()]
|
|
370
|
-
}),
|
|
371
|
-
AfterInput,
|
|
372
|
-
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
373
|
-
CustomComponent: Description,
|
|
374
|
-
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
375
|
-
description,
|
|
376
|
-
path
|
|
377
|
-
})
|
|
378
|
-
})
|
|
379
|
-
]
|
|
380
|
-
})]
|
|
64
|
+
value
|
|
381
65
|
});
|
|
382
66
|
};
|
|
383
67
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MeasurementField.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementField.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n\tuseField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { NumberFieldClientProps, Validate } from 'payload'\nimport { number } 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 MeasurementSystem, systemForLocale } from '../engine/locale'\nimport { exactModePrecisionOverride, resolvePrecision } from '../engine/precision'\nimport { createEngine, defaultEngine } from '../engine/registry'\nimport { COMPOUNDS, type MeasurementUnitId } from '../engine/units'\nimport type { MeasurementResolvedClientOptions } from '../options'\nimport {\n\tcommitDrafts,\n\ttype DirtyDrafts,\n\tdraftsFor,\n\ttype MeasurementDrafts,\n\tresolveDisplayUnit,\n} from './editModel'\nimport { useMeasurementUnits } from './MeasurementUnitsProvider'\nimport './measurementField.css'\n\nconst baseClass = 'fields-measurement'\n\n/** MeasurementFieldServer always resolves and threads precision; this only covers a hand-authored Field with no server wrapper. */\nconst DEFAULT_PRECISION = resolvePrecision([])\n\nconst CLEAN: DirtyDrafts = { minor: false, primary: false }\n\n/**\n * Every value input sizes to its content so \"5 ft 11 in\" (or a lone scalar)\n * reads as one left-aligned phrase. The half-ch keeps the caret off the edge;\n * the clamp keeps an empty input clickable and a runaway draft from pushing\n * the row into overflow.\n */\nconst draftWidth = (draft: string): React.CSSProperties => ({\n\twidth: `${Math.min(Math.max(draft.length, 2), 12) + 0.5}ch`,\n})\n\nconst unitKebab = (\n\t<svg\n\t\taria-hidden=\"true\"\n\t\tclassName={`${baseClass}__kebab`}\n\t\tfocusable=\"false\"\n\t\tviewBox=\"0 0 4 16\"\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t>\n\t\t<circle cx=\"2\" cy=\"2\" fill=\"currentColor\" r=\"1.6\" />\n\t\t<circle cx=\"2\" cy=\"8\" fill=\"currentColor\" r=\"1.6\" />\n\t\t<circle cx=\"2\" cy=\"14\" fill=\"currentColor\" r=\"1.6\" />\n\t</svg>\n)\n\nexport type MeasurementFieldProps = {\n\tmeasurementOptions: MeasurementResolvedClientOptions\n} & NumberFieldClientProps\n\nexport const MeasurementField: React.FC<MeasurementFieldProps> = (props) => {\n\tconst {\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\tmax,\n\t\t\tmin,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tmeasurementOptions,\n\t\tpath: pathFromProps,\n\t\treadOnly: readOnlyFromProps,\n\t} = props\n\tconst {\n\t\tcustom,\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tinitialUnit,\n\t\tlocaleDefaults,\n\t\tprecision,\n\t\tpreferenceKey,\n\t\tregistryDefault,\n\t\tstorageUnit,\n\t\tunits,\n\t} = measurementOptions\n\tconst { i18n, t } = useTranslation()\n\tconst locale = i18n.language\n\n\t// Every conversion, label and precision lookup runs through this, so the\n\t// field's custom units behave exactly like the built-in ones.\n\tconst engine = useMemo(() => (custom ? createEngine(custom) : defaultEngine), [custom])\n\n\tconst context = useMeasurementUnits()\n\t// Standalone fallback when the plugin (and so the provider) is absent\n\tconst [localUnit, setLocalUnit] = useState<MeasurementUnitId | null>(initialUnit ?? null)\n\t// navigator is read post-hydration only, or SSR markup would mismatch\n\tconst [system, setSystem] = useState<MeasurementSystem | null>(null)\n\tuseEffect(() => {\n\t\tsetSystem(systemForLocale(navigator.language))\n\t}, [])\n\n\tconst preferenceUnit = context\n\t\t? (context.units[preferenceKey] ?? (context.ready ? null : (initialUnit ?? null)))\n\t\t: localUnit\n\tconst displayUnit = resolveDisplayUnit({\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tpreferenceUnit,\n\t\tregistryDefault,\n\t\tsystem,\n\t\tunits,\n\t})\n\n\tconst resolvedPrecision = precision ?? DEFAULT_PRECISION\n\t// Bound messages sit next to a type=number input, which always renders Latin\n\t// digits; force the same numerals here so \"min 5\" and \"5\" agree in RTL/native-digit\n\t// locales (Arabic, Persian). The input itself stays native-digit for display. Exact\n\t// mode uses the same storage-digit override as the cell, so error text and cell\n\t// text always agree. Memoized: exact mode builds a fresh object every call, and an\n\t// unmemoized value here fed draftOpts -> the resync effect -> setDrafts in a loop\n\t// that never settled.\n\tconst displayPrecision = useMemo(\n\t\t() => exactModePrecisionOverride(resolvedPrecision, displayUnit),\n\t\t[resolvedPrecision, displayUnit]\n\t)\n\tconst fmtBound = useCallback(\n\t\t(bound: number) => {\n\t\t\ttry {\n\t\t\t\treturn engine.formatMeasurement(bound, {\n\t\t\t\t\tdisplayUnit,\n\t\t\t\t\tlocale: `${locale}-u-nu-latn`,\n\t\t\t\t\tprecision: displayPrecision,\n\t\t\t\t\tstorageUnit,\n\t\t\t\t})\n\t\t\t} catch {\n\t\t\t\treturn engine.formatMeasurement(bound, {\n\t\t\t\t\tdisplayUnit,\n\t\t\t\t\tlocale,\n\t\t\t\t\tprecision: displayPrecision,\n\t\t\t\t\tstorageUnit,\n\t\t\t\t})\n\t\t\t}\n\t\t},\n\t\t[displayUnit, engine, locale, displayPrecision, storageUnit]\n\t)\n\n\tconst memoizedValidate = useCallback<Validate<number | null | undefined>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'number' && !Number.isNaN(value)) {\n\t\t\t\tif (typeof min === 'number' && value < min) {\n\t\t\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t\t\t}\n\t\t\t\tif (typeof max === 'number' && value > max) {\n\t\t\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn number(value, {\n\t\t\t\t...options,\n\t\t\t\tmax: undefined,\n\t\t\t\tmin: undefined,\n\t\t\t\tname,\n\t\t\t\trequired,\n\t\t\t\ttype: 'number',\n\t\t\t} as Parameters<typeof number>[1])\n\t\t},\n\t\t[fmtBound, max, min, 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<number | null>({ 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\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\n\tconst numericValue = typeof value === 'number' && !Number.isNaN(value) ? value : null\n\tconst draftOpts = useMemo(\n\t\t() => ({\n\t\t\tdisplayUnit,\n\t\t\tdraft: resolvedPrecision.draft,\n\t\t\tengine,\n\t\t\tprecision: displayPrecision,\n\t\t\tstorageDigits: resolvedPrecision.storage,\n\t\t\tstorageUnit,\n\t\t}),\n\t\t[displayUnit, engine, displayPrecision, resolvedPrecision, storageUnit]\n\t)\n\n\t// Payload's server-driven form-state refresh (conditional-logic revalidation on\n\t// every change) can replace this field's errorMessage with the server's raw,\n\t// storage-unit message before our own throttled client validate lands. Compute\n\t// the unit-aware bound message independently and pass it straight to FieldError\n\t// so display never depends on winning that race.\n\tconst boundsMessage = useMemo(() => {\n\t\tif (numericValue === null) return undefined\n\t\tif (typeof min === 'number' && numericValue < min) {\n\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t}\n\t\tif (typeof max === 'number' && numericValue > max) {\n\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t}\n\t\treturn undefined\n\t}, [numericValue, min, max, fmtBound, t])\n\n\tconst editingRef = useRef(false)\n\tconst [drafts, setDrafts] = useState<MeasurementDrafts>(() => draftsFor(numericValue, draftOpts))\n\t// The drafts as painted on screen immediately before the current edit, refreshed\n\t// only at a resync (mount, external value, blur, unit switch) and never per\n\t// keystroke. A carry-rounded display (182.5 cm storage paints as 6 ft 0 in even\n\t// though the exact split is 5 ft 11.850394 in) must never be mistaken for the\n\t// exact stored value, so commits diff the typed value against this baseline\n\t// rather than against the exact decompose.\n\tconst paintedDraftsRef = useRef<MeasurementDrafts>(drafts)\n\t// The stored value the painted drafts were derived from, frozen at the same\n\t// resync points as paintedDraftsRef. A mid-edit setValue call updates Payload's\n\t// live form value (and so `numericValue`) before the viewer blurs; diffing the\n\t// next keystroke's delta against that advanced value, instead of this frozen\n\t// snapshot, would re-apply an already-committed delta on top of itself.\n\tconst paintedStoredRef = useRef<number | null>(numericValue)\n\t// Which part the viewer has actually typed into since the last resync: an\n\t// untouched part must commit the value it already holds, never whatever the\n\t// display-policy draft happens to show for it.\n\tconst [dirty, setDirty] = useState<DirtyDrafts>(CLEAN)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) {\n\t\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\t\tsetDrafts(resynced)\n\t\t\tpaintedDraftsRef.current = resynced\n\t\t\tpaintedStoredRef.current = numericValue\n\t\t\tsetDirty(CLEAN)\n\t\t}\n\t}, [numericValue, draftOpts])\n\n\tconst onDraftChange = useCallback(\n\t\t(part: keyof MeasurementDrafts) => (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\teditingRef.current = true\n\t\t\tconst next = { ...drafts, [part]: event.target.value }\n\t\t\tconst nextDirty = { ...dirty, [part]: true }\n\t\t\tsetDrafts(next)\n\t\t\tsetDirty(nextDirty)\n\t\t\tsetValue(\n\t\t\t\tcommitDrafts(next, {\n\t\t\t\t\t...draftOpts,\n\t\t\t\t\tdirty: nextDirty,\n\t\t\t\t\tentry: resolvedPrecision.entry,\n\t\t\t\t\tpaintedDrafts: paintedDraftsRef.current,\n\t\t\t\t\tstoredValue: paintedStoredRef.current,\n\t\t\t\t})\n\t\t\t)\n\t\t},\n\t\t[dirty, drafts, draftOpts, resolvedPrecision.entry, setValue]\n\t)\n\n\tconst onBlur = useCallback(() => {\n\t\teditingRef.current = false\n\t\tconst resynced = draftsFor(numericValue, draftOpts)\n\t\tsetDrafts(resynced)\n\t\tpaintedDraftsRef.current = resynced\n\t\tpaintedStoredRef.current = numericValue\n\t\tsetDirty(CLEAN)\n\t}, [numericValue, draftOpts])\n\n\tconst selectUnit = useCallback(\n\t\t(unit: MeasurementUnitId) => {\n\t\t\teditingRef.current = false\n\t\t\tsetDirty(CLEAN)\n\t\t\tif (context) context.setUnit(preferenceKey, unit)\n\t\t\telse setLocalUnit(unit)\n\t\t},\n\t\t[context, preferenceKey]\n\t)\n\n\tconst isCompound = engine.isCompoundUnit(displayUnit)\n\tconst compoundDef = isCompound ? COMPOUNDS[displayUnit] : null\n\tconst inputId = `field-${path?.replace(/\\./g, '__')}`\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\tconst primaryInputRef = useRef<HTMLInputElement>(null)\n\tconst minorInputRef = useRef<HTMLInputElement>(null)\n\n\t// Dead-space (or the passive unit suffix, e.g. \"in\") mousedown focuses the nearest\n\t// input like a native control; preventDefault stops an already-focused input from\n\t// blurring, so we never steal focus from it. The suffix is never inside the unit\n\t// trigger button, so this never intercepts opening the unit popup.\n\tconst focusNearestInput = useCallback((event: React.MouseEvent<HTMLElement>) => {\n\t\tconst target = event.target as HTMLElement\n\t\tconst isUnitSuffix = target.closest(`.${baseClass}__unit-static`) !== null\n\t\tif (target !== event.currentTarget && !isUnitSuffix) return\n\t\tevent.preventDefault()\n\t\tconst active = document.activeElement\n\t\tif (active === primaryInputRef.current || active === minorInputRef.current) return\n\t\tconst inputs = [primaryInputRef.current, minorInputRef.current].filter(\n\t\t\t(input): input is HTMLInputElement => input !== null\n\t\t)\n\t\tconst [first, ...rest] = inputs\n\t\tif (!first) return\n\t\tconst distanceFrom = (input: HTMLInputElement) => {\n\t\t\tconst rect = input.getBoundingClientRect()\n\t\t\treturn Math.abs(event.clientX - (rect.left + rect.width / 2))\n\t\t}\n\t\tlet nearest = first\n\t\tlet nearestDistance = distanceFrom(first)\n\t\tfor (const input of rest) {\n\t\t\tconst distance = distanceFrom(input)\n\t\t\tif (distance < nearestDistance) {\n\t\t\t\tnearestDistance = distance\n\t\t\t\tnearest = input\n\t\t\t}\n\t\t}\n\t\tnearest.focus()\n\t}, [])\n\n\tconst isUnitInteractive = units.length > 1 && !isReadOnly\n\tconst placeholderText = typeof placeholder === 'string' ? placeholder : undefined\n\n\tconst renderUnitPanel = ({ close }: { close: () => void }) => (\n\t\t<div aria-label={t(keys.selectUnit)} className={`${baseClass}__unit-panel`} role=\"listbox\">\n\t\t\t{units.map((unit) => (\n\t\t\t\t<button\n\t\t\t\t\taria-selected={unit === displayUnit}\n\t\t\t\t\tclassName={`${baseClass}__unit-option`}\n\t\t\t\t\tkey={unit}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tselectUnit(unit)\n\t\t\t\t\t\tclose()\n\t\t\t\t\t}}\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t>\n\t\t\t\t\t<span>{engine.unitLabel(unit, locale, 'long')}</span>\n\t\t\t\t\t<span className={`${baseClass}__unit-symbol`}>\n\t\t\t\t\t\t{engine.unitLabel(unit, locale, 'short')}\n\t\t\t\t\t</span>\n\t\t\t\t</button>\n\t\t\t))}\n\t\t</div>\n\t)\n\n\tconst renderUnitSuffix = (unit: MeasurementUnitId) => (\n\t\t<span className={`${baseClass}__unit-static`}>{engine.unitLabel(unit, locale, 'short')}</span>\n\t)\n\n\t// One kebab per field, pinned to the row's right edge; the unit text itself\n\t// stays a passive suffix so value and unit read as a single phrase.\n\tconst renderMenuTrigger = () => {\n\t\tif (!isUnitInteractive) return null\n\t\tconst shortLabel = engine.unitLabel(displayUnit, locale, 'short')\n\t\treturn (\n\t\t\t<Popup\n\t\t\t\tbutton={\n\t\t\t\t\t<>\n\t\t\t\t\t\t{unitKebab}\n\t\t\t\t\t\t<span className={`${baseClass}__sr-only`}>\n\t\t\t\t\t\t\t{t(keys.selectUnit)}: {shortLabel}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tbuttonClassName={`${baseClass}__unit-trigger`}\n\t\t\t\tbuttonType=\"default\"\n\t\t\t\tcaret={false}\n\t\t\t\tclassName={`${baseClass}__popup`}\n\t\t\t\thorizontalAlign=\"right\"\n\t\t\t\trender={renderUnitPanel}\n\t\t\t\tsize=\"fit-content\"\n\t\t\t\tverticalAlign=\"bottom\"\n\t\t\t/>\n\t\t)\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 message={boundsMessage} path={path} showError={showError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t{/* biome-ignore lint/a11y/noStaticElementInteractions: mousedown only refocuses an inner input, it adds no control and changes no semantics */}\n\t\t\t\t<div className={`${baseClass}__container`} onMouseDown={focusNearestInput}>\n\t\t\t\t\t{isCompound && compoundDef ? (\n\t\t\t\t\t\t// biome-ignore lint/a11y/noStaticElementInteractions: same as the container, refocuses whichever inner input is nearest\n\t\t\t\t\t\t<span className={`${baseClass}__compound`} onMouseDown={focusNearestInput}>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.major)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className={`${baseClass}__part`}>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\taria-label={engine.unitLabel(compoundDef.minor, locale, 'long')}\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\t\tmax={compoundDef.ratio - 0.001}\n\t\t\t\t\t\t\t\t\tmin={0}\n\t\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\t\tonChange={onDraftChange('minor')}\n\t\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\t\tref={minorInputRef}\n\t\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.minor)}\n\t\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\t\tvalue={drafts.minor}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{renderUnitSuffix(compoundDef.minor)}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\tinputMode=\"decimal\"\n\t\t\t\t\t\t\t\tname={path}\n\t\t\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\t\t\tonChange={onDraftChange('primary')}\n\t\t\t\t\t\t\t\tplaceholder={placeholderText}\n\t\t\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\t\t\tref={primaryInputRef}\n\t\t\t\t\t\t\t\tstep=\"any\"\n\t\t\t\t\t\t\t\tstyle={draftWidth(drafts.primary || placeholderText || '')}\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tvalue={drafts.primary}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{renderUnitSuffix(displayUnit)}\n\t\t\t\t\t\t</>\n\t\t\t\t\t)}\n\t\t\t\t\t{renderMenuTrigger()}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,MAAM,YAAY;;AAGlB,MAAM,oBAAoB,iBAAiB,CAAC,CAAC;AAE7C,MAAM,QAAqB;CAAE,OAAO;CAAO,SAAS;AAAM;;;;;;;AAQ1D,MAAM,cAAc,WAAwC,EAC3D,OAAO,GAAG,KAAK,IAAI,KAAK,IAAI,MAAM,QAAQ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,OAAO;KACd,CAAA,GACA,iBAAiB,WAAW,CAC5B,EAAA,CAAA,GAEF,kBAAkB,CACf;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"MeasurementField.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementField.tsx"],"sourcesContent":["'use client'\nimport { useField } from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { NumberFieldClientProps, Validate } from 'payload'\nimport { number } 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 { MeasurementResolvedClientOptions } from '../options'\nimport { MeasurementInputView } from './MeasurementInput'\nimport { useMeasurementModel } from './useMeasurementModel'\n\nexport type MeasurementFieldProps = {\n\tmeasurementOptions: MeasurementResolvedClientOptions\n} & NumberFieldClientProps\n\n/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */\nexport const MeasurementField: React.FC<MeasurementFieldProps> = (props) => {\n\tconst {\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\tmax,\n\t\t\tmin,\n\t\t\tname,\n\t\t\trequired,\n\t\t},\n\t\tmeasurementOptions,\n\t\tpath: pathFromProps,\n\t\treadOnly: readOnlyFromProps,\n\t} = props\n\tconst { t } = useTranslation()\n\tconst model = useMeasurementModel(measurementOptions)\n\tconst { fmtBound } = model\n\n\tconst memoizedValidate = useCallback<Validate<number | null | undefined>>(\n\t\t(value, options) => {\n\t\t\tif (typeof value === 'number' && !Number.isNaN(value)) {\n\t\t\t\tif (typeof min === 'number' && value < min) {\n\t\t\t\t\treturn t(keys.measurementBelowMin, { min: fmtBound(min) })\n\t\t\t\t}\n\t\t\t\tif (typeof max === 'number' && value > max) {\n\t\t\t\t\treturn t(keys.measurementAboveMax, { max: fmtBound(max) })\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn number(value, {\n\t\t\t\t...options,\n\t\t\t\tmax: undefined,\n\t\t\t\tmin: undefined,\n\t\t\t\tname,\n\t\t\t\trequired,\n\t\t\t\ttype: 'number',\n\t\t\t} as Parameters<typeof number>[1])\n\t\t},\n\t\t[fmtBound, max, min, 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<number | null>({ 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\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<MeasurementInputView\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\tmax={max}\n\t\t\tmin={min}\n\t\t\tmodel={model}\n\t\t\tonChange={setValue}\n\t\t\tpath={path}\n\t\t\tplaceholder={typeof placeholder === 'string' ? placeholder : undefined}\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":";;;;;;;;;;;;AAkBA,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EACL,OACA,OAAO,EACN,OAAO,EAAE,WAAW,aAAa,aAAa,UAAU,sBAAsB,CAAC,GAC/E,OACA,WACA,KACA,KACA,MACA,YAED,oBACA,MAAM,eACN,UAAU,sBACP;CACJ,MAAM,EAAE,MAAMA,iBAAe;CAC7B,MAAM,QAAQ,oBAAoB,kBAAkB;CACpD,MAAM,EAAE,aAAa;CAwBrB,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,MACA,UACA,WACA,UACG,SAAwB;EAAE,sBAAsB;EAAe,UA7B1C,aACvB,OAAO,YAAY;GACnB,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,KAAK,GAAG;IACtD,IAAI,OAAO,QAAQ,YAAY,QAAQ,KACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,SAAS,GAAG,EAAE,CAAC;IAE1D,IAAI,OAAO,QAAQ,YAAY,QAAQ,KACtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,SAAS,GAAG,EAAE,CAAC;GAE3D;GACA,OAAO,OAAO,OAAO;IACpB,GAAG;IACH,KAAK,KAAA;IACL,KAAK,KAAA;IACL;IACA;IACA,MAAM;GACP,CAAiC;EAClC,GACA;GAAC;GAAU;GAAK;GAAK;GAAM;GAAU;EAAC,CAUqD;CAAE,CAAC;CAI/F,MAAM,aAAa,QAAQ,qBAAqB,YAAY,iBAAiB;CAC7E,MAAM,SAAS,cAAc,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;CAE7D,OACC,oBAAC,sBAAD;EACa;EACC;EACF;EACE;EACA;EACb,OAAO;EACA;EACA;EACI;EACN;EACA;EACE;EACP,UAAU;EACJ;EACN,aAAa,OAAO,gBAAgB,WAAW,cAAc,KAAA;EAC7D,UAAU;EACA;EACC;EACX,OAAO;EACA;CACP,CAAA;AAEH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MeasurementInputOptions } from "./useMeasurementModel.js";
|
|
2
|
+
import { StaticDescription, StaticLabel } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/measurement/client/MeasurementInput.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the form-free measurement input. `value` is the number in
|
|
7
|
+
* `options.storageUnit`, exactly as `measurementField` stores it; the viewer reads and
|
|
8
|
+
* types in their display unit.
|
|
9
|
+
*/
|
|
10
|
+
type MeasurementInputProps = {
|
|
11
|
+
value: null | number | undefined; /** Fires on every edit with the value converted back to the storage unit. */
|
|
12
|
+
onChange: (value: null | number) => void;
|
|
13
|
+
options: MeasurementInputOptions; /** Bounds in the storage unit; a value outside them shows a message in the display unit. */
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number; /** 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; /** Message shown in the error tooltip. Left unset, the input reports its own bound errors. */
|
|
23
|
+
error?: string; /** Forces the error state on or off. Left unset, it follows `error` and the bound check. */
|
|
24
|
+
showError?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
Label?: React.ReactNode;
|
|
28
|
+
Error?: React.ReactNode;
|
|
29
|
+
Description?: React.ReactNode;
|
|
30
|
+
BeforeInput?: React.ReactNode;
|
|
31
|
+
AfterInput?: React.ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The measurement field's row, unit menu and conversion pipeline with no form behind
|
|
35
|
+
* it, for custom admin views and components. Inside the admin the display unit is the
|
|
36
|
+
* viewer's saved preference for `preferenceKey`, shared with every measurement field
|
|
37
|
+
* on that key; `MeasurementField` is this plus `useField`.
|
|
38
|
+
*/
|
|
39
|
+
declare const MeasurementInput: React.FC<MeasurementInputProps>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { MeasurementInput, MeasurementInputProps };
|
|
42
|
+
//# sourceMappingURL=MeasurementInput.d.ts.map
|