@masterteam/components 0.0.301 → 0.0.303

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 { readEntityValueColor, serializeEntityRawValue, 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 = {
@@ -824,6 +826,393 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
824
826
  * token is not registered, the field falls back to a minimal text-only popup.
825
827
  */
826
828
  const ENTITY_LIST_ADD_DIALOG_COMPONENT = new InjectionToken('ENTITY_LIST_ADD_DIALOG_COMPONENT');
829
+ /**
830
+ * Local counterpart of `ENTITY_LIST_ADD_DIALOG_COMPONENT`, registered by the
831
+ * same `provideEntityListAddForm()`. Without it a Local list is read-only.
832
+ */
833
+ const ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT = new InjectionToken('ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT');
834
+
835
+ function createLocalEditorState(base) {
836
+ return {
837
+ base,
838
+ created: [],
839
+ edited: {},
840
+ deleted: [],
841
+ order: null,
842
+ mutationId: null,
843
+ mutationKey: null,
844
+ };
845
+ }
846
+ /**
847
+ * Rows in display order. Until the user reorders, loaded rows keep their
848
+ * stored `order` and new rows go after the last one. After a reorder every row
849
+ * takes its position — the backend requires a non-negative order and nothing
850
+ * more, so positions are the simplest valid numbering.
851
+ */
852
+ function orderLocalRows(state) {
853
+ const deleted = new Set(state.deleted);
854
+ const loaded = sortLocalRows(state.base?.localRows).filter((row) => !deleted.has(row.rowId));
855
+ const maxOrder = loaded.reduce((max, row) => Math.max(max, row.order ?? 0), -1);
856
+ const rows = [
857
+ ...loaded.map((row) => ({
858
+ rowId: row.rowId,
859
+ order: row.order ?? 0,
860
+ existing: row,
861
+ })),
862
+ ...state.created.map((row, index) => ({
863
+ rowId: row.rowId,
864
+ order: maxOrder + 1 + index,
865
+ created: row,
866
+ })),
867
+ ];
868
+ if (!state.order)
869
+ return rows;
870
+ const position = new Map(state.order.map((rowId, index) => [rowId, index]));
871
+ return rows
872
+ .map((row, index) => ({ row, index }))
873
+ .sort((a, b) => (position.get(a.row.rowId) ?? state.order.length + a.index) -
874
+ (position.get(b.row.rowId) ?? state.order.length + b.index))
875
+ .map(({ row }, index) => ({ ...row, order: index }));
876
+ }
877
+ /**
878
+ * What changed, or null when nothing did.
879
+ *
880
+ * - A loaded row is sent only when a cell or its order changed, with its
881
+ * loaded version and only those cells: omission retains a cell or a row, it
882
+ * never deletes one. A reorder alone sends no cells.
883
+ * - A new row is sent with version 0 and every cell the user filled in.
884
+ * - A removed row is listed in `deletedRowIds` and never also submitted.
885
+ */
886
+ function buildLocalMutationContent(state) {
887
+ const localRows = [];
888
+ for (const row of orderLocalRows(state)) {
889
+ if (row.existing) {
890
+ const cells = toCells(state.edited[row.rowId]?.cells ?? {});
891
+ if (!cells.length && row.order === (row.existing.order ?? 0))
892
+ continue;
893
+ localRows.push({
894
+ rowId: row.rowId,
895
+ order: row.order,
896
+ version: row.existing.version ?? 0,
897
+ cells,
898
+ });
899
+ continue;
900
+ }
901
+ localRows.push({
902
+ rowId: row.rowId,
903
+ order: row.order,
904
+ version: 0,
905
+ cells: toCells(row.created?.draft.cells ?? {}).filter((cell) => cell.rawValue !== null),
906
+ });
907
+ }
908
+ if (!localRows.length && !state.deleted.length)
909
+ return null;
910
+ return { localRows, deletedRowIds: [...state.deleted] };
911
+ }
912
+ function toCells(cells) {
913
+ return Object.entries(cells).map(([fieldId, rawValue]) => ({
914
+ fieldId,
915
+ rawValue,
916
+ }));
917
+ }
918
+ /**
919
+ * The cells of an edited loaded row that differ from what was loaded.
920
+ * Setting a cell back to its loaded value drops it, so an edit that is undone
921
+ * by hand stops being an edit.
922
+ */
923
+ function diffLocalCells(loaded, next) {
924
+ const before = new Map((loaded.cells ?? []).map((cell) => [cell.fieldId, cell.rawValue ?? null]));
925
+ const changed = {};
926
+ for (const [fieldId, rawValue] of Object.entries(next)) {
927
+ if ((before.get(fieldId) ?? null) === rawValue)
928
+ continue;
929
+ changed[fieldId] = rawValue;
930
+ }
931
+ return changed;
932
+ }
933
+ /**
934
+ * A v4 UUID. Row ids and mutation ids are parsed as GUIDs by the backend.
935
+ * `crypto.randomUUID` exists only in secure contexts, and these apps are also
936
+ * served over plain HTTP, where `getRandomValues` is still available.
937
+ */
938
+ function newLocalUuid() {
939
+ if (typeof crypto.randomUUID === 'function')
940
+ return crypto.randomUUID();
941
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
942
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
943
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
944
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0'));
945
+ return [
946
+ hex.slice(0, 4).join(''),
947
+ hex.slice(4, 6).join(''),
948
+ hex.slice(6, 8).join(''),
949
+ hex.slice(8, 10).join(''),
950
+ hex.slice(10, 16).join(''),
951
+ ].join('-');
952
+ }
953
+
954
+ function createSelectionEditorState(base) {
955
+ return {
956
+ base,
957
+ ids: positiveIds(base?.entityIds),
958
+ names: {},
959
+ mutationId: null,
960
+ mutationKey: null,
961
+ };
962
+ }
963
+ function positiveIds(ids) {
964
+ const out = [];
965
+ for (const entry of ids ?? []) {
966
+ const id = Number(entry);
967
+ if (Number.isInteger(id) && id > 0 && !out.includes(id))
968
+ out.push(id);
969
+ }
970
+ return out;
971
+ }
972
+ /** Same records regardless of order — the backend stores them sorted. */
973
+ function sameSelection(a, b) {
974
+ if (a.length !== b.length)
975
+ return false;
976
+ const set = new Set(a);
977
+ return b.every((id) => set.has(id));
978
+ }
979
+ /**
980
+ * Replace the selection with the picker's result. Records already selected
981
+ * keep their place; new ones are appended in the order they were picked. In
982
+ * single mode only the last pick survives.
983
+ */
984
+ function applySelectionPicks(state, picks, multiple) {
985
+ const wanted = positiveIds(picks.map((pick) => pick.id));
986
+ const chosen = multiple ? wanted : wanted.slice(-1);
987
+ const kept = state.ids.filter((id) => chosen.includes(id));
988
+ const added = chosen.filter((id) => !kept.includes(id));
989
+ const names = { ...state.names };
990
+ for (const pick of picks) {
991
+ if (added.includes(pick.id) && pick.name)
992
+ names[pick.id] = pick.name;
993
+ }
994
+ return { ...state, ids: [...kept, ...added], names };
995
+ }
996
+ function removeSelectedRecord(state, id) {
997
+ return { ...state, ids: state.ids.filter((entry) => entry !== id) };
998
+ }
999
+ /**
1000
+ * The control's value for a state.
1001
+ *
1002
+ * A changed selection is a mutation: the full replacement `entityIds`, the
1003
+ * version it was loaded at, and a `mutationId` that stays the same while the
1004
+ * content does (a retry of the same save) and changes with it. Nothing else is
1005
+ * sent — the backend discards rendered records and snapshots, and rejects any
1006
+ * other member.
1007
+ *
1008
+ * An unchanged selection is the value it arrived as, which the submission
1009
+ * leaves out: an omitted Selected list keeps its membership.
1010
+ */
1011
+ function buildSelectionValue(next, newUuid) {
1012
+ const loaded = next.base?.entityIds ?? [];
1013
+ if (sameSelection(next.ids, positiveIds(loaded))) {
1014
+ return {
1015
+ state: { ...next, mutationId: null, mutationKey: null },
1016
+ value: next.base,
1017
+ };
1018
+ }
1019
+ const version = Number(next.base?.version ?? 0) || 0;
1020
+ const entityIds = [...next.ids];
1021
+ const mutationKey = JSON.stringify({
1022
+ version,
1023
+ entityIds: [...entityIds].sort((a, b) => a - b),
1024
+ });
1025
+ const mutationId = next.mutationKey === mutationKey && next.mutationId
1026
+ ? next.mutationId
1027
+ : newUuid();
1028
+ return {
1029
+ state: { ...next, mutationId, mutationKey },
1030
+ value: { recordMode: 'Selected', version, mutationId, entityIds },
1031
+ };
1032
+ }
1033
+
1034
+ /**
1035
+ * Candidates per request. The backend takes 1–100 and requires `skip` to be a
1036
+ * multiple of `take`, so paging only ever adds whole pages.
1037
+ */
1038
+ const PAGE_SIZE$1 = 25;
1039
+ /** The backend's limit on one list's selection. */
1040
+ const ENTITY_LIST_MAX_SELECTIONS = 100;
1041
+ /**
1042
+ * Picker of a Selected `EntityList` (`recordMode: "Selected"`), opened by
1043
+ * `mt-entity-list-field`.
1044
+ *
1045
+ * Candidates come from `GET forms/options/{propertyKey}` with the **parent's**
1046
+ * context: the backend resolves the source module and its eligibility filter
1047
+ * from the property's trusted configuration, so the caller never names the
1048
+ * source. Each candidate is only a key and a name — its field values are
1049
+ * rendered once the parent is saved.
1050
+ *
1051
+ * Closes with the chosen records as `SelectionPick[]`, or `null` on Cancel.
1052
+ */
1053
+ class EntityListSelectionDialog {
1054
+ ref = inject(ModalRef);
1055
+ /** Exposes the shared modal content/footer classes to the template. */
1056
+ modal = inject(ModalService);
1057
+ http = inject(HttpClient);
1058
+ destroyRef = inject(DestroyRef);
1059
+ /** The EntityList property's key — the options route. */
1060
+ propertyKey = input('', ...(ngDevMode ? [{ debugName: "propertyKey" }] : /* istanbul ignore next */ []));
1061
+ /** The parent form's context, e.g. `Level:3/Module:22`. */
1062
+ contextKey = input('', ...(ngDevMode ? [{ debugName: "contextKey" }] : /* istanbul ignore next */ []));
1063
+ levelDataId = input(null, ...(ngDevMode ? [{ debugName: "levelDataId" }] : /* istanbul ignore next */ []));
1064
+ multiple = input(true, ...(ngDevMode ? [{ debugName: "multiple" }] : /* istanbul ignore next */ []));
1065
+ /** The records the field holds now. */
1066
+ selectedIds = input([], ...(ngDevMode ? [{ debugName: "selectedIds" }] : /* istanbul ignore next */ []));
1067
+ context = input(undefined, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
1068
+ searchControl = new FormControl('', {
1069
+ nonNullable: true,
1070
+ });
1071
+ items = signal([], ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
1072
+ loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1073
+ hasMore = signal(false, ...(ngDevMode ? [{ debugName: "hasMore" }] : /* istanbul ignore next */ []));
1074
+ /** Translation key of the failure to show instead of the list, if any. */
1075
+ failureKey = signal(null, ...(ngDevMode ? [{ debugName: "failureKey" }] : /* istanbul ignore next */ []));
1076
+ /** Chosen records, in the order they were picked; id → name. */
1077
+ picked = signal(new Map(), ...(ngDevMode ? [{ debugName: "picked" }] : /* istanbul ignore next */ []));
1078
+ pickedCount = computed(() => this.picked().size, ...(ngDevMode ? [{ debugName: "pickedCount" }] : /* istanbul ignore next */ []));
1079
+ atLimit = computed(() => this.multiple() && this.pickedCount() >= ENTITY_LIST_MAX_SELECTIONS, ...(ngDevMode ? [{ debugName: "atLimit" }] : /* istanbul ignore next */ []));
1080
+ maxSelections = ENTITY_LIST_MAX_SELECTIONS;
1081
+ nextSkip = 0;
1082
+ request;
1083
+ ngOnInit() {
1084
+ this.picked.set(new Map(this.selectedIds().map((id) => [id, ''])));
1085
+ this.searchControl.valueChanges
1086
+ .pipe(debounceTime(300), map((value) => value.trim()), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef))
1087
+ .subscribe(() => this.load(true));
1088
+ this.load(true);
1089
+ }
1090
+ isPicked(id) {
1091
+ return this.picked().has(id);
1092
+ }
1093
+ /**
1094
+ * Multiple mode toggles the record. Single mode replaces the choice, and
1095
+ * picking the chosen record again clears it.
1096
+ */
1097
+ toggle(item) {
1098
+ const current = this.picked();
1099
+ if (current.has(item.id)) {
1100
+ const next = new Map(current);
1101
+ next.delete(item.id);
1102
+ this.picked.set(next);
1103
+ return;
1104
+ }
1105
+ if (!this.multiple()) {
1106
+ this.picked.set(new Map([[item.id, item.name]]));
1107
+ return;
1108
+ }
1109
+ if (this.atLimit())
1110
+ return;
1111
+ this.picked.set(new Map(current).set(item.id, item.name));
1112
+ }
1113
+ loadMore() {
1114
+ this.load(false);
1115
+ }
1116
+ onCancel() {
1117
+ this.ref.close(null);
1118
+ }
1119
+ onApply() {
1120
+ const names = new Map(this.items().map((item) => [item.id, item.name]));
1121
+ const picks = [...this.picked()].map(([id, name]) => ({
1122
+ id,
1123
+ name: name || names.get(id) || '',
1124
+ }));
1125
+ this.ref.close(picks);
1126
+ }
1127
+ /**
1128
+ * Load a page of candidates; `reset` starts over from the first page of the
1129
+ * current search.
1130
+ *
1131
+ * The first page of an unfiltered list also asks for the records already
1132
+ * selected (`includeSelected`), so they show as chosen even when they sit on
1133
+ * a later page. They are added beside the page, not counted in it.
1134
+ */
1135
+ load(reset) {
1136
+ this.request?.unsubscribe();
1137
+ if (reset) {
1138
+ this.nextSkip = 0;
1139
+ this.items.set([]);
1140
+ this.hasMore.set(false);
1141
+ }
1142
+ this.failureKey.set(null);
1143
+ const propertyKey = this.propertyKey();
1144
+ const contextKey = this.contextKey();
1145
+ if (!propertyKey || !contextKey) {
1146
+ this.failureKey.set('components.entityListField.selectionUnavailable');
1147
+ return;
1148
+ }
1149
+ const search = this.searchControl.value.trim();
1150
+ const skip = this.nextSkip;
1151
+ let params = new HttpParams()
1152
+ .set('contextKey', contextKey)
1153
+ .set('skip', String(skip))
1154
+ .set('take', String(PAGE_SIZE$1));
1155
+ const levelDataId = this.levelDataId();
1156
+ if (levelDataId != null && levelDataId !== '') {
1157
+ params = params.set('levelDataId', String(levelDataId));
1158
+ }
1159
+ if (search) {
1160
+ params = params.set('search', search);
1161
+ }
1162
+ const selected = this.selectedIds();
1163
+ if (skip === 0 && !search && selected.length) {
1164
+ params = params.set('includeSelected', 'true');
1165
+ for (const id of selected) {
1166
+ params = params.append('selectedIds', String(id));
1167
+ }
1168
+ }
1169
+ this.loading.set(true);
1170
+ const context = this.context();
1171
+ this.request = this.http
1172
+ .get(`forms/options/${encodeURIComponent(propertyKey)}`, {
1173
+ params,
1174
+ // Failures are shown inside the dialog, not as a host toast.
1175
+ headers: { noMessage: 'true' },
1176
+ ...(context ? { context } : {}),
1177
+ })
1178
+ .pipe(finalize(() => this.loading.set(false)), takeUntilDestroyed(this.destroyRef))
1179
+ .subscribe({
1180
+ next: (response) => this.applyPage(response, skip),
1181
+ error: (error) => this.failureKey.set(error?.error?.errors?.code === 'entity_list.target_read_denied'
1182
+ ? 'components.entityListField.accessDenied'
1183
+ : 'components.entityListField.selectionLoadFailed'),
1184
+ });
1185
+ }
1186
+ applyPage(response, skip) {
1187
+ const page = [];
1188
+ for (const item of response?.data?.items ?? []) {
1189
+ const id = Number(item?.key);
1190
+ if (!Number.isInteger(id) || id <= 0)
1191
+ continue;
1192
+ page.push({ id, name: item.name?.trim() || `#${id}` });
1193
+ }
1194
+ const seen = new Set(this.items().map((item) => item.id));
1195
+ this.items.set([
1196
+ ...this.items(),
1197
+ ...page.filter((item) => !seen.has(item.id)),
1198
+ ]);
1199
+ this.hasMore.set(!!response?.data?.hasMore);
1200
+ this.nextSkip = skip + PAGE_SIZE$1;
1201
+ }
1202
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListSelectionDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
1203
+ 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'\">\n <mt-text-field\n [formControl]=\"searchControl\"\n icon=\"general.search-md\"\n [placeholder]=\"'components.entityListField.searchRecords' | transloco\"\n />\n\n @if (multiple()) {\n <p\n class=\"text-xs\"\n [class.text-muted-color]=\"!atLimit()\"\n [class.text-amber-700]=\"atLimit()\"\n >\n {{\n (atLimit()\n ? \"components.entityListField.selectionLimit\"\n : \"components.entityListField.selectedCount\"\n ) | transloco: { count: pickedCount(), max: maxSelections }\n }}\n </p>\n }\n\n @if (failureKey(); as failure) {\n <div\n class=\"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700\"\n >\n {{ failure | transloco }}\n </div>\n } @else {\n <div\n class=\"flex min-h-40 flex-col gap-1 overflow-y-auto\"\n role=\"listbox\"\n [attr.aria-multiselectable]=\"multiple()\"\n >\n @for (item of items(); track item.id) {\n @let chosen = isPicked(item.id);\n <button\n type=\"button\"\n role=\"option\"\n [attr.aria-selected]=\"chosen\"\n [disabled]=\"!chosen && atLimit()\"\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\"\n [class.border-primary]=\"chosen\"\n [class.bg-primary-50]=\"chosen\"\n [class.border-surface]=\"!chosen\"\n (click)=\"toggle(item)\"\n >\n <span\n class=\"flex size-4 shrink-0 items-center justify-center border\"\n [class.rounded-sm]=\"multiple()\"\n [class.rounded-full]=\"!multiple()\"\n [class.border-primary]=\"chosen\"\n [class.bg-primary]=\"chosen\"\n [class.text-primary-contrast]=\"chosen\"\n [class.border-surface-400]=\"!chosen\"\n >\n @if (chosen) {\n <mt-icon icon=\"general.check\" class=\"text-[0.625rem]\" />\n }\n </span>\n <span class=\"min-w-0 flex-1 truncate text-color\">{{\n item.name\n }}</span>\n </button>\n }\n\n @if (loading()) {\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n } @else if (!items().length) {\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.noCandidates\" | transloco }}\n </div>\n }\n </div>\n\n @if (hasMore() && !loading()) {\n <div class=\"flex justify-center\">\n <mt-button\n [label]=\"'components.entityListField.loadMore' | transloco\"\n variant=\"text\"\n size=\"small\"\n (onClick)=\"loadMore()\"\n />\n </div>\n }\n }\n</div>\n\n<div [class]=\"modal.footerClass\">\n <mt-button\n [label]=\"'components.entityListField.cancel' | transloco\"\n severity=\"secondary\"\n variant=\"outlined\"\n (onClick)=\"onCancel()\"\n />\n <mt-button\n [label]=\"'components.entityListField.apply' | transloco\"\n severity=\"primary\"\n [disabled]=\"!!failureKey()\"\n (onClick)=\"onApply()\"\n />\n</div>\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 });
1204
+ }
1205
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListSelectionDialog, decorators: [{
1206
+ type: Component,
1207
+ args: [{ selector: 'mt-entity-list-selection-dialog', standalone: true, imports: [
1208
+ ReactiveFormsModule,
1209
+ TranslocoPipe,
1210
+ Skeleton,
1211
+ Icon,
1212
+ Button,
1213
+ TextField,
1214
+ ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [class]=\"modal.contentClass + ' flex max-h-[70vh] flex-col gap-3 p-4'\">\n <mt-text-field\n [formControl]=\"searchControl\"\n icon=\"general.search-md\"\n [placeholder]=\"'components.entityListField.searchRecords' | transloco\"\n />\n\n @if (multiple()) {\n <p\n class=\"text-xs\"\n [class.text-muted-color]=\"!atLimit()\"\n [class.text-amber-700]=\"atLimit()\"\n >\n {{\n (atLimit()\n ? \"components.entityListField.selectionLimit\"\n : \"components.entityListField.selectedCount\"\n ) | transloco: { count: pickedCount(), max: maxSelections }\n }}\n </p>\n }\n\n @if (failureKey(); as failure) {\n <div\n class=\"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700\"\n >\n {{ failure | transloco }}\n </div>\n } @else {\n <div\n class=\"flex min-h-40 flex-col gap-1 overflow-y-auto\"\n role=\"listbox\"\n [attr.aria-multiselectable]=\"multiple()\"\n >\n @for (item of items(); track item.id) {\n @let chosen = isPicked(item.id);\n <button\n type=\"button\"\n role=\"option\"\n [attr.aria-selected]=\"chosen\"\n [disabled]=\"!chosen && atLimit()\"\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\"\n [class.border-primary]=\"chosen\"\n [class.bg-primary-50]=\"chosen\"\n [class.border-surface]=\"!chosen\"\n (click)=\"toggle(item)\"\n >\n <span\n class=\"flex size-4 shrink-0 items-center justify-center border\"\n [class.rounded-sm]=\"multiple()\"\n [class.rounded-full]=\"!multiple()\"\n [class.border-primary]=\"chosen\"\n [class.bg-primary]=\"chosen\"\n [class.text-primary-contrast]=\"chosen\"\n [class.border-surface-400]=\"!chosen\"\n >\n @if (chosen) {\n <mt-icon icon=\"general.check\" class=\"text-[0.625rem]\" />\n }\n </span>\n <span class=\"min-w-0 flex-1 truncate text-color\">{{\n item.name\n }}</span>\n </button>\n }\n\n @if (loading()) {\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"2.5rem\" borderRadius=\"0.375rem\" />\n } @else if (!items().length) {\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.noCandidates\" | transloco }}\n </div>\n }\n </div>\n\n @if (hasMore() && !loading()) {\n <div class=\"flex justify-center\">\n <mt-button\n [label]=\"'components.entityListField.loadMore' | transloco\"\n variant=\"text\"\n size=\"small\"\n (onClick)=\"loadMore()\"\n />\n </div>\n }\n }\n</div>\n\n<div [class]=\"modal.footerClass\">\n <mt-button\n [label]=\"'components.entityListField.cancel' | transloco\"\n severity=\"secondary\"\n variant=\"outlined\"\n (onClick)=\"onCancel()\"\n />\n <mt-button\n [label]=\"'components.entityListField.apply' | transloco\"\n severity=\"primary\"\n [disabled]=\"!!failureKey()\"\n (onClick)=\"onApply()\"\n />\n</div>\n" }]
1215
+ }], 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 }] }] } });
827
1216
 
