@camstack/ui-library 1.2.347 → 1.2.348

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.
@@ -5,6 +5,8 @@ export type { ControlDateTimeFormat } from "./format-control-datetime";
5
5
  export { formatNumeric } from "./format-numeric";
6
6
  export { resolveSensorDisplay } from "./resolve-sensor-display";
7
7
  export type { SensorDisplayInput, ResolvedSensorDisplay } from "./resolve-sensor-display";
8
+ export { DEFAULT_UNIT_PREFERENCES, TEMPERATURE_SCALES, UNIT_PREFERENCES_NAMESPACE, preferenceForQuantity, readUnitPreferences } from "./unit-preferences";
9
+ export type { ParsedUnitPreferences, TemperatureScale, UnitPreferences } from "./unit-preferences";
8
10
  export { isAbsentProvider } from "./cap-error";
9
11
  export * from "./responsive";
10
12
  export { PHASE_CONFIG, getPhaseVisual } from "./phase-config";
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { DeviceDisplayOverride, ReadingQuantity, RoleDisplayDefault } from "@camstack/types";
7
7
  import { type DisplayPreference } from "@camstack/types";
8
+ import { type UnitPreferences } from "./unit-preferences";
8
9
  export interface SensorDisplayInput {
9
10
  /** Per-device override from the row (`DeviceInfo.display`). */
10
11
  readonly display?: DeviceDisplayOverride;
@@ -18,8 +19,10 @@ export interface SensorDisplayInput {
18
19
  readonly deviceQuantity?: ReadingQuantity;
19
20
  /** Precision declared on the reading, when the operator has not overridden it. */
20
21
  readonly declarationPrecision?: number;
21
- /** Read-time preference. Defaults to metric. */
22
+ /** Read-time preference for this one reading. Wins over `unitPreferences`. */
22
23
  readonly preference?: DisplayPreference;
24
+ /** The user's unit preferences (`useUnitPreferences()`); metric and °C when absent. */
25
+ readonly unitPreferences?: UnitPreferences;
23
26
  }
24
27
  export interface ResolvedSensorDisplay {
25
28
  /** Display unit — `''` when the quantity has none. */
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The signed-in user's unit preferences (account preference, namespace
3
+ * `admin.units`). Stored numbers stay in each quantity's base unit (D944); a
4
+ * preference only picks the label and the conversion at display time.
5
+ *
6
+ * Two independent choices: the temperature scale, and metric or imperial for
7
+ * every other quantity. The default is metric and °C, so a user who never
8
+ * opens the page sees what they always saw.
9
+ */
10
+ import { type DisplayPreference, type ReadingQuantity } from "@camstack/types";
11
+ export declare const UNIT_PREFERENCES_NAMESPACE = "admin.units";
12
+ export declare const TEMPERATURE_SCALES: readonly ["celsius", "fahrenheit"];
13
+ export type TemperatureScale = (typeof TEMPERATURE_SCALES)[number];
14
+ export interface UnitPreferences {
15
+ /** Metric or imperial, for every quantity except temperature. */
16
+ readonly system: DisplayPreference;
17
+ readonly temperature: TemperatureScale;
18
+ }
19
+ export declare const DEFAULT_UNIT_PREFERENCES: UnitPreferences;
20
+ export interface ParsedUnitPreferences {
21
+ readonly value: UnitPreferences;
22
+ /** False when the stored row holds a field this client cannot read. */
23
+ readonly parsed: boolean;
24
+ }
25
+ /** A missing row or field is the default; a field of the wrong shape is unreadable. */
26
+ export declare function readUnitPreferences(raw: unknown): ParsedUnitPreferences;
27
+ /** The display preference to hand `formatReading` for one quantity. */
28
+ export declare function preferenceForQuantity(preferences: UnitPreferences, quantity: ReadingQuantity | undefined): DisplayPreference;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/ui-library",
3
- "version": "1.2.347",
3
+ "version": "1.2.348",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/camstack/server.git",