inkmap-mcp 0.2.6 → 0.2.9
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/README.md +23 -3
- package/dist/bundles/antigravity/sidecars/inkmap/bridge.js +647 -80
- package/dist/bundles/antigravity/sidecars/inkmap/main.mjs +62 -36
- package/dist/bundles/codex/inkmap-codex/.codex-plugin/plugin.json +1 -1
- package/dist/bundles/codex/inkmap-codex/plugin.json +1 -1
- package/dist/bundles/vscode/dist/extension.js +1764 -0
- package/dist/bundles/vscode/images/icon.png +0 -0
- package/dist/bundles/vscode/package.json +243 -0
- package/dist/bundles/vscode/package.nls.json +19 -0
- package/dist/bundles/vscode/package.nls.zh-cn.json +19 -0
- package/dist/cli.cjs +753 -172
- package/dist/codex.html +948 -651
- package/dist/web/app.css +1 -1
- package/dist/web/app.js +26429 -25897
- package/dist/web/index.html +44 -5
- package/package.json +10 -2
- package/server.json +2 -2
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
window.INKMAP_ASSET_BASE = "/api/doc-asset?path=";
|
|
6
6
|
window.INKMAP_LOCALE = navigator.language;
|
|
7
|
+
window.INKMAP_ACCOUNT_MODE = "restore";
|
|
7
8
|
|
|
8
9
|
const params = new URLSearchParams(window.location.search);
|
|
9
10
|
const initialRequestedFile = params.get("file") || "";
|
|
@@ -69,14 +70,301 @@
|
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
let fileSelectEl = null;
|
|
73
|
+
let fileTriggerBtn = null;
|
|
74
|
+
let fileTriggerNameEl = null;
|
|
75
|
+
let fileTriggerDirEl = null;
|
|
76
|
+
let filePopoverEl = null;
|
|
77
|
+
let fileSearchInputEl = null;
|
|
78
|
+
let fileTreeBodyEl = null;
|
|
79
|
+
let cachedFiles = [];
|
|
80
|
+
const expandedKeys = new Set();
|
|
81
|
+
let initializedExpansionForFile = "";
|
|
72
82
|
let openRawBtn = null;
|
|
73
83
|
let splitMdBtn = null;
|
|
74
84
|
let mdPaneEl = null;
|
|
75
85
|
let mdTextareaEl = null;
|
|
76
86
|
let mdTitleEl = null;
|
|
87
|
+
let mdLineBadgeEl = null;
|
|
88
|
+
let mdCloseBtnEl = null;
|
|
89
|
+
let mdGutterEl = null;
|
|
90
|
+
let mdBandEl = null;
|
|
77
91
|
let splitOpen = false;
|
|
78
92
|
let splitWidthPct = 42;
|
|
79
93
|
let mdEditTimer = 0;
|
|
94
|
+
let activeStartLine = 0;
|
|
95
|
+
let activeEndLine = 0;
|
|
96
|
+
|
|
97
|
+
function parseFileEntry(item) {
|
|
98
|
+
const label = typeof item.label === "string" ? item.label : "";
|
|
99
|
+
const sepIdx = label.indexOf(" / ");
|
|
100
|
+
if (sepIdx > 0) {
|
|
101
|
+
const project = label.slice(0, sepIdx).trim();
|
|
102
|
+
const rel = label.slice(sepIdx + 3).replace(/\\/g, "/");
|
|
103
|
+
return { project, rel, item };
|
|
104
|
+
}
|
|
105
|
+
const rel = (label || (item.path || "").split(/[\\/]/).pop() || "").replace(/\\/g, "/");
|
|
106
|
+
const normPath = (item.path || "").replace(/\\/g, "/");
|
|
107
|
+
const suffix = "/" + rel;
|
|
108
|
+
let project = text("当前项目", "Workspace");
|
|
109
|
+
if (normPath.endsWith(suffix)) {
|
|
110
|
+
const rootDir = normPath.slice(0, normPath.length - suffix.length);
|
|
111
|
+
project = rootDir.split("/").filter(Boolean).pop() || project;
|
|
112
|
+
}
|
|
113
|
+
return { project, rel, item };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function buildProjectTree(files, filterText = "") {
|
|
117
|
+
const q = filterText.trim().toLowerCase();
|
|
118
|
+
const projectMap = new Map();
|
|
119
|
+
|
|
120
|
+
for (const raw of files) {
|
|
121
|
+
const { project, rel, item } = parseFileEntry(raw);
|
|
122
|
+
if (q && !project.toLowerCase().includes(q) && !rel.toLowerCase().includes(q)) continue;
|
|
123
|
+
let proj = projectMap.get(project);
|
|
124
|
+
if (!proj) {
|
|
125
|
+
proj = {
|
|
126
|
+
name: project,
|
|
127
|
+
key: `proj:${project}`,
|
|
128
|
+
active: item.group === "active",
|
|
129
|
+
count: 0,
|
|
130
|
+
root: { name: "", key: `proj:${project}`, folders: new Map(), files: [] },
|
|
131
|
+
};
|
|
132
|
+
projectMap.set(project, proj);
|
|
133
|
+
}
|
|
134
|
+
if (item.group === "active") proj.active = true;
|
|
135
|
+
proj.count++;
|
|
136
|
+
|
|
137
|
+
const parts = rel.split("/").filter(Boolean);
|
|
138
|
+
const fileName = parts.pop() || rel;
|
|
139
|
+
let curr = proj.root;
|
|
140
|
+
let pathAcc = `proj:${project}`;
|
|
141
|
+
for (const seg of parts) {
|
|
142
|
+
pathAcc += `/${seg}`;
|
|
143
|
+
let next = curr.folders.get(seg);
|
|
144
|
+
if (!next) {
|
|
145
|
+
next = { name: seg, key: pathAcc, folders: new Map(), files: [] };
|
|
146
|
+
curr.folders.set(seg, next);
|
|
147
|
+
}
|
|
148
|
+
curr = next;
|
|
149
|
+
}
|
|
150
|
+
curr.files.push({
|
|
151
|
+
name: fileName,
|
|
152
|
+
path: item.path,
|
|
153
|
+
rel,
|
|
154
|
+
project,
|
|
155
|
+
isMarkmap: /\.markmap\.md$/i.test(fileName),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function compactAndSort(folder) {
|
|
160
|
+
const compacted = [];
|
|
161
|
+
for (const child of folder.folders.values()) {
|
|
162
|
+
while (child.files.length === 0 && child.folders.size === 1) {
|
|
163
|
+
const onlySub = [...child.folders.values()][0];
|
|
164
|
+
child.name = `${child.name}/${onlySub.name}`;
|
|
165
|
+
child.key = onlySub.key;
|
|
166
|
+
child.folders = onlySub.folders;
|
|
167
|
+
child.files = onlySub.files;
|
|
168
|
+
}
|
|
169
|
+
compactAndSort(child);
|
|
170
|
+
compacted.push(child);
|
|
171
|
+
}
|
|
172
|
+
compacted.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" }));
|
|
173
|
+
folder.sortedFolders = compacted;
|
|
174
|
+
folder.files.sort((a, b) => {
|
|
175
|
+
if (a.isMarkmap !== b.isMarkmap) return a.isMarkmap ? -1 : 1;
|
|
176
|
+
return a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" });
|
|
177
|
+
});
|
|
178
|
+
let total = folder.files.length;
|
|
179
|
+
for (const c of compacted) total += c.totalFiles || 0;
|
|
180
|
+
folder.totalFiles = total;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const projects = [...projectMap.values()];
|
|
184
|
+
for (const p of projects) compactAndSort(p.root);
|
|
185
|
+
projects.sort((a, b) => {
|
|
186
|
+
if (a.active !== b.active) return a.active ? -1 : 1;
|
|
187
|
+
return a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: "base" });
|
|
188
|
+
});
|
|
189
|
+
return projects;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function ensureSelectedAncestorsExpanded(projects, selectedPath) {
|
|
193
|
+
if (!selectedPath || initializedExpansionForFile === selectedPath) return;
|
|
194
|
+
initializedExpansionForFile = selectedPath;
|
|
195
|
+
for (const p of projects) {
|
|
196
|
+
if (p.active) expandedKeys.add(p.key);
|
|
197
|
+
function markFolder(folder) {
|
|
198
|
+
let hasSelected = folder.files.some(f => f.path === selectedPath);
|
|
199
|
+
for (const sub of folder.sortedFolders || []) {
|
|
200
|
+
if (markFolder(sub)) hasSelected = true;
|
|
201
|
+
}
|
|
202
|
+
if (hasSelected) expandedKeys.add(folder.key);
|
|
203
|
+
return hasSelected;
|
|
204
|
+
}
|
|
205
|
+
if (markFolder(p.root)) {
|
|
206
|
+
expandedKeys.add(p.key);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function renderTreeDom() {
|
|
212
|
+
if (!fileTreeBodyEl) return;
|
|
213
|
+
const filterText = fileSearchInputEl ? fileSearchInputEl.value : "";
|
|
214
|
+
const isFiltering = Boolean(filterText.trim());
|
|
215
|
+
const projects = buildProjectTree(cachedFiles, filterText);
|
|
216
|
+
ensureSelectedAncestorsExpanded(projects, currentFile);
|
|
217
|
+
|
|
218
|
+
fileTreeBodyEl.innerHTML = "";
|
|
219
|
+
if (!projects.length) {
|
|
220
|
+
const empty = document.createElement("div");
|
|
221
|
+
empty.className = "ag-tree-empty";
|
|
222
|
+
empty.textContent = isFiltering
|
|
223
|
+
? text("无匹配的 Markdown 文件", "No matching Markdown files")
|
|
224
|
+
: text("未找到 Markdown 文件", "No Markdown files");
|
|
225
|
+
fileTreeBodyEl.appendChild(empty);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const chevronSvg = `<svg class="ag-tree-chevron" viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l4 4-4 4"/></svg>`;
|
|
230
|
+
const folderSvg = `<svg class="ag-tree-icon ag-icon-folder" viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M1.75 2.5A1.75 1.75 0 0 0 0 4.25v7.5C0 12.716.784 13.5 1.75 13.5h12.5A1.75 1.75 0 0 0 16 11.75v-5.5A1.75 1.75 0 0 0 14.25 4.5H7.82a.25.25 0 0 1-.177-.073L6.28 3.063A1.75 1.75 0 0 0 5.043 2.5H1.75Z"/></svg>`;
|
|
231
|
+
const mapFileSvg = `<svg class="ag-tree-icon ag-icon-map" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="3.5" cy="8" r="1.75"/><circle cx="12.5" cy="4" r="1.75"/><circle cx="12.5" cy="12" r="1.75"/><path d="M5.25 7.3L10.75 4.7M5.25 8.7l5.5 2.6"/></svg>`;
|
|
232
|
+
const mdFileSvg = `<svg class="ag-tree-icon ag-icon-md" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M9.5 1.5H4A1.5 1.5 0 0 0 2.5 3v10A1.5 1.5 0 0 0 4 14.5h8a1.5 1.5 0 0 0 1.5-1.5V5.5L9.5 1.5Z"/><path d="M9.5 1.5v4h4"/></svg>`;
|
|
233
|
+
|
|
234
|
+
const renderFolderContents = (folder, container, depth) => {
|
|
235
|
+
for (const sub of folder.sortedFolders || []) {
|
|
236
|
+
const isOpen = isFiltering || expandedKeys.has(sub.key);
|
|
237
|
+
const folderWrap = document.createElement("div");
|
|
238
|
+
folderWrap.className = "ag-tree-group";
|
|
239
|
+
|
|
240
|
+
const row = document.createElement("button");
|
|
241
|
+
row.type = "button";
|
|
242
|
+
row.className = `ag-tree-row ag-tree-folder ${isOpen ? "is-open" : ""}`;
|
|
243
|
+
row.style.paddingLeft = `${10 + depth * 14}px`;
|
|
244
|
+
row.innerHTML = `${chevronSvg}${folderSvg}<span class="ag-tree-label"></span><span class="ag-tree-count">${sub.totalFiles}</span>`;
|
|
245
|
+
row.querySelector(".ag-tree-label").textContent = sub.name;
|
|
246
|
+
row.title = sub.name;
|
|
247
|
+
row.addEventListener("click", e => {
|
|
248
|
+
e.stopPropagation();
|
|
249
|
+
if (expandedKeys.has(sub.key)) expandedKeys.delete(sub.key);
|
|
250
|
+
else expandedKeys.add(sub.key);
|
|
251
|
+
renderTreeDom();
|
|
252
|
+
});
|
|
253
|
+
folderWrap.appendChild(row);
|
|
254
|
+
|
|
255
|
+
if (isOpen) {
|
|
256
|
+
const childrenBox = document.createElement("div");
|
|
257
|
+
childrenBox.className = "ag-tree-children";
|
|
258
|
+
renderFolderContents(sub, childrenBox, depth + 1);
|
|
259
|
+
folderWrap.appendChild(childrenBox);
|
|
260
|
+
}
|
|
261
|
+
container.appendChild(folderWrap);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (const file of folder.files) {
|
|
265
|
+
const isSelected = file.path === currentFile;
|
|
266
|
+
const fileBtn = document.createElement("button");
|
|
267
|
+
fileBtn.type = "button";
|
|
268
|
+
fileBtn.className = `ag-tree-row ag-tree-file ${isSelected ? "is-selected" : ""}`;
|
|
269
|
+
fileBtn.style.paddingLeft = `${10 + depth * 14}px`;
|
|
270
|
+
fileBtn.innerHTML = `<span class="ag-tree-Check">${isSelected ? "✓" : ""}</span>${file.isMarkmap ? mapFileSvg : mdFileSvg}<span class="ag-tree-label"></span>${file.isMarkmap ? `<span class="ag-tree-tag">${text("导图", "Map")}</span>` : ""}`;
|
|
271
|
+
fileBtn.querySelector(".ag-tree-label").textContent = file.name;
|
|
272
|
+
fileBtn.title = `${file.project} / ${file.rel}`;
|
|
273
|
+
fileBtn.addEventListener("click", e => {
|
|
274
|
+
e.stopPropagation();
|
|
275
|
+
closeFilePopover();
|
|
276
|
+
void switchFile(file.path);
|
|
277
|
+
});
|
|
278
|
+
container.appendChild(fileBtn);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
for (const proj of projects) {
|
|
283
|
+
const isOpen = isFiltering || expandedKeys.has(proj.key) || projects.length === 1;
|
|
284
|
+
const projWrap = document.createElement("div");
|
|
285
|
+
projWrap.className = "ag-tree-project";
|
|
286
|
+
|
|
287
|
+
if (projects.length > 1 || !proj.active) {
|
|
288
|
+
const headerBtn = document.createElement("button");
|
|
289
|
+
headerBtn.type = "button";
|
|
290
|
+
headerBtn.className = `ag-tree-row ag-tree-proj-header ${isOpen ? "is-open" : ""}`;
|
|
291
|
+
headerBtn.innerHTML = `${chevronSvg}${folderSvg}<span class="ag-tree-label"></span>${proj.active ? `<span class="ag-tree-active-badge">${text("当前工作区", "Workspace")}</span>` : ""}<span class="ag-tree-count">${proj.count}</span>`;
|
|
292
|
+
headerBtn.querySelector(".ag-tree-label").textContent = proj.name;
|
|
293
|
+
headerBtn.addEventListener("click", e => {
|
|
294
|
+
e.stopPropagation();
|
|
295
|
+
if (expandedKeys.has(proj.key)) expandedKeys.delete(proj.key);
|
|
296
|
+
else expandedKeys.add(proj.key);
|
|
297
|
+
renderTreeDom();
|
|
298
|
+
});
|
|
299
|
+
projWrap.appendChild(headerBtn);
|
|
300
|
+
} else {
|
|
301
|
+
const topHeader = document.createElement("div");
|
|
302
|
+
topHeader.className = "ag-tree-proj-banner";
|
|
303
|
+
topHeader.innerHTML = `${folderSvg}<span class="ag-tree-label"></span><span class="ag-tree-active-badge">${text("当前工作区", "Workspace")}</span><span class="ag-tree-count">${proj.count}</span>`;
|
|
304
|
+
topHeader.querySelector(".ag-tree-label").textContent = proj.name;
|
|
305
|
+
projWrap.appendChild(topHeader);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (isOpen) {
|
|
309
|
+
const body = document.createElement("div");
|
|
310
|
+
body.className = "ag-tree-proj-body";
|
|
311
|
+
renderFolderContents(proj.root, body, projects.length > 1 ? 1 : 0);
|
|
312
|
+
projWrap.appendChild(body);
|
|
313
|
+
}
|
|
314
|
+
fileTreeBodyEl.appendChild(projWrap);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function closeFilePopover() {
|
|
319
|
+
if (!filePopoverEl || filePopoverEl.hidden) return;
|
|
320
|
+
filePopoverEl.hidden = true;
|
|
321
|
+
if (fileTriggerBtn) fileTriggerBtn.setAttribute("aria-expanded", "false");
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function toggleFilePopover() {
|
|
325
|
+
if (!filePopoverEl) return;
|
|
326
|
+
const nextOpen = filePopoverEl.hidden;
|
|
327
|
+
if (nextOpen) {
|
|
328
|
+
renderTreeDom();
|
|
329
|
+
filePopoverEl.hidden = false;
|
|
330
|
+
if (fileTriggerBtn) fileTriggerBtn.setAttribute("aria-expanded", "true");
|
|
331
|
+
requestAnimationFrame(() => {
|
|
332
|
+
const selectedRow = fileTreeBodyEl?.querySelector(".ag-tree-file.is-selected");
|
|
333
|
+
if (selectedRow) selectedRow.scrollIntoView({ block: "nearest" });
|
|
334
|
+
fileSearchInputEl?.focus();
|
|
335
|
+
});
|
|
336
|
+
} else {
|
|
337
|
+
closeFilePopover();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function renderMdGutterAndBand() {
|
|
342
|
+
if (!mdTextareaEl) return;
|
|
343
|
+
const totalLines = Math.max(1, mdTextareaEl.value.split("\n").length);
|
|
344
|
+
const sLine = Math.max(0, Math.min(activeStartLine, totalLines - 1));
|
|
345
|
+
const eLine = Math.max(sLine, Math.min(activeEndLine, totalLines - 1));
|
|
346
|
+
if (mdLineBadgeEl) {
|
|
347
|
+
const label = sLine === eLine ? `${sLine + 1}` : `${sLine + 1}–${eLine + 1}`;
|
|
348
|
+
mdLineBadgeEl.textContent = text(`行 ${label}`, `Ln ${label}`);
|
|
349
|
+
}
|
|
350
|
+
if (mdGutterEl) {
|
|
351
|
+
const nums = [];
|
|
352
|
+
for (let i = 0; i < totalLines; i++) {
|
|
353
|
+
const active = i >= sLine && i <= eLine;
|
|
354
|
+
nums.push(`<div class="ag-gutter-ln${active ? " is-active" : ""}">${i + 1}</div>`);
|
|
355
|
+
}
|
|
356
|
+
mdGutterEl.innerHTML = nums.join("");
|
|
357
|
+
mdGutterEl.scrollTop = mdTextareaEl.scrollTop;
|
|
358
|
+
}
|
|
359
|
+
if (mdBandEl) {
|
|
360
|
+
const lineHeight = 20.8;
|
|
361
|
+
const padTop = 12;
|
|
362
|
+
const top = padTop + sLine * lineHeight - mdTextareaEl.scrollTop;
|
|
363
|
+
const height = Math.max(1, eLine - sLine + 1) * lineHeight;
|
|
364
|
+
mdBandEl.style.transform = `translateY(${top}px)`;
|
|
365
|
+
mdBandEl.style.height = `${height}px`;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
80
368
|
|
|
81
369
|
function syncMdPaneContent(md = currentMd, force = false) {
|
|
82
370
|
if (mdTitleEl) {
|
|
@@ -88,6 +376,7 @@
|
|
|
88
376
|
if (force || document.activeElement !== mdTextareaEl) {
|
|
89
377
|
if (mdTextareaEl.value !== md) mdTextareaEl.value = md;
|
|
90
378
|
}
|
|
379
|
+
renderMdGutterAndBand();
|
|
91
380
|
}
|
|
92
381
|
|
|
93
382
|
function applySplitLayout(fitAfter = false) {
|
|
@@ -101,6 +390,16 @@
|
|
|
101
390
|
? text("关闭左侧 Markdown,仅保留右侧思维导图", "Close left Markdown pane and keep mind map only")
|
|
102
391
|
: text("开启左 Markdown 文件、右思维导图分屏对比与编辑", "Split screen: Markdown on left, Mind Map on right");
|
|
103
392
|
}
|
|
393
|
+
if (openRawBtn) {
|
|
394
|
+
openRawBtn.textContent = text("原文件", "Raw");
|
|
395
|
+
openRawBtn.title = text("在编辑器中打开 Markdown 原文件(也可关闭原文件仅留导图)", "Open raw Markdown file in editor");
|
|
396
|
+
}
|
|
397
|
+
if (mdCloseBtnEl) {
|
|
398
|
+
mdCloseBtnEl.textContent = text("× 关闭MD", "× Close MD");
|
|
399
|
+
}
|
|
400
|
+
if (fileSearchInputEl) {
|
|
401
|
+
fileSearchInputEl.placeholder = text("搜索项目 Markdown 文件…", "Filter Markdown files…");
|
|
402
|
+
}
|
|
104
403
|
if (splitOpen) syncMdPaneContent(currentMd, true);
|
|
105
404
|
requestAnimationFrame(() => {
|
|
106
405
|
try {
|
|
@@ -111,44 +410,40 @@
|
|
|
111
410
|
}
|
|
112
411
|
|
|
113
412
|
function renderFilePicker(files = [], selected = currentFile) {
|
|
114
|
-
|
|
115
|
-
fileSelectEl
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
opt.value = "";
|
|
119
|
-
opt.textContent = text("未找到 Markdown 文件", "No Markdown files");
|
|
120
|
-
fileSelectEl.appendChild(opt);
|
|
121
|
-
fileSelectEl.disabled = true;
|
|
122
|
-
if (openRawBtn) openRawBtn.disabled = true;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
fileSelectEl.disabled = false;
|
|
126
|
-
if (openRawBtn) openRawBtn.disabled = !selected;
|
|
127
|
-
|
|
128
|
-
const activeFiles = files.filter(f => f.group === "active");
|
|
129
|
-
const projectFiles = files.filter(f => f.group !== "active");
|
|
130
|
-
|
|
131
|
-
const appendOptions = (parent, list) => {
|
|
132
|
-
for (const item of list) {
|
|
413
|
+
cachedFiles = Array.isArray(files) ? files : [];
|
|
414
|
+
if (fileSelectEl) {
|
|
415
|
+
fileSelectEl.innerHTML = "";
|
|
416
|
+
for (const item of cachedFiles) {
|
|
133
417
|
const opt = document.createElement("option");
|
|
134
418
|
opt.value = item.path;
|
|
135
419
|
opt.textContent = item.label;
|
|
136
|
-
opt.title = item.path;
|
|
137
420
|
if (item.path === selected) opt.selected = true;
|
|
138
|
-
|
|
421
|
+
fileSelectEl.appendChild(opt);
|
|
139
422
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
423
|
+
fileSelectEl.disabled = !cachedFiles.length;
|
|
424
|
+
}
|
|
425
|
+
if (openRawBtn) openRawBtn.disabled = !selected;
|
|
426
|
+
if (fileTriggerBtn) {
|
|
427
|
+
fileTriggerBtn.disabled = !cachedFiles.length;
|
|
428
|
+
const found = cachedFiles.find(f => f.path === selected) || cachedFiles[0];
|
|
429
|
+
if (!found) {
|
|
430
|
+
if (fileTriggerNameEl) fileTriggerNameEl.textContent = text("未找到 Markdown 文件", "No Markdown files");
|
|
431
|
+
if (fileTriggerDirEl) fileTriggerDirEl.hidden = true;
|
|
432
|
+
} else {
|
|
433
|
+
const { project, rel } = parseFileEntry(found);
|
|
434
|
+
const parts = rel.split("/").filter(Boolean);
|
|
435
|
+
const fileName = parts.pop() || rel;
|
|
436
|
+
const dirHint = parts.length ? `${project}/${parts[parts.length - 1]}` : project;
|
|
437
|
+
if (fileTriggerNameEl) fileTriggerNameEl.textContent = fileName;
|
|
438
|
+
if (fileTriggerDirEl) {
|
|
439
|
+
fileTriggerDirEl.textContent = dirHint;
|
|
440
|
+
fileTriggerDirEl.hidden = false;
|
|
441
|
+
}
|
|
442
|
+
fileTriggerBtn.title = `${project} / ${rel}`;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (filePopoverEl && !filePopoverEl.hidden) {
|
|
446
|
+
renderTreeDom();
|
|
152
447
|
}
|
|
153
448
|
}
|
|
154
449
|
|
|
@@ -182,56 +477,268 @@
|
|
|
182
477
|
style.textContent = `
|
|
183
478
|
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink-bg) !important; color: var(--ui-text) !important; }
|
|
184
479
|
#map { position: fixed; inset: 0; width: 100vw; height: 100vh; transition: left .12s ease, width .12s ease; }
|
|
185
|
-
:root.ag-split-active #
|
|
186
|
-
|
|
480
|
+
:root.ag-split-active #bar {
|
|
481
|
+
top: 0 !important; left: 0 !important; right: 0 !important;
|
|
482
|
+
min-height: 44px; border-radius: 0 !important;
|
|
483
|
+
border-top: none !important; border-left: none !important; border-right: none !important;
|
|
484
|
+
border-bottom: 1px solid var(--ui-border-strong, rgba(31,35,41,.15)) !important;
|
|
485
|
+
box-shadow: none !important; padding: 4px 10px !important;
|
|
486
|
+
background: var(--ui-solid, #fff) !important;
|
|
487
|
+
}
|
|
488
|
+
:root.ag-split-active #map {
|
|
489
|
+
top: var(--toolbar-height, 44px) !important;
|
|
490
|
+
left: var(--ag-split-left, 42vw) !important;
|
|
491
|
+
width: calc(100vw - var(--ag-split-left, 42vw)) !important;
|
|
492
|
+
height: calc(100vh - var(--toolbar-height, 44px)) !important;
|
|
493
|
+
}
|
|
494
|
+
#ag-file-select { display: none !important; }
|
|
495
|
+
.ag-file-picker-wrap { position: relative; display: inline-flex; align-items: center; }
|
|
496
|
+
#ag-file-trigger {
|
|
497
|
+
display: inline-flex; align-items: center; gap: 5px; max-width: 210px; height: 28px;
|
|
498
|
+
padding: 0 9px; border-radius: 7px; border: 1px solid var(--ui-border-strong, rgba(31,35,41,.14));
|
|
499
|
+
background: var(--ui-subtle, rgba(31,35,41,.04)); color: var(--ui-text, #1f2329);
|
|
500
|
+
font-size: 12.5px; cursor: pointer; transition: background .12s, border-color .12s;
|
|
501
|
+
}
|
|
502
|
+
#ag-file-trigger:hover:not(:disabled), #ag-file-trigger[aria-expanded="true"] {
|
|
503
|
+
background: var(--ui-hover, rgba(31,35,41,.08));
|
|
504
|
+
border-color: color-mix(in srgb, var(--ui-primary, #336df4) 45%, var(--ui-border-strong, rgba(31,35,41,.2)));
|
|
505
|
+
}
|
|
506
|
+
.ag-trigger-icon { flex: none; color: var(--ui-primary, #336df4); display: inline-flex; }
|
|
507
|
+
.ag-trigger-name {
|
|
508
|
+
font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
|
|
509
|
+
}
|
|
510
|
+
.ag-trigger-dir {
|
|
511
|
+
font-size: 11px; color: var(--ui-muted, #646a73); background: color-mix(in srgb, var(--ui-text, #1f2329) 7%, transparent);
|
|
512
|
+
padding: 1px 5px; border-radius: 4px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none;
|
|
513
|
+
}
|
|
514
|
+
.ag-trigger-caret { flex: none; opacity: .65; transition: transform .15s ease; }
|
|
515
|
+
#ag-file-trigger[aria-expanded="true"] .ag-trigger-caret { transform: rotate(180deg); }
|
|
516
|
+
#ag-file-tree-popover {
|
|
517
|
+
position: fixed; top: calc(var(--toolbar-height, 40px) + 14px); left: 10px;
|
|
518
|
+
width: min(360px, calc(100vw - 24px)); max-height: min(72vh, 520px); z-index: 120;
|
|
519
|
+
display: flex; flex-direction: column;
|
|
520
|
+
background: var(--ui-solid, #fff); color: var(--ui-text, #1f2329);
|
|
521
|
+
border: 1px solid var(--ui-border-strong, rgba(31,35,41,.16)); border-radius: 11px;
|
|
522
|
+
box-shadow: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 6px rgba(15, 23, 42, .08);
|
|
523
|
+
overflow: hidden;
|
|
524
|
+
}
|
|
525
|
+
#ag-file-tree-popover[hidden] { display: none !important; }
|
|
526
|
+
.ag-tree-header {
|
|
527
|
+
display: flex; align-items: center; gap: 6px; padding: 8px 10px;
|
|
528
|
+
border-bottom: 1px solid var(--ui-border, rgba(31,35,41,.08));
|
|
529
|
+
background: var(--ui-subtle, #f8f9fb);
|
|
530
|
+
}
|
|
531
|
+
.ag-tree-search-wrap {
|
|
532
|
+
flex: 1; display: flex; align-items: center; gap: 6px;
|
|
533
|
+
background: var(--ui-solid, #fff); border: 1px solid var(--ui-border-strong, rgba(31,35,41,.15));
|
|
534
|
+
border-radius: 6px; padding: 4px 8px;
|
|
535
|
+
}
|
|
536
|
+
.ag-tree-search-wrap:focus-within {
|
|
537
|
+
border-color: var(--ui-primary, #336df4);
|
|
538
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--ui-primary, #336df4) 18%, transparent);
|
|
539
|
+
}
|
|
540
|
+
.ag-tree-search-icon { color: var(--ui-muted, #646a73); flex: none; }
|
|
541
|
+
.ag-tree-search {
|
|
542
|
+
flex: 1; border: 0; outline: none; background: transparent; color: var(--ui-text, #1f2329);
|
|
543
|
+
font-size: 12px; min-width: 0; padding: 0;
|
|
544
|
+
}
|
|
545
|
+
.ag-tree-body {
|
|
546
|
+
flex: 1; overflow-y: auto; padding: 6px 6px 8px;
|
|
547
|
+
scrollbar-width: thin;
|
|
548
|
+
}
|
|
549
|
+
.ag-tree-project + .ag-tree-project {
|
|
550
|
+
margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--ui-border, rgba(31,35,41,.08));
|
|
551
|
+
}
|
|
552
|
+
.ag-tree-proj-banner, .ag-tree-proj-header {
|
|
553
|
+
display: flex; align-items: center; gap: 6px; width: 100%; box-sizing: border-box;
|
|
554
|
+
padding: 5px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 650;
|
|
555
|
+
color: var(--ui-muted, #646a73); letter-spacing: .01em;
|
|
556
|
+
}
|
|
557
|
+
.ag-tree-proj-header {
|
|
558
|
+
border: 0; background: transparent; cursor: pointer; text-align: left;
|
|
559
|
+
}
|
|
560
|
+
.ag-tree-proj-header:hover { background: var(--ui-hover, rgba(31,35,41,.06)); color: var(--ui-text, #1f2329); }
|
|
561
|
+
.ag-tree-active-badge {
|
|
562
|
+
font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px;
|
|
563
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 12%, transparent);
|
|
564
|
+
color: var(--ui-primary, #336df4);
|
|
565
|
+
}
|
|
566
|
+
.ag-tree-row {
|
|
567
|
+
display: flex; align-items: center; gap: 6px; width: 100%; box-sizing: border-box;
|
|
568
|
+
min-height: 27px; padding: 3px 8px; border: 0; border-radius: 6px;
|
|
569
|
+
background: transparent; color: var(--ui-text, #1f2329); font-size: 12.5px;
|
|
570
|
+
cursor: pointer; text-align: left; transition: background .1s;
|
|
571
|
+
}
|
|
572
|
+
.ag-tree-row:hover { background: var(--ui-hover, rgba(31,35,41,.06)); }
|
|
573
|
+
.ag-tree-folder { font-weight: 550; color: var(--ui-text, #1f2329); }
|
|
574
|
+
.ag-tree-chevron {
|
|
575
|
+
flex: none; color: var(--ui-muted, #646a73); transition: transform .14s ease;
|
|
576
|
+
}
|
|
577
|
+
.ag-tree-folder.is-open > .ag-tree-chevron,
|
|
578
|
+
.ag-tree-proj-header.is-open > .ag-tree-chevron {
|
|
579
|
+
transform: rotate(90deg);
|
|
580
|
+
}
|
|
581
|
+
.ag-tree-icon { flex: none; }
|
|
582
|
+
.ag-icon-folder { color: #e09f3e; }
|
|
583
|
+
:root[data-theme="dark"] .ag-icon-folder { color: #f0b454; }
|
|
584
|
+
.ag-icon-map { color: var(--ui-primary, #336df4); }
|
|
585
|
+
.ag-icon-md { color: var(--ui-muted, #646a73); }
|
|
586
|
+
.ag-tree-label {
|
|
587
|
+
flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
588
|
+
}
|
|
589
|
+
.ag-tree-count {
|
|
590
|
+
flex: none; font-size: 10.5px; color: var(--ui-muted, #646a73);
|
|
591
|
+
background: color-mix(in srgb, var(--ui-text, #1f2329) 6%, transparent);
|
|
592
|
+
padding: 0 5px; border-radius: 999px; font-weight: 500;
|
|
593
|
+
}
|
|
594
|
+
.ag-tree-Check {
|
|
595
|
+
width: 12px; flex: none; font-size: 11px; font-weight: 700;
|
|
596
|
+
color: var(--ui-primary, #336df4); text-align: center;
|
|
597
|
+
}
|
|
598
|
+
.ag-tree-tag {
|
|
599
|
+
flex: none; font-size: 10px; font-weight: 600; padding: 0 5px; border-radius: 4px;
|
|
600
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 12%, transparent);
|
|
601
|
+
color: var(--ui-primary, #336df4);
|
|
602
|
+
}
|
|
603
|
+
.ag-tree-file.is-selected {
|
|
604
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 12%, transparent);
|
|
605
|
+
color: var(--ui-primary, #336df4); font-weight: 600;
|
|
606
|
+
}
|
|
607
|
+
.ag-tree-empty {
|
|
608
|
+
padding: 20px 12px; text-align: center; font-size: 12px; color: var(--ui-muted, #646a73);
|
|
609
|
+
}
|
|
187
610
|
#ag-open-raw, #ag-split-md { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
|
|
188
611
|
#ag-split-md[data-active="true"] { background: color-mix(in srgb, var(--ui-primary, #336df4) 14%, transparent); color: var(--ui-primary, #336df4); font-weight: 600; }
|
|
189
612
|
#ag-md-pane {
|
|
190
|
-
position: fixed; top:
|
|
191
|
-
width:
|
|
613
|
+
position: fixed; top: var(--toolbar-height, 44px); left: 0; bottom: 0;
|
|
614
|
+
width: var(--ag-split-left, 42vw); z-index: 30;
|
|
192
615
|
display: flex; flex-direction: column;
|
|
193
616
|
background: var(--ui-solid, #fff); color: var(--ui-text, #1f2329);
|
|
194
|
-
border: 1px solid var(--ui-border-strong, rgba(31,35,41,.
|
|
195
|
-
|
|
617
|
+
border-right: 1px solid var(--ui-border-strong, rgba(31,35,41,.16));
|
|
618
|
+
border-radius: 0; box-shadow: none; overflow: hidden;
|
|
196
619
|
}
|
|
197
620
|
#ag-md-pane[hidden] { display: none !important; }
|
|
198
621
|
.ag-md-header {
|
|
199
|
-
display: flex; align-items: center; justify-content: space-between; gap:
|
|
200
|
-
padding:
|
|
201
|
-
|
|
622
|
+
display: flex; align-items: center; justify-content: space-between; gap: 6px;
|
|
623
|
+
height: 34px; padding: 0 10px; box-sizing: border-box;
|
|
624
|
+
border-bottom: 1px solid var(--ui-border, rgba(31,35,41,.09));
|
|
625
|
+
background: var(--ui-subtle, #f6f7f9); font-size: 12px; flex: none;
|
|
202
626
|
}
|
|
203
627
|
.ag-md-title {
|
|
204
628
|
font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
|
|
205
629
|
}
|
|
630
|
+
.ag-md-line-badge {
|
|
631
|
+
font-size: 11px; font-weight: 560; font-variant-numeric: tabular-nums;
|
|
632
|
+
padding: 1px 6px; border-radius: 4px;
|
|
633
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 12%, transparent);
|
|
634
|
+
color: var(--ui-primary, #336df4); flex: none;
|
|
635
|
+
}
|
|
206
636
|
.ag-md-actions { display: inline-flex; align-items: center; gap: 4px; flex: none; }
|
|
207
637
|
.ag-md-close {
|
|
208
638
|
border: 1px solid var(--ui-border-strong, rgba(31,35,41,.15)); background: var(--ui-solid, #fff);
|
|
209
|
-
color: var(--ui-
|
|
639
|
+
color: var(--ui-muted, #646a73); border-radius: 5px; padding: 2px 7px; font-size: 11px; cursor: pointer;
|
|
640
|
+
}
|
|
641
|
+
.ag-md-close:hover { background: var(--ui-hover, rgba(31,35,41,.06)); color: var(--ui-text, #1f2329); }
|
|
642
|
+
.ag-md-body {
|
|
643
|
+
position: relative; flex: 1; display: flex; min-height: 0; overflow: hidden;
|
|
644
|
+
background: var(--ui-solid, #fff);
|
|
645
|
+
}
|
|
646
|
+
#ag-md-gutter {
|
|
647
|
+
width: 38px; flex: none; overflow: hidden; user-select: none;
|
|
648
|
+
padding: 12px 5px 12px 0; box-sizing: border-box; text-align: right;
|
|
649
|
+
background: color-mix(in srgb, var(--ui-subtle, #f6f7f9) 65%, var(--ui-solid, #fff));
|
|
650
|
+
border-right: 1px solid var(--ui-border, rgba(31,35,41,.08));
|
|
651
|
+
font: 11px/20.8px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
652
|
+
color: var(--ui-muted, #646a73); font-variant-numeric: tabular-nums;
|
|
653
|
+
}
|
|
654
|
+
.ag-gutter-ln { height: 20.8px; padding-right: 3px; }
|
|
655
|
+
.ag-gutter-ln.is-active {
|
|
656
|
+
color: var(--ui-primary, #336df4); font-weight: 700;
|
|
657
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 12%, transparent);
|
|
658
|
+
}
|
|
659
|
+
.ag-md-editor-stage {
|
|
660
|
+
position: relative; flex: 1; min-width: 0; height: 100%; overflow: hidden;
|
|
661
|
+
}
|
|
662
|
+
#ag-md-band {
|
|
663
|
+
position: absolute; left: 0; right: 0; top: 0; height: 20.8px; pointer-events: none;
|
|
664
|
+
background: color-mix(in srgb, var(--ui-primary, #336df4) 10%, transparent);
|
|
665
|
+
border-left: 2.5px solid var(--ui-primary, #336df4);
|
|
666
|
+
transition: transform .06s ease-out, height .06s ease-out;
|
|
210
667
|
}
|
|
211
|
-
.ag-md-close:hover { background: var(--ui-hover, rgba(31,35,41,.06)); }
|
|
212
668
|
#ag-md-textarea {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
669
|
+
position: relative; z-index: 1; width: 100%; height: 100%; box-sizing: border-box;
|
|
670
|
+
border: 0; outline: none; resize: none;
|
|
671
|
+
padding: 12px 12px; background: transparent; color: var(--ui-text, #1f2329);
|
|
672
|
+
font: 13px/20.8px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
673
|
+
tab-size: 2; overflow-y: auto;
|
|
217
674
|
}
|
|
218
675
|
#ag-md-resizer {
|
|
219
|
-
position: absolute; top: 0; right: 0; bottom: 0; width: 5px; cursor: col-resize;
|
|
220
|
-
background: transparent;
|
|
676
|
+
position: absolute; top: 0; right: 0; bottom: 0; width: 5px; z-index: 5; cursor: col-resize;
|
|
677
|
+
background: transparent; transition: background .12s ease;
|
|
221
678
|
}
|
|
222
|
-
#ag-md-resizer:hover { background:
|
|
679
|
+
#ag-md-resizer:hover, #ag-md-resizer:active { background: var(--ui-primary, #336df4); }
|
|
223
680
|
`;
|
|
224
681
|
document.head.appendChild(style);
|
|
225
682
|
|
|
226
683
|
fileSelectEl = document.createElement("select");
|
|
227
684
|
fileSelectEl.id = "ag-file-select";
|
|
228
|
-
fileSelectEl.
|
|
229
|
-
fileSelectEl.title = text("切换要编辑的 Markdown 导图文件", "Switch Markdown file");
|
|
685
|
+
fileSelectEl.hidden = true;
|
|
230
686
|
fileSelectEl.addEventListener("change", () => {
|
|
231
687
|
if (fileSelectEl.value) void switchFile(fileSelectEl.value);
|
|
232
|
-
fileSelectEl.blur();
|
|
233
688
|
});
|
|
234
689
|
|
|
690
|
+
const pickerWrap = document.createElement("div");
|
|
691
|
+
pickerWrap.className = "ag-file-picker-wrap";
|
|
692
|
+
|
|
693
|
+
fileTriggerBtn = document.createElement("button");
|
|
694
|
+
fileTriggerBtn.id = "ag-file-trigger";
|
|
695
|
+
fileTriggerBtn.type = "button";
|
|
696
|
+
fileTriggerBtn.setAttribute("aria-haspopup", "tree");
|
|
697
|
+
fileTriggerBtn.setAttribute("aria-expanded", "false");
|
|
698
|
+
fileTriggerBtn.innerHTML = `
|
|
699
|
+
<span class="ag-trigger-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M1.75 2.5A1.75 1.75 0 0 0 0 4.25v7.5C0 12.716.784 13.5 1.75 13.5h12.5A1.75 1.75 0 0 0 16 11.75v-5.5A1.75 1.75 0 0 0 14.25 4.5H7.82a.25.25 0 0 1-.177-.073L6.28 3.063A1.75 1.75 0 0 0 5.043 2.5H1.75Z"/></svg></span>
|
|
700
|
+
<span class="ag-trigger-name">Markdown</span>
|
|
701
|
+
<span class="ag-trigger-dir" hidden></span>
|
|
702
|
+
<svg class="ag-trigger-caret" viewBox="0 0 12 12" width="11" height="11" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M3 4.5l3 3 3-3"/></svg>
|
|
703
|
+
`;
|
|
704
|
+
fileTriggerNameEl = fileTriggerBtn.querySelector(".ag-trigger-name");
|
|
705
|
+
fileTriggerDirEl = fileTriggerBtn.querySelector(".ag-trigger-dir");
|
|
706
|
+
fileTriggerBtn.addEventListener("click", e => {
|
|
707
|
+
e.stopPropagation();
|
|
708
|
+
toggleFilePopover();
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
filePopoverEl = document.createElement("div");
|
|
712
|
+
filePopoverEl.id = "ag-file-tree-popover";
|
|
713
|
+
filePopoverEl.hidden = true;
|
|
714
|
+
filePopoverEl.innerHTML = `
|
|
715
|
+
<div class="ag-tree-header">
|
|
716
|
+
<div class="ag-tree-search-wrap">
|
|
717
|
+
<svg class="ag-tree-search-icon" viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5L14 14" stroke-linecap="round"/></svg>
|
|
718
|
+
<input type="search" class="ag-tree-search" placeholder="${text("搜索项目 Markdown 文件…", "Filter Markdown files…")}" />
|
|
719
|
+
</div>
|
|
720
|
+
</div>
|
|
721
|
+
<div class="ag-tree-body" role="tree"></div>
|
|
722
|
+
`;
|
|
723
|
+
fileSearchInputEl = filePopoverEl.querySelector(".ag-tree-search");
|
|
724
|
+
fileTreeBodyEl = filePopoverEl.querySelector(".ag-tree-body");
|
|
725
|
+
fileSearchInputEl.addEventListener("input", () => renderTreeDom());
|
|
726
|
+
filePopoverEl.addEventListener("click", e => e.stopPropagation());
|
|
727
|
+
document.body.appendChild(filePopoverEl);
|
|
728
|
+
|
|
729
|
+
document.addEventListener("pointerdown", e => {
|
|
730
|
+
if (!filePopoverEl || filePopoverEl.hidden) return;
|
|
731
|
+
if (filePopoverEl.contains(e.target) || fileTriggerBtn.contains(e.target)) return;
|
|
732
|
+
closeFilePopover();
|
|
733
|
+
});
|
|
734
|
+
document.addEventListener("keydown", e => {
|
|
735
|
+
if (e.key === "Escape" && filePopoverEl && !filePopoverEl.hidden) {
|
|
736
|
+
closeFilePopover();
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
pickerWrap.append(fileSelectEl, fileTriggerBtn);
|
|
741
|
+
|
|
235
742
|
splitMdBtn = document.createElement("button");
|
|
236
743
|
splitMdBtn.id = "ag-split-md";
|
|
237
744
|
splitMdBtn.type = "button";
|
|
@@ -260,7 +767,7 @@
|
|
|
260
767
|
const sep = document.createElement("span");
|
|
261
768
|
sep.className = "sep";
|
|
262
769
|
|
|
263
|
-
bar.prepend(
|
|
770
|
+
bar.prepend(pickerWrap, splitMdBtn, openRawBtn, sep);
|
|
264
771
|
|
|
265
772
|
mdPaneEl = document.createElement("aside");
|
|
266
773
|
mdPaneEl.id = "ag-md-pane";
|
|
@@ -268,37 +775,82 @@
|
|
|
268
775
|
mdPaneEl.innerHTML = `
|
|
269
776
|
<div class="ag-md-header">
|
|
270
777
|
<span class="ag-md-title" id="ag-md-title">Markdown</span>
|
|
778
|
+
<span class="ag-md-line-badge" id="ag-md-line-badge">Ln 1</span>
|
|
271
779
|
<div class="ag-md-actions">
|
|
272
780
|
<button type="button" class="ag-md-close" id="ag-md-close"></button>
|
|
273
781
|
</div>
|
|
274
782
|
</div>
|
|
275
|
-
<
|
|
783
|
+
<div class="ag-md-body">
|
|
784
|
+
<div id="ag-md-gutter" aria-hidden="true"></div>
|
|
785
|
+
<div class="ag-md-editor-stage">
|
|
786
|
+
<div id="ag-md-band" aria-hidden="true"></div>
|
|
787
|
+
<textarea id="ag-md-textarea" spellcheck="false"></textarea>
|
|
788
|
+
</div>
|
|
789
|
+
</div>
|
|
276
790
|
<div id="ag-md-resizer" title="拖拽调整分屏宽度"></div>
|
|
277
791
|
`;
|
|
278
792
|
document.body.appendChild(mdPaneEl);
|
|
279
793
|
mdTitleEl = document.getElementById("ag-md-title");
|
|
794
|
+
mdLineBadgeEl = document.getElementById("ag-md-line-badge");
|
|
795
|
+
mdCloseBtnEl = document.getElementById("ag-md-close");
|
|
796
|
+
mdGutterEl = document.getElementById("ag-md-gutter");
|
|
797
|
+
mdBandEl = document.getElementById("ag-md-band");
|
|
280
798
|
mdTextareaEl = document.getElementById("ag-md-textarea");
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
closeBtn.addEventListener("click", () => {
|
|
799
|
+
if (mdCloseBtnEl) {
|
|
800
|
+
mdCloseBtnEl.textContent = text("× 关闭MD", "× Close MD");
|
|
801
|
+
mdCloseBtnEl.title = text("关闭左侧 Markdown 面板,只保留思维导图", "Close Markdown pane and keep mind map only");
|
|
802
|
+
mdCloseBtnEl.addEventListener("click", () => {
|
|
286
803
|
splitOpen = false;
|
|
287
804
|
applySplitLayout(true);
|
|
288
805
|
});
|
|
289
806
|
}
|
|
290
807
|
if (mdTextareaEl) {
|
|
808
|
+
mdTextareaEl.addEventListener("scroll", () => {
|
|
809
|
+
renderMdGutterAndBand();
|
|
810
|
+
});
|
|
811
|
+
const handleCursorMove = () => {
|
|
812
|
+
if (!mdTextareaEl) return;
|
|
813
|
+
const startPos = mdTextareaEl.selectionStart ?? 0;
|
|
814
|
+
const endPos = mdTextareaEl.selectionEnd ?? startPos;
|
|
815
|
+
const startLine = mdTextareaEl.value.slice(0, startPos).split("\n").length - 1;
|
|
816
|
+
const endLine = mdTextareaEl.value.slice(0, endPos).split("\n").length - 1;
|
|
817
|
+
activeStartLine = startLine;
|
|
818
|
+
activeEndLine = Math.max(startLine, endLine);
|
|
819
|
+
renderMdGutterAndBand();
|
|
820
|
+
emitToEditor({ type: "reveal", line: startLine });
|
|
821
|
+
};
|
|
822
|
+
mdTextareaEl.addEventListener("click", handleCursorMove);
|
|
823
|
+
mdTextareaEl.addEventListener("keyup", e => {
|
|
824
|
+
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown"].includes(e.key)) {
|
|
825
|
+
handleCursorMove();
|
|
826
|
+
}
|
|
827
|
+
});
|
|
291
828
|
mdTextareaEl.addEventListener("input", () => {
|
|
292
829
|
const nextMd = mdTextareaEl.value;
|
|
293
830
|
currentMd = nextMd;
|
|
831
|
+
const startPos = mdTextareaEl.selectionStart ?? 0;
|
|
832
|
+
const startLine = nextMd.slice(0, startPos).split("\n").length - 1;
|
|
833
|
+
activeStartLine = startLine;
|
|
834
|
+
activeEndLine = startLine;
|
|
835
|
+
renderMdGutterAndBand();
|
|
294
836
|
clearTimeout(mdEditTimer);
|
|
295
837
|
mdEditTimer = window.setTimeout(() => {
|
|
296
838
|
if (window.inkmap?.load) {
|
|
297
|
-
void window.inkmap.load(nextMd, true)
|
|
839
|
+
void window.inkmap.load(nextMd, true).then(() => {
|
|
840
|
+
emitToEditor({ type: "reveal", line: startLine });
|
|
841
|
+
});
|
|
298
842
|
}
|
|
299
843
|
}, 320);
|
|
300
844
|
});
|
|
301
845
|
}
|
|
846
|
+
document.querySelectorAll(".language-select").forEach(sel => {
|
|
847
|
+
sel.addEventListener("change", () => {
|
|
848
|
+
setTimeout(() => {
|
|
849
|
+
applySplitLayout(false);
|
|
850
|
+
renderFilePicker(cachedFiles, currentFile);
|
|
851
|
+
}, 10);
|
|
852
|
+
});
|
|
853
|
+
});
|
|
302
854
|
const resizer = document.getElementById("ag-md-resizer");
|
|
303
855
|
if (resizer) {
|
|
304
856
|
resizer.addEventListener("pointerdown", e => {
|
|
@@ -504,6 +1056,37 @@
|
|
|
504
1056
|
}).catch(() => {});
|
|
505
1057
|
return;
|
|
506
1058
|
}
|
|
1059
|
+
case "mapMarkdownChange": {
|
|
1060
|
+
if (typeof msg.md === "string") {
|
|
1061
|
+
currentMd = msg.md;
|
|
1062
|
+
syncMdPaneContent(currentMd, false);
|
|
1063
|
+
}
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
case "select": {
|
|
1067
|
+
activeStartLine = Math.max(0, Number(msg.line) || 0);
|
|
1068
|
+
activeEndLine = Math.max(activeStartLine, Number(msg.endLine ?? msg.line) || activeStartLine);
|
|
1069
|
+
if (mdTextareaEl && splitOpen) {
|
|
1070
|
+
const lines = mdTextareaEl.value.split("\n");
|
|
1071
|
+
const sLine = Math.min(activeStartLine, Math.max(0, lines.length - 1));
|
|
1072
|
+
const eLine = Math.min(activeEndLine, Math.max(0, lines.length - 1));
|
|
1073
|
+
let startOffset = 0;
|
|
1074
|
+
for (let i = 0; i < sLine; i++) startOffset += lines[i].length + 1;
|
|
1075
|
+
let endOffset = startOffset;
|
|
1076
|
+
for (let i = sLine; i <= eLine; i++) {
|
|
1077
|
+
endOffset += lines[i].length + (i < eLine ? 1 : 0);
|
|
1078
|
+
}
|
|
1079
|
+
if (document.activeElement === mdTextareaEl) {
|
|
1080
|
+
try {
|
|
1081
|
+
mdTextareaEl.setSelectionRange(startOffset, endOffset);
|
|
1082
|
+
} catch {}
|
|
1083
|
+
}
|
|
1084
|
+
const lineHeight = 20.8;
|
|
1085
|
+
mdTextareaEl.scrollTop = Math.max(0, sLine * lineHeight - mdTextareaEl.clientHeight * 0.35);
|
|
1086
|
+
renderMdGutterAndBand();
|
|
1087
|
+
}
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
507
1090
|
case "undo": {
|
|
508
1091
|
window.inkmap?.mindMap?.execCommand("BACK");
|
|
509
1092
|
return;
|
|
@@ -536,10 +1119,10 @@
|
|
|
536
1119
|
case "checkout": {
|
|
537
1120
|
const res = await apiFetch("/api/checkout", {
|
|
538
1121
|
method: "POST",
|
|
539
|
-
body: JSON.stringify({ mode:
|
|
1122
|
+
body: JSON.stringify({ mode: "restore" }),
|
|
540
1123
|
});
|
|
541
1124
|
emitToEditor({ type: "checkout", id: msg.id });
|
|
542
|
-
// Poll license state after
|
|
1125
|
+
// Poll license state after restore sign-in link opens
|
|
543
1126
|
const checkTimer = setInterval(async () => {
|
|
544
1127
|
const state = await apiFetch("/api/license", { method: "GET" }).catch(() => null);
|
|
545
1128
|
if (state) emitToEditor({ type: "license", state });
|
|
@@ -549,22 +1132,6 @@
|
|
|
549
1132
|
if (res.url && !window.sidecar) window.open(res.url, "_blank", "noopener,noreferrer");
|
|
550
1133
|
return;
|
|
551
1134
|
}
|
|
552
|
-
case "orderPro": {
|
|
553
|
-
const { result } = await apiFetch("/api/order-pro", {
|
|
554
|
-
method: "POST",
|
|
555
|
-
body: "{}",
|
|
556
|
-
});
|
|
557
|
-
emitToEditor({ type: "proOrder", id: msg.id, result });
|
|
558
|
-
if (result?.status === "qr" || result?.status === "redirect") {
|
|
559
|
-
const checkTimer = setInterval(async () => {
|
|
560
|
-
const state = await apiFetch("/api/license", { method: "GET" }).catch(() => null);
|
|
561
|
-
if (state) emitToEditor({ type: "license", state });
|
|
562
|
-
if (state?.pro) clearInterval(checkTimer);
|
|
563
|
-
}, 3000);
|
|
564
|
-
setTimeout(() => clearInterval(checkTimer), 15 * 60_000);
|
|
565
|
-
}
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
1135
|
case "sendPhoneCode": {
|
|
569
1136
|
const { result } = await apiFetch("/api/phone-send", {
|
|
570
1137
|
method: "POST",
|