@entifix/react-controls 0.20.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/i18n/catalog/en.d.ts.map +1 -1
  2. package/dist/i18n/catalog/en.js +3 -0
  3. package/dist/i18n/catalog/en.js.map +1 -1
  4. package/dist/i18n/catalog/es.d.ts +3 -0
  5. package/dist/i18n/catalog/es.d.ts.map +1 -1
  6. package/dist/i18n/catalog/es.js +3 -0
  7. package/dist/i18n/catalog/es.js.map +1 -1
  8. package/dist/i18n/catalog/index.d.ts +6 -0
  9. package/dist/i18n/catalog/index.d.ts.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/ui/actions/action-surfaces.d.ts +13 -0
  15. package/dist/ui/actions/action-surfaces.d.ts.map +1 -1
  16. package/dist/ui/actions/action-surfaces.js +15 -0
  17. package/dist/ui/actions/action-surfaces.js.map +1 -1
  18. package/dist/ui/atoms/cell-value/cell-value.d.ts +6 -0
  19. package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
  20. package/dist/ui/atoms/cell-value/cell-value.js +97 -14
  21. package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
  22. package/dist/ui/atoms/cell-value/index.d.ts +1 -0
  23. package/dist/ui/atoms/cell-value/index.d.ts.map +1 -1
  24. package/dist/ui/atoms/cell-value/index.js +1 -0
  25. package/dist/ui/atoms/cell-value/index.js.map +1 -1
  26. package/dist/ui/atoms/cell-value/use-record-label.d.ts +16 -0
  27. package/dist/ui/atoms/cell-value/use-record-label.d.ts.map +1 -0
  28. package/dist/ui/atoms/cell-value/use-record-label.js +55 -0
  29. package/dist/ui/atoms/cell-value/use-record-label.js.map +1 -0
  30. package/dist/ui/atoms/table/table.d.ts +4 -2
  31. package/dist/ui/atoms/table/table.d.ts.map +1 -1
  32. package/dist/ui/atoms/table/table.js +3 -1
  33. package/dist/ui/atoms/table/table.js.map +1 -1
  34. package/dist/ui/organisms/entity-form/entity-form.d.ts +1 -1
  35. package/dist/ui/organisms/entity-form/entity-form.d.ts.map +1 -1
  36. package/dist/ui/organisms/entity-form/entity-form.js +19 -10
  37. package/dist/ui/organisms/entity-form/entity-form.js.map +1 -1
  38. package/dist/ui/organisms/entity-form/entity-form.types.d.ts +0 -8
  39. package/dist/ui/organisms/entity-form/entity-form.types.d.ts.map +1 -1
  40. package/dist/ui/organisms/entity-form/entity-form.types.js.map +1 -1
  41. package/dist/ui/organisms/entity-table/card-roles.d.ts +10 -0
  42. package/dist/ui/organisms/entity-table/card-roles.d.ts.map +1 -0
  43. package/dist/ui/organisms/entity-table/card-roles.js +14 -0
  44. package/dist/ui/organisms/entity-table/card-roles.js.map +1 -0
  45. package/dist/ui/organisms/entity-table/entity-table-slots.d.ts +2 -0
  46. package/dist/ui/organisms/entity-table/entity-table-slots.d.ts.map +1 -1
  47. package/dist/ui/organisms/entity-table/entity-table-slots.js.map +1 -1
  48. package/dist/ui/organisms/entity-table/entity-table.d.ts.map +1 -1
  49. package/dist/ui/organisms/entity-table/entity-table.js +242 -173
  50. package/dist/ui/organisms/entity-table/entity-table.js.map +1 -1
  51. package/dist/ui/organisms/entity-table/pivot.d.ts +32 -5
  52. package/dist/ui/organisms/entity-table/pivot.d.ts.map +1 -1
  53. package/dist/ui/organisms/entity-table/pivot.js +42 -9
  54. package/dist/ui/organisms/entity-table/pivot.js.map +1 -1
  55. package/dist/ui/organisms/entity-table/use-entity-table-columns.d.ts.map +1 -1
  56. package/dist/ui/organisms/entity-table/use-entity-table-columns.js +6 -3
  57. package/dist/ui/organisms/entity-table/use-entity-table-columns.js.map +1 -1
  58. package/dist/ui/utils/reference-labels.d.ts +59 -0
  59. package/dist/ui/utils/reference-labels.d.ts.map +1 -0
  60. package/dist/ui/utils/reference-labels.js +49 -0
  61. package/dist/ui/utils/reference-labels.js.map +1 -0
  62. package/dist/ui/utils/use-focus-on-arrival.d.ts +11 -0
  63. package/dist/ui/utils/use-focus-on-arrival.d.ts.map +1 -1
  64. package/dist/ui/utils/use-focus-on-arrival.js +33 -1
  65. package/dist/ui/utils/use-focus-on-arrival.js.map +1 -1
  66. package/package.json +11 -11