828
1217
  function resolveMetadataFailure(status) {
829
1218
  if (status === 403)
@@ -867,6 +1256,26 @@ const OBJECT_VALUED_VIEW_TYPES = new Set(['User', 'MultiUser']);
867
1256
  const ROW_CHANGE_KEY = '__change';
868
1257
  /** Column key of the synthetic flag column — never a target property key. */
869
1258
  const ROW_CHANGE_COLUMN_KEY = '__changeState';
1259
+ /** Internal row key marking a Local row added in this session. */
1260
+ const ROW_LOCAL_CREATED_KEY = '__localCreated';
1261
+ /**
1262
+ * The editing state behind each Local value this field emitted, keyed by that
1263
+ * value.
1264
+ *
1265
+ * A mutation carries only what changed, so it cannot rebuild the table on its
1266
+ * own — and the field is not always the one that emitted it: `mt-dynamic-form`
1267
+ * destroys the sections outside the current wizard step, and the field that
1268
+ * comes back is a new instance handed the form's current value. Keeping the
1269
+ * state out of the payload leaves the submitted JSON exactly the contract,
1270
+ * and a `WeakMap` lets it go with the value.
1271
+ */
1272
+ const LOCAL_EDITOR_STATES = new WeakMap();
1273
+ /**
1274
+ * The editing state behind each Selected value this field emitted, for the
1275
+ * same reason as `LOCAL_EDITOR_STATES`: a mutation is only ids, and the names
1276
+ * of records picked in this session live nowhere else.
1277
+ */
1278
+ const SELECTION_EDITOR_STATES = new WeakMap();
870
1279
  /**
871
1280
  * Badge colour per staged operation, as a hex: `mt-entity-status` derives its
872
1281
  * own 12%-alpha background by slicing the value's `color`, so a Tailwind class
@@ -888,6 +1297,11 @@ class EntityListField {
888
1297
  * effective configuration.
889
1298
  */
890
1299
  propertyId = input(null, ...(ngDevMode ? [{ debugName: "propertyId" }] : /* istanbul ignore next */ []));
1300
+ /**
1301
+ * EntityList property key. A Selected list's picker loads its candidates
1302
+ * from `forms/options/{propertyKey}`; no other mode reads it.
1303
+ */
1304
+ propertyKey = input('', ...(ngDevMode ? [{ debugName: "propertyKey" }] : /* istanbul ignore next */ []));
891
1305
  /**
892
1306
  * Stored property configuration (sourceType, moduleId, access, readFields …).
893
1307
  *
@@ -1247,6 +1661,329 @@ class EntityListField {
1247
1661
  },
1248
1662
  ];
1249
1663
  }, ...(ngDevMode ? [{ debugName: "tableColumns" }] : /* istanbul ignore next */ []));
