@3kles/kles-material-dynamicforms 19.4.2 → 19.4.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/3kles-kles-material-dynamicforms.mjs +65 -13
- package/fesm2022/3kles-kles-material-dynamicforms.mjs.map +1 -1
- package/lib/factories/field.factory.d.ts +4 -2
- package/lib/ui/ui-state/array-ui-state.d.ts +9 -6
- package/lib/ui/ui-state/control-ui-state.d.ts +4 -4
- package/lib/ui/ui-state/group-ui-state.d.ts +4 -0
- package/lib/ui/ui-state/ui-state.abstract.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { signal, InjectionToken, inject, Component, Injector, Input, Directive, Injectable, EventEmitter, Output, NgModule,
|
|
2
|
+
import { signal, InjectionToken, inject, Component, Injector, Input, Directive, Injectable, computed, EventEmitter, Output, NgModule, ViewContainerRef, HostBinding, Pipe, ChangeDetectorRef, ViewChildren, ViewChild, forwardRef, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { CommonModule } from '@angular/common';
|
|
5
5
|
import * as i2 from '@angular/forms';
|
|
@@ -136,7 +136,7 @@ class AbstractUiState {
|
|
|
136
136
|
if (currPath == null)
|
|
137
137
|
return null;
|
|
138
138
|
if (!Array.isArray(currPath))
|
|
139
|
-
currPath = currPath.split('.');
|
|
139
|
+
currPath = currPath.split('.').filter(Boolean);
|
|
140
140
|
if (currPath.length === 0)
|
|
141
141
|
return null;
|
|
142
142
|
return currPath.reduce((uiState, name) => uiState && uiState._find(name), this);
|
|
@@ -152,13 +152,23 @@ class AbstractUiState {
|
|
|
152
152
|
class ControlUiState extends AbstractUiState {
|
|
153
153
|
constructor(value) {
|
|
154
154
|
super();
|
|
155
|
-
|
|
155
|
+
if (value !== undefined) {
|
|
156
|
+
this._value.set(value);
|
|
157
|
+
}
|
|
156
158
|
}
|
|
157
159
|
setValue(value) {
|
|
158
160
|
this._value.set(value);
|
|
159
161
|
}
|
|
160
162
|
patchValue(value) {
|
|
161
|
-
|
|
163
|
+
if (value == null) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const curr = this._value();
|
|
167
|
+
if (curr == null) {
|
|
168
|
+
this._value.set(value);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this._value.set({ ...curr, ...value });
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -507,12 +517,19 @@ class GroupUiState extends AbstractUiState {
|
|
|
507
517
|
constructor(states) {
|
|
508
518
|
super();
|
|
509
519
|
this.states = {};
|
|
510
|
-
this.
|
|
520
|
+
this._computedValue = computed(() => {
|
|
521
|
+
return this._snapshot();
|
|
522
|
+
});
|
|
523
|
+
this.states = (states ?? {});
|
|
524
|
+
this._value.set(this._snapshot());
|
|
511
525
|
}
|
|
512
526
|
setValue(value) {
|
|
527
|
+
if (value == null)
|
|
528
|
+
return;
|
|
513
529
|
Object.keys(value).forEach((name) => {
|
|
514
530
|
this.states[name]?.setValue(value[name]);
|
|
515
531
|
});
|
|
532
|
+
this._value.set(value);
|
|
516
533
|
}
|
|
517
534
|
patchValue(value) {
|
|
518
535
|
if (value == null)
|
|
@@ -523,12 +540,28 @@ class GroupUiState extends AbstractUiState {
|
|
|
523
540
|
state.patchValue(value[name]);
|
|
524
541
|
}
|
|
525
542
|
});
|
|
543
|
+
const curr = this._value() ?? {};
|
|
544
|
+
this._value.set({ ...curr, ...value });
|
|
526
545
|
}
|
|
527
546
|
_find(name) {
|
|
528
|
-
|
|
547
|
+
const key = String(name);
|
|
548
|
+
const has = Object.prototype.hasOwnProperty.call(this.states, key);
|
|
549
|
+
return has ? this.states[key] : null;
|
|
529
550
|
}
|
|
530
551
|
addUiState(name, uiState) {
|
|
531
552
|
this.states[name] = uiState;
|
|
553
|
+
const curr = this._value() ?? {};
|
|
554
|
+
this._value.set({ ...curr, [name]: uiState.value() });
|
|
555
|
+
}
|
|
556
|
+
get value() {
|
|
557
|
+
return this._computedValue;
|
|
558
|
+
}
|
|
559
|
+
_snapshot() {
|
|
560
|
+
const out = {};
|
|
561
|
+
for (const key of Object.keys(this.states)) {
|
|
562
|
+
out[key] = this.states[key]?.value();
|
|
563
|
+
}
|
|
564
|
+
return out;
|
|
532
565
|
}
|
|
533
566
|
}
|
|
534
567
|
|
|
@@ -4280,27 +4313,45 @@ class ArrayUiState extends AbstractUiState {
|
|
|
4280
4313
|
constructor(states) {
|
|
4281
4314
|
super();
|
|
4282
4315
|
this.states = [];
|
|
4283
|
-
this.
|
|
4316
|
+
this._computedValue = computed(() => {
|
|
4317
|
+
return this.states.map((s) => s.value());
|
|
4318
|
+
});
|
|
4319
|
+
this.states = states ?? [];
|
|
4320
|
+
this._value.set(this.states.map((s) => s.value()));
|
|
4321
|
+
}
|
|
4322
|
+
get value() {
|
|
4323
|
+
return this._computedValue;
|
|
4284
4324
|
}
|
|
4285
4325
|
setValue(value) {
|
|
4326
|
+
if (!Array.isArray(value)) {
|
|
4327
|
+
return;
|
|
4328
|
+
}
|
|
4286
4329
|
value.forEach((newValue, index) => {
|
|
4287
|
-
this.at(index)
|
|
4330
|
+
this.at(index)?.setValue(newValue);
|
|
4288
4331
|
});
|
|
4332
|
+
this._value.set(value);
|
|
4289
4333
|
}
|
|
4290
4334
|
patchValue(value) {
|
|
4291
|
-
if (value == null)
|
|
4335
|
+
if (value == null) {
|
|
4292
4336
|
return;
|
|
4337
|
+
}
|
|
4293
4338
|
value.forEach((newValue, index) => {
|
|
4294
|
-
|
|
4295
|
-
|
|
4339
|
+
const st = this.at(index);
|
|
4340
|
+
if (st) {
|
|
4341
|
+
st.patchValue(newValue);
|
|
4296
4342
|
}
|
|
4297
4343
|
});
|
|
4344
|
+
const curr = this._value() ?? [];
|
|
4345
|
+
const next = [...curr];
|
|
4346
|
+
value.forEach((v, i) => (next[i] = v));
|
|
4347
|
+
this._value.set(next);
|
|
4298
4348
|
}
|
|
4299
4349
|
at(index) {
|
|
4300
|
-
return this.states?.[index];
|
|
4350
|
+
return this.states?.[index] ?? null;
|
|
4301
4351
|
}
|
|
4302
4352
|
_find(name) {
|
|
4303
|
-
|
|
4353
|
+
const idx = typeof name === 'number' ? name : Number(name);
|
|
4354
|
+
return Number.isFinite(idx) ? this.at(idx) : null;
|
|
4304
4355
|
}
|
|
4305
4356
|
push(control) {
|
|
4306
4357
|
if (Array.isArray(control)) {
|
|
@@ -4311,6 +4362,7 @@ class ArrayUiState extends AbstractUiState {
|
|
|
4311
4362
|
else {
|
|
4312
4363
|
this.states.push(control);
|
|
4313
4364
|
}
|
|
4365
|
+
this._value.set(this.states.map((s) => s.value()));
|
|
4314
4366
|
}
|
|
4315
4367
|
}
|
|
4316
4368
|
|