@energinet/watt 4.2.9 → 4.2.11
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.
|
@@ -16,68 +16,45 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
//#endregion
|
|
19
|
-
import { DestroyRef, Directive, inject } from '@angular/core';
|
|
20
|
-
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
21
19
|
import { FormGroupDirective } from '@angular/forms';
|
|
22
20
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
23
|
-
import
|
|
21
|
+
import { Directive, afterRenderEffect, inject } from '@angular/core';
|
|
24
22
|
import * as i0 from "@angular/core";
|
|
25
23
|
const filtersKey = 'filters';
|
|
26
24
|
export class WattQueryParamsDirective {
|
|
27
|
-
formGroup = inject(FormGroupDirective);
|
|
28
|
-
destoryRef = inject(DestroyRef);
|
|
29
25
|
router = inject(Router);
|
|
30
26
|
route = inject(ActivatedRoute);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
?.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
formGroup = inject(FormGroupDirective);
|
|
28
|
+
constructor() {
|
|
29
|
+
afterRenderEffect((onCleanup) => {
|
|
30
|
+
const subscription = this.formGroup.valueChanges?.subscribe((formValues) => {
|
|
31
|
+
const formValuesClone = structuredClone(formValues);
|
|
32
|
+
for (const key in formValuesClone) {
|
|
33
|
+
if (formValuesClone[key] === null || formValuesClone[key] === undefined) {
|
|
34
|
+
delete formValuesClone[key];
|
|
35
|
+
}
|
|
40
36
|
}
|
|
37
|
+
const hasSetProperties = Object.keys(formValuesClone).length > 0;
|
|
38
|
+
//Todo: Use toBase68 instead of btoa and atop when typescript 5.10 drops.
|
|
39
|
+
const encodedFormValues = new TextEncoder().encode(JSON.stringify(formValuesClone));
|
|
40
|
+
const base64FormValues = btoa(String.fromCharCode(...encodedFormValues));
|
|
41
|
+
this.router.navigate([], {
|
|
42
|
+
replaceUrl: true,
|
|
43
|
+
relativeTo: this.route,
|
|
44
|
+
queryParams: { [filtersKey]: hasSetProperties ? base64FormValues : null },
|
|
45
|
+
queryParamsHandling: 'merge',
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
if (Object.keys(this.route.snapshot.queryParams).length > 0) {
|
|
49
|
+
const value = atob(this.route.snapshot.queryParams[filtersKey] ?? '');
|
|
50
|
+
const decodedFormValues = new TextDecoder().decode(Uint8Array.from(value, (c) => c.charCodeAt(0)));
|
|
51
|
+
const parsedValue = JSON.parse(decodedFormValues);
|
|
52
|
+
this.formGroup.control.patchValue(parsedValue);
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
replaceUrl: true,
|
|
45
|
-
relativeTo: this.route,
|
|
46
|
-
queryParams: { [filtersKey]: hasSetProperties ? qs.stringify(formValuesClone) : null },
|
|
47
|
-
queryParamsHandling: 'merge',
|
|
54
|
+
onCleanup(() => {
|
|
55
|
+
subscription?.unsubscribe();
|
|
48
56
|
});
|
|
49
57
|
});
|
|
50
|
-
if (Object.keys(this.route.snapshot.queryParams).length > 0) {
|
|
51
|
-
const value = qs.parse(this.route.snapshot.queryParams[filtersKey] ?? '', {
|
|
52
|
-
// Needed because `qs` library has a default value of 20 elements
|
|
53
|
-
// after which arrays are parsed as objects
|
|
54
|
-
// See https://github.com/ljharb/qs?tab=readme-ov-file#parsing-arrays
|
|
55
|
-
arrayLimit: 200,
|
|
56
|
-
// See https://github.com/ljharb/qs/issues/91#issuecomment-1833694874
|
|
57
|
-
decoder(str, defaultDecoder, charset, type) {
|
|
58
|
-
// Custom logic not part of the GitHub comment above
|
|
59
|
-
// Handles "YYYY-MM" dates
|
|
60
|
-
if (type === 'value' && /\d{4}-\d{2}$/.test(str)) {
|
|
61
|
-
return defaultDecoder(str, defaultDecoder, charset);
|
|
62
|
-
}
|
|
63
|
-
if (type === 'value' &&
|
|
64
|
-
/^(?:-(?:[1-9](?:\d{0,2}(?:,\d{3})+|\d*))|(?:0|(?:[1-9](?:\d{0,2}(?:,\d{3})+|\d*))))(?:.\d+|)$/.test(str)) {
|
|
65
|
-
return parseFloat(str);
|
|
66
|
-
}
|
|
67
|
-
const keywords = {
|
|
68
|
-
true: true,
|
|
69
|
-
false: false,
|
|
70
|
-
null: null,
|
|
71
|
-
undefined: undefined,
|
|
72
|
-
};
|
|
73
|
-
if (type === 'value' && str in keywords) {
|
|
74
|
-
return keywords[str];
|
|
75
|
-
}
|
|
76
|
-
return defaultDecoder(str, defaultDecoder, charset);
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
this.formGroup.control.patchValue(value);
|
|
80
|
-
}
|
|
81
58
|
}
|
|
82
59
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: WattQueryParamsDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
83
60
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.15", type: WattQueryParamsDirective, isStandalone: true, selector: "[formGroup][wattQueryParams]", ngImport: i0 });
|
|
@@ -87,5 +64,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
|
|
|
87
64
|
args: [{
|
|
88
65
|
selector: '[formGroup][wattQueryParams]',
|
|
89
66
|
}]
|
|
90
|
-
}] });
|
|
67
|
+
}], ctorParameters: () => [] });
|
|
91
68
|
//# sourceMappingURL=watt-query-params.directive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watt-query-params.directive.js","sourceRoot":"","sources":["../../../../libs/watt/package/query-params/watt-query-params.directive.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB;;;;;;;;;;;;;;;GAeG;AACH,YAAY;AACZ,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"watt-query-params.directive.js","sourceRoot":"","sources":["../../../../lib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AC,CAAC,CAAC;gBAEzE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE;oBACvB,UAAU,EAAE,IAAI;oBAChB,UAAU,EAAE,IAAI,CAAC,KAAK;oBACtB,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE;oBACzE,mBAAmB,EAAE,OAAO;iBAC7B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;gBACtE,MAAM,iBAAiB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAChD,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC/C,CAAC;gBACF,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBAElD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACjD,CAAC;YAED,SAAS,CAAC,GAAG,EAAE;gBACb,YAAY,EAAE,WAAW,EAAE,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;wGA7CU,wBAAwB;4FAAxB,wBAAwB;;4FAAxB,wBAAwB;kBAHpC,SAAS;mBAAC;oBACT,QAAQ,EAAE,8BAA8B;iBACzC","sourcesContent":["//#region License\n/**\n * @license\n * Copyright 2020 Energinet DataHub A/S\n *\n * Licensed under the Apache License, Version 2.0 (the \"License2\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n//#endregion\nimport { FormGroupDirective } from '@angular/forms';\nimport { ActivatedRoute, Router } from '@angular/router';\nimport { Directive, afterRenderEffect, inject } from '@angular/core';\n\nconst filtersKey = 'filters';\n@Directive({\n selector: '[formGroup][wattQueryParams]',\n})\nexport class WattQueryParamsDirective {\n private router = inject(Router);\n private route = inject(ActivatedRoute);\n private formGroup = inject(FormGroupDirective);\n\n constructor() {\n afterRenderEffect((onCleanup) => {\n const subscription = this.formGroup.valueChanges?.subscribe((formValues) => {\n const formValuesClone = structuredClone(formValues);\n\n for (const key in formValuesClone) {\n if (formValuesClone[key] === null || formValuesClone[key] === undefined) {\n delete formValuesClone[key];\n }\n }\n\n const hasSetProperties = Object.keys(formValuesClone).length > 0;\n\n //Todo: Use toBase68 instead of btoa and atop when typescript 5.10 drops.\n const encodedFormValues = new TextEncoder().encode(JSON.stringify(formValuesClone));\n\n const base64FormValues = btoa(String.fromCharCode(...encodedFormValues));\n\n this.router.navigate([], {\n replaceUrl: true,\n relativeTo: this.route,\n queryParams: { [filtersKey]: hasSetProperties ? base64FormValues : null },\n queryParamsHandling: 'merge',\n });\n });\n\n if (Object.keys(this.route.snapshot.queryParams).length > 0) {\n const value = atob(this.route.snapshot.queryParams[filtersKey] ?? '');\n const decodedFormValues = new TextDecoder().decode(\n Uint8Array.from(value, (c) => c.charCodeAt(0))\n );\n const parsedValue = JSON.parse(decodedFormValues);\n\n this.formGroup.control.patchValue(parsedValue);\n }\n\n onCleanup(() => {\n subscription?.unsubscribe();\n });\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@energinet/watt",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.11",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -250,7 +250,6 @@
|
|
|
250
250
|
"dayjs": "^1.11.13",
|
|
251
251
|
"libphonenumber-js": "^1.11.9",
|
|
252
252
|
"ngx-mat-select-search": "^8.0.4",
|
|
253
|
-
"qs": "^6.12.1",
|
|
254
253
|
"rxjs": "^7.8.2"
|
|
255
254
|
},
|
|
256
255
|
"module": "esm2022/energinet-watt.js",
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Energinet DataHub A/S
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License2");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import { OnInit } from '@angular/core';
|
|
18
1
|
import * as i0 from "@angular/core";
|
|
19
|
-
export declare class WattQueryParamsDirective
|
|
20
|
-
private formGroup;
|
|
21
|
-
private destoryRef;
|
|
2
|
+
export declare class WattQueryParamsDirective {
|
|
22
3
|
private router;
|
|
23
4
|
private route;
|
|
24
|
-
|
|
5
|
+
private formGroup;
|
|
6
|
+
constructor();
|
|
25
7
|
static ɵfac: i0.ɵɵFactoryDeclaration<WattQueryParamsDirective, never>;
|
|
26
8
|
static ɵdir: i0.ɵɵDirectiveDeclaration<WattQueryParamsDirective, "[formGroup][wattQueryParams]", never, {}, {}, never, never, true, never>;
|
|
27
9
|
}
|