chore: restart the repository with a clean history
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
This commit is contained in:
438 files changed
+45070
No files matched your search
@@ -0,0 +1,94 @@
|
||||
import "@fontsource/plus-jakarta-sans/300.css";
|
||||
import "@fontsource/plus-jakarta-sans/400.css";
|
||||
import "@fontsource/plus-jakarta-sans/600.css";
|
||||
import "@fontsource/plus-jakarta-sans/700.css";
|
||||
import "@fontsource/plus-jakarta-sans/800.css";
|
||||
import { createBrowserRouter, Navigate, RouterProvider } from "react-router-dom";
|
||||
import "@/common/styles/main.sass";
|
||||
import { lazy, Suspense } from "react";
|
||||
import Root from "@/common/layouts/Root.jsx";
|
||||
import PublicRoot from "@/common/layouts/PublicRoot.jsx";
|
||||
import { ErrorBoundary, RouteErrorPage } from "@/common/components/ErrorBoundary";
|
||||
import PublicShell from "@/common/layouts/PublicShell.jsx";
|
||||
import Loading from "@/common/components/Loading";
|
||||
|
||||
const Tunnels = lazy(() => import("@/pages/Tunnels"));
|
||||
const TunnelDetail = lazy(() => import("@/pages/TunnelDetail"));
|
||||
const Settings = lazy(() => import("@/pages/Settings"));
|
||||
const SettingsServer = lazy(() => import("@/pages/Settings/pages/Server"));
|
||||
const SettingsForwarding = lazy(() => import("@/pages/Settings/pages/Forwarding"));
|
||||
const SettingsHttps = lazy(() => import("@/pages/Settings/pages/Https"));
|
||||
const SettingsDevices = lazy(() => import("@/pages/Settings/pages/Devices"));
|
||||
const SettingsAccount = lazy(() => import("@/pages/Settings/pages/Account"));
|
||||
const SettingsAccounts = lazy(() => import("@/pages/Settings/pages/Accounts"));
|
||||
const SettingsProviders = lazy(() => import("@/pages/Settings/pages/Providers"));
|
||||
const Setup = lazy(() => import("@/pages/Setup"));
|
||||
const Login = lazy(() => import("@/pages/Login"));
|
||||
const Select = lazy(() => import("@/pages/Select"));
|
||||
const Status = lazy(() => import("@/pages/Status"));
|
||||
const Handoff = lazy(() => import("@/pages/Handoff"));
|
||||
const Connect = lazy(() => import("@/pages/Connect"));
|
||||
const Invite = lazy(() => import("@/pages/Invite"));
|
||||
|
||||
export const BASE_PATH = "/@frislit";
|
||||
export const GITHUB_URL = "https://git.fristy.net/fristy/frislit";
|
||||
export const DOCS_URL = "https://git.fristy.net/fristy/frislit#documentation";
|
||||
export const AUTHOR_URL = "https://gnm.dev";
|
||||
export const FORK_URL = "https://fristy.dev";
|
||||
|
||||
const App = () => {
|
||||
const bootState = typeof window !== "undefined" ? window.__frislit__ : null;
|
||||
if (bootState) {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<PublicShell>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Status {...bootState} />
|
||||
</Suspense>
|
||||
</PublicShell>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <Root />,
|
||||
errorElement: <RouteErrorPage />,
|
||||
children: [
|
||||
{ path: "/", element: <Navigate to="/tunnels" replace /> },
|
||||
{ path: "/tunnels", element: <Tunnels /> },
|
||||
{ path: "/tunnels/:id", element: <TunnelDetail /> },
|
||||
{
|
||||
path: "/settings", element: <Settings />, children: [
|
||||
{ path: "server", element: <SettingsServer /> },
|
||||
{ path: "forwarding", element: <SettingsForwarding /> },
|
||||
{ path: "https", element: <SettingsHttps /> },
|
||||
{ path: "devices", element: <SettingsDevices /> },
|
||||
{ path: "accounts", element: <SettingsAccounts /> },
|
||||
{ path: "providers", element: <SettingsProviders /> },
|
||||
{ path: "account", element: <SettingsAccount /> },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
element: <PublicRoot />,
|
||||
errorElement: <RouteErrorPage />,
|
||||
children: [
|
||||
{ path: "/setup", element: <Setup /> },
|
||||
{ path: "/login", element: <Login /> },
|
||||
{ path: "/select", element: <Select /> },
|
||||
{ path: "/reattach", element: <Status kind="reattach" /> },
|
||||
{ path: "/handoff", element: <Handoff /> },
|
||||
{ path: "/connect/:code", element: <Connect /> },
|
||||
{ path: "/invite/:token", element: <Invite /> },
|
||||
],
|
||||
},
|
||||
], { basename: BASE_PATH });
|
||||
|
||||
return <RouterProvider router={router} />;
|
||||
};
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,28 @@
|
||||
import "./styles.sass";
|
||||
import { DialogProvider } from "@/common/components/Dialog";
|
||||
import Button from "@/common/components/Button";
|
||||
|
||||
export const ActionConfirmDialog = ({ open, setOpen, onConfirm, onCancel, title, text, confirmText }) => {
|
||||
const cancel = () => {
|
||||
setOpen(false);
|
||||
if (onCancel) onCancel();
|
||||
};
|
||||
|
||||
const confirm = () => {
|
||||
setOpen(false);
|
||||
if (onConfirm) onConfirm();
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogProvider open={open} onClose={cancel}>
|
||||
<div className="confirm-dialog">
|
||||
<h2>{title || "Are you sure?"}</h2>
|
||||
{text && <p>{text}</p>}
|
||||
<div className="confirm-actions">
|
||||
<Button type="secondary" text="Cancel" onClick={cancel} />
|
||||
<Button text={confirmText || "Confirm"} onClick={confirm} />
|
||||
</div>
|
||||
</div>
|
||||
</DialogProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { ActionConfirmDialog as default } from "./ActionConfirmDialog.jsx";
|
||||
@@ -0,0 +1,21 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.confirm-dialog
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.5rem
|
||||
|
||||
h2
|
||||
font-size: 1.125rem
|
||||
|
||||
p
|
||||
margin: 0
|
||||
color: colors.$subtext
|
||||
font-size: 0.875rem
|
||||
line-height: 1.5
|
||||
|
||||
.confirm-actions
|
||||
display: flex
|
||||
justify-content: flex-end
|
||||
gap: 0.5rem
|
||||
margin-top: 1rem
|
||||
@@ -0,0 +1,11 @@
|
||||
import "./styles.sass";
|
||||
|
||||
export const Button = ({ onClick, text, icon: Glyph, disabled, type = "primary", buttonType, title }) => {
|
||||
return (
|
||||
<button className={`btn btn-${type}${!text ? " btn-icon" : ""}`} onClick={onClick} disabled={disabled}
|
||||
type={buttonType} title={title} aria-label={title}>
|
||||
{Glyph && <Glyph />}
|
||||
{text && <span>{text}</span>}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Button as default } from "./Button.jsx";
|
||||
@@ -0,0 +1,75 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.btn
|
||||
display: inline-flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
gap: 0.5rem
|
||||
border: 1px solid transparent
|
||||
border-radius: 0.75rem
|
||||
padding: 0.5rem 1rem
|
||||
font-family: inherit
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
cursor: pointer
|
||||
white-space: nowrap
|
||||
transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease
|
||||
|
||||
svg
|
||||
width: 1.0625rem
|
||||
height: 1.0625rem
|
||||
|
||||
&:active
|
||||
transform: translateY(0.5px)
|
||||
|
||||
&:disabled
|
||||
opacity: 0.45
|
||||
cursor: not-allowed
|
||||
transform: none
|
||||
|
||||
.btn-primary
|
||||
background-color: colors.$primary-bright
|
||||
color: colors.$on-primary
|
||||
font-weight: 600
|
||||
|
||||
&:hover:not(:disabled)
|
||||
background-color: colors.$primary-hover
|
||||
|
||||
&:disabled
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$muted
|
||||
opacity: 1
|
||||
|
||||
.btn-secondary
|
||||
background-color: transparent
|
||||
border-color: colors.$border-strong
|
||||
color: colors.$text
|
||||
|
||||
&:hover:not(:disabled)
|
||||
background-color: colors.$surface-hover
|
||||
|
||||
.btn-ghost
|
||||
background-color: transparent
|
||||
color: colors.$subtext
|
||||
|
||||
&:hover:not(:disabled)
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
.btn-danger
|
||||
background-color: transparent
|
||||
border-color: colors.$border-strong
|
||||
color: colors.$subtext
|
||||
|
||||
&:hover:not(:disabled)
|
||||
background-color: colors.$error-tint
|
||||
border-color: transparent
|
||||
color: colors.$error
|
||||
|
||||
&.btn-icon
|
||||
border-color: transparent
|
||||
color: colors.$muted
|
||||
|
||||
.btn-icon
|
||||
padding: 0.5rem
|
||||
border-radius: 0.625rem
|
||||
@@ -0,0 +1,126 @@
|
||||
import "./styles.sass";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { EditorState, Compartment } from "@codemirror/state";
|
||||
import { EditorView, keymap, lineNumbers, highlightActiveLine, highlightActiveLineGutter, drawSelection, rectangularSelection, crosshairCursor, highlightSpecialChars } from "@codemirror/view";
|
||||
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
||||
import { bracketMatching, indentOnInput, foldGutter, foldKeymap } from "@codemirror/language";
|
||||
import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
|
||||
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
||||
import { Copy, WandSparkles, WrapText } from "lucide-react";
|
||||
import { useToast } from "@/common/contexts/toast.js";
|
||||
import { copyToClipboard } from "@/common/utils/clipboard.js";
|
||||
import { formatBytes } from "@/common/utils/formatUtils.js";
|
||||
import { extensionFor, format, formattable } from "./languages.js";
|
||||
import { theme } from "./theme.js";
|
||||
|
||||
const base = [
|
||||
lineNumbers(), foldGutter(), highlightActiveLine(), highlightActiveLineGutter(), highlightSpecialChars(), drawSelection(),
|
||||
rectangularSelection(), crosshairCursor(), history(), bracketMatching(), closeBrackets(), indentOnInput(), highlightSelectionMatches(),
|
||||
EditorState.tabSize.of(2),
|
||||
keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...historyKeymap, ...searchKeymap, ...foldKeymap, indentWithTab]),
|
||||
...theme,
|
||||
];
|
||||
|
||||
const position = state => {
|
||||
const line = state.doc.lineAt(state.selection.main.head);
|
||||
return { line: line.number, column: state.selection.main.head - line.from + 1 };
|
||||
};
|
||||
|
||||
const CodeEditor = ({ value, onChange, language, label, readOnly = false, maxHeight = "24rem" }) => {
|
||||
const { sendToast } = useToast();
|
||||
const host = useRef(null);
|
||||
const view = useRef(null);
|
||||
const languageSlot = useRef(new Compartment());
|
||||
const editableSlot = useRef(new Compartment());
|
||||
const wrapSlot = useRef(new Compartment());
|
||||
const emit = useRef(onChange);
|
||||
const shortcut = useRef(null);
|
||||
const initial = useRef({ value, language, readOnly });
|
||||
const [formatting, setFormatting] = useState(false);
|
||||
const [wrap, setWrap] = useState(true);
|
||||
const [cursor, setCursor] = useState({ line: 1, column: 1 });
|
||||
const [stats, setStats] = useState({ lines: 1, size: 0 });
|
||||
|
||||
useEffect(() => { emit.current = onChange; }, [onChange]);
|
||||
|
||||
useEffect(() => {
|
||||
const { value, language, readOnly } = initial.current;
|
||||
const editor = new EditorView({
|
||||
parent: host.current,
|
||||
state: EditorState.create({
|
||||
doc: value,
|
||||
extensions: [
|
||||
...base,
|
||||
languageSlot.current.of(extensionFor(language)),
|
||||
editableSlot.current.of([EditorView.editable.of(!readOnly), EditorState.readOnly.of(readOnly)]),
|
||||
wrapSlot.current.of(EditorView.lineWrapping),
|
||||
keymap.of([{ key: "Shift-Alt-f", run: () => { shortcut.current(); return true; } }]),
|
||||
EditorView.updateListener.of(update => {
|
||||
if (update.docChanged) {
|
||||
emit.current?.(update.state.doc.toString());
|
||||
setStats({ lines: update.state.doc.lines, size: new TextEncoder().encode(update.state.doc.toString()).length });
|
||||
}
|
||||
if (update.selectionSet || update.docChanged) setCursor(position(update.state));
|
||||
}),
|
||||
],
|
||||
}),
|
||||
});
|
||||
view.current = editor;
|
||||
setStats({ lines: editor.state.doc.lines, size: new TextEncoder().encode(value).length });
|
||||
return () => editor.destroy();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
view.current.dispatch({ effects: wrapSlot.current.reconfigure(wrap ? EditorView.lineWrapping : []) });
|
||||
}, [wrap]);
|
||||
|
||||
useEffect(() => {
|
||||
view.current.dispatch({ effects: languageSlot.current.reconfigure(extensionFor(language)) });
|
||||
}, [language]);
|
||||
|
||||
useEffect(() => {
|
||||
view.current.dispatch({ effects: editableSlot.current.reconfigure([EditorView.editable.of(!readOnly), EditorState.readOnly.of(readOnly)]) });
|
||||
}, [readOnly]);
|
||||
|
||||
useEffect(() => {
|
||||
const current = view.current.state.doc.toString();
|
||||
if (value !== current) view.current.dispatch({ changes: { from: 0, to: current.length, insert: value } });
|
||||
}, [value]);
|
||||
|
||||
const prettify = async () => {
|
||||
if (!formattable(language)) return;
|
||||
setFormatting(true);
|
||||
try {
|
||||
const pretty = await format(view.current.state.doc.toString(), language);
|
||||
view.current.dispatch({ changes: { from: 0, to: view.current.state.doc.length, insert: pretty } });
|
||||
} catch (error) {
|
||||
sendToast("Error", error.message.split("\n")[0]);
|
||||
} finally {
|
||||
setFormatting(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => { shortcut.current = prettify; });
|
||||
|
||||
return (
|
||||
<div className={`code-editor${readOnly ? " readonly" : ""}`}>
|
||||
<div className="code-editor-bar">
|
||||
{label && <span className="code-editor-label">{label}</span>}
|
||||
<span className="code-editor-language">{language}</span>
|
||||
<span className="code-editor-spacer" />
|
||||
<button type="button" className={wrap ? "active" : ""} onClick={() => setWrap(!wrap)} title="Wrap lines" aria-label="Wrap lines"><WrapText /></button>
|
||||
<button type="button" onClick={() => copyToClipboard(view.current.state.doc.toString()).then(() => sendToast("Success", "Copied"))} title="Copy" aria-label="Copy"><Copy /></button>
|
||||
{formattable(language) && (
|
||||
<button type="button" onClick={prettify} disabled={formatting} title="Format (Shift+Alt+F)"><WandSparkles />Format</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="code-editor-host" ref={host} style={{ "--editor-max-height": maxHeight }} />
|
||||
<div className="code-editor-status">
|
||||
<span>Ln {cursor.line}, Col {cursor.column}</span>
|
||||
<span>{stats.lines} {stats.lines === 1 ? "line" : "lines"} · {formatBytes(stats.size)}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CodeEditor;
|
||||
@@ -0,0 +1,8 @@
|
||||
export const languageFor = type => {
|
||||
if (/json/i.test(type)) return "json";
|
||||
if (/html/i.test(type)) return "html";
|
||||
if (/xml|svg/i.test(type)) return "xml";
|
||||
if (/css/i.test(type)) return "css";
|
||||
if (/javascript|ecmascript/i.test(type)) return "javascript";
|
||||
return "text";
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { lazy, Suspense } from "react";
|
||||
import Loading from "@/common/components/Loading";
|
||||
|
||||
const Editor = lazy(() => import("./CodeEditor.jsx"));
|
||||
|
||||
|
||||
const CodeEditor = props => (
|
||||
<Suspense fallback={<div className="code-editor-loading"><Loading /></div>}>
|
||||
<Editor {...props} />
|
||||
</Suspense>
|
||||
);
|
||||
|
||||
export default CodeEditor;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { StreamLanguage } from "@codemirror/language";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
import { html } from "@codemirror/lang-html";
|
||||
import { css } from "@codemirror/lang-css";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { xml } from "@codemirror/lang-xml";
|
||||
|
||||
const headers = () => StreamLanguage.define({
|
||||
token(stream) {
|
||||
if (stream.sol() && stream.match(/^[^:\s]+(?=:)/)) return "propertyName";
|
||||
if (stream.match(/^:\s*/)) return "punctuation";
|
||||
stream.skipToEnd();
|
||||
return "string";
|
||||
},
|
||||
});
|
||||
|
||||
const LANGUAGES = { json, html, css, javascript, xml, headers };
|
||||
|
||||
export const extensionFor = language => (LANGUAGES[language] ? LANGUAGES[language]() : []);
|
||||
|
||||
const PARSERS = { html: "html", css: "css", javascript: "babel", xml: "xml" };
|
||||
|
||||
const pluginsFor = async language => {
|
||||
switch (language) {
|
||||
case "html": return Promise.all([import("prettier/plugins/html"), import("prettier/plugins/postcss"), import("prettier/plugins/babel"), import("prettier/plugins/estree")]);
|
||||
case "css": return Promise.all([import("prettier/plugins/postcss")]);
|
||||
case "javascript": return Promise.all([import("prettier/plugins/babel"), import("prettier/plugins/estree")]);
|
||||
case "xml": return Promise.all([import("@prettier/plugin-xml")]);
|
||||
}
|
||||
};
|
||||
|
||||
export const formattable = language => language === "json" || language in PARSERS;
|
||||
|
||||
export const format = async (text, language) => {
|
||||
if (language === "json") return JSON.stringify(JSON.parse(text), null, 2);
|
||||
const [{ format: run }, plugins] = await Promise.all([import("prettier/standalone"), pluginsFor(language)]);
|
||||
return run(text, { parser: PARSERS[language], plugins: plugins.map(plugin => plugin.default), printWidth: 100, ...(language === "xml" ? { xmlWhitespaceSensitivity: "ignore" } : {}) });
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.code-editor
|
||||
display: flex
|
||||
flex-direction: column
|
||||
min-width: 0
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.625rem
|
||||
overflow: hidden
|
||||
|
||||
&:focus-within
|
||||
border-color: colors.$primary
|
||||
|
||||
&.readonly
|
||||
border-radius: 0
|
||||
border: none
|
||||
border-top: 1px solid colors.$border
|
||||
|
||||
.code-editor-bar
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
padding: 0.25rem 0.5rem 0.25rem 0.75rem
|
||||
border-bottom: 1px solid colors.$border
|
||||
background-color: colors.$surface-raised
|
||||
|
||||
button
|
||||
display: inline-flex
|
||||
align-items: center
|
||||
gap: 0.3rem
|
||||
height: 1.5rem
|
||||
padding: 0 0.5rem
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.375rem
|
||||
color: colors.$muted
|
||||
font-family: inherit
|
||||
font-size: 0.6875rem
|
||||
font-weight: 600
|
||||
cursor: pointer
|
||||
|
||||
svg
|
||||
width: 0.75rem
|
||||
height: 0.75rem
|
||||
|
||||
&:hover:not(:disabled), &.active
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
&:disabled
|
||||
opacity: 0.5
|
||||
cursor: default
|
||||
|
||||
.code-editor-spacer
|
||||
flex: 1
|
||||
|
||||
.code-editor-status
|
||||
display: flex
|
||||
justify-content: space-between
|
||||
gap: 0.75rem
|
||||
padding: 0.2rem 0.75rem
|
||||
border-top: 1px solid colors.$border
|
||||
background-color: colors.$surface-raised
|
||||
color: colors.$muted
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
|
||||
font-size: 0.625rem
|
||||
|
||||
.code-editor-label
|
||||
color: colors.$subtext
|
||||
font-size: 0.75rem
|
||||
font-weight: 500
|
||||
|
||||
.code-editor-language
|
||||
color: colors.$muted
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
|
||||
font-size: 0.6875rem
|
||||
|
||||
.code-editor-host
|
||||
min-width: 0
|
||||
|
||||
.cm-editor
|
||||
max-height: var(--editor-max-height)
|
||||
|
||||
.cm-scroller
|
||||
overflow: auto
|
||||
min-height: 6rem
|
||||
|
||||
.code-editor.readonly .cm-scroller
|
||||
min-height: 0
|
||||
|
||||
|
||||
.code-editor-loading
|
||||
display: flex
|
||||
justify-content: center
|
||||
padding: 1.5rem
|
||||
@@ -0,0 +1,42 @@
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
||||
import { tags } from "@lezer/highlight";
|
||||
|
||||
const mono = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
|
||||
const lineTint = "rgba(255, 255, 255, 0.03)";
|
||||
const selection = "rgba(20, 184, 166, 0.3)";
|
||||
|
||||
const editorTheme = EditorView.theme({
|
||||
"&": { color: "var(--text)", backgroundColor: "var(--surface)", fontSize: "0.75rem" },
|
||||
".cm-content": { fontFamily: mono, padding: "0.5rem 0", caretColor: "var(--text)" },
|
||||
".cm-scroller": { fontFamily: mono, lineHeight: "1.6" },
|
||||
".cm-gutters": { backgroundColor: "var(--surface)", color: "var(--muted)", border: "none", paddingLeft: "0.25rem" },
|
||||
".cm-lineNumbers .cm-gutterElement": { minWidth: "2.25rem", padding: "0 0.5rem 0 0" },
|
||||
".cm-activeLine": { backgroundColor: lineTint },
|
||||
".cm-activeLineGutter": { backgroundColor: lineTint, color: "var(--subtext)" },
|
||||
".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--text)" },
|
||||
".cm-selectionBackground": { backgroundColor: selection },
|
||||
".cm-selectionMatch": { backgroundColor: "var(--primary-tint)" },
|
||||
".cm-matchingBracket, &.cm-focused .cm-matchingBracket": { backgroundColor: "var(--primary-tint)", outline: "1px solid var(--primary-deep)" },
|
||||
".cm-nonmatchingBracket": { color: "var(--error)" },
|
||||
".cm-panels": { backgroundColor: "var(--surface-raised)", color: "var(--text)", borderColor: "var(--border)" },
|
||||
".cm-panels input, .cm-panels button": { fontFamily: "inherit", color: "var(--text)", backgroundColor: "var(--background)", border: "1px solid var(--border)", borderRadius: "0.375rem", backgroundImage: "none" },
|
||||
".cm-searchMatch": { backgroundColor: "var(--warning-tint)", outline: "1px solid var(--warning)" },
|
||||
".cm-searchMatch.cm-searchMatch-selected": { backgroundColor: "var(--warning-tint)" },
|
||||
".cm-tooltip": { backgroundColor: "var(--surface-raised)", border: "1px solid var(--border-strong)", color: "var(--text)" },
|
||||
"&.cm-focused": { outline: "none" },
|
||||
}, { dark: true });
|
||||
|
||||
const highlight = HighlightStyle.define([
|
||||
{ tag: [tags.comment, tags.documentMeta, tags.processingInstruction], color: "var(--muted)", fontStyle: "italic" },
|
||||
{ tag: [tags.punctuation, tags.bracket, tags.separator, tags.angleBracket], color: "var(--muted)" },
|
||||
{ tag: [tags.propertyName, tags.tagName, tags.attributeName, tags.definition(tags.variableName)], color: "var(--primary-bright)" },
|
||||
{ tag: [tags.string, tags.attributeValue, tags.special(tags.string), tags.character], color: "var(--success)" },
|
||||
{ tag: [tags.number, tags.bool, tags.unit, tags.color, tags.constant(tags.name)], color: "var(--warning)" },
|
||||
{ tag: [tags.null, tags.keyword, tags.operatorKeyword, tags.modifier, tags.controlKeyword, tags.atom, tags.self], color: "var(--error)" },
|
||||
{ tag: [tags.operator, tags.url, tags.escape, tags.regexp], color: "var(--subtext)" },
|
||||
{ tag: [tags.function(tags.variableName), tags.function(tags.propertyName), tags.className, tags.typeName, tags.namespace], color: "var(--primary-hover)" },
|
||||
{ tag: [tags.invalid], color: "var(--error)", textDecoration: "underline" },
|
||||
]);
|
||||
|
||||
export const theme = [editorTheme, syntaxHighlighting(highlight)];
|
||||
@@ -0,0 +1,21 @@
|
||||
import "./styles.sass";
|
||||
import { useState } from "react";
|
||||
import { Check, Copy } from "lucide-react";
|
||||
import { copyToClipboard } from "@/common/utils/clipboard.js";
|
||||
|
||||
export const CopyButton = ({ value, label = "Copy" }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const copy = async event => {
|
||||
event.stopPropagation();
|
||||
if (!await copyToClipboard(value)) return;
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
};
|
||||
|
||||
return (
|
||||
<button type="button" className={`copy-button${copied ? " copied" : ""}`} onClick={copy} aria-label={label} title={label}>
|
||||
{copied ? <Check /> : <Copy />}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { CopyButton as default } from "./CopyButton.jsx";
|
||||
@@ -0,0 +1,27 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.copy-button
|
||||
display: inline-flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
width: 1.375rem
|
||||
height: 1.375rem
|
||||
flex-shrink: 0
|
||||
padding: 0
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.35rem
|
||||
color: colors.$muted
|
||||
cursor: pointer
|
||||
transition: background-color 0.15s ease, color 0.15s ease
|
||||
|
||||
svg
|
||||
width: 0.8125rem
|
||||
height: 0.8125rem
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
&.copied
|
||||
color: colors.$success
|
||||
@@ -0,0 +1,29 @@
|
||||
import "./styles.sass";
|
||||
import { useState } from "react";
|
||||
import { copyToClipboard } from "@/common/utils/clipboard.js";
|
||||
import { Check, Copy, Eye, EyeOff } from "lucide-react";
|
||||
|
||||
export const CopyField = ({ value, secret }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [revealed, setRevealed] = useState(!secret);
|
||||
|
||||
const copy = async () => {
|
||||
if (!await copyToClipboard(value)) return;
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="copy-field">
|
||||
<code>{revealed ? value : "•".repeat(Math.min(value?.length || 0, 28))}</code>
|
||||
{secret && (
|
||||
<button type="button" onClick={() => setRevealed(!revealed)} aria-label={revealed ? "Hide" : "Reveal"}>
|
||||
{revealed ? <EyeOff /> : <Eye />}
|
||||
</button>
|
||||
)}
|
||||
<button type="button" onClick={copy} aria-label="Copy" className={copied ? "copied" : ""}>
|
||||
{copied ? <Check /> : <Copy />}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { CopyField as default } from "./CopyField.jsx";
|
||||
@@ -0,0 +1,46 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.copy-field
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.25rem
|
||||
min-width: 0
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.625rem
|
||||
padding: 0.25rem 0.25rem 0.25rem 0.75rem
|
||||
|
||||
code
|
||||
flex: 1
|
||||
min-width: 0
|
||||
overflow: hidden
|
||||
text-overflow: ellipsis
|
||||
white-space: nowrap
|
||||
font-size: 0.8125rem
|
||||
color: colors.$subtext
|
||||
user-select: all
|
||||
|
||||
button
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
width: 1.75rem
|
||||
height: 1.75rem
|
||||
flex-shrink: 0
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.4rem
|
||||
color: colors.$muted
|
||||
cursor: pointer
|
||||
transition: background-color 0.15s ease, color 0.15s ease
|
||||
|
||||
svg
|
||||
width: 0.9375rem
|
||||
height: 0.9375rem
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
&.copied
|
||||
color: colors.$success
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { DialogContext } from "./context.js";
|
||||
import { createPortal } from "react-dom";
|
||||
import "./styles.sass";
|
||||
|
||||
export const DialogProvider = ({ open, children, onClose, disableClosing }) => {
|
||||
const ref = useRef(null);
|
||||
|
||||
const close = useCallback(() => {
|
||||
if (disableClosing) return;
|
||||
if (onClose) onClose();
|
||||
}, [disableClosing, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
|
||||
const handleClick = event => { if (!ref.current?.contains(event.target)) close(); };
|
||||
const handleKey = event => { if (event.key === "Escape") close(); };
|
||||
|
||||
document.addEventListener("mousedown", handleClick);
|
||||
document.addEventListener("keydown", handleKey);
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClick);
|
||||
document.removeEventListener("keydown", handleKey);
|
||||
};
|
||||
}, [open, close]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<DialogContext.Provider value={close}>
|
||||
{createPortal(
|
||||
<div className="dialog-backdrop">
|
||||
<div className="dialog" ref={ref} role="dialog" aria-modal="true">{children}</div>
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</DialogContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
export const DialogContext = createContext({});
|
||||
@@ -0,0 +1 @@
|
||||
export { DialogProvider as default, DialogProvider } from "./Dialog.jsx";
|
||||
@@ -0,0 +1,32 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.dialog-backdrop
|
||||
position: fixed
|
||||
inset: 0
|
||||
z-index: 100
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
padding: 1rem
|
||||
background-color: rgba(0, 0, 0, 0.6)
|
||||
backdrop-filter: blur(3px)
|
||||
animation: dialog-fade 0.15s ease
|
||||
|
||||
.dialog
|
||||
width: 100%
|
||||
max-width: 24rem
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 1rem
|
||||
padding: 1.5rem
|
||||
box-shadow: colors.$shadow-lg
|
||||
animation: dialog-rise 0.18s ease
|
||||
|
||||
@keyframes dialog-fade
|
||||
from
|
||||
opacity: 0
|
||||
|
||||
@keyframes dialog-rise
|
||||
from
|
||||
opacity: 0
|
||||
transform: translateY(0.5rem) scale(0.98)
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Component } from "react";
|
||||
import { useRouteError } from "react-router-dom";
|
||||
import "./styles.sass";
|
||||
import { CircleAlert } from "lucide-react";
|
||||
|
||||
const ErrorDisplay = ({ message, is404 }) => (
|
||||
<div className="error-page">
|
||||
<CircleAlert />
|
||||
<h1>{is404 ? "Page not found" : "Something went wrong"}</h1>
|
||||
{!is404 && message && <p>{message}</p>}
|
||||
<div className="error-actions">
|
||||
{!is404 && <button type="button" onClick={() => window.location.reload()}>Reload</button>}
|
||||
<button type="button" onClick={() => (window.location.href = "/@frislit/")}>Go to dashboard</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
class ErrorBoundary extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { error: null };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error) {
|
||||
return { error };
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.error) return <ErrorDisplay message={this.state.error.message} />;
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
const RouteErrorPage = () => {
|
||||
const error = useRouteError();
|
||||
return <ErrorDisplay message={error?.message || error?.statusText} is404={error?.status === 404} />;
|
||||
};
|
||||
|
||||
export { ErrorBoundary, RouteErrorPage };
|
||||
@@ -0,0 +1 @@
|
||||
export { ErrorBoundary as default, ErrorBoundary, RouteErrorPage } from "./ErrorBoundary.jsx";
|
||||
@@ -0,0 +1,44 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.error-page
|
||||
display: flex
|
||||
flex-direction: column
|
||||
align-items: center
|
||||
justify-content: center
|
||||
gap: 0.75rem
|
||||
text-align: center
|
||||
min-height: 60vh
|
||||
padding: 2rem
|
||||
|
||||
> svg
|
||||
width: 2rem
|
||||
height: 2rem
|
||||
color: colors.$error
|
||||
|
||||
h1
|
||||
font-size: 1.375rem
|
||||
|
||||
p
|
||||
margin: 0
|
||||
color: colors.$subtext
|
||||
font-size: 0.875rem
|
||||
max-width: 28rem
|
||||
|
||||
.error-actions
|
||||
display: flex
|
||||
gap: 0.5rem
|
||||
margin-top: 0.5rem
|
||||
|
||||
button
|
||||
background: none
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 0.75rem
|
||||
padding: 0.5rem 1rem
|
||||
color: colors.$text
|
||||
font-family: inherit
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
cursor: pointer
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
@@ -0,0 +1,12 @@
|
||||
import "./styles.sass";
|
||||
import { countryName } from "@/common/utils/country.js";
|
||||
|
||||
const flags = import.meta.glob("/node_modules/flag-icons/flags/4x3/*.svg", { eager: true, import: "default", query: "?url" });
|
||||
|
||||
const urlFor = code => flags[`/node_modules/flag-icons/flags/4x3/${code.toLowerCase()}.svg`];
|
||||
|
||||
export const Flag = ({ code, size = "sm" }) => {
|
||||
const url = code && urlFor(code);
|
||||
if (!url) return null;
|
||||
return <img className={`flag flag-${size}`} src={url} alt={code} title={countryName(code)} draggable={false} />;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Flag as default } from "./Flag.jsx";
|
||||
@@ -0,0 +1,16 @@
|
||||
.flag
|
||||
display: inline-block
|
||||
flex-shrink: 0
|
||||
border-radius: 2px
|
||||
object-fit: cover
|
||||
vertical-align: -0.125em
|
||||
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08)
|
||||
|
||||
.flag-sm
|
||||
width: 1rem
|
||||
height: 0.75rem
|
||||
|
||||
.flag-lg
|
||||
width: 2.5rem
|
||||
height: 1.875rem
|
||||
border-radius: 4px
|
||||
@@ -0,0 +1,83 @@
|
||||
import "./styles.sass";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Heart } from "lucide-react";
|
||||
import { useUser } from "@/common/contexts/user.js";
|
||||
import { AUTHOR_URL, FORK_URL, GITHUB_URL } from "@/App.jsx";
|
||||
|
||||
const RELEASES_API = "https://git.fristy.net/api/v1/repos/fristy/frislit/releases/latest";
|
||||
const CACHE_KEY = "frislit.latestRelease";
|
||||
const CACHE_TTL = 6 * 60 * 60 * 1000;
|
||||
|
||||
const parseVersion = version => String(version || "").replace(/^v/, "").split("-")[0].split(".").map(Number);
|
||||
|
||||
const isNewer = (candidate, current) => {
|
||||
const a = parseVersion(candidate), b = parseVersion(current);
|
||||
if (a.some(Number.isNaN) || b.some(Number.isNaN)) return false;
|
||||
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
||||
if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) > (b[i] || 0);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const useLatestRelease = () => {
|
||||
const [latest, setLatest] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
try {
|
||||
const cached = JSON.parse(localStorage.getItem(CACHE_KEY));
|
||||
if (cached && Date.now() - cached.at < CACHE_TTL) return setLatest(cached.version);
|
||||
} catch {
|
||||
setLatest(null);
|
||||
}
|
||||
|
||||
fetch(RELEASES_API, { headers: { Accept: "application/json" } })
|
||||
.then(response => response.ok ? response.json() : null)
|
||||
.then(release => {
|
||||
if (cancelled || !release?.tag_name) return;
|
||||
setLatest(release.tag_name);
|
||||
try {
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify({ version: release.tag_name, at: Date.now() }));
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
})
|
||||
.catch(() => null);
|
||||
return () => { cancelled = true; };
|
||||
}, []);
|
||||
|
||||
return latest;
|
||||
};
|
||||
|
||||
export const Footer = () => {
|
||||
const { serverInfo } = useUser();
|
||||
const latest = useLatestRelease();
|
||||
const version = serverInfo?.version;
|
||||
const update = version && latest && isNewer(latest, version) ? latest : null;
|
||||
|
||||
return (
|
||||
<footer className="app-footer">
|
||||
<div className="app-footer-inner">
|
||||
<div className="app-footer-group">
|
||||
<span className="app-footer-brand wordmark">fris<em>lit</em></span>
|
||||
{version && (
|
||||
<a className="app-footer-version" href={`${GITHUB_URL}/releases/tag/v${version}`} target="_blank"
|
||||
rel="noreferrer" title="Release notes">v{version}</a>
|
||||
)}
|
||||
{update && (
|
||||
<a className="app-footer-update" href={`${GITHUB_URL}/releases/latest`} target="_blank" rel="noreferrer">
|
||||
{update.startsWith("v") ? update : `v${update}`} available
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<span className="app-footer-group app-footer-made">
|
||||
Made with <Heart size={12} fill="currentColor" /> by{" "}
|
||||
<a href={AUTHOR_URL} target="_blank" rel="noreferrer">GNM</a>
|
||||
{" · "}forked by{" "}
|
||||
<a href={FORK_URL} target="_blank" rel="noreferrer">fristy</a>
|
||||
</span>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Footer as default } from "./Footer.jsx";
|
||||
@@ -0,0 +1,68 @@
|
||||
@use "@/common/styles/colors"
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.app-footer
|
||||
flex-shrink: 0
|
||||
border-top: 1px solid colors.$border
|
||||
color: colors.$muted
|
||||
font-size: 0.75rem
|
||||
|
||||
.app-footer-inner
|
||||
max-width: 68rem
|
||||
margin: 0 auto
|
||||
padding: 0.625rem 2rem
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: space-between
|
||||
gap: 1rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
padding: 0.75rem 1rem
|
||||
flex-direction: column
|
||||
gap: 0.5rem
|
||||
|
||||
.app-footer-group
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
min-width: 0
|
||||
|
||||
.app-footer-brand
|
||||
color: colors.$subtext
|
||||
font-weight: 700
|
||||
letter-spacing: -0.02em
|
||||
|
||||
.app-footer-version
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
|
||||
color: colors.$muted
|
||||
transition: color 0.15s ease
|
||||
|
||||
&:hover
|
||||
color: colors.$text
|
||||
|
||||
.app-footer-update
|
||||
padding: 0.0625rem 0.45rem
|
||||
border-radius: 0.375rem
|
||||
background-color: colors.$primary-tint
|
||||
color: colors.$primary-bright
|
||||
font-weight: 600
|
||||
transition: background-color 0.15s ease, color 0.15s ease
|
||||
|
||||
&:hover
|
||||
background-color: colors.$primary
|
||||
color: colors.$on-primary
|
||||
|
||||
.app-footer-made
|
||||
gap: 0.3125rem
|
||||
white-space: nowrap
|
||||
|
||||
svg
|
||||
color: colors.$error
|
||||
|
||||
a
|
||||
color: colors.$subtext
|
||||
font-weight: 600
|
||||
transition: color 0.15s ease
|
||||
|
||||
&:hover
|
||||
color: colors.$text
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ModeDiagram } from "./ModeDiagram.jsx";
|
||||
import { MODES } from "./modes.js";
|
||||
|
||||
export const ForwardingChoice = ({ value, onChange, onPreview }) => (
|
||||
<div className="mode-choices" onMouseLeave={() => onPreview?.(null)}>
|
||||
{Object.entries(MODES).map(([mode, details]) => (
|
||||
<button type="button" key={mode} aria-pressed={value === mode}
|
||||
className={`mode-choice${value === mode ? " selected" : ""}`}
|
||||
onMouseEnter={() => onPreview?.(mode)}
|
||||
onFocus={() => onPreview?.(mode)}
|
||||
onClick={() => onChange(mode)}>
|
||||
<span className="mode-choice-title">
|
||||
{details.title}
|
||||
<span className="mode-choice-mark" aria-hidden="true" />
|
||||
</span>
|
||||
<span className="mode-choice-summary">{details.summary}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
export const ForwardingExplainer = ({ mode, domain }) => (
|
||||
<div className="mode-explainer">
|
||||
<ModeDiagram mode={mode} domain={domain} />
|
||||
<h3>{MODES[mode].title}</h3>
|
||||
<ul>{MODES[mode].facts.map(fact => <li key={fact}>{fact}</li>)}</ul>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,63 @@
|
||||
const LAYOUT = {
|
||||
url: { x: 0.5, width: 237 },
|
||||
gutter: 34,
|
||||
port: { width: 72 },
|
||||
row: { height: 34, gap: 12, top: 20 },
|
||||
label: { baseline: 8, size: 8.5 },
|
||||
padding: 13,
|
||||
};
|
||||
|
||||
const PORT_X = LAYOUT.url.x + LAYOUT.url.width + LAYOUT.gutter;
|
||||
const WIDTH = PORT_X + LAYOUT.port.width + 0.5;
|
||||
const HEIGHT = LAYOUT.row.top + LAYOUT.row.height * 2 + LAYOUT.row.gap + 2;
|
||||
const ARROW = LAYOUT.url.x + LAYOUT.url.width + LAYOUT.gutter / 2;
|
||||
const TEXT_BASELINE = LAYOUT.row.top + LAYOUT.row.height / 2 + 4.5;
|
||||
|
||||
const ROWS = [
|
||||
{ id: "app", port: ":3000", offset: 0 },
|
||||
{ id: "docs", port: ":8080", offset: LAYOUT.row.height + LAYOUT.row.gap },
|
||||
];
|
||||
|
||||
const MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
|
||||
|
||||
export const ModeDiagram = ({ mode, domain }) => {
|
||||
const isSubdomain = mode === "subdomain";
|
||||
const host = domain.length > 24 ? `${domain.slice(0, 23)}…` : domain;
|
||||
|
||||
return (
|
||||
<svg className="mode-diagram" viewBox={`0 0 ${WIDTH} ${HEIGHT}`} role="img"
|
||||
aria-label={isSubdomain
|
||||
? `Each tunnel gets its own hostname in front of ${domain}`
|
||||
: `Each tunnel gets a path under ${domain}`}>
|
||||
<text x={LAYOUT.url.x} y={LAYOUT.label.baseline} fontSize={LAYOUT.label.size}
|
||||
fill="var(--muted)" letterSpacing="0.09em">PUBLIC URL</text>
|
||||
<text x={PORT_X} y={LAYOUT.label.baseline} fontSize={LAYOUT.label.size}
|
||||
fill="var(--muted)" letterSpacing="0.09em">LOCAL PORT</text>
|
||||
|
||||
{ROWS.map(row => (
|
||||
<g key={row.id} transform={`translate(0 ${row.offset})`}>
|
||||
<rect x={LAYOUT.url.x} y={LAYOUT.row.top} width={LAYOUT.url.width} height={LAYOUT.row.height}
|
||||
rx="9" fill="var(--surface-raised)" stroke="var(--border-strong)" />
|
||||
<text x={LAYOUT.url.x + LAYOUT.padding} y={TEXT_BASELINE} fontSize="11.5" fontFamily={MONO}>
|
||||
{isSubdomain ? <>
|
||||
<tspan fill="var(--primary-bright)">{row.id}.</tspan>
|
||||
<tspan fill="var(--subtext)">{host}</tspan>
|
||||
</> : <>
|
||||
<tspan fill="var(--subtext)">{host}</tspan>
|
||||
<tspan fill="var(--primary-bright)">/@{row.id}</tspan>
|
||||
</>}
|
||||
</text>
|
||||
|
||||
<path d={`M${ARROW - 11} ${TEXT_BASELINE - 4.5} h22 m-4.5 -4.5 l4.5 4.5 -4.5 4.5`}
|
||||
fill="none" stroke="var(--border-strong)" strokeWidth="1.5"
|
||||
strokeLinecap="round" strokeLinejoin="round" />
|
||||
|
||||
<rect x={PORT_X} y={LAYOUT.row.top} width={LAYOUT.port.width} height={LAYOUT.row.height}
|
||||
rx="9" fill="var(--surface-raised)" stroke="var(--border)" />
|
||||
<text x={PORT_X + LAYOUT.port.width / 2} y={TEXT_BASELINE} fontSize="11.5" textAnchor="middle"
|
||||
fill="var(--text)" fontFamily={MONO}>{row.port}</text>
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { ForwardingChoice as default, ForwardingChoice, ForwardingExplainer } from "./ForwardingChoice.jsx";
|
||||
export { MODES } from "./modes.js";
|
||||
@@ -0,0 +1,20 @@
|
||||
export const MODES = {
|
||||
subdomain: {
|
||||
title: "Subdomain",
|
||||
summary: "Every tunnel gets its own hostname.",
|
||||
facts: [
|
||||
"The tunnel id becomes a label in front of your base domain.",
|
||||
"Needs a wildcard DNS record and a wildcard certificate.",
|
||||
"Each tunnel is its own origin, so cookies and storage stay separate.",
|
||||
],
|
||||
},
|
||||
path: {
|
||||
title: "Path",
|
||||
summary: "Every tunnel lives under one hostname.",
|
||||
facts: [
|
||||
"The tunnel id becomes a path segment after your base domain.",
|
||||
"Works with a single DNS record and an ordinary certificate.",
|
||||
"All tunnels share one origin; each browser tab is bound to its own.",
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import { memo } from "react";
|
||||
|
||||
export const FrislitLogo = memo(({ size = 40, className = "" }) => {
|
||||
return (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="0 0 512 512"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className={className}
|
||||
style={{ overflow: "visible" }}
|
||||
>
|
||||
<defs>
|
||||
<filter id="glow_frislit" x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox">
|
||||
<feGaussianBlur in="SourceGraphic" stdDeviation="15" result="blur" />
|
||||
<feMerge>
|
||||
<feMergeNode in="blur" />
|
||||
<feMergeNode in="SourceGraphic" />
|
||||
</feMerge>
|
||||
</filter>
|
||||
</defs>
|
||||
<g filter="url(#glow_frislit)">
|
||||
<path d="M96 366V226A160 160 0 0 1 416 226V366" stroke="var(--primary)" strokeWidth="62" strokeLinecap="round" strokeLinejoin="round" />
|
||||
<path d="M196 374V226A60 60 0 0 1 316 226V374" stroke="var(--primary)" strokeOpacity="0.45" strokeWidth="46" strokeLinecap="round" strokeLinejoin="round" />
|
||||
<path d="M150 446H362" stroke="var(--primary)" strokeWidth="62" strokeLinecap="round" strokeLinejoin="round" />
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
});
|
||||
|
||||
FrislitLogo.displayName = "FrislitLogo";
|
||||
@@ -0,0 +1 @@
|
||||
export { FrislitLogo as default } from "./FrislitLogo.jsx";
|
||||
@@ -0,0 +1,5 @@
|
||||
export const GithubMark = ({ size = 16 }) => (
|
||||
<svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<path d="M12 .5a12 12 0 0 0-3.79 23.4c.6.1.82-.26.82-.58v-2.2c-3.34.72-4.04-1.6-4.04-1.6-.55-1.4-1.34-1.77-1.34-1.77-1.09-.74.08-.73.08-.73 1.2.09 1.84 1.24 1.84 1.24 1.07 1.84 2.81 1.31 3.5 1 .1-.78.42-1.31.76-1.61-2.67-.3-5.47-1.34-5.47-5.96 0-1.32.47-2.4 1.24-3.24-.12-.31-.54-1.54.12-3.2 0 0 1.01-.33 3.3 1.23a11.4 11.4 0 0 1 6.01 0c2.29-1.56 3.3-1.23 3.3-1.23.66 1.66.24 2.89.12 3.2.77.84 1.24 1.92 1.24 3.24 0 4.63-2.8 5.65-5.48 5.95.43.37.81 1.1.81 2.22v3.29c0 .32.22.69.83.57A12 12 0 0 0 12 .5Z" />
|
||||
</svg>
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
export { GithubMark as default } from "./GithubMark.jsx";
|
||||
@@ -0,0 +1,21 @@
|
||||
import "./styles.sass";
|
||||
|
||||
export const Input = ({ type = "text", id, name = id, placeholder, value, setValue, onChange, onKeyDown,
|
||||
autoComplete, autoFocus, required, disabled, label, suffix, inputMode }) => {
|
||||
const handleChange = event => {
|
||||
if (setValue) setValue(event.target.value);
|
||||
if (onChange) onChange(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
{label && <label htmlFor={id}>{label}</label>}
|
||||
<div className="field-input">
|
||||
<input type={type} id={id} name={name} placeholder={placeholder} value={value} onChange={handleChange}
|
||||
onKeyDown={onKeyDown} autoComplete={autoComplete} autoFocus={autoFocus} required={required}
|
||||
disabled={disabled} inputMode={inputMode} />
|
||||
{suffix && <span className="field-suffix">{suffix}</span>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Input as default } from "./Input.jsx";
|
||||
@@ -0,0 +1,65 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.field
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.4rem
|
||||
min-width: 0
|
||||
|
||||
label
|
||||
color: colors.$subtext
|
||||
font-size: 0.8125rem
|
||||
font-weight: 500
|
||||
|
||||
.field-input
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.75rem
|
||||
padding: 0 0.875rem
|
||||
transition: border-color 0.15s ease
|
||||
|
||||
&:focus-within
|
||||
border-color: colors.$primary
|
||||
|
||||
input
|
||||
flex: 1
|
||||
min-width: 0
|
||||
background: none
|
||||
border: none
|
||||
outline: none
|
||||
color: colors.$text
|
||||
font-family: inherit
|
||||
font-size: 0.9375rem
|
||||
font-weight: 500
|
||||
padding: 0.625rem 0
|
||||
|
||||
&::placeholder
|
||||
color: colors.$muted
|
||||
|
||||
&:disabled
|
||||
color: colors.$muted
|
||||
cursor: not-allowed
|
||||
|
||||
.field-suffix
|
||||
color: colors.$muted
|
||||
font-size: 0.8125rem
|
||||
white-space: nowrap
|
||||
|
||||
@keyframes field-autofill
|
||||
from
|
||||
opacity: 1
|
||||
to
|
||||
opacity: 1
|
||||
|
||||
.field-input input
|
||||
&:-webkit-autofill,
|
||||
&:-webkit-autofill:hover,
|
||||
&:-webkit-autofill:focus
|
||||
animation-name: field-autofill
|
||||
animation-duration: 1ms
|
||||
box-shadow: 0 0 0 1000px colors.$surface inset
|
||||
-webkit-text-fill-color: colors.$text
|
||||
caret-color: colors.$text
|
||||
@@ -0,0 +1,12 @@
|
||||
import { memo } from "react";
|
||||
import "./styles.sass";
|
||||
|
||||
export const Loading = memo(() => {
|
||||
return (
|
||||
<div className="loading">
|
||||
<span className="loading-spinner" />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
Loading.displayName = "Loading";
|
||||
@@ -0,0 +1 @@
|
||||
export { Loading as default } from "./Loading.jsx";
|
||||
@@ -0,0 +1,20 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.loading
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
padding: 4rem 0
|
||||
flex: 1
|
||||
|
||||
.loading-spinner
|
||||
width: 1.5rem
|
||||
height: 1.5rem
|
||||
border: 2px solid colors.$border-strong
|
||||
border-top-color: colors.$primary
|
||||
border-radius: 50%
|
||||
animation: loading-spin 0.7s linear infinite
|
||||
|
||||
@keyframes loading-spin
|
||||
to
|
||||
transform: rotate(360deg)
|
||||
@@ -0,0 +1,54 @@
|
||||
import "./styles.sass";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Download, Terminal } from "lucide-react";
|
||||
import Button from "@/common/components/Button";
|
||||
import CopyField from "@/common/components/CopyField";
|
||||
import { getRequest } from "@/common/utils/RequestUtil.js";
|
||||
import { detectPlatform, downloadsFor, installCommand } from "@/common/utils/platform.js";
|
||||
|
||||
const HANDOFF_TIMEOUT = 1500;
|
||||
|
||||
export const OpenInFrislit = ({ href }) => {
|
||||
const [missing, setMissing] = useState(null);
|
||||
const timers = useRef([]);
|
||||
|
||||
useEffect(() => () => timers.current.forEach(clearTimeout), []);
|
||||
|
||||
const offerInstall = async () => {
|
||||
const [platform, info] = await Promise.all([detectPlatform(), getRequest("info").catch(() => ({}))]);
|
||||
setMissing({ command: installCommand(platform.os), downloads: downloadsFor(platform, info.version) });
|
||||
};
|
||||
|
||||
const open = () => {
|
||||
setMissing(null);
|
||||
window.location.href = href;
|
||||
|
||||
timers.current.push(setTimeout(() => {
|
||||
if (document.hasFocus()) offerInstall();
|
||||
}, HANDOFF_TIMEOUT));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="open-in-frislit">
|
||||
<Button icon={Terminal} text="Open in frislit" type="secondary" onClick={open} />
|
||||
|
||||
{missing && (
|
||||
<div className="open-in-frislit-install">
|
||||
<p>frislit does not seem to be installed here. Install it, then try again.</p>
|
||||
<CopyField value={missing.command} />
|
||||
<div className="open-in-frislit-files">
|
||||
{missing.downloads.files.map(file => (
|
||||
<a key={file.url} href={file.url} download>
|
||||
<Download size={14} />
|
||||
{file.label}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
<a className="open-in-frislit-all" href={missing.downloads.all} target="_blank" rel="noreferrer noopener">
|
||||
{missing.downloads.version ? `All builds of ${missing.downloads.version}` : "All builds"}
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { OpenInFrislit as default } from "./OpenInFrislit.jsx";
|
||||
@@ -0,0 +1,58 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.open-in-frislit
|
||||
display: flex
|
||||
flex-direction: column
|
||||
align-items: flex-start
|
||||
gap: 0.75rem
|
||||
|
||||
.open-in-frislit-install
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.625rem
|
||||
width: 100%
|
||||
padding: 0.875rem
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.75rem
|
||||
|
||||
> p
|
||||
margin: 0
|
||||
color: colors.$subtext
|
||||
font-size: 0.8125rem
|
||||
|
||||
.open-in-frislit-files
|
||||
display: flex
|
||||
flex-wrap: wrap
|
||||
gap: 0.5rem
|
||||
|
||||
a
|
||||
display: inline-flex
|
||||
align-items: center
|
||||
gap: 0.375rem
|
||||
padding: 0.4375rem 0.75rem
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 0.5rem
|
||||
color: colors.$text
|
||||
font-size: 0.8125rem
|
||||
font-weight: 500
|
||||
text-decoration: none
|
||||
transition: background-color 0.15s ease, border-color 0.15s ease
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
border-color: colors.$primary
|
||||
|
||||
&:first-child
|
||||
border-color: colors.$primary
|
||||
color: colors.$primary-bright
|
||||
|
||||
.open-in-frislit-all
|
||||
color: colors.$muted
|
||||
font-size: 0.75rem
|
||||
text-decoration: none
|
||||
|
||||
&:hover
|
||||
color: colors.$subtext
|
||||
text-decoration: underline
|
||||
@@ -0,0 +1,13 @@
|
||||
import "./styles.sass";
|
||||
import Input from "@/common/components/Input";
|
||||
import { FIELDS } from "./limits.js";
|
||||
|
||||
export const QuotaFields = ({ values, setValues, idPrefix, placeholders }) => (
|
||||
<div className="quota-fields">
|
||||
{FIELDS.map(({ key, label, suffix }) => (
|
||||
<Input key={key} id={`${idPrefix}-${key}`} type="number" inputMode="decimal" label={label} suffix={suffix}
|
||||
placeholder={placeholders ? placeholders[key] : "0"}
|
||||
value={values[key]} setValue={value => setValues({ ...values, [key]: value })} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
export { QuotaFields as default } from "./QuotaFields.jsx";
|
||||
export { FIELDS, toForm, fromForm } from "./limits.js";
|
||||
@@ -0,0 +1,21 @@
|
||||
const GB = 1e9;
|
||||
|
||||
export const FIELDS = [
|
||||
{ key: "tunnels", label: "Tunnels" },
|
||||
{ key: "persistent", label: "Persistent" },
|
||||
{ key: "domains", label: "Domains" },
|
||||
{ key: "traffic", label: "Traffic", suffix: "GB / month" },
|
||||
];
|
||||
|
||||
export const toForm = limits => Object.fromEntries(FIELDS.map(({ key }) => {
|
||||
const value = limits?.[key];
|
||||
if (value === undefined || value === null) return [key, ""];
|
||||
return [key, String(key === "traffic" ? value / GB : value)];
|
||||
}));
|
||||
|
||||
export const fromForm = values => Object.fromEntries(FIELDS.map(({ key }) => {
|
||||
const text = String(values[key] ?? "").trim();
|
||||
if (text === "") return [key, null];
|
||||
const number = Number(text);
|
||||
return [key, key === "traffic" ? Math.round(number * GB) : number];
|
||||
}));
|
||||
@@ -0,0 +1,9 @@
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.quota-fields
|
||||
display: grid
|
||||
grid-template-columns: repeat(4, 1fr)
|
||||
gap: 0.75rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
grid-template-columns: 1fr 1fr
|
||||
@@ -0,0 +1,62 @@
|
||||
import "./styles.sass";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Check, ChevronDown } from "lucide-react";
|
||||
|
||||
export const Select = ({ options, selected, setSelected, label, id, disabled, multiple = false, emptyLabel = "Select" }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef(null);
|
||||
const values = multiple ? selected || [] : [selected];
|
||||
const current = multiple ? null : options.find(option => option.value === selected);
|
||||
const summary = multiple
|
||||
? values.length === 0
|
||||
? emptyLabel
|
||||
: values.length === 1
|
||||
? options.find(option => option.value === values[0])?.label || emptyLabel
|
||||
: `${values.length} selected`
|
||||
: current?.label || emptyLabel;
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const handleClick = event => { if (!ref.current?.contains(event.target)) setOpen(false); };
|
||||
const handleKey = event => { if (event.key === "Escape") setOpen(false); };
|
||||
document.addEventListener("mousedown", handleClick);
|
||||
document.addEventListener("keydown", handleKey);
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", handleClick);
|
||||
document.removeEventListener("keydown", handleKey);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const choose = value => {
|
||||
if (!multiple) {
|
||||
setSelected(value);
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
setSelected(values.includes(value) ? values.filter(entry => entry !== value) : [...values, value]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
{label && <label htmlFor={id}>{label}</label>}
|
||||
<div className={`select${open ? " open" : ""}`} ref={ref}>
|
||||
<button type="button" id={id} className="select-trigger" disabled={disabled} onClick={() => setOpen(!open)}>
|
||||
<span>{summary}</span>
|
||||
<ChevronDown />
|
||||
</button>
|
||||
{open && (
|
||||
<div className="select-menu" role="listbox" aria-multiselectable={multiple || undefined}>
|
||||
{options.map(option => (
|
||||
<button type="button" key={option.value} role="option" aria-selected={values.includes(option.value)}
|
||||
className={`select-option${values.includes(option.value) ? " selected" : ""}`}
|
||||
onClick={() => choose(option.value)}>
|
||||
<span>{option.label}</span>
|
||||
{values.includes(option.value) && <Check />}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Select as default } from "./Select.jsx";
|
||||
@@ -0,0 +1,82 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.select
|
||||
position: relative
|
||||
|
||||
.select-trigger
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: space-between
|
||||
gap: 0.5rem
|
||||
width: 100%
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.75rem
|
||||
padding: 0.625rem 0.875rem
|
||||
color: colors.$text
|
||||
font-family: inherit
|
||||
font-size: 0.9375rem
|
||||
font-weight: 500
|
||||
text-align: left
|
||||
cursor: pointer
|
||||
transition: border-color 0.15s ease
|
||||
|
||||
svg
|
||||
width: 1.125rem
|
||||
height: 1.125rem
|
||||
color: colors.$muted
|
||||
flex-shrink: 0
|
||||
transition: transform 0.15s ease
|
||||
|
||||
&:disabled
|
||||
color: colors.$muted
|
||||
cursor: not-allowed
|
||||
|
||||
.select.open .select-trigger
|
||||
border-color: colors.$primary
|
||||
|
||||
svg
|
||||
transform: rotate(180deg)
|
||||
|
||||
.select-menu
|
||||
position: absolute
|
||||
top: calc(100% + 0.375rem)
|
||||
left: 0
|
||||
right: 0
|
||||
z-index: 50
|
||||
max-height: 15rem
|
||||
overflow-y: auto
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 0.75rem
|
||||
padding: 0.25rem
|
||||
box-shadow: colors.$shadow-lg
|
||||
|
||||
.select-option
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: space-between
|
||||
gap: 0.5rem
|
||||
width: 100%
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.5rem
|
||||
padding: 0.5rem 0.625rem
|
||||
color: colors.$subtext
|
||||
font-family: inherit
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
text-align: left
|
||||
cursor: pointer
|
||||
|
||||
svg
|
||||
width: 1rem
|
||||
height: 1rem
|
||||
color: colors.$primary
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
&.selected
|
||||
color: colors.$text
|
||||
@@ -0,0 +1,25 @@
|
||||
import "./styles.sass";
|
||||
import Input from "@/common/components/Input";
|
||||
import Select from "@/common/components/Select";
|
||||
|
||||
export const ServerSettingsForm = ({ values, setValues, idPrefix = "settings", showHttpMode = true }) => {
|
||||
const update = (key, value) => setValues({ ...values, [key]: value });
|
||||
|
||||
return (
|
||||
<div className="settings-form">
|
||||
<Input id={`${idPrefix}-baseDomain`} label="Base domain" placeholder="frislit.example.com"
|
||||
value={values.baseDomain} setValue={value => update("baseDomain", value)} autoComplete="off" />
|
||||
<Input id={`${idPrefix}-publicUrl`} label="Public URL" placeholder={`https://${values.baseDomain || "frislit.example.com"}`}
|
||||
value={values.publicUrl} setValue={value => update("publicUrl", value)} autoComplete="off" />
|
||||
{showHttpMode && (
|
||||
<Select id={`${idPrefix}-httpMode`} label="Forwarding mode" selected={values.httpMode}
|
||||
setSelected={value => update("httpMode", value)}
|
||||
options={[{ value: "subdomain", label: "Subdomain" }, { value: "path", label: "Path" }]} />
|
||||
)}
|
||||
<div className="settings-form-row">
|
||||
<Input id={`${idPrefix}-gracePeriod`} type="number" label="Grace period" suffix="sec"
|
||||
value={values.gracePeriod} setValue={value => update("gracePeriod", value)} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { ServerSettingsForm as default, ServerSettingsForm } from "./ServerSettingsForm.jsx";
|
||||
export { normalizeSettings } from "./normalizeSettings.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
export const normalizeSettings = values => ({
|
||||
baseDomain: values.baseDomain.trim(),
|
||||
publicUrl: values.publicUrl.trim(),
|
||||
httpMode: values.httpMode,
|
||||
tlsMode: values.tlsMode || "proxy",
|
||||
gracePeriod: Number(values.gracePeriod),
|
||||
trustProxy: values.tlsMode === "acme" ? false : !!values.trustProxy,
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.settings-form
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.875rem
|
||||
|
||||
.settings-form-row
|
||||
display: flex
|
||||
gap: 0.75rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
flex-direction: column
|
||||
|
||||
> *
|
||||
flex: 1
|
||||
min-width: 0
|
||||
@@ -0,0 +1,28 @@
|
||||
import { TlsDiagram } from "./TlsDiagram.jsx";
|
||||
import { TLS_MODES } from "./modes.js";
|
||||
|
||||
export const TlsChoice = ({ value, onChange, onPreview, disabled }) => (
|
||||
<div className="mode-choices" onMouseLeave={() => onPreview?.(null)}>
|
||||
{Object.entries(TLS_MODES).map(([mode, details]) => (
|
||||
<button type="button" key={mode} aria-pressed={value === mode}
|
||||
className={`mode-choice${value === mode ? " selected" : ""}`} disabled={disabled && value !== mode}
|
||||
onMouseEnter={() => onPreview?.(mode)}
|
||||
onFocus={() => onPreview?.(mode)}
|
||||
onClick={() => onChange(mode)}>
|
||||
<span className="mode-choice-title">
|
||||
{details.title}
|
||||
<span className="mode-choice-mark" aria-hidden="true" />
|
||||
</span>
|
||||
<span className="mode-choice-summary">{details.summary}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
export const TlsExplainer = ({ mode }) => (
|
||||
<div className="mode-explainer">
|
||||
<TlsDiagram mode={mode} />
|
||||
<h3>{TLS_MODES[mode].title}</h3>
|
||||
<ul>{TLS_MODES[mode].facts.map(fact => <li key={fact}>{fact}</li>)}</ul>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
const BOX = { width: 92, height: 42, radius: 10 };
|
||||
const GAP = 40;
|
||||
const PAD = 4;
|
||||
const WIDTH = BOX.width * 3 + GAP * 2 + PAD * 2;
|
||||
const HEIGHT = BOX.height + PAD * 2;
|
||||
const MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
|
||||
|
||||
const CHAINS = {
|
||||
acme: [
|
||||
{ label: "Visitor", port: "https" },
|
||||
{ label: "frislit", port: ":443", accent: true },
|
||||
],
|
||||
proxy: [
|
||||
{ label: "Visitor", port: "https" },
|
||||
{ label: "nginx", port: ":443" },
|
||||
{ label: "frislit", port: ":8080", accent: true },
|
||||
],
|
||||
};
|
||||
|
||||
export const TlsDiagram = ({ mode }) => {
|
||||
const chain = CHAINS[mode] || CHAINS.proxy;
|
||||
const span = chain.length * BOX.width + (chain.length - 1) * GAP;
|
||||
const left = (WIDTH - span) / 2;
|
||||
|
||||
return (
|
||||
<svg className="mode-diagram" viewBox={`0 0 ${WIDTH} ${HEIGHT}`} role="img"
|
||||
aria-label={mode === "acme"
|
||||
? "Visitors reach frislit directly over HTTPS"
|
||||
: "Visitors reach your proxy, which forwards to frislit over plain HTTP"}>
|
||||
{chain.map((node, index) => {
|
||||
const x = left + index * (BOX.width + GAP);
|
||||
return (
|
||||
<g key={node.label}>
|
||||
<rect x={x} y={PAD} width={BOX.width} height={BOX.height} rx={BOX.radius}
|
||||
fill="var(--surface-raised)"
|
||||
stroke={node.accent ? "var(--primary)" : "var(--border-strong)"} />
|
||||
<text x={x + BOX.width / 2} y={PAD + 18} fontSize="11" textAnchor="middle"
|
||||
fill="var(--text)">{node.label}</text>
|
||||
<text x={x + BOX.width / 2} y={PAD + 31} fontSize="10" textAnchor="middle" fontFamily={MONO}
|
||||
fill={node.accent ? "var(--primary-bright)" : "var(--muted)"}>{node.port}</text>
|
||||
|
||||
{index < chain.length - 1 && (
|
||||
<path d={`M${x + BOX.width + 8} ${PAD + BOX.height / 2} h${GAP - 16} m-5 -5 l5 5 -5 5`}
|
||||
fill="none" stroke="var(--border-strong)" strokeWidth="1.5"
|
||||
strokeLinecap="round" strokeLinejoin="round" />
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { TlsChoice as default, TlsChoice, TlsExplainer } from "./TlsChoice.jsx";
|
||||
export { TLS_MODES } from "./modes.js";
|
||||
@@ -0,0 +1,20 @@
|
||||
export const TLS_MODES = {
|
||||
proxy: {
|
||||
title: "Behind a proxy",
|
||||
summary: "nginx or Caddy terminates TLS and forwards to frislit.",
|
||||
facts: [
|
||||
"frislit serves plain HTTP on one port and never sees a certificate.",
|
||||
"Your proxy already holds the wildcard certificate and renews it.",
|
||||
"Trust the X-Forwarded-* headers so tunnels see the real visitor.",
|
||||
],
|
||||
},
|
||||
acme: {
|
||||
title: "frislit manages it",
|
||||
summary: "frislit gets certificates from Let's Encrypt and serves HTTPS.",
|
||||
facts: [
|
||||
"Listens on 443 for traffic and on 80 to send visitors to HTTPS.",
|
||||
"Renews on its own, thirty days before a certificate runs out.",
|
||||
"Nothing else needs to run in front of it.",
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import "./styles.sass";
|
||||
|
||||
export const Toggle = ({ checked, onChange, id, disabled, label }) => {
|
||||
return (
|
||||
<div className="toggle-row">
|
||||
{label && <label htmlFor={id}>{label}</label>}
|
||||
<button type="button" id={id} role="switch" aria-checked={!!checked} disabled={disabled}
|
||||
className={`toggle${checked ? " on" : ""}`} onClick={() => onChange(!checked)}>
|
||||
<span className="toggle-knob" />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Toggle as default } from "./Toggle.jsx";
|
||||
@@ -0,0 +1,45 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.toggle-row
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: space-between
|
||||
gap: 1rem
|
||||
|
||||
label
|
||||
color: colors.$subtext
|
||||
font-size: 0.8125rem
|
||||
font-weight: 500
|
||||
|
||||
.toggle
|
||||
position: relative
|
||||
width: 2.5rem
|
||||
height: 1.4rem
|
||||
flex-shrink: 0
|
||||
border: none
|
||||
border-radius: 999px
|
||||
background-color: colors.$border-strong
|
||||
cursor: pointer
|
||||
padding: 0
|
||||
transition: background-color 0.15s ease
|
||||
|
||||
.toggle-knob
|
||||
position: absolute
|
||||
top: 0.2rem
|
||||
left: 0.2rem
|
||||
width: 1rem
|
||||
height: 1rem
|
||||
border-radius: 50%
|
||||
background-color: colors.$subtext
|
||||
transition: transform 0.15s ease, background-color 0.15s ease
|
||||
|
||||
&.on
|
||||
background-color: colors.$primary
|
||||
|
||||
.toggle-knob
|
||||
transform: translateX(1.1rem)
|
||||
background-color: colors.$on-primary
|
||||
|
||||
&:disabled
|
||||
opacity: 0.45
|
||||
cursor: not-allowed
|
||||
@@ -0,0 +1,66 @@
|
||||
import "./styles.sass";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { NavLink, useNavigate } from "react-router-dom";
|
||||
import { BookOpen, ChevronDown, LogOut } from "lucide-react";
|
||||
import GithubMark from "@/common/components/GithubMark";
|
||||
import FrislitLogo from "@/common/components/FrislitLogo";
|
||||
import ActionConfirmDialog from "@/common/components/ActionConfirmDialog";
|
||||
import { useUser } from "@/common/contexts/user.js";
|
||||
import { getNavigation } from "@/common/utils/navigationConfig.js";
|
||||
import { DOCS_URL, GITHUB_URL } from "@/App.jsx";
|
||||
|
||||
export const TopNav = () => {
|
||||
const { user, logout } = useUser();
|
||||
const navigate = useNavigate();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [logoutOpen, setLogoutOpen] = useState(false);
|
||||
const menuRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!menuOpen) return;
|
||||
const handleClick = event => { if (!menuRef.current?.contains(event.target)) setMenuOpen(false); };
|
||||
document.addEventListener("mousedown", handleClick);
|
||||
return () => document.removeEventListener("mousedown", handleClick);
|
||||
}, [menuOpen]);
|
||||
|
||||
return (
|
||||
<header className="topnav">
|
||||
<ActionConfirmDialog open={logoutOpen} setOpen={setLogoutOpen} onConfirm={logout}
|
||||
title="Log out" text="You will need to sign in again." confirmText="Log out" />
|
||||
<div className="topnav-inner">
|
||||
<div className="topnav-brand" onClick={() => navigate("/tunnels")}>
|
||||
<FrislitLogo size={26} />
|
||||
<span className="wordmark">fris<em>lit</em></span>
|
||||
</div>
|
||||
<nav className="topnav-links">
|
||||
{getNavigation().map(({ key, path, title, icon: Glyph }) => (
|
||||
<NavLink key={key} to={path} className={({ isActive }) => `topnav-link${isActive ? " active" : ""}`}>
|
||||
<Glyph size={15} />{title}
|
||||
</NavLink>
|
||||
))}
|
||||
</nav>
|
||||
<div className="topnav-account" ref={menuRef}>
|
||||
<button type="button" className={`topnav-user${menuOpen ? " open" : ""}`} onClick={() => setMenuOpen(!menuOpen)}>
|
||||
<span className="topnav-avatar">{user?.username?.[0]?.toUpperCase()}</span>
|
||||
<span className="topnav-username">{user?.username}</span>
|
||||
<ChevronDown />
|
||||
</button>
|
||||
{menuOpen && (
|
||||
<div className="topnav-menu">
|
||||
<a className="topnav-menu-item" href={DOCS_URL} target="_blank" rel="noreferrer" onClick={() => setMenuOpen(false)}>
|
||||
<BookOpen />Documentation
|
||||
</a>
|
||||
<a className="topnav-menu-item" href={GITHUB_URL} target="_blank" rel="noreferrer" onClick={() => setMenuOpen(false)}>
|
||||
<GithubMark />GitHub
|
||||
</a>
|
||||
<div className="topnav-menu-divider" />
|
||||
<button type="button" className="topnav-menu-item danger" onClick={() => { setMenuOpen(false); setLogoutOpen(true); }}>
|
||||
<LogOut />Log out
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { TopNav as default } from "./TopNav.jsx";
|
||||
@@ -0,0 +1,161 @@
|
||||
@use "@/common/styles/colors"
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.topnav
|
||||
flex-shrink: 0
|
||||
border-bottom: 1px solid colors.$border
|
||||
background-color: colors.$background
|
||||
position: sticky
|
||||
top: 0
|
||||
z-index: 40
|
||||
|
||||
.topnav-inner
|
||||
max-width: 68rem
|
||||
margin: 0 auto
|
||||
height: 3.5rem
|
||||
padding: 0 2rem
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 2rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
padding: 0 1rem
|
||||
gap: 1rem
|
||||
|
||||
.topnav-brand
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
cursor: pointer
|
||||
user-select: none
|
||||
flex-shrink: 0
|
||||
|
||||
span
|
||||
font-size: 1rem
|
||||
font-weight: 700
|
||||
letter-spacing: -0.02em
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
span
|
||||
display: none
|
||||
|
||||
.topnav-links
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.25rem
|
||||
flex: 1
|
||||
min-width: 0
|
||||
overflow-x: auto
|
||||
scrollbar-width: none
|
||||
|
||||
&::-webkit-scrollbar
|
||||
display: none
|
||||
|
||||
.topnav-link
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.45rem
|
||||
padding: 0.375rem 0.75rem
|
||||
border-radius: 0.625rem
|
||||
color: colors.$muted
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
white-space: nowrap
|
||||
transition: color 0.15s ease, background-color 0.15s ease
|
||||
|
||||
&:hover
|
||||
color: colors.$text
|
||||
|
||||
&.active
|
||||
color: colors.$text
|
||||
background-color: colors.$surface-hover
|
||||
|
||||
.topnav-account
|
||||
position: relative
|
||||
flex-shrink: 0
|
||||
|
||||
.topnav-user
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.625rem
|
||||
padding: 0.3rem 0.5rem 0.3rem 0.3rem
|
||||
color: colors.$subtext
|
||||
font-family: inherit
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
cursor: pointer
|
||||
transition: background-color 0.15s ease, color 0.15s ease
|
||||
|
||||
svg
|
||||
width: 1rem
|
||||
height: 1rem
|
||||
color: colors.$muted
|
||||
|
||||
&:hover, &.open
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
.topnav-username
|
||||
display: none
|
||||
|
||||
.topnav-avatar
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: center
|
||||
width: 1.625rem
|
||||
height: 1.625rem
|
||||
flex-shrink: 0
|
||||
border-radius: 0.5rem
|
||||
background-color: colors.$primary-tint
|
||||
color: colors.$primary
|
||||
font-size: 0.75rem
|
||||
font-weight: 700
|
||||
|
||||
.topnav-menu
|
||||
position: absolute
|
||||
top: calc(100% + 0.5rem)
|
||||
right: 0
|
||||
min-width: 11rem
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 0.75rem
|
||||
padding: 0.25rem
|
||||
box-shadow: colors.$shadow-lg
|
||||
z-index: 50
|
||||
|
||||
.topnav-menu-item
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.625rem
|
||||
width: 100%
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0.5rem
|
||||
padding: 0.5rem 0.625rem
|
||||
color: colors.$subtext
|
||||
font-family: inherit
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
text-align: left
|
||||
cursor: pointer
|
||||
|
||||
svg
|
||||
width: 1rem
|
||||
height: 1rem
|
||||
|
||||
&:hover
|
||||
background-color: colors.$surface-hover
|
||||
color: colors.$text
|
||||
|
||||
&.danger:hover
|
||||
background-color: colors.$error-tint
|
||||
color: colors.$error
|
||||
|
||||
.topnav-menu-divider
|
||||
height: 1px
|
||||
background-color: colors.$border
|
||||
margin: 0.25rem 0
|
||||
@@ -0,0 +1,19 @@
|
||||
import "./styles.sass";
|
||||
import { FIELDS } from "@/common/components/QuotaFields";
|
||||
import { formatBytes } from "@/common/utils/formatUtils.js";
|
||||
|
||||
const show = (key, value) => (key === "traffic" ? formatBytes(value) : value);
|
||||
|
||||
export const UsageSummary = ({ usage, limits }) => (
|
||||
<ul className="usage-summary">
|
||||
{FIELDS.map(({ key, label }) => (
|
||||
<li key={key}>
|
||||
<span className="usage-label">{label}</span>
|
||||
<span className="usage-value">
|
||||
{show(key, usage[key])}
|
||||
<span className="usage-limit">{limits[key] ? ` / ${show(key, limits[key])}` : ""}</span>
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
export { UsageSummary as default } from "./UsageSummary.jsx";
|
||||
@@ -0,0 +1,32 @@
|
||||
@use "@/common/styles/colors"
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.usage-summary
|
||||
display: grid
|
||||
grid-template-columns: repeat(4, 1fr)
|
||||
gap: 0.75rem
|
||||
|
||||
li
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.125rem
|
||||
padding: 0.75rem 0.875rem
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.75rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
grid-template-columns: 1fr 1fr
|
||||
|
||||
.usage-label
|
||||
color: colors.$muted
|
||||
font-size: 0.75rem
|
||||
|
||||
.usage-value
|
||||
font-size: 1rem
|
||||
font-weight: 600
|
||||
font-variant-numeric: tabular-nums
|
||||
|
||||
.usage-limit
|
||||
color: colors.$muted
|
||||
font-weight: 500
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useCallback, useState } from "react";
|
||||
import { ToastContext } from "./toast.js";
|
||||
import "@/common/styles/toast.sass";
|
||||
import { CircleAlert, CircleCheck, Info, X } from "lucide-react";
|
||||
|
||||
const ICONS = {
|
||||
Success: CircleCheck,
|
||||
Error: CircleAlert,
|
||||
Info: Info,
|
||||
};
|
||||
|
||||
export const ToastProvider = ({ children }) => {
|
||||
const [toasts, setToasts] = useState([]);
|
||||
|
||||
const removeToast = useCallback(id => setToasts(prev => prev.filter(toast => toast.id !== id)), []);
|
||||
|
||||
const sendToast = useCallback((type, message, duration = 4000) => {
|
||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
setToasts(prev => [...prev, { id, type, message }]);
|
||||
setTimeout(() => removeToast(id), duration);
|
||||
return id;
|
||||
}, [removeToast]);
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={{ sendToast, removeToast }}>
|
||||
{children}
|
||||
<div className="toast-container">
|
||||
{toasts.map(toast => {
|
||||
const Glyph = ICONS[toast.type] || ICONS.Info;
|
||||
return (
|
||||
<div className="toast" key={toast.id} data-type={toast.type}>
|
||||
<Glyph />
|
||||
<span>{toast.message}</span>
|
||||
<button type="button" onClick={() => removeToast(toast.id)} aria-label="Dismiss">
|
||||
<X />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { UserContext } from "./user.js";
|
||||
import { getRequest, postRequest } from "@/common/utils/RequestUtil.js";
|
||||
|
||||
export const UserProvider = ({ children }) => {
|
||||
const [user, setUser] = useState(null);
|
||||
const [setupRequired, setSetupRequired] = useState(false);
|
||||
const [serverInfo, setServerInfo] = useState(null);
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
const checkSetup = useCallback(async () => {
|
||||
const status = await getRequest("setup/status");
|
||||
setSetupRequired(status.setupRequired);
|
||||
return status;
|
||||
}, []);
|
||||
|
||||
const login = useCallback(async () => {
|
||||
try {
|
||||
setUser(await getRequest("auth/me"));
|
||||
return true;
|
||||
} catch {
|
||||
setUser(null);
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
await postRequest("auth/logout");
|
||||
} catch { /* the session may already be gone */ }
|
||||
setUser(null);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([checkSetup(), login(), getRequest("info").then(setServerInfo).catch(() => null)])
|
||||
.catch(console.error)
|
||||
.finally(() => setLoaded(true));
|
||||
}, [checkSetup, login]);
|
||||
|
||||
return (
|
||||
<UserContext.Provider value={{ user, setUser, setupRequired, setSetupRequired, serverInfo, loaded, login, logout, checkSetup }}>
|
||||
{children}
|
||||
</UserContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const ToastContext = createContext({});
|
||||
|
||||
export const useToast = () => useContext(ToastContext);
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const UserContext = createContext({});
|
||||
|
||||
export const useUser = () => useContext(UserContext);
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
import { Suspense } from "react";
|
||||
import { UserProvider } from "@/common/contexts/UserContext.jsx";
|
||||
import { useUser } from "@/common/contexts/user.js";
|
||||
import { ToastProvider } from "@/common/contexts/ToastContext.jsx";
|
||||
import Loading from "@/common/components/Loading";
|
||||
import { ErrorBoundary } from "@/common/components/ErrorBoundary";
|
||||
import PublicShell from "./PublicShell.jsx";
|
||||
|
||||
const PublicContent = () => {
|
||||
const { loaded, setupRequired } = useUser();
|
||||
const { pathname } = useLocation();
|
||||
|
||||
if (!loaded) return <Loading />;
|
||||
if (setupRequired && pathname !== "/setup") return <Navigate to="/setup" replace />;
|
||||
|
||||
return (
|
||||
<PublicShell>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
</PublicShell>
|
||||
);
|
||||
};
|
||||
|
||||
const PublicRoot = () => (
|
||||
<ErrorBoundary>
|
||||
<ToastProvider>
|
||||
<UserProvider>
|
||||
<PublicContent />
|
||||
</UserProvider>
|
||||
</ToastProvider>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
||||
export default PublicRoot;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { useState } from "react";
|
||||
import { AsideContext } from "./aside.js";
|
||||
import FrislitLogo from "@/common/components/FrislitLogo";
|
||||
import "./public.sass";
|
||||
|
||||
export const PublicShell = ({ children }) => {
|
||||
const [aside, setAside] = useState(null);
|
||||
|
||||
return (
|
||||
<AsideContext.Provider value={setAside}>
|
||||
<div className="split">
|
||||
<div className="split-form">
|
||||
<div className="split-form-inner">{children}</div>
|
||||
</div>
|
||||
<aside className={`split-hero${aside ? " filled" : ""}`}>
|
||||
{aside || <>
|
||||
<FrislitLogo size={40} className="split-hero-logo" />
|
||||
<h2>One port.<br />Every tunnel.</h2>
|
||||
</>}
|
||||
</aside>
|
||||
</div>
|
||||
</AsideContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default PublicShell;
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
import { Suspense } from "react";
|
||||
import { UserProvider } from "@/common/contexts/UserContext.jsx";
|
||||
import { useUser } from "@/common/contexts/user.js";
|
||||
import { ToastProvider } from "@/common/contexts/ToastContext.jsx";
|
||||
import Loading from "@/common/components/Loading";
|
||||
import { ErrorBoundary } from "@/common/components/ErrorBoundary";
|
||||
import TopNav from "@/common/components/TopNav";
|
||||
import Footer from "@/common/components/Footer";
|
||||
|
||||
const AppContent = () => {
|
||||
const { loaded, user, setupRequired } = useUser();
|
||||
const location = useLocation();
|
||||
|
||||
if (!loaded) return <Loading />;
|
||||
if (setupRequired) return <Navigate to="/setup" replace />;
|
||||
if (!user) return <Navigate to="/login" replace state={{ from: location.pathname }} />;
|
||||
|
||||
return (
|
||||
<div className="app-wrapper">
|
||||
<TopNav />
|
||||
<main className="main-content">
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const Root = () => (
|
||||
<ErrorBoundary>
|
||||
<ToastProvider>
|
||||
<UserProvider>
|
||||
<AppContent />
|
||||
</UserProvider>
|
||||
</ToastProvider>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
||||
export default Root;
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
export const AsideContext = createContext(null);
|
||||
|
||||
export const usePublicAside = () => useContext(AsideContext) || (() => {});
|
||||
@@ -0,0 +1,90 @@
|
||||
@use "@/common/styles/colors"
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.split
|
||||
display: grid
|
||||
grid-template-columns: 1fr 1fr
|
||||
height: 100vh
|
||||
|
||||
@media (max-width: breakpoints.$tablet)
|
||||
grid-template-columns: 1fr
|
||||
|
||||
.split-form
|
||||
display: flex
|
||||
align-items: center
|
||||
justify-content: flex-end
|
||||
overflow-y: auto
|
||||
padding: 3rem 2rem
|
||||
|
||||
@media (max-width: breakpoints.$tablet)
|
||||
justify-content: center
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
padding: 2rem 1.25rem
|
||||
|
||||
.split-form-inner
|
||||
width: 100%
|
||||
max-width: 23rem
|
||||
|
||||
.split-hero
|
||||
position: relative
|
||||
overflow: hidden
|
||||
display: flex
|
||||
flex-direction: column
|
||||
justify-content: flex-end
|
||||
padding: 3.5rem
|
||||
|
||||
&.filled
|
||||
justify-content: center
|
||||
background: radial-gradient(90% 70% at 85% 15%, rgba(20, 184, 166, 0.16), transparent 70%), linear-gradient(200deg, #16211F 0%, #0C0F0F 55%, #000000 100%)
|
||||
border-left: 1px solid colors.$border
|
||||
|
||||
&::after
|
||||
content: ""
|
||||
position: absolute
|
||||
inset: 0
|
||||
background: radial-gradient(60% 50% at 50% 120%, rgba(13, 148, 136, 0.18), transparent 70%)
|
||||
pointer-events: none
|
||||
|
||||
h2
|
||||
position: relative
|
||||
font-size: 2.75rem
|
||||
line-height: 1.1
|
||||
letter-spacing: -0.04em
|
||||
color: colors.$text
|
||||
|
||||
@media (max-width: breakpoints.$tablet)
|
||||
display: none
|
||||
|
||||
.split-hero-logo
|
||||
position: absolute
|
||||
top: 3.5rem
|
||||
left: 3.5rem
|
||||
opacity: 0.9
|
||||
|
||||
.form-head
|
||||
margin-bottom: 1.75rem
|
||||
|
||||
h1
|
||||
font-size: 1.875rem
|
||||
margin-bottom: 0.5rem
|
||||
|
||||
p
|
||||
margin: 0
|
||||
color: colors.$subtext
|
||||
font-size: 0.875rem
|
||||
line-height: 1.55
|
||||
|
||||
.form-body
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.875rem
|
||||
|
||||
.form-actions
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.5rem
|
||||
margin-top: 1.5rem
|
||||
|
||||
.spacer
|
||||
flex: 1
|
||||
@@ -0,0 +1,2 @@
|
||||
$mobile: 768px
|
||||
$tablet: 1024px
|
||||
@@ -0,0 +1,128 @@
|
||||
@use "@/common/styles/colors"
|
||||
@use "@/common/styles/breakpoints"
|
||||
|
||||
.mode-choices
|
||||
display: grid
|
||||
grid-template-columns: 1fr 1fr
|
||||
gap: 0.75rem
|
||||
|
||||
@media (max-width: 30rem)
|
||||
grid-template-columns: 1fr
|
||||
|
||||
.mode-choice
|
||||
display: flex
|
||||
flex-direction: column
|
||||
align-items: stretch
|
||||
gap: 0.3rem
|
||||
padding: 0.875rem
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.875rem
|
||||
color: colors.$text
|
||||
font-family: inherit
|
||||
text-align: left
|
||||
cursor: pointer
|
||||
transition: border-color 0.15s ease, background-color 0.15s ease
|
||||
|
||||
&:hover
|
||||
border-color: colors.$border-strong
|
||||
|
||||
&:disabled
|
||||
opacity: 0.45
|
||||
cursor: not-allowed
|
||||
|
||||
&:hover
|
||||
border-color: colors.$border
|
||||
|
||||
&.selected
|
||||
border-color: colors.$primary
|
||||
background-color: colors.$primary-tint
|
||||
|
||||
.mode-choice-mark
|
||||
border-color: colors.$primary
|
||||
background-color: colors.$primary
|
||||
|
||||
&::after
|
||||
opacity: 1
|
||||
|
||||
&:focus-visible
|
||||
outline: 2px solid colors.$primary
|
||||
outline-offset: 2px
|
||||
|
||||
.mode-choice-title
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.4rem
|
||||
font-size: 0.9375rem
|
||||
font-weight: 600
|
||||
|
||||
.mode-choice-mark
|
||||
position: relative
|
||||
width: 0.9375rem
|
||||
height: 0.9375rem
|
||||
margin-left: auto
|
||||
flex-shrink: 0
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 999px
|
||||
|
||||
&::after
|
||||
content: ""
|
||||
position: absolute
|
||||
inset: 0.1875rem
|
||||
border-radius: 999px
|
||||
background-color: colors.$on-primary
|
||||
opacity: 0
|
||||
|
||||
.mode-choice-summary
|
||||
color: colors.$subtext
|
||||
font-size: 0.8125rem
|
||||
line-height: 1.45
|
||||
|
||||
.mode-explainer
|
||||
position: relative
|
||||
width: 100%
|
||||
max-width: 26rem
|
||||
|
||||
h3
|
||||
margin-top: 1.5rem
|
||||
font-size: 1.25rem
|
||||
font-weight: 600
|
||||
letter-spacing: -0.025em
|
||||
|
||||
ul
|
||||
margin-top: 0.625rem
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.4rem
|
||||
|
||||
li
|
||||
position: relative
|
||||
padding-left: 0.875rem
|
||||
color: colors.$subtext
|
||||
font-size: 0.8125rem
|
||||
line-height: 1.5
|
||||
|
||||
&::before
|
||||
content: ""
|
||||
position: absolute
|
||||
left: 0
|
||||
top: 0.5rem
|
||||
width: 0.25rem
|
||||
height: 0.25rem
|
||||
border-radius: 999px
|
||||
background-color: colors.$primary
|
||||
|
||||
.mode-diagram
|
||||
width: 100%
|
||||
height: auto
|
||||
|
||||
.mode-explainer-inline
|
||||
display: none
|
||||
margin-top: 1.25rem
|
||||
padding: 1rem
|
||||
background-color: colors.$surface
|
||||
border: 1px solid colors.$border
|
||||
border-radius: 0.875rem
|
||||
|
||||
@media (max-width: breakpoints.$tablet)
|
||||
display: block
|
||||
@@ -0,0 +1,55 @@
|
||||
:root
|
||||
--background: #11100E
|
||||
--surface: #171613
|
||||
--surface-raised: #1C1A17
|
||||
--surface-hover: #221F1B
|
||||
--border: rgba(255, 255, 255, 0.07)
|
||||
--border-strong: rgba(255, 255, 255, 0.13)
|
||||
|
||||
--primary: #14B8A6
|
||||
--primary-deep: #0D9488
|
||||
--primary-bright: #2DD4BF
|
||||
--primary-hover: #5EEAD4
|
||||
--primary-tint: rgba(20, 184, 166, 0.14)
|
||||
--on-primary: #05201C
|
||||
|
||||
--text: #FAFAF9
|
||||
--subtext: #A8A29E
|
||||
--muted: #79716B
|
||||
|
||||
--error: #F87171
|
||||
--error-tint: rgba(248, 113, 113, 0.13)
|
||||
--success: #34D399
|
||||
--success-tint: rgba(52, 211, 153, 0.13)
|
||||
--warning: #FBBF24
|
||||
--warning-tint: rgba(251, 191, 36, 0.13)
|
||||
|
||||
--chart-in: #0D9488
|
||||
--chart-out: #D97706
|
||||
|
||||
--shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4)
|
||||
--shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5)
|
||||
|
||||
$background: var(--background)
|
||||
$surface: var(--surface)
|
||||
$surface-raised: var(--surface-raised)
|
||||
$surface-hover: var(--surface-hover)
|
||||
$border: var(--border)
|
||||
$border-strong: var(--border-strong)
|
||||
$primary: var(--primary)
|
||||
$primary-deep: var(--primary-deep)
|
||||
$primary-bright: var(--primary-bright)
|
||||
$primary-hover: var(--primary-hover)
|
||||
$primary-tint: var(--primary-tint)
|
||||
$on-primary: var(--on-primary)
|
||||
$text: var(--text)
|
||||
$subtext: var(--subtext)
|
||||
$muted: var(--muted)
|
||||
$error: var(--error)
|
||||
$error-tint: var(--error-tint)
|
||||
$success: var(--success)
|
||||
$success-tint: var(--success-tint)
|
||||
$warning: var(--warning)
|
||||
$warning-tint: var(--warning-tint)
|
||||
$shadow-md: var(--shadow-md)
|
||||
$shadow-lg: var(--shadow-lg)
|
||||
@@ -0,0 +1,93 @@
|
||||
@use "colors"
|
||||
@use "breakpoints"
|
||||
@use "choices"
|
||||
|
||||
*
|
||||
box-sizing: border-box
|
||||
|
||||
ul, ol
|
||||
margin: 0
|
||||
padding: 0
|
||||
list-style: none
|
||||
|
||||
body, html
|
||||
margin: 0
|
||||
height: 100%
|
||||
background-color: colors.$background
|
||||
color: colors.$text
|
||||
font-family: "Plus Jakarta Sans", sans-serif
|
||||
font-weight: 500
|
||||
-webkit-font-smoothing: antialiased
|
||||
|
||||
h1, h2, h3
|
||||
letter-spacing: -0.025em
|
||||
font-weight: 600
|
||||
margin: 0
|
||||
|
||||
a
|
||||
color: inherit
|
||||
text-decoration: none
|
||||
|
||||
code, pre
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
|
||||
|
||||
.app-wrapper
|
||||
display: flex
|
||||
flex-direction: column
|
||||
height: 100vh
|
||||
overflow: hidden
|
||||
|
||||
.main-content
|
||||
flex: 1
|
||||
overflow-y: auto
|
||||
min-height: 0
|
||||
transition: padding-right 0.18s ease
|
||||
|
||||
@media (min-width: 90rem)
|
||||
body.panel-open &
|
||||
padding-right: 40rem
|
||||
|
||||
.page
|
||||
max-width: 68rem
|
||||
margin: 0 auto
|
||||
padding: 2.5rem 2rem 4rem
|
||||
|
||||
@media (max-width: breakpoints.$mobile)
|
||||
padding: 1.5rem 1rem 3rem
|
||||
|
||||
.page-title
|
||||
display: flex
|
||||
align-items: flex-end
|
||||
justify-content: space-between
|
||||
gap: 1rem
|
||||
margin-bottom: 1.75rem
|
||||
|
||||
h1
|
||||
font-size: 1.875rem
|
||||
|
||||
.page-title-meta
|
||||
color: colors.$muted
|
||||
font-size: 0.8125rem
|
||||
font-weight: 500
|
||||
|
||||
.page-title-side
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.875rem
|
||||
|
||||
::-webkit-scrollbar
|
||||
width: 10px
|
||||
|
||||
::-webkit-scrollbar-track
|
||||
background: transparent
|
||||
|
||||
::-webkit-scrollbar-thumb
|
||||
background: colors.$border-strong
|
||||
border-radius: 10px
|
||||
|
||||
&:hover
|
||||
background: colors.$subtext
|
||||
|
||||
.wordmark em
|
||||
font-style: normal
|
||||
color: colors.$primary
|
||||
@@ -0,0 +1,59 @@
|
||||
@use "colors"
|
||||
|
||||
.toast-container
|
||||
position: fixed
|
||||
bottom: 1.5rem
|
||||
left: 50%
|
||||
transform: translateX(-50%)
|
||||
display: flex
|
||||
flex-direction: column-reverse
|
||||
gap: 0.5rem
|
||||
z-index: 200
|
||||
pointer-events: none
|
||||
width: min(24rem, calc(100% - 2rem))
|
||||
|
||||
.toast
|
||||
display: flex
|
||||
align-items: center
|
||||
gap: 0.625rem
|
||||
background-color: colors.$surface-raised
|
||||
border: 1px solid colors.$border-strong
|
||||
border-radius: 0.75rem
|
||||
padding: 0.625rem 0.875rem
|
||||
box-shadow: colors.$shadow-lg
|
||||
pointer-events: all
|
||||
animation: toast-in 0.18s ease
|
||||
|
||||
svg
|
||||
width: 1.0625rem
|
||||
height: 1.0625rem
|
||||
flex-shrink: 0
|
||||
color: colors.$primary
|
||||
|
||||
span
|
||||
flex: 1
|
||||
min-width: 0
|
||||
font-size: 0.875rem
|
||||
font-weight: 500
|
||||
|
||||
button
|
||||
display: flex
|
||||
background: none
|
||||
border: none
|
||||
padding: 0
|
||||
color: colors.$muted
|
||||
cursor: pointer
|
||||
|
||||
&:hover
|
||||
color: colors.$text
|
||||
|
||||
&[data-type="Error"] svg
|
||||
color: colors.$error
|
||||
|
||||
&[data-type="Success"] svg
|
||||
color: colors.$success
|
||||
|
||||
@keyframes toast-in
|
||||
from
|
||||
opacity: 0
|
||||
transform: translateY(0.5rem)
|
||||
@@ -0,0 +1,24 @@
|
||||
const API_BASE = "/@frislit/api/";
|
||||
|
||||
export const request = async (url, method, body, headers) => {
|
||||
url = url.startsWith("/") ? url.substring(1) : url;
|
||||
|
||||
const response = await fetch(`${API_BASE}${url}`, {
|
||||
method: method,
|
||||
headers: { ...headers, "Content-Type": "application/json" },
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
credentials: "same-origin",
|
||||
});
|
||||
|
||||
const rawData = await response.text();
|
||||
const data = rawData ? JSON.parse(rawData) : {};
|
||||
|
||||
if (!response.ok) throw Object.assign(new Error(data.message || data.error || `Request failed (${response.status})`), { code: response.status, ...data });
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getRequest = url => request(url, "GET");
|
||||
export const postRequest = (url, body) => request(url, "POST", body);
|
||||
export const putRequest = (url, body) => request(url, "PUT", body);
|
||||
export const deleteRequest = url => request(url, "DELETE");
|
||||
@@ -0,0 +1,34 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const AUTOFILL_ANIMATION = "field-autofill";
|
||||
|
||||
export const formValues = form => Object.fromEntries(new FormData(form).entries());
|
||||
|
||||
export const useAutofill = (formRef, apply) => {
|
||||
const latest = useRef(apply);
|
||||
useEffect(() => { latest.current = apply; });
|
||||
|
||||
useEffect(() => {
|
||||
const form = formRef.current;
|
||||
if (!form) return;
|
||||
|
||||
const sync = () => {
|
||||
const filled = {};
|
||||
for (const element of form.elements) if (element.name && element.value) filled[element.name] = element.value;
|
||||
if (Object.keys(filled).length) latest.current(filled);
|
||||
};
|
||||
|
||||
const onAnimation = event => {
|
||||
if (event.animationName === AUTOFILL_ANIMATION) sync();
|
||||
};
|
||||
|
||||
sync();
|
||||
const timer = setTimeout(sync, 250);
|
||||
form.addEventListener("animationstart", onAnimation, true);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
form.removeEventListener("animationstart", onAnimation, true);
|
||||
};
|
||||
}, [formRef]);
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
export const copyToClipboard = async text => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
const area = document.createElement("textarea");
|
||||
area.value = text;
|
||||
area.style.position = "fixed";
|
||||
area.style.opacity = "0";
|
||||
document.body.appendChild(area);
|
||||
area.select();
|
||||
const ok = document.execCommand("copy");
|
||||
document.body.removeChild(area);
|
||||
return ok;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
const names = new Intl.DisplayNames(["en"], { type: "region" });
|
||||
const flags = import.meta.glob("/node_modules/flag-icons/flags/4x3/*.svg", { eager: true, import: "default", query: "?url" });
|
||||
|
||||
export const countryName = code => {
|
||||
try {
|
||||
return names.of(code);
|
||||
} catch {
|
||||
return code;
|
||||
}
|
||||
};
|
||||
|
||||
export const countryCodes = Object.keys(flags)
|
||||
.map(path => path.slice(path.lastIndexOf("/") + 1, -4).toUpperCase())
|
||||
.filter(code => /^[A-Z]{2}$/.test(code) && countryName(code) !== code)
|
||||
.sort((a, b) => countryName(a).localeCompare(countryName(b)));
|
||||
@@ -0,0 +1,34 @@
|
||||
const toMillis = value => (typeof value === "string" ? Date.parse(value) : value);
|
||||
|
||||
export const formatRelative = timestamp => {
|
||||
const seconds = Math.round((Date.now() - toMillis(timestamp)) / 1000);
|
||||
if (!Number.isFinite(seconds)) return "unknown";
|
||||
if (seconds < 5) return "just now";
|
||||
if (seconds < 60) return `${seconds}s ago`;
|
||||
const minutes = Math.round(seconds / 60);
|
||||
if (minutes < 60) return `${minutes}m ago`;
|
||||
const hours = Math.round(minutes / 60);
|
||||
if (hours < 24) return `${hours}h ago`;
|
||||
return `${Math.round(hours / 24)}d ago`;
|
||||
};
|
||||
|
||||
export const formatCountdown = (until, now = Date.now()) => {
|
||||
const seconds = Math.max(0, Math.ceil((until - now) / 1000));
|
||||
if (seconds < 60) return `${seconds}s`;
|
||||
return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
||||
};
|
||||
|
||||
const UNITS = ["B", "kB", "MB", "GB", "TB"];
|
||||
|
||||
export const formatBytes = bytes => {
|
||||
let value = Number(bytes) || 0;
|
||||
let unit = 0;
|
||||
while (value >= 1000 && unit < UNITS.length - 1) {
|
||||
value /= 1000;
|
||||
unit += 1;
|
||||
}
|
||||
const rounded = unit === 0 ? Math.round(value) : value.toFixed(value < 10 ? 1 : 0);
|
||||
return `${rounded} ${UNITS[unit]}`;
|
||||
};
|
||||
|
||||
export const formatRate = bytesPerSecond => `${formatBytes(bytesPerSecond)}/s`;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Settings, Waypoints } from "lucide-react";
|
||||
|
||||
export const getNavigation = () => [
|
||||
{ title: "Tunnels", key: "tunnels", path: "/tunnels", icon: Waypoints },
|
||||
{ title: "Settings", key: "settings", path: "/settings", icon: Settings },
|
||||
];
|
||||
@@ -0,0 +1,77 @@
|
||||
const REPOSITORY = "https://git.fristy.net/fristy/frislit";
|
||||
|
||||
const PLATFORMS = { Windows: "windows", macOS: "macos", Linux: "linux" };
|
||||
|
||||
const appleSilicon = () => {
|
||||
try {
|
||||
const gl = document.createElement("canvas").getContext("webgl");
|
||||
const debug = gl?.getExtension("WEBGL_debug_renderer_info");
|
||||
const renderer = debug ? String(gl.getParameter(debug.UNMASKED_RENDERER_WEBGL)) : "";
|
||||
return /apple\s*m\d|apple gpu/i.test(renderer);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const fromUserAgent = () => {
|
||||
const agent = navigator.userAgent;
|
||||
const os = /Windows/i.test(agent) ? "windows"
|
||||
: /Mac OS X|Macintosh/i.test(agent) ? "macos"
|
||||
: /Linux|X11/i.test(agent) ? "linux" : null;
|
||||
|
||||
if (os === "macos") return { os, arch: appleSilicon() ? "arm64" : null };
|
||||
if (/arm64|aarch64/i.test(agent)) return { os, arch: "arm64" };
|
||||
if (/x86_64|x86-64|Win64|WOW64|x64/i.test(agent)) return { os, arch: "x64" };
|
||||
return { os, arch: null };
|
||||
};
|
||||
|
||||
export const detectPlatform = async () => {
|
||||
const hints = navigator.userAgentData;
|
||||
if (hints?.getHighEntropyValues) {
|
||||
try {
|
||||
const high = await hints.getHighEntropyValues(["architecture", "bitness", "platform"]);
|
||||
const os = PLATFORMS[high.platform] || null;
|
||||
const arch = high.architecture === "arm" && high.bitness === "64" ? "arm64"
|
||||
: high.architecture === "x86" && high.bitness === "64" ? "x64" : null;
|
||||
if (os) return { os, arch: arch || fromUserAgent().arch };
|
||||
} catch {
|
||||
return fromUserAgent();
|
||||
}
|
||||
}
|
||||
return fromUserAgent();
|
||||
};
|
||||
|
||||
export const installCommand = os => (os === "windows" ? "irm https://git.fristy.net/fristy/frislit/raw/branch/main/packaging/install/install.ps1 | iex" : "curl -fsSL https://git.fristy.net/fristy/frislit/raw/branch/main/packaging/install/install | sh");
|
||||
|
||||
export const releasesUrl = version => (version ? `${REPOSITORY}/releases/tag/v${version}` : `${REPOSITORY}/releases/latest`);
|
||||
|
||||
export const downloadsFor = ({ os, arch }, version) => {
|
||||
const all = releasesUrl(version);
|
||||
if (!os) return { version, all, files: [] };
|
||||
|
||||
const base = version ? `${REPOSITORY}/releases/download/v${version}` : `${REPOSITORY}/releases/latest/download`;
|
||||
const file = (name, label) => ({ url: `${base}/${name}`, label });
|
||||
|
||||
if (os === "windows") {
|
||||
const suffix = arch === "arm64" ? "arm64" : "x64";
|
||||
return { version, all, files: [
|
||||
file(`frislit-${suffix}.msi`, "Windows installer"),
|
||||
file(`frislit-windows-${suffix}.exe`, "Plain frislit.exe"),
|
||||
] };
|
||||
}
|
||||
|
||||
if (os === "macos") {
|
||||
const silicon = file("frislit-macos-arm64", "macOS, Apple Silicon");
|
||||
const intel = file("frislit-macos-x64", "macOS, Intel");
|
||||
return { version, all, files: arch === "x64" ? [intel, silicon] : [silicon, intel] };
|
||||
}
|
||||
|
||||
const onArm = arch === "arm64";
|
||||
const plain = onArm ? "frislit-linux-arm64" : "frislit-linux-x64";
|
||||
return { version, all, files: [
|
||||
file(`frislit-cli-${onArm ? "arm64" : "amd64"}.deb`, "Debian, Ubuntu"),
|
||||
file(`frislit-cli-${onArm ? "aarch64" : "x86_64"}.rpm`, "Fedora, RHEL"),
|
||||
file(plain, "Plain binary"),
|
||||
file(`${plain}-static`, "Static binary, any distro"),
|
||||
] };
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
const STORAGE_KEY = "frislit-tunnel";
|
||||
const SW_PATH = "/@frislit/sw.js";
|
||||
|
||||
export const readTab = () => {
|
||||
try {
|
||||
return sessionStorage.getItem(STORAGE_KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const rememberTab = tunnel => {
|
||||
try {
|
||||
sessionStorage.setItem(STORAGE_KEY, tunnel);
|
||||
} catch { /* private mode: the worker binding below still carries this tab */ }
|
||||
};
|
||||
|
||||
export const bindTab = tunnel => new Promise((resolve, reject) => {
|
||||
if (!navigator.serviceWorker || !window.isSecureContext) return reject(new Error("service workers unavailable"));
|
||||
|
||||
const onMessage = event => {
|
||||
if (event.data?.type !== "frislit-bound") return;
|
||||
navigator.serviceWorker.removeEventListener("message", onMessage);
|
||||
resolve();
|
||||
};
|
||||
navigator.serviceWorker.addEventListener("message", onMessage);
|
||||
|
||||
navigator.serviceWorker.register(SW_PATH, { scope: "/" })
|
||||
.then(() => navigator.serviceWorker.ready)
|
||||
.then(registration => {
|
||||
const worker = navigator.serviceWorker.controller || registration.active;
|
||||
if (!worker) return resolve();
|
||||
worker.postMessage({ type: "frislit-bind", tunnel });
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
|
||||
export const resetWorkers = async () => {
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker?.getRegistrations() || [];
|
||||
await Promise.all(registrations.map(registration => registration.unregister()));
|
||||
} catch { /* nothing registered, or the API is unavailable */ }
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
||||
import { deleteRequest, getRequest, postRequest } from "@/common/utils/RequestUtil.js";
|
||||
|
||||
export const passkeysSupported = () => typeof window !== "undefined" && !!window.PublicKeyCredential;
|
||||
|
||||
export const listPasskeys = async () => (await getRequest("auth/passkeys")).passkeys;
|
||||
|
||||
export const addPasskey = async name => {
|
||||
const options = await postRequest("auth/passkeys/options");
|
||||
const response = await startRegistration({ optionsJSON: options });
|
||||
return postRequest("auth/passkeys", { response, name });
|
||||
};
|
||||
|
||||
export const removePasskey = id => deleteRequest(`auth/passkeys/${id}`);
|
||||
|
||||
export const signInWithPasskey = async username => {
|
||||
const options = await postRequest("auth/passkey/options", { username });
|
||||
const response = await startAuthentication({ optionsJSON: options });
|
||||
return postRequest("auth/passkey/verify", { response });
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import App from "@/App.jsx";
|
||||
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,30 @@
|
||||
import "./styles.sass";
|
||||
import { useParams } from "react-router-dom";
|
||||
import CopyField from "@/common/components/CopyField";
|
||||
import OpenInFrislit from "@/common/components/OpenInFrislit";
|
||||
|
||||
export const Connect = () => {
|
||||
const { code } = useParams();
|
||||
const command = `frislit connect ${window.location.origin}/@frislit/connect/${code}`;
|
||||
|
||||
return (
|
||||
<div className="connect-page">
|
||||
<div className="form-head">
|
||||
<h1>Connect to this port.</h1>
|
||||
<p>The port appears on your own machine, as if it were running there.</p>
|
||||
</div>
|
||||
|
||||
<OpenInFrislit href={`frislit://connect/${encodeURIComponent(code)}?server=${encodeURIComponent(window.location.origin)}`} />
|
||||
|
||||
<div className="connect-command">
|
||||
<span>or run</span>
|
||||
<CopyField value={command} />
|
||||
</div>
|
||||
|
||||
<p className="connect-hint">
|
||||
No frislit yet? <a href="https://git.fristy.net/fristy/frislit/blob/main/docs/installation.md" target="_blank" rel="noreferrer noopener">Install it</a> in one line.
|
||||
You do not need an account to connect.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { Connect as default } from "./Connect.jsx";
|
||||
@@ -0,0 +1,37 @@
|
||||
@use "@/common/styles/colors"
|
||||
|
||||
.connect-page
|
||||
width: 100%
|
||||
|
||||
.copy-field
|
||||
align-items: flex-start
|
||||
|
||||
code
|
||||
overflow: visible
|
||||
text-overflow: clip
|
||||
white-space: pre-wrap
|
||||
word-break: break-all
|
||||
line-height: 1.5
|
||||
|
||||
.connect-hint
|
||||
margin-top: 1rem
|
||||
color: colors.$muted
|
||||
font-size: 0.8125rem
|
||||
line-height: 1.55
|
||||
|
||||
a
|
||||
color: colors.$primary-bright
|
||||
text-decoration: none
|
||||
|
||||
&:hover
|
||||
text-decoration: underline
|
||||
|
||||
.connect-command
|
||||
display: flex
|
||||
flex-direction: column
|
||||
gap: 0.375rem
|
||||
margin-top: 1.25rem
|
||||
|
||||
> span
|
||||
color: colors.$muted
|
||||
font-size: 0.75rem
|
||||
Loaded 100 of 438 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user