openclacky 1.5.21 → 1.5.23
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +119 -0
- data/docs/secretary-prototype.md +286 -0
- data/lib/clacky/agent/session_serializer.rb +15 -11
- data/lib/clacky/agent.rb +58 -15
- data/lib/clacky/agent_config.rb +3 -1
- data/lib/clacky/agent_profile.rb +33 -6
- data/lib/clacky/billing/platform_billing.rb +9 -0
- data/lib/clacky/default_extensions/advisor/README.md +25 -0
- data/lib/clacky/default_extensions/advisor/README.zh.md +25 -0
- data/lib/clacky/default_extensions/advisor/ext.yml +1 -1
- data/lib/clacky/default_extensions/advisor/icon.svg +14 -0
- data/lib/clacky/default_extensions/coding/ext.yml +0 -1
- data/lib/clacky/default_extensions/computer-use/README.md +48 -0
- data/lib/clacky/default_extensions/computer-use/README.zh.md +48 -0
- data/lib/clacky/default_extensions/computer-use/ext.yml +1 -1
- data/lib/clacky/default_extensions/computer-use/icon.svg +16 -0
- data/lib/clacky/default_extensions/ext-studio/ext.yml +0 -1
- data/lib/clacky/default_extensions/general/ext.yml +0 -1
- data/lib/clacky/default_extensions/git/README.md +41 -0
- data/lib/clacky/default_extensions/git/README.zh.md +41 -0
- data/lib/clacky/default_extensions/git/ext.yml +1 -1
- data/lib/clacky/default_extensions/git/icon.svg +15 -0
- data/lib/clacky/default_extensions/git/panels/git/view.js +1960 -399
- data/lib/clacky/default_extensions/meeting/README.md +46 -0
- data/lib/clacky/default_extensions/meeting/README.zh.md +47 -0
- data/lib/clacky/default_extensions/meeting/ext.yml +1 -1
- data/lib/clacky/default_extensions/meeting/icon.svg +13 -0
- data/lib/clacky/default_extensions/preview/README.md +29 -0
- data/lib/clacky/default_extensions/preview/README.zh.md +29 -0
- data/lib/clacky/default_extensions/preview/ext.yml +1 -1
- data/lib/clacky/default_extensions/preview/icon.svg +13 -0
- data/lib/clacky/default_extensions/preview/panels/preview/view.js +199 -34
- data/lib/clacky/default_extensions/secretary/agents/secretary.md +41 -0
- data/lib/clacky/default_extensions/secretary/agents/worker.md +35 -0
- data/lib/clacky/default_extensions/secretary/api/handler.rb +8 -0
- data/lib/clacky/default_extensions/secretary/ext.yml +39 -0
- data/lib/clacky/default_extensions/secretary/panels/work/view.js +344 -0
- data/lib/clacky/default_extensions/secretary/tools/delegate_work.rb +37 -0
- data/lib/clacky/default_extensions/secretary/tools/manage_work.rb +22 -0
- data/lib/clacky/default_extensions/secretary/tools/yield_work.rb +35 -0
- data/lib/clacky/default_extensions/time_machine/README.md +32 -0
- data/lib/clacky/default_extensions/time_machine/README.zh.md +32 -0
- data/lib/clacky/default_extensions/time_machine/ext.yml +1 -1
- data/lib/clacky/default_extensions/time_machine/icon.svg +14 -0
- data/lib/clacky/default_skills/channel-manager/SKILL.md +79 -8
- data/lib/clacky/default_skills/channel-manager/discord_setup.rb +5 -1
- data/lib/clacky/default_skills/channel-manager/weixin_setup.rb +8 -1
- data/lib/clacky/default_skills/cron-task-creator/SKILL.md +183 -206
- data/lib/clacky/default_skills/cron-task-creator/evals/evals.json +45 -0
- data/lib/clacky/default_skills/media-gen/SKILL.md +17 -8
- data/lib/clacky/extension/api_extension.rb +10 -2
- data/lib/clacky/extension/loader.rb +2 -0
- data/lib/clacky/extension/verifier.rb +2 -2
- data/lib/clacky/locales/en.rb +14 -0
- data/lib/clacky/locales/zh.rb +14 -0
- data/lib/clacky/prompts/base.md +1 -1
- data/lib/clacky/providers.rb +68 -31
- data/lib/clacky/search_config.rb +33 -11
- data/lib/clacky/server/channel/adapters/base.rb +18 -0
- data/lib/clacky/server/channel/adapters/feishu/message_parser.rb +1 -0
- data/lib/clacky/server/channel/adapters/telegram/adapter.rb +1 -0
- data/lib/clacky/server/channel/channel_config.rb +185 -48
- data/lib/clacky/server/channel/channel_manager.rb +179 -66
- data/lib/clacky/server/git_panel.rb +362 -35
- data/lib/clacky/server/http_server.rb +530 -181
- data/lib/clacky/server/preview.rb +118 -17
- data/lib/clacky/server/scheduler.rb +211 -51
- data/lib/clacky/server/web_ui_controller.rb +35 -27
- data/lib/clacky/session_manager.rb +56 -6
- data/lib/clacky/tools/base.rb +7 -1
- data/lib/clacky/utils/file_processor.rb +20 -10
- data/lib/clacky/utils/mac_app_detector.rb +8 -7
- data/lib/clacky/utils/model_pricing.rb +60 -2
- data/lib/clacky/utils/windows_app_detector.rb +3 -1
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky/web/app.css +1114 -205
- data/lib/clacky/web/app.js +143 -8
- data/lib/clacky/web/auth.js +1 -1
- data/lib/clacky/web/components/code-editor.js +73 -4
- data/lib/clacky/web/components/composer.js +107 -8
- data/lib/clacky/web/components/image-zoom.js +165 -0
- data/lib/clacky/web/components/model-picker.js +7 -5
- data/lib/clacky/web/components/notify.js +39 -12
- data/lib/clacky/web/components/onboard.js +1 -1
- data/lib/clacky/web/core/aside.js +60 -3
- data/lib/clacky/web/features/billing/view.js +2 -2
- data/lib/clacky/web/features/channels/store.js +19 -4
- data/lib/clacky/web/features/channels/view.js +92 -28
- data/lib/clacky/web/features/extensions/view.js +17 -10
- data/lib/clacky/web/features/new-session/store.js +79 -2
- data/lib/clacky/web/features/new-session/view.js +516 -75
- data/lib/clacky/web/features/skills/store.js +1 -1
- data/lib/clacky/web/features/tasks/store.js +5 -3
- data/lib/clacky/web/features/tasks/view.js +249 -66
- data/lib/clacky/web/features/workspace/store.js +13 -6
- data/lib/clacky/web/features/workspace/view.js +340 -214
- data/lib/clacky/web/i18n.js +366 -68
- data/lib/clacky/web/index.html +196 -165
- data/lib/clacky/web/projects.js +37 -4
- data/lib/clacky/web/sessions.js +263 -146
- data/lib/clacky/web/settings.js +241 -53
- data/lib/clacky/web/skills.js +2 -2
- data/lib/clacky/web/theme.js +17 -2
- data/lib/clacky/web/utils.js +234 -2
- data/lib/clacky/web/weixin-qr.html +2 -1
- data/lib/clacky/web/ws-dispatcher.js +14 -31
- data/lib/clacky/work/service.rb +542 -0
- data/lib/clacky/work/store.rb +57 -0
- metadata +31 -1
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// it shows for every session regardless of agent profile. All I/O goes through
|
|
12
12
|
// WorkspaceStore.
|
|
13
13
|
//
|
|
14
|
-
// Depends on: WorkspaceStore, Clacky.ext, I18n, Modal, CodeEditor
|
|
14
|
+
// Depends on: WorkspaceStore, Clacky.ext, Composer, I18n, Modal, CodeEditor,
|
|
15
|
+
// ImageZoom.
|
|
15
16
|
// ───────────────────────────────────────────────────────────────────────────
|
|
16
17
|
"use strict";
|
|
17
18
|
|
|
@@ -29,6 +30,8 @@ const WorkspaceView = (() => {
|
|
|
29
30
|
const ICON_EYE = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';
|
|
30
31
|
const ICON_CLOSE = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><path d="M18 6L6 18M6 6l12 12"/></svg>';
|
|
31
32
|
const ICON_CHEVRON_DOWN = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>';
|
|
33
|
+
const ICON_CHEVRON_RIGHT = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>';
|
|
34
|
+
const ICON_OPEN_WITH = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 4h6v6"/><path d="M20 4l-8 8"/><path d="M18 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h5"/></svg>';
|
|
32
35
|
const ICON_EXTERNAL = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>';
|
|
33
36
|
const ICON_PANEL_LEFT = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="3" x2="9" y2="21"/></svg>';
|
|
34
37
|
const ICON_ARROW_LEFT = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5"/><path d="m12 19-7-7 7-7"/></svg>';
|
|
@@ -143,6 +146,30 @@ const WorkspaceView = (() => {
|
|
|
143
146
|
'<path fill="#c3ccd4" d="M9.7 1.5v3.3H13z"/>'
|
|
144
147
|
);
|
|
145
148
|
|
|
149
|
+
const ICON_TEXT = svgWrap(
|
|
150
|
+
'<path fill="#90a4ae" d="M3.5 1.5h6.2L13 4.8v9.2a1 1 0 0 1-1 1H3.5a1 1 0 0 1-1-1v-11a1 1 0 0 1 1-1z"/>' +
|
|
151
|
+
'<path fill="#c3ccd4" d="M9.7 1.5v3.3H13z"/>' +
|
|
152
|
+
'<path d="M4.8 7.5h5.4M4.8 9.9h5.4M4.8 12.3h3.4" stroke="#fff" stroke-width="1.1" stroke-linecap="round"/>'
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const ICON_PDF = svgWrap(
|
|
156
|
+
'<rect x="1" y="1" width="14" height="14" rx="3" fill="#e5383b"/>' +
|
|
157
|
+
`<text x="8" y="10.4" text-anchor="middle" ${ICON_FONT} font-size="5.6" font-weight="700" letter-spacing="-0.2" fill="#fff">PDF</text>`
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Office-style tile: a lettered square overlapping a tinted page
|
|
161
|
+
function officeIcon(label, color) {
|
|
162
|
+
return svgWrap(
|
|
163
|
+
`<path fill="${color}" opacity="0.35" d="M5.5 1.5h6.2L14.5 4.3v9.7a.9.9 0 0 1-.9.9H5.5a.9.9 0 0 1-.9-.9V2.4a.9.9 0 0 1 .9-.9z"/>` +
|
|
164
|
+
`<rect x="1" y="4" width="9" height="9" rx="1.6" fill="${color}"/>` +
|
|
165
|
+
`<text x="5.5" y="11.1" text-anchor="middle" ${ICON_FONT} font-size="7" font-weight="800" fill="#fff">${label}</text>`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const ICON_WORD = officeIcon("W", "#2b579a");
|
|
170
|
+
const ICON_EXCEL = officeIcon("X", "#217346");
|
|
171
|
+
const ICON_PPT = officeIcon("P", "#d24726");
|
|
172
|
+
|
|
146
173
|
const ICON_VIDEO = svgWrap(
|
|
147
174
|
'<rect x="1.5" y="3" width="13" height="10" rx="2" fill="#5c8ee6"/>' +
|
|
148
175
|
'<path d="m6.5 5.8 4 2.2-4 2.2z" fill="#fff"/>'
|
|
@@ -186,7 +213,11 @@ const WorkspaceView = (() => {
|
|
|
186
213
|
gif: imgIcon("#a074c4"), webp: imgIcon("#a074c4"), ico: imgIcon("#a074c4"), bmp: imgIcon("#a074c4"),
|
|
187
214
|
mp4: ICON_VIDEO, webm: ICON_VIDEO, mov: ICON_VIDEO,
|
|
188
215
|
mp3: ICON_AUDIO, wav: ICON_AUDIO, ogg: ICON_AUDIO, aac: ICON_AUDIO, flac: ICON_AUDIO, m4a: ICON_AUDIO,
|
|
189
|
-
pdf:
|
|
216
|
+
pdf: ICON_PDF,
|
|
217
|
+
doc: ICON_WORD, docx: ICON_WORD, odt: ICON_WORD, rtf: ICON_WORD, wps: ICON_WORD,
|
|
218
|
+
xls: ICON_EXCEL, xlsx: ICON_EXCEL, ods: ICON_EXCEL, numbers: ICON_EXCEL,
|
|
219
|
+
ppt: ICON_PPT, pptx: ICON_PPT, odp: ICON_PPT, key: ICON_PPT,
|
|
220
|
+
txt: ICON_TEXT, log: ICON_TEXT,
|
|
190
221
|
zip: boxIcon("Z", "#dba15d"), tar: boxIcon("Z", "#dba15d"), gz: boxIcon("Z", "#dba15d"),
|
|
191
222
|
"7z": boxIcon("Z", "#dba15d"), rar: boxIcon("Z", "#dba15d"), dmg: boxIcon("Z", "#dba15d"), iso: boxIcon("Z", "#dba15d"),
|
|
192
223
|
lock: ICON_LOCK,
|
|
@@ -312,6 +343,16 @@ const WorkspaceView = (() => {
|
|
|
312
343
|
node.appendChild(children);
|
|
313
344
|
row.addEventListener("click", () => toggleDir(entry, caret, children, icon, openFile));
|
|
314
345
|
} else {
|
|
346
|
+
row.draggable = true;
|
|
347
|
+
row.addEventListener("dragstart", (e) => {
|
|
348
|
+
if (!e.dataTransfer || typeof Composer === "undefined" ||
|
|
349
|
+
typeof Composer.beginWorkspaceFileDrag !== "function") {
|
|
350
|
+
e.preventDefault();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const started = Composer.beginWorkspaceFileDrag(e.dataTransfer, chatAttachment(entry));
|
|
354
|
+
if (!started) e.preventDefault();
|
|
355
|
+
});
|
|
315
356
|
row.addEventListener("click", () => openFile(entry));
|
|
316
357
|
}
|
|
317
358
|
|
|
@@ -338,10 +379,18 @@ const WorkspaceView = (() => {
|
|
|
338
379
|
<span class="session-actions-menu-label">${t("workspace.addToChat")}</span>
|
|
339
380
|
</div>` : "";
|
|
340
381
|
|
|
382
|
+
const openWithItem = entry.type === "file" ? `
|
|
383
|
+
<div class="session-actions-menu-item session-actions-menu-item--has-submenu" data-action="openwith">
|
|
384
|
+
<span class="session-actions-menu-icon">${ICON_OPEN_WITH}</span>
|
|
385
|
+
<span class="session-actions-menu-label">${t("workspace.openWithMenu")}</span>
|
|
386
|
+
<span class="session-actions-menu-arrow">${ICON_CHEVRON_RIGHT}</span>
|
|
387
|
+
</div>` : "";
|
|
388
|
+
|
|
341
389
|
const menu = document.createElement("div");
|
|
342
390
|
menu.className = "wt-context-menu session-context-menu";
|
|
343
391
|
menu.innerHTML = `
|
|
344
392
|
${addToChatItem}
|
|
393
|
+
${openWithItem}
|
|
345
394
|
<div class="session-actions-menu-item" data-action="reveal">
|
|
346
395
|
<span class="session-actions-menu-icon">${ICON_FOLDER}</span>
|
|
347
396
|
<span class="session-actions-menu-label">${t("workspace.revealInFinder")}</span>
|
|
@@ -368,6 +417,11 @@ const WorkspaceView = (() => {
|
|
|
368
417
|
if (r.bottom > window.innerHeight) menu.style.top = (window.innerHeight - r.height - 8) + "px";
|
|
369
418
|
});
|
|
370
419
|
|
|
420
|
+
if (entry.type === "file") {
|
|
421
|
+
const row = menu.querySelector('[data-action="openwith"]');
|
|
422
|
+
if (row) OpenWith.mount(row, entry, { menu: menu });
|
|
423
|
+
}
|
|
424
|
+
|
|
371
425
|
menu.addEventListener("click", async (ev) => {
|
|
372
426
|
const item = ev.target.closest(".session-actions-menu-item");
|
|
373
427
|
if (!item) return;
|
|
@@ -433,42 +487,20 @@ const WorkspaceView = (() => {
|
|
|
433
487
|
document.addEventListener("click", closeOpenWithMenu, { once: true });
|
|
434
488
|
}, 0);
|
|
435
489
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Workspace.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
img.src = "/api/app-icon?path=" + encodeURIComponent(app.path);
|
|
451
|
-
img.addEventListener("error", () => { img.remove(); });
|
|
452
|
-
iconEl.appendChild(img);
|
|
453
|
-
const labelEl = el("span", "session-actions-menu-label");
|
|
454
|
-
labelEl.textContent = app.name;
|
|
455
|
-
item.appendChild(iconEl);
|
|
456
|
-
item.appendChild(labelEl);
|
|
457
|
-
item.addEventListener("click", async () => {
|
|
458
|
-
closeOpenWithMenu();
|
|
459
|
-
try {
|
|
460
|
-
await Workspace.openWithApp(entry, app.path);
|
|
461
|
-
} catch (err) {
|
|
462
|
-
console.error("open_with failed:", err);
|
|
463
|
-
Modal.toast(t("workspace.openWithFailed") + ": " + err.message, "error");
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
frag.appendChild(item);
|
|
467
|
-
});
|
|
468
|
-
frag.appendChild(el("div", "wv-open-menu-separator"));
|
|
469
|
-
menu.insertBefore(frag, menu.firstChild);
|
|
470
|
-
fitMenu();
|
|
471
|
-
}
|
|
490
|
+
OpenWith.appRows(entry, (app) => {
|
|
491
|
+
closeOpenWithMenu();
|
|
492
|
+
Workspace.openWithApp(entry, app.path).catch((err) => {
|
|
493
|
+
console.error("open_with failed:", err);
|
|
494
|
+
Modal.toast(t("workspace.openWithFailed") + ": " + err.message, "error");
|
|
495
|
+
});
|
|
496
|
+
}, { base: "session-actions-menu" }).then((rows) => {
|
|
497
|
+
// No app claims this type: keep just reveal/download, as before.
|
|
498
|
+
if (!document.body.contains(menu) || !rows.length) return;
|
|
499
|
+
const frag = document.createDocumentFragment();
|
|
500
|
+
rows.forEach((node) => frag.appendChild(node));
|
|
501
|
+
frag.appendChild(el("div", "wv-open-menu-separator"));
|
|
502
|
+
menu.insertBefore(frag, menu.firstChild);
|
|
503
|
+
fitMenu();
|
|
472
504
|
}).catch(() => { /* not macOS or scan failed — reveal/download still work */ });
|
|
473
505
|
}
|
|
474
506
|
|
|
@@ -505,6 +537,15 @@ const WorkspaceView = (() => {
|
|
|
505
537
|
}
|
|
506
538
|
}
|
|
507
539
|
|
|
540
|
+
function chatAttachment(entry) {
|
|
541
|
+
return {
|
|
542
|
+
type: "file",
|
|
543
|
+
name: entry.name,
|
|
544
|
+
path: Workspace.absPath(entry.path),
|
|
545
|
+
size: entry.size,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
508
549
|
// Hand the file to the composer, which stages it and focuses the input. The
|
|
509
550
|
// absolute path is what the agent ultimately reads, so resolve it here where
|
|
510
551
|
// the session's working directory is known.
|
|
@@ -513,11 +554,7 @@ const WorkspaceView = (() => {
|
|
|
513
554
|
console.error("add to chat failed: Sessions.attachWorkspaceFile is unavailable");
|
|
514
555
|
return;
|
|
515
556
|
}
|
|
516
|
-
Sessions.attachWorkspaceFile(
|
|
517
|
-
name: entry.name,
|
|
518
|
-
path: Workspace.absPath(entry.path),
|
|
519
|
-
size: entry.size,
|
|
520
|
-
});
|
|
557
|
+
Sessions.attachWorkspaceFile(chatAttachment(entry));
|
|
521
558
|
}
|
|
522
559
|
|
|
523
560
|
async function toggleDir(entry, caret, children, iconEl, openFile) {
|
|
@@ -542,7 +579,8 @@ const WorkspaceView = (() => {
|
|
|
542
579
|
highlightActiveRow();
|
|
543
580
|
} catch (err) {
|
|
544
581
|
console.error("workspace load failed:", err);
|
|
545
|
-
children.
|
|
582
|
+
children.replaceChildren();
|
|
583
|
+
renderLoadError(children, err);
|
|
546
584
|
}
|
|
547
585
|
}
|
|
548
586
|
|
|
@@ -563,6 +601,52 @@ const WorkspaceView = (() => {
|
|
|
563
601
|
}
|
|
564
602
|
}
|
|
565
603
|
|
|
604
|
+
// A session outlives its working dir all the time (deleted temp clone,
|
|
605
|
+
// removed workspace, renamed folder). The API flags that case with a code;
|
|
606
|
+
// "Failed to load files" alone leaves the user with nothing to act on, so
|
|
607
|
+
// name the cause and offer the folder picker the status bar already owns.
|
|
608
|
+
function isDirGone(err) {
|
|
609
|
+
const code = err && err.code;
|
|
610
|
+
return code === "working_dir_missing" || code === "directory_missing";
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function renderLoadError(container, err) {
|
|
614
|
+
if (!isDirGone(err)) {
|
|
615
|
+
container.innerHTML = `<div class="wt-error">${t("workspace.error")}</div>`;
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const workingDirGone = err.code === "working_dir_missing";
|
|
619
|
+
const card = el("div", "wt-error-card");
|
|
620
|
+
const title = el("div", "wt-error-card-title");
|
|
621
|
+
title.textContent = t(workingDirGone ? "workspace.dirMissingTitle" : "workspace.dirGoneTitle");
|
|
622
|
+
const desc = el("div", "wt-error-card-desc");
|
|
623
|
+
desc.textContent = t(workingDirGone ? "workspace.dirMissingDesc" : "workspace.dirGoneDesc");
|
|
624
|
+
card.appendChild(title);
|
|
625
|
+
card.appendChild(desc);
|
|
626
|
+
|
|
627
|
+
if (workingDirGone) {
|
|
628
|
+
const fullPath = Workspace.state.workingDir || "";
|
|
629
|
+
const pathEl = el("div", "wt-error-card-path");
|
|
630
|
+
// A full path in a 168px-wide pane hides the segment that differs from
|
|
631
|
+
// other checkouts, which is the one worth reading.
|
|
632
|
+
pathEl.textContent = fullPath.length > 44 ? `…${fullPath.slice(-43)}` : fullPath;
|
|
633
|
+
pathEl.title = fullPath;
|
|
634
|
+
card.appendChild(pathEl);
|
|
635
|
+
|
|
636
|
+
const action = el("button", "btn-card-grid-action wt-error-card-action");
|
|
637
|
+
action.type = "button";
|
|
638
|
+
action.textContent = t("workspace.dirMissingAction");
|
|
639
|
+
// Reuse the status-bar picker's click: it owns the dialog, the PATCH and
|
|
640
|
+
// the "this folder no longer exists" wording for a missing bound path.
|
|
641
|
+
action.addEventListener("click", () => {
|
|
642
|
+
const statusBarDir = document.getElementById("sib-dir");
|
|
643
|
+
if (statusBarDir) statusBarDir.click();
|
|
644
|
+
});
|
|
645
|
+
card.appendChild(action);
|
|
646
|
+
}
|
|
647
|
+
container.replaceChildren(card);
|
|
648
|
+
}
|
|
649
|
+
|
|
566
650
|
async function loadRoot(tree, openFile, opts) {
|
|
567
651
|
if (!tree || !Workspace.state.hasSession()) return;
|
|
568
652
|
// A different working dir (session switch) shares no history with what is
|
|
@@ -578,7 +662,9 @@ const WorkspaceView = (() => {
|
|
|
578
662
|
entries = await Workspace.fetchEntries("");
|
|
579
663
|
} catch (err) {
|
|
580
664
|
console.error("workspace load failed:", err);
|
|
581
|
-
|
|
665
|
+
// Rows that stay on screen after the dir disappeared claim files exist
|
|
666
|
+
// where they don't; a transient failure keeps the listing it already has.
|
|
667
|
+
if (firstLoad || isDirGone(err)) renderLoadError(tree, err);
|
|
582
668
|
return false;
|
|
583
669
|
}
|
|
584
670
|
reconcileEntries(tree, entries, openFile);
|
|
@@ -680,12 +766,6 @@ const WorkspaceView = (() => {
|
|
|
680
766
|
|
|
681
767
|
const VIEWER_ASIDE_WIDTH = 700;
|
|
682
768
|
|
|
683
|
-
// Image zoom is expressed against the picture's own pixels, so 100% always
|
|
684
|
-
// means "one screen pixel per image pixel" whatever the pane is doing.
|
|
685
|
-
const IMAGE_MIN_ZOOM = 0.1;
|
|
686
|
-
const IMAGE_MAX_ZOOM = 8;
|
|
687
|
-
const IMAGE_ZOOM_STEP = 1.25;
|
|
688
|
-
|
|
689
769
|
// Open files outlive a reload: the strip is rebuilt from a per-session record
|
|
690
770
|
// in localStorage, so refreshing the page (or coming back to a session) lands
|
|
691
771
|
// on the same files. Paths only — every tab body is fetched from disk again.
|
|
@@ -754,9 +834,16 @@ const WorkspaceView = (() => {
|
|
|
754
834
|
return !!ext && !NO_AUTO_OPEN_EXTS.has(ext);
|
|
755
835
|
}
|
|
756
836
|
|
|
757
|
-
function
|
|
837
|
+
function withCacheBuster(url) {
|
|
838
|
+
if (!url) return url;
|
|
839
|
+
const clean = url.replace(/([?&])_v=\d+(&|$)/, (_m, p1, p2) => (p2 ? p1 : "")).replace(/[?&]$/, "");
|
|
840
|
+
return clean + (clean.includes("?") ? "&" : "?") + "_v=" + Date.now();
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function createViewer(onTabsChanged, onTreeHidden, onShowMobileTree) {
|
|
758
844
|
const tabs = [];
|
|
759
845
|
let activeId = null;
|
|
846
|
+
let treeHidden = false;
|
|
760
847
|
let releaseAsideWidth = null;
|
|
761
848
|
const notify = () => {
|
|
762
849
|
if (onTabsChanged) onTabsChanged({ count: tabs.length, activeId });
|
|
@@ -806,38 +893,62 @@ const WorkspaceView = (() => {
|
|
|
806
893
|
|
|
807
894
|
const content = el("div", "wv-content");
|
|
808
895
|
|
|
809
|
-
|
|
896
|
+
// `key` is the i18n lookup so a language switch can rewrite the hint
|
|
897
|
+
// after the toolbar has already been built.
|
|
898
|
+
function actionBtn(icon, key, cls) {
|
|
810
899
|
const btn = el("button", "wv-action" + (cls ? " " + cls : ""));
|
|
811
900
|
btn.type = "button";
|
|
812
|
-
btn.
|
|
813
|
-
btn.setAttribute("
|
|
901
|
+
btn.setAttribute("data-tooltip", t(key));
|
|
902
|
+
btn.setAttribute("data-i18n-tooltip", key);
|
|
903
|
+
btn.setAttribute("aria-label", t(key));
|
|
814
904
|
btn.innerHTML = icon;
|
|
815
905
|
return btn;
|
|
816
906
|
}
|
|
817
907
|
|
|
818
|
-
|
|
908
|
+
// Strip the shared tooltip from a button that is self-describing on its
|
|
909
|
+
// own (visible label, or a glyph right next to one).
|
|
910
|
+
function dropTooltip(btn) {
|
|
911
|
+
btn.removeAttribute("data-tooltip");
|
|
912
|
+
btn.removeAttribute("data-i18n-tooltip");
|
|
913
|
+
return btn;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
const toggleTreeBtn = actionBtn(ICON_PANEL_LEFT, "workspace.toggleTree");
|
|
819
917
|
toggleTreeBtn.classList.add("wv-toggle-tree", "active");
|
|
820
918
|
toggleTreeBtn.addEventListener("click", () => {
|
|
821
|
-
|
|
822
|
-
toggleTreeBtn.classList.toggle("active", !hidden);
|
|
919
|
+
setTreeHidden(!treeHidden);
|
|
823
920
|
});
|
|
824
921
|
|
|
825
|
-
|
|
922
|
+
// The tree is the only thing left once the last tab closes. Keeping it
|
|
923
|
+
// hidden there would blank the panel with no visible control to restore it,
|
|
924
|
+
// so an empty tab strip always wins over the user's earlier toggle.
|
|
925
|
+
function setTreeHidden(hidden) {
|
|
926
|
+
treeHidden = tabs.length === 0 ? false : !!hidden;
|
|
927
|
+
if (onTreeHidden) onTreeHidden(treeHidden);
|
|
928
|
+
toggleTreeBtn.classList.toggle("active", !treeHidden);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
const mobileBackBtn = actionBtn(ICON_ARROW_LEFT, "workspace.backToFiles", "wv-mobile-back");
|
|
826
932
|
mobileBackBtn.addEventListener("click", () => {
|
|
827
933
|
if (onShowMobileTree) onShowMobileTree();
|
|
828
934
|
});
|
|
829
935
|
|
|
830
|
-
const previewBtn = actionBtn(ICON_EYE,
|
|
831
|
-
const splitBtn = actionBtn(ICON_COLUMNS,
|
|
832
|
-
const copyBtn = actionBtn(ICON_COPY,
|
|
833
|
-
const saveBtn = actionBtn(ICON_SAVE,
|
|
936
|
+
const previewBtn = actionBtn(ICON_EYE, "workspace.preview");
|
|
937
|
+
const splitBtn = actionBtn(ICON_COLUMNS, "workspace.splitPreview");
|
|
938
|
+
const copyBtn = actionBtn(ICON_COPY, "workspace.copyContent");
|
|
939
|
+
const saveBtn = actionBtn(ICON_SAVE, "modal.save");
|
|
834
940
|
|
|
835
941
|
// Split button shown for binary (non-previewable) tabs: text part opens
|
|
836
942
|
// with the OS default app, the chevron opens the "open with" dropdown.
|
|
943
|
+
// Both halves are self-describing, so they get no tooltip — only a
|
|
944
|
+
// screen-reader label, which is updated once the default app is known.
|
|
837
945
|
const openGroup = el("div", "wv-action-group");
|
|
838
946
|
const openMainBtn = el("button", "wv-action wv-action--open");
|
|
839
947
|
openMainBtn.type = "button";
|
|
840
|
-
|
|
948
|
+
const setOpenLabel = (label) => {
|
|
949
|
+
openMainBtn.setAttribute("aria-label", label);
|
|
950
|
+
};
|
|
951
|
+
setOpenLabel(t("workspace.openDefault"));
|
|
841
952
|
const openIconEl = el("span", "wv-main-app-icon");
|
|
842
953
|
openIconEl.innerHTML = ICON_EXTERNAL;
|
|
843
954
|
const openLabel = el("span");
|
|
@@ -849,7 +960,8 @@ const WorkspaceView = (() => {
|
|
|
849
960
|
if (!tab) return;
|
|
850
961
|
await openWithSystem(tab.entry);
|
|
851
962
|
});
|
|
852
|
-
const openArrowBtn = actionBtn(ICON_CHEVRON_DOWN,
|
|
963
|
+
const openArrowBtn = actionBtn(ICON_CHEVRON_DOWN, "workspace.openWithMenu");
|
|
964
|
+
dropTooltip(openArrowBtn);
|
|
853
965
|
openArrowBtn.addEventListener("click", (e) => {
|
|
854
966
|
e.stopPropagation();
|
|
855
967
|
const tab = activeTab();
|
|
@@ -904,7 +1016,8 @@ const WorkspaceView = (() => {
|
|
|
904
1016
|
|
|
905
1017
|
const close = el("span", "wv-tab-close");
|
|
906
1018
|
close.innerHTML = ICON_CLOSE;
|
|
907
|
-
close.
|
|
1019
|
+
close.setAttribute("data-tooltip", t("workspace.closeTab"));
|
|
1020
|
+
close.setAttribute("data-i18n-tooltip", "workspace.closeTab");
|
|
908
1021
|
|
|
909
1022
|
btn.appendChild(label);
|
|
910
1023
|
btn.appendChild(dot);
|
|
@@ -913,6 +1026,7 @@ const WorkspaceView = (() => {
|
|
|
913
1026
|
btn.addEventListener("click", (e) => {
|
|
914
1027
|
if (e.target.closest(".wv-tab-close")) return;
|
|
915
1028
|
activate(tab.id);
|
|
1029
|
+
if (!tab.dirty) reloadTab(tab);
|
|
916
1030
|
});
|
|
917
1031
|
close.addEventListener("click", (e) => {
|
|
918
1032
|
e.stopPropagation();
|
|
@@ -952,7 +1066,7 @@ const WorkspaceView = (() => {
|
|
|
952
1066
|
if (tab && tab.id === _openIconTabId) return;
|
|
953
1067
|
_openIconTabId = tab ? tab.id : null;
|
|
954
1068
|
openIconEl.innerHTML = ICON_EXTERNAL;
|
|
955
|
-
|
|
1069
|
+
setOpenLabel(t("workspace.openDefault"));
|
|
956
1070
|
if (!tab) return;
|
|
957
1071
|
Workspace.fetchDefaultApp(tab.entry).then((app) => {
|
|
958
1072
|
if (!app || _openIconTabId !== tab.id) return;
|
|
@@ -963,7 +1077,7 @@ const WorkspaceView = (() => {
|
|
|
963
1077
|
if (_openIconTabId === tab.id) openIconEl.innerHTML = ICON_EXTERNAL;
|
|
964
1078
|
});
|
|
965
1079
|
openIconEl.replaceChildren(img);
|
|
966
|
-
|
|
1080
|
+
setOpenLabel(t("workspace.openWith", { app: app.name }));
|
|
967
1081
|
}).catch(() => { /* keep generic icon */ });
|
|
968
1082
|
}
|
|
969
1083
|
|
|
@@ -991,7 +1105,7 @@ const WorkspaceView = (() => {
|
|
|
991
1105
|
|
|
992
1106
|
function disposeTab(tab) {
|
|
993
1107
|
if (tab.editor) tab.editor.destroy();
|
|
994
|
-
if (tab.
|
|
1108
|
+
if (tab.zoomController) tab.zoomController.destroy();
|
|
995
1109
|
if (tab.imageUrl) URL.revokeObjectURL(tab.imageUrl);
|
|
996
1110
|
if (tab.mediaEl) {
|
|
997
1111
|
tab.mediaEl.pause();
|
|
@@ -1017,7 +1131,10 @@ const WorkspaceView = (() => {
|
|
|
1017
1131
|
} else {
|
|
1018
1132
|
rebuildTabbar();
|
|
1019
1133
|
}
|
|
1020
|
-
if (tabs.length === 0)
|
|
1134
|
+
if (tabs.length === 0) {
|
|
1135
|
+
restoreAsideWidth();
|
|
1136
|
+
setTreeHidden(false);
|
|
1137
|
+
}
|
|
1021
1138
|
notify();
|
|
1022
1139
|
}
|
|
1023
1140
|
|
|
@@ -1040,7 +1157,10 @@ const WorkspaceView = (() => {
|
|
|
1040
1157
|
? (tabs.length ? tabs[tabs.length - 1].id : null)
|
|
1041
1158
|
: activeId;
|
|
1042
1159
|
activate(nextId);
|
|
1043
|
-
if (tabs.length === 0)
|
|
1160
|
+
if (tabs.length === 0) {
|
|
1161
|
+
restoreAsideWidth();
|
|
1162
|
+
setTreeHidden(false);
|
|
1163
|
+
}
|
|
1044
1164
|
}
|
|
1045
1165
|
|
|
1046
1166
|
function closeAllTabs() {
|
|
@@ -1145,6 +1265,74 @@ const WorkspaceView = (() => {
|
|
|
1145
1265
|
updateActions();
|
|
1146
1266
|
}
|
|
1147
1267
|
|
|
1268
|
+
async function reloadTab(tab) {
|
|
1269
|
+
if (!tab || tab.dirty) return;
|
|
1270
|
+
try {
|
|
1271
|
+
if (tab.kind === "text") {
|
|
1272
|
+
const text = await Workspace.fetchFileText(tab.entry);
|
|
1273
|
+
if (tab.dirty || CodeEditor.looksBinary(text)) return;
|
|
1274
|
+
if (tab.editor && typeof tab.editor.setContent === "function") {
|
|
1275
|
+
tab.editor.setContent(text);
|
|
1276
|
+
} else if (tab.editor && tab.editor.view) {
|
|
1277
|
+
tab.editor.view.dispatch({
|
|
1278
|
+
changes: { from: 0, to: tab.editor.view.state.doc.length, insert: text },
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
if (tab.isMd && tab.previewEl) {
|
|
1282
|
+
renderPreview(tab);
|
|
1283
|
+
}
|
|
1284
|
+
} else if (tab.kind === "image") {
|
|
1285
|
+
const blob = await Workspace.fetchFileBlob(tab.entry);
|
|
1286
|
+
if (tab.imageUrl) URL.revokeObjectURL(tab.imageUrl);
|
|
1287
|
+
tab.imageUrl = URL.createObjectURL(blob);
|
|
1288
|
+
const img = tab.el.querySelector("img");
|
|
1289
|
+
if (img) img.src = tab.imageUrl;
|
|
1290
|
+
if (tab.zoomController && typeof tab.zoomController.reset === "function") {
|
|
1291
|
+
tab.zoomController.reset();
|
|
1292
|
+
}
|
|
1293
|
+
} else if (tab.kind === "table") {
|
|
1294
|
+
const text = await Workspace.fetchFileText(tab.entry);
|
|
1295
|
+
const result = CodeEditor.renderTable(text, tab.entry.name);
|
|
1296
|
+
const scroller = tab.el.querySelector(".wv-table-scroll");
|
|
1297
|
+
if (scroller) scroller.replaceChildren(result.table);
|
|
1298
|
+
let note = tab.el.querySelector(".wv-table-note");
|
|
1299
|
+
if (result.truncated) {
|
|
1300
|
+
if (!note) {
|
|
1301
|
+
note = el("div", "wv-table-note");
|
|
1302
|
+
tab.el.appendChild(note);
|
|
1303
|
+
}
|
|
1304
|
+
note.textContent = t("workspace.tableTruncated").replace("%{rows}", result.rows);
|
|
1305
|
+
} else if (note) {
|
|
1306
|
+
note.remove();
|
|
1307
|
+
}
|
|
1308
|
+
} else if (tab.kind === "pdf") {
|
|
1309
|
+
const frame = tab.el.querySelector("iframe");
|
|
1310
|
+
if (frame && frame.src) {
|
|
1311
|
+
frame.src = withCacheBuster(frame.src);
|
|
1312
|
+
}
|
|
1313
|
+
} else if (tab.kind === "video" || tab.kind === "audio") {
|
|
1314
|
+
if (tab.mediaEl && tab.mediaEl.src) {
|
|
1315
|
+
tab.mediaEl.src = withCacheBuster(tab.mediaEl.src);
|
|
1316
|
+
if (typeof tab.mediaEl.load === "function") tab.mediaEl.load();
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
} catch (_err) {
|
|
1320
|
+
// Tab reload is best-effort (e.g. file was deleted or unreadable)
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
async function reloadOpenTabs() {
|
|
1325
|
+
const active = activeTab();
|
|
1326
|
+
if (active && !active.dirty) {
|
|
1327
|
+
await reloadTab(active);
|
|
1328
|
+
}
|
|
1329
|
+
for (const tab of tabs) {
|
|
1330
|
+
if (tab !== active && !tab.dirty) {
|
|
1331
|
+
await reloadTab(tab);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1148
1336
|
async function doSave(tab) {
|
|
1149
1337
|
if (!tab.editor) return;
|
|
1150
1338
|
try {
|
|
@@ -1161,10 +1349,22 @@ const WorkspaceView = (() => {
|
|
|
1161
1349
|
function applyMode(tab) {
|
|
1162
1350
|
tab.el.dataset.mode = tab.splitMode ? "split" : (tab.previewMode ? "preview" : "edit");
|
|
1163
1351
|
if ((tab.previewMode || tab.splitMode) && tab.editor) {
|
|
1164
|
-
|
|
1352
|
+
renderPreview(tab);
|
|
1353
|
+
if (tab.splitMode && tab.scrollSync) {
|
|
1354
|
+
tab.scrollSync.syncFrom(tab.editor.view.scrollDOM);
|
|
1355
|
+
}
|
|
1165
1356
|
}
|
|
1166
1357
|
}
|
|
1167
1358
|
|
|
1359
|
+
// innerHTML wipes the preview's scroll position, which would also drag the
|
|
1360
|
+
// editor back through the scroll sync on every keystroke.
|
|
1361
|
+
function renderPreview(tab) {
|
|
1362
|
+
if (!tab.previewEl) return;
|
|
1363
|
+
const top = tab.previewEl.scrollTop;
|
|
1364
|
+
tab.previewEl.innerHTML = CodeEditor.renderMarkdown(tab.editor.getContent());
|
|
1365
|
+
tab.previewEl.scrollTop = top;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1168
1368
|
function togglePreview(tab) {
|
|
1169
1369
|
tab.previewMode = !tab.previewMode;
|
|
1170
1370
|
tab.splitMode = false;
|
|
@@ -1199,6 +1399,7 @@ const WorkspaceView = (() => {
|
|
|
1199
1399
|
previewMode: false,
|
|
1200
1400
|
splitMode: false,
|
|
1201
1401
|
previewEl: null,
|
|
1402
|
+
scrollSync: null,
|
|
1202
1403
|
editor: null,
|
|
1203
1404
|
imageUrl: null,
|
|
1204
1405
|
};
|
|
@@ -1217,13 +1418,15 @@ const WorkspaceView = (() => {
|
|
|
1217
1418
|
tab.dirty = true;
|
|
1218
1419
|
syncDirty(tab);
|
|
1219
1420
|
}
|
|
1220
|
-
if (tab.splitMode && tab.previewEl)
|
|
1221
|
-
tab.previewEl.innerHTML = CodeEditor.renderMarkdown(tab.editor.getContent());
|
|
1222
|
-
}
|
|
1421
|
+
if (tab.splitMode && tab.previewEl) renderPreview(tab);
|
|
1223
1422
|
},
|
|
1224
1423
|
onSave: () => doSave(tab),
|
|
1225
1424
|
});
|
|
1226
1425
|
|
|
1426
|
+
if (isMd) {
|
|
1427
|
+
tab.scrollSync = CodeEditor.linkScrollSync(tab.editor.view.scrollDOM, tab.previewEl);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1227
1430
|
return tab;
|
|
1228
1431
|
}
|
|
1229
1432
|
|
|
@@ -1237,139 +1440,42 @@ const WorkspaceView = (() => {
|
|
|
1237
1440
|
viewport.appendChild(img);
|
|
1238
1441
|
|
|
1239
1442
|
const bar = el("div", "wv-zoom-bar");
|
|
1240
|
-
const outBtn = actionBtn(ICON_ZOOM_OUT,
|
|
1443
|
+
const outBtn = actionBtn(ICON_ZOOM_OUT, "workspace.zoomOut", "wv-zoom-btn");
|
|
1241
1444
|
const level = el("span", "wv-zoom-level");
|
|
1242
|
-
const inBtn = actionBtn(ICON_ZOOM_IN,
|
|
1243
|
-
const fitBtn = actionBtn(ICON_ZOOM_FIT,
|
|
1445
|
+
const inBtn = actionBtn(ICON_ZOOM_IN, "workspace.zoomIn", "wv-zoom-btn");
|
|
1446
|
+
const fitBtn = actionBtn(ICON_ZOOM_FIT, "workspace.zoomFit", "wv-zoom-btn");
|
|
1244
1447
|
bar.append(outBtn, level, inBtn, fitBtn);
|
|
1245
|
-
pane.append(viewport, bar);
|
|
1246
|
-
|
|
1247
|
-
// The picture keeps its natural size and is scaled by transform, so the
|
|
1248
|
-
// number in the bar is a pixel ratio rather than a share of the pane.
|
|
1249
|
-
// `fit` is the scale that shows all of it; the buttons, the wheel and the
|
|
1250
|
-
// double click all move away from there.
|
|
1251
|
-
let scale = 1;
|
|
1252
|
-
let fit = 1;
|
|
1253
|
-
let x = 0;
|
|
1254
|
-
let y = 0;
|
|
1255
|
-
|
|
1256
|
-
function fitScale() {
|
|
1257
|
-
const vw = viewport.clientWidth;
|
|
1258
|
-
const vh = viewport.clientHeight;
|
|
1259
|
-
// A pane inside a hidden tab measures as zero, and a zero ratio would
|
|
1260
|
-
// park the picture at an invisible size — stay neutral until it is real.
|
|
1261
|
-
if (!vw || !vh) return 1;
|
|
1262
|
-
const nw = img.naturalWidth || vw;
|
|
1263
|
-
const nh = img.naturalHeight || vh;
|
|
1264
|
-
return Math.min(1, vw / nw, vh / nh);
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
function pan(offsetX, offsetY) {
|
|
1268
|
-
// Nothing to reveal beyond the edges, so an image narrower than the
|
|
1269
|
-
// pane stays centred instead of being dragged off into a corner.
|
|
1270
|
-
const maxX = Math.max(0, (img.naturalWidth * scale - viewport.clientWidth) / 2);
|
|
1271
|
-
const maxY = Math.max(0, (img.naturalHeight * scale - viewport.clientHeight) / 2);
|
|
1272
|
-
x = Math.max(-maxX, Math.min(maxX, offsetX));
|
|
1273
|
-
y = Math.max(-maxY, Math.min(maxY, offsetY));
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
function render() {
|
|
1277
|
-
pan(x, y);
|
|
1278
|
-
img.style.transform = "translate(" + x + "px, " + y + "px) scale(" + scale + ")";
|
|
1279
|
-
level.textContent = Math.round(scale * 100) + "%";
|
|
1280
|
-
outBtn.disabled = scale <= IMAGE_MIN_ZOOM + 1e-6;
|
|
1281
|
-
inBtn.disabled = scale >= IMAGE_MAX_ZOOM - 1e-6;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
// Zoom around a point (pane centre by default) so the pixels under the
|
|
1285
|
-
// cursor stay put instead of the picture drifting toward a corner.
|
|
1286
|
-
function zoomAt(target, px, py) {
|
|
1287
|
-
const next = Math.max(IMAGE_MIN_ZOOM, Math.min(IMAGE_MAX_ZOOM, target));
|
|
1288
|
-
if (next === scale) return;
|
|
1289
|
-
const k = next / scale;
|
|
1290
|
-
x = px - k * (px - x);
|
|
1291
|
-
y = py - k * (py - y);
|
|
1292
|
-
scale = next;
|
|
1293
|
-
render();
|
|
1294
|
-
}
|
|
1295
1448
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
// small deltas a trackpad sends add up to a glide instead of a jump.
|
|
1323
|
-
viewport.addEventListener("wheel", (ev) => {
|
|
1324
|
-
ev.preventDefault();
|
|
1325
|
-
const anchor = anchorOf(ev);
|
|
1326
|
-
zoomAt(scale * Math.exp(-ev.deltaY * 0.002), anchor[0], anchor[1]);
|
|
1327
|
-
}, { passive: false });
|
|
1328
|
-
|
|
1329
|
-
viewport.addEventListener("dblclick", (ev) => {
|
|
1330
|
-
ev.preventDefault();
|
|
1331
|
-
if (atFit()) {
|
|
1332
|
-
const anchor = anchorOf(ev);
|
|
1333
|
-
zoomAt(closerTarget(), anchor[0], anchor[1]);
|
|
1334
|
-
} else {
|
|
1335
|
-
reset();
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
|
|
1339
|
-
let drag = null;
|
|
1340
|
-
viewport.addEventListener("pointerdown", (ev) => {
|
|
1341
|
-
if (ev.button) return;
|
|
1342
|
-
drag = { id: ev.pointerId, x: ev.clientX, y: ev.clientY };
|
|
1343
|
-
viewport.classList.add("is-panning");
|
|
1344
|
-
viewport.setPointerCapture(ev.pointerId);
|
|
1345
|
-
ev.preventDefault();
|
|
1346
|
-
});
|
|
1347
|
-
viewport.addEventListener("pointermove", (ev) => {
|
|
1348
|
-
if (!drag || ev.pointerId !== drag.id) return;
|
|
1349
|
-
pan(x + ev.clientX - drag.x, y + ev.clientY - drag.y);
|
|
1350
|
-
drag.x = ev.clientX;
|
|
1351
|
-
drag.y = ev.clientY;
|
|
1352
|
-
img.style.transform = "translate(" + x + "px, " + y + "px) scale(" + scale + ")";
|
|
1449
|
+
// A zero-byte or truncated file still fetches fine and then fails to
|
|
1450
|
+
// decode, leaving the browser's own broken-image glyph in the pane. Say
|
|
1451
|
+
// what happened instead.
|
|
1452
|
+
const broken = el("div", "wv-image-broken");
|
|
1453
|
+
const brokenIcon = el("div", "wv-fallback-icon");
|
|
1454
|
+
brokenIcon.innerHTML = fileIconSvg(entry.name);
|
|
1455
|
+
const brokenName = el("div", "wv-fallback-name");
|
|
1456
|
+
brokenName.textContent = entry.name;
|
|
1457
|
+
const brokenHint = el("div", "wv-fallback-hint");
|
|
1458
|
+
brokenHint.textContent = t("workspace.imageBroken");
|
|
1459
|
+
broken.append(brokenIcon, brokenName, brokenHint);
|
|
1460
|
+
|
|
1461
|
+
const setBroken = (isBroken) => pane.classList.toggle("is-broken", isBroken);
|
|
1462
|
+
img.addEventListener("load", () => setBroken(false));
|
|
1463
|
+
img.addEventListener("error", () => setBroken(true));
|
|
1464
|
+
|
|
1465
|
+
pane.append(viewport, bar, broken);
|
|
1466
|
+
|
|
1467
|
+
const zoomController = ImageZoom.create({
|
|
1468
|
+
viewport,
|
|
1469
|
+
image: img,
|
|
1470
|
+
onChange(state) {
|
|
1471
|
+
level.textContent = Math.round(state.scale * 100) + "%";
|
|
1472
|
+
outBtn.disabled = !state.canZoomOut;
|
|
1473
|
+
inBtn.disabled = !state.canZoomIn;
|
|
1474
|
+
},
|
|
1353
1475
|
});
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
viewport.classList.remove("is-panning");
|
|
1358
|
-
};
|
|
1359
|
-
viewport.addEventListener("pointerup", endDrag);
|
|
1360
|
-
viewport.addEventListener("pointercancel", endDrag);
|
|
1361
|
-
|
|
1362
|
-
img.addEventListener("load", reset);
|
|
1363
|
-
if (img.complete) reset();
|
|
1364
|
-
render();
|
|
1365
|
-
|
|
1366
|
-
// Dragging the aside or the window changes the fit ratio, and a tab that
|
|
1367
|
-
// was opened in the background only finds its real size once it is shown —
|
|
1368
|
-
// so refit on every new size, but leave a deliberate zoom alone.
|
|
1369
|
-
const observer = typeof ResizeObserver === "function"
|
|
1370
|
-
? new ResizeObserver(() => { if (atFit()) reset(); })
|
|
1371
|
-
: null;
|
|
1372
|
-
if (observer) observer.observe(viewport);
|
|
1476
|
+
inBtn.addEventListener("click", zoomController.zoomIn);
|
|
1477
|
+
outBtn.addEventListener("click", zoomController.zoomOut);
|
|
1478
|
+
fitBtn.addEventListener("click", zoomController.reset);
|
|
1373
1479
|
|
|
1374
1480
|
return {
|
|
1375
1481
|
id: entry.path,
|
|
@@ -1382,7 +1488,7 @@ const WorkspaceView = (() => {
|
|
|
1382
1488
|
previewEl: null,
|
|
1383
1489
|
editor: null,
|
|
1384
1490
|
imageUrl: url,
|
|
1385
|
-
|
|
1491
|
+
zoomController,
|
|
1386
1492
|
};
|
|
1387
1493
|
}
|
|
1388
1494
|
|
|
@@ -1505,6 +1611,9 @@ const WorkspaceView = (() => {
|
|
|
1505
1611
|
const existing = tabs.find((x) => x.id === entry.path);
|
|
1506
1612
|
if (existing) {
|
|
1507
1613
|
activate(existing.id);
|
|
1614
|
+
if (!existing.dirty) {
|
|
1615
|
+
await reloadTab(existing);
|
|
1616
|
+
}
|
|
1508
1617
|
// A fallback pane renders nothing of its own — the handoff to the OS is
|
|
1509
1618
|
// its entire effect, and it is not repeatable by redrawing. Re-selecting
|
|
1510
1619
|
// the tab has to redo it, or a second click after the user closes the
|
|
@@ -1597,7 +1706,7 @@ const WorkspaceView = (() => {
|
|
|
1597
1706
|
activeId = null;
|
|
1598
1707
|
}
|
|
1599
1708
|
|
|
1600
|
-
return { root, openTab, activate, destroy };
|
|
1709
|
+
return { root, openTab, activate, reloadOpenTabs, destroy };
|
|
1601
1710
|
}
|
|
1602
1711
|
|
|
1603
1712
|
// Draggable split between the file tree and the viewer. The tree width is a
|
|
@@ -1669,7 +1778,8 @@ const WorkspaceView = (() => {
|
|
|
1669
1778
|
searchInput.setAttribute("aria-label", t("workspace.search"));
|
|
1670
1779
|
const searchClear = el("button", "wt-search-clear");
|
|
1671
1780
|
searchClear.type = "button";
|
|
1672
|
-
searchClear.
|
|
1781
|
+
searchClear.setAttribute("data-tooltip", t("workspace.closeTab"));
|
|
1782
|
+
searchClear.setAttribute("data-i18n-tooltip", "workspace.closeTab");
|
|
1673
1783
|
searchClear.innerHTML = ICON_CLOSE;
|
|
1674
1784
|
searchWrap.appendChild(searchIcon);
|
|
1675
1785
|
searchWrap.appendChild(searchInput);
|
|
@@ -1677,7 +1787,8 @@ const WorkspaceView = (() => {
|
|
|
1677
1787
|
|
|
1678
1788
|
const refresh = el("button", "wt-bar-btn");
|
|
1679
1789
|
refresh.type = "button";
|
|
1680
|
-
refresh.
|
|
1790
|
+
refresh.setAttribute("data-tooltip", t("workspace.refresh"));
|
|
1791
|
+
refresh.setAttribute("data-i18n-tooltip", "workspace.refresh");
|
|
1681
1792
|
refresh.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><polyline points="21 3 21 9 15 9"/></svg>';
|
|
1682
1793
|
bar.appendChild(searchWrap);
|
|
1683
1794
|
bar.appendChild(refresh);
|
|
@@ -1702,9 +1813,8 @@ const WorkspaceView = (() => {
|
|
|
1702
1813
|
if (!count) root.classList.remove("mobile-tree-visible");
|
|
1703
1814
|
setActiveFilePath(activeId);
|
|
1704
1815
|
},
|
|
1705
|
-
() => {
|
|
1706
|
-
|
|
1707
|
-
return hidden;
|
|
1816
|
+
(hidden) => {
|
|
1817
|
+
root.classList.toggle("tree-hidden", hidden);
|
|
1708
1818
|
},
|
|
1709
1819
|
() => {
|
|
1710
1820
|
root.classList.add("mobile-tree-visible");
|
|
@@ -1868,6 +1978,7 @@ const WorkspaceView = (() => {
|
|
|
1868
1978
|
const offTaskComplete = Workspace.on("workspace:taskCompleted", (payload) => {
|
|
1869
1979
|
if (payload && payload.sessionId === Workspace.state.sessionId) {
|
|
1870
1980
|
reloadTree();
|
|
1981
|
+
viewer.reloadOpenTabs();
|
|
1871
1982
|
}
|
|
1872
1983
|
});
|
|
1873
1984
|
const offAll = () => { offSessionChanged(); offTaskComplete(); };
|
|
@@ -1904,6 +2015,14 @@ const WorkspaceView = (() => {
|
|
|
1904
2015
|
return { name, path: absPath, type: "file", size: 0 };
|
|
1905
2016
|
}
|
|
1906
2017
|
|
|
2018
|
+
// The preview panel resolves a file:// URL against its /preview/f proxy, so
|
|
2019
|
+
// handing it the original path keeps the address bar showing the file's real
|
|
2020
|
+
// location instead of the session-relative /preview/s form.
|
|
2021
|
+
function fileUrl(absPath) {
|
|
2022
|
+
if (/^file:\/\//i.test(absPath)) return absPath;
|
|
2023
|
+
return absPath.startsWith("/") ? "file://" + absPath : "file:///" + absPath;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
1907
2026
|
// Open a file:// link target in the Files tab of the session aside.
|
|
1908
2027
|
// Returns true when the viewer handled it; false lets the caller fall back
|
|
1909
2028
|
// to the system open action. HTML files open in the preview panel instead
|
|
@@ -1912,7 +2031,7 @@ const WorkspaceView = (() => {
|
|
|
1912
2031
|
if (!absPath || !Workspace.state.hasSession()) return false;
|
|
1913
2032
|
const entry = toEntry(absPath);
|
|
1914
2033
|
if (/\.html?$/i.test(entry.name) && window.Clacky && Clacky.Preview) {
|
|
1915
|
-
return Clacky.Preview.open(
|
|
2034
|
+
return Clacky.Preview.open(fileUrl(absPath));
|
|
1916
2035
|
}
|
|
1917
2036
|
if (window.Clacky && Clacky.Aside) Clacky.Aside.open();
|
|
1918
2037
|
const tabBtn = document.querySelector('.aside-tab[data-tab="files"]');
|
|
@@ -1923,8 +2042,15 @@ const WorkspaceView = (() => {
|
|
|
1923
2042
|
return true;
|
|
1924
2043
|
}
|
|
1925
2044
|
|
|
1926
|
-
// autoOpenWithSystem is exported for the regression harness
|
|
1927
|
-
|
|
2045
|
+
// autoOpenWithSystem is exported for the regression harness; the icon
|
|
2046
|
+
// helpers are reused by the git panel so both trees show the same file
|
|
2047
|
+
// glyphs.
|
|
2048
|
+
return {
|
|
2049
|
+
mount, openFile, autoOpenWithSystem,
|
|
2050
|
+
fileIcon: fileIconSvg,
|
|
2051
|
+
iconFolder: ICON_FOLDER,
|
|
2052
|
+
iconFolderOpen: ICON_FOLDER_OPEN,
|
|
2053
|
+
};
|
|
1928
2054
|
})();
|
|
1929
2055
|
|
|
1930
2056
|
if (window.Clacky) Clacky.WorkspaceView = WorkspaceView;
|