ludicord 2.2.0 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/ludicord.js +0 -0
- package/dist/api/runtime.d.ts +4 -0
- package/dist/api/runtime.js +61 -10
- package/dist/auth/client.d.ts +10 -0
- package/dist/auth/client.js +81 -8
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/server.js +175 -32
- package/dist/auth/types.d.ts +5 -0
- package/dist/cli/index.js +14 -13
- package/dist/cli/project-commands.js +49 -34
- package/dist/compiler/build.js +37 -127
- package/dist/compiler/client-entry.d.ts +4 -0
- package/dist/compiler/client-entry.js +35 -0
- package/dist/compiler/client-tooling.d.ts +5 -0
- package/dist/compiler/client-tooling.js +97 -0
- package/dist/compiler/scanner.js +8 -0
- package/dist/compiler/server-bundle.d.ts +11 -0
- package/dist/compiler/server-bundle.js +31 -0
- package/dist/compiler/type-generation.js +11 -2
- package/dist/config/defaults.js +28 -2
- package/dist/config/environment.d.ts +2 -0
- package/dist/config/environment.js +18 -0
- package/dist/discord/data.d.ts +21 -0
- package/dist/discord/data.js +91 -0
- package/dist/discord/events.d.ts +42 -4
- package/dist/discord/events.js +120 -41
- package/dist/discord/index.d.ts +4 -2
- package/dist/discord/index.js +2 -1
- package/dist/discord/runtime.d.ts +2 -2
- package/dist/discord/runtime.js +9 -13
- package/dist/discord/testing.d.ts +1 -0
- package/dist/discord/testing.js +10 -0
- package/dist/manifests/types.d.ts +4 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/runtime/client/dev-panel.d.ts +2 -0
- package/dist/runtime/client/dev-panel.js +63 -0
- package/dist/runtime/client/embed-router.d.ts +4 -1
- package/dist/runtime/client/embed-router.js +69 -17
- package/dist/runtime/client/files.d.ts +23 -0
- package/dist/runtime/client/files.js +12 -0
- package/dist/runtime/client/minimize-card.js +4 -4
- package/dist/runtime/client/minimize.d.ts +1 -0
- package/dist/runtime/client/minimize.js +1 -0
- package/dist/runtime/client/root.d.ts +7 -0
- package/dist/runtime/client/root.js +19 -0
- package/dist/runtime/index.d.ts +8 -4
- package/dist/runtime/index.js +14 -2
- package/dist/runtime/server/dev-server.d.ts +1 -0
- package/dist/runtime/server/dev-server.js +294 -282
- package/dist/runtime/server/diagnostics.d.ts +17 -0
- package/dist/runtime/server/diagnostics.js +87 -0
- package/dist/runtime/server/index.d.ts +5 -0
- package/dist/runtime/server/index.js +3 -0
- package/dist/runtime/server/production-server.js +14 -1
- package/dist/security/discord.d.ts +9 -0
- package/dist/security/discord.js +37 -7
- package/dist/security/secret-scan.d.ts +3 -0
- package/dist/security/secret-scan.js +40 -0
- package/dist/server/discord-rest.d.ts +45 -0
- package/dist/server/discord-rest.js +46 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/sessions/cookies.d.ts +4 -1
- package/dist/sessions/cookies.js +17 -4
- package/dist/sessions/crypto.js +6 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +24 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/ws/client.d.ts +6 -0
- package/dist/ws/client.js +46 -10
- package/dist/ws/server.d.ts +4 -0
- package/dist/ws/server.js +36 -15
- package/package.json +31 -4
- package/dist/api/runtime.d.ts.map +0 -1
- package/dist/api/runtime.js.map +0 -1
- package/dist/auth/client.d.ts.map +0 -1
- package/dist/auth/client.js.map +0 -1
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/server.d.ts.map +0 -1
- package/dist/auth/server.js.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/project-commands.d.ts.map +0 -1
- package/dist/cli/project-commands.js.map +0 -1
- package/dist/compiler/build.d.ts.map +0 -1
- package/dist/compiler/build.js.map +0 -1
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/index.js.map +0 -1
- package/dist/compiler/scanner.d.ts.map +0 -1
- package/dist/compiler/scanner.js.map +0 -1
- package/dist/compiler/type-generation.d.ts.map +0 -1
- package/dist/compiler/type-generation.js.map +0 -1
- package/dist/compiler/write-manifests.d.ts.map +0 -1
- package/dist/compiler/write-manifests.js.map +0 -1
- package/dist/config/defaults.d.ts.map +0 -1
- package/dist/config/defaults.js.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/config/loader.js.map +0 -1
- package/dist/config/project-root.d.ts.map +0 -1
- package/dist/config/project-root.js.map +0 -1
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js.map +0 -1
- package/dist/discord/events.d.ts.map +0 -1
- package/dist/discord/events.js.map +0 -1
- package/dist/discord/index.d.ts.map +0 -1
- package/dist/discord/index.js.map +0 -1
- package/dist/discord/runtime.d.ts.map +0 -1
- package/dist/discord/runtime.js.map +0 -1
- package/dist/discord/safe-area.d.ts.map +0 -1
- package/dist/discord/safe-area.js.map +0 -1
- package/dist/discord/testing.d.ts.map +0 -1
- package/dist/discord/testing.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/manifests/types.d.ts.map +0 -1
- package/dist/manifests/types.js.map +0 -1
- package/dist/navigation/index.d.ts.map +0 -1
- package/dist/navigation/index.js.map +0 -1
- package/dist/router/match.d.ts.map +0 -1
- package/dist/router/match.js.map +0 -1
- package/dist/runtime/client/embed-router.d.ts.map +0 -1
- package/dist/runtime/client/embed-router.js.map +0 -1
- package/dist/runtime/client/minimize-card.d.ts.map +0 -1
- package/dist/runtime/client/minimize-card.js.map +0 -1
- package/dist/runtime/client/minimize.d.ts.map +0 -1
- package/dist/runtime/client/minimize.js.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/server/dev-server.d.ts.map +0 -1
- package/dist/runtime/server/dev-server.js.map +0 -1
- package/dist/runtime/server/production-server.d.ts.map +0 -1
- package/dist/runtime/server/production-server.js.map +0 -1
- package/dist/security/discord.d.ts.map +0 -1
- package/dist/security/discord.js.map +0 -1
- package/dist/security/index.d.ts.map +0 -1
- package/dist/security/index.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/session.d.ts.map +0 -1
- package/dist/server/session.js.map +0 -1
- package/dist/server/types.d.ts.map +0 -1
- package/dist/server/types.js.map +0 -1
- package/dist/sessions/cookies.d.ts.map +0 -1
- package/dist/sessions/cookies.js.map +0 -1
- package/dist/sessions/crypto.d.ts.map +0 -1
- package/dist/sessions/crypto.js.map +0 -1
- package/dist/shared/errors.d.ts.map +0 -1
- package/dist/shared/errors.js.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/ws/client.d.ts.map +0 -1
- package/dist/ws/client.js.map +0 -1
- package/dist/ws/index.d.ts.map +0 -1
- package/dist/ws/index.js.map +0 -1
- package/dist/ws/server.d.ts.map +0 -1
- package/dist/ws/server.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const hot = import.meta.hot;
|
|
2
|
+
const host = document.createElement("ludicord-devtools");
|
|
3
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
4
|
+
shadow.innerHTML = `<style>
|
|
5
|
+
:host{all:initial;font-family:Inter,ui-sans-serif,system-ui,sans-serif;color:#f4f0ff}*{box-sizing:border-box}button{font:inherit;cursor:pointer}
|
|
6
|
+
.backdrop{position:fixed;inset:0;z-index:2147483646;background:#080712c9;display:grid;place-items:center;padding:24px;backdrop-filter:blur(8px)}
|
|
7
|
+
.panel{width:min(960px,100%);max-height:90vh;overflow:auto;background:#14121f;border:1px solid #4c355c;border-radius:18px;box-shadow:0 30px 100px #0009}
|
|
8
|
+
header{display:flex;align-items:center;gap:12px;padding:20px 24px;border-bottom:1px solid #30283f}.brand{color:#e9c9ff;font-weight:800;letter-spacing:-.4px}.pill{color:#b3a4c9;background:#272033;padding:4px 8px;border-radius:6px;font-size:10px;letter-spacing:1.5px}
|
|
9
|
+
.close{margin-left:auto;border:0;background:transparent;color:#b7aec8;font-size:23px}article{padding:26px}h1{font-size:22px;line-height:1.4;margin:12px 0 20px;white-space:pre-wrap;overflow-wrap:anywhere}.kind{font-size:11px;letter-spacing:1.5px;color:#ffaba8;text-transform:uppercase}
|
|
10
|
+
.file{font:13px ui-monospace,monospace;color:#d8b8fa;overflow-wrap:anywhere}pre{font:13px/1.75 ui-monospace,SFMono-Regular,monospace;overflow:auto;max-height:45vh;background:#0d0c14;padding:20px;border:1px solid #30283f;border-radius:10px;tab-size:2;color:#ded7eb}details{margin-top:20px;color:#a79bbd}summary{cursor:pointer;font-size:13px}
|
|
11
|
+
footer{padding:16px 24px;border-top:1px solid #30283f;display:flex;align-items:center;gap:10px;font-size:12px;color:#9a8fab}footer button{border:1px solid #514160;background:#251d33;color:#eadcf8;padding:8px 12px;border-radius:7px}.count{margin-right:auto}.badge{position:fixed;bottom:18px;left:18px;z-index:2147483647;background:#20172c;border:1px solid #b778e3;border-radius:100px;color:#f4eaff;padding:10px 15px;box-shadow:0 8px 30px #0006;font-size:12px}.hidden{display:none!important}
|
|
12
|
+
@media(max-width:600px){.backdrop{padding:10px}header,article,footer{padding:16px}h1{font-size:18px}pre{font-size:11px}}
|
|
13
|
+
</style><div class="backdrop hidden"><section class="panel" role="dialog" aria-modal="true" aria-label="Ludicord development error"><header><span class="brand">◈ ludicord</span><span class="pill">DEVELOPMENT</span><button class="close" aria-label="Dismiss error">×</button></header><article><span class="kind"></span><h1></h1><div class="file"></div><pre class="frame"></pre><details><summary>Call stack</summary><pre class="stack"></pre></details></article><footer><span class="count"></span><button class="previous" aria-label="Previous error">←</button><button class="next" aria-label="Next error">→</button><button class="copy">Copy location</button><button class="retry">Retry</button></footer></section></div><button class="badge hidden"></button>`;
|
|
14
|
+
document.documentElement.append(host);
|
|
15
|
+
const element = (selector) => shadow.querySelector(selector);
|
|
16
|
+
let issues = [];
|
|
17
|
+
let index = 0;
|
|
18
|
+
let dismissed = false;
|
|
19
|
+
function render() {
|
|
20
|
+
const issue = issues[index];
|
|
21
|
+
element(".backdrop").classList.toggle("hidden", issue === undefined || dismissed);
|
|
22
|
+
element(".badge").classList.toggle("hidden", issue === undefined || !dismissed);
|
|
23
|
+
if (issue === undefined)
|
|
24
|
+
return;
|
|
25
|
+
element(".kind").textContent = `${issue.kind ?? "runtime"} error`;
|
|
26
|
+
element("h1").textContent = issue.message;
|
|
27
|
+
element(".file").textContent = issue.file ? `${issue.file}:${issue.line ?? 1}:${issue.column ?? 1}` : "Activity runtime";
|
|
28
|
+
element(".frame").textContent = issue.frame ?? "Fix the error in your source. Ludicord will update automatically.";
|
|
29
|
+
element(".stack").textContent = issue.stack ?? "No additional stack available.";
|
|
30
|
+
element(".count").textContent = `${index + 1} of ${issues.length} · Ludicord dev`;
|
|
31
|
+
element(".badge").textContent = `◈ ${issues.length} ${issues.length === 1 ? "issue" : "issues"}`;
|
|
32
|
+
}
|
|
33
|
+
function show(next) { issues = next; index = Math.min(index, Math.max(0, next.length - 1)); dismissed = false; render(); }
|
|
34
|
+
function recover() { window.dispatchEvent(new Event("ludicord:recover")); }
|
|
35
|
+
element(".close").onclick = () => { dismissed = true; render(); };
|
|
36
|
+
element(".badge").onclick = () => { dismissed = false; render(); };
|
|
37
|
+
element(".next").onclick = () => { index = (index + 1) % issues.length; render(); };
|
|
38
|
+
element(".previous").onclick = () => { index = (index + issues.length - 1) % issues.length; render(); };
|
|
39
|
+
element(".copy").onclick = () => { void navigator.clipboard?.writeText(element(".file").textContent ?? ""); };
|
|
40
|
+
element(".retry").onclick = () => { recover(); show([]); };
|
|
41
|
+
async function report(issue) {
|
|
42
|
+
show([issue]);
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch("/_ludicord/dev/error", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(issue) });
|
|
45
|
+
if (response.ok)
|
|
46
|
+
show([await response.json()]);
|
|
47
|
+
}
|
|
48
|
+
catch { /* Keep the original error while disconnected. */ }
|
|
49
|
+
}
|
|
50
|
+
const runtime = (event) => { void report(event.detail); };
|
|
51
|
+
const rejection = (event) => { void report({ message: event.reason?.message ?? String(event.reason), stack: event.reason?.stack }); };
|
|
52
|
+
const error = (event) => { if (event.message)
|
|
53
|
+
void report({ message: event.message, stack: event.error?.stack, file: event.filename, line: event.lineno, column: event.colno }); };
|
|
54
|
+
window.addEventListener("ludicord:runtime-error", runtime);
|
|
55
|
+
window.addEventListener("unhandledrejection", rejection);
|
|
56
|
+
window.addEventListener("error", error);
|
|
57
|
+
hot?.on("ludicord:diagnostics", (data) => show(data.issues));
|
|
58
|
+
hot?.on("vite:error", (data) => show([data.err]));
|
|
59
|
+
hot?.on("vite:afterUpdate", () => { recover(); void fetch("/_ludicord/dev/diagnostics").then(r => r.json()).then(data => show(data.issues)).catch(() => { }); });
|
|
60
|
+
void fetch("/_ludicord/dev/diagnostics").then(r => r.json()).then(data => show(data.issues)).catch(() => { });
|
|
61
|
+
hot?.dispose(() => { host.remove(); window.removeEventListener("ludicord:runtime-error", runtime); window.removeEventListener("unhandledrejection", rejection); window.removeEventListener("error", error); });
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=dev-panel.js.map
|
|
@@ -34,8 +34,11 @@ interface LudicordErrorBoundaryState {
|
|
|
34
34
|
}
|
|
35
35
|
export declare class LudicordErrorBoundary extends Component<LudicordErrorBoundaryProps, LudicordErrorBoundaryState> {
|
|
36
36
|
state: LudicordErrorBoundaryState;
|
|
37
|
+
private readonly recover;
|
|
38
|
+
componentDidMount(): void;
|
|
39
|
+
componentWillUnmount(): void;
|
|
37
40
|
static getDerivedStateFromError(error: Error): LudicordErrorBoundaryState;
|
|
38
|
-
componentDidCatch(
|
|
41
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
39
42
|
componentDidUpdate(previous: LudicordErrorBoundaryProps): void;
|
|
40
43
|
render(): ReactNode;
|
|
41
44
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Component, Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
3
3
|
import { initializeDiscordFromEnvironment } from "../../discord/runtime.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { initializeLudicordAuthFromEnvironment, useLudicordAuth } from "../../auth/client.js";
|
|
5
|
+
import { useDiscord } from "../../discord/runtime.js";
|
|
6
|
+
import { useActivityLayoutMode } from "../../discord/events.js";
|
|
7
|
+
import { useOptionalLudicordMinimize } from "./minimize.js";
|
|
8
|
+
import { useLudicordFiles, isDevelopmentRuntime, reportClientError } from "./files.js";
|
|
6
9
|
import { installLudicordSafeAreaVariables } from "../../discord/safe-area.js";
|
|
7
10
|
const EmbedContext = createContext(null);
|
|
8
11
|
const lazyComponentCache = new WeakMap();
|
|
@@ -120,25 +123,46 @@ export function LudicordActivity({ defaultEmbed, children, embeds, loading = nul
|
|
|
120
123
|
installLudicordSafeAreaVariables();
|
|
121
124
|
void initializeDiscordFromEnvironment()
|
|
122
125
|
.then(async (discord) => {
|
|
123
|
-
await initializeDiscordEventsFromEnvironment(discord);
|
|
124
126
|
return initializeLudicordAuthFromEnvironment(discord);
|
|
125
127
|
})
|
|
126
128
|
.catch(() => {
|
|
127
129
|
// Public hooks surface initialization errors to the Activity UI.
|
|
128
130
|
});
|
|
129
131
|
}, []);
|
|
132
|
+
const files = useLudicordFiles();
|
|
133
|
+
const Loading = files.loading;
|
|
134
|
+
const ErrorFile = files.error;
|
|
135
|
+
const Minimized = files.minimize;
|
|
136
|
+
const minimize = useOptionalLudicordMinimize();
|
|
137
|
+
const layoutMode = useActivityLayoutMode();
|
|
138
|
+
const minimized = Minimized !== undefined && (minimize?.minimized === true || layoutMode === 1 || layoutMode === 2 || layoutMode === "pip" || layoutMode === "grid");
|
|
130
139
|
const definitions = useMemo(() => [...(embeds ?? globalDefinitions())], [embeds]);
|
|
131
140
|
const initialPath = normalizeEmbedPath(defaultEmbed);
|
|
132
141
|
const [state, setState] = useState(() => {
|
|
133
|
-
|
|
142
|
+
let path = initialPath;
|
|
143
|
+
try {
|
|
144
|
+
path = findMatch(definitions, hashEmbedPath(initialPath)).path;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
if (typeof window !== "undefined")
|
|
148
|
+
window.history.replaceState(null, "", embedHash(initialPath, initialPath));
|
|
149
|
+
}
|
|
134
150
|
return { entries: [path], index: 0 };
|
|
135
151
|
});
|
|
136
152
|
useEffect(() => {
|
|
137
|
-
const path = hashEmbedPath(initialPath);
|
|
138
153
|
if (window.location.hash === "")
|
|
139
154
|
window.history.replaceState(null, "", "#/");
|
|
140
155
|
const onHashChange = () => {
|
|
141
156
|
const nextPath = hashEmbedPath(initialPath);
|
|
157
|
+
try {
|
|
158
|
+
findMatch(definitions, nextPath);
|
|
159
|
+
}
|
|
160
|
+
catch (cause) {
|
|
161
|
+
reportClientError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
162
|
+
window.history.replaceState(null, "", embedHash(initialPath, initialPath));
|
|
163
|
+
setState({ entries: [initialPath], index: 0 });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
142
166
|
setState((current) => {
|
|
143
167
|
const currentPath = current.entries[current.index];
|
|
144
168
|
return currentPath === nextPath
|
|
@@ -151,14 +175,14 @@ export function LudicordActivity({ defaultEmbed, children, embeds, loading = nul
|
|
|
151
175
|
};
|
|
152
176
|
window.addEventListener("hashchange", onHashChange);
|
|
153
177
|
return () => window.removeEventListener("hashchange", onHashChange);
|
|
154
|
-
}, [initialPath]);
|
|
178
|
+
}, [initialPath, definitions]);
|
|
155
179
|
const currentPath = state.entries[state.index] ?? initialPath;
|
|
156
180
|
const match = useMemo(() => findMatch(definitions, currentPath), [currentPath, definitions]);
|
|
157
181
|
const push = useCallback((path) => {
|
|
158
182
|
const normalized = normalizeEmbedPath(path);
|
|
159
183
|
findMatch(definitions, normalized);
|
|
160
184
|
if (typeof window !== "undefined")
|
|
161
|
-
window.
|
|
185
|
+
window.history.replaceState(null, "", embedHash(normalized, initialPath));
|
|
162
186
|
setState((current) => ({
|
|
163
187
|
entries: [...current.entries.slice(0, current.index + 1), normalized],
|
|
164
188
|
index: current.index + 1,
|
|
@@ -168,7 +192,7 @@ export function LudicordActivity({ defaultEmbed, children, embeds, loading = nul
|
|
|
168
192
|
const normalized = normalizeEmbedPath(path);
|
|
169
193
|
findMatch(definitions, normalized);
|
|
170
194
|
if (typeof window !== "undefined")
|
|
171
|
-
window.
|
|
195
|
+
window.history.replaceState(null, "", embedHash(normalized, initialPath));
|
|
172
196
|
setState((current) => ({
|
|
173
197
|
entries: current.entries.map((entry, index) => index === current.index ? normalized : entry),
|
|
174
198
|
index: current.index,
|
|
@@ -194,10 +218,33 @@ export function LudicordActivity({ defaultEmbed, children, embeds, loading = nul
|
|
|
194
218
|
const value = useMemo(() => ({
|
|
195
219
|
router,
|
|
196
220
|
match,
|
|
197
|
-
loading,
|
|
198
|
-
...(errorFallback === undefined ? {} : { errorFallback }),
|
|
199
|
-
}), [errorFallback, loading, match, router]);
|
|
200
|
-
return _jsx(EmbedContext.Provider, { value: value, children: children });
|
|
221
|
+
loading: loading ?? (Loading === undefined ? null : _jsx(Loading, {})),
|
|
222
|
+
...(errorFallback !== undefined ? { errorFallback } : ErrorFile === undefined ? {} : { errorFallback: (error) => _jsx(ErrorFile, { error: error, reset: () => window.dispatchEvent(new Event("ludicord:recover")) }) }),
|
|
223
|
+
}), [errorFallback, loading, match, router, Loading, ErrorFile]);
|
|
224
|
+
return _jsx(EmbedContext.Provider, { value: value, children: _jsxs(ActivityAuthGate, { children: [_jsx("div", { hidden: minimized, style: { display: minimized ? "none" : "contents" }, children: children }), minimized && Minimized !== undefined ? _jsx(Minimized, {}) : null] }) });
|
|
225
|
+
}
|
|
226
|
+
function ActivityAuthGate({ children }) {
|
|
227
|
+
const files = useLudicordFiles();
|
|
228
|
+
const auth = useLudicordAuth();
|
|
229
|
+
const discord = useDiscord();
|
|
230
|
+
const config = globalThis.__LUDICORD_PUBLIC_CONFIG__;
|
|
231
|
+
// Standalone runtime/tests without generated config retain their explicit UI ownership.
|
|
232
|
+
if (config?.authRequired !== true || auth.status === "authenticated" ||
|
|
233
|
+
(discord.status === "outside-discord" && config.environment === "development" && config.outsideDiscord === "allow"))
|
|
234
|
+
return children;
|
|
235
|
+
const retry = () => { void initializeDiscordFromEnvironment().then((snapshot) => initializeLudicordAuthFromEnvironment(snapshot)).catch(() => undefined); };
|
|
236
|
+
if (auth.status === "denied" && files.authDenied !== undefined) {
|
|
237
|
+
const Denied = files.authDenied;
|
|
238
|
+
return _jsx(Denied, {});
|
|
239
|
+
}
|
|
240
|
+
const error = auth.error ?? discord.error;
|
|
241
|
+
if (error !== null || discord.status === "outside-discord") {
|
|
242
|
+
const ErrorFile = files.authError;
|
|
243
|
+
const safeError = isDevelopmentRuntime() ? error ?? new Error("Open this Activity inside Discord.") : new Error("Discord sign-in is required. Please reopen the Activity or retry.");
|
|
244
|
+
return ErrorFile === undefined ? _jsxs("main", { role: "alert", style: { padding: 24, fontFamily: "system-ui" }, children: [_jsx("h1", { children: "Discord sign-in required" }), _jsx("p", { children: safeError.message }), _jsx("button", { onClick: retry, children: "Try again" })] }) : _jsx(ErrorFile, { error: safeError, reset: retry });
|
|
245
|
+
}
|
|
246
|
+
const Loading = files.authLoading ?? files.loading;
|
|
247
|
+
return Loading === undefined ? _jsx("main", { role: "status", style: { padding: 24, fontFamily: "system-ui" }, children: "Connecting to Discord\u2026" }) : _jsx(Loading, {});
|
|
201
248
|
}
|
|
202
249
|
export function EmbedOutlet() {
|
|
203
250
|
const { match, loading, errorFallback } = useEmbedContext();
|
|
@@ -215,11 +262,16 @@ export function useEmbedParams() {
|
|
|
215
262
|
}
|
|
216
263
|
export class LudicordErrorBoundary extends Component {
|
|
217
264
|
state = { error: null };
|
|
265
|
+
recover = () => this.setState({ error: null });
|
|
266
|
+
componentDidMount() { if (typeof window !== "undefined")
|
|
267
|
+
window.addEventListener("ludicord:recover", this.recover); }
|
|
268
|
+
componentWillUnmount() { if (typeof window !== "undefined")
|
|
269
|
+
window.removeEventListener("ludicord:recover", this.recover); }
|
|
218
270
|
static getDerivedStateFromError(error) {
|
|
219
271
|
return { error };
|
|
220
272
|
}
|
|
221
|
-
componentDidCatch(
|
|
222
|
-
|
|
273
|
+
componentDidCatch(error, info) {
|
|
274
|
+
reportClientError(error, info.componentStack);
|
|
223
275
|
}
|
|
224
276
|
componentDidUpdate(previous) {
|
|
225
277
|
if (this.state.error !== null &&
|
|
@@ -232,9 +284,9 @@ export class LudicordErrorBoundary extends Component {
|
|
|
232
284
|
if (error === null)
|
|
233
285
|
return this.props.children;
|
|
234
286
|
if (typeof this.props.fallback === "function") {
|
|
235
|
-
return this.props.fallback(error);
|
|
287
|
+
return this.props.fallback(isDevelopmentRuntime() ? error : new Error("The Activity encountered an error. Please try again."));
|
|
236
288
|
}
|
|
237
|
-
return (this.props.fallback ?? (_jsx("div", { role: "alert", "data-ludicord-error": "", children: error.message })));
|
|
289
|
+
return (this.props.fallback ?? (_jsx("div", { role: "alert", "data-ludicord-error": "", children: isDevelopmentRuntime() ? error.message : "The Activity encountered an error. Please try again." })));
|
|
238
290
|
}
|
|
239
291
|
}
|
|
240
292
|
export function LudicordLoadingBoundary({ children, fallback = null, }) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
export interface LudicordFileComponents {
|
|
3
|
+
readonly layout?: ComponentType<{
|
|
4
|
+
readonly children: ReactNode;
|
|
5
|
+
}>;
|
|
6
|
+
readonly loading?: ComponentType;
|
|
7
|
+
readonly error?: ComponentType<{
|
|
8
|
+
readonly error: Error;
|
|
9
|
+
readonly reset: () => void;
|
|
10
|
+
}>;
|
|
11
|
+
readonly minimize?: ComponentType;
|
|
12
|
+
readonly authLoading?: ComponentType;
|
|
13
|
+
readonly authError?: ComponentType<{
|
|
14
|
+
readonly error: Error;
|
|
15
|
+
readonly reset: () => void;
|
|
16
|
+
}>;
|
|
17
|
+
readonly authDenied?: ComponentType;
|
|
18
|
+
}
|
|
19
|
+
export declare const LudicordFilesContext: import("react").Context<LudicordFileComponents>;
|
|
20
|
+
export declare function useLudicordFiles(): LudicordFileComponents;
|
|
21
|
+
export declare function isDevelopmentRuntime(): boolean;
|
|
22
|
+
export declare function reportClientError(error: Error, componentStack?: string | null): void;
|
|
23
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
export const LudicordFilesContext = createContext({});
|
|
3
|
+
export function useLudicordFiles() { return useContext(LudicordFilesContext); }
|
|
4
|
+
export function isDevelopmentRuntime() {
|
|
5
|
+
return globalThis.__LUDICORD_PUBLIC_CONFIG__?.environment === "development";
|
|
6
|
+
}
|
|
7
|
+
export function reportClientError(error, componentStack) {
|
|
8
|
+
if (!isDevelopmentRuntime() || typeof window === "undefined")
|
|
9
|
+
return;
|
|
10
|
+
window.dispatchEvent(new CustomEvent("ludicord:runtime-error", { detail: { message: error.message, stack: error.stack, componentStack } }));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -11,9 +11,9 @@ export function Minimize({ heading = "Message preview", message = "Welcome to th
|
|
|
11
11
|
const channelName = customChannelName ?? (guest ? "browser" : (channel?.name ?? "this channel"));
|
|
12
12
|
const avatar = customAvatar === undefined ? user?.avatar : customAvatar;
|
|
13
13
|
const content = children ?? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "message-card-heading", children: [_jsx("span", { children: heading }), _jsxs("span", { className: "message-channel", children: ["# ", channelName] })] }), _jsxs("div", { className: "message-card-body", children: [avatar ? (_jsx("img", { className: "avatar", src: avatar, alt: "" })) : (_jsx("span", { className: "avatar avatar-fallback", children: author.slice(0, 1).toUpperCase() })), _jsxs("div", { className: "message-copy", children: [_jsxs("div", { className: "message-author", children: [_jsx("strong", { children: author }), _jsx("span", { children: timestamp })] }), _jsx("p", { children: message })] })] })] }));
|
|
14
|
-
return (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
return (_jsxs("div", { className: "ludicord-minimize-viewport", children: [_jsx("style", { children: `.ludicord-minimize-viewport{min-height:100dvh;display:grid;place-items:center;padding:12px;background:#15131e;color:#eee6fc;font-family:system-ui}.ludicord-minimize-viewport .message-card{width:min(460px,100%);border:1px solid #463554;border-radius:14px;padding:18px;background:#201a2b}.ludicord-minimize-viewport .message-card-heading{display:flex;justify-content:space-between;gap:12px;font-weight:700;font-size:13px}.ludicord-minimize-viewport .message-channel,.ludicord-minimize-viewport .message-author span{color:#aaa0b8;font-size:11px}.ludicord-minimize-viewport .message-card-body{display:flex;gap:12px;margin-top:16px}.ludicord-minimize-viewport .avatar{width:36px;height:36px;border-radius:50%;object-fit:cover}.ludicord-minimize-viewport .avatar-fallback{display:grid;place-items:center;background:#654285;flex-shrink:0}.ludicord-minimize-viewport .message-author{display:flex;gap:8px;align-items:center;font-size:13px}.ludicord-minimize-viewport p{font-size:13px;line-height:1.5;margin:6px 0 0}.ludicord-minimize-viewport [role=button]:focus-visible{outline:2px solid #b69ce3;outline-offset:3px}` }), _jsx("div", { className: card ? "message-card minimize-card" : "minimize-content", "aria-label": "Minimized Activity. Double-click to open the full Activity.", onDoubleClick: toggle, onKeyDown: (event) => {
|
|
15
|
+
if (event.key === "Enter" || event.key === " ")
|
|
16
|
+
toggle();
|
|
17
|
+
}, role: "button", tabIndex: 0, children: content })] }));
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=minimize-card.js.map
|
|
@@ -11,4 +11,5 @@ export interface LudicordMinimizeProviderProps {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function LudicordMinimizeProvider({ children, defaultMinimized, }: LudicordMinimizeProviderProps): import("react").JSX.Element;
|
|
13
13
|
export declare function useLudicordMinimize(): LudicordMinimizeState;
|
|
14
|
+
export declare function useOptionalLudicordMinimize(): LudicordMinimizeState | null;
|
|
14
15
|
//# sourceMappingURL=minimize.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { LudicordFileComponents } from "./files.js";
|
|
3
|
+
export declare function LudicordRoot({ children, files }: {
|
|
4
|
+
readonly children: ReactNode;
|
|
5
|
+
readonly files?: LudicordFileComponents;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { LudicordErrorBoundary, LudicordLoadingBoundary } from "./embed-router.js";
|
|
4
|
+
import { LudicordMinimizeProvider } from "./minimize.js";
|
|
5
|
+
import { LudicordFilesContext } from "./files.js";
|
|
6
|
+
export function LudicordRoot({ children, files = {} }) {
|
|
7
|
+
const [revision, setRevision] = useState(0);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const recover = () => setRevision((value) => value + 1);
|
|
10
|
+
window.addEventListener("ludicord:recover", recover);
|
|
11
|
+
return () => window.removeEventListener("ludicord:recover", recover);
|
|
12
|
+
}, []);
|
|
13
|
+
const Layout = files.layout;
|
|
14
|
+
const Loading = files.loading;
|
|
15
|
+
const ErrorFile = files.error;
|
|
16
|
+
const reset = () => setRevision((value) => value + 1);
|
|
17
|
+
return _jsx(LudicordFilesContext.Provider, { value: files, children: _jsx(LudicordMinimizeProvider, { children: _jsx(LudicordErrorBoundary, { resetKey: String(revision), fallback: ErrorFile === undefined ? undefined : (error) => _jsx(ErrorFile, { error: error, reset: reset }), children: _jsx(LudicordLoadingBoundary, { fallback: Loading === undefined ? null : _jsx(Loading, {}), children: Layout === undefined ? children : _jsx(Layout, { children: children }) }) }) }) });
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=root.js.map
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare function useLudicordRuntime(): {
|
|
2
|
+
readonly environment: string;
|
|
3
|
+
readonly version: "2.2.4";
|
|
4
|
+
readonly activityReady: boolean;
|
|
5
|
+
readonly discordReady: boolean;
|
|
6
|
+
readonly authStatus: import("../auth/types.js").LudicordAuthStatus;
|
|
7
|
+
readonly wsReady: boolean;
|
|
8
|
+
};
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { useDiscord } from "../discord/runtime.js";
|
|
3
|
+
import { useAuthStatus } from "../auth/client.js";
|
|
4
|
+
import { subscribeWebSocketRuntime, isWebSocketRuntimeReady } from "../ws/client.js";
|
|
5
|
+
import { LUDICORD_VERSION } from "../version.js";
|
|
6
|
+
export function useLudicordRuntime() {
|
|
7
|
+
const discord = useDiscord();
|
|
8
|
+
const authStatus = useAuthStatus();
|
|
9
|
+
const [activityReady, setReady] = useState(false);
|
|
10
|
+
useEffect(() => setReady(true), []);
|
|
11
|
+
const wsReady = useSyncExternalStore(subscribeWebSocketRuntime, isWebSocketRuntimeReady, () => false);
|
|
12
|
+
const config = globalThis.__LUDICORD_PUBLIC_CONFIG__;
|
|
13
|
+
return { environment: config?.environment ?? "production", version: LUDICORD_VERSION, activityReady, discordReady: discord.status === "ready", authStatus, wsReady };
|
|
14
|
+
}
|
|
3
15
|
//# sourceMappingURL=index.js.map
|