@evandu/super-pi 0.1.233 → 0.1.234

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 +8 -8
  2. package/dist/client/assets/CodeMirrorEditor-Bghp-U4C.js +2 -0
  3. package/dist/client/assets/{dist-BxJsFYNz.js → dist-B8NaV9Cv.js} +1 -1
  4. package/dist/client/assets/{dist-Dv5RvBil.js → dist-BESOLyaG.js} +1 -1
  5. package/dist/client/assets/{dist-BH-kaMWJ.js → dist-BNTyu0GR.js} +1 -1
  6. package/dist/client/assets/{dist-BX6V-2ch.js → dist-BOLAeWpo.js} +1 -1
  7. package/dist/client/assets/{dist-D6L_I39S.js → dist-BXS7H8-R.js} +1 -1
  8. package/dist/client/assets/{dist-CXQ72jK0.js → dist-BfJ86nxw.js} +1 -1
  9. package/dist/client/assets/{dist-CADYSFwN.js → dist-Bs7CHuCU.js} +1 -1
  10. package/dist/client/assets/{dist-Qu_JVRdm.js → dist-C7Frt-j5.js} +1 -1
  11. package/dist/client/assets/{dist-8ntSzuyc.js → dist-CWI_J8Y8.js} +1 -1
  12. package/dist/client/assets/{dist-BTFTY60x.js → dist-CXgcMgdt.js} +1 -1
  13. package/dist/client/assets/{dist-n9h1Tr_V.js → dist-CeyskXU5.js} +1 -1
  14. package/dist/client/assets/{dist-DfIfNI5O.js → dist-CpJDmC2s.js} +1 -1
  15. package/dist/client/assets/{dist-RRg5quSb.js → dist-DDQEsi6d.js} +1 -1
  16. package/dist/client/assets/{dist-DsaVwWTi.js → dist-DkGaMCuB.js} +1 -1
  17. package/dist/client/assets/{dist-CBkmTbun.js → dist-DzEYlfwN.js} +1 -1
  18. package/dist/client/assets/{dist-CNOENBsx.js → dist-Ka-oeqiz.js} +1 -1
  19. package/dist/client/assets/{dist-BboHMFNI.js → dist-Zo5WaMe0.js} +1 -1
  20. package/dist/client/assets/{dist-DTpnIL-S.js → dist-gzowmwC2.js} +1 -1
  21. package/dist/client/assets/{dist-BdS5YuVr.js → dist-jtZ_yT6e.js} +1 -1
  22. package/dist/client/assets/{dist-mIg0RKXQ.js → dist-pz-FtJ-_.js} +1 -1
  23. package/dist/client/assets/{dist-DILlxwEE.js → dist-qY4JuH16.js} +1 -1
  24. package/dist/client/assets/{dist-DlyF9NDv.js → dist-vqHBACjg.js} +1 -1
  25. package/dist/client/assets/{index-ULLf_i7J.css → index-CYevEn2Z.css} +1 -1
  26. package/dist/client/assets/{index-09FegZJi.js → index-_JUMqd3d.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 +10 -0
  35. package/dist/server/git.js +135 -1
  36. package/dist/server/http-server.js +88 -5
  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
@@ -1334,9 +1336,26 @@ export function createHttpServer(options) {
1334
1336
  }
1335
1337
  const sessionRoot = await resolveFileCwd(workspace.path, requestedCwd);
1336
1338
  const cwd = relative(resolve(workspace.path), sessionRoot).replaceAll("\\", "/");
1339
+ if (op === "commit-detail" || op === "commit-diff") {
1340
+ if (request.method !== "GET") {
1341
+ json(405, { error: "查看提交需要 GET 请求", code: "method" });
1342
+ return;
1343
+ }
1344
+ const worktreeId = url.searchParams.get("worktreeId");
1345
+ if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
1346
+ json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
1347
+ return;
1348
+ }
1349
+ const root = worktreeId ? (await resolveGitWorktree(workspace.path, worktreeId)).path : workspace.path;
1350
+ const directory = worktreeId ? "" : cwd;
1351
+ const hash = url.searchParams.get("hash") ?? "";
1352
+ json(200, op === "commit-detail" ? await gitCommit(root, directory, hash)
1353
+ : await gitCommitDiff(root, directory, hash, url.searchParams.get("path") ?? ""));
1354
+ return;
1355
+ }
1337
1356
  // Blame is a read with a GET shape: every other verb is refused HERE, before the POST branch
1338
1357
  // could ever route the op into gitMutate and before any body is read.
