@evandu/super-pi 0.1.233 → 0.1.235

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.
Files changed (44) hide show
  1. package/dist/client/.super-pi-client-sources.json +9 -8
  2. package/dist/client/assets/CodeMirrorEditor-DBSi0y5V.js +2 -0
  3. package/dist/client/assets/{dist-BboHMFNI.js → dist-0NfztBk-.js} +1 -1
  4. package/dist/client/assets/{dist-Qu_JVRdm.js → dist-AFzBxMiM.js} +1 -1
  5. package/dist/client/assets/{dist-8ntSzuyc.js → dist-AuOQsEQB.js} +1 -1
  6. package/dist/client/assets/{dist-DILlxwEE.js → dist-BFIiLPLD.js} +1 -1
  7. package/dist/client/assets/{dist-CBkmTbun.js → dist-BIJ9NGer.js} +1 -1
  8. package/dist/client/assets/{dist-CADYSFwN.js → dist-BYCGZ2pA.js} +1 -1
  9. package/dist/client/assets/{dist-BH-kaMWJ.js → dist-BzVCaLha.js} +1 -1
  10. package/dist/client/assets/{dist-CNOENBsx.js → dist-BzkoHuGc.js} +1 -1
  11. package/dist/client/assets/{dist-DTpnIL-S.js → dist-CCS69OpS.js} +1 -1
  12. package/dist/client/assets/{dist-DfIfNI5O.js → dist-CKnqkrKG.js} +1 -1
  13. package/dist/client/assets/{dist-mIg0RKXQ.js → dist-CMmqt5Ls.js} +1 -1
  14. package/dist/client/assets/{dist-BX6V-2ch.js → dist-CN_srcoq.js} +1 -1
  15. package/dist/client/assets/{dist-RRg5quSb.js → dist-ClI_GbBL.js} +1 -1
  16. package/dist/client/assets/{dist-CXQ72jK0.js → dist-Ctqsash1.js} +1 -1
  17. package/dist/client/assets/{dist-DsaVwWTi.js → dist-CvBx0FR6.js} +1 -1
  18. package/dist/client/assets/{dist-n9h1Tr_V.js → dist-DOhnZjPv.js} +1 -1
  19. package/dist/client/assets/{dist-Dv5RvBil.js → dist-DREIvqD0.js} +1 -1
  20. package/dist/client/assets/{dist-BTFTY60x.js → dist-DTKai_jj.js} +1 -1
  21. package/dist/client/assets/{dist-BdS5YuVr.js → dist-DnxKnc-T.js} +1 -1
  22. package/dist/client/assets/{dist-BxJsFYNz.js → dist-o5ICDbri.js} +1 -1
  23. package/dist/client/assets/{dist-DlyF9NDv.js → dist-od0aIXVf.js} +1 -1
  24. package/dist/client/assets/{dist-D6L_I39S.js → dist-yUsZ_PQw.js} +1 -1
  25. package/dist/client/assets/{index-ULLf_i7J.css → index-D-s-Xog1.css} +1 -1
  26. package/dist/client/assets/{index-09FegZJi.js → index-GRdiKmhS.js} +51 -50
  27. package/dist/client/index.html +2 -2
  28. package/dist/server/explicit-file-open.d.ts +34 -0
  29. package/dist/server/explicit-file-open.js +105 -0
  30. package/dist/server/file-name-index.d.ts +5 -5
  31. package/dist/server/file-name-index.js +22 -19
  32. package/dist/server/files.d.ts +5 -0
  33. package/dist/server/files.js +12 -6
  34. package/dist/server/git.d.ts +12 -2
  35. package/dist/server/git.js +162 -6
  36. package/dist/server/http-server.js +92 -8
  37. package/dist/server/workspace-file-response.d.ts +6 -2
  38. package/dist/server/workspace-file-response.js +6 -6
  39. package/dist/shared/git-commit.d.ts +11 -0
  40. package/dist/shared/git-commit.js +1 -0
  41. package/dist/shared/git-graph.d.ts +38 -0
  42. package/dist/shared/git-graph.js +30 -0
  43. package/package.json +1 -1
  44. package/dist/client/assets/CodeMirrorEditor-D30doKD5.js +0 -2
