@entifix/react-controls 0.23.5 → 0.23.7
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/README.md +16 -0
- package/dist/i18n/catalog/en.d.ts.map +1 -1
- package/dist/i18n/catalog/en.js +45 -1
- package/dist/i18n/catalog/en.js.map +1 -1
- package/dist/i18n/catalog/es.d.ts +46 -0
- package/dist/i18n/catalog/es.d.ts.map +1 -1
- package/dist/i18n/catalog/es.js +46 -1
- package/dist/i18n/catalog/es.js.map +1 -1
- package/dist/i18n/catalog/index.d.ts +82 -0
- package/dist/i18n/catalog/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/primitives.d.ts +1 -0
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +1 -0
- package/dist/primitives.js.map +1 -1
- package/dist/theme/theme-context.d.ts.map +1 -1
- package/dist/theme/theme-context.js +9 -0
- package/dist/theme/theme-context.js.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts +2 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.js +31 -5
- package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
- package/dist/ui/atoms/field-control/field-control.d.ts +2 -1
- package/dist/ui/atoms/field-control/field-control.d.ts.map +1 -1
- package/dist/ui/atoms/field-control/field-control.js +19 -0
- package/dist/ui/atoms/field-control/field-control.js.map +1 -1
- package/dist/ui/atoms/money/money-input.d.ts +4 -0
- package/dist/ui/atoms/money/money-input.d.ts.map +1 -1
- package/dist/ui/atoms/money/money-input.js +10 -13
- package/dist/ui/atoms/money/money-input.js.map +1 -1
- package/dist/ui/atoms/number-input/quantity-input.d.ts +19 -4
- package/dist/ui/atoms/number-input/quantity-input.d.ts.map +1 -1
- package/dist/ui/atoms/number-input/quantity-input.js +13 -5
- package/dist/ui/atoms/number-input/quantity-input.js.map +1 -1
- package/dist/ui/atoms/number-input/scaled-quantity-input.d.ts +16 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.js +135 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.js.map +1 -0
- package/dist/ui/atoms/number-input/step-button.d.ts +3 -0
- package/dist/ui/atoms/number-input/step-button.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/step-button.js +3 -0
- package/dist/ui/atoms/number-input/step-button.js.map +1 -0
- package/dist/ui/atoms/number-input/unparsed.d.ts +10 -0
- package/dist/ui/atoms/number-input/unparsed.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/unparsed.js +10 -0
- package/dist/ui/atoms/number-input/unparsed.js.map +1 -0
- package/dist/ui/atoms/scaled/index.d.ts +5 -0
- package/dist/ui/atoms/scaled/index.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/index.js +6 -0
- package/dist/ui/atoms/scaled/index.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-input.d.ts +24 -0
- package/dist/ui/atoms/scaled/scaled-input.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-input.js +98 -0
- package/dist/ui/atoms/scaled/scaled-input.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-math.d.ts +13 -0
- package/dist/ui/atoms/scaled/scaled-math.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-math.js +17 -0
- package/dist/ui/atoms/scaled/scaled-math.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-value.d.ts +14 -0
- package/dist/ui/atoms/scaled/scaled-value.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-value.js +14 -0
- package/dist/ui/atoms/scaled/scaled-value.js.map +1 -0
- package/dist/ui/atoms/scaled/use-unit-label.d.ts +4 -0
- package/dist/ui/atoms/scaled/use-unit-label.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/use-unit-label.js +11 -0
- package/dist/ui/atoms/scaled/use-unit-label.js.map +1 -0
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.d.ts.map +1 -1
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.js +1 -1
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.js.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table-slots.d.ts +6 -1
- package/dist/ui/organisms/entity-table/entity-table-slots.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table-slots.js.map +1 -1
- package/dist/ui/organisms/entity-table/use-entity-table-columns.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js +2 -0
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/number-input/quantity-input.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quantity-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/number-input/quantity-input.tsx"],"names":[],"mappings":"AASA,UAAU,iBAAiB;IACzB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6EAA6E;IAC7E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,uFAAuF;AACvF,MAAM,WAAW,4BAA6B,SAAQ,iBAAiB;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,KAAK,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,8BAA+B,SAAQ,iBAAiB;IACvE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,MAAM,kBAAkB,GAC5B,4BAA4B,GAAG,8BAA8B,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BAMtD"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
4
|
import { useEffect, useState } from 'react';
|
|
4
5
|
import { useT } from '../../../i18n/index.js';
|
|
5
6
|
import { cn } from '../../utils/cn.js';
|
|
6
|
-
|
|
7
|
+
import { ScaledQuantityInput } from './scaled-quantity-input.js';
|
|
8
|
+
import { STEP_BUTTON } from './step-button.js';
|
|
7
9
|
/**
|
|
8
|
-
* A count,
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* A count — or, given a `scale`, a measure: see that prop — on the WAI-ARIA
|
|
11
|
+
* spinbutton pattern: Up and Down step it, Home and End jump to its bounds,
|
|
12
|
+
* and a count typed is committed on Enter or on leaving the field, clamped
|
|
13
|
+
* to the bounds. The − and + beside it are named
|
|
11
14
|
* "Decrease {label}" and "Increase {label}" and sit at `--target-min`; they are
|
|
12
15
|
* out of the Tab order, as the pattern has them, because the arrow keys
|
|
13
16
|
* already do what they do.
|
|
@@ -15,7 +18,12 @@ const STEP_BUTTON = 'flex min-h-(--target-min) min-w-(--target-min) shrink-0 ite
|
|
|
15
18
|
* Controlled with `value` and `onChange`, or uncontrolled with `defaultValue`
|
|
16
19
|
* — the second is how a Server Action form uses it, since a server component
|
|
17
20
|
* can pass neither a state nor a handler.
|
|
18
|
-
*/ export function QuantityInput(
|
|
21
|
+
*/ export function QuantityInput(props) {
|
|
22
|
+
return props.scale === undefined ? /*#__PURE__*/ _jsx(CountInput, _extends({}, props)) : /*#__PURE__*/ _jsx(ScaledQuantityInput, _extends({}, props, {
|
|
23
|
+
scale: props.scale
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
/** The count: what is typed is committed clamped to the bounds. */ function CountInput({ label, value: controlled, defaultValue, onChange, min = 0, max, step = 1, disabled = false, id, name, className }) {
|
|
19
27
|
const t = useT();
|
|
20
28
|
const [own, setOwn] = useState(defaultValue != null ? defaultValue : min);
|
|
21
29
|
const value = controlled != null ? controlled : own;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/atoms/number-input/quantity-input.tsx"],"sourcesContent":["'use client';\n\nimport { type KeyboardEvent, useEffect, useState } from 'react';\n\nimport { useT } from '../../../i18n/index.js';\nimport { cn } from '../../utils/cn.js';\n\ninterface QuantityInputBase {\n /** What is being counted; names the spinbutton and both of its buttons. */\n label: string;\n min?: number;\n max?: number;\n step?: number;\n disabled?: boolean;\n id?: string;\n /**\n * Posts the count with the form it sits in, under this name — a server\n * action's form works without JavaScript, where the field is the only part\n * a reader can change, so the field itself carries it. The server clamps\n * what it receives: a typed value is only clamped here once committed.\n */\n name?: string;\n className?: string;\n}\n\n/** The caller owns the count: every committed change comes back through `onChange`. */\nexport interface ControlledQuantityInputProps extends QuantityInputBase {\n value: number;\n onChange: (value: number) => void;\n defaultValue?: never;\n}\n\n/**\n * The field owns the count, starting at `defaultValue` (or `min`). This is the\n * shape a server-rendered form takes: a server component cannot hand a client\n * one a function, and with `name` the count posts with the form, so the page\n * needs no client parent of its own. `onChange` still reports each commit.\n */\nexport interface UncontrolledQuantityInputProps extends QuantityInputBase {\n value?: never;\n defaultValue?: number;\n onChange?: (value: number) => void;\n}\n\nexport type QuantityInputProps =\n ControlledQuantityInputProps | UncontrolledQuantityInputProps;\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/number-input/quantity-input.tsx"],"sourcesContent":["'use client';\n\nimport { type KeyboardEvent, useEffect, useState } from 'react';\n\nimport { useT } from '../../../i18n/index.js';\nimport { cn } from '../../utils/cn.js';\nimport { ScaledQuantityInput } from './scaled-quantity-input.js';\nimport { STEP_BUTTON } from './step-button.js';\n\ninterface QuantityInputBase {\n /** What is being counted; names the spinbutton and both of its buttons. */\n label: string;\n min?: number;\n max?: number;\n step?: number;\n /**\n * How many decimals a stored unit is: `3` reads `3500` as 3.5. Given, every\n * number in these props is that stored integer and a typed entry is never\n * clamped or rounded — one outside `min`, `max` or `step` is marked invalid\n * and still reported, and text that is no number is reported as `NaN`.\n * `0` is whole units under those same rules.\n */\n scale?: number;\n /** With `scale`: the unit, as the reader names it. */\n unit?: string;\n /** With `scale`: the caller's own refusal, beside the field's. */\n invalid?: boolean;\n /** With `scale`: what describes the field, usually the refusal's message. */\n 'aria-describedby'?: string;\n disabled?: boolean;\n id?: string;\n /**\n * Posts the count with the form it sits in, under this name — a server\n * action's form works without JavaScript, where the field is the only part\n * a reader can change, so the field itself carries it. The server clamps\n * what it receives: a typed value is only clamped here once committed.\n */\n name?: string;\n className?: string;\n}\n\n/** The caller owns the count: every committed change comes back through `onChange`. */\nexport interface ControlledQuantityInputProps extends QuantityInputBase {\n value: number;\n onChange: (value: number) => void;\n defaultValue?: never;\n}\n\n/**\n * The field owns the count, starting at `defaultValue` (or `min`). This is the\n * shape a server-rendered form takes: a server component cannot hand a client\n * one a function, and with `name` the count posts with the form, so the page\n * needs no client parent of its own. `onChange` still reports each commit.\n */\nexport interface UncontrolledQuantityInputProps extends QuantityInputBase {\n value?: never;\n defaultValue?: number;\n onChange?: (value: number) => void;\n}\n\nexport type QuantityInputProps =\n ControlledQuantityInputProps | UncontrolledQuantityInputProps;\n\n/**\n * A count — or, given a `scale`, a measure: see that prop — on the WAI-ARIA\n * spinbutton pattern: Up and Down step it, Home and End jump to its bounds,\n * and a count typed is committed on Enter or on leaving the field, clamped\n * to the bounds. The − and + beside it are named\n * \"Decrease {label}\" and \"Increase {label}\" and sit at `--target-min`; they are\n * out of the Tab order, as the pattern has them, because the arrow keys\n * already do what they do.\n *\n * Controlled with `value` and `onChange`, or uncontrolled with `defaultValue`\n * — the second is how a Server Action form uses it, since a server component\n * can pass neither a state nor a handler.\n */\nexport function QuantityInput(props: QuantityInputProps) {\n return props.scale === undefined ? (\n <CountInput {...props} />\n ) : (\n <ScaledQuantityInput {...props} scale={props.scale} />\n );\n}\n\n/** The count: what is typed is committed clamped to the bounds. */\nfunction CountInput({\n label,\n value: controlled,\n defaultValue,\n onChange,\n min = 0,\n max,\n step = 1,\n disabled = false,\n id,\n name,\n className,\n}: QuantityInputProps) {\n const t = useT();\n const [own, setOwn] = useState(defaultValue ?? min);\n const value = controlled ?? own;\n const [text, setText] = useState(String(value));\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- the value moved from outside (a step, a reset)\n setText(String(value));\n }, [value]);\n\n const clamp = (next: number) =>\n Math.min(max ?? Number.POSITIVE_INFINITY, Math.max(min, next));\n const set = (next: number) => {\n const clamped = clamp(next);\n setText(String(clamped));\n if (clamped === value) return;\n setOwn(clamped);\n onChange?.(clamped);\n };\n const commit = () => {\n const typed = Number.parseInt(text, 10);\n set(Number.isNaN(typed) ? value : typed);\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const next = {\n ArrowUp: value + step,\n ArrowDown: value - step,\n Home: min,\n End: max,\n }[event.key];\n if (event.key === 'Enter') {\n commit();\n return;\n }\n if (next === undefined) return;\n event.preventDefault();\n set(next);\n };\n\n return (\n <span className={cn('inline-flex items-center gap-3xs', className)}>\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={t('quantity.decrease', { label })}\n disabled={disabled || value <= min}\n onClick={() => set(value - step)}\n className={STEP_BUTTON}\n >\n <span aria-hidden=\"true\">−</span>\n </button>\n <input\n id={id}\n name={name}\n type=\"text\"\n role=\"spinbutton\"\n inputMode=\"numeric\"\n aria-label={label}\n aria-valuenow={value}\n aria-valuemin={min}\n aria-valuemax={max}\n disabled={disabled}\n value={text}\n onChange={event => setText(event.currentTarget.value)}\n onBlur={commit}\n onKeyDown={onKeyDown}\n className=\"w-16 min-h-(--target-min) rounded-lg border border-border-control bg-surface-elevated px-2xs py-3xs text-center text-step-sm text-content tabular-nums focus-ring disabled:cursor-not-allowed disabled:opacity-50\"\n />\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={t('quantity.increase', { label })}\n disabled={disabled || (max !== undefined && value >= max)}\n onClick={() => set(value + step)}\n className={STEP_BUTTON}\n >\n <span aria-hidden=\"true\">+</span>\n </button>\n </span>\n );\n}\n"],"names":["useEffect","useState","useT","cn","ScaledQuantityInput","STEP_BUTTON","QuantityInput","props","scale","undefined","CountInput","label","value","controlled","defaultValue","onChange","min","max","step","disabled","id","name","className","t","own","setOwn","text","setText","String","clamp","next","Math","Number","POSITIVE_INFINITY","set","clamped","commit","typed","parseInt","isNaN","onKeyDown","event","ArrowUp","ArrowDown","Home","End","key","preventDefault","span","button","type","tabIndex","aria-label","onClick","aria-hidden","input","role","inputMode","aria-valuenow","aria-valuemin","aria-valuemax","currentTarget","onBlur"],"mappings":"AAAA;;;AAEA,SAA6BA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,IAAI,QAAQ,yBAAyB;AAC9C,SAASC,EAAE,QAAQ,oBAAoB;AACvC,SAASC,mBAAmB,QAAQ,6BAA6B;AACjE,SAASC,WAAW,QAAQ,mBAAmB;AAwD/C;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,cAAcC,KAAy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IJ;IACN;IAEA,qBACE,MAACkB;QAAK1B,WAAWnB,GAAG,oCAAoCmB;;0BACtD,KAAC2B;gBACCC,MAAK;gBACLC,UAAU,CAAC;gBACXC,cAAY7B,EAAE,qBAAqB;oBAAEZ;gBAAM;gBAC3CQ,UAAUA,YAAYP,SAASI;gBAC/BqC,SAAS,IAAMnB,IAAItB,QAAQM;gBAC3BI,WAAWjB;0BAEX,cAAA,KAAC2C;oBAAKM,eAAY;8BAAO;;;0BAE3B,KAACC;gBACCnC,IAAIA;gBACJC,MAAMA;gBACN6B,MAAK;gBACLM,MAAK;gBACLC,WAAU;gBACVL,cAAYzC;gBACZ+C,iBAAe9C;gBACf+C,iBAAe3C;gBACf4C,iBAAe3C;gBACfE,UAAUA;gBACVP,OAAOc;gBACPX,UAAU0B,CAAAA,QAASd,QAAQc,MAAMoB,aAAa,CAACjD,KAAK;gBACpDkD,QAAQ1B;gBACRI,WAAWA;gBACXlB,WAAU;;0BAEZ,KAAC2B;gBACCC,MAAK;gBACLC,UAAU,CAAC;gBACXC,cAAY7B,EAAE,qBAAqB;oBAAEZ;gBAAM;gBAC3CQ,UAAUA,YAAaF,QAAQR,aAAaG,SAASK;gBACrDoC,SAAS,IAAMnB,IAAItB,QAAQM;gBAC3BI,WAAWjB;0BAEX,cAAA,KAAC2C;oBAAKM,eAAY;8BAAO;;;;;AAIjC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { QuantityInputProps } from './quantity-input.js';
|
|
2
|
+
/**
|
|
3
|
+
* `QuantityInput` given a `scale`: every number across its props is the stored
|
|
4
|
+
* integer, and the field shows and takes the decimal.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ It never alters what was typed — no clamp, no rounding, no snap to the
|
|
7
|
+
* step: selling 3 to someone who typed 3,5 is the defect this mode exists to
|
|
8
|
+
* prevent. An entry outside the rules is marked invalid and still reported,
|
|
9
|
+
* and text that is no number is reported as `NaN`, so a caller never keeps
|
|
10
|
+
* the previous quantity under a field that shows another. Only − and +, which
|
|
11
|
+
* ask for a change, land on the step and inside the bounds.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ScaledQuantityInput({ label, value: controlled, defaultValue, onChange, min, max, step, scale, unit, invalid, disabled, id, name, className, 'aria-describedby': describedBy, }: QuantityInputProps & {
|
|
14
|
+
scale: number;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=scaled-quantity-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaled-quantity-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/number-input/scaled-quantity-input.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,KAAK,EAAE,UAAU,EACjB,YAAY,EACZ,QAAQ,EACR,GAAO,EACP,GAAG,EACH,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,OAAe,EACf,QAAgB,EAChB,EAAE,EACF,IAAI,EACJ,SAAS,EACT,kBAAkB,EAAE,WAAW,GAChC,EAAE,kBAAkB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,+BA0HxC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatScaled, parseScaled, scaledToDecimal } from '@entifix/core';
|
|
4
|
+
import { useEffect, useId, useState } from 'react';
|
|
5
|
+
import { useLocale, useT } from '../../../i18n/index.js';
|
|
6
|
+
import { cn } from '../../utils/cn.js';
|
|
7
|
+
import { STEP_BUTTON } from './step-button.js';
|
|
8
|
+
/**
|
|
9
|
+
* `QuantityInput` given a `scale`: every number across its props is the stored
|
|
10
|
+
* integer, and the field shows and takes the decimal.
|
|
11
|
+
*
|
|
12
|
+
* ⚠️ It never alters what was typed — no clamp, no rounding, no snap to the
|
|
13
|
+
* step: selling 3 to someone who typed 3,5 is the defect this mode exists to
|
|
14
|
+
* prevent. An entry outside the rules is marked invalid and still reported,
|
|
15
|
+
* and text that is no number is reported as `NaN`, so a caller never keeps
|
|
16
|
+
* the previous quantity under a field that shows another. Only − and +, which
|
|
17
|
+
* ask for a change, land on the step and inside the bounds.
|
|
18
|
+
*/ export function ScaledQuantityInput({ label, value: controlled, defaultValue, onChange, min = 0, max, step, scale, unit, invalid = false, disabled = false, id, name, className, 'aria-describedby': describedBy }) {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const locale = useLocale();
|
|
21
|
+
const unitId = useId();
|
|
22
|
+
const editable = (stored)=>Number.isSafeInteger(stored) ? formatScaled(stored, scale, locale, {
|
|
23
|
+
grouping: false
|
|
24
|
+
}) : '';
|
|
25
|
+
const [own, setOwn] = useState(defaultValue != null ? defaultValue : min);
|
|
26
|
+
const value = controlled != null ? controlled : own;
|
|
27
|
+
const [text, setText] = useState(()=>editable(value));
|
|
28
|
+
const [emitted, setEmitted] = useState(value);
|
|
29
|
+
useEffect(()=>{
|
|
30
|
+
if (Object.is(value, emitted)) return;
|
|
31
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- the value moved from outside (a reset, a load)
|
|
32
|
+
setText(editable(value));
|
|
33
|
+
setEmitted(value);
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- it answers an outside value, never its own typing
|
|
35
|
+
}, [
|
|
36
|
+
value
|
|
37
|
+
]);
|
|
38
|
+
const report = (next)=>{
|
|
39
|
+
setEmitted(next);
|
|
40
|
+
setOwn(next);
|
|
41
|
+
if (!Object.is(next, value)) onChange == null ? void 0 : onChange(next);
|
|
42
|
+
};
|
|
43
|
+
const jump = (next)=>{
|
|
44
|
+
const bounded = Math.min(max != null ? max : Number.MAX_SAFE_INTEGER, Math.max(min, next));
|
|
45
|
+
setText(editable(bounded));
|
|
46
|
+
report(bounded);
|
|
47
|
+
};
|
|
48
|
+
const readable = Number.isSafeInteger(value);
|
|
49
|
+
const by = step != null ? step : 10 ** scale;
|
|
50
|
+
const more = ()=>jump(readable ? (Math.floor(value / by) + 1) * by : min);
|
|
51
|
+
const less = ()=>jump(readable ? (Math.ceil(value / by) - 1) * by : min);
|
|
52
|
+
const refused = !readable || value < min || max !== undefined && value > max || step !== undefined && value % step !== 0;
|
|
53
|
+
const onKeyDown = (event)=>{
|
|
54
|
+
const move = {
|
|
55
|
+
ArrowUp: more,
|
|
56
|
+
ArrowDown: less,
|
|
57
|
+
Home: ()=>jump(min),
|
|
58
|
+
End: max === undefined ? undefined : ()=>jump(max)
|
|
59
|
+
}[event.key];
|
|
60
|
+
if (move === undefined) return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
move();
|
|
63
|
+
};
|
|
64
|
+
const decimal = (stored)=>Number(scaledToDecimal(stored, scale));
|
|
65
|
+
return /*#__PURE__*/ _jsxs("span", {
|
|
66
|
+
className: cn('inline-flex items-center gap-3xs', className),
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ _jsx("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
tabIndex: -1,
|
|
71
|
+
"aria-label": t('quantity.decrease', {
|
|
72
|
+
label
|
|
73
|
+
}),
|
|
74
|
+
disabled: disabled || readable && value <= min,
|
|
75
|
+
onClick: less,
|
|
76
|
+
className: STEP_BUTTON,
|
|
77
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
78
|
+
"aria-hidden": "true",
|
|
79
|
+
children: "−"
|
|
80
|
+
})
|
|
81
|
+
}),
|
|
82
|
+
/*#__PURE__*/ _jsx("input", {
|
|
83
|
+
id: id,
|
|
84
|
+
name: name,
|
|
85
|
+
type: "text",
|
|
86
|
+
role: "spinbutton",
|
|
87
|
+
inputMode: scale === 0 ? 'numeric' : 'decimal',
|
|
88
|
+
"aria-label": label,
|
|
89
|
+
"aria-valuenow": readable ? decimal(value) : undefined,
|
|
90
|
+
"aria-valuetext": readable ? [
|
|
91
|
+
formatScaled(value, scale, locale),
|
|
92
|
+
unit
|
|
93
|
+
].filter(Boolean).join(' ') : text || undefined,
|
|
94
|
+
"aria-valuemin": decimal(min),
|
|
95
|
+
"aria-valuemax": max === undefined ? undefined : decimal(max),
|
|
96
|
+
"aria-invalid": invalid || refused || undefined,
|
|
97
|
+
"aria-describedby": [
|
|
98
|
+
describedBy,
|
|
99
|
+
unit === undefined ? undefined : unitId
|
|
100
|
+
].filter(Boolean).join(' ') || undefined,
|
|
101
|
+
disabled: disabled,
|
|
102
|
+
value: text,
|
|
103
|
+
onChange: (event)=>{
|
|
104
|
+
var _parseScaled;
|
|
105
|
+
const next = event.currentTarget.value;
|
|
106
|
+
setText(next);
|
|
107
|
+
report((_parseScaled = parseScaled(next, scale, locale)) != null ? _parseScaled : Number.NaN);
|
|
108
|
+
},
|
|
109
|
+
onKeyDown: onKeyDown,
|
|
110
|
+
className: "w-24 min-h-(--target-min) rounded-lg border border-border-control bg-surface-elevated px-2xs py-3xs text-center text-step-sm text-content tabular-nums focus-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger"
|
|
111
|
+
}),
|
|
112
|
+
unit !== undefined && /*#__PURE__*/ _jsx("span", {
|
|
113
|
+
id: unitId,
|
|
114
|
+
className: "text-step-sm text-content-muted",
|
|
115
|
+
children: unit
|
|
116
|
+
}),
|
|
117
|
+
/*#__PURE__*/ _jsx("button", {
|
|
118
|
+
type: "button",
|
|
119
|
+
tabIndex: -1,
|
|
120
|
+
"aria-label": t('quantity.increase', {
|
|
121
|
+
label
|
|
122
|
+
}),
|
|
123
|
+
disabled: disabled || max !== undefined && value >= max,
|
|
124
|
+
onClick: more,
|
|
125
|
+
className: STEP_BUTTON,
|
|
126
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
127
|
+
"aria-hidden": "true",
|
|
128
|
+
children: "+"
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=scaled-quantity-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/number-input/scaled-quantity-input.tsx"],"sourcesContent":["'use client';\n\nimport { formatScaled, parseScaled, scaledToDecimal } from '@entifix/core';\nimport { type KeyboardEvent, useEffect, useId, useState } from 'react';\n\nimport { useLocale, useT } from '../../../i18n/index.js';\nimport { cn } from '../../utils/cn.js';\nimport type { QuantityInputProps } from './quantity-input.js';\nimport { STEP_BUTTON } from './step-button.js';\n\n/**\n * `QuantityInput` given a `scale`: every number across its props is the stored\n * integer, and the field shows and takes the decimal.\n *\n * ⚠️ It never alters what was typed — no clamp, no rounding, no snap to the\n * step: selling 3 to someone who typed 3,5 is the defect this mode exists to\n * prevent. An entry outside the rules is marked invalid and still reported,\n * and text that is no number is reported as `NaN`, so a caller never keeps\n * the previous quantity under a field that shows another. Only − and +, which\n * ask for a change, land on the step and inside the bounds.\n */\nexport function ScaledQuantityInput({\n label,\n value: controlled,\n defaultValue,\n onChange,\n min = 0,\n max,\n step,\n scale,\n unit,\n invalid = false,\n disabled = false,\n id,\n name,\n className,\n 'aria-describedby': describedBy,\n}: QuantityInputProps & { scale: number }) {\n const t = useT();\n const locale = useLocale();\n const unitId = useId();\n const editable = (stored: number) =>\n Number.isSafeInteger(stored)\n ? formatScaled(stored, scale, locale, { grouping: false })\n : '';\n\n const [own, setOwn] = useState(defaultValue ?? min);\n const value = controlled ?? own;\n const [text, setText] = useState(() => editable(value));\n const [emitted, setEmitted] = useState(value);\n\n useEffect(() => {\n if (Object.is(value, emitted)) return;\n // eslint-disable-next-line react-hooks/set-state-in-effect -- the value moved from outside (a reset, a load)\n setText(editable(value));\n setEmitted(value);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- it answers an outside value, never its own typing\n }, [value]);\n\n const report = (next: number) => {\n setEmitted(next);\n setOwn(next);\n if (!Object.is(next, value)) onChange?.(next);\n };\n const jump = (next: number) => {\n const bounded = Math.min(\n max ?? Number.MAX_SAFE_INTEGER,\n Math.max(min, next),\n );\n setText(editable(bounded));\n report(bounded);\n };\n\n const readable = Number.isSafeInteger(value);\n const by = step ?? 10 ** scale;\n const more = () => jump(readable ? (Math.floor(value / by) + 1) * by : min);\n const less = () => jump(readable ? (Math.ceil(value / by) - 1) * by : min);\n const refused =\n !readable ||\n value < min ||\n (max !== undefined && value > max) ||\n (step !== undefined && value % step !== 0);\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const move = {\n ArrowUp: more,\n ArrowDown: less,\n Home: () => jump(min),\n End: max === undefined ? undefined : () => jump(max),\n }[event.key];\n if (move === undefined) return;\n event.preventDefault();\n move();\n };\n\n const decimal = (stored: number) => Number(scaledToDecimal(stored, scale));\n\n return (\n <span className={cn('inline-flex items-center gap-3xs', className)}>\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={t('quantity.decrease', { label })}\n disabled={disabled || (readable && value <= min)}\n onClick={less}\n className={STEP_BUTTON}\n >\n <span aria-hidden=\"true\">−</span>\n </button>\n <input\n id={id}\n name={name}\n type=\"text\"\n role=\"spinbutton\"\n inputMode={scale === 0 ? 'numeric' : 'decimal'}\n aria-label={label}\n aria-valuenow={readable ? decimal(value) : undefined}\n aria-valuetext={\n readable\n ? [formatScaled(value, scale, locale), unit]\n .filter(Boolean)\n .join(' ')\n : text || undefined\n }\n aria-valuemin={decimal(min)}\n aria-valuemax={max === undefined ? undefined : decimal(max)}\n aria-invalid={invalid || refused || undefined}\n aria-describedby={\n [describedBy, unit === undefined ? undefined : unitId]\n .filter(Boolean)\n .join(' ') || undefined\n }\n disabled={disabled}\n value={text}\n onChange={event => {\n const next = event.currentTarget.value;\n setText(next);\n report(parseScaled(next, scale, locale) ?? Number.NaN);\n }}\n onKeyDown={onKeyDown}\n className=\"w-24 min-h-(--target-min) rounded-lg border border-border-control bg-surface-elevated px-2xs py-3xs text-center text-step-sm text-content tabular-nums focus-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-danger\"\n />\n {unit !== undefined && (\n <span id={unitId} className=\"text-step-sm text-content-muted\">\n {unit}\n </span>\n )}\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={t('quantity.increase', { label })}\n disabled={disabled || (max !== undefined && value >= max)}\n onClick={more}\n className={STEP_BUTTON}\n >\n <span aria-hidden=\"true\">+</span>\n </button>\n </span>\n );\n}\n"],"names":["formatScaled","parseScaled","scaledToDecimal","useEffect","useId","useState","useLocale","useT","cn","STEP_BUTTON","ScaledQuantityInput","label","value","controlled","defaultValue","onChange","min","max","step","scale","unit","invalid","disabled","id","name","className","describedBy","t","locale","unitId","editable","stored","Number","isSafeInteger","grouping","own","setOwn","text","setText","emitted","setEmitted","Object","is","report","next","jump","bounded","Math","MAX_SAFE_INTEGER","readable","by","more","floor","less","ceil","refused","undefined","onKeyDown","event","move","ArrowUp","ArrowDown","Home","End","key","preventDefault","decimal","span","button","type","tabIndex","aria-label","onClick","aria-hidden","input","role","inputMode","aria-valuenow","aria-valuetext","filter","Boolean","join","aria-valuemin","aria-valuemax","aria-invalid","aria-describedby","currentTarget","NaN"],"mappings":"AAAA;;AAEA,SAASA,YAAY,EAAEC,WAAW,EAAEC,eAAe,QAAQ,gBAAgB;AAC3E,SAA6BC,SAAS,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAQ;AAEvE,SAASC,SAAS,EAAEC,IAAI,QAAQ,yBAAyB;AACzD,SAASC,EAAE,QAAQ,oBAAoB;AAEvC,SAASC,WAAW,QAAQ,mBAAmB;AAE/C;;;;;;;;;;CAUC,GACD,OAAO,SAASC,oBAAoB,EAClCC,KAAK,EACLC,OAAOC,UAAU,EACjBC,YAAY,EACZC,QAAQ,EACRC,MAAM,CAAC,EACPC,GAAG,EACHC,IAAI,EACJC,KAAK,EACLC,IAAI,EACJC,UAAU,KAAK,EACfC,WAAW,KAAK,EAChBC,EAAE,EACFC,IAAI,EACJC,SAAS,EACT,oBAAoBC,WAAW,EACQ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M4B,aAAa,CAAC1E,KAAK;oBACtC0B,QAAQM;oBACRD,QAAO1C,eAAAA,YAAY2C,MAAMzB,OAAOS,mBAAzB3B,eAAoC+B,OAAOuD,GAAG;gBACvD;gBACA9B,WAAWA;gBACXhC,WAAU;;YAEXL,SAASoC,2BACR,KAACW;gBAAK5C,IAAIM;gBAAQJ,WAAU;0BACzBL;;0BAGL,KAACgD;gBACCC,MAAK;gBACLC,UAAU,CAAC;gBACXC,cAAY5C,EAAE,qBAAqB;oBAAEhB;gBAAM;gBAC3CW,UAAUA,YAAaL,QAAQuC,aAAa5C,SAASK;gBACrDuD,SAASrB;gBACT1B,WAAWhB;0BAEX,cAAA,KAAC0D;oBAAKM,eAAY;8BAAO;;;;;AAIjC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** The − and + beside a quantity. */
|
|
2
|
+
export declare const STEP_BUTTON = "flex min-h-(--target-min) min-w-(--target-min) shrink-0 items-center justify-center rounded-md border border-border-control bg-surface-elevated text-content hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50";
|
|
3
|
+
//# sourceMappingURL=step-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-button.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/number-input/step-button.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,eAAO,MAAM,WAAW,kOACyM,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** The − and + beside a quantity. */ export const STEP_BUTTON = 'flex min-h-(--target-min) min-w-(--target-min) shrink-0 items-center justify-center rounded-md border border-border-control bg-surface-elevated text-content hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50';
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=step-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/number-input/step-button.ts"],"sourcesContent":["/** The − and + beside a quantity. */\nexport const STEP_BUTTON =\n 'flex min-h-(--target-min) min-w-(--target-min) shrink-0 items-center justify-center rounded-md border border-border-control bg-surface-elevated text-content hover:bg-surface disabled:cursor-not-allowed disabled:opacity-50';\n"],"names":["STEP_BUTTON"],"mappings":"AAAA,mCAAmC,GACnC,OAAO,MAAMA,cACX,gOAAgO"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The draft for text an input could not read as its number: the text itself,
|
|
3
|
+
* kept so it can be shown again. Text that `Number` would still read — `12.5`
|
|
4
|
+
* typed where only whole units exist — is marked, or validation would let it
|
|
5
|
+
* through and store it as if it were already in the stored unit.
|
|
6
|
+
*/
|
|
7
|
+
export declare const unparsedDraft: (text: string) => string;
|
|
8
|
+
/** What was typed, out of a draft {@link unparsedDraft} made. */
|
|
9
|
+
export declare const typedText: (draft: string) => string;
|
|
10
|
+
//# sourceMappingURL=unparsed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unparsed.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/number-input/unparsed.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAKrB,CAAC;AAEzB,iEAAiE;AACjE,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,MAAiC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** U+2060, a word joiner: invisible, and never part of a number. */ const MARK = '\u2060';
|
|
2
|
+
/**
|
|
3
|
+
* The draft for text an input could not read as its number: the text itself,
|
|
4
|
+
* kept so it can be shown again. Text that `Number` would still read — `12.5`
|
|
5
|
+
* typed where only whole units exist — is marked, or validation would let it
|
|
6
|
+
* through and store it as if it were already in the stored unit.
|
|
7
|
+
*/ export const unparsedDraft = (text)=>text.trim() === '' ? '' : Number.isNaN(Number(text)) ? text : `${MARK}${text}`;
|
|
8
|
+
/** What was typed, out of a draft {@link unparsedDraft} made. */ export const typedText = (draft)=>draft.replace(MARK, '');
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=unparsed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/number-input/unparsed.ts"],"sourcesContent":["/** U+2060, a word joiner: invisible, and never part of a number. */\nconst MARK = '\\u2060';\n\n/**\n * The draft for text an input could not read as its number: the text itself,\n * kept so it can be shown again. Text that `Number` would still read — `12.5`\n * typed where only whole units exist — is marked, or validation would let it\n * through and store it as if it were already in the stored unit.\n */\nexport const unparsedDraft = (text: string): string =>\n text.trim() === ''\n ? ''\n : Number.isNaN(Number(text))\n ? text\n : `${MARK}${text}`;\n\n/** What was typed, out of a draft {@link unparsedDraft} made. */\nexport const typedText = (draft: string): string => draft.replace(MARK, '');\n"],"names":["MARK","unparsedDraft","text","trim","Number","isNaN","typedText","draft","replace"],"mappings":"AAAA,kEAAkE,GAClE,MAAMA,OAAO;AAEb;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC,OAC5BA,KAAKC,IAAI,OAAO,KACZ,KACAC,OAAOC,KAAK,CAACD,OAAOF,SAClBA,OACA,GAAGF,OAAOE,MAAM,CAAC;AAEzB,+DAA+D,GAC/D,OAAO,MAAMI,YAAY,CAACC,QAA0BA,MAAMC,OAAO,CAACR,MAAM,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/scaled/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/scaled/index.ts"],"sourcesContent":["export * from './scaled-input.js';\nexport * from './scaled-math.js';\nexport * from './scaled-value.js';\nexport * from './use-unit-label.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,sBAAsB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type NumberInputProps } from '../number-input/number-input.js';
|
|
2
|
+
export interface ScaledInputProps extends Omit<NumberInputProps, 'value' | 'onChange' | 'inputMode'> {
|
|
3
|
+
/** The stored integer, as a draft string (`'3500'`), or `''` for none. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Called with the stored integer as a draft string. */
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
/** `undefined` while the record names no unit: the field then waits. */
|
|
8
|
+
scale: number | undefined;
|
|
9
|
+
/** The unit as the reader names it, shown after the field. */
|
|
10
|
+
unit?: string;
|
|
11
|
+
locale: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Edits a scaled integer as the decimal it stands for and writes back the
|
|
15
|
+
* integer. What was typed is kept as typed and is never rounded: text that is
|
|
16
|
+
* no number in this scale reaches the draft as itself, for validation to
|
|
17
|
+
* refuse.
|
|
18
|
+
*
|
|
19
|
+
* When the unit changes under it, a number the person typed keeps its meaning
|
|
20
|
+
* — `3` stays three, metres or pieces — and a stored one is only shown again
|
|
21
|
+
* in the new scale.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ScaledInput({ value, onChange, scale, unit, locale, disabled, 'aria-describedby': describedBy, ...props }: ScaledInputProps): import("react").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=scaled-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaled-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/scaled/scaled-input.tsx"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AAGzC,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAC5C,gBAAgB,EAChB,OAAO,GAAG,UAAU,GAAG,WAAW,CACnC;IACC,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,wEAAwE;IACxE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,kBAAkB,EAAE,WAAW,EAC/B,GAAG,KAAK,EACT,EAAE,gBAAgB,+BAuElB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
+
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { formatScaled, parseScaled } from '@entifix/core';
|
|
6
|
+
import { useEffect, useId, useState } from 'react';
|
|
7
|
+
import { useT } from '../../../i18n/index.js';
|
|
8
|
+
import { NumberInput } from '../number-input/number-input.js';
|
|
9
|
+
import { typedText, unparsedDraft } from '../number-input/unparsed.js';
|
|
10
|
+
/**
|
|
11
|
+
* Edits a scaled integer as the decimal it stands for and writes back the
|
|
12
|
+
* integer. What was typed is kept as typed and is never rounded: text that is
|
|
13
|
+
* no number in this scale reaches the draft as itself, for validation to
|
|
14
|
+
* refuse.
|
|
15
|
+
*
|
|
16
|
+
* When the unit changes under it, a number the person typed keeps its meaning
|
|
17
|
+
* — `3` stays three, metres or pieces — and a stored one is only shown again
|
|
18
|
+
* in the new scale.
|
|
19
|
+
*/ export function ScaledInput(_0) {
|
|
20
|
+
let { value, onChange, scale, unit, locale, disabled, 'aria-describedby': describedBy } = _0, props = _object_without_properties_loose(_0, [
|
|
21
|
+
"value",
|
|
22
|
+
"onChange",
|
|
23
|
+
"scale",
|
|
24
|
+
"unit",
|
|
25
|
+
"locale",
|
|
26
|
+
"disabled",
|
|
27
|
+
'aria-describedby'
|
|
28
|
+
]);
|
|
29
|
+
const t = useT();
|
|
30
|
+
const unitId = useId();
|
|
31
|
+
const display = (stored)=>scale === undefined || !Number.isSafeInteger(Number(stored || Number.NaN)) ? typedText(stored) : formatScaled(Number(stored), scale, locale, {
|
|
32
|
+
grouping: false
|
|
33
|
+
});
|
|
34
|
+
const storedOf = (typed, at)=>{
|
|
35
|
+
const parsed = parseScaled(typed, at, locale);
|
|
36
|
+
return parsed === undefined ? unparsedDraft(typed) : String(parsed);
|
|
37
|
+
};
|
|
38
|
+
const [text, setText] = useState(()=>display(value));
|
|
39
|
+
const [emitted, setEmitted] = useState(value);
|
|
40
|
+
const [typed, setTyped] = useState(false);
|
|
41
|
+
const [readAt, setReadAt] = useState(scale);
|
|
42
|
+
useEffect(()=>{
|
|
43
|
+
if (value !== emitted) {
|
|
44
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- an outside write (a reset, a load) replaces what was typed
|
|
45
|
+
setText(display(value));
|
|
46
|
+
setEmitted(value);
|
|
47
|
+
setTyped(false);
|
|
48
|
+
setReadAt(scale);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (scale === readAt) return;
|
|
52
|
+
setReadAt(scale);
|
|
53
|
+
if (!typed) {
|
|
54
|
+
setText(display(value));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const next = scale === undefined ? unparsedDraft(text) : storedOf(text, scale);
|
|
58
|
+
setEmitted(next);
|
|
59
|
+
if (next !== value) onChange(next);
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- it answers an outside value or a changed scale, never its own typing
|
|
61
|
+
}, [
|
|
62
|
+
value,
|
|
63
|
+
scale,
|
|
64
|
+
locale
|
|
65
|
+
]);
|
|
66
|
+
const waiting = scale === undefined;
|
|
67
|
+
const hint = waiting ? t('quantity.needsUnit') : unit;
|
|
68
|
+
return /*#__PURE__*/ _jsxs("span", {
|
|
69
|
+
className: "inline-flex items-center gap-2xs",
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ _jsx(NumberInput, _extends({}, props, {
|
|
72
|
+
disabled: disabled === true || waiting,
|
|
73
|
+
"aria-describedby": [
|
|
74
|
+
describedBy,
|
|
75
|
+
hint === undefined ? undefined : unitId
|
|
76
|
+
].filter(Boolean).join(' ') || undefined,
|
|
77
|
+
inputMode: scale === 0 ? 'numeric' : 'decimal',
|
|
78
|
+
value: text,
|
|
79
|
+
onChange: (event)=>{
|
|
80
|
+
const next = event.currentTarget.value;
|
|
81
|
+
setText(next);
|
|
82
|
+
setTyped(true);
|
|
83
|
+
// Disabled while it waits, so there is always a scale to read in.
|
|
84
|
+
const stored = storedOf(next, scale);
|
|
85
|
+
setEmitted(stored);
|
|
86
|
+
onChange(stored);
|
|
87
|
+
}
|
|
88
|
+
})),
|
|
89
|
+
hint !== undefined && /*#__PURE__*/ _jsx("span", {
|
|
90
|
+
id: unitId,
|
|
91
|
+
className: "text-step-sm text-content-muted",
|
|
92
|
+
children: hint
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=scaled-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/scaled/scaled-input.tsx"],"sourcesContent":["'use client';\n\nimport { formatScaled, parseScaled } from '@entifix/core';\nimport { useEffect, useId, useState } from 'react';\n\nimport { useT } from '../../../i18n/index.js';\nimport {\n NumberInput,\n type NumberInputProps,\n} from '../number-input/number-input.js';\nimport { typedText, unparsedDraft } from '../number-input/unparsed.js';\n\nexport interface ScaledInputProps extends Omit<\n NumberInputProps,\n 'value' | 'onChange' | 'inputMode'\n> {\n /** The stored integer, as a draft string (`'3500'`), or `''` for none. */\n value: string;\n /** Called with the stored integer as a draft string. */\n onChange: (value: string) => void;\n /** `undefined` while the record names no unit: the field then waits. */\n scale: number | undefined;\n /** The unit as the reader names it, shown after the field. */\n unit?: string;\n locale: string;\n}\n\n/**\n * Edits a scaled integer as the decimal it stands for and writes back the\n * integer. What was typed is kept as typed and is never rounded: text that is\n * no number in this scale reaches the draft as itself, for validation to\n * refuse.\n *\n * When the unit changes under it, a number the person typed keeps its meaning\n * — `3` stays three, metres or pieces — and a stored one is only shown again\n * in the new scale.\n */\nexport function ScaledInput({\n value,\n onChange,\n scale,\n unit,\n locale,\n disabled,\n 'aria-describedby': describedBy,\n ...props\n}: ScaledInputProps) {\n const t = useT();\n const unitId = useId();\n const display = (stored: string) =>\n scale === undefined || !Number.isSafeInteger(Number(stored || Number.NaN))\n ? typedText(stored)\n : formatScaled(Number(stored), scale, locale, { grouping: false });\n const storedOf = (typed: string, at: number) => {\n const parsed = parseScaled(typed, at, locale);\n return parsed === undefined ? unparsedDraft(typed) : String(parsed);\n };\n\n const [text, setText] = useState(() => display(value));\n const [emitted, setEmitted] = useState(value);\n const [typed, setTyped] = useState(false);\n const [readAt, setReadAt] = useState(scale);\n\n useEffect(() => {\n if (value !== emitted) {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- an outside write (a reset, a load) replaces what was typed\n setText(display(value));\n setEmitted(value);\n setTyped(false);\n setReadAt(scale);\n return;\n }\n if (scale === readAt) return;\n setReadAt(scale);\n if (!typed) {\n setText(display(value));\n return;\n }\n const next =\n scale === undefined ? unparsedDraft(text) : storedOf(text, scale);\n setEmitted(next);\n if (next !== value) onChange(next);\n // eslint-disable-next-line react-hooks/exhaustive-deps -- it answers an outside value or a changed scale, never its own typing\n }, [value, scale, locale]);\n\n const waiting = scale === undefined;\n const hint = waiting ? t('quantity.needsUnit') : unit;\n\n return (\n <span className=\"inline-flex items-center gap-2xs\">\n <NumberInput\n {...props}\n disabled={disabled === true || waiting}\n aria-describedby={\n [describedBy, hint === undefined ? undefined : unitId]\n .filter(Boolean)\n .join(' ') || undefined\n }\n inputMode={scale === 0 ? 'numeric' : 'decimal'}\n value={text}\n onChange={event => {\n const next = event.currentTarget.value;\n setText(next);\n setTyped(true);\n // Disabled while it waits, so there is always a scale to read in.\n const stored = storedOf(next, scale as number);\n setEmitted(stored);\n onChange(stored);\n }}\n />\n {hint !== undefined && (\n <span id={unitId} className=\"text-step-sm text-content-muted\">\n {hint}\n </span>\n )}\n </span>\n );\n}\n"],"names":["formatScaled","parseScaled","useEffect","useId","useState","useT","NumberInput","typedText","unparsedDraft","ScaledInput","value","onChange","scale","unit","locale","disabled","describedBy","props","t","unitId","display","stored","undefined","Number","isSafeInteger","NaN","grouping","storedOf","typed","at","parsed","String","text","setText","emitted","setEmitted","setTyped","readAt","setReadAt","next","waiting","hint","span","className","aria-describedby","filter","Boolean","join","inputMode","event","currentTarget","id"],"mappings":"AAAA;;;;AAEA,SAASA,YAAY,EAAEC,WAAW,QAAQ,gBAAgB;AAC1D,SAASC,SAAS,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAQ;AAEnD,SAASC,IAAI,QAAQ,yBAAyB;AAC9C,SACEC,WAAW,QAEN,kCAAkC;AACzC,SAASC,SAAS,EAAEC,aAAa,QAAQ,8BAA8B;AAiBvE;;;;;;;;;CASC,GACD,OAAO,SAASC,YAAY,EAST;QATS,EAC1BC,KAAK,EACLC,QAAQ,EACRC,KAAK,EACLC,IAAI,EACJC,MAAM,EACNC,QAAQ,EACR,oBAAoBC,WAAW,EAEd,OADdC;;;;;;;QADH;;IAGA,MAAMC,IAAIb;IACV,MAAMc,SAAShB;IACf,MAAMiB,UAAU,CAACC,SACfT,UAAUU,aAAa,CAACC,OAAOC,aAAa,CAACD,OAAOF,UAAUE,OAAOE,GAAG,KACpElB,UAAUc,UACVrB,aAAauB,OAAOF,SAAST,OAAOE,QAAQ;YAAEY,UAAU;QAAM;IACpE,MAAMC,WAAW,CAACC,OAAeC;QAC/B,MAAMC,SAAS7B,YAAY2B,OAAOC,IAAIf;QAC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wB,WAAU;0BACzBF;;;;AAKX"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ScaledFormat } from '@entifix/core';
|
|
2
|
+
/** The scale a record's value is in, and the unit that decided it. */
|
|
3
|
+
export interface ResolvedScale {
|
|
4
|
+
readonly scale: number;
|
|
5
|
+
readonly unit?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* How many decimals a member holds in this record: the fixed scale, or its
|
|
9
|
+
* unit's. `undefined` while the record names no unit the member declares,
|
|
10
|
+
* because an integer cannot be read without one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function scaleOf(scaled: ScaledFormat, record: Readonly<Record<string, unknown>> | undefined): ResolvedScale | undefined;
|
|
13
|
+
//# sourceMappingURL=scaled-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaled-math.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/scaled/scaled-math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,sEAAsE;AACtE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GACpD,aAAa,GAAG,SAAS,CAM3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many decimals a member holds in this record: the fixed scale, or its
|
|
3
|
+
* unit's. `undefined` while the record names no unit the member declares,
|
|
4
|
+
* because an integer cannot be read without one.
|
|
5
|
+
*/ export function scaleOf(scaled, record) {
|
|
6
|
+
if (scaled.units === undefined) return {
|
|
7
|
+
scale: scaled.scale
|
|
8
|
+
};
|
|
9
|
+
const unit = record == null ? void 0 : record[scaled.unitMember];
|
|
10
|
+
if (typeof unit !== 'string' || !Object.hasOwn(scaled.units, unit)) return undefined;
|
|
11
|
+
return {
|
|
12
|
+
scale: scaled.units[unit],
|
|
13
|
+
unit
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=scaled-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/scaled/scaled-math.ts"],"sourcesContent":["import type { ScaledFormat } from '@entifix/core';\n\n/** The scale a record's value is in, and the unit that decided it. */\nexport interface ResolvedScale {\n readonly scale: number;\n readonly unit?: string;\n}\n\n/**\n * How many decimals a member holds in this record: the fixed scale, or its\n * unit's. `undefined` while the record names no unit the member declares,\n * because an integer cannot be read without one.\n */\nexport function scaleOf(\n scaled: ScaledFormat,\n record: Readonly<Record<string, unknown>> | undefined,\n): ResolvedScale | undefined {\n if (scaled.units === undefined) return { scale: scaled.scale };\n const unit = record?.[scaled.unitMember];\n if (typeof unit !== 'string' || !Object.hasOwn(scaled.units, unit))\n return undefined;\n return { scale: scaled.units[unit] as number, unit };\n}\n"],"names":["scaleOf","scaled","record","units","undefined","scale","unit","unitMember","Object","hasOwn"],"mappings":"AAQA;;;;CAIC,GACD,OAAO,SAASA,QACdC,MAAoB,EACpBC,MAAqD;IAErD,IAAID,OAAOE,KAAK,KAAKC,WAAW,OAAO;QAAEC,OAAOJ,OAAOI,KAAK;IAAC;IAC7D,MAAMC,OAAOJ,0BAAAA,MAAQ,CAACD,OAAOM,UAAU,CAAC;IACxC,IAAI,OAAOD,SAAS,YAAY,CAACE,OAAOC,MAAM,CAACR,OAAOE,KAAK,EAAEG,OAC3D,OAAOF;IACT,OAAO;QAAEC,OAAOJ,OAAOE,KAAK,CAACG,KAAK;QAAYA;IAAK;AACrD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ScaledValueProps {
|
|
2
|
+
/** The stored integer. */
|
|
3
|
+
value: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
/** The unit as the reader names it. */
|
|
6
|
+
unit?: string;
|
|
7
|
+
locale: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A scaled integer as a person reads it — `3,5 m`, never `3500` — with
|
|
11
|
+
* tabular figures and its unit kept on the same line. Server-safe.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ScaledValue({ value, scale, unit, locale }: ScaledValueProps): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=scaled-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaled-value.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/scaled/scaled-value.tsx"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB,+BAO3E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { formatScaled } from '@entifix/core';
|
|
3
|
+
/**
|
|
4
|
+
* A scaled integer as a person reads it — `3,5 m`, never `3500` — with
|
|
5
|
+
* tabular figures and its unit kept on the same line. Server-safe.
|
|
6
|
+
*/ export function ScaledValue({ value, scale, unit, locale }) {
|
|
7
|
+
const number = formatScaled(value, scale, locale);
|
|
8
|
+
return /*#__PURE__*/ _jsx("span", {
|
|
9
|
+
className: "whitespace-nowrap tabular-nums",
|
|
10
|
+
children: unit === undefined ? number : `${number}\u00a0${unit}`
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=scaled-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/scaled/scaled-value.tsx"],"sourcesContent":["import { formatScaled } from '@entifix/core';\n\nexport interface ScaledValueProps {\n /** The stored integer. */\n value: number;\n scale: number;\n /** The unit as the reader names it. */\n unit?: string;\n locale: string;\n}\n\n/**\n * A scaled integer as a person reads it — `3,5 m`, never `3500` — with\n * tabular figures and its unit kept on the same line. Server-safe.\n */\nexport function ScaledValue({ value, scale, unit, locale }: ScaledValueProps) {\n const number = formatScaled(value, scale, locale);\n return (\n <span className=\"whitespace-nowrap tabular-nums\">\n {unit === undefined ? number : `${number}\\u00a0${unit}`}\n </span>\n );\n}\n"],"names":["formatScaled","ScaledValue","value","scale","unit","locale","number","span","className","undefined"],"mappings":";AAAA,SAASA,YAAY,QAAQ,gBAAgB;AAW7C;;;CAGC,GACD,OAAO,SAASC,YAAY,EAAEC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAoB;IAC1E,MAAMC,SAASN,aAAaE,OAAOC,OAAOE;IAC1C,qBACE,KAACE;QAAKC,WAAU;kBACbJ,SAASK,YAAYH,SAAS,GAAGA,OAAO,MAAM,EAAEF,MAAM;;AAG7D"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ScaledFormat } from '@entifix/core';
|
|
2
|
+
/** A unit in the reader's words, or its code when the host declared none. */
|
|
3
|
+
export declare function useUnitLabel(): (scaled: ScaledFormat, unit: string | undefined) => string | undefined;
|
|
4
|
+
//# sourceMappingURL=use-unit-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-unit-label.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/scaled/use-unit-label.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKlD,6EAA6E;AAC7E,wBAAgB,YAAY,IAAI,CAC9B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,GAAG,SAAS,KACrB,MAAM,GAAG,SAAS,CAStB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useTranslateKey } from '../../../i18n/index.js';
|
|
4
|
+
/** A unit in the reader's words, or its code when the host declared none. */ export function useUnitLabel() {
|
|
5
|
+
const translate = useTranslateKey();
|
|
6
|
+
return useCallback((scaled, unit)=>unit === undefined || scaled.unitLabelKey === undefined ? unit : translate(`${scaled.unitLabelKey}.${unit}`), [
|
|
7
|
+
translate
|
|
8
|
+
]);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=use-unit-label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/scaled/use-unit-label.ts"],"sourcesContent":["'use client';\n\nimport type { ScaledFormat } from '@entifix/core';\nimport { useCallback } from 'react';\n\nimport { useTranslateKey } from '../../../i18n/index.js';\n\n/** A unit in the reader's words, or its code when the host declared none. */\nexport function useUnitLabel(): (\n scaled: ScaledFormat,\n unit: string | undefined,\n) => string | undefined {\n const translate = useTranslateKey();\n return useCallback(\n (scaled, unit) =>\n unit === undefined || scaled.unitLabelKey === undefined\n ? unit\n : translate(`${scaled.unitLabelKey}.${unit}`),\n [translate],\n );\n}\n"],"names":["useCallback","useTranslateKey","useUnitLabel","translate","scaled","unit","undefined","unitLabelKey"],"mappings":"AAAA;AAGA,SAASA,WAAW,QAAQ,QAAQ;AAEpC,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,2EAA2E,GAC3E,OAAO,SAASC;IAId,MAAMC,YAAYF;IAClB,OAAOD,YACL,CAACI,QAAQC,OACPA,SAASC,aAAaF,OAAOG,YAAY,KAAKD,YAC1CD,OACAF,UAAU,GAAGC,OAAOG,YAAY,CAAC,CAAC,EAAEF,MAAM,GAChD;QAACF;KAAU;AAEf"}
|