@entifix/react-controls 0.23.9 → 0.23.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/i18n/catalog/en.d.ts.map +1 -1
- package/dist/i18n/catalog/en.js +3 -0
- package/dist/i18n/catalog/en.js.map +1 -1
- package/dist/i18n/catalog/es.d.ts +3 -0
- package/dist/i18n/catalog/es.d.ts.map +1 -1
- package/dist/i18n/catalog/es.js +3 -0
- package/dist/i18n/catalog/es.js.map +1 -1
- package/dist/i18n/catalog/index.d.ts +6 -0
- package/dist/i18n/catalog/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts +12 -0
- package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.js +20 -2
- package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
- package/dist/ui/molecules/entity-link-input/entity-link-input.d.ts +9 -3
- package/dist/ui/molecules/entity-link-input/entity-link-input.d.ts.map +1 -1
- package/dist/ui/molecules/entity-link-input/entity-link-input.js +9 -5
- package/dist/ui/molecules/entity-link-input/entity-link-input.js.map +1 -1
- package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.d.ts +32 -0
- package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.d.ts.map +1 -0
- package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.js +94 -0
- package/dist/ui/molecules/entity-link-multi-input/entity-link-multi-input.js.map +1 -0
- package/dist/ui/molecules/entity-link-multi-input/index.d.ts +2 -0
- package/dist/ui/molecules/entity-link-multi-input/index.d.ts.map +1 -0
- package/dist/ui/molecules/entity-link-multi-input/index.js +3 -0
- package/dist/ui/molecules/entity-link-multi-input/index.js.map +1 -0
- package/dist/ui/organisms/entity-form/entity-form.d.ts.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.js +19 -2
- package/dist/ui/organisms/entity-form/entity-form.js.map +1 -1
- package/dist/ui/utils/reference-labels.d.ts +7 -0
- package/dist/ui/utils/reference-labels.d.ts.map +1 -1
- package/dist/ui/utils/reference-labels.js +21 -2
- package/dist/ui/utils/reference-labels.js.map +1 -1
- package/package.json +11 -11
|
@@ -57,13 +57,15 @@ 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 }) {
|
|
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 =
|
|
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
|
|
@@ -89,7 +91,9 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
|
|
|
89
91
|
children: [
|
|
90
92
|
/*#__PURE__*/ _jsx(ComboboxInput, {
|
|
91
93
|
id: id,
|
|
92
|
-
"aria-label": t('link.
|
|
94
|
+
"aria-label": adding ? t('link.add', {
|
|
95
|
+
field: descriptor.label
|
|
96
|
+
}) : t('link.search', {
|
|
93
97
|
field: descriptor.label
|
|
94
98
|
}),
|
|
95
99
|
placeholder: display,
|
|
@@ -169,7 +173,7 @@ import { LoadingBoundary } from '../loading-boundary/index.js';
|
|
|
169
173
|
})
|
|
170
174
|
]
|
|
171
175
|
}),
|
|
172
|
-
/*#__PURE__*/ _jsx("span", {
|
|
176
|
+
!adding && /*#__PURE__*/ _jsx("span", {
|
|
173
177
|
"data-testid": `entity-link-value-${descriptor.name}`,
|
|
174
178
|
className: "text-step-sm text-content",
|
|
175
179
|
children: display
|
|
@@ -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":"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;AAiB/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;gBA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4B,KAAK;;0BAIpC,KAAC3D;gBACCe,YAAYA;gBACZE,QAAQA;gBACRC,UAAUY,CAAAA;oBACRZ,SAASY;oBACTb,OAAOqC,MAAM,CAACO,KAAK;gBACrB;;;;AAIR"}
|
|
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\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}: 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 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 && 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 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 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","t","errorMessage","assigned","label","selected","display","field","isLoading","handleSelect","entity","quick","setTerm","div","onChange","immediate","aria-label","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":"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;AAuB/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;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EAAE,cAAc;4BAAEM,OAAOd,WAAWW,KAAK;wBAAC;;;;YAOhD,CAACJ,wBACA,KAACmC;gBACCC,eAAa,CAAC,kBAAkB,EAAE3C,WAAW4C,IAAI,EAAE;gBACnDrD,WAAU;0BAETsB;;YAIJX,OAAOgB,KAAK,CAAC2B,KAAK,kBACjB,KAACH;gBAAKI,MAAK;gBAAQvD,WAAU;0BAC1BkB,aAAaP,OAAOgB,KAAK,CAAC2B,KAAK;;0BAIpC,KAAC5D;gBACCe,YAAYA;gBACZE,QAAQA;gBACRC,UAAUc,CAAAA;oBACRd,SAASc;oBACTf,OAAOsC,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 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 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
|
+
const next = String(target.id);
|
|
57
|
+
if (held.includes(next)) return;
|
|
58
|
+
onChange([
|
|
59
|
+
...held,
|
|
60
|
+
next
|
|
61
|
+
].join(','));
|
|
62
|
+
};
|
|
63
|
+
const remove = (index)=>onChange(held.filter((_, at)=>at !== index).join(','));
|
|
64
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
65
|
+
className: "flex flex-col gap-3xs",
|
|
66
|
+
children: [
|
|
67
|
+
held.length === 0 ? /*#__PURE__*/ _jsx("span", {
|
|
68
|
+
"data-testid": `entity-link-value-${descriptor.name}`,
|
|
69
|
+
className: "text-step-sm text-content-muted",
|
|
70
|
+
children: t('link.none')
|
|
71
|
+
}) : /*#__PURE__*/ _jsx("ul", {
|
|
72
|
+
"aria-label": descriptor.label,
|
|
73
|
+
"data-testid": `entity-link-value-${descriptor.name}`,
|
|
74
|
+
className: "flex flex-wrap gap-3xs",
|
|
75
|
+
children: held.map((heldId, index)=>/*#__PURE__*/ _jsx(HeldReference, {
|
|
76
|
+
entity: entity,
|
|
77
|
+
id: heldId,
|
|
78
|
+
disabled: disabled,
|
|
79
|
+
onRemove: ()=>remove(index)
|
|
80
|
+
}, heldId))
|
|
81
|
+
}),
|
|
82
|
+
!disabled && /*#__PURE__*/ _jsx(EntityLinkInput, {
|
|
83
|
+
descriptor: descriptor,
|
|
84
|
+
value: "",
|
|
85
|
+
source: source,
|
|
86
|
+
id: id,
|
|
87
|
+
adding: true,
|
|
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 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 const next = String(target.id);\n if (held.includes(next)) return;\n onChange([...held, next].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 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","next","String","includes","join","remove","index","_","at","div","length","span","data-testid","name","ul","label","heldId","adding","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,MAAMwB,OAAOC,OAAOF,OAAOvB,EAAE;QAC7B,IAAIoB,KAAKM,QAAQ,CAACF,OAAO;QACzBL,SAAS;eAAIC;YAAMI;SAAK,CAACG,IAAI,CAAC;IAChC;IAEA,MAAMC,SAAS,CAACC,QACdV,SAASC,KAAKvB,MAAM,CAAC,CAACiC,GAAGC,KAAOA,OAAOF,OAAOF,IAAI,CAAC;IAErD,qBACE,MAACK;QAAI1B,WAAU;;YACZc,KAAKa,MAAM,KAAK,kBACf,KAACC;gBACCC,eAAa,CAAC,kBAAkB,EAAElB,WAAWmB,IAAI,EAAE;gBACnD9B,WAAU;0BAETH,EAAE;+BAGL,KAACkC;gBACC5B,cAAYQ,WAAWqB,KAAK;gBAC5BH,eAAa,CAAC,kBAAkB,EAAElB,WAAWmB,IAAI,EAAE;gBACnD9B,WAAU;0BAETc,KAAK1B,GAAG,CAAC,CAAC6C,QAAQV,sBACjB,KAAC/B;wBAECC,QAAQA;wBACRC,IAAIuC;wBACJtC,UAAUA;wBACVC,UAAU,IAAM0B,OAAOC;uBAJlBU;;YASZ,CAACtC,0BACA,KAACX;gBACC2B,YAAYA;gBACZzB,OAAM;gBACN0B,QAAQA;gBACRlB,IAAIA;gBACJwC,MAAM;gBACNC,UAAUnB;;;;AAKpB"}
|
|
@@ -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 @@
|
|
|
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"}
|
|
@@ -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,
|
|
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,EAYZ,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,+BAygB1B"}
|
|
@@ -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
|
|
@@ -533,7 +541,7 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
|
|
|
533
541
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
534
542
|
linkSources) {
|
|
535
543
|
if (linkSources === undefined) return;
|
|
536
|
-
const sourced = fields.filter((field)=>linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type));
|
|
544
|
+
const sourced = fields.filter((field)=>linkSources[field.name] !== undefined && !PICKABLE_TYPES.has(field.type) && !isReferenceList(field));
|
|
537
545
|
if (sourced.length === 0) return;
|
|
538
546
|
const toMany = sourced.filter((field)=>field.type === 'linkCollection').map((field)=>field.name);
|
|
539
547
|
if (toMany.length > 0) {
|
|
@@ -544,7 +552,7 @@ linkSources) {
|
|
|
544
552
|
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
553
|
}
|
|
546
554
|
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
|
|
555
|
+
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
556
|
}
|
|
549
557
|
/**
|
|
550
558
|
* One label + control (or value) row. A `readonly` member renders its read
|
|
@@ -578,6 +586,15 @@ linkSources) {
|
|
|
578
586
|
setField,
|
|
579
587
|
id
|
|
580
588
|
});
|
|
589
|
+
} else if (linkSource && isReferenceList(field)) {
|
|
590
|
+
control = /*#__PURE__*/ _jsx(EntityLinkMultiInput, {
|
|
591
|
+
descriptor: field,
|
|
592
|
+
value: value,
|
|
593
|
+
source: linkSource,
|
|
594
|
+
id: id,
|
|
595
|
+
disabled: field.readonly,
|
|
596
|
+
onChange: (next)=>setField(field.name, next)
|
|
597
|
+
});
|
|
581
598
|
} else if (linkSource && PICKABLE_TYPES.has(field.type)) {
|
|
582
599
|
control = /*#__PURE__*/ _jsx(EntityLinkInput, {
|
|
583
600
|
descriptor: field,
|