@evandu/super-pi 0.1.248 → 0.1.250

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 (49) hide show
  1. package/dist/client/.super-pi-client-sources.json +7 -7
  2. package/dist/client/assets/CodeMirrorEditor-BAARAbkf.js +2 -0
  3. package/dist/client/assets/GitDiffEditor-D6rq77Wh.js +27 -0
  4. package/dist/client/assets/dist-0FXz0KLB.js +9 -0
  5. package/dist/client/assets/dist-AczI3ocs.js +1 -0
  6. package/dist/client/assets/{dist-KYkkwisQ.js → dist-B3-a6uF0.js} +6 -6
  7. package/dist/client/assets/dist-BSugRTzs.js +1 -0
  8. package/dist/client/assets/{dist-DfYcl24C.js → dist-BUl4ovQu.js} +2 -2
  9. package/dist/client/assets/dist-BbuAnJ4T.js +1 -0
  10. package/dist/client/assets/dist-BsG-6pTu.js +3 -0
  11. package/dist/client/assets/{dist-CsOcBQZU.js → dist-C8yZkfJN.js} +2 -2
  12. package/dist/client/assets/dist-CISO_jYt.js +1 -0
  13. package/dist/client/assets/dist-D09S6VMH.js +1 -0
  14. package/dist/client/assets/dist-D1NpQAva.js +1 -0
  15. package/dist/client/assets/dist-D5-SYidb.js +1 -0
  16. package/dist/client/assets/dist-D978o95T.js +5 -0
  17. package/dist/client/assets/dist-DRk4qy9i.js +23 -0
  18. package/dist/client/assets/dist-DkPVc7Rf.js +1 -0
  19. package/dist/client/assets/dist-QyJg7PsR.js +11 -0
  20. package/dist/client/assets/dist-gBVaCjue.js +1 -0
  21. package/dist/client/assets/{dist-KRvDAowe.js → dist-scBkrwv-.js} +2 -2
  22. package/dist/client/assets/dist-uuaqc1SU.js +1 -0
  23. package/dist/client/assets/dist-vK4fMIi8.js +1 -0
  24. package/dist/client/assets/{index-CVSDagOL.js → index-B1oejSFf.js} +11 -11
  25. package/dist/client/assets/index-CwOjMymH.css +1 -0
  26. package/dist/client/index.html +2 -2
  27. package/dist/server/git.d.ts +6 -0
  28. package/dist/server/git.js +24 -3
  29. package/dist/server/http-server.js +19 -1
  30. package/package.json +2 -1
  31. package/dist/client/assets/CodeMirrorEditor-DRwfpJuj.js +0 -2
  32. package/dist/client/assets/GitDiffEditor-BRCFAb-9.js +0 -26
  33. package/dist/client/assets/dist-B8HMl2sC.js +0 -1
  34. package/dist/client/assets/dist-BJ4DyKpr.js +0 -1
  35. package/dist/client/assets/dist-BOxW9j9f.js +0 -1
  36. package/dist/client/assets/dist-BUCp8C1J.js +0 -3
  37. package/dist/client/assets/dist-BZcQqwK2.js +0 -1
  38. package/dist/client/assets/dist-BaqnkrBt.js +0 -23
  39. package/dist/client/assets/dist-Bd_1wEMo.js +0 -1
  40. package/dist/client/assets/dist-CDdAirBD.js +0 -1
  41. package/dist/client/assets/dist-DDMxAmWr.js +0 -1
  42. package/dist/client/assets/dist-DDX_kEXl.js +0 -11
  43. package/dist/client/assets/dist-DMNSi_OW.js +0 -9
  44. package/dist/client/assets/dist-Dobw-6kL.js +0 -5
  45. package/dist/client/assets/dist-EZTF454G.js +0 -1
  46. package/dist/client/assets/dist-MjzwBrDE.js +0 -1
  47. package/dist/client/assets/dist-blcD_RX0.js +0 -1
  48. package/dist/client/assets/dist-rWx2sy4G.js +0 -1
  49. package/dist/client/assets/index-NdrxLvOm.css +0 -1
@@ -8,9 +8,9 @@
8
8
  <link rel="alternate icon" href="/favicon.ico" />
9
9
  <link rel="apple-touch-icon" href="/favicon.svg" />
10
10
  <title>Super Pi</title>
11
- <script type="module" crossorigin src="/assets/index-CVSDagOL.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-B1oejSFf.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-NdrxLvOm.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-CwOjMymH.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -127,12 +127,18 @@ export declare function gitDiff(root: string, path: string, staged: boolean, ful
127
127
  staged: boolean;
