feat: composer dock in the bar (send / insert)
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
3b457aad1c
commit
a404829261
1 file changed
+92
-1
@@ -67,6 +67,7 @@ import {
|
|||||||
import * as storage from "./storage.js";
|
import * as storage from "./storage.js";
|
||||||
import { record, panelState, moveIndex, otherTab, toggleFavorite, isFavorite } from "./history.js";
|
import { record, panelState, moveIndex, otherTab, toggleFavorite, isFavorite } from "./history.js";
|
||||||
import { renderPanel, renderPreview } from "./panel.js";
|
import { renderPanel, renderPreview } from "./panel.js";
|
||||||
|
import { dockAction } from "./dock.js";
|
||||||
import {
|
import {
|
||||||
agentKey,
|
agentKey,
|
||||||
agentName,
|
agentName,
|
||||||
@@ -247,6 +248,8 @@ export default class Composer extends View {
|
|||||||
}
|
}
|
||||||
this.panelScroll = VirtualListScrollHandle.new();
|
this.panelScroll = VirtualListScrollHandle.new();
|
||||||
this.favorites = storage.loadFavorites(this.store);
|
this.favorites = storage.loadFavorites(this.store);
|
||||||
|
// The buttons of the dock - one dock for every agent (dock.js).
|
||||||
|
this.dock = storage.loadDock(this.store);
|
||||||
|
|
||||||
// The preview of an image (null when closed).
|
// The preview of an image (null when closed).
|
||||||
this.preview = null;
|
this.preview = null;
|
||||||
@@ -2495,13 +2498,101 @@ export default class Composer extends View {
|
|||||||
(event, cx) => this.toggleCurrentFavorite(cx),
|
(event, cx) => this.toggleCurrentFavorite(cx),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(div().flex_1())
|
.child(div().w(1).h(18).flex_none().bg(t.border))
|
||||||
|
.child(this.renderDock(t, active))
|
||||||
.child(this.renderChip(t, agent, status, files.length))
|
.child(this.renderChip(t, agent, status, files.length))
|
||||||
.child(stop ? this.renderStop(t, agent) : this.renderSend(t, agent, over)),
|
.child(stop ? this.renderStop(t, agent) : this.renderSend(t, agent, over)),
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dock: the buttons the person pinned, between the star and the chip.
|
||||||
|
* It is 28 px high whatever is in it (the block must not grow for it) and it
|
||||||
|
* scrolls sideways when the buttons do not fit.
|
||||||
|
*/
|
||||||
|
renderDock(t, active) {
|
||||||
|
const row = h_flex()
|
||||||
|
.id("composer-dock")
|
||||||
|
.flex_1()
|
||||||
|
.min_w(0)
|
||||||
|
.h(28)
|
||||||
|
.gap(6)
|
||||||
|
.items_center()
|
||||||
|
.overflow_x_scroll();
|
||||||
|
|
||||||
|
if (this.dock.length === 0) {
|
||||||
|
return row.child(
|
||||||
|
div().flex_none().text_size(12).text_color(t.dim).child("Prawy klik w Ulubionych → Przypnij do docka"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return row.children(this.dock.map((button) => this.renderDockButton(t, button, active)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One button of the dock: `send` has a fill, `insert` a frame and the ✎ mark. */
|
||||||
|
renderDockButton(t, button, active) {
|
||||||
|
const insert = button.mode === "insert";
|
||||||
|
let el = h_flex()
|
||||||
|
.id(`dock-${button.id}`)
|
||||||
|
.h(28)
|
||||||
|
.px(11)
|
||||||
|
.rounded(8)
|
||||||
|
.flex_none()
|
||||||
|
.max_w(150)
|
||||||
|
.items_center()
|
||||||
|
.text_size(12)
|
||||||
|
.text_color(active ? t.foreground : t.dim)
|
||||||
|
.tooltip(button.text);
|
||||||
|
|
||||||
|
el = insert ? el.border(1).border_dashed().border_color(t.border) : el.bg(t.chrome);
|
||||||
|
if (active) {
|
||||||
|
el = el
|
||||||
|
.cursor_pointer()
|
||||||
|
.hover((s) => s.bg(t.hover))
|
||||||
|
.on_click((event, cx) => this.dockPress(button, cx));
|
||||||
|
}
|
||||||
|
if (insert) el = el.child(div().flex_none().text_color(t.dim).child("✎ "));
|
||||||
|
return el.child(div().min_w(0).truncate().child(button.label));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A button of the dock was clicked.
|
||||||
|
*
|
||||||
|
* `insert` puts the text in at the caret and sends nothing. `send` goes the
|
||||||
|
* way of Enter (`finish`: the queue, the countdown, `--force` for a blocked
|
||||||
|
* agent, the check of who the agent is) but leaves the field, the draft and
|
||||||
|
* the attachments alone: only the text of the button goes out.
|
||||||
|
*/
|
||||||
|
dockPress(button, cx) {
|
||||||
|
const hasAgent = Boolean(this.target());
|
||||||
|
const action = dockAction(button, { hasAgent });
|
||||||
|
if (action === "none" || !hasAgent) return;
|
||||||
|
|
||||||
|
if (action === "insert") {
|
||||||
|
this.textarea.replace(button.text);
|
||||||
|
this.syncFieldAfterReplace();
|
||||||
|
this.notice("Wstawiono w miejscu kursora — nic nie zostało wysłane.");
|
||||||
|
cx.notify();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.syncOk(cx)) {
|
||||||
|
this.notice("Agent się zmienił — wiadomość nie została wysłana.", "problem", cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const agent = this.target();
|
||||||
|
if (!agent) {
|
||||||
|
this.notice("Composer nie ma do kogo pisać — brak agenta.", "problem", cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const over = overLimit(button.text);
|
||||||
|
if (over > 0) {
|
||||||
|
this.notice(`Limit ${LIMITS.messageChars} znaków · ${over} za dużo`, "problem", cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.finish(agent, button.text.trim(), cx);
|
||||||
|
}
|
||||||
|
|
||||||
/** A round icon button next to the field (history, star). */
|
/** A round icon button next to the field (history, star). */
|
||||||
renderIcon(t, id, glyph, lit, enabled, action) {
|
renderIcon(t, id, glyph, lit, enabled, action) {
|
||||||
return div()
|
return div()
|
||||||
|
|||||||
Reference in new issue
Block a user