texlite 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +87 -5
- package/OPERATIONS.md +27 -0
- package/dist/client/assets/AdminUsers-5cAOkdRO.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-G2kKkA2f.js +1 -0
- package/dist/client/assets/Dashboard-BJDFbzQa.js +5 -0
- package/dist/client/assets/GitDialog-BEtLh2S_.js +3 -0
- package/dist/client/assets/GitHubAccountDialog-D2kdCzOs.js +1 -0
- package/dist/client/assets/{HistoryDialog-DWYErBwj.js → HistoryDialog-BwxDdj-j.js} +3 -3
- package/dist/client/assets/LatexEditor-sMjmvA6V.js +141 -0
- package/dist/client/assets/{PdfPreview-BjghzUb1.js → PdfPreview-z5KnowpL.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-DNV7M7vH.js +1 -0
- package/dist/client/assets/ProjectSettings-Mf8zDGRu.js +1 -0
- package/dist/client/assets/ProjectWorkspace-BJFxjMCn.js +32 -0
- package/dist/client/assets/QuickOpenDialog-C758pouQ.js +1 -0
- package/dist/client/assets/{SelectionHistoryDialog-CR5c3I8k.js → SelectionHistoryDialog-p8L2n4RS.js} +2 -2
- package/dist/client/assets/SystemMetricsDialog-DDiSuglF.js +1 -0
- package/dist/client/assets/TagManagementDialog-BTVERmQS.js +1 -0
- package/dist/client/assets/WordCountDialog-B6RvAI6V.js +1 -0
- package/dist/client/assets/check-Hlb-tLSh.js +1 -0
- package/dist/client/assets/chevron-up-D0psXvTv.js +1 -0
- package/dist/client/assets/chktex-ZnIx425m.js +3 -0
- package/dist/client/assets/clock-3-C71NmJZI.js +1 -0
- package/dist/client/assets/{editor-CLY5CgkY.js → editor-_i6aPXT4.js} +1 -1
- package/dist/client/assets/eye-swovgNYS.js +1 -0
- package/dist/client/assets/github-y6i0qxSV.js +1 -0
- package/dist/client/assets/{hard-drive-Ctj3K_zx.js → hard-drive-BqcHPdoY.js} +1 -1
- package/dist/client/assets/index-7WrjzKvC.js +5 -0
- package/dist/client/assets/index-C5T8_lAl.js +1 -0
- package/dist/client/assets/index-DF5cor0N.js +10 -0
- package/dist/client/assets/index-Do5FsFqg.js +1 -0
- package/dist/client/assets/index-Y-wXUwwe.css +1 -0
- package/dist/client/assets/{minimize-2-BiVyoWZA.js → minimize-2-CK7jUy7-.js} +1 -1
- package/dist/client/assets/{minus-Bl8l4LXq.js → minus-B2sswwWT.js} +1 -1
- package/dist/client/assets/{plus-CCxK-HNt.js → plus-Co7iyp5m.js} +1 -1
- package/dist/client/assets/{refresh-cw-BE8IbaHI.js → refresh-cw-BHVcjInn.js} +1 -1
- package/dist/client/assets/{search-CPbhRWQE.js → search-Tpi6WAga.js} +1 -1
- package/dist/client/assets/{sigma-LxGD9tK2.js → sigma-DoHJQYf7.js} +1 -1
- package/dist/client/assets/spellCheck-BSbFJY9f.js +1 -0
- package/dist/client/assets/{tags-DuN89PsZ.js → tags-BHDlIcSb.js} +1 -1
- package/dist/client/assets/{type-BiettCiY.js → type-C-6Jq_0r.js} +1 -1
- package/dist/client/index.html +15 -3
- package/dist/server/app.js +6 -1
- package/dist/server/cgroups.js +35 -0
- package/dist/server/compilerVersions.js +46 -0
- package/dist/server/config.js +8 -0
- package/dist/server/cpuMetrics.js +122 -0
- package/dist/server/db.js +13 -0
- package/dist/server/environment.js +11 -0
- package/dist/server/i18n.js +0 -2
- package/dist/server/resourceMetrics.js +214 -0
- package/dist/server/routes/projectFiles.js +1 -59
- package/dist/server/routes/system.js +32 -1
- package/dist/server/systemMemory.js +51 -0
- package/dist/server/updates.js +116 -0
- package/dist/shared/compilerVersions.js +11 -0
- package/dist/shared/resourceMetrics.js +1 -0
- package/dist/shared/updates.js +5 -0
- package/package.json +3 -1
- package/texlite.config.example.json +3 -0
- package/dist/client/assets/AdminUsers-Dyapv-3c.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-CU7Q7r0Z.js +0 -1
- package/dist/client/assets/Dashboard-DsdhFENx.js +0 -2
- package/dist/client/assets/GitDialog-CZpnKw-J.js +0 -3
- package/dist/client/assets/GitHubAccountDialog-CZ8O_PjD.js +0 -1
- package/dist/client/assets/LatexEditor-CssVgypt.js +0 -141
- package/dist/client/assets/ProjectIconPickerDialog-CqRmgFBM.js +0 -1
- package/dist/client/assets/ProjectNavigationDialogs-BZxI3PJO.js +0 -1
- package/dist/client/assets/ProjectSettings-CZE_xDKn.js +0 -1
- package/dist/client/assets/ProjectWorkspace-CAX3qEYr.js +0 -32
- package/dist/client/assets/SystemMetricsDialog-DDpFwgXh.js +0 -1
- package/dist/client/assets/TagManagementDialog-CXLA9h_j.js +0 -1
- package/dist/client/assets/WordCountDialog-DUyR24vv.js +0 -1
- package/dist/client/assets/check-CwBYzomT.js +0 -1
- package/dist/client/assets/chevron-up-D5lCNKlk.js +0 -1
- package/dist/client/assets/chktex-CRkLYKcV.js +0 -3
- package/dist/client/assets/external-link-C9Td1CCj.js +0 -1
- package/dist/client/assets/github-D-JDXb-w.js +0 -1
- package/dist/client/assets/index-9hnQ8Q9x.js +0 -5
- package/dist/client/assets/index-C0qg2Ylw.css +0 -1
- package/dist/client/assets/index-DkpU9Fgs.js +0 -10
- package/dist/client/assets/index-_eYe7K9T.js +0 -1
- package/dist/client/assets/spellCheck-hpm8qZTr.js +0 -1
- package/dist/client/assets/x-C_3swJOC.js +0 -1
- package/dist/server/projectSearch.js +0 -113
|
@@ -11,10 +11,9 @@ import { compileMainFile } from "../compileArtifacts.js";
|
|
|
11
11
|
import { assertNoSourceSymlinks, listProjectFilesAsync, resolveSourcePath, safePathSegment, safeRelativePath, sourceRoot } from "../files.js";
|
|
12
12
|
import { apiError, contentDisposition, httpError } from "../http.js";
|
|
13
13
|
import { accessibleProject, canEdit } from "../projects.js";
|
|
14
|
-
import { replaceProject, searchProject } from "../projectSearch.js";
|
|
15
14
|
import { mainDocumentCandidates } from "../latexRoot.js";
|
|
16
15
|
import { commentsForFile, escapeGlobPattern, movedProjectPath, now, requireEditableProject, touchProject } from "./projectShared.js";
|
|
17
|
-
/** Register project file-tree, editor content,
|
|
16
|
+
/** Register project file-tree, editor content, and upload routes. */
|
|
18
17
|
export function registerProjectFileRoutes(app, context) {
|
|
19
18
|
const { config, db, collaboration, projectMutations, latexCompletions, projectOutlines, metrics, recordHistory } = context;
|
|
20
19
|
app.get("/api/projects/:id/files", async (request, reply) => {
|
|
@@ -87,63 +86,6 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
87
86
|
metrics.record("outline.build", performance.now() - startedAt);
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
|
-
app.get("/api/projects/:id/search", async (request, reply) => {
|
|
91
|
-
const user = requireUser(request, reply, db);
|
|
92
|
-
if (!user)
|
|
93
|
-
return;
|
|
94
|
-
const { id } = request.params;
|
|
95
|
-
if (!accessibleProject(db, id, user))
|
|
96
|
-
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
97
|
-
const query = request.query;
|
|
98
|
-
const startedAt = performance.now();
|
|
99
|
-
try {
|
|
100
|
-
return await projectMutations.runConsistentRead(id, () => searchProject(config, id, {
|
|
101
|
-
query: query.q ?? "",
|
|
102
|
-
caseSensitive: query.caseSensitive === "1",
|
|
103
|
-
wholeWord: query.wholeWord === "1"
|
|
104
|
-
}), {
|
|
105
|
-
preflight: () => {
|
|
106
|
-
if (!accessibleProject(db, id, user))
|
|
107
|
-
throw httpError(404, "PROJECT_NOT_FOUND");
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
metrics.record("search.project", performance.now() - startedAt);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
app.post("/api/projects/:id/search/replace", async (request, reply) => {
|
|
116
|
-
const user = requireUser(request, reply, db);
|
|
117
|
-
if (!user)
|
|
118
|
-
return;
|
|
119
|
-
const { id } = request.params;
|
|
120
|
-
const project = accessibleProject(db, id, user);
|
|
121
|
-
if (!project || !canEdit(project))
|
|
122
|
-
return apiError(reply, 403, "PROJECT_EDIT_FORBIDDEN");
|
|
123
|
-
const body = request.body;
|
|
124
|
-
if (typeof body.query !== "string" || typeof body.replacement !== "string" || body.replacement.length > 100_000) {
|
|
125
|
-
return apiError(reply, 400, "SEARCH_QUERY_INVALID");
|
|
126
|
-
}
|
|
127
|
-
return await projectMutations.runExclusive(id, "project-wide replace", async () => {
|
|
128
|
-
const changed = await replaceProject(config, id, {
|
|
129
|
-
query: body.query,
|
|
130
|
-
caseSensitive: body.caseSensitive === true,
|
|
131
|
-
wholeWord: body.wholeWord === true,
|
|
132
|
-
maxFileBytes: maxCollaborativeFileBytes(config)
|
|
133
|
-
}, body.replacement);
|
|
134
|
-
let replacements = 0;
|
|
135
|
-
for (const file of changed) {
|
|
136
|
-
reanchorFileComments(db, id, file.path, file.previous, file.content);
|
|
137
|
-
collaboration.updateFile(id, file.path, file.content, user.id);
|
|
138
|
-
replacements += file.count;
|
|
139
|
-
}
|
|
140
|
-
if (changed.length) {
|
|
141
|
-
touchProject(db, id, user.id);
|
|
142
|
-
recordHistory(id, user.id, "file", changed.map((file) => file.path));
|
|
143
|
-
}
|
|
144
|
-
return { ok: true, replacements, files: changed.map((file) => file.path) };
|
|
145
|
-
}, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
146
|
-
});
|
|
147
89
|
app.get("/api/projects/:id/completions", async (request, reply) => {
|
|
148
90
|
const user = requireUser(request, reply, db);
|
|
149
91
|
if (!user)
|
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { requireAdmin } from "../auth.js";
|
|
1
|
+
import { requireAdmin, requireUser } from "../auth.js";
|
|
2
2
|
import { maxCollaborativeFileBytes } from "../collaboration.js";
|
|
3
3
|
import { MAX_CITATION_BIBTEX_BYTES } from "../limits.js";
|
|
4
4
|
import { MIN_PASSWORD_LENGTH } from "../security.js";
|
|
5
|
+
import { apiError } from "../http.js";
|
|
6
|
+
import { ResourceMetrics } from "../resourceMetrics.js";
|
|
7
|
+
import { CompilerVersionService } from "../compilerVersions.js";
|
|
8
|
+
import { inspectCompilerEnvironment } from "../environment.js";
|
|
5
9
|
/** Register routes that describe the running server or its live connections. */
|
|
6
10
|
export function registerSystemRoutes(app, context) {
|
|
7
11
|
const { config, db, queue, collaboration, latexCompletions, projectOutlines, metrics, eventLoopDelay } = context;
|
|
12
|
+
const resources = new ResourceMetrics();
|
|
13
|
+
const compilerVersions = new CompilerVersionService(() => inspectCompilerEnvironment(config));
|
|
14
|
+
app.get("/api/compiler/versions", async (request, reply) => {
|
|
15
|
+
if (!requireUser(request, reply, db))
|
|
16
|
+
return;
|
|
17
|
+
reply.header("Cache-Control", "no-store");
|
|
18
|
+
return compilerVersions.getVersions();
|
|
19
|
+
});
|
|
20
|
+
app.get("/api/admin/updates", async (request, reply) => {
|
|
21
|
+
const user = requireAdmin(request, reply, db);
|
|
22
|
+
if (!user)
|
|
23
|
+
return;
|
|
24
|
+
reply.header("Cache-Control", "no-store");
|
|
25
|
+
await context.updates.check();
|
|
26
|
+
return { update: context.updates.notice(user.id) };
|
|
27
|
+
});
|
|
28
|
+
app.post("/api/admin/updates/dismiss", async (request, reply) => {
|
|
29
|
+
const user = requireAdmin(request, reply, db);
|
|
30
|
+
if (!user)
|
|
31
|
+
return;
|
|
32
|
+
if (!context.updates.dismiss(user.id, request.body?.version))
|
|
33
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
34
|
+
return { ok: true };
|
|
35
|
+
});
|
|
8
36
|
app.get("/api/config", async () => ({
|
|
9
37
|
siteName: config.siteName,
|
|
10
38
|
adminEmail: config.adminEmail,
|
|
@@ -20,10 +48,13 @@ export function registerSystemRoutes(app, context) {
|
|
|
20
48
|
app.get("/api/health/metrics", async (request, reply) => {
|
|
21
49
|
if (!requireAdmin(request, reply, db))
|
|
22
50
|
return;
|
|
51
|
+
reply.header("Cache-Control", "no-store");
|
|
52
|
+
const resourceMemory = await resources.sample();
|
|
23
53
|
const memory = process.memoryUsage();
|
|
24
54
|
return {
|
|
25
55
|
uptimeSeconds: Math.round(process.uptime()),
|
|
26
56
|
memory: { rssBytes: memory.rss, heapUsedBytes: memory.heapUsed, heapTotalBytes: memory.heapTotal },
|
|
57
|
+
...resourceMemory,
|
|
27
58
|
eventLoopDelay: {
|
|
28
59
|
p50Ms: Math.round(eventLoopDelay.percentile(50) / 100_000) / 10,
|
|
29
60
|
p95Ms: Math.round(eventLoopDelay.percentile(95) / 100_000) / 10,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cgroupPaths } from "./cgroups.js";
|
|
5
|
+
const readText = (file) => readFile(file, "utf8");
|
|
6
|
+
/** Linux containers expose their own cgroup, not the Docker daemon or host socket. */
|
|
7
|
+
export async function collectSystemMemory(platform = process.platform, read = readText) {
|
|
8
|
+
const total = os.totalmem();
|
|
9
|
+
const fallback = { scope: "host", totalBytes: total, usedBytes: Math.max(0, total - os.freemem()) };
|
|
10
|
+
if (platform !== "linux")
|
|
11
|
+
return fallback;
|
|
12
|
+
const optional = (file) => read(file).catch(() => null);
|
|
13
|
+
const [groups, mounts, docker, podman] = await Promise.all([
|
|
14
|
+
optional("/proc/self/cgroup"), optional("/proc/self/mountinfo"), optional("/.dockerenv"), optional("/run/.containerenv")
|
|
15
|
+
]);
|
|
16
|
+
const container = docker !== null || podman !== null || /(?:docker|kubepods|libpod|containerd)/.test(groups ?? "");
|
|
17
|
+
if (!container) {
|
|
18
|
+
const info = await optional("/proc/meminfo");
|
|
19
|
+
const available = info?.match(/^MemAvailable:\s+(\d+)\s+kB$/m);
|
|
20
|
+
if (available)
|
|
21
|
+
fallback.usedBytes = Math.max(0, total - Number(available[1]) * 1024);
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
const candidates = cgroupPaths(groups ?? "", mounts ?? "", "memory");
|
|
25
|
+
for (const { directory, mountPoint, v2 } of candidates) {
|
|
26
|
+
const usage = await optional(`${directory}/${v2 ? "memory.current" : "memory.usage_in_bytes"}`);
|
|
27
|
+
const usedBytes = memoryNumber(usage);
|
|
28
|
+
if (usedBytes === null)
|
|
29
|
+
continue;
|
|
30
|
+
// A parent cgroup can impose a tighter limit than the container's own entry.
|
|
31
|
+
let totalBytes = null;
|
|
32
|
+
for (let current = directory;; current = path.posix.dirname(current)) {
|
|
33
|
+
const raw = await optional(`${current}/${v2 ? "memory.max" : "memory.limit_in_bytes"}`);
|
|
34
|
+
const limit = memoryNumber(raw);
|
|
35
|
+
// cgroup v1 uses a huge sentinel for an unlimited group; v2 uses "max".
|
|
36
|
+
if (limit !== null && limit > 0 && limit < 2 ** 60)
|
|
37
|
+
totalBytes = Math.min(totalBytes ?? total, limit, total);
|
|
38
|
+
if (current === mountPoint || current === "/")
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return { scope: "container", usedBytes, totalBytes };
|
|
42
|
+
}
|
|
43
|
+
// Never label host-wide usage as container usage when cgroup access is unavailable.
|
|
44
|
+
return { scope: "container", usedBytes: null, totalBytes: null };
|
|
45
|
+
}
|
|
46
|
+
function memoryNumber(value) {
|
|
47
|
+
if (value === null || !/^\d+$/.test(value.trim()))
|
|
48
|
+
return null;
|
|
49
|
+
const number = Number(value.trim());
|
|
50
|
+
return Number.isSafeInteger(number) ? number : null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { gt, prerelease, valid } from "semver";
|
|
4
|
+
import { packageRootDirectory } from "./runtimePaths.js";
|
|
5
|
+
export const UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60_000;
|
|
6
|
+
export const UPDATE_RETRY_INTERVAL_MS = 60 * 60_000;
|
|
7
|
+
const REQUEST_TIMEOUT_MS = 5_000;
|
|
8
|
+
const REGISTRY_URL = "https://registry.npmjs.org/texlite/latest";
|
|
9
|
+
function packageVersion() {
|
|
10
|
+
const metadata = JSON.parse(fs.readFileSync(path.join(packageRootDirectory(), "package.json"), "utf8"));
|
|
11
|
+
return metadata.version;
|
|
12
|
+
}
|
|
13
|
+
function stableVersion(value) {
|
|
14
|
+
return typeof value === "string" && valid(value) === value && prerelease(value) === null;
|
|
15
|
+
}
|
|
16
|
+
/** One background checker per server; cached results and dismissals survive restarts. */
|
|
17
|
+
export class UpdateChecker {
|
|
18
|
+
db;
|
|
19
|
+
options;
|
|
20
|
+
fetch;
|
|
21
|
+
now;
|
|
22
|
+
currentVersion;
|
|
23
|
+
method;
|
|
24
|
+
pending = null;
|
|
25
|
+
controller = null;
|
|
26
|
+
timer = null;
|
|
27
|
+
disposed = false;
|
|
28
|
+
constructor(db, options) {
|
|
29
|
+
this.db = db;
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.fetch = options.fetch ?? globalThis.fetch;
|
|
32
|
+
this.now = options.now ?? Date.now;
|
|
33
|
+
this.currentVersion = options.currentVersion ?? packageVersion();
|
|
34
|
+
this.method = options.method ?? (fs.existsSync("/.dockerenv") || fs.existsSync("/run/.containerenv") ? "docker" : "npm");
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
if (!this.options.enabled || this.disposed || this.timer)
|
|
38
|
+
return;
|
|
39
|
+
void this.check().catch(() => undefined);
|
|
40
|
+
this.timer = setInterval(() => { void this.check().catch(() => undefined); }, UPDATE_RETRY_INTERVAL_MS);
|
|
41
|
+
this.timer.unref();
|
|
42
|
+
}
|
|
43
|
+
cache() {
|
|
44
|
+
return this.db.prepare("SELECT latest_version, next_check_at FROM update_check_cache WHERE id = 1").get();
|
|
45
|
+
}
|
|
46
|
+
check() {
|
|
47
|
+
if (!this.options.enabled || this.disposed || !valid(this.currentVersion))
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
if (this.pending)
|
|
50
|
+
return this.pending;
|
|
51
|
+
if ((this.cache()?.next_check_at ?? 0) > this.now())
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
this.pending = this.checkRegistry().finally(() => { this.pending = null; });
|
|
54
|
+
return this.pending;
|
|
55
|
+
}
|
|
56
|
+
async checkRegistry() {
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
this.controller = controller;
|
|
59
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
60
|
+
timeout.unref();
|
|
61
|
+
let latest = null;
|
|
62
|
+
try {
|
|
63
|
+
const response = await this.fetch(REGISTRY_URL, {
|
|
64
|
+
headers: { Accept: "application/json" }, signal: controller.signal,
|
|
65
|
+
credentials: "omit", redirect: "error"
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok)
|
|
68
|
+
throw new Error("Update registry unavailable");
|
|
69
|
+
const metadata = await response.json();
|
|
70
|
+
const version = metadata && typeof metadata === "object" && "version" in metadata ? metadata.version : null;
|
|
71
|
+
if (!stableVersion(version))
|
|
72
|
+
throw new Error("Invalid stable release version");
|
|
73
|
+
latest = version;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Offline operation is normal. Keep the last known release and back off.
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
this.controller = null;
|
|
81
|
+
}
|
|
82
|
+
if (this.disposed)
|
|
83
|
+
return;
|
|
84
|
+
this.db.prepare(`INSERT INTO update_check_cache (id, latest_version, next_check_at) VALUES (1, ?, ?)
|
|
85
|
+
ON CONFLICT(id) DO UPDATE SET latest_version = COALESCE(excluded.latest_version, latest_version), next_check_at = excluded.next_check_at`)
|
|
86
|
+
.run(latest, this.now() + (latest ? UPDATE_CHECK_INTERVAL_MS : UPDATE_RETRY_INTERVAL_MS));
|
|
87
|
+
}
|
|
88
|
+
notice(userId) {
|
|
89
|
+
if (!this.options.enabled || !valid(this.currentVersion))
|
|
90
|
+
return null;
|
|
91
|
+
const latest = this.cache()?.latest_version;
|
|
92
|
+
if (!stableVersion(latest) || !gt(latest, this.currentVersion))
|
|
93
|
+
return null;
|
|
94
|
+
const dismissed = this.db.prepare("SELECT version FROM dismissed_updates WHERE user_id = ?").get(userId);
|
|
95
|
+
if (dismissed && valid(dismissed.version) && !gt(latest, dismissed.version))
|
|
96
|
+
return null;
|
|
97
|
+
return { currentVersion: this.currentVersion, latestVersion: latest, method: this.method };
|
|
98
|
+
}
|
|
99
|
+
dismiss(userId, version) {
|
|
100
|
+
if (!stableVersion(version) || this.cache()?.latest_version !== version)
|
|
101
|
+
return false;
|
|
102
|
+
const previous = this.db.prepare("SELECT version FROM dismissed_updates WHERE user_id = ?").get(userId);
|
|
103
|
+
if (previous && valid(previous.version) && gt(previous.version, version))
|
|
104
|
+
return true;
|
|
105
|
+
this.db.prepare(`INSERT INTO dismissed_updates (user_id, version) VALUES (?, ?)
|
|
106
|
+
ON CONFLICT(user_id) DO UPDATE SET version = excluded.version`).run(userId, version);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
async dispose() {
|
|
110
|
+
this.disposed = true;
|
|
111
|
+
if (this.timer)
|
|
112
|
+
clearInterval(this.timer);
|
|
113
|
+
this.controller?.abort();
|
|
114
|
+
await this.pending;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const COMPILER_VERSION_TOOLS = [
|
|
2
|
+
{ id: "texlive", name: "TeX Live" },
|
|
3
|
+
{ id: "pdflatex", name: "pdfLaTeX" },
|
|
4
|
+
{ id: "xelatex", name: "XeLaTeX" },
|
|
5
|
+
{ id: "lualatex", name: "LuaLaTeX" },
|
|
6
|
+
{ id: "latexmk", name: "latexmk" },
|
|
7
|
+
{ id: "bibtex", name: "BibTeX" },
|
|
8
|
+
{ id: "biber", name: "Biber" },
|
|
9
|
+
{ id: "texcount", name: "TeXcount" },
|
|
10
|
+
{ id: "chktex", name: "ChkTeX" }
|
|
11
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "texlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "A lightweight local-first collaborative LaTeX workspace",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
"react-dom": "^19.1.1",
|
|
99
99
|
"react-i18next": "^15.6.1",
|
|
100
100
|
"react-resizable-panels": "^2.1.9",
|
|
101
|
+
"semver": "^7.8.5",
|
|
101
102
|
"tex-fmt": "0.5.7-npm.1",
|
|
102
103
|
"ws": "^8.21.1",
|
|
103
104
|
"y-codemirror.next": "^0.3.5",
|
|
@@ -115,6 +116,7 @@
|
|
|
115
116
|
"@types/node": "^24.1.0",
|
|
116
117
|
"@types/react": "^19.1.9",
|
|
117
118
|
"@types/react-dom": "^19.1.7",
|
|
119
|
+
"@types/semver": "^7.8.0",
|
|
118
120
|
"@types/ws": "^8.18.1",
|
|
119
121
|
"@types/yauzl": "^2.10.3",
|
|
120
122
|
"@types/yazl": "^3.3.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as be,r,j as e}from"./react-CltQJflK.js";import{U as ee,D as ye,a as Ce,b as Ne,c as we,d as Se}from"./index-_eYe7K9T.js";import{c as q,g as N,h as w,d as se,M as L,C as ve}from"./index-DkpU9Fgs.js";import{U as Pe,X as $,E as ke,T as ae,i as ze,C as Me}from"./x-C_3swJOC.js";import{S as Te}from"./search-CPbhRWQE.js";const re=q("Dices",[["rect",{width:"12",height:"12",x:"2",y:"10",rx:"2",ry:"2",key:"6agr2n"}],["path",{d:"m17.92 14 3.5-3.5a2.24 2.24 0 0 0 0-3l-5-4.92a2.24 2.24 0 0 0-3 0L10 6",key:"1o487t"}],["path",{d:"M6 18h.01",key:"uhywen"}],["path",{d:"M10 14h.01",key:"ssrbsk"}],["path",{d:"M15 6h.01",key:"cblpky"}],["path",{d:"M18 9h.01",key:"2061c0"}]]);const te=q("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);const ne=q("LockKeyhole",[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]]);function ie(V=10){const n="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789!@#$%",s=crypto.getRandomValues(new Uint8Array(V));return Array.from(s,S=>n[S%n.length]).join("")}function Ue({currentUser:V,minPasswordLength:n}){const{t:s}=be(),[S,oe]=r.useState([]),[J,H]=r.useState(""),[I,j]=r.useState(1),[o,le]=r.useState({page:1,pageSize:20,total:0,totalPages:0}),[x,Q]=r.useState(!0),[v,X]=r.useState(!1),[ce,de]=r.useState(0),[G,W]=r.useState(""),[P,k]=r.useState(""),[i,z]=r.useState(!1),[M,d]=r.useState("");r.useEffect(()=>{if(!P)return;const a=window.setTimeout(()=>k(""),3e3);return()=>window.clearTimeout(a)},[P]);const[ue,T]=r.useState(!1),[t,h]=r.useState({username:"",displayName:"",password:"",role:"user",canCreateProjects:!1}),[D,E]=r.useState(null),[g,F]=r.useState(""),[f,O]=r.useState(null),[K,R]=r.useState(!1),[u,Y]=r.useState(!1),[Z,b]=r.useState(""),[l,U]=r.useState(null),[A,_]=r.useState(!1),[me,y]=r.useState(""),C=J.trim(),B=()=>de(a=>a+1);r.useEffect(()=>{const a=new AbortController;Q(!0),X(!1),W("");const m=window.setTimeout(()=>{const c=new URLSearchParams({page:String(I)});C&&c.set("q",C),N(`/api/admin/users?${c}`,{signal:a.signal}).then(p=>{a.signal.aborted||(oe(p.users),le(p.pagination),j(p.pagination.page))}).catch(p=>{a.signal.aborted||(W(w(p)),X(!0))}).finally(()=>{a.signal.aborted||Q(!1)})},C?200:0);return()=>{window.clearTimeout(m),a.abort()}},[C,I,ce]);const he=async()=>{if(!i){if(t.password.length<n)return d(s("auth.passwordMinimum",{count:n}));z(!0),d("");try{await N("/api/admin/users",{method:"POST",body:JSON.stringify({username:t.username,displayName:t.displayName||t.username,password:t.password,role:t.role,canCreateProjects:t.canCreateProjects})}),T(!1),h({username:"",displayName:"",password:"",role:"user",canCreateProjects:!1}),B(),k(s("users.saved"))}catch(a){d(w(a))}finally{z(!1)}}},pe=async a=>{U({target:a,setting:a.role==="admin"?"demote":"promote"}),y("")},je=async a=>{U({target:a,setting:a.canCreateProjects?"denyProjectCreation":"allowProjectCreation"}),y("")},xe=async()=>{if(!l||A)return;const{target:a,setting:m}=l,c=m==="demote"?{role:"user"}:m==="promote"?{role:"admin"}:{canCreateProjects:m==="allowProjectCreation"};_(!0),y("");try{await N(`/api/admin/users/${a.id}`,{method:"PATCH",body:JSON.stringify(c)}),B(),U(null),k(s("users.saved"))}catch(p){y(w(p))}finally{_(!1)}},ge=async()=>{if(!(!D||!g||i)){if(g.length<n)return d(s("auth.passwordMinimum",{count:n}));z(!0),d("");try{await N(`/api/admin/users/${D.id}`,{method:"PATCH",body:JSON.stringify({password:g})}),E(null),F(""),k(s("users.saved"))}catch(a){d(w(a))}finally{z(!1)}}},fe=async()=>{if(!(!f||u)){Y(!0),b("");try{await N(`/api/admin/users/${f.id}`,{method:"DELETE",body:JSON.stringify({deleteProjects:K})}),O(null),R(!1),B()}catch(a){b(w(a))}finally{Y(!1)}}};return e.jsxs("main",{className:"dashboard",children:[e.jsx("div",{className:"section-title",children:e.jsxs("div",{children:[e.jsxs("h1",{children:[e.jsx(Pe,{"aria-hidden":!0,size:25}),s("users.manage")]}),e.jsx("p",{className:"muted",children:s("users.onlyAdmin")})]})}),e.jsxs("div",{className:"admin-user-toolbar",children:[e.jsxs("div",{className:"admin-user-filters",children:[e.jsxs("div",{className:"admin-user-search",role:"search",children:[e.jsx(Te,{"aria-hidden":!0,size:16}),e.jsx("input",{role:"searchbox","aria-label":s("users.searchPlaceholder"),placeholder:s("users.searchPlaceholder"),value:J,onChange:a=>{H(a.target.value),j(1)}}),J&&e.jsx("button",{type:"button","aria-label":s("users.clearSearch"),title:s("users.clearSearch"),onClick:()=>{H(""),j(1)},children:e.jsx($,{"aria-hidden":!0,size:14})})]}),!x&&!v&&e.jsx("span",{className:"admin-user-count",role:"status",children:s("users.total",{count:o.total})})]}),e.jsxs("button",{className:"primary icon-button admin-user-add",onClick:()=>{d(""),T(!0)},children:[e.jsx(ee,{"aria-hidden":!0,size:15}),s("users.add")]})]}),P&&e.jsx("p",{className:"admin-user-notice",role:"status",children:P}),G&&e.jsx("p",{className:"error",role:"alert",children:G}),e.jsx("div",{className:"table-card admin-user-table","aria-busy":x,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:s("common.user")}),e.jsx("th",{children:s("users.role")}),e.jsx("th",{children:s("users.createProjects")}),e.jsx("th",{children:s("users.ownedProjects")}),e.jsx("th",{children:s("users.actions")})]})}),e.jsx("tbody",{children:x?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"admin-user-list-state",children:e.jsxs("span",{role:"status",children:[e.jsx(se,{className:"spin",size:16}),s("common.loading")]})})}):v?e.jsx("tr",{children:e.jsxs("td",{colSpan:5,className:"admin-user-list-state",children:[e.jsx("span",{children:s("users.loadFailed")}),e.jsx("button",{type:"button",onClick:B,children:s("common.retry")})]})}):S.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"admin-user-list-state",children:s(C?"users.noMatches":"users.empty")})}):S.map(a=>{const m=a.id===V.id,c=i||A;return e.jsxs("tr",{children:[e.jsxs("td",{className:"admin-user-identity",children:[e.jsx("strong",{children:a.displayName}),e.jsxs("small",{children:["@",a.username]})]}),e.jsx("td",{children:m?e.jsxs("span",{className:"admin-user-badge",title:s("users.selfProtected"),children:[e.jsx(ne,{size:12,"aria-hidden":!0}),s("common.admin")]}):e.jsxs("select",{className:"admin-user-role","aria-label":s("users.roleFor",{username:a.username}),value:a.role,disabled:c,onChange:()=>{pe(a)},children:[e.jsx("option",{value:"user",children:s("common.user")}),e.jsx("option",{value:"admin",children:s("common.admin")})]})}),e.jsx("td",{children:a.role==="admin"?e.jsxs("span",{className:"admin-user-locked",title:s("users.adminCreation"),children:[e.jsx(ne,{size:12,"aria-hidden":!0}),s("users.allow")]}):e.jsx("button",{type:"button",className:"admin-user-switch",role:"switch","aria-checked":a.canCreateProjects,"aria-label":s("users.creationFor",{username:a.username}),disabled:c,onClick:()=>{je(a)},children:e.jsx("span",{})})}),e.jsx("td",{children:a.ownedProjects??0}),e.jsx("td",{children:e.jsxs("div",{className:"admin-user-actions",children:[e.jsxs("button",{className:"icon-button",disabled:c,onClick:()=>{E(a),F(""),d("")},children:[e.jsx(te,{"aria-hidden":!0,size:13}),s("users.resetPassword")]}),!m&&e.jsxs(ye,{modal:!1,children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{className:"icon-button",disabled:c,"aria-label":s("users.actionsFor",{username:a.username}),children:e.jsx(ke,{size:17,"aria-hidden":!0})})}),e.jsx(Ne,{children:e.jsx(we,{className:"comment-actions-menu-content",align:"end",sideOffset:5,children:e.jsxs(Se,{className:"danger-text",onSelect:()=>{O(a),R(!1),b("")},children:[e.jsx(ae,{size:14,"aria-hidden":!0}),s("users.deleteTitle")]})})})]})]})})]},a.id)})})]})}),o.totalPages>1&&e.jsxs("nav",{className:"project-pagination admin-user-pagination","aria-label":s("users.pagination"),children:[e.jsxs("button",{type:"button",disabled:x||v||o.page<=1,onClick:()=>j(o.page-1),children:[e.jsx(ze,{size:15}),s("users.previousPage")]}),e.jsx("span",{children:s("users.pageOf",{page:o.page,totalPages:o.totalPages})}),e.jsxs("button",{type:"button",disabled:x||v||o.page>=o.totalPages,onClick:()=>j(o.page+1),children:[s("users.nextPage"),e.jsx(Me,{size:15})]})]}),e.jsxs(L,{open:ue,title:s("users.add"),description:s("users.addDescription"),onOpenChange:a=>{i||T(a)},footer:e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"icon-button",disabled:i,onClick:()=>T(!1),children:[e.jsx($,{"aria-hidden":!0,size:14}),s("common.cancel")]}),e.jsxs("button",{className:"primary icon-button",disabled:i||!t.username.trim()||t.password.length<n,onClick:()=>{he()},children:[e.jsx(ee,{"aria-hidden":!0,size:14}),s("users.createUser")]})]}),children:[M&&e.jsx("p",{className:"error",role:"alert",children:M}),e.jsxs("fieldset",{className:"admin-user-form form-stack",disabled:i,children:[e.jsxs("label",{className:"form-field",children:[s("auth.username"),e.jsx("input",{value:t.username,onChange:a=>h({...t,username:a.target.value})})]}),e.jsxs("label",{className:"form-field",children:[s("users.displayName"),e.jsx("input",{value:t.displayName,onChange:a=>h({...t,displayName:a.target.value})})]}),e.jsxs("label",{className:"form-field",children:[s("users.initialPassword"),e.jsxs("span",{className:"password-generator",children:[e.jsx("input",{minLength:n,autoComplete:"new-password",value:t.password,onChange:a=>h({...t,password:a.target.value})}),e.jsxs("button",{type:"button",title:s("users.generatePassword"),onClick:()=>h({...t,password:ie()}),children:[e.jsx(re,{size:15}),s("users.randomPassword")]})]}),e.jsx("small",{className:"field-hint",children:s("auth.passwordMinimum",{count:n})})]}),e.jsxs("label",{className:"form-field",children:[s("users.role"),e.jsxs("select",{value:t.role,onChange:a=>h({...t,role:a.target.value}),children:[e.jsx("option",{value:"user",children:s("common.user")}),e.jsx("option",{value:"admin",children:s("common.admin")})]})]}),e.jsxs("label",{className:"checkbox-field",children:[e.jsx("input",{type:"checkbox",checked:t.canCreateProjects||t.role==="admin",disabled:t.role==="admin",onChange:a=>h({...t,canCreateProjects:a.target.checked})})," ",s("users.allowCreate")]})]})]}),e.jsxs(L,{open:!!D,title:s("users.resetPassword"),description:s("users.resetDescription",{username:D?.username??""}),onOpenChange:a=>{!a&&!i&&E(null)},footer:e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"icon-button",disabled:i,onClick:()=>E(null),children:[e.jsx($,{"aria-hidden":!0,size:14}),s("common.cancel")]}),e.jsxs("button",{className:"primary icon-button",disabled:i||g.length<n,onClick:()=>{ge()},children:[e.jsx(te,{"aria-hidden":!0,size:14}),s("users.reset")]})]}),children:[M&&e.jsx("p",{className:"error",role:"alert",children:M}),e.jsxs("label",{className:"form-field",children:[s("auth.newPassword"),e.jsxs("span",{className:"password-generator",children:[e.jsx("input",{disabled:i,autoFocus:!0,minLength:n,autoComplete:"new-password",value:g,onChange:a=>F(a.target.value)}),e.jsxs("button",{type:"button",disabled:i,onClick:()=>F(ie()),children:[e.jsx(re,{size:15}),s("users.randomPassword")]})]}),e.jsx("small",{className:"field-hint",children:s("auth.passwordMinimum",{count:n})})]})]}),e.jsx(L,{open:!!f,title:s("users.deleteTitle"),description:s("users.deleteDescription",{username:f?.username??""}),onOpenChange:a=>{!a&&!u&&(O(null),b(""))},footer:e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"icon-button",disabled:u,onClick:()=>{O(null),b("")},children:[e.jsx($,{"aria-hidden":!0,size:14}),s("common.cancel")]}),e.jsxs("button",{className:"danger icon-button",disabled:u,"aria-busy":u,onClick:()=>{fe()},children:[u?e.jsx(se,{className:"spin","aria-hidden":!0,size:14}):e.jsx(ae,{"aria-hidden":!0,size:14}),s(u?"common.loading":"users.deleteTitle")]})]}),children:e.jsxs(e.Fragment,{children:[Z&&e.jsx("p",{className:"error dialog-error",children:Z}),e.jsxs("fieldset",{className:"choice-group",disabled:u,children:[e.jsx("legend",{children:s("users.ownedChoice",{count:f?.ownedProjects??0})}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:!K,onChange:()=>R(!1)})," ",s("users.transferProjects")]}),e.jsxs("label",{children:[e.jsx("input",{type:"radio",checked:K,onChange:()=>R(!0)})," ",s("users.deleteProjects")]})]})]})}),e.jsx(ve,{open:!!l,title:s(`userConfirmations.${l?.setting??"demote"}Title`),description:s(`userConfirmations.${l?.setting??"demote"}Description`,{username:l?.target.username??""}),confirmLabel:s(`userConfirmations.${l?.setting??"demote"}Confirm`),danger:l?.setting!=="promote"&&l?.setting!=="allowProjectCreation",busy:A,error:me,onCancel:()=>{A||(U(null),y(""))},onConfirm:()=>{xe()}})]})}export{Ue as AdminUsers};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as fe,r as s,j as e}from"./react-CltQJflK.js";import{c as De,M as re,d as q,C as Fe,g as A,h as D}from"./index-DkpU9Fgs.js";import{a as Ge,C as Ze}from"./chevron-up-D5lCNKlk.js";import{T as Re}from"./tags-DuN89PsZ.js";import{C as I}from"./check-CwBYzomT.js";import{X as Z,P as et,T as Oe,B as oe,i as xe,C as tt,k as Ke}from"./x-C_3swJOC.js";import{P as le}from"./plus-CCxK-HNt.js";import{parseBibEntriesResult as it,citationBibtexLimitLabel as at,parseSingleBibEntry as Me,citationVenue as nt}from"./citationLibrary-C9WnXB-1.js";import{S as st}from"./search-CPbhRWQE.js";const ot=De("Import",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m8 11 4 4 4-4",key:"1dohi6"}],["path",{d:"M8 5H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-4",key:"1ywtjm"}]]);const rt=De("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);function lt({tags:l,selectedId:y,onSelect:b,onManage:L}){const{t:c}=fe(),[x,k]=s.useState(!1),[N,j]=s.useState(Number.POSITIVE_INFINITY),[T,a]=s.useState(),w=s.useRef(null),K=y?[...l.filter(d=>d.id===y),...l.filter(d=>d.id!==y)]:l;s.useLayoutEffect(()=>{const d=w.current;if(!d)return;const g=()=>{const z=Array.from(d.querySelectorAll("button")),M=[...new Set(z.map(u=>u.offsetTop))][2],h=M===void 0?z:z.filter(u=>u.offsetTop<M);j(h.length),a(h.length?Math.max(...h.map(u=>u.offsetTop+u.offsetHeight)):void 0)};g();const C=new ResizeObserver(g);return C.observe(d),()=>C.disconnect()},[l,y]);const m=N<l.length+1;return e.jsxs("div",{className:"citation-tag-bar",children:[e.jsxs("div",{className:"citation-tag-filter-catalog",children:[e.jsx("div",{className:"citation-tag-filter-clip",style:!x&&m?{maxHeight:T}:void 0,children:e.jsxs("div",{className:"citation-tag-filters",ref:w,children:[e.jsx("button",{type:"button",className:y?"":"active","aria-pressed":!y,onClick:()=>b(""),children:c("citationLibrary.allTags")}),K.map((d,g)=>{const C=!x&&g+1>=N;return e.jsxs("button",{type:"button",className:y===d.id?"active":"","aria-pressed":y===d.id,"aria-hidden":C||void 0,tabIndex:C?-1:0,title:d.name,onClick:()=>b(y===d.id?"":d.id),children:[e.jsx("span",{className:`citation-tag-dot tag-${d.color}`}),e.jsx("span",{className:"citation-tag-name",children:d.name})]},d.id)})]})}),l.length===0&&e.jsx("span",{className:"muted",children:c("citationLibrary.noTags")}),m&&e.jsxs("button",{type:"button",className:"citation-tag-expand","aria-expanded":x,onClick:()=>k(d=>!d),children:[x?e.jsx(Ge,{size:13}):e.jsx(Ze,{size:13}),c(x?"citationTagManagement.collapse":"citationTagManagement.expand")]})]}),e.jsxs("button",{type:"button",className:"citation-tag-manage",onClick:L,children:[e.jsx(Re,{size:14}),c("citationTagManagement.title")]})]})}const ct=["red","orange","yellow","green","blue","purple","gray"];function dt({tags:l,onClose:y,onUpdated:b,onDeleted:L}){const{t:c}=fe(),[x,k]=s.useState(""),[N,j]=s.useState("green"),[T,a]=s.useState(null),[w,K]=s.useState(""),[m,d]=s.useState("green"),[g,C]=s.useState(!1),[z,E]=s.useState(""),[M,h]=s.useState(""),[u,V]=s.useState(null),[ce,F]=s.useState("");s.useEffect(()=>{if(!M)return;const r=window.setTimeout(()=>h(""),2e3);return()=>window.clearTimeout(r)},[M]);const O=async r=>{const p=(r?w:x).trim();if(!(g||!p)){C(!0),E(""),h("");try{const f=await A(r?`/api/citations/tags/${encodeURIComponent(r.id)}`:"/api/citations/tags",{method:r?"PATCH":"POST",body:JSON.stringify({name:p,color:r?m:N})});b(f.tag),r?a(null):k(""),h(c(r?"citationLibrary.tagsUpdated":f.created===!1?"citationTagManagement.exists":"citationLibrary.tagCreated"))}catch(f){E(D(f))}finally{C(!1)}}},Q=async()=>{if(!(!u||g)){C(!0),F(""),h("");try{await A(`/api/citations/tags/${encodeURIComponent(u.id)}`,{method:"DELETE"}),L(u.id),T?.id===u.id&&a(null),V(null),h(c("citationTagManagement.deleted"))}catch(r){F(D(r))}finally{C(!1)}}},ee=ct.map(r=>e.jsx("option",{value:r,children:c(`tags.${r}`)},r));return e.jsxs(e.Fragment,{children:[e.jsx(re,{open:!0,wide:!0,className:"tag-management-modal",title:c("citationTagManagement.title"),description:c("citationTagManagement.description"),onOpenChange:r=>{!r&&!g&&y()},footer:e.jsx("button",{disabled:g,onClick:y,children:c("common.close")}),children:e.jsxs("div",{className:"tag-management",children:[z&&e.jsx("p",{className:"error dialog-error",role:"alert",children:z}),M&&e.jsxs("p",{className:"citation-library-notice",role:"status",children:[e.jsx(I,{size:14}),M,e.jsx("button",{"aria-label":c("common.close"),onClick:()=>h(""),children:e.jsx(Z,{size:13})})]}),e.jsxs("fieldset",{disabled:g,className:"citation-tag-management-fields",children:[e.jsxs("form",{className:"tag-management-create",onSubmit:r=>{r.preventDefault(),O()},children:[e.jsxs("label",{className:"tag-management-field",children:[e.jsx("span",{children:c("tags.name")}),e.jsx("input",{autoFocus:!0,maxLength:32,value:x,placeholder:c("citationLibrary.newTagPlaceholder"),onChange:r=>k(r.target.value)})]}),e.jsxs("label",{className:"tag-management-field tag-management-color",children:[e.jsx("span",{children:c("tags.color")}),e.jsx("select",{value:N,onChange:r=>j(r.target.value),children:ee})]}),e.jsxs("button",{type:"submit",className:"primary",disabled:!x.trim(),children:[g?e.jsx(q,{className:"spin",size:14}):e.jsx(le,{size:14}),c("citationLibrary.createTag")]})]}),l.length===0?e.jsx("p",{className:"tag-management-empty",children:c("citationLibrary.noTags")}):e.jsx("div",{className:"tag-management-list",children:l.map(r=>e.jsxs("article",{className:`tag-management-item${T?.id===r.id?" editing":""}`,children:[e.jsxs("div",{className:"tag-management-item-main",children:[e.jsx("span",{className:`tag-dot tag-${r.color}`,"aria-hidden":!0}),e.jsx("strong",{title:r.name,children:r.name})]}),e.jsxs("div",{className:"tag-management-item-actions",children:[e.jsx("button",{type:"button","aria-label":c("citationTagManagement.edit",{tag:r.name}),onClick:()=>{a(r),K(r.name),d(r.color),E("")},children:e.jsx(et,{size:14})}),e.jsx("button",{type:"button",className:"danger-text","aria-label":c("citationTagManagement.delete",{tag:r.name}),onClick:()=>{V(r),F("")},children:e.jsx(Oe,{size:14})})]}),T?.id===r.id&&e.jsxs("form",{className:"tag-management-edit",onSubmit:p=>{p.preventDefault(),O(r)},children:[e.jsxs("label",{className:"tag-management-field",children:[e.jsx("span",{children:c("tags.rename")}),e.jsx("input",{maxLength:32,value:w,onChange:p=>K(p.target.value)})]}),e.jsxs("label",{className:"tag-management-field tag-management-color",children:[e.jsx("span",{children:c("tags.color")}),e.jsx("select",{value:m,onChange:p=>d(p.target.value),children:ee})]}),e.jsxs("div",{className:"tag-management-edit-actions",children:[e.jsx("button",{type:"button",onClick:()=>{a(null),E("")},children:c("common.cancel")}),e.jsxs("button",{type:"submit",className:"primary",disabled:!w.trim(),children:[e.jsx(I,{size:14}),c("common.save")]})]})]})]},r.id))})]})]})}),e.jsx(Fe,{open:!!u,title:c("tags.deleteTitle"),description:c("citationTagManagement.deleteDescription",{tag:u?.name??""}),confirmLabel:c("common.delete"),danger:!0,busy:g,error:ce,onCancel:()=>{g||V(null)},onConfirm:()=>{Q()}})]})}const mt=[],ut={status:"empty",entries:mt};function Nt({open:l,onOpenChange:y,page:b=!1,onBack:L,currentFile:c="",currentSource:x="",readOnly:k=!1,currentUserId:N,maxBibtexBytes:j,onInsert:T}){const{t:a}=fe(),[w,K]=s.useState("library"),[m,d]=s.useState(""),[g,C]=s.useState(""),[z,E]=s.useState([]),[M,h]=s.useState(1),[u,V]=s.useState({page:1,pageSize:60,total:0,totalPages:0}),[ce,F]=s.useState(0),[O,Q]=s.useState([]),[ee,r]=s.useState(!1),[p,f]=s.useState(null),[te,_]=s.useState([]),[de,ve]=s.useState(!1),[_e,Ne]=s.useState(!1),[X,B]=s.useState(null),[S,P]=s.useState(null),[me,ue]=s.useState(""),[$e,H]=s.useState(!1),[ie,ye]=s.useState(""),[Ce,ge]=s.useState(null),[he,ae]=s.useState(null),[Ie,G]=s.useState(""),[W,v]=s.useState(""),[ne,$]=s.useState("");s.useEffect(()=>{if(!ne)return;const t=window.setTimeout(()=>$(""),2e3);return()=>window.clearTimeout(t)},[ne]),s.useEffect(()=>{l||r(!1)},[l]);const[Le,R]=s.useState(new Map),[He,se]=s.useState(!1),[Ue,Je]=s.useState(0),U=!!(/\.bib$/i.test(c)&&T),pe=s.useMemo(()=>l&&U?it(x,j):ut,[l,x,U,j]),Te=pe.status==="too-large",we=pe.status==="invalid",J=pe.entries,qe=s.useMemo(()=>new Set(J.map(t=>t.citationKey.toLowerCase())),[J]);s.useEffect(()=>{if(!l)return;const t=new AbortController,n=window.setTimeout(()=>{Ne(!0),v("");const i=new URLSearchParams;m.trim()&&i.set("q",m.trim()),g&&i.set("tag",g),i.set("page",String(M)),i.set("pageSize","60"),A(`/api/citations?${i.toString()}`,{signal:t.signal}).then(o=>{E(o.entries),V(o.pagination),o.pagination.page!==M&&h(o.pagination.page)}).catch(o=>{o instanceof Error&&o.name==="AbortError"||v(D(o))}).finally(()=>{t.signal.aborted||Ne(!1)})},m.trim()?180:0);return()=>{window.clearTimeout(n),t.abort()}},[l,m,g,M,ce]),s.useEffect(()=>{if(!l)return;const t=new AbortController;return A("/api/citations/tags",{signal:t.signal}).then(n=>Q(n.tags)).catch(n=>{n instanceof Error&&n.name==="AbortError"||v(D(n))}),()=>t.abort()},[l]),s.useEffect(()=>{if(!l||!U){R(new Map),se(!1);return}const t=new AbortController,n=[...new Set(J.map(i=>i.citationKey))];return n.length?(se(!0),A("/api/citations/lookup",{method:"POST",body:JSON.stringify({keys:n}),signal:t.signal}).then(i=>{R(new Map(i.matches.map(o=>[o.citationKey.toLowerCase(),o])))}).catch(i=>{i instanceof Error&&i.name==="AbortError"||v(D(i))}).finally(()=>{t.signal.aborted||se(!1)}),()=>t.abort()):(R(new Map),se(!1),()=>t.abort())},[l,U,J,Ue]),s.useEffect(()=>{l&&(K("library"),d(""),C(""),h(1),V({page:1,pageSize:60,total:0,totalPages:0}),P(null),H(!1),ye(""),f(null),ge(null),ae(null),G(""),v(""),$(""),R(new Map))},[l,U]);const Ve=async t=>{B(t.citationKey),v("");try{const n=Le.get(t.citationKey.toLowerCase()),i=await A("/api/citations",{method:"POST",body:JSON.stringify({bibtex:t.bibtex,citationKey:t.citationKey,entryType:t.entryType,title:t.title,authors:t.authors,year:t.year,overwrite:!!n,expectedRevision:n?.revision})});E(o=>[i.entry,...o.filter(Y=>Y.id!==i.entry.id&&Y.citationKey.toLowerCase()!==i.entry.citationKey.toLowerCase())]),R(o=>new Map(o).set(i.entry.citationKey.toLowerCase(),{id:i.entry.id,citationKey:i.entry.citationKey,revision:i.entry.revision})),f(i.entry),_(i.entry.tags.map(o=>o.id)),$(i.updated?a("citationLibrary.updated"):a("citationLibrary.saved")),h(1),F(o=>o+1)}catch(n){v(D(n)),Je(i=>i+1)}finally{B(null)}},Se=async()=>{if(S){B(S.citationKey),v("");try{const t=Me(me,j);if(!t){v(a("citationErrors.invalid"));return}const n=await A(`/api/citations/${encodeURIComponent(S.id)}`,{method:"PATCH",body:JSON.stringify({bibtex:t.bibtex,citationKey:t.citationKey,entryType:t.entryType,title:t.title,authors:t.authors,year:t.year,expectedRevision:S.revision})});E(i=>[n.entry,...i.filter(o=>o.id!==n.entry.id)]),R(i=>{const o=new Map(i);return o.delete(S.citationKey.toLowerCase()),o.set(n.entry.citationKey.toLowerCase(),{id:n.entry.id,citationKey:n.entry.citationKey,revision:n.entry.revision}),o}),P(null),$(a("citationLibrary.updated")),h(1),F(i=>i+1)}catch(t){v(D(t))}finally{B(null)}}},Be=async()=>{if(ie.trim()){B("__new__"),v("");try{const t=Me(ie,j);if(!t){v(a("citationErrors.invalid"));return}const n=await A("/api/citations",{method:"POST",body:JSON.stringify({bibtex:t.bibtex,citationKey:t.citationKey,entryType:t.entryType,title:t.title,authors:t.authors,year:t.year})});E(i=>[n.entry,...i.filter(o=>o.id!==n.entry.id&&o.citationKey.toLowerCase()!==n.entry.citationKey.toLowerCase())]),R(i=>new Map(i).set(n.entry.citationKey.toLowerCase(),{id:n.entry.id,citationKey:n.entry.citationKey,revision:n.entry.revision})),H(!1),ye(""),$(n.updated?a("citationLibrary.updated"):a("citationLibraryActions.added")),f(n.entry),_(n.entry.tags.map(i=>i.id)),h(1),F(i=>i+1)}catch(t){v(D(t))}finally{B(null)}}},We=t=>{Q(i=>[...i.filter(o=>o.id!==t.id),t].sort((o,Y)=>o.name.localeCompare(Y.name)));const n=i=>({...i,tags:i.tags.map(o=>o.id===t.id?t:o)});E(i=>i.map(n)),f(i=>i?n(i):null),P(i=>i?n(i):null)},Ye=t=>{Q(i=>i.filter(o=>o.id!==t));const n=i=>({...i,tags:i.tags.filter(o=>o.id!==t)});E(i=>i.map(n)),f(i=>i?n(i):null),P(i=>i?n(i):null),_(i=>i.filter(o=>o!==t)),g===t&&(C(""),h(1))},Qe=t=>{P(null),H(!1),f(t),_(t.tags.map(n=>n.id))},be=async()=>{if(p){ve(!0),v("");try{const t=await A(`/api/citations/${encodeURIComponent(p.id)}/tags`,{method:"PATCH",body:JSON.stringify({tagIds:te,expectedRevision:p.revision})});E(n=>n.map(i=>i.id===t.entry.id?t.entry:i)),R(n=>new Map(n).set(t.entry.citationKey.toLowerCase(),{id:t.entry.id,citationKey:t.entry.citationKey,revision:t.entry.revision})),f(t.entry),_(t.entry.tags.map(n=>n.id)),$(a("citationLibrary.tagsUpdated")),F(n=>n+1)}catch(t){v(D(t))}finally{ve(!1)}}},Xe=async t=>{ge(t.id),G("");try{await A(`/api/citations/${encodeURIComponent(t.id)}`,{method:"DELETE"}),E(n=>n.filter(i=>i.id!==t.id)),R(n=>{const i=new Map(n);return i.delete(t.citationKey.toLowerCase()),i}),S?.id===t.id&&P(null),p?.id===t.id&&f(null),$(a("citationLibrary.deleted")),h(1),F(n=>n+1),ae(null)}catch(n){G(D(n))}finally{ge(null)}},Ee=e.jsxs("div",{className:"citation-library-dialog",children:[e.jsxs("div",{className:"citation-library-tabs",role:"tablist","aria-label":a("citationLibrary.title"),children:[e.jsxs("button",{type:"button",role:"tab","aria-selected":w==="library",className:w==="library"?"active":"",onClick:()=>K("library"),children:[e.jsx(oe,{size:15}),a("citationLibrary.myLibrary"),e.jsx("span",{children:u.total})]}),U&&e.jsxs("button",{type:"button",role:"tab","aria-selected":w==="current",className:w==="current"?"active":"",onClick:()=>K("current"),children:[e.jsx(le,{size:15}),a("citationLibrary.currentFile"),e.jsx("span",{children:J.length})]})]}),W&&!(b&&(p||S))&&e.jsx("p",{className:"error dialog-error",children:W}),ne&&e.jsxs("p",{className:"citation-library-notice",role:"status",children:[e.jsx(I,{size:14}),ne,e.jsx("button",{type:"button","aria-label":a("common.close"),onClick:()=>$(""),children:e.jsx(Z,{size:13})})]}),w==="library"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"citation-library-search-row",children:[e.jsxs("label",{className:"citation-library-search",children:[e.jsx(st,{size:15}),e.jsx("input",{autoFocus:!0,placeholder:a("citationLibrary.searchPlaceholder"),value:m,onChange:t=>{d(t.target.value),h(1)}}),e.jsx("span",{children:a("citationLibrary.searchHint")})]}),e.jsxs("button",{type:"button",className:"citation-add-entry-button",onClick:()=>{H(!0),P(null),f(null)},children:[e.jsx(le,{size:14}),a("citationLibraryActions.addEntry")]})]}),e.jsx(lt,{tags:O,selectedId:g,onSelect:t=>{C(t),h(1)},onManage:()=>r(!0)}),$e&&e.jsxs("div",{className:"citation-edit-panel",children:[e.jsxs("div",{className:"citation-edit-header",children:[e.jsxs("div",{children:[e.jsx("strong",{children:a("citationLibraryActions.addEntryTitle")}),e.jsx("small",{children:a("citationLibraryActions.addEntryDescription")})]}),e.jsx("button",{type:"button","aria-label":a("common.close"),onClick:()=>H(!1),children:e.jsx(Z,{size:15})})]}),e.jsx("textarea",{autoFocus:!0,value:ie,onChange:t=>ye(t.target.value),placeholder:a("citationLibraryActions.addEntryPlaceholder"),spellCheck:!1,rows:9}),e.jsxs("div",{className:"citation-edit-actions",children:[e.jsx("button",{type:"button",onClick:()=>H(!1),children:a("common.cancel")}),e.jsxs("button",{type:"button",className:"primary",disabled:!ie.trim()||X==="__new__",onClick:()=>{Be()},children:[X==="__new__"?e.jsx(q,{className:"spin",size:14}):e.jsx(I,{size:14}),a("citationLibraryActions.addEntry")]})]})]}),_e?e.jsxs("div",{className:"citation-library-empty",children:[e.jsx(q,{className:"spin",size:22}),e.jsx("span",{children:a("common.loading")})]}):z.length===0?e.jsxs("div",{className:"citation-library-empty",children:[e.jsx(oe,{size:28}),e.jsx("strong",{children:a("citationLibrary.emptyTitle")}),e.jsx("span",{children:a(g?"citationLibrary.noTagMatches":"citationLibrary.emptyDescription")})]}):e.jsx("div",{className:"citation-entry-list",children:z.map(t=>e.jsxs("div",{className:"citation-entry-item",children:[e.jsx(Pe,{entry:t,selected:p?.id===t.id||S?.id===t.id,alreadyInFile:!b&&qe.has(t.citationKey.toLowerCase()),importDisabled:k,deleting:Ce===t.id,onImport:T?async()=>{await T(t)&&y(!1)}:void 0,onEdit:t.ownerId===N?()=>{f(null),H(!1),P(t),ue(t.bibtex)}:void 0,onTags:t.ownerId===N?()=>Qe(t):void 0,onDelete:t.ownerId===N?()=>{ae(t),G("")}:void 0,t:a}),!b&&p?.id===t.id&&e.jsx(je,{entry:p,tags:O,selectedIds:te,saving:de,onClose:()=>f(null),onToggle:n=>_(i=>i.includes(n)?i.filter(o=>o!==n):[...i,n]),onSave:()=>{be()},t:a}),!b&&S?.id===t.id&&e.jsx(Ae,{title:a("citationLibrary.editTitle",{key:S.citationKey}),value:me,saving:X===S.citationKey,onChange:ue,onClose:()=>P(null),onSave:()=>{Se()},t:a})]},t.id))}),u.totalPages>1&&e.jsxs("nav",{className:"citation-library-pagination","aria-label":a("citationLibraryPagination.pageOf",{page:u.page,totalPages:u.totalPages,count:u.total}),children:[e.jsxs("button",{type:"button",disabled:u.page<=1,onClick:()=>h(t=>Math.max(1,t-1)),children:[e.jsx(xe,{size:14}),a("citationLibraryPagination.previous")]}),e.jsx("span",{children:a("citationLibraryPagination.pageOf",{page:u.page,totalPages:u.totalPages,count:u.total})}),e.jsxs("button",{type:"button",disabled:u.page>=u.totalPages,onClick:()=>h(t=>Math.min(u.totalPages,t+1)),children:[a("citationLibraryPagination.next"),e.jsx(tt,{size:14})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"citation-current-heading",children:[e.jsxs("div",{children:[e.jsx("strong",{children:a("citationLibrary.currentFileTitle")}),e.jsx("span",{children:a("citationLibrary.currentFileDescription")})]}),e.jsxs("button",{type:"button",onClick:()=>K("library"),children:[e.jsx(xe,{size:14}),a("citationLibrary.backToLibrary")]})]}),Te&&e.jsxs("p",{className:"warning citation-library-warning",children:[e.jsx(Ke,{size:15}),a("citationLibrary.fileTooLarge",{size:at(j)})]}),we&&e.jsxs("p",{className:"warning citation-library-warning",children:[e.jsx(Ke,{size:15}),a("citationLibrary.fileInvalid")]}),J.length===0?e.jsxs("div",{className:"citation-library-empty",children:[e.jsx(oe,{size:28}),e.jsx("strong",{children:a("citationLibrary.noEntries")}),e.jsx("span",{children:a(Te?"citationLibrary.fileTooLargeHint":we?"citationLibrary.fileInvalidHint":"citationLibrary.noEntriesDescription")})]}):e.jsx("div",{className:"citation-entry-list",children:J.map((t,n)=>e.jsxs("div",{className:"citation-entry-item",children:[e.jsx(Pe,{entry:t,saved:Le.has(t.citationKey.toLowerCase()),saving:X===t.citationKey,saveDisabled:He,onSave:()=>{Ve(t)},t:a}),!b&&p?.citationKey.toLowerCase()===t.citationKey.toLowerCase()&&e.jsx(je,{entry:p,tags:O,selectedIds:te,saving:de,onClose:()=>f(null),onToggle:i=>_(o=>o.includes(i)?o.filter(Y=>Y!==i):[...o,i]),onSave:()=>{be()},t:a})]},`${t.citationKey}-${n}`))})]})]}),ke=e.jsx(Fe,{open:!!he,title:a("citationLibrary.deleteTitle"),description:a("citationLibrary.deleteDescription",{key:he?.citationKey??""}),confirmLabel:a("common.delete"),danger:!0,error:Ie,busy:!!Ce,onCancel:()=>{ae(null),G("")},onConfirm:()=>{const t=he;t&&Xe(t)}}),ze=l&&ee&&e.jsx(dt,{tags:O,onClose:()=>r(!1),onUpdated:We,onDeleted:Ye});return b?e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"citation-library-page",children:[e.jsxs("header",{className:"citation-library-page-header",children:[e.jsxs("div",{children:[e.jsxs("h1",{children:[e.jsx(oe,{"aria-hidden":!0,size:26}),a("citationLibrary.title")]}),e.jsx("p",{children:a("citationLibraryHomeDescription")})]}),L&&e.jsxs("button",{type:"button",onClick:L,children:[e.jsx(xe,{size:15}),a("projects.title")]})]}),Ee]}),p&&e.jsx(re,{open:!0,title:a("citationLibrary.tagsTitle",{key:p.citationKey}),description:a("citationLibrary.tags"),onOpenChange:t=>{t||(f(null),v(""))},children:e.jsxs(e.Fragment,{children:[W&&e.jsx("p",{className:"error dialog-error",children:W}),e.jsx(je,{entry:p,tags:O,selectedIds:te,saving:de,modal:!0,onClose:()=>{f(null),v("")},onToggle:t=>_(n=>n.includes(t)?n.filter(i=>i!==t):[...n,t]),onSave:()=>{be()},t:a})]})}),S&&e.jsx(re,{open:!0,extraWide:!0,title:a("citationLibrary.editTitle",{key:S.citationKey}),description:a("citationLibrary.title"),onOpenChange:t=>{t||(P(null),v(""))},children:e.jsxs(e.Fragment,{children:[W&&e.jsx("p",{className:"error dialog-error",children:W}),e.jsx(Ae,{title:a("citationLibrary.editTitle",{key:S.citationKey}),value:me,saving:X===S.citationKey,modal:!0,onChange:ue,onClose:()=>{P(null),v("")},onSave:()=>{Se()},t:a})]})}),ke,ze]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{open:l,extraWide:!0,className:"citation-library-modal",title:a("citationLibrary.title"),description:a(U?"citationLibrary.description":"citationLibraryHomeDescription",{file:c}),onOpenChange:y,footer:e.jsx("button",{onClick:()=>y(!1),children:a("common.close")}),children:Ee}),ke,ze]})}function Pe({entry:l,selected:y,alreadyInFile:b,saved:L,saving:c,saveDisabled:x,importDisabled:k,deleting:N,onSave:j,onImport:T,onEdit:a,onTags:w,onDelete:K,t:m}){const d="id"in l,g=d?l:null,C=nt(l);return e.jsxs("article",{className:`citation-entry-card${y?" selected":""}${b?" already-in-file":""}`,title:b?m("citationErrors.alreadyInFile",{key:l.citationKey}):void 0,children:[e.jsxs("div",{className:"citation-entry-main",children:[e.jsxs("div",{className:"citation-entry-heading",children:[e.jsx("code",{children:l.citationKey}),e.jsxs("span",{children:["@",l.entryType]}),C&&e.jsx("span",{className:"citation-entry-venue",title:C,children:C}),L&&e.jsxs("em",{children:[e.jsx(I,{size:11}),m("citationLibrary.savedLabel")]})]}),e.jsx("strong",{children:l.title||m("citationLibrary.untitled")}),e.jsxs("p",{children:[l.authors||m("citationLibrary.authorUnknown"),l.year&&e.jsxs("span",{children:[" · ",l.year]})]}),g&&g.tags.length>0&&e.jsx("div",{className:"citation-entry-tags",children:g.tags.map(z=>e.jsxs("span",{className:`citation-tag-pill tag-${z.color}`,children:[e.jsx("span",{className:"citation-tag-dot"}),z.name]},z.id))})]}),e.jsxs("div",{className:"citation-entry-actions",children:[j&&e.jsxs("button",{type:"button",className:L?"saved":"primary",disabled:c||x,onClick:j,children:[c||x?e.jsx(q,{className:"spin",size:13}):L?e.jsx(I,{size:13}):e.jsx(le,{size:13}),m(c?"citationLibrary.saving":L?"citationLibrary.update":"citationLibrary.save")]}),T&&e.jsxs("button",{type:"button",disabled:k||b,title:b?m("citationErrors.alreadyInFile",{key:l.citationKey}):m(k?"citationLibrary.importRequiresWrite":"citationLibrary.importToFile"),onClick:()=>{T()},children:[e.jsx(ot,{size:13}),m("citationLibrary.import")]}),g&&w&&e.jsxs("button",{type:"button",onClick:w,children:[e.jsx(Re,{size:13}),m("citationLibrary.tags")]}),d&&a&&e.jsxs("button",{type:"button",onClick:a,children:[e.jsx(rt,{size:13}),m("common.edit")]}),d&&K&&e.jsxs("button",{type:"button",className:"danger-text",disabled:N,onClick:K,children:[N?e.jsx(q,{className:"spin",size:13}):e.jsx(Oe,{size:13}),m("common.delete")]})]})]})}function je({entry:l,tags:y,selectedIds:b,saving:L,modal:c=!1,onClose:x,onToggle:k,onSave:N,t:j}){const T=e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"citation-tag-choice-list",children:y.length===0?e.jsx("span",{className:"muted",children:j("citationLibrary.noTagsToAssign")}):y.map(a=>e.jsxs("label",{children:[e.jsx("input",{type:"checkbox",checked:b.includes(a.id),onChange:()=>k(a.id)}),e.jsx("span",{className:`citation-tag-dot tag-${a.color}`}),a.name]},a.id))}),e.jsxs("div",{className:"citation-edit-actions",children:[e.jsx("button",{type:"button",onClick:x,children:j("common.cancel")}),e.jsxs("button",{type:"button",className:"primary",disabled:L||y.length===0,onClick:N,children:[L?e.jsx(q,{className:"spin",size:14}):e.jsx(I,{size:14}),j("citationLibrary.saveTags")]})]})]});return c?e.jsx("div",{className:"citation-modal-form",children:T}):e.jsxs("div",{className:"citation-tag-editor",children:[e.jsxs("div",{className:"citation-edit-header",children:[e.jsx("strong",{children:j("citationLibrary.tagsTitle",{key:l.citationKey})}),e.jsx("button",{type:"button","aria-label":j("common.close"),onClick:x,children:e.jsx(Z,{size:15})})]}),T]})}function Ae({title:l,value:y,saving:b,modal:L=!1,onChange:c,onClose:x,onSave:k,t:N}){const j=e.jsxs(e.Fragment,{children:[e.jsx("textarea",{autoFocus:!L,value:y,onChange:T=>c(T.target.value),spellCheck:!1,rows:12}),e.jsxs("div",{className:"citation-edit-actions",children:[e.jsx("button",{type:"button",onClick:x,children:N("common.cancel")}),e.jsxs("button",{type:"button",className:"primary",disabled:!y.trim()||b,onClick:k,children:[b?e.jsx(q,{className:"spin",size:14}):e.jsx(I,{size:14}),N("common.save")]})]})]});return L?e.jsx("div",{className:"citation-modal-form citation-edit-panel",children:j}):e.jsxs("div",{className:"citation-edit-panel",children:[e.jsxs("div",{className:"citation-edit-header",children:[e.jsx("strong",{children:l}),e.jsx("button",{type:"button","aria-label":N("common.close"),onClick:x,children:e.jsx(Z,{size:15})})]}),j]})}export{Nt as CitationLibraryDialog};
|