128
128
  diff: null;
129
129
  kind: "untracked";
130
+ currentExists: boolean;
130
131
  } | {
131
132
  path: string;
132
133
  staged: boolean;
133
134
  diff: string;
134
135
  kind: "binary" | "text";
136
+ currentExists: boolean;
135
137
  }>;
138
+ /** Read the index version for the editable working-tree comparison. The path is resolved beneath the
139
+ * workspace before it becomes a Git object expression, and the blob stays within the file editor's
140
+ * existing size limit. */
141
+ export declare function gitIndexFileContent(root: string, path: string): Promise<string>;
136
142
  /**
137
143
  * The content of a file AS IT WAS COMMITTED, or `null` when there is no such version.
138
144
  *
@@ -4,6 +4,7 @@ import { promisify } from "node:util";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
5
  import { existsSync } from "node:fs";
6
6
  import { mkdir, readFile, realpath, stat } from "node:fs/promises";
7
+ import { MAX_FILE_BYTES } from "./files.js";
7
8
  const exec = promisify(execFile);
8
9
  async function git(cwd, args, options) { return exec("git", ["--literal-pathspecs", "-c", "core.quotepath=false", ...args], { cwd, windowsHide: true, maxBuffer: options?.maxBuffer ?? 8 * 1024 * 1024, timeout: options?.timeout }); }
9
10
  function files(raw, cwd = "") {
@@ -489,14 +490,34 @@ export async function gitDiff(root, path, staged, fullContext = false) {
489
490
  const safe = resolve(root, path);
490
491
  if (!safe.startsWith(resolve(root) + sep) || path.includes("\0"))
491
492
  throw Object.assign(new Error("文件路径无效"), { code: "path" });
493
+ const currentExists = existsSync(safe);
492
494
  const tracked = await git(root, ["ls-files", "--error-unmatch", "--", path]).then(() => true).catch(() => false)
493
495
  || staged && await git(root, ["cat-file", "-e", `HEAD:${relative(root, safe).split(sep).join("/")}`]).then(() => true).catch(() => false);
494
- if (!tracked && !existsSync(safe))
496
+ if (!tracked && !currentExists)
495
497
  throw Object.assign(new Error("文件路径无效"), { code: "path" });
496
498
  if (!tracked)
497
- return { path, staged, diff: null, kind: "untracked" };
499
+ return { path, staged, diff: null, kind: "untracked", currentExists };
498
500
  const patch = await readGitDiff(root, ["diff", ...PATCH_OPTIONS, patchContext(fullContext), ...(staged ? ["--cached"] : []), "--", path], fullContext);
499
- return { path, staged, diff: patch, kind: /^Binary files .* differ$/m.test(patch) ? "binary" : "text" };
501
+ return { path, staged, diff: patch, kind: /^Binary files .* differ$/m.test(patch) ? "binary" : "text", currentExists };
502
+ }
503
+ /** Read the index version for the editable working-tree comparison. The path is resolved beneath the
504
+ * workspace before it becomes a Git object expression, and the blob stays within the file editor's
505
+ * existing size limit. */
506
+ export async function gitIndexFileContent(root, path) {
507
+ const safe = resolve(root, path);
508
+ if (!safe.startsWith(resolve(root) + sep) || path.includes("\0"))
509
+ throw gitFailure("文件路径无效", "path");
510
+ const repoPath = relative(root, safe).split(sep).join("/");
511
+ const object = `:0:${repoPath}`;
512
+ const size = Number((await git(root, ["cat-file", "-s", object])).stdout.trim());
513
+ if (!Number.isSafeInteger(size) || size < 0)
514
+ throw gitFailure("无法读取暂存区中的文件版本", "missing_index_blob");
515
+ if (size > MAX_FILE_BYTES)
516
+ throw gitFailure("文件过大,无法在差异编辑器中编辑", "file_too_large");
517
+ const content = (await git(root, ["show", object], { maxBuffer: MAX_FILE_BYTES * 2 })).stdout;
518
+ if (content.includes("\0"))
519
+ throw gitFailure("二进制文件不能在差异编辑器中编辑", "binary");
520
+ return content;
500
521
  }
