@meldgrove/ui 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +213 -2
- package/dist/components/alert-dialog.d.ts +18 -0
- package/dist/components/alert-dialog.js +44 -0
- package/dist/components/alert.d.ts +9 -0
- package/dist/components/alert.js +25 -0
- package/dist/components/avatar.d.ts +11 -0
- package/dist/components/avatar.js +24 -0
- package/dist/components/badge.d.ts +9 -0
- package/dist/components/badge.js +25 -0
- package/dist/components/breadcrumb.d.ts +11 -0
- package/dist/components/breadcrumb.js +28 -0
- package/dist/components/button-group.d.ts +11 -0
- package/dist/components/button-group.js +27 -0
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +36 -0
- package/dist/components/calendar.d.ts +8 -0
- package/dist/components/calendar.js +73 -0
- package/dist/components/card.d.ts +9 -0
- package/dist/components/card.js +25 -0
- package/dist/components/chart.d.ts +44 -0
- package/dist/components/chart.js +117 -0
- package/dist/components/checkbox.d.ts +4 -0
- package/dist/components/checkbox.js +10 -0
- package/dist/components/collapsible.d.ts +5 -0
- package/dist/components/collapsible.js +13 -0
- package/dist/components/command.d.ts +18 -0
- package/dist/components/command.js +35 -0
- package/dist/components/confirm-dialog.d.ts +15 -0
- package/dist/components/confirm-dialog.js +26 -0
- package/dist/components/copy-button.d.ts +6 -0
- package/dist/components/copy-button.js +23 -0
- package/dist/components/dialog.d.ts +17 -0
- package/dist/components/dialog.js +39 -0
- package/dist/components/dropdown-menu.d.ts +25 -0
- package/dist/components/dropdown-menu.js +53 -0
- package/dist/components/empty.d.ts +11 -0
- package/dist/components/empty.js +33 -0
- package/dist/components/field.d.ts +24 -0
- package/dist/components/field.js +74 -0
- package/dist/components/hover-card.d.ts +6 -0
- package/dist/components/hover-card.js +16 -0
- package/dist/components/input-group.d.ts +16 -0
- package/dist/components/input-group.js +64 -0
- package/dist/components/input.d.ts +3 -0
- package/dist/components/input.js +7 -0
- package/dist/components/item.d.ts +23 -0
- package/dist/components/item.js +67 -0
- package/dist/components/kbd.d.ts +3 -0
- package/dist/components/kbd.js +11 -0
- package/dist/components/label.d.ts +4 -0
- package/dist/components/label.js +9 -0
- package/dist/components/native-select.d.ts +8 -0
- package/dist/components/native-select.js +14 -0
- package/dist/components/pager.d.ts +7 -0
- package/dist/components/pager.js +11 -0
- package/dist/components/pagination.d.ts +13 -0
- package/dist/components/pagination.js +30 -0
- package/dist/components/popover.d.ts +10 -0
- package/dist/components/popover.js +28 -0
- package/dist/components/progress.d.ts +4 -0
- package/dist/components/progress.js +9 -0
- package/dist/components/radio-group.d.ts +5 -0
- package/dist/components/radio-group.js +13 -0
- package/dist/components/scroll-area.d.ts +5 -0
- package/dist/components/scroll-area.js +12 -0
- package/dist/components/secret-field.d.ts +23 -0
- package/dist/components/secret-field.js +47 -0
- package/dist/components/select.d.ts +15 -0
- package/dist/components/select.js +40 -0
- package/dist/components/separator.d.ts +4 -0
- package/dist/components/separator.js +9 -0
- package/dist/components/sheet.d.ts +14 -0
- package/dist/components/sheet.js +42 -0
- package/dist/components/sidebar.d.ts +70 -0
- package/dist/components/sidebar.js +212 -0
- package/dist/components/skeleton.d.ts +2 -0
- package/dist/components/skeleton.js +6 -0
- package/dist/components/sonner.d.ts +5 -0
- package/dist/components/sonner.js +14 -0
- package/dist/components/spinner.d.ts +2 -0
- package/dist/components/spinner.js +7 -0
- package/dist/components/states.d.ts +14 -0
- package/dist/components/states.js +18 -0
- package/dist/components/switch.d.ts +6 -0
- package/dist/components/switch.js +9 -0
- package/dist/components/table.d.ts +17 -0
- package/dist/components/table.js +34 -0
- package/dist/components/tabs.d.ts +11 -0
- package/dist/components/tabs.js +30 -0
- package/dist/components/textarea.d.ts +3 -0
- package/dist/components/textarea.js +7 -0
- package/dist/components/toggle-group.d.ts +9 -0
- package/dist/components/toggle-group.js +23 -0
- package/dist/components/toggle.d.ts +9 -0
- package/dist/components/toggle.js +27 -0
- package/dist/components/tooltip.d.ts +7 -0
- package/dist/components/tooltip.js +19 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.js +13 -0
- package/dist/lib/format.d.ts +8 -0
- package/dist/lib/format.js +38 -0
- package/dist/lib/i18n-core.d.ts +38 -0
- package/dist/lib/i18n-core.js +61 -0
- package/dist/lib/i18n.d.ts +11 -0
- package/dist/lib/i18n.js +19 -0
- package/dist/lib/portal.d.ts +13 -0
- package/dist/lib/portal.js +17 -0
- package/dist/lib/theme.d.ts +5 -0
- package/dist/lib/theme.js +17 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +5 -0
- package/dist/standalone/meldgrove-updates.js +57 -0
- package/dist/styles.css +11 -0
- package/dist/theme.css +62 -0
- package/dist/tokens.css +94 -0
- package/dist/updates/controller.d.ts +249 -0
- package/dist/updates/controller.js +657 -0
- package/dist/updates/core.d.ts +10 -0
- package/dist/updates/core.js +10 -0
- package/dist/updates/index.d.ts +15 -0
- package/dist/updates/index.js +15 -0
- package/dist/updates/messages.d.ts +92 -0
- package/dist/updates/messages.js +182 -0
- package/dist/updates/notice.d.ts +3 -0
- package/dist/updates/notice.js +6 -0
- package/dist/updates/react.d.ts +56 -0
- package/dist/updates/react.js +72 -0
- package/dist/updates/state.d.ts +224 -0
- package/dist/updates/state.js +411 -0
- package/dist/updates/transport.d.ts +50 -0
- package/dist/updates/transport.js +76 -0
- package/dist/updates/types.d.ts +77 -0
- package/dist/updates/types.js +68 -0
- package/dist/updates/update-button.d.ts +9 -0
- package/dist/updates/update-button.js +161 -0
- package/dist/updates/updates-settings.d.ts +17 -0
- package/dist/updates/updates-settings.js +97 -0
- package/package.json +159 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The update button for the app's top bar (render it for admins only): shows
|
|
3
|
+
* whether an update is available, checks on click, installs on request,
|
|
4
|
+
* follows the installation through the restart and reloads the page when the
|
|
5
|
+
* new version answers. Needs `UpdatesProvider` above it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function UpdateButton({ className }: {
|
|
8
|
+
className?: string;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Download, ExternalLink, LoaderCircle, RefreshCw, TriangleAlert } from "lucide-react";
|
|
5
|
+
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "../components/alert-dialog.js";
|
|
6
|
+
import { Badge } from "../components/badge.js";
|
|
7
|
+
import { Button } from "../components/button.js";
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../components/popover.js";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../components/tooltip.js";
|
|
10
|
+
import { formatDateTime, formatRelative } from "../lib/format.js";
|
|
11
|
+
import { common, translate } from "../lib/i18n.js";
|
|
12
|
+
import { cn } from "../lib/utils.js";
|
|
13
|
+
import { runningVersion } from "./controller.js";
|
|
14
|
+
import { useGuideUrl, useUpdatesController, useUpdatesSnapshot } from "./react.js";
|
|
15
|
+
import { canInstall, failureOf, noteSummary, replacedFailure } from "./state.js";
|
|
16
|
+
function StateIcon({ state }) {
|
|
17
|
+
switch (state) {
|
|
18
|
+
case "checking":
|
|
19
|
+
return _jsx(RefreshCw, { className: "motion-safe:animate-spin" });
|
|
20
|
+
case "installing":
|
|
21
|
+
return _jsx(LoaderCircle, { className: "motion-safe:animate-spin" });
|
|
22
|
+
case "available":
|
|
23
|
+
case "attention":
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx(Download, {}), _jsx("span", { "aria-hidden": true, className: cn("ring-background absolute top-1 right-1 size-2 rounded-full ring-2", state === "available" ? "bg-primary" : "bg-warning") })] }));
|
|
25
|
+
case "failed":
|
|
26
|
+
return _jsx(TriangleAlert, { className: "text-destructive" });
|
|
27
|
+
case "unreachable":
|
|
28
|
+
return _jsx(RefreshCw, { className: "text-muted-foreground opacity-60" });
|
|
29
|
+
default:
|
|
30
|
+
return _jsx(RefreshCw, { className: "text-muted-foreground" });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** The release notes of a release, or the changes (compare view) of a preview. */
|
|
34
|
+
function ReleaseNotesLink({ controller, update }) {
|
|
35
|
+
if (!update.url)
|
|
36
|
+
return null;
|
|
37
|
+
return (_jsxs("a", { href: update.url, target: "_blank", rel: "noreferrer", className: "text-primary inline-flex w-fit items-center gap-1 text-sm font-medium underline-offset-4 hover:underline", children: [controller.t(update.preview ? "changes" : "releaseNotes"), _jsx(ExternalLink, { className: "size-3.5", "aria-hidden": true }), " ", _jsx("span", { className: "sr-only", children: controller.t("opensInNewTab") })] }));
|
|
38
|
+
}
|
|
39
|
+
const STAGES = new Set(["pulling", "starting", "rolling-back", "deploying"]);
|
|
40
|
+
/** In mode off, in place of the install buttons: nothing can install from here. */
|
|
41
|
+
function OffNote({ controller }) {
|
|
42
|
+
const guideUrl = useGuideUrl();
|
|
43
|
+
const [before, after] = controller.t("offText").split("{guide}");
|
|
44
|
+
return (_jsxs("p", { className: "text-muted-foreground text-sm", children: [before, guideUrl ? (_jsx("a", { href: guideUrl, target: "_blank", rel: "noreferrer", className: "text-primary font-medium underline-offset-4 hover:underline", children: controller.t("deploymentGuide") })) : (controller.t("deploymentGuide")), after] }));
|
|
45
|
+
}
|
|
46
|
+
/** In place of "Install anyway…" where the platform's image tag decides: change the tag there. */
|
|
47
|
+
function LockedNote({ controller, version }) {
|
|
48
|
+
return (_jsx("p", { className: "text-muted-foreground text-sm", children: controller.t("attentionLocked", { app: controller.appName, version }) }));
|
|
49
|
+
}
|
|
50
|
+
/** Version, age, preview badge and the change titles of an update. */
|
|
51
|
+
function UpdateSummary({ controller, snapshot, update }) {
|
|
52
|
+
const { notes, more } = noteSummary(update);
|
|
53
|
+
return (_jsxs(_Fragment, { children: [_jsxs("p", { className: "flex flex-wrap items-center gap-x-1.5 gap-y-1 text-sm", children: [_jsx("span", { className: "font-medium", children: update.version }), update.publishedAt ? (_jsxs("span", { className: "text-muted-foreground", title: formatDateTime(update.publishedAt, controller.dateLocale, controller.timeZone), children: ["\u00B7 ", formatRelative(update.publishedAt, controller.locale, snapshot.now)] })) : null, update.preview ? _jsx(Badge, { variant: "secondary", children: controller.t("preview") }) : null] }), notes.length > 0 ? (_jsxs("ul", { className: "grid list-disc gap-1 pl-4 text-sm", children: [notes.map((note, index) => (_jsx("li", { className: "break-words", children: note }, index))), more > 0 ? (_jsx("li", { className: "text-muted-foreground list-none", children: controller.t("moreChanges", { n: more, count: more }) })) : null] })) : null] }));
|
|
54
|
+
}
|
|
55
|
+
function Title({ children }) {
|
|
56
|
+
return _jsx("h2", { className: "text-sm font-semibold break-words", children: children });
|
|
57
|
+
}
|
|
58
|
+
/** In a newer offer: the failure it took the place of. */
|
|
59
|
+
function ReplacedFailure({ controller, snapshot }) {
|
|
60
|
+
const failure = replacedFailure(snapshot.response, snapshot.recent);
|
|
61
|
+
if (!failure)
|
|
62
|
+
return null;
|
|
63
|
+
return (_jsx("p", { className: "text-destructive text-sm break-words", children: failure.message
|
|
64
|
+
? controller.t("failedLine", { version: failure.version, message: failure.message })
|
|
65
|
+
: controller.t("failed", { version: failure.version }) }));
|
|
66
|
+
}
|
|
67
|
+
/** The popover's content for the button's state, with the footer every state shares. */
|
|
68
|
+
function UpdatePanel(props) {
|
|
69
|
+
const { controller, snapshot } = props;
|
|
70
|
+
const t = controller.t;
|
|
71
|
+
const { shown: state, status } = snapshot;
|
|
72
|
+
const running = runningVersion(snapshot.response);
|
|
73
|
+
const failure = failureOf(snapshot.response, snapshot.recent);
|
|
74
|
+
const update = status?.available ?? status?.attention;
|
|
75
|
+
// Mode off: the popover shows the update, but nothing can install from here.
|
|
76
|
+
const installable = status?.mode !== "off";
|
|
77
|
+
let body = null;
|
|
78
|
+
// Only a followed installation shows without a status (the app restarts).
|
|
79
|
+
if (state === "installing") {
|
|
80
|
+
const version = snapshot.pending?.version ?? status?.installing?.version ?? "";
|
|
81
|
+
const stage = status?.installing?.version === version ? status.installing.stage : null;
|
|
82
|
+
body = (_jsxs(_Fragment, { children: [_jsx(Title, { children: t("installing", { version }) }), snapshot.restarting ? (_jsx("p", { className: "text-sm", children: t("restarting") })) : stage && STAGES.has(stage) ? (_jsx("p", { className: "text-sm", children: t(`stage_${stage}`, { version: status?.installed ?? running ?? "" }) })) : null, snapshot.waiting ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t("restarts", { app: controller.appName }) })) : null, snapshot.slow ? (_jsxs(_Fragment, { children: [_jsx("p", { role: "alert", className: "text-destructive text-sm break-words", children: t("slow", { project: controller.project }) }), _jsx(Button, { size: "sm", variant: "outline", className: "w-full", onClick: controller.stopWaiting, children: t("stopWaiting") })] })) : null] }));
|
|
83
|
+
}
|
|
84
|
+
else if (!status) {
|
|
85
|
+
// Every other state has a status (hasPanel).
|
|
86
|
+
}
|
|
87
|
+
else if (state === "failed" && failure) {
|
|
88
|
+
const offer = failure.offer;
|
|
89
|
+
body = (_jsxs(_Fragment, { children: [_jsx(Title, { children: t("failed", { version: failure.version }) }), failure.message ? _jsx("p", { className: "text-destructive text-sm break-words", children: failure.message }) : null, running ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t("stillRunning", { version: running }) })) : null, !installable ? (_jsx(OffNote, { controller: controller })) : offer && canInstall(status, offer) ? (_jsx(Button, { size: "sm", className: "w-full", onClick: () => props.onInstall(offer, offer === status.attention), children: t("tryAgain") })) : offer ? (_jsx(LockedNote, { controller: controller, version: offer.version })) : null] }));
|
|
90
|
+
}
|
|
91
|
+
else if (state === "available" && status.available) {
|
|
92
|
+
const available = status.available;
|
|
93
|
+
const installsAt = available.installsAt;
|
|
94
|
+
body = (_jsxs(_Fragment, { children: [_jsx(Title, { children: t("available") }), _jsx(UpdateSummary, { controller: controller, snapshot: snapshot, update: available }), _jsx(ReplacedFailure, { controller: controller, snapshot: snapshot }), _jsx(ReleaseNotesLink, { controller: controller, update: available }), !installable ? (_jsx(OffNote, { controller: controller })) : (_jsxs(_Fragment, { children: [installsAt ? (_jsx("p", { className: "text-muted-foreground text-sm", children: new Date(installsAt).getTime() > snapshot.now
|
|
95
|
+
? t("installsOn", {
|
|
96
|
+
date: formatDateTime(installsAt, controller.dateLocale, controller.timeZone),
|
|
97
|
+
})
|
|
98
|
+
: t("installsNextCheck") })) : null, _jsx(Button, { size: "sm", className: "w-full", onClick: () => props.onInstall(available, false), children: t("installNow") })] }))] }));
|
|
99
|
+
}
|
|
100
|
+
else if (state === "attention" && status.attention) {
|
|
101
|
+
const attention = status.attention;
|
|
102
|
+
body = (_jsxs(_Fragment, { children: [_jsx(Title, { children: t("attention", { version: attention.version }) }), _jsx("p", { className: "text-sm", children: t("attentionText") }), _jsx(ReplacedFailure, { controller: controller, snapshot: snapshot }), _jsx(ReleaseNotesLink, { controller: controller, update: attention }), !installable ? (_jsx(OffNote, { controller: controller })) : canInstall(status, attention) ? (_jsx(Button, { size: "sm", variant: "outline", className: "w-full", onClick: () => props.onInstall(attention, true), children: t("installAnyway") })) : (_jsx(LockedNote, { controller: controller, version: attention.version }))] }));
|
|
103
|
+
}
|
|
104
|
+
else if (update) {
|
|
105
|
+
body = _jsx(UpdateSummary, { controller: controller, snapshot: snapshot, update: update });
|
|
106
|
+
}
|
|
107
|
+
if (!status)
|
|
108
|
+
return _jsx("div", { className: "grid gap-3", children: body });
|
|
109
|
+
return (_jsxs("div", { className: "grid gap-3", children: [body, _jsxs("div", { className: cn("text-muted-foreground grid gap-1 text-xs", body ? "border-t pt-3" : null), children: [_jsx("p", { children: t("installedFooter", { version: running ?? t("development"), channel: t(status.channel) }) }), _jsxs("p", { className: "flex flex-wrap items-center gap-x-2", children: [_jsx("span", { "aria-live": "polite", children: snapshot.checking
|
|
110
|
+
? t("checking")
|
|
111
|
+
: status.checkedAt
|
|
112
|
+
? t("checked", {
|
|
113
|
+
time: formatRelative(status.checkedAt, controller.locale, snapshot.now),
|
|
114
|
+
})
|
|
115
|
+
: t("notChecked") }), state !== "installing" && !snapshot.checking ? (_jsx(Button, { variant: "link", size: "xs", className: "h-auto p-0 text-xs", onClick: () => void controller.check(), children: t("checkNow") })) : null] }), status.error ? (_jsx("p", { className: "text-destructive break-words", children: t("checkFailed", { error: status.error }) })) : null] })] }));
|
|
116
|
+
}
|
|
117
|
+
/** Asks before an installation; for a release with upgrade steps, names its release notes. */
|
|
118
|
+
function ConfirmInstall(props) {
|
|
119
|
+
const { controller, target } = props;
|
|
120
|
+
const t = controller.t;
|
|
121
|
+
const c = translate(common, controller.locale);
|
|
122
|
+
return (_jsx(AlertDialog, { open: target !== null, onOpenChange: (open) => (open ? undefined : props.onCancel()), children: _jsx(AlertDialogContent, { children: target ? (_jsxs(_Fragment, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: target.anyway
|
|
123
|
+
? t("confirmAnywayTitle", { version: target.update.version })
|
|
124
|
+
: t("confirmTitle", { version: target.update.version }) }), _jsxs(AlertDialogDescription, { children: [target.anyway ? `${t("confirmAnywayText", { app: controller.appName })} ` : null, t("confirmText", { app: controller.appName })] }), target.anyway ? _jsx(ReleaseNotesLink, { controller: controller, update: target.update }) : null] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: c("cancel") }), _jsx(AlertDialogAction, { variant: target.anyway ? "destructive" : "default", onClick: () => props.onConfirm(target.update), children: t("install") })] })] })) : null }) }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The update button for the app's top bar (render it for admins only): shows
|
|
128
|
+
* whether an update is available, checks on click, installs on request,
|
|
129
|
+
* follows the installation through the restart and reloads the page when the
|
|
130
|
+
* new version answers. Needs `UpdatesProvider` above it.
|
|
131
|
+
*/
|
|
132
|
+
export function UpdateButton({ className }) {
|
|
133
|
+
const controller = useUpdatesController();
|
|
134
|
+
const snapshot = useUpdatesSnapshot();
|
|
135
|
+
const [confirm, setConfirm] = useState(null);
|
|
136
|
+
const t = controller.t;
|
|
137
|
+
const { state, status } = snapshot;
|
|
138
|
+
const running = runningVersion(snapshot.response);
|
|
139
|
+
const failure = failureOf(snapshot.response, snapshot.recent);
|
|
140
|
+
const label = {
|
|
141
|
+
loading: t("checkForUpdates"),
|
|
142
|
+
// The route's reason when it has one (the app answers, the update service does not).
|
|
143
|
+
unreachable: snapshot.response?.error ?? t("unreachable"),
|
|
144
|
+
installing: snapshot.restarting
|
|
145
|
+
? t("restarting")
|
|
146
|
+
: t("installing", { version: snapshot.pending?.version ?? status?.installing?.version ?? "" }),
|
|
147
|
+
checking: t("checking"),
|
|
148
|
+
off: t("off"),
|
|
149
|
+
failed: t("failed", { version: failure?.version ?? "" }),
|
|
150
|
+
available: `${t("available")} · ${status?.available?.version ?? ""}`,
|
|
151
|
+
attention: t("attention", { version: status?.attention?.version ?? "" }),
|
|
152
|
+
current: running ? t("upToDateVersion", { version: running }) : t("upToDate"),
|
|
153
|
+
};
|
|
154
|
+
return (_jsxs(TooltipProvider, { children: [_jsxs(Popover, { open: snapshot.open, onOpenChange: controller.setOpen, children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(PopoverTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon-sm", className: cn("relative rounded-full", className), "aria-label": label[state], "data-update-state": state, children: _jsx(StateIcon, { state: state }) }) }) }), _jsx(TooltipContent, { side: "bottom", children: label[state] })] }), _jsx(PopoverContent, { align: "end", className: "w-[min(20rem,calc(100vw-1.5rem))]", children: snapshot.panel ? (_jsx(UpdatePanel, { controller: controller, snapshot: snapshot, onInstall: (update, anyway) => {
|
|
155
|
+
controller.setOpen(false);
|
|
156
|
+
setConfirm({ update, anyway });
|
|
157
|
+
} })) : null })] }), _jsx(ConfirmInstall, { controller: controller, target: confirm, onCancel: () => setConfirm(null), onConfirm: (update) => {
|
|
158
|
+
setConfirm(null);
|
|
159
|
+
void controller.install(update);
|
|
160
|
+
} })] }));
|
|
161
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Translate } from "../lib/i18n.tsx";
|
|
2
|
+
import type { messages } from "./messages.ts";
|
|
3
|
+
import type { UpdaterStatus } from "./types.ts";
|
|
4
|
+
type T = Translate<(typeof messages)["en"]>;
|
|
5
|
+
/** When updates install by themselves on this server. */
|
|
6
|
+
export declare function automaticText(t: T, status: UpdaterStatus): string;
|
|
7
|
+
/**
|
|
8
|
+
* The "Updates" settings: the installed version, the update channel and when
|
|
9
|
+
* updates install automatically. Content only; `UpdatesSettingsCard` puts it
|
|
10
|
+
* in a card. Needs `UpdatesProvider` above it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function UpdatesSettings(): import("react").JSX.Element;
|
|
13
|
+
/** `UpdatesSettings` in a card with the heading "Updates". */
|
|
14
|
+
export declare function UpdatesSettingsCard({ className }: {
|
|
15
|
+
className?: string;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { Alert, AlertDescription } from "../components/alert.js";
|
|
5
|
+
import { Badge } from "../components/badge.js";
|
|
6
|
+
import { Button } from "../components/button.js";
|
|
7
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../components/card.js";
|
|
8
|
+
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet, } from "../components/field.js";
|
|
9
|
+
import { RadioGroup, RadioGroupItem } from "../components/radio-group.js";
|
|
10
|
+
import { Spinner } from "../components/spinner.js";
|
|
11
|
+
import { LoadingState } from "../components/states.js";
|
|
12
|
+
import { errorMessage } from "../lib/i18n.js";
|
|
13
|
+
import { useGuideUrl, useUpdatesController, useUpdatesSnapshot } from "./react.js";
|
|
14
|
+
import { formatRelative } from "../lib/format.js";
|
|
15
|
+
import { cooldownParts, windowParts } from "./state.js";
|
|
16
|
+
function cooldownText(t, cooldown) {
|
|
17
|
+
const parts = cooldownParts(cooldown);
|
|
18
|
+
return parts ? t(parts.unit, { count: parts.count }) : null;
|
|
19
|
+
}
|
|
20
|
+
/** When updates install by themselves on this server. */
|
|
21
|
+
export function automaticText(t, status) {
|
|
22
|
+
if (status.mode === "off" || !status.automatic)
|
|
23
|
+
return t("autoOff");
|
|
24
|
+
if (status.mode === "platform")
|
|
25
|
+
return t("autoPlatform");
|
|
26
|
+
const window = windowParts(status.window);
|
|
27
|
+
const range = window ? { ...window, timezone: status.timezone } : null;
|
|
28
|
+
const cooldown = status.channel === "stable" ? cooldownText(t, status.cooldown) : null;
|
|
29
|
+
if (cooldown) {
|
|
30
|
+
return range ? t("autoReleasesWindow", { cooldown, ...range }) : t("autoReleases", { cooldown });
|
|
31
|
+
}
|
|
32
|
+
return range ? t("autoNextCheckWindow", range) : t("autoNextCheck");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The "Updates" settings: the installed version, the update channel and when
|
|
36
|
+
* updates install automatically. Content only; `UpdatesSettingsCard` puts it
|
|
37
|
+
* in a card. Needs `UpdatesProvider` above it.
|
|
38
|
+
*/
|
|
39
|
+
export function UpdatesSettings() {
|
|
40
|
+
const controller = useUpdatesController();
|
|
41
|
+
const snapshot = useUpdatesSnapshot();
|
|
42
|
+
const guideUrl = useGuideUrl();
|
|
43
|
+
const t = controller.t;
|
|
44
|
+
const id = useId();
|
|
45
|
+
const [choice, setChoice] = useState(null);
|
|
46
|
+
const [error, setError] = useState(null);
|
|
47
|
+
const { response, status } = snapshot;
|
|
48
|
+
const current = status?.channel ?? null;
|
|
49
|
+
// Without a status, no channel is shown as chosen.
|
|
50
|
+
const selected = choice ?? current ?? "";
|
|
51
|
+
const locked = status?.channelLocked ?? null;
|
|
52
|
+
const disabled = !status || locked !== null || snapshot.savingChannel;
|
|
53
|
+
const cooldown = cooldownText(t, status?.cooldown ?? null);
|
|
54
|
+
if (!response) {
|
|
55
|
+
if (snapshot.stopped)
|
|
56
|
+
return _jsx("p", { className: "text-muted-foreground text-sm", children: t("signedOut") });
|
|
57
|
+
return _jsx(LoadingState, {});
|
|
58
|
+
}
|
|
59
|
+
const submit = async () => {
|
|
60
|
+
if (!choice || choice === current)
|
|
61
|
+
return;
|
|
62
|
+
setError(null);
|
|
63
|
+
try {
|
|
64
|
+
// Saved only when the update service answered with the chosen channel; else keep the choice.
|
|
65
|
+
const saved = await controller.setChannel(choice);
|
|
66
|
+
const latest = controller.getSnapshot().response;
|
|
67
|
+
if (!latest?.reachable || !latest.updater)
|
|
68
|
+
return setError(latest?.error ?? t("unreachable"));
|
|
69
|
+
if (!saved)
|
|
70
|
+
return setError(t("channelNotSaved"));
|
|
71
|
+
setChoice(null);
|
|
72
|
+
controller.notify({ kind: "success", title: t("channelSaved") });
|
|
73
|
+
}
|
|
74
|
+
catch (cause) {
|
|
75
|
+
setError(errorMessage(cause));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const option = (value, label, description) => (_jsxs(Field, { orientation: "horizontal", className: "items-start", "data-disabled": disabled || undefined, children: [_jsx(RadioGroupItem, { value: value, id: `${id}-${value}`, className: "mt-0.5" }), _jsxs(FieldContent, { children: [_jsx(FieldLabel, { htmlFor: `${id}-${value}`, children: label }), _jsx(FieldDescription, { children: description })] })] }));
|
|
79
|
+
return (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs("dl", { className: "grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]", children: [_jsx("dt", { className: "text-muted-foreground", children: t("installedVersion") }), _jsxs("dd", { className: "flex flex-wrap items-center gap-2 font-medium", children: [response.app.version ?? t("development"), status?.available ? (_jsxs(Badge, { variant: "secondary", children: [t("available"), " \u00B7 ", status.available.version] })) : status?.attention ? (_jsx(Badge, { variant: "outline", children: t("attention", { version: status.attention.version }) })) : null] }), status ? (_jsxs(_Fragment, { children: [_jsx("dt", { className: "text-muted-foreground", children: t("channel") }), _jsx("dd", { className: "font-medium", children: t(status.channel) }), _jsx("dt", { className: "text-muted-foreground", children: t("automatic") }), _jsx("dd", { children: automaticText(t, status) }), _jsx("dt", { className: "text-muted-foreground", children: t("lastCheck") }), _jsxs("dd", { className: "flex flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx("span", { "aria-live": "polite", children: snapshot.checking
|
|
80
|
+
? t("checking")
|
|
81
|
+
: status.checkedAt
|
|
82
|
+
? formatRelative(status.checkedAt, controller.locale, snapshot.now)
|
|
83
|
+
: t("notChecked") }), _jsxs("span", { className: "text-muted-foreground", children: ["\u00B7 ", t("updaterVersion", { version: status.updater })] }), !snapshot.checking ? (_jsx(Button, { variant: "link", size: "xs", className: "h-auto p-0", onClick: () => void controller.check(), children: t("checkNow") })) : null] }), status.error ? (_jsx("dd", { className: "text-destructive break-words sm:col-start-2", children: t("checkFailed", { error: status.error }) })) : null] })) : null] }), !response.reachable || !status ? (_jsx(Alert, { children: _jsxs(AlertDescription, { children: [_jsx("p", { className: "break-words", children: response.error ?? t("sectionUnreachable") }), _jsx("p", { children: _jsx(GuideText, { controller: controller, guideUrl: guideUrl }) })] }) })) : null, _jsxs(FieldSet, { disabled: disabled, children: [_jsx(FieldLegend, { variant: "label", children: t("channel") }), _jsxs(RadioGroup, { value: selected, disabled: disabled, onValueChange: (value) => {
|
|
84
|
+
setError(null);
|
|
85
|
+
setChoice(value);
|
|
86
|
+
}, children: [option("stable", `${t("stable")} (${t("recommended")})`, cooldown ? t("stableText", { cooldown }) : t("stableTextNoCooldown")), option("preview", t("preview"), t("previewText"))] }), locked ? _jsx(FieldDescription, { className: "text-foreground", children: locked }) : null, _jsx(FieldDescription, { children: t("switchBack") })] }), _jsxs("div", { className: "flex flex-wrap items-center justify-end gap-3", children: [error ? (_jsx("span", { role: "alert", className: "text-destructive mr-auto text-sm break-words", children: error })) : null, _jsxs(Button, { type: "button", disabled: disabled || choice === null || choice === current, onClick: () => void submit(), children: [snapshot.savingChannel ? _jsx(Spinner, {}) : null, t("saveChannel")] })] })] }));
|
|
87
|
+
}
|
|
88
|
+
/** "Automatic updates need the updater service from compose.yaml (deployment guide)", with the link. */
|
|
89
|
+
function GuideText({ controller, guideUrl }) {
|
|
90
|
+
const [before, after] = controller.t("sectionUnreachableHelp").split("{guide}");
|
|
91
|
+
return (_jsxs(_Fragment, { children: [before, guideUrl ? (_jsx("a", { href: guideUrl, target: "_blank", rel: "noreferrer", className: "text-primary font-medium underline-offset-4 hover:underline", children: controller.t("deploymentGuide") })) : (controller.t("deploymentGuide")), after] }));
|
|
92
|
+
}
|
|
93
|
+
/** `UpdatesSettings` in a card with the heading "Updates". */
|
|
94
|
+
export function UpdatesSettingsCard({ className }) {
|
|
95
|
+
const controller = useUpdatesController();
|
|
96
|
+
return (_jsxs(Card, { className: className, children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { role: "heading", "aria-level": 2, children: controller.t("updates") }), _jsx(CardDescription, { children: controller.t("sectionText", { app: controller.appName }) })] }), _jsx(CardContent, { children: _jsx(UpdatesSettings, {}) })] }));
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,161 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meldgrove/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The shared interface of the Meldgrove apps: theme, components and the update button.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Simon Schubert",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/meldgrove/ui.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/meldgrove/ui#readme",
|
|
12
|
+
"bugs": "https://github.com/meldgrove/ui/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"meldgrove",
|
|
15
|
+
"react",
|
|
16
|
+
"shadcn",
|
|
17
|
+
"tailwindcss",
|
|
18
|
+
"components"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"packageManager": "npm@11.20.0",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"**/*.css",
|
|
27
|
+
"./dist/standalone/*"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
"./styles.css": "./dist/styles.css",
|
|
36
|
+
"./tokens.css": "./dist/tokens.css",
|
|
37
|
+
"./theme.css": "./dist/theme.css",
|
|
38
|
+
"./standalone/meldgrove-updates.js": "./dist/standalone/meldgrove-updates.js",
|
|
39
|
+
"./updates": {
|
|
40
|
+
"types": "./dist/updates/index.d.ts",
|
|
41
|
+
"default": "./dist/updates/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./updates/core": {
|
|
44
|
+
"types": "./dist/updates/core.d.ts",
|
|
45
|
+
"default": "./dist/updates/core.js"
|
|
46
|
+
},
|
|
47
|
+
"./utils": {
|
|
48
|
+
"types": "./dist/lib/utils.d.ts",
|
|
49
|
+
"default": "./dist/lib/utils.js"
|
|
50
|
+
},
|
|
51
|
+
"./i18n": {
|
|
52
|
+
"types": "./dist/lib/i18n.d.ts",
|
|
53
|
+
"default": "./dist/lib/i18n.js"
|
|
54
|
+
},
|
|
55
|
+
"./format": {
|
|
56
|
+
"types": "./dist/lib/format.d.ts",
|
|
57
|
+
"default": "./dist/lib/format.js"
|
|
58
|
+
},
|
|
59
|
+
"./portal": {
|
|
60
|
+
"types": "./dist/lib/portal.d.ts",
|
|
61
|
+
"default": "./dist/lib/portal.js"
|
|
62
|
+
},
|
|
63
|
+
"./theme": {
|
|
64
|
+
"types": "./dist/lib/theme.d.ts",
|
|
65
|
+
"default": "./dist/lib/theme.js"
|
|
66
|
+
},
|
|
67
|
+
"./use-mobile": {
|
|
68
|
+
"types": "./dist/hooks/use-mobile.d.ts",
|
|
69
|
+
"default": "./dist/hooks/use-mobile.js"
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json",
|
|
72
|
+
"./*": {
|
|
73
|
+
"types": "./dist/components/*.d.ts",
|
|
74
|
+
"default": "./dist/components/*.js"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"dev": "vite --config demo/vite.config.ts",
|
|
79
|
+
"build": "node scripts/build.mjs",
|
|
80
|
+
"lint": "eslint . --max-warnings=0",
|
|
81
|
+
"format": "prettier --write .",
|
|
82
|
+
"format:check": "prettier --check .",
|
|
83
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
84
|
+
"test": "vitest run",
|
|
85
|
+
"test:visual": "playwright test",
|
|
86
|
+
"test:visual:update": "node scripts/visual-update.mjs",
|
|
87
|
+
"pack:check": "node scripts/pack-check.mjs"
|
|
88
|
+
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"cmdk": "^1.1.0",
|
|
91
|
+
"lucide-react": "^1.0.0",
|
|
92
|
+
"radix-ui": "^1.4.0",
|
|
93
|
+
"react": "^19.0.0",
|
|
94
|
+
"react-day-picker": ">=9.0.0",
|
|
95
|
+
"react-dom": "^19.0.0",
|
|
96
|
+
"recharts": "^3.0.0",
|
|
97
|
+
"sonner": "^2.0.0"
|
|
98
|
+
},
|
|
99
|
+
"peerDependenciesMeta": {
|
|
100
|
+
"cmdk": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"lucide-react": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"radix-ui": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"react": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"react-day-picker": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"react-dom": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
118
|
+
"recharts": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
121
|
+
"sonner": {
|
|
122
|
+
"optional": true
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"dependencies": {
|
|
126
|
+
"class-variance-authority": "^0.7.1",
|
|
127
|
+
"clsx": "^2.1.1",
|
|
128
|
+
"tailwind-merge": "^3.7.0",
|
|
129
|
+
"tw-animate-css": "^1.4.0"
|
|
130
|
+
},
|
|
131
|
+
"devDependencies": {
|
|
132
|
+
"@eslint/js": "10.0.1",
|
|
133
|
+
"@playwright/test": "1.65.0",
|
|
134
|
+
"@tailwindcss/vite": "4.3.5",
|
|
135
|
+
"@testing-library/jest-dom": "7.0.1",
|
|
136
|
+
"@testing-library/react": "16.3.3",
|
|
137
|
+
"@testing-library/user-event": "14.6.9",
|
|
138
|
+
"@types/node": "26.6.6",
|
|
139
|
+
"@types/react": "19.3.0",
|
|
140
|
+
"@types/react-dom": "19.3.0",
|
|
141
|
+
"@vitejs/plugin-react": "6.3.0",
|
|
142
|
+
"cmdk": "1.1.1",
|
|
143
|
+
"eslint": "10.15.0",
|
|
144
|
+
"eslint-plugin-react-hooks": "7.1.1",
|
|
145
|
+
"globals": "17.14.0",
|
|
146
|
+
"jsdom": "31.0.0",
|
|
147
|
+
"lucide-react": "1.71.0",
|
|
148
|
+
"prettier": "3.9.10",
|
|
149
|
+
"radix-ui": "1.8.1",
|
|
150
|
+
"react": "19.3.1",
|
|
151
|
+
"react-day-picker": "10.0.2",
|
|
152
|
+
"react-dom": "19.3.1",
|
|
153
|
+
"recharts": "3.10.1",
|
|
154
|
+
"sonner": "2.0.8",
|
|
155
|
+
"tailwindcss": "4.3.5",
|
|
156
|
+
"typescript": "6.0.3",
|
|
157
|
+
"typescript-eslint": "8.73.0",
|
|
158
|
+
"vite": "8.3.8",
|
|
159
|
+
"vitest": "5.1.0"
|
|
160
|
+
}
|
|
161
|
+
}
|