@vritti/quantum-ui 0.6.9 → 0.6.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.
Files changed (42) hide show
  1. package/dist/QuantityField.js +323 -105
  2. package/dist/QuantityField.js.map +1 -1
  3. package/dist/Spinner.js +8 -2
  4. package/dist/Spinner.js.map +1 -1
  5. package/dist/assets/quantum-ui.css +88 -0
  6. package/dist/components/QuantityField.js +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index13.js +2 -1
  9. package/dist/index13.js.map +1 -1
  10. package/dist/lib/components/DataTable/DataTable.d.ts.map +1 -1
  11. package/dist/lib/components/DataTable/components/DataTablePagination.d.ts.map +1 -1
  12. package/dist/lib/components/DataTable/components/DataTableSelectionBar.d.ts +3 -2
  13. package/dist/lib/components/DataTable/components/DataTableSelectionBar.d.ts.map +1 -1
  14. package/dist/lib/components/DataTable/hooks/useDataTable.d.ts +4 -1
  15. package/dist/lib/components/DataTable/hooks/useDataTable.d.ts.map +1 -1
  16. package/dist/lib/components/DataTable/index.d.ts +1 -1
  17. package/dist/lib/components/DataTable/index.d.ts.map +1 -1
  18. package/dist/lib/components/DataTable/types.d.ts +13 -1
  19. package/dist/lib/components/DataTable/types.d.ts.map +1 -1
  20. package/dist/lib/components/DataTable/utils.d.ts +2 -2
  21. package/dist/lib/components/DataTable/utils.d.ts.map +1 -1
  22. package/dist/lib/components/QuantityField/QuantityField.d.ts +6 -1
  23. package/dist/lib/components/QuantityField/QuantityField.d.ts.map +1 -1
  24. package/dist/lib/components/QuantityField/index.d.ts +1 -1
  25. package/dist/lib/components/QuantityField/index.d.ts.map +1 -1
  26. package/dist/lib/components/QuantityField/quantity.d.ts +14 -0
  27. package/dist/lib/components/QuantityField/quantity.d.ts.map +1 -1
  28. package/dist/lib/utils/format.d.ts +4 -0
  29. package/dist/lib/utils/format.d.ts.map +1 -1
  30. package/dist/popover.js +5 -2
  31. package/dist/popover.js.map +1 -1
  32. package/dist/shadcn/shadcnPopover/index.d.ts +1 -1
  33. package/dist/shadcn/shadcnPopover/index.d.ts.map +1 -1
  34. package/dist/shadcn/shadcnPopover/popover.d.ts +2 -1
  35. package/dist/shadcn/shadcnPopover/popover.d.ts.map +1 -1
  36. package/dist/useDataTable.js +145 -21
  37. package/dist/useDataTable.js.map +1 -1
  38. package/dist/utils/format.js +14 -6
  39. package/dist/utils/format.js.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/Spinner2.js +0 -10
  42. package/dist/Spinner2.js.map +0 -1