501
522
  /**
502
523
  * The content of a file AS IT WAS COMMITTED, or `null` when there is no such version.
@@ -14,7 +14,7 @@ import { describe as describeFilesError, FilesError, fileMeta, listDirectory, MA
14
14
  import { findUploadFile, MAX_UPLOAD_BODY_BYTES, saveUpload } from "./upload.js";
15
15
  import { describeThrown } from "./failure-text.js";
16
16
  import { checkDiskVersion, readPackageVersion } from "./version.js";
17
- import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
17
+ import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitIndexFileContent, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
18
18
  import { computeFileDiff } from "./file-diff.js";
19
19
  import { verifyCapability } from "./capability.js";
20
20
  import { conversationWorkspace } from "./model-filter.js";
@@ -1686,6 +1686,24 @@ export function createHttpServer(options) {
1686
1686
  else
1687
1687
  json(200, await gitStashes(workspace.path, cwd, query, offset));
1688
1688
  }
1689
+ else if (op === "diff-edit") {
1690
+ if (request.method !== "GET") {
1691
+ json(405, { error: "读取差异编辑内容需要 GET 请求", code: "method" });
1692
+ return;
1693
+ }
1694
+ const requested = url.searchParams.get("path");
1695
+ if (!requested) {
1696
+ json(400, { error: "差异编辑需要 path", code: "bad_path" });
1697
+ return;
1698
+ }
1699
+ await explorerPath(workspace.path, sessionRoot, requested, true);
1700
+ const path = await workspacePathFromSession(workspace.path, sessionRoot, requested);
1701
+ const [original, file] = await Promise.all([
1702
+ gitIndexFileContent(workspace.path, path),
1703
+ readWorkspaceFile(workspace.path, path),
1704
+ ]);
1705
+ json(200, { path: file.path, original, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta });
1706
+ }
1689
1707
  else if (op === "diff") {
1690
1708
  const path = url.searchParams.get("path");
1691
1709
  if (!path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.248",
3
+ "version": "0.1.250",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -426,6 +426,7 @@
426
426
  "@codemirror/lang-yaml": "^6.1.3",
427
427
  "@codemirror/language": "^6.13.1",
428
428
  "@codemirror/legacy-modes": "^6.5.5",
429
+ "@codemirror/merge": "^6.12.3",
429
430
  "@codemirror/search": "^6.7.2",
430
431
  "@codemirror/state": "^6.7.6",
431
432
  "@codemirror/view": "^6.43.15",
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-BUCp8C1J.js","assets/dist-Dobw-6kL.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-KYkkwisQ.js","assets/dist-Cus6_oaF.js","assets/dist-B8HMl2sC.js","assets/dist-BXAOrsjq.js","assets/dist-BaqnkrBt.js","assets/dist-BOxW9j9f.js","assets/dist-DMNSi_OW.js","assets/dist-BZcQqwK2.js","assets/dist-MjzwBrDE.js","assets/dist-EZTF454G.js","assets/dist-CDdAirBD.js","assets/dist-CsOcBQZU.js","assets/dist-rWx2sy4G.js","assets/dist-Bd_1wEMo.js","assets/dist-blcD_RX0.js","assets/dist-DfYcl24C.js","assets/dist-BJ4DyKpr.js","assets/dist-DDX_kEXl.js","assets/dist-DDMxAmWr.js","assets/dist-KRvDAowe.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{l as t,n,o as r,r as i,t as a}from"./index-CVSDagOL.js";var o=e(t(),1);async function s(e,t){let[{StreamLanguage:n},r]=await Promise.all([i(()=>import(`./dist-BUCp8C1J.js`),__vite__mapDeps([0,1,2,3,4])),e()]),a=r[t]??r.default??r;return n.define(a)}var c={cpp:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),cc:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),cxx:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),hpp:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),hh:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),hxx:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),c:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),h:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),cu:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),cuh:()=>i(()=>import(`./dist-B8HMl2sC.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,2,0,1,3,6])),js:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,2,1,3,4,0,6,8])),jsx:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([7,2,1,3,4,0,6,8])),mjs:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,2,1,3,4,0,6,8])),cjs:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,2,1,3,4,0,6,8])),ts:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,2,1,3,4,0,6,8])),tsx:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0,jsx:!0})),__vite__mapDeps([7,2,1,3,4,0,6,8])),mts:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,2,1,3,4,0,6,8])),cts:()=>i(()=>import(`./dist-BaqnkrBt.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,2,1,3,4,0,6,8])),py:()=>i(()=>import(`./dist-DMNSi_OW.js`).then(e=>e.python()),__vite__mapDeps([9,4,2,0,1,3,6,8])),pyi:()=>i(()=>import(`./dist-DMNSi_OW.js`).then(e=>e.python()),__vite__mapDeps([9,4,2,0,1,3,6,8])),java:()=>i(()=>import(`./dist-BZcQqwK2.js`).then(e=>e.java()),__vite__mapDeps([10,4,2,0,1,3,6])),php:()=>i(()=>import(`./dist-MjzwBrDE.js`).then(e=>e.php()),__vite__mapDeps([11,4,2,0,1,3,6,12,13,7,8])),sql:()=>i(()=>import(`./dist-CsOcBQZU.js`).then(e=>e.sql()),__vite__mapDeps([14,4,2,0,1,3,6,8])),yaml:()=>i(()=>import(`./dist-rWx2sy4G.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,2,0,1,3,6])),yml:()=>i(()=>import(`./dist-rWx2sy4G.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,2,0,1,3,6])),xml:()=>i(()=>import(`./dist-Bd_1wEMo.js`).then(e=>e.xml()),__vite__mapDeps([16,1,2,3,4,0,6])),json:()=>i(()=>import(`./dist-blcD_RX0.js`).then(e=>e.json()),__vite__mapDeps([17,4,2,0,1,3,6])),jsonc:()=>i(()=>import(`./dist-blcD_RX0.js`).then(e=>e.json()),__vite__mapDeps([17,4,2,0,1,3,6])),json5:()=>i(()=>import(`./dist-blcD_RX0.js`).then(e=>e.json()),__vite__mapDeps([17,4,2,0,1,3,6])),html:()=>i(()=>import(`./dist-EZTF454G.js`).then(e=>e.html()),__vite__mapDeps([12,1,2,3,4,0,6,13,7,8])),htm:()=>i(()=>import(`./dist-EZTF454G.js`).then(e=>e.html()),__vite__mapDeps([12,1,2,3,4,0,6,13,7,8])),vue:()=>i(()=>import(`./dist-EZTF454G.js`).then(e=>e.html()),__vite__mapDeps([12,1,2,3,4,0,6,13,7,8])),svelte:()=>i(()=>import(`./dist-EZTF454G.js`).then(e=>e.html()),__vite__mapDeps([12,1,2,3,4,0,6,13,7,8])),css:()=>i(()=>import(`./dist-CDdAirBD.js`).then(e=>e.r).then(e=>e.css()),__vite__mapDeps([13,2,4,0,1,3,6])),md:()=>i(()=>import(`./dist-DfYcl24C.js`).then(e=>e.markdown()),__vite__mapDeps([18,1,2,3,4,0,8,12,6,13,7])),markdown:()=>i(()=>import(`./dist-DfYcl24C.js`).then(e=>e.markdown()),__vite__mapDeps([18,1,2,3,4,0,8,12,6,13,7])),mdx:()=>i(()=>import(`./dist-DfYcl24C.js`).then(e=>e.markdown()),__vite__mapDeps([18,1,2,3,4,0,8,12,6,13,7])),rs:()=>i(()=>import(`./dist-BJ4DyKpr.js`).then(e=>e.rust()),__vite__mapDeps([19,4,2,0,1,3,6])),go:()=>i(()=>import(`./dist-DDX_kEXl.js`).then(e=>e.go()),__vite__mapDeps([20,4,2,0,1,3,6,8])),sh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),bash:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),zsh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),fish:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),ps1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),psm1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),rb:()=>s(()=>i(()=>import(`./ruby-ChfNwlCY.js`),[]),`ruby`),swift:()=>s(()=>i(()=>import(`./swift-DKB6_1j6.js`),[]),`swift`),toml:()=>s(()=>i(()=>import(`./toml-BPTmHmyx.js`),[]),`toml`),ini:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),cfg:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),conf:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),properties:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),dockerfile:()=>s(()=>i(()=>import(`./dockerfile-BDePf5PZ.js`),[]),`dockerfile`),diff:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`),patch:()=>s(()=>i(()=>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=r(),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:r,jumpToLine:s,onSave:c,workspaceId:l,blame:g,onPosition:v,readOnly:y=!1}){let 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)(null),O=(0,o.useRef)(r),k=(0,o.useRef)(c);O.current=r,k.current=c;let[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)(`0,0`),[I,L]=(0,o.useState)(0);(0,o.useEffect)(()=>{let r=!1,a,o,s,c,l;return(async()=>{try{let d=h(e),f=u(d),[m,g,v,A,M,P,I,R]=await Promise.all([i(()=>import(`./dist-Dobw-6kL.js`).then(e=>e.x),__vite__mapDeps([1,2])),i(()=>import(`./dist-KYkkwisQ.js`).then(e=>e.s),__vite__mapDeps([3,2,1])),i(()=>import(`./dist-DDMxAmWr.js`),__vite__mapDeps([21,1,2,3,4,0])),i(()=>import(`./dist-KRvDAowe.js`),__vite__mapDeps([22,1,2,3])),i(()=>import(`./dist-BUCp8C1J.js`),__vite__mapDeps([0,1,2,3,4])),i(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,2])),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(r||!b.current)return;c=M,l=P,C.current=m.Annotation.define(),w.current=m.Transaction.addToHistory;let z=t.length<=p&&I!==null;o=new m.Compartment;let B=[g.lineNumbers(),g.highlightActiveLine(),g.drawSelection(),v.history(),g.keymap.of([v.indentWithTab,...v.defaultKeymap,...v.historyKeymap,...A.searchKeymap,{key:`Mod-s`,run:()=>(k.current(),!0)}]),g.EditorView.updateListener.of(e=>{e.docChanged&&!(C.current&&e.transactions.some(e=>e.annotation(C.current)===!0))&&O.current(e.state.doc.toString()),e.selectionSet&&F(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),g.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(y&&B.push(m.EditorState.readOnly.of(!0),g.EditorView.editable.of(!1)),R&&!y&&(s=new m.Compartment,B.splice(1,0,s.of([])),B.push(R.base)),I)try{B.push(I)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${d}:`,e),z=!1}if(z&&o&&c&&l)try{B.push(o.of(c.syntaxHighlighting(_(c,l))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${d}:`,e),z=!1}if(a=new g.EditorView({state:m.EditorState.create({doc:t,extensions:B}),parent:b.current}),r){a.destroy();return}x.current=a,j(z),N(!0),T.current=R,E.current=s??null,D.current=null,L(e=>e+1);let V=new MutationObserver(()=>{let e=x.current;if(e&&z&&o&&c&&l)try{e.dispatch({effects:o.reconfigure(c.syntaxHighlighting(_(c,l)))})}catch{}});S.current=V,V.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),r||N(!0)}})(),()=>{r=!0,S.current?.disconnect(),S.current=null,a?.destroy(),x.current=null,N(!1),b.current&&(b.current.textContent=``)}},[e,y]),(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let n=e.state.doc.toString();n!==t&&e.dispatch({changes:{from:0,to:n.length,insert:t},annotations:C.current?C.current.of(!0):void 0})},[t]),(0,o.useEffect)(()=>{let e=x.current;if(!e||!s)return;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(s.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},scrollIntoView:!0}),e.focus()},[s,M]);let R=!!(g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l);(0,o.useEffect)(()=>{let t=x.current,n=T.current,r=E.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;D.current!==o&&(D.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[g?.state,g?.response,g?.path,g?.workspaceId,e,l,I]);let z=x.current?.state.doc.toString()??t,B=z.length<=m?z:z.slice(0,m),V=h(e),H=d(V),U=x.current?.state,W=U?.selection.main.head,G=W===void 0?void 0:U?.doc.lineAt(W),K=G?.number,q=W!==void 0&&G?W-G.from+1:void 0;return(0,o.useEffect)(()=>{M&&K!==void 0&&q!==void 0&&v?.({line:K,column:q,language:A&&H||`纯文本`,highlight:A?V:`plain`})},[M,K,q,A,H,V,v]),(0,o.useEffect)(()=>()=>v?.(),[v]),(0,f.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":B,"data-file-content-truncated":z.length>m?`1`:`0`,"data-file-selection":P,"data-file-editor-ready":M?`1`:`0`,"data-file-blame-gutter":R?`1`:void 0,onMouseDown:()=>x.current?.focus(),children:[(0,f.jsx)(`div`,{className:`file-cm`,ref:b,"aria-label":`${y?`查看`:`编辑`} ${e}`}),(!M||!v)&&(0,f.jsxs)(`div`,{className:`file-editor-status`,children:[!M&&(0,f.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),M&&W!==void 0&&G&&(0,f.jsxs)(`span`,{children:[`第 `,G.number,` 行,第 `,W-G.from+1,` 列`]}),M&&!A&&(0,f.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),M&&A&&H&&(0,f.jsx)(`span`,{"data-file-highlight-status":V,children:H})]})]})}export{v as CodeMirrorEditor};