@jsonforms/angular-material 3.2.1 → 3.3.0-alpha.1

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.
Files changed (31) hide show
  1. package/lib/esm2022/library/controls/date.renderer.mjs +112 -14
  2. package/lib/esm2022/library/layouts/index.mjs +2 -1
  3. package/lib/esm2022/library/module.mjs +5 -3
  4. package/lib/esm2022/library/other/master-detail/master.mjs +3 -1
  5. package/lib/esm2022/library/other/table.renderer.mjs +190 -168
  6. package/lib/esm2022/library/util/date-format.mjs +27 -0
  7. package/lib/esm2022/library/util/dayjs-date-adapter.mjs +100 -0
  8. package/lib/fesm2022/jsonforms-angular-material.mjs +424 -184
  9. package/lib/fesm2022/jsonforms-angular-material.mjs.map +1 -1
  10. package/lib/library/controls/date.renderer.d.ts +15 -3
  11. package/lib/library/controls/date.renderer.d.ts.map +1 -1
  12. package/lib/library/layouts/index.d.ts +1 -0
  13. package/lib/library/layouts/index.d.ts.map +1 -1
  14. package/lib/library/module.d.ts +1 -1
  15. package/lib/library/module.d.ts.map +1 -1
  16. package/lib/library/other/master-detail/master.d.ts.map +1 -1
  17. package/lib/library/other/table.renderer.d.ts +10 -2
  18. package/lib/library/other/table.renderer.d.ts.map +1 -1
  19. package/lib/library/util/date-format.d.ts +17 -0
  20. package/lib/library/util/date-format.d.ts.map +1 -0
  21. package/lib/library/util/dayjs-date-adapter.d.ts +28 -0
  22. package/lib/library/util/dayjs-date-adapter.d.ts.map +1 -0
  23. package/lib/package.json +4 -3
  24. package/package.json +10 -8
  25. package/src/library/controls/date.renderer.ts +106 -8
  26. package/src/library/layouts/index.ts +1 -0
  27. package/src/library/module.ts +2 -1
  28. package/src/library/other/master-detail/master.ts +1 -0
  29. package/src/library/other/table.renderer.ts +104 -88
  30. package/src/library/util/date-format.ts +24 -0
  31. package/src/library/util/dayjs-date-adapter.ts +101 -0
@@ -0,0 +1,24 @@
1
+ import { Injectable } from '@angular/core';
2
+
3
+ @Injectable()
4
+ export class MyFormat {
5
+ displayFormat = 'M/D/YYYY';
6
+
7
+ setDisplayFormat(displayFormat: string) {
8
+ this.displayFormat = displayFormat;
9
+ }
10
+
11
+ get display() {
12
+ return {
13
+ monthYearLabel: 'YYYY-MM',
14
+ dateA11yLabel: 'YYYY-MM-DD',
15
+ monthYearA11yLabel: 'YYYY-MM',
16
+ dateInput: this.displayFormat,
17
+ };
18
+ }
19
+ get parse() {
20
+ return {
21
+ dateInput: this.displayFormat,
22
+ };
23
+ }
24
+ }
@@ -0,0 +1,101 @@
1
+ /*
2
+ The MIT License
3
+
4
+ Copyright (c) 2017-2019 EclipseSource Munich
5
+ https://github.com/eclipsesource/jsonforms
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+ */
25
+
26
+ import { Injectable } from '@angular/core';
27
+ import { NativeDateAdapter } from '@angular/material/core';
28
+ import { defaultDateFormat } from '@jsonforms/core';
29
+ import dayjs from 'dayjs';
30
+ import customParsing from 'dayjs/plugin/customParseFormat';
31
+
32
+ // allows to parse date strings with custom format
33
+ dayjs.extend(customParsing);
34
+
35
+ /**
36
+ * date adapter for dayjs to parse and format dates
37
+ */
38
+ @Injectable()
39
+ export class DayJsDateAdapter extends NativeDateAdapter {
40
+ saveFormat: string = defaultDateFormat;
41
+
42
+ setSaveFormat(format: string) {
43
+ this.saveFormat = format;
44
+ }
45
+
46
+ /**
47
+ * parses a given data prop string in the save-format into a date object
48
+ * @param value date string to be parsed
49
+ * @returns date object or null if parsing failed
50
+ */
51
+ parseSaveFormat(value: string): Date | null {
52
+ return this.parse(value, this.saveFormat);
53
+ }
54
+
55
+ parse(value: string, format: string): Date | null {
56
+ if (!value) {
57
+ return null;
58
+ }
59
+ const date = dayjs(value, format);
60
+
61
+ if (date.isValid()) {
62
+ return date.toDate();
63
+ } else {
64
+ return null;
65
+ }
66
+ }
67
+
68
+ toSaveFormat(value: Date) {
69
+ if (!value) {
70
+ return undefined;
71
+ }
72
+ const date = dayjs(value);
73
+ if (date.isValid()) {
74
+ return date.format(this.saveFormat);
75
+ } else {
76
+ return undefined;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * transforms the date to a string representation for display
82
+ * @param date date to be formatted
83
+ * @param displayFormat format to be used for formatting the date e.g. YYYY-MM-DD
84
+ * @returns string representation of the date
85
+ */
86
+ format(date: Date, displayFormat: string): string {
87
+ return dayjs(date).format(displayFormat);
88
+ }
89
+
90
+ deserialize(value: any): Date | null {
91
+ if (!value) {
92
+ return null;
93
+ }
94
+ const date = dayjs(value);
95
+ if (date.isValid()) {
96
+ return date.toDate();
97
+ } else {
98
+ return null;
99
+ }
100
+ }
101
+ }