@@ -4,9 +4,11 @@ import { F as Field, e as FieldLabel, a as FieldContent, b as FieldDescription,
4
4
  import { c as cn } from './utils.js';
5
5
  import { formatNumber } from './utils/format.js';
6
6
  import { getLocale } from './utils/locale.js';
7
+ import { B as Button } from './Button.js';
7
8
  import { S as Select } from './Select.js';
8
9
  import Decimal from './utils/decimal.js';
9
- import { S as Spinner } from './Spinner2.js';
10
+ import { P as Popover, c as PopoverAnchor, a as PopoverTrigger, b as PopoverContent } from './popover.js';
11
+ import { a as Spinner } from './Spinner.js';
10
12
  import { C as ChevronDown } from './chevron-down.js';
11
13
 
12
14
  const PRIMARY_DECIMALS = 3;
@@ -27,6 +29,86 @@ function fromPrimaryQty(primaryQty, unit) {
27
29
  if (primaryQty == null || !Number.isFinite(primaryQty)) return "";
28
30
  return new Decimal(primaryQty).times(unit.uomQty).div(unit.primaryUomQty).toDecimalPlaces(UNIT_DECIMALS).toFixed();
29
31
  }
32
+ function unitSize(unit) {
33
+ return new Decimal(unit.primaryUomQty).div(unit.uomQty);
34
+ }
35
+ function isPackUnit(unit, primaryUnitId) {
36
+ return unit.id !== primaryUnitId && unit.isPack !== false;
37
+ }
38
+ function packLadder(anchor, units, primaryUnitId, cascade) {
39
+ const ladder = [anchor];
40
+ if (!cascade) return ladder;
41
+ const smaller = units.filter((unit) => isPackUnit(unit, primaryUnitId) && unit.id !== anchor.id).filter((unit) => unitSize(unit).lt(unitSize(anchor)) && unitSize(unit).gt(1)).sort((a, b) => unitSize(b).cmp(unitSize(a)));
42
+ for (const unit of smaller) {
43
+ if (unitSize(ladder[ladder.length - 1]).mod(unitSize(unit)).isZero())
44
+ ladder.push(unit);
45
+ }
46
+ return ladder;
47
+ }
48
+ function breakDownQty(primaryQty, units, anchorUnitId, primaryUnitId, cascade = false) {
49
+ const primary = units.find((unit) => unit.id === primaryUnitId);
50
+ if (!primary || !Number.isFinite(primaryQty)) return [];
51
+ const anchor = units.find((unit) => unit.id === anchorUnitId) ?? primary;
52
+ const total = new Decimal(primaryQty);
53
+ if (anchor.id !== primary.id && !isPackUnit(anchor, primaryUnitId)) {
54
+ return [{ unit: anchor, amount: total.div(unitSize(anchor)).toDecimalPlaces(PRIMARY_DECIMALS) }];
55
+ }
56
+ const pieces = [];
57
+ let left = total;
58
+ if (anchor.id !== primary.id) {
59
+ for (const unit of packLadder(anchor, units, primaryUnitId, cascade)) {
60
+ const amount = left.div(unitSize(unit)).floor();
61
+ pieces.push({ unit, amount });
62
+ left = left.minus(amount.times(unitSize(unit)));
63
+ }
64
+ }
65
+ pieces.push({ unit: primary, amount: left.toDecimalPlaces(PRIMARY_DECIMALS) });
66
+ return pieces;
67
+ }
68
+ function entryUnits(units, primaryUnitId, anchorUnitId) {
69
+ return units.filter((unit) => unit.id === primaryUnitId || unit.id === anchorUnitId || isPackUnit(unit, primaryUnitId)).sort((a, b) => unitSize(b).cmp(unitSize(a)));
70
+ }
71
+ function takesDecimals(unit, primaryUnitId, allowDecimal) {
72
+ return allowDecimal && !isPackUnit(unit, primaryUnitId);
73
+ }
74
+ function toDisplayQuantity(primaryQty, units, primaryUnitId, displayUnitId, cascade = false) {
75
+ const primary = units.find((unit) => unit.id === primaryUnitId);
76
+ if (!primary || !Number.isFinite(primaryQty)) return null;
77
+ const display = units.find((unit) => unit.id === displayUnitId) ?? primary;
78
+ const size = unitSize(display);
79
+ const total = new Decimal(primaryQty);
80
+ const whole = total.div(size).trunc();
81
+ const isPack = isPackUnit(display, primaryUnitId);
82
+ const breakdown = isPack && primaryQty >= 0 ? breakDownQty(primaryQty, units, display.id, primaryUnitId, cascade).filter((piece) => !piece.amount.isZero()).map((piece) => ({ qty: piece.amount.toNumber(), symbol: piece.unit.symbol })) : [];
83
+ return {
84
+ primaryUomQty: primaryQty,
85
+ displayUomQty: total.div(size).toDecimalPlaces(PRIMARY_DECIMALS).toNumber(),
86
+ wholeDisplayUomQty: whole.toNumber(),
87
+ remainderPrimaryUomQty: total.minus(whole.times(size)).toDecimalPlaces(PRIMARY_DECIMALS).toNumber(),
88
+ displayUomSymbol: display.symbol,
89
+ primaryUomSymbol: primary.symbol,
90
+ isPack,
91
+ breakdown
92
+ };
93
+ }
94
+ function sumParts(parts, units) {
95
+ let total = null;
96
+ for (const unit of units) {
97
+ const amount = parseAmount(parts[unit.id] ?? "");
98
+ if (amount) total = (total ?? new Decimal(0)).plus(amount.times(unitSize(unit)));
99
+ }
100
+ return total?.toDecimalPlaces(PRIMARY_DECIMALS).toNumber();
101
+ }
102
+ function partsOfQty(primaryQty, units, anchorUnitId, primaryUnitId, cascade = false) {
103
+ if (primaryQty == null) return {};
104
+ const anchor = units.find((unit) => unit.id === anchorUnitId);
105
+ const enteredIn = anchor && isPackUnit(anchor, primaryUnitId) ? anchorUnitId : primaryUnitId;
106
+ const parts = breakDownQty(primaryQty, units, enteredIn, primaryUnitId, cascade).filter(
107
+ (piece) => !piece.amount.isZero()
108
+ );
109
+ if (parts.length === 0) return { [enteredIn]: "0" };
110
+ return Object.fromEntries(parts.map((piece) => [piece.unit.id, piece.amount.toFixed()]));
111
+ }
30
112
  function quantityPlaceholder(primaryQty) {
31
113
  return `{{qty:${primaryQty}}}`;
32
114
  }
@@ -37,7 +119,9 @@ function resolveQuantityMessage(message, unit, primaryUnit, formatNumber) {
37
119
  ).split(PRIMARY_UNIT_PLACEHOLDER).join(primaryUnit.symbol);
38
120
  }
