@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.
- package/dist/cjs/Button/Button.cjs +1 -0
- package/dist/cjs/Pagination/Pagination.cjs +7 -7
- package/dist/cjs/TableSection/TableSection.styles.cjs +1 -1
- package/dist/cjs/TimeAgo/TimeAgo.cjs +1 -2
- package/dist/cjs/TimeAgo/formatUtils.cjs +65 -98
- package/dist/cjs/TimeAgo/useTimeAgo.cjs +7 -5
- package/dist/esm/Button/Button.js +1 -0
- package/dist/esm/Button/Button.js.map +1 -1
- package/dist/esm/Pagination/Pagination.js +7 -5
- package/dist/esm/Pagination/Pagination.js.map +1 -1
- package/dist/esm/TableSection/TableSection.styles.js +1 -1
- package/dist/esm/TimeAgo/TimeAgo.js +1 -2
- package/dist/esm/TimeAgo/TimeAgo.js.map +1 -1
- package/dist/esm/TimeAgo/formatUtils.js +66 -91
- package/dist/esm/TimeAgo/formatUtils.js.map +1 -1
- package/dist/esm/TimeAgo/useTimeAgo.js +7 -5
- package/dist/esm/TimeAgo/useTimeAgo.js.map +1 -1
- package/dist/esm/TreeView/TreeItem/useHvTreeItem.js.map +1 -1
- package/dist/types/index.d.ts +58 -58
- package/package.json +6 -6
|
@@ -1,97 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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":["
|
|
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,WAAW,iBAAiB;AAC9B,WAAO,QAAQ;AAAA,EACjB;AACO,SAAA;AACT;AAMa,MAAA,gBAAgB,CAC3B,WACA,QACA,cAAc,OACd,gBAAoB,oBAAA,WACjB;AACG,QAAA,eAAe,IAAI,KAAK,mBAAmB,QAAQ,EAAE,SAAS,QAAQ;AAC5E,QAAM,eAAe,IAAI,KAAK,eAAe,QAAQ;AAAA,IACnD,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ,cAAc,YAAY;AAAA,EAAA,CACnC;AACD,QAAM,gBAAgB,IAAI,KAAK,eAAe,QAAQ;AAAA,IACpD,SAAS;AAAA,IACT,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ,cAAc,YAAY;AAAA,EAAA,CACnC;AACD,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A,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(
|
|
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(
|
|
11
|
-
|
|
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
|
|
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(
|
|
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
|
|
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,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