@masterteam/components 0.0.302 → 0.0.304

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.
@@ -3,10 +3,10 @@ import * as i0 from '@angular/core';
3
3
  import { input, inject, DestroyRef, signal, computed, ChangeDetectionStrategy, Component, ChangeDetectorRef, effect, untracked, viewChild, linkedSignal, InjectionToken } from '@angular/core';
4
4
  import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
5
5
  import * as i1 from '@angular/forms';
6
- import { ControlContainer, NgControl, FormsModule, Validators } from '@angular/forms';
6
+ import { ControlContainer, NgControl, FormsModule, Validators, FormControl, ReactiveFormsModule } from '@angular/forms';
7
7
  import * as i2 from '@jsverse/transloco';
8
8
  import { TranslocoService, TranslocoModule, TranslocoPipe } from '@jsverse/transloco';
9
- import { startWith, finalize, catchError, of, take, expand, EMPTY, reduce, map } from 'rxjs';
9
+ import { startWith, finalize, catchError, of, debounceTime, map, distinctUntilChanged, take, expand, EMPTY, reduce } from 'rxjs';
10
10
  import { Tooltip } from '@masterteam/components/tooltip';
11
11
  import { Icon } from '@masterteam/icons';
12
12
  import { SelectField } from '@masterteam/components/select-field';
@@ -20,7 +20,9 @@ import { newFieldId, coerceCheckboxValue } from '@masterteam/components';
20
20
  import { Skeleton } from 'primeng/skeleton';
21
21
  import { Message } from 'primeng/message';
22
22
  import { ModalService } from '@masterteam/components/modal';
23
- import { sortLocalRows, visibleLocalSchemaFields, resolveLocalFieldViewType, resolveLocalFieldLabel, localCellsByFieldId, resolveLocalFieldConfiguration, isEntityListLocalDocument, serializeEntityRawValue, readEntityValueColor, EntityRuntimeContextStore, ENTITY_LIST_TABLE_COMPONENT } from '@masterteam/components/entities';
23
+ import { sortLocalRows, visibleLocalSchemaFields, resolveLocalFieldViewType, resolveLocalFieldLabel, localCellsByFieldId, resolveLocalFieldConfiguration, isEntityListSelectionDocument, isEntityListLocalDocument, serializeEntityRawValue, readEntityValueColor, EntityRuntimeContextStore, ENTITY_LIST_TABLE_COMPONENT } from '@masterteam/components/entities';
24
+ import { ModalRef } from '@masterteam/components/dialog';
25
+ import { TextField } from '@masterteam/components/text-field';
24
26
  import * as i2$1 from 'primeng/inputtext';
25
27
  import { InputTextModule } from 'primeng/inputtext';
26
28
 
@@ -543,7 +545,7 @@ class SchemaConnectionField {
543
545
  this.disabled.set(disabled);
544
546
  }
545
547
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: SchemaConnectionField, deps: [], target: i0.ɵɵFactoryTarget.Component });
546
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: SchemaConnectionField, isStandalone: true, selector: "mt-schema-connection-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: true, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, ngImport: i0, template: "<div class=\"flex gap-4 w-full\">\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\n <!--\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\n every other mt-* field gets from its host class; the explicit column\n keeps the implicit max-content track from letting long values overflow.\n -->\n <div\n [style.width]=\"dropdownWidth()\"\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\n >\n <div class=\"flex items-center gap-1\">\n <label\n class=\"truncate\"\n [class.required]=\"state.source.isOptional !== true\"\n >\n {{ resolveSourceName(state.source) }}\n </label>\n <span\n class=\"inline-flex shrink-0 text-surface-400\"\n [mtTooltip]=\"connectionHint()\"\n tooltipPosition=\"top\"\n >\n <mt-icon icon=\"general.link-01\" />\n </span>\n </div>\n\n @if (state.source.allowManyToMany) {\n <mt-multi-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [showClear]=\"state.source.isOptional === true\"\n display=\"chip\"\n />\n } @else {\n <mt-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [loading]=\"state.loading\"\n [showClear]=\"state.source.isOptional === true\"\n />\n }\n\n <!--\n The error belongs to the dropdown that is empty, not to the field. One\n message below the whole row always rendered under the first source, so\n a missing `Program` read as an error on `Portfolio`.\n -->\n <mt-field-validation\n [control]=\"sourceErrorControl(state.source)\"\n ></mt-field-validation>\n </div>\n }\n</div>\n\n<!--\n Whatever the control reports that no single source owns \u2014 a server error, say.\n Null while a source is missing, so the message is never shown twice.\n-->\n<mt-field-validation\n [control]=\"unattributedErrorControl()\"\n></mt-field-validation>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: SelectField, selector: "mt-select-field", inputs: ["field", "hint", "label", "placeholder", "hasPlaceholderPrefix", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "clearAfterSelect", "required", "group", "size", "optionGroupLabel", "optionGroupChildren", "loading", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape", "markCurrentUser"], outputs: ["onChange"] }, { kind: "component", type: MultiSelectField, selector: "mt-multi-select-field", inputs: ["field", "label", "placeholder", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "display", "required", "maxSelectedLabels", "group", "virtualScroll", "virtualScrollItemSize", "optionGroupLabel", "optionGroupChildren", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape"], outputs: ["onChange"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
548
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: SchemaConnectionField, isStandalone: true, selector: "mt-schema-connection-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: true, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, ngImport: i0, template: "<div class=\"flex gap-4 w-full\">\r\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\r\n <!--\r\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\r\n every other mt-* field gets from its host class; the explicit column\r\n keeps the implicit max-content track from letting long values overflow.\r\n -->\r\n <div\r\n [style.width]=\"dropdownWidth()\"\r\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\r\n >\r\n <div class=\"flex items-center gap-1\">\r\n <label\r\n class=\"truncate\"\r\n [class.required]=\"state.source.isOptional !== true\"\r\n >\r\n {{ resolveSourceName(state.source) }}\r\n </label>\r\n <span\r\n class=\"inline-flex shrink-0 text-surface-400\"\r\n [mtTooltip]=\"connectionHint()\"\r\n tooltipPosition=\"top\"\r\n >\r\n <mt-icon icon=\"general.link-01\" />\r\n </span>\r\n </div>\r\n\r\n @if (state.source.allowManyToMany) {\r\n <mt-multi-select-field\r\n [field]=\"false\"\r\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\r\n (ngModelChange)=\"syncValue()\"\r\n [options]=\"state.options\"\r\n optionLabel=\"name\"\r\n optionValue=\"id\"\r\n [placeholder]=\"sourcePlaceholder(state.source)\"\r\n [readonly]=\"disabled() || readonly()\"\r\n [filter]=\"filter()\"\r\n [showClear]=\"state.source.isOptional === true\"\r\n display=\"chip\"\r\n />\r\n } @else {\r\n <mt-select-field\r\n [field]=\"false\"\r\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\r\n (ngModelChange)=\"syncValue()\"\r\n [options]=\"state.options\"\r\n optionLabel=\"name\"\r\n optionValue=\"id\"\r\n [placeholder]=\"sourcePlaceholder(state.source)\"\r\n [readonly]=\"disabled() || readonly()\"\r\n [filter]=\"filter()\"\r\n [loading]=\"state.loading\"\r\n [showClear]=\"state.source.isOptional === true\"\r\n />\r\n }\r\n\r\n <!--\r\n The error belongs to the dropdown that is empty, not to the field. One\r\n message below the whole row always rendered under the first source, so\r\n a missing `Program` read as an error on `Portfolio`.\r\n -->\r\n <mt-field-validation\r\n [control]=\"sourceErrorControl(state.source)\"\r\n ></mt-field-validation>\r\n </div>\r\n }\r\n</div>\r\n\r\n<!--\r\n Whatever the control reports that no single source owns \u2014 a server error, say.\r\n Null while a source is missing, so the message is never shown twice.\r\n-->\r\n<mt-field-validation\r\n [control]=\"unattributedErrorControl()\"\r\n></mt-field-validation>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: SelectField, selector: "mt-select-field", inputs: ["field", "hint", "label", "placeholder", "hasPlaceholderPrefix", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "clearAfterSelect", "required", "group", "size", "optionGroupLabel", "optionGroupChildren", "loading", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape", "markCurrentUser"], outputs: ["onChange"] }, { kind: "component", type: MultiSelectField, selector: "mt-multi-select-field", inputs: ["field", "label", "placeholder", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "display", "required", "maxSelectedLabels", "group", "virtualScroll", "virtualScrollItemSize", "optionGroupLabel", "optionGroupChildren", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape"], outputs: ["onChange"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
547
549
  }
548
550
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: SchemaConnectionField, decorators: [{
549
551
  type: Component,
@@ -556,7 +558,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
556
558
  Icon,
557
559
  ], changeDetection: ChangeDetectionStrategy.OnPush, host: {
558
560
  class: 'grid gap-1',
559
- }, template: "<div class=\"flex gap-4 w-full\">\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\n <!--\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\n every other mt-* field gets from its host class; the explicit column\n keeps the implicit max-content track from letting long values overflow.\n -->\n <div\n [style.width]=\"dropdownWidth()\"\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\n >\n <div class=\"flex items-center gap-1\">\n <label\n class=\"truncate\"\n [class.required]=\"state.source.isOptional !== true\"\n >\n {{ resolveSourceName(state.source) }}\n </label>\n <span\n class=\"inline-flex shrink-0 text-surface-400\"\n [mtTooltip]=\"connectionHint()\"\n tooltipPosition=\"top\"\n >\n <mt-icon icon=\"general.link-01\" />\n </span>\n </div>\n\n @if (state.source.allowManyToMany) {\n <mt-multi-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [showClear]=\"state.source.isOptional === true\"\n display=\"chip\"\n />\n } @else {\n <mt-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [loading]=\"state.loading\"\n [showClear]=\"state.source.isOptional === true\"\n />\n }\n\n <!--\n The error belongs to the dropdown that is empty, not to the field. One\n message below the whole row always rendered under the first source, so\n a missing `Program` read as an error on `Portfolio`.\n -->\n <mt-field-validation\n [control]=\"sourceErrorControl(state.source)\"\n ></mt-field-validation>\n </div>\n }\n</div>\n\n<!--\n Whatever the control reports that no single source owns \u2014 a server error, say.\n Null while a source is missing, so the message is never shown twice.\n-->\n<mt-field-validation\n [control]=\"unattributedErrorControl()\"\n></mt-field-validation>\n" }]
561
+ }, template: "<div class=\"flex gap-4 w-full\">\r\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\r\n <!--\r\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\r\n every other mt-* field gets from its host class; the explicit column\r\n keeps the implicit max-content track from letting long values overflow.\r\n -->\r\n <div\r\n [style.width]=\"dropdownWidth()\"\r\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\r\n >\r\n <div class=\"flex items-center gap-1\">\r\n <label\r\n class=\"truncate\"\r\n [class.required]=\"state.source.isOptional !== true\"\r\n >\r\n {{ resolveSourceName(state.source) }}\r\n </label>\r\n <span\r\n class=\"inline-flex shrink-0 text-surface-400\"\r\n [mtTooltip]=\"connectionHint()\"\r\n tooltipPosition=\"top\"\r\n >\r\n <mt-icon icon=\"general.link-01\" />\r\n </span>\r\n </div>\r\n\r\n @if (state.source.allowManyToMany) {\r\n <mt-multi-select-field\r\n [field]=\"false\"\r\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\r\n (ngModelChange)=\"syncValue()\"\r\n [options]=\"state.options\"\r\n optionLabel=\"name\"\r\n optionValue=\"id\"\r\n [placeholder]=\"sourcePlaceholder(state.source)\"\r\n [readonly]=\"disabled() || readonly()\"\r\n [filter]=\"filter()\"\r\n [showClear]=\"state.source.isOptional === true\"\r\n display=\"chip\"\r\n />\r\n } @else {\r\n <mt-select-field\r\n [field]=\"false\"\r\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\r\n (ngModelChange)=\"syncValue()\"\r\n [options]=\"state.options\"\r\n optionLabel=\"name\"\r\n optionValue=\"id\"\r\n [placeholder]=\"sourcePlaceholder(state.source)\"\r\n [readonly]=\"disabled() || readonly()\"\r\n [filter]=\"filter()\"\r\n [loading]=\"state.loading\"\r\n [showClear]=\"state.source.isOptional === true\"\r\n />\r\n }\r\n\r\n <!--\r\n The error belongs to the dropdown that is empty, not to the field. One\r\n message below the whole row always rendered under the first source, so\r\n a missing `Program` read as an error on `Portfolio`.\r\n -->\r\n <mt-field-validation\r\n [control]=\"sourceErrorControl(state.source)\"\r\n ></mt-field-validation>\r\n </div>\r\n }\r\n</div>\r\n\r\n<!--\r\n Whatever the control reports that no single source owns \u2014 a server error, say.\r\n Null while a source is missing, so the message is never shown twice.\r\n-->\r\n<mt-field-validation\r\n [control]=\"unattributedErrorControl()\"\r\n></mt-field-validation>\r\n" }]
560
562
  }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: true }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