39
121
 
40
- const AMOUNT_PATTERN = /^-?\d*\.?\d*$/;
122
+ const WHOLE_PATTERN = /^\d*$/;
123
+ const DECIMAL_PATTERN = /^\d*\.?\d{0,3}$/;
124
+ const DIGIT_KEY = /^\d$/;
41
125
  function formatAmount(value) {
42
126
  return String(formatNumber(value, { localeTag: getLocale() ?? "en-US" }).primary);
43
127
  }
@@ -46,13 +130,18 @@ const QuantityField = React__default.forwardRef(
46
130
  units,
47
131
  primaryUnitId,
48
132
  defaultUnitId,
133
+ anchorUnitId,
134
+ onAnchorUnitChange,
135
+ allowDecimal = false,
136
+ cascade = false,
137
+ compact,
49
138
  value,
50
139
  onChange,
51
140
  onBlur,
52
141
  nullable,
53
142
  label,
54
143
  description,
55
- placeholder,
144
+ placeholder = "Qty",
56
145
  error,
57
146
  disabled,
58
147
  required,
@@ -61,122 +150,251 @@ const QuantityField = React__default.forwardRef(
61
150
  }, ref) => {
62
151
  const fieldId = React__default.useId();
63
152
  const [pickedUnitId, setPickedUnitId] = React__default.useState();
64
- const [text, setText] = React__default.useState("");
153
+ const [parts, setParts] = React__default.useState({});
154
+ const [open, setOpen] = React__default.useState(false);
65
155
  const shown = React__default.useRef(null);
66
- const unit = units.find((option) => option.id === pickedUnitId) ?? units.find((option) => option.id === defaultUnitId) ?? units.find((option) => option.id === primaryUnitId);
67
- const primaryUnit = units.find((option) => option.id === primaryUnitId);
68
- const isDisabled = !!disabled || !!loading || !unit;
156
+ const focusTarget = React__default.useRef(null);
157
+ const rowInputs = React__default.useRef(/* @__PURE__ */ new Map());
158
+ React__default.useImperativeHandle(ref, () => focusTarget.current);
159
+ const primaryUnit = units.find((unit) => unit.id === primaryUnitId);
160
+ const anchor = units.find((unit) => unit.id === (anchorUnitId ?? pickedUnitId)) ?? units.find((unit) => unit.id === defaultUnitId) ?? primaryUnit;
161
+ const singleUnit = units.length === 1 && !!primaryUnit;
162
+ const isDisabled = !!disabled || !!loading || !anchor;
69
163
  const options = React__default.useMemo(
70
- () => units.map((option) => ({ value: option.id, label: option.symbol, description: option.name })),
164
+ () => [...units].sort((a, b) => unitSize(b).cmp(unitSize(a))).map((unit) => ({ value: unit.id, label: unit.symbol, description: unit.name })),
71
165
  [units]
72
166
  );
167
+ const ladder = React__default.useMemo(() => entryUnits(units, primaryUnitId, anchor?.id), [units, primaryUnitId, anchor]);
73
168
  React__default.useEffect(() => {
74
- if (!unit) return;
169
+ if (!primaryUnit || !anchor) return;
75
170
  const qty = value ?? void 0;
76
- if (shown.current && shown.current.qty === qty && shown.current.unitId === unit.id) return;
77
- shown.current = { qty, unitId: unit.id };
78
- setText(fromPrimaryQty(qty, unit));
79
- }, [value, unit]);
80
- const emit = (nextText, nextUnit) => {
81
- const qty = toPrimaryQty(nextText, nextUnit);
171
+ if (shown.current && shown.current.qty === qty) return;
172
+ shown.current = { qty };
173
+ setParts(partsOfQty(qty, units, anchor.id, primaryUnit.id, cascade));
174
+ }, [value, units, anchor, primaryUnit, cascade]);
175
+ const commit = (next) => {
176
+ setParts(next);
177
+ const qty = sumParts(next, units);
82
178
  const previous = shown.current?.qty;
83
- shown.current = { qty, unitId: nextUnit.id };
179
+ shown.current = { qty };
84
180
  if (qty !== previous) onChange?.(qty === void 0 && nullable ? null : qty);
85
181
  };
