@entifix/react-controls 0.20.2 → 0.20.3
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/dist/ui/actions/action-surfaces.d.ts +13 -0
- package/dist/ui/actions/action-surfaces.d.ts.map +1 -1
- package/dist/ui/actions/action-surfaces.js +15 -0
- package/dist/ui/actions/action-surfaces.js.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.d.ts.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.js +12 -4
- package/dist/ui/organisms/entity-form/entity-form.js.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table.js +27 -2
- package/dist/ui/organisms/entity-table/entity-table.js.map +1 -1
- package/dist/ui/utils/use-focus-on-arrival.d.ts +11 -0
- package/dist/ui/utils/use-focus-on-arrival.d.ts.map +1 -1
- package/dist/ui/utils/use-focus-on-arrival.js +33 -1
- package/dist/ui/utils/use-focus-on-arrival.js.map +1 -1
- package/package.json +11 -11
|
@@ -56,4 +56,17 @@ export declare function surfaceFor(descriptor: UseCaseDescriptor): ActionSurface
|
|
|
56
56
|
* `alsoAt` is validated on that same first render, not on the surface it names.
|
|
57
57
|
*/
|
|
58
58
|
export declare function useCasesForSurface(surface: ActionSurface, useCases: readonly UseCaseDescriptor[] | undefined): UseCaseDescriptor[];
|
|
59
|
+
/**
|
|
60
|
+
* The descriptors a surface showing one record offers on it: those whose
|
|
61
|
+
* declared states the record is in. A verb the record's state does not allow
|
|
62
|
+
* is left out rather than disabled — a shipment awaiting dispatch has no use
|
|
63
|
+
* for a greyed-out Record delivery, and four buttons of equal weight whatever
|
|
64
|
+
* the status is what made the one that applies hard to find. The verb's handler
|
|
65
|
+
* still refuses an illegal move: a record can change between render and click.
|
|
66
|
+
*
|
|
67
|
+
* Only for a surface about one record. A selection carries no states, so the
|
|
68
|
+
* bulk bar and the toolbar offer every verb and a refused row comes back as a
|
|
69
|
+
* failed outcome.
|
|
70
|
+
*/
|
|
71
|
+
export declare function availableUseCases(useCases: readonly UseCaseDescriptor[], record: object | undefined): UseCaseDescriptor[];
|
|
59
72
|
//# sourceMappingURL=action-surfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-surfaces.d.ts","sourceRoot":"","sources":["../../../src/ui/actions/action-surfaces.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"action-surfaces.d.ts","sourceRoot":"","sources":["../../../src/ui/actions/action-surfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,qGAOlB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAyB7D;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,WAAW,CAAC;AAuBvC;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,iBAAiB,GAC5B,SAAS,aAAa,EAAE,CAa1B;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,iBAAiB,GAAG,aAAa,CAMvE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GAAG,SAAS,GACjD,iBAAiB,EAAE,CAIrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,iBAAiB,EAAE,CAErB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isUseCaseAvailable } from '@entifix/core';
|
|
1
2
|
/**
|
|
2
3
|
* Where a declared verb is rendered.
|
|
3
4
|
*
|
|
@@ -100,5 +101,19 @@
|
|
|
100
101
|
*/ export function useCasesForSurface(surface, useCases) {
|
|
101
102
|
return (useCases != null ? useCases : []).filter((descriptor)=>surfacesFor(descriptor).includes(surface));
|
|
102
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The descriptors a surface showing one record offers on it: those whose
|
|
106
|
+
* declared states the record is in. A verb the record's state does not allow
|
|
107
|
+
* is left out rather than disabled — a shipment awaiting dispatch has no use
|
|
108
|
+
* for a greyed-out Record delivery, and four buttons of equal weight whatever
|
|
109
|
+
* the status is what made the one that applies hard to find. The verb's handler
|
|
110
|
+
* still refuses an illegal move: a record can change between render and click.
|
|
111
|
+
*
|
|
112
|
+
* Only for a surface about one record. A selection carries no states, so the
|
|
113
|
+
* bulk bar and the toolbar offer every verb and a refused row comes back as a
|
|
114
|
+
* failed outcome.
|
|
115
|
+
*/ export function availableUseCases(useCases, record) {
|
|
116
|
+
return useCases.filter((descriptor)=>isUseCaseAvailable(descriptor, record));
|
|
117
|
+
}
|
|
103
118
|
|
|
104
119
|
//# sourceMappingURL=action-surfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/actions/action-surfaces.ts"],"sourcesContent":["import {\n type UseCaseBinding,\n type UseCaseDescriptor,\n type UseCasePlacement,\n} from '@entifix/core';\n\n/**\n * Where a declared verb is rendered.\n *\n * The use-case descriptor has two independent axes, and at first only one\n * surface, so four of the nine cells had nowhere to go: `EntityForm` filtered\n * `binding === 'entity' && placement !== 'context-dependent'` and everything\n * else was dropped without a word. This is the map that closes it —\n * **placement decides the surface, binding decides the payload** — and it lives\n * in one module so no surface re-derives it and the two axes cannot drift\n * apart again.\n */\nexport const ACTION_SURFACES = [\n 'form-header',\n 'form-footer',\n 'row-menu',\n 'bulk-bar',\n 'table-toolbar',\n 'command-palette',\n] as const;\nexport type ActionSurface = (typeof ACTION_SURFACES)[number];\n\n/**\n * The nine cells, exhaustively.\n *\n * `collection` + `determining` is deliberately absent, and asking for it\n * throws rather than returning `undefined`. A determining action *finalizes a\n * page* — it is the footer that ends an object page — and a list screen has no\n * such thing to finalize, which is Fiori's own rule. Dropping it silently is\n * the fault this repo already writes an assertion against elsewhere: the verb\n * would be declared, granted, exported, pass every check a register runs,\n * and simply never appear, which reads to its author as \"the permission is\n * wrong\" and sends them looking in the wrong place entirely.\n */\nconst SURFACE_BY_CELL: Record<string, ActionSurface> = {\n 'entity:context-independent': 'form-header',\n 'entity:determining': 'form-footer',\n 'entity:context-dependent': 'row-menu',\n 'collection:context-dependent': 'bulk-bar',\n 'collection:context-independent': 'table-toolbar',\n 'unbound:context-dependent': 'command-palette',\n 'unbound:context-independent': 'command-palette',\n 'unbound:determining': 'command-palette',\n};\n\n/**\n * The overflow trigger's glyph.\n *\n * A constant rather than a literal in JSX, because `react/jsx-no-literals`\n * fails the build on written-in copy and is right to: it cannot tell a\n * typographic glyph from a forgotten Spanish string. The trigger's *name* is a\n * catalog key (`actions.more`, `actions.forRecord`) — this is only the mark,\n * and it is never read aloud.\n */\nexport const OVERFLOW_GLYPH = '\\u22ef';\n\n/** Which surface renders one cell. Throws on a cell no surface owns. */\nfunction surfaceForCell(\n key: string,\n binding: UseCaseBinding,\n placement: UseCasePlacement,\n): ActionSurface {\n const surface = SURFACE_BY_CELL[`${binding}:${placement}`];\n\n if (surface === undefined) {\n throw new Error(\n `The use case \"${key}\" is declared ${binding} + ${placement}, which no surface renders. ` +\n 'A `determining` action finalizes a page — it is an object page’s footer — and a list ' +\n 'screen has no page to finalize, so a collection-bound verb cannot be determining. ' +\n 'Declare it `context-dependent` to reach the bulk bar, or `context-independent` to sit ' +\n 'in the table toolbar.',\n );\n }\n\n return surface;\n}\n\n/**\n * Every surface this descriptor renders on.\n *\n * ⚠️ **A verb may name more than one cell**, and that is what makes publishing\n * reachable from a form header, a row menu and a selection without becoming\n * three permissions. The primary `binding` + `placement` come first, then\n * whatever `alsoAt` adds, and each is validated the same way — an illegal cell\n * in `alsoAt` throws exactly as one in the primary pair does.\n *\n * Duplicates are collapsed. A descriptor that named the same cell twice would\n * otherwise render the verb twice in one menu, which reads as a bug in the\n * screen rather than in the declaration.\n */\nexport function surfacesFor(\n descriptor: UseCaseDescriptor,\n): readonly ActionSurface[] {\n const cells = [\n { binding: descriptor.binding, placement: descriptor.placement },\n ...(descriptor.alsoAt ?? []),\n ];\n\n return [\n ...new Set(\n cells.map(cell =>\n surfaceForCell(descriptor.key, cell.binding, cell.placement),\n ),\n ),\n ];\n}\n\n/**\n * The single surface this descriptor renders on.\n *\n * Kept for the callers that genuinely have one — the command palette asks \"is\n * this mine?\" of an `unbound` verb, which can only ever be in one place. Any\n * caller that renders a *list* of verbs wants {@link surfacesFor}.\n */\nexport function surfaceFor(descriptor: UseCaseDescriptor): ActionSurface {\n return surfaceForCell(\n descriptor.key,\n descriptor.binding,\n descriptor.placement,\n );\n}\n\n/**\n * The descriptors one surface should render, in declaration order.\n *\n * Every descriptor is passed through {@link surfacesFor}, so an unrenderable\n * cell throws on the **first render of any surface** rather than only on the\n * one that would have shown it — the same reason\n * `assertLinkSourcesAreEditable` runs as one pass over the registry instead of\n * per row: a check that only fires on the screen that was already looking for\n * the verb is a check that fires after the bug is reported. A cell declared in\n * `alsoAt` is validated on that same first render, not on the surface it names.\n */\nexport function useCasesForSurface(\n surface: ActionSurface,\n useCases: readonly UseCaseDescriptor[] | undefined,\n): UseCaseDescriptor[] {\n return (useCases ?? []).filter(descriptor =>\n surfacesFor(descriptor).includes(surface),\n );\n}\n"],"names":["ACTION_SURFACES","SURFACE_BY_CELL","OVERFLOW_GLYPH","surfaceForCell","key","binding","placement","surface","undefined","Error","surfacesFor","descriptor","cells","alsoAt","Set","map","cell","surfaceFor","useCasesForSurface","useCases","filter","includes"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/actions/action-surfaces.ts"],"sourcesContent":["import {\n isUseCaseAvailable,\n type UseCaseBinding,\n type UseCaseDescriptor,\n type UseCasePlacement,\n} from '@entifix/core';\n\n/**\n * Where a declared verb is rendered.\n *\n * The use-case descriptor has two independent axes, and at first only one\n * surface, so four of the nine cells had nowhere to go: `EntityForm` filtered\n * `binding === 'entity' && placement !== 'context-dependent'` and everything\n * else was dropped without a word. This is the map that closes it —\n * **placement decides the surface, binding decides the payload** — and it lives\n * in one module so no surface re-derives it and the two axes cannot drift\n * apart again.\n */\nexport const ACTION_SURFACES = [\n 'form-header',\n 'form-footer',\n 'row-menu',\n 'bulk-bar',\n 'table-toolbar',\n 'command-palette',\n] as const;\nexport type ActionSurface = (typeof ACTION_SURFACES)[number];\n\n/**\n * The nine cells, exhaustively.\n *\n * `collection` + `determining` is deliberately absent, and asking for it\n * throws rather than returning `undefined`. A determining action *finalizes a\n * page* — it is the footer that ends an object page — and a list screen has no\n * such thing to finalize, which is Fiori's own rule. Dropping it silently is\n * the fault this repo already writes an assertion against elsewhere: the verb\n * would be declared, granted, exported, pass every check a register runs,\n * and simply never appear, which reads to its author as \"the permission is\n * wrong\" and sends them looking in the wrong place entirely.\n */\nconst SURFACE_BY_CELL: Record<string, ActionSurface> = {\n 'entity:context-independent': 'form-header',\n 'entity:determining': 'form-footer',\n 'entity:context-dependent': 'row-menu',\n 'collection:context-dependent': 'bulk-bar',\n 'collection:context-independent': 'table-toolbar',\n 'unbound:context-dependent': 'command-palette',\n 'unbound:context-independent': 'command-palette',\n 'unbound:determining': 'command-palette',\n};\n\n/**\n * The overflow trigger's glyph.\n *\n * A constant rather than a literal in JSX, because `react/jsx-no-literals`\n * fails the build on written-in copy and is right to: it cannot tell a\n * typographic glyph from a forgotten Spanish string. The trigger's *name* is a\n * catalog key (`actions.more`, `actions.forRecord`) — this is only the mark,\n * and it is never read aloud.\n */\nexport const OVERFLOW_GLYPH = '\\u22ef';\n\n/** Which surface renders one cell. Throws on a cell no surface owns. */\nfunction surfaceForCell(\n key: string,\n binding: UseCaseBinding,\n placement: UseCasePlacement,\n): ActionSurface {\n const surface = SURFACE_BY_CELL[`${binding}:${placement}`];\n\n if (surface === undefined) {\n throw new Error(\n `The use case \"${key}\" is declared ${binding} + ${placement}, which no surface renders. ` +\n 'A `determining` action finalizes a page — it is an object page’s footer — and a list ' +\n 'screen has no page to finalize, so a collection-bound verb cannot be determining. ' +\n 'Declare it `context-dependent` to reach the bulk bar, or `context-independent` to sit ' +\n 'in the table toolbar.',\n );\n }\n\n return surface;\n}\n\n/**\n * Every surface this descriptor renders on.\n *\n * ⚠️ **A verb may name more than one cell**, and that is what makes publishing\n * reachable from a form header, a row menu and a selection without becoming\n * three permissions. The primary `binding` + `placement` come first, then\n * whatever `alsoAt` adds, and each is validated the same way — an illegal cell\n * in `alsoAt` throws exactly as one in the primary pair does.\n *\n * Duplicates are collapsed. A descriptor that named the same cell twice would\n * otherwise render the verb twice in one menu, which reads as a bug in the\n * screen rather than in the declaration.\n */\nexport function surfacesFor(\n descriptor: UseCaseDescriptor,\n): readonly ActionSurface[] {\n const cells = [\n { binding: descriptor.binding, placement: descriptor.placement },\n ...(descriptor.alsoAt ?? []),\n ];\n\n return [\n ...new Set(\n cells.map(cell =>\n surfaceForCell(descriptor.key, cell.binding, cell.placement),\n ),\n ),\n ];\n}\n\n/**\n * The single surface this descriptor renders on.\n *\n * Kept for the callers that genuinely have one — the command palette asks \"is\n * this mine?\" of an `unbound` verb, which can only ever be in one place. Any\n * caller that renders a *list* of verbs wants {@link surfacesFor}.\n */\nexport function surfaceFor(descriptor: UseCaseDescriptor): ActionSurface {\n return surfaceForCell(\n descriptor.key,\n descriptor.binding,\n descriptor.placement,\n );\n}\n\n/**\n * The descriptors one surface should render, in declaration order.\n *\n * Every descriptor is passed through {@link surfacesFor}, so an unrenderable\n * cell throws on the **first render of any surface** rather than only on the\n * one that would have shown it — the same reason\n * `assertLinkSourcesAreEditable` runs as one pass over the registry instead of\n * per row: a check that only fires on the screen that was already looking for\n * the verb is a check that fires after the bug is reported. A cell declared in\n * `alsoAt` is validated on that same first render, not on the surface it names.\n */\nexport function useCasesForSurface(\n surface: ActionSurface,\n useCases: readonly UseCaseDescriptor[] | undefined,\n): UseCaseDescriptor[] {\n return (useCases ?? []).filter(descriptor =>\n surfacesFor(descriptor).includes(surface),\n );\n}\n\n/**\n * The descriptors a surface showing one record offers on it: those whose\n * declared states the record is in. A verb the record's state does not allow\n * is left out rather than disabled — a shipment awaiting dispatch has no use\n * for a greyed-out Record delivery, and four buttons of equal weight whatever\n * the status is what made the one that applies hard to find. The verb's handler\n * still refuses an illegal move: a record can change between render and click.\n *\n * Only for a surface about one record. A selection carries no states, so the\n * bulk bar and the toolbar offer every verb and a refused row comes back as a\n * failed outcome.\n */\nexport function availableUseCases(\n useCases: readonly UseCaseDescriptor[],\n record: object | undefined,\n): UseCaseDescriptor[] {\n return useCases.filter(descriptor => isUseCaseAvailable(descriptor, record));\n}\n"],"names":["isUseCaseAvailable","ACTION_SURFACES","SURFACE_BY_CELL","OVERFLOW_GLYPH","surfaceForCell","key","binding","placement","surface","undefined","Error","surfacesFor","descriptor","cells","alsoAt","Set","map","cell","surfaceFor","useCasesForSurface","useCases","filter","includes","availableUseCases","record"],"mappings":"AAAA,SACEA,kBAAkB,QAIb,gBAAgB;AAEvB;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AAGX;;;;;;;;;;;CAWC,GACD,MAAMC,kBAAiD;IACrD,8BAA8B;IAC9B,sBAAsB;IACtB,4BAA4B;IAC5B,gCAAgC;IAChC,kCAAkC;IAClC,6BAA6B;IAC7B,+BAA+B;IAC/B,uBAAuB;AACzB;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMC,iBAAiB,SAAS;AAEvC,sEAAsE,GACtE,SAASC,eACPC,GAAW,EACXC,OAAuB,EACvBC,SAA2B;IAE3B,MAAMC,UAAUN,eAAe,CAAC,GAAGI,QAAQ,CAAC,EAAEC,WAAW,CAAC;IAE1D,IAAIC,YAAYC,WAAW;QACzB,MAAM,IAAIC,MACR,CAAC,cAAc,EAAEL,IAAI,cAAc,EAAEC,QAAQ,GAAG,EAAEC,UAAU,4BAA4B,CAAC,GACvF,0FACA,uFACA,2FACA;IAEN;IAEA,OAAOC;AACT;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASG,YACdC,UAA6B;QAIvBA;IAFN,MAAMC,QAAQ;QACZ;YAAEP,SAASM,WAAWN,OAAO;YAAEC,WAAWK,WAAWL,SAAS;QAAC;YAC3DK,qBAAAA,WAAWE,MAAM,YAAjBF,qBAAqB,EAAE;KAC5B;IAED,OAAO;WACF,IAAIG,IACLF,MAAMG,GAAG,CAACC,CAAAA,OACRb,eAAeQ,WAAWP,GAAG,EAAEY,KAAKX,OAAO,EAAEW,KAAKV,SAAS;KAGhE;AACH;AAEA;;;;;;CAMC,GACD,OAAO,SAASW,WAAWN,UAA6B;IACtD,OAAOR,eACLQ,WAAWP,GAAG,EACdO,WAAWN,OAAO,EAClBM,WAAWL,SAAS;AAExB;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASY,mBACdX,OAAsB,EACtBY,QAAkD;IAElD,OAAO,CAACA,mBAAAA,WAAY,EAAE,EAAEC,MAAM,CAACT,CAAAA,aAC7BD,YAAYC,YAAYU,QAAQ,CAACd;AAErC;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASe,kBACdH,QAAsC,EACtCI,MAA0B;IAE1B,OAAOJ,SAASC,MAAM,CAACT,CAAAA,aAAcZ,mBAAmBY,YAAYY;AACtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-form.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-form.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,eAAe,CAAC;AAsCvB,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAqDhC,wBAAgB,UAAU,CAAC,OAAO,SAAS,MAAM,EAAE,EACjD,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,aAAa,EACb,WAAW,EACX,YAAY,EACZ,IAAI,EAAE,QAAQ,EACd,WAAW,EACX,YAAY,EACZ,MAAM,EACN,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAwB,EACxB,WAAW,EAAE,eAAe,EAC5B,QAAgB,EAChB,SAAiB,EACjB,QAAe,EACf,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,UAAyB,EACzB,KAAK,EACL,QAAQ,EACR,iBAAyB,EACzB,SAAS,EACT,OAAO,EACP,QAAQ,GACT,EAAE,eAAe,CAAC,OAAO,CAAC,+BAkd1B"}
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
4
4
|
import { cloneEntityDraft, describeEntityColumns, extractMetaEntity, readDraftString, readLocalizedDraft, readRowDrafts } from '@entifix/core';
|
|
5
5
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
6
6
|
import { useEntityNoun, useLocalizedDescriptors, useT, useTranslateKey } from '../../../i18n/index.js';
|
|
7
|
-
import { renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
7
|
+
import { availableUseCases, renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
8
8
|
import { useVerbInvoker } from '../../actions/use-verb-invoker.js';
|
|
9
9
|
import { Button, button } from '../../atoms/button/index.js';
|
|
10
10
|
import { CellValue } from '../../atoms/cell-value/index.js';
|
|
@@ -20,7 +20,7 @@ import { RegionState } from '../../molecules/region-state/index.js';
|
|
|
20
20
|
import { Stack } from '../../molecules/stack/index.js';
|
|
21
21
|
import { cn } from '../../utils/cn.js';
|
|
22
22
|
import { useLiveUpdates } from '../../utils/live-updates.js';
|
|
23
|
-
import { useFocusOnArrival } from '../../utils/use-focus-on-arrival.js';
|
|
23
|
+
import { useFocusOnArrival, useFocusOnLoss } from '../../utils/use-focus-on-arrival.js';
|
|
24
24
|
import { EntityDetailGrid } from '../entity-detail-grid/index.js';
|
|
25
25
|
import { readEntityFormFields } from './entity-form-slots.js';
|
|
26
26
|
import { resolveEntityFormFields } from './use-entity-form-fields.js';
|
|
@@ -144,8 +144,16 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
|
|
|
144
144
|
// hook count must stay fixed across renders.
|
|
145
145
|
const declaredHeaderUseCases = useCasesForSurface('form-header', metadata == null ? void 0 : metadata.useCases);
|
|
146
146
|
const declaredFooterUseCases = useCasesForSurface('form-footer', metadata == null ? void 0 : metadata.useCases);
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
// And only the verbs the record's state allows: a shipment awaiting dispatch
|
|
148
|
+
// offers Dispatch, not every move a shipment can ever make.
|
|
149
|
+
const headerUseCases = onUseCase ? availableUseCases(declaredHeaderUseCases, entity) : [];
|
|
150
|
+
const footerUseCases = onUseCase ? availableUseCases(declaredFooterUseCases, entity) : [];
|
|
151
|
+
// A verb that moved its record out of the states it applies to unmounts the
|
|
152
|
+
// button the reader just pressed; focus goes to the heading, not `<body>`.
|
|
153
|
+
useFocusOnLoss(()=>heading.current, [
|
|
154
|
+
...headerUseCases,
|
|
155
|
+
...footerUseCases
|
|
156
|
+
].map(({ key })=>key).join(' '));
|
|
149
157
|
// Every verb on the form, and its own Delete, goes through one invoker: a
|
|
150
158
|
// destructive verb asks, asks for the name, or runs and offers Undo, as it
|
|
151
159
|
// declared — `revoke-sessions` ends every session a user holds.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n cloneEntityDraft,\n describeEntityColumns,\n type Entity,\n type EntityAction,\n type EntityDraft,\n type EntityDraftValue,\n type EntityLinkSource,\n extractMetaEntity,\n type MetaAccessorType,\n readDraftString,\n readLocalizedDraft,\n readRowDrafts,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport { type ReactNode, useEffect, useId, useRef, useState } from 'react';\n\nimport {\n useEntityNoun,\n useLocalizedDescriptors,\n useT,\n useTranslateKey,\n} from '../../../i18n/index.js';\nimport { renderAnchor, useCasesForSurface } from '../../actions/index.js';\nimport { useVerbInvoker } from '../../actions/use-verb-invoker.js';\nimport { Button, button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { FieldControl } from '../../atoms/field-control/index.js';\nimport { LocalizedFieldControl } from '../../atoms/localized-field-control/index.js';\nimport { Skeleton } from '../../atoms/skeleton/index.js';\nimport { Text } from '../../atoms/text/index.js';\nimport {\n ActionBar,\n type ActionBarItem,\n itemsForUseCases,\n} from '../../molecules/action-bar/index.js';\nimport { Card } from '../../molecules/card/index.js';\nimport { EntityLinkInput } from '../../molecules/entity-link-input/index.js';\nimport { LoadingBoundary } from '../../molecules/loading-boundary/index.js';\nimport { RegionState } from '../../molecules/region-state/index.js';\nimport { Stack } from '../../molecules/stack/index.js';\nimport { cn } from '../../utils/cn.js';\nimport { useLiveUpdates } from '../../utils/live-updates.js';\nimport { useFocusOnArrival } from '../../utils/use-focus-on-arrival.js';\nimport { EntityDetailGrid } from '../entity-detail-grid/index.js';\nimport type {\n EntityFormField,\n EntityFormMode,\n EntityFormProps,\n} from './entity-form.types.js';\nimport { readEntityFormFields } from './entity-form-slots.js';\nimport { resolveEntityFormFields } from './use-entity-form-fields.js';\n\n/**\n * The member types a `linkSources` entry can actually produce an editor for.\n *\n * `link` is the obvious one. `string` is here because a foreign key does not\n * have to be a typed relation: when the target lives in **another slice's\n * store**, an `EntityLink` would be an illegal edge and a storage-layer join\n * across a store boundary, so the member is a plain id and the relation exists\n * only in the operator's head — a cross-store reference is an id, never a\n * link. Nothing about the editor cares which of the two it is —\n * `EntityLinkInput` writes `String(target.id)` into the draft either way, and\n * the *only* place `link`-ness still matters is `applyEntityLinks` at submit,\n * which skips a non-`link` descriptor and so leaves the id as the truth.\n *\n * Everything else is excluded on purpose rather than by omission: a `boolean`,\n * `enum`, `number` or `date` member cannot name another record, so a source\n * pointed at one is a wiring mistake — see {@link assertLinkSourcesAreEditable}.\n */\nconst PICKABLE_TYPES: ReadonlySet<MetaAccessorType> = new Set<MetaAccessorType>(\n ['link', 'string'],\n);\n\n/**\n * A form that builds itself from an entity's metadata: fields, labels and value\n * formatting all come from `@accessor()` declarations, so editing a new entity\n * needs no bespoke form. The read/edit toggle is the whole point — the same\n * component shows a record as text or as inputs.\n *\n * Two things layer on top of that default:\n * - **modes** — `read` renders each member through `CellValue`; `edit` renders\n * the matching `FieldControl`. A member in {@link PICKABLE_TYPES} with an\n * entry in `linkSources` gets the full picker instead — a to-one `link`, or a\n * `string` holding a foreign key into another slice's store. Without a source,\n * a relation stays read-only, and a `linkCollection` always does, the to-many\n * editor being a follow-up. A source aimed at a member that can render no\n * picker is a wiring mistake rather than a no-op, and throws.\n * - **slots** — `<EntityField>` children override one field's label, control or\n * read display, or add a computed field.\n *\n * It is presentational: the draft, its errors and the save/delete actions are\n * all props, so the same form hosts on a plain route and inside a workspace tab.\n */\n/** The key the built-in Delete runs under, which no declared verb can take. */\nconst DELETE_KEY = '$delete';\n\n/** Save, from anywhere in the form — the caret in a field included. */\nconst SAVE_SHORTCUT = 'Mod+S';\n/** The footer's declared primary, when it is not Save. */\nconst PRIMARY_SHORTCUT = 'Mod+Enter';\n\nexport function EntityForm<TEntity extends Entity>({\n entityConstructor,\n entity,\n values,\n onFieldChange,\n linkSources,\n onLinkChange,\n mode: modeProp,\n defaultMode,\n onModeChange,\n errors,\n formError,\n onSubmit,\n onDelete,\n deletePolicy = 'confirm',\n recordLabel: hostRecordLabel,\n embedded = false,\n isLoading = false,\n skeleton = true,\n isSaving = false,\n isPending = false,\n isDeleting = false,\n error,\n onRetry,\n backHref,\n renderLink = renderAnchor,\n title,\n metadata,\n isMetadataLoading = false,\n onUseCase,\n onClone,\n children,\n}: EntityFormProps<TEntity>) {\n const formId = useId();\n const slots = readEntityFormFields<TEntity>(children);\n // The *field* descriptors, which stay local and synchronous — a column is a\n // property of the class every caller holds. Only an action's availability is\n // a property of the caller, which is why that half arrives as `metadata`.\n const columnDescriptors = describeEntityColumns(\n entityConstructor,\n entity,\n ) as Array<EntityFormField<TEntity>>;\n // Before slots resolve, so an `<EntityField label>` override still wins.\n const described = useLocalizedDescriptors(columnDescriptors);\n const resolved = resolveEntityFormFields(described, slots.fields);\n assertLinkSourcesAreEditable(resolved, linkSources);\n\n // **Form above, table below**, and it is a partition rather than an ordering\n // hint. A grid rendered between two labelled inputs reads as a field, which\n // it is not — it is a second record list — so every owned collection is\n // pulled out of the field stack whatever `order` it declared, and rendered\n // full width beneath it. A composition that named no child has nothing to\n // render and stays where it was, showing its row count as before.\n const fields = resolved.filter(field => !isOwnedCollection(field));\n const ownedCollections = resolved.filter(isOwnedCollection);\n\n /**\n * `true`/omitted → the built-in default, which draws one label+control pair\n * per resolved field; a node → that node; `false` → nothing. The field list\n * comes from the constructor's metadata, not from the record, so it is already\n * complete while the record is still in flight — which is what lets the\n * placeholder match the form it is standing in for.\n */\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n const showSkeleton = isLoading && skeleton !== false;\n\n const [internalMode, setInternalMode] = useState<EntityFormMode>(\n defaultMode ?? (entity ? 'read' : 'edit'),\n );\n const mode = modeProp ?? internalMode;\n const editing = mode === 'edit';\n\n const draft: EntityDraft = values ?? {};\n const setField = (name: string, value: EntityDraftValue) =>\n onFieldChange?.(name, value);\n\n const toggleMode = () => {\n const next: EntityFormMode = editing ? 'read' : 'edit';\n setInternalMode(next);\n onModeChange?.(next);\n };\n\n const t = useT();\n const translateKey = useTranslateKey();\n const entityNoun = useEntityNoun();\n const live = useLiveUpdates();\n // A form reached by a write — saved, handed off by a wizard — takes focus on\n // its heading, so it never rests on `<body>` (ADR 0028).\n const heading = useRef<HTMLHeadingElement>(null);\n useFocusOnArrival(heading);\n const busy = isSaving || isPending || isDeleting;\n\n // A draft restored from storage holds relation ids and no instances, so every\n // picker is resolving its target for a moment after mount. Saving inside that\n // window is exactly the case `applyEntityLinks` refuses: an `embedded` member\n // with an id and nothing to inline. Gating the save is the honest answer —\n // the form is still assembling itself, and the wait is one lookup long.\n //\n // Deliberately not narrowed to `embedded` members: a descriptor's\n // serialization is not what makes an in-flight lookup a bad moment to submit,\n // and a form that saves half-resolved is confusing whichever shape it writes.\n const resolvingLinks = Object.values(linkSources ?? {}).some(\n source => source.selected.isLoading,\n );\n\n // Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n // site renders exactly as before. Present metadata is authoritative: it is\n // what the service already decided this caller may do.\n const may = (action: EntityAction) =>\n metadata === undefined || metadata.actions.includes(action);\n\n // A single-record form shows the verbs that act on *this* record. Which cell\n // lands where is `action-surfaces`' business and nobody else's — a\n // `context-dependent` entity verb belongs to a row's overflow menu and a\n // `collection`-bound one to the bulk bar, and resolving that here as well is\n // how the two surfaces drifted apart in the first place.\n //\n // ⚠️ **Only when there is somewhere for them to go.** Every cell these two\n // surfaces render is `binding: 'entity'`, so without an `onUseCase` the\n // button has no handler and clicking it does nothing at all. That is not a\n // hypothetical: `makeEntityCrud` withholds the handler on a create, because\n // there is no record for a verb to act on — and Publish and Unpublish\n // rendered on a new `ProductOffering` and were inert, which reads as a broken\n // feature rather than an inapplicable one.\n //\n // The hooks are called unconditionally and their *results* are gated: React's\n // hook count must stay fixed across renders.\n const declaredHeaderUseCases = useCasesForSurface(\n 'form-header',\n metadata?.useCases,\n );\n const declaredFooterUseCases = useCasesForSurface(\n 'form-footer',\n metadata?.useCases,\n );\n const headerUseCases = onUseCase ? declaredHeaderUseCases : [];\n const footerUseCases = onUseCase ? declaredFooterUseCases : [];\n\n // Every verb on the form, and its own Delete, goes through one invoker: a\n // destructive verb asks, asks for the name, or runs and offers Undo, as it\n // declared — `revoke-sessions` ends every session a user holds.\n const verbs = useVerbInvoker<undefined>({\n run: key => (key === DELETE_KEY ? onDelete?.() : onUseCase?.(key)),\n busy,\n served: metadata?.useCases,\n });\n // What a confirmation names: the record as the reader knows it — its first\n // filled-in field — or, for a record with nothing filled in, the entity.\n const metaEntity = extractMetaEntity(entityConstructor);\n const named = fields.find(\n field => field.type !== 'id' && readDraftString(draft, field.name) !== '',\n );\n const recordLabel =\n hostRecordLabel ??\n (named === undefined\n ? entityNoun(metaEntity)\n : readDraftString(draft, named.name));\n const invoke = (descriptor: UseCaseDescriptor) =>\n verbs.invoke({\n descriptor,\n target: undefined,\n object: recordLabel,\n count: 1,\n });\n const requestDelete = () => {\n // Undo is the host's to offer: only it can put a deleted record back.\n if (deletePolicy === 'undo') {\n onDelete?.();\n return;\n }\n invoke({\n key: DELETE_KEY,\n binding: 'entity',\n placement: 'determining',\n labelKey: 'controls:form.delete',\n confirm: {\n tone: 'destructive',\n messageKey: 'controls:confirm.deleteMessage',\n },\n reversible: deletePolicy,\n });\n };\n\n const headerItems = itemsForUseCases(\n headerUseCases,\n translateKey,\n invoke,\n busy,\n );\n const footerItems = itemsForUseCases(\n footerUseCases,\n translateKey,\n invoke,\n busy,\n );\n /**\n * A save attempt. Counted, so a refused one moves focus to the error summary\n * once — not again on every keystroke that leaves an error standing.\n */\n const [attempt, setAttempt] = useState(0);\n const save = () => {\n setAttempt(current => current + 1);\n onSubmit?.(draft);\n };\n const summary = useRef<HTMLDivElement>(null);\n const summaryId = useId();\n const invalid = editing\n ? fields.filter(field => errors?.[field.name] !== undefined)\n : [];\n const focusedAttempt = useRef(0);\n useEffect(() => {\n if (attempt === focusedAttempt.current || invalid.length === 0) return;\n focusedAttempt.current = attempt;\n summary.current?.focus();\n }, [attempt, invalid.length]);\n\n // Save is the footer's primary unless the entity declared one of its own — a\n // determining \"Publish\" is what that page is for, and Save steps aside.\n const declaresFooterPrimary = footerItems.some(\n item => item.emphasis === 'primary',\n );\n const footerActions: ActionBarItem[] = [\n ...(may('write')\n ? [\n {\n key: 'save',\n // A pending write waits on the push stream; while that is down\n // it says so, rather than waiting without a word.\n label: isPending\n ? t(live.connection === 'open' ? 'form.pending' : 'live.waiting')\n : isSaving\n ? t('form.saving')\n : t('form.save'),\n emphasis: declaresFooterPrimary\n ? ('default' as const)\n : ('primary' as const),\n disabled: busy || resolvingLinks,\n submit: true,\n shortcut: SAVE_SHORTCUT,\n onSelect: save,\n },\n ]\n : []),\n // The page's main act answers Mod+Enter, unless it declared its own.\n ...footerItems.map(item =>\n item.emphasis === 'primary' && item.shortcut === undefined\n ? { ...item, shortcut: PRIMARY_SHORTCUT }\n : item,\n ),\n // Clone is the CRUD triple's, not a declared verb's: every entity can be\n // copied, so giving it a `@useCase()` would mean declaring the same verb on\n // all 28 of them. It needs `write`, because what it produces is a create.\n ...(onClone && entity && may('write')\n ? [\n {\n key: 'clone',\n label: t('form.clone'),\n disabled: busy,\n onSelect: () => onClone(cloneEntityDraft(entityConstructor, draft)),\n },\n ]\n : []),\n ...(onDelete && may('delete')\n ? [\n {\n key: 'delete',\n label: isDeleting ? t('form.deleting') : t('form.delete'),\n destructive: true,\n disabled: busy,\n onSelect: requestDelete,\n },\n ]\n : []),\n ];\n\n // A real form while editing, so Enter in a field saves; an embedded one\n // belongs to its host's flow, and a caller who may not write has no Save.\n const asForm = editing && !embedded && may('write');\n const rows = fields.map(field => (\n <FieldRow\n key={field.name}\n field={field}\n entity={entity}\n draft={draft}\n value={readDraftString(draft, field.name)}\n editing={editing}\n error={editing ? errors?.[field.name] : undefined}\n setField={setField}\n linkSource={linkSources?.[field.name]}\n onLinkChange={onLinkChange}\n id={`${formId}-${field.name}`}\n />\n ));\n\n const body = (\n <Stack gap=\"s\">\n {/* An embedded form brings only its fields: the heading and the action\n row belong to whatever is hosting it — a wizard step sits under the\n wizard's own heading and advances with the wizard's own footer, so\n rendering a second of each is two controls for one job. */}\n {!embedded && (\n <Stack direction=\"row\" gap=\"xs\" align=\"center\">\n <Text\n as=\"h2\"\n ref={heading}\n tabIndex={-1}\n step={1}\n weight=\"semibold\"\n className=\"focus-ring\"\n >\n {/* `entity` is undefined while the record is still in flight, so\n testing it alone made a loading edit form announce itself as\n \"New\" for as long as the fetch took, then relabel when the\n record landed. A form that is loading is never a create. */}\n {title ?? (entity || isLoading ? t('form.details') : t('form.new'))}\n </Text>\n {/* The built-in toggle only appears when the form owns its mode and\n there is a record to view — a create form has nothing to read. */}\n {modeProp === undefined && entity && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={toggleMode}\n >\n {editing ? t('form.view') : t('form.edit')}\n </Button>\n )}\n <LoadingBoundary isLoading={isMetadataLoading} lines={0}>\n <>\n {headerItems.length > 0 && (\n <ActionBar surface=\"form-header\" items={headerItems} />\n )}\n {slots.headerActions}\n </>\n </LoadingBoundary>\n </Stack>\n )}\n\n {/* One announcement for the form; the shimmer below is aria-hidden. */}\n <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {isLoading ? t('form.loading') : ''}\n </span>\n\n <RegionState\n plural={entityNoun(metaEntity, 'plural')}\n error={error}\n onRetry={onRetry}\n // Only a load that can be retried leaves an out-of-date record; a\n // failed save leaves what the reader typed, which is current.\n hasStaleData={entity !== undefined && onRetry !== undefined}\n />\n\n {/* A refused save, as one summary of links to what needs fixing: the\n only alert in the form, and where focus goes after the attempt. */}\n {invalid.length > 0 && (\n <div\n ref={summary}\n tabIndex={-1}\n role=\"alert\"\n aria-labelledby={summaryId}\n data-testid=\"entity-form-error-summary\"\n className=\"rounded-lg border-l-4 border-danger bg-danger-subtle px-s py-xs text-step-sm text-content focus-ring\"\n >\n <p id={summaryId} className=\"m-0 font-semibold\">\n {t('form.errorSummary', { count: invalid.length })}\n </p>\n <ul className=\"m-0 ps-s\">\n {invalid.map(field => (\n <li key={field.name}>\n <a\n href={`#${formId}-${field.name}`}\n // The content colour: primary on the danger surface misses\n // 4.5:1.\n className=\"font-medium text-content underline underline-offset-2 focus-ring\"\n onClick={event => {\n event.preventDefault();\n document.getElementById(`${formId}-${field.name}`)?.focus();\n }}\n >\n {errors?.[field.name]}\n </a>\n </li>\n ))}\n </ul>\n </div>\n )}\n\n {editing && fields.some(field => field.required && !field.readonly) && (\n <Text step={-1} tone=\"muted\">\n {t('form.requiredHint')}\n </Text>\n )}\n\n {/* The placeholder *replaces* the rows rather than sitting above them.\n Rendering both meant a shimmer stacked on a full set of empty fields,\n which is two loading signals for one region and twice the height the\n loaded form settles at. */}\n {showSkeleton\n ? (customSkeleton ??\n fields.map(field => (\n <Stack key={field.name} gap=\"3xs\">\n <Skeleton shape=\"line\" className=\"w-24\" />\n <Skeleton className=\"h-9 w-full\" />\n </Stack>\n )))\n : editing\n ? rows\n : // Read mode is a description list: a label points at nothing\n // when there is no control, and a term and its value is what\n // the pair is.\n rows.length > 0 && (\n <dl className=\"m-0 flex flex-col gap-s\">{rows}</dl>\n )}\n\n {/* The rows the record owns, full width and below every field. Each\n grid is handed the *whole* error map and picks out the keys naming\n its own member, so a record owning two collections needs no\n bookkeeping here. */}\n {ownedCollections.map(field => (\n <EntityDetailGrid\n key={field.name}\n descriptor={field}\n rows={readRowDrafts(draft[field.name])}\n onRowsChange={rows => setField(field.name, rows)}\n errors={editing ? errors : undefined}\n editing={editing}\n isLoading={isLoading}\n skeleton={skeleton}\n />\n ))}\n\n {/* A cross-field rule has no row to sit under, so it sits with the\n actions it blocks. */}\n {editing && formError && (\n <span role=\"alert\" className=\"text-step-sm text-danger\">\n {formError}\n </span>\n )}\n\n {editing && !embedded && (\n <Stack direction=\"row\" gap=\"xs\" align=\"center\">\n <ActionBar surface=\"form-footer\" size=\"md\" items={footerActions} />\n {slots.footerActions}\n {/* A link styled as a button, not a button inside a link: the old\n nesting was two interactive elements for one action, and its\n `disabled` stopped nothing, because the anchor around it still\n navigated. While busy the link is inert instead. */}\n {backHref &&\n renderLink({\n href: backHref,\n className: cn(\n button({ variant: 'ghost' }),\n busy && 'pointer-events-none opacity-50',\n ),\n children: t('form.back'),\n intent: { kind: 'back' },\n })}\n </Stack>\n )}\n\n {slots.rest}\n </Stack>\n );\n\n return (\n <Card>\n {asForm ? (\n <form\n noValidate\n // Enter submits through Save, the form's default button, which is\n // disabled while a save is in flight — so a busy form stays put.\n onSubmit={event => {\n event.preventDefault();\n save();\n }}\n >\n {body}\n </form>\n ) : (\n body\n )}\n\n {verbs.dialog}\n </Card>\n );\n}\n\n/**\n * A member the detail grid renders rather than the field stack.\n *\n * The `childType` half is not defensive: a `composition` that declared no child\n * has no columns, so there is nothing for a grid to draw. It keeps its place in\n * the field stack and reads as its row count, which is what it did before this\n * control existed — an honest \"some rows\" rather than an empty table implying\n * there are none.\n */\nfunction isOwnedCollection<TEntity extends Entity>(\n field: EntityFormField<TEntity>,\n): boolean {\n return field.type === 'composition' && field.childType !== undefined;\n}\n\n/**\n * Refuse a `linkSources` entry that names a member no picker can be built for.\n *\n * `FieldRow` asks for {@link PICKABLE_TYPES} before it builds an editor, so a\n * source handed to anything else used to fall through to the read-only display\n * or a plain `FieldControl` with nothing said: the caller wired a picker, no\n * picker appeared, and the field was indistinguishable from one the entity had\n * declared read-only. That is a wiring mistake rather than a state — the entry\n * is dead in *every* shape such a field can render, since an\n * `<EntityField render>` slot is handed the draft and never the source — so it\n * costs the render instead of a warning nobody reads. `useEntityLinkSource`\n * already throws at render for the sibling mistake (a search\n * property the target does not declare `filterable`); this is the same fault\n * caught one level up.\n *\n * Two messages, because the two faults are not the same thing. A\n * `linkCollection` is a member the editor has simply not been built for yet\n * (#26), so the fix is to wait or to point at the to-one you meant. Any other\n * type is a member that can never name another record at all, so the fix is to\n * remove the entry.\n *\n * Here rather than inside `FieldRow`, and that is the whole reason it is a\n * separate pass: a row only reaches its editor branch in **edit** mode, so a\n * per-row check would stay silent on a form that opens in `read` — the default\n * whenever there is a record — and then throw on a click, minutes later. One\n * pass over the registry fires on the first render either way.\n *\n * Against the resolved fields rather than the raw metadata: a slot may drop a\n * member, and a source left behind for a field that no longer renders is not\n * worth a page.\n */\nfunction assertLinkSourcesAreEditable<TEntity extends Entity>(\n fields: Array<EntityFormField<TEntity>>,\n // Same reason as the prop's own declaration: a source's target is another\n // entity entirely and cannot be expressed in terms of `TEntity`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linkSources: Record<string, EntityLinkSource<any>> | undefined,\n): void {\n if (linkSources === undefined) return;\n\n const sourced = fields.filter(\n field =>\n linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type),\n );\n if (sourced.length === 0) return;\n\n const toMany = sourced\n .filter(field => field.type === 'linkCollection')\n .map(field => field.name);\n if (toMany.length > 0) {\n throw new Error(\n `EntityForm was given a link source for a to-many member: ${toMany.join(', ')}. ` +\n 'A `linkCollection` has no editor yet, so the source can only be dropped ' +\n 'and the field would render read-only with no sign anything was wired. ' +\n 'Remove the entry, or point it at the to-one `link` you meant.',\n );\n }\n\n const owned = sourced\n .filter(field => field.type === 'composition')\n .map(field => field.name);\n if (owned.length > 0) {\n throw new Error(\n `EntityForm was given a link source for an owned collection: ${owned.join(', ')}. ` +\n 'A `composition` is not a reference — its rows have no life outside this ' +\n 'record and are never picked from existing ones, so there is nothing for a ' +\n 'picker to look up. The detail grid is what edits them.',\n );\n }\n\n const unpickable = sourced.map(field => `${field.name} (${field.type})`);\n throw new Error(\n `EntityForm was given a link source for a member that cannot hold one: ${unpickable.join(', ')}. ` +\n 'A picker writes the target’s id into the draft, so the member has to be a ' +\n '`link` or the `string` that carries a foreign key. Remove the entry, or ' +\n 'point it at the member that actually holds the reference.',\n );\n}\n\ninterface FieldRowProps<TEntity extends Entity> {\n field: EntityFormField<TEntity>;\n entity: TEntity | undefined;\n draft: EntityDraft;\n value: string;\n editing: boolean;\n error: string | undefined;\n setField: (name: string, value: EntityDraftValue) => void;\n // The target of a relation is a different entity than the form's own.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linkSource: EntityLinkSource<any> | undefined;\n onLinkChange:\n ((name: string, entity: Entity | undefined) => void) | undefined;\n id: string;\n}\n\n/**\n * One label + control (or value) row. A `readonly` member renders its read\n * display even in edit mode, and so does a relation with no source; everything\n * else edits through `FieldControl` — or, when a source was supplied for a\n * member in {@link PICKABLE_TYPES}, through `EntityLinkInput`. A boolean edited\n * inline carries its own label, so the row does not add a second one.\n *\n * The source branch sits above the `virtual || isRelation` fallback and below\n * `field.render`, which is what lets a slot still override a picked field.\n */\nfunction FieldRow<TEntity extends Entity>({\n field,\n entity,\n draft,\n value,\n editing,\n error,\n setField,\n linkSource,\n onLinkChange,\n id,\n}: FieldRowProps<TEntity>) {\n const t = useT();\n const errorId = `${id}-error`;\n const readNode: ReactNode = field.readRender ? (\n field.readRender(entity)\n ) : (\n <CellValue\n value={\n entity ? (entity as Record<string, unknown>)[field.name] : undefined\n }\n descriptor={field}\n record={entity as Record<string, unknown> | undefined}\n />\n );\n\n // Members with no editor of their own here: a to-one `link` whose picker was\n // never wired, a `linkCollection` (#26) and a `composition`. All three\n // fall back to the read display, which is honest — a disabled text box\n // holding `[object Object]` is not.\n const isRelation =\n field.type === 'link' ||\n field.type === 'linkCollection' ||\n field.type === 'composition';\n\n let control: ReactNode;\n if (!editing) {\n control = readNode;\n } else if (field.render) {\n control = field.render({ draft, value, setField, id });\n } else if (linkSource && PICKABLE_TYPES.has(field.type)) {\n control = (\n <EntityLinkInput\n descriptor={field}\n value={value}\n source={linkSource}\n id={id}\n disabled={field.readonly}\n onSelect={target => {\n setField(field.name, target.id == null ? '' : String(target.id));\n onLinkChange?.(field.name, target);\n }}\n onClear={() => {\n setField(field.name, '');\n onLinkChange?.(field.name, undefined);\n }}\n />\n );\n } else if (field.type === 'localized' && !field.virtual) {\n control = (\n <LocalizedFieldControl\n descriptor={field}\n value={readLocalizedDraft(draft, field.name)}\n onChange={next => setField(field.name, next)}\n id={id}\n />\n );\n } else if (field.virtual || isRelation) {\n // A relation with no source has no input to offer, and a virtual field has\n // no member to edit unless a `render` was supplied — both fall back to the\n // read display.\n control = readNode;\n } else {\n control = (\n <FieldControl\n descriptor={field}\n value={value}\n onChange={next => setField(field.name, next)}\n id={id}\n record={draft}\n aria-invalid={error !== undefined || undefined}\n aria-describedby={error === undefined ? undefined : errorId}\n aria-required={field.required || undefined}\n />\n );\n }\n\n if (!editing)\n return (\n <div className=\"flex flex-col gap-3xs\">\n <dt className=\"text-step-sm text-content-muted\">{field.label}</dt>\n <dd className=\"m-0\">{control}</dd>\n </div>\n );\n\n const ownsLabel = field.type === 'boolean' && !field.render && !field.virtual;\n // Marked before anyone submits, not discovered after.\n const marked = field.required && !field.readonly;\n\n return (\n <Stack gap=\"3xs\">\n {!ownsLabel && (\n // The marker sits beside the label, not in it: the name stays the\n // field's own, and `aria-required` is what says it to a reader.\n <span className=\"flex items-baseline gap-3xs\">\n <label htmlFor={id} className=\"text-step-sm text-content-muted\">\n {field.label}\n </label>\n {marked && (\n <span aria-hidden=\"true\" className=\"text-step-sm text-danger\">\n {t('form.requiredMarker')}\n </span>\n )}\n </span>\n )}\n {control}\n {/* Not an alert of its own: the summary above the fields is the one\n announcement, and this is what the control's description reads. */}\n {error && (\n <span id={errorId} className=\"text-step-sm text-danger\">\n {error}\n </span>\n )}\n </Stack>\n );\n}\n"],"names":["cloneEntityDraft","describeEntityColumns","extractMetaEntity","readDraftString","readLocalizedDraft","readRowDrafts","useEffect","useId","useRef","useState","useEntityNoun","useLocalizedDescriptors","useT","useTranslateKey","renderAnchor","useCasesForSurface","useVerbInvoker","Button","button","CellValue","FieldControl","LocalizedFieldControl","Skeleton","Text","ActionBar","itemsForUseCases","Card","EntityLinkInput","LoadingBoundary","RegionState","Stack","cn","useLiveUpdates","useFocusOnArrival","EntityDetailGrid","readEntityFormFields","resolveEntityFormFields","PICKABLE_TYPES","Set","DELETE_KEY","SAVE_SHORTCUT","PRIMARY_SHORTCUT","EntityForm","entityConstructor","entity","values","onFieldChange","linkSources","onLinkChange","mode","modeProp","defaultMode","onModeChange","errors","formError","onSubmit","onDelete","deletePolicy","recordLabel","hostRecordLabel","embedded","isLoading","skeleton","isSaving","isPending","isDeleting","error","onRetry","backHref","renderLink","title","metadata","isMetadataLoading","onUseCase","onClone","children","formId","slots","columnDescriptors","described","resolved","fields","assertLinkSourcesAreEditable","filter","field","isOwnedCollection","ownedCollections","customSkeleton","undefined","showSkeleton","internalMode","setInternalMode","editing","draft","setField","name","value","toggleMode","next","t","translateKey","entityNoun","live","heading","busy","resolvingLinks","Object","some","source","selected","may","action","actions","includes","declaredHeaderUseCases","useCases","declaredFooterUseCases","headerUseCases","footerUseCases","verbs","run","key","served","metaEntity","named","find","type","invoke","descriptor","target","object","count","requestDelete","binding","placement","labelKey","confirm","tone","messageKey","reversible","headerItems","footerItems","attempt","setAttempt","save","current","summary","summaryId","invalid","focusedAttempt","length","focus","declaresFooterPrimary","item","emphasis","footerActions","label","connection","disabled","submit","shortcut","onSelect","map","destructive","asForm","rows","FieldRow","linkSource","id","body","gap","direction","align","as","ref","tabIndex","step","weight","className","variant","size","onClick","lines","surface","items","headerActions","span","role","aria-live","plural","hasStaleData","div","aria-labelledby","data-testid","p","ul","li","a","href","event","document","preventDefault","getElementById","required","readonly","shape","dl","onRowsChange","intent","kind","rest","form","noValidate","dialog","childType","sourced","has","toMany","Error","join","owned","unpickable","errorId","readNode","readRender","record","isRelation","control","render","String","onClear","virtual","onChange","aria-invalid","aria-describedby","aria-required","dt","dd","ownsLabel","marked","htmlFor","aria-hidden"],"mappings":"AAAA;;;AAEA,SACEA,gBAAgB,EAChBC,qBAAqB,EAMrBC,iBAAiB,EAEjBC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QAER,gBAAgB;AACvB,SAAyBC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE3E,SACEC,aAAa,EACbC,uBAAuB,EACvBC,IAAI,EACJC,eAAe,QACV,yBAAyB;AAChC,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,yBAAyB;AAC1E,SAASC,cAAc,QAAQ,o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ACJyD,QAAQpI;YACR4I,gBAAcvK,UAAUsB,aAAaA;YACrCkJ,oBAAkBxK,UAAUsB,YAAYA,YAAYsI;YACpDa,iBAAevJ,MAAMuH,QAAQ,IAAInH;;IAGvC;IAEA,IAAI,CAACI,SACH,qBACE,MAACmG;QAAIb,WAAU;;0BACb,KAAC0D;gBAAG1D,WAAU;0BAAmC9F,MAAMwE,KAAK;;0BAC5D,KAACiF;gBAAG3D,WAAU;0BAAOiD;;;;IAI3B,MAAMW,YAAY1J,MAAM0C,IAAI,KAAK,aAAa,CAAC1C,MAAMgJ,MAAM,IAAI,CAAChJ,MAAMmJ,OAAO;IAC7E,sDAAsD;IACtD,MAAMQ,SAAS3J,MAAMuH,QAAQ,IAAI,CAACvH,MAAMwH,QAAQ;IAEhD,qBACE,MAAC9K;QAAM4I,KAAI;;YACR,CAACoE,aACA,kEAAkE;YAClE,gEAAgE;0BAChE,MAACpD;gBAAKR,WAAU;;kCACd,KAACtB;wBAAMoF,SAASxE;wBAAIU,WAAU;kCAC3B9F,MAAMwE,KAAK;;oBAEbmF,wBACC,KAACrD;wBAAKuD,eAAY;wBAAO/D,WAAU;kCAChC/E,EAAE;;;;YAKVgI;YAGAjK,uBACC,KAACwH;gBAAKlB,IAAIsD;gBAAS5C,WAAU;0BAC1BhH;;;;AAKX"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"sourcesContent":["'use client';\n\nimport {\n cloneEntityDraft,\n describeEntityColumns,\n type Entity,\n type EntityAction,\n type EntityDraft,\n type EntityDraftValue,\n type EntityLinkSource,\n extractMetaEntity,\n type MetaAccessorType,\n readDraftString,\n readLocalizedDraft,\n readRowDrafts,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport { type ReactNode, useEffect, useId, useRef, useState } from 'react';\n\nimport {\n useEntityNoun,\n useLocalizedDescriptors,\n useT,\n useTranslateKey,\n} from '../../../i18n/index.js';\nimport {\n availableUseCases,\n renderAnchor,\n useCasesForSurface,\n} from '../../actions/index.js';\nimport { useVerbInvoker } from '../../actions/use-verb-invoker.js';\nimport { Button, button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { FieldControl } from '../../atoms/field-control/index.js';\nimport { LocalizedFieldControl } from '../../atoms/localized-field-control/index.js';\nimport { Skeleton } from '../../atoms/skeleton/index.js';\nimport { Text } from '../../atoms/text/index.js';\nimport {\n ActionBar,\n type ActionBarItem,\n itemsForUseCases,\n} from '../../molecules/action-bar/index.js';\nimport { Card } from '../../molecules/card/index.js';\nimport { EntityLinkInput } from '../../molecules/entity-link-input/index.js';\nimport { LoadingBoundary } from '../../molecules/loading-boundary/index.js';\nimport { RegionState } from '../../molecules/region-state/index.js';\nimport { Stack } from '../../molecules/stack/index.js';\nimport { cn } from '../../utils/cn.js';\nimport { useLiveUpdates } from '../../utils/live-updates.js';\nimport {\n useFocusOnArrival,\n useFocusOnLoss,\n} from '../../utils/use-focus-on-arrival.js';\nimport { EntityDetailGrid } from '../entity-detail-grid/index.js';\nimport type {\n EntityFormField,\n EntityFormMode,\n EntityFormProps,\n} from './entity-form.types.js';\nimport { readEntityFormFields } from './entity-form-slots.js';\nimport { resolveEntityFormFields } from './use-entity-form-fields.js';\n\n/**\n * The member types a `linkSources` entry can actually produce an editor for.\n *\n * `link` is the obvious one. `string` is here because a foreign key does not\n * have to be a typed relation: when the target lives in **another slice's\n * store**, an `EntityLink` would be an illegal edge and a storage-layer join\n * across a store boundary, so the member is a plain id and the relation exists\n * only in the operator's head — a cross-store reference is an id, never a\n * link. Nothing about the editor cares which of the two it is —\n * `EntityLinkInput` writes `String(target.id)` into the draft either way, and\n * the *only* place `link`-ness still matters is `applyEntityLinks` at submit,\n * which skips a non-`link` descriptor and so leaves the id as the truth.\n *\n * Everything else is excluded on purpose rather than by omission: a `boolean`,\n * `enum`, `number` or `date` member cannot name another record, so a source\n * pointed at one is a wiring mistake — see {@link assertLinkSourcesAreEditable}.\n */\nconst PICKABLE_TYPES: ReadonlySet<MetaAccessorType> = new Set<MetaAccessorType>(\n ['link', 'string'],\n);\n\n/**\n * A form that builds itself from an entity's metadata: fields, labels and value\n * formatting all come from `@accessor()` declarations, so editing a new entity\n * needs no bespoke form. The read/edit toggle is the whole point — the same\n * component shows a record as text or as inputs.\n *\n * Two things layer on top of that default:\n * - **modes** — `read` renders each member through `CellValue`; `edit` renders\n * the matching `FieldControl`. A member in {@link PICKABLE_TYPES} with an\n * entry in `linkSources` gets the full picker instead — a to-one `link`, or a\n * `string` holding a foreign key into another slice's store. Without a source,\n * a relation stays read-only, and a `linkCollection` always does, the to-many\n * editor being a follow-up. A source aimed at a member that can render no\n * picker is a wiring mistake rather than a no-op, and throws.\n * - **slots** — `<EntityField>` children override one field's label, control or\n * read display, or add a computed field.\n *\n * It is presentational: the draft, its errors and the save/delete actions are\n * all props, so the same form hosts on a plain route and inside a workspace tab.\n */\n/** The key the built-in Delete runs under, which no declared verb can take. */\nconst DELETE_KEY = '$delete';\n\n/** Save, from anywhere in the form — the caret in a field included. */\nconst SAVE_SHORTCUT = 'Mod+S';\n/** The footer's declared primary, when it is not Save. */\nconst PRIMARY_SHORTCUT = 'Mod+Enter';\n\nexport function EntityForm<TEntity extends Entity>({\n entityConstructor,\n entity,\n values,\n onFieldChange,\n linkSources,\n onLinkChange,\n mode: modeProp,\n defaultMode,\n onModeChange,\n errors,\n formError,\n onSubmit,\n onDelete,\n deletePolicy = 'confirm',\n recordLabel: hostRecordLabel,\n embedded = false,\n isLoading = false,\n skeleton = true,\n isSaving = false,\n isPending = false,\n isDeleting = false,\n error,\n onRetry,\n backHref,\n renderLink = renderAnchor,\n title,\n metadata,\n isMetadataLoading = false,\n onUseCase,\n onClone,\n children,\n}: EntityFormProps<TEntity>) {\n const formId = useId();\n const slots = readEntityFormFields<TEntity>(children);\n // The *field* descriptors, which stay local and synchronous — a column is a\n // property of the class every caller holds. Only an action's availability is\n // a property of the caller, which is why that half arrives as `metadata`.\n const columnDescriptors = describeEntityColumns(\n entityConstructor,\n entity,\n ) as Array<EntityFormField<TEntity>>;\n // Before slots resolve, so an `<EntityField label>` override still wins.\n const described = useLocalizedDescriptors(columnDescriptors);\n const resolved = resolveEntityFormFields(described, slots.fields);\n assertLinkSourcesAreEditable(resolved, linkSources);\n\n // **Form above, table below**, and it is a partition rather than an ordering\n // hint. A grid rendered between two labelled inputs reads as a field, which\n // it is not — it is a second record list — so every owned collection is\n // pulled out of the field stack whatever `order` it declared, and rendered\n // full width beneath it. A composition that named no child has nothing to\n // render and stays where it was, showing its row count as before.\n const fields = resolved.filter(field => !isOwnedCollection(field));\n const ownedCollections = resolved.filter(isOwnedCollection);\n\n /**\n * `true`/omitted → the built-in default, which draws one label+control pair\n * per resolved field; a node → that node; `false` → nothing. The field list\n * comes from the constructor's metadata, not from the record, so it is already\n * complete while the record is still in flight — which is what lets the\n * placeholder match the form it is standing in for.\n */\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n const showSkeleton = isLoading && skeleton !== false;\n\n const [internalMode, setInternalMode] = useState<EntityFormMode>(\n defaultMode ?? (entity ? 'read' : 'edit'),\n );\n const mode = modeProp ?? internalMode;\n const editing = mode === 'edit';\n\n const draft: EntityDraft = values ?? {};\n const setField = (name: string, value: EntityDraftValue) =>\n onFieldChange?.(name, value);\n\n const toggleMode = () => {\n const next: EntityFormMode = editing ? 'read' : 'edit';\n setInternalMode(next);\n onModeChange?.(next);\n };\n\n const t = useT();\n const translateKey = useTranslateKey();\n const entityNoun = useEntityNoun();\n const live = useLiveUpdates();\n // A form reached by a write — saved, handed off by a wizard — takes focus on\n // its heading, so it never rests on `<body>` (ADR 0028).\n const heading = useRef<HTMLHeadingElement>(null);\n useFocusOnArrival(heading);\n const busy = isSaving || isPending || isDeleting;\n\n // A draft restored from storage holds relation ids and no instances, so every\n // picker is resolving its target for a moment after mount. Saving inside that\n // window is exactly the case `applyEntityLinks` refuses: an `embedded` member\n // with an id and nothing to inline. Gating the save is the honest answer —\n // the form is still assembling itself, and the wait is one lookup long.\n //\n // Deliberately not narrowed to `embedded` members: a descriptor's\n // serialization is not what makes an in-flight lookup a bad moment to submit,\n // and a form that saves half-resolved is confusing whichever shape it writes.\n const resolvingLinks = Object.values(linkSources ?? {}).some(\n source => source.selected.isLoading,\n );\n\n // Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call\n // site renders exactly as before. Present metadata is authoritative: it is\n // what the service already decided this caller may do.\n const may = (action: EntityAction) =>\n metadata === undefined || metadata.actions.includes(action);\n\n // A single-record form shows the verbs that act on *this* record. Which cell\n // lands where is `action-surfaces`' business and nobody else's — a\n // `context-dependent` entity verb belongs to a row's overflow menu and a\n // `collection`-bound one to the bulk bar, and resolving that here as well is\n // how the two surfaces drifted apart in the first place.\n //\n // ⚠️ **Only when there is somewhere for them to go.** Every cell these two\n // surfaces render is `binding: 'entity'`, so without an `onUseCase` the\n // button has no handler and clicking it does nothing at all. That is not a\n // hypothetical: `makeEntityCrud` withholds the handler on a create, because\n // there is no record for a verb to act on — and Publish and Unpublish\n // rendered on a new `ProductOffering` and were inert, which reads as a broken\n // feature rather than an inapplicable one.\n //\n // The hooks are called unconditionally and their *results* are gated: React's\n // hook count must stay fixed across renders.\n const declaredHeaderUseCases = useCasesForSurface(\n 'form-header',\n metadata?.useCases,\n );\n const declaredFooterUseCases = useCasesForSurface(\n 'form-footer',\n metadata?.useCases,\n );\n // And only the verbs the record's state allows: a shipment awaiting dispatch\n // offers Dispatch, not every move a shipment can ever make.\n const headerUseCases = onUseCase\n ? availableUseCases(declaredHeaderUseCases, entity)\n : [];\n const footerUseCases = onUseCase\n ? availableUseCases(declaredFooterUseCases, entity)\n : [];\n // A verb that moved its record out of the states it applies to unmounts the\n // button the reader just pressed; focus goes to the heading, not `<body>`.\n useFocusOnLoss(\n () => heading.current,\n [...headerUseCases, ...footerUseCases].map(({ key }) => key).join(' '),\n );\n\n // Every verb on the form, and its own Delete, goes through one invoker: a\n // destructive verb asks, asks for the name, or runs and offers Undo, as it\n // declared — `revoke-sessions` ends every session a user holds.\n const verbs = useVerbInvoker<undefined>({\n run: key => (key === DELETE_KEY ? onDelete?.() : onUseCase?.(key)),\n busy,\n served: metadata?.useCases,\n });\n // What a confirmation names: the record as the reader knows it — its first\n // filled-in field — or, for a record with nothing filled in, the entity.\n const metaEntity = extractMetaEntity(entityConstructor);\n const named = fields.find(\n field => field.type !== 'id' && readDraftString(draft, field.name) !== '',\n );\n const recordLabel =\n hostRecordLabel ??\n (named === undefined\n ? entityNoun(metaEntity)\n : readDraftString(draft, named.name));\n const invoke = (descriptor: UseCaseDescriptor) =>\n verbs.invoke({\n descriptor,\n target: undefined,\n object: recordLabel,\n count: 1,\n });\n const requestDelete = () => {\n // Undo is the host's to offer: only it can put a deleted record back.\n if (deletePolicy === 'undo') {\n onDelete?.();\n return;\n }\n invoke({\n key: DELETE_KEY,\n binding: 'entity',\n placement: 'determining',\n labelKey: 'controls:form.delete',\n confirm: {\n tone: 'destructive',\n messageKey: 'controls:confirm.deleteMessage',\n },\n reversible: deletePolicy,\n });\n };\n\n const headerItems = itemsForUseCases(\n headerUseCases,\n translateKey,\n invoke,\n busy,\n );\n const footerItems = itemsForUseCases(\n footerUseCases,\n translateKey,\n invoke,\n busy,\n );\n /**\n * A save attempt. Counted, so a refused one moves focus to the error summary\n * once — not again on every keystroke that leaves an error standing.\n */\n const [attempt, setAttempt] = useState(0);\n const save = () => {\n setAttempt(current => current + 1);\n onSubmit?.(draft);\n };\n const summary = useRef<HTMLDivElement>(null);\n const summaryId = useId();\n const invalid = editing\n ? fields.filter(field => errors?.[field.name] !== undefined)\n : [];\n const focusedAttempt = useRef(0);\n useEffect(() => {\n if (attempt === focusedAttempt.current || invalid.length === 0) return;\n focusedAttempt.current = attempt;\n summary.current?.focus();\n }, [attempt, invalid.length]);\n\n // Save is the footer's primary unless the entity declared one of its own — a\n // determining \"Publish\" is what that page is for, and Save steps aside.\n const declaresFooterPrimary = footerItems.some(\n item => item.emphasis === 'primary',\n );\n const footerActions: ActionBarItem[] = [\n ...(may('write')\n ? [\n {\n key: 'save',\n // A pending write waits on the push stream; while that is down\n // it says so, rather than waiting without a word.\n label: isPending\n ? t(live.connection === 'open' ? 'form.pending' : 'live.waiting')\n : isSaving\n ? t('form.saving')\n : t('form.save'),\n emphasis: declaresFooterPrimary\n ? ('default' as const)\n : ('primary' as const),\n disabled: busy || resolvingLinks,\n submit: true,\n shortcut: SAVE_SHORTCUT,\n onSelect: save,\n },\n ]\n : []),\n // The page's main act answers Mod+Enter, unless it declared its own.\n ...footerItems.map(item =>\n item.emphasis === 'primary' && item.shortcut === undefined\n ? { ...item, shortcut: PRIMARY_SHORTCUT }\n : item,\n ),\n // Clone is the CRUD triple's, not a declared verb's: every entity can be\n // copied, so giving it a `@useCase()` would mean declaring the same verb on\n // all 28 of them. It needs `write`, because what it produces is a create.\n ...(onClone && entity && may('write')\n ? [\n {\n key: 'clone',\n label: t('form.clone'),\n disabled: busy,\n onSelect: () => onClone(cloneEntityDraft(entityConstructor, draft)),\n },\n ]\n : []),\n ...(onDelete && may('delete')\n ? [\n {\n key: 'delete',\n label: isDeleting ? t('form.deleting') : t('form.delete'),\n destructive: true,\n disabled: busy,\n onSelect: requestDelete,\n },\n ]\n : []),\n ];\n\n // A real form while editing, so Enter in a field saves; an embedded one\n // belongs to its host's flow, and a caller who may not write has no Save.\n const asForm = editing && !embedded && may('write');\n const rows = fields.map(field => (\n <FieldRow\n key={field.name}\n field={field}\n entity={entity}\n draft={draft}\n value={readDraftString(draft, field.name)}\n editing={editing}\n error={editing ? errors?.[field.name] : undefined}\n setField={setField}\n linkSource={linkSources?.[field.name]}\n onLinkChange={onLinkChange}\n id={`${formId}-${field.name}`}\n />\n ));\n\n const body = (\n <Stack gap=\"s\">\n {/* An embedded form brings only its fields: the heading and the action\n row belong to whatever is hosting it — a wizard step sits under the\n wizard's own heading and advances with the wizard's own footer, so\n rendering a second of each is two controls for one job. */}\n {!embedded && (\n <Stack direction=\"row\" gap=\"xs\" align=\"center\">\n <Text\n as=\"h2\"\n ref={heading}\n tabIndex={-1}\n step={1}\n weight=\"semibold\"\n className=\"focus-ring\"\n >\n {/* `entity` is undefined while the record is still in flight, so\n testing it alone made a loading edit form announce itself as\n \"New\" for as long as the fetch took, then relabel when the\n record landed. A form that is loading is never a create. */}\n {title ?? (entity || isLoading ? t('form.details') : t('form.new'))}\n </Text>\n {/* The built-in toggle only appears when the form owns its mode and\n there is a record to view — a create form has nothing to read. */}\n {modeProp === undefined && entity && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={toggleMode}\n >\n {editing ? t('form.view') : t('form.edit')}\n </Button>\n )}\n <LoadingBoundary isLoading={isMetadataLoading} lines={0}>\n <>\n {headerItems.length > 0 && (\n <ActionBar surface=\"form-header\" items={headerItems} />\n )}\n {slots.headerActions}\n </>\n </LoadingBoundary>\n </Stack>\n )}\n\n {/* One announcement for the form; the shimmer below is aria-hidden. */}\n <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {isLoading ? t('form.loading') : ''}\n </span>\n\n <RegionState\n plural={entityNoun(metaEntity, 'plural')}\n error={error}\n onRetry={onRetry}\n // Only a load that can be retried leaves an out-of-date record; a\n // failed save leaves what the reader typed, which is current.\n hasStaleData={entity !== undefined && onRetry !== undefined}\n />\n\n {/* A refused save, as one summary of links to what needs fixing: the\n only alert in the form, and where focus goes after the attempt. */}\n {invalid.length > 0 && (\n <div\n ref={summary}\n tabIndex={-1}\n role=\"alert\"\n aria-labelledby={summaryId}\n data-testid=\"entity-form-error-summary\"\n className=\"rounded-lg border-l-4 border-danger bg-danger-subtle px-s py-xs text-step-sm text-content focus-ring\"\n >\n <p id={summaryId} className=\"m-0 font-semibold\">\n {t('form.errorSummary', { count: invalid.length })}\n </p>\n <ul className=\"m-0 ps-s\">\n {invalid.map(field => (\n <li key={field.name}>\n <a\n href={`#${formId}-${field.name}`}\n // The content colour: primary on the danger surface misses\n // 4.5:1.\n className=\"font-medium text-content underline underline-offset-2 focus-ring\"\n onClick={event => {\n event.preventDefault();\n document.getElementById(`${formId}-${field.name}`)?.focus();\n }}\n >\n {errors?.[field.name]}\n </a>\n </li>\n ))}\n </ul>\n </div>\n )}\n\n {editing && fields.some(field => field.required && !field.readonly) && (\n <Text step={-1} tone=\"muted\">\n {t('form.requiredHint')}\n </Text>\n )}\n\n {/* The placeholder *replaces* the rows rather than sitting above them.\n Rendering both meant a shimmer stacked on a full set of empty fields,\n which is two loading signals for one region and twice the height the\n loaded form settles at. */}\n {showSkeleton\n ? (customSkeleton ??\n fields.map(field => (\n <Stack key={field.name} gap=\"3xs\">\n <Skeleton shape=\"line\" className=\"w-24\" />\n <Skeleton className=\"h-9 w-full\" />\n </Stack>\n )))\n : editing\n ? rows\n : // Read mode is a description list: a label points at nothing\n // when there is no control, and a term and its value is what\n // the pair is.\n rows.length > 0 && (\n <dl className=\"m-0 flex flex-col gap-s\">{rows}</dl>\n )}\n\n {/* The rows the record owns, full width and below every field. Each\n grid is handed the *whole* error map and picks out the keys naming\n its own member, so a record owning two collections needs no\n bookkeeping here. */}\n {ownedCollections.map(field => (\n <EntityDetailGrid\n key={field.name}\n descriptor={field}\n rows={readRowDrafts(draft[field.name])}\n onRowsChange={rows => setField(field.name, rows)}\n errors={editing ? errors : undefined}\n editing={editing}\n isLoading={isLoading}\n skeleton={skeleton}\n />\n ))}\n\n {/* A cross-field rule has no row to sit under, so it sits with the\n actions it blocks. */}\n {editing && formError && (\n <span role=\"alert\" className=\"text-step-sm text-danger\">\n {formError}\n </span>\n )}\n\n {editing && !embedded && (\n <Stack direction=\"row\" gap=\"xs\" align=\"center\">\n <ActionBar surface=\"form-footer\" size=\"md\" items={footerActions} />\n {slots.footerActions}\n {/* A link styled as a button, not a button inside a link: the old\n nesting was two interactive elements for one action, and its\n `disabled` stopped nothing, because the anchor around it still\n navigated. While busy the link is inert instead. */}\n {backHref &&\n renderLink({\n href: backHref,\n className: cn(\n button({ variant: 'ghost' }),\n busy && 'pointer-events-none opacity-50',\n ),\n children: t('form.back'),\n intent: { kind: 'back' },\n })}\n </Stack>\n )}\n\n {slots.rest}\n </Stack>\n );\n\n return (\n <Card>\n {asForm ? (\n <form\n noValidate\n // Enter submits through Save, the form's default button, which is\n // disabled while a save is in flight — so a busy form stays put.\n onSubmit={event => {\n event.preventDefault();\n save();\n }}\n >\n {body}\n </form>\n ) : (\n body\n )}\n\n {verbs.dialog}\n </Card>\n );\n}\n\n/**\n * A member the detail grid renders rather than the field stack.\n *\n * The `childType` half is not defensive: a `composition` that declared no child\n * has no columns, so there is nothing for a grid to draw. It keeps its place in\n * the field stack and reads as its row count, which is what it did before this\n * control existed — an honest \"some rows\" rather than an empty table implying\n * there are none.\n */\nfunction isOwnedCollection<TEntity extends Entity>(\n field: EntityFormField<TEntity>,\n): boolean {\n return field.type === 'composition' && field.childType !== undefined;\n}\n\n/**\n * Refuse a `linkSources` entry that names a member no picker can be built for.\n *\n * `FieldRow` asks for {@link PICKABLE_TYPES} before it builds an editor, so a\n * source handed to anything else used to fall through to the read-only display\n * or a plain `FieldControl` with nothing said: the caller wired a picker, no\n * picker appeared, and the field was indistinguishable from one the entity had\n * declared read-only. That is a wiring mistake rather than a state — the entry\n * is dead in *every* shape such a field can render, since an\n * `<EntityField render>` slot is handed the draft and never the source — so it\n * costs the render instead of a warning nobody reads. `useEntityLinkSource`\n * already throws at render for the sibling mistake (a search\n * property the target does not declare `filterable`); this is the same fault\n * caught one level up.\n *\n * Two messages, because the two faults are not the same thing. A\n * `linkCollection` is a member the editor has simply not been built for yet\n * (#26), so the fix is to wait or to point at the to-one you meant. Any other\n * type is a member that can never name another record at all, so the fix is to\n * remove the entry.\n *\n * Here rather than inside `FieldRow`, and that is the whole reason it is a\n * separate pass: a row only reaches its editor branch in **edit** mode, so a\n * per-row check would stay silent on a form that opens in `read` — the default\n * whenever there is a record — and then throw on a click, minutes later. One\n * pass over the registry fires on the first render either way.\n *\n * Against the resolved fields rather than the raw metadata: a slot may drop a\n * member, and a source left behind for a field that no longer renders is not\n * worth a page.\n */\nfunction assertLinkSourcesAreEditable<TEntity extends Entity>(\n fields: Array<EntityFormField<TEntity>>,\n // Same reason as the prop's own declaration: a source's target is another\n // entity entirely and cannot be expressed in terms of `TEntity`.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linkSources: Record<string, EntityLinkSource<any>> | undefined,\n): void {\n if (linkSources === undefined) return;\n\n const sourced = fields.filter(\n field =>\n linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type),\n );\n if (sourced.length === 0) return;\n\n const toMany = sourced\n .filter(field => field.type === 'linkCollection')\n .map(field => field.name);\n if (toMany.length > 0) {\n throw new Error(\n `EntityForm was given a link source for a to-many member: ${toMany.join(', ')}. ` +\n 'A `linkCollection` has no editor yet, so the source can only be dropped ' +\n 'and the field would render read-only with no sign anything was wired. ' +\n 'Remove the entry, or point it at the to-one `link` you meant.',\n );\n }\n\n const owned = sourced\n .filter(field => field.type === 'composition')\n .map(field => field.name);\n if (owned.length > 0) {\n throw new Error(\n `EntityForm was given a link source for an owned collection: ${owned.join(', ')}. ` +\n 'A `composition` is not a reference — its rows have no life outside this ' +\n 'record and are never picked from existing ones, so there is nothing for a ' +\n 'picker to look up. The detail grid is what edits them.',\n );\n }\n\n const unpickable = sourced.map(field => `${field.name} (${field.type})`);\n throw new Error(\n `EntityForm was given a link source for a member that cannot hold one: ${unpickable.join(', ')}. ` +\n 'A picker writes the target’s id into the draft, so the member has to be a ' +\n '`link` or the `string` that carries a foreign key. Remove the entry, or ' +\n 'point it at the member that actually holds the reference.',\n );\n}\n\ninterface FieldRowProps<TEntity extends Entity> {\n field: EntityFormField<TEntity>;\n entity: TEntity | undefined;\n draft: EntityDraft;\n value: string;\n editing: boolean;\n error: string | undefined;\n setField: (name: string, value: EntityDraftValue) => void;\n // The target of a relation is a different entity than the form's own.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linkSource: EntityLinkSource<any> | undefined;\n onLinkChange:\n ((name: string, entity: Entity | undefined) => void) | undefined;\n id: string;\n}\n\n/**\n * One label + control (or value) row. A `readonly` member renders its read\n * display even in edit mode, and so does a relation with no source; everything\n * else edits through `FieldControl` — or, when a source was supplied for a\n * member in {@link PICKABLE_TYPES}, through `EntityLinkInput`. A boolean edited\n * inline carries its own label, so the row does not add a second one.\n *\n * The source branch sits above the `virtual || isRelation` fallback and below\n * `field.render`, which is what lets a slot still override a picked field.\n */\nfunction FieldRow<TEntity extends Entity>({\n field,\n entity,\n draft,\n value,\n editing,\n error,\n setField,\n linkSource,\n onLinkChange,\n id,\n}: FieldRowProps<TEntity>) {\n const t = useT();\n const errorId = `${id}-error`;\n const readNode: ReactNode = field.readRender ? (\n field.readRender(entity)\n ) : (\n <CellValue\n value={\n entity ? (entity as Record<string, unknown>)[field.name] : undefined\n }\n descriptor={field}\n record={entity as Record<string, unknown> | undefined}\n />\n );\n\n // Members with no editor of their own here: a to-one `link` whose picker was\n // never wired, a `linkCollection` (#26) and a `composition`. All three\n // fall back to the read display, which is honest — a disabled text box\n // holding `[object Object]` is not.\n const isRelation =\n field.type === 'link' ||\n field.type === 'linkCollection' ||\n field.type === 'composition';\n\n let control: ReactNode;\n if (!editing) {\n control = readNode;\n } else if (field.render) {\n control = field.render({ draft, value, setField, id });\n } else if (linkSource && PICKABLE_TYPES.has(field.type)) {\n control = (\n <EntityLinkInput\n descriptor={field}\n value={value}\n source={linkSource}\n id={id}\n disabled={field.readonly}\n onSelect={target => {\n setField(field.name, target.id == null ? '' : String(target.id));\n onLinkChange?.(field.name, target);\n }}\n onClear={() => {\n setField(field.name, '');\n onLinkChange?.(field.name, undefined);\n }}\n />\n );\n } else if (field.type === 'localized' && !field.virtual) {\n control = (\n <LocalizedFieldControl\n descriptor={field}\n value={readLocalizedDraft(draft, field.name)}\n onChange={next => setField(field.name, next)}\n id={id}\n />\n );\n } else if (field.virtual || isRelation) {\n // A relation with no source has no input to offer, and a virtual field has\n // no member to edit unless a `render` was supplied — both fall back to the\n // read display.\n control = readNode;\n } else {\n control = (\n <FieldControl\n descriptor={field}\n value={value}\n onChange={next => setField(field.name, next)}\n id={id}\n record={draft}\n aria-invalid={error !== undefined || undefined}\n aria-describedby={error === undefined ? undefined : errorId}\n aria-required={field.required || undefined}\n />\n );\n }\n\n if (!editing)\n return (\n <div className=\"flex flex-col gap-3xs\">\n <dt className=\"text-step-sm text-content-muted\">{field.label}</dt>\n <dd className=\"m-0\">{control}</dd>\n </div>\n );\n\n const ownsLabel = field.type === 'boolean' && !field.render && !field.virtual;\n // Marked before anyone submits, not discovered after.\n const marked = field.required && !field.readonly;\n\n return (\n <Stack gap=\"3xs\">\n {!ownsLabel && (\n // The marker sits beside the label, not in it: the name stays the\n // field's own, and `aria-required` is what says it to a reader.\n <span className=\"flex items-baseline gap-3xs\">\n <label htmlFor={id} className=\"text-step-sm text-content-muted\">\n {field.label}\n </label>\n {marked && (\n <span aria-hidden=\"true\" className=\"text-step-sm text-danger\">\n {t('form.requiredMarker')}\n </span>\n )}\n </span>\n )}\n {control}\n {/* Not an alert of its own: the summary above the fields is the one\n announcement, and this is what the control's description reads. */}\n {error && (\n <span id={errorId} className=\"text-step-sm text-danger\">\n {error}\n </span>\n )}\n </Stack>\n );\n}\n"],"names":["cloneEntityDraft","describeEntityColumns","extractMetaEntity","readDraftString","readLocalizedDraft","readRowDrafts","useEffect","useId","useRef","useState","useEntityNoun","useLocalizedDescriptors","useT","useTranslateKey","availableUseCases","renderAnchor","useCasesForSurface","useVerbInvoker","Button","button","CellValue","FieldControl","LocalizedFieldControl","Skeleton","Text","ActionBar","itemsForUseCases","Card","EntityLinkInput","LoadingBoundary","RegionState","Stack","cn","useLiveUpdates","useFocusOnArrival","useFocusOnLoss","EntityDetailGrid","readEntityFormFields","resolveEntityFormFields","PICKABLE_TYPES","Set","DELETE_KEY","SAVE_SHORTCUT","PRIMARY_SHORTCUT","EntityForm","entityConstructor","entity","values","onFieldChange","linkSources","onLinkChange","mode","modeProp","defaultMode","onModeChange","errors","formError","onSubmit","onDelete","deletePolicy","recordLabel","hostRecordLabel","embedded","isLoading","skeleton","isSaving","isPending","isDeleting","error","onRetry","backHref","renderLink","title","metadata","isMetadataLoading","onUseCase","onClone","children","formId","slots","columnDescriptors","described","resolved","fields","assertLinkSourcesAreEditable","filter","field","isOwnedCollection","ownedCollections","customSkeleton","undefined","showSkeleton","internalMode","setInternalMode","editing","draft","setField","name","value","toggleMode","next","t","translateKey","entityNoun","live","heading","busy","resolvingLinks","Object","some","source","selected","may","action","actions","includes","declaredHeaderUseCases","useCases","declaredFooterUseCases","headerUseCases","footerUseCases","current","map","key","join","verbs","run","served","metaEntity","named","find","type","invoke","descriptor","target","object","count","requestDelete","binding","placement","labelKey","confirm","tone","messageKey","reversible","headerItems","footerItems","attempt","setAttempt","save","summary","summaryId","invalid","focusedAttempt","length","focus","declaresFooterPrimary","item","emphasis","footerActions","label","connection","disabled","submit","shortcut","onSelect","destructive","asForm","rows","FieldRow","linkSource","id","body","gap","direction","align","as","ref","tabIndex","step","weight","className","variant","size","onClick","lines","surface","items","headerActions","span","role","aria-live","plural","hasStaleData","div","aria-labelledby","data-testid","p","ul","li","a","href","event","document","preventDefault","getElementById","required","readonly","shape","dl","onRowsChange","intent","kind","rest","form","noValidate","dialog","childType","sourced","has","toMany","Error","owned","unpickable","errorId","readNode","readRender","record","isRelation","control","render","String","onClear","virtual","onChange","aria-invalid","aria-describedby","aria-required","dt","dd","ownsLabel","marked","htmlFor","aria-hidden"],"mappings":"AAAA;;;AAEA,SACEA,gBAAgB,EAChBC,qBAAqB,EAMrBC,iBAAiB,EAEjBC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,QAER,gBAAgB;AACvB,SAAyBC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE3E,SACEC,aAAa,EACbC,uBAAuB,EACvBC,IAAI,EACJC,eAAe,QACV,yBAAyB;AAChC,SACEC,iBAAiB,EACjBC,YAAY,EACZC,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":[],"mappings":"AAEA,OAAO,EAEL,KAAK,MAAM,EAYZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-table.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-table/entity-table.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,MAAM,EAYZ,MAAM,eAAe,CAAC;AAqDvB,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAqDjC,wBAAgB,WAAW,CAAC,OAAO,SAAS,MAAM,EAAE,EAClD,iBAAiB,EACjB,SAAS,EACT,QAAe,EACf,KAAK,EACL,KAAK,EACL,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,OAAO,EACP,UAAyB,EACzB,QAAQ,EACR,cAAc,EACd,YAAmB,EACnB,eAAe,EACf,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,eAAe,EACf,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,iBAAyB,EACzB,aAAa,EACb,SAAS,EACT,OAAO,EACP,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAqB,EACrB,QAAQ,GACT,EAAE,gBAAgB,CAAC,OAAO,CAAC,+BAs6B3B"}
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { emptySelection, extractMetaEntity, hierarchyOf, isSelected, queryPropertyFor, selectionSize, toggleSelected } from '@entifix/core';
|
|
4
4
|
import { Fragment, useId, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { useEntityNoun, useLocale, useT, useTranslateKey } from '../../../i18n/index.js';
|
|
6
|
-
import { renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
6
|
+
import { availableUseCases, renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
7
7
|
import { useVerbInvoker } from '../../actions/use-verb-invoker.js';
|
|
8
8
|
import { Button, button } from '../../atoms/button/index.js';
|
|
9
9
|
import { CellValue } from '../../atoms/cell-value/index.js';
|
|
@@ -23,6 +23,7 @@ import { Pagination } from '../../molecules/pagination/index.js';
|
|
|
23
23
|
import { RegionState } from '../../molecules/region-state/index.js';
|
|
24
24
|
import { SortBuilder } from '../../molecules/sort-builder/index.js';
|
|
25
25
|
import { TableToolbar } from '../../molecules/table-toolbar/index.js';
|
|
26
|
+
import { useFocusOnLoss } from '../../utils/use-focus-on-arrival.js';
|
|
26
27
|
import { readEntityTableSlots } from './entity-table-slots.js';
|
|
27
28
|
import { shownTreeRows, TreeCell, treeRows } from './entity-table-tree.js';
|
|
28
29
|
import { nextHeaderSorting, sortKeys } from './header-sort.js';
|
|
@@ -279,8 +280,15 @@ export function EntityTable({ entityConstructor, isLoading, skeleton = true, err
|
|
|
279
280
|
busy: isBulkRunning,
|
|
280
281
|
served: metadata == null ? void 0 : metadata.useCases
|
|
281
282
|
});
|
|
283
|
+
// The row a verb last ran on. Its menu trigger unmounts when the verb moved
|
|
284
|
+
// the record out of every state a row verb applies to, and focus then goes
|
|
285
|
+
// to that row's own link or control rather than `<body>`.
|
|
286
|
+
const rowScope = useId();
|
|
287
|
+
const [lastRow, setLastRow] = useState(undefined);
|
|
288
|
+
useFocusOnLoss(()=>lastRow === undefined ? undefined : focusableIn(`${rowScope}${lastRow}`), shown.map(({ item })=>availableUseCases(rowUseCases, item).map(({ key })=>key).join(',')).join(' '));
|
|
282
289
|
const invoke = (useCase, target)=>{
|
|
283
290
|
if (target.kind === 'row') {
|
|
291
|
+
setLastRow(String(target.item.id));
|
|
284
292
|
verbs.invoke({
|
|
285
293
|
descriptor: useCase,
|
|
286
294
|
target,
|
|
@@ -307,7 +315,7 @@ export function EntityTable({ entityConstructor, isLoading, skeleton = true, err
|
|
|
307
315
|
menuLabel: t('actions.forRecord', {
|
|
308
316
|
record: rowLabel(item)
|
|
309
317
|
}),
|
|
310
|
-
items: itemsForUseCases(rowUseCases, translateKey, (useCase)=>invoke(useCase, {
|
|
318
|
+
items: itemsForUseCases(availableUseCases(rowUseCases, item), translateKey, (useCase)=>invoke(useCase, {
|
|
311
319
|
kind: 'row',
|
|
312
320
|
item
|
|
313
321
|
}))
|
|
@@ -604,6 +612,7 @@ export function EntityTable({ entityConstructor, isLoading, skeleton = true, err
|
|
|
604
612
|
/*#__PURE__*/ _jsx(Fragment, {
|
|
605
613
|
children: slots.row.render(item, visibleColumns)
|
|
606
614
|
}, String((_item_id = item.id) != null ? _item_id : index)) : /*#__PURE__*/ _jsxs(TableRow, {
|
|
615
|
+
"data-record-id": `${rowScope}${String(item.id)}`,
|
|
607
616
|
children: [
|
|
608
617
|
selectionState && /*#__PURE__*/ _jsx(TableCell, {
|
|
609
618
|
children: selectionCell(item, index, selectionState)
|
|
@@ -662,6 +671,7 @@ export function EntityTable({ entityConstructor, isLoading, skeleton = true, err
|
|
|
662
671
|
var _item_id;
|
|
663
672
|
const parts = cardParts(item);
|
|
664
673
|
return /*#__PURE__*/ _jsx("li", {
|
|
674
|
+
"data-record-id": `${rowScope}${String(item.id)}`,
|
|
665
675
|
// A tree's card says how deep it sits, as its row does.
|
|
666
676
|
"aria-level": treeKeys === undefined ? undefined : depth + 1,
|
|
667
677
|
style: treeKeys === undefined ? undefined : {
|
|
@@ -702,5 +712,20 @@ export function EntityTable({ entityConstructor, isLoading, skeleton = true, err
|
|
|
702
712
|
]
|
|
703
713
|
});
|
|
704
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* The first control in a record's row or card that the reader can see. Both
|
|
717
|
+
* layouts are in the DOM and CSS shows one, so a control inside the hidden
|
|
718
|
+
* one is skipped. `scoped` is the record's id under this table's own prefix,
|
|
719
|
+
* so a second table on the page holding the same record is never reached.
|
|
720
|
+
*/ function focusableIn(scoped) {
|
|
721
|
+
return [
|
|
722
|
+
...document.querySelectorAll(`[data-record-id="${CSS.escape(scoped)}"] :is(a[href], button)`)
|
|
723
|
+
].find((control)=>{
|
|
724
|
+
var _ref;
|
|
725
|
+
return (_ref = // `checkVisibility` is recent; a browser without it is asked for the
|
|
726
|
+
// boxes the control lays out, which a `display: none` layout has none of.
|
|
727
|
+
control.checkVisibility == null ? void 0 : control.checkVisibility.call(control)) != null ? _ref : control.getClientRects().length > 0;
|
|
728
|
+
});
|
|
729
|
+
}
|
|
705
730
|
|
|
706
731
|
//# sourceMappingURL=entity-table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/entity-table.tsx"],"sourcesContent":["'use client';\n\nimport {\n emptySelection,\n type Entity,\n type EntityId,\n type EntitySelection,\n type EntitySorting,\n extractMetaEntity,\n type FilterGroup,\n hierarchyOf,\n isSelected,\n queryPropertyFor,\n selectionSize,\n toggleSelected,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport {\n Fragment,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n useEntityNoun,\n useLocale,\n useT,\n useTranslateKey,\n} from '../../../i18n/index.js';\nimport { renderAnchor, useCasesForSurface } from '../../actions/index.js';\nimport { useVerbInvoker } from '../../actions/use-verb-invoker.js';\nimport { Button, button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { Checkbox } from '../../atoms/field/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 { linkClassName } from '../../atoms/text/index.js';\nimport {\n ActionBar,\n type ActionBarItem,\n itemsForUseCases,\n} from '../../molecules/action-bar/index.js';\nimport { BulkActionBar } from '../../molecules/bulk-action-bar/index.js';\nimport { BulkResult } from '../../molecules/bulk-result/index.js';\nimport { ColumnSettings } from '../../molecules/column-settings/index.js';\nimport { EntityRecordCard } from '../../molecules/entity-record-card/index.js';\nimport { FilterBuilder } from '../../molecules/filter-builder/index.js';\nimport { FilterChips } from '../../molecules/filter-chips/index.js';\nimport { LoadingBoundary } from '../../molecules/loading-boundary/index.js';\nimport { Pagination } from '../../molecules/pagination/index.js';\nimport { RegionState } from '../../molecules/region-state/index.js';\nimport { SortBuilder } from '../../molecules/sort-builder/index.js';\nimport { TableToolbar } from '../../molecules/table-toolbar/index.js';\nimport type {\n EntityTableColumn,\n EntityTableProps,\n} from './entity-table.types.js';\nimport { readEntityTableSlots } from './entity-table-slots.js';\nimport { shownTreeRows, TreeCell, treeRows } from './entity-table-tree.js';\nimport { nextHeaderSorting, sortKeys } from './header-sort.js';\nimport {\n ACTIONS_WIDTH,\n pivotClasses,\n pivotWidth,\n SELECTION_WIDTH,\n} from './pivot.js';\nimport { useEntityTableColumns } from './use-entity-table-columns.js';\nimport { useResultAnnouncement } from './use-result-announcement.js';\n\ntype Panel = 'none' | 'filters' | 'sorting';\n\n/**\n * How many placeholder rows the built-in skeleton draws.\n *\n * The column count is taken from the real geometry, because that is the axis a\n * mismatch shifts; the row count is capped instead of tracking `pageSize`, since\n * a fifty-row page would otherwise paint fifty shimmer rows to stand in for\n * content that arrives below the fold anyway.\n */\nconst SKELETON_ROW_CAP = 5;\n\n/** How many members a card shows as meta when none declares a `card` role. */\nconst UNDECLARED_META_CAP = 3;\n\n/**\n * A table that builds itself from an entity's metadata: columns, labels, value\n * formatting and the filter/sort controls all come from `@accessor()`\n * declarations, so listing a new entity needs no bespoke table.\n *\n * Three things layer on top of that default:\n * - **personalization** — column order and visibility, persisted through the\n * UI-preferences port (so it survives reloads and can later move server-side);\n * - **responsiveness** — below `pivotBreakpoint` rows pivot into label/value\n * cards instead of scrolling sideways;\n * - **slots** — `<EntityColumn>` / `<EntityTableHeader>` / `<EntityTableRow>` /\n * `<EntityTableToolbar>` children override any part of the default rendering.\n */\n/**\n * What a pending verb will act on once it is confirmed.\n *\n * A form has one record; a table has a row or a selection, and those reach two\n * different handlers with two different payloads. Carrying the selection itself\n * rather than reading it back at confirm time also removes a branch that could\n * not happen: the bulk bar only renders inside a truthy selection.\n */\ntype PendingTarget<TEntity extends Entity> =\n | { kind: 'row'; item: TEntity }\n | { kind: 'selection'; selection: EntitySelection<TEntity> };\n\nexport function EntityTable<TEntity extends Entity>({\n entityConstructor,\n isLoading,\n skeleton = true,\n error,\n items,\n totalItems,\n currentPage,\n pageSize,\n onPageChange,\n onPageSizeChange,\n hrefFor,\n newHref,\n renderLink = renderAnchor,\n onSelect,\n preferencesKey,\n showControls = true,\n pivotBreakpoint,\n filtering,\n sorting,\n onFilteringChange,\n onSortingChange,\n facets,\n selection,\n onSelectionChange,\n metadata,\n isMetadataLoading = false,\n onBulkUseCase,\n onUseCase,\n onRetry,\n bulkOutcomes,\n onBulkDismiss,\n onBulkRetry,\n isBulkRunning = false,\n children,\n}: EntityTableProps<TEntity>) {\n const t = useT();\n // A descriptor's label is a runtime catalog key — the typed gate cannot see\n // it, which is why a host's catalog check is what catches a typo.\n const translateKey = useTranslateKey();\n const entityNoun = useEntityNoun();\n const metaEntity = extractMetaEntity(entityConstructor);\n const slots = readEntityTableSlots<TEntity>(children);\n const [panel, setPanel] = useState<Panel>('none');\n\n const { columns, visibleColumns, hidden, setPersonalization } =\n useEntityTableColumns<TEntity>(\n entityConstructor,\n slots.columns,\n items[0],\n `entity-table:${preferencesKey ?? metaEntity.key ?? metaEntity.name}`,\n );\n\n // A picker's table is choosing *one* value; a multi-selection there would\n // offer a set to a form member that holds a single reference, and the two\n // controls would fight over the same row. This is a wiring mistake rather\n // than a state, so it costs the render — the same call `EntityForm` makes\n // for a link source aimed at a member no picker can edit.\n if (onSelect !== undefined && selection !== undefined) {\n throw new Error(\n 'EntityTable was given both `onSelect` and `selection`. A picker picks one ' +\n 'row and a selection accumulates many, so the row control cannot be both. ' +\n 'Drop `selection` inside a picker, or drop `onSelect` outside one.',\n );\n }\n\n /**\n * The selection, or `undefined` when the table is not selectable at all.\n *\n * One value rather than a `selection` prop beside a `selectable` boolean:\n * two of them means every render site has to re-test both, and the second\n * test is unreachable — which reads as a defensive check and is really dead\n * code the coverage gate then cannot close.\n */\n const selectionState =\n selection !== undefined && onSelectionChange !== undefined\n ? selection\n : undefined;\n const selectable = selectionState !== undefined;\n const rowUseCases = useCasesForSurface('row-menu', metadata?.useCases);\n const bulkUseCases = useCasesForSurface('bulk-bar', metadata?.useCases);\n const toolbarUseCases = useCasesForSurface(\n 'table-toolbar',\n metadata?.useCases,\n );\n const hasRowMenu = rowUseCases.length > 0 && onUseCase !== undefined;\n\n /**\n * What a `context-independent` collection verb acts on: everything the\n * current filter matches.\n *\n * Not an empty `ids` selection, which would say \"no rows\" — the verb is\n * available *without* a selection precisely because its subject is the\n * collection, so the honest payload is the same filter the listing is\n * showing, and the same one a \"select all matching\" escalation would send.\n */\n const everythingMatching: EntitySelection<TEntity> = {\n mode: 'matching',\n filtering,\n total: totalItems,\n excluded: new Set<EntityId>(),\n };\n\n // Opening a record is its title's link, so a row needs an actions column\n // only to pick it or to run a verb on it.\n const hasRowAction = onSelect !== undefined || hasRowMenu;\n const columnCount =\n visibleColumns.length + (hasRowAction ? 1 : 0) + (selectable ? 1 : 0);\n\n /**\n * The grid and the cards are both rendered, and a container query on the\n * table's own box picks one — at the width its visible columns need. A\n * viewport breakpoint was wrong inside a split view, a drawer or a wizard\n * step, and a JS measurement would guess during SSR and correct after mount.\n */\n const pivot = pivotClasses(\n pivotWidth(\n visibleColumns,\n (selectable ? SELECTION_WIDTH : 0) + (hasRowAction ? ACTIONS_WIDTH : 0),\n pivotBreakpoint,\n ),\n );\n /**\n * The first load has nothing to show and is held with a skeleton; a refetch\n * already has rows, so it keeps them and only marks the region busy. Splitting\n * the two is what stops every pagination click flashing grey.\n */\n const isFirstLoad = isLoading && items.length === 0;\n\n /** `true`/omitted → the built-in default; a node → that node; `false` → none. */\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n const showSkeleton = isFirstLoad && skeleton !== false;\n const skeletonRows = Array.from(\n { length: Math.min(pageSize, SKELETON_ROW_CAP) },\n (_, index) => index,\n );\n\n /**\n * A refetch keeps its rows at full contrast and marks them `aria-busy`:\n * dimming them through opacity took the text under the contrast a reader\n * needs, on every page change.\n */\n const busy = isLoading || undefined;\n\n /** The column a row reads *as*: the first non-identifier one it filled in. */\n const titleColumn = (item: TEntity) =>\n visibleColumns.find(column => {\n if (column.type === 'id') return false;\n const value = (item as Record<string, unknown>)[column.name];\n return value != null && String(value) !== '';\n });\n\n /** The column that links to the record: one declared `card: 'title'`, else the row's title. */\n const declaredTitle = visibleColumns.find(column => column.card === 'title');\n const linkColumn = (item: TEntity) => declaredTitle ?? titleColumn(item);\n\n /**\n * What a record's card shows, by each member's declared `card` role or the\n * default: an id is hidden, the first enum is the badge, and up to\n * {@link UNDECLARED_META_CAP} more members are meta — a card is a summary,\n * and the grid holds the rest.\n */\n const firstEnum = visibleColumns.find(\n column => column.card === undefined && column.type === 'enum',\n );\n const roleOf = (column: EntityTableColumn<TEntity>) =>\n column.card ??\n (column.type === 'id' ? 'hidden' : column === firstEnum ? 'badge' : 'meta');\n const cardParts = (item: TEntity) => {\n const title = linkColumn(item);\n const rest = visibleColumns.filter(column => column !== title);\n let undeclared = 0;\n return {\n title,\n subtitle: rest.find(column => roleOf(column) === 'subtitle'),\n badges: rest.filter(column => roleOf(column) === 'badge'),\n meta: rest.filter(column => {\n if (roleOf(column) !== 'meta') return false;\n if (column.card !== undefined) return true;\n undeclared += 1;\n return undeclared <= UNDECLARED_META_CAP;\n }),\n };\n };\n\n const renderValue = (\n column: EntityTableColumn<TEntity>,\n item: TEntity,\n ): ReactNode =>\n column.render ? (\n column.render(item)\n ) : (\n <CellValue\n value={(item as Record<string, unknown>)[column.name]}\n descriptor={column}\n record={item as Record<string, unknown>}\n />\n );\n\n /**\n * A cell, and the row's title cell is the record's link\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n * A column of identical \"Open\" links named nothing, and a reader tabbing\n * down it heard \"Open\" once per row; the title says which record it opens.\n * A picker's rows are chosen, not opened, so they stay plain.\n */\n const renderCell = (\n column: EntityTableColumn<TEntity>,\n item: TEntity,\n ): ReactNode => {\n const value = renderValue(column, item);\n if (hrefFor === undefined || onSelect !== undefined) return value;\n if (linkColumn(item)?.name !== column.name) return value;\n return renderLink({\n href: hrefFor(item.id),\n className: linkClassName,\n children: value,\n intent: { kind: 'open', id: item.id },\n });\n };\n\n /**\n * The row a shift-click ranges *from* — the last box the user actually\n * toggled. Held in a ref rather than state because it changes nothing on\n * screen, and re-rendering the whole table on every click to remember an\n * anchor is a cost with no visible return.\n */\n const anchorIndex = useRef<number | undefined>(undefined);\n\n /**\n * An entity that declares a parent renders as a tree: the page arranged\n * depth first, its first column indented, and a subtree hidden while its\n * record is collapsed. Collapsing is view state, so it lives here and is\n * forgotten with the table, like the shift-click anchor above.\n */\n const treeKeys = useMemo(\n () => hierarchyOf(entityConstructor),\n [entityConstructor],\n );\n const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(\n () => new Set(),\n );\n const rows = useMemo(() => treeRows(items, treeKeys), [items, treeKeys]);\n const shown = shownTreeRows(rows, collapsed);\n const shownItems = shown.map(row => row.item);\n const toggleCollapsed = (key: string) =>\n setCollapsed(current => {\n const next = new Set(current);\n if (next.has(key)) next.delete(key);\n else next.add(key);\n return next;\n });\n\n const setSelection = (next: EntitySelection<TEntity>) =>\n onSelectionChange?.(next);\n\n const toggleRow = (\n index: number,\n checked: boolean,\n shiftKey: boolean,\n current: EntitySelection<TEntity>,\n ) => {\n // A shift-click extends the last toggle across the rows *on this page*, in\n // the direction the user dragged, and applies the new state to all of them.\n const from = shiftKey ? (anchorIndex.current ?? index) : index;\n const [start, end] = from <= index ? [from, index] : [index, from];\n\n let next = current;\n // The rows as shown: in a tree the order on screen is not the load's.\n for (const row of shownItems.slice(start, end + 1)) {\n next = toggleSelected(next, row.id, checked);\n }\n\n anchorIndex.current = index;\n setSelection(next);\n };\n\n /**\n * The header box, and it has three states rather than two: none of this\n * page's rows selected, all of them, or some. Without the third the box\n * reads as \"nothing is selected\" while a bulk bar sits below it saying\n * otherwise.\n */\n const pageIds = items.map(item => item.id);\n const selectedOnPage = selectionState\n ? pageIds.filter(id => isSelected(selectionState, id)).length\n : 0;\n const allOnPageSelected =\n pageIds.length > 0 && selectedOnPage === pageIds.length;\n const someOnPageSelected = selectedOnPage > 0 && !allOnPageSelected;\n\n const toggleAllOnPage = (\n checked: boolean,\n current: EntitySelection<TEntity>,\n ) => {\n let next = current;\n for (const id of pageIds) next = toggleSelected(next, id, checked);\n anchorIndex.current = undefined;\n setSelection(next);\n };\n\n /**\n * How a row names itself to a screen reader.\n *\n * The first visible column's value, because that is what the user reads the\n * row *as* — \"Seleccionar Acme\" rather than \"Seleccionar fila 3\", which tells\n * them the position they can already see and not the thing they cannot.\n */\n const rowLabel = (item: TEntity): string => {\n // The first non-identifier column **that this row actually filled in**.\n //\n // An id names a row the way \"row 3\" does: it repeats what the user can\n // already see. But skipping only the id is not enough — measured against\n // the seeded catalog, where `code` is the first non-id column and is empty\n // on every brand, so the label fell straight through to the id and never\n // reached `name`. A column that is blank on this row names it no better\n // than its position does, so the search continues past it.\n //\n // The id remains the last resort, because a row with nothing rendered\n // still has to announce itself.\n const named = titleColumn(item);\n\n return named\n ? String((item as Record<string, unknown>)[named.name])\n : String(item.id);\n };\n\n const selectionCell = (\n item: TEntity,\n index: number,\n // Passed in rather than closed over: this is only ever called under\n // `selectable`, which already proves the selection exists, and reading the\n // optional prop here would add a fallback arm that nothing can reach.\n current: EntitySelection<TEntity>,\n ) => (\n <Checkbox\n // Deliberately no `id`: both pivots are always in the DOM, so an id here\n // would be emitted twice per row. `aria-label` names the control instead,\n // and it names the *record* rather than the position.\n aria-label={t('table.selectRow', { record: rowLabel(item) })}\n checked={isSelected(current, item.id)}\n disabled={isBulkRunning}\n onChange={event =>\n toggleRow(\n index,\n event.currentTarget.checked,\n (event.nativeEvent as MouseEvent).shiftKey === true,\n current,\n )\n }\n />\n );\n\n const runTarget = (key: string, target: PendingTarget<TEntity>) => {\n if (target.kind === 'row') onUseCase?.(key, target.item);\n else onBulkUseCase?.(key, target.selection);\n };\n\n /**\n * Every verb on the table goes through here — the row menu, the bulk bar and\n * the toolbar — so none reaches a destructive verb around its confirmation,\n * its typed check or its Undo.\n */\n const verbs = useVerbInvoker<PendingTarget<TEntity>>({\n run: runTarget,\n busy: isBulkRunning,\n served: metadata?.useCases,\n });\n\n const invoke = (\n useCase: UseCaseDescriptor,\n target: PendingTarget<TEntity>,\n ) => {\n if (target.kind === 'row') {\n verbs.invoke({\n descriptor: useCase,\n target,\n object: rowLabel(target.item),\n count: 1,\n });\n return;\n }\n const count = selectionSize(target.selection);\n verbs.invoke({\n descriptor: useCase,\n target,\n object: t('confirm.selection', {\n count,\n label: entityNoun(metaEntity),\n plural: entityNoun(metaEntity, 'plural'),\n }),\n count,\n matching: target.selection.mode === 'matching',\n });\n };\n\n const rowMenu = (item: TEntity) =>\n hasRowMenu ? (\n <ActionBar\n surface=\"row-menu\"\n menuLabel={t('actions.forRecord', { record: rowLabel(item) })}\n items={itemsForUseCases(rowUseCases, translateKey, useCase =>\n invoke(useCase, { kind: 'row', item }),\n )}\n />\n ) : undefined;\n\n /**\n * A picker's Select, then the row's verbs. Opening the record is not here:\n * it is the title's link.\n */\n const recordAction = (item: TEntity) => {\n const pick = onSelect ? (\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n onClick={() => onSelect(item)}\n >\n {t('table.select')}\n </Button>\n ) : undefined;\n\n const menu = rowMenu(item);\n if (!menu) return pick;\n\n return (\n <span className=\"flex items-center gap-2xs\">\n {pick}\n {menu}\n </span>\n );\n };\n\n /**\n * \"New\" is the list's primary, and only where something can be created\n * here: the entity is not one only a flow writes (`creatable: false`), and\n * the caller may write it. A list that offered \"New\" to a reader who could\n * never save opened a form with no Save on it.\n */\n const mayCreate =\n newHref !== undefined &&\n metaEntity.creatable &&\n (metadata === undefined || metadata.actions.includes('write'));\n const toolbarItems: ActionBarItem[] = itemsForUseCases(\n toolbarUseCases,\n translateKey,\n useCase =>\n invoke(useCase, { kind: 'selection', selection: everythingMatching }),\n isBulkRunning,\n );\n const declaresToolbarPrimary = toolbarItems.some(\n item => item.emphasis === 'primary',\n );\n const toolbarActions: ActionBarItem[] = [\n ...(mayCreate\n ? [\n {\n key: 'new',\n label: t('table.new'),\n emphasis: declaresToolbarPrimary\n ? ('default' as const)\n : ('primary' as const),\n href: newHref,\n intent: { kind: 'new' as const },\n },\n ]\n : []),\n ...toolbarItems,\n ];\n\n const locale = useLocale();\n const panelId = useId();\n const keys = sortKeys(sorting, columns);\n const activeFilters = filtering?.values.length ?? 0;\n const results = t('table.results', { count: totalItems });\n\n /**\n * What the status region says once a filter, a sort or a page has settled —\n * debounced, and silent on the first load.\n */\n const announcement = useResultAnnouncement(\n !isLoading,\n totalItems === 0 && activeFilters > 0\n ? t('table.noResultsFiltered')\n : results,\n JSON.stringify([filtering, sorting, currentPage, pageSize]),\n );\n\n /** The caption: what the table holds, how many, and in what order. */\n const primaryKey = keys[0];\n const primaryColumn =\n primaryKey === undefined\n ? undefined\n : columns.find(column => column.name === primaryKey.member);\n const caption =\n primaryKey === undefined || primaryColumn === undefined\n ? t('table.caption', {\n entity: entityNoun(metaEntity, 'plural'),\n results,\n })\n : t('table.captionSorted', {\n entity: entityNoun(metaEntity, 'plural'),\n results,\n column: primaryColumn.label,\n direction: t(\n primaryKey.type === 'asc' ? 'sort.ascending' : 'sort.descending',\n ),\n });\n\n /**\n * A column's header: its name, and — for a sortable one — a button that\n * cycles it ascending → descending → unsorted, with Shift adding it as the\n * next key. Only the primary key carries `aria-sort`.\n */\n const headerCell = (column: EntityTableColumn<TEntity>) => {\n const label = column.header ?? column.label;\n if (!column.sortable || onSortingChange === undefined)\n return <TableHeaderCell key={column.name}>{label}</TableHeaderCell>;\n const position = keys.findIndex(key => key.member === column.name);\n const type = keys[position]?.type;\n return (\n <TableHeaderCell\n key={column.name}\n aria-sort={\n position === 0\n ? type === 'asc'\n ? 'ascending'\n : 'descending'\n : undefined\n }\n >\n <button\n type=\"button\"\n className=\"inline-flex min-h-(--target-min) items-center gap-3xs rounded-sm focus-ring hover:text-content\"\n onClick={event =>\n onSortingChange(\n nextHeaderSorting<TEntity>(\n keys,\n {\n member: column.name,\n property: queryPropertyFor(column, locale),\n },\n event.shiftKey,\n ),\n )\n }\n >\n {label}\n <span aria-hidden=\"true\">\n {type === 'asc' ? '▲' : type === 'desc' ? '▼' : '↕'}\n </span>\n {keys.length > 1 && position >= 0 && (\n <span aria-hidden=\"true\" className=\"text-step-sm\">\n {position + 1}\n </span>\n )}\n </button>\n </TableHeaderCell>\n );\n };\n\n /** A panel toggle: its state said by `aria-expanded`, and its count shown. */\n const panelToggle = (which: Exclude<Panel, 'none'>, count: number) => (\n <Button\n type=\"button\"\n variant={panel === which ? 'primary' : 'secondary'}\n size=\"sm\"\n aria-expanded={panel === which}\n aria-controls={panelId}\n onClick={() => setPanel(current => (current === which ? 'none' : which))}\n >\n {t(which === 'filters' ? 'table.filters' : 'table.sorting')}\n {count > 0 && (\n // Its name stays \"Filters\": the chips say which filters, and a count\n // in the name would change it under the reader with every filter.\n <span\n aria-hidden=\"true\"\n className=\"ms-3xs rounded-full bg-surface px-3xs text-step-sm text-content\"\n >\n {count}\n </span>\n )}\n </Button>\n );\n\n return (\n <div className=\"@container/entity-table flex flex-col gap-s\">\n {/*\n One announcement for the whole table, not one per layout. Both the grid\n and the card list are always in the DOM — CSS picks which is visible —\n so a live region inside each meant assistive tech was told twice that\n the table was loading. The shimmer itself is aria-hidden, so this is the\n only thing that carries the news.\n */}\n <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {isFirstLoad ? t('table.loading') : announcement}\n </span>\n\n {showControls && (\n <TableToolbar\n start={\n <>\n {/* \"New\" and the collection-bound verbs that need no\n selection. They sit here rather than in the bulk bar,\n because the bulk bar only exists while rows are ticked and\n these are always available. */}\n <LoadingBoundary isLoading={isMetadataLoading} lines={0}>\n <>\n {toolbarActions.length > 0 && (\n <ActionBar\n surface=\"table-toolbar\"\n items={toolbarActions}\n renderLink={renderLink}\n />\n )}\n </>\n </LoadingBoundary>\n {slots.toolbar}\n </>\n }\n end={\n <>\n {panelToggle('filters', activeFilters)}\n {panelToggle('sorting', keys.length)}\n <ColumnSettings\n columns={columns}\n hidden={hidden}\n onChange={setPersonalization}\n />\n </>\n }\n panelId={panelId}\n panel={\n panel === 'filters' ? (\n <FilterBuilder<TEntity>\n // Remounted when the filtering changes from outside — a chip\n // removed — so its rows show what is in effect.\n key={JSON.stringify(filtering ?? null)}\n descriptors={columns.filter(column => column.filterable)}\n facets={facets}\n value={filtering}\n onChange={(applied: FilterGroup<TEntity>) =>\n onFilteringChange?.(applied)\n }\n />\n ) : panel === 'sorting' ? (\n <SortBuilder<TEntity>\n descriptors={columns.filter(column => column.sortable)}\n value={sorting}\n onChange={(applied: EntitySorting<TEntity>) =>\n onSortingChange?.(applied)\n }\n />\n ) : undefined\n }\n />\n )}\n\n {showControls && onFilteringChange !== undefined && (\n <FilterChips<TEntity>\n descriptors={columns.filter(column => column.filterable)}\n value={filtering}\n onChange={onFilteringChange}\n />\n )}\n\n {/*\n The bar appears when there is something selected and something to do\n with it. It sits above the rows rather than floating over them: a fixed\n overlay covers the last row of a short page, which is the row the user\n most likely just ticked.\n */}\n {selectionState && selectionSize(selectionState) > 0 && (\n <BulkActionBar\n count={selectionSize(selectionState)}\n useCases={bulkUseCases}\n busy={isBulkRunning}\n // Offered only when this page is fully ticked and the store holds\n // more than the page — the escalation has somewhere to escalate to.\n matchingTotal={\n selectionState.mode === 'ids' &&\n allOnPageSelected &&\n totalItems > items.length\n ? totalItems\n : undefined\n }\n onSelectAllMatching={() => setSelection(everythingMatching)}\n onClear={() => setSelection(emptySelection<TEntity>())}\n onUseCase={useCase =>\n invoke(useCase, { kind: 'selection', selection: selectionState })\n }\n />\n )}\n\n {verbs.dialog}\n\n {bulkOutcomes && bulkOutcomes.length > 0 && onBulkDismiss && (\n <BulkResult\n outcomes={bulkOutcomes}\n busy={isBulkRunning}\n labelFor={id => {\n const row = items.find(item => item.id === id);\n return row ? rowLabel(row) : undefined;\n }}\n onRetryFailed={onBulkRetry}\n onDismiss={onBulkDismiss}\n />\n )}\n\n {/*\n Rendered once, outside both layouts, and independently of whether there\n are rows: a refetch that fails leaves the previous page on screen, and\n without this the user would read stale data as current.\n */}\n {/*\n One state for the region, outside both layouts (ADR 0028): a failed\n load with Retry — and the rows from before it marked as possibly out of\n date — or an empty answer, which says whether a filter emptied it.\n */}\n <RegionState\n plural={entityNoun(metaEntity, 'plural')}\n isLoading={isLoading}\n error={error}\n onRetry={onRetry}\n hasStaleData={items.length > 0}\n isEmpty={items.length === 0}\n isFiltered={activeFilters > 0}\n onClearFilters={\n onFilteringChange === undefined\n ? undefined\n : () =>\n onFilteringChange({\n // Only offered under a filter, so there is one to keep the\n // logic of.\n operator: (filtering as FilterGroup<TEntity>).operator,\n values: [],\n })\n }\n emptyAction={\n mayCreate\n ? renderLink({\n href: newHref as string,\n className: button({ variant: 'primary' }),\n children: t('table.new'),\n intent: { kind: 'new' },\n })\n : undefined\n }\n />\n\n {/* Wide viewports: a grid. */}\n <div className={pivot.grid} aria-busy={busy}>\n {/* Held to most of the viewport so the header can stick above the\n rows; the scroll padding keeps a focused row out from under it. */}\n <Table\n caption={caption}\n containerClassName=\"max-h-(--table-max-block) scroll-pt-12\"\n >\n <TableHead>\n {slots.header ? (\n slots.header.render(visibleColumns)\n ) : (\n <tr>\n {selectable && (\n <TableHeaderCell>\n <Checkbox\n aria-label={t('table.selectAllOnPage')}\n checked={allOnPageSelected}\n indeterminate={someOnPageSelected}\n disabled={isBulkRunning || items.length === 0}\n onChange={event =>\n toggleAllOnPage(\n event.currentTarget.checked,\n selectionState,\n )\n }\n />\n </TableHeaderCell>\n )}\n {visibleColumns.map(headerCell)}\n {hasRowAction && (\n <TableHeaderCell>{t('table.actions')}</TableHeaderCell>\n )}\n </tr>\n )}\n </TableHead>\n <TableBody>\n {/* Skeleton rows rather than the word \"Loading\", and one per column\n rather than a single full-width blob: the placeholder occupies\n the real grid, so the swap to rows shifts nothing sideways.\n `TableMessageRow` is deliberately bypassed — it is one centred\n full-span cell and cannot express the geometry. */}\n {showSkeleton &&\n (customSkeleton ? (\n <TableMessageRow colSpan={columnCount}>\n {customSkeleton}\n </TableMessageRow>\n ) : (\n skeletonRows.map(row => (\n <TableRow key={row}>\n {selectable && (\n <TableCell>\n <Skeleton shape=\"line\" className=\"w-4\" />\n </TableCell>\n )}\n {visibleColumns.map(column => (\n <TableCell key={column.name}>\n <Skeleton shape=\"line\" className=\"w-full\" />\n </TableCell>\n ))}\n {hasRowAction && (\n <TableCell>\n <Skeleton shape=\"line\" className=\"w-16\" />\n </TableCell>\n )}\n </TableRow>\n ))\n ))}\n {shown.map(({ item, depth, hasChildren }, index) =>\n slots.row ? (\n // A Fragment carries the key without wrapping the custom row in\n // an element `<tbody>` would reject.\n <Fragment key={String(item.id ?? index)}>\n {slots.row.render(item, visibleColumns)}\n </Fragment>\n ) : (\n <TableRow key={String(item.id ?? index)}>\n {selectionState && (\n <TableCell>\n {selectionCell(item, index, selectionState)}\n </TableCell>\n )}\n {visibleColumns.map((column, columnIndex) => (\n <TableCell key={column.name}>\n {treeKeys !== undefined && columnIndex === 0 ? (\n <TreeCell\n depth={depth}\n hasChildren={hasChildren}\n expanded={!collapsed.has(treeKeys.idOf(item))}\n label={t(\n collapsed.has(treeKeys.idOf(item))\n ? 'table.expandRow'\n : 'table.collapseRow',\n { record: rowLabel(item) },\n )}\n onToggle={() => toggleCollapsed(treeKeys.idOf(item))}\n >\n {renderCell(column, item)}\n </TreeCell>\n ) : (\n renderCell(column, item)\n )}\n </TableCell>\n ))}\n {hasRowAction && <TableCell>{recordAction(item)}</TableCell>}\n </TableRow>\n ),\n )}\n </TableBody>\n </Table>\n </div>\n\n {/* Narrow containers: the same columns pivoted into a list of cards. */}\n <div className={pivot.cards} aria-busy={busy}>\n {/* The card pivot gets card-shaped placeholders, not a bare shimmer\n block: the border, radius and padding are the geometry here. */}\n {showSkeleton &&\n (customSkeleton ?? (\n <ul role=\"list\" className=\"m-0 p-0 flex list-none flex-col gap-2xs\">\n {skeletonRows.map(row => (\n <li key={row}>\n <EntityRecordCard\n title={<Skeleton shape=\"line\" className=\"w-32\" />}\n meta={visibleColumns.slice(1).map(column => ({\n key: column.name,\n label: column.label,\n value: <Skeleton shape=\"line\" className=\"w-24\" />,\n }))}\n />\n </li>\n ))}\n </ul>\n ))}\n {shown.length > 0 && (\n <ul role=\"list\" className=\"m-0 p-0 flex list-none flex-col gap-2xs\">\n {shown.map(({ item, depth }, index) => {\n const parts = cardParts(item);\n return (\n <li\n key={String(item.id ?? index)}\n // A tree's card says how deep it sits, as its row does.\n aria-level={treeKeys === undefined ? undefined : depth + 1}\n style={\n treeKeys === undefined\n ? undefined\n : { marginInlineStart: `${depth * 1.5}rem` }\n }\n >\n <EntityRecordCard\n // The same renderers as the grid, so the two layouts agree.\n title={\n parts.title === undefined\n ? rowLabel(item)\n : renderCell(parts.title, item)\n }\n subtitle={\n parts.subtitle === undefined\n ? undefined\n : renderCell(parts.subtitle, item)\n }\n badges={parts.badges.map(column => ({\n key: column.name,\n value: renderCell(column, item),\n }))}\n meta={parts.meta.map(column => ({\n key: column.name,\n label: column.header ?? column.label,\n value: renderCell(column, item),\n }))}\n leading={\n selectionState\n ? selectionCell(item, index, selectionState)\n : undefined\n }\n actions={recordAction(item)}\n />\n </li>\n );\n })}\n </ul>\n )}\n </div>\n\n <Pagination\n currentPage={currentPage}\n pageSize={pageSize}\n totalItems={totalItems}\n onPageChange={onPageChange}\n onPageSizeChange={onPageSizeChange}\n />\n\n {slots.rest}\n </div>\n );\n}\n"],"names":["emptySelection","extractMetaEntity","hierarchyOf","isSelected","queryPropertyFor","selectionSize","toggleSelected","Fragment","useId","useMemo","useRef","useState","useEntityNoun","useLocale","useT","useTranslateKey","renderAnchor","useCasesForSurface","useVerbInvoker","Button","button","CellValue","Checkbox","Skeleton","Table","TableBody","TableCell","TableHead","TableHeaderCell","TableMessageRow","TableRow","linkClassName","ActionBar","itemsForUseCases","BulkActionBar","BulkResult","ColumnSettings","EntityRecordCard","FilterBuilder","FilterChips","LoadingBoundary","Pagination","RegionState","SortBuilder","TableToolbar","readEntityTableSlots","shownTreeRows","TreeCell","treeRows","nextHeaderSorting","sortKeys","ACTIONS_WIDTH","pivotClasses","pivotWidth","SELECTION_WIDTH","useEntityTableColumns","useResultAnnouncement","SKELETON_ROW_CAP","UNDECLARED_META_CAP","EntityTable","entityConstructor","isLoading","skeleton","error","items","totalItems","currentPage","pageSize","onPageChange","onPageSizeChange","hrefFor","newHref","renderLink","onSelect","preferencesKey","showControls","pivotBreakpoint","filtering","sorting","onFilteringChange","onSortingChange","facets","selection","onSelectionChange","metadata","isMetadataLoading","onBulkUseCase","onUseCase","onRetry","bulkOutcomes","onBulkDismiss","onBulkRetry","isBulkRunning","children","t","translateKey","entityNoun","metaEntity","slots","panel","setPanel","columns","visibleColumns","hidden","setPersonalization","key","name","undefined","Error","selectionState","selectable","rowUseCases","useCases","bulkUseCases","toolbarUseCases","hasRowMenu","length","everythingMatching","mode","total","excluded","Set","hasRowAction","columnCount","pivot","isFirstLoad","customSkeleton","showSkeleton","skeletonRows","Array","from","Math","min","_","index","busy","titleColumn","item","find","column","type","value","String","declaredTitle","card","linkColumn","firstEnum","roleOf","cardParts","title","rest","filter","undeclared","subtitle","badges","meta","renderValue","render","descriptor","record","renderCell","href","id","className","intent","kind","anchorIndex","treeKeys","collapsed","setCollapsed","rows","shown","shownItems","map","row","toggleCollapsed","current","next","has","delete","add","setSelection","toggleRow","checked","shiftKey","start","end","slice","pageIds","selectedOnPage","allOnPageSelected","someOnPageSelected","toggleAllOnPage","rowLabel","named","selectionCell","aria-label","disabled","onChange","event","currentTarget","nativeEvent","runTarget","target","verbs","run","served","invoke","useCase","object","count","label","plural","matching","rowMenu","surface","menuLabel","recordAction","pick","variant","size","onClick","menu","span","mayCreate","creatable","actions","includes","toolbarItems","declaresToolbarPrimary","some","emphasis","toolbarActions","locale","panelId","keys","activeFilters","values","results","announcement","JSON","stringify","primaryKey","primaryColumn","member","caption","entity","direction","headerCell","header","sortable","position","findIndex","aria-sort","property","aria-hidden","panelToggle","which","aria-expanded","aria-controls","div","role","aria-live","lines","toolbar","descriptors","filterable","applied","matchingTotal","onSelectAllMatching","onClear","dialog","outcomes","labelFor","onRetryFailed","onDismiss","hasStaleData","isEmpty","isFiltered","onClearFilters","operator","emptyAction","grid","aria-busy","containerClassName","tr","indeterminate","colSpan","shape","depth","hasChildren","columnIndex","expanded","idOf","onToggle","cards","ul","li","parts","aria-level","style","marginInlineStart","leading"],"mappings":"AAAA;;AAEA,SACEA,cAAc,EAKdC,iBAAiB,EAEjBC,WAAW,EACXC,UAAU,EACVC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,QAET,gBAAgB;AACvB,SACEC,QAAQ,EAERC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SACEC,aAAa,EACbC,SAAS,EACTC,IAAI,EACJC,eAAe,QACV,yBAAyB;AAChC,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,yBAAyB;AAC1E,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,MAAM,EAAEC,MAAM,QAAQ,8BAA8B;AAC7D,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,QAAQ,QAAQ,6BAA6B;AACtD,SAASC,QAAQ,QAAQ,gCAAgC;AACzD,SACEC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,QAAQ,QACH,6BAA6B;AACpC,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SACEC,SAAS,EAETC,gBAAgB,QACX,sCAAsC;AAC7C,SAASC,aAAa,QAAQ,2CAA2C;AACzE,SAASC,UAAU,QAAQ,uCAAuC;AAClE,SAASC,cAAc,QAAQ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MrJ,KAAK,EAAEZ;oCAE9BgB,UACEiJ,MAAMjJ,QAAQ,KAAK9C,YACfA,YACAqD,WAAW0I,MAAMjJ,QAAQ,EAAEhB;oCAEjCiB,QAAQgJ,MAAMhJ,MAAM,CAACmB,GAAG,CAAClC,CAAAA,SAAW,CAAA;4CAClClC,KAAKkC,OAAOjC,IAAI;4CAChBmC,OAAOmB,WAAWrB,QAAQF;wCAC5B,CAAA;oCACAkB,MAAM+I,MAAM/I,IAAI,CAACkB,GAAG,CAAClC,CAAAA;4CAEZA;+CAFuB;4CAC9BlC,KAAKkC,OAAOjC,IAAI;4CAChByG,KAAK,GAAExE,iBAAAA,OAAO8G,MAAM,YAAb9G,iBAAiBA,OAAOwE,KAAK;4CACpCtE,OAAOmB,WAAWrB,QAAQF;wCAC5B;;oCACAqK,SACEjM,iBACIsF,cAAc1D,MAAMH,OAAOzB,kBAC3BF;oCAENuH,SAAST,aAAahF;;+BAnCnBK,QAAOL,WAAAA,KAAKyB,EAAE,YAAPzB,WAAWH;wBAuC7B;;;;0BAKN,KAAC7F;gBACCyB,aAAaA;gBACbC,UAAUA;gBACVF,YAAYA;gBACZG,cAAcA;gBACdC,kBAAkBA;;YAGnB6B,MAAMoD,IAAI;;;AAGjB"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/entity-table.tsx"],"sourcesContent":["'use client';\n\nimport {\n emptySelection,\n type Entity,\n type EntityId,\n type EntitySelection,\n type EntitySorting,\n extractMetaEntity,\n type FilterGroup,\n hierarchyOf,\n isSelected,\n queryPropertyFor,\n selectionSize,\n toggleSelected,\n type UseCaseDescriptor,\n} from '@entifix/core';\nimport {\n Fragment,\n type ReactNode,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n useEntityNoun,\n useLocale,\n useT,\n useTranslateKey,\n} from '../../../i18n/index.js';\nimport {\n availableUseCases,\n renderAnchor,\n useCasesForSurface,\n} from '../../actions/index.js';\nimport { useVerbInvoker } from '../../actions/use-verb-invoker.js';\nimport { Button, button } from '../../atoms/button/index.js';\nimport { CellValue } from '../../atoms/cell-value/index.js';\nimport { Checkbox } from '../../atoms/field/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 { linkClassName } from '../../atoms/text/index.js';\nimport {\n ActionBar,\n type ActionBarItem,\n itemsForUseCases,\n} from '../../molecules/action-bar/index.js';\nimport { BulkActionBar } from '../../molecules/bulk-action-bar/index.js';\nimport { BulkResult } from '../../molecules/bulk-result/index.js';\nimport { ColumnSettings } from '../../molecules/column-settings/index.js';\nimport { EntityRecordCard } from '../../molecules/entity-record-card/index.js';\nimport { FilterBuilder } from '../../molecules/filter-builder/index.js';\nimport { FilterChips } from '../../molecules/filter-chips/index.js';\nimport { LoadingBoundary } from '../../molecules/loading-boundary/index.js';\nimport { Pagination } from '../../molecules/pagination/index.js';\nimport { RegionState } from '../../molecules/region-state/index.js';\nimport { SortBuilder } from '../../molecules/sort-builder/index.js';\nimport { TableToolbar } from '../../molecules/table-toolbar/index.js';\nimport { useFocusOnLoss } from '../../utils/use-focus-on-arrival.js';\nimport type {\n EntityTableColumn,\n EntityTableProps,\n} from './entity-table.types.js';\nimport { readEntityTableSlots } from './entity-table-slots.js';\nimport { shownTreeRows, TreeCell, treeRows } from './entity-table-tree.js';\nimport { nextHeaderSorting, sortKeys } from './header-sort.js';\nimport {\n ACTIONS_WIDTH,\n pivotClasses,\n pivotWidth,\n SELECTION_WIDTH,\n} from './pivot.js';\nimport { useEntityTableColumns } from './use-entity-table-columns.js';\nimport { useResultAnnouncement } from './use-result-announcement.js';\n\ntype Panel = 'none' | 'filters' | 'sorting';\n\n/**\n * How many placeholder rows the built-in skeleton draws.\n *\n * The column count is taken from the real geometry, because that is the axis a\n * mismatch shifts; the row count is capped instead of tracking `pageSize`, since\n * a fifty-row page would otherwise paint fifty shimmer rows to stand in for\n * content that arrives below the fold anyway.\n */\nconst SKELETON_ROW_CAP = 5;\n\n/** How many members a card shows as meta when none declares a `card` role. */\nconst UNDECLARED_META_CAP = 3;\n\n/**\n * A table that builds itself from an entity's metadata: columns, labels, value\n * formatting and the filter/sort controls all come from `@accessor()`\n * declarations, so listing a new entity needs no bespoke table.\n *\n * Three things layer on top of that default:\n * - **personalization** — column order and visibility, persisted through the\n * UI-preferences port (so it survives reloads and can later move server-side);\n * - **responsiveness** — below `pivotBreakpoint` rows pivot into label/value\n * cards instead of scrolling sideways;\n * - **slots** — `<EntityColumn>` / `<EntityTableHeader>` / `<EntityTableRow>` /\n * `<EntityTableToolbar>` children override any part of the default rendering.\n */\n/**\n * What a pending verb will act on once it is confirmed.\n *\n * A form has one record; a table has a row or a selection, and those reach two\n * different handlers with two different payloads. Carrying the selection itself\n * rather than reading it back at confirm time also removes a branch that could\n * not happen: the bulk bar only renders inside a truthy selection.\n */\ntype PendingTarget<TEntity extends Entity> =\n | { kind: 'row'; item: TEntity }\n | { kind: 'selection'; selection: EntitySelection<TEntity> };\n\nexport function EntityTable<TEntity extends Entity>({\n entityConstructor,\n isLoading,\n skeleton = true,\n error,\n items,\n totalItems,\n currentPage,\n pageSize,\n onPageChange,\n onPageSizeChange,\n hrefFor,\n newHref,\n renderLink = renderAnchor,\n onSelect,\n preferencesKey,\n showControls = true,\n pivotBreakpoint,\n filtering,\n sorting,\n onFilteringChange,\n onSortingChange,\n facets,\n selection,\n onSelectionChange,\n metadata,\n isMetadataLoading = false,\n onBulkUseCase,\n onUseCase,\n onRetry,\n bulkOutcomes,\n onBulkDismiss,\n onBulkRetry,\n isBulkRunning = false,\n children,\n}: EntityTableProps<TEntity>) {\n const t = useT();\n // A descriptor's label is a runtime catalog key — the typed gate cannot see\n // it, which is why a host's catalog check is what catches a typo.\n const translateKey = useTranslateKey();\n const entityNoun = useEntityNoun();\n const metaEntity = extractMetaEntity(entityConstructor);\n const slots = readEntityTableSlots<TEntity>(children);\n const [panel, setPanel] = useState<Panel>('none');\n\n const { columns, visibleColumns, hidden, setPersonalization } =\n useEntityTableColumns<TEntity>(\n entityConstructor,\n slots.columns,\n items[0],\n `entity-table:${preferencesKey ?? metaEntity.key ?? metaEntity.name}`,\n );\n\n // A picker's table is choosing *one* value; a multi-selection there would\n // offer a set to a form member that holds a single reference, and the two\n // controls would fight over the same row. This is a wiring mistake rather\n // than a state, so it costs the render — the same call `EntityForm` makes\n // for a link source aimed at a member no picker can edit.\n if (onSelect !== undefined && selection !== undefined) {\n throw new Error(\n 'EntityTable was given both `onSelect` and `selection`. A picker picks one ' +\n 'row and a selection accumulates many, so the row control cannot be both. ' +\n 'Drop `selection` inside a picker, or drop `onSelect` outside one.',\n );\n }\n\n /**\n * The selection, or `undefined` when the table is not selectable at all.\n *\n * One value rather than a `selection` prop beside a `selectable` boolean:\n * two of them means every render site has to re-test both, and the second\n * test is unreachable — which reads as a defensive check and is really dead\n * code the coverage gate then cannot close.\n */\n const selectionState =\n selection !== undefined && onSelectionChange !== undefined\n ? selection\n : undefined;\n const selectable = selectionState !== undefined;\n const rowUseCases = useCasesForSurface('row-menu', metadata?.useCases);\n const bulkUseCases = useCasesForSurface('bulk-bar', metadata?.useCases);\n const toolbarUseCases = useCasesForSurface(\n 'table-toolbar',\n metadata?.useCases,\n );\n const hasRowMenu = rowUseCases.length > 0 && onUseCase !== undefined;\n\n /**\n * What a `context-independent` collection verb acts on: everything the\n * current filter matches.\n *\n * Not an empty `ids` selection, which would say \"no rows\" — the verb is\n * available *without* a selection precisely because its subject is the\n * collection, so the honest payload is the same filter the listing is\n * showing, and the same one a \"select all matching\" escalation would send.\n */\n const everythingMatching: EntitySelection<TEntity> = {\n mode: 'matching',\n filtering,\n total: totalItems,\n excluded: new Set<EntityId>(),\n };\n\n // Opening a record is its title's link, so a row needs an actions column\n // only to pick it or to run a verb on it.\n const hasRowAction = onSelect !== undefined || hasRowMenu;\n const columnCount =\n visibleColumns.length + (hasRowAction ? 1 : 0) + (selectable ? 1 : 0);\n\n /**\n * The grid and the cards are both rendered, and a container query on the\n * table's own box picks one — at the width its visible columns need. A\n * viewport breakpoint was wrong inside a split view, a drawer or a wizard\n * step, and a JS measurement would guess during SSR and correct after mount.\n */\n const pivot = pivotClasses(\n pivotWidth(\n visibleColumns,\n (selectable ? SELECTION_WIDTH : 0) + (hasRowAction ? ACTIONS_WIDTH : 0),\n pivotBreakpoint,\n ),\n );\n /**\n * The first load has nothing to show and is held with a skeleton; a refetch\n * already has rows, so it keeps them and only marks the region busy. Splitting\n * the two is what stops every pagination click flashing grey.\n */\n const isFirstLoad = isLoading && items.length === 0;\n\n /** `true`/omitted → the built-in default; a node → that node; `false` → none. */\n const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;\n const showSkeleton = isFirstLoad && skeleton !== false;\n const skeletonRows = Array.from(\n { length: Math.min(pageSize, SKELETON_ROW_CAP) },\n (_, index) => index,\n );\n\n /**\n * A refetch keeps its rows at full contrast and marks them `aria-busy`:\n * dimming them through opacity took the text under the contrast a reader\n * needs, on every page change.\n */\n const busy = isLoading || undefined;\n\n /** The column a row reads *as*: the first non-identifier one it filled in. */\n const titleColumn = (item: TEntity) =>\n visibleColumns.find(column => {\n if (column.type === 'id') return false;\n const value = (item as Record<string, unknown>)[column.name];\n return value != null && String(value) !== '';\n });\n\n /** The column that links to the record: one declared `card: 'title'`, else the row's title. */\n const declaredTitle = visibleColumns.find(column => column.card === 'title');\n const linkColumn = (item: TEntity) => declaredTitle ?? titleColumn(item);\n\n /**\n * What a record's card shows, by each member's declared `card` role or the\n * default: an id is hidden, the first enum is the badge, and up to\n * {@link UNDECLARED_META_CAP} more members are meta — a card is a summary,\n * and the grid holds the rest.\n */\n const firstEnum = visibleColumns.find(\n column => column.card === undefined && column.type === 'enum',\n );\n const roleOf = (column: EntityTableColumn<TEntity>) =>\n column.card ??\n (column.type === 'id' ? 'hidden' : column === firstEnum ? 'badge' : 'meta');\n const cardParts = (item: TEntity) => {\n const title = linkColumn(item);\n const rest = visibleColumns.filter(column => column !== title);\n let undeclared = 0;\n return {\n title,\n subtitle: rest.find(column => roleOf(column) === 'subtitle'),\n badges: rest.filter(column => roleOf(column) === 'badge'),\n meta: rest.filter(column => {\n if (roleOf(column) !== 'meta') return false;\n if (column.card !== undefined) return true;\n undeclared += 1;\n return undeclared <= UNDECLARED_META_CAP;\n }),\n };\n };\n\n const renderValue = (\n column: EntityTableColumn<TEntity>,\n item: TEntity,\n ): ReactNode =>\n column.render ? (\n column.render(item)\n ) : (\n <CellValue\n value={(item as Record<string, unknown>)[column.name]}\n descriptor={column}\n record={item as Record<string, unknown>}\n />\n );\n\n /**\n * A cell, and the row's title cell is the record's link\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n * A column of identical \"Open\" links named nothing, and a reader tabbing\n * down it heard \"Open\" once per row; the title says which record it opens.\n * A picker's rows are chosen, not opened, so they stay plain.\n */\n const renderCell = (\n column: EntityTableColumn<TEntity>,\n item: TEntity,\n ): ReactNode => {\n const value = renderValue(column, item);\n if (hrefFor === undefined || onSelect !== undefined) return value;\n if (linkColumn(item)?.name !== column.name) return value;\n return renderLink({\n href: hrefFor(item.id),\n className: linkClassName,\n children: value,\n intent: { kind: 'open', id: item.id },\n });\n };\n\n /**\n * The row a shift-click ranges *from* — the last box the user actually\n * toggled. Held in a ref rather than state because it changes nothing on\n * screen, and re-rendering the whole table on every click to remember an\n * anchor is a cost with no visible return.\n */\n const anchorIndex = useRef<number | undefined>(undefined);\n\n /**\n * An entity that declares a parent renders as a tree: the page arranged\n * depth first, its first column indented, and a subtree hidden while its\n * record is collapsed. Collapsing is view state, so it lives here and is\n * forgotten with the table, like the shift-click anchor above.\n */\n const treeKeys = useMemo(\n () => hierarchyOf(entityConstructor),\n [entityConstructor],\n );\n const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(\n () => new Set(),\n );\n const rows = useMemo(() => treeRows(items, treeKeys), [items, treeKeys]);\n const shown = shownTreeRows(rows, collapsed);\n const shownItems = shown.map(row => row.item);\n const toggleCollapsed = (key: string) =>\n setCollapsed(current => {\n const next = new Set(current);\n if (next.has(key)) next.delete(key);\n else next.add(key);\n return next;\n });\n\n const setSelection = (next: EntitySelection<TEntity>) =>\n onSelectionChange?.(next);\n\n const toggleRow = (\n index: number,\n checked: boolean,\n shiftKey: boolean,\n current: EntitySelection<TEntity>,\n ) => {\n // A shift-click extends the last toggle across the rows *on this page*, in\n // the direction the user dragged, and applies the new state to all of them.\n const from = shiftKey ? (anchorIndex.current ?? index) : index;\n const [start, end] = from <= index ? [from, index] : [index, from];\n\n let next = current;\n // The rows as shown: in a tree the order on screen is not the load's.\n for (const row of shownItems.slice(start, end + 1)) {\n next = toggleSelected(next, row.id, checked);\n }\n\n anchorIndex.current = index;\n setSelection(next);\n };\n\n /**\n * The header box, and it has three states rather than two: none of this\n * page's rows selected, all of them, or some. Without the third the box\n * reads as \"nothing is selected\" while a bulk bar sits below it saying\n * otherwise.\n */\n const pageIds = items.map(item => item.id);\n const selectedOnPage = selectionState\n ? pageIds.filter(id => isSelected(selectionState, id)).length\n : 0;\n const allOnPageSelected =\n pageIds.length > 0 && selectedOnPage === pageIds.length;\n const someOnPageSelected = selectedOnPage > 0 && !allOnPageSelected;\n\n const toggleAllOnPage = (\n checked: boolean,\n current: EntitySelection<TEntity>,\n ) => {\n let next = current;\n for (const id of pageIds) next = toggleSelected(next, id, checked);\n anchorIndex.current = undefined;\n setSelection(next);\n };\n\n /**\n * How a row names itself to a screen reader.\n *\n * The first visible column's value, because that is what the user reads the\n * row *as* — \"Seleccionar Acme\" rather than \"Seleccionar fila 3\", which tells\n * them the position they can already see and not the thing they cannot.\n */\n const rowLabel = (item: TEntity): string => {\n // The first non-identifier column **that this row actually filled in**.\n //\n // An id names a row the way \"row 3\" does: it repeats what the user can\n // already see. But skipping only the id is not enough — measured against\n // the seeded catalog, where `code` is the first non-id column and is empty\n // on every brand, so the label fell straight through to the id and never\n // reached `name`. A column that is blank on this row names it no better\n // than its position does, so the search continues past it.\n //\n // The id remains the last resort, because a row with nothing rendered\n // still has to announce itself.\n const named = titleColumn(item);\n\n return named\n ? String((item as Record<string, unknown>)[named.name])\n : String(item.id);\n };\n\n const selectionCell = (\n item: TEntity,\n index: number,\n // Passed in rather than closed over: this is only ever called under\n // `selectable`, which already proves the selection exists, and reading the\n // optional prop here would add a fallback arm that nothing can reach.\n current: EntitySelection<TEntity>,\n ) => (\n <Checkbox\n // Deliberately no `id`: both pivots are always in the DOM, so an id here\n // would be emitted twice per row. `aria-label` names the control instead,\n // and it names the *record* rather than the position.\n aria-label={t('table.selectRow', { record: rowLabel(item) })}\n checked={isSelected(current, item.id)}\n disabled={isBulkRunning}\n onChange={event =>\n toggleRow(\n index,\n event.currentTarget.checked,\n (event.nativeEvent as MouseEvent).shiftKey === true,\n current,\n )\n }\n />\n );\n\n const runTarget = (key: string, target: PendingTarget<TEntity>) => {\n if (target.kind === 'row') onUseCase?.(key, target.item);\n else onBulkUseCase?.(key, target.selection);\n };\n\n /**\n * Every verb on the table goes through here — the row menu, the bulk bar and\n * the toolbar — so none reaches a destructive verb around its confirmation,\n * its typed check or its Undo.\n */\n const verbs = useVerbInvoker<PendingTarget<TEntity>>({\n run: runTarget,\n busy: isBulkRunning,\n served: metadata?.useCases,\n });\n\n // The row a verb last ran on. Its menu trigger unmounts when the verb moved\n // the record out of every state a row verb applies to, and focus then goes\n // to that row's own link or control rather than `<body>`.\n const rowScope = useId();\n const [lastRow, setLastRow] = useState<string | undefined>(undefined);\n useFocusOnLoss(\n () =>\n lastRow === undefined ? undefined : focusableIn(`${rowScope}${lastRow}`),\n shown\n .map(({ item }) =>\n availableUseCases(rowUseCases, item)\n .map(({ key }) => key)\n .join(','),\n )\n .join(' '),\n );\n\n const invoke = (\n useCase: UseCaseDescriptor,\n target: PendingTarget<TEntity>,\n ) => {\n if (target.kind === 'row') {\n setLastRow(String(target.item.id));\n verbs.invoke({\n descriptor: useCase,\n target,\n object: rowLabel(target.item),\n count: 1,\n });\n return;\n }\n const count = selectionSize(target.selection);\n verbs.invoke({\n descriptor: useCase,\n target,\n object: t('confirm.selection', {\n count,\n label: entityNoun(metaEntity),\n plural: entityNoun(metaEntity, 'plural'),\n }),\n count,\n matching: target.selection.mode === 'matching',\n });\n };\n\n const rowMenu = (item: TEntity) =>\n hasRowMenu ? (\n <ActionBar\n surface=\"row-menu\"\n menuLabel={t('actions.forRecord', { record: rowLabel(item) })}\n items={itemsForUseCases(\n availableUseCases(rowUseCases, item),\n translateKey,\n useCase => invoke(useCase, { kind: 'row', item }),\n )}\n />\n ) : undefined;\n\n /**\n * A picker's Select, then the row's verbs. Opening the record is not here:\n * it is the title's link.\n */\n const recordAction = (item: TEntity) => {\n const pick = onSelect ? (\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n onClick={() => onSelect(item)}\n >\n {t('table.select')}\n </Button>\n ) : undefined;\n\n const menu = rowMenu(item);\n if (!menu) return pick;\n\n return (\n <span className=\"flex items-center gap-2xs\">\n {pick}\n {menu}\n </span>\n );\n };\n\n /**\n * \"New\" is the list's primary, and only where something can be created\n * here: the entity is not one only a flow writes (`creatable: false`), and\n * the caller may write it. A list that offered \"New\" to a reader who could\n * never save opened a form with no Save on it.\n */\n const mayCreate =\n newHref !== undefined &&\n metaEntity.creatable &&\n (metadata === undefined || metadata.actions.includes('write'));\n const toolbarItems: ActionBarItem[] = itemsForUseCases(\n toolbarUseCases,\n translateKey,\n useCase =>\n invoke(useCase, { kind: 'selection', selection: everythingMatching }),\n isBulkRunning,\n );\n const declaresToolbarPrimary = toolbarItems.some(\n item => item.emphasis === 'primary',\n );\n const toolbarActions: ActionBarItem[] = [\n ...(mayCreate\n ? [\n {\n key: 'new',\n label: t('table.new'),\n emphasis: declaresToolbarPrimary\n ? ('default' as const)\n : ('primary' as const),\n href: newHref,\n intent: { kind: 'new' as const },\n },\n ]\n : []),\n ...toolbarItems,\n ];\n\n const locale = useLocale();\n const panelId = useId();\n const keys = sortKeys(sorting, columns);\n const activeFilters = filtering?.values.length ?? 0;\n const results = t('table.results', { count: totalItems });\n\n /**\n * What the status region says once a filter, a sort or a page has settled —\n * debounced, and silent on the first load.\n */\n const announcement = useResultAnnouncement(\n !isLoading,\n totalItems === 0 && activeFilters > 0\n ? t('table.noResultsFiltered')\n : results,\n JSON.stringify([filtering, sorting, currentPage, pageSize]),\n );\n\n /** The caption: what the table holds, how many, and in what order. */\n const primaryKey = keys[0];\n const primaryColumn =\n primaryKey === undefined\n ? undefined\n : columns.find(column => column.name === primaryKey.member);\n const caption =\n primaryKey === undefined || primaryColumn === undefined\n ? t('table.caption', {\n entity: entityNoun(metaEntity, 'plural'),\n results,\n })\n : t('table.captionSorted', {\n entity: entityNoun(metaEntity, 'plural'),\n results,\n column: primaryColumn.label,\n direction: t(\n primaryKey.type === 'asc' ? 'sort.ascending' : 'sort.descending',\n ),\n });\n\n /**\n * A column's header: its name, and — for a sortable one — a button that\n * cycles it ascending → descending → unsorted, with Shift adding it as the\n * next key. Only the primary key carries `aria-sort`.\n */\n const headerCell = (column: EntityTableColumn<TEntity>) => {\n const label = column.header ?? column.label;\n if (!column.sortable || onSortingChange === undefined)\n return <TableHeaderCell key={column.name}>{label}</TableHeaderCell>;\n const position = keys.findIndex(key => key.member === column.name);\n const type = keys[position]?.type;\n return (\n <TableHeaderCell\n key={column.name}\n aria-sort={\n position === 0\n ? type === 'asc'\n ? 'ascending'\n : 'descending'\n : undefined\n }\n >\n <button\n type=\"button\"\n className=\"inline-flex min-h-(--target-min) items-center gap-3xs rounded-sm focus-ring hover:text-content\"\n onClick={event =>\n onSortingChange(\n nextHeaderSorting<TEntity>(\n keys,\n {\n member: column.name,\n property: queryPropertyFor(column, locale),\n },\n event.shiftKey,\n ),\n )\n }\n >\n {label}\n <span aria-hidden=\"true\">\n {type === 'asc' ? '▲' : type === 'desc' ? '▼' : '↕'}\n </span>\n {keys.length > 1 && position >= 0 && (\n <span aria-hidden=\"true\" className=\"text-step-sm\">\n {position + 1}\n </span>\n )}\n </button>\n </TableHeaderCell>\n );\n };\n\n /** A panel toggle: its state said by `aria-expanded`, and its count shown. */\n const panelToggle = (which: Exclude<Panel, 'none'>, count: number) => (\n <Button\n type=\"button\"\n variant={panel === which ? 'primary' : 'secondary'}\n size=\"sm\"\n aria-expanded={panel === which}\n aria-controls={panelId}\n onClick={() => setPanel(current => (current === which ? 'none' : which))}\n >\n {t(which === 'filters' ? 'table.filters' : 'table.sorting')}\n {count > 0 && (\n // Its name stays \"Filters\": the chips say which filters, and a count\n // in the name would change it under the reader with every filter.\n <span\n aria-hidden=\"true\"\n className=\"ms-3xs rounded-full bg-surface px-3xs text-step-sm text-content\"\n >\n {count}\n </span>\n )}\n </Button>\n );\n\n return (\n <div className=\"@container/entity-table flex flex-col gap-s\">\n {/*\n One announcement for the whole table, not one per layout. Both the grid\n and the card list are always in the DOM — CSS picks which is visible —\n so a live region inside each meant assistive tech was told twice that\n the table was loading. The shimmer itself is aria-hidden, so this is the\n only thing that carries the news.\n */}\n <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {isFirstLoad ? t('table.loading') : announcement}\n </span>\n\n {showControls && (\n <TableToolbar\n start={\n <>\n {/* \"New\" and the collection-bound verbs that need no\n selection. They sit here rather than in the bulk bar,\n because the bulk bar only exists while rows are ticked and\n these are always available. */}\n <LoadingBoundary isLoading={isMetadataLoading} lines={0}>\n <>\n {toolbarActions.length > 0 && (\n <ActionBar\n surface=\"table-toolbar\"\n items={toolbarActions}\n renderLink={renderLink}\n />\n )}\n </>\n </LoadingBoundary>\n {slots.toolbar}\n </>\n }\n end={\n <>\n {panelToggle('filters', activeFilters)}\n {panelToggle('sorting', keys.length)}\n <ColumnSettings\n columns={columns}\n hidden={hidden}\n onChange={setPersonalization}\n />\n </>\n }\n panelId={panelId}\n panel={\n panel === 'filters' ? (\n <FilterBuilder<TEntity>\n // Remounted when the filtering changes from outside — a chip\n // removed — so its rows show what is in effect.\n key={JSON.stringify(filtering ?? null)}\n descriptors={columns.filter(column => column.filterable)}\n facets={facets}\n value={filtering}\n onChange={(applied: FilterGroup<TEntity>) =>\n onFilteringChange?.(applied)\n }\n />\n ) : panel === 'sorting' ? (\n <SortBuilder<TEntity>\n descriptors={columns.filter(column => column.sortable)}\n value={sorting}\n onChange={(applied: EntitySorting<TEntity>) =>\n onSortingChange?.(applied)\n }\n />\n ) : undefined\n }\n />\n )}\n\n {showControls && onFilteringChange !== undefined && (\n <FilterChips<TEntity>\n descriptors={columns.filter(column => column.filterable)}\n value={filtering}\n onChange={onFilteringChange}\n />\n )}\n\n {/*\n The bar appears when there is something selected and something to do\n with it. It sits above the rows rather than floating over them: a fixed\n overlay covers the last row of a short page, which is the row the user\n most likely just ticked.\n */}\n {selectionState && selectionSize(selectionState) > 0 && (\n <BulkActionBar\n count={selectionSize(selectionState)}\n useCases={bulkUseCases}\n busy={isBulkRunning}\n // Offered only when this page is fully ticked and the store holds\n // more than the page — the escalation has somewhere to escalate to.\n matchingTotal={\n selectionState.mode === 'ids' &&\n allOnPageSelected &&\n totalItems > items.length\n ? totalItems\n : undefined\n }\n onSelectAllMatching={() => setSelection(everythingMatching)}\n onClear={() => setSelection(emptySelection<TEntity>())}\n onUseCase={useCase =>\n invoke(useCase, { kind: 'selection', selection: selectionState })\n }\n />\n )}\n\n {verbs.dialog}\n\n {bulkOutcomes && bulkOutcomes.length > 0 && onBulkDismiss && (\n <BulkResult\n outcomes={bulkOutcomes}\n busy={isBulkRunning}\n labelFor={id => {\n const row = items.find(item => item.id === id);\n return row ? rowLabel(row) : undefined;\n }}\n onRetryFailed={onBulkRetry}\n onDismiss={onBulkDismiss}\n />\n )}\n\n {/*\n Rendered once, outside both layouts, and independently of whether there\n are rows: a refetch that fails leaves the previous page on screen, and\n without this the user would read stale data as current.\n */}\n {/*\n One state for the region, outside both layouts (ADR 0028): a failed\n load with Retry — and the rows from before it marked as possibly out of\n date — or an empty answer, which says whether a filter emptied it.\n */}\n <RegionState\n plural={entityNoun(metaEntity, 'plural')}\n isLoading={isLoading}\n error={error}\n onRetry={onRetry}\n hasStaleData={items.length > 0}\n isEmpty={items.length === 0}\n isFiltered={activeFilters > 0}\n onClearFilters={\n onFilteringChange === undefined\n ? undefined\n : () =>\n onFilteringChange({\n // Only offered under a filter, so there is one to keep the\n // logic of.\n operator: (filtering as FilterGroup<TEntity>).operator,\n values: [],\n })\n }\n emptyAction={\n mayCreate\n ? renderLink({\n href: newHref as string,\n className: button({ variant: 'primary' }),\n children: t('table.new'),\n intent: { kind: 'new' },\n })\n : undefined\n }\n />\n\n {/* Wide viewports: a grid. */}\n <div className={pivot.grid} aria-busy={busy}>\n {/* Held to most of the viewport so the header can stick above the\n rows; the scroll padding keeps a focused row out from under it. */}\n <Table\n caption={caption}\n containerClassName=\"max-h-(--table-max-block) scroll-pt-12\"\n >\n <TableHead>\n {slots.header ? (\n slots.header.render(visibleColumns)\n ) : (\n <tr>\n {selectable && (\n <TableHeaderCell>\n <Checkbox\n aria-label={t('table.selectAllOnPage')}\n checked={allOnPageSelected}\n indeterminate={someOnPageSelected}\n disabled={isBulkRunning || items.length === 0}\n onChange={event =>\n toggleAllOnPage(\n event.currentTarget.checked,\n selectionState,\n )\n }\n />\n </TableHeaderCell>\n )}\n {visibleColumns.map(headerCell)}\n {hasRowAction && (\n <TableHeaderCell>{t('table.actions')}</TableHeaderCell>\n )}\n </tr>\n )}\n </TableHead>\n <TableBody>\n {/* Skeleton rows rather than the word \"Loading\", and one per column\n rather than a single full-width blob: the placeholder occupies\n the real grid, so the swap to rows shifts nothing sideways.\n `TableMessageRow` is deliberately bypassed — it is one centred\n full-span cell and cannot express the geometry. */}\n {showSkeleton &&\n (customSkeleton ? (\n <TableMessageRow colSpan={columnCount}>\n {customSkeleton}\n </TableMessageRow>\n ) : (\n skeletonRows.map(row => (\n <TableRow key={row}>\n {selectable && (\n <TableCell>\n <Skeleton shape=\"line\" className=\"w-4\" />\n </TableCell>\n )}\n {visibleColumns.map(column => (\n <TableCell key={column.name}>\n <Skeleton shape=\"line\" className=\"w-full\" />\n </TableCell>\n ))}\n {hasRowAction && (\n <TableCell>\n <Skeleton shape=\"line\" className=\"w-16\" />\n </TableCell>\n )}\n </TableRow>\n ))\n ))}\n {shown.map(({ item, depth, hasChildren }, index) =>\n slots.row ? (\n // A Fragment carries the key without wrapping the custom row in\n // an element `<tbody>` would reject.\n <Fragment key={String(item.id ?? index)}>\n {slots.row.render(item, visibleColumns)}\n </Fragment>\n ) : (\n <TableRow\n key={String(item.id ?? index)}\n data-record-id={`${rowScope}${String(item.id)}`}\n >\n {selectionState && (\n <TableCell>\n {selectionCell(item, index, selectionState)}\n </TableCell>\n )}\n {visibleColumns.map((column, columnIndex) => (\n <TableCell key={column.name}>\n {treeKeys !== undefined && columnIndex === 0 ? (\n <TreeCell\n depth={depth}\n hasChildren={hasChildren}\n expanded={!collapsed.has(treeKeys.idOf(item))}\n label={t(\n collapsed.has(treeKeys.idOf(item))\n ? 'table.expandRow'\n : 'table.collapseRow',\n { record: rowLabel(item) },\n )}\n onToggle={() => toggleCollapsed(treeKeys.idOf(item))}\n >\n {renderCell(column, item)}\n </TreeCell>\n ) : (\n renderCell(column, item)\n )}\n </TableCell>\n ))}\n {hasRowAction && <TableCell>{recordAction(item)}</TableCell>}\n </TableRow>\n ),\n )}\n </TableBody>\n </Table>\n </div>\n\n {/* Narrow containers: the same columns pivoted into a list of cards. */}\n <div className={pivot.cards} aria-busy={busy}>\n {/* The card pivot gets card-shaped placeholders, not a bare shimmer\n block: the border, radius and padding are the geometry here. */}\n {showSkeleton &&\n (customSkeleton ?? (\n <ul role=\"list\" className=\"m-0 p-0 flex list-none flex-col gap-2xs\">\n {skeletonRows.map(row => (\n <li key={row}>\n <EntityRecordCard\n title={<Skeleton shape=\"line\" className=\"w-32\" />}\n meta={visibleColumns.slice(1).map(column => ({\n key: column.name,\n label: column.label,\n value: <Skeleton shape=\"line\" className=\"w-24\" />,\n }))}\n />\n </li>\n ))}\n </ul>\n ))}\n {shown.length > 0 && (\n <ul role=\"list\" className=\"m-0 p-0 flex list-none flex-col gap-2xs\">\n {shown.map(({ item, depth }, index) => {\n const parts = cardParts(item);\n return (\n <li\n key={String(item.id ?? index)}\n data-record-id={`${rowScope}${String(item.id)}`}\n // A tree's card says how deep it sits, as its row does.\n aria-level={treeKeys === undefined ? undefined : depth + 1}\n style={\n treeKeys === undefined\n ? undefined\n : { marginInlineStart: `${depth * 1.5}rem` }\n }\n >\n <EntityRecordCard\n // The same renderers as the grid, so the two layouts agree.\n title={\n parts.title === undefined\n ? rowLabel(item)\n : renderCell(parts.title, item)\n }\n subtitle={\n parts.subtitle === undefined\n ? undefined\n : renderCell(parts.subtitle, item)\n }\n badges={parts.badges.map(column => ({\n key: column.name,\n value: renderCell(column, item),\n }))}\n meta={parts.meta.map(column => ({\n key: column.name,\n label: column.header ?? column.label,\n value: renderCell(column, item),\n }))}\n leading={\n selectionState\n ? selectionCell(item, index, selectionState)\n : undefined\n }\n actions={recordAction(item)}\n />\n </li>\n );\n })}\n </ul>\n )}\n </div>\n\n <Pagination\n currentPage={currentPage}\n pageSize={pageSize}\n totalItems={totalItems}\n onPageChange={onPageChange}\n onPageSizeChange={onPageSizeChange}\n />\n\n {slots.rest}\n </div>\n );\n}\n\n/**\n * The first control in a record's row or card that the reader can see. Both\n * layouts are in the DOM and CSS shows one, so a control inside the hidden\n * one is skipped. `scoped` is the record's id under this table's own prefix,\n * so a second table on the page holding the same record is never reached.\n */\nfunction focusableIn(scoped: string): HTMLElement | undefined {\n return [\n ...document.querySelectorAll<HTMLElement>(\n `[data-record-id=\"${CSS.escape(scoped)}\"] :is(a[href], button)`,\n ),\n ].find(\n control =>\n // `checkVisibility` is recent; a browser without it is asked for the\n // boxes the control lays out, which a `display: none` layout has none of.\n control.checkVisibility?.() ?? control.getClientRects().length > 0,\n );\n}\n"],"names":["emptySelection","extractMetaEntity","hierarchyOf","isSelected","queryPropertyFor","selectionSize","toggleSelected","Fragment","useId","useMemo","useRef","useState","useEntityNoun","useLocale","useT","useTranslateKey","availableUseCases","renderAnchor","useCasesForSurface","useVerbInvoker","Button","button","CellValue","Checkbox","Skeleton","Table","TableBody","TableCell","TableHead","TableHeaderCell","TableMessageRow","TableRow","linkClassName","ActionBar","itemsForUseCases","BulkActionBar","BulkResult","ColumnSettings","EntityRecordCard","FilterBuilder","FilterChips","LoadingBoundary","Pagination","RegionState","SortBuilder","TableToolbar","useFocusOnLoss","readEntityTableSlots","shownTreeRows","TreeCell","treeRows","nextHeaderSorting","sortKeys","ACTIONS_WIDTH","pivotClasses","pivotWidth","SELECTION_WIDTH","useEntityTableColumns","useResultAnnouncement","SKELETON_ROW_CAP","UNDECLARED_META_CAP","EntityTable","entityConstructor","isLoading","skeleton","error","items","totalItems","currentPage","pageSize","onPageChange","onPageSizeChange","hrefFor","newHref","renderLink","onSelect","preferencesKey","showControls","pivotBreakpoint","filtering","sorting","onFilteringChange","onSortingChange","facets","selection","onSelectionChange","metadata","isMetadataLoading","onBulkUseCase","onUseCase","onRetry","bulkOutcomes","onBulkDismiss","onBulkRetry","isBulkRunning","children","t","translateKey","entityNoun","metaEntity","slots","panel","setPanel","columns","visibleColumns","hidden","setPersonalization","key","name","undefined","Error","selectionState","selectable","rowUseCases","useCases","bulkUseCases","toolbarUseCases","hasRowMenu","length","everythingMatching","mode","total","excluded","Set","hasRowAction","columnCount","pivot","isFirstLoad","customSkeleton","showSkeleton","skeletonRows","Array","from","Math","min","_","index","busy","titleColumn","item","find","column","type","value","String","declaredTitle","card","linkColumn","firstEnum","roleOf","cardParts","title","rest","filter","undeclared","subtitle","badges","meta","renderValue","render","descriptor","record","renderCell","href","id","className","intent","kind","anchorIndex","treeKeys","collapsed","setCollapsed","rows","shown","shownItems","map","row","toggleCollapsed","current","next","has","delete","add","setSelection","toggleRow","checked","shiftKey","start","end","slice","pageIds","selectedOnPage","allOnPageSelected","someOnPageSelected","toggleAllOnPage","rowLabel","named","selectionCell","aria-label","disabled","onChange","event","currentTarget","nativeEvent","runTarget","target","verbs","run","served","rowScope","lastRow","setLastRow","focusableIn","join","invoke","useCase","object","count","label","plural","matching","rowMenu","surface","menuLabel","recordAction","pick","variant","size","onClick","menu","span","mayCreate","creatable","actions","includes","toolbarItems","declaresToolbarPrimary","some","emphasis","toolbarActions","locale","panelId","keys","activeFilters","values","results","announcement","JSON","stringify","primaryKey","primaryColumn","member","caption","entity","direction","headerCell","header","sortable","position","findIndex","aria-sort","property","aria-hidden","panelToggle","which","aria-expanded","aria-controls","div","role","aria-live","lines","toolbar","descriptors","filterable","applied","matchingTotal","onSelectAllMatching","onClear","dialog","outcomes","labelFor","onRetryFailed","onDismiss","hasStaleData","isEmpty","isFiltered","onClearFilters","operator","emptyAction","grid","aria-busy","containerClassName","tr","indeterminate","colSpan","shape","depth","hasChildren","data-record-id","columnIndex","expanded","idOf","onToggle","cards","ul","li","parts","aria-level","style","marginInlineStart","leading","scoped","document","querySelectorAll","CSS","escape","control","checkVisibility","getClientRects"],"mappings":"AAAA;;AAEA,SACEA,cAAc,EAKdC,iBAAiB,EAEjBC,WAAW,EACXC,UAAU,EACVC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,QAET,gBAAgB;AACvB,SACEC,QAAQ,EAERC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SACEC,aAAa,EACbC,SAAS,EACTC,IAAI,EACJC,eAAe,QACV,yBAAyB;AAChC,SACEC,iBAAiB,EACjBC,YAAY,EACZC,kBAAkB,QACb,yBAAyB;AAChC,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,MAAM,EAAEC,MAAM,QAAQ,8BAA8B;AAC7D,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,QAAQ,QAAQ,6BAA6B;AACtD,SAASC,QAAQ,QAAQ,gCAAgC;AACzD,SACEC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,eAAe,EACfC,e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OAAO6E,KAAK;4CACpC3E,OAAOmB,WAAWrB,QAAQF;wCAC5B;;oCACA2K,SACEvM,iBACIsF,cAAc1D,MAAMH,OAAOzB,kBAC3BF;oCAEN4H,SAAST,aAAarF;;+BApCnBK,QAAOL,WAAAA,KAAKyB,EAAE,YAAPzB,WAAWH;wBAwC7B;;;;0BAKN,KAAC9F;gBACC0B,aAAaA;gBACbC,UAAUA;gBACVF,YAAYA;gBACZG,cAAcA;gBACdC,kBAAkBA;;YAGnB6B,MAAMoD,IAAI;;;AAGjB;AAEA;;;;;CAKC,GACD,SAAS4D,YAAYmG,MAAc;IACjC,OAAO;WACFC,SAASC,gBAAgB,CAC1B,CAAC,iBAAiB,EAAEC,IAAIC,MAAM,CAACJ,QAAQ,uBAAuB,CAAC;KAElE,CAAC3K,IAAI,CACJgL,CAAAA;;uBACE,qEAAqE;QACrE,0EAA0E;QAC1EA,QAAQC,eAAe,oBAAvBD,QAAQC,eAAe,MAAvBD,2BAA+BA,QAAQE,cAAc,GAAGxM,MAAM,GAAG;;AAEvE"}
|
|
@@ -11,4 +11,15 @@ export declare const resetArrivalForTesting: () => void;
|
|
|
11
11
|
* focus is on something — a tab they clicked — it stays there.
|
|
12
12
|
*/
|
|
13
13
|
export declare function useFocusOnArrival(heading: RefObject<HTMLElement | null>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Keeps focus off `<body>` when the control holding it goes away under the
|
|
16
|
+
* reader: a verb that ran and moved its record into a state the verb no longer
|
|
17
|
+
* applies to unmounts the very button that was focused, and the browser drops
|
|
18
|
+
* focus to the document. Each time `revision` changes — the set of verbs on
|
|
19
|
+
* show — focus goes to `target()`, but **only** when the element that last held
|
|
20
|
+
* it has left the document and nothing has taken focus since. A revision that
|
|
21
|
+
* removed nothing the reader was on moves nothing, so a live update to some
|
|
22
|
+
* other row never pulls focus around.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useFocusOnLoss(target: () => HTMLElement | null | undefined, revision: string): void;
|
|
14
25
|
//# sourceMappingURL=use-focus-on-arrival.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-focus-on-arrival.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/use-focus-on-arrival.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"use-focus-on-arrival.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/use-focus-on-arrival.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAA6B,MAAM,OAAO,CAAC;AAgClE,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,YAGlC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACrC,IAAI,CAON;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,EAC5C,QAAQ,EAAE,MAAM,GACf,IAAI,CAQN"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useEffect, useEffectEvent } from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Whether the reader has pressed a key or a pointer in this document yet. A
|
|
5
5
|
* page that mounts before that is the one they loaded, and its focus is the
|
|
6
6
|
* browser's to place; one that mounts after was reached by doing something.
|
|
7
7
|
*/ let interacted = false;
|
|
8
|
+
/**
|
|
9
|
+
* The element that last took focus, whatever it was. `focusin` always fires on
|
|
10
|
+
* the way in, while nothing reliable fires when a focused element is removed —
|
|
11
|
+
* so this is what tells a dropped focus from one that was never anywhere.
|
|
12
|
+
*/ let lastFocused;
|
|
8
13
|
/* v8 ignore next -- a server render has no document to listen on */ if (typeof document !== 'undefined') {
|
|
9
14
|
const mark = ()=>{
|
|
10
15
|
interacted = true;
|
|
@@ -15,9 +20,15 @@ import { useEffect } from 'react';
|
|
|
15
20
|
document.addEventListener('keydown', mark, {
|
|
16
21
|
capture: true
|
|
17
22
|
});
|
|
23
|
+
document.addEventListener('focusin', (event)=>{
|
|
24
|
+
lastFocused = event.target;
|
|
25
|
+
}, {
|
|
26
|
+
capture: true
|
|
27
|
+
});
|
|
18
28
|
}
|
|
19
29
|
/** For specs: the document as it was before anyone touched it. */ export const resetArrivalForTesting = ()=>{
|
|
20
30
|
interacted = false;
|
|
31
|
+
lastFocused = undefined;
|
|
21
32
|
};
|
|
22
33
|
/**
|
|
23
34
|
* Moves focus to a region's heading when the region arrives under a reader
|
|
@@ -38,5 +49,26 @@ import { useEffect } from 'react';
|
|
|
38
49
|
heading
|
|
39
50
|
]);
|
|
40
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Keeps focus off `<body>` when the control holding it goes away under the
|
|
54
|
+
* reader: a verb that ran and moved its record into a state the verb no longer
|
|
55
|
+
* applies to unmounts the very button that was focused, and the browser drops
|
|
56
|
+
* focus to the document. Each time `revision` changes — the set of verbs on
|
|
57
|
+
* show — focus goes to `target()`, but **only** when the element that last held
|
|
58
|
+
* it has left the document and nothing has taken focus since. A revision that
|
|
59
|
+
* removed nothing the reader was on moves nothing, so a live update to some
|
|
60
|
+
* other row never pulls focus around.
|
|
61
|
+
*/ export function useFocusOnLoss(target, revision) {
|
|
62
|
+
const refocus = useEffectEvent(()=>{
|
|
63
|
+
var _target;
|
|
64
|
+
const active = document.activeElement;
|
|
65
|
+
if (active !== null && active !== document.body) return;
|
|
66
|
+
if (lastFocused === undefined || lastFocused.isConnected) return;
|
|
67
|
+
(_target = target()) == null ? void 0 : _target.focus();
|
|
68
|
+
});
|
|
69
|
+
useEffect(()=>refocus(), [
|
|
70
|
+
revision
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
41
73
|
|
|
42
74
|
//# sourceMappingURL=use-focus-on-arrival.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/utils/use-focus-on-arrival.ts"],"sourcesContent":["'use client';\n\nimport { type RefObject, useEffect } from 'react';\n\n/**\n * Whether the reader has pressed a key or a pointer in this document yet. A\n * page that mounts before that is the one they loaded, and its focus is the\n * browser's to place; one that mounts after was reached by doing something.\n */\nlet interacted = false;\n\n/* v8 ignore next -- a server render has no document to listen on */\nif (typeof document !== 'undefined') {\n const mark = () => {\n interacted = true;\n };\n document.addEventListener('pointerdown', mark, { capture: true });\n document.addEventListener('keydown', mark, { capture: true });\n}\n\n/** For specs: the document as it was before anyone touched it. */\nexport const resetArrivalForTesting = () => {\n interacted = false;\n};\n\n/**\n * Moves focus to a region's heading when the region arrives under a reader\n * whose focus was dropped — a save that returned to the list, a delete, a\n * wizard handing off to the record it made — so it never rests on `<body>`\n * (ADR 0028). The heading needs `tabIndex={-1}`.\n *\n * Only then: on the page the reader loaded nothing has been dropped, and where\n * focus is on something — a tab they clicked — it stays there.\n */\nexport function useFocusOnArrival(\n heading: RefObject<HTMLElement | null>,\n): void {\n useEffect(() => {\n if (!interacted) return;\n const active = document.activeElement;\n if (active !== null && active !== document.body) return;\n heading.current?.focus();\n }, [heading]);\n}\n"],"names":["useEffect","interacted","document","mark","addEventListener","capture","resetArrivalForTesting","useFocusOnArrival","heading","active","activeElement","body","current","focus"],"mappings":"AAAA;AAEA,SAAyBA,SAAS,QAAQ,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/utils/use-focus-on-arrival.ts"],"sourcesContent":["'use client';\n\nimport { type RefObject, useEffect, useEffectEvent } from 'react';\n\n/**\n * Whether the reader has pressed a key or a pointer in this document yet. A\n * page that mounts before that is the one they loaded, and its focus is the\n * browser's to place; one that mounts after was reached by doing something.\n */\nlet interacted = false;\n\n/**\n * The element that last took focus, whatever it was. `focusin` always fires on\n * the way in, while nothing reliable fires when a focused element is removed —\n * so this is what tells a dropped focus from one that was never anywhere.\n */\nlet lastFocused: Element | undefined;\n\n/* v8 ignore next -- a server render has no document to listen on */\nif (typeof document !== 'undefined') {\n const mark = () => {\n interacted = true;\n };\n document.addEventListener('pointerdown', mark, { capture: true });\n document.addEventListener('keydown', mark, { capture: true });\n document.addEventListener(\n 'focusin',\n event => {\n lastFocused = event.target as Element;\n },\n { capture: true },\n );\n}\n\n/** For specs: the document as it was before anyone touched it. */\nexport const resetArrivalForTesting = () => {\n interacted = false;\n lastFocused = undefined;\n};\n\n/**\n * Moves focus to a region's heading when the region arrives under a reader\n * whose focus was dropped — a save that returned to the list, a delete, a\n * wizard handing off to the record it made — so it never rests on `<body>`\n * (ADR 0028). The heading needs `tabIndex={-1}`.\n *\n * Only then: on the page the reader loaded nothing has been dropped, and where\n * focus is on something — a tab they clicked — it stays there.\n */\nexport function useFocusOnArrival(\n heading: RefObject<HTMLElement | null>,\n): void {\n useEffect(() => {\n if (!interacted) return;\n const active = document.activeElement;\n if (active !== null && active !== document.body) return;\n heading.current?.focus();\n }, [heading]);\n}\n\n/**\n * Keeps focus off `<body>` when the control holding it goes away under the\n * reader: a verb that ran and moved its record into a state the verb no longer\n * applies to unmounts the very button that was focused, and the browser drops\n * focus to the document. Each time `revision` changes — the set of verbs on\n * show — focus goes to `target()`, but **only** when the element that last held\n * it has left the document and nothing has taken focus since. A revision that\n * removed nothing the reader was on moves nothing, so a live update to some\n * other row never pulls focus around.\n */\nexport function useFocusOnLoss(\n target: () => HTMLElement | null | undefined,\n revision: string,\n): void {\n const refocus = useEffectEvent(() => {\n const active = document.activeElement;\n if (active !== null && active !== document.body) return;\n if (lastFocused === undefined || lastFocused.isConnected) return;\n target()?.focus();\n });\n useEffect(() => refocus(), [revision]);\n}\n"],"names":["useEffect","useEffectEvent","interacted","lastFocused","document","mark","addEventListener","capture","event","target","resetArrivalForTesting","undefined","useFocusOnArrival","heading","active","activeElement","body","current","focus","useFocusOnLoss","revision","refocus","isConnected"],"mappings":"AAAA;AAEA,SAAyBA,SAAS,EAAEC,cAAc,QAAQ,QAAQ;AAElE;;;;CAIC,GACD,IAAIC,aAAa;AAEjB;;;;CAIC,GACD,IAAIC;AAEJ,kEAAkE,GAClE,IAAI,OAAOC,aAAa,aAAa;IACnC,MAAMC,OAAO;QACXH,aAAa;IACf;IACAE,SAASE,gBAAgB,CAAC,eAAeD,MAAM;QAAEE,SAAS;IAAK;IAC/DH,SAASE,gBAAgB,CAAC,WAAWD,MAAM;QAAEE,SAAS;IAAK;IAC3DH,SAASE,gBAAgB,CACvB,WACAE,CAAAA;QACEL,cAAcK,MAAMC,MAAM;IAC5B,GACA;QAAEF,SAAS;IAAK;AAEpB;AAEA,gEAAgE,GAChE,OAAO,MAAMG,yBAAyB;IACpCR,aAAa;IACbC,cAAcQ;AAChB,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,SAASC,kBACdC,OAAsC;IAEtCb,UAAU;YAIRa;QAHA,IAAI,CAACX,YAAY;QACjB,MAAMY,SAASV,SAASW,aAAa;QACrC,IAAID,WAAW,QAAQA,WAAWV,SAASY,IAAI,EAAE;SACjDH,mBAAAA,QAAQI,OAAO,qBAAfJ,iBAAiBK,KAAK;IACxB,GAAG;QAACL;KAAQ;AACd;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASM,eACdV,MAA4C,EAC5CW,QAAgB;IAEhB,MAAMC,UAAUpB,eAAe;YAI7BQ;QAHA,MAAMK,SAASV,SAASW,aAAa;QACrC,IAAID,WAAW,QAAQA,WAAWV,SAASY,IAAI,EAAE;QACjD,IAAIb,gBAAgBQ,aAAaR,YAAYmB,WAAW,EAAE;SAC1Db,UAAAA,6BAAAA,QAAUS,KAAK;IACjB;IACAlB,UAAU,IAAMqB,WAAW;QAACD;KAAS;AACvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/react-controls",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
4
4
|
"description": "Entity-agnostic React UI — table, form, filters, wizard, command palette — rendered from entity metadata, plus layout primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@headlessui/react": "^2.2.10",
|
|
20
20
|
"class-variance-authority": "^0.7.1",
|
|
21
21
|
"idb": "^8.0.4",
|
|
22
|
-
"@entifix/core": "0.20.
|
|
22
|
+
"@entifix/core": "0.20.3"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@storybook/addon-a11y": "^10.6.
|
|
49
|
-
"@storybook/addon-docs": "^10.6.
|
|
50
|
-
"@storybook/addon-themes": "^10.6.
|
|
51
|
-
"@storybook/addon-vitest": "^10.6.
|
|
52
|
-
"@storybook/react-vite": "^10.6.
|
|
48
|
+
"@storybook/addon-a11y": "^10.6.6",
|
|
49
|
+
"@storybook/addon-docs": "^10.6.6",
|
|
50
|
+
"@storybook/addon-themes": "^10.6.6",
|
|
51
|
+
"@storybook/addon-vitest": "^10.6.6",
|
|
52
|
+
"@storybook/react-vite": "^10.6.6",
|
|
53
53
|
"effect": "4.0.7",
|
|
54
54
|
"i18next": "26.6.0",
|
|
55
55
|
"react": "19.3.1",
|
|
56
56
|
"react-i18next": "17.1.10",
|
|
57
|
-
"storybook": "^10.6.
|
|
58
|
-
"@entifix/
|
|
59
|
-
"@entifix/
|
|
57
|
+
"storybook": "^10.6.6",
|
|
58
|
+
"@entifix/style": "0.20.3",
|
|
59
|
+
"@entifix/i18n": "0.20.3"
|
|
60
60
|
},
|
|
61
61
|
"nx": {
|
|
62
62
|
"tags": [
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"i18next": ">=26 <27",
|
|
112
112
|
"react": ">=19 <20",
|
|
113
113
|
"react-i18next": ">=17 <18",
|
|
114
|
-
"@entifix/i18n": "0.20.
|
|
114
|
+
"@entifix/i18n": "0.20.3"
|
|
115
115
|
},
|
|
116
116
|
"peerDependenciesMeta": {
|
|
117
117
|
"@entifix/i18n": {
|