@dbcdk/react-components 0.0.181 → 0.0.183

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 (56) hide show
  1. package/dist/client.cjs +21 -0
  2. package/dist/client.d.ts +3 -0
  3. package/dist/client.js +3 -0
  4. package/dist/components/clear-button/ClearButton.cjs +35 -12
  5. package/dist/components/clear-button/ClearButton.d.ts +17 -1
  6. package/dist/components/clear-button/ClearButton.js +35 -12
  7. package/dist/components/clear-button/ClearButton.module.css +12 -0
  8. package/dist/components/forms/multi-select/MultiSelect.cjs +2 -1
  9. package/dist/components/forms/multi-select/MultiSelect.js +2 -1
  10. package/dist/components/forms/select/Select.cjs +3 -1
  11. package/dist/components/forms/select/Select.js +3 -1
  12. package/dist/components/interval-select/IntervalSelect.cjs +2 -1
  13. package/dist/components/interval-select/IntervalSelect.js +2 -1
  14. package/dist/components/json-viewer/JsonViewer.cjs +3 -2
  15. package/dist/components/json-viewer/JsonViewer.d.ts +1 -1
  16. package/dist/components/json-viewer/JsonViewer.js +3 -2
  17. package/dist/components/json-viewer/JsonViewer.module.css +7 -0
  18. package/dist/components/json-viewer/types.d.ts +6 -0
  19. package/dist/components/line-viewer/LineViewer.cjs +174 -0
  20. package/dist/components/line-viewer/LineViewer.d.ts +20 -0
  21. package/dist/components/line-viewer/LineViewer.js +168 -0
  22. package/dist/components/line-viewer/LineViewer.module.css +112 -0
  23. package/dist/components/line-viewer/tokenizeLineFormat.cjs +52 -0
  24. package/dist/components/line-viewer/tokenizeLineFormat.d.ts +14 -0
  25. package/dist/components/line-viewer/tokenizeLineFormat.js +50 -0
  26. package/dist/components/tree-view/TreeNodeRow.cjs +99 -0
  27. package/dist/components/tree-view/TreeNodeRow.d.ts +18 -0
  28. package/dist/components/tree-view/TreeNodeRow.js +93 -0
  29. package/dist/components/tree-view/TreeView.cjs +93 -0
  30. package/dist/components/tree-view/TreeView.d.ts +20 -0
  31. package/dist/components/tree-view/TreeView.js +79 -0
  32. package/dist/components/tree-view/TreeView.module.css +141 -0
  33. package/dist/components/tree-view/types.cjs +2 -0
  34. package/dist/components/tree-view/types.d.ts +44 -0
  35. package/dist/components/tree-view/types.js +1 -0
  36. package/dist/components/tree-view/useTreeExpansion.cjs +47 -0
  37. package/dist/components/tree-view/useTreeExpansion.d.ts +17 -0
  38. package/dist/components/tree-view/useTreeExpansion.js +45 -0
  39. package/dist/components/tree-view/utils.cjs +32 -0
  40. package/dist/components/tree-view/utils.d.ts +16 -0
  41. package/dist/components/tree-view/utils.js +29 -0
  42. package/dist/components/xml-viewer/XmlViewer.cjs +175 -0
  43. package/dist/components/xml-viewer/XmlViewer.d.ts +20 -0
  44. package/dist/components/xml-viewer/XmlViewer.js +169 -0
  45. package/dist/components/xml-viewer/XmlViewer.module.css +109 -0
  46. package/dist/components/xml-viewer/tokenizeXml.cjs +50 -0
  47. package/dist/components/xml-viewer/tokenizeXml.d.ts +12 -0
  48. package/dist/components/xml-viewer/tokenizeXml.js +48 -0
  49. package/dist/index.cjs +7 -0
  50. package/dist/index.css +3 -0
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/utils/date/formatDate.cjs +29 -17
  54. package/dist/utils/date/formatDate.d.ts +7 -0
  55. package/dist/utils/date/formatDate.js +29 -17
  56. package/package.json +1 -1
@@ -9,41 +9,53 @@ function formatDate(date, options = {}) {
9
9
  userFriendlyLabel = false,
10
10
  timeOnly = false,
11
11
  ignoreDate = false,
12
- ignoreDateIfSame = false
12
+ ignoreDateIfSame = false,
13
+ ignoreTimezone = false
13
14
  } = options;
14
15
  const useTimeOnly = timeOnly || ignoreDate;
15
16
  const pad = (n) => n.toString().padStart(2, "0");
