@evandu/super-pi 0.1.314 → 0.1.315
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/agents/super-pi-task/index.ts +23 -0
- package/dist/client/.super-pi-client-sources.json +7 -6
- package/dist/client/assets/{CodeMirrorEditor-DodqscaS.js → CodeMirrorEditor-CNkxpHoE.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-BA3eG1na.js → GitDiffEditor-IgRl-QlD.js} +1 -1
- package/dist/client/assets/index-BP3z0_br.css +1 -0
- package/dist/client/assets/{index-B9lWq5MJ.js → index-COe1c4FI.js} +61 -61
- package/dist/client/index.html +2 -2
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +1 -1
- package/dist/server/file-review-threads.d.ts +25 -0
- package/dist/server/file-review-threads.js +165 -0
- package/dist/server/http-server.js +123 -1
- package/dist/server/index.js +1 -0
- package/dist/server/runtime.js +4 -1
- package/dist/shared/file-review.d.ts +39 -0
- package/dist/shared/file-review.js +9 -0
- package/package.json +3 -1
- package/dist/client/assets/index-CtsA5apS.css +0 -1
|
@@ -203,6 +203,29 @@ const extension = (pi: ExtensionApi): void => {
|
|
|
203
203
|
const questionEndpoint = process.env.SUPER_PI_QUESTION_ENDPOINT;
|
|
204
204
|
const taskConversationId = process.env.SUPER_PI_TASK_CONVERSATION;
|
|
205
205
|
const taskCapability = process.env.SUPER_PI_TASK_CAPABILITY;
|
|
206
|
+
const reviewEndpoint = process.env.SUPER_PI_REVIEW_ENDPOINT;
|
|
207
|
+
|
|
208
|
+
if (reviewEndpoint && taskCapability && taskConversationId) pi.registerTool({
|
|
209
|
+
name: "review_reply",
|
|
210
|
+
label: "回复文件批注",
|
|
211
|
+
description: "Reply to a file review thread explicitly identified in the user's message. First examine the referenced code, then describe your interpretation, actual changes, and what you verified. Say clearly if anything remains or you made no change. The user decides whether the thread is resolved.",
|
|
212
|
+
parameters: Type.Object({ id: Type.String(), text: Type.String({ minLength: 1, maxLength: 12000 }),
|
|
213
|
+
location: Type.Optional(Type.Object({ path: Type.String(), line: Type.Optional(Type.Integer({ minimum: 1 })) })) }),
|
|
214
|
+
execute: async (replyId, raw, signal) => {
|
|
215
|
+
const { id, text, location } = raw as { id: string; text: string; location?: { path: string; line?: number } };
|
|
216
|
+
try {
|
|
217
|
+
const timeout = AbortSignal.timeout(15000);
|
|
218
|
+
const response = await fetch(reviewEndpoint, {
|
|
219
|
+
method: "POST", headers: { "Content-Type": "application/json", "X-Review-Capability": taskCapability, "X-Review-Conversation": taskConversationId },
|
|
220
|
+
body: JSON.stringify({ id, text, replyId, location }), signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
221
|
+
});
|
|
222
|
+
const result = await response.json();
|
|
223
|
+
return { content: [{ type: "text", text: response.ok ? "Reply recorded in the original review thread." : result.error ?? "Review reply failed." }], details: undefined, ...(!response.ok ? { isError: true } : {}) };
|
|
224
|
+
} catch {
|
|
225
|
+
return { content: [{ type: "text", text: "Unable to record the review reply. Mention this in the session if retrying fails." }], details: undefined, isError: true };
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
});
|
|
206
229
|
|
|
207
230
|
// THE QUESTION TOOL. It blocks on an HTTP request until the person answers, and the answer comes back
|
|
208
231
|
// as the tool result, which is what keeps the run alive across the exchange - the model does not decide
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"hash": "
|
|
2
|
+
"hash": "7007e51617caad3d7b0c2de2c542fb0265a1b7d7fd9bd36d83fa7986a1a7661f",
|
|
3
3
|
"files": {
|
|
4
4
|
"src/client/AgentHandbookManager.tsx": "af1a64ac128d35dbdc7389884821fda1a272b43d319f2906f41bc518bf2d5fb9",
|
|
5
5
|
"src/client/AnchoredPopover.tsx": "b8c8e32e2c4ca87ec4c555480f7b96338e132356e3bcff73637b4e78526cd0a6",
|
|
6
|
-
"src/client/App.tsx": "
|
|
6
|
+
"src/client/App.tsx": "555b09d57f5eff9d4f494c86f657b83912c8e12b0ec72adca6df570669de3c23",
|
|
7
7
|
"src/client/BackgroundReturnBatch.tsx": "70c4ffb2f93fa4a55e9527c652942c67cea60a4a1b603576603751bcb8be9116",
|
|
8
8
|
"src/client/BottomDockDivider.tsx": "18f53c336e7f390c8af84c71ffa0ea9814f5aac1a03f08a1cfa57d7e522b67a7",
|
|
9
9
|
"src/client/CacheWarmingSettings.tsx": "cce26c4547634b76c08c681a4b9605f884d8502f554f12ff8c30cbd2fd0bd9c0",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"src/client/ErrorBoundary.tsx": "d16376f9f6c7cc1fab8590c65a66438127642f7d6bb8023cec53d8a6cc9f3964",
|
|
17
17
|
"src/client/FeishuPanel.tsx": "3b3257da36bf863e004a33a4c1d721db364b4449fb23f0805cb74b973a2ed2da",
|
|
18
18
|
"src/client/FileMentionMenu.tsx": "d400e7afb31008eda49d4b531eceda65a926b877177d0cffd9a8056b55161c3e",
|
|
19
|
-
"src/client/FileReview.tsx": "
|
|
19
|
+
"src/client/FileReview.tsx": "4a6c10c76da67360ce44af1069f2134433af60dda384c3cbfdc5c4661706f991",
|
|
20
|
+
"src/client/FileReviewThreads.tsx": "13a370504f91f623e6b1da03bd14f9658fb9599c8cda2935bf1861fcef66762d",
|
|
20
21
|
"src/client/FileWorkbenchChrome.tsx": "0863c988bdc50962e3dab365e918ad6de6aee7cc2d0d4d3cce049fa3529d2b6b",
|
|
21
22
|
"src/client/FilesPanel.tsx": "cc242d4addf577532ab26af9fb63f9175068559c291525c09d974f61f887e3e2",
|
|
22
23
|
"src/client/FindControls.tsx": "d98c14e74e1d026c48a487d112974cc70f73889de6daf3446b501fd66b01e4db",
|
|
@@ -96,8 +97,8 @@
|
|
|
96
97
|
"src/client/file-diff-layout.css": "aee864e990d66d90380aeb991181cce39e2a29d02ea85095a4bf0c1d59c9ed50",
|
|
97
98
|
"src/client/file-diff.ts": "b1fd62dd0f561c567f249d98364068c947e31758fa9f1644d27250679e0f62a4",
|
|
98
99
|
"src/client/file-icons.tsx": "65e571a5378723511caef0e4bdbecdd4adba9461a46db878d65a948fc99fcb65",
|
|
99
|
-
"src/client/file-review.css": "
|
|
100
|
-
"src/client/file-review.ts": "
|
|
100
|
+
"src/client/file-review.css": "2d04fb0b98da53925a177652f2a110b86c13a6e000cca8a4266443a82be84106",
|
|
101
|
+
"src/client/file-review.ts": "654044866bb068faad59b69757f90075f2b51491a3d76243bc53c79c72760e1b",
|
|
101
102
|
"src/client/find-controls.css": "d173162f4c4c13f279ddbeca1c4a7b6fde63e5751e3403141a87cd0f7992b007",
|
|
102
103
|
"src/client/find-controls.ts": "517ea11ffd61ffecefda431fe1108800ee9ddce6cf16f410452874d102387531",
|
|
103
104
|
"src/client/git-diff-visual.css": "da7d897e2fdb170cdd7e73493190a1c04cad2f9e2eb5e5bc6599c14bd6d030e2",
|
|
@@ -148,5 +149,5 @@
|
|
|
148
149
|
"src/client/workbench-navigation.ts": "fff6e8546b2fb19a5db474764628bd10e147779dc26512aa6de9e3a0145a1de5",
|
|
149
150
|
"src/client/workbench-search-panel.css": "cf256f436f344cff60f54838a18553ee05ba8170ef823d3ca265b5d15044859d"
|
|
150
151
|
},
|
|
151
|
-
"recordedAt": "2026-11-
|
|
152
|
+
"recordedAt": "2026-11-28T09:38:23.314Z"
|
|
152
153
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-D978o95T.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-DTIPfQj7.js","assets/dist-S5ntGzJB.js","assets/dist-Cus6_oaF.js","assets/dist-DP4hrTBF.js","assets/dist-Qjm1p8SR.js","assets/dist-BJHpSQV1.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{C as t,S as n,T as r,c as i,d as a,i as o,l as s,o as c,r as l,s as u,u as d,w as f,x as p}from"./index-B9lWq5MJ.js";var m=e(r(),1);function ee(e,t,n,r){return[n.EditorView.decorations.compute([`selection`,`doc`],e=>n.Decoration.set(e.selection.ranges.filter(e=>!e.empty).map(e=>n.Decoration.mark({class:`cm-workbench-selectedText`}).range(e.from,e.to)),!0)),n.ViewPlugin.define(e=>{let n=null,i,a=!1,o=e=>{n&&(e===`expanded`?(a=!a,l()):n.querySelector(`input[name="${e===`caseSensitive`?`case`:e===`wholeWord`?`word`:`re`}"]`)?.click())},c=e=>{let t=s(e);t&&(e.preventDefault(),e.stopPropagation(),o(t))},l=()=>{if(!n||!i)return;let r=t.getSearchQuery(e.state);if(n.dataset.editorSearchExpanded=String(a),i.update({caseSensitive:r.caseSensitive,wholeWord:r.wholeWord,regexp:r.regexp,expanded:a}),n.querySelector(`[data-find-error]`)?.remove(),r.search&&!r.valid){let e=document.createElement(`output`);e.dataset.findError=``,e.setAttribute(`role`,`alert`),e.textContent=`正则表达式无效`,n.append(e)}},u=()=>{let s=r.querySelector(`.cm-panel.cm-search`);if(s===n)return;if(n?.removeEventListener(`keydown`,c,!0),i?.destroy(),n=s,!n){i=void 0;return}for(let[e,t,r]of[[`next`,`↓`,`下一处`],[`prev`,`↑`,`上一处`]]){let i=n.querySelector(`button[name="${e}"]`);i&&(i.textContent=t,i.setAttribute(`aria-label`,r),i.title=r)}let u=document.createElement(`span`);u.dataset.findControls=``,n.prepend(u);let f=t.getSearchQuery(e.state);a=!1,i=d(u,{...f,expanded:a},o),n.addEventListener(`keydown`,c,!0),l()},f=new MutationObserver(u);return f.observe(r,{childList:!0,subtree:!0}),u(),{update(){l()},destroy(){f.disconnect(),n?.removeEventListener(`keydown`,c,!0),i?.destroy()}}}),e.Prec.highest(n.keymap.of([{key:`Mod-Shift-l`,run:t.selectSelectionMatches},{key:`Mod-h`,scope:`editor search-panel`,run:e=>(t.searchPanelOpen(e.state)||t.openSearchPanel(e),requestAnimationFrame(()=>{e.dom.isConnected&&r.querySelector(`[data-editor-search-options][aria-expanded="false"]`)?.click()}),!0)},...[`c`,`w`,`r`].map(e=>({key:`Alt-${e}`,run:n=>{t.searchPanelOpen(n.state)||t.openSearchPanel(n);let r=t.getSearchQuery(n.state);return n.dispatch({effects:t.setSearchQuery.of(new t.SearchQuery({...r,...e===`c`?{caseSensitive:!r.caseSensitive}:e===`w`?{wholeWord:!r.wholeWord}:{regexp:!r.regexp}}))}),!0}}))])),n.panels({topContainer:r}),n.EditorView.scrollMargins.of(()=>({top:r.querySelector(`.cm-search`)?Math.min(r.getBoundingClientRect().height+8,Math.max(0,(r.parentElement?.clientHeight??0)-32)):0})),t.highlightSelectionMatches({wholeWords:!0,minSelectionLength:1,maxMatches:1e3}),t.search({top:!0}),e.EditorState.phrases.of({Find:`查找`,Replace:`替换为`,next:`下一处`,previous:`上一处`,all:`全部选中`,"match case":`区分大小写`,regexp:`正则表达式`,"by word":`全词匹配`,replace:`替换`,"replace all":`全部替换`,close:`关闭查找`,"current match":`当前匹配`,"on line":`所在行`})]}function te(e,t,n,r,a){let o=new e.Compartment,s=()=>{let r=c();return[e.EditorState.tabSize.of(r.tabSize),n.indentUnit.of(r.indent===`tabs`?` `:` `.repeat(r.tabSize)),r.wrap?t.EditorView.lineWrapping:[],r.whitespace?[t.highlightWhitespace(),t.highlightTrailingWhitespace()]:[]]};return[e.EditorState.allowMultipleSelections.of(!0),t.rectangularSelection(),t.crosshairCursor({key:`Alt`}),e.EditorState.phrases.of({"folded code":`已折叠代码`,unfold:`展开代码`,"Fold line":`折叠代码`,"Unfold line":`展开代码`}),t.highlightActiveLineGutter(),t.highlightSpecialChars(),t.dropCursor(),n.bracketMatching(),n.indentOnInput(),n.foldGutter(),r.closeBrackets(),e.Prec.highest(t.keymap.of([...r.closeBracketsKeymap,...n.foldKeymap,{key:`Alt-z`,run:()=>(u({wrap:!c().wrap}),!0)},{key:`Mod-Shift-z`,run:a.redo},{key:`Mod-y`,run:a.redo}])),o.of(s()),t.ViewPlugin.define(e=>({destroy:i(()=>{e.dispatch({effects:o.reconfigure(s())})})}))]}var h=new Map;function ne(e){let t=h.get(e);return t&&(h.delete(e),h.set(e,t)),t}function g(e,t){h.delete(e),h.set(e,t);let n=[...h.values()].reduce((e,t)=>e+t.state.doc.length,0);for(;h.size>32||n>16777216;){let e=h.keys().next().value;n-=h.get(e).state.doc.length,h.delete(e)}}var _=f(),re=262144,v=131072;function ie(e){return e.split(`.`).pop()?.toLowerCase()??``}function y(e,t,n=!1){let r=e=>n?`var(--git-diff-${e.slice(5)}, var(${e}))`:`var(${e})`;return e.HighlightStyle.define([{tag:t.tags.keyword,color:r(`--cm-keyword`)},{tag:t.tags.string,color:r(`--cm-string`)},{tag:t.tags.number,color:r(`--cm-number`)},{tag:t.tags.comment,color:r(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:r(`--cm-function`)},{tag:t.tags.typeName,color:r(`--cm-type`)},{tag:t.tags.className,color:r(`--cm-type`)},{tag:t.tags.propertyName,color:r(`--cm-property`)},{tag:t.tags.operator,color:r(`--cm-operator`)},{tag:t.tags.variableName,color:r(`--cm-variable`)}])}function b({path:e,value:r,onChange:i,jumpToLine:s,onSave:c,workspaceId:u,cwd:d=``,blame:f,onPosition:h,onView:b,readOnly:x=!1,languageOverride:S,onReviewLine:C}){let w=(0,m.useRef)(null),T=(0,m.useRef)(null),E=(0,m.useRef)(null),ae=(0,m.useRef)(null),D=JSON.stringify([u,d,e]),O=(0,m.useRef)(void 0),k=(0,m.useRef)(null),A=(0,m.useRef)(null),oe=(0,m.useRef)(null),j=(0,m.useRef)(null),M=(0,m.useRef)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(i),F=(0,m.useRef)(c),I=(0,m.useRef)(r);I.current=r;let L=(0,m.useRef)(!1),R=(0,m.useRef)(b);R.current=b;let z=(0,m.useRef)(C);z.current=C;let B=!!C;P.current=i,F.current=c;let[V,se]=(0,m.useState)(!1),[H,U]=(0,m.useState)(!1),[W,ce]=(0,m.useState)(`0,0`),[G,le]=(0,m.useState)(0),[K,ue]=(0,m.useState)(1);(0,m.useEffect)(()=>{let i=!1,s,c,l,u,d;return(async()=>{try{let f=S??ie(e),p=n(f),[m,h,g,_,v,b,C,V,H]=await Promise.all([t(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([0,1])),t(()=>import(`./dist-DTIPfQj7.js`).then(e=>e.s),__vite__mapDeps([2,1,0])),t(()=>import(`./dist-S5ntGzJB.js`),__vite__mapDeps([3,0,1,2,4,5])),t(()=>import(`./dist-Qjm1p8SR.js`),__vite__mapDeps([6,0,1,2])),t(()=>import(`./dist-DP4hrTBF.js`).then(e=>e.d),__vite__mapDeps([5,1,0,2,4])),t(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),p?p().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${f}:`,e),null)):Promise.resolve(null),o().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null)),t(()=>import(`./dist-BJHpSQV1.js`).then(e=>e.r),__vite__mapDeps([7,1,0,2,5,4]))]);if(i||!w.current||!T.current)return;ae.current=h.EditorView,u=v,d=b,A.current=m.Annotation.define(),oe.current=m.Transaction.addToHistory;let W=r.length<=re&&C!==null;c=new m.Compartment;let G=[h.lineNumbers(),h.highlightActiveLine(),h.drawSelection(),g.history(),h.keymap.of([g.indentWithTab,...g.defaultKeymap,...g.historyKeymap,..._.searchKeymap,{key:`Mod-s`,run:()=>(F.current(),!0)}]),h.EditorView.updateListener.of(e=>{e.docChanged&&!(A.current&&e.transactions.some(e=>e.annotation(A.current)===!0))&&P.current(e.state.doc.toString()),e.selectionSet&&ce(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),h.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(B&&G.push(a(h,e=>z.current?.(e),`file`)),G.push(h.EditorView.updateListener.of(e=>{e.selectionSet&&ue(e.state.selection.ranges.length),e.docChanged?L.current=!1:e.selectionSet&&(L.current=e.transactions.some(e=>e.isUserEvent(`select.search`)||e.isUserEvent(`select.pointer`)))}),ee(m,_,h,T.current),te(m,h,v,H,g)),x&&G.push(m.EditorState.readOnly.of(!0),h.EditorView.editable.of(!1),h.EditorView.contentAttributes.of({tabindex:`0`})),V&&!x&&(l=new m.Compartment,G.splice(1,0,l.of([])),G.push(V.base)),C)try{G.push(C)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${f}:`,e),W=!1}if(W&&c&&u&&d)try{G.push(c.of(u.syntaxHighlighting(y(u,d))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${f}:`,e),W=!1}let K=ne(D),q=K&&K.state.doc.toString()===I.current,J=q?K.state.update({effects:m.StateEffect.reconfigure.of(G)}).state:m.EditorState.create({doc:I.current,extensions:G});if(s=new h.EditorView({state:J,parent:w.current}),O.current=q?K.jump:void 0,ue(s.state.selection.ranges.length),ce(`${s.state.selection.main.from},${s.state.selection.main.to}`),q&&(s.scrollDOM.scrollTop=K.top,s.scrollDOM.scrollLeft=K.left,O.current=K.jump),i){s.destroy();return}E.current=s,R.current?.(s),se(W),U(!0),j.current=V,M.current=l??null,N.current=null,le(e=>e+1);let Y=new MutationObserver(()=>{let e=E.current;if(e&&W&&c&&u&&d)try{e.dispatch({effects:c.reconfigure(u.syntaxHighlighting(y(u,d)))})}catch{}});k.current=Y,Y.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),i||U(!0)}})(),()=>{i=!0,k.current?.disconnect(),k.current=null,s&&g(D,{state:s.state,top:s.scrollDOM.scrollTop,left:s.scrollDOM.scrollLeft,jump:O.current}),s?.destroy(),E.current=null,R.current?.(),U(!1),w.current&&(w.current.textContent=``)}},[D,x,S,B]),(0,m.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.state.doc.toString();t!==r&&e.dispatch({changes:{from:0,to:t.length,insert:r},annotations:A.current?A.current.of(!0):void 0})},[r,H]),(0,m.useEffect)(()=>{let e=E.current;if(!e||!s||O.current===s.request)return;O.current=s.request;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},effects:ae.current?.scrollIntoView(n,{y:`start`,yMargin:Math.round(e.scrollDOM.clientHeight/3)})}),e.focus()},[s,H]);let q=!!(f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u);(0,m.useEffect)(()=>{let t=E.current,n=j.current,r=M.current;if(!t||!n||!r)return;let i=f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u?f.response:null,a=i?l(i):null;N.current!==a&&(N.current=a,t.dispatch({effects:[n.setBlame.of(a),r.reconfigure(a?n.gutter:[])]}))},[f?.state,f?.response,f?.path,f?.workspaceId,e,u,G]);let J=E.current?.state.doc.toString()??r,Y=J.length<=v?J:J.slice(0,v),X=S??ie(e),Z=p(X),de=E.current?.state,Q=de?.selection.main.head,$=Q===void 0?void 0:de?.doc.lineAt(Q),fe=$?.number,pe=Q!==void 0&&$?Q-$.from+1:void 0;return(0,m.useEffect)(()=>{let e=E.current;if(H&&e&&(!s||O.current===s.request)){let t=e.state.selection.main.head,n=e.state.doc.lineAt(t);h?.({line:n.number,column:t-n.from+1,language:V&&Z||`纯文本`,highlight:V?X:`plain`,navigation:L.current,selections:e.state.selection.ranges.length})}},[H,fe,pe,V,Z,X,h,K,s?.request]),(0,m.useEffect)(()=>()=>h?.(),[h]),(0,_.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":Y,"data-file-content-truncated":J.length>v?`1`:`0`,"data-file-selection":W,"data-editor-selection-count":K,"data-file-editor-ready":H?`1`:`0`,"data-file-blame-gutter":q?`1`:void 0,onMouseDown:e=>{e.target.closest(`.cm-panels`)||E.current?.focus()},children:[(0,_.jsx)(`div`,{className:`file-cm`,ref:w,"aria-label":`${x?`查看`:`编辑`} ${e}`}),(0,_.jsx)(`div`,{className:`workbench-editor-search`,ref:T,"data-editor-find-host":`file`}),(!H||!h)&&(0,_.jsxs)(`div`,{className:`file-editor-status`,children:[!H&&(0,_.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),H&&Q!==void 0&&$&&(0,_.jsxs)(`span`,{children:[`第 `,$.number,` 行,第 `,Q-$.from+1,` 列`]}),H&&!V&&(0,_.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),H&&V&&Z&&(0,_.jsx)(`span`,{"data-file-highlight-status":X,children:Z})]})]})}export{b as CodeMirrorEditor,ee as n,te as t,y as themeHighlightStyle};
|
|
2
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{C as t,S as n,T as r,c as i,d as a,i as o,l as s,o as c,r as l,s as u,u as d,w as f,x as p}from"./index-COe1c4FI.js";var m=e(r(),1);function ee(e,t,n,r){return[n.EditorView.decorations.compute([`selection`,`doc`],e=>n.Decoration.set(e.selection.ranges.filter(e=>!e.empty).map(e=>n.Decoration.mark({class:`cm-workbench-selectedText`}).range(e.from,e.to)),!0)),n.ViewPlugin.define(e=>{let n=null,i,a=!1,o=e=>{n&&(e===`expanded`?(a=!a,l()):n.querySelector(`input[name="${e===`caseSensitive`?`case`:e===`wholeWord`?`word`:`re`}"]`)?.click())},c=e=>{let t=s(e);t&&(e.preventDefault(),e.stopPropagation(),o(t))},l=()=>{if(!n||!i)return;let r=t.getSearchQuery(e.state);if(n.dataset.editorSearchExpanded=String(a),i.update({caseSensitive:r.caseSensitive,wholeWord:r.wholeWord,regexp:r.regexp,expanded:a}),n.querySelector(`[data-find-error]`)?.remove(),r.search&&!r.valid){let e=document.createElement(`output`);e.dataset.findError=``,e.setAttribute(`role`,`alert`),e.textContent=`正则表达式无效`,n.append(e)}},u=()=>{let s=r.querySelector(`.cm-panel.cm-search`);if(s===n)return;if(n?.removeEventListener(`keydown`,c,!0),i?.destroy(),n=s,!n){i=void 0;return}for(let[e,t,r]of[[`next`,`↓`,`下一处`],[`prev`,`↑`,`上一处`]]){let i=n.querySelector(`button[name="${e}"]`);i&&(i.textContent=t,i.setAttribute(`aria-label`,r),i.title=r)}let u=document.createElement(`span`);u.dataset.findControls=``,n.prepend(u);let f=t.getSearchQuery(e.state);a=!1,i=d(u,{...f,expanded:a},o),n.addEventListener(`keydown`,c,!0),l()},f=new MutationObserver(u);return f.observe(r,{childList:!0,subtree:!0}),u(),{update(){l()},destroy(){f.disconnect(),n?.removeEventListener(`keydown`,c,!0),i?.destroy()}}}),e.Prec.highest(n.keymap.of([{key:`Mod-Shift-l`,run:t.selectSelectionMatches},{key:`Mod-h`,scope:`editor search-panel`,run:e=>(t.searchPanelOpen(e.state)||t.openSearchPanel(e),requestAnimationFrame(()=>{e.dom.isConnected&&r.querySelector(`[data-editor-search-options][aria-expanded="false"]`)?.click()}),!0)},...[`c`,`w`,`r`].map(e=>({key:`Alt-${e}`,run:n=>{t.searchPanelOpen(n.state)||t.openSearchPanel(n);let r=t.getSearchQuery(n.state);return n.dispatch({effects:t.setSearchQuery.of(new t.SearchQuery({...r,...e===`c`?{caseSensitive:!r.caseSensitive}:e===`w`?{wholeWord:!r.wholeWord}:{regexp:!r.regexp}}))}),!0}}))])),n.panels({topContainer:r}),n.EditorView.scrollMargins.of(()=>({top:r.querySelector(`.cm-search`)?Math.min(r.getBoundingClientRect().height+8,Math.max(0,(r.parentElement?.clientHeight??0)-32)):0})),t.highlightSelectionMatches({wholeWords:!0,minSelectionLength:1,maxMatches:1e3}),t.search({top:!0}),e.EditorState.phrases.of({Find:`查找`,Replace:`替换为`,next:`下一处`,previous:`上一处`,all:`全部选中`,"match case":`区分大小写`,regexp:`正则表达式`,"by word":`全词匹配`,replace:`替换`,"replace all":`全部替换`,close:`关闭查找`,"current match":`当前匹配`,"on line":`所在行`})]}function te(e,t,n,r,a){let o=new e.Compartment,s=()=>{let r=c();return[e.EditorState.tabSize.of(r.tabSize),n.indentUnit.of(r.indent===`tabs`?` `:` `.repeat(r.tabSize)),r.wrap?t.EditorView.lineWrapping:[],r.whitespace?[t.highlightWhitespace(),t.highlightTrailingWhitespace()]:[]]};return[e.EditorState.allowMultipleSelections.of(!0),t.rectangularSelection(),t.crosshairCursor({key:`Alt`}),e.EditorState.phrases.of({"folded code":`已折叠代码`,unfold:`展开代码`,"Fold line":`折叠代码`,"Unfold line":`展开代码`}),t.highlightActiveLineGutter(),t.highlightSpecialChars(),t.dropCursor(),n.bracketMatching(),n.indentOnInput(),n.foldGutter(),r.closeBrackets(),e.Prec.highest(t.keymap.of([...r.closeBracketsKeymap,...n.foldKeymap,{key:`Alt-z`,run:()=>(u({wrap:!c().wrap}),!0)},{key:`Mod-Shift-z`,run:a.redo},{key:`Mod-y`,run:a.redo}])),o.of(s()),t.ViewPlugin.define(e=>({destroy:i(()=>{e.dispatch({effects:o.reconfigure(s())})})}))]}var h=new Map;function ne(e){let t=h.get(e);return t&&(h.delete(e),h.set(e,t)),t}function g(e,t){h.delete(e),h.set(e,t);let n=[...h.values()].reduce((e,t)=>e+t.state.doc.length,0);for(;h.size>32||n>16777216;){let e=h.keys().next().value;n-=h.get(e).state.doc.length,h.delete(e)}}var _=f(),re=262144,v=131072;function ie(e){return e.split(`.`).pop()?.toLowerCase()??``}function y(e,t,n=!1){let r=e=>n?`var(--git-diff-${e.slice(5)}, var(${e}))`:`var(${e})`;return e.HighlightStyle.define([{tag:t.tags.keyword,color:r(`--cm-keyword`)},{tag:t.tags.string,color:r(`--cm-string`)},{tag:t.tags.number,color:r(`--cm-number`)},{tag:t.tags.comment,color:r(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:r(`--cm-function`)},{tag:t.tags.typeName,color:r(`--cm-type`)},{tag:t.tags.className,color:r(`--cm-type`)},{tag:t.tags.propertyName,color:r(`--cm-property`)},{tag:t.tags.operator,color:r(`--cm-operator`)},{tag:t.tags.variableName,color:r(`--cm-variable`)}])}function b({path:e,value:r,onChange:i,jumpToLine:s,onSave:c,workspaceId:u,cwd:d=``,blame:f,onPosition:h,onView:b,readOnly:x=!1,languageOverride:S,onReviewLine:C}){let w=(0,m.useRef)(null),T=(0,m.useRef)(null),E=(0,m.useRef)(null),ae=(0,m.useRef)(null),D=JSON.stringify([u,d,e]),O=(0,m.useRef)(void 0),k=(0,m.useRef)(null),A=(0,m.useRef)(null),oe=(0,m.useRef)(null),j=(0,m.useRef)(null),M=(0,m.useRef)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(i),F=(0,m.useRef)(c),I=(0,m.useRef)(r);I.current=r;let L=(0,m.useRef)(!1),R=(0,m.useRef)(b);R.current=b;let z=(0,m.useRef)(C);z.current=C;let B=!!C;P.current=i,F.current=c;let[V,se]=(0,m.useState)(!1),[H,U]=(0,m.useState)(!1),[W,ce]=(0,m.useState)(`0,0`),[G,le]=(0,m.useState)(0),[K,ue]=(0,m.useState)(1);(0,m.useEffect)(()=>{let i=!1,s,c,l,u,d;return(async()=>{try{let f=S??ie(e),p=n(f),[m,h,g,_,v,b,C,V,H]=await Promise.all([t(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([0,1])),t(()=>import(`./dist-DTIPfQj7.js`).then(e=>e.s),__vite__mapDeps([2,1,0])),t(()=>import(`./dist-S5ntGzJB.js`),__vite__mapDeps([3,0,1,2,4,5])),t(()=>import(`./dist-Qjm1p8SR.js`),__vite__mapDeps([6,0,1,2])),t(()=>import(`./dist-DP4hrTBF.js`).then(e=>e.d),__vite__mapDeps([5,1,0,2,4])),t(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),p?p().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${f}:`,e),null)):Promise.resolve(null),o().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null)),t(()=>import(`./dist-BJHpSQV1.js`).then(e=>e.r),__vite__mapDeps([7,1,0,2,5,4]))]);if(i||!w.current||!T.current)return;ae.current=h.EditorView,u=v,d=b,A.current=m.Annotation.define(),oe.current=m.Transaction.addToHistory;let W=r.length<=re&&C!==null;c=new m.Compartment;let G=[h.lineNumbers(),h.highlightActiveLine(),h.drawSelection(),g.history(),h.keymap.of([g.indentWithTab,...g.defaultKeymap,...g.historyKeymap,..._.searchKeymap,{key:`Mod-s`,run:()=>(F.current(),!0)}]),h.EditorView.updateListener.of(e=>{e.docChanged&&!(A.current&&e.transactions.some(e=>e.annotation(A.current)===!0))&&P.current(e.state.doc.toString()),e.selectionSet&&ce(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),h.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(B&&G.push(a(h,e=>z.current?.(e),`file`)),G.push(h.EditorView.updateListener.of(e=>{e.selectionSet&&ue(e.state.selection.ranges.length),e.docChanged?L.current=!1:e.selectionSet&&(L.current=e.transactions.some(e=>e.isUserEvent(`select.search`)||e.isUserEvent(`select.pointer`)))}),ee(m,_,h,T.current),te(m,h,v,H,g)),x&&G.push(m.EditorState.readOnly.of(!0),h.EditorView.editable.of(!1),h.EditorView.contentAttributes.of({tabindex:`0`})),V&&!x&&(l=new m.Compartment,G.splice(1,0,l.of([])),G.push(V.base)),C)try{G.push(C)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${f}:`,e),W=!1}if(W&&c&&u&&d)try{G.push(c.of(u.syntaxHighlighting(y(u,d))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${f}:`,e),W=!1}let K=ne(D),q=K&&K.state.doc.toString()===I.current,J=q?K.state.update({effects:m.StateEffect.reconfigure.of(G)}).state:m.EditorState.create({doc:I.current,extensions:G});if(s=new h.EditorView({state:J,parent:w.current}),O.current=q?K.jump:void 0,ue(s.state.selection.ranges.length),ce(`${s.state.selection.main.from},${s.state.selection.main.to}`),q&&(s.scrollDOM.scrollTop=K.top,s.scrollDOM.scrollLeft=K.left,O.current=K.jump),i){s.destroy();return}E.current=s,R.current?.(s),se(W),U(!0),j.current=V,M.current=l??null,N.current=null,le(e=>e+1);let Y=new MutationObserver(()=>{let e=E.current;if(e&&W&&c&&u&&d)try{e.dispatch({effects:c.reconfigure(u.syntaxHighlighting(y(u,d)))})}catch{}});k.current=Y,Y.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),i||U(!0)}})(),()=>{i=!0,k.current?.disconnect(),k.current=null,s&&g(D,{state:s.state,top:s.scrollDOM.scrollTop,left:s.scrollDOM.scrollLeft,jump:O.current}),s?.destroy(),E.current=null,R.current?.(),U(!1),w.current&&(w.current.textContent=``)}},[D,x,S,B]),(0,m.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.state.doc.toString();t!==r&&e.dispatch({changes:{from:0,to:t.length,insert:r},annotations:A.current?A.current.of(!0):void 0})},[r,H]),(0,m.useEffect)(()=>{let e=E.current;if(!e||!s||O.current===s.request)return;O.current=s.request;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},effects:ae.current?.scrollIntoView(n,{y:`start`,yMargin:Math.round(e.scrollDOM.clientHeight/3)})}),e.focus()},[s,H]);let q=!!(f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u);(0,m.useEffect)(()=>{let t=E.current,n=j.current,r=M.current;if(!t||!n||!r)return;let i=f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u?f.response:null,a=i?l(i):null;N.current!==a&&(N.current=a,t.dispatch({effects:[n.setBlame.of(a),r.reconfigure(a?n.gutter:[])]}))},[f?.state,f?.response,f?.path,f?.workspaceId,e,u,G]);let J=E.current?.state.doc.toString()??r,Y=J.length<=v?J:J.slice(0,v),X=S??ie(e),Z=p(X),de=E.current?.state,Q=de?.selection.main.head,$=Q===void 0?void 0:de?.doc.lineAt(Q),fe=$?.number,pe=Q!==void 0&&$?Q-$.from+1:void 0;return(0,m.useEffect)(()=>{let e=E.current;if(H&&e&&(!s||O.current===s.request)){let t=e.state.selection.main.head,n=e.state.doc.lineAt(t);h?.({line:n.number,column:t-n.from+1,language:V&&Z||`纯文本`,highlight:V?X:`plain`,navigation:L.current,selections:e.state.selection.ranges.length})}},[H,fe,pe,V,Z,X,h,K,s?.request]),(0,m.useEffect)(()=>()=>h?.(),[h]),(0,_.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":Y,"data-file-content-truncated":J.length>v?`1`:`0`,"data-file-selection":W,"data-editor-selection-count":K,"data-file-editor-ready":H?`1`:`0`,"data-file-blame-gutter":q?`1`:void 0,onMouseDown:e=>{e.target.closest(`.cm-panels`)||E.current?.focus()},children:[(0,_.jsx)(`div`,{className:`file-cm`,ref:w,"aria-label":`${x?`查看`:`编辑`} ${e}`}),(0,_.jsx)(`div`,{className:`workbench-editor-search`,ref:T,"data-editor-find-host":`file`}),(!H||!h)&&(0,_.jsxs)(`div`,{className:`file-editor-status`,children:[!H&&(0,_.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),H&&Q!==void 0&&$&&(0,_.jsxs)(`span`,{children:[`第 `,$.number,` 行,第 `,Q-$.from+1,` 列`]}),H&&!V&&(0,_.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),H&&V&&Z&&(0,_.jsx)(`span`,{"data-file-highlight-status":X,children:Z})]})]})}export{b as CodeMirrorEditor,ee as n,te as t,y as themeHighlightStyle};
|