@hitachivantara/uikit-react-core 5.72.1 → 5.73.0

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.
@@ -1,97 +1,72 @@
1
- import dayjs from "dayjs";
2
- import calendar from "dayjs/plugin/calendar";
3
- import duration from "dayjs/plugin/duration";
4
- import localeData from "dayjs/plugin/localeData";
5
- import localizedFormat from "dayjs/plugin/localizedFormat";
6
- import relativeTime from "dayjs/plugin/relativeTime";
7
- import updateLocale from "dayjs/plugin/updateLocale";
8
- const thresholds = [
9
- { l: "s", r: 119, d: "second" },
10
- { l: "m", r: 1 },
11
- { l: "mm", r: 59, d: "minute" },
12
- { l: "h", r: 1 },
13
- { l: "hh", r: 23, d: "hour" },
14
- { l: "d", r: 1 },
15
- { l: "dd", r: 29, d: "day" },
16
- { l: "M", r: 1 },
17
- { l: "MM", r: 11, d: "month" },
18
- { l: "y", r: 17 },
19
- { l: "yy", d: "year" }
20
- ];
21
- dayjs.extend(localeData);
22
- dayjs.extend(duration);
23
- dayjs.extend(calendar);
24
- dayjs.extend(localizedFormat);
25
- dayjs.extend(relativeTime, { thresholds });
26
- dayjs.extend(updateLocale);
27
- const secondsUntilNextDay = (date = /* @__PURE__ */ new Date()) => {
28
- const midnight = new Date(date.getTime());
29
- midnight.setDate(midnight.getDate() + 1);
30
- midnight.setHours(0);
31
- midnight.setMinutes(0);
32
- midnight.setSeconds(0);
33
- midnight.setMilliseconds(0);
34
- return (midnight.getTime() - date.getTime()) / 1e3;
35
- };
36
- const secondsUntilNextWeek = (date = /* @__PURE__ */ new Date()) => {
37
- const firstMonthDayOfWeek = date.getDate() - date.getDay();
38
- const firstMonthDayOfNextWeek = firstMonthDayOfWeek + 7;
39
- const firstDayNextWeek = new Date(date.getTime());
40
- firstDayNextWeek.setDate(firstMonthDayOfNextWeek);
41
- firstDayNextWeek.setHours(0);
42
- firstDayNextWeek.setMinutes(0);
43
- firstDayNextWeek.setSeconds(0);
44
- firstDayNextWeek.setMilliseconds(0);
45
- return (firstDayNextWeek.getTime() - date.getTime()) / 1e3;
46
- };
47
- const formatTimeAgo = (date, locale, showSeconds = false, referenceDate = /* @__PURE__ */ new Date()) => {
48
- const dayReferenceDate = dayjs(referenceDate);
49
- const dayDate = dayjs(date).locale(locale);
50
- const dayDiffSeconds = dayReferenceDate.diff(dayDate, "second");
51
- const formatUseSeconds = showSeconds ? "LTS" : "LT";
52
- if (date.getTime() > referenceDate.getTime()) {
53
- return {
54
- timeAgo: dayDate.format(`L ${formatUseSeconds}`),
55
- delay: (date.getTime() - referenceDate.getTime()) / 1e3
56
- };
57
- }
58
- if (dayDiffSeconds < 120) {
59
- return {
60
- timeAgo: dayjs.duration(dayDiffSeconds, "second").locale(locale).humanize(),
61
- delay: 120 - dayDiffSeconds
62
- };
1
+ const isDateInPeriod = (timeAgoMs, period, referenceDate = /* @__PURE__ */ new Date()) => {
2
+ const date = new Date(timeAgoMs);
3
+ const startOfToday = new Date(referenceDate);
4
+ startOfToday.setHours(0, 0, 0, 0);
5
+ const startOfTomorrow = new Date(startOfToday);
6
+ startOfTomorrow.setDate(startOfToday.getDate() + 1);
7
+ const startOfDayAfterTomorrow = new Date(startOfTomorrow);
8
+ startOfDayAfterTomorrow.setDate(startOfTomorrow.getDate() + 1);
9
+ if (period === "tomorrow") {
10
+ return date >= startOfTomorrow && date < startOfDayAfterTomorrow;
63
11
  }
64
- const dayDiffMinutes = dayReferenceDate.diff(dayDate, "minute");
65
- if (dayDiffMinutes < 60) {
66
- return {
67
- timeAgo: dayjs.duration(-dayDiffMinutes, "minute").locale(locale).humanize(true),
68
- delay: 60 * (dayDiffMinutes + 1) - dayDiffSeconds
69
- };
12
+ if (period === "afterTomorrow") {
13
+ return date >= startOfDayAfterTomorrow;
70
14
  }
71
- if (dayReferenceDate.isSame(dayDate, "day")) {
72
- return {
73
- timeAgo: `${dayDate.calendar(dayReferenceDate)}`,
74
- delay: secondsUntilNextDay(referenceDate)
75
- };
76
- }
77
- if (dayReferenceDate.subtract(1, "day").isSame(dayDate, "day")) {
78
- return {
79
- timeAgo: `${dayDate.calendar(dayReferenceDate)}`,
80
- delay: secondsUntilNextDay(referenceDate)
81
- };
82
- }
83
- if (dayDate.isSame(dayReferenceDate, "week")) {
84
- return {
85
- timeAgo: dayDate.format(`ddd, ${formatUseSeconds}`),
86
- delay: secondsUntilNextWeek(date)
87
- };
15
+ return false;
16
+ };
17
+ const formatTimeAgo = (timeAgoMs, locale, showSeconds = false, referenceDate = /* @__PURE__ */ new Date()) => {
18
+ const relFormatter = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
19
+ const dayFormatter = new Intl.DateTimeFormat(locale, {
20
+ hour: "numeric",
21
+ minute: "numeric",
22
+ second: showSeconds ? "numeric" : void 0
23
+ });
24
+ const weekFormatter = new Intl.DateTimeFormat(locale, {
25
+ weekday: "short",
26
+ hour: "numeric",
27
+ minute: "numeric",
28
+ second: showSeconds ? "numeric" : void 0
29
+ });
30
+ const fullFormatter = new Intl.DateTimeFormat(locale, {
31
+ year: "numeric",
32
+ month: "short",
33
+ day: "numeric",
34
+ hour: "numeric",
35
+ minute: "numeric",
36
+ second: showSeconds ? "numeric" : void 0
37
+ });
38
+ const date = new Date(timeAgoMs);
39
+ const secsInDay = date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds();
40
+ const secsInWeek = date.getDay() * 86400 + secsInDay;
41
+ const secsAgo = Math.floor((referenceDate.getTime() - timeAgoMs) / 1e3);
42
+ const minsAgo = Math.floor(secsAgo / 60);
43
+ switch (true) {
44
+ case isDateInPeriod(timeAgoMs, "afterTomorrow", referenceDate):
45
+ return fullFormatter.format(date);
46
+ case isDateInPeriod(timeAgoMs, "tomorrow", referenceDate):
47
+ return `${relFormatter.format(1, "days")}, ${dayFormatter.format(date)}`;
48
+ case minsAgo < -60:
49
+ return `${relFormatter.format(0, "days")}, ${dayFormatter.format(date)}`;
50
+ case minsAgo < -2:
51
+ return relFormatter.format(-minsAgo, "minutes");
52
+ case secsAgo < 0:
53
+ return `${relFormatter.format(Math.abs(secsAgo), "seconds")}`;
54
+ case secsAgo < 20:
55
+ return relFormatter.format(0, "seconds");
56
+ case minsAgo < 2:
57
+ return relFormatter.format(-secsAgo, "seconds");
58
+ case minsAgo < 60:
59
+ return relFormatter.format(-minsAgo, "minutes");
60
+ case secsAgo < secsInDay:
61
+ return `${relFormatter.format(0, "days")}, ${dayFormatter.format(date)}`;
62
+ case secsAgo < secsInDay + 86400:
63
+ return `${relFormatter.format(-1, "days")}, ${dayFormatter.format(date)}`;
64
+ case secsAgo < secsInWeek:
65
+ return weekFormatter.format(date);
66
+ default:
67
+ return fullFormatter.format(date);
88
68
  }
89
- return {
90
- timeAgo: dayDate.format(`L ${formatUseSeconds}`),
91
- delay: 0
92
- };
93
69
  };
94
70
  export {
95
- formatTimeAgo,
96
- secondsUntilNextDay
71
+ formatTimeAgo
97
72
  };
@@ -1 +1 @@
1
- {"version":3,"file":"formatUtils.js","sources":["../../../src/TimeAgo/formatUtils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport calendar from \"dayjs/plugin/calendar\";\nimport duration from \"dayjs/plugin/duration\";\nimport localeData from \"dayjs/plugin/localeData\";\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\nimport relativeTime from \"dayjs/plugin/relativeTime\";\nimport updateLocale from \"dayjs/plugin/updateLocale\";\n\n/**\n * Relative time thresholds defined by\n * {@link https://xd.adobe.com/view/1b7df235-5cf8-4b51-a2f0-0be1bb591c55-4e2e/ Design System}\n *\n * Implementation using day.js {@link https://day.js.org/docs/en/customization/relative-time relativeTime}\n */\nconst thresholds = [\n { l: \"s\", r: 119, d: \"second\" },\n { l: \"m\", r: 1 },\n { l: \"mm\", r: 59, d: \"minute\" },\n { l: \"h\", r: 1 },\n { l: \"hh\", r: 23, d: \"hour\" },\n { l: \"d\", r: 1 },\n { l: \"dd\", r: 29, d: \"day\" },\n { l: \"M\", r: 1 },\n { l: \"MM\", r: 11, d: \"month\" },\n { l: \"y\", r: 17 },\n { l: \"yy\", d: \"year\" },\n];\n\ndayjs.extend(localeData);\ndayjs.extend(duration);\ndayjs.extend(calendar);\ndayjs.extend(localizedFormat);\ndayjs.extend(relativeTime, { thresholds });\ndayjs.extend(updateLocale);\n\nexport const secondsUntilNextDay = (date = new Date()) => {\n const midnight = new Date(date.getTime());\n\n midnight.setDate(midnight.getDate() + 1);\n midnight.setHours(0);\n midnight.setMinutes(0);\n midnight.setSeconds(0);\n midnight.setMilliseconds(0);\n\n return (midnight.getTime() - date.getTime()) / 1000;\n};\n\nconst secondsUntilNextWeek = (date = new Date()) => {\n const firstMonthDayOfWeek = date.getDate() - date.getDay();\n const firstMonthDayOfNextWeek = firstMonthDayOfWeek + 7; // auto roll over to next month if needed\n\n const firstDayNextWeek = new Date(date.getTime());\n\n firstDayNextWeek.setDate(firstMonthDayOfNextWeek);\n firstDayNextWeek.setHours(0);\n firstDayNextWeek.setMinutes(0);\n firstDayNextWeek.setSeconds(0);\n firstDayNextWeek.setMilliseconds(0);\n\n return (firstDayNextWeek.getTime() - date.getTime()) / 1000;\n};\n\n/**\n * @typedef {Object} TimeAgo\n * @property {string} timeAgo - the formatted date using the \"time ago format\"\n * @property {number} delay - the time until the date needs to be updated\n */\n\n/**\n * Formats a date to the a relative time format using dayjs.\n *\n * @param {Date} date - date to format.\n * @param {String} locale - locale to use.\n * @param {Boolean} [showSeconds=false] - if seconds should be part of the result.\n * @param {Date} referenceDate - reference date to use when formatting (defaults to current date).\n *\n * @return {TimeAgo} the formatted date using the \"time ago format\" and the time until it needs to be updated\n */\nexport const formatTimeAgo = (\n date: Date,\n locale: string,\n showSeconds = false,\n referenceDate = new Date(),\n) => {\n const dayReferenceDate = dayjs(referenceDate);\n const dayDate = dayjs(date).locale(locale);\n\n const dayDiffSeconds = dayReferenceDate.diff(dayDate, \"second\");\n\n const formatUseSeconds = showSeconds ? \"LTS\" : \"LT\";\n\n // check if the date is after the reference date\n if (date.getTime() > referenceDate.getTime()) {\n return {\n timeAgo: dayDate.format(`L ${formatUseSeconds}`),\n delay: (date.getTime() - referenceDate.getTime()) / 1000,\n };\n }\n\n // just now, until the 2 minutes\n if (dayDiffSeconds < 120) {\n return {\n timeAgo: dayjs\n .duration(dayDiffSeconds, \"second\")\n .locale(locale)\n .humanize(),\n delay: 120 - dayDiffSeconds,\n };\n }\n\n // ago in minutes, until the 1 hour mark\n const dayDiffMinutes = dayReferenceDate.diff(dayDate, \"minute\");\n\n if (dayDiffMinutes < 60) {\n return {\n timeAgo: dayjs\n .duration(-dayDiffMinutes, \"minute\")\n .locale(locale)\n .humanize(true),\n delay: 60 * (dayDiffMinutes + 1) - dayDiffSeconds,\n };\n }\n\n // formatted date with text description for today\n if (dayReferenceDate.isSame(dayDate, \"day\")) {\n return {\n timeAgo: `${dayDate.calendar(dayReferenceDate)}`,\n delay: secondsUntilNextDay(referenceDate),\n };\n }\n\n // formatted date with text description for yesterday\n if (dayReferenceDate.subtract(1, \"day\").isSame(dayDate, \"day\")) {\n return {\n timeAgo: `${dayDate.calendar(dayReferenceDate)}`,\n delay: secondsUntilNextDay(referenceDate),\n };\n }\n\n // formatted date with week during the current week\n if (dayDate.isSame(dayReferenceDate, \"week\")) {\n return {\n timeAgo: dayDate.format(`ddd, ${formatUseSeconds}`),\n delay: secondsUntilNextWeek(date),\n };\n }\n\n // formatted without special gimmicks\n return {\n timeAgo: dayDate.format(`L ${formatUseSeconds}`),\n delay: 0,\n };\n};\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,aAAa;AAAA,EACjB,EAAE,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS;AAAA,EAC9B,EAAE,GAAG,KAAK,GAAG,EAAE;AAAA,EACf,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;AAAA,EAC9B,EAAE,GAAG,KAAK,GAAG,EAAE;AAAA,EACf,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;AAAA,EAC5B,EAAE,GAAG,KAAK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OAAO,KAAK,gBAAgB,EAAE;AAAA,IAC/C,OAAO;AAAA,EAAA;AAEX;"}
1
+ {"version":3,"file":"formatUtils.js","sources":["../../../src/TimeAgo/formatUtils.ts"],"sourcesContent":["const isDateInPeriod = (\n timeAgoMs: number,\n period: \"tomorrow\" | \"afterTomorrow\",\n referenceDate = new Date(),\n) => {\n const date = new Date(timeAgoMs);\n\n const startOfToday = new Date(referenceDate);\n startOfToday.setHours(0, 0, 0, 0);\n const startOfTomorrow = new Date(startOfToday);\n startOfTomorrow.setDate(startOfToday.getDate() + 1);\n const startOfDayAfterTomorrow = new Date(startOfTomorrow);\n startOfDayAfterTomorrow.setDate(startOfTomorrow.getDate() + 1);\n\n if (period === \"tomorrow\") {\n return date >= startOfTomorrow && date < startOfDayAfterTomorrow;\n }\n if (period === \"afterTomorrow\") {\n return date >= startOfDayAfterTomorrow;\n }\n return false;\n};\n\n/**\n * Relative time thresholds defined by\n * {@link https://xd.adobe.com/view/1b7df235-5cf8-4b51-a2f0-0be1bb591c55-4e2e/ Design System}\n */\nexport const formatTimeAgo = (\n timeAgoMs: number,\n locale: Intl.LocalesArgument,\n showSeconds = false,\n referenceDate = new Date(),\n) => {\n const relFormatter = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\" });\n const dayFormatter = new Intl.DateTimeFormat(locale, {\n hour: \"numeric\",\n minute: \"numeric\",\n second: showSeconds ? \"numeric\" : undefined,\n });\n const weekFormatter = new Intl.DateTimeFormat(locale, {\n weekday: \"short\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: showSeconds ? \"numeric\" : undefined,\n });\n const fullFormatter = new Intl.DateTimeFormat(locale, {\n year: \"numeric\",\n month: \"short\",\n day: \"numeric\",\n hour: \"numeric\",\n minute: \"numeric\",\n second: showSeconds ? \"numeric\" : undefined,\n });\n const date = new Date(timeAgoMs);\n const secsInDay =\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds();\n const secsInWeek = date.getDay() * 86400 + secsInDay;\n\n const secsAgo = Math.floor((referenceDate.getTime() - timeAgoMs) / 1000);\n const minsAgo = Math.floor(secsAgo / 60);\n\n switch (true) {\n case isDateInPeriod(timeAgoMs, \"afterTomorrow\", referenceDate):\n return fullFormatter.format(date);\n case isDateInPeriod(timeAgoMs, \"tomorrow\", referenceDate):\n return `${relFormatter.format(1, \"days\")}, ${dayFormatter.format(date)}`;\n case minsAgo < -60: // Future date more than 1 hour ahead\n return `${relFormatter.format(0, \"days\")}, ${dayFormatter.format(date)}`;\n case minsAgo < -2: // Future date more than 2 minutes ahead\n return relFormatter.format(-minsAgo, \"minutes\");\n case secsAgo < 0: // Future date within 1 minute\n return `${relFormatter.format(Math.abs(secsAgo), \"seconds\")}`;\n case secsAgo < 20:\n return relFormatter.format(0, \"seconds\");\n case minsAgo < 2:\n return relFormatter.format(-secsAgo, \"seconds\");\n case minsAgo < 60:\n return relFormatter.format(-minsAgo, \"minutes\");\n case secsAgo < secsInDay: // today\n return `${relFormatter.format(0, \"days\")}, ${dayFormatter.format(date)}`;\n case secsAgo < secsInDay + 86400: // yesterday\n return `${relFormatter.format(-1, \"days\")}, ${dayFormatter.format(date)}`;\n case secsAgo < secsInWeek: // this week\n return weekFormatter.format(date);\n default:\n return fullFormatter.format(date);\n }\n};\n"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,CACrB,WACA,QACA,gBAAgB,oBAAI,WACjB;AACG,QAAA,OAAO,IAAI,KAAK,SAAS;AAEzB,QAAA,eAAe,IAAI,KAAK,aAAa;AAC3C,eAAa,SAAS,GAAG,GAAG,GAAG,CAAC;AAC1B,QAAA,kBAAkB,IAAI,KAAK,YAAY;AAC7C,kBAAgB,QAAQ,aAAa,QAAQ,IAAI,CAAC;AAC5C,QAAA,0BAA0B,IAAI,KAAK,eAAe;AACxD,0BAAwB,QAAQ,gBAAgB,QAAQ,IAAI,CAAC;AAE7D,MAAI,WAAW,YAAY;AAClB,WAAA,QAAQ,mBAAmB,OAAO;AAAA,EAC3C;AACA,MAAI,WAA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AAK,UAAU;AACb,aAAO,aAAa,OAAO,CAAC,SAAS,SAAS;AAAA,IAChD,KAAK,UAAU;AACN,aAAA,GAAG,aAAa,OAAO,KAAK,IAAI,OAAO,GAAG,SAAS,CAAC;AAAA,IAC7D,KAAK,UAAU;AACN,aAAA,aAAa,OAAO,GAAG,SAAS;AAAA,IACzC,KAAK,UAAU;AACb,aAAO,aAAa,OAAO,CAAC,SAAS,SAAS;AAAA,IAChD,KAAK,UAAU;AACb,aAAO,aAAa,OAAO,CAAC,SAAS,SAAS;AAAA,IAChD,KAAK,UAAU;AACN,aAAA,GAAG,aAAa,OAAO,GAAG,MAAM,CAAC,KAAK,aAAa,OAAO,IAAI,CAAC;AAAA,IACxE,KAAK,UAAU,YAAY;AAClB,aAAA,GAAG,aAAa,OAAO,IAAI,MAAM,CAAC,KAAK,aAAa,OAAO,IAAI,CAAC;AAAA,IACzE,KAAK,UAAU;AACN,aAAA,cAAc,OAAO,IAAI;AAAA,IAClC;AACS,aAAA,cAAc,OAAO,IAAI;AAAA,EACpC;AACF;"}
@@ -3,12 +3,14 @@ import { formatTimeAgo } from "./formatUtils.js";
3
3
  import { useTimeout } from "./useTimeout.js";
4
4
  const fmt = (timestamp, locale, showSeconds) => {
5
5
  const timestampMs = String(timestamp).length > 11 ? timestamp : timestamp * 1e3;
6
- return formatTimeAgo(new Date(timestampMs), locale, showSeconds);
6
+ return formatTimeAgo(timestampMs, locale, showSeconds);
7
7
  };
8
- function useTimeAgo(timestamp, options) {
8
+ function useTimeAgo(timestamp = Date.now(), options) {
9
9
  const { locale, disableRefresh = false, showSeconds = false } = options || {};
10
- const [timeAgo, setTimeAgo] = useState(fmt(timestamp, locale, showSeconds));
11
- const refreshTime = disableRefresh ? 0 : timeAgo.delay * 1e3;
10
+ const [timeAgo, setTimeAgo] = useState(
11
+ () => fmt(timestamp, locale, showSeconds)
12
+ );
13
+ const refreshTime = disableRefresh ? 0 : 1e4;
12
14
  useEffect(() => {
13
15
  const newTimeAgo = fmt(timestamp, locale, showSeconds);
14
16
  setTimeAgo(newTimeAgo);
@@ -17,7 +19,7 @@ function useTimeAgo(timestamp, options) {
17
19
  const newTimeAgo = fmt(timestamp, locale, showSeconds);
18
20
  setTimeAgo(newTimeAgo);
19
21
  }, refreshTime);
20
- return timeAgo.timeAgo;
22
+ return timeAgo;
21
23
  }
22
24
  export {
23
25
  useTimeAgo as default
@@ -1 +1 @@
1
- {"version":3,"file":"useTimeAgo.js","sources":["../../../src/TimeAgo/useTimeAgo.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { formatTimeAgo } from \"./formatUtils\";\nimport type { HvTimeAgoProps } from \"./TimeAgo\";\nimport { useTimeout } from \"./useTimeout\";\n\n/**\n * Calls `formatTimeAgo` with timestamp conversion\n */\nconst fmt = (timestamp: any, locale: any, showSeconds?: boolean) => {\n const timestampMs =\n String(timestamp).length > 11 ? timestamp : timestamp * 1000;\n return formatTimeAgo(new Date(timestampMs), locale, showSeconds);\n};\n\nexport default function useTimeAgo(\n timestamp: number | undefined,\n options?: Pick<HvTimeAgoProps, \"locale\" | \"disableRefresh\" | \"showSeconds\">,\n) {\n const { locale, disableRefresh = false, showSeconds = false } = options || {};\n const [timeAgo, setTimeAgo] = useState(fmt(timestamp, locale, showSeconds));\n const refreshTime = disableRefresh ? 0 : timeAgo.delay * 1000;\n\n useEffect(() => {\n const newTimeAgo = fmt(timestamp, locale, showSeconds);\n setTimeAgo(newTimeAgo);\n }, [timestamp, locale, showSeconds]);\n\n useTimeout(() => {\n const newTimeAgo = fmt(timestamp, locale, showSeconds);\n setTimeAgo(newTimeAgo);\n }, refreshTime);\n\n return timeAgo.timeAgo;\n}\n"],"names":[],"mappings":";;;AASA,MAAM,MAAM,CAAC,WAAgB,QAAa,gBAA0B;AAClE,QAAM,cACJ,OAAO,SAAS,EAAE,SAAS,KAAK,YAAY,YAAY;AAC1D,SAAO,cAAc,IAAI,KAAK,WAAW,GAAG,QAAQ,WAAW;AACjE;AAEwB,SAAA,WACtB,WACA,SACA;AACM,QAAA,EAAE,QAAQ,iBAAiB,OAAO,cAAc,MAAM,IAAI,WAAW;AACrE,QAAA,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI,WAAW,QAAQ,WAAW,CAAC;AAC1E,QAAM,cAAc,iBAAiB,IAAI,QAAQ,QAAQ;AAEzD,YAAU,MAAM;AACd,UAAM,aAAa,IAAI,WAAW,QAAQ,WAAW;AACrD,eAAW,UAAU;AAAA,EACpB,GAAA,CAAC,WAAW,QAAQ,WAAW,CAAC;AAEnC,aAAW,MAAM;AACf,UAAM,aAAa,IAAI,WAAW,QAAQ,WAAW;AACrD,eAAW,UAAU;AAAA,KACpB,WAAW;AAEd,SAAO,QAAQ;AACjB;"}
1
+ {"version":3,"file":"useTimeAgo.js","sources":["../../../src/TimeAgo/useTimeAgo.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { formatTimeAgo } from \"./formatUtils\";\nimport type { HvTimeAgoProps } from \"./TimeAgo\";\nimport { useTimeout } from \"./useTimeout\";\n\n/**\n * Calls `formatTimeAgo` with timestamp conversion\n */\nconst fmt = (timestamp: any, locale: any, showSeconds?: boolean) => {\n const timestampMs =\n String(timestamp).length > 11 ? timestamp : timestamp * 1000;\n return formatTimeAgo(timestampMs, locale, showSeconds);\n};\n\nexport default function useTimeAgo(\n timestamp = Date.now(),\n options?: Pick<HvTimeAgoProps, \"locale\" | \"disableRefresh\" | \"showSeconds\">,\n) {\n const { locale, disableRefresh = false, showSeconds = false } = options || {};\n const [timeAgo, setTimeAgo] = useState(() =>\n fmt(timestamp, locale, showSeconds),\n );\n const refreshTime = disableRefresh ? 0 : 10_000;\n\n useEffect(() => {\n const newTimeAgo = fmt(timestamp, locale, showSeconds);\n setTimeAgo(newTimeAgo);\n }, [timestamp, locale, showSeconds]);\n\n useTimeout(() => {\n const newTimeAgo = fmt(timestamp, locale, showSeconds);\n setTimeAgo(newTimeAgo);\n }, refreshTime);\n\n return timeAgo;\n}\n"],"names":[],"mappings":";;;AASA,MAAM,MAAM,CAAC,WAAgB,QAAa,gBAA0B;AAClE,QAAM,cACJ,OAAO,SAAS,EAAE,SAAS,KAAK,YAAY,YAAY;AACnD,SAAA,cAAc,aAAa,QAAQ,WAAW;AACvD;AAEA,SAAwB,WACtB,YAAY,KAAK,IAAA,GACjB,SACA;AACM,QAAA,EAAE,QAAQ,iBAAiB,OAAO,cAAc,MAAM,IAAI,WAAW;AACrE,QAAA,CAAC,SAAS,UAAU,IAAI;AAAA,IAAS,MACrC,IAAI,WAAW,QAAQ,WAAW;AAAA,EAAA;AAE9B,QAAA,cAAc,iBAAiB,IAAI;AAEzC,YAAU,MAAM;AACd,UAAM,aAAa,IAAI,WAAW,QAAQ,WAAW;AACrD,eAAW,UAAU;AAAA,EACpB,GAAA,CAAC,WAAW,QAAQ,WAAW,CAAC;AAEnC,aAAW,MAAM;AACf,UAAM,aAAa,IAAI,WAAW,QAAQ,WAAW;AACrD,eAAW,UAAU;AAAA,KACpB,WAAW;AAEP,SAAA;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useHvTreeItem.js","sources":["../../../../src/TreeView/TreeItem/useHvTreeItem.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport { DescendantContext } from \"../internals/DescendantProvider\";\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\n\nexport function useHvTreeItem(nodeId: string) {\n const { instance, multiSelect } =\n useTreeViewContext<DefaultTreeViewPlugins>();\n const { level = 0 } = React.useContext(DescendantContext);\n\n const expandable = instance ? instance.isNodeExpandable(nodeId) : false;\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const handleExpansion = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n // If already expanded and trying to toggle selection don't close\n if (expandable && !(multiple && instance.isNodeExpanded(nodeId))) {\n instance.toggleNodeExpansion(event, nodeId);\n }\n };\n\n const handleSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n if (multiple) {\n if (event.shiftKey) {\n instance.selectRange(event, { end: nodeId });\n } else {\n instance.selectNode(event, nodeId, true);\n }\n } else {\n instance.selectNode(event, nodeId);\n }\n };\n\n const preventSelection = (event: React.MouseEvent<HTMLDivElement>) => {\n if (event.shiftKey || event.ctrlKey || event.metaKey || disabled) {\n // Prevent text selection\n event.preventDefault();\n }\n };\n\n return {\n instance,\n level,\n disabled,\n expanded,\n selected,\n focused,\n handleExpansion,\n handleSelection,\n preventSelection,\n };\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,cAAc,QAAgB;AAC5C,QAAM,EAAE,UAAU,YAAY,IAC5B,mBAA2C;AAC7C,QAAM,EAAE,QAAQ,EAAA,IAAM,MAAM,WAAW,iBAAiB;AAExD,QAAM,aAAa,WAAW,SAAS,iBAAiB,MAAM,IAAI;AAClE,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,UAAU,WAAW,SAAS,cAAc,MAAM,IAAI;AAC5D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAExD,QAAA,kBAAkB,CAAC,UAA4C;AAC/D,QAAA,CAAC,YAAY,SAAU;AAE3B,QAAI,CAAC,SAAS;AACH,eAAA,UAAU,OAAO,MAAM;AAAA,IAClC;AAEA,UAAM,WACJ,gBAAgB,MAAM,YAAY,MAAM,WAAW,MAAM;AAG3D,QAAI,cAAc,EAAE,YAAY,SAAS,eAAe,MAAM,IAAI;AACvD,eAAA,oBAAoB,OAAO,MAAM;AAAA,IAC5C;AAAA,EAAA;AAGI,QAAA,kBAAkB,CAAC,UAA4C;AAC/D,QAAA,CAAC,YAAY,SAAU;AAE3B,QAAI,CAAC,SAAS;AACH,eAAA,UAAU,OAAO,MAAM;AAAA,IAClC;AAEA,UAAM,WACJ,gBAAgB,MAAM,YAAY,MAAM,WAAW,MAAM;AAE3D,QAAI,UAAU;AACZ,UAAI,MAAM,UAAU;AAClB,iBAAS,YAAY,OAAO,EAAE,KAAK,OAAQ,CAAA;AAAA,MAAA,OACtC;AACI,iBAAA,WAAW,OAAO,QAAQ,IAAI;AAAA,MACzC;AAAA,IAAA,OACK;AACI,eAAA,WAAW,OAAO,MAAM;AAAA,IACnC;AAAA,EAAA;AAGI,QAAA,mBAAmB,CAAC,UAA4C;AACpE,QAAI,MAAM,YAAY,MAAM,WAAW,MAAM,WAAW,UAAU;AAEhE,YAAM,eAAe;AAAA,IACvB;AAAA,EAAA;AAGK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useHvTreeItem.js","sources":["../../../../src/TreeView/TreeItem/useHvTreeItem.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport { DescendantContext } from \"../internals/DescendantProvider\";\nimport { DefaultTreeViewPlugins } from \"../internals/hooks/plugins\";\nimport { useTreeViewContext } from \"../internals/TreeViewProvider\";\n\nexport function useHvTreeItem(nodeId: string) {\n const { instance, multiSelect } =\n useTreeViewContext<DefaultTreeViewPlugins>();\n const { level = 0 } = React.useContext(DescendantContext);\n\n const expandable = instance ? instance.isNodeExpandable(nodeId) : false;\n const expanded = instance ? instance.isNodeExpanded(nodeId) : false;\n const focused = instance ? instance.isNodeFocused(nodeId) : false;\n const selected = instance ? instance.isNodeSelected(nodeId) : false;\n const disabled = instance ? instance.isNodeDisabled(nodeId) : false;\n\n const handleExpansion = (event: React.MouseEvent) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n // If already expanded and trying to toggle selection don't close\n if (expandable && !(multiple && instance.isNodeExpanded(nodeId))) {\n instance.toggleNodeExpansion(event, nodeId);\n }\n };\n\n const handleSelection = (event: React.MouseEvent) => {\n if (!instance || disabled) return;\n\n if (!focused) {\n instance.focusNode(event, nodeId);\n }\n\n const multiple =\n multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);\n\n if (multiple) {\n if (event.shiftKey) {\n instance.selectRange(event, { end: nodeId });\n } else {\n instance.selectNode(event, nodeId, true);\n }\n } else {\n instance.selectNode(event, nodeId);\n }\n };\n\n const preventSelection = (event: React.MouseEvent) => {\n if (event.shiftKey || event.ctrlKey || event.metaKey || disabled) {\n // Prevent text selection\n event.preventDefault();\n }\n };\n\n return {\n instance,\n level,\n disabled,\n expanded,\n selected,\n focused,\n handleExpansion,\n handleSelection,\n preventSelection,\n };\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,cAAc,QAAgB;AAC5C,QAAM,EAAE,UAAU,YAAY,IAC5B,mBAA2C;AAC7C,QAAM,EAAE,QAAQ,EAAA,IAAM,MAAM,WAAW,iBAAiB;AAExD,QAAM,aAAa,WAAW,SAAS,iBAAiB,MAAM,IAAI;AAClE,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,UAAU,WAAW,SAAS,cAAc,MAAM,IAAI;AAC5D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAC9D,QAAM,WAAW,WAAW,SAAS,eAAe,MAAM,IAAI;AAExD,QAAA,kBAAkB,CAAC,UAA4B;AAC/C,QAAA,CAAC,YAAY,SAAU;AAE3B,QAAI,CAAC,SAAS;AACH,eAAA,UAAU,O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