@dsivd/prestations-ng 19.2.0-beta.18 → 19.2.0-beta.19
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/CHANGELOG.md
CHANGED
|
@@ -203,6 +203,21 @@ Please check the [UPGRADING_V19.md](UPGRADING_V19.md) guide for more information
|
|
|
203
203
|
- `foehn-input-address`: the deferred clean-up of the model (hidden address lines and post office box) applies
|
|
204
204
|
to the latest model, it could restore a previous value (e.g. remove the default country); nothing is
|
|
205
205
|
updated anymore once the component is destroyed.
|
|
206
|
+
- `FoehnInputComponent`: when the user empties at once every field of a model given by the page, the model is `null`
|
|
207
|
+
again, as in v18, for the components overriding `onModelChange()` without calling `super.onModelChange()`: in
|
|
208
|
+
prestations-ng `foehn-input-date`, `foehn-input-date-time`, `foehn-input-foreign-locality` and
|
|
209
|
+
`foehn-input-foreign-street` (also in the foreign address of `foehn-input-address`), and in your project e.g. a
|
|
210
|
+
list whose last item is removed. Since 19.0.0, the model kept its previous value, which was then saved. The model
|
|
211
|
+
of the page is now known (`model_`) once it has a value to display, before `onModelChange()`, which can still
|
|
212
|
+
change it. Nothing to change in your components, except one whose model can hold a value only in a part it doesn't
|
|
213
|
+
display (e.g. an id) and which updates its model without any input of the user: override the new protected method
|
|
214
|
+
`hasValueToDisplay()`, as `foehn-input-address` does for the country of an address only Swiss.
|
|
215
|
+
- `foehn-input-date-time`: emptying its only filled field empties the model, it kept its value also in v18.
|
|
216
|
+
- 🚨 `ObjectHelper.hasAnyValue()` and `ObjectHelper.isEmpty()`: a number (`0` included), a boolean (`false`
|
|
217
|
+
included) and a date are values. `true`, `5` or a date were empty, as well as `0`, `false` or a date in an object
|
|
218
|
+
or an array (e.g. `{ checked: false }`, `[0, 0]`). Only `null`, `undefined`, `''` and the arrays and objects
|
|
219
|
+
holding none but them are empty. Check your calls on such values, e.g. in the `getValidValue()` of your
|
|
220
|
+
components: a field holding `true` no longer counts as empty.
|
|
206
221
|
- `foehn-multi-upload` and `foehn-bo-multi-upload`:
|
|
207
222
|
- after a failed upload (network, HTTP error), the next files are uploaded: nothing was uploaded anymore,
|
|
208
223
|
without any message, until the page was reloaded
|
package/GOOD_PRACTICES.md
CHANGED
|
@@ -1213,8 +1213,8 @@ item (3).
|
|
|
1213
1213
|
export class VehiculesListComponent extends FoehnInputComponent<Vehicule[]> {
|
|
1214
1214
|
readonly removedVehicule = output<void>(); // (1) event to send up to the parent
|
|
1215
1215
|
|
|
1216
|
-
// Signal holding your repeatable items: it is replaced, never modified in place
|
|
1217
|
-
readonly vehicules =
|
|
1216
|
+
// Signal holding your repeatable items, derived from the model: it is replaced, never modified in place
|
|
1217
|
+
readonly vehicules = linkedSignal(() => this.model() ?? []);
|
|
1218
1218
|
|
|
1219
1219
|
updateVehiculesList(vehicule: Vehicule, index: number): void {
|
|
1220
1220
|
this.vehicules.update((vehicules) =>
|
|
@@ -1232,10 +1232,6 @@ export class VehiculesListComponent extends FoehnInputComponent<Vehicule[]> {
|
|
|
1232
1232
|
this.removedVehicule.emit(); // (1) the event is sent up
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
|
-
override onModelChange(value: Vehicule[] | null): void {
|
|
1236
|
-
this.vehicules.set(value ?? []);
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
1235
|
addVehicule(): void {
|
|
1240
1236
|
// (3) Handling of the addition of an item
|
|
1241
1237
|
// ...code
|
|
@@ -506,7 +506,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImpo
|
|
|
506
506
|
}]
|
|
507
507
|
}] });
|
|
508
508
|
|
|
509
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
510
509
|
class ObjectHelper {
|
|
511
510
|
/**
|
|
512
511
|
* Angular uses object identity to select option. It's possible for the identities of items to change while the data does not.
|
|
@@ -523,29 +522,31 @@ class ObjectHelper {
|
|
|
523
522
|
value2 &&
|
|
524
523
|
typeof value1 === 'object' &&
|
|
525
524
|
typeof value2 === 'object') {
|
|
526
|
-
const matches = (obj, source) =>
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
525
|
+
const matches = (obj, source) => {
|
|
526
|
+
const objValues = obj;
|
|
527
|
+
const sourceValues = source;
|
|
528
|
+
return (Object.keys(source).length === Object.keys(obj).length &&
|
|
529
|
+
Object.keys(source).every((key) => {
|
|
530
|
+
if (!Object.hasOwn(obj, key)) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
const objValue = objValues[key];
|
|
534
|
+
const sourceValue = sourceValues[key];
|
|
535
|
+
if (typeof objValue === 'function' &&
|
|
536
|
+
typeof sourceValue === 'function') {
|
|
536
537
|
// Didn't find better to compare two functions
|
|
537
|
-
return (
|
|
538
|
+
return (skipFunctionTypeCompare ||
|
|
539
|
+
objValue.toString() === sourceValue.toString());
|
|
538
540
|
}
|
|
539
|
-
if (
|
|
540
|
-
|
|
541
|
-
typeof
|
|
542
|
-
typeof
|
|
543
|
-
return matches(
|
|
541
|
+
if (objValue &&
|
|
542
|
+
sourceValue &&
|
|
543
|
+
typeof objValue === 'object' &&
|
|
544
|
+
typeof sourceValue === 'object') {
|
|
545
|
+
return matches(objValue, sourceValue);
|
|
544
546
|
}
|
|
545
|
-
return
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
});
|
|
547
|
+
return objValue === sourceValue;
|
|
548
|
+
}));
|
|
549
|
+
};
|
|
549
550
|
return matches(value1, value2);
|
|
550
551
|
}
|
|
551
552
|
return value1 === value2;
|
|
@@ -553,19 +554,31 @@ class ObjectHelper {
|
|
|
553
554
|
static isDifferent(value1, value2, skipFunctionType = true) {
|
|
554
555
|
return !ObjectHelper.isEqual(value1, value2, skipFunctionType);
|
|
555
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* @param value to check
|
|
559
|
+
* @returns whether the value isn't `null`, `undefined` or `''`, and, for an array or an object, whether one of its
|
|
560
|
+
* items or properties holds a value (deeply). A number (`0` included), a boolean (`false` included) and a date are
|
|
561
|
+
* values.
|
|
562
|
+
*/
|
|
556
563
|
static hasAnyValue(value) {
|
|
557
|
-
if (
|
|
564
|
+
if (value === null || value === undefined || value === '') {
|
|
558
565
|
return false;
|
|
559
566
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
567
|
+
if (value instanceof Date) {
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
if (Array.isArray(value)) {
|
|
571
|
+
return value.some((item) => ObjectHelper.hasAnyValue(item));
|
|
572
|
+
}
|
|
573
|
+
if (typeof value === 'object') {
|
|
574
|
+
return Object.values(value).some((item) => ObjectHelper.hasAnyValue(item));
|
|
575
|
+
}
|
|
576
|
+
return true;
|
|
568
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* @param value to check
|
|
580
|
+
* @returns the contrary of {@link hasAnyValue}
|
|
581
|
+
*/
|
|
569
582
|
static isEmpty(value) {
|
|
570
583
|
return !ObjectHelper.hasAnyValue(value);
|
|
571
584
|
}
|
|
@@ -580,6 +593,7 @@ class ObjectHelper {
|
|
|
580
593
|
* @param obj is the object to copied
|
|
581
594
|
* @returns obj
|
|
582
595
|
*/
|
|
596
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the callers use the copy without typing it
|
|
583
597
|
static deepCopy(obj) {
|
|
584
598
|
if (!obj || typeof obj !== 'object') {
|
|
585
599
|
return obj;
|
|
@@ -611,18 +625,20 @@ class ObjectHelper {
|
|
|
611
625
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
612
626
|
return doc.body.textContent || '';
|
|
613
627
|
}
|
|
628
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the type of the property depends on the key
|
|
614
629
|
static getNestedProperty(obj, key) {
|
|
615
|
-
|
|
616
|
-
|
|
630
|
+
const values = obj;
|
|
631
|
+
for (const property in values) {
|
|
632
|
+
if (Object.hasOwn(values, property)) {
|
|
617
633
|
// in case it is an object
|
|
618
|
-
if (typeof
|
|
619
|
-
const result = this.getNestedProperty(
|
|
634
|
+
if (typeof values[property] === 'object') {
|
|
635
|
+
const result = this.getNestedProperty(values[property], key.split('.').slice(1).join('.'));
|
|
620
636
|
if (result !== undefined) {
|
|
621
637
|
return result;
|
|
622
638
|
}
|
|
623
639
|
}
|
|
624
640
|
else if (property === key) {
|
|
625
|
-
return
|
|
641
|
+
return values[key]; // returns the value
|
|
626
642
|
}
|
|
627
643
|
}
|
|
628
644
|
}
|
|
@@ -788,7 +804,16 @@ class FoehnInputComponent {
|
|
|
788
804
|
const value = this.model();
|
|
789
805
|
// Only a change of the model must call onModelChange(), not a change
|
|
790
806
|
// of the state it reads or updates (which can be signals).
|
|
791
|
-
untracked(() =>
|
|
807
|
+
untracked(() => {
|
|
808
|
+
// The model of the page is known (model_) once it has a value to display: when the user empties every
|
|
809
|
+
// field, the getValidValue() of the components then returns null. A model without any value to display
|
|
810
|
+
// stays unknown, so that it is never replaced by null without any input of the user. Set before
|
|
811
|
+
// onModelChange(), which can change it.
|
|
812
|
+
if (this.hasValueToDisplay(value)) {
|
|
813
|
+
this.model_ = value;
|
|
814
|
+
}
|
|
815
|
+
this.onModelChange(value);
|
|
816
|
+
});
|
|
792
817
|
}, ...(ngDevMode ? [{ debugName: "modelEffect" }] : /* istanbul ignore next */ []));
|
|
793
818
|
// ECMAScript private fields: cannot collide with a member of the components extending this class.
|
|
794
819
|
#pendingTasks = inject(PendingTasks);
|
|
@@ -1039,6 +1064,16 @@ class FoehnInputComponent {
|
|
|
1039
1064
|
}
|
|
1040
1065
|
return null;
|
|
1041
1066
|
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Whether a model given by the page has a value to display, which makes it known (`model_`) before
|
|
1069
|
+
* `onModelChange()`: by default, any value (see `ObjectHelper.hasAnyValue()`). To override when the component
|
|
1070
|
+
* doesn't display a part of its model (e.g. the country of an address only Swiss, or an id).
|
|
1071
|
+
* @param value of the model
|
|
1072
|
+
* @returns whether the model has a value to display
|
|
1073
|
+
*/
|
|
1074
|
+
hasValueToDisplay(value) {
|
|
1075
|
+
return ObjectHelper.hasAnyValue(value);
|
|
1076
|
+
}
|
|
1042
1077
|
isEmpty(data) {
|
|
1043
1078
|
return data === null || data === undefined || data === '';
|
|
1044
1079
|
}
|
|
@@ -9365,6 +9400,10 @@ class FoehnInputAddressComponent extends FoehnInputComponent {
|
|
|
9365
9400
|
}
|
|
9366
9401
|
return !this.street() || !!this.postOfficeBoxText();
|
|
9367
9402
|
}
|
|
9403
|
+
hasValueToDisplay(value) {
|
|
9404
|
+
// The country isn't displayed when the address is only Swiss (see isModelEmpty())
|
|
9405
|
+
return ObjectHelper.hasAnyValue(this.isOnlySwiss() && value ? { ...value, country: null } : value);
|
|
9406
|
+
}
|
|
9368
9407
|
sanitizeAddress(value) {
|
|
9369
9408
|
if (ObjectHelper.isEmpty(value)) {
|
|
9370
9409
|
return value;
|
|
@@ -11867,7 +11906,7 @@ class FoehnTimeComponent extends FoehnInputStringComponent {
|
|
|
11867
11906
|
}
|
|
11868
11907
|
}
|
|
11869
11908
|
onModelChange(_value) {
|
|
11870
|
-
// The hour and the minute are linked signals of the model
|
|
11909
|
+
// The hour and the minute are linked signals of the model
|
|
11871
11910
|
}
|
|
11872
11911
|
resetModel() {
|
|
11873
11912
|
this.hour.set(null);
|
|
@@ -12005,7 +12044,7 @@ class FoehnDateTimeComponent extends FoehnInputComponent {
|
|
|
12005
12044
|
this.handleUserInput();
|
|
12006
12045
|
}
|
|
12007
12046
|
onModelChange(_value) {
|
|
12008
|
-
// The date and the time are linked signals of the model
|
|
12047
|
+
// The date and the time are linked signals of the model
|
|
12009
12048
|
}
|
|
12010
12049
|
getValidValue() {
|
|
12011
12050
|
if (this.isEmpty()) {
|