1339
- if (op === "blame" && request.method !== "GET") {
1358
+ if ((op === "blame" || op === "graph") && request.method !== "GET") {
1340
1359
  json(405, { error: "Git 请求方法不支持", code: "method" });
1341
1360
  return;
1342
1361
  }
@@ -1412,6 +1431,9 @@ export function createHttpServer(options) {
1412
1431
  }
1413
1432
  if (op === "status")
1414
1433
  json(200, await gitStatus(workspace.path, cwd));
1434
+ else if (op === "graph") {
1435
+ 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") ?? ""));
1436
+ }
1415
1437
  else if (op === "log" || op === "branches" || op === "stash") {
1416
1438
  const query = url.searchParams.get("q") ?? "";
1417
1439
  const offset = Number(url.searchParams.get("offset") ?? 0);
@@ -1465,6 +1487,10 @@ export function createHttpServer(options) {
1465
1487
  }
1466
1488
  else if (code === "not_found")
1467
1489
  json(404, { error: message, code: "not_found" });
1490
+ else if (code === "commit_diff_too_large")
1491
+ json(413, { error: message, code });
1492
+ else if (code === "graph_changed")
1493
+ json(409, { error: message, code });
1468
1494
  else if (code === "bad_range" || code === "bad_revision")
1469
1495
  json(400, { error: message, code });
1470
1496
  else if (["outside_scope", "empty_index", "empty_worktree", "bad_message", "bad_op"].includes(String(code)))
@@ -2598,6 +2624,61 @@ export function createHttpServer(options) {
2598
2624
  }
2599
2625
  return;
2600
2626
  }
2627
+ const openFileRoute = /^\/api\/files\/(open|open-asset|open-document)$/.exec(url.pathname)?.[1];
2628
+ if (openFileRoute) {
2629
+ try {
2630
+ const origin = request.headers.origin;
2631
+ const fetchSite = request.headers["sec-fetch-site"];
2632
+ if (!isLocalOrPrivateAddress(remote) || (fetchSite && fetchSite !== "same-origin" && fetchSite !== "none")
2633
+ || (origin && (fetchSite ? fetchSite !== "same-origin" : origin !== url.origin))) {
2634
+ throw new FilesError(403, "打开外部文件需要来自同源的本机或局域网请求。", "denied");
2635
+ }
2636
+ const workspaceId = url.searchParams.get("workspaceId")?.trim();
2637
+ const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
2638
+ if (!workspaceId || !workspace || workspace.closedAt)
2639
+ throw new FilesError(404, "请先选择有效工作区。", "no_workspace");
2640
+ const root = await resolveFileCwd(workspace.path, url.searchParams.get("cwd"));
2641
+ if (openFileRoute === "open" && request.method === "POST") {
2642
+ const body = await readRequestText(request, 16 * 1024);
2643
+ if (body.tooLarge)
2644
+ throw new FilesError(413, "文件打开请求过大。", "too_large");
2645
+ let path;
2646
+ try {
2647
+ path = JSON.parse(body.text)?.path;
2648
+ }
2649
+ catch {
2650
+ throw new FilesError(400, "需要有效的文件打开请求。", "bad_request");
2651
+ }
2652
+ if (typeof path !== "string" || !path.trim())
2653
+ throw new FilesError(400, "请提供文件路径。", "bad_path");
2654
+ json(200, await explicitFileOpen.open(workspaceId, workspace.path, root, path));
2655
+ return;
2656
+ }
2657
+ const asset = openFileRoute === "open-asset" && (request.method === "GET" || request.method === "HEAD");
2658
+ const document = openFileRoute === "open-document" && request.method === "GET";
2659
+ if (!asset && !document)
2660
+ throw new FilesError(405, "不支持此文件操作。", "method");
2661
+ const path = await explicitFileOpen.target(workspaceId, root, url.searchParams.get("ticket") ?? "");
2662
+ if (asset)
2663
+ await respondWithWorkspaceFile(request, response, path, url.searchParams.has("download"), { noFollow: true });
2664
+ else
2665
+ json(200, await readWorkspaceDocumentPreview(path, { noFollow: true }));
2666
+ }
2667
+ catch (error) {
2668
+ if (response.headersSent) {
2669
+ response.destroy();
2670
+ return;
2671
+ }
2672
+ const code = error?.code;
2673
+ if (code === "ENOENT" || code === "ENOTDIR") {
2674
+ json(404, { error: "文件不存在或已被移动。", code: "not_found" });
2675
+ return;
2676
+ }
2677
+ const described = describeFilesError(error);
2678
+ json(described.status, described.body);
2679
+ }
2680
+ return;
2681
+ }
2601
2682
  const explorerRoute = /^\/api\/files\/(tree|upload|upload-check|asset|document)$/.exec(url.pathname)?.[1];
2602
2683
  if (explorerRoute) {
2603
2684
  try {
@@ -2898,13 +2979,15 @@ export function createHttpServer(options) {
2898
2979
  // failure this work exists to remove. Past the deadline the answer is still returned, with
2899
2980
  // `indexed: false` so the UI can say the index is still building rather than pretending
2900
2981
  // the tree is empty.
2901
- const result = index.search(query);
2982
+ const linksOnly = url.searchParams.get("links") === "1";
2983
+ const result = index.search(query, linksOnly);
2984
+ const hits = linksOnly ? result.hits.slice(0, 20) : result.hits;
2902
2985
  json(200, {
2903
2986
  mode: "search",
2904
2987
  query: query.trim(),
2905
- hits: result.hits.map((hit) => ({ path: hit.path, name: hit.name, directory: hit.directory })),
2988
+ hits: hits.map(({ path, name, directory, openLink }) => ({ path, name, directory, ...(openLink ? { openLink } : {}) })),
2906
2989
  total: result.total,
2907
- truncated: false,
2990
+ truncated: hits.length < result.total,
2908
2991
  skipped: [],
2909
2992
  indexed: result.indexed,
2910
2993
  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.234",
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};