86
- const handleTextChange = (event) => {
87
- if (!AMOUNT_PATTERN.test(event.target.value)) return;
88
- setText(event.target.value);
89
- if (unit) emit(event.target.value, unit);
182
+ const enter = (unit, text) => {
183
+ const pattern = takesDecimals(unit, primaryUnitId, allowDecimal) ? DECIMAL_PATTERN : WHOLE_PATTERN;
184
+ if (!pattern.test(text)) return;
185
+ commit({ ...parts, [unit.id]: text });
186
+ };
187
+ const handleAnchorChange = (next) => {
188
+ const unit = units.find((option) => option.id === next);
189
+ if (!unit) return;
190
+ setPickedUnitId(unit.id);
191
+ onAnchorUnitChange?.(unit.id);
192
+ };
193
+ const focusRow = (unitId) => {
194
+ const input = unitId ? rowInputs.current.get(unitId) : void 0;
195
+ if (!input) return;
196
+ input.focus();
197
+ input.setSelectionRange(input.value.length, input.value.length);
198
+ };
199
+ const handleOpenChange = (next) => {
200
+ setOpen(next);
201
+ if (!next) onBlur?.();
90
202
  };
91
- const handleUnitChange = (next) => {
92
- const nextUnit = units.find((option) => option.id === next);
93
- if (!nextUnit) return;
94
- setPickedUnitId(nextUnit.id);
95
- emit(text, nextUnit);
203
+ const handleReadingKeyDown = (event) => {
204
+ if (!anchor) return;
205
+ if (DIGIT_KEY.test(event.key)) {
206
+ event.preventDefault();
207
+ const typed = Object.values(parts).filter((amount) => amount !== "" && Number(amount) !== 0).length;
208
+ if (typed <= 1) commit({ [anchor.id]: event.key });
209
+ setOpen(true);
210
+ } else if (event.key === "ArrowDown") {
211
+ event.preventDefault();
212
+ setOpen(true);
213
+ }
96
214
  };
97
- const showHint = !!unit && !!primaryUnit && unit.id !== primaryUnit.id && value != null;
98
- const message = error && unit && primaryUnit ? resolveQuantityMessage(error, unit, primaryUnit, formatAmount) : error;
99
- const describedBy = [
100
- showHint && `${fieldId}-hint`,
101
- description && !message && `${fieldId}-description`,
102
- message && `${fieldId}-error`
103
- ].filter(Boolean).join(" ") || void 0;
215
+ const handleRowKeyDown = (event, index) => {
216
+ if (event.key !== "Enter" && event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
217
+ event.preventDefault();
218
+ const next = ladder[index + (event.key === "ArrowUp" ? -1 : 1)];
219
+ if (next) focusRow(next.id);
220
+ else if (event.key === "Enter") handleOpenChange(false);
221
+ };
222
+ const total = sumParts(parts, units);
223
+ const pieces = total === void 0 || !anchor || !primaryUnit ? [] : breakDownQty(total, units, anchor.id, primaryUnit.id, cascade);
224
+ const shownPieces = pieces.filter((piece) => !piece.amount.isZero());
225
+ const reading = total === void 0 || !anchor ? null : shownPieces.length === 0 ? `0 ${anchor.symbol}` : shownPieces.map((piece) => `${formatAmount(piece.amount.toNumber())} ${piece.unit.symbol}`).join(compact ? " " : " + ");
226
+ const message = error && anchor && primaryUnit ? resolveQuantityMessage(error, anchor, primaryUnit, formatAmount) : error;
227
+ const describedBy = [description && !message && `${fieldId}-description`, message && `${fieldId}-error`].filter(Boolean).join(" ") || void 0;
228
+ const boxClass = cn(
229
+ "flex h-9 w-full items-stretch rounded-md border border-input bg-transparent shadow-xs transition-[color,box-shadow] dark:bg-input/30",
230
+ "focus-within:border-ring focus-within:ring-1 focus-within:ring-ring/50",
231
+ open && "border-ring ring-1 ring-ring/50",
232
+ isDisabled && "cursor-not-allowed opacity-50",
233
+ message && "border-destructive focus-within:ring-destructive/20 dark:focus-within:ring-destructive/40",
234
+ className
235
+ );
104
236
  return /* @__PURE__ */ jsxs(Field, { "data-disabled": isDisabled, children: [
105
237
  label && /* @__PURE__ */ jsx(FieldLabel, { htmlFor: fieldId, children: label }),
106
238
  /* @__PURE__ */ jsxs(FieldContent, { children: [
107
- /* @__PURE__ */ jsxs(
108
- "div",
109
- {
110
- className: cn(
111
- "flex h-9 w-full items-stretch rounded-md border border-input bg-transparent shadow-xs transition-[color,box-shadow] dark:bg-input/30",
112
- "focus-within:border-ring focus-within:ring-1 focus-within:ring-ring/50",
113
- isDisabled && "cursor-not-allowed opacity-50",
114
- message && "border-destructive focus-within:ring-destructive/20 dark:focus-within:ring-destructive/40",
115
- className
116
- ),
117
- children: [
118
- /* @__PURE__ */ jsx(
119
- "input",
120
- {
121
- ref,
122
- id: fieldId,
123
- type: "text",
124
- inputMode: "decimal",
125
- autoComplete: "off",
126
- value: text,
127
- onChange: handleTextChange,
128
- onBlur,
129
- disabled: isDisabled,
130
- required,
131
- placeholder,
132
- "aria-invalid": !!message,
133
- "aria-busy": loading || void 0,
134
- "aria-describedby": describedBy,
135
- className: "min-w-0 flex-1 bg-transparent px-3 py-1 text-sm tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
136
- }
239
+ singleUnit ? /* @__PURE__ */ jsxs("div", { className: boxClass, children: [
240
+ /* @__PURE__ */ jsx(
241
+ "input",
242
+ {
243
+ ref: (node) => {
244
+ focusTarget.current = node;
245
+ },
246
+ id: fieldId,
247
+ type: "text",
248
+ inputMode: allowDecimal ? "decimal" : "numeric",
249
+ autoComplete: "off",
250
+ value: parts[primaryUnit.id] ?? "",
251
+ onChange: (event) => enter(primaryUnit, event.target.value),
252
+ onBlur,
253
+ disabled: isDisabled,
254
+ required,
255
+ placeholder,
256
+ "aria-invalid": !!message,
257
+ "aria-describedby": describedBy,
258
+ className: cn(
259
+ "min-w-0 flex-1 bg-transparent py-1 text-sm tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed",
260
+ compact ? "px-2.5" : "px-3"
261
+ )
262
+ }
263
+ ),
264
+ /* @__PURE__ */ jsx(
265
+ "span",
266
+ {
267
+ className: cn(
268
+ "flex shrink-0 items-center rounded-r-md border-l border-input bg-muted/60 text-sm font-medium text-muted-foreground",
269
+ compact ? "px-2" : "px-3"
137
270
  ),
138
- /* @__PURE__ */ jsx("div", { className: "flex w-28 shrink-0 items-stretch border-l border-input", children: /* @__PURE__ */ jsx(
139
- Select,
140
- {
141
- options,
142
- value: unit?.id ?? null,
143
- onChange: handleUnitChange,
144
- disabled: isDisabled,
145
- clearable: false,
146
- label: "",
147
- contentClassName: "min-w-40",
148
- anchor: ({ selectedOption, open, disabled: anchorDisabled }) => /* @__PURE__ */ jsxs(
149
- "button",
150
- {
151
- type: "button",
152
- disabled: anchorDisabled,
153
- "aria-label": "Unit",
154
- "aria-expanded": open,
155
- className: "flex h-full w-full items-center justify-between gap-1 rounded-r-md px-3 text-sm font-medium text-foreground outline-none hover:bg-accent/50 focus-visible:bg-accent/50 disabled:cursor-not-allowed",
156
- children: [
157
- loading ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5 text-muted-foreground" }) : /* @__PURE__ */ jsx("span", { className: "truncate", children: selectedOption?.label ?? unit?.symbol ?? "—" }),
158
- /* @__PURE__ */ jsx(
159
- ChevronDown,
160
- {
161
- className: cn(
162
- "size-3.5 shrink-0 text-muted-foreground transition-transform",
163
- open && "rotate-180"
164
- )
165
- }
166
- )
167
- ]
168
- }
169
- )
170
- }
171
- ) })
172
- ]
173
- }
174
- ),
175
- showHint && /* @__PURE__ */ jsxs("p", { id: `${fieldId}-hint`, "aria-live": "polite", className: "text-xs tabular-nums text-muted-foreground", children: [
176
- "= ",
177
- formatAmount(value),
178
- " ",
179
- primaryUnit.symbol
271
+ children: primaryUnit.symbol
272
+ }
273
+ )
274
+ ] }) : /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
275
+ /* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: boxClass, children: [
276
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
277
+ "button",
278
+ {
279
+ ref: (node) => {
280
+ focusTarget.current = node;
281
+ },
282
+ id: fieldId,
283
+ type: "button",
284
+ disabled: isDisabled,
285
+ title: reading ?? void 0,
286
+ onKeyDown: handleReadingKeyDown,
287
+ "aria-invalid": !!message,
288
+ "aria-busy": loading || void 0,
289
+ "aria-describedby": describedBy,
290
+ className: cn(
291
+ "flex min-w-0 flex-1 items-center rounded-l-md text-left text-sm tabular-nums outline-none disabled:cursor-not-allowed",
292
+ compact ? "px-2.5" : "px-3"
293
+ ),
294
+ children: /* @__PURE__ */ jsx("span", { className: cn("min-w-0 truncate", !reading && "text-muted-foreground"), children: reading ?? placeholder })
295
+ }
296
+ ) }),
297
+ /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-stretch border-l border-input", children: /* @__PURE__ */ jsx(
298
+ Select,
299
+ {
300
+ options,
301
+ value: anchor?.id ?? null,
302
+ onChange: handleAnchorChange,
303
+ disabled: isDisabled,
304
+ clearable: false,
305
+ label: "",
306
+ contentClassName: "min-w-40",
307
+ anchor: ({ selectedOption, open: unitsOpen, disabled: anchorDisabled }) => /* @__PURE__ */ jsxs(
308
+ "button",
309
+ {
310
+ type: "button",
311
+ disabled: anchorDisabled,
312
+ "aria-label": "Read the quantity in",
313
+ "aria-expanded": unitsOpen,
314
+ className: cn(
315
+ "flex h-full items-center gap-1 rounded-r-md text-sm font-medium text-foreground outline-none hover:bg-accent/50 focus-visible:bg-accent/50 disabled:cursor-not-allowed",
316
+ compact ? "px-2" : "px-3"
317
+ ),
318
+ children: [
319
+ loading ? /* @__PURE__ */ jsx(Spinner, { className: "size-3.5 text-muted-foreground" }) : /* @__PURE__ */ jsx("span", { className: "truncate", children: selectedOption?.label ?? anchor?.symbol ?? "—" }),
320
+ /* @__PURE__ */ jsx(
321
+ ChevronDown,
322
+ {
323
+ className: cn(
324
+ "size-3.5 shrink-0 text-muted-foreground transition-transform",
325
+ unitsOpen && "rotate-180"
326
+ )
327
+ }
328
+ )
329
+ ]
330
+ }
331
+ )
332
+ }
333
+ ) })
334
+ ] }) }),
335
+ /* @__PURE__ */ jsxs(
336
+ PopoverContent,
337
+ {
338
+ align: "start",
339
+ className: "w-72 p-3",
340
+ "aria-label": "Quantity by unit",
341
+ onOpenAutoFocus: (event) => {
342
+ event.preventDefault();
343
+ focusRow(anchor?.id);
344
+ },
345
+ children: [
346
+ /* @__PURE__ */ jsx("p", { className: "mb-2 text-xs font-medium tracking-wider text-muted-foreground uppercase", children: "Quantity by unit" }),
347
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1.5", children: ladder.map((unit, index) => {
348
+ const decimal = takesDecimals(unit, primaryUnitId, allowDecimal);
349
+ const size = unitSize(unit);
350
+ return /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2", children: [
351
+ /* @__PURE__ */ jsx("span", { className: "w-14 truncate text-sm font-medium", children: unit.symbol }),
352
+ /* @__PURE__ */ jsx(
353
+ "input",
354
+ {
355
+ ref: (node) => {
356
+ if (node) rowInputs.current.set(unit.id, node);
357
+ else rowInputs.current.delete(unit.id);
358
+ },
359
+ type: "text",
360
+ inputMode: decimal ? "decimal" : "numeric",
361
+ autoComplete: "off",
362
+ value: parts[unit.id] ?? "",
363
+ placeholder: "0",
364
+ onChange: (event) => enter(unit, event.target.value),
365
+ onKeyDown: (event) => handleRowKeyDown(event, index),
366
+ className: "h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 text-sm tabular-nums shadow-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30"
367
+ }
368
+ ),
369
+ /* @__PURE__ */ jsx("span", { className: "w-20 shrink-0 truncate text-right text-xs text-muted-foreground tabular-nums", children: unit.id === primaryUnitId || !primaryUnit ? "" : `×${formatAmount(size.toNumber())} ${primaryUnit.symbol}` })
370
+ ] }, unit.id);
371
+ }) }),
372
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 flex items-center justify-between border-t pt-2.5", children: [
373
+ /* @__PURE__ */ jsxs("span", { className: "text-sm tabular-nums", children: [
374
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "=" }),
375
+ " ",
376
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: total === void 0 || !primaryUnit ? "—" : `${formatAmount(total)} ${primaryUnit.symbol}` })
377
+ ] }),
378
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-1.5", children: [
379
+ /* @__PURE__ */ jsx(
380
+ Button,
381
+ {
382
+ type: "button",
383
+ variant: "ghost",
384
+ size: "xs",
385
+ onClick: () => {
386
+ commit({});
387
+ focusRow(anchor?.id);
388
+ },
389
+ children: "Clear"
390
+ }
391
+ ),
392
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "xs", onClick: () => handleOpenChange(false), children: "Done" })
393
+ ] })
394
+ ] })
395
+ ]
396
+ }
397
+ )
180
398
  ] }),
181
399
  description && !message && /* @__PURE__ */ jsx(FieldDescription, { id: `${fieldId}-description`, children: description }),
182
400
  message && /* @__PURE__ */ jsx(FieldError, { id: `${fieldId}-error`, children: message })
@@ -186,5 +404,5 @@ const QuantityField = React__default.forwardRef(
186
404
  );
187
405
  QuantityField.displayName = "QuantityField";
188
406
 
189
- export { PRIMARY_UNIT_PLACEHOLDER as P, QuantityField as Q, fromPrimaryQty as f, quantityPlaceholder as q, resolveQuantityMessage as r, toPrimaryQty as t };
407
+ export { PRIMARY_UNIT_PLACEHOLDER as P, QuantityField as Q, toDisplayQuantity as a, breakDownQty as b, toPrimaryQty as c, entryUnits as e, fromPrimaryQty as f, partsOfQty as p, quantityPlaceholder as q, resolveQuantityMessage as r, sumParts as s, takesDecimals as t, unitSize as u };
190
408
  //# sourceMappingURL=QuantityField.js.map