561
563
 
562
564
  const PREDECESSOR_TYPE_BY_TOKEN = {
@@ -949,6 +951,299 @@ function newLocalUuid() {
949
951
  ].join('-');
950
952
  }
951
953
 
954
+ /**
955
+ * The display record an option carries in `metadataJson` — a JSON string
956
+ * holding `{ entityId, values }`, the shape of a projected `records` entry.
957
+ * Null when absent (an older backend), unparsable, or for another record.
958
+ */
959
+ function parseOptionRecord(metadataJson, id) {
960
+ if (typeof metadataJson !== 'string' || !metadataJson.trim())
961
+ return null;
962
+ try {
963
+ const parsed = JSON.parse(metadataJson);
964
+ if (Number(parsed?.entityId) !== id || !Array.isArray(parsed?.values)) {
965
+ return null;
966
+ }
967
+ return { entityId: id, values: parsed.values };
968
+ }
969
+ catch {
970
+ return null;
971
+ }
972
+ }
973
+ function createSelectionEditorState(base) {
974
+ return {
975
+ base,
976
+ ids: positiveIds(base?.entityIds),
977
+ names: {},
978
+ records: {},
979
+ mutationId: null,
980
+ mutationKey: null,
981
+ };
982
+ }
983
+ function positiveIds(ids) {
984
+ const out = [];
985
+ for (const entry of ids ?? []) {
986
+ const id = Number(entry);
987
+ if (Number.isInteger(id) && id > 0 && !out.includes(id))
988
+ out.push(id);
989
+ }
990
+ return out;
991
+ }
992
+ /** Same records regardless of order — the backend stores them sorted. */
993
+ function sameSelection(a, b) {
994
+ if (a.length !== b.length)
995
+ return false;
996
+ const set = new Set(a);
997
+ return b.every((id) => set.has(id));
998
+ }
999
+ /**
1000
+ * Replace the selection with the picker's result. Records already selected
1001
+ * keep their place; new ones are appended in the order they were picked. In
1002
+ * single mode only the last pick survives.
1003
+ */
1004
+ function applySelectionPicks(state, picks, multiple) {
1005
+ const wanted = positiveIds(picks.map((pick) => pick.id));
1006
+ const chosen = multiple ? wanted : wanted.slice(-1);
1007
+ const kept = state.ids.filter((id) => chosen.includes(id));
1008
+ const added = chosen.filter((id) => !kept.includes(id));
1009
+ const names = { ...state.names };
1010
+ const records = { ...state.records };
1011
+ for (const pick of picks) {
1012
+ if (!added.includes(pick.id))
1013
+ continue;
1014
+ if (pick.name)
1015
+ names[pick.id] = pick.name;
1016
+ if (pick.record)
1017
+ records[pick.id] = pick.record;
1018
+ }
1019
+ return { ...state, ids: [...kept, ...added], names, records };
1020
+ }
1021
+ function removeSelectedRecord(state, id) {
1022
+ return { ...state, ids: state.ids.filter((entry) => entry !== id) };
1023
+ }
1024
+ /**
1025
+ * The control's value for a state.
1026
+ *
1027
+ * A changed selection is a mutation: the full replacement `entityIds`, the
1028
+ * version it was loaded at, and a `mutationId` that stays the same while the
1029
+ * content does (a retry of the same save) and changes with it. Nothing else is
1030
+ * sent — the backend discards rendered records and snapshots, and rejects any
1031
+ * other member.
1032
+ *
1033
+ * An unchanged selection is the value it arrived as, which the submission
1034
+ * leaves out: an omitted Selected list keeps its membership.
1035
+ */
1036
+ function buildSelectionValue(next, newUuid) {
1037
+ const loaded = next.base?.entityIds ?? [];
1038
+ if (sameSelection(next.ids, positiveIds(loaded))) {
1039
+ return {
1040
+ state: { ...next, mutationId: null, mutationKey: null },
1041
+ value: next.base,
1042
+ };
1043
+ }
1044
+ const version = Number(next.base?.version ?? 0) || 0;
1045
+ const entityIds = [...next.ids];
1046
+ const mutationKey = JSON.stringify({
1047
+ version,
1048
+ entityIds: [...entityIds].sort((a, b) => a - b),
1049
+ });
1050
+ const mutationId = next.mutationKey === mutationKey && next.mutationId
1051
+ ? next.mutationId
1052
+ : newUuid();
1053
+ return {
1054
+ state: { ...next, mutationId, mutationKey },
1055
+ value: { recordMode: 'Selected', version, mutationId, entityIds },
1056
+ };
1057
+ }
1058
+
1059
+ /**
1060
+ * Candidates per request. The backend takes 1–100 and requires `skip` to be a
1061
+ * multiple of `take`, so paging only ever adds whole pages.
1062
+ */
1063
+ const PAGE_SIZE$1 = 25;
1064
+ /** The backend's limit on one list's selection. */
1065
+ const ENTITY_LIST_MAX_SELECTIONS = 100;
1066
+ /**
1067
+ * Picker of a Selected `EntityList` (`recordMode: "Selected"`), opened by
1068
+ * `mt-entity-list-field`.
1069
+ *
1070
+ * Candidates come from `GET forms/options/{propertyKey}` with the **parent's**
1071
+ * context: the backend resolves the source module and its eligibility filter
1072
+ * from the property's trusted configuration, so the caller never names the
1073
+ * source. Each candidate is only a key and a name — its field values are
1074
+ * rendered once the parent is saved.
1075
+ *
1076
+ * Closes with the chosen records as `SelectionPick[]`, or `null` on Cancel.
1077
+ */
1078
+ class EntityListSelectionDialog {
1079
+ ref = inject(ModalRef);
1080
+ /** Exposes the shared modal content/footer classes to the template. */
1081
+ modal = inject(ModalService);
1082
+ http = inject(HttpClient);
1083
+ destroyRef = inject(DestroyRef);
1084
+ /** The EntityList property's key — the options route. */
1085
+ propertyKey = input('', ...(ngDevMode ? [{ debugName: "propertyKey" }] : /* istanbul ignore next */ []));
1086
+ /** The parent form's context, e.g. `Level:3/Module:22`. */
1087
+ contextKey = input('', ...(ngDevMode ? [{ debugName: "contextKey" }] : /* istanbul ignore next */ []));
1088
+ levelDataId = input(null, ...(ngDevMode ? [{ debugName: "levelDataId" }] : /* istanbul ignore next */ []));
1089
+ multiple = input(true, ...(ngDevMode ? [{ debugName: "multiple" }] : /* istanbul ignore next */ []));
1090
+ /** The records the field holds now. */
1091
+ selectedIds = input([], ...(ngDevMode ? [{ debugName: "selectedIds" }] : /* istanbul ignore next */ []));
1092
+ context = input(undefined, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
1093
+ searchControl = new FormControl('', {
1094
+ nonNullable: true,
1095
+ });
1096
+ items = signal([], ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
1097
+ loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1098
+ hasMore = signal(false, ...(ngDevMode ? [{ debugName: "hasMore" }] : /* istanbul ignore next */ []));
1099
+ /** Translation key of the failure to show instead of the list, if any. */
1100
+ failureKey = signal(null, ...(ngDevMode ? [{ debugName: "failureKey" }] : /* istanbul ignore next */ []));
1101
+ /** Chosen records, in the order they were picked; id → name. */
1102
+ picked = signal(new Map(), ...(ngDevMode ? [{ debugName: "picked" }] : /* istanbul ignore next */ []));
1103
+ pickedCount = computed(() => this.picked().size, ...(ngDevMode ? [{ debugName: "pickedCount" }] : /* istanbul ignore next */ []));
1104
+ atLimit = computed(() => this.multiple() && this.pickedCount() >= ENTITY_LIST_MAX_SELECTIONS, ...(ngDevMode ? [{ debugName: "atLimit" }] : /* istanbul ignore next */ []));
1105
+ maxSelections = ENTITY_LIST_MAX_SELECTIONS;
1106
+ nextSkip = 0;
1107
+ request;
1108
+ ngOnInit() {
1109
+ this.picked.set(new Map(this.selectedIds().map((id) => [id, ''])));
1110
+ this.searchControl.valueChanges
1111
+ .pipe(debounceTime(300), map((value) => value.trim()), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef))
1112
+ .subscribe(() => this.load(true));
1113
+ this.load(true);
1114
+ }
1115
+ isPicked(id) {
1116
+ return this.picked().has(id);
1117
+ }
1118
+ /**
1119
+ * Multiple mode toggles the record. Single mode replaces the choice, and
1120
+ * picking the chosen record again clears it.
1121
+ */
1122
+ toggle(item) {
1123
+ const current = this.picked();
1124
+ if (current.has(item.id)) {
1125
+ const next = new Map(current);
1126
+ next.delete(item.id);
1127
+ this.picked.set(next);
1128
+ return;
1129
+ }
1130
+ if (!this.multiple()) {
1131
+ this.picked.set(new Map([[item.id, item.name]]));
1132
+ return;
1133
+ }
1134
+ if (this.atLimit())
1135
+ return;
1136
+ this.picked.set(new Map(current).set(item.id, item.name));
1137
+ }
1138
+ loadMore() {
1139
+ this.load(false);
1140
+ }
1141
+ onCancel() {
1142
+ this.ref.close(null);
1143
+ }
1144
+ onApply() {
1145
+ const listed = new Map(this.items().map((item) => [item.id, item]));
1146
+ const picks = [...this.picked()].map(([id, name]) => ({
1147
+ id,
1148
+ name: name || listed.get(id)?.name || '',
1149
+ record: listed.get(id)?.record ?? null,
1150
+ }));
1151
+ this.ref.close(picks);
1152
+ }
1153
+ /**
1154
+ * Load a page of candidates; `reset` starts over from the first page of the
1155
+ * current search.
1156
+ *
1157
+ * The first page of an unfiltered list also asks for the records already
1158
+ * selected (`includeSelected`), so they show as chosen even when they sit on
1159
+ * a later page. They are added beside the page, not counted in it.
1160
+ */
1161
+ load(reset) {
1162
+ this.request?.unsubscribe();
1163
+ if (reset) {
1164
+ this.nextSkip = 0;
1165
+ this.items.set([]);
1166
+ this.hasMore.set(false);
1167
+ }
1168
+ this.failureKey.set(null);
1169
+ const propertyKey = this.propertyKey();
1170
+ const contextKey = this.contextKey();
1171
+ if (!propertyKey || !contextKey) {
1172
+ this.failureKey.set('components.entityListField.selectionUnavailable');
1173
+ return;
1174
+ }
1175
+ const search = this.searchControl.value.trim();
1176
+ const skip = this.nextSkip;
1177
+ let params = new HttpParams()
1178
+ .set('contextKey', contextKey)
1179
+ .set('skip', String(skip))
1180
+ .set('take', String(PAGE_SIZE$1));
1181
+ const levelDataId = this.levelDataId();
1182
+ if (levelDataId != null && levelDataId !== '') {
1183
+ params = params.set('levelDataId', String(levelDataId));
1184
+ }
1185
+ if (search) {
1186
+ params = params.set('search', search);
1187
+ }
1188
+ const selected = this.selectedIds();
1189
+ if (skip === 0 && !search && selected.length) {
1190
+ params = params.set('includeSelected', 'true');
1191
+ for (const id of selected) {
1192
+ params = params.append('selectedIds', String(id));
1193
+ }
1194
+ }
1195
+ this.loading.set(true);
1196
+ const context = this.context();
1197
+ this.request = this.http
1198
+ .get(`forms/options/${encodeURIComponent(propertyKey)}`, {
1199
+ params,
1200
+ // Failures are shown inside the dialog, not as a host toast.
1201
+ headers: { noMessage: 'true' },
1202
+ ...(context ? { context } : {}),
1203
+ })
1204
+ .pipe(finalize(() => this.loading.set(false)), takeUntilDestroyed(this.destroyRef))
1205
+ .subscribe({
1206
+ next: (response) => this.applyPage(response, skip),
1207
+ error: (error) => this.failureKey.set(error?.error?.errors?.code === 'entity_list.target_read_denied'
1208
+ ? 'components.entityListField.accessDenied'
1209
+ : 'components.entityListField.selectionLoadFailed'),
1210
+ });
1211
+ }
1212
+ applyPage(response, skip) {
1213
+ const page = [];
1214
+ for (const item of response?.data?.items ?? []) {
1215
+ const id = Number(item?.key);
1216
+ if (!Number.isInteger(id) || id <= 0)
1217
+ continue;
1218
+ page.push({
1219
+ id,
1220
+ name: item.name?.trim() || `#${id}`,
1221
+ record: parseOptionRecord(item.metadataJson, id),
1222
+ });
1223
+ }
1224
+ const seen = new Set(this.items().map((item) => item.id));
1225
+ this.items.set([
1226
+ ...this.items(),
1227
+ ...page.filter((item) => !seen.has(item.id)),
1228
+ ]);
1229
+ this.hasMore.set(!!response?.data?.hasMore);
1230
+ this.nextSkip = skip + PAGE_SIZE$1;
1231
+ }
1232
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListSelectionDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
1233
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityListSelectionDialog, isStandalone: true, selector: "mt-entity-list-selection-dialog", inputs: { propertyKey: { classPropertyName: "propertyKey", publicName: "propertyKey", isSignal: true, isRequired: false, transformFunction: null }, contextKey: { classPropertyName: "contextKey", publicName: "contextKey", isSignal: true, isRequired: false, transformFunction: null }, levelDataId: { classPropertyName: "levelDataId", publicName: "levelDataId", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, selectedIds: { classPropertyName: "selectedIds", publicName: "selectedIds", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div [class]=\"modal.contentClass + ' flex max-h-[70vh] flex-col gap-3 p-4'\">\r\n <mt-text-field\r\n [formControl]=\"searchControl\"\r\n icon=\"general.search-md\"\r\n [placeholder]=\"'components.entityListField.searchRecords' | transloco\"\r\n />\r\n\r\n @if (multiple()) {\r\n <p\r\n class=\"text-xs\"\r\n [class.text-muted-color]=\"!atLimit()\"\r\n [class.text-amber-700]=\"atLimit()\"\r\n >\r\n {{\r\n (atLimit()\r\n ? \"components.entityListField.selectionLimit\"\r\n : \"components.entityListField.selectedCount\"\r\n ) | transloco: { count: pickedCount(), max: maxSelections }\r\n }}\r\n </p>\r\n }\r\n\r\n @if (failureKey(); as failure) {\r\n <div\r\n class=\"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700\"\r\n >\r\n {{ failure | transloco }}\r\n </div>\r\n } @else {\r\n <div\r\n class=\"flex min-h-40 flex-col gap-1 overflow-y-auto\"\r\n role=\"listbox\"\r\n [attr.aria-multiselectable]=\"multiple()\"\r\n >\r\n @for (item of items(); track item.id) {\r\n @let chosen = isPicked(item.id);\r\n <button\r\n type=\"button\"\r\n role=\"option\"\r\n [attr.aria-selected]=\"chosen\"\r\n [disabled]=\"!chosen && atLimit()\"\r\n class=\"flex w-full items-center gap-3 rounded-md border px-3 py-2 text-start text-sm transition-colors hover:border-primary disabled:cursor-not-allowed disabled:opacity-50\"\r\n [class.border-primary]=\"chosen\"\r\n [class.bg-primary-50]=\"chosen\"\r\n [class.border-surface]=\"!chosen\"\r\n (click)=\"toggle(item)\"\r\n >\r\n <span\r\n class=\"flex size-4 shrink-0 items-center justify-center border\"\r\n [class.rounded-sm]=\"multiple()\"\r\n [class.rounded-full]=\"!multiple()\"\r\n [class.border-primary]=\"chosen\"\r\n [class.bg-primary]=\"chosen\"\r\n [class.text-primary-contrast]=\"chosen\"\r\n [class.border-surface-400]=\"!chosen\"\r\n >\r\n @if (chosen) {\r\n <mt-icon icon=\"general.check\" class=\"text-[0.625rem]\" />\r\n }\r\n </span>\r\n <span class=\"min-w-0 flex-1 truncate text-color\">{{\r\n item.name\r\n }}</span>\r\n </button>\r\n }\r\n\r\n @if (loading()) {\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n } @else if (!items().length) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noCandidates\" | transloco }}\r\n </div>\r\n }\r\n </div>\r\n\r\n @if (hasMore() && !loading()) {\r\n <div class=\"flex justify-center\">\r\n <mt-button\r\n [label]=\"'components.entityListField.loadMore' | transloco\"\r\n variant=\"text\"\r\n size=\"small\"\r\n (onClick)=\"loadMore()\"\r\n />\r\n </div>\r\n }\r\n }\r\n</div>\r\n\r\n<div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"'components.entityListField.cancel' | transloco\"\r\n severity=\"secondary\"\r\n variant=\"outlined\"\r\n (onClick)=\"onCancel()\"\r\n />\r\n <mt-button\r\n [label]=\"'components.entityListField.apply' | transloco\"\r\n severity=\"primary\"\r\n [disabled]=\"!!failureKey()\"\r\n (onClick)=\"onApply()\"\r\n />\r\n</div>\r\n", dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs", "ariaLabel"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "component", type: TextField, selector: "mt-text-field", inputs: ["field", "hint", "label", "placeholder", "class", "type", "readonly", "pInputs", "required", "maxLength", "icon", "iconPosition"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1234
+ }
1235
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListSelectionDialog, decorators: [{
1236
+ type: Component,
1237
+ args: [{ selector: 'mt-entity-list-selection-dialog', standalone: true, imports: [
1238
+ ReactiveFormsModule,
1239
+ TranslocoPipe,
1240
+ Skeleton,
1241
+ Icon,
1242
+ Button,
1243
+ TextField,
1244
+ ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [class]=\"modal.contentClass + ' flex max-h-[70vh] flex-col gap-3 p-4'\">\r\n <mt-text-field\r\n [formControl]=\"searchControl\"\r\n icon=\"general.search-md\"\r\n [placeholder]=\"'components.entityListField.searchRecords' | transloco\"\r\n />\r\n\r\n @if (multiple()) {\r\n <p\r\n class=\"text-xs\"\r\n [class.text-muted-color]=\"!atLimit()\"\r\n [class.text-amber-700]=\"atLimit()\"\r\n >\r\n {{\r\n (atLimit()\r\n ? \"components.entityListField.selectionLimit\"\r\n : \"components.entityListField.selectedCount\"\r\n ) | transloco: { count: pickedCount(), max: maxSelections }\r\n }}\r\n </p>\r\n }\r\n\r\n @if (failureKey(); as failure) {\r\n <div\r\n class=\"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700\"\r\n >\r\n {{ failure | transloco }}\r\n </div>\r\n } @else {\r\n <div\r\n class=\"flex min-h-40 flex-col gap-1 overflow-y-auto\"\r\n role=\"listbox\"\r\n [attr.aria-multiselectable]=\"multiple()\"\r\n >\r\n @for (item of items(); track item.id) {\r\n @let chosen = isPicked(item.id);\r\n <button\r\n type=\"button\"\r\n role=\"option\"\r\n [attr.aria-selected]=\"chosen\"\r\n [disabled]=\"!chosen && atLimit()\"\r\n class=\"flex w-full items-center gap-3 rounded-md border px-3 py-2 text-start text-sm transition-colors hover:border-primary disabled:cursor-not-allowed disabled:opacity-50\"\r\n [class.border-primary]=\"chosen\"\r\n [class.bg-primary-50]=\"chosen\"\r\n [class.border-surface]=\"!chosen\"\r\n (click)=\"toggle(item)\"\r\n >\r\n <span\r\n class=\"flex size-4 shrink-0 items-center justify-center border\"\r\n [class.rounded-sm]=\"multiple()\"\r\n [class.rounded-full]=\"!multiple()\"\r\n [class.border-primary]=\"chosen\"\r\n [class.bg-primary]=\"chosen\"\r\n [class.text-primary-contrast]=\"chosen\"\r\n [class.border-surface-400]=\"!chosen\"\r\n >\r\n @if (chosen) {\r\n <mt-icon icon=\"general.check\" class=\"text-[0.625rem]\" />\r\n }\r\n </span>\r\n <span class=\"min-w-0 flex-1 truncate text-color\">{{\r\n item.name\r\n }}</span>\r\n </button>\r\n }\r\n\r\n @if (loading()) {\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\r\n } @else if (!items().length) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noCandidates\" | transloco }}\r\n </div>\r\n }\r\n </div>\r\n\r\n @if (hasMore() && !loading()) {\r\n <div class=\"flex justify-center\">\r\n <mt-button\r\n [label]=\"'components.entityListField.loadMore' | transloco\"\r\n variant=\"text\"\r\n size=\"small\"\r\n (onClick)=\"loadMore()\"\r\n />\r\n </div>\r\n }\r\n }\r\n</div>\r\n\r\n<div [class]=\"modal.footerClass\">\r\n <mt-button\r\n [label]=\"'components.entityListField.cancel' | transloco\"\r\n severity=\"secondary\"\r\n variant=\"outlined\"\r\n (onClick)=\"onCancel()\"\r\n />\r\n <mt-button\r\n [label]=\"'components.entityListField.apply' | transloco\"\r\n severity=\"primary\"\r\n [disabled]=\"!!failureKey()\"\r\n (onClick)=\"onApply()\"\r\n />\r\n</div>\r\n" }]
1245
+ }], propDecorators: { propertyKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyKey", required: false }] }], contextKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "contextKey", required: false }] }], levelDataId: [{ type: i0.Input, args: [{ isSignal: true, alias: "levelDataId", required: false }] }], multiple: [{ type: i0.Input, args: [{ isSignal: true, alias: "multiple", required: false }] }], selectedIds: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedIds", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
1246
+
952
1247
  function resolveMetadataFailure(status) {
953
1248
  if (status === 403)
954
1249
  return 'forbidden';
@@ -1005,6 +1300,12 @@ const ROW_LOCAL_CREATED_KEY = '__localCreated';
1005
1300
  * and a `WeakMap` lets it go with the value.
1006
1301
  */
1007
1302
  const LOCAL_EDITOR_STATES = new WeakMap();
1303
+ /**
1304
+ * The editing state behind each Selected value this field emitted, for the
1305
+ * same reason as `LOCAL_EDITOR_STATES`: a mutation is only ids, and the names
1306
+ * of records picked in this session live nowhere else.
1307
+ */
1308
+ const SELECTION_EDITOR_STATES = new WeakMap();
1008
1309
  /**
1009
1310
  * Badge colour per staged operation, as a hex: `mt-entity-status` derives its
1010
1311
  * own 12%-alpha background by slicing the value's `color`, so a Tailwind class
@@ -1026,6 +1327,11 @@ class EntityListField {
1026
1327
  * effective configuration.
1027
1328
  */
1028
1329
  propertyId = input(null, ...(ngDevMode ? [{ debugName: "propertyId" }] : /* istanbul ignore next */ []));
1330
+ /**
1331
+ * EntityList property key. A Selected list's picker loads its candidates
1332
+ * from `forms/options/{propertyKey}`; no other mode reads it.
1333
+ */
1334
+ propertyKey = input('', ...(ngDevMode ? [{ debugName: "propertyKey" }] : /* istanbul ignore next */ []));
1029
1335
  /**
1030
1336
  * Stored property configuration (sourceType, moduleId, access, readFields …).
1031
1337
  *
@@ -1146,6 +1452,19 @@ class EntityListField {
1146
1452
  * value keys.
1147
1453
  */
1148
1454
  writeFields = computed(() => this.metadata()?.writeFields ?? [], ...(ngDevMode ? [{ debugName: "writeFields" }] : /* istanbul ignore next */ []));
1455
+ /**
1456
+ * Write fields a new row must fill: the target's required, non-calculated
1457
+ * properties. The backend rejects a create row without any of them
1458
+ * (`entity_list.required_field_missing`), while the target module's form —
1459
+ * which the add dialog renders — may mark fewer required.
1460
+ */
1461
+ createRequiredFields = computed(() => {
1462
+ const properties = this.propertyByKey();
1463
+ return this.writeFields().filter((key) => {
1464
+ const property = properties.get(key);
1465
+ return !!property?.isRequired && !property.isCalculated;
1466
+ });
1467
+ }, ...(ngDevMode ? [{ debugName: "createRequiredFields" }] : /* istanbul ignore next */ []));
1149
1468
  /**
1150
1469
  * Pending create/update rows, in the exact shape persisted by the backend
1151
1470
  * (`rows[]` of the stored EntityList JSON). Rows with `entityId > 0` are
@@ -1525,6 +1844,198 @@ class EntityListField {
1525
1844
  }
1526
1845
  return actions;
1527
1846
  }, ...(ngDevMode ? [{ debugName: "localRowActions" }] : /* istanbul ignore next */ []));
1847
+ // ============================================================================
1848
+ // Selected records (`recordMode: "Selected"`) — source records the user picked
1849
+ // ============================================================================
1850
+ /** Loaded selection plus this session's picks; see `SelectionEditorState`. */
1851
+ selectionState = signal(createSelectionEditorState(null), ...(ngDevMode ? [{ debugName: "selectionState" }] : /* istanbul ignore next */ []));
1852
+ /** The bound value was a Selected document, whatever the metadata says yet. */
1853
+ selectionValueSeen = signal(false, ...(ngDevMode ? [{ debugName: "selectionValueSeen" }] : /* istanbul ignore next */ []));
1854
+ /** The last Selected value emitted, so its echo does not reset the picks. */
1855
+ lastSelectionEmit = null;
1856
+ /**
1857
+ * The list holds only the records the user picked. It never falls back to
1858
+ * every related record: an empty selection is empty. Known from the
1859
+ * metadata, or earlier from the value itself.
1860
+ */
1861
+ selectionMode = computed(() => this.metadata()?.recordMode === 'Selected' || this.selectionValueSeen(), ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
1862
+ /** Render once the metadata answered: it is the access boundary. */
1863
+ selectionReady = computed(() => this.selectionMode() && !!this.metadata(), ...(ngDevMode ? [{ debugName: "selectionReady" }] : /* istanbul ignore next */ []));
1864
+ selectionMultiple = computed(() => this.metadata()?.selectionMode !== 'Single', ...(ngDevMode ? [{ debugName: "selectionMultiple" }] : /* istanbul ignore next */ []));
1865
+ /**
1866
+ * The picker's `contextKey`: the context of the form that owns the property
1867
+ * — never the source module, which the backend resolves from the property's
1868
+ * own configuration.
1869
+ */
1870
+ selectionContextKey = computed(() => {
1871
+ const levelId = this.levelId();
1872
+ if (levelId == null)
1873
+ return null;
1874
+ const moduleId = this.runtimeContext()?.moduleId;
1875
+ return moduleId == null || moduleId === ''
1876
+ ? `Level:${levelId}`
1877
+ : `Level:${levelId}/Module:${moduleId}`;
1878
+ }, ...(ngDevMode ? [{ debugName: "selectionContextKey" }] : /* istanbul ignore next */ []));
1879
+ /**
1880
+ * Whether the user may change which records are selected. That is the
1881
+ * form's call — `readonly`, from the field's `isWrite` — and not the
1882
+ * metadata's `access` or its `allow*` switches: those describe the source
1883
+ * records, which selecting never writes.
1884
+ */
1885
+ selectionWritable = computed(() => this.selectionReady() &&
1886
+ !this.readonly() &&
1887
+ !this.disabled() &&
1888
+ !!this.propertyKey() &&
1889
+ !!this.selectionContextKey(), ...(ngDevMode ? [{ debugName: "selectionWritable" }] : /* istanbul ignore next */ []));
1890
+ /**
1891
+ * The selected records as table rows, in selection order.
1892
+ *
1893
+ * A saved record renders from the backend's `records`, cell by cell against
1894
+ * the metadata columns — the same cells a related list shows. A record
1895
+ * picked in this session renders the display values its option carried
1896
+ * (`metadataJson`) the same way; an older backend sends none, and the row
1897
+ * then shows its name and "Shown after saving". A record in `unavailableIds` was
1898
+ * deleted or is no longer visible: the backend keeps it selected but
1899
+ * withholds its values, and the row says so, so the user can remove it.
1900
+ */
1901
+ selectionRows = computed(() => {
1902
+ const state = this.selectionState();
1903
+ const columns = this.columns();
1904
+ const properties = this.propertyByKey();
1905
+ const records = new Map((state.base?.records ?? []).map((record) => [record.entityId, record]));
1906
+ const unavailable = new Set(state.base?.unavailableIds ?? []);
1907
+ return state.ids.map((id) => {
1908
+ const row = {
1909
+ Id: id,
1910
+ [ROW_ID_KEY]: `entity-${id}`,
1911
+ [ROW_ENTITY_ID_KEY]: id,
1912
+ };
1913
+ // A loaded record renders the backend's values for it; a record picked
1914
+ // in this session renders the picker's display values, when sent.
1915
+ const record = records.get(id) ?? state.records[id];
1916
+ if (record) {
1917
+ const values = new Map((record.values ?? []).map((item) => [item.propertyKey, item]));
1918
+ for (const column of columns) {
1919
+ const propertyKey = column.propertyKey ?? column.key;
1920
+ const item = values.get(propertyKey) ?? values.get(column.key);
1921
+ row[column.key] = this.toEntityData(column, item ? { raw: item.rawValue, value: item.value } : undefined, properties.get(propertyKey), id);
1922
+ }
1923
+ return row;
1924
+ }
1925
+ const isUnavailable = unavailable.has(id);
1926
+ const label = isUnavailable
1927
+ ? this.transloco.translate('components.entityListField.unavailableRecord', { id }, this.lang())
1928
+ : state.names[id] || `#${id}`;
1929
+ // The picker returns only names; the other values are rendered once the
1930
+ // parent is saved. Say so rather than show a known value as empty.
1931
+ const pending = isUnavailable
1932
+ ? ''
1933
+ : this.transloco.translate('components.entityListField.shownAfterSave', {}, this.lang());
1934
+ columns.forEach((column, index) => {
1935
+ row[column.key] = {
1936
+ key: column.key,
1937
+ name: column.label,
1938
+ viewType: 'Text',
1939
+ value: index === 0 ? label : pending,
1940
+ };
1941
+ });
1942
+ return row;
1943
+ });
1944
+ }, ...(ngDevMode ? [{ debugName: "selectionRows" }] : /* istanbul ignore next */ []));
1945
+ selectionRowActions = computed(() => {
1946
+ this.lang();
1947
+ if (!this.selectionWritable())
1948
+ return [];
1949
+ return [
1950
+ {
1951
+ icon: 'general.x-close',
1952
+ tooltip: this.transloco.translate('components.entityListField.unselect'),
1953
+ color: 'danger',
1954
+ action: (row) => this.emitSelection(removeSelectedRecord(this.selectionState(), Number(row[ROW_ENTITY_ID_KEY]))),
1955
+ },
1956
+ ];
1957
+ }, ...(ngDevMode ? [{ debugName: "selectionRowActions" }] : /* istanbul ignore next */ []));
1958
+ /**
1959
+ * A required Selected list needs a record. An emptied selection is an
1960
+ * object — a mutation with no ids — so `Validators.required` passes it and
1961
+ * only the backend would object (`entity_list.selection_required`).
1962
+ */
1963
+ selectionRequiredValidator = (control) => {
1964
+ if (!this.required())
1965
+ return null;
1966
+ const value = control.value;
1967
+ if (isEntityListSelectionDocument(value)) {
1968
+ return value.entityIds?.length ? null : { required: true };
1969
+ }
1970
+ return value == null && this.selectionMode() ? { required: true } : null;
1971
+ };
1972
+ openSelectionDialog() {
1973
+ if (!this.selectionWritable())
1974
+ return;
1975
+ const ref = this.modal.openModal(EntityListSelectionDialog, 'dialog', {
1976
+ header: this.transloco.translate('components.entityListField.selectRecords'),
1977
+ styleClass: '!w-[36rem] max-w-[96vw]',
1978
+ dismissableMask: true,
1979
+ inputValues: {
1980
+ propertyKey: this.propertyKey(),
1981
+ contextKey: this.selectionContextKey(),
1982
+ levelDataId: this.levelDataId(),
1983
+ multiple: this.selectionMultiple(),
1984
+ selectedIds: this.selectionState().ids,
1985
+ context: this.context(),
1986
+ },
1987
+ });
1988
+ ref.onClose.pipe(take(1)).subscribe((result) => {
1989
+ if (!Array.isArray(result))
1990
+ return;
1991
+ this.emitSelection(applySelectionPicks(this.selectionState(), result, this.selectionMultiple()));
1992
+ });
1993
+ }
1994
+ /**
1995
+ * Publish the selection as the control's value: a mutation when it differs
1996
+ * from what was loaded, else the loaded value, which the submission leaves
1997
+ * out. See `buildSelectionValue`.
1998
+ */
1999
+ emitSelection(next) {
2000
+ const { state, value } = buildSelectionValue(next, newLocalUuid);
2001
+ this.selectionState.set(state);
2002
+ if (value)
2003
+ SELECTION_EDITOR_STATES.set(value, state);
2004
+ this.lastSelectionEmit = value;
2005
+ this.onModelChange(value);
2006
+ this.onTouched();
2007
+ }
2008
+ /**
2009
+ * Take a Selected document, and say whether it was one.
2010
+ *
2011
+ * Our own emission echoed back keeps the session; a value some instance of
2012
+ * this field emitted restores that instance's state (see
2013
+ * `SELECTION_EDITOR_STATES`); anything else starts a session on it. That is
2014
+ * the projection `process-form-load` returns, the stored document a preview
2015
+ * gets from the fetch endpoints, or a mutation the form already held — which
2016
+ * stays the control's value until the user changes the selection.
2017
+ *
2018
+ * An empty value resets the session too and still falls through, since
2019
+ * which mode the list uses may not be known yet.
2020
+ */
2021
+ writeSelectionValue(value) {
2022
+ const incoming = this.coerceStoredValue(value);
2023
+ if (!isEntityListSelectionDocument(incoming)) {
2024
+ if (incoming == null) {
2025
+ this.lastSelectionEmit = null;
2026
+ this.selectionState.set(createSelectionEditorState(null));
2027
+ }
2028
+ return false;
2029
+ }
2030
+ this.selectionValueSeen.set(true);
2031
+ if (incoming === this.lastSelectionEmit)
2032
+ return true;
2033
+ this.lastSelectionEmit = null;
2034
+ const restored = SELECTION_EDITOR_STATES.get(incoming);
2035
+ this.selectionState.set(restored ??
2036
+ createSelectionEditorState(incoming));
2037
+ return true;
2038
+ }
1528
2039
  /** Enough context to ask the backend what this field should render. */
1529
2040
  hasRequiredContext = computed(() => this.propertyKeyId() > 0 && Number(this.levelId()) > 0, ...(ngDevMode ? [{ debugName: "hasRequiredContext" }] : /* istanbul ignore next */ []));
1530
2041
  /**
@@ -1600,6 +2111,23 @@ class EntityListField {
1600
2111
  const levelDataId = this.levelDataId();
1601
2112
  untracked(() => this.loadTable(propertyId, levelId, levelDataId));
1602
2113
  });
2114
+ // The control exists once the form directive has resolved it, which is
2115
+ // after construction. The validator reads `required` and the mode itself,
2116
+ // so it is added once; the control is re-validated when either changes —
2117
+ // the mode is only known once the metadata or the value arrives.
2118
+ effect(() => {
2119
+ this.selectionMode();
2120
+ this.required();
2121
+ const control = this.ngControl?.control;
2122
+ if (!control)
2123
+ return;
2124
+ untracked(() => {
2125
+ if (!control.hasValidator(this.selectionRequiredValidator)) {
2126
+ control.addValidators(this.selectionRequiredValidator);
2127
+ }
2128
+ control.updateValueAndValidity({ emitEvent: false });
2129
+ });
2130
+ });
1603
2131
  // Form-less hosts hand the value over as an input instead. `writeValue` is
1604
2132
  // the one entry point that resets the pending rows and deletions with it,
1605
2133
  // so it is reused rather than re-implemented.
@@ -1620,12 +2148,15 @@ class EntityListField {
1620
2148
  writeValue(value) {
1621
2149
  if (this.writeLocalValue(value))
1622
2150
  return;
2151
+ if (this.writeSelectionValue(value))
2152
+ return;
1623
2153
  const incoming = this.coerceStoredValue(value);
1624
2154
  // Ignore the echo of our own emission (DynamicForm re-writes the model on
1625
2155
  // every value change) so pending edits/deletions are not reset.
1626
2156
  if (this.isEchoOfLastEmit(incoming))
1627
2157
  return;
1628
2158
  this.lastEmittedJson = null;
2159
+ this.linkedMutation = null;
1629
2160
  this.storedValue.set(incoming);
1630
2161
  // Restore rows the backend left unprocessed. Whether the loaded
1631
2162
  // `deletedIds` are historical markers or pending intent depends on the
@@ -1647,9 +2178,10 @@ class EntityListField {
1647
2178
  * - A value some instance of this field emitted restores that instance's
1648
2179
  * state — see `LOCAL_EDITOR_STATES`.
1649
2180
  * - A document the backend sent starts a fresh session on it: the projection
1650
- * `process-form-load` returns (its `schema` set, cells rendered), or the
1651
- * stored document the fetch endpoints return for a preview (`schema:
1652
- * null`, cells unrendered) — the schema then comes from the metadata.
2181
+ * `process-form-load` and the fetch endpoints return (its `schema` set,
2182
+ * cells rendered), or the stored document an older backend's fetch
2183
+ * endpoints returned (`schema: null`, cells unrendered) — the schema then
2184
+ * comes from the metadata.
1653
2185
  * Every backend document carries the `schema` member, null or not; a
1654
2186
  * mutation never does. So a mutation nobody here emitted has no rows to
1655
2187
  * rebuild the table from and is left as the control's value, untouched
@@ -1760,6 +2292,7 @@ class EntityListField {
1760
2292
  levelId: this.levelId(),
1761
2293
  levelDataId: this.levelDataId(),
1762
2294
  writeFields: this.writeFields(),
2295
+ requiredFieldKeys: this.createRequiredFields(),
1763
2296
  lookups: this.lookups(),
1764
2297
  },
1765
2298
  });
@@ -1805,6 +2338,9 @@ class EntityListField {
1805
2338
  levelId: this.levelId(),
1806
2339
  levelDataId: this.levelDataId(),
1807
2340
  writeFields: this.writeFields(),
2341
+ // A row not saved yet is still a create; an existing record's update
2342
+ // carries only what changed.
2343
+ requiredFieldKeys: entityId > 0 ? [] : this.createRequiredFields(),
1808
2344
  lookups: this.lookups(),
1809
2345
  initialValues: prefillValues,
1810
2346
  isEdit: true,
@@ -2086,9 +2622,9 @@ class EntityListField {
2086
2622
  }
2087
2623
  /**
2088
2624
  * A loaded cell: the backend's rendered `value` beside its `rawValue`. A
2089
- * stored document from the fetch endpoints has no rendered values, so the
2090
- * raw one is shaped the way a locally set cell would be — a user id still
2091
- * renders as a user, though only as its id until the backend renders it.
2625
+ * stored document (what an older backend's fetch endpoints returned) has no
2626
+ * rendered values, so the raw one is shaped the way a locally set cell would
2627
+ * be — a user id still renders as a user, though only as its id.
2092
2628
  */
2093
2629
  buildLocalLoadedCell(column, cell, configuration) {
2094
2630
  const value = cell?.value != null
@@ -2261,23 +2797,27 @@ class EntityListField {
2261
2797
  // Submit payload (see EntityList.md — "Stored Value Shape")
2262
2798
  // ============================================================================
2263
2799
  emitValue() {
2264
- const current = this.storedValue();
2265
- // `entityIds` / `createdIds` / `updatedIds` / `snapshot` are backend-owned
2266
- // and passed through untouched; the frontend only contributes pending rows
2267
- // and delete intents.
2268
- const next = {
2269
- ...(current ?? {}),
2270
- // `values[].value` is the backend's rendered label, carried only so the
2271
- // table can print it. Submitting it back would echo a user object where
2272
- // the stored scalar belongs.
2273
- rows: this.pendingRows().map((row) => ({
2274
- ...row,
2275
- values: (row.values ?? []).map(({ propertyKey, rawValue }) => ({
2276
- propertyKey,
2277
- rawValue,
2278
- })),
2800
+ // `entityIds` / `createdIds` / `updatedIds` / `snapshot`, and the loaded
2801
+ // `version` / `expectedVersions`, are backend-owned and passed through
2802
+ // untouched; the frontend only contributes pending rows, delete intents
2803
+ // and the change's id. `live` is response-only and stays behind.
2804
+ const { live: _live, ...current } = this.storedValue() ?? {};
2805
+ // `values[].value` is the backend's rendered label, carried only so the
2806
+ // table can print it. Submitting it back would echo a user object where
2807
+ // the stored scalar belongs.
2808
+ const rows = this.pendingRows().map((row) => ({
2809
+ ...row,
2810
+ values: (row.values ?? []).map(({ propertyKey, rawValue }) => ({
2811
+ propertyKey,
2812
+ rawValue,
2279
2813
  })),
2280
- deletedIds: this.deletedIds(),
2814
+ }));
2815
+ const deletedIds = this.deletedIds();
2816
+ const next = {
2817
+ ...current,
2818
+ rows,
2819
+ deletedIds,
2820
+ ...this.linkedMutationId(current, rows, deletedIds),
2281
2821
  };
2282
2822
  this.storedValue.set(next);
2283
2823
  this.lastEmittedJson = JSON.stringify({
@@ -2287,6 +2827,30 @@ class EntityListField {
2287
2827
  this.onModelChange(next);
2288
2828
  this.onTouched();
2289
2829
  }
2830
+ /**
2831
+ * The id of the change a Related list's value carries. The backend rejects
2832
+ * a Related change without one (`entity_list.invalid_payload`), and the form
2833
+ * load sends it empty — so a value with rows or deletions gets its own: the
2834
+ * same while the change is (a retry of the same save), a new one when it
2835
+ * differs, since reusing an id for other content is refused
2836
+ * (`entity_list.linked_mutation_reused`). A value with nothing to apply keeps
2837
+ * what it loaded with; the backend skips it.
2838
+ */
2839
+ linkedMutation = null;
2840
+ linkedMutationId(current, rows, deletedIds) {
2841
+ if (rows.length === 0 && deletedIds.length === 0)
2842
+ return {};
2843
+ const version = Number(current.version ?? 0) || 0;
2844
+ const key = JSON.stringify({ version, rows, deletedIds });
2845
+ if (this.linkedMutation?.key !== key) {
2846
+ this.linkedMutation = { key, id: newLocalUuid() };
2847
+ }
2848
+ return {
2849
+ version,
2850
+ mutationId: this.linkedMutation.id,
2851
+ expectedVersions: current.expectedVersions ?? {},
2852
+ };
2853
+ }
2290
2854
  /**
2291
2855
  * `values[]` entries, restricted to `writeFields` when configured.
2292
2856
  *
@@ -2452,6 +3016,13 @@ class EntityListField {
2452
3016
  return;
2453
3017
  }
2454
3018
  this.columns.set(this.buildColumns(metadata));
3019
+ // A Selected list's rows are the records in its value. Fetching the source
3020
+ // module would list every related record, which is exactly what this mode
3021
+ // is not.
3022
+ if (this.selectionMode()) {
3023
+ this.loading.set(false);
3024
+ return;
3025
+ }
2455
3026
  if (!this.moduleBacked() ||
2456
3027
  !this.canRead() ||
2457
3028
  levelDataId == null ||
@@ -2623,7 +3194,7 @@ class EntityListField {
2623
3194
  };
2624
3195
  }
2625
3196
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, deps: [], target: i0.ɵɵFactoryTarget.Component });
2626
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityListField, isStandalone: true, selector: "mt-entity-list-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, propertyId: { classPropertyName: "propertyId", publicName: "propertyId", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: false, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, pendingSubmission: { classPropertyName: "pendingSubmission", publicName: "pendingSubmission", isSignal: true, isRequired: false, transformFunction: null }, lookups: { classPropertyName: "lookups", publicName: "lookups", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null }, initialValue: { classPropertyName: "initialValue", publicName: "initialValue", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, providers: [EntityRuntimeContextStore], ngImport: i0, template: "<div class=\"flex flex-col gap-2\">\n @if (label()) {\n <label class=\"font-medium text-color\">\n {{ label() }}\n @if (required()) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n @if (errorMessage(); as err) {\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\n } @else if (noticeKey(); as notice) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ notice | transloco }}\n </div>\n } @else if (localReady()) {\n <!--\n A Local list: rows owned by this record, staged into its own submission.\n Add / edit / delete / drag follow the Local operation switches.\n -->\n @if (localCanCreate()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openLocalRowDialog()\"\n />\n </div>\n }\n @if (localTableRows().length || localCanCreate()) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"localTableRows()\"\n [columns]=\"localColumns()\"\n [rowActions]=\"localRowActions()\"\n [reorderableRows]=\"localCanReorder()\"\n (rowReorder)=\"onLocalReorder($event)\"\n dataKey=\"Id\"\n />\n } @else {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noLocalRows\" | transloco }}\n </div>\n }\n } @else if (canWrite()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openAddDialog()\"\n />\n </div>\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"tableColumns()\"\n [rowActions]=\"writeRowActions()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n } @else if (loading() && !hasRows()) {\n <div class=\"flex flex-col gap-2\">\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n </div>\n } @else if (!hasRows()) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\n </div>\n } @else {\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"tableColumns()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n }\n\n @if (ngControl?.control) {\n <mt-field-validation\n [control]=\"ngControl?.control!\"\n [touched]=\"ngControl?.touched ?? false\"\n />\n }\n</div>\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "component", type: Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant", "motionOptions"], outputs: ["onClose"] }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "clickableRows", "generalSearch", "lazyLocalSearch", "showFilters", "filterMode", "loading", "updating", "lazy", "lazyLocalSort", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "storageKey", "storageMode", "persistStateExclude", "exportable", "printable", "groupable", "groupCountMap", "cellClickFilter", "freezeActions", "virtualScroll", "virtualScrollItemSize", "scrollHeight", "printTitle", "exportFilename", "actionShape", "rowActionsLoadingFn", "tableLayout", "noCard", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "captionStartTemplate", "captionEndTemplate", "emptyTitle", "emptyDescription", "emptyActionLabel", "emptyActionIcon", "paginatorPosition", "alwaysShowPaginator", "rowsPerPageOptions", "pageSize", "currentPage", "first", "filterTerm", "groupBy", "sortField", "sortDirection"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "rowClick", "emptyAction", "rowActionsRequested", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange", "groupByChange", "sortFieldChange", "sortDirectionChange"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs", "ariaLabel"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
3197
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityListField, isStandalone: true, selector: "mt-entity-list-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, propertyId: { classPropertyName: "propertyId", publicName: "propertyId", isSignal: true, isRequired: false, transformFunction: null }, propertyKey: { classPropertyName: "propertyKey", publicName: "propertyKey", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: false, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, pendingSubmission: { classPropertyName: "pendingSubmission", publicName: "pendingSubmission", isSignal: true, isRequired: false, transformFunction: null }, lookups: { classPropertyName: "lookups", publicName: "lookups", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null }, initialValue: { classPropertyName: "initialValue", publicName: "initialValue", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, providers: [EntityRuntimeContextStore], ngImport: i0, template: "<div class=\"flex flex-col gap-2\">\r\n @if (label()) {\r\n <label class=\"font-medium text-color\">\r\n {{ label() }}\r\n @if (required()) {\r\n <span class=\"text-red-500\">*</span>\r\n }\r\n </label>\r\n }\r\n\r\n @if (errorMessage(); as err) {\r\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\r\n } @else if (noticeKey(); as notice) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ notice | transloco }}\r\n </div>\r\n } @else if (localReady()) {\r\n <!--\r\n A Local list: rows owned by this record, staged into its own submission.\r\n Add / edit / delete / drag follow the Local operation switches.\r\n -->\r\n @if (localCanCreate()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.add' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openLocalRowDialog()\"\r\n />\r\n </div>\r\n }\r\n @if (localTableRows().length || localCanCreate()) {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"localTableRows()\"\r\n [columns]=\"localColumns()\"\r\n [rowActions]=\"localRowActions()\"\r\n [reorderableRows]=\"localCanReorder()\"\r\n (rowReorder)=\"onLocalReorder($event)\"\r\n dataKey=\"Id\"\r\n />\r\n } @else {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noLocalRows\" | transloco }}\r\n </div>\r\n }\r\n } @else if (selectionReady()) {\r\n <!--\r\n A Selected list: the source records picked for this record, and nothing\r\n else. Picking and removing change only which records it holds.\r\n -->\r\n @if (selectionWritable()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.selectRecords' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openSelectionDialog()\"\r\n />\r\n </div>\r\n }\r\n @if (selectionRows().length) {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"selectionRows()\"\r\n [columns]=\"columns()\"\r\n [rowActions]=\"selectionRowActions()\"\r\n dataKey=\"Id\"\r\n />\r\n } @else {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noSelectedRecords\" | transloco }}\r\n </div>\r\n }\r\n } @else if (canWrite()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.add' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openAddDialog()\"\r\n />\r\n </div>\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"displayRows()\"\r\n [columns]=\"tableColumns()\"\r\n [rowActions]=\"writeRowActions()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n } @else if (loading() && !hasRows()) {\r\n <div class=\"flex flex-col gap-2\">\r\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\r\n </div>\r\n } @else if (!hasRows()) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\r\n </div>\r\n } @else {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"displayRows()\"\r\n [columns]=\"tableColumns()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n }\r\n\r\n @if (ngControl?.control) {\r\n <mt-field-validation\r\n [control]=\"ngControl?.control!\"\r\n [touched]=\"ngControl?.touched ?? false\"\r\n />\r\n }\r\n</div>\r\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "component", type: Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant", "motionOptions"], outputs: ["onClose"] }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "clickableRows", "generalSearch", "lazyLocalSearch", "showFilters", "filterMode", "loading", "updating", "lazy", "lazyLocalSort", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "storageKey", "storageMode", "persistStateExclude", "exportable", "printable", "groupable", "groupCountMap", "cellClickFilter", "freezeActions", "virtualScroll", "virtualScrollItemSize", "scrollHeight", "printTitle", "exportFilename", "actionShape", "rowActionsLoadingFn", "tableLayout", "noCard", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "captionStartTemplate", "captionEndTemplate", "emptyTitle", "emptyDescription", "emptyActionLabel", "emptyActionIcon", "paginatorPosition", "alwaysShowPaginator", "rowsPerPageOptions", "pageSize", "currentPage", "first", "filterTerm", "groupBy", "sortField", "sortDirection"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "rowClick", "emptyAction", "rowActionsRequested", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange", "groupByChange", "sortFieldChange", "sortDirectionChange"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs", "ariaLabel"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2627
3198
  }
2628
3199
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, decorators: [{
2629
3200
  type: Component,
@@ -2635,8 +3206,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
2635
3206
  Table,
2636
3207
  Button,
2637
3208
  TranslocoPipe,
2638
- ], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, providers: [EntityRuntimeContextStore], template: "<div class=\"flex flex-col gap-2\">\n @if (label()) {\n <label class=\"font-medium text-color\">\n {{ label() }}\n @if (required()) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n @if (errorMessage(); as err) {\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\n } @else if (noticeKey(); as notice) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ notice | transloco }}\n </div>\n } @else if (localReady()) {\n <!--\n A Local list: rows owned by this record, staged into its own submission.\n Add / edit / delete / drag follow the Local operation switches.\n -->\n @if (localCanCreate()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openLocalRowDialog()\"\n />\n </div>\n }\n @if (localTableRows().length || localCanCreate()) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"localTableRows()\"\n [columns]=\"localColumns()\"\n [rowActions]=\"localRowActions()\"\n [reorderableRows]=\"localCanReorder()\"\n (rowReorder)=\"onLocalReorder($event)\"\n dataKey=\"Id\"\n />\n } @else {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noLocalRows\" | transloco }}\n </div>\n }\n } @else if (canWrite()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openAddDialog()\"\n />\n </div>\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"tableColumns()\"\n [rowActions]=\"writeRowActions()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n } @else if (loading() && !hasRows()) {\n <div class=\"flex flex-col gap-2\">\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n </div>\n } @else if (!hasRows()) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\n </div>\n } @else {\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"tableColumns()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n }\n\n @if (ngControl?.control) {\n <mt-field-validation\n [control]=\"ngControl?.control!\"\n [touched]=\"ngControl?.touched ?? false\"\n />\n }\n</div>\n", styles: [":host{display:block}\n"] }]
2639
- }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], propertyId: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyId", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: false }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], pendingSubmission: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingSubmission", required: false }] }], lookups: [{ type: i0.Input, args: [{ isSignal: true, alias: "lookups", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }], initialValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialValue", required: false }] }] } });
3209
+ ], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, providers: [EntityRuntimeContextStore], template: "<div class=\"flex flex-col gap-2\">\r\n @if (label()) {\r\n <label class=\"font-medium text-color\">\r\n {{ label() }}\r\n @if (required()) {\r\n <span class=\"text-red-500\">*</span>\r\n }\r\n </label>\r\n }\r\n\r\n @if (errorMessage(); as err) {\r\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\r\n } @else if (noticeKey(); as notice) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ notice | transloco }}\r\n </div>\r\n } @else if (localReady()) {\r\n <!--\r\n A Local list: rows owned by this record, staged into its own submission.\r\n Add / edit / delete / drag follow the Local operation switches.\r\n -->\r\n @if (localCanCreate()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.add' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openLocalRowDialog()\"\r\n />\r\n </div>\r\n }\r\n @if (localTableRows().length || localCanCreate()) {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"localTableRows()\"\r\n [columns]=\"localColumns()\"\r\n [rowActions]=\"localRowActions()\"\r\n [reorderableRows]=\"localCanReorder()\"\r\n (rowReorder)=\"onLocalReorder($event)\"\r\n dataKey=\"Id\"\r\n />\r\n } @else {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noLocalRows\" | transloco }}\r\n </div>\r\n }\r\n } @else if (selectionReady()) {\r\n <!--\r\n A Selected list: the source records picked for this record, and nothing\r\n else. Picking and removing change only which records it holds.\r\n -->\r\n @if (selectionWritable()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.selectRecords' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openSelectionDialog()\"\r\n />\r\n </div>\r\n }\r\n @if (selectionRows().length) {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"selectionRows()\"\r\n [columns]=\"columns()\"\r\n [rowActions]=\"selectionRowActions()\"\r\n dataKey=\"Id\"\r\n />\r\n } @else {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noSelectedRecords\" | transloco }}\r\n </div>\r\n }\r\n } @else if (canWrite()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.add' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openAddDialog()\"\r\n />\r\n </div>\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"displayRows()\"\r\n [columns]=\"tableColumns()\"\r\n [rowActions]=\"writeRowActions()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n } @else if (loading() && !hasRows()) {\r\n <div class=\"flex flex-col gap-2\">\r\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\r\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\r\n </div>\r\n } @else if (!hasRows()) {\r\n <div\r\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\r\n </div>\r\n } @else {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"displayRows()\"\r\n [columns]=\"tableColumns()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n }\r\n\r\n @if (ngControl?.control) {\r\n <mt-field-validation\r\n [control]=\"ngControl?.control!\"\r\n [touched]=\"ngControl?.touched ?? false\"\r\n />\r\n }\r\n</div>\r\n", styles: [":host{display:block}\n"] }]
3210
+ }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], propertyId: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyId", required: false }] }], propertyKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyKey", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: false }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], pendingSubmission: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingSubmission", required: false }] }], lookups: [{ type: i0.Input, args: [{ isSignal: true, alias: "lookups", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }], initialValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialValue", required: false }] }] } });
2640
3211
 
2641
3212
  /**
2642
3213
  * Lets `mt-entity-list-preview` render a module-backed `EntityList` as the