@entifix/react-controls 0.23.6 → 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 +2 -1
- package/dist/i18n/catalog/en.js.map +1 -1
- package/dist/i18n/catalog/es.d.ts +1 -0
- package/dist/i18n/catalog/es.d.ts.map +1 -1
- package/dist/i18n/catalog/es.js +2 -1
- package/dist/i18n/catalog/es.js.map +1 -1
- package/dist/i18n/catalog/index.d.ts +2 -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/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
|
@@ -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;A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AAI,CAAC,OACR5C,QAAQmB;gBAEd0B,iBAAehB,QAAQlD;gBACvBmE,iBAAelE,QAAQuC,YAAYA,YAAYU,QAAQjD;gBACvDmE,gBAAc/D,WAAWkC,WAAWC;gBACpC6B,oBACE;oBAAC3D;oBAAaN,SAASoC,YAAYA,YAAY3B;iBAAO,CACnDkD,MAAM,CAACC,SACPC,IAAI,CAAC,QAAQzB;gBAElBlC,UAAUA;gBACVV,OAAOyB;gBACPtB,UAAU2C,CAAAA;wBAGDzD;oBAFP,MAAM2C,OAAOc,MAAM4B,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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CACnD0B,MAAM,CAACC,SACPC,IAAI,CAAC,QAAQzB;gBAElB0B,WAAWpC,UAAU,IAAI,YAAY;gBACrCF,OAAOsB;gBACPrB,UAAUsC,CAAAA;oBACR,MAAMV,OAAOU,MAAMC,aAAa,CAACxC,KAAK;oBACtCuB,QAAQM;oBACRH,SAAS;oBACT,kEAAkE;oBAClE,MAAMf,SAASM,SAASY,MAAM3B;oBAC9BuB,WAAWd;oBACXV,SAASU;gBACX;;YAEDoB,SAASnB,2BACR,KAACoB;gBAAKS,IAAIhC;gBAAQwB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-detail-grid.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-detail-grid/entity-detail-grid.tsx"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAK3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,OAAe,EACf,SAAiB,EACjB,QAAe,EACf,MAAM,EACN,SAAS,GACV,EAAE,qBAAqB,+
|
|
1
|
+
{"version":3,"file":"entity-detail-grid.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-detail-grid/entity-detail-grid.tsx"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAK3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,OAAe,EACf,SAAiB,EACjB,QAAe,EACf,MAAM,EACN,SAAS,GACV,EAAE,qBAAqB,+BA6MvB"}
|
|
@@ -182,7 +182,7 @@ import { cn } from '../../utils/cn.js';
|
|
|
182
182
|
"aria-describedby": error === undefined ? undefined : `${cellId}-error`,
|
|
183
183
|
onChange: (next)=>setRow(index, column.name, next),
|
|
184
184
|
record: row
|
|
185
|
-
}) : column.money === undefined ? /*#__PURE__*/ _jsx("span", {
|
|
185
|
+
}) : column.money === undefined && column.scaled === undefined ? /*#__PURE__*/ _jsx("span", {
|
|
186
186
|
children: (_row_column_name1 = row[column.name]) != null ? _row_column_name1 : ''
|
|
187
187
|
}) : /*#__PURE__*/ _jsx(CellValue, {
|
|
188
188
|
value: row[column.name],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/organisms/entity-detail-grid/entity-detail-grid.tsx"],"sourcesContent":["'use client';\n\nimport {\n describeChildColumns,\n editableChildColumns,\n type EntityFieldDescriptor,\n type EntityRowDraft,\n newRowKey,\n parseRowFieldPath,\n ROW_KEY,\n rowFieldPath,\n} from '@entifix/core';\nimport { type KeyboardEvent, useId, useMemo } from 'react';\n\nimport { useLocalizedDescriptors, useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { FieldControl } from '../../atoms/field-control/index.js';\nimport { Skeleton } from '../../atoms/skeleton/index.js';\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeaderCell,\n TableMessageRow,\n TableRow,\n} from '../../atoms/table/index.js';\nimport { Stack } from '../../molecules/stack/index.js';\nimport { cn } from '../../utils/cn.js';\nimport type { EntityDetailGridProps } from './entity-detail-grid.types.js';\n\n/** Rows the placeholder stands in for. Enough to read as a grid, not a page. */\nconst SKELETON_ROW_COUNT = 3;\n\n/**\n * The rows a record **owns**, edited in place.\n *\n * A `composition` — an order and its lines — where the rows have no life outside\n * the master and go out in the same write\n *. Not\n * a `linkCollection`, which is association to records that exist on their own\n * and save separately; that editor is still #26.\n *\n * ## Why this is not `EntityTable`\n *\n * `EntityTable` is a *server* listing: pages, RSQL filtering and sorting,\n * column personalization, a selection model and a bulk bar. A detail grid has\n * none of those and cannot have them — its rows are local, unsaved, and\n * unqueryable by construction, since a collection member is never `filterable`.\n * Sharing the organism would mean every one of those features growing a\n * \"detail\" branch. It shares the `Table` **atoms** instead, which is the level\n * the two actually have in common.\n *\n * ## Inline cells, and why Enter is free\n *\n * Each cell is a {@link FieldControl}, the same descriptor→input map the form\n * uses, so a child's `enum` gets a select and its `date` a date input with no\n * code here. `Tab` walks the row natively and crosses into the next; `Enter` on\n * the last row appends and focuses the new row's first cell.\n *\n * That last binding is available only because `EntityForm` renders a `<Card>`\n * with a `<button onClick>` Save rather than a `<form>` — inside a real form,\n * `Enter` in a text input submits, and appending a row would fight the browser\n * for it. Wrapping the form in a `<form>` element later would break this, which\n * is the one thing worth knowing before doing it.\n *\n * ## Errors\n *\n * A cell carries `aria-invalid` and points at its own message; the grid carries\n * **one** summary above it, which is the only `role=\"alert\"` in the component.\n * A live region per cell would announce the whole grid on every keystroke, and\n * a message rendered only in the cell is unreachable when the failing row is\n * scrolled out — the case a long grid always meets.\n */\nexport function EntityDetailGrid({\n descriptor,\n rows,\n onRowsChange,\n errors,\n editing = false,\n isLoading = false,\n skeleton = true,\n footer,\n className,\n}: EntityDetailGridProps) {\n const t = useT();\n const gridId = useId();\n\n const described = useMemo(\n () =>\n descriptor.childType === undefined\n ? []\n : editableChildColumns(describeChildColumns(descriptor.childType)),\n [descriptor.childType],\n );\n const columns = useLocalizedDescriptors(described);\n\n // Only the messages that name *this* member. The form hands over its whole\n // error map so a record with two owned collections needs no bookkeeping at\n // the call site, and a grid that filtered nothing would show the other's.\n const rowErrors = useMemo(\n () => readRowErrors(descriptor.name, errors),\n [descriptor.name, errors],\n );\n\n const showSkeleton = isLoading && skeleton !== false;\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n // One more than the columns: every row carries its remove control.\n const columnCount = columns.length + (editing ? 1 : 0);\n\n const setRow = (index: number, member: string, value: string) => {\n onRowsChange(\n rows.map((row, position) =>\n position === index ? { ...row, [member]: value } : row,\n ),\n );\n };\n\n const firstColumn = columns[0]?.name;\n\n const appendRow = () => {\n onRowsChange([...rows, seedEmptyRow(columns)]);\n focusCell(gridId, rows.length, firstColumn);\n };\n\n const removeRow = (index: number) => {\n onRowsChange(rows.filter((_row, position) => position !== index));\n // Focus the row that slid into this position, or the one above it when the\n // removed row was last — never nothing, which drops the user to the page.\n focusCell(gridId, Math.min(index, rows.length - 2), firstColumn);\n };\n\n /**\n * `Enter` anywhere in the **last row** appends the next one.\n *\n * Bound to the row rather than to its final cell, which is what it looked\n * like it should be: the last *column* is whatever the child declared last,\n * and a read-only member there renders a disabled input that never receives a\n * key at all — so the binding would exist and be unreachable, on exactly the\n * entities that have a computed column. The row is the unit the user is\n * finishing anyway.\n *\n * Only from a text input: a `<select>` opens on Enter and a checkbox toggles\n * on Space, so taking the key from those would break a control's own\n * behaviour to add a row the user did not ask for. A read-only column needs\n * no test of its own — its input is `disabled`, so it never takes focus and\n * never raises a key here at all.\n */\n const onLastRowKeyDown = (event: KeyboardEvent<HTMLTableRowElement>) => {\n if (event.key !== 'Enter') return;\n if (!(event.target instanceof HTMLInputElement)) return;\n event.preventDefault();\n appendRow();\n };\n\n return (\n <Stack gap=\"2xs\" className={className}>\n <div className=\"flex items-center justify-between gap-s\">\n <span className=\"text-step-sm font-medium text-content-muted\">\n {descriptor.label}\n </span>\n {editing && (\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n onClick={appendRow}\n disabled={isLoading}\n >\n {t('detail.addRow')}\n </Button>\n )}\n </div>\n\n {editing && rowErrors.size > 0 && (\n <div role=\"alert\" className=\"text-step-sm text-danger\">\n {t('detail.errorSummary', { count: rowErrors.size })}\n </div>\n )}\n\n <Table aria-label={descriptor.label} aria-busy={isLoading || undefined}>\n <TableHead>\n <TableRow>\n {columns.map(column => (\n <TableHeaderCell\n key={column.name}\n id={`${gridId}-${column.name}`}\n >\n {column.label}\n </TableHeaderCell>\n ))}\n {editing && (\n <TableHeaderCell align=\"end\">\n <span className=\"sr-only\">{t('detail.rowActions')}</span>\n </TableHeaderCell>\n )}\n </TableRow>\n </TableHead>\n\n <TableBody>\n {showSkeleton\n ? (customSkeleton ?? (\n <SkeletonRows\n columns={columns.length}\n extra={editing ? 1 : 0}\n />\n ))\n : rows.map((row, index) => (\n <TableRow\n key={row[ROW_KEY]}\n onKeyDown={\n editing && index === rows.length - 1\n ? onLastRowKeyDown\n : undefined\n }\n >\n {columns.map(column => {\n const error = rowErrors.get(\n rowFieldPath(descriptor.name, index, column.name),\n );\n const cellId = `${gridId}-${index}-${column.name}`;\n return (\n <TableCell key={column.name}>\n {editing ? (\n <FieldControl\n descriptor={column}\n value={row[column.name] ?? ''}\n id={cellId}\n aria-labelledby={`${gridId}-${column.name}`}\n aria-invalid={error !== undefined || undefined}\n aria-describedby={\n error === undefined\n ? undefined\n : `${cellId}-error`\n }\n onChange={next => setRow(index, column.name, next)}\n record={row}\n />\n ) : column.money === undefined ? (\n <span>{row[column.name] ?? ''}</span>\n ) : (\n <CellValue\n value={row[column.name]}\n descriptor={column}\n record={row}\n />\n )}\n {editing && error !== undefined && (\n <span\n id={`${cellId}-error`}\n className=\"mt-3xs block text-step-sm text-danger\"\n >\n {error}\n </span>\n )}\n </TableCell>\n );\n })}\n {editing && (\n <TableCell align=\"end\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => removeRow(index)}\n >\n {t('detail.removeRow', { row: index + 1 })}\n </Button>\n </TableCell>\n )}\n </TableRow>\n ))}\n\n {!showSkeleton && rows.length === 0 && (\n <TableMessageRow colSpan={Math.max(columnCount, 1)}>\n {t('detail.empty')}\n </TableMessageRow>\n )}\n </TableBody>\n </Table>\n\n {footer !== undefined && !showSkeleton && (\n <div className={cn('flex justify-end text-step-sm text-content')}>\n {footer(rows)}\n </div>\n )}\n </Stack>\n );\n}\n\n/** The placeholder, shaped like the grid it stands in for. */\nfunction SkeletonRows({ columns, extra }: { columns: number; extra: number }) {\n return (\n <>\n {Array.from({ length: SKELETON_ROW_COUNT }, (_row, index) => (\n <TableRow key={index}>\n {Array.from({ length: columns + extra }, (_cell, cellIndex) => (\n <TableCell key={cellIndex}>\n <Skeleton className=\"h-8 w-full\" />\n </TableCell>\n ))}\n </TableRow>\n ))}\n </>\n );\n}\n\n/**\n * A blank row, seeded with every column the grid edits.\n *\n * Every member is present and empty rather than absent, for the reason a form's\n * seed carries every key: a control handed `undefined` flips from controlled to\n * uncontrolled the moment the user types into it.\n */\nfunction seedEmptyRow(\n columns: readonly EntityFieldDescriptor[],\n): EntityRowDraft {\n const row: EntityRowDraft = { [ROW_KEY]: newRowKey() };\n for (const column of columns) row[column.name] = '';\n return row;\n}\n\n/**\n * Moves focus into a cell after the list changed.\n *\n * By element id rather than through a ref into the `<tbody>`, because the row\n * being focused does not exist yet when this is called — it is the row the\n * caller has just asked React to render. Deferring to a microtask lets that\n * render commit first; `getElementById` then finds the input the same way the\n * cell's own `aria-describedby` does.\n *\n * A row index that names nothing simply focuses nothing, which is the right\n * outcome for removing the only row: there is no cell to land in, and stealing\n * focus somewhere arbitrary is worse than leaving it where the user put it.\n */\nfunction focusCell(gridId: string, index: number, column?: string): void {\n if (column === undefined || index < 0) return;\n\n queueMicrotask(() => {\n document.getElementById(`${gridId}-${index}-${column}`)?.focus();\n });\n}\n\n/** The messages naming a row of `member`, keyed by their full path. */\nfunction readRowErrors(\n member: string,\n errors: Record<string, string> | undefined,\n): Map<string, string> {\n const found = new Map<string, string>();\n if (errors === undefined) return found;\n\n for (const [path, message] of Object.entries(errors)) {\n if (parseRowFieldPath(path)?.member === member) found.set(path, message);\n }\n return found;\n}\n"],"names":["describeChildColumns","editableChildColumns","newRowKey","parseRowFieldPath","ROW_KEY","rowFieldPath","useId","useMemo","useLocalizedDescriptors","useT","Button","CellValue","FieldControl","Skeleton","Table","TableBody","TableCell","TableHead","TableHeaderCell","TableMessageRow","TableRow","Stack","cn","SKELETON_ROW_COUNT","EntityDetailGrid","descriptor","rows","onRowsChange","errors","editing","isLoading","skeleton","footer","className","columns","t","gridId","described","childType","undefined","rowErrors","readRowErrors","name","showSkeleton","customSkeleton","columnCount","length","setRow","index","member","value","map","row","position","firstColumn","appendRow","seedEmptyRow","focusCell","removeRow","filter","_row","Math","min","onLastRowKeyDown","event","key","target","HTMLInputElement","preventDefault","gap","div","span","label","type","variant","size","onClick","disabled","role","count","aria-label","aria-busy","column","id","align","SkeletonRows","extra","onKeyDown","error","get","cellId","aria-labelledby","aria-invalid","aria-describedby","onChange","next","record","money","colSpan","max","Array","from","_cell","cellIndex","queueMicrotask","document","getElementById","focus","found","Map","path","message","Object","entries","set"],"mappings":"AAAA;;;AAEA,SACEA,oBAAoB,EACpBC,oBAAoB,EAGpBC,SAAS,EACTC,iBAAiB,EACjBC,OAAO,EACPC,YAAY,QACP,gBAAgB;AACvB,SAA6BC,KAAK,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,uBAAuB,EAAEC,IAAI,QAAQ,yBAAyB;AACvE,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,YAAY,QAAQ,qCAAqC;AAClE,SAASC,QAAQ,QAAQ,gCAAgC;AACzD,SACEC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,QAAQ,QACH,6BAA6B;AACpC,SAASC,KAAK,QAAQ,iCAAiC;AACvD,SAASC,EAAE,QAAQ,oBAAoB;AAGvC,8EAA8E,GAC9E,MAAMC,qBAAqB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCC,GACD,OAAO,SAASC,iBAAiB,EAC/BC,UAAU,EACVC,IAAI,EACJC,YAAY,EACZC,MAAM,EACNC,UAAU,KAAK,EACfC,YAAY,KAAK,EACjBC,WAAW,IAAI,EACfC,MAAM,EACNC,SAAS,EACa;QAkCFC;IAjCpB,MAAMC,IAAI1B;IACV,MAAM2B,SAAS9B;IAEf,MAAM+B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S2D,aAAa,EAAEnD,OAAO,EAAEoD,KAAK,EAAsC;IAC1E,qBACE;kBACGc,MAAMC,IAAI,CAAC;YAAEvD,QAAQvB;QAAmB,GAAG,CAACqC,MAAMZ,sBACjD,KAAC5B;0BACEgF,MAAMC,IAAI,CAAC;oBAAEvD,QAAQZ,UAAUoD;gBAAM,GAAG,CAACgB,OAAOC,0BAC/C,KAACvF;kCACC,cAAA,KAACH;4BAASoB,WAAU;;uBADNsE;eAFLvD;;AAUvB;AAEA;;;;;;CAMC,GACD,SAASQ,aACPtB,OAAyC;IAEzC,MAAMkB,MAAsB;QAAE,CAAChD,QAAQ,EAAEF;IAAY;IACrD,KAAK,MAAMgF,UAAUhD,QAASkB,GAAG,CAAC8B,OAAOxC,IAAI,CAAC,GAAG;IACjD,OAAOU;AACT;AAEA;;;;;;;;;;;;CAYC,GACD,SAASK,UAAUrB,MAAc,EAAEY,KAAa,EAAEkC,MAAe;IAC/D,IAAIA,WAAW3C,aAAaS,QAAQ,GAAG;IAEvCwD,eAAe;YACbC;SAAAA,2BAAAA,SAASC,cAAc,CAAC,GAAGtE,OAAO,CAAC,EAAEY,MAAM,CAAC,EAAEkC,QAAQ,sBAAtDuB,yBAAyDE,KAAK;IAChE;AACF;AAEA,qEAAqE,GACrE,SAASlE,cACPQ,MAAc,EACdrB,MAA0C;IAE1C,MAAMgF,QAAQ,IAAIC;IAClB,IAAIjF,WAAWW,WAAW,OAAOqE;IAEjC,KAAK,MAAM,CAACE,MAAMC,QAAQ,IAAIC,OAAOC,OAAO,CAACrF,QAAS;YAChDzB;QAAJ,IAAIA,EAAAA,qBAAAA,kBAAkB2G,0BAAlB3G,mBAAyB8C,MAAM,MAAKA,QAAQ2D,MAAMM,GAAG,CAACJ,MAAMC;IAClE;IACA,OAAOH;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/organisms/entity-detail-grid/entity-detail-grid.tsx"],"sourcesContent":["'use client';\n\nimport {\n describeChildColumns,\n editableChildColumns,\n type EntityFieldDescriptor,\n type EntityRowDraft,\n newRowKey,\n parseRowFieldPath,\n ROW_KEY,\n rowFieldPath,\n} from '@entifix/core';\nimport { type KeyboardEvent, useId, useMemo } from 'react';\n\nimport { useLocalizedDescriptors, useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { FieldControl } from '../../atoms/field-control/index.js';\nimport { Skeleton } from '../../atoms/skeleton/index.js';\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeaderCell,\n TableMessageRow,\n TableRow,\n} from '../../atoms/table/index.js';\nimport { Stack } from '../../molecules/stack/index.js';\nimport { cn } from '../../utils/cn.js';\nimport type { EntityDetailGridProps } from './entity-detail-grid.types.js';\n\n/** Rows the placeholder stands in for. Enough to read as a grid, not a page. */\nconst SKELETON_ROW_COUNT = 3;\n\n/**\n * The rows a record **owns**, edited in place.\n *\n * A `composition` — an order and its lines — where the rows have no life outside\n * the master and go out in the same write\n *. Not\n * a `linkCollection`, which is association to records that exist on their own\n * and save separately; that editor is still #26.\n *\n * ## Why this is not `EntityTable`\n *\n * `EntityTable` is a *server* listing: pages, RSQL filtering and sorting,\n * column personalization, a selection model and a bulk bar. A detail grid has\n * none of those and cannot have them — its rows are local, unsaved, and\n * unqueryable by construction, since a collection member is never `filterable`.\n * Sharing the organism would mean every one of those features growing a\n * \"detail\" branch. It shares the `Table` **atoms** instead, which is the level\n * the two actually have in common.\n *\n * ## Inline cells, and why Enter is free\n *\n * Each cell is a {@link FieldControl}, the same descriptor→input map the form\n * uses, so a child's `enum` gets a select and its `date` a date input with no\n * code here. `Tab` walks the row natively and crosses into the next; `Enter` on\n * the last row appends and focuses the new row's first cell.\n *\n * That last binding is available only because `EntityForm` renders a `<Card>`\n * with a `<button onClick>` Save rather than a `<form>` — inside a real form,\n * `Enter` in a text input submits, and appending a row would fight the browser\n * for it. Wrapping the form in a `<form>` element later would break this, which\n * is the one thing worth knowing before doing it.\n *\n * ## Errors\n *\n * A cell carries `aria-invalid` and points at its own message; the grid carries\n * **one** summary above it, which is the only `role=\"alert\"` in the component.\n * A live region per cell would announce the whole grid on every keystroke, and\n * a message rendered only in the cell is unreachable when the failing row is\n * scrolled out — the case a long grid always meets.\n */\nexport function EntityDetailGrid({\n descriptor,\n rows,\n onRowsChange,\n errors,\n editing = false,\n isLoading = false,\n skeleton = true,\n footer,\n className,\n}: EntityDetailGridProps) {\n const t = useT();\n const gridId = useId();\n\n const described = useMemo(\n () =>\n descriptor.childType === undefined\n ? []\n : editableChildColumns(describeChildColumns(descriptor.childType)),\n [descriptor.childType],\n );\n const columns = useLocalizedDescriptors(described);\n\n // Only the messages that name *this* member. The form hands over its whole\n // error map so a record with two owned collections needs no bookkeeping at\n // the call site, and a grid that filtered nothing would show the other's.\n const rowErrors = useMemo(\n () => readRowErrors(descriptor.name, errors),\n [descriptor.name, errors],\n );\n\n const showSkeleton = isLoading && skeleton !== false;\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n // One more than the columns: every row carries its remove control.\n const columnCount = columns.length + (editing ? 1 : 0);\n\n const setRow = (index: number, member: string, value: string) => {\n onRowsChange(\n rows.map((row, position) =>\n position === index ? { ...row, [member]: value } : row,\n ),\n );\n };\n\n const firstColumn = columns[0]?.name;\n\n const appendRow = () => {\n onRowsChange([...rows, seedEmptyRow(columns)]);\n focusCell(gridId, rows.length, firstColumn);\n };\n\n const removeRow = (index: number) => {\n onRowsChange(rows.filter((_row, position) => position !== index));\n // Focus the row that slid into this position, or the one above it when the\n // removed row was last — never nothing, which drops the user to the page.\n focusCell(gridId, Math.min(index, rows.length - 2), firstColumn);\n };\n\n /**\n * `Enter` anywhere in the **last row** appends the next one.\n *\n * Bound to the row rather than to its final cell, which is what it looked\n * like it should be: the last *column* is whatever the child declared last,\n * and a read-only member there renders a disabled input that never receives a\n * key at all — so the binding would exist and be unreachable, on exactly the\n * entities that have a computed column. The row is the unit the user is\n * finishing anyway.\n *\n * Only from a text input: a `<select>` opens on Enter and a checkbox toggles\n * on Space, so taking the key from those would break a control's own\n * behaviour to add a row the user did not ask for. A read-only column needs\n * no test of its own — its input is `disabled`, so it never takes focus and\n * never raises a key here at all.\n */\n const onLastRowKeyDown = (event: KeyboardEvent<HTMLTableRowElement>) => {\n if (event.key !== 'Enter') return;\n if (!(event.target instanceof HTMLInputElement)) return;\n event.preventDefault();\n appendRow();\n };\n\n return (\n <Stack gap=\"2xs\" className={className}>\n <div className=\"flex items-center justify-between gap-s\">\n <span className=\"text-step-sm font-medium text-content-muted\">\n {descriptor.label}\n </span>\n {editing && (\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n onClick={appendRow}\n disabled={isLoading}\n >\n {t('detail.addRow')}\n </Button>\n )}\n </div>\n\n {editing && rowErrors.size > 0 && (\n <div role=\"alert\" className=\"text-step-sm text-danger\">\n {t('detail.errorSummary', { count: rowErrors.size })}\n </div>\n )}\n\n <Table aria-label={descriptor.label} aria-busy={isLoading || undefined}>\n <TableHead>\n <TableRow>\n {columns.map(column => (\n <TableHeaderCell\n key={column.name}\n id={`${gridId}-${column.name}`}\n >\n {column.label}\n </TableHeaderCell>\n ))}\n {editing && (\n <TableHeaderCell align=\"end\">\n <span className=\"sr-only\">{t('detail.rowActions')}</span>\n </TableHeaderCell>\n )}\n </TableRow>\n </TableHead>\n\n <TableBody>\n {showSkeleton\n ? (customSkeleton ?? (\n <SkeletonRows\n columns={columns.length}\n extra={editing ? 1 : 0}\n />\n ))\n : rows.map((row, index) => (\n <TableRow\n key={row[ROW_KEY]}\n onKeyDown={\n editing && index === rows.length - 1\n ? onLastRowKeyDown\n : undefined\n }\n >\n {columns.map(column => {\n const error = rowErrors.get(\n rowFieldPath(descriptor.name, index, column.name),\n );\n const cellId = `${gridId}-${index}-${column.name}`;\n return (\n <TableCell key={column.name}>\n {editing ? (\n <FieldControl\n descriptor={column}\n value={row[column.name] ?? ''}\n id={cellId}\n aria-labelledby={`${gridId}-${column.name}`}\n aria-invalid={error !== undefined || undefined}\n aria-describedby={\n error === undefined\n ? undefined\n : `${cellId}-error`\n }\n onChange={next => setRow(index, column.name, next)}\n record={row}\n />\n ) : column.money === undefined &&\n column.scaled === undefined ? (\n <span>{row[column.name] ?? ''}</span>\n ) : (\n <CellValue\n value={row[column.name]}\n descriptor={column}\n record={row}\n />\n )}\n {editing && error !== undefined && (\n <span\n id={`${cellId}-error`}\n className=\"mt-3xs block text-step-sm text-danger\"\n >\n {error}\n </span>\n )}\n </TableCell>\n );\n })}\n {editing && (\n <TableCell align=\"end\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => removeRow(index)}\n >\n {t('detail.removeRow', { row: index + 1 })}\n </Button>\n </TableCell>\n )}\n </TableRow>\n ))}\n\n {!showSkeleton && rows.length === 0 && (\n <TableMessageRow colSpan={Math.max(columnCount, 1)}>\n {t('detail.empty')}\n </TableMessageRow>\n )}\n </TableBody>\n </Table>\n\n {footer !== undefined && !showSkeleton && (\n <div className={cn('flex justify-end text-step-sm text-content')}>\n {footer(rows)}\n </div>\n )}\n </Stack>\n );\n}\n\n/** The placeholder, shaped like the grid it stands in for. */\nfunction SkeletonRows({ columns, extra }: { columns: number; extra: number }) {\n return (\n <>\n {Array.from({ length: SKELETON_ROW_COUNT }, (_row, index) => (\n <TableRow key={index}>\n {Array.from({ length: columns + extra }, (_cell, cellIndex) => (\n <TableCell key={cellIndex}>\n <Skeleton className=\"h-8 w-full\" />\n </TableCell>\n ))}\n </TableRow>\n ))}\n </>\n );\n}\n\n/**\n * A blank row, seeded with every column the grid edits.\n *\n * Every member is present and empty rather than absent, for the reason a form's\n * seed carries every key: a control handed `undefined` flips from controlled to\n * uncontrolled the moment the user types into it.\n */\nfunction seedEmptyRow(\n columns: readonly EntityFieldDescriptor[],\n): EntityRowDraft {\n const row: EntityRowDraft = { [ROW_KEY]: newRowKey() };\n for (const column of columns) row[column.name] = '';\n return row;\n}\n\n/**\n * Moves focus into a cell after the list changed.\n *\n * By element id rather than through a ref into the `<tbody>`, because the row\n * being focused does not exist yet when this is called — it is the row the\n * caller has just asked React to render. Deferring to a microtask lets that\n * render commit first; `getElementById` then finds the input the same way the\n * cell's own `aria-describedby` does.\n *\n * A row index that names nothing simply focuses nothing, which is the right\n * outcome for removing the only row: there is no cell to land in, and stealing\n * focus somewhere arbitrary is worse than leaving it where the user put it.\n */\nfunction focusCell(gridId: string, index: number, column?: string): void {\n if (column === undefined || index < 0) return;\n\n queueMicrotask(() => {\n document.getElementById(`${gridId}-${index}-${column}`)?.focus();\n });\n}\n\n/** The messages naming a row of `member`, keyed by their full path. */\nfunction readRowErrors(\n member: string,\n errors: Record<string, string> | undefined,\n): Map<string, string> {\n const found = new Map<string, string>();\n if (errors === undefined) return found;\n\n for (const [path, message] of Object.entries(errors)) {\n if (parseRowFieldPath(path)?.member === member) found.set(path, message);\n }\n return found;\n}\n"],"names":["describeChildColumns","editableChildColumns","newRowKey","parseRowFieldPath","ROW_KEY","rowFieldPath","useId","useMemo","useLocalizedDescriptors","useT","Button","CellValue","FieldControl","Skeleton","Table","TableBody","TableCell","TableHead","TableHeaderCell","TableMessageRow","TableRow","Stack","cn","SKELETON_ROW_COUNT","EntityDetailGrid","descriptor","rows","onRowsChange","errors","editing","isLoading","skeleton","footer","className","columns","t","gridId","described","childType","undefined","rowErrors","readRowErrors","name","showSkeleton","customSkeleton","columnCount","length","setRow","index","member","value","map","row","position","firstColumn","appendRow","seedEmptyRow","focusCell","removeRow","filter","_row","Math","min","onLastRowKeyDown","event","key","target","HTMLInputElement","preventDefault","gap","div","span","label","type","variant","size","onClick","disabled","role","count","aria-label","aria-busy","column","id","align","SkeletonRows","extra","onKeyDown","error","get","cellId","aria-labelledby","aria-invalid","aria-describedby","onChange","next","record","money","scaled","colSpan","max","Array","from","_cell","cellIndex","queueMicrotask","document","getElementById","focus","found","Map","path","message","Object","entries","set"],"mappings":"AAAA;;;AAEA,SACEA,oBAAoB,EACpBC,oBAAoB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AAY;IACrD,KAAK,MAAMgF,UAAUhD,QAASkB,GAAG,CAAC8B,OAAOxC,IAAI,CAAC,GAAG;IACjD,OAAOU;AACT;AAEA;;;;;;;;;;;;CAYC,GACD,SAASK,UAAUrB,MAAc,EAAEY,KAAa,EAAEkC,MAAe;IAC/D,IAAIA,WAAW3C,aAAaS,QAAQ,GAAG;IAEvCyD,eAAe;YACbC;SAAAA,2BAAAA,SAASC,cAAc,CAAC,GAAGvE,OAAO,CAAC,EAAEY,MAAM,CAAC,EAAEkC,QAAQ,sBAAtDwB,yBAAyDE,KAAK;IAChE;AACF;AAEA,qEAAqE,GACrE,SAASnE,cACPQ,MAAc,EACdrB,MAA0C;IAE1C,MAAMiF,QAAQ,IAAIC;IAClB,IAAIlF,WAAWW,WAAW,OAAOsE;IAEjC,KAAK,MAAM,CAACE,MAAMC,QAAQ,IAAIC,OAAOC,OAAO,CAACtF,QAAS;YAChDzB;QAAJ,IAAIA,EAAAA,qBAAAA,kBAAkB4G,0BAAlB5G,mBAAyB8C,MAAM,MAAKA,QAAQ4D,MAAMM,GAAG,CAACJ,MAAMC;IAClE;IACA,OAAOH;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entity, MetaAccessorType, MoneyFormat } from '@entifix/core';
|
|
1
|
+
import type { Entity, MetaAccessorType, MoneyFormat, ScaledFormat } from '@entifix/core';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import type { EntityTableColumn } from './entity-table.types.js';
|
|
4
4
|
/**
|
|
@@ -21,6 +21,11 @@ export interface EntityColumnProps<TEntity extends Entity = Entity> {
|
|
|
21
21
|
* the stored number. A computed column has no accessor to declare it on.
|
|
22
22
|
*/
|
|
23
23
|
money?: MoneyFormat;
|
|
24
|
+
/**
|
|
25
|
+
* The column holds a scaled integer: printed as the decimal it stands for,
|
|
26
|
+
* beside its unit. A computed column has no accessor to declare it on.
|
|
27
|
+
*/
|
|
28
|
+
scaled?: ScaledFormat;
|
|
24
29
|
order?: number;
|
|
25
30
|
sortable?: boolean;
|
|
26
31
|
filterable?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-table-slots.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-table/entity-table-slots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"entity-table-slots.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-table/entity-table-slots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;;GAMG;AAEH,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IAChE,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC;CACvC;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC1D,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,SAAS,CAEX;AAED,MAAM,WAAW,sB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|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/entity-table-slots.tsx"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/entity-table-slots.tsx"],"sourcesContent":["import type {\n Entity,\n MetaAccessorType,\n MoneyFormat,\n ScaledFormat,\n} from '@entifix/core';\nimport { Children, isValidElement, type ReactNode } from 'react';\n\nimport type { EntityTableColumn } from './entity-table.types.js';\n\n/**\n * The declarative customization API. Slots are configuration expressed as JSX:\n * they never render themselves — `EntityTable` reads their props and decides\n * where the configuration applies. That keeps simple tables to a single\n * self-closing tag while complex ones stay declarative instead of drowning in\n * option objects.\n */\n\nexport interface EntityColumnProps<TEntity extends Entity = Entity> {\n /** Accessor name. Unknown names create an extra, entity-less column. */\n field: string;\n label?: string;\n header?: ReactNode;\n type?: MetaAccessorType;\n /** The narrowest the column reads at, in `rem` — what the pivot counts it as. */\n minWidth?: number;\n /**\n * The column holds an amount: printed as `Money` in its currency, never as\n * the stored number. A computed column has no accessor to declare it on.\n */\n money?: MoneyFormat;\n /**\n * The column holds a scaled integer: printed as the decimal it stands for,\n * beside its unit. A computed column has no accessor to declare it on.\n */\n scaled?: ScaledFormat;\n order?: number;\n sortable?: boolean;\n filterable?: boolean;\n render?: (item: TEntity) => ReactNode;\n}\n\n/** Overrides one metadata-derived column, or adds a computed one. */\nexport function EntityColumn<TEntity extends Entity = Entity>(\n _props: EntityColumnProps<TEntity>,\n): ReactNode {\n return null;\n}\n\nexport interface EntityTableHeaderProps<TEntity extends Entity = Entity> {\n /** Replaces the whole header row. Receives the resolved visible columns. */\n render: (columns: Array<EntityTableColumn<TEntity>>) => ReactNode;\n}\n\nexport function EntityTableHeader<TEntity extends Entity = Entity>(\n _props: EntityTableHeaderProps<TEntity>,\n): ReactNode {\n return null;\n}\n\nexport interface EntityTableRowProps<TEntity extends Entity = Entity> {\n /** Replaces the whole body row for every item. */\n render: (\n item: TEntity,\n columns: Array<EntityTableColumn<TEntity>>,\n ) => ReactNode;\n}\n\nexport function EntityTableRow<TEntity extends Entity = Entity>(\n _props: EntityTableRowProps<TEntity>,\n): ReactNode {\n return null;\n}\n\nexport interface EntityTableToolbarProps {\n children?: ReactNode;\n}\n\n/** Extra actions placed alongside the built-in toolbar controls. */\nexport function EntityTableToolbar(_props: EntityTableToolbarProps): ReactNode {\n return null;\n}\n\nexport interface EntityTableSlots<TEntity extends Entity> {\n columns: Array<EntityColumnProps<TEntity>>;\n header?: EntityTableHeaderProps<TEntity>;\n row?: EntityTableRowProps<TEntity>;\n toolbar?: ReactNode;\n /** Children that matched no slot — rendered below the table untouched. */\n rest: ReactNode[];\n}\n\n/**\n * Sorts children into slots.\n *\n * Matching is by component identity rather than by `displayName`: identity\n * survives minification and cannot collide with an unrelated component that\n * happens to share a name.\n */\nexport function readEntityTableSlots<TEntity extends Entity>(\n children: ReactNode,\n): EntityTableSlots<TEntity> {\n const slots: EntityTableSlots<TEntity> = { columns: [], rest: [] };\n\n Children.toArray(children).forEach(child => {\n if (!isValidElement(child)) {\n slots.rest.push(child);\n return;\n }\n\n switch (child.type) {\n case EntityColumn:\n slots.columns.push(child.props as EntityColumnProps<TEntity>);\n break;\n case EntityTableHeader:\n slots.header = child.props as EntityTableHeaderProps<TEntity>;\n break;\n case EntityTableRow:\n slots.row = child.props as EntityTableRowProps<TEntity>;\n break;\n case EntityTableToolbar:\n slots.toolbar = (child.props as EntityTableToolbarProps).children;\n break;\n default:\n slots.rest.push(child);\n }\n });\n\n return slots;\n}\n"],"names":["Children","isValidElement","EntityColumn","_props","EntityTableHeader","EntityTableRow","EntityTableToolbar","readEntityTableSlots","children","slots","columns","rest","toArray","forEach","child","push","type","props","header","row","toolbar"],"mappings":"AAMA,SAASA,QAAQ,EAAEC,cAAc,QAAwB,QAAQ;AAoCjE,mEAAmE,GACnE,OAAO,SAASC,aACdC,MAAkC;IAElC,OAAO;AACT;AAOA,OAAO,SAASC,kBACdD,MAAuC;IAEvC,OAAO;AACT;AAUA,OAAO,SAASE,eACdF,MAAoC;IAEpC,OAAO;AACT;AAMA,kEAAkE,GAClE,OAAO,SAASG,mBAAmBH,MAA+B;IAChE,OAAO;AACT;AAWA;;;;;;CAMC,GACD,OAAO,SAASI,qBACdC,QAAmB;IAEnB,MAAMC,QAAmC;QAAEC,SAAS,EAAE;QAAEC,MAAM,EAAE;IAAC;IAEjEX,SAASY,OAAO,CAACJ,UAAUK,OAAO,CAACC,CAAAA;QACjC,IAAI,eAACb,eAAea,QAAQ;YAC1BL,MAAME,IAAI,CAACI,IAAI,CAACD;YAChB;QACF;QAEA,OAAQA,MAAME,IAAI;YAChB,KAAKd;gBACHO,MAAMC,OAAO,CAACK,IAAI,CAACD,MAAMG,KAAK;gBAC9B;YACF,KAAKb;gBACHK,MAAMS,MAAM,GAAGJ,MAAMG,KAAK;gBAC1B;YACF,KAAKZ;gBACHI,MAAMU,GAAG,GAAGL,MAAMG,KAAK;gBACvB;YACF,KAAKX;gBACHG,MAAMW,OAAO,GAAG,AAACN,MAAMG,KAAK,CAA6BT,QAAQ;gBACjE;YACF;gBACEC,MAAME,IAAI,CAACI,IAAI,CAACD;QACpB;IACF;IAEA,OAAOL;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-entity-table-columns.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-table/use-entity-table-columns.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAKvB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-entity-table-columns.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-table/use-entity-table-columns.ts"],"names":[],"m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