@@ -12,7 +12,7 @@ import { describe as describeFilesError, FilesError, fileMeta, listDirectory, MA
12
12
  import { findUploadFile, MAX_UPLOAD_BODY_BYTES, saveUpload } from "./upload.js";
13
13
  import { describeThrown } from "./failure-text.js";
14
14
  import { checkDiskVersion } from "./version.js";
15
- import { gitBlame, gitBranches, gitDiff, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
15
+ import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
16
16
  import { computeFileDiff } from "./file-diff.js";
17
17
  import { verifyCapability } from "./capability.js";
18
18
  import { conversationWorkspace } from "./model-filter.js";
@@ -30,6 +30,7 @@ import { ensureNameIndex, recordWorkspacePath } from "./file-name-index.js";
30
30
  import { resolveFileCwd, sessionScopeKey, workspacePathFromSession } from "./session-cwd.js";
31
31
  import { explorerInternalPath, explorerPath, inspectWorkspaceUpload, listWorkspaceTrash, MAX_WORKSPACE_UPLOAD_BYTES, mutateWorkspaceTree, serializeWorkspaceWrite, uploadWorkspaceFile } from "./workspace-file-operations.js";
32
32
  import { readWorkspaceDocumentPreview, respondWithWorkspaceFile } from "./workspace-file-response.js";
33
+ import { createExplicitFileOpen } from "./explicit-file-open.js";
33
34
  import { updateExplorerIndexes } from "./workspace-file-indexes.js";
34
35
  import { readMessageMedia } from "./message-media.js";
35
36
  import { MESSAGE_FRAME_CSP, MESSAGE_HTML_CSP } from "../shared/message-media.js";
@@ -355,6 +356,7 @@ export function createHttpServer(options) {
355
356
  const { uploadsDir, clientDir, rootDir } = paths;
356
357
  const gitDrafts = new Set();
357
358
  const manageWorktree = createWorktreeService(context);
359
+ const explicitFileOpen = createExplicitFileOpen();
358
360
  return createServer(async (request, response) => {
359
361
  // Every HTTP request gets one stable id. It is returned to the browser and
360
362
  // included in the server log, so a report containing a status code or a
@@ -1276,6 +1278,7 @@ export function createHttpServer(options) {
1276
1278
  }
1277
1279
  const op = url.searchParams.get("op") ?? "status";
1278
1280
  const requestedCwd = url.searchParams.get("cwd");
1281
+ const fullDiff = url.searchParams.get("context") === "full";
1279
1282
  if (op.startsWith("worktree") && requestedCwd !== null)
1280
1283
  await resolveFileCwd(workspace.path, requestedCwd);
1281
1284
  if (op === "worktree-manage") {
@@ -1328,15 +1331,32 @@ export function createHttpServer(options) {
1328
1331
  }
1329
1332
  const path = await workspacePathFromSession(checkout.path, checkout.path, file);
1330
1333
  json(200, url.searchParams.get("comparison") === "committed"
1331
- ? await gitWorktreeCommittedDiff(checkout.path, checkout.base, path)
1332
- : await gitDiff(checkout.path, path, url.searchParams.get("staged") === "1"));
1334
+ ? await gitWorktreeCommittedDiff(checkout.path, checkout.base, path, fullDiff)
1335
+ : await gitDiff(checkout.path, path, url.searchParams.get("staged") === "1", fullDiff));
1333
1336
  return;
1334
1337
  }
1335
1338
  const sessionRoot = await resolveFileCwd(workspace.path, requestedCwd);
1336
1339
  const cwd = relative(resolve(workspace.path), sessionRoot).replaceAll("\\", "/");
1340
+ if (op === "commit-detail" || op === "commit-diff") {
1341
+ if (request.method !== "GET") {
1342
+ json(405, { error: "查看提交需要 GET 请求", code: "method" });
1343
+ return;
1344
+ }
1345
+ const worktreeId = url.searchParams.get("worktreeId");
1346
+ if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
1347
+ json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
1348
+ return;
1349
+ }
1350
+ const root = worktreeId ? (await resolveGitWorktree(workspace.path, worktreeId)).path : workspace.path;
1351
+ const directory = worktreeId ? "" : cwd;
1352
+ const hash = url.searchParams.get("hash") ?? "";
1353
+ json(200, op === "commit-detail" ? await gitCommit(root, directory, hash)
1354
+ : await gitCommitDiff(root, directory, hash, url.searchParams.get("path") ?? "", fullDiff));
1355
+ return;
1356
+ }
1337
1357
  // Blame is a read with a GET shape: every other verb is refused HERE, before the POST branch
1338
1358
  // could ever route the op into gitMutate and before any body is read.
1339
- if (op === "blame" && request.method !== "GET") {
1359
+ if ((op === "blame" || op === "graph") && request.method !== "GET") {
1340
1360
  json(405, { error: "Git 请求方法不支持", code: "method" });
1341
1361
  return;
1342
1362
  }
@@ -1412,6 +1432,9 @@ export function createHttpServer(options) {
1412
1432
  }
1413
1433
  if (op === "status")
1414
1434
  json(200, await gitStatus(workspace.path, cwd));
1435
+ else if (op === "graph") {
1436
+ json(200, await gitGraph(workspace.path, Number(url.searchParams.get("limit") ?? 50), Number(url.searchParams.get("offset") ?? 0), url.searchParams.get("snapshot") ?? "", url.searchParams.get("after") ?? ""));
1437
+ }
1415
1438
  else if (op === "log" || op === "branches" || op === "stash") {
1416
1439
  const query = url.searchParams.get("q") ?? "";
1417
1440
  const offset = Number(url.searchParams.get("offset") ?? 0);
@@ -1432,7 +1455,7 @@ export function createHttpServer(options) {
1432
1455
  json(400, { error: "diff 需要 path", code: "bad_path" });
1433
1456
  return;
1434
1457
  }
1435
- json(200, await gitDiff(workspace.path, await workspacePathFromSession(workspace.path, sessionRoot, path), url.searchParams.get("staged") === "1"));
1458
+ json(200, await gitDiff(workspace.path, await workspacePathFromSession(workspace.path, sessionRoot, path), url.searchParams.get("staged") === "1", fullDiff));
1436
1459
  }
1437
1460
  else if (op === "blame") {
1438
1461
  const path = url.searchParams.get("path");
@@ -1465,6 +1488,10 @@ export function createHttpServer(options) {
1465
1488
  }
1466
1489
  else if (code === "not_found")
1467
1490
  json(404, { error: message, code: "not_found" });
1491
+ else if (code === "commit_diff_too_large" || code === "diff_context_too_large")
1492
+ json(413, { error: message, code });
1493
+ else if (code === "graph_changed")
1494
+ json(409, { error: message, code });
1468
1495
  else if (code === "bad_range" || code === "bad_revision")
1469
1496
  json(400, { error: message, code });
1470
1497
  else if (["outside_scope", "empty_index", "empty_worktree", "bad_message", "bad_op"].includes(String(code)))
@@ -2598,6 +2625,61 @@ export function createHttpServer(options) {
2598
2625
  }
2599
2626
  return;
2600
2627
  }
2628
+ const openFileRoute = /^\/api\/files\/(open|open-asset|open-document)$/.exec(url.pathname)?.[1];
2629
+ if (openFileRoute) {
2630
+ try {
2631
+ const origin = request.headers.origin;
2632
+ const fetchSite = request.headers["sec-fetch-site"];
2633
+ if (!isLocalOrPrivateAddress(remote) || (fetchSite && fetchSite !== "same-origin" && fetchSite !== "none")
2634
+ || (origin && (fetchSite ? fetchSite !== "same-origin" : origin !== url.origin))) {
2635
+ throw new FilesError(403, "打开外部文件需要来自同源的本机或局域网请求。", "denied");
2636
+ }
2637
+ const workspaceId = url.searchParams.get("workspaceId")?.trim();
2638
+ const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
2639
+ if (!workspaceId || !workspace || workspace.closedAt)
2640
+ throw new FilesError(404, "请先选择有效工作区。", "no_workspace");
2641
+ const root = await resolveFileCwd(workspace.path, url.searchParams.get("cwd"));
2642
+ if (openFileRoute === "open" && request.method === "POST") {
2643
+ const body = await readRequestText(request, 16 * 1024);
2644
+ if (body.tooLarge)
2645
+ throw new FilesError(413, "文件打开请求过大。", "too_large");
2646
+ let path;
2647
+ try {
2648
+ path = JSON.parse(body.text)?.path;
2649
+ }
2650
+ catch {
2651
+ throw new FilesError(400, "需要有效的文件打开请求。", "bad_request");
2652
+ }
2653
+ if (typeof path !== "string" || !path.trim())
2654
+ throw new FilesError(400, "请提供文件路径。", "bad_path");
2655
+ json(200, await explicitFileOpen.open(workspaceId, workspace.path, root, path));
2656
+ return;
2657
+ }
2658
+ const asset = openFileRoute === "open-asset" && (request.method === "GET" || request.method === "HEAD");
2659
+ const document = openFileRoute === "open-document" && request.method === "GET";
2660
+ if (!asset && !document)
2661
+ throw new FilesError(405, "不支持此文件操作。", "method");
2662
+ const path = await explicitFileOpen.target(workspaceId, root, url.searchParams.get("ticket") ?? "");
2663
+ if (asset)
2664
+ await respondWithWorkspaceFile(request, response, path, url.searchParams.has("download"), { noFollow: true });
2665
+ else
2666
+ json(200, await readWorkspaceDocumentPreview(path, { noFollow: true }));
2667
+ }
2668
+ catch (error) {
2669
+ if (response.headersSent) {
2670
+ response.destroy();
2671
+ return;
2672
+ }
2673
+ const code = error?.code;
2674
+ if (code === "ENOENT" || code === "ENOTDIR") {
2675
+ json(404, { error: "文件不存在或已被移动。", code: "not_found" });
2676
+ return;
2677
+ }
2678
+ const described = describeFilesError(error);
2679
+ json(described.status, described.body);
2680
+ }
2681
+ return;
2682
+ }
2601
2683
  const explorerRoute = /^\/api\/files\/(tree|upload|upload-check|asset|document)$/.exec(url.pathname)?.[1];
2602
2684
  if (explorerRoute) {
2603
2685
  try {
@@ -2898,13 +2980,15 @@ export function createHttpServer(options) {
2898
2980
  // failure this work exists to remove. Past the deadline the answer is still returned, with
2899
2981
  // `indexed: false` so the UI can say the index is still building rather than pretending
2900
2982
  // the tree is empty.
2901
- const result = index.search(query);
2983
+ const linksOnly = url.searchParams.get("links") === "1";
2984
+ const result = index.search(query, linksOnly);
2985
+ const hits = linksOnly ? result.hits.slice(0, 20) : result.hits;
2902
2986
  json(200, {
2903
2987
  mode: "search",
2904
2988
  query: query.trim(),
2905
- hits: result.hits.map((hit) => ({ path: hit.path, name: hit.name, directory: hit.directory })),
2989
+ hits: hits.map(({ path, name, directory, openLink }) => ({ path, name, directory, ...(openLink ? { openLink } : {}) })),
2906
2990
  total: result.total,
2907
- truncated: false,
2991
+ truncated: hits.length < result.total,
2908
2992
  skipped: [],
2909
2993
  indexed: result.indexed,
2910
2994
  progress: result.progress,
@@ -1,3 +1,7 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
- export declare function readWorkspaceDocumentPreview(path: string): Promise<import("./documents.js").ExtractResult>;
3
- export declare function respondWithWorkspaceFile(request: IncomingMessage, response: ServerResponse, path: string, download: boolean): Promise<void>;
2
+ type OpenOptions = {
3
+ noFollow?: boolean;
4
+ };
5
+ export declare function readWorkspaceDocumentPreview(path: string, options?: OpenOptions): Promise<import("./documents.js").ExtractResult>;
6
+ export declare function respondWithWorkspaceFile(request: IncomingMessage, response: ServerResponse, path: string, download: boolean, options?: OpenOptions): Promise<void>;
7
+ export {};
@@ -6,17 +6,17 @@ import { workspaceFileMime } from "../shared/workspace-file-preview.js";
6
6
  import { FilesError } from "./files.js";
7
7
  import { extractTextFromBytes } from "./documents.js";
8
8
  const MAX_DOCUMENT_PREVIEW_BYTES = 16 * 1024 * 1024;
9
- function openWorkspaceAsset(path) {
10
- return open(path, constants.O_RDONLY | constants.O_NONBLOCK).catch((error) => {
9
+ function openWorkspaceAsset(path, { noFollow } = {}) {
10
+ return open(path, constants.O_RDONLY | constants.O_NONBLOCK | (noFollow ? constants.O_NOFOLLOW ?? 0 : 0)).catch((error) => {
11
11
  if (error.code === "ENOENT" || error.code === "ENOTDIR")
12
12
  throw new FilesError(404, "文件已不存在。", "missing");
13
13
  throw error;
14
14
  });
15
15
  }
16
- export async function readWorkspaceDocumentPreview(path) {
16
+ export async function readWorkspaceDocumentPreview(path, options) {
17
17
  if (!/\.docx$/i.test(path))
18
18
  throw new FilesError(415, "该文件没有文字预览。", "unsupported_entry");
19
- const handle = await openWorkspaceAsset(path);
19
+ const handle = await openWorkspaceAsset(path, options);
20
20
  try {
21
21
  const info = await handle.stat();
22
22
  if (!info.isFile())
@@ -41,11 +41,11 @@ function parseRange(header, size) {
41
41
  if (Number.isSafeInteger(start) && Number.isSafeInteger(end) && start <= end)
42
42
  return { start, end };
43
43
  }
44
- export async function respondWithWorkspaceFile(request, response, path, download) {
44
+ export async function respondWithWorkspaceFile(request, response, path, download, options) {
45
45
  const mime = workspaceFileMime(path);
46
46
  if (!download && !mime)
47
47
  throw new FilesError(415, "该文件可下载。", "unsupported_entry");
48
- const handle = await openWorkspaceAsset(path);
48
+ const handle = await openWorkspaceAsset(path, options);
49
49
  try {
50
50
  const info = await handle.stat();
51
51
  if (!info.isFile())
@@ -0,0 +1,11 @@
1
+ export type GitCommitFile = {
2
+ path: string;
3
+ previousPath?: string;
4
+ status: string;
5
+ };
6
+ export type GitCommitDetail = {
7
+ hash: string;
8
+ parents: string[];
9
+ message: string;
10
+ files: GitCommitFile[];
11
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ export type GitGraphRef = {
2
+ kind: "head" | "worktree" | "branch" | "remote" | "tag" | "stash";
3
+ name: string;
4
+ checkoutId?: string;
5
+ };
6
+ export type GitGraphCommit = {
7
+ hash: string;
8
+ short: string;
9
+ parents: string[];
10
+ subject: string;
11
+ author: string;
12
+ date: string;
13
+ refs: GitGraphRef[];
14
+ };
15
+ export type GitGraphPage = {
16
+ commits: GitGraphCommit[];
17
+ snapshot: string;
18
+ hasMore: boolean;
19
+ };
20
+ type Lane = {
21
+ index: number;
22
+ color: number;
23
+ };
24
+ type ParentLine = {
25
+ hash: string;
26
+ lane: Lane;
27
+ };
28
+ export type GitGraphRow = {
29
+ node: Lane;
30
+ incoming: boolean;
31
+ through: Lane[];
32
+ parents: ParentLine[];
33
+ };
34
+ export declare function layoutGitGraph(commits: readonly Pick<GitGraphCommit, "hash" | "parents">[]): {
35
+ columns: number;
36
+ rows: GitGraphRow[];
37
+ };
38
+ export {};
@@ -0,0 +1,30 @@
1
+ export function layoutGitGraph(commits) {
2
+ const pending = new Map();
3
+ const occupied = [];
4
+ let nextColor = 0;
5
+ let columns = 1;
6
+ const reserve = (color, preferred) => {
7
+ const free = preferred ?? occupied.indexOf(false);
8
+ const index = free < 0 ? occupied.length : free;
9
+ occupied[index] = true;
10
+ columns = Math.max(columns, index + 1);
11
+ return { index, color };
12
+ };
13
+ const rows = commits.map(({ hash, parents }) => {
14
+ const previous = pending.get(hash);
15
+ const node = previous ?? reserve(nextColor++);
16
+ pending.delete(hash);
17
+ occupied[node.index] = false;
18
+ const through = [...pending.values()];
19
+ const edges = [...new Set(parents)].map((parent, order) => {
20
+ let lane = pending.get(parent);
21
+ if (!lane) {
22
+ lane = order === 0 ? reserve(node.color, node.index) : reserve(nextColor++);
23
+ pending.set(parent, lane);
24
+ }
25
+ return { hash: parent, lane };
26
+ });
27
+ return { node, incoming: previous !== undefined, through, parents: edges };
28
+ });
29
+ return { columns, rows };
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.233",
3
+ "version": "0.1.235",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-DfIfNI5O.js","assets/dist-DTpnIL-S.js","assets/index-09FegZJi.js","assets/index-ULLf_i7J.css","assets/dist-DsaVwWTi.js","assets/dist-CADYSFwN.js","assets/dist-mIg0RKXQ.js","assets/dist-RRg5quSb.js","assets/dist-D6L_I39S.js","assets/dist-BboHMFNI.js","assets/dist-CXQ72jK0.js","assets/dist-Qu_JVRdm.js","assets/dist-DlyF9NDv.js","assets/dist-CBkmTbun.js","assets/dist-BTFTY60x.js","assets/dist-DILlxwEE.js","assets/dist-8ntSzuyc.js","assets/dist-Dv5RvBil.js","assets/dist-BX6V-2ch.js","assets/dist-n9h1Tr_V.js","assets/dist-BH-kaMWJ.js","assets/dist-CNOENBsx.js","assets/dist-BxJsFYNz.js","assets/dist-BdS5YuVr.js"])))=>i.map(i=>d[i]);
2
- import{a as e,i as t,n,r,s as i,t as a}from"./index-09FegZJi.js";var o=i(e(),1);async function s(e,t){let[{StreamLanguage:n},i]=await Promise.all([r(()=>import(`./dist-DfIfNI5O.js`),__vite__mapDeps([0,1,2,3,4,5])),e()]),a=i[t]??i.default??i;return n.define(a)}var c={cpp:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),cc:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),cxx:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),hpp:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),hh:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),hxx:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),c:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),h:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),cu:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),cuh:()=>r(()=>import(`./dist-mIg0RKXQ.js`).then(e=>e.cpp()),__vite__mapDeps([6,5,2,3,0,1,4,7])),js:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),jsx:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),mjs:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),cjs:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),ts:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),tsx:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0,jsx:!0})),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),mts:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),cts:()=>r(()=>import(`./dist-D6L_I39S.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([8,2,3,1,4,5,0,7,9])),py:()=>r(()=>import(`./dist-CXQ72jK0.js`).then(e=>e.python()),__vite__mapDeps([10,5,2,3,0,1,4,7,9])),pyi:()=>r(()=>import(`./dist-CXQ72jK0.js`).then(e=>e.python()),__vite__mapDeps([10,5,2,3,0,1,4,7,9])),java:()=>r(()=>import(`./dist-Qu_JVRdm.js`).then(e=>e.java()),__vite__mapDeps([11,5,2,3,0,1,4,7])),php:()=>r(()=>import(`./dist-DlyF9NDv.js`).then(e=>e.php()),__vite__mapDeps([12,5,2,3,0,1,4,7,13,14,8,9])),sql:()=>r(()=>import(`./dist-DILlxwEE.js`).then(e=>e.sql()),__vite__mapDeps([15,5,2,3,0,1,4,7,9])),yaml:()=>r(()=>import(`./dist-8ntSzuyc.js`).then(e=>e.yaml()),__vite__mapDeps([16,5,2,3,0,1,4,7])),yml:()=>r(()=>import(`./dist-8ntSzuyc.js`).then(e=>e.yaml()),__vite__mapDeps([16,5,2,3,0,1,4,7])),xml:()=>r(()=>import(`./dist-Dv5RvBil.js`).then(e=>e.xml()),__vite__mapDeps([17,1,2,3,4,5,0,7])),json:()=>r(()=>import(`./dist-BX6V-2ch.js`).then(e=>e.json()),__vite__mapDeps([18,5,2,3,0,1,4,7])),jsonc:()=>r(()=>import(`./dist-BX6V-2ch.js`).then(e=>e.json()),__vite__mapDeps([18,5,2,3,0,1,4,7])),json5:()=>r(()=>import(`./dist-BX6V-2ch.js`).then(e=>e.json()),__vite__mapDeps([18,5,2,3,0,1,4,7])),html:()=>r(()=>import(`./dist-CBkmTbun.js`).then(e=>e.html()),__vite__mapDeps([13,1,2,3,4,5,0,7,14,8,9])),htm:()=>r(()=>import(`./dist-CBkmTbun.js`).then(e=>e.html()),__vite__mapDeps([13,1,2,3,4,5,0,7,14,8,9])),vue:()=>r(()=>import(`./dist-CBkmTbun.js`).then(e=>e.html()),__vite__mapDeps([13,1,2,3,4,5,0,7,14,8,9])),svelte:()=>r(()=>import(`./dist-CBkmTbun.js`).then(e=>e.html()),__vite__mapDeps([13,1,2,3,4,5,0,7,14,8,9])),css:()=>r(()=>import(`./dist-BTFTY60x.js`).then(e=>e.r).then(e=>e.css()),__vite__mapDeps([14,2,3,5,0,1,4,7])),md:()=>r(()=>import(`./dist-n9h1Tr_V.js`).then(e=>e.markdown()),__vite__mapDeps([19,1,2,3,4,5,0,9,13,7,14,8])),markdown:()=>r(()=>import(`./dist-n9h1Tr_V.js`).then(e=>e.markdown()),__vite__mapDeps([19,1,2,3,4,5,0,9,13,7,14,8])),mdx:()=>r(()=>import(`./dist-n9h1Tr_V.js`).then(e=>e.markdown()),__vite__mapDeps([19,1,2,3,4,5,0,9,13,7,14,8])),rs:()=>r(()=>import(`./dist-BH-kaMWJ.js`).then(e=>e.rust()),__vite__mapDeps([20,5,2,3,0,1,4,7])),go:()=>r(()=>import(`./dist-CNOENBsx.js`).then(e=>e.go()),__vite__mapDeps([21,5,2,3,0,1,4,7,9])),sh:()=>s(()=>r(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),bash:()=>s(()=>r(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),zsh:()=>s(()=>r(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),fish:()=>s(()=>r(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),ps1:()=>s(()=>r(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),psm1:()=>s(()=>r(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),rb:()=>s(()=>r(()=>import(`./ruby-ChfNwlCY.js`),[]),`ruby`),swift:()=>s(()=>r(()=>import(`./swift-DKB6_1j6.js`),[]),`swift`),toml:()=>s(()=>r(()=>import(`./toml-BPTmHmyx.js`),[]),`toml`),ini:()=>s(()=>r(()=>import(`./properties-C357ku5U.js`),[]),`properties`),cfg:()=>s(()=>r(()=>import(`./properties-C357ku5U.js`),[]),`properties`),conf:()=>s(()=>r(()=>import(`./properties-C357ku5U.js`),[]),`properties`),properties:()=>s(()=>r(()=>import(`./properties-C357ku5U.js`),[]),`properties`),dockerfile:()=>s(()=>r(()=>import(`./dockerfile-BDePf5PZ.js`),[]),`dockerfile`),diff:()=>s(()=>r(()=>import(`./diff-ChtP43wD.js`),[]),`diff`),patch:()=>s(()=>r(()=>import(`./diff-ChtP43wD.js`),[]),`diff`)},l={cpp:`C++`,cc:`C++`,cxx:`C++`,hpp:`C++`,hh:`C++`,hxx:`C++`,cu:`CUDA C++`,cuh:`CUDA C++`,c:`C`,h:`C/C++ Header`,js:`JavaScript`,jsx:`JSX`,mjs:`JavaScript`,cjs:`JavaScript`,ts:`TypeScript`,tsx:`TSX`,mts:`TypeScript`,cts:`TypeScript`,py:`Python`,pyi:`Python Stub`,java:`Java`,php:`PHP`,sql:`SQL`,yaml:`YAML`,yml:`YAML`,xml:`XML`,json:`JSON`,jsonc:`JSON with Comments`,json5:`JSON5`,css:`CSS`,md:`Markdown`,markdown:`Markdown`,mdx:`MDX`,rs:`Rust`,go:`Go`,html:`HTML`,htm:`HTML`,vue:`Vue`,svelte:`Svelte`,sh:`Shell`,bash:`Bash`,zsh:`Zsh`,fish:`Fish`,ps1:`PowerShell`,psm1:`PowerShell`,rb:`Ruby`,swift:`Swift`,toml:`TOML`,ini:`INI`,cfg:`Config`,conf:`Config`,properties:`Properties`,dockerfile:`Dockerfile`,diff:`Diff`,patch:`Patch`};function u(e){return c[e.toLowerCase()]}function d(e){return l[e.toLowerCase()]}var f=t(),p=262144,m=131072;function h(e){return e.split(`.`).pop()?.toLowerCase()??``}function g(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function _(e,t){return e.HighlightStyle.define([{tag:t.tags.keyword,color:g(`--cm-keyword`)},{tag:t.tags.string,color:g(`--cm-string`)},{tag:t.tags.number,color:g(`--cm-number`)},{tag:t.tags.comment,color:g(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:g(`--cm-function`)},{tag:t.tags.typeName,color:g(`--cm-type`)},{tag:t.tags.className,color:g(`--cm-type`)},{tag:t.tags.propertyName,color:g(`--cm-property`)},{tag:t.tags.operator,color:g(`--cm-operator`)},{tag:t.tags.variableName,color:g(`--cm-variable`)}])}function v({path:e,value:t,onChange:i,jumpToLine:s,onSave:c,workspaceId:l,blame:g,onPosition:v}){let y=(0,o.useRef)(null),b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(null),w=(0,o.useRef)(null),T=(0,o.useRef)(null),E=(0,o.useRef)(null),D=(0,o.useRef)(i),O=(0,o.useRef)(c);D.current=i,O.current=c;let[k,A]=(0,o.useState)(!1),[j,M]=(0,o.useState)(!1),[N,P]=(0,o.useState)(`0,0`),[F,I]=(0,o.useState)(0);(0,o.useEffect)(()=>{let i=!1,a,o,s,c,l;return(async()=>{try{let d=h(e),f=u(d),[m,g,v,k,j,N,F,L]=await Promise.all([r(()=>import(`./dist-DTpnIL-S.js`).then(e=>e.x),__vite__mapDeps([1,2,3])),r(()=>import(`./dist-DsaVwWTi.js`).then(e=>e.s),__vite__mapDeps([4,2,3,1])),r(()=>import(`./dist-BxJsFYNz.js`),__vite__mapDeps([22,1,2,3,4,5,0])),r(()=>import(`./dist-BdS5YuVr.js`),__vite__mapDeps([23,1,2,3,4])),r(()=>import(`./dist-DfIfNI5O.js`),__vite__mapDeps([0,1,2,3,4,5])),r(()=>import(`./dist-CADYSFwN.js`).then(e=>e.n),__vite__mapDeps([5,2,3])),f?f().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${d}:`,e),null)):Promise.resolve(null),n().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(i||!y.current)return;c=j,l=N,S.current=m.Annotation.define(),C.current=m.Transaction.addToHistory;let R=t.length<=p&&F!==null;o=new m.Compartment;let z=[g.lineNumbers(),g.highlightActiveLine(),g.drawSelection(),v.history(),g.keymap.of([v.indentWithTab,...v.defaultKeymap,...v.historyKeymap,...k.searchKeymap,{key:`Mod-s`,run:()=>(O.current(),!0)}]),g.EditorView.updateListener.of(e=>{e.docChanged&&!(S.current&&e.transactions.some(e=>e.annotation(S.current)===!0))&&D.current(e.state.doc.toString()),e.selectionSet&&P(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),g.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(L&&(s=new m.Compartment,z.splice(1,0,s.of([])),z.push(L.base)),F)try{z.push(F)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${d}:`,e),R=!1}if(R&&o&&c&&l)try{z.push(o.of(c.syntaxHighlighting(_(c,l))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${d}:`,e),R=!1}if(a=new g.EditorView({state:m.EditorState.create({doc:t,extensions:z}),parent:y.current}),i){a.destroy();return}b.current=a,A(R),M(!0),w.current=L,T.current=s??null,E.current=null,I(e=>e+1);let B=new MutationObserver(()=>{let e=b.current;if(e&&R&&o&&c&&l)try{e.dispatch({effects:o.reconfigure(c.syntaxHighlighting(_(c,l)))})}catch{}});x.current=B,B.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),i||M(!0)}})(),()=>{i=!0,x.current?.disconnect(),x.current=null,a?.destroy(),b.current=null,M(!1),y.current&&(y.current.textContent=``)}},[e]),(0,o.useEffect)(()=>{let e=b.current;if(!e)return;let n=e.state.doc.toString();n!==t&&e.dispatch({changes:{from:0,to:n.length,insert:t},annotations:S.current?S.current.of(!0):void 0})},[t]),(0,o.useEffect)(()=>{let e=b.current;if(!e||!s)return;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines));e.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0}),e.focus()},[s,j]);let L=!!(g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l);(0,o.useEffect)(()=>{let t=b.current,n=w.current,r=T.current;if(!t||!n||!r)return;let i=g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l?g.response:null,o=i?a(i):null;E.current!==o&&(E.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[g?.state,g?.response,g?.path,g?.workspaceId,e,l,F]);let R=b.current?.state.doc.toString()??t,z=R.length<=m?R:R.slice(0,m),B=h(e),V=d(B),H=b.current?.state,U=H?.selection.main.head,W=U===void 0?void 0:H?.doc.lineAt(U),G=W?.number,K=U!==void 0&&W?U-W.from+1:void 0;return(0,o.useEffect)(()=>{j&&G!==void 0&&K!==void 0&&v?.({line:G,column:K,language:k&&V||`纯文本`,highlight:k?B:`plain`})},[j,G,K,k,V,B,v]),(0,o.useEffect)(()=>()=>v?.(),[v]),(0,f.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":z,"data-file-content-truncated":R.length>m?`1`:`0`,"data-file-selection":N,"data-file-editor-ready":j?`1`:`0`,"data-file-blame-gutter":L?`1`:void 0,onMouseDown:()=>b.current?.focus(),children:[(0,f.jsx)(`div`,{className:`file-cm`,ref:y,"aria-label":`编辑 ${e}`}),(!j||!v)&&(0,f.jsxs)(`div`,{className:`file-editor-status`,children:[!j&&(0,f.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),j&&U!==void 0&&W&&(0,f.jsxs)(`span`,{children:[`第 `,W.number,` 行,第 `,U-W.from+1,` 列`]}),j&&!k&&(0,f.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),j&&k&&V&&(0,f.jsx)(`span`,{"data-file-highlight-status":B,children:V})]})]})}export{v as CodeMirrorEditor};