Files
client/native/ui/chat.slint
T

642 lines
49 KiB
Plaintext

import { ListView, ScrollView } from "std-widgets.slint";
import { Theme } from "theme.slint";
import { ActionButton, TextField, Toggle } from "controls.slint";
export struct ChatMeasure { width: float, height: float }
export struct ChatRun {
x: float, y: float, width: float, height: float, text: string,
font-size: float, font-weight: int, italic: bool, underline: bool, strike: bool,
mono: bool, marked: bool, concealed: bool, selected: bool, foreground: color, use-color: bool,
action: string, asset: image, image-ready: bool, start: int, end: int,
}
export struct ChatVisual {
id: string, message: string, plain: string, kind: int, height: float, content-width: float, indent: float, label: string,
author: string, time: string, time-width: float, time-below: bool, author-color: color, avatar: image, has-avatar: bool,
header: bool, own: bool, compact: bool, runs: [ChatRun], preview-position: int,
group-start: bool, bubble-x: float, bubble-width: float, first-block: bool, last-block: bool, body-y: float, body-end-gap: float, system: bool,
}
export struct ChatTab { id: string, label: string, unread: string, active: bool, closable: bool }
export struct ChatCompletion { id: string, label: string }
export global ChatBridge {
in-out property <[ChatTab]> tabs;
in-out property <[ChatVisual]> rows;
in-out property <[ChatVisual]> before;
in-out property <[ChatVisual]> after;
in-out property <[ChatCompletion]> completions;
in-out property <[ChatCompletion]> tools;
in-out property <string> title;
in-out property <string> active-tree-key;
in-out property <string> status;
in-out property <string> error;
in-out property <int> language-revision;
in-out property <int> action-revision;
in-out property <string> editor-text;
in-out property <string> placeholder;
in-out property <string> search;
in-out property <bool> search-open;
in-out property <string> emoji-search;
in-out property <string> selected-text;
in-out property <int> editor-anchor;
in-out property <int> editor-cursor;
in-out property <int> editor-revision;
in-out property <int> conversation-revision;
in-out property <int> editor-byte-length;
in-out property <int> completion-index;
in-out property <bool> enabled;
in-out property <bool> can-send;
in-out property <bool> can-attach;
in-out property <bool> can-info;
in-out property <bool> can-undo;
in-out property <bool> can-redo;
in-out property <bool> loading;
in-out property <bool> has-older;
in-out property <bool> older-page;
in-out property <bool> hybrid: true;
in-out property <bool> desktop: true;
in-out property <bool> toolbar-visible: true;
in-out property <bool> toolbar-dynamic;
in-out property <bool> composing;
in-out property <bool> focus-request;
in-out property <bool> bottom-pinned: true;
in-out property <float> log-height;
in-out property <float> log-position;
in-out property <float> content-width;
in-out property <float> editor-width;
pure callback translate(string, int) -> string;
public pure function tr(key: string) -> string { return translate(key, language-revision); }
callback toggle-search();
callback choose-tab(string);
callback close-tab(string);
callback history(bool);
callback search-history(string);
callback send();
callback attach();
callback client-info();
callback draft-edited(string, int, int);
callback selection-changed(int, int);
callback composition-changed(bool);
callback format(string);
callback command(string) -> bool;
callback complete(int);
callback emoji(string);
callback set-hybrid(bool);
callback activate(string);
pure callback action-caption(string, int) -> string;
public pure function action-label(key: string) -> string { return action-caption(key, action-revision); }
callback select-text(string, float, float, bool);
callback copy-selection();
callback preview-edit(int);
callback layout(float, float);
}
export global MarkupBridge {
in-out property <bool> visible;
in-out property <string> title;
in-out property <string> close-label;
in-out property <[ChatVisual]> rows;
callback close();
callback layout(float);
callback render-request(string);
}
component ChatSelectionArea inherits TouchArea {
in property <string> row-id;
in property <string> action;
in property <float> offset-x;
in property <float> offset-y;
callback begun();
mouse-cursor: root.action != "" ? pointer : text;
clicked => { if root.action != "" && ChatBridge.selected-text == "" { ChatBridge.activate(root.action); } }
pointer-event(event) => {
if event.button == PointerEventButton.left && event.kind == PointerEventKind.down {
root.begun();
ChatBridge.select-text(root.row-id, root.offset-x + self.mouse-x / 1px, root.offset-y + self.mouse-y / 1px, false);
}
}
moved => { if self.pressed { ChatBridge.select-text(root.row-id, root.offset-x + self.mouse-x / 1px, root.offset-y + self.mouse-y / 1px, true); } }
}
global ChatPaint {
out property <color> incoming: Theme.high-contrast ? Theme.bg : Theme.dark ? #697a97 : #a4bae0;
out property <color> outgoing: Theme.high-contrast ? Theme.bg : Theme.dark ? #0c1326 : #8acecc;
out property <color> bubble-text: Theme.high-contrast ? Theme.fg : Theme.dark ? #fff : #333;
out property <color> system-start: Theme.high-contrast ? Theme.bg : Theme.dark ? #131824 : #c9d9e5;
}
component ComposerButton inherits Rectangle {
in property <string> label;
in property <string> text: root.label;
in property <string> icon;
in property <bool> enabled: true;
in property <bool> tool;
in property <bool> accented;
in property <bool> italic;
in property <int> weight: 500;
out property <bool> has-focus: focus.has-focus;
callback clicked();
min-height: ChatBridge.desktop ? (root.tool ? 24px : 26px) : Theme.touch-target;
min-width: !root.visible ? 0px : root.icon != "" && ChatBridge.desktop ? 26px : max(ChatBridge.desktop ? 24px : 44px, caption.preferred-width + (ChatBridge.desktop ? 10px : 16px));
preferred-height: self.min-height;
preferred-width: self.min-width;
border-radius: root.tool ? 2px : 4px;
border-width: focus.has-focus ? 2px : 0px;
border-color: Theme.tint;
background: touch.has-hover && root.enabled ? Theme.deviant : transparent;
opacity: root.enabled ? 1 : 0.5;
accessible-role: button;
accessible-label: root.label;
accessible-enabled: root.enabled;
accessible-action-default => { if root.enabled { root.clicked(); } }
if ChatBridge.desktop && (root.icon != "" || root.text != root.label): Tooltip { text: @markdown("\{root.label}"); }
caption := Text {
visible: root.icon == "" || !ChatBridge.desktop;
text: self.visible ? root.text : ""; color: Theme.fg; font-family: Theme.font-family;
font-size: 13px; font-weight: root.weight; font-italic: root.italic; horizontal-alignment: center; vertical-alignment: center; overflow: elide;
}
if root.icon != "" && ChatBridge.desktop: Path {
x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2;
width: 18px; height: 18px; viewbox-width: 24; viewbox-height: 24;
commands: root.icon; fill: transparent; stroke: root.accented ? (Theme.dark ? #6fb8ff : Theme.tint) : Theme.fg; stroke-width: 1.6px;
}
focus := FocusScope {
enabled: root.enabled && root.visible;
key-pressed(event) => { if event.text == Key.Return || event.text == " " { root.clicked(); return accept; } return reject; }
}
touch := TouchArea { enabled: root.enabled; clicked => { focus.focus(); root.clicked(); } }
}
component ChatAvatar inherits Rectangle {
in property <image> asset;
in property <bool> has-image;
border-radius: self.width / 2;
clip: true;
background: root.has-image ? transparent : Theme.contrast;
accessible-role: none;
if root.has-image: Image { source: root.asset; image-fit: cover; }
if !root.has-image: Rectangle { x: parent.width * 0.35; y: parent.height * 0.18; width: parent.width * 0.3; height: self.width; border-radius: self.width / 2; background: Theme.muted; }
if !root.has-image: Rectangle { x: parent.width * 0.2; y: parent.height * 0.54; width: parent.width * 0.6; height: parent.height * 0.34; border-radius: self.height / 2; background: Theme.muted; }
}
component RichRow inherits Rectangle {
in property <ChatVisual> visual;
in property <bool> inert;
in property <length> viewport-width;
callback render-request(string);
render-request(id) => { ChatBridge.activate(id); }
height: root.visual.height * 1px + ((root.visual.kind == 6 || root.visual.kind == 7) ? Theme.touch-target : 0px);
width: max(root.viewport-width, root.visual.content-width * 1px);
private property <bool> detailed: !root.inert && ChatBridge.desktop && !root.visual.compact && root.visual.bubble-width > 0;
private property <length> body-height: self.height - root.visual.body-y * 1px - root.visual.body-end-gap * 1px;
private property <color> bubble-color: root.visual.own ? ChatPaint.outgoing : ChatPaint.incoming;
private property <color> ink: root.detailed ? ChatPaint.bubble-text : root.visual.system ? (ChatBridge.desktop && !Theme.high-contrast ? Theme.subtitle : Theme.muted) : Theme.fg;
private property <color> link-ink: root.detailed && !Theme.high-contrast ? (root.visual.own ? (Theme.dark ? #6fb8ff : #134971) : Theme.dark ? #fff : #081cbd) : Theme.tint;
background: !ChatBridge.desktop && !root.visual.compact && !root.visual.header && !root.inert && !root.visual.system ? (root.visual.own ? Theme.contrast : Theme.muted) : transparent;
border-radius: 4px;
if root.detailed: Rectangle {
x: root.visual.bubble-x * 1px; y: root.visual.body-y * 1px;
width: root.visual.bubble-width * 1px; height: root.body-height;
background: root.bubble-color; border-radius: 8px;
if !root.visual.first-block: Rectangle { height: min(8px, parent.height); background: root.bubble-color; }
if !root.visual.last-block: Rectangle { y: max(0px, parent.height - 8px); height: min(8px, parent.height); background: root.bubble-color; }
if root.visual.first-block && root.visual.group-start: Rectangle { width: 8px; height: 8px; background: root.bubble-color; }
}
if root.detailed && root.visual.first-block && root.visual.group-start: Path {
x: root.visual.bubble-x * 1px - 11px; y: root.visual.body-y * 1px;
width: 12px; height: 14px; viewbox-width: 12; viewbox-height: 14;
commands: "M 0 0 L 12 0 L 12 14 Z"; fill: root.bubble-color;
}
if root.visual.system: Rectangle {
x: root.visual.bubble-x * 1px; y: root.visual.body-y * 1px; height: root.body-height;
width: max(0px, root.viewport-width - self.x - (ChatBridge.desktop ? 20px : 8px));
border-radius: 10px;
background: @linear-gradient(90deg, ChatPaint.system-start 0%, transparent 80%);
}
if root.visual.kind == 3 || root.visual.kind == 4 || root.visual.kind == 7 || root.visual.kind == 8: Rectangle {
x: root.detailed ? (root.visual.bubble-x + 5) * 1px : 0px;
y: root.visual.body-y * 1px; height: root.body-height;
width: root.detailed ? max(0px, root.visual.bubble-width * 1px - 10px) : parent.width;
background: root.visual.kind == 4 ? Theme.deviant : root.visual.kind == 8 ? Theme.bg : Theme.header;
border-radius: 4px;
}
row-focus := FocusScope {
accessible-role: text;
accessible-label: root.visual.plain;
key-pressed(event) => {
if (event.modifiers.control || event.modifiers.meta) && event.text == "c" { ChatBridge.copy-selection(); return accept; }
if (event.modifiers.control || event.modifiers.meta) && event.text == "a" { ChatBridge.select-text(root.visual.id, 0, 0, false); ChatBridge.select-text(root.visual.id, 100000, root.visual.height, true); return accept; }
return reject;
}
}
if root.visual.kind == 2: Rectangle { x: root.visual.indent * 1px; y: root.visual.body-y * 1px + 5px; height: 1px; width: root.detailed ? max(0px, (root.visual.bubble-x + root.visual.bubble-width - root.visual.indent) * 1px - 12.5px) : parent.width - self.x; background: Theme.outline; }
if root.visual.kind == 4: Rectangle { x: root.visual.indent * 1px - 8px; y: root.visual.body-y * 1px; height: root.body-height; width: 1px; background: Theme.muted; }
if root.visual.kind == 8: Rectangle { x: root.detailed ? root.visual.bubble-x * 1px + 5px : 0px; y: parent.height - root.visual.body-end-gap * 1px - 1px; height: 1px; width: root.detailed ? max(0px, root.visual.bubble-width * 1px - 10px) : parent.width; background: Theme.outline; }
if root.visual.system && (!ChatBridge.desktop || root.visual.first-block): Text {
x: ChatBridge.desktop ? max(root.visual.bubble-x * 1px, root.viewport-width - 25px - self.width) : 0px;
width: ChatBridge.desktop ? root.visual.time-width * 1px : parent.width;
y: !ChatBridge.desktop ? parent.height - 18px
: root.visual.time-below ? parent.height - self.height - 4px : root.visual.body-y * 1px + 4px;
height: ChatBridge.desktop ? Theme.font-size : 18px;
text: root.visual.label; color: ChatBridge.desktop && !Theme.high-contrast ? Theme.subtitle : Theme.muted;
opacity: ChatBridge.desktop && !Theme.high-contrast ? 0.75 : 1;
font-family: Theme.font-family; font-size: ChatBridge.desktop ? Theme.small-font : 13px;
font-weight: ChatBridge.desktop ? Theme.normal-weight : 400;
overflow: ChatBridge.desktop ? clip : elide; horizontal-alignment: right; vertical-alignment: ChatBridge.desktop ? top : center;
}
if root.visual.kind == 3 && root.visual.label != "": Text { x: root.visual.indent * 1px; y: root.visual.body-y * 1px; height: 20px; text: root.visual.label; color: Theme.muted; font-family: Theme.font-family; font-size: 12px; }
if root.visual.header: HorizontalLayout {
y: ChatBridge.desktop ? 4px : 0px;
height: ChatBridge.desktop ? 22px : parent.height;
x: ChatBridge.desktop ? root.visual.bubble-x * 1px : 0px;
width: max(0px, parent.width - self.x - (ChatBridge.desktop ? 10px : 0px));
padding: ChatBridge.desktop ? 0px : 4px; spacing: ChatBridge.desktop ? 5px : 8px;
alignment: ChatBridge.desktop ? start : stretch;
if root.visual.compact: Text { width: 65px; text: root.visual.time; color: Theme.muted; font-family: Theme.font-family; font-size: 13px; overflow: elide; vertical-alignment: center; }
if !ChatBridge.desktop && !root.visual.compact && root.visual.author != "": ChatAvatar { width: 33px; height: 33px; asset: root.visual.avatar; has-image: root.visual.has-avatar; }
Text { text: root.visual.author; color: Theme.high-contrast ? Theme.fg : root.visual.author-color; font-family: Theme.font-family; font-size: ChatBridge.desktop ? Theme.large-font : 13px; font-weight: 700; overflow: elide; vertical-alignment: center; horizontal-stretch: 1; }
if !root.visual.compact: Text { text: root.visual.time; color: ChatBridge.desktop ? Theme.fg : Theme.muted; font-family: Theme.font-family; font-size: ChatBridge.desktop ? Theme.small-font : 13px; font-weight: ChatBridge.desktop ? 300 : 400; vertical-alignment: center; horizontal-alignment: ChatBridge.desktop ? left : right; horizontal-stretch: ChatBridge.desktop ? 0 : 1; }
}
if ChatBridge.desktop && root.visual.header && root.visual.author != "": Rectangle {
x: 15px; y: 12.6px; width: 37.95px; height: self.width;
if root.visual.has-avatar: ChatAvatar { asset: root.visual.avatar; has-image: true; }
// ContactPlaceholder is an outlined portrait inside an 18/23-diameter subtitle circle.
if !root.visual.has-avatar: Rectangle {
x: (parent.width - self.width) / 2; y: self.x; width: parent.width * 18 / 23; height: self.width;
border-radius: self.width / 2; background: Theme.high-contrast ? Theme.fg : Theme.subtitle;
Path {
width: parent.width; height: parent.height; viewbox-width: 18; viewbox-height: 18;
commands: "M 4.5 14.1 V 13 A 2.25 2.25 0 0 1 6.75 10.75 H 11.25 A 2.25 2.25 0 0 1 13.5 13 V 14.1 M 9 3.6 A 2.25 2.25 0 1 1 9 8.1 A 2.25 2.25 0 1 1 9 3.6 Z";
fill: transparent; stroke: Theme.shaded; stroke-width: 1.75px;
}
}
}
if ChatBridge.desktop && !root.inert && !root.visual.header && root.visual.first-block && root.visual.compact && !root.visual.system: HorizontalLayout {
x: 18px; width: max(0px, root.visual.bubble-x * 1px - self.x - 5px); height: 18px; spacing: 5px;
Text { width: 65px; text: root.visual.time; color: Theme.muted; font-family: Theme.font-family; font-size: 11px; overflow: elide; vertical-alignment: center; }
if root.visual.author != "": Text { text: root.visual.author; color: Theme.high-contrast ? Theme.fg : root.visual.author-color; font-family: Theme.font-family; font-size: 13px; font-weight: 600; overflow: elide; vertical-alignment: center; }
}
if root.detailed && root.visual.last-block && !root.visual.group-start: Text {
x: 15px; y: max(0px, parent.height - 18px); width: max(0px, (root.visual.bubble-x - 25) * 1px); height: 17px;
text: root.visual.time; color: row-hover.has-hover || row-focus.has-focus ? Theme.muted : transparent;
font-family: Theme.font-family; font-size: 11px; overflow: elide; horizontal-alignment: right; vertical-alignment: center;
accessible-role: text; accessible-label: self.text;
}
row-hover := TouchArea { enabled: root.detailed && !root.visual.group-start; }
for run in root.visual.runs: Rectangle {
x: run.x * 1px; y: run.y * 1px; width: max(1px, run.width * 1px); height: run.height * 1px;
background: run.selected ? Theme.tint : run.concealed ? (root.detailed ? root.ink : Theme.contrast) : run.marked ? Theme.deviant : transparent;
border-radius: 2px;
if run.image-ready && !run.concealed: Image { source: run.asset; image-fit: contain; }
if !run.image-ready && !run.concealed: Text {
text: run.text;
color: run.selected || run.marked ? Theme.fg
: run.use-color && !Theme.high-contrast ? run.foreground
: run.action != "" && !root.inert ? root.link-ink
: root.visual.system && run.font-weight >= 600 && !Theme.high-contrast ? (Theme.dark ? #acacac : #646464)
: root.visual.kind == 3 || root.visual.kind == 4 || root.visual.kind == 7 || root.visual.kind == 8 ? Theme.fg : root.ink;
font-family: run.mono ? "monospace" : Theme.font-family;
font-size: run.font-size * 1px; font-weight: run.font-weight; font-italic: run.italic;
vertical-alignment: top;
accessible-role: none;
}
if run.underline && !run.concealed: Rectangle { y: parent.height - 2px; height: 1px; background: run.use-color && !Theme.high-contrast ? run.foreground : root.link-ink; }
if run.strike && !run.concealed: Rectangle { y: parent.height / 2; height: 1px; background: run.use-color && !Theme.high-contrast ? run.foreground : root.ink; }
if !root.inert && run.action != "": action-focus := FocusScope {
accessible-role: button;
accessible-label: run.concealed ? ChatBridge.tr("chat.message.spoiler.reveal") : run.action != "" ? ChatBridge.action-label(run.action) : run.text;
accessible-action-default => { if run.action != "" { ChatBridge.activate(run.action); } }
key-pressed(event) => {
if event.text == Key.Return || event.text == " " { if run.action != "" { ChatBridge.activate(run.action); return accept; } }
if (event.modifiers.control || event.modifiers.meta) && event.text == "c" { ChatBridge.copy-selection(); return accept; }
return reject;
}
Rectangle { border-width: action-focus.has-focus ? 1px : 0px; border-color: Theme.tint; background: transparent; }
ChatSelectionArea { row-id: root.visual.id; action: run.action; offset-x: run.x; offset-y: run.y; begun => { action-focus.focus(); } }
}
if !root.inert && run.action == "": ChatSelectionArea { row-id: root.visual.id; offset-x: run.x; offset-y: run.y; begun => { row-focus.focus(); } }
}
if root.inert && root.visual.preview-position >= 0: TouchArea { clicked => { ChatBridge.preview-edit(root.visual.preview-position); } }
if root.visual.kind == 6 || root.visual.kind == 7: HorizontalLayout {
x: root.detailed ? root.visual.bubble-x * 1px + 5px : 0px;
width: root.detailed ? max(0px, root.visual.bubble-width * 1px - 10px) : parent.width;
y: (root.visual.height - root.visual.body-end-gap) * 1px; height: Theme.touch-target;
for run in root.visual.runs: ActionButton { text: ChatBridge.action-label(run.action) != "" ? ChatBridge.action-label(run.action) : root.visual.kind == 7 ? ChatBridge.tr("chat.message.mermaid.placeholder.load") : ChatBridge.tr("chat.snippet.math"); visible: run.action != "" && !run.image-ready; clicked => { root.render-request(run.action); } }
}
}
// Static help and editor fragments share the exact native message display list.
export component RichDocument inherits Rectangle {
in property <[ChatVisual]> rows;
min-width: 0px; preferred-width: 100%;
in property <bool> inert: true;
callback render-request(string);
render-request(id) => { ChatBridge.activate(id); }
height: contents.preferred-height;
contents := VerticalLayout { spacing: 0px; for row in root.rows: RichRow { visual: row; viewport-width: root.width; inert: root.inert; render-request(id) => { root.render-request(id); } } }
}
export component MarkupPanel inherits Rectangle {
background: Theme.bg;
changed width => { MarkupBridge.layout(max(32, (self.width - 32px) / 1px)); }
init => { focus.focus(); }
TouchArea { }
focus := FocusScope {
VerticalLayout {
padding: 16px; spacing: 8px;
HorizontalLayout {
min-height: Theme.touch-target;
Text { text: MarkupBridge.title; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; font-weight: 600; vertical-alignment: center; accessible-role: text; accessible-label: self.text; }
ActionButton { text: MarkupBridge.close-label; clicked => { MarkupBridge.close(); } }
}
ScrollView {
RichDocument { rows: MarkupBridge.rows; inert: true; render-request(id) => { MarkupBridge.render-request(id); } }
}
}
}
}
export component ChatScreen inherits Rectangle {
background: Theme.shaded;
min-width: 0px; min-height: 0px;
preferred-width: 100%; preferred-height: 100%;
in property <bool> embedded-header;
private property <length> editor-viewport: max(32px, editor-slot.width - (ChatBridge.desktop ? 20px : 0px));
private property <length> timeline-viewport: max(32px, root.width - (ChatBridge.desktop ? 8px : 32px));
private property <bool> toolbar-open: ChatBridge.toolbar-visible && (!ChatBridge.toolbar-dynamic || input.has-focus || root.show-tools || root.show-emoji || bold.has-focus || italic.has-focus || toolbar-more.has-focus || emoji.has-focus || attachment.has-focus || send.has-focus);
changed editor-viewport => { ChatBridge.layout(root.timeline-viewport / 1px, self.editor-viewport / 1px); }
changed timeline-viewport => { ChatBridge.layout(self.timeline-viewport / 1px, root.editor-viewport / 1px); }
init => { ChatBridge.layout(root.timeline-viewport / 1px, root.editor-viewport / 1px); }
function toggle-emoji() {
root.show-emoji = !root.show-emoji;
root.show-tools = false;
if root.show-emoji { ChatBridge.emoji-search = ""; ChatBridge.emoji(""); }
else { ChatBridge.command("dismiss-completion"); input.focus(); }
}
private property <bool> show-tools;
private property <bool> show-emoji;
private property <bool> show-search: ChatBridge.search-open;
private property <int> conversation-revision: ChatBridge.conversation-revision;
changed conversation-revision => { root.show-tools = false; root.show-emoji = false; }
// Measure the allocated viewport; composer constraints must not size their own parent.
private property <length> allocated-height;
changed height => { allocated-height = self.height; }
FocusScope {
key-pressed(event) => {
if event.text == Key.Escape && (root.show-search || root.show-emoji || root.show-tools) {
if root.show-search { ChatBridge.toggle-search(); }
root.show-tools = false; root.show-emoji = false; ChatBridge.command("dismiss-completion"); input.focus(); return accept;
}
return reject;
}
// The scope must contain the inputs for unhandled Escape to reach it.
VerticalLayout {
spacing: 0px;
if ChatBridge.tabs.length > 0 && (!root.embedded-header || ChatBridge.tabs.length > 1 || ChatBridge.tabs[0].closable): ScrollView {
height: root.embedded-header ? 32px : Theme.touch-target; vertical-stretch: 0;
HorizontalLayout {
spacing: 4px;
for tab in ChatBridge.tabs: HorizontalLayout {
spacing: 0px;
if !root.embedded-header: ActionButton { text: tab.label + (tab.unread != "" ? " " + tab.unread : ""); primary: tab.active; clicked => { ChatBridge.choose-tab(tab.id); } }
if !root.embedded-header && tab.closable: ActionButton { text: ChatBridge.tr("ui.close"); clicked => { ChatBridge.close-tab(tab.id); } }
if root.embedded-header: ComposerButton { label: tab.label + (tab.unread != "" ? " " + tab.unread : ""); background: tab.active ? Theme.contrast : transparent; clicked => { ChatBridge.choose-tab(tab.id); } }
if root.embedded-header && tab.closable: ComposerButton { label: ChatBridge.tr("ui.close"); icon: "M 7 7 L 17 17 M 17 7 L 7 17"; clicked => { ChatBridge.close-tab(tab.id); } }
}
}
}
if !root.embedded-header: HorizontalLayout {
padding: 8px; spacing: 8px; height: 52px;
Text { text: ChatBridge.title; color: Theme.fg; font-family: Theme.font-family; font-size: 18px; font-weight: 700; overflow: elide; vertical-alignment: center; horizontal-stretch: 1; }
if ChatBridge.can-info: ActionButton { text: ChatBridge.tr("admin.info"); clicked => { ChatBridge.client-info(); } }
ActionButton { text: ChatBridge.tr("admin.search"); clicked => { ChatBridge.toggle-search(); } }
}
if root.show-search: HorizontalLayout {
padding-left: 12px; padding-right: 12px; spacing: 8px;
TextField { text <=> ChatBridge.search; placeholder: ChatBridge.tr("admin.search"); init => { self.focus(); } accepted => { ChatBridge.search-history(ChatBridge.search); } }
ActionButton { text: ChatBridge.tr("admin.search"); clicked => { ChatBridge.search-history(ChatBridge.search); } }
}
if ChatBridge.has-older || ChatBridge.older-page || ChatBridge.loading: HorizontalLayout {
padding-left: 12px; padding-right: 12px; spacing: 8px;
if ChatBridge.has-older: ActionButton { text: ChatBridge.tr("chat.history.older"); enabled: !ChatBridge.loading; clicked => { ChatBridge.history(false); } }
if ChatBridge.older-page: ActionButton { text: ChatBridge.tr("chat.history.latest"); enabled: !ChatBridge.loading; clicked => { ChatBridge.history(true); } }
if ChatBridge.loading: Text { text: ChatBridge.tr("admin.loading"); color: Theme.muted; vertical-alignment: center; }
}
Rectangle {
vertical-stretch: 1;
min-height: ChatBridge.desktop ? 0px : composer-footer.min-height;
preferred-height: ChatBridge.desktop ? 0px : composer-footer.preferred-height;
parity-chat-log := ListView {
content-width: max(self.visible-width, ChatBridge.content-width * 1px);
private property <float> requested-position: ChatBridge.log-position;
// Reserve the measured footer and the existing message gap inside the desktop scroller.
private property <length> bottom-padding: ChatBridge.desktop ? composer-footer.height + 8px : 0px;
private property <length> top-padding: ChatBridge.desktop && !ChatBridge.older-page ? max(0px, self.height - self.bottom-padding - ChatBridge.log-height * 1px) : 0px;
width: parent.width; height: ChatBridge.desktop ? parent.height : max(0px, composer-footer.y);
changed requested-position => { if self.content-y / 1px != self.requested-position { self.content-y = clamp(self.requested-position * 1px, min(0px, self.height - self.content-height), 0px); } }
changed content-y => {
ChatBridge.log-position = self.content-y / 1px;
ChatBridge.bottom-pinned = self.content-height + self.content-y - self.height < 80px;
}
changed content-height => { if ChatBridge.bottom-pinned && !ChatBridge.older-page { self.content-y = min(0px, self.height - self.content-height); } }
changed height => { if ChatBridge.bottom-pinned && !ChatBridge.older-page { self.content-y = min(0px, self.height - self.content-height); } }
for row[index] in ChatBridge.rows: Rectangle {
private property <length> leading: index == 0 ? parity-chat-log.top-padding : 0px;
private property <length> trailing: index == ChatBridge.rows.length - 1 ? parity-chat-log.bottom-padding : 0px;
width: message-row.width;
height: self.leading + message-row.height + self.trailing;
message-row := RichRow {
y: parent.leading;
visual: row;
viewport-width: ChatBridge.desktop ? root.timeline-viewport : parity-chat-log.visible-width;
inert: false;
}
}
}
if ChatBridge.rows.length == 0 && !ChatBridge.loading: Text { y: ChatBridge.desktop ? 10px : 0px; width: parent.width; text: ChatBridge.tr("chat.history.empty"); color: Theme.muted; font-family: Theme.font-family; font-size: ChatBridge.desktop ? 13px : Theme.font-size; horizontal-alignment: center; }
// Layer the composer above the desktop timeline; on mobile the timeline stops here.
composer-footer := VerticalLayout {
y: parent.height - self.height;
height: max(self.min-height, min(parent.height, self.preferred-height));
spacing: 0px;
if ChatBridge.selected-text != "": HorizontalLayout {
padding-left: 12px; spacing: 8px;
ActionButton { text: ChatBridge.tr("ui.copy"); clicked => { ChatBridge.copy-selection(); } }
Text { text: ChatBridge.selected-text; color: Theme.muted; overflow: elide; vertical-alignment: center; }
}
if ChatBridge.status != "": Text { text: ChatBridge.status; color: Theme.muted; wrap: word-wrap; font-family: Theme.font-family; font-size: 13px; }
if ChatBridge.error != "": Text { text: ChatBridge.error; color: Theme.error; wrap: word-wrap; font-family: Theme.font-family; font-size: 13px; accessible-role: text; }
if ChatBridge.desktop && ChatBridge.can-info && ChatBridge.enabled && ChatBridge.rows.length == 0 && !ChatBridge.loading && !root.show-search: HorizontalLayout {
alignment: start; padding-left: 10px; padding-right: 10px; padding-bottom: 6px;
Rectangle {
min-width: 0px; preferred-width: min(max(0px, root.width - 20px), start-caption.preferred-width + 68px); height: 38px;
background: Theme.contrast; border-radius: 15px;
Path { x: 20px; y: 10px; width: 18px; height: 18px; viewbox-width: 24; viewbox-height: 24; commands: "M 20 11 A 8 8 0 0 1 12 19 H 4 L 5 14 A 8 8 0 1 1 20 11 Z"; fill: transparent; stroke: Theme.fg; stroke-width: 1.6px; }
start-caption := Text { x: 52px; width: max(0px, parent.width - 68px); text: ChatBridge.tr("chat.input.start_conversation"); color: Theme.fg; font-family: Theme.font-family; font-size: 13px; overflow: elide; vertical-alignment: center; }
}
}
HorizontalLayout {
padding-left: ChatBridge.desktop ? 10px : 0px; padding-right: ChatBridge.desktop ? 10px : 0px; padding-bottom: ChatBridge.desktop ? 10px : 0px;
vertical-stretch: 0;
parity-composer := Rectangle {
background: Theme.bg; border-radius: 8px; border-width: 1px;
border-color: input.has-focus || composer-hover.has-hover ? Theme.tint : Theme.high-contrast ? Theme.outline : ChatBridge.desktop ? ChatPaint.incoming : Theme.outline;
min-height: ChatBridge.desktop ? 36px : 92px;
max-height: max(ChatBridge.desktop ? 180px : 120px, root.allocated-height * 0.55); vertical-stretch: 0;
composer-hover := TouchArea { }
VerticalLayout {
padding: ChatBridge.desktop ? 1px : 8px; spacing: ChatBridge.desktop ? 0px : 4px;
toolbar := Rectangle {
height: root.toolbar-open ? (ChatBridge.desktop ? 31px : Theme.touch-target) : 0px;
visible: root.toolbar-open;
background: ChatBridge.desktop ? Theme.shaded : transparent;
border-radius: 8px;
if ChatBridge.desktop: Rectangle { y: parent.height / 2; height: parent.height / 2; background: Theme.shaded; }
if ChatBridge.desktop: Rectangle { y: parent.height - 1px; height: 1px; background: Theme.outline; }
HorizontalLayout {
padding-left: ChatBridge.desktop ? 10px : 0px; padding-right: ChatBridge.desktop ? 10px : 0px;
padding-top: ChatBridge.desktop ? 2px : 0px; padding-bottom: ChatBridge.desktop ? 3px : 0px;
spacing: ChatBridge.desktop ? 2.5px : 4px; alignment: start;
bold := ComposerButton { label: ChatBridge.tr("chat.snippet.bold"); text: "B"; weight: 700; tool: true; enabled: root.toolbar-open && ChatBridge.enabled && !ChatBridge.composing; clicked => { ChatBridge.format("bold"); } }
italic := ComposerButton { label: ChatBridge.tr("chat.snippet.italic"); text: "I"; italic: true; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("italic"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.strike"); icon: "M 5 12 H 19 M 9 9 C 7 5 17 3 17 8 M 9 17 C 12 21 18 17 15 14"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("strike"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.underline"); icon: "M 7 4 V 11 A 5 5 0 0 0 17 11 V 4 M 5 20 H 19"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("underline"); } }
if ChatBridge.desktop || root.width > 420px: ComposerButton { label: ChatBridge.tr("chat.snippet.link"); icon: "M 10 9 L 14 5 A 4 4 0 0 1 20 11 L 16 15 M 14 15 L 10 19 A 4 4 0 0 1 4 13 L 8 9 M 8 16 L 16 8"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("link"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.quote"); icon: "M 5 5 V 19 M 8 6 H 20 M 8 12 H 17 M 8 18 H 15"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("quote"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.code"); icon: "M 8 7 L 3 12 L 8 17 M 16 7 L 21 12 L 16 17 M 14 5 L 10 19"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("code"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.ul"); icon: "M 4 6 H 6 M 4 12 H 6 M 4 18 H 6 M 9 6 H 20 M 9 12 H 20 M 9 18 H 20"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("ul"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.spoiler"); icon: "M 3 12 C 7 5 17 5 21 12 C 17 19 7 19 3 12 Z M 8 16 L 16 8 M 5 20 L 19 4"; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("spoiler"); } }
if ChatBridge.desktop && root.width >= 365px: ComposerButton { label: ChatBridge.tr("chat.snippet.h1"); text: "H"; weight: 700; tool: true; enabled: bold.enabled; clicked => { ChatBridge.format("h1"); } }
toolbar-more := ComposerButton { label: ChatBridge.tr("chat.toolbar.more"); tool: true; enabled: root.toolbar-open && ChatBridge.enabled; clicked => { root.show-tools = !root.show-tools; root.show-emoji = false; ChatBridge.command("dismiss-completion"); } }
}
}
if !ChatBridge.desktop || root.show-tools: HorizontalLayout {
padding-left: ChatBridge.desktop ? 10px : 0px; padding-right: ChatBridge.desktop ? 10px : 0px;
Text { text: ChatBridge.tr("settings.chat.text_edit.rich_text"); color: Theme.muted; font-family: Theme.font-family; font-size: 13px; vertical-alignment: center; horizontal-stretch: 1; }
Toggle { label: ChatBridge.tr("settings.chat.text_edit.rich_text"); checked: ChatBridge.hybrid; enabled: !ChatBridge.composing; toggled(value) => { ChatBridge.hybrid = value; ChatBridge.set-hybrid(value); } }
}
if root.show-tools: ListView {
height: ChatBridge.desktop ? min(160px, root.allocated-height * 0.24) : 160px;
for tool in ChatBridge.tools: ActionButton { text: tool.label; enabled: ChatBridge.enabled && !ChatBridge.composing; clicked => { ChatBridge.format(tool.id); root.show-tools = false; } }
}
if root.show-emoji: TextField {
text <=> ChatBridge.emoji-search; placeholder: ChatBridge.tr("chat.emoji.search");
init => { if ChatBridge.desktop { self.focus(); } }
edited(value) => { ChatBridge.emoji(value); }
accepted => { if ChatBridge.completions.length > 0 { ChatBridge.complete(ChatBridge.completion-index); root.show-emoji = false; } }
}
if ChatBridge.completions.length > 0: ListView {
height: min(ChatBridge.desktop ? min(160px, root.allocated-height * 0.24) : 160px, ChatBridge.completions.length * Theme.touch-target);
for item[index] in ChatBridge.completions: ActionButton { text: item.label; primary: index == ChatBridge.completion-index; clicked => { ChatBridge.complete(index); root.show-emoji = false; } }
}
HorizontalLayout {
spacing: 0px;
editor-slot := Rectangle {
min-width: 0px; horizontal-stretch: 1;
min-height: ChatBridge.desktop ? 34px : 48px;
preferred-height: ChatBridge.desktop ? min(250px, editor-content.height + 14px) : clamp(editor-content.height, 48px, 240px);
editor-scroll := ScrollView {
x: ChatBridge.desktop ? 10px : 0px; y: ChatBridge.desktop ? 8px : 0px;
width: max(0px, parent.width - (ChatBridge.desktop ? 20px : 0px));
height: max(0px, parent.height - (ChatBridge.desktop ? 14px : 0px));
content-width: max(self.visible-width, ChatBridge.editor-width * 1px);
vertical-stretch: 1;
VerticalLayout {
spacing: 0px;
editor-content := Rectangle {
width: ChatBridge.editor-width * 1px;
height: before-doc.height + input.height + after-doc.height;
before-doc := RichDocument { rows: ChatBridge.before; width: parent.width; }
input := TextInput {
y: before-doc.height; width: max(0px, min(parent.width, root.editor-viewport)); height: max(ChatBridge.desktop ? 18px : 36px, self.preferred-height);
text <=> ChatBridge.editor-text; enabled: ChatBridge.enabled;
single-line: false; wrap: word-wrap; font-family: Theme.font-family; font-size: 14px;
color: Theme.fg; selection-foreground-color: Theme.fg; selection-background-color: Theme.tint;
accessible-label: ChatBridge.tr("ui.message"); accessible-placeholder-text: ChatBridge.placeholder;
page-height: editor-scroll.visible-height;
changed preedit-text => { ChatBridge.composing = self.preedit-text != ""; ChatBridge.composition-changed(ChatBridge.composing); }
edited => { ChatBridge.draft-edited(self.text, self.anchor-position-byte-offset, self.cursor-position-byte-offset); }
cursor-position-changed(point) => {
ChatBridge.selection-changed(self.anchor-position-byte-offset, self.cursor-position-byte-offset);
if point.y + self.y + editor-scroll.content-y < 0px { editor-scroll.content-y = -point.y - self.y; }
if point.y + self.y + editor-scroll.content-y > max(0px, editor-scroll.visible-height - 18px) { editor-scroll.content-y = min(0px, editor-scroll.visible-height - point.y - self.y - 18px); }
}
key-pressed(event) => {
if self.preedit-text != "" { return reject; }
if (event.modifiers.control || event.modifiers.meta) {
if event.text == "z" { ChatBridge.command(event.modifiers.shift ? "redo" : "undo"); return accept; }
if event.text == "y" { ChatBridge.command("redo"); return accept; }
if event.text == "b" { ChatBridge.format("bold"); return accept; }
if event.text == "i" { ChatBridge.format("italic"); return accept; }
if event.text == "k" { ChatBridge.format("link"); return accept; }
if event.text == "`" { ChatBridge.format("code"); return accept; }
if event.text == "c" && event.modifiers.alt { ChatBridge.format("codeblock"); return accept; }
if event.text == "a" { ChatBridge.command("select-all"); return accept; }
}
if ChatBridge.completions.length > 0 {
if event.text == Key.DownArrow { ChatBridge.command("completion-next"); return accept; }
if event.text == Key.UpArrow { ChatBridge.command("completion-previous"); return accept; }
if event.text == Key.Return || event.text == Key.Tab { ChatBridge.complete(ChatBridge.completion-index); return accept; }
if event.text == Key.Escape { ChatBridge.command("dismiss-completion"); return accept; }
}
if event.text == Key.Return { if event.modifiers.shift { if ChatBridge.command("newline") { return accept; } } else { ChatBridge.send(); return accept; } }
if event.text == Key.Tab { if ChatBridge.command(event.modifiers.shift ? "outdent" : "indent") { return accept; } }
if (event.text == Key.UpArrow || event.text == Key.LeftArrow) && self.cursor-position-byte-offset == 0 { if ChatBridge.command(event.modifiers.shift ? "previous-block-select" : "previous-block") { return accept; } }
if (event.text == Key.DownArrow || event.text == Key.RightArrow) && self.cursor-position-byte-offset == ChatBridge.editor-byte-length { if ChatBridge.command(event.modifiers.shift ? "next-block-select" : "next-block") { return accept; } }
return reject;
}
private property <int> applied-revision: ChatBridge.editor-revision;
init => {
self.set-selection-offsets(ChatBridge.editor-anchor, ChatBridge.editor-cursor);
if ChatBridge.focus-request && ChatBridge.enabled && !ChatBridge.search-open { self.focus(); }
}
changed applied-revision => {
self.set-selection-offsets(ChatBridge.editor-anchor, ChatBridge.editor-cursor);
if ChatBridge.focus-request && ChatBridge.enabled && !ChatBridge.search-open { self.focus(); }
}
}
ContextMenuArea {
y: input.y; width: input.width; height: input.height; enabled: !ChatBridge.composing;
Menu {
MenuItem { title: ChatBridge.tr("native.chat.undo"); enabled: ChatBridge.can-undo; activated => { ChatBridge.command("undo"); } }
MenuItem { title: ChatBridge.tr("native.chat.redo"); enabled: ChatBridge.can-redo; activated => { ChatBridge.command("redo"); } }
MenuItem { title: ChatBridge.tr("native.chat.cut"); enabled: ChatBridge.enabled; activated => { input.cut(); } }
MenuItem { title: ChatBridge.tr("ui.copy"); activated => { input.copy(); } }
MenuItem { title: ChatBridge.tr("native.chat.paste"); enabled: ChatBridge.enabled; activated => { input.paste(); } }
MenuItem { title: ChatBridge.tr("native.chat.selectAll"); activated => { ChatBridge.command("select-all"); } }
}
}
if input.text == "" && input.preedit-text == "": Text { y: input.y; width: input.width; text: ChatBridge.placeholder; color: Theme.muted; font-family: Theme.font-family; font-size: 14px; overflow: elide; }
after-doc := RichDocument { y: input.y + input.height; rows: ChatBridge.after; width: parent.width; }
}
}
}
}
Rectangle {
visible: ChatBridge.desktop;
width: ChatBridge.desktop ? (ChatBridge.can-attach ? 93px : 67px) : 0px;
HorizontalLayout {
y: max(0px, parent.height - self.height); height: ChatBridge.desktop ? 31px : 0px;
alignment: start; spacing: 4px;
padding-left: 2px; padding-right: 5px; padding-bottom: 4px;
emoji := ComposerButton { label: ChatBridge.tr("chat.emoji.label"); icon: "M 21 12 A 9 9 0 1 1 3 12 A 9 9 0 1 1 21 12 Z M 8 13 C 9 17 15 17 16 13 M 9 9 L 9 10 M 15 9 L 15 10"; enabled: ChatBridge.desktop && ChatBridge.enabled && !ChatBridge.composing; clicked => { root.toggle-emoji(); } }
attachment := ComposerButton { label: ChatBridge.tr("chat.attachment.label"); icon: "M 8 13 L 14 7 A 2 2 0 0 1 17 10 L 10 17 A 3 3 0 0 1 6 13 L 14 5 A 4 4 0 0 1 20 11 L 11 20 A 5 5 0 0 1 4 13 L 12 5"; visible: ChatBridge.can-attach; enabled: ChatBridge.desktop && self.visible && ChatBridge.enabled && !ChatBridge.composing; clicked => { ChatBridge.attach(); } }
send := ComposerButton { label: ChatBridge.tr("ui.send"); icon: "M 4 5 L 21 12 L 4 19 L 7 12 Z M 7 12 H 21"; accented: true; enabled: ChatBridge.desktop && ChatBridge.can-send && !ChatBridge.composing; clicked => { ChatBridge.send(); input.focus(); } }
}
}
}
if !ChatBridge.desktop: HorizontalLayout {
spacing: 4px;
ActionButton { text: ChatBridge.tr("chat.emoji.label"); enabled: ChatBridge.enabled && !ChatBridge.composing; clicked => { root.toggle-emoji(); } }
if ChatBridge.can-attach: ActionButton { text: ChatBridge.tr("chat.attachment.label"); enabled: ChatBridge.enabled; clicked => { ChatBridge.attach(); } }
Rectangle { horizontal-stretch: 1; }
ActionButton { text: ChatBridge.tr("ui.send"); primary: true; enabled: ChatBridge.can-send && !ChatBridge.composing; clicked => { ChatBridge.send(); } }
}
}
}
}
}
}
}
}
}