@entifix/react-controls 0.23.10 → 0.23.12

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 (48) hide show
  1. package/dist/i18n/catalog/en.d.ts.map +1 -1
  2. package/dist/i18n/catalog/en.js +4 -0
  3. package/dist/i18n/catalog/en.js.map +1 -1
  4. package/dist/i18n/catalog/es.d.ts +4 -0
  5. package/dist/i18n/catalog/es.d.ts.map +1 -1
  6. package/dist/i18n/catalog/es.js +4 -0
  7. package/dist/i18n/catalog/es.js.map +1 -1
  8. package/dist/i18n/catalog/index.d.ts +8 -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/atoms/cell-value/cell-value.d.ts +12 -0
  15. package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
  16. package/dist/ui/atoms/cell-value/cell-value.js +20 -2
  17. package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
  18. package/dist/ui/molecules/entity-link-input/entity-link-input.d.ts +15 -3
  19. package/dist/ui/molecules/entity-link-input/entity-link-input.d.ts.map +1 -1
  20. package/dist/ui/molecules/entity-link-input/entity-link-input.js +14 -8
  21. package/dist/ui/molecules/entity-link-input/entity-link-input.js.map +1 -1
  22. package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.d.ts +32 -0
  23. package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.d.ts.map +1 -0
  24. package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.js +94 -0
  25. package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.js.map +1 -0
  26. package/dist/ui/molecules/entity-link-multi-input/index.d.ts +2 -0
  27. package/dist/ui/molecules/entity-link-multi-input/index.d.ts.map +1 -0
  28. package/dist/ui/molecules/entity-link-multi-input/index.js +3 -0
  29. package/dist/ui/molecules/entity-link-multi-input/index.js.map +1 -0
  30. package/dist/ui/molecules/entity-link-picker/entity-link-picker.d.ts +3 -1
  31. package/dist/ui/molecules/entity-link-picker/entity-link-picker.d.ts.map +1 -1
  32. package/dist/ui/molecules/entity-link-picker/entity-link-picker.js +4 -1
  33. package/dist/ui/molecules/entity-link-picker/entity-link-picker.js.map +1 -1
  34. package/dist/ui/organisms/entity-form/entity-form.d.ts.map +1 -1
  35. package/dist/ui/organisms/entity-form/entity-form.js +45 -11
  36. package/dist/ui/organisms/entity-form/entity-form.js.map +1 -1
  37. package/dist/ui/organisms/entity-table/entity-table.d.ts +1 -1
  38. package/dist/ui/organisms/entity-table/entity-table.d.ts.map +1 -1
  39. package/dist/ui/organisms/entity-table/entity-table.js +4 -2
  40. package/dist/ui/organisms/entity-table/entity-table.js.map +1 -1
  41. package/dist/ui/organisms/entity-table/entity-table.types.d.ts +6 -0
  42. package/dist/ui/organisms/entity-table/entity-table.types.d.ts.map +1 -1
  43. package/dist/ui/organisms/entity-table/entity-table.types.js.map +1 -1
  44. package/dist/ui/utils/reference-labels.d.ts +7 -0
  45. package/dist/ui/utils/reference-labels.d.ts.map +1 -1
  46. package/dist/ui/utils/reference-labels.js +21 -2
  47. package/dist/ui/utils/reference-labels.js.map +1 -1
  48. package/package.json +11 -11
@@ -7,11 +7,23 @@ export interface EntityLinkInputProps<TTarget extends Entity> {
7
7
  source: EntityLinkSource<TTarget>;
8
8
  /** A target was chosen — in either mode. */
9
9
  onSelect: (entity: TTarget) => void;
10
- /** The relation was emptied. */
11
- onClear: () => void;
10
+ /** The relation was emptied. Never called while `adding`. */
11
+ onClear?: () => void;
12
12
  /** The id the field's label points at. */
13
13
  id?: string;
14
14
  disabled?: boolean;
15
+ /**
16
+ * The input adds a target to a list rather than holding one: no value is
17
+ * shown and nothing is cleared, since the list beside it shows what is held
18
+ * and removes each item itself. What `EntityLinkMultiInput` mounts.
19
+ */
20
+ adding?: boolean;
21
+ /**
22
+ * Ids not to offer: the quick search leaves them out and the browse dialog
23
+ * marks them chosen. What a list passes for the ids it already holds, so a
24
+ * target is never suggested twice.
25
+ */
26
+ exclude?: readonly string[];
15
27
  }
16
28
  /**
17
29
  * The editor for a to-one relation: what the value *is*, plus the two ways to
@@ -32,5 +44,5 @@ export interface EntityLinkInputProps<TTarget extends Entity> {
32
44
  * key when it is not, so a draft restored before its label resolves still shows
33
45
  * *something* true rather than an empty box.
34
46
  */
35
- export declare function EntityLinkInput<TTarget extends Entity>({ descriptor, value, source, onSelect, onClear, id, disabled, }: EntityLinkInputProps<TTarget>): import("react").JSX.Element;
47
+ export declare function EntityLinkInput<TTarget extends Entity>({ descriptor, value, source, onSelect, onClear, id, disabled, adding, exclude, }: EntityLinkInputProps<TTarget>): import("react").JSX.Element;
36
48
  //# sourceMappingURL=entity-link-input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity-link-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-input/entity-link-input.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAcvB,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,MAAM;IAC1D,+DAA+D;IAC/D,UAAU,EAAE,qBAAqB,CAAC;IAClC,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,4CAA4C;IAC5C,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,gCAAgC;IAChC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAsBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,EAAE,EACtD,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,EAAE,EACF,QAAgB,GACjB,EAAE,oBAAoB,CAAC,OAAO,CAAC,+BAoJ/B"}
1
+ {"version":3,"file":"entity-link-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-input/entity-link-input.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAcvB,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,MAAM;IAC1D,+DAA+D;IAC/D,UAAU,EAAE,qBAAqB,CAAC;IAClC,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,4CAA4C;IAC5C,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAsBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,EAAE,EACtD,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,EAAE,EACF,QAAgB,EAChB,MAAc,EACd,OAAO,GACR,EAAE,oBAAoB,CAAC,OAAO,CAAC,+BAqK/B"}
@@ -57,18 +57,21 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
57
57
  * The displayed text is the target's label when one is known and the bare foreign
58
58
  * key when it is not, so a draft restored before its label resolves still shows
59
59
  * *something* true rather than an empty box.
