asab_webui_components 25.2.13 → 25.2.14

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/README.md CHANGED
@@ -25,7 +25,7 @@ Possible imports:
25
25
  - ControlledSwitch
26
26
  - UncontrolledSwitch
27
27
  - CellContentLoader, ChartLoader
28
- - DateTime, timeToString, useDateFNSLocale
28
+ - DateTime, DateTimeRelative, timeToString, timeToStringRelative, useDateFNSLocale
29
29
  - TreeMenuCard, formatIntoLeafFolderTree, removeTreeContent, formatIntoTree
30
30
  - saveToLS, getFromLS, removeFromLS
31
31
  - validateAccess, validateTenantAccess, validateResourceAccess
@@ -11,7 +11,7 @@ var _reactRedux = require("react-redux");
11
11
  var _reactRouterDom = require("react-router-dom");
12
12
  var _reactJsonView = _interopRequireDefault(require("react-json-view"));
13
13
  var _reactstrap = require("reactstrap");
14
- var _DateTime = require("../DateTime/DateTime.js");
14
+ var _DateTime = require("../DateTime/absolute/DateTime.js");
15
15
  var _Buttons = require("./Buttons");
16
16
  require("./DataTable.scss");
17
17
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DateTime = DateTime;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _timeToString = _interopRequireDefault(require("./timeToString.js"));
10
+ var _useDateFNSLocale = _interopRequireDefault(require("../utils/useDateFNSLocale.js"));
11
+ var _InvalidDate = require("../components/InvalidDate.js");
12
+ // Component that displays the absolute time and shows the relative time on hover
13
+ function DateTime(props) {
14
+ if (props.value == undefined) {
15
+ return /*#__PURE__*/_react.default.createElement("span", {
16
+ className: "datetime"
17
+ }, ' ');
18
+ }
19
+
20
+ // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
21
+ var locale = (0, _useDateFNSLocale.default)();
22
+ var date = (0, _timeToString.default)(props.value, props.dateTimeFormat, locale);
23
+
24
+ // Check for invalid date from timeToString method
25
+ if (date === 'Invalid Date') {
26
+ return /*#__PURE__*/_react.default.createElement(_InvalidDate.InvalidDate, null);
27
+ }
28
+ return /*#__PURE__*/_react.default.createElement("span", {
29
+ className: "datetime text-nowrap",
30
+ title: date.distanceToNow
31
+ }, /*#__PURE__*/_react.default.createElement("i", {
32
+ className: "bi bi-clock pe-1"
33
+ }), date.date);
34
+ }
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+
3
+ import timeToString from './timeToString.js';
4
+ import useDateFNSLocale from '../utils/useDateFNSLocale.js';
5
+ import { InvalidDate } from '../components/InvalidDate.jsx';
6
+
7
+ // Component that displays the absolute time and shows the relative time on hover
8
+ export function DateTime(props) {
9
+ if (props.value == undefined) {
10
+ return (
11
+ <span className='datetime'>{' '}</span>
12
+ );
13
+ }
14
+
15
+ // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
16
+ const locale = useDateFNSLocale();
17
+
18
+ const date = timeToString(props.value, props.dateTimeFormat, locale);
19
+
20
+ // Check for invalid date from timeToString method
21
+ if (date === 'Invalid Date') {
22
+ return (
23
+ <InvalidDate />
24
+ );
25
+ }
26
+
27
+ return (
28
+ <span
29
+ className='datetime text-nowrap'
30
+ title={date.distanceToNow}
31
+ >
32
+ <i className='bi bi-clock pe-1' />
33
+ {date.date}
34
+ </span>
35
+ );
36
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.timeToString = exports.default = void 0;
7
+ var _timeToStringCommon = require("../utils/timeToStringCommon.js");
8
+ // Absolute time formatting with "ago"
9
+ var timeToString = exports.timeToString = function timeToString(value) {
10
+ var dateTimeFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "medium";
11
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
12
+ return (0, _timeToStringCommon.timeToStringCommon)(value, dateTimeFormat, locale, true); // addSuffix = true
13
+ };
14
+ var _default = exports.default = timeToString;
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.DateTimeRelative = DateTimeRelative;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _timeToString = _interopRequireDefault(require("./timeToString"));
10
- var _useDateFNSLocale = _interopRequireDefault(require("./useDateFNSLocale"));
11
- var _InvalidDate = require("./InvalidDate.js");
9
+ var _timeToStringRelative = require("./timeToStringRelative.js");
10
+ var _useDateFNSLocale = _interopRequireDefault(require("../utils/useDateFNSLocale"));
11
+ var _InvalidDate = require("../components/InvalidDate.js");
12
12
  // Component that displays the relative time and shows the absolute time on hover
13
13
  function DateTimeRelative(props) {
14
14
  if (props.value == undefined) {
@@ -19,10 +19,7 @@ function DateTimeRelative(props) {
19
19
 
20
20
  // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
21
21
  var locale = (0, _useDateFNSLocale.default)();
22
- if (new Date(props.value).toString() === 'Invalid Date') {
23
- return /*#__PURE__*/_react.default.createElement(_InvalidDate.InvalidDate, null);
24
- }
25
- var date = (0, _timeToString.default)(props.value, props.dateTimeFormat, locale);
22
+ var date = (0, _timeToStringRelative.timeToStringRelative)(props.value, props.dateTimeFormat, props.addSuffix, locale);
26
23
 
27
24
  // Check for invalid date from timeToString method
28
25
  if (date === 'Invalid Date') {
@@ -30,8 +27,8 @@ function DateTimeRelative(props) {
30
27
  }
31
28
  return /*#__PURE__*/_react.default.createElement("span", {
32
29
  className: "datetime text-nowrap",
33
- title: date.date
30
+ title: date.absoluteTime
34
31
  }, /*#__PURE__*/_react.default.createElement("i", {
35
32
  className: "bi bi-clock pe-1"
36
- }), date.distanceToNow);
33
+ }), date.date);
37
34
  }
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
- import timeToString from './timeToString';
4
- import useDateFNSLocale from './useDateFNSLocale';
5
- import { InvalidDate } from './InvalidDate.jsx';
3
+ import { timeToStringRelative } from './timeToStringRelative.jsx';
4
+ import useDateFNSLocale from '../utils/useDateFNSLocale';
5
+ import { InvalidDate } from '../components/InvalidDate.jsx';
6
6
 
7
7
  // Component that displays the relative time and shows the absolute time on hover
8
8
  export function DateTimeRelative(props) {
@@ -14,13 +14,8 @@ export function DateTimeRelative(props) {
14
14
 
15
15
  // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
16
16
  const locale = useDateFNSLocale();
17
- if (new Date(props.value).toString() === 'Invalid Date') {
18
- return (
19
- <InvalidDate />
20
- );
21
- }
22
17
 
23
- const date = timeToString(props.value, props.dateTimeFormat, locale);
18
+ const date = timeToStringRelative(props.value, props.dateTimeFormat, props.addSuffix, locale);
24
19
 
25
20
  // Check for invalid date from timeToString method
26
21
  if (date === 'Invalid Date') {
@@ -32,10 +27,10 @@ export function DateTimeRelative(props) {
32
27
  return (
33
28
  <span
34
29
  className='datetime text-nowrap'
35
- title={date.date}
30
+ title={date.absoluteTime}
36
31
  >
37
32
  <i className='bi bi-clock pe-1' />
38
- {date.distanceToNow}
33
+ {date.date}
39
34
  </span>
40
35
  );
41
36
  }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.timeToStringRelative = void 0;
7
+ var _timeToStringCommon = require("../utils/timeToStringCommon.js");
8
+ // Relative time formatting without "ago"
9
+ var timeToStringRelative = exports.timeToStringRelative = function timeToStringRelative(value) {
10
+ var dateTimeFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "medium";
11
+ var addSuffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
12
+ var locale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
13
+ // TODO: add addSuffix = true for values which are to the future from now (we can use of isAfter from date-fns)
14
+ var {
15
+ date,
16
+ distanceToNow
17
+ } = (0, _timeToStringCommon.timeToStringCommon)(value, dateTimeFormat, locale, addSuffix);
18
+ return {
19
+ date: distanceToNow,
20
+ absoluteTime: date
21
+ };
22
+ };
@@ -0,0 +1,8 @@
1
+ import { timeToStringCommon } from '../utils/timeToStringCommon.jsx';
2
+
3
+ // Relative time formatting without "ago"
4
+ export const timeToStringRelative = (value, dateTimeFormat = "medium", addSuffix = false, locale = undefined) => {
5
+ // TODO: add addSuffix = true for values which are to the future from now (we can use of isAfter from date-fns)
6
+ const { date, distanceToNow } = timeToStringCommon(value, dateTimeFormat, locale, addSuffix);
7
+ return { date: distanceToNow, absoluteTime: date };
8
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.timeToStringCommon = void 0;
7
+ var _dateFns = require("date-fns");
8
+ var _validateDateTime = require("./validateDateTime.js");
9
+ // Common logic for both timeToString and timeToStringRelative
10
+ var timeToStringCommon = (value, dateTimeFormat, locale, addSuffix) => {
11
+ if (value == undefined) {
12
+ return 'Invalid Date';
13
+ }
14
+ var datetime = (0, _validateDateTime.validateDateTime)(value);
15
+ if (datetime.toString() === 'Invalid Date') {
16
+ return 'Invalid Date';
17
+ }
18
+ if (new Date(datetime).toString() === "Invalid Date") {
19
+ return 'Invalid Date';
20
+ }
21
+
22
+ // TODO: uncomment to eventually add more defensiveness on dateTimeFormat
23
+ // try {
24
+ // format(datetime, dateTimeFormat);
25
+ // } catch(e) {
26
+ // console.error(`ASAB WebUI Components: DateTime - Invalid date time format ${dateTimeFormat}. The format is set to its default.`);
27
+ // dateTimeFormat = "medium";
28
+ // }
29
+
30
+ var date;
31
+ if (isNaN(datetime) == true) {
32
+ // Checking dates for parsing
33
+ if ((0, _dateFns.parseISO)(datetime) == "Invalid Date") {
34
+ return 'Invalid Date';
35
+ } else {
36
+ date = formatDate((0, _dateFns.parseISO)(datetime), dateTimeFormat, locale, addSuffix);
37
+ }
38
+ } else {
39
+ if (datetime > 9999999999) {
40
+ date = formatDate(datetime, dateTimeFormat, locale, addSuffix);
41
+ } else {
42
+ date = formatDate(datetime * 1000, dateTimeFormat, locale, addSuffix);
43
+ }
44
+ }
45
+ return {
46
+ date: date.date,
47
+ distanceToNow: date.distanceToNow
48
+ };
49
+ };
50
+ exports.timeToStringCommon = timeToStringCommon;
51
+ var formatDate = (datetime, dateTimeFormat, locale, addSuffix) => {
52
+ switch (dateTimeFormat) {
53
+ case "long":
54
+ return {
55
+ date: (0, _dateFns.format)(datetime, 'PPpp', {
56
+ locale
57
+ }),
58
+ distanceToNow: (0, _dateFns.formatDistanceToNow)(datetime, {
59
+ addSuffix,
60
+ locale: locale
61
+ })
62
+ };
63
+ case "iso":
64
+ return {
65
+ date: (0, _dateFns.formatISO)(datetime),
66
+ distanceToNow: (0, _dateFns.formatDistanceToNow)(datetime, {
67
+ addSuffix,
68
+ locale: locale
69
+ })
70
+ };
71
+ case "medium":
72
+ return {
73
+ date: (0, _dateFns.format)(datetime, 'PPp', {
74
+ locale
75
+ }),
76
+ distanceToNow: (0, _dateFns.formatDistanceToNow)(datetime, {
77
+ addSuffix,
78
+ locale: locale
79
+ })
80
+ };
81
+ default:
82
+ return {
83
+ date: (0, _dateFns.format)(datetime, dateTimeFormat),
84
+ distanceToNow: (0, _dateFns.formatDistanceToNow)(datetime, {
85
+ addSuffix,
86
+ locale: locale
87
+ })
88
+ };
89
+ }
90
+ };
@@ -0,0 +1,55 @@
1
+ import { format, parseISO, formatISO, formatDistanceToNow } from 'date-fns';
2
+ import { validateDateTime } from './validateDateTime.jsx';
3
+
4
+ // Common logic for both timeToString and timeToStringRelative
5
+ export const timeToStringCommon = (value, dateTimeFormat, locale, addSuffix) => {
6
+ if (value == undefined) {
7
+ return 'Invalid Date';
8
+ }
9
+
10
+ const datetime = validateDateTime(value);
11
+
12
+ if (datetime.toString() === 'Invalid Date') {
13
+ return 'Invalid Date';
14
+ }
15
+
16
+ if (new Date(datetime).toString() === "Invalid Date") {
17
+ return 'Invalid Date';
18
+ }
19
+
20
+ // TODO: uncomment to eventually add more defensiveness on dateTimeFormat
21
+ // try {
22
+ // format(datetime, dateTimeFormat);
23
+ // } catch(e) {
24
+ // console.error(`ASAB WebUI Components: DateTime - Invalid date time format ${dateTimeFormat}. The format is set to its default.`);
25
+ // dateTimeFormat = "medium";
26
+ // }
27
+
28
+ let date;
29
+
30
+ if (isNaN(datetime) == true) {
31
+ // Checking dates for parsing
32
+ if (parseISO(datetime) == "Invalid Date") {
33
+ return 'Invalid Date';
34
+ } else {
35
+ date = formatDate(parseISO(datetime), dateTimeFormat, locale, addSuffix);
36
+ }
37
+ } else {
38
+ if (datetime > 9999999999) {
39
+ date = formatDate(datetime, dateTimeFormat, locale, addSuffix);
40
+ } else {
41
+ date = formatDate(datetime * 1000, dateTimeFormat, locale, addSuffix);
42
+ }
43
+ }
44
+
45
+ return {date: date.date, distanceToNow: date.distanceToNow};
46
+ }
47
+
48
+ const formatDate = (datetime, dateTimeFormat, locale, addSuffix) => {
49
+ switch(dateTimeFormat) {
50
+ case "long": return {date: format(datetime, 'PPpp', { locale }), distanceToNow: formatDistanceToNow(datetime, { addSuffix, locale: locale })};
51
+ case "iso": return {date: formatISO(datetime), distanceToNow: formatDistanceToNow(datetime, { addSuffix, locale: locale })};
52
+ case "medium": return {date: format(datetime, 'PPp', { locale }), distanceToNow: formatDistanceToNow(datetime, { addSuffix, locale: locale })};
53
+ default: return {date: format(datetime, dateTimeFormat), distanceToNow: formatDistanceToNow(datetime, { addSuffix, locale: locale })};
54
+ }
55
+ }
@@ -3,7 +3,50 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.splDatetimeToIso = splDatetimeToIso;
6
+ exports.validateDateTime = validateDateTime;
7
+ function validateDateTime(value) {
8
+ // Return 'Invalid Date' if the input is null or undefined
9
+ if (value == null) {
10
+ return 'Invalid Date';
11
+ }
12
+
13
+ // Handle BigInt values explicitly
14
+ if (typeof value === 'bigint') {
15
+ // SP-Lang datetime format is represented as BigInt
16
+ return splDatetimeToIso(value);
17
+ }
18
+
19
+ // Handle string values
20
+ if (typeof value === 'string') {
21
+ return new Date(value);
22
+ }
23
+
24
+ // Handle number values
25
+ if (typeof value === 'number') {
26
+ // Reject infinite, NaN, or negative numbers
27
+ if (!Number.isFinite(value) || value < 0) {
28
+ return 'Invalid Date';
29
+ }
30
+
31
+ // Handle Unix timestamp in seconds (less than 1e10)
32
+ if (value < 1e10) {
33
+ return new Date(value * 1000); // Convert seconds to milliseconds
34
+ }
35
+
36
+ // Handle timestamps in milliseconds (less than 1e13)
37
+ if (value < 1e13) {
38
+ return new Date(value); // Already in milliseconds
39
+ }
40
+
41
+ // Handle timestamps in microseconds (less than 1e16)
42
+ if (value < 1e16) {
43
+ return new Date(value / 1000); // Convert microseconds to milliseconds
44
+ }
45
+ }
46
+
47
+ // All other types are unsupported and result in 'Invalid Date'
48
+ return 'Invalid Date';
49
+ }
7
50
  function splDatetimeToIso(datetime) {
8
51
  // Check if datetime is a number or BigInt
9
52
  if (typeof datetime !== 'bigint' && typeof datetime !== 'number') {
@@ -0,0 +1,88 @@
1
+ export function validateDateTime(value) {
2
+ // Return 'Invalid Date' if the input is null or undefined
3
+ if (value == null) {
4
+ return 'Invalid Date';
5
+ }
6
+
7
+ // Handle BigInt values explicitly
8
+ if (typeof value === 'bigint') {
9
+ // SP-Lang datetime format is represented as BigInt
10
+ return splDatetimeToIso(value);
11
+ }
12
+
13
+ // Handle string values
14
+ if (typeof value === 'string') {
15
+ return new Date(value);
16
+ }
17
+
18
+ // Handle number values
19
+ if (typeof value === 'number') {
20
+ // Reject infinite, NaN, or negative numbers
21
+ if (!Number.isFinite(value) || value < 0) {
22
+ return 'Invalid Date';
23
+ }
24
+
25
+ // Handle Unix timestamp in seconds (less than 1e10)
26
+ if (value < 1e10) {
27
+ return new Date(value * 1000); // Convert seconds to milliseconds
28
+ }
29
+
30
+ // Handle timestamps in milliseconds (less than 1e13)
31
+ if (value < 1e13) {
32
+ return new Date(value); // Already in milliseconds
33
+ }
34
+
35
+ // Handle timestamps in microseconds (less than 1e16)
36
+ if (value < 1e16) {
37
+ return new Date(value / 1000); // Convert microseconds to milliseconds
38
+ }
39
+ }
40
+
41
+ // All other types are unsupported and result in 'Invalid Date'
42
+ return 'Invalid Date';
43
+ }
44
+
45
+ function splDatetimeToIso(datetime) {
46
+ // Check if datetime is a number or BigInt
47
+ if ((typeof datetime !== 'bigint') && (typeof datetime !== 'number')) {
48
+ return 'Invalid Date';
49
+ }
50
+ // Year extraction (bits 46-60)
51
+ let year = Number((datetime >> BigInt(46)) & BigInt(0b111111111111)); // 14 bits
52
+ if (year >= 0b10_0000_0000_0000) {
53
+ year -= 0b10_0000_0000_0000; // Adjust for sign bit if necessary
54
+ }
55
+
56
+ // Month extraction (bits 42-46)
57
+ let month = Number((datetime >> BigInt(42)) & BigInt(0b1111)); // 4 bits
58
+
59
+ // Day extraction (bits 37-42)
60
+ const day = Number((datetime >> BigInt(37)) & BigInt(0b11111)); // 5 bits
61
+
62
+ // Hour extraction (bits 32-37)
63
+ const hour = Number((datetime >> BigInt(32)) & BigInt(0b11111)); // 5 bits
64
+
65
+ // Minute extraction (bits 26-32)
66
+ const minute = Number((datetime >> BigInt(26)) & BigInt(0b111111)); // 6 bits
67
+
68
+ // Second extraction (bits 20-26)
69
+ const second = Number((datetime >> BigInt(20)) & BigInt(0b111111)); // 6 bits
70
+
71
+ // Microsecond extraction (bits 0-20)
72
+ const microsecond = Number(datetime & BigInt(0b111111111111111111111)); // 20 bits
73
+
74
+ // Adjust for zero-based month
75
+ month += 1;
76
+
77
+ // Check if the values are correct
78
+ if (
79
+ year < 0 || month < 1 || month > 12 ||
80
+ day < 1 || day > 31 || hour > 23 ||
81
+ minute > 59 || second > 59
82
+ ) {
83
+ return 'Invalid Date';
84
+ }
85
+
86
+ // Format date string
87
+ return `${year.toString().padStart(4, '0')}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}T${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}:${second.toString().padStart(2, '0')}.${microsecond.toString().padStart(6, '0')}Z`;
88
+ }
package/dist/index.js CHANGED
@@ -304,6 +304,12 @@ Object.defineProperty(exports, "timeToString", {
304
304
  return _timeToString.default;
305
305
  }
306
306
  });
307
+ Object.defineProperty(exports, "timeToStringRelative", {
308
+ enumerable: true,
309
+ get: function get() {
310
+ return _timeToStringRelative.timeToStringRelative;
311
+ }
312
+ });
307
313
  Object.defineProperty(exports, "useDateFNSLocale", {
308
314
  enumerable: true,
309
315
  get: function get() {
@@ -346,10 +352,11 @@ var _ControlledSwitch = _interopRequireDefault(require("./components/ControlledS
346
352
  var _UncontrolledSwitch = _interopRequireDefault(require("./components/UncontrolledSwitch"));
347
353
  var _Credentials = require("./components/Authz/Credentials");
348
354
  var _ContentLoader = require("./components/ContentLoader");
349
- var _DateTime = require("./components/DateTime/DateTime.js");
350
- var _DateTimeRelative = require("./components/DateTime/DateTimeRelative.js");
351
- var _timeToString = _interopRequireDefault(require("./components/DateTime/timeToString"));
352
- var _useDateFNSLocale = _interopRequireDefault(require("./components/DateTime/useDateFNSLocale"));
355
+ var _DateTime = require("./components/DateTime/absolute/DateTime.js");
356
+ var _DateTimeRelative = require("./components/DateTime/relative/DateTimeRelative.js");
357
+ var _timeToString = _interopRequireDefault(require("./components/DateTime/absolute/timeToString"));
358
+ var _timeToStringRelative = require("./components/DateTime/relative/timeToStringRelative.js");
359
+ var _useDateFNSLocale = _interopRequireDefault(require("./components/DateTime/utils/useDateFNSLocale"));
353
360
  var _TreeMenu = require("./components/TreeMenu");
354
361
  var _localStorage = require("./utils/localStorage");
355
362
  var _validateAccess = require("./utils/validateAccess");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_components",
3
- "version": "25.2.13",
3
+ "version": "25.2.14",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Components Library",
6
6
  "contributors": [
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DateTime = DateTime;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _timeToString = _interopRequireDefault(require("./timeToString.js"));
10
- var _useDateFNSLocale = _interopRequireDefault(require("./useDateFNSLocale.js"));
11
- var _InvalidDate = require("./InvalidDate.js");
12
- var _splDatetimeToIso = require("./splDatetimeToIso");
13
- // Component that displays the absolute time and shows the relative time on hover
14
- function DateTime(props) {
15
- if (props.value == undefined) {
16
- return /*#__PURE__*/_react.default.createElement("span", {
17
- className: "datetime"
18
- }, ' ');
19
- }
20
-
21
- // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
22
- var locale = (0, _useDateFNSLocale.default)();
23
- var datetime = validateDateTime(props.value);
24
- if (datetime.toString() === 'Invalid Date') {
25
- return /*#__PURE__*/_react.default.createElement(_InvalidDate.InvalidDate, null);
26
- }
27
- var date = (0, _timeToString.default)(datetime, props.dateTimeFormat, locale);
28
-
29
- // Check for invalid date from timeToString method
30
- if (date === 'Invalid Date') {
31
- return /*#__PURE__*/_react.default.createElement(_InvalidDate.InvalidDate, null);
32
- }
33
- return /*#__PURE__*/_react.default.createElement("span", {
34
- className: "datetime text-nowrap",
35
- title: date.distanceToNow
36
- }, /*#__PURE__*/_react.default.createElement("i", {
37
- className: "bi bi-clock pe-1"
38
- }), date.date);
39
- }
40
- function validateDateTime(value) {
41
- // Return 'Invalid Date' if the input is null or undefined
42
- if (value == null) {
43
- return 'Invalid Date';
44
- }
45
-
46
- // Handle BigInt values explicitly
47
- if (typeof value === 'bigint') {
48
- // SP-Lang datetime format is represented as BigInt
49
- return (0, _splDatetimeToIso.splDatetimeToIso)(value);
50
- }
51
-
52
- // Handle string values
53
- if (typeof value === 'string') {
54
- return new Date(value);
55
- }
56
-
57
- // Handle number values
58
- if (typeof value === 'number') {
59
- // Reject infinite, NaN, or negative numbers
60
- if (!Number.isFinite(value) || value < 0) {
61
- return 'Invalid Date';
62
- }
63
-
64
- // Handle Unix timestamp in seconds (less than 1e10)
65
- if (value < 1e10) {
66
- return new Date(value * 1000); // Convert seconds to milliseconds
67
- }
68
-
69
- // Handle timestamps in milliseconds (less than 1e13)
70
- if (value < 1e13) {
71
- return new Date(value); // Already in milliseconds
72
- }
73
-
74
- // Handle timestamps in microseconds (less than 1e16)
75
- if (value < 1e16) {
76
- return new Date(value / 1000); // Convert microseconds to milliseconds
77
- }
78
- }
79
-
80
- // All other types are unsupported and result in 'Invalid Date'
81
- return 'Invalid Date';
82
- }
@@ -1,89 +0,0 @@
1
- import React from 'react';
2
-
3
- import timeToString from './timeToString.js';
4
- import useDateFNSLocale from './useDateFNSLocale.js';
5
- import { InvalidDate } from './InvalidDate.jsx';
6
- import { splDatetimeToIso } from './splDatetimeToIso';
7
-
8
- // Component that displays the absolute time and shows the relative time on hover
9
- export function DateTime(props) {
10
- if (props.value == undefined) {
11
- return (
12
- <span className='datetime'>{' '}</span>
13
- );
14
- }
15
-
16
- // Declaration of locale must be below span returned for `undefined` values to avoid bad react state handling in useDateFNSLocale
17
- const locale = useDateFNSLocale();
18
-
19
- const datetime = validateDateTime(props.value);
20
-
21
- if (datetime.toString() === 'Invalid Date') {
22
- return (
23
- <InvalidDate />
24
- );
25
- }
26
-
27
- const date = timeToString(datetime, props.dateTimeFormat, locale);
28
-
29
- // Check for invalid date from timeToString method
30
- if (date === 'Invalid Date') {
31
- return (
32
- <InvalidDate />
33
- );
34
- }
35
-
36
- return (
37
- <span
38
- className='datetime text-nowrap'
39
- title={date.distanceToNow}
40
- >
41
- <i className='bi bi-clock pe-1' />
42
- {date.date}
43
- </span>
44
- );
45
- }
46
-
47
- function validateDateTime(value) {
48
- // Return 'Invalid Date' if the input is null or undefined
49
- if (value == null) {
50
- return 'Invalid Date';
51
- }
52
-
53
- // Handle BigInt values explicitly
54
- if (typeof value === 'bigint') {
55
- // SP-Lang datetime format is represented as BigInt
56
- return splDatetimeToIso(value);
57
- }
58
-
59
- // Handle string values
60
- if (typeof value === 'string') {
61
- return new Date(value);
62
- }
63
-
64
- // Handle number values
65
- if (typeof value === 'number') {
66
- // Reject infinite, NaN, or negative numbers
67
- if (!Number.isFinite(value) || value < 0) {
68
- return 'Invalid Date';
69
- }
70
-
71
- // Handle Unix timestamp in seconds (less than 1e10)
72
- if (value < 1e10) {
73
- return new Date(value * 1000); // Convert seconds to milliseconds
74
- }
75
-
76
- // Handle timestamps in milliseconds (less than 1e13)
77
- if (value < 1e13) {
78
- return new Date(value); // Already in milliseconds
79
- }
80
-
81
- // Handle timestamps in microseconds (less than 1e16)
82
- if (value < 1e16) {
83
- return new Date(value / 1000); // Convert microseconds to milliseconds
84
- }
85
- }
86
-
87
- // All other types are unsupported and result in 'Invalid Date'
88
- return 'Invalid Date';
89
- }
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _dateFns = require("date-fns");
8
- var timeToString = function timeToString(value) {
9
- var dateTimeFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "medium";
10
- var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
11
- if (value == undefined) {
12
- return 'Invalid Date';
13
- }
14
- if (new Date(value).toString() === "Invalid Date") {
15
- return 'Invalid Date';
16
- }
17
-
18
- // TODO: uncomment to eventually add more defensiveness on dateTimeFormat
19
- // try {
20
- // format(value, dateTimeFormat);
21
- // } catch(e) {
22
- // console.error(`ASAB WebUI Components: DateTime - Invalid date time format ${dateTimeFormat}. The format is set to its default.`);
23
- // dateTimeFormat = "medium";
24
- // }
25
-
26
- var date;
27
- if (isNaN(value) == true) {
28
- // Checking dates for parsing
29
- if ((0, _dateFns.parseISO)(value) == "Invalid Date") {
30
- return 'Invalid Date';
31
- } else {
32
- date = formatDate((0, _dateFns.parseISO)(value), dateTimeFormat, locale);
33
- }
34
- } else {
35
- if (value > 9999999999) {
36
- date = formatDate(value, dateTimeFormat, locale);
37
- } else {
38
- date = formatDate(value * 1000, dateTimeFormat, locale);
39
- }
40
- }
41
- return {
42
- date: date.date,
43
- distanceToNow: date.distanceToNow
44
- };
45
- };
46
- var formatDate = (value, dateTimeFormat, locale) => {
47
- switch (dateTimeFormat) {
48
- case "long":
49
- return {
50
- date: (0, _dateFns.format)(value, 'PPpp', {
51
- locale
52
- }),
53
- distanceToNow: (0, _dateFns.formatDistanceToNow)(value, {
54
- addSuffix: true,
55
- locale: locale
56
- })
57
- };
58
- case "iso":
59
- return {
60
- date: (0, _dateFns.formatISO)(value),
61
- distanceToNow: (0, _dateFns.formatDistanceToNow)(value, {
62
- addSuffix: true,
63
- locale: locale
64
- })
65
- };
66
- case "medium":
67
- return {
68
- date: (0, _dateFns.format)(value, 'PPp', {
69
- locale
70
- }),
71
- distanceToNow: (0, _dateFns.formatDistanceToNow)(value, {
72
- addSuffix: true,
73
- locale: locale
74
- })
75
- };
76
- default:
77
- return {
78
- date: (0, _dateFns.format)(value, dateTimeFormat),
79
- distanceToNow: (0, _dateFns.formatDistanceToNow)(value, {
80
- addSuffix: true,
81
- locale: locale
82
- })
83
- };
84
- }
85
- };
86
- var _default = exports.default = timeToString;