@@ -0,0 +1,59 @@
1
+ import { type LocalizedText } from '@entifix/core';
2
+ import { type ReactNode } from 'react';
3
+ import { type EntityNounSource } from '../../i18n/index.js';
4
+ /**
5
+ * Where the name of one referenced record stands
6
+ * ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)):
7
+ *
8
+ * - `resolving` — asked for and not here yet;
9
+ * - `named` — read, as a text or a text per locale;
10
+ * - `notFound` — read, and no record answered the id (deleted, or one the
11
+ * reader may not read);
12
+ * - `failed` — the read itself failed;
13
+ * - `unregistered` — the host registered nothing that reads this entity.
14
+ */
15
+ export type ReferenceLabelState = {
16
+ readonly status: 'resolving';
17
+ } | {
18
+ readonly status: 'named';
19
+ readonly label: string | LocalizedText;
20
+ } | {
21
+ readonly status: 'notFound';
22
+ } | {
23
+ readonly status: 'failed';
24
+ } | {
25
+ readonly status: 'unregistered';
26
+ };
27
+ /**
28
+ * How the controls ask what a referenced record is called. A host fills it —
29
+ * batching what a render asks for into one read per target entity — and the
30
+ * controls only read it, so this package imports neither TanStack nor the
31
+ * integration layer.
32
+ */
33
+ export interface ReferenceLabelLookup {
34
+ /** The name of the record of `entityKey` (`domain:key`) whose id is `id`. */
35
+ label(entityKey: string, id: string): ReferenceLabelState;
36
+ /** How to call the entity itself, when a record's name could not be read. */
37
+ noun?(entityKey: string): EntityNounSource | undefined;
38
+ }
39
+ /**
40
+ * Publishes a host's reference lookup to every control that renders a
41
+ * reference — a cell, a card, a read form, a confirm dialog. Without one, a
42
+ * reference reads as its raw id, muted, which is what tells a developer the
43
+ * registry is missing.
44
+ */
45
+ export declare function ReferenceLabelsProvider({ lookup, children, }: {
46
+ lookup: ReferenceLabelLookup;
47
+ children: ReactNode;
48
+ }): import("react").JSX.Element;
49
+ /** The nearest {@link ReferenceLabelsProvider}'s lookup. */
50
+ export declare const useReferenceLabels: () => ReferenceLabelLookup;
51
+ /** Where one referenced record's name stands. */
52
+ export declare function useReferenceLabel(entityKey: string, id: string): ReferenceLabelState;
53
+ /**
54
+ * Words for a referenced record that has no name to show — its entity's noun
55
+ * and the id's short form ("Offering product-…"), so the reader still has
56
+ * something to quote. Never the whole id.
57
+ */
58
+ export declare function useUnresolvedReference(): (entityKey: string, id: string) => string;
59
+ //# sourceMappingURL=reference-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-labels.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/reference-labels.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAW,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAiB,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAE/E,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAChC;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,GACpE;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC;AAExC;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC1D,6EAA6E;IAC7E,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;CACxD;AAQD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,EAAE,SAAS,CAAC;CACrB,+BAMA;AAED,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,QAAO,oBACF,CAAC;AAErC,iDAAiD;AACjD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACT,mBAAmB,CAErB;AAMD;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,CACxC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,KACP,MAAM,CAcV"}
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { shortId } from '@entifix/core';
4
+ import { createContext, useCallback, useContext } from 'react';
5
+ import { useEntityNoun, useT } from '../../i18n/index.js';
6
+ const UNREGISTERED = {
7
+ status: 'unregistered'
8
+ };
9
+ const ReferenceLabelsContext = /*#__PURE__*/ createContext({
10
+ label: ()=>UNREGISTERED
11
+ });
12
+ /**
13
+ * Publishes a host's reference lookup to every control that renders a
14
+ * reference — a cell, a card, a read form, a confirm dialog. Without one, a
15
+ * reference reads as its raw id, muted, which is what tells a developer the
16
+ * registry is missing.
17
+ */ export function ReferenceLabelsProvider({ lookup, children }) {
18
+ return /*#__PURE__*/ _jsx(ReferenceLabelsContext.Provider, {
19
+ value: lookup,
20
+ children: children
21
+ });
22
+ }
23
+ /** The nearest {@link ReferenceLabelsProvider}'s lookup. */ export const useReferenceLabels = ()=>useContext(ReferenceLabelsContext);
24
+ /** Where one referenced record's name stands. */ export function useReferenceLabel(entityKey, id) {
25
+ return useReferenceLabels().label(entityKey, id);
26
+ }
27
+ /** `catalog:product-offering` → `product-offering`: the entity's key, when it has no noun. */ const keyOf = (entityKey)=>entityKey.slice(entityKey.indexOf(':') + 1);
28
+ /**
29
+ * Words for a referenced record that has no name to show — its entity's noun
30
+ * and the id's short form ("Offering product-…"), so the reader still has
31
+ * something to quote. Never the whole id.
32
+ */ export function useUnresolvedReference() {
33
+ const t = useT();
34
+ const noun = useEntityNoun();
35
+ const lookup = useReferenceLabels();
36
+ return useCallback((entityKey, id)=>{
37
+ const source = lookup.noun == null ? void 0 : lookup.noun.call(lookup, entityKey);
38
+ return t('reference.unresolved', {
39
+ noun: source === undefined ? keyOf(entityKey) : noun(source),
40
+ id: shortId(id)
41
+ });
42
+ }, [
43
+ lookup,
44
+ noun,
45
+ t
46
+ ]);
47
+ }
48
+
49
+ //# sourceMappingURL=reference-labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/utils/reference-labels.tsx"],"sourcesContent":["'use client';\n\nimport { type LocalizedText, shortId } from '@entifix/core';\nimport { createContext, type ReactNode, useCallback, useContext } from 'react';\n\nimport {\n type EntityNounSource,\n useEntityNoun,\n useT,\n} from '../../i18n/index.js';\n\n/**\n * Where the name of one referenced record stands\n * ([ADR 0030](../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)):\n *\n * - `resolving` — asked for and not here yet;\n * - `named` — read, as a text or a text per locale;\n * - `notFound` — read, and no record answered the id (deleted, or one the\n * reader may not read);\n * - `failed` — the read itself failed;\n * - `unregistered` — the host registered nothing that reads this entity.\n */\nexport type ReferenceLabelState =\n | { readonly status: 'resolving' }\n | { readonly status: 'named'; readonly label: string | LocalizedText }\n | { readonly status: 'notFound' }\n | { readonly status: 'failed' }\n | { readonly status: 'unregistered' };\n\n/**\n * How the controls ask what a referenced record is called. A host fills it —\n * batching what a render asks for into one read per target entity — and the\n * controls only read it, so this package imports neither TanStack nor the\n * integration layer.\n */\nexport interface ReferenceLabelLookup {\n /** The name of the record of `entityKey` (`domain:key`) whose id is `id`. */\n label(entityKey: string, id: string): ReferenceLabelState;\n /** How to call the entity itself, when a record's name could not be read. */\n noun?(entityKey: string): EntityNounSource | undefined;\n}\n\nconst UNREGISTERED: ReferenceLabelState = { status: 'unregistered' };\n\nconst ReferenceLabelsContext = createContext<ReferenceLabelLookup>({\n label: () => UNREGISTERED,\n});\n\n/**\n * Publishes a host's reference lookup to every control that renders a\n * reference — a cell, a card, a read form, a confirm dialog. Without one, a\n * reference reads as its raw id, muted, which is what tells a developer the\n * registry is missing.\n */\nexport function ReferenceLabelsProvider({\n lookup,\n children,\n}: {\n lookup: ReferenceLabelLookup;\n children: ReactNode;\n}) {\n return (\n <ReferenceLabelsContext.Provider value={lookup}>\n {children}\n </ReferenceLabelsContext.Provider>\n );\n}\n\n/** The nearest {@link ReferenceLabelsProvider}'s lookup. */\nexport const useReferenceLabels = (): ReferenceLabelLookup =>\n useContext(ReferenceLabelsContext);\n\n/** Where one referenced record's name stands. */\nexport function useReferenceLabel(\n entityKey: string,\n id: string,\n): ReferenceLabelState {\n return useReferenceLabels().label(entityKey, id);\n}\n\n/** `catalog:product-offering` → `product-offering`: the entity's key, when it has no noun. */\nconst keyOf = (entityKey: string) =>\n entityKey.slice(entityKey.indexOf(':') + 1);\n\n/**\n * Words for a referenced record that has no name to show — its entity's noun\n * and the id's short form (\"Offering product-…\"), so the reader still has\n * something to quote. Never the whole id.\n */\nexport function useUnresolvedReference(): (\n entityKey: string,\n id: string,\n) => string {\n const t = useT();\n const noun = useEntityNoun();\n const lookup = useReferenceLabels();\n return useCallback(\n (entityKey, id) => {\n const source = lookup.noun?.(entityKey);\n return t('reference.unresolved', {\n noun: source === undefined ? keyOf(entityKey) : noun(source),\n id: shortId(id),\n });\n },\n [lookup, noun, t],\n );\n}\n"],"names":["shortId","createContext","useCallback","useContext","useEntityNoun","useT","UNREGISTERED","status","ReferenceLabelsContext","label","ReferenceLabelsProvider","lookup","children","Provider","value","useReferenceLabels","useReferenceLabel","entityKey","id","keyOf","slice","indexOf","useUnresolvedReference","t","noun","source","undefined"],"mappings":"AAAA;;AAEA,SAA6BA,OAAO,QAAQ,gBAAgB;AAC5D,SAASC,aAAa,EAAkBC,WAAW,EAAEC,UAAU,QAAQ,QAAQ;AAE/E,SAEEC,aAAa,EACbC,IAAI,QACC,sBAAsB;AAiC7B,MAAMC,eAAoC;IAAEC,QAAQ;AAAe;AAEnE,MAAMC,uCAAyBP,cAAoC;IACjEQ,OAAO,IAAMH;AACf;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wBAAwB,EACtCC,MAAM,EACNC,QAAQ,EAIT;IACC,qBACE,KAACJ,uBAAuBK,QAAQ;QAACC,OAAOH;kBACrCC;;AAGP;AAEA,0DAA0D,GAC1D,OAAO,MAAMG,qBAAqB,IAChCZ,WAAWK,wBAAwB;AAErC,+CAA+C,GAC/C,OAAO,SAASQ,kBACdC,SAAiB,EACjBC,EAAU;IAEV,OAAOH,qBAAqBN,KAAK,CAACQ,WAAWC;AAC/C;AAEA,4FAA4F,GAC5F,MAAMC,QAAQ,CAACF,YACbA,UAAUG,KAAK,CAACH,UAAUI,OAAO,CAAC,OAAO;AAE3C;;;;CAIC,GACD,OAAO,SAASC;IAId,MAAMC,IAAIlB;IACV,MAAMmB,OAAOpB;IACb,MAAMO,SAASI;IACf,OAAOb,YACL,CAACe,WAAWC;QACV,MAAMO,SAASd,OAAOa,IAAI,oBAAXb,OAAOa,IAAI,MAAXb,QAAcM;QAC7B,OAAOM,EAAE,wBAAwB;YAC/BC,MAAMC,WAAWC,YAAYP,MAAMF,aAAaO,KAAKC;YACrDP,IAAIlB,QAAQkB;QACd;IACF,GACA;QAACP;QAAQa;QAAMD;KAAE;AAErB"}
@@ -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,EAAa,MAAM,OAAO,CAAC;AAkBlD,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,YAElC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACrC,IAAI,CAON"}
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;AAElD;;;;CAIC,GACD,IAAIC,aAAa;AAEjB,kEAAkE,GAClE,IAAI,OAAOC,aAAa,aAAa;IACnC,MAAMC,OAAO;QACXF,aAAa;IACf;IACAC,SAASE,gBAAgB,CAAC,eAAeD,MAAM;QAAEE,SAAS;IAAK;IAC/DH,SAASE,gBAAgB,CAAC,WAAWD,MAAM;QAAEE,SAAS;IAAK;AAC7D;AAEA,gEAAgE,GAChE,OAAO,MAAMC,yBAAyB;IACpCL,aAAa;AACf,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,SAASM,kBACdC,OAAsC;IAEtCR,UAAU;YAIRQ;QAHA,IAAI,CAACP,YAAY;QACjB,MAAMQ,SAASP,SAASQ,aAAa;QACrC,IAAID,WAAW,QAAQA,WAAWP,SAASS,IAAI,EAAE;SACjDH,mBAAAA,QAAQI,OAAO,qBAAfJ,iBAAiBK,KAAK;IACxB,GAAG;QAACL;KAAQ;AACd"}
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.2",
3
+ "version": "0.21.0",
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.2"
22
+ "@entifix/core": "0.21.0"
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.5",
49
- "@storybook/addon-docs": "^10.6.5",
50
- "@storybook/addon-themes": "^10.6.5",
51
- "@storybook/addon-vitest": "^10.6.5",
52
- "@storybook/react-vite": "^10.6.5",
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.5",
58
- "@entifix/i18n": "0.20.2",
59
- "@entifix/style": "0.20.2"
57
+ "storybook": "^10.6.6",
58
+ "@entifix/i18n": "0.21.0",
59
+ "@entifix/style": "0.21.0"
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.2"
114
+ "@entifix/i18n": "0.21.0"
115
115
  },
116
116
  "peerDependenciesMeta": {
117
117
  "@entifix/i18n": {