@10x-media/fields 0.1.0-beta.0 → 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 +173 -0
- package/README.md +8 -4
- package/dist/exports/client.d.ts +10 -1
- package/dist/exports/client.js +9 -1
- package/dist/exports/color-utils.d.ts +4 -2
- package/dist/exports/color-utils.js +3 -1
- package/dist/exports/color.d.ts +5 -2
- package/dist/exports/color.js +4 -1
- package/dist/exports/encrypted.d.ts +7 -4
- package/dist/exports/encrypted.js +6 -3
- package/dist/exports/icon-adapters/radix.d.ts +2 -2
- package/dist/exports/icon-adapters/radix.js +2 -2
- package/dist/exports/icon-react.d.ts +2 -2
- package/dist/exports/icon.d.ts +6 -2
- package/dist/exports/icon.js +6 -2
- 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 -288
- 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 +31 -5
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
- package/dist/fields/color/client/colorField.css +30 -0
- package/dist/fields/color/colorField.d.ts +9 -2
- package/dist/fields/color/colorField.js +68 -15
- package/dist/fields/color/colorField.js.map +1 -1
- package/dist/fields/color/engine/index.d.ts +2 -1
- package/dist/fields/color/engine/scheme.d.ts +13 -0
- package/dist/fields/color/engine/scheme.js +12 -0
- package/dist/fields/color/engine/scheme.js.map +1 -0
- package/dist/fields/color/options.d.ts +5 -4
- package/dist/fields/color/options.js.map +1 -1
- package/dist/fields/color/paths.d.ts +1 -0
- package/dist/fields/color/paths.js +32 -0
- package/dist/fields/color/paths.js.map +1 -0
- 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/presetsFromArray.d.ts +30 -0
- package/dist/fields/color/presetsFromArray.js +58 -0
- package/dist/fields/color/presetsFromArray.js.map +1 -0
- package/dist/fields/color/presetsFromDoc.js +1 -23
- package/dist/fields/color/presetsFromDoc.js.map +1 -1
- package/dist/fields/color/resolvePresets.d.ts +2 -2
- package/dist/fields/color/resolvePresets.js +38 -8
- package/dist/fields/color/resolvePresets.js.map +1 -1
- package/dist/fields/color/schemeValue.js +30 -0
- package/dist/fields/color/schemeValue.js.map +1 -0
- package/dist/fields/color/server/ColorCell.js +9 -3
- 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/adapter.js +7 -0
- package/dist/fields/icon/adapters/radix/adapter.js.map +1 -1
- package/dist/fields/icon/adapters/radix/client.d.ts +3 -2
- package/dist/fields/icon/adapters/radix/client.js +3 -2
- package/dist/fields/icon/adapters/radix/client.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 +3625 -0
- package/dist/fields/icon/adapters/radix/generated/nodes.js.map +1 -0
- 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/DrawerGlyph.js +34 -17
- package/dist/fields/icon/client/DrawerGlyph.js.map +1 -1
- package/dist/fields/icon/client/IconDrawerContent.js +9 -45
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
- package/dist/fields/icon/client/IconFieldClient.d.ts +7 -0
- package/dist/fields/icon/client/IconFieldClient.js +15 -7
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
- package/dist/fields/icon/client/IconGridCell.js +67 -0
- package/dist/fields/icon/client/IconGridCell.js.map +1 -0
- package/dist/fields/icon/client/icon-field.css +12 -2
- package/dist/fields/icon/codegen/emit.js +5 -4
- package/dist/fields/icon/codegen/emit.js.map +1 -1
- package/dist/fields/icon/codegen/generate.js +32 -6
- package/dist/fields/icon/codegen/generate.js.map +1 -1
- package/dist/fields/icon/layers/coalesce.js +41 -0
- package/dist/fields/icon/layers/coalesce.js.map +1 -0
- package/dist/fields/icon/layers/manifestCache.d.ts +6 -0
- package/dist/fields/icon/layers/manifestCache.js +49 -0
- package/dist/fields/icon/layers/manifestCache.js.map +1 -0
- package/dist/fields/icon/layers/resolve.d.ts +20 -0
- package/dist/fields/icon/layers/resolve.js +63 -0
- package/dist/fields/icon/layers/resolve.js.map +1 -0
- package/dist/fields/icon/layers/upload.d.ts +52 -0
- package/dist/fields/icon/layers/upload.js +116 -0
- package/dist/fields/icon/layers/upload.js.map +1 -0
- package/dist/fields/icon/plugin.js +24 -0
- package/dist/fields/icon/plugin.js.map +1 -1
- package/dist/fields/icon/react/createIcon.d.ts +5 -0
- package/dist/fields/icon/react/createIcon.js +22 -4
- package/dist/fields/icon/react/createIcon.js.map +1 -1
- package/dist/fields/icon/react/createRscIcon.js +22 -1
- package/dist/fields/icon/react/createRscIcon.js.map +1 -1
- package/dist/fields/icon/react/resolveRendered.js +21 -0
- package/dist/fields/icon/react/resolveRendered.js.map +1 -0
- package/dist/fields/icon/react/types.d.ts +15 -1
- package/dist/fields/icon/rsc/IconCell.d.ts +2 -2
- package/dist/fields/icon/rsc/IconCell.js +12 -5
- package/dist/fields/icon/rsc/IconCell.js.map +1 -1
- package/dist/fields/icon/rsc/IconFieldServer.js +16 -2
- 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/server/endpoint.d.ts +12 -0
- package/dist/fields/icon/server/endpoint.js +52 -0
- package/dist/fields/icon/server/endpoint.js.map +1 -0
- package/dist/fields/icon/server/manifestCache.js +9 -4
- package/dist/fields/icon/server/manifestCache.js.map +1 -1
- package/dist/fields/icon/server/resolveIconMeta.js +31 -0
- package/dist/fields/icon/server/resolveIconMeta.js.map +1 -0
- package/dist/fields/icon/server/validate.js +5 -2
- package/dist/fields/icon/server/validate.js.map +1 -1
- package/dist/fields/icon/shared/adapterComponents.d.ts +3 -2
- package/dist/fields/icon/shared/iconLabel.js +26 -0
- package/dist/fields/icon/shared/iconLabel.js.map +1 -0
- 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 +165 -8
- package/dist/utils/resolveStaticLabel.js +13 -0
- package/dist/utils/resolveStaticLabel.js.map +1 -0
- package/package.json +31 -7
- package/dist/fields/icon/rsc/resolveStaticLabel.js +0 -16
- package/dist/fields/icon/rsc/resolveStaticLabel.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
2
|
+
import { ClientField, DefaultCellComponentProps } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
//#region src/fields/measurement/client/MeasurementCell.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* `field` and `onClick` are excluded and re-added as optional: the RSC cell only
|
|
7
|
+
* carries the server-sanitized Field (which serializes functions Payload attaches,
|
|
8
|
+
* e.g. hooks/validate), never a ClientField, and no onClick handler crosses the
|
|
9
|
+
* flight boundary. This cell reads neither, so both stay optional rather than forced.
|
|
10
|
+
*/
|
|
11
|
+
type MeasurementCellProps = {
|
|
12
|
+
measurementOptions: MeasurementResolvedClientOptions;
|
|
13
|
+
field?: ClientField;
|
|
14
|
+
} & Omit<DefaultCellComponentProps, 'field' | 'onClick'>;
|
|
15
|
+
declare const MeasurementCell: React.FC<MeasurementCellProps>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MeasurementCell, MeasurementCellProps };
|
|
18
|
+
//# sourceMappingURL=MeasurementCell.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { exactModePrecisionOverride, resolvePrecision } from "../engine/precision.js";
|
|
3
|
+
import { useTranslation } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { resolveDisplayUnit, systemForLocale } from "../engine/locale.js";
|
|
5
|
+
import { createEngine, defaultEngine } from "../engine/registry.js";
|
|
6
|
+
import { useMeasurementUnits } from "./MeasurementUnitsProvider.js";
|
|
7
|
+
import { useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
import "./measurementCell.css";
|
|
10
|
+
//#region src/fields/measurement/client/MeasurementCell.tsx
|
|
11
|
+
/** MeasurementCellServer always resolves and threads precision; this only covers a hand-authored Cell with no server wrapper. */
|
|
12
|
+
const DEFAULT_PRECISION = resolvePrecision([]);
|
|
13
|
+
const MeasurementCell = (props) => {
|
|
14
|
+
const { cellData, measurementOptions } = props;
|
|
15
|
+
const { custom, dimension, fallbackUnit, localeDefaults, precision, preferenceKey, registryDefault, storageUnit, units } = measurementOptions;
|
|
16
|
+
const { i18n } = useTranslation();
|
|
17
|
+
const context = useMeasurementUnits();
|
|
18
|
+
const engine = useMemo(() => custom ? createEngine(custom) : defaultEngine, [custom]);
|
|
19
|
+
const [system, setSystem] = useState(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (context) setSystem(systemForLocale(navigator.language));
|
|
22
|
+
}, [context]);
|
|
23
|
+
if (typeof cellData !== "number" || Number.isNaN(cellData)) return null;
|
|
24
|
+
const displayUnit = resolveDisplayUnit({
|
|
25
|
+
dimension,
|
|
26
|
+
fallbackUnit,
|
|
27
|
+
localeDefaults,
|
|
28
|
+
preferenceUnit: context?.units[preferenceKey] ?? null,
|
|
29
|
+
registryDefault,
|
|
30
|
+
system,
|
|
31
|
+
units
|
|
32
|
+
});
|
|
33
|
+
const precisionOverride = exactModePrecisionOverride(precision ?? DEFAULT_PRECISION, displayUnit);
|
|
34
|
+
return /* @__PURE__ */ jsx("span", {
|
|
35
|
+
className: "fields-measurement-cell",
|
|
36
|
+
children: engine.formatMeasurement(cellData, {
|
|
37
|
+
displayUnit,
|
|
38
|
+
locale: i18n.language,
|
|
39
|
+
precision: precisionOverride,
|
|
40
|
+
storageUnit
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { MeasurementCell };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=MeasurementCell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeasurementCell.js","names":[],"sources":["../../../../src/fields/measurement/client/MeasurementCell.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, DefaultCellComponentProps } from 'payload'\nimport type React from 'react'\nimport { useEffect, useMemo, useState } from 'react'\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 type { MeasurementResolvedClientOptions } from '../options'\nimport { resolveDisplayUnit } from './editModel'\nimport { useMeasurementUnits } from './MeasurementUnitsProvider'\nimport './measurementCell.css'\n\n/** MeasurementCellServer always resolves and threads precision; this only covers a hand-authored Cell with no server wrapper. */\nconst DEFAULT_PRECISION = resolvePrecision([])\n\n/**\n * `field` and `onClick` are excluded and re-added as optional: the RSC cell only\n * carries the server-sanitized Field (which serializes functions Payload attaches,\n * e.g. hooks/validate), never a ClientField, and no onClick handler crosses the\n * flight boundary. This cell reads neither, so both stay optional rather than forced.\n */\nexport type MeasurementCellProps = {\n\tmeasurementOptions: MeasurementResolvedClientOptions\n\tfield?: ClientField\n} & Omit<DefaultCellComponentProps, 'field' | 'onClick'>\n\nexport const MeasurementCell: React.FC<MeasurementCellProps> = (props) => {\n\tconst { cellData, measurementOptions } = props\n\tconst {\n\t\tcustom,\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tprecision,\n\t\tpreferenceKey,\n\t\tregistryDefault,\n\t\tstorageUnit,\n\t\tunits,\n\t} = measurementOptions\n\tconst { i18n } = useTranslation()\n\tconst context = useMeasurementUnits()\n\tconst engine = useMemo(() => (custom ? createEngine(custom) : defaultEngine), [custom])\n\tconst [system, setSystem] = useState<MeasurementSystem | null>(null)\n\t// Gated on the provider: plugin-less cells stay on the field default, not the browser locale.\n\tuseEffect(() => {\n\t\tif (context) setSystem(systemForLocale(navigator.language))\n\t}, [context])\n\n\tif (typeof cellData !== 'number' || Number.isNaN(cellData)) return null\n\n\tconst displayUnit = resolveDisplayUnit({\n\t\tdimension,\n\t\tfallbackUnit,\n\t\tlocaleDefaults,\n\t\tpreferenceUnit: context?.units[preferenceKey] ?? null,\n\t\tregistryDefault,\n\t\tsystem,\n\t\tunits,\n\t})\n\tconst resolvedPrecision = precision ?? DEFAULT_PRECISION\n\t// The override key is the unit id itself, so it works for a compound displayUnit\n\t// too: precisionFor/formatMeasurement treat that key as the compound's minor digits.\n\tconst precisionOverride = exactModePrecisionOverride(resolvedPrecision, displayUnit)\n\treturn (\n\t\t<span className=\"fields-measurement-cell\">\n\t\t\t{engine.formatMeasurement(cellData, {\n\t\t\t\tdisplayUnit,\n\t\t\t\tlocale: i18n.language,\n\t\t\t\tprecision: precisionOverride,\n\t\t\t\tstorageUnit,\n\t\t\t})}\n\t\t</span>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,oBAAoB,iBAAiB,CAAC,CAAC;AAa7C,MAAa,mBAAmD,UAAU;CACzE,MAAM,EAAE,UAAU,uBAAuB;CACzC,MAAM,EACL,QACA,WACA,cACA,gBACA,WACA,eACA,iBACA,aACA,UACG;CACJ,MAAM,EAAE,SAAS,eAAe;CAChC,MAAM,UAAU,oBAAoB;CACpC,MAAM,SAAS,cAAe,SAAS,aAAa,MAAM,IAAI,eAAgB,CAAC,MAAM,CAAC;CACtF,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CAEnE,gBAAgB;EACf,IAAI,SAAS,UAAU,gBAAgB,UAAU,QAAQ,CAAC;CAC3D,GAAG,CAAC,OAAO,CAAC;CAEZ,IAAI,OAAO,aAAa,YAAY,OAAO,MAAM,QAAQ,GAAG,OAAO;CAEnE,MAAM,cAAc,mBAAmB;EACtC;EACA;EACA;EACA,gBAAgB,SAAS,MAAM,kBAAkB;EACjD;EACA;EACA;CACD,CAAC;CAID,MAAM,oBAAoB,2BAHA,aAAa,mBAGiC,WAAW;CACnF,OACC,oBAAC,QAAD;EAAM,WAAU;YACd,OAAO,kBAAkB,UAAU;GACnC;GACA,QAAQ,KAAK;GACb,WAAW;GACX;EACD,CAAC;CACI,CAAA;AAER"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MeasurementResolvedClientOptions } from "../options.js";
|
|
2
|
+
import { NumberFieldClientProps } from "payload";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/fields/measurement/client/MeasurementField.d.ts
|
|
6
|
+
type MeasurementFieldProps = {
|
|
7
|
+
measurementOptions: MeasurementResolvedClientOptions;
|
|
8
|
+
} & NumberFieldClientProps;
|
|
9
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
10
|
+
declare const MeasurementField: React.FC<MeasurementFieldProps>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MeasurementField, MeasurementFieldProps };
|
|
13
|
+
//# sourceMappingURL=MeasurementField.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { keys } from "../../../translations/keys.js";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
4
|
+
import { useMeasurementModel } from "./useMeasurementModel.js";
|
|
5
|
+
import { MeasurementInputView } from "./MeasurementInput.js";
|
|
6
|
+
import { number } from "payload/shared";
|
|
7
|
+
import { useField } from "@payloadcms/ui";
|
|
8
|
+
import { mergeFieldStyles } from "@payloadcms/ui/shared";
|
|
9
|
+
import { useCallback, useMemo } from "react";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
//#region src/fields/measurement/client/MeasurementField.tsx
|
|
12
|
+
/** The measurement row bound to the document form through `useField`, with unit-aware bound messages. */
|
|
13
|
+
const MeasurementField = (props) => {
|
|
14
|
+
const { field, field: { admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {}, label, localized, max, min, name, required }, measurementOptions, path: pathFromProps, readOnly: readOnlyFromProps } = props;
|
|
15
|
+
const { t } = useTranslation$1();
|
|
16
|
+
const model = useMeasurementModel(measurementOptions);
|
|
17
|
+
const { fmtBound } = model;
|
|
18
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {}, disabled, path, setValue, showError, value } = useField({
|
|
19
|
+
potentiallyStalePath: pathFromProps,
|
|
20
|
+
validate: useCallback((value, options) => {
|
|
21
|
+
if (typeof value === "number" && !Number.isNaN(value)) {
|
|
22
|
+
if (typeof min === "number" && value < min) return t(keys.measurementBelowMin, { min: fmtBound(min) });
|
|
23
|
+
if (typeof max === "number" && value > max) return t(keys.measurementAboveMax, { max: fmtBound(max) });
|
|
24
|
+
}
|
|
25
|
+
return number(value, {
|
|
26
|
+
...options,
|
|
27
|
+
max: void 0,
|
|
28
|
+
min: void 0,
|
|
29
|
+
name,
|
|
30
|
+
required,
|
|
31
|
+
type: "number"
|
|
32
|
+
});
|
|
33
|
+
}, [
|
|
34
|
+
fmtBound,
|
|
35
|
+
max,
|
|
36
|
+
min,
|
|
37
|
+
name,
|
|
38
|
+
required,
|
|
39
|
+
t
|
|
40
|
+
])
|
|
41
|
+
});
|
|
42
|
+
const isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin);
|
|
43
|
+
const styles = useMemo(() => mergeFieldStyles(field), [field]);
|
|
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,
|
|
63
|
+
style: styles,
|
|
64
|
+
value
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { MeasurementField };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=MeasurementField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { COMPOUNDS } from "../engine/units.js";
|
|
3
|
+
import { keys } from "../../../translations/keys.js";
|
|
4
|
+
import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
|
|
5
|
+
import { commitDrafts, draftsFor } from "./editModel.js";
|
|
6
|
+
import { useMeasurementModel } from "./useMeasurementModel.js";
|
|
7
|
+
import { FieldDescription, FieldError, FieldLabel, Popup, RenderCustomComponent, fieldBaseClass } from "@payloadcms/ui";
|
|
8
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import "./measurementField.css";
|
|
11
|
+
//#region src/fields/measurement/client/MeasurementInput.tsx
|
|
12
|
+
const baseClass = "fields-measurement";
|
|
13
|
+
const CLEAN = {
|
|
14
|
+
minor: false,
|
|
15
|
+
primary: false
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Every value input sizes to its content so "5 ft 11 in" (or a lone scalar)
|
|
19
|
+
* reads as one left-aligned phrase. The half-ch keeps the caret off the edge;
|
|
20
|
+
* the clamp keeps an empty input clickable and a runaway draft from pushing
|
|
21
|
+
* the row into overflow.
|
|
22
|
+
*/
|
|
23
|
+
const draftWidth = (draft) => ({ width: `${Math.min(Math.max(draft.length, 2), 12) + .5}ch` });
|
|
24
|
+
const unitKebab = /* @__PURE__ */ jsxs("svg", {
|
|
25
|
+
"aria-hidden": "true",
|
|
26
|
+
className: `${baseClass}__kebab`,
|
|
27
|
+
focusable: "false",
|
|
28
|
+
viewBox: "0 0 4 16",
|
|
29
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ jsx("circle", {
|
|
32
|
+
cx: "2",
|
|
33
|
+
cy: "2",
|
|
34
|
+
fill: "currentColor",
|
|
35
|
+
r: "1.6"
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ jsx("circle", {
|
|
38
|
+
cx: "2",
|
|
39
|
+
cy: "8",
|
|
40
|
+
fill: "currentColor",
|
|
41
|
+
r: "1.6"
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx("circle", {
|
|
44
|
+
cx: "2",
|
|
45
|
+
cy: "14",
|
|
46
|
+
fill: "currentColor",
|
|
47
|
+
r: "1.6"
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
/** The row itself, shared by `MeasurementInput` and the form-bound `MeasurementField`. */
|
|
52
|
+
const MeasurementInputView = (props) => {
|
|
53
|
+
const { AfterInput, BeforeInput, className, Description, description, Error: ErrorComponent, error, Label, label, localized, max, min, model, onChange, path, placeholder, readOnly, required, showError: showErrorFromProps, style, value } = props;
|
|
54
|
+
const { displayPrecision, displayUnit, engine, fmtBound, locale, resolvedPrecision, selectUnit: selectModelUnit, storageUnit, units } = model;
|
|
55
|
+
const { t } = useTranslation$1();
|
|
56
|
+
const isReadOnly = Boolean(readOnly);
|
|
57
|
+
const numericValue = typeof value === "number" && !Number.isNaN(value) ? value : null;
|
|
58
|
+
const draftOpts = useMemo(() => ({
|
|
59
|
+
displayUnit,
|
|
60
|
+
draft: resolvedPrecision.draft,
|
|
61
|
+
engine,
|
|
62
|
+
precision: displayPrecision,
|
|
63
|
+
storageDigits: resolvedPrecision.storage,
|
|
64
|
+
storageUnit
|
|
65
|
+
}), [
|
|
66
|
+
displayUnit,
|
|
67
|
+
engine,
|
|
68
|
+
displayPrecision,
|
|
69
|
+
resolvedPrecision,
|
|
70
|
+
storageUnit
|
|
71
|
+
]);
|
|
72
|
+
const boundsMessage = useMemo(() => {
|
|
73
|
+
if (numericValue === null) return void 0;
|
|
74
|
+
if (typeof min === "number" && numericValue < min) return t(keys.measurementBelowMin, { min: fmtBound(min) });
|
|
75
|
+
if (typeof max === "number" && numericValue > max) return t(keys.measurementAboveMax, { max: fmtBound(max) });
|
|
76
|
+
}, [
|
|
77
|
+
numericValue,
|
|
78
|
+
min,
|
|
79
|
+
max,
|
|
80
|
+
fmtBound,
|
|
81
|
+
t
|
|
82
|
+
]);
|
|
83
|
+
const errorMessage = error ?? boundsMessage;
|
|
84
|
+
const showError = showErrorFromProps ?? errorMessage !== void 0;
|
|
85
|
+
const editingRef = useRef(false);
|
|
86
|
+
const [drafts, setDrafts] = useState(() => draftsFor(numericValue, draftOpts));
|
|
87
|
+
const paintedDraftsRef = useRef(drafts);
|
|
88
|
+
const paintedStoredRef = useRef(numericValue);
|
|
89
|
+
const [dirty, setDirty] = useState(CLEAN);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (!editingRef.current) {
|
|
92
|
+
const resynced = draftsFor(numericValue, draftOpts);
|
|
93
|
+
setDrafts(resynced);
|
|
94
|
+
paintedDraftsRef.current = resynced;
|
|
95
|
+
paintedStoredRef.current = numericValue;
|
|
96
|
+
setDirty(CLEAN);
|
|
97
|
+
}
|
|
98
|
+
}, [numericValue, draftOpts]);
|
|
99
|
+
const onDraftChange = useCallback((part) => (event) => {
|
|
100
|
+
editingRef.current = true;
|
|
101
|
+
const next = {
|
|
102
|
+
...drafts,
|
|
103
|
+
[part]: event.target.value
|
|
104
|
+
};
|
|
105
|
+
const nextDirty = {
|
|
106
|
+
...dirty,
|
|
107
|
+
[part]: true
|
|
108
|
+
};
|
|
109
|
+
setDrafts(next);
|
|
110
|
+
setDirty(nextDirty);
|
|
111
|
+
onChange(commitDrafts(next, {
|
|
112
|
+
...draftOpts,
|
|
113
|
+
dirty: nextDirty,
|
|
114
|
+
entry: resolvedPrecision.entry,
|
|
115
|
+
paintedDrafts: paintedDraftsRef.current,
|
|
116
|
+
storedValue: paintedStoredRef.current
|
|
117
|
+
}));
|
|
118
|
+
}, [
|
|
119
|
+
dirty,
|
|
120
|
+
drafts,
|
|
121
|
+
draftOpts,
|
|
122
|
+
onChange,
|
|
123
|
+
resolvedPrecision.entry
|
|
124
|
+
]);
|
|
125
|
+
const onBlur = useCallback(() => {
|
|
126
|
+
editingRef.current = false;
|
|
127
|
+
const resynced = draftsFor(numericValue, draftOpts);
|
|
128
|
+
setDrafts(resynced);
|
|
129
|
+
paintedDraftsRef.current = resynced;
|
|
130
|
+
paintedStoredRef.current = numericValue;
|
|
131
|
+
setDirty(CLEAN);
|
|
132
|
+
}, [numericValue, draftOpts]);
|
|
133
|
+
const selectUnit = useCallback((unit) => {
|
|
134
|
+
editingRef.current = false;
|
|
135
|
+
setDirty(CLEAN);
|
|
136
|
+
selectModelUnit(unit);
|
|
137
|
+
}, [selectModelUnit]);
|
|
138
|
+
const isCompound = engine.isCompoundUnit(displayUnit);
|
|
139
|
+
const compoundDef = isCompound ? COMPOUNDS[displayUnit] : null;
|
|
140
|
+
const generatedId = useId();
|
|
141
|
+
const inputId = path ? `field-${path.replace(/\./g, "__")}` : generatedId;
|
|
142
|
+
const primaryInputRef = useRef(null);
|
|
143
|
+
const minorInputRef = useRef(null);
|
|
144
|
+
const focusNearestInput = useCallback((event) => {
|
|
145
|
+
const target = event.target;
|
|
146
|
+
const isUnitSuffix = target.closest(`.${baseClass}__unit-static`) !== null;
|
|
147
|
+
if (target !== event.currentTarget && !isUnitSuffix) return;
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
const active = document.activeElement;
|
|
150
|
+
if (active === primaryInputRef.current || active === minorInputRef.current) return;
|
|
151
|
+
const [first, ...rest] = [primaryInputRef.current, minorInputRef.current].filter((input) => input !== null);
|
|
152
|
+
if (!first) return;
|
|
153
|
+
const distanceFrom = (input) => {
|
|
154
|
+
const rect = input.getBoundingClientRect();
|
|
155
|
+
return Math.abs(event.clientX - (rect.left + rect.width / 2));
|
|
156
|
+
};
|
|
157
|
+
let nearest = first;
|
|
158
|
+
let nearestDistance = distanceFrom(first);
|
|
159
|
+
for (const input of rest) {
|
|
160
|
+
const distance = distanceFrom(input);
|
|
161
|
+
if (distance < nearestDistance) {
|
|
162
|
+
nearestDistance = distance;
|
|
163
|
+
nearest = input;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
nearest.focus();
|
|
167
|
+
}, []);
|
|
168
|
+
const isUnitInteractive = units.length > 1 && !isReadOnly;
|
|
169
|
+
const renderUnitPanel = ({ close }) => /* @__PURE__ */ jsx("div", {
|
|
170
|
+
"aria-label": t(keys.selectUnit),
|
|
171
|
+
className: `${baseClass}__unit-panel`,
|
|
172
|
+
role: "listbox",
|
|
173
|
+
children: units.map((unit) => /* @__PURE__ */ jsxs("button", {
|
|
174
|
+
"aria-selected": unit === displayUnit,
|
|
175
|
+
className: `${baseClass}__unit-option`,
|
|
176
|
+
onClick: () => {
|
|
177
|
+
selectUnit(unit);
|
|
178
|
+
close();
|
|
179
|
+
},
|
|
180
|
+
role: "option",
|
|
181
|
+
type: "button",
|
|
182
|
+
children: [/* @__PURE__ */ jsx("span", { children: engine.unitLabel(unit, locale, "long") }), /* @__PURE__ */ jsx("span", {
|
|
183
|
+
className: `${baseClass}__unit-symbol`,
|
|
184
|
+
children: engine.unitLabel(unit, locale, "short")
|
|
185
|
+
})]
|
|
186
|
+
}, unit))
|
|
187
|
+
});
|
|
188
|
+
const renderUnitSuffix = (unit) => /* @__PURE__ */ jsx("span", {
|
|
189
|
+
className: `${baseClass}__unit-static`,
|
|
190
|
+
children: engine.unitLabel(unit, locale, "short")
|
|
191
|
+
});
|
|
192
|
+
const renderMenuTrigger = () => {
|
|
193
|
+
if (!isUnitInteractive) return null;
|
|
194
|
+
const shortLabel = engine.unitLabel(displayUnit, locale, "short");
|
|
195
|
+
return /* @__PURE__ */ jsx(Popup, {
|
|
196
|
+
button: /* @__PURE__ */ jsxs(Fragment$1, { children: [unitKebab, /* @__PURE__ */ jsxs("span", {
|
|
197
|
+
className: `${baseClass}__sr-only`,
|
|
198
|
+
children: [
|
|
199
|
+
t(keys.selectUnit),
|
|
200
|
+
": ",
|
|
201
|
+
shortLabel
|
|
202
|
+
]
|
|
203
|
+
})] }),
|
|
204
|
+
buttonClassName: `${baseClass}__unit-trigger`,
|
|
205
|
+
buttonType: "default",
|
|
206
|
+
caret: false,
|
|
207
|
+
className: `${baseClass}__popup`,
|
|
208
|
+
horizontalAlign: "right",
|
|
209
|
+
render: renderUnitPanel,
|
|
210
|
+
size: "fit-content",
|
|
211
|
+
verticalAlign: "bottom"
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
215
|
+
className: [
|
|
216
|
+
fieldBaseClass,
|
|
217
|
+
baseClass,
|
|
218
|
+
className,
|
|
219
|
+
showError && "error",
|
|
220
|
+
isReadOnly && "read-only"
|
|
221
|
+
].filter(Boolean).join(" "),
|
|
222
|
+
style,
|
|
223
|
+
children: [/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
224
|
+
CustomComponent: Label,
|
|
225
|
+
Fallback: /* @__PURE__ */ jsx(FieldLabel, {
|
|
226
|
+
htmlFor: path ? void 0 : inputId,
|
|
227
|
+
label,
|
|
228
|
+
localized,
|
|
229
|
+
path,
|
|
230
|
+
required
|
|
231
|
+
})
|
|
232
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
233
|
+
className: `${fieldBaseClass}__wrap`,
|
|
234
|
+
children: [
|
|
235
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
236
|
+
CustomComponent: ErrorComponent,
|
|
237
|
+
Fallback: /* @__PURE__ */ jsx(FieldError, {
|
|
238
|
+
message: errorMessage,
|
|
239
|
+
path,
|
|
240
|
+
showError
|
|
241
|
+
})
|
|
242
|
+
}),
|
|
243
|
+
BeforeInput,
|
|
244
|
+
/* @__PURE__ */ jsxs("div", {
|
|
245
|
+
className: `${baseClass}__container`,
|
|
246
|
+
onMouseDown: focusNearestInput,
|
|
247
|
+
children: [isCompound && compoundDef ? /* @__PURE__ */ jsxs("span", {
|
|
248
|
+
className: `${baseClass}__compound`,
|
|
249
|
+
onMouseDown: focusNearestInput,
|
|
250
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
251
|
+
className: `${baseClass}__part`,
|
|
252
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
253
|
+
className: `${baseClass}__input`,
|
|
254
|
+
id: inputId,
|
|
255
|
+
inputMode: "decimal",
|
|
256
|
+
name: path,
|
|
257
|
+
onBlur,
|
|
258
|
+
onChange: onDraftChange("primary"),
|
|
259
|
+
readOnly: isReadOnly,
|
|
260
|
+
ref: primaryInputRef,
|
|
261
|
+
step: "any",
|
|
262
|
+
style: draftWidth(drafts.primary),
|
|
263
|
+
type: "number",
|
|
264
|
+
value: drafts.primary
|
|
265
|
+
}), renderUnitSuffix(compoundDef.major)]
|
|
266
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
267
|
+
className: `${baseClass}__part`,
|
|
268
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
269
|
+
"aria-label": engine.unitLabel(compoundDef.minor, locale, "long"),
|
|
270
|
+
className: `${baseClass}__input`,
|
|
271
|
+
inputMode: "decimal",
|
|
272
|
+
max: compoundDef.ratio - .001,
|
|
273
|
+
min: 0,
|
|
274
|
+
onBlur,
|
|
275
|
+
onChange: onDraftChange("minor"),
|
|
276
|
+
readOnly: isReadOnly,
|
|
277
|
+
ref: minorInputRef,
|
|
278
|
+
step: "any",
|
|
279
|
+
style: draftWidth(drafts.minor),
|
|
280
|
+
type: "number",
|
|
281
|
+
value: drafts.minor
|
|
282
|
+
}), renderUnitSuffix(compoundDef.minor)]
|
|
283
|
+
})]
|
|
284
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("input", {
|
|
285
|
+
className: `${baseClass}__input`,
|
|
286
|
+
id: inputId,
|
|
287
|
+
inputMode: "decimal",
|
|
288
|
+
name: path,
|
|
289
|
+
onBlur,
|
|
290
|
+
onChange: onDraftChange("primary"),
|
|
291
|
+
placeholder,
|
|
292
|
+
readOnly: isReadOnly,
|
|
293
|
+
ref: primaryInputRef,
|
|
294
|
+
step: "any",
|
|
295
|
+
style: draftWidth(drafts.primary || placeholder || ""),
|
|
296
|
+
type: "number",
|
|
297
|
+
value: drafts.primary
|
|
298
|
+
}), renderUnitSuffix(displayUnit)] }), renderMenuTrigger()]
|
|
299
|
+
}),
|
|
300
|
+
AfterInput,
|
|
301
|
+
/* @__PURE__ */ jsx(RenderCustomComponent, {
|
|
302
|
+
CustomComponent: Description,
|
|
303
|
+
Fallback: /* @__PURE__ */ jsx(FieldDescription, {
|
|
304
|
+
description,
|
|
305
|
+
path: path ?? ""
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
]
|
|
309
|
+
})]
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* The measurement field's row, unit menu and conversion pipeline with no form behind
|
|
314
|
+
* it, for custom admin views and components. Inside the admin the display unit is the
|
|
315
|
+
* viewer's saved preference for `preferenceKey`, shared with every measurement field
|
|
316
|
+
* on that key; `MeasurementField` is this plus `useField`.
|
|
317
|
+
*/
|
|
318
|
+
const MeasurementInput = ({ options, ...props }) => {
|
|
319
|
+
return /* @__PURE__ */ jsx(MeasurementInputView, {
|
|
320
|
+
model: useMeasurementModel(options),
|
|
321
|
+
...props
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
//#endregion
|
|
325
|
+
export { MeasurementInput, MeasurementInputView };
|
|
326
|
+
|
|
327
|
+
//# sourceMappingURL=MeasurementInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeasurementInput.js","names":["useTranslation"],"sources":["../../../../src/fields/measurement/client/MeasurementInput.tsx"],"sourcesContent":["'use client'\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tPopup,\n\tRenderCustomComponent,\n} from '@payloadcms/ui'\nimport type { StaticDescription, StaticLabel } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { COMPOUNDS, type MeasurementUnitId } from '../engine/units'\nimport { commitDrafts, type DirtyDrafts, draftsFor, type MeasurementDrafts } from './editModel'\nimport {\n\ttype MeasurementInputOptions,\n\ttype MeasurementModel,\n\tuseMeasurementModel,\n} from './useMeasurementModel'\nimport './measurementField.css'\n\nconst baseClass = 'fields-measurement'\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\n/**\n * Props for the form-free measurement input. `value` is the number in\n * `options.storageUnit`, exactly as `measurementField` stores it; the viewer reads and\n * types in their display unit.\n */\nexport type MeasurementInputProps = {\n\tvalue: null | number | undefined\n\t/** Fires on every edit with the value converted back to the storage unit. */\n\tonChange: (value: null | number) => void\n\toptions: MeasurementInputOptions\n\t/** Bounds in the storage unit; a value outside them shows a message in the display unit. */\n\tmin?: number\n\tmax?: number\n\t/** Names the input (`id`, `name`, label `htmlFor`), as on a native field. */\n\tpath?: string\n\tlabel?: StaticLabel\n\tdescription?: StaticDescription\n\tplaceholder?: string\n\trequired?: boolean\n\tlocalized?: boolean\n\treadOnly?: boolean\n\t/** Message shown in the error tooltip. Left unset, the input reports its own bound errors. */\n\terror?: string\n\t/** Forces the error state on or off. Left unset, it follows `error` and the bound check. */\n\tshowError?: boolean\n\tclassName?: string\n\tstyle?: React.CSSProperties\n\tLabel?: React.ReactNode\n\tError?: React.ReactNode\n\tDescription?: React.ReactNode\n\tBeforeInput?: React.ReactNode\n\tAfterInput?: React.ReactNode\n}\n\ntype MeasurementInputViewProps = { model: MeasurementModel } & Omit<\n\tMeasurementInputProps,\n\t'options'\n>\n\n/** The row itself, shared by `MeasurementInput` and the form-bound `MeasurementField`. */\nexport const MeasurementInputView: React.FC<MeasurementInputViewProps> = (props) => {\n\tconst {\n\t\tAfterInput,\n\t\tBeforeInput,\n\t\tclassName,\n\t\tDescription,\n\t\tdescription,\n\t\tError: ErrorComponent,\n\t\terror,\n\t\tLabel,\n\t\tlabel,\n\t\tlocalized,\n\t\tmax,\n\t\tmin,\n\t\tmodel,\n\t\tonChange,\n\t\tpath,\n\t\tplaceholder,\n\t\treadOnly,\n\t\trequired,\n\t\tshowError: showErrorFromProps,\n\t\tstyle,\n\t\tvalue,\n\t} = props\n\tconst {\n\t\tdisplayPrecision,\n\t\tdisplayUnit,\n\t\tengine,\n\t\tfmtBound,\n\t\tlocale,\n\t\tresolvedPrecision,\n\t\tselectUnit: selectModelUnit,\n\t\tstorageUnit,\n\t\tunits,\n\t} = model\n\tconst { t } = useTranslation()\n\tconst isReadOnly = Boolean(readOnly)\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\tconst errorMessage = error ?? boundsMessage\n\tconst showError = showErrorFromProps ?? errorMessage !== undefined\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 commit updates the live value\n\t// (and so `numericValue`) before the viewer blurs; diffing the next keystroke's\n\t// delta against that advanced value, instead of this frozen snapshot, would\n\t// 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\tonChange(\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, onChange, resolvedPrecision.entry]\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\tselectModelUnit(unit)\n\t\t},\n\t\t[selectModelUnit]\n\t)\n\n\tconst isCompound = engine.isCompoundUnit(displayUnit)\n\tconst compoundDef = isCompound ? COMPOUNDS[displayUnit] : null\n\t// Without a path there is no field id to derive, so the label pairs with a generated one\n\tconst generatedId = useId()\n\tconst inputId = path ? `field-${path.replace(/\\./g, '__')}` : generatedId\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\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={style}\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\n\t\t\t\t\t\thtmlFor={path ? undefined : inputId}\n\t\t\t\t\t\tlabel={label}\n\t\t\t\t\t\tlocalized={localized}\n\t\t\t\t\t\tpath={path}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError message={errorMessage} 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={placeholder}\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 || placeholder || '')}\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\n/**\n * The measurement field's row, unit menu and conversion pipeline with no form behind\n * it, for custom admin views and components. Inside the admin the display unit is the\n * viewer's saved preference for `preferenceKey`, shared with every measurement field\n * on that key; `MeasurementField` is this plus `useField`.\n */\nexport const MeasurementInput: React.FC<MeasurementInputProps> = ({ options, ...props }) => {\n\tconst model = useMeasurementModel(options)\n\treturn <MeasurementInputView model={model} {...props} />\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MeasurementUnitId } from "../engine/units.js";
|
|
2
|
+
import { MeasurementUnitsPreference } from "../options.js";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/fields/measurement/client/MeasurementUnitsProvider.d.ts
|
|
6
|
+
type MeasurementUnitsContextValue = {
|
|
7
|
+
ready: boolean;
|
|
8
|
+
units: MeasurementUnitsPreference;
|
|
9
|
+
setUnit: (preferenceKey: string, unit: MeasurementUnitId) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Reactive layer over payload-preferences for the per-bucket display units.
|
|
13
|
+
* Payload's own usePreferences is ref-backed and never re-renders consumers,
|
|
14
|
+
* so this provider holds the map in state: one toggle re-renders every
|
|
15
|
+
* measurement field and cell on the page, then persists with merge mode.
|
|
16
|
+
*/
|
|
17
|
+
declare const MeasurementUnitsProvider: React.FC<{
|
|
18
|
+
children: React.ReactNode; /** Kiosk/shared-account mode: skips both the preference fetch and writes, state stays session-only. Defaults to true. */
|
|
19
|
+
persist?: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
declare const useMeasurementUnits: () => MeasurementUnitsContextValue | null;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MeasurementUnitsProvider, useMeasurementUnits };
|
|
24
|
+
//# sourceMappingURL=MeasurementUnitsProvider.d.ts.map
|