@ng-forge/dynamic-forms 1.3.0-next.2 → 1.3.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/ng-forge-dynamic-forms-active-page-initialized.event-CiKN-mcc.mjs +12 -0
- package/fesm2022/ng-forge-dynamic-forms-active-page-initialized.event-CiKN-mcc.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-array-field.component-Dv9mPnJ3.mjs +770 -0
- package/fesm2022/ng-forge-dynamic-forms-array-field.component-Dv9mPnJ3.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-array-item-registry.service-D-AxVLdk.mjs +83 -0
- package/fesm2022/ng-forge-dynamic-forms-array-item-registry.service-D-AxVLdk.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-derivation-orchestrator-EuYCbquo.mjs +1887 -0
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-derivation-orchestrator-EuYCbquo.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-web-mcp-2wQK_wPp.mjs +954 -0
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-web-mcp-2wQK_wPp.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-container-field-processors-C_JRvaVt.mjs +117 -0
- package/fesm2022/ng-forge-dynamic-forms-container-field-processors-C_JRvaVt.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-container-field.component-Bg7Win9n.mjs +228 -0
- package/fesm2022/ng-forge-dynamic-forms-container-field.component-Bg7Win9n.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-css-wrapper.component-R2yc-H0T.mjs +102 -0
- package/fesm2022/ng-forge-dynamic-forms-css-wrapper.component-R2yc-H0T.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-debounce-CG3uP5B-.mjs +4 -0
- package/fesm2022/{ng-forge-dynamic-forms-debounce-C9F4v1Ke.mjs.map → ng-forge-dynamic-forms-debounce-CG3uP5B-.mjs.map} +1 -1
- package/fesm2022/ng-forge-dynamic-forms-default-value-D5M4MNE-.mjs +77 -0
- package/fesm2022/ng-forge-dynamic-forms-default-value-D5M4MNE-.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-dev-mode-4rbYBBo_.mjs +4 -0
- package/fesm2022/ng-forge-dynamic-forms-dev-mode-4rbYBBo_.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-df-field-outlet.directive-CQsDMV-s.mjs +644 -0
- package/fesm2022/ng-forge-dynamic-forms-df-field-outlet.directive-CQsDMV-s.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-field-errors-wrapper.component-DKgkpIpG.mjs +56 -0
- package/fesm2022/ng-forge-dynamic-forms-field-errors-wrapper.component-DKgkpIpG.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-form-schema.service-Dd-gHJ_7.mjs +38 -0
- package/fesm2022/{ng-forge-dynamic-forms-form-schema.service-Dx5Dlb15.mjs.map → ng-forge-dynamic-forms-form-schema.service-Dd-gHJ_7.mjs.map} +1 -1
- package/fesm2022/ng-forge-dynamic-forms-form-state-manager-DcOXRFRL.mjs +1522 -0
- package/fesm2022/ng-forge-dynamic-forms-form-state-manager-DcOXRFRL.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-group-field.component-BjZi0bhq.mjs +292 -0
- package/fesm2022/ng-forge-dynamic-forms-group-field.component-BjZi0bhq.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-integration.mjs +1318 -843
- package/fesm2022/ng-forge-dynamic-forms-integration.mjs.map +1 -1
- package/fesm2022/ng-forge-dynamic-forms-internal.mjs +3326 -3641
- package/fesm2022/ng-forge-dynamic-forms-internal.mjs.map +1 -1
- package/fesm2022/ng-forge-dynamic-forms-page-field.component-BRjQmWC9.mjs +295 -0
- package/fesm2022/ng-forge-dynamic-forms-page-field.component-BRjQmWC9.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-resolve-field-ByGa5cpo.mjs +329 -0
- package/fesm2022/ng-forge-dynamic-forms-resolve-field-ByGa5cpo.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-row-wrapper.component-CuFycQb-.mjs +81 -0
- package/fesm2022/ng-forge-dynamic-forms-row-wrapper.component-CuFycQb-.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-schema-builder-C62afItJ.mjs +400 -0
- package/fesm2022/ng-forge-dynamic-forms-schema-builder-C62afItJ.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-schema-registry.service-axBV9FBH.mjs +45 -0
- package/fesm2022/ng-forge-dynamic-forms-schema-registry.service-axBV9FBH.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-schema.mjs +8 -14
- package/fesm2022/ng-forge-dynamic-forms-schema.mjs.map +1 -1
- package/fesm2022/ng-forge-dynamic-forms-testing.mjs +68 -73
- package/fesm2022/ng-forge-dynamic-forms-testing.mjs.map +1 -1
- package/fesm2022/ng-forge-dynamic-forms-text-field.component--MAh_h4Q.mjs +257 -0
- package/fesm2022/ng-forge-dynamic-forms-text-field.component--MAh_h4Q.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-validation-execution.token-BFyySKtp.mjs +8 -0
- package/fesm2022/ng-forge-dynamic-forms-validation-execution.token-BFyySKtp.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-with-logger-config-BAATqYY0.mjs +94 -0
- package/fesm2022/ng-forge-dynamic-forms-with-logger-config-BAATqYY0.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms-wrapper-chain-BnntfNU1.mjs +115 -0
- package/fesm2022/ng-forge-dynamic-forms-wrapper-chain-BnntfNU1.mjs.map +1 -0
- package/fesm2022/ng-forge-dynamic-forms.mjs +2136 -3
- package/fesm2022/ng-forge-dynamic-forms.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ng-forge-dynamic-forms-integration.d.ts +543 -415
- package/types/ng-forge-dynamic-forms-internal.d.ts +2319 -2436
- package/types/ng-forge-dynamic-forms-schema.d.ts +13 -16
- package/types/ng-forge-dynamic-forms-testing.d.ts +34 -37
- package/types/ng-forge-dynamic-forms.d.ts +735 -722
- package/fesm2022/ng-forge-dynamic-forms-array-field.component-CSCKq_1K.mjs +0 -750
- package/fesm2022/ng-forge-dynamic-forms-array-field.component-CSCKq_1K.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-derivation-orchestrator-CTOTwzzw.mjs +0 -2394
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-derivation-orchestrator-CTOTwzzw.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-web-mcp-BtjqeJOj.mjs +0 -1054
- package/fesm2022/ng-forge-dynamic-forms-bootstrap-web-mcp-BtjqeJOj.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-container-field.component-Dc3ROhHL.mjs +0 -86
- package/fesm2022/ng-forge-dynamic-forms-container-field.component-Dc3ROhHL.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-css-wrapper.component-BzgX8lAD.mjs +0 -33
- package/fesm2022/ng-forge-dynamic-forms-css-wrapper.component-BzgX8lAD.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-debounce-C9F4v1Ke.mjs +0 -17
- package/fesm2022/ng-forge-dynamic-forms-field-errors-wrapper.component-CIKbWqYA.mjs +0 -25
- package/fesm2022/ng-forge-dynamic-forms-field-errors-wrapper.component-CIKbWqYA.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-form-schema.service-Dx5Dlb15.mjs +0 -24
- package/fesm2022/ng-forge-dynamic-forms-group-field.component-DAC3P9DC.mjs +0 -177
- package/fesm2022/ng-forge-dynamic-forms-group-field.component-DAC3P9DC.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-ng-forge-dynamic-forms-CXQe_5td.mjs +0 -5133
- package/fesm2022/ng-forge-dynamic-forms-ng-forge-dynamic-forms-CXQe_5td.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-page-field.component-DPKJcwUO.mjs +0 -176
- package/fesm2022/ng-forge-dynamic-forms-page-field.component-DPKJcwUO.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-row-wrapper.component-DMEeKZny.mjs +0 -19
- package/fesm2022/ng-forge-dynamic-forms-row-wrapper.component-DMEeKZny.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-schema-builder-BvDTzfdM.mjs +0 -570
- package/fesm2022/ng-forge-dynamic-forms-schema-builder-BvDTzfdM.mjs.map +0 -1
- package/fesm2022/ng-forge-dynamic-forms-text-field.component-BB-jutBq.mjs +0 -126
- package/fesm2022/ng-forge-dynamic-forms-text-field.component-BB-jutBq.mjs.map +0 -1
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
import { a as initializationComponentPath, s as emitComponentInitialized, t as DfFieldOutlet } from "./ng-forge-dynamic-forms-df-field-outlet.directive-CQsDMV-s.mjs";
|
|
2
|
+
import { n as createHiddenSignal, r as createRenderReadySignal, s as mapFieldToInputs, u as injectFieldRegistry } from "./ng-forge-dynamic-forms-resolve-field-ByGa5cpo.mjs";
|
|
3
|
+
import { n as getNormalizedArrayMetadata, t as getFieldDefaultValue } from "./ng-forge-dynamic-forms-default-value-D5M4MNE-.mjs";
|
|
4
|
+
import { t as ArrayItemRegistryService } from "./ng-forge-dynamic-forms-array-item-registry.service-D-AxVLdk.mjs";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, EnvironmentInjector, Injector, computed, inject, input, linkedSignal, runInInjectionContext, signal } from "@angular/core";
|
|
7
|
+
import { explicitEffect } from "ngxtension/explicit-effect";
|
|
8
|
+
import { catchError, filter, firstValueFrom, forkJoin, from, map, of, tap } from "rxjs";
|
|
9
|
+
import { ARRAY_CONTEXT, DynamicFormLogger, EventBus, FIELD_SIGNAL_CONTEXT, GROUP_CONTEXT, getFieldValueHandling, injectFieldSignalContext, isEqual, isGroupField } from "@ng-forge/dynamic-forms/internal";
|
|
10
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
11
|
+
var ArrayFieldStateMachine = class {
|
|
12
|
+
_state = signal("idle", ...ngDevMode ? [{ debugName: "_state" }] : /* istanbul ignore next */ []);
|
|
13
|
+
_runId = signal(0, ...ngDevMode ? [{ debugName: "_runId" }] : /* istanbul ignore next */ []);
|
|
14
|
+
lastEmittedRunId = -1;
|
|
15
|
+
_hasEverEmitted = false;
|
|
16
|
+
state = this._state.asReadonly();
|
|
17
|
+
runId = this._runId.asReadonly();
|
|
18
|
+
get hasEverEmitted() {
|
|
19
|
+
return this._hasEverEmitted;
|
|
20
|
+
}
|
|
21
|
+
dispatch(op) {
|
|
22
|
+
const nextId = this._runId() + 1;
|
|
23
|
+
this._runId.set(nextId);
|
|
24
|
+
switch (op.kind) {
|
|
25
|
+
case "clear":
|
|
26
|
+
case "initial":
|
|
27
|
+
case "recreate": this._state.set("pending");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
id: nextId,
|
|
31
|
+
isStale: () => this._runId() !== nextId,
|
|
32
|
+
resolve: () => {
|
|
33
|
+
if (this._runId() === nextId && this._state() === "pending") this._state.set("settled");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
shouldEmit(allReady) {
|
|
38
|
+
if (this._state() !== "settled" || !allReady) return false;
|
|
39
|
+
if (this.lastEmittedRunId === this._runId()) return false;
|
|
40
|
+
this.lastEmittedRunId = this._runId();
|
|
41
|
+
this._hasEverEmitted = true;
|
|
42
|
+
this._state.set("idle");
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function getArrayValue(value, key) {
|
|
47
|
+
const arrayValue = value?.[key];
|
|
48
|
+
return Array.isArray(arrayValue) ? arrayValue : [];
|
|
49
|
+
}
|
|
50
|
+
function determineDifferentialOperation(currentItems, newLength) {
|
|
51
|
+
const currentLength = currentItems.length;
|
|
52
|
+
if (newLength === 0) return { type: "clear" };
|
|
53
|
+
if (currentLength === 0) return {
|
|
54
|
+
type: "initial",
|
|
55
|
+
fieldTreesLength: newLength
|
|
56
|
+
};
|
|
57
|
+
if (newLength > currentLength) return {
|
|
58
|
+
type: "append",
|
|
59
|
+
startIndex: currentLength,
|
|
60
|
+
endIndex: newLength
|
|
61
|
+
};
|
|
62
|
+
if (newLength < currentLength) return { type: "recreate" };
|
|
63
|
+
return { type: "none" };
|
|
64
|
+
}
|
|
65
|
+
function createArrayItemInjectorAndInputs(options) {
|
|
66
|
+
const { template, indexSignal, parentFieldSignalContext, parentInjector, registry, arrayField, primitiveFieldKey } = options;
|
|
67
|
+
const injector = createItemInjector({
|
|
68
|
+
itemFormAccessor: computed(() => {
|
|
69
|
+
const parentForm = parentFieldSignalContext.form;
|
|
70
|
+
const index = indexSignal();
|
|
71
|
+
const arrayFieldTree = parentForm[arrayField.key];
|
|
72
|
+
if (!arrayFieldTree) return;
|
|
73
|
+
return arrayFieldTree[index];
|
|
74
|
+
}, {
|
|
75
|
+
...ngDevMode ? { debugName: "itemFormAccessor" } : /* istanbul ignore next */ {},
|
|
76
|
+
equal: isEqual
|
|
77
|
+
}),
|
|
78
|
+
indexSignal,
|
|
79
|
+
parentFieldSignalContext,
|
|
80
|
+
parentInjector,
|
|
81
|
+
arrayField,
|
|
82
|
+
primitiveFieldKey
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
injector,
|
|
86
|
+
inputs: runInInjectionContext(injector, () => {
|
|
87
|
+
return mapFieldToInputs(template, registry);
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function createItemInjector(options) {
|
|
92
|
+
const { itemFormAccessor, indexSignal, parentFieldSignalContext, parentInjector, arrayField, primitiveFieldKey } = options;
|
|
93
|
+
const arrayContext = {
|
|
94
|
+
arrayKey: arrayField.key,
|
|
95
|
+
index: indexSignal,
|
|
96
|
+
get formValue() {
|
|
97
|
+
return parentFieldSignalContext.value();
|
|
98
|
+
},
|
|
99
|
+
field: arrayField
|
|
100
|
+
};
|
|
101
|
+
let cachedPrimitiveRaw;
|
|
102
|
+
let cachedPrimitiveWrapped;
|
|
103
|
+
return Injector.create({
|
|
104
|
+
parent: parentInjector,
|
|
105
|
+
providers: [
|
|
106
|
+
{
|
|
107
|
+
provide: FIELD_SIGNAL_CONTEXT,
|
|
108
|
+
useFactory: (injector) => ({
|
|
109
|
+
injector,
|
|
110
|
+
value: parentFieldSignalContext.value,
|
|
111
|
+
defaultValues: () => ({}),
|
|
112
|
+
get form() {
|
|
113
|
+
const raw = itemFormAccessor();
|
|
114
|
+
if (!raw) return {};
|
|
115
|
+
if (primitiveFieldKey) {
|
|
116
|
+
if (raw !== cachedPrimitiveRaw) {
|
|
117
|
+
cachedPrimitiveRaw = raw;
|
|
118
|
+
cachedPrimitiveWrapped = { [primitiveFieldKey]: raw };
|
|
119
|
+
}
|
|
120
|
+
return cachedPrimitiveWrapped;
|
|
121
|
+
}
|
|
122
|
+
return raw;
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
deps: [Injector]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
provide: ARRAY_CONTEXT,
|
|
129
|
+
useValue: arrayContext
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
provide: GROUP_CONTEXT,
|
|
133
|
+
useValue: EMPTY_GROUP_CONTEXT
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const EMPTY_GROUP_CONTEXT = { groupPath: signal("") };
|
|
139
|
+
function resolveArrayItem(options) {
|
|
140
|
+
const { index, templates, arrayField, itemPositionMap, parentFieldSignalContext, parentInjector, registry, destroyRef, loadTypeComponent, generateItemId, existingItemId, primitiveFieldKey } = options;
|
|
141
|
+
if (templates.length === 0) return of(void 0);
|
|
142
|
+
const itemId = existingItemId ?? generateItemId();
|
|
143
|
+
const indexSignal = linkedSignal(() => {
|
|
144
|
+
return itemPositionMap().get(itemId) ?? index;
|
|
145
|
+
}, ...ngDevMode ? [{ debugName: "indexSignal" }] : /* istanbul ignore next */ []);
|
|
146
|
+
const fieldObservables = templates.map((template) => from(loadTypeComponent(template.type)).pipe(map((component) => {
|
|
147
|
+
if (destroyRef.destroyed) return;
|
|
148
|
+
if (!component) return;
|
|
149
|
+
const { injector, inputs } = createArrayItemInjectorAndInputs({
|
|
150
|
+
template,
|
|
151
|
+
indexSignal,
|
|
152
|
+
parentFieldSignalContext,
|
|
153
|
+
parentInjector,
|
|
154
|
+
registry,
|
|
155
|
+
arrayField,
|
|
156
|
+
primitiveFieldKey
|
|
157
|
+
});
|
|
158
|
+
if (!inputs) return;
|
|
159
|
+
return {
|
|
160
|
+
key: template.key,
|
|
161
|
+
fieldDef: template,
|
|
162
|
+
component,
|
|
163
|
+
injector,
|
|
164
|
+
inputs,
|
|
165
|
+
renderReady: createRenderReadySignal(inputs, registry.get(template.type)),
|
|
166
|
+
hidden: createHiddenSignal(inputs)
|
|
167
|
+
};
|
|
168
|
+
}), catchError((error) => {
|
|
169
|
+
if (!destroyRef.destroyed) parentInjector.get(DynamicFormLogger).error(`Failed to load component for field type '${template.type}' at index ${index} within array '${arrayField.key}'. Ensure the field type is registered in your field registry.`, error);
|
|
170
|
+
return of(void 0);
|
|
171
|
+
})));
|
|
172
|
+
return forkJoin(fieldObservables).pipe(map((fields) => {
|
|
173
|
+
const validFields = fields.filter((f) => f !== void 0);
|
|
174
|
+
if (validFields.length === 0) return;
|
|
175
|
+
return {
|
|
176
|
+
id: itemId,
|
|
177
|
+
fields: validFields
|
|
178
|
+
};
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
const ARRAY_EVENT_TYPES = [
|
|
182
|
+
"append-array-item",
|
|
183
|
+
"prepend-array-item",
|
|
184
|
+
"insert-array-item",
|
|
185
|
+
"move-array-item",
|
|
186
|
+
"pop-array-item",
|
|
187
|
+
"shift-array-item",
|
|
188
|
+
"remove-at-index"
|
|
189
|
+
];
|
|
190
|
+
function toArrayAction(event) {
|
|
191
|
+
switch (event.type) {
|
|
192
|
+
case "append-array-item": return {
|
|
193
|
+
action: "add",
|
|
194
|
+
template: event.template
|
|
195
|
+
};
|
|
196
|
+
case "prepend-array-item": return {
|
|
197
|
+
action: "add",
|
|
198
|
+
template: event.template,
|
|
199
|
+
index: 0
|
|
200
|
+
};
|
|
201
|
+
case "insert-array-item": return {
|
|
202
|
+
action: "add",
|
|
203
|
+
template: event.template,
|
|
204
|
+
index: event.index
|
|
205
|
+
};
|
|
206
|
+
case "move-array-item": return {
|
|
207
|
+
action: "move",
|
|
208
|
+
fromIndex: event.fromIndex,
|
|
209
|
+
toIndex: event.toIndex
|
|
210
|
+
};
|
|
211
|
+
case "pop-array-item": return { action: "remove" };
|
|
212
|
+
case "shift-array-item": return {
|
|
213
|
+
action: "remove",
|
|
214
|
+
index: 0
|
|
215
|
+
};
|
|
216
|
+
case "remove-at-index": return {
|
|
217
|
+
action: "remove",
|
|
218
|
+
index: event.index
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function observeArrayActions(eventBus, arrayKey) {
|
|
223
|
+
return eventBus.on(ARRAY_EVENT_TYPES).pipe(filter((event) => event.arrayKey === arrayKey()), map(toArrayAction));
|
|
224
|
+
}
|
|
225
|
+
var ArrayFieldComponent = class ArrayFieldComponent {
|
|
226
|
+
destroyRef = inject(DestroyRef);
|
|
227
|
+
fieldRegistry = injectFieldRegistry();
|
|
228
|
+
parentFieldSignalContext = injectFieldSignalContext();
|
|
229
|
+
parentInjector = inject(Injector);
|
|
230
|
+
environmentInjector = inject(EnvironmentInjector);
|
|
231
|
+
eventBus = inject(EventBus);
|
|
232
|
+
logger = inject(DynamicFormLogger);
|
|
233
|
+
arrayItemRegistry = inject(ArrayItemRegistryService);
|
|
234
|
+
groupContext = inject(GROUP_CONTEXT, { optional: true });
|
|
235
|
+
slot = computed(() => this.arrayItemRegistry.slotFor(this.field().key), ...ngDevMode ? [{ debugName: "slot" }] : /* istanbul ignore next */ []);
|
|
236
|
+
generateItemId = () => this.slot().nextId();
|
|
237
|
+
field = input.required(...ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []);
|
|
238
|
+
key = input.required(...ngDevMode ? [{ debugName: "key" }] : /* istanbul ignore next */ []);
|
|
239
|
+
className = input(...ngDevMode ? [void 0, { debugName: "className" }] : /* istanbul ignore next */ []);
|
|
240
|
+
hidden = input(false, ...ngDevMode ? [{ debugName: "hidden" }] : /* istanbul ignore next */ []);
|
|
241
|
+
hostClasses = computed(() => {
|
|
242
|
+
const base = "df-field df-array";
|
|
243
|
+
const custom = this.className();
|
|
244
|
+
return custom ? `${base} ${custom}` : base;
|
|
245
|
+
}, ...ngDevMode ? [{ debugName: "hostClasses" }] : /* istanbul ignore next */ []);
|
|
246
|
+
rawFieldRegistry = computed(() => this.fieldRegistry.raw, ...ngDevMode ? [{ debugName: "rawFieldRegistry" }] : /* istanbul ignore next */ []);
|
|
247
|
+
autoRemoveButton = computed(() => {
|
|
248
|
+
return getNormalizedArrayMetadata(this.field())?.autoRemoveButton;
|
|
249
|
+
}, ...ngDevMode ? [{ debugName: "autoRemoveButton" }] : /* istanbul ignore next */ []);
|
|
250
|
+
primitiveFieldKey = linkedSignal(() => {
|
|
251
|
+
const metadata = getNormalizedArrayMetadata(this.field());
|
|
252
|
+
if (metadata?.primitiveFieldKey) return metadata.primitiveFieldKey;
|
|
253
|
+
const definitions = this.field().fields || [];
|
|
254
|
+
if (definitions.length > 0 && !Array.isArray(definitions[0])) return definitions[0].key;
|
|
255
|
+
}, ...ngDevMode ? [{ debugName: "primitiveFieldKey" }] : /* istanbul ignore next */ []);
|
|
256
|
+
rawItemTemplates = computed(() => {
|
|
257
|
+
return (this.field().fields || []).map((def) => {
|
|
258
|
+
return Array.isArray(def) ? def : [def];
|
|
259
|
+
});
|
|
260
|
+
}, ...ngDevMode ? [{ debugName: "rawItemTemplates" }] : /* istanbul ignore next */ []);
|
|
261
|
+
fallbackTemplate = computed(() => {
|
|
262
|
+
const raw = getNormalizedArrayMetadata(this.field())?.template;
|
|
263
|
+
if (!raw) return void 0;
|
|
264
|
+
return Array.isArray(raw) ? [...raw] : [raw];
|
|
265
|
+
}, ...ngDevMode ? [{ debugName: "fallbackTemplate" }] : /* istanbul ignore next */ []);
|
|
266
|
+
itemTemplates = computed(() => {
|
|
267
|
+
const raw = this.rawItemTemplates();
|
|
268
|
+
const removeButton = this.autoRemoveButton();
|
|
269
|
+
if (!removeButton) return raw;
|
|
270
|
+
return raw.map((normalized) => {
|
|
271
|
+
return [...normalized, removeButton];
|
|
272
|
+
});
|
|
273
|
+
}, ...ngDevMode ? [{ debugName: "itemTemplates" }] : /* istanbul ignore next */ []);
|
|
274
|
+
arrayFieldTree = computed(() => {
|
|
275
|
+
return this.parentFieldSignalContext.form[this.field().key];
|
|
276
|
+
}, ...ngDevMode ? [{ debugName: "arrayFieldTree" }] : /* istanbul ignore next */ []);
|
|
277
|
+
currentArrayValue = computed(() => {
|
|
278
|
+
const tree = this.arrayFieldTree();
|
|
279
|
+
if (tree) {
|
|
280
|
+
const value = tree().value();
|
|
281
|
+
return Array.isArray(value) ? value : [];
|
|
282
|
+
}
|
|
283
|
+
return getArrayValue(this.parentFieldSignalContext.value(), this.field().key);
|
|
284
|
+
}, ...ngDevMode ? [{ debugName: "currentArrayValue" }] : /* istanbul ignore next */ []);
|
|
285
|
+
arrayFieldTrees = computed(() => {
|
|
286
|
+
const arrayValue = this.currentArrayValue();
|
|
287
|
+
if (arrayValue.length === 0) return [];
|
|
288
|
+
const arrayFieldTree = this.arrayFieldTree();
|
|
289
|
+
if (!arrayFieldTree) return arrayValue.map(() => null);
|
|
290
|
+
const items = [];
|
|
291
|
+
for (let i = 0; i < arrayValue.length; i++) {
|
|
292
|
+
const itemFieldTree = arrayFieldTree[i];
|
|
293
|
+
items.push(itemFieldTree ?? null);
|
|
294
|
+
}
|
|
295
|
+
return items;
|
|
296
|
+
}, ...ngDevMode ? [{ debugName: "arrayFieldTrees" }] : /* istanbul ignore next */ []);
|
|
297
|
+
resolvedItemsSignal = signal([], ...ngDevMode ? [{ debugName: "resolvedItemsSignal" }] : /* istanbul ignore next */ []);
|
|
298
|
+
fsm = new ArrayFieldStateMachine();
|
|
299
|
+
itemPositionMap = computed(() => {
|
|
300
|
+
const items = this.resolvedItemsSignal();
|
|
301
|
+
return new Map(items.map((item, idx) => [item.id, idx]));
|
|
302
|
+
}, ...ngDevMode ? [{ debugName: "itemPositionMap" }] : /* istanbul ignore next */ []);
|
|
303
|
+
resolvedItems = computed(() => this.resolvedItemsSignal(), ...ngDevMode ? [{ debugName: "resolvedItems" }] : /* istanbul ignore next */ []);
|
|
304
|
+
allResolvedFieldsRenderReady = computed(() => this.resolvedItems().every((item) => item.fields.every((field) => field.renderReady())), ...ngDevMode ? [{ debugName: "allResolvedFieldsRenderReady" }] : /* istanbul ignore next */ []);
|
|
305
|
+
atMaxLength = computed(() => {
|
|
306
|
+
const maxLength = this.field().maxLength;
|
|
307
|
+
if (maxLength === void 0) return false;
|
|
308
|
+
return this.currentArrayValue().length >= maxLength;
|
|
309
|
+
}, ...ngDevMode ? [{ debugName: "atMaxLength" }] : /* istanbul ignore next */ []);
|
|
310
|
+
autoRemoveCache = /* @__PURE__ */ new WeakMap();
|
|
311
|
+
constructor() {
|
|
312
|
+
this.setupEffects();
|
|
313
|
+
this.setupEventHandlers();
|
|
314
|
+
}
|
|
315
|
+
setupEffects() {
|
|
316
|
+
explicitEffect([this.arrayFieldTrees], ([fieldTrees]) => {
|
|
317
|
+
this.performDifferentialUpdate(fieldTrees);
|
|
318
|
+
});
|
|
319
|
+
explicitEffect([this.fsm.state, this.allResolvedFieldsRenderReady], ([, allReady]) => {
|
|
320
|
+
if (this.fsm.shouldEmit(allReady)) emitComponentInitialized(this.eventBus, "array", initializationComponentPath(this.field().key, this.groupContext?.groupPath()), this.parentInjector);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
setupEventHandlers() {
|
|
324
|
+
observeArrayActions(this.eventBus, () => this.key()).pipe(takeUntilDestroyed()).subscribe((action) => {
|
|
325
|
+
if (action.action === "add") {
|
|
326
|
+
if ((Array.isArray(action.template) ? action.template : action.template ? [action.template] : []).length === 0) {
|
|
327
|
+
this.logger.error(`Cannot add item to array '${this.key()}': template is REQUIRED. Buttons must specify an explicit template property. There is no default template - each add operation must provide its own.`);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.handleAddFromEvent(action.template, action.index);
|
|
331
|
+
} else if (action.action === "move") this.moveItem(action.fromIndex, action.toIndex);
|
|
332
|
+
else this.removeItem(action.index);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
async handleAddFromEvent(template, index) {
|
|
336
|
+
const templates = Array.isArray(template) ? [...template] : [template];
|
|
337
|
+
const isPrimitiveItem = !Array.isArray(template) && getFieldValueHandling(templates[0].type, this.rawFieldRegistry()) !== "flatten";
|
|
338
|
+
if (isPrimitiveItem && templates[0].key && !this.primitiveFieldKey()) this.primitiveFieldKey.set(templates[0].key);
|
|
339
|
+
if (templates.length === 0) {
|
|
340
|
+
this.logger.error(`Cannot add item to array '${this.field().key}': no field templates provided. Buttons must specify an explicit template property when adding array items.`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const arrayKey = this.field().key;
|
|
344
|
+
const parentForm = this.parentFieldSignalContext.form;
|
|
345
|
+
const currentValue = parentForm().value();
|
|
346
|
+
const currentArray = getArrayValue(currentValue, arrayKey);
|
|
347
|
+
const insertIndex = index !== void 0 ? Math.min(index, currentArray.length) : currentArray.length;
|
|
348
|
+
let value;
|
|
349
|
+
if (isPrimitiveItem) value = getFieldDefaultValue(templates[0], this.rawFieldRegistry());
|
|
350
|
+
else {
|
|
351
|
+
value = {};
|
|
352
|
+
for (const templateField of templates) {
|
|
353
|
+
const rawValue = getFieldDefaultValue(templateField, this.rawFieldRegistry());
|
|
354
|
+
const valueHandling = getFieldValueHandling(templateField.type, this.rawFieldRegistry());
|
|
355
|
+
if (templateField.type === "group" || templateField.type === "row" || templateField.type === "container") {
|
|
356
|
+
if (isGroupField(templateField)) value = {
|
|
357
|
+
...value,
|
|
358
|
+
[templateField.key]: rawValue
|
|
359
|
+
};
|
|
360
|
+
else value = {
|
|
361
|
+
...value,
|
|
362
|
+
...rawValue
|
|
363
|
+
};
|
|
364
|
+
} else if (valueHandling === "include" && templateField.key) value = {
|
|
365
|
+
...value,
|
|
366
|
+
[templateField.key]: rawValue
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const run = this.fsm.dispatch({ kind: "append" });
|
|
371
|
+
const resolveTemplates = this.withAutoRemove(templates);
|
|
372
|
+
const resolvedItem = await firstValueFrom(resolveArrayItem({
|
|
373
|
+
index: insertIndex,
|
|
374
|
+
templates: resolveTemplates,
|
|
375
|
+
arrayField: this.field(),
|
|
376
|
+
itemPositionMap: this.itemPositionMap,
|
|
377
|
+
parentFieldSignalContext: this.parentFieldSignalContext,
|
|
378
|
+
parentInjector: this.parentInjector,
|
|
379
|
+
registry: this.rawFieldRegistry(),
|
|
380
|
+
destroyRef: this.destroyRef,
|
|
381
|
+
loadTypeComponent: (type) => this.fieldRegistry.loadTypeComponent(type),
|
|
382
|
+
generateItemId: this.generateItemId,
|
|
383
|
+
primitiveFieldKey: isPrimitiveItem ? templates[0].key : void 0
|
|
384
|
+
}).pipe(catchError((error) => {
|
|
385
|
+
this.logger.error(`Failed to resolve array item at index ${insertIndex}:`, error);
|
|
386
|
+
return of(void 0);
|
|
387
|
+
})));
|
|
388
|
+
if (run.isStale() || !resolvedItem) return;
|
|
389
|
+
this.slot().templates.set(resolvedItem.id, templates);
|
|
390
|
+
this.slot().itemOrder.splice(insertIndex, 0, resolvedItem.id);
|
|
391
|
+
this.resolvedItemsSignal.update((current) => {
|
|
392
|
+
const newItems = [...current];
|
|
393
|
+
newItems.splice(insertIndex, 0, resolvedItem);
|
|
394
|
+
return newItems;
|
|
395
|
+
});
|
|
396
|
+
const newArray = [...currentArray];
|
|
397
|
+
newArray.splice(insertIndex, 0, value);
|
|
398
|
+
parentForm().value.set({
|
|
399
|
+
...currentValue,
|
|
400
|
+
[arrayKey]: newArray
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
performDifferentialUpdate(fieldTrees) {
|
|
404
|
+
const resolvedItems = this.resolvedItemsSignal();
|
|
405
|
+
const operation = determineDifferentialOperation(resolvedItems, fieldTrees.length);
|
|
406
|
+
if (operation.type === "none") return;
|
|
407
|
+
switch (operation.type) {
|
|
408
|
+
case "clear": {
|
|
409
|
+
this.slot().templates.clear();
|
|
410
|
+
this.resolvedItemsSignal.set([]);
|
|
411
|
+
const run = this.fsm.dispatch({ kind: "clear" });
|
|
412
|
+
if (resolvedItems.length === 0 && !this.fsm.hasEverEmitted) run.resolve();
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case "initial": {
|
|
416
|
+
const slot = this.slot();
|
|
417
|
+
const useSurvival = slot.itemOrder.length === fieldTrees.length && fieldTrees.length > 0;
|
|
418
|
+
const positionalTemplates = useSurvival ? slot.itemOrder.map((id) => slot.templates.get(id)) : void 0;
|
|
419
|
+
const existingItemIds = useSurvival ? slot.itemOrder.slice() : void 0;
|
|
420
|
+
const run = this.fsm.dispatch({ kind: "initial" });
|
|
421
|
+
this.resolveAllItems(fieldTrees, run, positionalTemplates, existingItemIds);
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
case "append": {
|
|
425
|
+
const run = this.fsm.dispatch({ kind: "append" });
|
|
426
|
+
this.appendItems(fieldTrees, operation.startIndex, operation.endIndex, run);
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
case "recreate": {
|
|
430
|
+
const positionalTemplates = resolvedItems.map((item) => {
|
|
431
|
+
return this.slot().templates.get(item.id);
|
|
432
|
+
});
|
|
433
|
+
this.resolvedItemsSignal.set([]);
|
|
434
|
+
const run = this.fsm.dispatch({ kind: "recreate" });
|
|
435
|
+
this.resolveAllItems(fieldTrees, run, positionalTemplates);
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
async resolveAllItems(fieldTrees, run, positionalTemplates, existingItemIds) {
|
|
441
|
+
if (fieldTrees.length === 0) {
|
|
442
|
+
this.resolvedItemsSignal.set([]);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const safeItemObservables = fieldTrees.map((_, i) => this.createResolveItemObservable(i, positionalTemplates?.[i], existingItemIds?.[i]).pipe(catchError((error) => {
|
|
446
|
+
this.logger.error(`Failed to resolve array item at index ${i}:`, error);
|
|
447
|
+
return of(void 0);
|
|
448
|
+
})));
|
|
449
|
+
try {
|
|
450
|
+
const items = await firstValueFrom(forkJoin(safeItemObservables).pipe(map((items) => items.filter((item) => item !== void 0))));
|
|
451
|
+
if (!run.isStale()) {
|
|
452
|
+
if (positionalTemplates) {
|
|
453
|
+
const newItemIds = new Set(items.map((item) => item.id));
|
|
454
|
+
for (const existingId of this.slot().templates.keys()) if (!newItemIds.has(existingId)) this.slot().templates.delete(existingId);
|
|
455
|
+
items.forEach((item, idx) => {
|
|
456
|
+
const template = positionalTemplates[idx];
|
|
457
|
+
if (template) this.slot().templates.set(item.id, template);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const slot = this.slot();
|
|
461
|
+
slot.itemOrder.length = 0;
|
|
462
|
+
for (const item of items) slot.itemOrder.push(item.id);
|
|
463
|
+
this.resolvedItemsSignal.set(items);
|
|
464
|
+
run.resolve();
|
|
465
|
+
}
|
|
466
|
+
} catch (err) {
|
|
467
|
+
this.logger.error("Failed to resolve array items:", err);
|
|
468
|
+
this.resolvedItemsSignal.set([]);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async appendItems(fieldTrees, startIndex, endIndex, run) {
|
|
472
|
+
const itemsToResolve = fieldTrees.slice(startIndex, endIndex);
|
|
473
|
+
if (itemsToResolve.length === 0) return;
|
|
474
|
+
const safeItemObservables = itemsToResolve.map((_, i) => {
|
|
475
|
+
const index = startIndex + i;
|
|
476
|
+
return this.createResolveItemObservable(index).pipe(catchError((error) => {
|
|
477
|
+
this.logger.error(`Failed to resolve array item at index ${index}:`, error);
|
|
478
|
+
return of(void 0);
|
|
479
|
+
}));
|
|
480
|
+
});
|
|
481
|
+
try {
|
|
482
|
+
const newItems = await firstValueFrom(forkJoin(safeItemObservables).pipe(map((items) => items.filter((item) => item !== void 0))));
|
|
483
|
+
if (!run.isStale()) {
|
|
484
|
+
const slot = this.slot();
|
|
485
|
+
for (const item of newItems) slot.itemOrder.push(item.id);
|
|
486
|
+
this.resolvedItemsSignal.update((current) => [...current, ...newItems]);
|
|
487
|
+
}
|
|
488
|
+
} catch (err) {
|
|
489
|
+
this.logger.error("Failed to append array items:", err);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
createResolveItemObservable(index, overrideTemplate, existingItemId) {
|
|
493
|
+
const itemTemplates = this.itemTemplates();
|
|
494
|
+
const primitiveKey = this.primitiveFieldKey();
|
|
495
|
+
if (overrideTemplate && overrideTemplate.length > 0) return resolveArrayItem({
|
|
496
|
+
index,
|
|
497
|
+
templates: this.withAutoRemove(overrideTemplate),
|
|
498
|
+
arrayField: this.field(),
|
|
499
|
+
itemPositionMap: this.itemPositionMap,
|
|
500
|
+
parentFieldSignalContext: this.parentFieldSignalContext,
|
|
501
|
+
parentInjector: this.parentInjector,
|
|
502
|
+
registry: this.rawFieldRegistry(),
|
|
503
|
+
destroyRef: this.destroyRef,
|
|
504
|
+
loadTypeComponent: (type) => this.fieldRegistry.loadTypeComponent(type),
|
|
505
|
+
generateItemId: this.generateItemId,
|
|
506
|
+
existingItemId,
|
|
507
|
+
primitiveFieldKey: primitiveKey
|
|
508
|
+
});
|
|
509
|
+
const templates = itemTemplates[index];
|
|
510
|
+
if (templates && templates.length > 0) return resolveArrayItem({
|
|
511
|
+
index,
|
|
512
|
+
templates,
|
|
513
|
+
arrayField: this.field(),
|
|
514
|
+
itemPositionMap: this.itemPositionMap,
|
|
515
|
+
parentFieldSignalContext: this.parentFieldSignalContext,
|
|
516
|
+
parentInjector: this.parentInjector,
|
|
517
|
+
registry: this.rawFieldRegistry(),
|
|
518
|
+
destroyRef: this.destroyRef,
|
|
519
|
+
loadTypeComponent: (type) => this.fieldRegistry.loadTypeComponent(type),
|
|
520
|
+
generateItemId: this.generateItemId,
|
|
521
|
+
existingItemId,
|
|
522
|
+
primitiveFieldKey: primitiveKey
|
|
523
|
+
});
|
|
524
|
+
const fallback = this.fallbackTemplate();
|
|
525
|
+
if (fallback && fallback.length > 0) return resolveArrayItem({
|
|
526
|
+
index,
|
|
527
|
+
templates: this.withAutoRemove(fallback),
|
|
528
|
+
arrayField: this.field(),
|
|
529
|
+
itemPositionMap: this.itemPositionMap,
|
|
530
|
+
parentFieldSignalContext: this.parentFieldSignalContext,
|
|
531
|
+
parentInjector: this.parentInjector,
|
|
532
|
+
registry: this.rawFieldRegistry(),
|
|
533
|
+
destroyRef: this.destroyRef,
|
|
534
|
+
loadTypeComponent: (type) => this.fieldRegistry.loadTypeComponent(type),
|
|
535
|
+
generateItemId: this.generateItemId,
|
|
536
|
+
existingItemId,
|
|
537
|
+
primitiveFieldKey: primitiveKey
|
|
538
|
+
}).pipe(tap((item) => {
|
|
539
|
+
if (item) this.slot().templates.set(item.id, fallback);
|
|
540
|
+
}));
|
|
541
|
+
this.logger.warn(`No template found for array item at index ${index}. This likely occured for a Full-API array element that was created from the DynamicForm's value being set directly, which is currently not supported. Consider using the simplified array API.`);
|
|
542
|
+
return of(void 0);
|
|
543
|
+
}
|
|
544
|
+
withAutoRemove(templates) {
|
|
545
|
+
const removeButton = this.autoRemoveButton();
|
|
546
|
+
if (!removeButton) return templates;
|
|
547
|
+
let cached = this.autoRemoveCache.get(templates);
|
|
548
|
+
if (cached) return cached;
|
|
549
|
+
cached = [...templates, removeButton];
|
|
550
|
+
this.autoRemoveCache.set(templates, cached);
|
|
551
|
+
return cached;
|
|
552
|
+
}
|
|
553
|
+
moveItem(fromIndex, toIndex) {
|
|
554
|
+
const arrayKey = this.field().key;
|
|
555
|
+
const parentForm = this.parentFieldSignalContext.form;
|
|
556
|
+
const currentValue = parentForm().value();
|
|
557
|
+
const currentArray = getArrayValue(currentValue, arrayKey);
|
|
558
|
+
const length = currentArray.length;
|
|
559
|
+
if (fromIndex < 0 || fromIndex >= length) {
|
|
560
|
+
this.logger.warn(`moveArrayItem fromIndex ${fromIndex} is out of bounds for array '${arrayKey}' with length ${length}. Operation skipped.`);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (toIndex < 0 || toIndex >= length) {
|
|
564
|
+
this.logger.warn(`moveArrayItem toIndex ${toIndex} is out of bounds for array '${arrayKey}' with length ${length}. Operation skipped.`);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (fromIndex === toIndex) return;
|
|
568
|
+
const rawTemplates = this.rawItemTemplates();
|
|
569
|
+
const currentItems = this.resolvedItemsSignal();
|
|
570
|
+
const lo = Math.min(fromIndex, toIndex);
|
|
571
|
+
const hi = Math.max(fromIndex, toIndex);
|
|
572
|
+
for (let i = lo; i <= hi; i++) {
|
|
573
|
+
const item = currentItems[i];
|
|
574
|
+
if (item && !this.slot().templates.has(item.id) && i < rawTemplates.length) this.slot().templates.set(item.id, rawTemplates[i]);
|
|
575
|
+
}
|
|
576
|
+
this.resolvedItemsSignal.update((current) => {
|
|
577
|
+
const newItems = [...current];
|
|
578
|
+
const [moved] = newItems.splice(fromIndex, 1);
|
|
579
|
+
newItems.splice(toIndex, 0, moved);
|
|
580
|
+
return newItems;
|
|
581
|
+
});
|
|
582
|
+
this.slot().moveItem(fromIndex, toIndex);
|
|
583
|
+
const newArray = [...currentArray];
|
|
584
|
+
const [movedValue] = newArray.splice(fromIndex, 1);
|
|
585
|
+
newArray.splice(toIndex, 0, movedValue);
|
|
586
|
+
parentForm().value.set({
|
|
587
|
+
...currentValue,
|
|
588
|
+
[arrayKey]: newArray
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
removeItem(index) {
|
|
592
|
+
const arrayKey = this.field().key;
|
|
593
|
+
const parentForm = this.parentFieldSignalContext.form;
|
|
594
|
+
const currentValue = parentForm().value();
|
|
595
|
+
const currentArray = getArrayValue(currentValue, arrayKey);
|
|
596
|
+
if (currentArray.length === 0) return;
|
|
597
|
+
let removeIndex;
|
|
598
|
+
if (index === void 0 || index === -1) removeIndex = currentArray.length - 1;
|
|
599
|
+
else if (index < -1 || index >= currentArray.length) {
|
|
600
|
+
this.logger.warn(`removeArrayItem index ${index} is out of bounds for array '${arrayKey}' with length ${currentArray.length}. Operation skipped.`);
|
|
601
|
+
return;
|
|
602
|
+
} else removeIndex = index;
|
|
603
|
+
const removedItem = this.resolvedItemsSignal()[removeIndex];
|
|
604
|
+
if (removedItem) this.slot().templates.delete(removedItem.id);
|
|
605
|
+
this.slot().removeAt(removeIndex);
|
|
606
|
+
this.resolvedItemsSignal.update((current) => {
|
|
607
|
+
const newItems = [...current];
|
|
608
|
+
newItems.splice(removeIndex, 1);
|
|
609
|
+
return newItems;
|
|
610
|
+
});
|
|
611
|
+
const newArray = [...currentArray];
|
|
612
|
+
newArray.splice(removeIndex, 1);
|
|
613
|
+
parentForm().value.set({
|
|
614
|
+
...currentValue,
|
|
615
|
+
[arrayKey]: newArray
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
619
|
+
minVersion: "12.0.0",
|
|
620
|
+
version: "22.2.5",
|
|
621
|
+
ngImport: i0,
|
|
622
|
+
type: ArrayFieldComponent,
|
|
623
|
+
deps: [],
|
|
624
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
625
|
+
});
|
|
626
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
627
|
+
minVersion: "17.0.0",
|
|
628
|
+
version: "22.2.5",
|
|
629
|
+
type: ArrayFieldComponent,
|
|
630
|
+
isStandalone: true,
|
|
631
|
+
selector: "array-field",
|
|
632
|
+
inputs: {
|
|
633
|
+
field: {
|
|
634
|
+
classPropertyName: "field",
|
|
635
|
+
publicName: "field",
|
|
636
|
+
isSignal: true,
|
|
637
|
+
isRequired: true,
|
|
638
|
+
transformFunction: null
|
|
639
|
+
},
|
|
640
|
+
key: {
|
|
641
|
+
classPropertyName: "key",
|
|
642
|
+
publicName: "key",
|
|
643
|
+
isSignal: true,
|
|
644
|
+
isRequired: true,
|
|
645
|
+
transformFunction: null
|
|
646
|
+
},
|
|
647
|
+
className: {
|
|
648
|
+
classPropertyName: "className",
|
|
649
|
+
publicName: "className",
|
|
650
|
+
isSignal: true,
|
|
651
|
+
isRequired: false,
|
|
652
|
+
transformFunction: null
|
|
653
|
+
},
|
|
654
|
+
hidden: {
|
|
655
|
+
classPropertyName: "hidden",
|
|
656
|
+
publicName: "hidden",
|
|
657
|
+
isSignal: true,
|
|
658
|
+
isRequired: false,
|
|
659
|
+
transformFunction: null
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
host: { properties: {
|
|
663
|
+
"class": "hostClasses()",
|
|
664
|
+
"class.df-container-hidden": "hidden()",
|
|
665
|
+
"attr.aria-hidden": "hidden() || null",
|
|
666
|
+
"id": "`${key()}`",
|
|
667
|
+
"attr.data-testid": "key()"
|
|
668
|
+
} },
|
|
669
|
+
ngImport: i0,
|
|
670
|
+
template: `
|
|
671
|
+
@for (item of resolvedItems(); track item.id; let i = $index) {
|
|
672
|
+
<div
|
|
673
|
+
class="df-array-item"
|
|
674
|
+
role="group"
|
|
675
|
+
[attr.aria-label]="'Item ' + (i + 1)"
|
|
676
|
+
[attr.data-array-item-id]="item.id"
|
|
677
|
+
[attr.data-array-item-index]="i"
|
|
678
|
+
>
|
|
679
|
+
@for (field of item.fields; track $index) {
|
|
680
|
+
<ng-container *dfFieldOutlet="field; environmentInjector: environmentInjector" />
|
|
681
|
+
}
|
|
682
|
+
</div>
|
|
683
|
+
}
|
|
684
|
+
`,
|
|
685
|
+
isInline: true,
|
|
686
|
+
styles: [".df-form{display:grid;grid-template-columns:1fr;gap:var(--df-grid-row-gap, .5rem);width:100%}.df-form>*{grid-column:1/-1}.df-row{display:grid;grid-template-columns:repeat(var(--df-grid-columns, 12),1fr);gap:var(--df-grid-gap, .5rem);align-items:start;width:100%}.df-row>*:not([class*=df-col-]){grid-column:1/-1}.df-col-1{grid-column:span 1}.df-col-2{grid-column:span 2}.df-col-3{grid-column:span 3}.df-col-4{grid-column:span 4}.df-col-5{grid-column:span 5}.df-col-6{grid-column:span 6}.df-col-7{grid-column:span 7}.df-col-8{grid-column:span 8}.df-col-9{grid-column:span 9}.df-col-10{grid-column:span 10}.df-col-11{grid-column:span 11}.df-col-12{grid-column:span 12}.df-col-auto{grid-column:span auto;width:auto}.df-col-full{grid-column:1/-1}.df-col-start-1{grid-column-start:1}.df-col-start-2{grid-column-start:2}.df-col-start-3{grid-column-start:3}.df-col-start-4{grid-column-start:4}.df-col-start-5{grid-column-start:5}.df-col-start-6{grid-column-start:6}.df-col-start-7{grid-column-start:7}.df-col-start-8{grid-column-start:8}.df-col-start-9{grid-column-start:9}.df-col-start-10{grid-column-start:10}.df-col-start-11{grid-column-start:11}.df-col-start-12{grid-column-start:12}.df-col-end-1{grid-column-end:1}.df-col-end-2{grid-column-end:2}.df-col-end-3{grid-column-end:3}.df-col-end-4{grid-column-end:4}.df-col-end-5{grid-column-end:5}.df-col-end-6{grid-column-end:6}.df-col-end-7{grid-column-end:7}.df-col-end-8{grid-column-end:8}.df-col-end-9{grid-column-end:9}.df-col-end-10{grid-column-end:10}.df-col-end-11{grid-column-end:11}.df-col-end-12{grid-column-end:12}.df-col-end-13{grid-column-end:13}@media(max-width:576px){.df-form{--df-grid-gap: var(--df-grid-gap-sm, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-sm, .5rem)}.df-row{grid-template-columns:1fr}.df-row>*{grid-column:1/-1!important}.df-row.df-row-mobile-keep-cols{grid-template-columns:repeat(var(--df-grid-columns, 12),1fr)}.df-row.df-row-mobile-keep-cols>*{grid-column:revert!important}}@media(min-width:577px)and (max-width:768px){.df-form{--df-grid-gap: var(--df-grid-gap-md, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-md, .5rem)}.df-row{--df-grid-columns: 6}.df-col-sm-1{grid-column:span 1}.df-col-sm-2{grid-column:span 2}.df-col-sm-3{grid-column:span 3}.df-col-sm-4{grid-column:span 4}.df-col-sm-5{grid-column:span 5}.df-col-sm-6{grid-column:span 6}.df-col-sm-full{grid-column:1/-1}}@media(min-width:769px)and (max-width:992px){.df-form{--df-grid-gap: var(--df-grid-gap-lg, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-lg, .5rem)}.df-col-md-1{grid-column:span 1}.df-col-md-2{grid-column:span 2}.df-col-md-3{grid-column:span 3}.df-col-md-4{grid-column:span 4}.df-col-md-5{grid-column:span 5}.df-col-md-6{grid-column:span 6}.df-col-md-7{grid-column:span 7}.df-col-md-8{grid-column:span 8}.df-col-md-9{grid-column:span 9}.df-col-md-10{grid-column:span 10}.df-col-md-11{grid-column:span 11}.df-col-md-12{grid-column:span 12}.df-col-md-full{grid-column:1/-1}}@media(min-width:993px){.df-form{--df-grid-gap: var(--df-grid-gap-xl, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-xl, .5rem)}.df-col-lg-1{grid-column:span 1}.df-col-lg-2{grid-column:span 2}.df-col-lg-3{grid-column:span 3}.df-col-lg-4{grid-column:span 4}.df-col-lg-5{grid-column:span 5}.df-col-lg-6{grid-column:span 6}.df-col-lg-7{grid-column:span 7}.df-col-lg-8{grid-column:span 8}.df-col-lg-9{grid-column:span 9}.df-col-lg-10{grid-column:span 10}.df-col-lg-11{grid-column:span 11}.df-col-lg-12{grid-column:span 12}.df-col-lg-full{grid-column:1/-1}}.df-gap-none{--df-grid-gap: 0}.df-gap-xs{--df-grid-gap: .25rem}.df-gap-sm{--df-grid-gap: .5rem}.df-gap-md{--df-grid-gap: 1rem}.df-gap-lg{--df-grid-gap: 1.5rem}.df-gap-xl{--df-grid-gap: 2rem}.df-row-gap-none{--df-grid-row-gap: 0}.df-row-gap-xs{--df-grid-row-gap: .25rem}.df-row-gap-sm{--df-grid-row-gap: .5rem}.df-row-gap-md{--df-grid-row-gap: 1rem}.df-row-gap-lg{--df-grid-row-gap: 1.5rem}.df-row-gap-xl{--df-grid-row-gap: 2rem}.df-field{display:block;width:100%;min-width:0;overflow:hidden;margin:0}.df-group,.df-page{display:block;width:100%}.df-form.disabled,.df-row.disabled,.df-field.disabled{opacity:.6;pointer-events:none}.df-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.df-sr-only-focusable:focus,.df-sr-only-focusable:active{position:static;width:auto;height:auto;padding:inherit;margin:inherit;overflow:visible;clip:auto;white-space:normal}.df-live-region{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.df-form :focus-visible{outline:2px solid var(--df-focus-color, #005fcc);outline-offset:2px}.df-group:focus-within{outline:1px dashed var(--df-focus-color, #005fcc);outline-offset:4px}:host{display:grid;grid-template-columns:1fr;gap:var(--df-array-item-gap, var(--df-grid-row-gap, .5rem));width:100%}:host>*{grid-column:1/-1}:host.df-container-hidden{display:none}.df-array-item{display:grid;grid-template-columns:1fr;gap:var(--df-grid-row-gap, .5rem);width:100%}.df-array-item>*{grid-column:1/-1}\n"],
|
|
687
|
+
dependencies: [{
|
|
688
|
+
kind: "directive",
|
|
689
|
+
type: DfFieldOutlet,
|
|
690
|
+
selector: "[dfFieldOutlet]",
|
|
691
|
+
inputs: ["dfFieldOutlet", "dfFieldOutletEnvironmentInjector"]
|
|
692
|
+
}],
|
|
693
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
697
|
+
minVersion: "12.0.0",
|
|
698
|
+
version: "22.2.5",
|
|
699
|
+
ngImport: i0,
|
|
700
|
+
type: ArrayFieldComponent,
|
|
701
|
+
decorators: [{
|
|
702
|
+
type: Component,
|
|
703
|
+
args: [{
|
|
704
|
+
selector: "array-field",
|
|
705
|
+
imports: [DfFieldOutlet],
|
|
706
|
+
template: `
|
|
707
|
+
@for (item of resolvedItems(); track item.id; let i = $index) {
|
|
708
|
+
<div
|
|
709
|
+
class="df-array-item"
|
|
710
|
+
role="group"
|
|
711
|
+
[attr.aria-label]="'Item ' + (i + 1)"
|
|
712
|
+
[attr.data-array-item-id]="item.id"
|
|
713
|
+
[attr.data-array-item-index]="i"
|
|
714
|
+
>
|
|
715
|
+
@for (field of item.fields; track $index) {
|
|
716
|
+
<ng-container *dfFieldOutlet="field; environmentInjector: environmentInjector" />
|
|
717
|
+
}
|
|
718
|
+
</div>
|
|
719
|
+
}
|
|
720
|
+
`,
|
|
721
|
+
host: {
|
|
722
|
+
"[class]": "hostClasses()",
|
|
723
|
+
"[class.df-container-hidden]": "hidden()",
|
|
724
|
+
"[attr.aria-hidden]": "hidden() || null",
|
|
725
|
+
"[id]": "`${key()}`",
|
|
726
|
+
"[attr.data-testid]": "key()"
|
|
727
|
+
},
|
|
728
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
729
|
+
styles: [".df-form{display:grid;grid-template-columns:1fr;gap:var(--df-grid-row-gap, .5rem);width:100%}.df-form>*{grid-column:1/-1}.df-row{display:grid;grid-template-columns:repeat(var(--df-grid-columns, 12),1fr);gap:var(--df-grid-gap, .5rem);align-items:start;width:100%}.df-row>*:not([class*=df-col-]){grid-column:1/-1}.df-col-1{grid-column:span 1}.df-col-2{grid-column:span 2}.df-col-3{grid-column:span 3}.df-col-4{grid-column:span 4}.df-col-5{grid-column:span 5}.df-col-6{grid-column:span 6}.df-col-7{grid-column:span 7}.df-col-8{grid-column:span 8}.df-col-9{grid-column:span 9}.df-col-10{grid-column:span 10}.df-col-11{grid-column:span 11}.df-col-12{grid-column:span 12}.df-col-auto{grid-column:span auto;width:auto}.df-col-full{grid-column:1/-1}.df-col-start-1{grid-column-start:1}.df-col-start-2{grid-column-start:2}.df-col-start-3{grid-column-start:3}.df-col-start-4{grid-column-start:4}.df-col-start-5{grid-column-start:5}.df-col-start-6{grid-column-start:6}.df-col-start-7{grid-column-start:7}.df-col-start-8{grid-column-start:8}.df-col-start-9{grid-column-start:9}.df-col-start-10{grid-column-start:10}.df-col-start-11{grid-column-start:11}.df-col-start-12{grid-column-start:12}.df-col-end-1{grid-column-end:1}.df-col-end-2{grid-column-end:2}.df-col-end-3{grid-column-end:3}.df-col-end-4{grid-column-end:4}.df-col-end-5{grid-column-end:5}.df-col-end-6{grid-column-end:6}.df-col-end-7{grid-column-end:7}.df-col-end-8{grid-column-end:8}.df-col-end-9{grid-column-end:9}.df-col-end-10{grid-column-end:10}.df-col-end-11{grid-column-end:11}.df-col-end-12{grid-column-end:12}.df-col-end-13{grid-column-end:13}@media(max-width:576px){.df-form{--df-grid-gap: var(--df-grid-gap-sm, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-sm, .5rem)}.df-row{grid-template-columns:1fr}.df-row>*{grid-column:1/-1!important}.df-row.df-row-mobile-keep-cols{grid-template-columns:repeat(var(--df-grid-columns, 12),1fr)}.df-row.df-row-mobile-keep-cols>*{grid-column:revert!important}}@media(min-width:577px)and (max-width:768px){.df-form{--df-grid-gap: var(--df-grid-gap-md, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-md, .5rem)}.df-row{--df-grid-columns: 6}.df-col-sm-1{grid-column:span 1}.df-col-sm-2{grid-column:span 2}.df-col-sm-3{grid-column:span 3}.df-col-sm-4{grid-column:span 4}.df-col-sm-5{grid-column:span 5}.df-col-sm-6{grid-column:span 6}.df-col-sm-full{grid-column:1/-1}}@media(min-width:769px)and (max-width:992px){.df-form{--df-grid-gap: var(--df-grid-gap-lg, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-lg, .5rem)}.df-col-md-1{grid-column:span 1}.df-col-md-2{grid-column:span 2}.df-col-md-3{grid-column:span 3}.df-col-md-4{grid-column:span 4}.df-col-md-5{grid-column:span 5}.df-col-md-6{grid-column:span 6}.df-col-md-7{grid-column:span 7}.df-col-md-8{grid-column:span 8}.df-col-md-9{grid-column:span 9}.df-col-md-10{grid-column:span 10}.df-col-md-11{grid-column:span 11}.df-col-md-12{grid-column:span 12}.df-col-md-full{grid-column:1/-1}}@media(min-width:993px){.df-form{--df-grid-gap: var(--df-grid-gap-xl, .5rem);--df-grid-row-gap: var(--df-grid-row-gap-xl, .5rem)}.df-col-lg-1{grid-column:span 1}.df-col-lg-2{grid-column:span 2}.df-col-lg-3{grid-column:span 3}.df-col-lg-4{grid-column:span 4}.df-col-lg-5{grid-column:span 5}.df-col-lg-6{grid-column:span 6}.df-col-lg-7{grid-column:span 7}.df-col-lg-8{grid-column:span 8}.df-col-lg-9{grid-column:span 9}.df-col-lg-10{grid-column:span 10}.df-col-lg-11{grid-column:span 11}.df-col-lg-12{grid-column:span 12}.df-col-lg-full{grid-column:1/-1}}.df-gap-none{--df-grid-gap: 0}.df-gap-xs{--df-grid-gap: .25rem}.df-gap-sm{--df-grid-gap: .5rem}.df-gap-md{--df-grid-gap: 1rem}.df-gap-lg{--df-grid-gap: 1.5rem}.df-gap-xl{--df-grid-gap: 2rem}.df-row-gap-none{--df-grid-row-gap: 0}.df-row-gap-xs{--df-grid-row-gap: .25rem}.df-row-gap-sm{--df-grid-row-gap: .5rem}.df-row-gap-md{--df-grid-row-gap: 1rem}.df-row-gap-lg{--df-grid-row-gap: 1.5rem}.df-row-gap-xl{--df-grid-row-gap: 2rem}.df-field{display:block;width:100%;min-width:0;overflow:hidden;margin:0}.df-group,.df-page{display:block;width:100%}.df-form.disabled,.df-row.disabled,.df-field.disabled{opacity:.6;pointer-events:none}.df-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.df-sr-only-focusable:focus,.df-sr-only-focusable:active{position:static;width:auto;height:auto;padding:inherit;margin:inherit;overflow:visible;clip:auto;white-space:normal}.df-live-region{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.df-form :focus-visible{outline:2px solid var(--df-focus-color, #005fcc);outline-offset:2px}.df-group:focus-within{outline:1px dashed var(--df-focus-color, #005fcc);outline-offset:4px}:host{display:grid;grid-template-columns:1fr;gap:var(--df-array-item-gap, var(--df-grid-row-gap, .5rem));width:100%}:host>*{grid-column:1/-1}:host.df-container-hidden{display:none}.df-array-item{display:grid;grid-template-columns:1fr;gap:var(--df-grid-row-gap, .5rem);width:100%}.df-array-item>*{grid-column:1/-1}\n"]
|
|
730
|
+
}]
|
|
731
|
+
}],
|
|
732
|
+
ctorParameters: () => [],
|
|
733
|
+
propDecorators: {
|
|
734
|
+
field: [{
|
|
735
|
+
type: i0.Input,
|
|
736
|
+
args: [{
|
|
737
|
+
isSignal: true,
|
|
738
|
+
alias: "field",
|
|
739
|
+
required: true
|
|
740
|
+
}]
|
|
741
|
+
}],
|
|
742
|
+
key: [{
|
|
743
|
+
type: i0.Input,
|
|
744
|
+
args: [{
|
|
745
|
+
isSignal: true,
|
|
746
|
+
alias: "key",
|
|
747
|
+
required: true
|
|
748
|
+
}]
|
|
749
|
+
}],
|
|
750
|
+
className: [{
|
|
751
|
+
type: i0.Input,
|
|
752
|
+
args: [{
|
|
753
|
+
isSignal: true,
|
|
754
|
+
alias: "className",
|
|
755
|
+
required: false
|
|
756
|
+
}]
|
|
757
|
+
}],
|
|
758
|
+
hidden: [{
|
|
759
|
+
type: i0.Input,
|
|
760
|
+
args: [{
|
|
761
|
+
isSignal: true,
|
|
762
|
+
alias: "hidden",
|
|
763
|
+
required: false
|
|
764
|
+
}]
|
|
765
|
+
}]
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
export { ArrayFieldComponent, ArrayFieldComponent as default };
|
|
769
|
+
|
|
770
|
+
//# sourceMappingURL=ng-forge-dynamic-forms-array-field.component-Dv9mPnJ3.mjs.map
|