@carlonicora/nextjs-jsonapi 4.0.5 → 4.0.6
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/{BlockNoteEditor-L3STMBP2.mjs → BlockNoteEditor-6CTF5DEV.mjs} +2 -2
- package/dist/{BlockNoteEditor-H6EXQD46.js → BlockNoteEditor-JJ3S5COJ.js} +9 -9
- package/dist/{BlockNoteEditor-H6EXQD46.js.map → BlockNoteEditor-JJ3S5COJ.js.map} +1 -1
- package/dist/billing/index.js +335 -335
- package/dist/billing/index.mjs +1 -1
- package/dist/{chunk-3JET3LL7.js → chunk-XUUHPYMM.js} +14 -12
- package/dist/chunk-XUUHPYMM.js.map +1 -0
- package/dist/{chunk-KX2776OK.mjs → chunk-Y2AWOWWH.mjs} +14 -12
- package/dist/chunk-Y2AWOWWH.mjs.map +1 -0
- package/dist/client/index.js +2 -2
- package/dist/client/index.mjs +1 -1
- package/dist/components/index.js +2 -2
- package/dist/components/index.mjs +1 -1
- package/dist/contexts/index.js +2 -2
- package/dist/contexts/index.mjs +1 -1
- package/dist/features/analytics/index.js +88 -88
- package/dist/features/analytics/index.mjs +1 -1
- package/dist/features/help/index.js +31 -31
- package/dist/features/help/index.mjs +1 -1
- package/dist/features/tokenusage/index.js +75 -75
- package/dist/features/tokenusage/index.mjs +1 -1
- package/package.json +1 -1
- package/src/shadcnui/ui/__tests__/sidebar.session.test.tsx +136 -0
- package/src/shadcnui/ui/sidebar.tsx +21 -13
- package/dist/chunk-3JET3LL7.js.map +0 -1
- package/dist/chunk-KX2776OK.mjs.map +0 -1
- /package/dist/{BlockNoteEditor-L3STMBP2.mjs.map → BlockNoteEditor-6CTF5DEV.mjs.map} +0 -0
|
@@ -37,7 +37,7 @@ var _chunkC2WQXUL5js = require('../../chunk-C2WQXUL5.js');
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
var
|
|
40
|
+
var _chunkXUUHPYMMjs = require('../../chunk-XUUHPYMM.js');
|
|
41
41
|
require('../../chunk-7ZRQOLSV.js');
|
|
42
42
|
require('../../chunk-G4JR3SFV.js');
|
|
43
43
|
|
|
@@ -82,7 +82,7 @@ function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, o
|
|
|
82
82
|
};
|
|
83
83
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
84
84
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "max-md:w-full max-md:[&_#date]:w-full", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
85
|
-
|
|
85
|
+
_chunkXUUHPYMMjs.DateRangeSelector,
|
|
86
86
|
{
|
|
87
87
|
onDateChange: (range) => {
|
|
88
88
|
if (!_optionalChain([range, 'optionalAccess', _ => _.from]) || !_optionalChain([range, 'optionalAccess', _2 => _2.to])) return;
|
|
@@ -117,16 +117,16 @@ function TokenUsageAdminFilterBar({ granularity, companyId, metric, companies, o
|
|
|
117
117
|
}
|
|
118
118
|
),
|
|
119
119
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
120
|
-
|
|
120
|
+
_chunkXUUHPYMMjs.Select,
|
|
121
121
|
{
|
|
122
122
|
items: companyItems,
|
|
123
123
|
value: _nullishCoalesce(companyId, () => ( ALL_COMPANIES)),
|
|
124
124
|
onValueChange: (value) => onChange({ companyId: !value || value === ALL_COMPANIES ? void 0 : value }),
|
|
125
125
|
children: [
|
|
126
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
127
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
128
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
129
|
-
companies.map((company) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
126
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectTrigger, { className: "w-56", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectValue, { placeholder: t("token_usage.admin.all_companies") }) }),
|
|
127
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.SelectContent, { children: [
|
|
128
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectItem, { value: ALL_COMPANIES, children: t("token_usage.admin.all_companies") }),
|
|
129
|
+
companies.map((company) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectItem, { value: company.id, children: company.label }, company.id))
|
|
130
130
|
] })
|
|
131
131
|
]
|
|
132
132
|
}
|
|
@@ -149,7 +149,7 @@ function Segmented({
|
|
|
149
149
|
children: options.map((option) => {
|
|
150
150
|
const selected = option.value === value;
|
|
151
151
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
152
|
-
|
|
152
|
+
_chunkXUUHPYMMjs.Button,
|
|
153
153
|
{
|
|
154
154
|
type: "button",
|
|
155
155
|
size: "sm",
|
|
@@ -231,7 +231,7 @@ var TokenUsageAdminProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
|
|
|
231
231
|
pageUrl = TOKEN_USAGE_ADMIN_PAGE_URL
|
|
232
232
|
}) => {
|
|
233
233
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
234
|
-
const generateUrl =
|
|
234
|
+
const generateUrl = _chunkXUUHPYMMjs.usePageUrlGenerator.call(void 0, );
|
|
235
235
|
const [filters, setFilterState] = _react.useState.call(void 0, () => {
|
|
236
236
|
const range = defaultRange();
|
|
237
237
|
return {
|
|
@@ -349,7 +349,7 @@ var TokenUsageAdminProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
|
|
|
349
349
|
error
|
|
350
350
|
]
|
|
351
351
|
);
|
|
352
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
352
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SharedProvider, { value: { breadcrumbs: breadcrumb(), title: title() }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageAdminContext.Provider, { value: contextValue, children }) });
|
|
353
353
|
}, "TokenUsageAdminProvider");
|
|
354
354
|
var useTokenUsageAdmin = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
|
|
355
355
|
const ctx = _react.useContext.call(void 0, TokenUsageAdminContext);
|
|
@@ -446,7 +446,7 @@ function LeadTile({
|
|
|
446
446
|
previousLabel,
|
|
447
447
|
decimal
|
|
448
448
|
}) {
|
|
449
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
449
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": testId, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
450
450
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: label }),
|
|
451
451
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-primary text-xl font-semibold tabular-nums", children: value }),
|
|
452
452
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-1", children: [
|
|
@@ -463,7 +463,7 @@ function SupportingTile({
|
|
|
463
463
|
delta,
|
|
464
464
|
decimal
|
|
465
465
|
}) {
|
|
466
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
466
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": testId, size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
467
467
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: label }),
|
|
468
468
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-2", children: [
|
|
469
469
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm font-medium tabular-nums", children: value }),
|
|
@@ -560,8 +560,8 @@ function TokenUsageBreakdownTable({ rows, metric }) {
|
|
|
560
560
|
// The package's <Table> wraps itself in an `overflow-x-clip` container, which
|
|
561
561
|
// would swallow the overflow before this scroller ever saw it — hence the
|
|
562
562
|
// child override. Wide metric tables must scroll, never widen the page.
|
|
563
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "overflow-x-auto [&_[data-slot=table-container]]:overflow-x-visible", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
564
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
563
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "overflow-x-auto [&_[data-slot=table-container]]:overflow-x-visible", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Table, { children: [
|
|
564
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableRow, { children: columns.map((column) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableHead, { className: _chunk5PNDDYGLjs.cn.call(void 0, column.numeric && "text-end"), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
565
565
|
"button",
|
|
566
566
|
{
|
|
567
567
|
type: "button",
|
|
@@ -576,20 +576,20 @@ function TokenUsageBreakdownTable({ rows, metric }) {
|
|
|
576
576
|
]
|
|
577
577
|
}
|
|
578
578
|
) }, column.key)) }) }),
|
|
579
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
579
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableBody, { children: sortedRows.map((row) => {
|
|
580
580
|
const value = _chunkC2WQXUL5js.metricValue.call(void 0, row, metric);
|
|
581
581
|
const share = total > 0 ? value / total * 100 : 0;
|
|
582
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
583
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
584
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
585
|
-
showActiveUsers && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
586
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
587
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
588
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
589
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
590
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
591
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
592
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
582
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.TableRow, { "data-testid": `breakdown-row-${row.id}`, children: [
|
|
583
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-xs", children: row.id === "other" ? t("token_usage.admin.other") : row.label }),
|
|
584
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-muted-foreground text-xs", children: _nullishCoalesce(row.sublabel, () => ( "")) }),
|
|
585
|
+
showActiveUsers && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: row.activeUsers === void 0 ? "" : decimal(row.activeUsers, 0) }),
|
|
586
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.calls, 0) }),
|
|
587
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.tokensIn, 0) }),
|
|
588
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: decimal(row.tokensOut, 0) }),
|
|
589
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: percent(_chunkC2WQXUL5js.cacheHitPercentage.call(void 0, row.cached, row.tokensIn)) }),
|
|
590
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: formatValue(row.cost, "cost") }),
|
|
591
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: formatValue(row.credits, "credits") }),
|
|
592
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.TableCell, { className: "text-end text-xs tabular-nums", children: percent(share) })
|
|
593
593
|
] }, row.id);
|
|
594
594
|
}) })
|
|
595
595
|
] }) })
|
|
@@ -757,7 +757,7 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
|
757
757
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className, dir: "ltr", children: [
|
|
758
758
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "sr-only", "data-testid": "timeline-data", children: JSON.stringify(chartData) }),
|
|
759
759
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "sr-only", "data-testid": "timeline-series", children: JSON.stringify(seriesKeys) }),
|
|
760
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
760
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.ChartContainer, { config: chartConfig, className: "aspect-auto h-72 w-full", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _recharts.BarChart, { accessibilityLayer: true, data: chartData, margin: { top: 8, right: 8, bottom: 0, left: 0 }, children: [
|
|
761
761
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _recharts.CartesianGrid, { vertical: false }),
|
|
762
762
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
763
763
|
_recharts.XAxis,
|
|
@@ -781,10 +781,10 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
|
781
781
|
}
|
|
782
782
|
),
|
|
783
783
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
784
|
-
|
|
784
|
+
_chunkXUUHPYMMjs.ChartTooltip,
|
|
785
785
|
{
|
|
786
786
|
content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
787
|
-
|
|
787
|
+
_chunkXUUHPYMMjs.ChartTooltipContent,
|
|
788
788
|
{
|
|
789
789
|
labelFormatter: (value) => bucketDate(String(value), granularity),
|
|
790
790
|
valueFormatter: (value) => formatValue(Number(value), metric),
|
|
@@ -793,7 +793,7 @@ function TokenUsageTimelineChart({ rows, metric, stackBy, className }) {
|
|
|
793
793
|
)
|
|
794
794
|
}
|
|
795
795
|
),
|
|
796
|
-
seriesKeys.length >= 2 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
796
|
+
seriesKeys.length >= 2 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.ChartLegend, { content: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.ChartLegendContent, {}) }) : null,
|
|
797
797
|
seriesKeys.map((series, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
798
798
|
_recharts.Bar,
|
|
799
799
|
{
|
|
@@ -845,19 +845,19 @@ function TokenUsageAdminContainer() {
|
|
|
845
845
|
[t]
|
|
846
846
|
);
|
|
847
847
|
if (error) {
|
|
848
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
848
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-destructive text-xs/relaxed", children: error }) }) }) }) });
|
|
849
849
|
}
|
|
850
|
-
if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
850
|
+
if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true });
|
|
851
851
|
const emptyLabel = t("token_usage.admin.no_data");
|
|
852
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
852
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col gap-4 p-4", children: [
|
|
853
853
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageAdminTiles, { summary, metric: filters.metric, singleCustomerMode: hidePlatform }),
|
|
854
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
855
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
856
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
857
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
854
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
855
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: [
|
|
856
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.usage_over_time") }),
|
|
857
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardAction, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
|
|
858
858
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.admin.stack_by") }),
|
|
859
859
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
860
|
-
|
|
860
|
+
_chunkXUUHPYMMjs.Select,
|
|
861
861
|
{
|
|
862
862
|
items: stackByItems,
|
|
863
863
|
value: filters.stackBy,
|
|
@@ -865,29 +865,29 @@ function TokenUsageAdminContainer() {
|
|
|
865
865
|
if (value) setFilters({ stackBy: value });
|
|
866
866
|
},
|
|
867
867
|
children: [
|
|
868
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
869
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
868
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectTrigger, { size: "sm", className: "w-36", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectValue, {}) }),
|
|
869
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectContent, { children: STACK_BY_VALUES.map((value) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SelectItem, { value, children: stackByItems[value] }, value)) })
|
|
870
870
|
]
|
|
871
871
|
}
|
|
872
872
|
)
|
|
873
873
|
] }) })
|
|
874
874
|
] }),
|
|
875
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
875
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageTimelineChart, { rows: timeline, metric: filters.metric, stackBy: filters.stackBy }) })
|
|
876
876
|
] }),
|
|
877
877
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-4 md:grid-cols-2", children: [
|
|
878
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
879
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
880
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
878
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
879
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.by_company") }) }),
|
|
880
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byCompany, metric: filters.metric, emptyLabel }) })
|
|
881
881
|
] }),
|
|
882
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
883
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
884
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
882
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
883
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.by_user") }) }),
|
|
884
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byUser, metric: filters.metric, emptyLabel }) })
|
|
885
885
|
] })
|
|
886
886
|
] }),
|
|
887
887
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunk5PNDDYGLjs.cn.call(void 0, "grid gap-4", !hidePlatform && "md:grid-cols-2"), children: [
|
|
888
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
889
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
890
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
888
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
889
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.customer_by_operation") }) }),
|
|
890
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
891
891
|
TokenUsageRankedBar,
|
|
892
892
|
{
|
|
893
893
|
rows: byCustomerOperation,
|
|
@@ -897,9 +897,9 @@ function TokenUsageAdminContainer() {
|
|
|
897
897
|
}
|
|
898
898
|
) })
|
|
899
899
|
] }),
|
|
900
|
-
!hidePlatform && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
901
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
902
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
900
|
+
!hidePlatform && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
901
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.platform_by_operation") }) }),
|
|
902
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
903
903
|
TokenUsageRankedBar,
|
|
904
904
|
{
|
|
905
905
|
rows: byOperation,
|
|
@@ -910,9 +910,9 @@ function TokenUsageAdminContainer() {
|
|
|
910
910
|
) })
|
|
911
911
|
] })
|
|
912
912
|
] }),
|
|
913
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
914
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
915
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
913
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
914
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.admin.detail") }) }),
|
|
915
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageBreakdownTable, { rows: byCompany, metric: filters.metric }) })
|
|
916
916
|
] })
|
|
917
917
|
] }) });
|
|
918
918
|
}
|
|
@@ -1033,7 +1033,7 @@ var TOKEN_USAGE_REPORT_I18N_KEYS = [
|
|
|
1033
1033
|
|
|
1034
1034
|
function TokenUsageReportFilterBar({ onChange }) {
|
|
1035
1035
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { "data-help": "tokenusage.filters", className: "flex flex-wrap items-center gap-2", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1036
|
-
|
|
1036
|
+
_chunkXUUHPYMMjs.DateRangeSelector,
|
|
1037
1037
|
{
|
|
1038
1038
|
onDateChange: (range) => {
|
|
1039
1039
|
if (!_optionalChain([range, 'optionalAccess', _5 => _5.from]) || !_optionalChain([range, 'optionalAccess', _6 => _6.to])) return;
|
|
@@ -1066,7 +1066,7 @@ var TokenUsageReportProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
|
|
|
1066
1066
|
pageUrl = TOKEN_USAGE_REPORT_PAGE_URL
|
|
1067
1067
|
}) => {
|
|
1068
1068
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
1069
|
-
const generateUrl =
|
|
1069
|
+
const generateUrl = _chunkXUUHPYMMjs.usePageUrlGenerator.call(void 0, );
|
|
1070
1070
|
const [filters, setFilterState] = _react.useState.call(void 0, () => {
|
|
1071
1071
|
const range = defaultRange2();
|
|
1072
1072
|
return { from: _nullishCoalesce(initialFrom, () => ( range.from)), to: _nullishCoalesce(initialTo, () => ( range.to)) };
|
|
@@ -1130,7 +1130,7 @@ var TokenUsageReportProvider = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void
|
|
|
1130
1130
|
() => ({ summary, timeline, byOperation, byTarget, targetPanelTitleKey, filters, setFilters, isLoading, error }),
|
|
1131
1131
|
[summary, timeline, byOperation, byTarget, targetPanelTitleKey, filters, setFilters, isLoading, error]
|
|
1132
1132
|
);
|
|
1133
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1133
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.SharedProvider, { value: { breadcrumbs: breadcrumb(), title: title() }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageReportContext.Provider, { value: contextValue, children }) });
|
|
1134
1134
|
}, "TokenUsageReportProvider");
|
|
1135
1135
|
var useTokenUsageReport = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
|
|
1136
1136
|
const ctx = _react.useContext.call(void 0, TokenUsageReportContext);
|
|
@@ -1158,7 +1158,7 @@ function TokenUsageReportTiles({ summary, metric, balances }) {
|
|
|
1158
1158
|
const monthlyColor = monthlyPercentage > 75 ? "text-success" : monthlyPercentage >= 5 ? "text-warning" : "text-destructive";
|
|
1159
1159
|
const whole = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (value) => decimal(Math.max(0, Math.floor(value)), 0), "whole");
|
|
1160
1160
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-3", children: [
|
|
1161
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1161
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": "tile-used", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
1162
1162
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.report.used_in_period") }),
|
|
1163
1163
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-primary text-xl font-semibold tabular-nums", children: formatValue(_chunkC2WQXUL5js.metricValue.call(void 0, current, metric), metric) }),
|
|
1164
1164
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center gap-1", children: [
|
|
@@ -1174,7 +1174,7 @@ function TokenUsageReportTiles({ summary, metric, balances }) {
|
|
|
1174
1174
|
] })
|
|
1175
1175
|
] }) }),
|
|
1176
1176
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid gap-3 sm:grid-cols-3", children: [
|
|
1177
|
-
balances && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1177
|
+
balances && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": "tile-monthly", size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
1178
1178
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.report.monthly_left") }),
|
|
1179
1179
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-baseline gap-1", children: [
|
|
1180
1180
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { "data-testid": "tile-monthly-value", className: _chunk5PNDDYGLjs.cn.call(void 0, "text-sm font-medium tabular-nums", monthlyColor), children: whole(balances.availableMonthlyCredits) }),
|
|
@@ -1184,11 +1184,11 @@ function TokenUsageReportTiles({ summary, metric, balances }) {
|
|
|
1184
1184
|
] })
|
|
1185
1185
|
] })
|
|
1186
1186
|
] }) }),
|
|
1187
|
-
balances && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1187
|
+
balances && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": "tile-extra", size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
1188
1188
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.report.extra_credits") }),
|
|
1189
1189
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm font-medium tabular-nums", children: whole(balances.availableExtraCredits) })
|
|
1190
1190
|
] }) }),
|
|
1191
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1191
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { "data-testid": "tile-calls", size: "sm", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.CardContent, { className: "grid gap-1", children: [
|
|
1192
1192
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground text-xs", children: t("token_usage.report.calls") }),
|
|
1193
1193
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm font-medium tabular-nums", children: decimal(current.calls, 0) })
|
|
1194
1194
|
] }) })
|
|
@@ -1230,21 +1230,21 @@ function TokenUsageReportContainer({ balances = null }) {
|
|
|
1230
1230
|
const t = _nextintl.useTranslations.call(void 0, );
|
|
1231
1231
|
const { summary, timeline, byOperation, byTarget, isLoading, error, targetPanelTitleKey } = useTokenUsageReport();
|
|
1232
1232
|
if (error) {
|
|
1233
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1233
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.Card, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-destructive text-xs/relaxed", children: error }) }) }) }) });
|
|
1234
1234
|
}
|
|
1235
|
-
if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1235
|
+
if (isLoading) return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true });
|
|
1236
1236
|
const emptyLabel = t("token_usage.report.no_data");
|
|
1237
1237
|
const targetTitle = targetPanelTitleKey && byTarget.length > 0 ? t(targetPanelTitleKey) : void 0;
|
|
1238
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1238
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.RoundPageContainer, { fullWidth: true, forceHeader: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col gap-4 p-4", children: [
|
|
1239
1239
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageReportTiles, { summary, metric: "credits", balances }),
|
|
1240
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1241
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1242
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1240
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
1241
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.report.usage_over_time") }) }),
|
|
1242
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageTimelineChart, { rows: timeline, metric: "credits", stackBy: "type" }) })
|
|
1243
1243
|
] }),
|
|
1244
1244
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunk5PNDDYGLjs.cn.call(void 0, "grid gap-4", targetTitle && "md:grid-cols-2"), children: [
|
|
1245
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1246
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1247
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1245
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
1246
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: t("token_usage.report.by_operation") }) }),
|
|
1247
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1248
1248
|
TokenUsageRankedBar,
|
|
1249
1249
|
{
|
|
1250
1250
|
rows: byOperation,
|
|
@@ -1254,9 +1254,9 @@ function TokenUsageReportContainer({ balances = null }) {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
) })
|
|
1256
1256
|
] }),
|
|
1257
|
-
targetTitle && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1258
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1259
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1257
|
+
targetTitle && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXUUHPYMMjs.Card, { children: [
|
|
1258
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardHeader, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardTitle, { children: targetTitle }) }),
|
|
1259
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXUUHPYMMjs.CardContent, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenUsageRankedBar, { rows: byTarget, metric: "credits", emptyLabel }) })
|
|
1260
1260
|
] })
|
|
1261
1261
|
] })
|
|
1262
1262
|
] }) });
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { act, render, screen } from "@testing-library/react";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { ViewportProvider } from "../../../contexts/ViewportContext";
|
|
4
5
|
import type { SessionSnapshot } from "../../../server/ServerSession";
|
|
5
6
|
import { SidebarProvider, useSidebar, useSidebarControls } from "../sidebar";
|
|
6
7
|
|
|
@@ -131,3 +132,138 @@ describe("SidebarProvider with a session", () => {
|
|
|
131
132
|
expect(screen.getByTestId("state").textContent).toBe("collapsed");
|
|
132
133
|
});
|
|
133
134
|
});
|
|
135
|
+
|
|
136
|
+
describe("SidebarProvider with a session inside a ViewportProvider", () => {
|
|
137
|
+
let viewportListeners: Array<() => void>;
|
|
138
|
+
|
|
139
|
+
function setWidth(width: number) {
|
|
140
|
+
Object.defineProperty(window, "innerWidth", { writable: true, configurable: true, value: width });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function resize(width: number) {
|
|
144
|
+
setWidth(width);
|
|
145
|
+
for (const listener of viewportListeners) listener();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
viewportListeners = [];
|
|
150
|
+
vi.stubGlobal(
|
|
151
|
+
"matchMedia",
|
|
152
|
+
vi.fn(() => ({
|
|
153
|
+
matches: false,
|
|
154
|
+
addEventListener: (_: string, listener: () => void) => viewportListeners.push(listener),
|
|
155
|
+
removeEventListener: (_: string, listener: () => void) => {
|
|
156
|
+
viewportListeners = viewportListeners.filter((l) => l !== listener);
|
|
157
|
+
},
|
|
158
|
+
})),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
afterEach(() => {
|
|
163
|
+
vi.unstubAllGlobals();
|
|
164
|
+
setWidth(1024);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// The documented 4.0 shell: both providers receive the same session promise.
|
|
168
|
+
function Shell({ session }: { session: Promise<SessionSnapshot> }) {
|
|
169
|
+
return (
|
|
170
|
+
<ViewportProvider session={session}>
|
|
171
|
+
<SidebarProvider session={session}>
|
|
172
|
+
<React.Suspense fallback="waiting">
|
|
173
|
+
<MobileReader />
|
|
174
|
+
</React.Suspense>
|
|
175
|
+
</SidebarProvider>
|
|
176
|
+
</ViewportProvider>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
it("follows the measurement when the session says mobile and the viewport is desktop", async () => {
|
|
181
|
+
setWidth(1280);
|
|
182
|
+
const session = deferred<SessionSnapshot>();
|
|
183
|
+
await act(async () => {
|
|
184
|
+
render(<Shell session={session.promise} />);
|
|
185
|
+
});
|
|
186
|
+
await act(async () => {
|
|
187
|
+
session.resolve(snapshot({ isMobile: true }));
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(screen.getByText("desktop")).toBeInTheDocument();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("follows the measurement when the session says desktop and the viewport is mobile", async () => {
|
|
194
|
+
setWidth(500);
|
|
195
|
+
const session = deferred<SessionSnapshot>();
|
|
196
|
+
await act(async () => {
|
|
197
|
+
render(<Shell session={session.promise} />);
|
|
198
|
+
});
|
|
199
|
+
await act(async () => {
|
|
200
|
+
session.resolve(snapshot({ isMobile: false }));
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(screen.getByText("mobile")).toBeInTheDocument();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("follows a live resize across the breakpoint", async () => {
|
|
207
|
+
setWidth(500);
|
|
208
|
+
const session = deferred<SessionSnapshot>();
|
|
209
|
+
await act(async () => {
|
|
210
|
+
render(<Shell session={session.promise} />);
|
|
211
|
+
});
|
|
212
|
+
await act(async () => {
|
|
213
|
+
session.resolve(snapshot({ isMobile: true }));
|
|
214
|
+
});
|
|
215
|
+
expect(screen.getByText("mobile")).toBeInTheDocument();
|
|
216
|
+
|
|
217
|
+
act(() => resize(1280));
|
|
218
|
+
expect(screen.getByText("desktop")).toBeInTheDocument();
|
|
219
|
+
|
|
220
|
+
act(() => resize(500));
|
|
221
|
+
expect(screen.getByText("mobile")).toBeInTheDocument();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("toggleSidebar acts on the live value", async () => {
|
|
225
|
+
setWidth(1280);
|
|
226
|
+
const session = deferred<SessionSnapshot>();
|
|
227
|
+
function Toggler() {
|
|
228
|
+
const { toggleSidebar, state, openMobile } = useSidebar();
|
|
229
|
+
return (
|
|
230
|
+
<button onClick={toggleSidebar}>
|
|
231
|
+
{state}/{openMobile ? "sheet-open" : "sheet-closed"}
|
|
232
|
+
</button>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
await act(async () => {
|
|
236
|
+
render(
|
|
237
|
+
<ViewportProvider session={session.promise}>
|
|
238
|
+
<SidebarProvider session={session.promise}>
|
|
239
|
+
<React.Suspense fallback="waiting">
|
|
240
|
+
<Toggler />
|
|
241
|
+
</React.Suspense>
|
|
242
|
+
</SidebarProvider>
|
|
243
|
+
</ViewportProvider>,
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
await act(async () => {
|
|
247
|
+
session.resolve(snapshot({ isMobile: true, sidebarOpen: true }));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
act(() => screen.getByRole("button").click());
|
|
251
|
+
expect(screen.getByRole("button").textContent).toBe("collapsed/sheet-closed");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("useSidebarControls never suspends while the session is pending", () => {
|
|
255
|
+
const pending = new Promise<SessionSnapshot>(() => {});
|
|
256
|
+
function ControlsReader() {
|
|
257
|
+
const { state } = useSidebarControls();
|
|
258
|
+
return <p>{state}</p>;
|
|
259
|
+
}
|
|
260
|
+
render(
|
|
261
|
+
<ViewportProvider session={pending}>
|
|
262
|
+
<SidebarProvider session={pending}>
|
|
263
|
+
<ControlsReader />
|
|
264
|
+
</SidebarProvider>
|
|
265
|
+
</ViewportProvider>,
|
|
266
|
+
);
|
|
267
|
+
expect(screen.getByText("expanded")).toBeInTheDocument();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -18,6 +18,7 @@ import { PanelLeftIcon } from "lucide-react";
|
|
|
18
18
|
import { useDir } from "../../contexts/DirectionContext";
|
|
19
19
|
import type { SessionSnapshot } from "../../server/ServerSession";
|
|
20
20
|
import { mapThenable } from "../../utils/map-thenable";
|
|
21
|
+
import { getViewportContext } from "../../utils/use-mobile";
|
|
21
22
|
|
|
22
23
|
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
|
23
24
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
@@ -91,8 +92,9 @@ type SidebarProviderProps = React.ComponentProps<"div"> & {
|
|
|
91
92
|
};
|
|
92
93
|
|
|
93
94
|
function SidebarProvider({ session, ...props }: SidebarProviderProps) {
|
|
94
|
-
// With a session
|
|
95
|
-
//
|
|
95
|
+
// With a session useIsMobile() is never called: it would suspend the
|
|
96
|
+
// provider. The core reads the ViewportProvider's context without unwrapping
|
|
97
|
+
// it; without a session the behaviour is unchanged.
|
|
96
98
|
if (session) return <SidebarProviderCore {...props} session={session} />;
|
|
97
99
|
return <ViewportSidebarProvider {...props} />;
|
|
98
100
|
}
|
|
@@ -113,22 +115,28 @@ function SidebarProviderCore({
|
|
|
113
115
|
children,
|
|
114
116
|
...props
|
|
115
117
|
}: SidebarProviderProps & { viewportIsMobile?: boolean }) {
|
|
118
|
+
// With a session, the live value is the ViewportProvider's: its
|
|
119
|
+
// session-seeded promise first (same snapshot, so SSR and first paint match),
|
|
120
|
+
// then every measurement. Read raw, never unwrapped here, so the provider does
|
|
121
|
+
// not suspend. Outside a ViewportProvider, fall back to the session snapshot.
|
|
122
|
+
const viewport = React.useContext(getViewportContext());
|
|
123
|
+
const hasViewport = viewport !== undefined;
|
|
116
124
|
const sessionIsMobile = React.useMemo(
|
|
117
|
-
() => (session ? mapThenable(session, (s) => s.isMobile) : undefined),
|
|
118
|
-
[session],
|
|
125
|
+
() => (session && !hasViewport ? mapThenable(session, (s) => s.isMobile) : undefined),
|
|
126
|
+
[session, hasViewport],
|
|
119
127
|
);
|
|
120
|
-
const isMobile: boolean | Promise<boolean> =
|
|
128
|
+
const isMobile: boolean | Promise<boolean> = session ? (viewport ?? sessionIsMobile!) : viewportIsMobile;
|
|
121
129
|
|
|
122
130
|
// Synchronous reads (toggle, keyboard shortcut) cannot suspend: they use the
|
|
123
|
-
// last resolved value, false until the
|
|
124
|
-
const isMobileRef = React.useRef<boolean>(
|
|
131
|
+
// last resolved value, false until the first one arrives.
|
|
132
|
+
const isMobileRef = React.useRef<boolean>(typeof isMobile === "boolean" ? isMobile : false);
|
|
125
133
|
React.useEffect(() => {
|
|
126
|
-
if (!
|
|
127
|
-
isMobileRef.current =
|
|
134
|
+
if (!(isMobile instanceof Promise)) {
|
|
135
|
+
isMobileRef.current = isMobile;
|
|
128
136
|
return;
|
|
129
137
|
}
|
|
130
138
|
let cancelled = false;
|
|
131
|
-
|
|
139
|
+
isMobile
|
|
132
140
|
.then((value) => {
|
|
133
141
|
if (!cancelled) isMobileRef.current = value;
|
|
134
142
|
})
|
|
@@ -136,7 +144,7 @@ function SidebarProviderCore({
|
|
|
136
144
|
return () => {
|
|
137
145
|
cancelled = true;
|
|
138
146
|
};
|
|
139
|
-
}, [
|
|
147
|
+
}, [isMobile]);
|
|
140
148
|
|
|
141
149
|
const [openMobile, setOpenMobile] = React.useState(false);
|
|
142
150
|
|
|
@@ -183,9 +191,9 @@ function SidebarProviderCore({
|
|
|
183
191
|
|
|
184
192
|
// Helper to toggle the sidebar.
|
|
185
193
|
const toggleSidebar = React.useCallback(() => {
|
|
186
|
-
const mobile =
|
|
194
|
+
const mobile = typeof isMobile === "boolean" ? isMobile : isMobileRef.current;
|
|
187
195
|
return mobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
|
188
|
-
}, [
|
|
196
|
+
}, [isMobile, setOpen, setOpenMobile]);
|
|
189
197
|
|
|
190
198
|
// Adds a keyboard shortcut to toggle the sidebar.
|
|
191
199
|
React.useEffect(() => {
|