16
- const formatTime = () => {
17
- const hours = pad(d.getHours());
18
- const minutes = pad(d.getMinutes());
17
+ const parts = (dt, useUTC) => ({
18
+ date: useUTC ? dt.getUTCDate() : dt.getDate(),
19
+ month: useUTC ? dt.getUTCMonth() : dt.getMonth(),
20
+ year: useUTC ? dt.getUTCFullYear() : dt.getFullYear(),
21
+ hours: useUTC ? dt.getUTCHours() : dt.getHours(),
22
+ minutes: useUTC ? dt.getUTCMinutes() : dt.getMinutes(),
23
+ seconds: useUTC ? dt.getUTCSeconds() : dt.getSeconds()
24
+ });
25
+ const dParts = parts(d, ignoreTimezone);
26
+ const formatTime = (p) => {
27
+ const hours = pad(p.hours);
28
+ const minutes = pad(p.minutes);
19
29
  if (!showSeconds) return `${hours}:${minutes}`;
20
- const seconds = pad(d.getSeconds());
30
+ const seconds = pad(p.seconds);
21
31
  return `${hours}:${minutes}:${seconds}`;
22
32
  };
23
- const isSameCalendarDay = (a, b) => a.getDate() === b.getDate() && a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear();
33
+ const isSameCalendarDay = (a, b) => a.date === b.date && a.month === b.month && a.year === b.year;
24
34
  if (useTimeOnly) {
25
- return formatTime();
35
+ return formatTime(dParts);
26
36
  }
27
- if (ignoreDateIfSame && isSameCalendarDay(d, /* @__PURE__ */ new Date())) {
28
- return formatTime();
37
+ const nowParts = parts(/* @__PURE__ */ new Date(), false);
38
+ if (ignoreDateIfSame && isSameCalendarDay(dParts, nowParts)) {
39
+ return formatTime(dParts);
29
40
  }
30
41
  if (userFriendlyLabel) {
31
42
  const now = /* @__PURE__ */ new Date();
32
43
  const yesterday = new Date(now);
33
44
  yesterday.setDate(now.getDate() - 1);
34
- if (isSameCalendarDay(d, now)) {
35
- return showTime ? `I dag, kl. ${formatTime()}` : "I dag";
45
+ const yesterdayParts = parts(yesterday, false);
46
+ if (isSameCalendarDay(dParts, nowParts)) {
47
+ return showTime ? `I dag, kl. ${formatTime(dParts)}` : "I dag";
36
48
  }
37
- if (isSameCalendarDay(d, yesterday)) {
38
- return showTime ? `I g\xE5r, kl. ${formatTime()}` : "I g\xE5r";
49
+ if (isSameCalendarDay(dParts, yesterdayParts)) {
50
+ return showTime ? `I g\xE5r, kl. ${formatTime(dParts)}` : "I g\xE5r";
39
51
  }
40
52
  }
41
- const day = pad(d.getDate());
42
- const month = pad(d.getMonth() + 1);
43
- const year = d.getFullYear();
53
+ const day = pad(dParts.date);
54
+ const month = pad(dParts.month + 1);
55
+ const year = dParts.year;
44
56
  const base = `${day}.${month}.${year}`;
45
57
  if (!showTime) return base;
46
- return `${base} ${formatTime()}`;
58
+ return `${base} ${formatTime(dParts)}`;
47
59
  }
48
60
 
49
61
  exports.formatDate = formatDate;
@@ -8,6 +8,7 @@
8
8
  * - formatDate(date, { showTime: true }) => "10.03.2026 14:30"
9
9
  * - formatDate(date, { timeOnly: true }) => "14:30"
10
10
  * - formatDate(date, { showTime: true, ignoreDateIfSame: true }) => "14:30" for today, otherwise "10.03.2026 14:30"
11
+ * - formatDate('2026-03-10T14:30:00.000Z', { showTime: true, ignoreTimezone: true }) => "10.03.2026 14:30" regardless of the viewer's timezone
11
12
  *
12
13
  * @param date - The Date or date-parsable value to format
13
14
  * @param options.showTime - If true, append time "hh:mm" or "hh:mm:ss"
@@ -16,6 +17,11 @@
16
17
  * @param options.timeOnly - If true, return only the time portion
17
18
  * @param options.ignoreDate - Alias for timeOnly
18
19
  * @param options.ignoreDateIfSame - If true, return only the time when the date is today
20
+ * @param options.ignoreTimezone - If true, read the date's UTC field values verbatim instead of converting
21
+ * to the viewer's local timezone. Use this when `date` already carries the intended wall-clock values in
22
+ * its UTC fields (e.g. a "timestamp without time zone" DB column serialized with a trailing "Z") and any
23
+ * further timezone conversion would be wrong. "I dag"/"I går" comparisons still use the viewer's real
24
+ * local "today", since that part is genuinely about the viewer's current day.
19
25
  * @returns A formatted string
20
26
  */
21
27
  export declare function formatDate(date: Date | string | number, options?: {
@@ -25,4 +31,5 @@ export declare function formatDate(date: Date | string | number, options?: {
25
31
  timeOnly?: boolean;
26
32
  ignoreDate?: boolean;
27
33
  ignoreDateIfSame?: boolean;
34
+ ignoreTimezone?: boolean;
28
35
  }): string;
@@ -7,41 +7,53 @@ function formatDate(date, options = {}) {
7
7
  userFriendlyLabel = false,
8
8
  timeOnly = false,
9
9
  ignoreDate = false,
10
- ignoreDateIfSame = false
10
+ ignoreDateIfSame = false,
11
+ ignoreTimezone = false
11
12
  } = options;
12
13
  const useTimeOnly = timeOnly || ignoreDate;
13
14
  const pad = (n) => n.toString().padStart(2, "0");
14
- const formatTime = () => {
15
- const hours = pad(d.getHours());
16
- const minutes = pad(d.getMinutes());
15
+ const parts = (dt, useUTC) => ({
16
+ date: useUTC ? dt.getUTCDate() : dt.getDate(),
17
+ month: useUTC ? dt.getUTCMonth() : dt.getMonth(),
18
+ year: useUTC ? dt.getUTCFullYear() : dt.getFullYear(),
19
+ hours: useUTC ? dt.getUTCHours() : dt.getHours(),
20
+ minutes: useUTC ? dt.getUTCMinutes() : dt.getMinutes(),
21
+ seconds: useUTC ? dt.getUTCSeconds() : dt.getSeconds()
22
+ });
23
+ const dParts = parts(d, ignoreTimezone);
24
+ const formatTime = (p) => {
25
+ const hours = pad(p.hours);
26
+ const minutes = pad(p.minutes);
17
27
  if (!showSeconds) return `${hours}:${minutes}`;
18
- const seconds = pad(d.getSeconds());
28
+ const seconds = pad(p.seconds);
19
29
  return `${hours}:${minutes}:${seconds}`;
20
30
  };
21
- const isSameCalendarDay = (a, b) => a.getDate() === b.getDate() && a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear();
31
+ const isSameCalendarDay = (a, b) => a.date === b.date && a.month === b.month && a.year === b.year;
22
32
  if (useTimeOnly) {
23
- return formatTime();
33
+ return formatTime(dParts);
24
34
  }
25
- if (ignoreDateIfSame && isSameCalendarDay(d, /* @__PURE__ */ new Date())) {
26
- return formatTime();
35
+ const nowParts = parts(/* @__PURE__ */ new Date(), false);
36
+ if (ignoreDateIfSame && isSameCalendarDay(dParts, nowParts)) {
37
+ return formatTime(dParts);
27
38
  }
28
39
  if (userFriendlyLabel) {
29
40
  const now = /* @__PURE__ */ new Date();
30
41
  const yesterday = new Date(now);
31
42
  yesterday.setDate(now.getDate() - 1);
32
- if (isSameCalendarDay(d, now)) {
33
- return showTime ? `I dag, kl. ${formatTime()}` : "I dag";
43
+ const yesterdayParts = parts(yesterday, false);
44
+ if (isSameCalendarDay(dParts, nowParts)) {
45
+ return showTime ? `I dag, kl. ${formatTime(dParts)}` : "I dag";
34
46
  }
35
- if (isSameCalendarDay(d, yesterday)) {
36
- return showTime ? `I g\xE5r, kl. ${formatTime()}` : "I g\xE5r";
47
+ if (isSameCalendarDay(dParts, yesterdayParts)) {
48
+ return showTime ? `I g\xE5r, kl. ${formatTime(dParts)}` : "I g\xE5r";
37
49
  }
38
50
  }
39
- const day = pad(d.getDate());
40
- const month = pad(d.getMonth() + 1);
41
- const year = d.getFullYear();
51
+ const day = pad(dParts.date);
52
+ const month = pad(dParts.month + 1);
53
+ const year = dParts.year;
42
54
  const base = `${day}.${month}.${year}`;
43
55
  if (!showTime) return base;
44
- return `${base} ${formatTime()}`;
56
+ return `${base} ${formatTime(dParts)}`;
45
57
  }
46
58
 
47
59
  export { formatDate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.181",
3
+ "version": "0.0.183",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",