60
- */ export function EntityLinkInput({ descriptor, value, source, onSelect, onClear, id, disabled = false }) {
60
+ */ export function EntityLinkInput({ descriptor, value, source, onSelect, onClear, id, disabled = false, adding = false, exclude }) {
61
61
  var _source_selected_label;
62
62
  const t = useT();
63
63
  const errorMessage = useErrorMessage();
64
- const assigned = value !== '';
64
+ const assigned = !adding && value !== '';
65
65
  const label = (_source_selected_label = source.selected.label) != null ? _source_selected_label : assigned ? value : '';
66
- const display = source.selected.isLoading ? t('link.loading') : label === '' ? t('link.empty') : label;
66
+ const display = adding ? t('link.add', {
67
+ field: descriptor.label
68
+ }) : source.selected.isLoading ? t('link.loading') : label === '' ? t('link.empty') : label;
67
69
  /**
68
70
  * Headless UI reports `null` when the search is abandoned (escape, blur). That
69
71
  * is not a request to empty the relation — clearing is the explicit action
70
72
  * beside the input — so it leaves the held value alone.
71
- */ const handleSelect = (entity)=>{
73
+ */ const options = exclude === undefined || exclude.length === 0 ? source.quick.options : source.quick.options.filter((option)=>!exclude.includes(String(option.id)));
74
+ const handleSelect = (entity)=>{
72
75
  if (entity === null) return;
73
76
  onSelect(entity);
74
77
  source.quick.setTerm('');
@@ -89,7 +92,9 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
89
92
  children: [
90
93
  /*#__PURE__*/ _jsx(ComboboxInput, {
91
94
  id: id,
92
- "aria-label": t('link.search', {
95
+ "aria-label": adding ? t('link.add', {
96
+ field: descriptor.label
97
+ }) : t('link.search', {
93
98
  field: descriptor.label
94
99
  }),
95
100
  placeholder: display,
@@ -127,11 +132,11 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
127
132
  className: "px-2xs py-3xs",
128
133
  children: null
129
134
  }),
130
- !source.quick.isLoading && source.quick.options.length === 0 && /*#__PURE__*/ _jsx("div", {
135
+ !source.quick.isLoading && options.length === 0 && /*#__PURE__*/ _jsx("div", {
131
136
  className: "px-2xs py-3xs text-step-sm text-content-muted",
132
137
  children: t('link.noResults')
133
138
  }),
134
- source.quick.options.map((option)=>/*#__PURE__*/ _jsx(ComboboxOption, {
139
+ options.map((option)=>/*#__PURE__*/ _jsx(ComboboxOption, {
135
140
  value: option,
136
141
  className: [
137
142
  'flex min-h-(--target-min) cursor-pointer items-center rounded-md border-l-2 border-transparent px-2xs py-3xs text-step-sm text-content',
@@ -169,7 +174,7 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
169
174
  })
170
175
  ]
171
176
  }),
172
- /*#__PURE__*/ _jsx("span", {
177
+ !adding && /*#__PURE__*/ _jsx("span", {
173
178
  "data-testid": `entity-link-value-${descriptor.name}`,
174
179
  className: "text-step-sm text-content",
175
180
  children: display
@@ -182,6 +187,7 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
182
187
  /*#__PURE__*/ _jsx(EntityLinkPicker, {
183
188
  descriptor: descriptor,
184
189
  source: source,
190
+ exclude: exclude,
185
191
  onSelect: (entity)=>{
186
192
  onSelect(entity);
187
193
  source.browse.close();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/molecules/entity-link-input/entity-link-input.tsx"],"sourcesContent":["'use client';\n\nimport type {\n Entity,\n EntityFieldDescriptor,\n EntityLinkSource,\n} from '@entifix/core';\nimport {\n Combobox,\n ComboboxButton,\n ComboboxInput,\n ComboboxOption,\n ComboboxOptions,\n} from '@headlessui/react';\n\nimport { useErrorMessage, useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { EntityLinkPicker } from '../entity-link-picker/index.js';\nimport { LoadingBoundary } from '../loading-boundary/index.js';\n\nexport interface EntityLinkInputProps<TTarget extends Entity> {\n /** The relation being edited. Its label names the controls. */\n descriptor: EntityFieldDescriptor;\n /** The held foreign key, as the draft carries it. `''` means unassigned. */\n value: string;\n source: EntityLinkSource<TTarget>;\n /** A target was chosen — in either mode. */\n onSelect: (entity: TTarget) => void;\n /** The relation was emptied. */\n onClear: () => void;\n /** The id the field's label points at. */\n id?: string;\n disabled?: boolean;\n}\n\n/** Chevron — the quick search. Inline so the package ships no icon dependency. */\nfunction ChevronIcon() {\n return (\n <svg aria-hidden viewBox=\"0 0 20 20\" className=\"size-4 fill-current\">\n <path d=\"M5.5 7.5 10 12l4.5-4.5z\" />\n </svg>\n );\n}\n\n/** Ellipsis — the browse dialog, the same affordance a desktop app uses. */\nfunction EllipsisIcon() {\n return (\n <svg aria-hidden viewBox=\"0 0 20 20\" className=\"size-4 fill-current\">\n <circle cx=\"4\" cy=\"10\" r=\"1.5\" />\n <circle cx=\"10\" cy=\"10\" r=\"1.5\" />\n <circle cx=\"16\" cy=\"10\" r=\"1.5\" />\n </svg>\n );\n}\n\n/**\n * The editor for a to-one relation: what the value *is*, plus the two ways to\n * change it.\n *\n * - the chevron opens a type-ahead over the target entity — \"I know roughly what\n * it is called\";\n * - the ellipsis opens the target's full table in a dialog — \"I need to filter\n * the catalog to find it\".\n *\n * It is presentational. Every option, loading flag and error arrives through\n * {@link EntityLinkSource}, which the integration layer produces; this component\n * cannot fetch, and never decides how the relation is written back — it reports\n * the chosen instance and the form's reconstruction step applies the entity's own\n * `linkSerialization` policy.\n *\n * The displayed text is the target's label when one is known and the bare foreign\n * key when it is not, so a draft restored before its label resolves still shows\n * *something* true rather than an empty box.\n */\nexport function EntityLinkInput<TTarget extends Entity>({\n descriptor,\n value,\n source,\n onSelect,\n onClear,\n id,\n disabled = false,\n}: EntityLinkInputProps<TTarget>) {\n const t = useT();\n const errorMessage = useErrorMessage();\n\n const assigned = value !== '';\n const label = source.selected.label ?? (assigned ? value : '');\n const display = source.selected.isLoading\n ? t('link.loading')\n : label === ''\n ? t('link.empty')\n : label;\n\n /**\n * Headless UI reports `null` when the search is abandoned (escape, blur). That\n * is not a request to empty the relation — clearing is the explicit action\n * beside the input — so it leaves the held value alone.\n */\n const handleSelect = (entity: TTarget | null) => {\n if (entity === null) return;\n onSelect(entity);\n source.quick.setTerm('');\n };\n\n return (\n <div className=\"flex flex-col gap-3xs\">\n <div className=\"flex items-stretch gap-3xs\">\n <div className=\"relative flex-1\">\n <Combobox<TTarget | null>\n value={null}\n onChange={handleSelect}\n disabled={disabled}\n immediate\n >\n {/*\n The input edits the *search term*, never the value: the value is a\n foreign key, which is not something a user types. So it displays the\n resolved label while idle and the term while searching.\n */}\n <ComboboxInput\n id={id}\n aria-label={t('link.search', { field: descriptor.label })}\n placeholder={display}\n value={source.quick.term}\n disabled={disabled}\n onChange={event =>\n source.quick.setTerm(event.currentTarget.value)\n }\n className={[\n 'min-h-(--target-min) w-full rounded-lg border border-border-control bg-surface-elevated px-2xs py-3xs',\n 'text-step-sm text-content',\n 'focus-ring',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n ].join(' ')}\n />\n <ComboboxButton\n aria-label={t('link.suggestAria', { field: descriptor.label })}\n className=\"inset-y-0 right-0 absolute flex items-center px-2xs text-content-muted\"\n >\n <ChevronIcon />\n </ComboboxButton>\n <ComboboxOptions\n className={[\n 'max-h-64 absolute z-(--z-dropdown) mt-3xs w-full overflow-auto',\n 'rounded-lg border border-border bg-surface-elevated p-3xs shadow-overlay',\n // The panel itself is a focus-managed CONTAINER, not a target: the ring\n // belongs on the item inside it. Stripping the outline here is\n // correct, and is not a missing `focus-ring`.\n 'focus:outline-none',\n ].join(' ')}\n >\n {source.quick.isLoading && (\n <LoadingBoundary\n isLoading\n lines={2}\n label={t('link.loading')}\n className=\"px-2xs py-3xs\"\n >\n {null}\n </LoadingBoundary>\n )}\n {!source.quick.isLoading && source.quick.options.length === 0 && (\n <div className=\"px-2xs py-3xs text-step-sm text-content-muted\">\n {t('link.noResults')}\n </div>\n )}\n {source.quick.options.map(option => (\n <ComboboxOption\n key={String(option.id)}\n value={option}\n className={[\n 'flex min-h-(--target-min) cursor-pointer items-center rounded-md border-l-2 border-transparent px-2xs py-3xs text-step-sm text-content',\n // Active: the focus ring. Chosen but not under the\n // keyboard: a `selected` edge, 3:1 on the panel.\n 'focus-ring data-focus:bg-surface data-focus:-outline-offset-2',\n 'data-selected:border-selected',\n ].join(' ')}\n >\n {source.labelOf(option)}\n </ComboboxOption>\n ))}\n </ComboboxOptions>\n </Combobox>\n </div>\n\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n disabled={disabled}\n aria-label={t('link.browseAria', { field: descriptor.label })}\n onClick={source.browse.open}\n >\n <EllipsisIcon />\n </Button>\n {/* Clearing is only offered when there is something to clear — and a\n required relation still offers it, because `required` is the form's\n rule to report, not the input's to enforce. */}\n {assigned && !disabled && (\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={onClear}>\n {t('link.clear', { field: descriptor.label })}\n </Button>\n )}\n </div>\n\n {/* The held value, always readable — the combobox input shows the term. */}\n <span\n data-testid={`entity-link-value-${descriptor.name}`}\n className=\"text-step-sm text-content\"\n >\n {display}\n </span>\n\n {source.quick.error && (\n <span role=\"alert\" className=\"text-step-sm text-danger\">\n {errorMessage(source.quick.error)}\n </span>\n )}\n\n <EntityLinkPicker<TTarget>\n descriptor={descriptor}\n source={source}\n onSelect={entity => {\n onSelect(entity);\n source.browse.close();\n }}\n />\n </div>\n );\n}\n"],"names":["Combobox","ComboboxButton","ComboboxInput","ComboboxOption","ComboboxOptions","useErrorMessage","useT","Button","EntityLinkPicker","LoadingBoundary","ChevronIcon","svg","aria-hidden","viewBox","className","path","d","EllipsisIcon","circle","cx","cy","r","EntityLinkInput","descriptor","value","source","onSelect","onClear","id","disabled","t","errorMessage","assigned","label","selected","display","isLoading","handleSelect","entity","quick","setTerm","div","onChange","immediate","aria-label","field","placeholder","term","event","currentTarget","join","lines","options","length","map","option","labelOf","String","type","variant","size","onClick","browse","open","span","data-testid","name","error","role","close"],"mappings":"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"}
1
+ {"version":3,"sources":["../../../../src/ui/molecules/entity-link-input/entity-link-input.tsx"],"sourcesContent":["'use client';\n\nimport type {\n Entity,\n EntityFieldDescriptor,\n EntityLinkSource,\n} from '@entifix/core';\nimport {\n Combobox,\n ComboboxButton,\n ComboboxInput,\n ComboboxOption,\n ComboboxOptions,\n} from '@headlessui/react';\n\nimport { useErrorMessage, useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { EntityLinkPicker } from '../entity-link-picker/index.js';\nimport { LoadingBoundary } from '../loading-boundary/index.js';\n\nexport interface EntityLinkInputProps<TTarget extends Entity> {\n /** The relation being edited. Its label names the controls. */\n descriptor: EntityFieldDescriptor;\n /** The held foreign key, as the draft carries it. `''` means unassigned. */\n value: string;\n source: EntityLinkSource<TTarget>;\n /** A target was chosen — in either mode. */\n onSelect: (entity: TTarget) => void;\n /** The relation was emptied. Never called while `adding`. */\n onClear?: () => void;\n /** The id the field's label points at. */\n id?: string;\n disabled?: boolean;\n /**\n * The input adds a target to a list rather than holding one: no value is\n * shown and nothing is cleared, since the list beside it shows what is held\n * and removes each item itself. What `EntityLinkMultiInput` mounts.\n */\n adding?: boolean;\n /**\n * Ids not to offer: the quick search leaves them out and the browse dialog\n * marks them chosen. What a list passes for the ids it already holds, so a\n * target is never suggested twice.\n */\n exclude?: readonly string[];\n}\n\n/** Chevron — the quick search. Inline so the package ships no icon dependency. */\nfunction ChevronIcon() {\n return (\n <svg aria-hidden viewBox=\"0 0 20 20\" className=\"size-4 fill-current\">\n <path d=\"M5.5 7.5 10 12l4.5-4.5z\" />\n </svg>\n );\n}\n\n/** Ellipsis — the browse dialog, the same affordance a desktop app uses. */\nfunction EllipsisIcon() {\n return (\n <svg aria-hidden viewBox=\"0 0 20 20\" className=\"size-4 fill-current\">\n <circle cx=\"4\" cy=\"10\" r=\"1.5\" />\n <circle cx=\"10\" cy=\"10\" r=\"1.5\" />\n <circle cx=\"16\" cy=\"10\" r=\"1.5\" />\n </svg>\n );\n}\n\n/**\n * The editor for a to-one relation: what the value *is*, plus the two ways to\n * change it.\n *\n * - the chevron opens a type-ahead over the target entity — \"I know roughly what\n * it is called\";\n * - the ellipsis opens the target's full table in a dialog — \"I need to filter\n * the catalog to find it\".\n *\n * It is presentational. Every option, loading flag and error arrives through\n * {@link EntityLinkSource}, which the integration layer produces; this component\n * cannot fetch, and never decides how the relation is written back — it reports\n * the chosen instance and the form's reconstruction step applies the entity's own\n * `linkSerialization` policy.\n *\n * The displayed text is the target's label when one is known and the bare foreign\n * key when it is not, so a draft restored before its label resolves still shows\n * *something* true rather than an empty box.\n */\nexport function EntityLinkInput<TTarget extends Entity>({\n descriptor,\n value,\n source,\n onSelect,\n onClear,\n id,\n disabled = false,\n adding = false,\n exclude,\n}: EntityLinkInputProps<TTarget>) {\n const t = useT();\n const errorMessage = useErrorMessage();\n\n const assigned = !adding && value !== '';\n const label = source.selected.label ?? (assigned ? value : '');\n const display = adding\n ? t('link.add', { field: descriptor.label })\n : source.selected.isLoading\n ? t('link.loading')\n : label === ''\n ? t('link.empty')\n : label;\n\n /**\n * Headless UI reports `null` when the search is abandoned (escape, blur). That\n * is not a request to empty the relation — clearing is the explicit action\n * beside the input — so it leaves the held value alone.\n */\n const options =\n exclude === undefined || exclude.length === 0\n ? source.quick.options\n : source.quick.options.filter(\n option => !exclude.includes(String(option.id)),\n );\n\n const handleSelect = (entity: TTarget | null) => {\n if (entity === null) return;\n onSelect(entity);\n source.quick.setTerm('');\n };\n\n return (\n <div className=\"flex flex-col gap-3xs\">\n <div className=\"flex items-stretch gap-3xs\">\n <div className=\"relative flex-1\">\n <Combobox<TTarget | null>\n value={null}\n onChange={handleSelect}\n disabled={disabled}\n immediate\n >\n {/*\n The input edits the *search term*, never the value: the value is a\n foreign key, which is not something a user types. So it displays the\n resolved label while idle and the term while searching.\n */}\n <ComboboxInput\n id={id}\n aria-label={\n adding\n ? t('link.add', { field: descriptor.label })\n : t('link.search', { field: descriptor.label })\n }\n placeholder={display}\n value={source.quick.term}\n disabled={disabled}\n onChange={event =>\n source.quick.setTerm(event.currentTarget.value)\n }\n className={[\n 'min-h-(--target-min) w-full rounded-lg border border-border-control bg-surface-elevated px-2xs py-3xs',\n 'text-step-sm text-content',\n 'focus-ring',\n 'disabled:cursor-not-allowed disabled:opacity-50',\n ].join(' ')}\n />\n <ComboboxButton\n aria-label={t('link.suggestAria', { field: descriptor.label })}\n className=\"inset-y-0 right-0 absolute flex items-center px-2xs text-content-muted\"\n >\n <ChevronIcon />\n </ComboboxButton>\n <ComboboxOptions\n className={[\n 'max-h-64 absolute z-(--z-dropdown) mt-3xs w-full overflow-auto',\n 'rounded-lg border border-border bg-surface-elevated p-3xs shadow-overlay',\n // The panel itself is a focus-managed CONTAINER, not a target: the ring\n // belongs on the item inside it. Stripping the outline here is\n // correct, and is not a missing `focus-ring`.\n 'focus:outline-none',\n ].join(' ')}\n >\n {source.quick.isLoading && (\n <LoadingBoundary\n isLoading\n lines={2}\n label={t('link.loading')}\n className=\"px-2xs py-3xs\"\n >\n {null}\n </LoadingBoundary>\n )}\n {!source.quick.isLoading && options.length === 0 && (\n <div className=\"px-2xs py-3xs text-step-sm text-content-muted\">\n {t('link.noResults')}\n </div>\n )}\n {options.map(option => (\n <ComboboxOption\n key={String(option.id)}\n value={option}\n className={[\n 'flex min-h-(--target-min) cursor-pointer items-center rounded-md border-l-2 border-transparent px-2xs py-3xs text-step-sm text-content',\n // Active: the focus ring. Chosen but not under the\n // keyboard: a `selected` edge, 3:1 on the panel.\n 'focus-ring data-focus:bg-surface data-focus:-outline-offset-2',\n 'data-selected:border-selected',\n ].join(' ')}\n >\n {source.labelOf(option)}\n </ComboboxOption>\n ))}\n </ComboboxOptions>\n </Combobox>\n </div>\n\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n disabled={disabled}\n aria-label={t('link.browseAria', { field: descriptor.label })}\n onClick={source.browse.open}\n >\n <EllipsisIcon />\n </Button>\n {/* Clearing is only offered when there is something to clear — and a\n required relation still offers it, because `required` is the form's\n rule to report, not the input's to enforce. */}\n {assigned && !disabled && (\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={onClear}>\n {t('link.clear', { field: descriptor.label })}\n </Button>\n )}\n </div>\n\n {/* The held value, always readable — the combobox input shows the term.\n Adding to a list holds nothing here: the list shows what is held. */}\n {!adding && (\n <span\n data-testid={`entity-link-value-${descriptor.name}`}\n className=\"text-step-sm text-content\"\n >\n {display}\n </span>\n )}\n\n {source.quick.error && (\n <span role=\"alert\" className=\"text-step-sm text-danger\">\n {errorMessage(source.quick.error)}\n </span>\n )}\n\n <EntityLinkPicker<TTarget>\n descriptor={descriptor}\n source={source}\n exclude={exclude}\n onSelect={entity => {\n onSelect(entity);\n source.browse.close();\n }}\n />\n </div>\n );\n}\n"],"names":["Combobox","ComboboxButton","ComboboxInput","ComboboxOption","ComboboxOptions","useErrorMessage","useT","Button","EntityLinkPicker","LoadingBoundary","ChevronIcon","svg","aria-hidden","viewBox","className","path","d","EllipsisIcon","circle","cx","cy","r","EntityLinkInput","descriptor","value","source","onSelect","onClear","id","disabled","adding","exclude","t","errorMessage","assigned","label","selected","display","field","isLoading","options","undefined","length","quick","filter","option","includes","String","handleSelect","entity","setTerm","div","onChange","immediate","aria-label","placeholder","term","event","currentTarget","join","lines","map","labelOf","type","variant","size","onClick","browse","open","span","data-testid","name","error","role","close"],"mappings":"AAAA;;AAOA,SACEA,QAAQ,EACRC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,eAAe,QACV,oBAAoB;AAE3B,SAASC,eAAe,EAAEC,IAAI,QAAQ,yBAAyB;AAC/D,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,gBAAgB,QAAQ,iCAAiC;AAClE,SAASC,eAAe,QAAQ,+BAA+B;AA6B/D,gFAAgF,GAChF,SAASC;IACP,qBACE,KAACC;QAAIC,aAAW;QAACC,SAAQ;QAAYC,WAAU;kBAC7C,cAAA,KAACC;YAAKC,GAAE;;;AAGd;AAEA,0EAA0E,GAC1E,SAASC;IACP,qBACE,MAACN;QAAIC,aAAW;QAACC,SAAQ;QAAYC,WAAU;;0BAC7C,KAACI;gBAAOC,IAAG;gBAAIC,IAAG;gBAAKC,GAAE;;0BACzB,KAACH;gBAAOC,IAAG;gBAAKC,IAAG;gBAAKC,GAAE;;0BAC1B,KAACH;gBAAOC,IAAG;gBAAKC,IAAG;gBAAKC,GAAE;;;;AAGhC;AAEA;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,gBAAwC,EACtDC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,EAAE,EACFC,WAAW,KAAK,EAChBC,SAAS,KAAK,EACdC,OAAO,EACuB;QAKhBN;IAJd,MAAMO,IAAI1B;IACV,MAAM2B,eAAe5B;IAErB,MAAM6B,WAAW,CAACJ,UAAUN,UAAU;IACtC,MAAMW,SAAQV,yBAAAA,OAAOW,QAAQ,CAACD,KAAK,YAArBV,yBAA0BS,WAAWV,QAAQ;IAC3D,MAAMa,UAAUP,SACZE,EAAE,YAAY;QAAEM,OAAOf,WAAWY,KAAK;IAAC,KACxCV,OAAOW,QAAQ,CAACG,SAAS,GACvBP,EAAE,kBACFG,UAAU,KACRH,EAAE,gBACFG;IAER;;;;GAIC,GACD,MAAMK,UACJT,YAAYU,aAAaV,QAAQW,MAAM,KAAK,IACxCjB,OAAOkB,KAAK,CAACH,OAAO,GACpBf,OAAOkB,KAAK,CAACH,OAAO,CAACI,MAAM,CACzBC,CAAAA,SAAU,CAACd,QAAQe,QAAQ,CAACC,OAAOF,OAAOjB,EAAE;IAGpD,MAAMoB,eAAe,CAACC;QACpB,IAAIA,WAAW,MAAM;QACrBvB,SAASuB;QACTxB,OAAOkB,KAAK,CAACO,OAAO,CAAC;IACvB;IAEA,qBACE,MAACC;QAAIrC,WAAU;;0BACb,MAACqC;gBAAIrC,WAAU;;kCACb,KAACqC;wBAAIrC,WAAU;kCACb,cAAA,MAACd;4BACCwB,OAAO;4BACP4B,UAAUJ;4BACVnB,UAAUA;4BACVwB,SAAS;;8CAOT,KAACnD;oCACC0B,IAAIA;oCACJ0B,cACExB,SACIE,EAAE,YAAY;wCAAEM,OAAOf,WAAWY,KAAK;oCAAC,KACxCH,EAAE,eAAe;wCAAEM,OAAOf,WAAWY,KAAK;oCAAC;oCAEjDoB,aAAalB;oCACbb,OAAOC,OAAOkB,KAAK,CAACa,IAAI;oCACxB3B,UAAUA;oCACVuB,UAAUK,CAAAA,QACRhC,OAAOkB,KAAK,CAACO,OAAO,CAACO,MAAMC,aAAa,CAAClC,KAAK;oCAEhDV,WAAW;wCACT;wCACA;wCACA;wCACA;qCACD,CAAC6C,IAAI,CAAC;;8CAET,KAAC1D;oCACCqD,cAAYtB,EAAE,oBAAoB;wCAAEM,OAAOf,WAAWY,KAAK;oCAAC;oCAC5DrB,WAAU;8CAEV,cAAA,KAACJ;;8CAEH,MAACN;oCACCU,WAAW;wCACT;wCACA;wCACA,wEAAwE;wCACxE,+DAA+D;wCAC/D,8CAA8C;wCAC9C;qCACD,CAAC6C,IAAI,CAAC;;wCAENlC,OAAOkB,KAAK,CAACJ,SAAS,kBACrB,KAAC9B;4CACC8B,SAAS;4CACTqB,OAAO;4CACPzB,OAAOH,EAAE;4CACTlB,WAAU;sDAET;;wCAGJ,CAACW,OAAOkB,KAAK,CAACJ,SAAS,IAAIC,QAAQE,MAAM,KAAK,mBAC7C,KAACS;4CAAIrC,WAAU;sDACZkB,EAAE;;wCAGNQ,QAAQqB,GAAG,CAAChB,CAAAA,uBACX,KAAC1C;gDAECqB,OAAOqB;gDACP/B,WAAW;oDACT;oDACA,mDAAmD;oDACnD,iDAAiD;oDACjD;oDACA;iDACD,CAAC6C,IAAI,CAAC;0DAENlC,OAAOqC,OAAO,CAACjB;+CAVXE,OAAOF,OAAOjB,EAAE;;;;;;kCAiB/B,KAACrB;wBACCwD,MAAK;wBACLC,SAAQ;wBACRC,MAAK;wBACLpC,UAAUA;wBACVyB,cAAYtB,EAAE,mBAAmB;4BAAEM,OAAOf,WAAWY,KAAK;wBAAC;wBAC3D+B,SAASzC,OAAO0C,MAAM,CAACC,IAAI;kCAE3B,cAAA,KAACnD;;oBAKFiB,YAAY,CAACL,0BACZ,KAACtB;wBAAOwD,MAAK;wBAASC,SAAQ;wBAAQC,MAAK;wBAAKC,SAASvC;kCACtDK,EAAE,cAAc;4BAAEM,OAAOf,WAAWY,KAAK;wBAAC;;;;YAOhD,CAACL,wBACA,KAACuC;gBACCC,eAAa,CAAC,kBAAkB,EAAE/C,WAAWgD,IAAI,EAAE;gBACnDzD,WAAU;0BAETuB;;YAIJZ,OAAOkB,KAAK,CAAC6B,KAAK,kBACjB,KAACH;gBAAKI,MAAK;gBAAQ3D,WAAU;0BAC1BmB,aAAaR,OAAOkB,KAAK,CAAC6B,KAAK;;0BAIpC,KAAChE;gBACCe,YAAYA;gBACZE,QAAQA;gBACRM,SAASA;gBACTL,UAAUuB,CAAAA;oBACRvB,SAASuB;oBACTxB,OAAO0C,MAAM,CAACO,KAAK;gBACrB;;;;AAIR"}
@@ -0,0 +1,32 @@
1
+ import type { Entity, EntityFieldDescriptor, EntityLinkSource } from '@entifix/core';
2
+ export interface EntityLinkMultiInputProps<TTarget extends Entity> {
3
+ /**
4
+ * The `scalarCollection` being edited. It declares `references`, which is
5
+ * how each held id is named.
6
+ */
7
+ descriptor: EntityFieldDescriptor;
8
+ /** The held ids as the draft carries a list: comma-separated, `''` for none. */
9
+ value: string;
10
+ source: EntityLinkSource<TTarget>;
11
+ /** The new comma list, after an id was added or removed. */
12
+ onChange: (next: string) => void;
13
+ /** The id the field's label points at — the input that adds one more. */
14
+ id?: string;
15
+ disabled?: boolean;
16
+ }
17
+ /** The draft's comma list as ids, blanks dropped. */
18
+ export declare const readIdList: (value: string) => string[];
19
+ /**
20
+ * The editor for a list of references — a `scalarCollection` that declares
21
+ * `references`, each element one target's id. What is held is a list of names,
22
+ * each with its own remove button; one more is added through the same quick
23
+ * search and browse dialog a single reference uses, so a picker that holds
24
+ * many is the picker that holds one, said twice.
25
+ *
26
+ * It writes the comma list the draft carries for every `scalarCollection`, so
27
+ * validation, reconstruction and every adapter see the ids exactly as before.
28
+ * An id already held is never offered again, and not added twice. An id no record answers still shows
29
+ * — as the noun and a short id — and can still be removed.
30
+ */
31
+ export declare function EntityLinkMultiInput<TTarget extends Entity>({ descriptor, value, source, onChange, id, disabled, }: EntityLinkMultiInputProps<TTarget>): import("react").JSX.Element;
32
+ //# sourceMappingURL=entity-link-multi-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-link-multi-input.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-multi-input/entity-link-multi-input.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,yBAAyB,CAAC,OAAO,SAAS,MAAM;IAC/D;;;OAGG;IACH,UAAU,EAAE,qBAAqB,CAAC;IAClC,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,4DAA4D;IAC5D,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,yEAAyE;IACzE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qDAAqD;AACrD,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAAM,EAIjB,CAAC;AAkCjC;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,MAAM,EAAE,EAC3D,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EACR,EAAE,EACF,QAAgB,GACjB,EAAE,yBAAyB,CAAC,OAAO,CAAC,+BAqDpC"}
@@ -0,0 +1,94 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useT } from '../../../i18n/index.js';
4
+ import { ReferenceValue } from '../../atoms/cell-value/cell-value.js';
5
+ import { useReferenceText } from '../../utils/reference-labels.js';
6
+ import { EntityLinkInput } from '../entity-link-input/index.js';
7
+ /** The draft's comma list as ids, blanks dropped. */ export const readIdList = (value)=>value.split(',').map((item)=>item.trim()).filter((item)=>item !== '');
8
+ function HeldReference({ entity, id, disabled, onRemove }) {
9
+ const t = useT();
10
+ const text = useReferenceText(entity, id);
11
+ return /*#__PURE__*/ _jsxs("li", {
12
+ className: "flex min-h-(--target-min) items-center gap-3xs rounded-md border border-border bg-surface-elevated ps-2xs text-step-sm text-content",
13
+ children: [
14
+ /*#__PURE__*/ _jsx(ReferenceValue, {
15
+ entity: entity,
16
+ id: id
17
+ }),
18
+ !disabled && /*#__PURE__*/ _jsx("button", {
19
+ type: "button",
20
+ "aria-label": t('link.remove', {
21
+ item: text
22
+ }),
23
+ onClick: onRemove,
24
+ className: "flex min-h-(--target-min) min-w-(--target-min) items-center justify-center rounded-md text-content-muted focus-ring hover:text-content",
25
+ children: /*#__PURE__*/ _jsx("svg", {
26
+ "aria-hidden": true,
27
+ viewBox: "0 0 20 20",
28
+ className: "size-4 fill-current",
29
+ children: /*#__PURE__*/ _jsx("path", {
30
+ d: "M6 4.6 10 8.6l4-4 1.4 1.4-4 4 4 4-1.4 1.4-4-4-4 4L4.6 14l4-4-4-4z"
31
+ })
32
+ })
33
+ })
34
+ ]
35
+ });
36
+ }
37
+ /**
38
+ * The editor for a list of references — a `scalarCollection` that declares
39
+ * `references`, each element one target's id. What is held is a list of names,
40
+ * each with its own remove button; one more is added through the same quick
41
+ * search and browse dialog a single reference uses, so a picker that holds
42
+ * many is the picker that holds one, said twice.
43
+ *
44
+ * It writes the comma list the draft carries for every `scalarCollection`, so
45
+ * validation, reconstruction and every adapter see the ids exactly as before.
46
+ * An id already held is never offered again, and not added twice. An id no record answers still shows
47
+ * — as the noun and a short id — and can still be removed.
48
+ */ export function EntityLinkMultiInput({ descriptor, value, source, onChange, id, disabled = false }) {
49
+ var _ref;
50
+ var _descriptor_references;
51
+ const t = useT();
52
+ const held = readIdList(value);
53
+ const entity = (_ref = (_descriptor_references = descriptor.references) == null ? void 0 : _descriptor_references.entity) != null ? _ref : '';
54
+ const add = (target)=>{
55
+ if (target.id == null) return;
56
+ // A held id is never offered, so whatever arrives here is new.
57
+ onChange([
58
+ ...held,
59
+ String(target.id)
60
+ ].join(','));
61
+ };
62
+ const remove = (index)=>onChange(held.filter((_, at)=>at !== index).join(','));
63
+ return /*#__PURE__*/ _jsxs("div", {
64
+ className: "flex flex-col gap-3xs",
65
+ children: [
66
+ held.length === 0 ? /*#__PURE__*/ _jsx("span", {
67
+ "data-testid": `entity-link-value-${descriptor.name}`,
68
+ className: "text-step-sm text-content-muted",
69
+ children: t('link.none')
70
+ }) : /*#__PURE__*/ _jsx("ul", {
71
+ "aria-label": descriptor.label,
72
+ "data-testid": `entity-link-value-${descriptor.name}`,
73
+ className: "flex flex-wrap gap-3xs",
74
+ children: held.map((heldId, index)=>/*#__PURE__*/ _jsx(HeldReference, {
75
+ entity: entity,
76
+ id: heldId,
77
+ disabled: disabled,
78
+ onRemove: ()=>remove(index)
79
+ }, heldId))
80
+ }),
81
+ !disabled && /*#__PURE__*/ _jsx(EntityLinkInput, {
82
+ descriptor: descriptor,
83
+ value: "",
84
+ source: source,
85
+ id: id,
86
+ adding: true,
87
+ exclude: held,
88
+ onSelect: add
89
+ })
90
+ ]
91
+ });
92
+ }
93
+
94
+ //# sourceMappingURL=entity-link-multi-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/molecules/entity-link-multi-input/entity-link-multi-input.tsx"],"sourcesContent":["'use client';\n\nimport type {\n Entity,\n EntityFieldDescriptor,\n EntityLinkSource,\n} from '@entifix/core';\n\nimport { useT } from '../../../i18n/index.js';\nimport { ReferenceValue } from '../../atoms/cell-value/cell-value.js';\nimport { useReferenceText } from '../../utils/reference-labels.js';\nimport { EntityLinkInput } from '../entity-link-input/index.js';\n\nexport interface EntityLinkMultiInputProps<TTarget extends Entity> {\n /**\n * The `scalarCollection` being edited. It declares `references`, which is\n * how each held id is named.\n */\n descriptor: EntityFieldDescriptor;\n /** The held ids as the draft carries a list: comma-separated, `''` for none. */\n value: string;\n source: EntityLinkSource<TTarget>;\n /** The new comma list, after an id was added or removed. */\n onChange: (next: string) => void;\n /** The id the field's label points at — the input that adds one more. */\n id?: string;\n disabled?: boolean;\n}\n\n/** The draft's comma list as ids, blanks dropped. */\nexport const readIdList = (value: string): string[] =>\n value\n .split(',')\n .map(item => item.trim())\n .filter(item => item !== '');\n\nfunction HeldReference({\n entity,\n id,\n disabled,\n onRemove,\n}: {\n entity: string;\n id: string;\n disabled: boolean;\n onRemove: () => void;\n}) {\n const t = useT();\n const text = useReferenceText(entity, id);\n return (\n <li className=\"flex min-h-(--target-min) items-center gap-3xs rounded-md border border-border bg-surface-elevated ps-2xs text-step-sm text-content\">\n <ReferenceValue entity={entity} id={id} />\n {!disabled && (\n <button\n type=\"button\"\n aria-label={t('link.remove', { item: text })}\n onClick={onRemove}\n className=\"flex min-h-(--target-min) min-w-(--target-min) items-center justify-center rounded-md text-content-muted focus-ring hover:text-content\"\n >\n <svg aria-hidden viewBox=\"0 0 20 20\" className=\"size-4 fill-current\">\n <path d=\"M6 4.6 10 8.6l4-4 1.4 1.4-4 4 4 4-1.4 1.4-4-4-4 4L4.6 14l4-4-4-4z\" />\n </svg>\n </button>\n )}\n </li>\n );\n}\n\n/**\n * The editor for a list of references — a `scalarCollection` that declares\n * `references`, each element one target's id. What is held is a list of names,\n * each with its own remove button; one more is added through the same quick\n * search and browse dialog a single reference uses, so a picker that holds\n * many is the picker that holds one, said twice.\n *\n * It writes the comma list the draft carries for every `scalarCollection`, so\n * validation, reconstruction and every adapter see the ids exactly as before.\n * An id already held is never offered again, and not added twice. An id no record answers still shows\n * — as the noun and a short id — and can still be removed.\n */\nexport function EntityLinkMultiInput<TTarget extends Entity>({\n descriptor,\n value,\n source,\n onChange,\n id,\n disabled = false,\n}: EntityLinkMultiInputProps<TTarget>) {\n const t = useT();\n const held = readIdList(value);\n const entity = descriptor.references?.entity ?? '';\n\n const add = (target: TTarget) => {\n if (target.id == null) return;\n // A held id is never offered, so whatever arrives here is new.\n onChange([...held, String(target.id)].join(','));\n };\n\n const remove = (index: number) =>\n onChange(held.filter((_, at) => at !== index).join(','));\n\n return (\n <div className=\"flex flex-col gap-3xs\">\n {held.length === 0 ? (\n <span\n data-testid={`entity-link-value-${descriptor.name}`}\n className=\"text-step-sm text-content-muted\"\n >\n {t('link.none')}\n </span>\n ) : (\n <ul\n aria-label={descriptor.label}\n data-testid={`entity-link-value-${descriptor.name}`}\n className=\"flex flex-wrap gap-3xs\"\n >\n {held.map((heldId, index) => (\n <HeldReference\n key={heldId}\n entity={entity}\n id={heldId}\n disabled={disabled}\n onRemove={() => remove(index)}\n />\n ))}\n </ul>\n )}\n {!disabled && (\n <EntityLinkInput<TTarget>\n descriptor={descriptor}\n value=\"\"\n source={source}\n id={id}\n adding\n exclude={held}\n onSelect={add}\n />\n )}\n </div>\n );\n}\n"],"names":["useT","ReferenceValue","useReferenceText","EntityLinkInput","readIdList","value","split","map","item","trim","filter","HeldReference","entity","id","disabled","onRemove","t","text","li","className","button","type","aria-label","onClick","svg","aria-hidden","viewBox","path","d","EntityLinkMultiInput","descriptor","source","onChange","held","references","add","target","String","join","remove","index","_","at","div","length","span","data-testid","name","ul","label","heldId","adding","exclude","onSelect"],"mappings":"AAAA;;AAQA,SAASA,IAAI,QAAQ,yBAAyB;AAC9C,SAASC,cAAc,QAAQ,uCAAuC;AACtE,SAASC,gBAAgB,QAAQ,kCAAkC;AACnE,SAASC,eAAe,QAAQ,gCAAgC;AAkBhE,mDAAmD,GACnD,OAAO,MAAMC,aAAa,CAACC,QACzBA,MACGC,KAAK,CAAC,KACNC,GAAG,CAACC,CAAAA,OAAQA,KAAKC,IAAI,IACrBC,MAAM,CAACF,CAAAA,OAAQA,SAAS,IAAI;AAEjC,SAASG,cAAc,EACrBC,MAAM,EACNC,EAAE,EACFC,QAAQ,EACRC,QAAQ,EAMT;IACC,MAAMC,IAAIhB;IACV,MAAMiB,OAAOf,iBAAiBU,QAAQC;IACtC,qBACE,MAACK;QAAGC,WAAU;;0BACZ,KAAClB;gBAAeW,QAAQA;gBAAQC,IAAIA;;YACnC,CAACC,0BACA,KAACM;gBACCC,MAAK;gBACLC,cAAYN,EAAE,eAAe;oBAAER,MAAMS;gBAAK;gBAC1CM,SAASR;gBACTI,WAAU;0BAEV,cAAA,KAACK;oBAAIC,aAAW;oBAACC,SAAQ;oBAAYP,WAAU;8BAC7C,cAAA,KAACQ;wBAAKC,GAAE;;;;;;AAMpB;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,qBAA6C,EAC3DC,UAAU,EACVzB,KAAK,EACL0B,MAAM,EACNC,QAAQ,EACRnB,EAAE,EACFC,WAAW,KAAK,EACmB;;QAGpBgB;IAFf,MAAMd,IAAIhB;IACV,MAAMiC,OAAO7B,WAAWC;IACxB,MAAMO,kBAASkB,yBAAAA,WAAWI,UAAU,qBAArBJ,uBAAuBlB,MAAM,mBAAI;IAEhD,MAAMuB,MAAM,CAACC;QACX,IAAIA,OAAOvB,EAAE,IAAI,MAAM;QACvB,+DAA+D;QAC/DmB,SAAS;eAAIC;YAAMI,OAAOD,OAAOvB,EAAE;SAAE,CAACyB,IAAI,CAAC;IAC7C;IAEA,MAAMC,SAAS,CAACC,QACdR,SAASC,KAAKvB,MAAM,CAAC,CAAC+B,GAAGC,KAAOA,OAAOF,OAAOF,IAAI,CAAC;IAErD,qBACE,MAACK;QAAIxB,WAAU;;YACZc,KAAKW,MAAM,KAAK,kBACf,KAACC;gBACCC,eAAa,CAAC,kBAAkB,EAAEhB,WAAWiB,IAAI,EAAE;gBACnD5B,WAAU;0BAETH,EAAE;+BAGL,KAACgC;gBACC1B,cAAYQ,WAAWmB,KAAK;gBAC5BH,eAAa,CAAC,kBAAkB,EAAEhB,WAAWiB,IAAI,EAAE;gBACnD5B,WAAU;0BAETc,KAAK1B,GAAG,CAAC,CAAC2C,QAAQV,sBACjB,KAAC7B;wBAECC,QAAQA;wBACRC,IAAIqC;wBACJpC,UAAUA;wBACVC,UAAU,IAAMwB,OAAOC;uBAJlBU;;YASZ,CAACpC,0BACA,KAACX;gBACC2B,YAAYA;gBACZzB,OAAM;gBACN0B,QAAQA;gBACRlB,IAAIA;gBACJsC,MAAM;gBACNC,SAASnB;gBACToB,UAAUlB;;;;AAKpB"}
@@ -0,0 +1,2 @@
1
+ export * from './entity-link-multi-input.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-multi-input/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './entity-link-multi-input.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/molecules/entity-link-multi-input/index.ts"],"sourcesContent":["export * from './entity-link-multi-input.js';\n"],"names":[],"mappings":"AAAA,cAAc,+BAA+B"}
@@ -4,6 +4,8 @@ export interface EntityLinkPickerProps<TTarget extends Entity> {
4
4
  descriptor: EntityFieldDescriptor;
5
5
  source: EntityLinkSource<TTarget>;
6
6
  onSelect: (entity: TTarget) => void;
7
+ /** Ids already chosen: their rows say so instead of offering Select. */
8
+ exclude?: readonly string[];
7
9
  }
8
10
  /**
9
11
  * The thorough half of setting a relation: the target entity's own table, with
@@ -15,5 +17,5 @@ export interface EntityLinkPickerProps<TTarget extends Entity> {
15
17
  * Everything it renders comes from `source.browse`, so it holds no fetch of its
16
18
  * own.
17
19
  */
18
- export declare function EntityLinkPicker<TTarget extends Entity>({ descriptor, source, onSelect, }: EntityLinkPickerProps<TTarget>): import("react").JSX.Element;
20
+ export declare function EntityLinkPicker<TTarget extends Entity>({ descriptor, source, onSelect, exclude, }: EntityLinkPickerProps<TTarget>): import("react").JSX.Element;
19
21
  //# sourceMappingURL=entity-link-picker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity-link-picker.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-picker/entity-link-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,qBAAqB,CAAC,OAAO,SAAS,MAAM;IAC3D,2DAA2D;IAC3D,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EAAE,EACvD,UAAU,EACV,MAAM,EACN,QAAQ,GACT,EAAE,qBAAqB,CAAC,OAAO,CAAC,+BAsDhC"}
1
+ {"version":3,"file":"entity-link-picker.d.ts","sourceRoot":"","sources":["../../../../src/ui/molecules/entity-link-picker/entity-link-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,MAAM,EACN,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,qBAAqB,CAAC,OAAO,SAAS,MAAM;IAC3D,2DAA2D;IAC3D,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,wEAAwE;IACxE,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EAAE,EACvD,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,GACR,EAAE,qBAAqB,CAAC,OAAO,CAAC,+BA6DhC"}
@@ -13,7 +13,7 @@ import { EntityTable } from '../../organisms/entity-table/index.js';
13
13
  * the same `EntityTable` and swaps navigation for selection through `onSelect`.
14
14
  * Everything it renders comes from `source.browse`, so it holds no fetch of its
15
15
  * own.
16
- */ export function EntityLinkPicker({ descriptor, source, onSelect }) {
16
+ */ export function EntityLinkPicker({ descriptor, source, onSelect, exclude }) {
17
17
  const t = useT();
18
18
  const { browse } = source;
19
19
  return(// The dialog element itself fills the viewport rather than wrapping a
@@ -65,6 +65,9 @@ import { EntityTable } from '../../organisms/entity-table/index.js';
65
65
  onFilteringChange: browse.onFilteringChange,
66
66
  onSortingChange: browse.onSortingChange,
67
67
  onSelect: onSelect,
68
+ // A row already chosen stays in the page — hiding it would make the
69
+ // page count lie — and says it is chosen rather than offering Select.
70
+ isSelectable: exclude === undefined || exclude.length === 0 ? undefined : (item)=>!exclude.includes(String(item.id)),
68
71
  // Scoped so a picker's column personalization does not overwrite the
69
72
  // one the user set on the full listing of the same entity.
70
73
  preferencesKey: `link-picker:${descriptor.name}`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/molecules/entity-link-picker/entity-link-picker.tsx"],"sourcesContent":["'use client';\n\nimport type {\n Entity,\n EntityFieldDescriptor,\n EntityLinkSource,\n} from '@entifix/core';\nimport { Dialog, DialogPanel, DialogTitle } from '@headlessui/react';\n\nimport { useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { EntityTable } from '../../organisms/entity-table/index.js';\n\nexport interface EntityLinkPickerProps<TTarget extends Entity> {\n /** The relation being set — its label names the dialog. */\n descriptor: EntityFieldDescriptor;\n source: EntityLinkSource<TTarget>;\n onSelect: (entity: TTarget) => void;\n}\n\n/**\n * The thorough half of setting a relation: the target entity's own table, with\n * its filters, sorting and paging, inside a dialog.\n *\n * It adds nothing to the table — that is the point. A picker that re-implemented\n * filtering would drift from the listing the user already knows, so this mounts\n * the same `EntityTable` and swaps navigation for selection through `onSelect`.\n * Everything it renders comes from `source.browse`, so it holds no fetch of its\n * own.\n */\nexport function EntityLinkPicker<TTarget extends Entity>({\n descriptor,\n source,\n onSelect,\n}: EntityLinkPickerProps<TTarget>) {\n const t = useT();\n const { browse } = source;\n\n return (\n // The dialog element itself fills the viewport rather than wrapping a\n // `fixed` child in a `relative` box: a zero-sized dialog is invisible to\n // anything measuring it — assistive tech and Playwright alike — even with a\n // painted panel inside it.\n <Dialog\n open={browse.isOpen}\n onClose={browse.close}\n className=\"inset-0 fixed z-(--z-overlay) flex items-start justify-center overflow-y-auto p-s\"\n >\n {/* Backdrop and panel are separate so a click outside closes the dialog\n without the table's own clicks bubbling into it. */}\n <div aria-hidden className=\"inset-0 fixed bg-scrim\" />\n <DialogPanel className=\"max-w-4xl relative w-full rounded-lg border border-border bg-surface p-s shadow-overlay\">\n <div className=\"flex items-center justify-between gap-s\">\n <DialogTitle className=\"text-step-1 font-semibold text-content\">\n {t('link.browseTitle', { field: descriptor.label })}\n </DialogTitle>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={browse.close}\n >\n {t('link.close')}\n </Button>\n </div>\n\n <EntityTable<TTarget>\n entityConstructor={source.entityConstructor}\n isLoading={browse.isLoading}\n error={browse.error}\n items={browse.items}\n totalItems={browse.totalItems}\n currentPage={browse.currentPage}\n pageSize={browse.pageSize}\n onPageChange={browse.onPageChange}\n onPageSizeChange={browse.onPageSizeChange}\n filtering={browse.filtering}\n sorting={browse.sorting}\n onFilteringChange={browse.onFilteringChange}\n onSortingChange={browse.onSortingChange}\n onSelect={onSelect}\n // Scoped so a picker's column personalization does not overwrite the\n // one the user set on the full listing of the same entity.\n preferencesKey={`link-picker:${descriptor.name}`}\n />\n </DialogPanel>\n </Dialog>\n );\n}\n"],"names":["Dialog","DialogPanel","DialogTitle","useT","Button","EntityTable","EntityLinkPicker","descriptor","source","onSelect","t","browse","open","isOpen","onClose","close","className","div","aria-hidden","field","label","type","variant","size","onClick","entityConstructor","isLoading","error","items","totalItems","currentPage","pageSize","onPageChange","onPageSizeChange","filtering","sorting","onFilteringChange","onSortingChange","preferencesKey","name"],"mappings":"AAAA;;AAOA,SAASA,MAAM,EAAEC,WAAW,EAAEC,WAAW,QAAQ,oBAAoB;AAErE,SAASC,IAAI,QAAQ,yBAAyB;AAC9C,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,WAAW,QAAQ,wCAAwC;AASpE;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAyC,EACvDC,UAAU,EACVC,MAAM,EACNC,QAAQ,EACuB;IAC/B,MAAMC,IAAIP;IACV,MAAM,EAAEQ,MAAM,EAAE,GAAGH;IAEnB,OACE,sEAAsE;IACtE,yEAAyE;IACzE,4EAA4E;IAC5E,2BAA2B;kBAC3B,MAACR;QACCY,MAAMD,OAAOE,MAAM;QACnBC,SAASH,OAAOI,KAAK;QACrBC,WAAU;;0BAIV,KAACC;gBAAIC,aAAW;gBAACF,WAAU;;0BAC3B,MAACf;gBAAYe,WAAU;;kCACrB,MAACC;wBAAID,WAAU;;0CACb,KAACd;gCAAYc,WAAU;0CACpBN,EAAE,oBAAoB;oCAAES,OAAOZ,WAAWa,KAAK;gCAAC;;0CAEnD,KAAChB;gCACCiB,MAAK;gCACLC,SAAQ;gCACRC,MAAK;gCACLC,SAASb,OAAOI,KAAK;0CAEpBL,EAAE;;;;kCAIP,KAACL;wBACCoB,mBAAmBjB,OAAOiB,iBAAiB;wBAC3CC,WAAWf,OAAOe,SAAS;wBAC3BC,OAAOhB,OAAOgB,KAAK;wBACnBC,OAAOjB,OAAOiB,KAAK;wBACnBC,YAAYlB,OAAOkB,UAAU;wBAC7BC,aAAanB,OAAOmB,WAAW;wBAC/BC,UAAUpB,OAAOoB,QAAQ;wBACzBC,cAAcrB,OAAOqB,YAAY;wBACjCC,kBAAkBtB,OAAOsB,gBAAgB;wBACzCC,WAAWvB,OAAOuB,SAAS;wBAC3BC,SAASxB,OAAOwB,OAAO;wBACvBC,mBAAmBzB,OAAOyB,iBAAiB;wBAC3CC,iBAAiB1B,OAAO0B,eAAe;wBACvC5B,UAAUA;wBACV,qEAAqE;wBACrE,2DAA2D;wBAC3D6B,gBAAgB,CAAC,YAAY,EAAE/B,WAAWgC,IAAI,EAAE;;;;;;AAK1D"}
1
+ {"version":3,"sources":["../../../../src/ui/molecules/entity-link-picker/entity-link-picker.tsx"],"sourcesContent":["'use client';\n\nimport type {\n Entity,\n EntityFieldDescriptor,\n EntityLinkSource,\n} from '@entifix/core';\nimport { Dialog, DialogPanel, DialogTitle } from '@headlessui/react';\n\nimport { useT } from '../../../i18n/index.js';\nimport { Button } from '../../atoms/button/index.js';\nimport { EntityTable } from '../../organisms/entity-table/index.js';\n\nexport interface EntityLinkPickerProps<TTarget extends Entity> {\n /** The relation being set — its label names the dialog. */\n descriptor: EntityFieldDescriptor;\n source: EntityLinkSource<TTarget>;\n onSelect: (entity: TTarget) => void;\n /** Ids already chosen: their rows say so instead of offering Select. */\n exclude?: readonly string[];\n}\n\n/**\n * The thorough half of setting a relation: the target entity's own table, with\n * its filters, sorting and paging, inside a dialog.\n *\n * It adds nothing to the table — that is the point. A picker that re-implemented\n * filtering would drift from the listing the user already knows, so this mounts\n * the same `EntityTable` and swaps navigation for selection through `onSelect`.\n * Everything it renders comes from `source.browse`, so it holds no fetch of its\n * own.\n */\nexport function EntityLinkPicker<TTarget extends Entity>({\n descriptor,\n source,\n onSelect,\n exclude,\n}: EntityLinkPickerProps<TTarget>) {\n const t = useT();\n const { browse } = source;\n\n return (\n // The dialog element itself fills the viewport rather than wrapping a\n // `fixed` child in a `relative` box: a zero-sized dialog is invisible to\n // anything measuring it — assistive tech and Playwright alike — even with a\n // painted panel inside it.\n <Dialog\n open={browse.isOpen}\n onClose={browse.close}\n className=\"inset-0 fixed z-(--z-overlay) flex items-start justify-center overflow-y-auto p-s\"\n >\n {/* Backdrop and panel are separate so a click outside closes the dialog\n without the table's own clicks bubbling into it. */}\n <div aria-hidden className=\"inset-0 fixed bg-scrim\" />\n <DialogPanel className=\"max-w-4xl relative w-full rounded-lg border border-border bg-surface p-s shadow-overlay\">\n <div className=\"flex items-center justify-between gap-s\">\n <DialogTitle className=\"text-step-1 font-semibold text-content\">\n {t('link.browseTitle', { field: descriptor.label })}\n </DialogTitle>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={browse.close}\n >\n {t('link.close')}\n </Button>\n </div>\n\n <EntityTable<TTarget>\n entityConstructor={source.entityConstructor}\n isLoading={browse.isLoading}\n error={browse.error}\n items={browse.items}\n totalItems={browse.totalItems}\n currentPage={browse.currentPage}\n pageSize={browse.pageSize}\n onPageChange={browse.onPageChange}\n onPageSizeChange={browse.onPageSizeChange}\n filtering={browse.filtering}\n sorting={browse.sorting}\n onFilteringChange={browse.onFilteringChange}\n onSortingChange={browse.onSortingChange}\n onSelect={onSelect}\n // A row already chosen stays in the page — hiding it would make the\n // page count lie — and says it is chosen rather than offering Select.\n isSelectable={\n exclude === undefined || exclude.length === 0\n ? undefined\n : item => !exclude.includes(String(item.id))\n }\n // Scoped so a picker's column personalization does not overwrite the\n // one the user set on the full listing of the same entity.\n preferencesKey={`link-picker:${descriptor.name}`}\n />\n </DialogPanel>\n </Dialog>\n );\n}\n"],"names":["Dialog","DialogPanel","DialogTitle","useT","Button","EntityTable","EntityLinkPicker","descriptor","source","onSelect","exclude","t","browse","open","isOpen","onClose","close","className","div","aria-hidden","field","label","type","variant","size","onClick","entityConstructor","isLoading","error","items","totalItems","currentPage","pageSize","onPageChange","onPageSizeChange","filtering","sorting","onFilteringChange","onSortingChange","isSelectable","undefined","length","item","includes","String","id","preferencesKey","name"],"mappings":"AAAA;;AAOA,SAASA,MAAM,EAAEC,WAAW,EAAEC,WAAW,QAAQ,oBAAoB;AAErE,SAASC,IAAI,QAAQ,yBAAyB;AAC9C,SAASC,MAAM,QAAQ,8BAA8B;AACrD,SAASC,WAAW,QAAQ,wCAAwC;AAWpE;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAyC,EACvDC,UAAU,EACVC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACwB;IAC/B,MAAMC,IAAIR;IACV,MAAM,EAAES,MAAM,EAAE,GAAGJ;IAEnB,OACE,sEAAsE;IACtE,yEAAyE;IACzE,4EAA4E;IAC5E,2BAA2B;kBAC3B,MAACR;QACCa,MAAMD,OAAOE,MAAM;QACnBC,SAASH,OAAOI,KAAK;QACrBC,WAAU;;0BAIV,KAACC;gBAAIC,aAAW;gBAACF,WAAU;;0BAC3B,MAAChB;gBAAYgB,WAAU;;kCACrB,MAACC;wBAAID,WAAU;;0CACb,KAACf;gCAAYe,WAAU;0CACpBN,EAAE,oBAAoB;oCAAES,OAAOb,WAAWc,KAAK;gCAAC;;0CAEnD,KAACjB;gCACCkB,MAAK;gCACLC,SAAQ;gCACRC,MAAK;gCACLC,SAASb,OAAOI,KAAK;0CAEpBL,EAAE;;;;kCAIP,KAACN;wBACCqB,mBAAmBlB,OAAOkB,iBAAiB;wBAC3CC,WAAWf,OAAOe,SAAS;wBAC3BC,OAAOhB,OAAOgB,KAAK;wBACnBC,OAAOjB,OAAOiB,KAAK;wBACnBC,YAAYlB,OAAOkB,UAAU;wBAC7BC,aAAanB,OAAOmB,WAAW;wBAC/BC,UAAUpB,OAAOoB,QAAQ;wBACzBC,cAAcrB,OAAOqB,YAAY;wBACjCC,kBAAkBtB,OAAOsB,gBAAgB;wBACzCC,WAAWvB,OAAOuB,SAAS;wBAC3BC,SAASxB,OAAOwB,OAAO;wBACvBC,mBAAmBzB,OAAOyB,iBAAiB;wBAC3CC,iBAAiB1B,OAAO0B,eAAe;wBACvC7B,UAAUA;wBACV,oEAAoE;wBACpE,sEAAsE;wBACtE8B,cACE7B,YAAY8B,aAAa9B,QAAQ+B,MAAM,KAAK,IACxCD,YACAE,CAAAA,OAAQ,CAAChC,QAAQiC,QAAQ,CAACC,OAAOF,KAAKG,EAAE;wBAE9C,qEAAqE;wBACrE,2DAA2D;wBAC3DC,gBAAgB,CAAC,YAAY,EAAEvC,WAAWwC,IAAI,EAAE;;;;;;AAK1D"}
@@ -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;AAuCvB,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,QAAgB,EAChB,SAAiB,EACjB,QAAe,EACf,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,KAAK,EACL,OAAO,EACP,UAAU,EACV,aAAa,EACb,QAAQ,EACR,UAAyB,EACzB,KAAK,EACL,QAAQ,EACR,iBAAyB,EACzB,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,GACT,EAAE,eAAe,CAAC,OAAO,CAAC,+BAygB1B"}
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,EAcZ,MAAM,eAAe,CAAC;AAwCvB,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,wBAAwB,CAAC;AA+DhC,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,QAAgB,EAChB,SAAiB,EACjB,QAAe,EACf,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,KAAK,EACL,OAAO,EACP,UAAU,EACV,aAAa,EACb,QAAQ,EACR,UAAyB,EACzB,KAAK,EACL,QAAQ,EACR,iBAAyB,EACzB,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,GACT,EAAE,eAAe,CAAC,OAAO,CAAC,+BA0iB1B"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { _ as _extends } from "@swc/helpers/_/_extends";
3
3
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
- import { cloneEntityDraft, describeEntityColumns, extractMetaEntity, readDraftString, readLocalizedDraft, readRowDrafts } from '@entifix/core';
4
+ import { cloneEntityDraft, describeEntityColumns, extractMetaEntity, isRecordDeletable, isRecordWritable, 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
7
  import { availableUseCases, renderAnchor, useCasesForSurface } from '../../actions/index.js';
@@ -16,6 +16,7 @@ import { Text } from '../../atoms/text/index.js';
16
16
  import { ActionBar, itemsForUseCases } from '../../molecules/action-bar/index.js';
17
17
  import { Card } from '../../molecules/card/index.js';
18
18
  import { EntityLinkInput } from '../../molecules/entity-link-input/index.js';
19
+ import { EntityLinkMultiInput } from '../../molecules/entity-link-multi-input/index.js';
19
20
  import { LoadingBoundary } from '../../molecules/loading-boundary/index.js';
20
21
  import { RegionState } from '../../molecules/region-state/index.js';
21
22
  import { Stack } from '../../molecules/stack/index.js';
@@ -38,6 +39,12 @@ import { resolveEntityFormFields } from './use-entity-form-fields.js';
38
39
  * the *only* place `link`-ness still matters is `applyEntityLinks` at submit,
39
40
  * which skips a non-`link` descriptor and so leaves the id as the truth.
40
41
  *
42
+ * A `scalarCollection` that declares `references` is the to-many form of the
43
+ * same thing: each element is one target's id, and the editor is
44
+ * `EntityLinkMultiInput`, which adds and removes ids by name. Without
45
+ * `references` a list of values names no record, so a source on it is the
46
+ * same wiring mistake as one on a `number`.
47
+ *
41
48
  * Everything else is excluded on purpose rather than by omission: a `boolean`,
42
49
  * `enum`, `number` or `date` member cannot name another record, so a source
43
50
  * pointed at one is a wiring mistake — see {@link assertLinkSourcesAreEditable}.
@@ -45,6 +52,7 @@ import { resolveEntityFormFields } from './use-entity-form-fields.js';
45
52
  'link',
46
53
  'string'
47
54
  ]);
55
+ /** A list of ids into another entity: a `scalarCollection` that declares `references`. */ const isReferenceList = (field)=>field.type === 'scalarCollection' && field.references !== undefined;
48
56
  /**
49
57
  * A form that builds itself from an entity's metadata: fields, labels and value
50
58
  * formatting all come from `@accessor()` declarations, so editing a new entity
@@ -97,7 +105,13 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
97
105
  */ const customSkeleton = typeof skeleton === 'boolean' ? undefined : skeleton;
98
106
  const showSkeleton = isLoading && skeleton !== false;
99
107
  const [internalMode, setInternalMode] = useState(defaultMode != null ? defaultMode : entity ? 'read' : 'edit');
100
- const mode = modeProp != null ? modeProp : internalMode;
108
+ // A stored record outside the states it may be saved in is read, not
109
+ // edited: no field takes input and there is no Save (ADR 0029). The verbs
110
+ // its state allows stay, so the next legal move — a New version — is right
111
+ // there. A create has no state to hold, and absent metadata decides nothing.
112
+ const frozen = entity !== undefined && metadata !== undefined && !isRecordWritable(metadata, entity);
113
+ const undeletable = entity !== undefined && metadata !== undefined && !isRecordDeletable(metadata, entity);
114
+ const mode = frozen ? 'read' : modeProp != null ? modeProp : internalMode;
101
115
  const editing = mode === 'edit';
102
116
  const draft = values != null ? values : {};
103
117
  const setField = (name, value)=>onFieldChange == null ? void 0 : onFieldChange(name, value);
@@ -128,7 +142,10 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
128
142
  // Absent metadata keeps the pre-ADR-0026 behaviour, so an un-migrated call
129
143
  // site renders exactly as before. Present metadata is authoritative: it is
130
144
  // what the service already decided this caller may do.
131
- const may = (action)=>metadata === undefined || metadata.actions.includes(action);
145
+ const granted = (action)=>metadata === undefined || metadata.actions.includes(action);
146
+ // What this caller may do with **this** record: the grant, narrowed by the
147
+ // record's state. Clone asks for the grant alone — what it makes is a create.
148
+ const may = (action)=>granted(action) && !(action === 'write' && frozen) && !(action === 'delete' && undeletable);
132
149
  // A single-record form shows the verbs that act on *this* record. Which cell
133
150
  // lands where is `action-surfaces`' business and nobody else's — a
134
151
  // `context-dependent` entity verb belongs to a row's overflow menu and a
@@ -154,9 +171,12 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
154
171
  // A verb that moved its record out of the states it applies to unmounts the
155
172
  // button the reader just pressed; focus goes to the heading, not `<body>`.
156
173
  useFocusOnLoss(()=>heading.current, [
157
- ...headerUseCases,
158
- ...footerUseCases
159
- ].map(({ key })=>key).join(' '));
174
+ ...headerUseCases.map(({ key })=>key),
175
+ ...footerUseCases.map(({ key })=>key),
176
+ ...frozen ? [] : [
177
+ 'save'
178
+ ]
179
+ ].join(' '));
160
180
  // Every verb on the form, and its own Delete, goes through one invoker: a
161
181
  // destructive verb asks, asks for the name, or runs and offers Undo, as it
162
182
  // declared — `revoke-sessions` ends every session a user holds.
@@ -256,7 +276,7 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
256
276
  // Clone is the CRUD triple's, not a declared verb's: every entity can be
257
277
  // copied, so giving it a `@useCase()` would mean declaring the same verb on
258
278
  // all 28 of them. It needs `write`, because what it produces is a create.
259
- ...onClone && entity && may('write') ? [
279
+ ...onClone && entity && granted('write') ? [
260
280
  {
261
281
  key: 'clone',
262
282
  label: t('form.clone'),
@@ -306,7 +326,7 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
306
326
  className: "focus-ring",
307
327
  children: title != null ? title : entity || isLoading ? t('form.details') : t('form.new')
308
328
  }),
309
- modeProp === undefined && entity && /*#__PURE__*/ _jsx(Button, {
329
+ modeProp === undefined && entity && !frozen && /*#__PURE__*/ _jsx(Button, {
310
330
  type: "button",
311
331
  variant: "ghost",
312
332
  size: "sm",
@@ -328,6 +348,11 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
328
348
  })
329
349
  ]
330
350
  }),
351
+ frozen && metadata.readOnlyReasonKey !== undefined && /*#__PURE__*/ _jsx(Alert, {
352
+ tone: "info",
353
+ "data-testid": "entity-form-read-only",
354
+ children: translateKey(metadata.readOnlyReasonKey)
355
+ }),
331
356
  /*#__PURE__*/ _jsx("span", {
332
357
  role: "status",
333
358
  "aria-live": "polite",
@@ -445,7 +470,7 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
445
470
  className: "text-step-sm text-danger",
446
471
  children: formError
447
472
  }),
448
- editing && !embedded && /*#__PURE__*/ _jsxs(Stack, {
473
+ (editing || frozen) && !embedded && /*#__PURE__*/ _jsxs(Stack, {
449
474
  direction: "row",
450
475
  gap: "xs",
451
476
  align: "center",
@@ -533,7 +558,7 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
533
558
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
534
559
  linkSources) {
535
560
  if (linkSources === undefined) return;
536
- const sourced = fields.filter((field)=>linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type));
561
+ const sourced = fields.filter((field)=>linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type) && !isReferenceList(field));
537
562
  if (sourced.length === 0) return;
538
563
  const toMany = sourced.filter((field)=>field.type === 'linkCollection').map((field)=>field.name);
539
564
  if (toMany.length > 0) {
@@ -544,7 +569,7 @@ linkSources) {
544
569
  throw new Error(`EntityForm was given a link source for an owned collection: ${owned.join(', ')}. ` + 'A `composition` is not a reference — its rows have no life outside this ' + 'record and are never picked from existing ones, so there is nothing for a ' + 'picker to look up. The detail grid is what edits them.');
545
570
  }
546
571
  const unpickable = sourced.map((field)=>`${field.name} (${field.type})`);
547
- throw new Error(`EntityForm was given a link source for a member that cannot hold one: ${unpickable.join(', ')}. ` + 'A picker writes the target’s id into the draft, so the member has to be a ' + '`link` or the `string` that carries a foreign key. Remove the entry, or ' + 'point it at the member that actually holds the reference.');
572
+ throw new Error(`EntityForm was given a link source for a member that cannot hold one: ${unpickable.join(', ')}. ` + 'A picker writes the target’s id into the draft, so the member has to be a ' + '`link`, the `string` that carries a foreign key, or a `scalarCollection` ' + 'that declares `references`. Remove the entry, or point it at the member ' + 'that actually holds the reference.');
548
573
  }
549
574
  /**
550
575
  * One label + control (or value) row. A `readonly` member renders its read
@@ -578,6 +603,15 @@ linkSources) {
578
603
  setField,
579
604
  id
580
605
  });
606
+ } else if (linkSource && isReferenceList(field)) {
607
+ control = /*#__PURE__*/ _jsx(EntityLinkMultiInput, {
608
+ descriptor: field,
609
+ value: value,
610
+ source: linkSource,
611
+ id: id,
612
+ disabled: field.readonly,
613
+ onChange: (next)=>setField(field.name, next)
614
+ });
581
615
  } else if (linkSource && PICKABLE_TYPES.has(field.type)) {
582
616
  control = /*#__PURE__*/ _jsx(EntityLinkInput, {
583
617
  descriptor: field,