1664
+ // ============================================================================
1665
+ // Local storage (`storageMode: "Local"`) — rows owned by the parent record
1666
+ // ============================================================================
1667
+ /** Loaded document plus this session's edits; see `LocalEditorState`. */
1668
+ localState = signal(createLocalEditorState(null), ...(ngDevMode ? [{ debugName: "localState" }] : /* istanbul ignore next */ []));
1669
+ /** The bound value was a Local document, whatever the metadata says yet. */
1670
+ localValueSeen = signal(false, ...(ngDevMode ? [{ debugName: "localValueSeen" }] : /* istanbul ignore next */ []));
1671
+ /** The last Local value emitted, so its echo does not reset the edits. */
1672
+ lastLocalEmit = null;
1673
+ /**
1674
+ * Rows live inside the parent record: no target records, no `fetch/query`,
1675
+ * and the value is a document of its own rather than operation markers.
1676
+ * Known from the metadata, or earlier from the value itself.
1677
+ */
1678
+ localMode = computed(() => this.metadata()?.storageMode === 'Local' || this.localValueSeen(), ...(ngDevMode ? [{ debugName: "localMode" }] : /* istanbul ignore next */ []));
1679
+ /**
1680
+ * The schema the table is built from. A loaded value's own schema wins: it
1681
+ * is the one its rows were projected against, and pending or approved
1682
+ * evidence stays pinned to the schema it was submitted with. The metadata's
1683
+ * active schema is the fallback for a list that has never been saved.
1684
+ */
1685
+ localSchema = computed(() => this.localState().base?.schema ?? this.metadata()?.localSchema ?? null, ...(ngDevMode ? [{ debugName: "localSchema" }] : /* istanbul ignore next */ []));
1686
+ localFields = computed(() => visibleLocalSchemaFields(this.localSchema()), ...(ngDevMode ? [{ debugName: "localFields" }] : /* istanbul ignore next */ []));
1687
+ /**
1688
+ * Render the Local table once the metadata answered: it is the access
1689
+ * boundary, and it carries the operation switches the table obeys.
1690
+ */
1691
+ localReady = computed(() => this.localMode() && !!this.metadata(), ...(ngDevMode ? [{ debugName: "localReady" }] : /* istanbul ignore next */ []));
1692
+ /**
1693
+ * Writes are staged into the parent's submission, never sent on their own.
1694
+ *
1695
+ * Whether the host lets this field be edited is the form's call —
1696
+ * `readonly` — as it is for a linked list; `pendingSubmission` is not one.
1697
+ * A loaded request is not always a review: a returned request is loaded to
1698
+ * be corrected and resubmitted, and the backend projects the active schema
1699
+ * for exactly that.
1700
+ */
1701
+ localWritable = computed(() => !!this.localDialogComponent &&
1702
+ !!this.metadata() &&
1703
+ this.writeAllowed() &&
1704
+ !this.readonly() &&
1705
+ !this.disabled() &&
1706
+ this.localFields().length > 0, ...(ngDevMode ? [{ debugName: "localWritable" }] : /* istanbul ignore next */ []));
1707
+ localCanCreate = computed(() => this.localWritable() && this.metadata()?.allowCreate !== false, ...(ngDevMode ? [{ debugName: "localCanCreate" }] : /* istanbul ignore next */ []));
1708
+ localCanEdit = computed(() => this.localWritable() && this.metadata()?.allowEdit !== false, ...(ngDevMode ? [{ debugName: "localCanEdit" }] : /* istanbul ignore next */ []));
1709
+ localCanDelete = computed(() => this.localWritable() && this.metadata()?.allowDelete !== false, ...(ngDevMode ? [{ debugName: "localCanDelete" }] : /* istanbul ignore next */ []));
1710
+ /** Reordering rewrites loaded rows, so it is an edit. */
1711
+ localCanReorder = computed(() => this.localCanEdit() && this.localTableRows().length > 1, ...(ngDevMode ? [{ debugName: "localCanReorder" }] : /* istanbul ignore next */ []));
1712
+ /**
1713
+ * One column per visible schema field, keyed by the field's local id — the
1714
+ * id cells are keyed by. Sorting is off while rows can be dragged: a sorted
1715
+ * table would show an order that is not the one being saved.
1716
+ */
1717
+ localColumns = computed(() => {
1718
+ const lang = this.lang();
1719
+ const sortable = !this.localCanEdit();
1720
+ return this.localFields().map((field, index) => {
1721
+ const viewType = resolveLocalFieldViewType(field);
1722
+ return {
1723
+ key: field.id,
1724
+ label: resolveLocalFieldLabel(field, lang),
1725
+ type: 'entity',
1726
+ sortable: sortable &&
1727
+ !UNSORTABLE_ENTITY_VIEW_TYPES.has(viewType),
1728
+ viewType,
1729
+ order: index,
1730
+ visible: true,
1731
+ configuration: null,
1732
+ };
1733
+ });
1734
+ }, ...(ngDevMode ? [{ debugName: "localColumns" }] : /* istanbul ignore next */ []));
1735
+ /**
1736
+ * Rows as rendered: loaded rows with this session's edits over them, then
1737
+ * new rows, in the order they would be saved. A loaded cell renders from the
1738
+ * backend's resolved `value`; a cell the user set renders from the dialog's
1739
+ * control value and option label, like a locally added linked row.
1740
+ */
1741
+ localTableRows = computed(() => {
1742
+ const state = this.localState();
1743
+ const fields = this.localFields();
1744
+ const columns = new Map(this.localColumns().map((column) => [column.key, column]));
1745
+ return orderLocalRows(state).map((entry) => {
1746
+ const cells = entry.existing
1747
+ ? localCellsByFieldId(entry.existing)
1748
+ : new Map();
1749
+ const draft = entry.created?.draft ?? state.edited[entry.rowId];
1750
+ const row = {
1751
+ Id: entry.rowId,
1752
+ [ROW_ID_KEY]: entry.rowId,
1753
+ [ROW_LOCAL_CREATED_KEY]: !!entry.created,
1754
+ };
1755
+ for (const field of fields) {
1756
+ const fieldId = field.id;
1757
+ const column = columns.get(fieldId);
1758
+ if (!column)
1759
+ continue;
1760
+ const configuration = resolveLocalFieldConfiguration(field);
1761
+ row[fieldId] =
1762
+ draft && (entry.created || fieldId in draft.cells)
1763
+ ? this.buildLocalDraftCell(column, draft, configuration)
1764
+ : this.buildLocalLoadedCell(column, cells.get(fieldId), configuration);
1765
+ }
1766
+ return row;
1767
+ });
1768
+ }, ...(ngDevMode ? [{ debugName: "localTableRows" }] : /* istanbul ignore next */ []));
1769
+ /**
1770
+ * Edit and delete per row. A row added in this session is still part of the
1771
+ * create — changing or dropping it undoes nothing stored — so it follows
1772
+ * `allowCreate`; a loaded row follows `allowEdit` / `allowDelete`.
1773
+ */
1774
+ localRowActions = computed(() => {
1775
+ this.lang();
1776
+ const canCreate = this.localCanCreate();
1777
+ const canEdit = this.localCanEdit();
1778
+ const canDelete = this.localCanDelete();
1779
+ const isCreated = (row) => row[ROW_LOCAL_CREATED_KEY] === true;
1780
+ const actions = [];
1781
+ if (canCreate || canEdit) {
1782
+ actions.push({
1783
+ icon: 'custom.pencil',
1784
+ tooltip: this.transloco.translate('components.entityListField.edit'),
1785
+ hidden: (row) => isCreated(row) ? !canCreate : !canEdit,
1786
+ action: (row) => this.openLocalRowDialog(row),
1787
+ });
1788
+ }
1789
+ if (canCreate || canDelete) {
1790
+ actions.push({
1791
+ icon: 'general.trash-01',
1792
+ tooltip: this.transloco.translate('components.entityListField.delete'),
1793
+ color: 'danger',
1794
+ confirmation: {
1795
+ type: 'popup',
1796
+ confirmationType: 'delete',
1797
+ },
1798
+ hidden: (row) => isCreated(row) ? !canCreate : !canDelete,
1799
+ action: (row) => this.deleteLocalRow(row),
1800
+ });
1801
+ }
1802
+ return actions;
1803
+ }, ...(ngDevMode ? [{ debugName: "localRowActions" }] : /* istanbul ignore next */ []));
1804
+ // ============================================================================
1805
+ // Selected records (`recordMode: "Selected"`) — source records the user picked
1806
+ // ============================================================================
1807
+ /** Loaded selection plus this session's picks; see `SelectionEditorState`. */
1808
+ selectionState = signal(createSelectionEditorState(null), ...(ngDevMode ? [{ debugName: "selectionState" }] : /* istanbul ignore next */ []));
1809
+ /** The bound value was a Selected document, whatever the metadata says yet. */
1810
+ selectionValueSeen = signal(false, ...(ngDevMode ? [{ debugName: "selectionValueSeen" }] : /* istanbul ignore next */ []));
1811
+ /** The last Selected value emitted, so its echo does not reset the picks. */
1812
+ lastSelectionEmit = null;
1813
+ /**
1814
+ * The list holds only the records the user picked. It never falls back to
1815
+ * every related record: an empty selection is empty. Known from the
1816
+ * metadata, or earlier from the value itself.
1817
+ */
1818
+ selectionMode = computed(() => this.metadata()?.recordMode === 'Selected' || this.selectionValueSeen(), ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
1819
+ /** Render once the metadata answered: it is the access boundary. */
1820
+ selectionReady = computed(() => this.selectionMode() && !!this.metadata(), ...(ngDevMode ? [{ debugName: "selectionReady" }] : /* istanbul ignore next */ []));
1821
+ selectionMultiple = computed(() => this.metadata()?.selectionMode !== 'Single', ...(ngDevMode ? [{ debugName: "selectionMultiple" }] : /* istanbul ignore next */ []));
1822
+ /**
1823
+ * The picker's `contextKey`: the context of the form that owns the property
1824
+ * — never the source module, which the backend resolves from the property's
1825
+ * own configuration.
1826
+ */
1827
+ selectionContextKey = computed(() => {
1828
+ const levelId = this.levelId();
1829
+ if (levelId == null)
1830
+ return null;
1831
+ const moduleId = this.runtimeContext()?.moduleId;
1832
+ return moduleId == null || moduleId === ''
1833
+ ? `Level:${levelId}`
1834
+ : `Level:${levelId}/Module:${moduleId}`;
1835
+ }, ...(ngDevMode ? [{ debugName: "selectionContextKey" }] : /* istanbul ignore next */ []));
1836
+ /**
1837
+ * Whether the user may change which records are selected. That is the
1838
+ * form's call — `readonly`, from the field's `isWrite` — and not the
1839
+ * metadata's `access` or its `allow*` switches: those describe the source
1840
+ * records, which selecting never writes.
1841
+ */
1842
+ selectionWritable = computed(() => this.selectionReady() &&
1843
+ !this.readonly() &&
1844
+ !this.disabled() &&
1845
+ !!this.propertyKey() &&
1846
+ !!this.selectionContextKey(), ...(ngDevMode ? [{ debugName: "selectionWritable" }] : /* istanbul ignore next */ []));
1847
+ /**
1848
+ * The selected records as table rows, in selection order.
1849
+ *
1850
+ * A saved record renders from the backend's `records`, cell by cell against
1851
+ * the metadata columns — the same cells a related list shows. A record
1852
+ * picked in this session has no rendered values until the parent is saved,
1853
+ * so it shows its name in the first column. A record in `unavailableIds` was
1854
+ * deleted or is no longer visible: the backend keeps it selected but
1855
+ * withholds its values, and the row says so, so the user can remove it.
1856
+ */
1857
+ selectionRows = computed(() => {
1858
+ const state = this.selectionState();
1859
+ const columns = this.columns();
1860
+ const properties = this.propertyByKey();
1861
+ const records = new Map((state.base?.records ?? []).map((record) => [record.entityId, record]));
1862
+ const unavailable = new Set(state.base?.unavailableIds ?? []);
1863
+ return state.ids.map((id) => {
1864
+ const row = {
1865
+ Id: id,
1866
+ [ROW_ID_KEY]: `entity-${id}`,
1867
+ [ROW_ENTITY_ID_KEY]: id,
1868
+ };
1869
+ const record = records.get(id);
1870
+ if (record) {
1871
+ const values = new Map((record.values ?? []).map((item) => [item.propertyKey, item]));
1872
+ for (const column of columns) {
1873
+ const propertyKey = column.propertyKey ?? column.key;
1874
+ const item = values.get(propertyKey) ?? values.get(column.key);
1875
+ row[column.key] = this.toEntityData(column, item ? { raw: item.rawValue, value: item.value } : undefined, properties.get(propertyKey), id);
1876
+ }
1877
+ return row;
1878
+ }
1879
+ const label = unavailable.has(id)
1880
+ ? this.transloco.translate('components.entityListField.unavailableRecord', { id }, this.lang())
1881
+ : state.names[id] || `#${id}`;
1882
+ columns.forEach((column, index) => {
1883
+ row[column.key] = {
1884
+ key: column.key,
1885
+ name: column.label,
1886
+ viewType: 'Text',
1887
+ value: index === 0 ? label : '',
1888
+ };
1889
+ });
1890
+ return row;
1891
+ });
1892
+ }, ...(ngDevMode ? [{ debugName: "selectionRows" }] : /* istanbul ignore next */ []));
1893
+ selectionRowActions = computed(() => {
1894
+ this.lang();
1895
+ if (!this.selectionWritable())
1896
+ return [];
1897
+ return [
1898
+ {
1899
+ icon: 'general.x-close',
1900
+ tooltip: this.transloco.translate('components.entityListField.unselect'),
1901
+ color: 'danger',
1902
+ action: (row) => this.emitSelection(removeSelectedRecord(this.selectionState(), Number(row[ROW_ENTITY_ID_KEY]))),
1903
+ },
1904
+ ];
1905
+ }, ...(ngDevMode ? [{ debugName: "selectionRowActions" }] : /* istanbul ignore next */ []));
1906
+ /**
1907
+ * A required Selected list needs a record. An emptied selection is an
1908
+ * object — a mutation with no ids — so `Validators.required` passes it and
1909
+ * only the backend would object (`entity_list.selection_required`).
1910
+ */
1911
+ selectionRequiredValidator = (control) => {
1912
+ if (!this.required())
1913
+ return null;
1914
+ const value = control.value;
1915
+ if (isEntityListSelectionDocument(value)) {
1916
+ return value.entityIds?.length ? null : { required: true };
1917
+ }
1918
+ return value == null && this.selectionMode() ? { required: true } : null;
1919
+ };
1920
+ openSelectionDialog() {
1921
+ if (!this.selectionWritable())
1922
+ return;
1923
+ const ref = this.modal.openModal(EntityListSelectionDialog, 'dialog', {
1924
+ header: this.transloco.translate('components.entityListField.selectRecords'),
1925
+ styleClass: '!w-[36rem] max-w-[96vw]',
1926
+ dismissableMask: true,
1927
+ inputValues: {
1928
+ propertyKey: this.propertyKey(),
1929
+ contextKey: this.selectionContextKey(),
1930
+ levelDataId: this.levelDataId(),
1931
+ multiple: this.selectionMultiple(),
1932
+ selectedIds: this.selectionState().ids,
1933
+ context: this.context(),
1934
+ },
1935
+ });
1936
+ ref.onClose.pipe(take(1)).subscribe((result) => {
1937
+ if (!Array.isArray(result))
1938
+ return;
1939
+ this.emitSelection(applySelectionPicks(this.selectionState(), result, this.selectionMultiple()));
1940
+ });
1941
+ }
1942
+ /**
1943
+ * Publish the selection as the control's value: a mutation when it differs
1944
+ * from what was loaded, else the loaded value, which the submission leaves
1945
+ * out. See `buildSelectionValue`.
1946
+ */
1947
+ emitSelection(next) {
1948
+ const { state, value } = buildSelectionValue(next, newLocalUuid);
1949
+ this.selectionState.set(state);
1950
+ if (value)
1951
+ SELECTION_EDITOR_STATES.set(value, state);
1952
+ this.lastSelectionEmit = value;
1953
+ this.onModelChange(value);
1954
+ this.onTouched();
1955
+ }
1956
+ /**
1957
+ * Take a Selected document, and say whether it was one.
1958
+ *
1959
+ * Our own emission echoed back keeps the session; a value some instance of
1960
+ * this field emitted restores that instance's state (see
1961
+ * `SELECTION_EDITOR_STATES`); anything else starts a session on it. That is
1962
+ * the projection `process-form-load` returns, the stored document a preview
1963
+ * gets from the fetch endpoints, or a mutation the form already held — which
1964
+ * stays the control's value until the user changes the selection.
1965
+ *
1966
+ * An empty value resets the session too and still falls through, since
1967
+ * which mode the list uses may not be known yet.
1968
+ */
1969
+ writeSelectionValue(value) {
1970
+ const incoming = this.coerceStoredValue(value);
1971
+ if (!isEntityListSelectionDocument(incoming)) {
1972
+ if (incoming == null) {
1973
+ this.lastSelectionEmit = null;
1974
+ this.selectionState.set(createSelectionEditorState(null));
1975
+ }
1976
+ return false;
1977
+ }
1978
+ this.selectionValueSeen.set(true);
1979
+ if (incoming === this.lastSelectionEmit)
1980
+ return true;
1981
+ this.lastSelectionEmit = null;
1982
+ const restored = SELECTION_EDITOR_STATES.get(incoming);
1983
+ this.selectionState.set(restored ??
1984
+ createSelectionEditorState(incoming));
1985
+ return true;
1986
+ }
1250
1987
  /** Enough context to ask the backend what this field should render. */
1251
1988
  hasRequiredContext = computed(() => this.propertyKeyId() > 0 && Number(this.levelId()) > 0, ...(ngDevMode ? [{ debugName: "hasRequiredContext" }] : /* istanbul ignore next */ []));
1252
1989
  /**
@@ -1268,6 +2005,13 @@ class EntityListField {
1268
2005
  }
1269
2006
  if (!this.metadata())
1270
2007
  return null;
2008
+ // A Local list reads nothing from the source module; it needs only a
2009
+ // schema to render its own rows with.
2010
+ if (this.localMode()) {
2011
+ return this.localFields().length
2012
+ ? null
2013
+ : 'components.entityListField.missingConfiguration';
2014
+ }
1271
2015
  if (!this.moduleBacked()) {
1272
2016
  return 'components.entityListField.missingConfiguration';
1273
2017
  }
@@ -1294,6 +2038,12 @@ class EntityListField {
1294
2038
  * `writeFields`.
1295
2039
  */
1296
2040
  addDialogComponent = inject(ENTITY_LIST_ADD_DIALOG_COMPONENT, { optional: true });
2041
+ /**
2042
+ * Row dialog of a Local list, built from the schema's captured definitions
2043
+ * (`provideEntityListAddForm()` registers it beside the linked one). Without
2044
+ * it a Local list renders read-only.
2045
+ */
2046
+ localDialogComponent = inject(ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT, { optional: true });
1297
2047
  constructor() {
1298
2048
  this.ngControl = inject(NgControl, { self: true, optional: true });
1299
2049
  if (this.ngControl) {
@@ -1309,6 +2059,23 @@ class EntityListField {
1309
2059
  const levelDataId = this.levelDataId();
1310
2060
  untracked(() => this.loadTable(propertyId, levelId, levelDataId));
1311
2061
  });
2062
+ // The control exists once the form directive has resolved it, which is
2063
+ // after construction. The validator reads `required` and the mode itself,
2064
+ // so it is added once; the control is re-validated when either changes —
2065
+ // the mode is only known once the metadata or the value arrives.
2066
+ effect(() => {
2067
+ this.selectionMode();
2068
+ this.required();
2069
+ const control = this.ngControl?.control;
2070
+ if (!control)
2071
+ return;
2072
+ untracked(() => {
2073
+ if (!control.hasValidator(this.selectionRequiredValidator)) {
2074
+ control.addValidators(this.selectionRequiredValidator);
2075
+ }
2076
+ control.updateValueAndValidity({ emitEvent: false });
2077
+ });
2078
+ });
1312
2079
  // Form-less hosts hand the value over as an input instead. `writeValue` is
1313
2080
  // the one entry point that resets the pending rows and deletions with it,
1314
2081
  // so it is reused rather than re-implemented.
@@ -1327,6 +2094,10 @@ class EntityListField {
1327
2094
  // CVA
1328
2095
  // ============================================================================
1329
2096
  writeValue(value) {
2097
+ if (this.writeLocalValue(value))
2098
+ return;
2099
+ if (this.writeSelectionValue(value))
2100
+ return;
1330
2101
  const incoming = this.coerceStoredValue(value);
1331
2102
  // Ignore the echo of our own emission (DynamicForm re-writes the model on
1332
2103
  // every value change) so pending edits/deletions are not reset.
@@ -1346,6 +2117,47 @@ class EntityListField {
1346
2117
  this.stagedDeletedIds.set([]);
1347
2118
  this.rowDrafts.set({});
1348
2119
  }
2120
+ /**
2121
+ * Take a Local document, and say whether it was one.
2122
+ *
2123
+ * - Our own emission echoed back (`mt-dynamic-form` re-writes the model on
2124
+ * every change) keeps the session's edits.
2125
+ * - A value some instance of this field emitted restores that instance's
2126
+ * state — see `LOCAL_EDITOR_STATES`.
2127
+ * - A document the backend sent starts a fresh session on it: the projection
2128
+ * `process-form-load` and the fetch endpoints return (its `schema` set,
2129
+ * cells rendered), or the stored document an older backend's fetch
2130
+ * endpoints returned (`schema: null`, cells unrendered) — the schema then
2131
+ * comes from the metadata.
2132
+ * Every backend document carries the `schema` member, null or not; a
2133
+ * mutation never does. So a mutation nobody here emitted has no rows to
2134
+ * rebuild the table from and is left as the control's value, untouched
2135
+ * until the user edits.
2136
+ *
2137
+ * An empty value resets the Local session too — a form reset — and still
2138
+ * falls through, since which storage the list uses may not be known yet.
2139
+ */
2140
+ writeLocalValue(value) {
2141
+ const incoming = this.coerceStoredValue(value);
2142
+ if (!isEntityListLocalDocument(incoming)) {
2143
+ if (incoming == null) {
2144
+ this.lastLocalEmit = null;
2145
+ this.localState.set(createLocalEditorState(null));
2146
+ }
2147
+ return false;
2148
+ }
2149
+ this.localValueSeen.set(true);
2150
+ if (incoming === this.lastLocalEmit)
2151
+ return true;
2152
+ this.lastLocalEmit = null;
2153
+ const restored = LOCAL_EDITOR_STATES.get(incoming);
2154
+ if (restored) {
2155
+ this.localState.set(restored);
2156
+ return true;
2157
+ }
2158
+ this.localState.set(createLocalEditorState('schema' in incoming ? incoming : null));
2159
+ return true;
2160
+ }
1349
2161
  /**
1350
2162
  * True when the written value still carries exactly the rows and deletions
1351
2163
  * we last emitted — i.e. the form is echoing our own value back rather than
@@ -1550,6 +2362,226 @@ class EntityListField {
1550
2362
  this.clearRowDraft(rowId);
1551
2363
  this.emitValue();
1552
2364
  }
2365
+ // ============================================================================
2366
+ // Local write mode — staged into the parent's own submission
2367
+ // ============================================================================
2368
+ /**
2369
+ * Add a Local row (no `row`) or edit one. The dialog is built from the
2370
+ * schema; its `submit` map is serialized here into cell `rawValue`s.
2371
+ *
2372
+ * A loaded row keeps only the cells that differ from what was loaded, so an
2373
+ * untouched cell is omitted and retained. Emptying a cell that had a value
2374
+ * is a clear, sent as `null` — the dialog is filled from every schema field,
2375
+ * so an empty control here really was emptied.
2376
+ */
2377
+ openLocalRowDialog(row) {
2378
+ const component = this.localDialogComponent;
2379
+ if (!component || this.disabled())
2380
+ return;
2381
+ const state = this.localState();
2382
+ const rowId = row ? String(row[ROW_ID_KEY] ?? '') : null;
2383
+ const created = rowId
2384
+ ? state.created.find((entry) => entry.rowId === rowId)
2385
+ : undefined;
2386
+ const existing = rowId && !created
2387
+ ? state.base?.localRows?.find((entry) => entry.rowId === rowId)
2388
+ : undefined;
2389
+ const ref = this.modal.openModal(component, 'dialog', {
2390
+ header: this.transloco.translate(row
2391
+ ? 'components.entityListField.edit'
2392
+ : 'components.entityListField.add'),
2393
+ styleClass: '!w-[48rem] max-w-[96vw]',
2394
+ dismissableMask: true,
2395
+ inputValues: {
2396
+ fields: this.localFields(),
2397
+ lookups: this.lookups(),
2398
+ initialCells: existing
2399
+ ? Object.fromEntries(localCellsByFieldId(existing))
2400
+ : undefined,
2401
+ initialValues: created?.draft.values ??
2402
+ (rowId ? state.edited[rowId]?.values : undefined),
2403
+ isEdit: !!row,
2404
+ },
2405
+ });
2406
+ ref.onClose.pipe(take(1)).subscribe((result) => {
2407
+ const parsed = this.parseDialogResult(result);
2408
+ if (!parsed)
2409
+ return;
2410
+ const draft = {
2411
+ cells: this.toLocalCells(parsed.values, parsed.submit),
2412
+ values: parsed.values,
2413
+ display: parsed.display,
2414
+ };
2415
+ const current = this.localState();
2416
+ if (!rowId) {
2417
+ this.emitLocal({
2418
+ ...current,
2419
+ created: [...current.created, { rowId: newLocalUuid(), draft }],
2420
+ });
2421
+ return;
2422
+ }
2423
+ if (created) {
2424
+ this.emitLocal({
2425
+ ...current,
2426
+ created: current.created.map((entry) => entry.rowId === rowId ? { ...entry, draft } : entry),
2427
+ });
2428
+ return;
2429
+ }
2430
+ if (!existing)
2431
+ return;
2432
+ const edited = { ...current.edited };
2433
+ const changed = diffLocalCells(existing, draft.cells);
2434
+ if (Object.keys(changed).length > 0) {
2435
+ edited[rowId] = { ...draft, cells: changed };
2436
+ }
2437
+ else {
2438
+ delete edited[rowId];
2439
+ }
2440
+ this.emitLocal({ ...current, edited });
2441
+ });
2442
+ }
2443
+ /**
2444
+ * Remove a Local row. A loaded row is listed in `deletedRowIds` and its
2445
+ * pending edit dropped — a row is never both deleted and submitted. A row
2446
+ * added in this session just disappears.
2447
+ */
2448
+ deleteLocalRow(row) {
2449
+ if (this.disabled())
2450
+ return;
2451
+ const rowId = String(row[ROW_ID_KEY] ?? '');
2452
+ const current = this.localState();
2453
+ if (current.created.some((entry) => entry.rowId === rowId)) {
2454
+ this.emitLocal({
2455
+ ...current,
2456
+ created: current.created.filter((entry) => entry.rowId !== rowId),
2457
+ });
2458
+ return;
2459
+ }
2460
+ const edited = { ...current.edited };
2461
+ delete edited[rowId];
2462
+ this.emitLocal({
2463
+ ...current,
2464
+ edited,
2465
+ deleted: current.deleted.includes(rowId)
2466
+ ? current.deleted
2467
+ : [...current.deleted, rowId],
2468
+ });
2469
+ }
2470
+ /**
2471
+ * Apply a drag within the table. Replays PrimeNG's own move on the rows as
2472
+ * rendered: `p-table` is bound to a derived array, so the event's `value`
2473
+ * is not reliably the reordered one.
2474
+ */
2475
+ onLocalReorder(event) {
2476
+ const from = Number(event?.dragIndex);
2477
+ const to = Number(event?.dropIndex);
2478
+ const ids = this.localTableRows().map((row) => String(row[ROW_ID_KEY]));
2479
+ if (!Number.isInteger(from) ||
2480
+ !Number.isInteger(to) ||
2481
+ from === to ||
2482
+ from < 0 ||
2483
+ to < 0 ||
2484
+ from >= ids.length ||
2485
+ to >= ids.length) {
2486
+ return;
2487
+ }
2488
+ const [moved] = ids.splice(from, 1);
2489
+ ids.splice(to, 0, moved);
2490
+ this.emitLocal({ ...this.localState(), order: ids });
2491
+ }
2492
+ /**
2493
+ * Serialize one dialog result into cells, by field id, for every visible
2494
+ * field. `submit` is the dialog's reduction to stored scalars and wins over
2495
+ * the raw control value, as for linked rows.
2496
+ */
2497
+ toLocalCells(values, submit) {
2498
+ const cells = {};
2499
+ for (const field of this.localFields()) {
2500
+ const fieldId = field.id;
2501
+ cells[fieldId] = this.toRawValue(fieldId in submit ? submit[fieldId] : values[fieldId]);
2502
+ }
2503
+ return cells;
2504
+ }
2505
+ /**
2506
+ * Publish the Local state as the control's value.
2507
+ *
2508
+ * With changes, the value is a mutation: the loaded list and schema
2509
+ * versions, only the changed rows and cells, explicit deletions, and a
2510
+ * `mutationId` that stays the same while the content does (a retry of the
2511
+ * same save) and changes with it (a new save). Without changes it is the
2512
+ * loaded document again, which `mapFormValueToSubmitFields` leaves out of the
2513
+ * submission — an unchanged Local list is omitted, never re-sent.
2514
+ */
2515
+ emitLocal(next) {
2516
+ const content = buildLocalMutationContent(next);
2517
+ let state = next;
2518
+ let value = next.base;
2519
+ if (content) {
2520
+ const mutation = {
2521
+ storageMode: 'Local',
2522
+ formatVersion: 1,
2523
+ schemaVersion: next.base?.schemaVersion ??
2524
+ this.metadata()?.localSchema?.version ??
2525
+ '',
2526
+ version: next.base?.version ?? 0,
2527
+ ...content,
2528
+ };
2529
+ const mutationKey = JSON.stringify(mutation);
2530
+ const mutationId = next.mutationKey === mutationKey && next.mutationId
2531
+ ? next.mutationId
2532
+ : newLocalUuid();
2533
+ state = { ...next, mutationId, mutationKey };
2534
+ value = { ...mutation, mutationId };
2535
+ }
2536
+ else {
2537
+ state = { ...next, mutationId: null, mutationKey: null };
2538
+ }
2539
+ this.localState.set(state);
2540
+ if (value)
2541
+ LOCAL_EDITOR_STATES.set(value, state);
2542
+ this.lastLocalEmit = value;
2543
+ this.onModelChange(value);
2544
+ this.onTouched();
2545
+ }
2546
+ /** A cell the user set in this session, shaped like a backend one. */
2547
+ buildLocalDraftCell(column, draft, configuration) {
2548
+ const fieldId = column.key;
2549
+ const raw = draft.values[fieldId];
2550
+ const label = draft.display[fieldId];
2551
+ // A multi-select holds ids and resolves to labels; print the labels.
2552
+ const value = Array.isArray(raw) && Array.isArray(label)
2553
+ ? label.join(', ')
2554
+ : this.toLocalEntityValue(column.viewType, raw, label);
2555
+ return {
2556
+ key: fieldId,
2557
+ name: column.label,
2558
+ viewType: (column.viewType ?? 'Text'),
2559
+ value: (value !== null && typeof value === 'object'
2560
+ ? value
2561
+ : (this.toRawValue(value) ?? '')),
2562
+ rawValue: draft.cells[fieldId] ?? undefined,
2563
+ propertyConfiguration: configuration ?? undefined,
2564
+ };
2565
+ }
2566
+ /**
2567
+ * A loaded cell: the backend's rendered `value` beside its `rawValue`. A
2568
+ * stored document (what an older backend's fetch endpoints returned) has no
2569
+ * rendered values, so the raw one is shaped the way a locally set cell would
2570
+ * be — a user id still renders as a user, though only as its id.
2571
+ */
2572
+ buildLocalLoadedCell(column, cell, configuration) {
2573
+ const value = cell?.value != null
2574
+ ? cell.value
2575
+ : this.toLocalEntityValue(column.viewType, cell?.rawValue, undefined);
2576
+ return {
2577
+ key: column.key,
2578
+ name: column.label,
2579
+ viewType: (column.viewType ?? 'Text'),
2580
+ value: (value ?? ''),
2581
+ rawValue: serializeEntityRawValue(cell?.rawValue),
2582
+ propertyConfiguration: configuration ?? undefined,
2583
+ };
2584
+ }
1553
2585
  /**
1554
2586
  * Normalize the add/edit dialog close payload. The rich dialog returns
1555
2587
  * `{ values, display }`; a custom add-dialog may still return the raw values
@@ -1893,7 +2925,19 @@ class EntityListField {
1893
2925
  */
1894
2926
  applyMetadata(metadata, levelDataId) {
1895
2927
  this.metadata.set(metadata);
2928
+ // A Local list's rows are the value; the source module is not read.
2929
+ if (this.localMode()) {
2930
+ this.loading.set(false);
2931
+ return;
2932
+ }
1896
2933
  this.columns.set(this.buildColumns(metadata));
2934
+ // A Selected list's rows are the records in its value. Fetching the source
2935
+ // module would list every related record, which is exactly what this mode
2936
+ // is not.
2937
+ if (this.selectionMode()) {
2938
+ this.loading.set(false);
2939
+ return;
2940
+ }
1897
2941
  if (!this.moduleBacked() ||
1898
2942
  !this.canRead() ||
1899
2943
  levelDataId == null ||
@@ -2065,7 +3109,7 @@ class EntityListField {
2065
3109
  };
2066
3110
  }
2067
3111
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, deps: [], target: i0.ɵɵFactoryTarget.Component });
2068
- 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\">\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 (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 });
3112
+ 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\">\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 (selectionReady()) {\n <!--\n A Selected list: the source records picked for this record, and nothing\n else. Picking and removing change only which records it holds.\n -->\n @if (selectionWritable()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.selectRecords' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openSelectionDialog()\"\n />\n </div>\n }\n @if (selectionRows().length) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"selectionRows()\"\n [columns]=\"columns()\"\n [rowActions]=\"selectionRowActions()\"\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.noSelectedRecords\" | 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 });
2069
3113
  }
2070
3114
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, decorators: [{
2071
3115
  type: Component,
@@ -2077,8 +3121,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
2077
3121
  Table,
2078
3122
  Button,
2079
3123
  TranslocoPipe,
2080
- ], 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 (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"] }]
2081
- }], 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 }] }] } });
3124
+ ], 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 (selectionReady()) {\n <!--\n A Selected list: the source records picked for this record, and nothing\n else. Picking and removing change only which records it holds.\n -->\n @if (selectionWritable()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.selectRecords' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openSelectionDialog()\"\n />\n </div>\n }\n @if (selectionRows().length) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"selectionRows()\"\n [columns]=\"columns()\"\n [rowActions]=\"selectionRowActions()\"\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.noSelectedRecords\" | 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"] }]
3125
+ }], 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 }] }] } });
2082
3126
 
2083
3127
  /**
2084
3128
  * Lets `mt-entity-list-preview` render a module-backed `EntityList` as the
@@ -2530,5 +3574,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
2530
3574
  * Generated bundle index. Do not edit.
2531
3575
  */
2532
3576
 
2533
- export { ENTITY_LIST_ADD_DIALOG_COMPONENT, EntityListField, LOOKUP_CHECK_LIST_FORM_COMPONENT, LookupMatrixField, LookupModuleCheckListField, ScheduleItemSelectorField, SchedulePredecessorField, SchemaConnectionField, provideEntityListTablePreview };
3577
+ export { ENTITY_LIST_ADD_DIALOG_COMPONENT, ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT, EntityListField, LOOKUP_CHECK_LIST_FORM_COMPONENT, LookupMatrixField, LookupModuleCheckListField, ScheduleItemSelectorField, SchedulePredecessorField, SchemaConnectionField, provideEntityListTablePreview };
2534
3578
  //# sourceMappingURL=masterteam-components-business-fields.mjs.map