|
|
@@ -0,0 +1,188 @@
|
|
|
+import { Component, ChangeDetectionStrategy, input, output, signal, effect, ElementRef, viewChild } from '@angular/core';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 会话标题编辑弹层(2026-11-23 新建)
|
|
|
+ *
|
|
|
+ * 背景:用户反馈「对话标题不能点击编辑」。标题来自 Matrix 房间名,
|
|
|
+ * 由首句总结生成后就不再变化,聊着聊着主题偏了标题还是错的。
|
|
|
+ *
|
|
|
+ * 形态参照 `m-confirm`(同类底部确认弹层),保持移动端交互一致:
|
|
|
+ * 底部升起、遮罩可点关闭、主按钮在右。
|
|
|
+ *
|
|
|
+ * 只负责「输入 + 提交」,改名和同步房间名由父组件做 ——
|
|
|
+ * 组件不知道 Matrix 的存在,方便复用到其他场景。
|
|
|
+ */
|
|
|
+@Component({
|
|
|
+ selector: 'app-m-title-editor',
|
|
|
+ changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
+ template: `
|
|
|
+ @if (open()) {
|
|
|
+ <div class="mte-mask" role="dialog" aria-modal="true" aria-label="编辑会话标题" (click)="onCancel()">
|
|
|
+ <section class="mte-sheet" (click)="$event.stopPropagation()">
|
|
|
+ <div class="mte-grabber" aria-hidden="true"></div>
|
|
|
+ <h2 class="mte-title">编辑会话标题</h2>
|
|
|
+ <p class="mte-hint">仅修改显示名称,不影响对话内容</p>
|
|
|
+
|
|
|
+ <input
|
|
|
+ #field
|
|
|
+ type="text"
|
|
|
+ class="mte-input"
|
|
|
+ [value]="draft()"
|
|
|
+ (input)="onInput($event)"
|
|
|
+ (keydown.enter)="onConfirm()"
|
|
|
+ maxlength="60"
|
|
|
+ placeholder="给这段对话起个名字"
|
|
|
+ aria-label="会话标题"
|
|
|
+ />
|
|
|
+ <div class="mte-count">{{ draft().length }}/60</div>
|
|
|
+
|
|
|
+ <div class="mte-actions">
|
|
|
+ <button type="button" class="mte-btn" (click)="onCancel()">取消</button>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="mte-btn mte-btn--primary"
|
|
|
+ [disabled]="!canSave()"
|
|
|
+ (click)="onConfirm()"
|
|
|
+ >
|
|
|
+ 保存
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ `,
|
|
|
+ styles: [
|
|
|
+ `
|
|
|
+ .mte-mask {
|
|
|
+ position: fixed;
|
|
|
+ inset: 0;
|
|
|
+ z-index: var(--z-modal);
|
|
|
+ display: flex;
|
|
|
+ align-items: flex-end;
|
|
|
+ background: var(--overlay);
|
|
|
+ }
|
|
|
+ .mte-sheet {
|
|
|
+ width: 100%;
|
|
|
+ padding: var(--sp-3) var(--mob-gutter) calc(var(--sp-5) + env(safe-area-inset-bottom));
|
|
|
+ background: var(--surface);
|
|
|
+ border-radius: var(--r-sheet) var(--r-sheet) 0 0;
|
|
|
+ box-sizing: border-box;
|
|
|
+ }
|
|
|
+ .mte-grabber {
|
|
|
+ width: 36px;
|
|
|
+ height: 4px;
|
|
|
+ margin: 0 auto var(--sp-3);
|
|
|
+ border-radius: 2px;
|
|
|
+ background: var(--edge);
|
|
|
+ }
|
|
|
+ .mte-title {
|
|
|
+ margin: 0 0 4px;
|
|
|
+ font-size: var(--fs-16);
|
|
|
+ font-weight: 600;
|
|
|
+ color: var(--ink);
|
|
|
+ }
|
|
|
+ .mte-hint {
|
|
|
+ margin: 0 0 var(--sp-3);
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ color: var(--muted);
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 字号 16px —— 低于 16px 时 iOS 会在聚焦时自动放大页面,
|
|
|
+ * 这是移动端输入框的硬约束,不是设计偏好。
|
|
|
+ */
|
|
|
+ .mte-input {
|
|
|
+ width: 100%;
|
|
|
+ box-sizing: border-box;
|
|
|
+ padding: 12px var(--sp-3);
|
|
|
+ border: 1px solid var(--edge);
|
|
|
+ border-radius: var(--r-tag);
|
|
|
+ background: var(--bg);
|
|
|
+ color: var(--ink);
|
|
|
+ font-size: 16px;
|
|
|
+ outline: none;
|
|
|
+ }
|
|
|
+ .mte-input:focus {
|
|
|
+ border-color: var(--primary);
|
|
|
+ }
|
|
|
+ .mte-count {
|
|
|
+ margin-top: 6px;
|
|
|
+ text-align: right;
|
|
|
+ font-size: var(--fs-11);
|
|
|
+ color: var(--muted);
|
|
|
+ }
|
|
|
+ .mte-actions {
|
|
|
+ display: flex;
|
|
|
+ gap: var(--sp-3);
|
|
|
+ margin-top: var(--sp-4);
|
|
|
+ }
|
|
|
+ .mte-btn {
|
|
|
+ flex: 1;
|
|
|
+ min-height: var(--touch-min);
|
|
|
+ border: 1px solid var(--edge);
|
|
|
+ border-radius: var(--r-tag);
|
|
|
+ background: var(--surface);
|
|
|
+ color: var(--ink);
|
|
|
+ font-size: var(--fs-15);
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .mte-btn--primary {
|
|
|
+ border-color: var(--primary);
|
|
|
+ background: var(--primary);
|
|
|
+ color: #fff;
|
|
|
+ }
|
|
|
+ .mte-btn:disabled {
|
|
|
+ opacity: 0.45;
|
|
|
+ cursor: not-allowed;
|
|
|
+ }
|
|
|
+ `,
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class TitleEditorComponent {
|
|
|
+ readonly open = input(false);
|
|
|
+ /** 打开时填入的初始标题 */
|
|
|
+ readonly initial = input('');
|
|
|
+
|
|
|
+ readonly save = output<string>();
|
|
|
+ readonly cancel = output<void>();
|
|
|
+
|
|
|
+ protected readonly draft = signal('');
|
|
|
+
|
|
|
+ private readonly field = viewChild<ElementRef<HTMLInputElement>>('field');
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ /*
|
|
|
+ * 每次打开重新灌入初值 —— 用 effect 监听 open,
|
|
|
+ * 保证上一次没保存的残留内容不会带到下一次。
|
|
|
+ */
|
|
|
+ effect(() => {
|
|
|
+ if (this.open()) {
|
|
|
+ this.draft.set(this.initial());
|
|
|
+ // 等弹层渲染完再聚焦,否则拿不到元素
|
|
|
+ setTimeout(() => {
|
|
|
+ const el = this.field()?.nativeElement;
|
|
|
+ el?.focus();
|
|
|
+ el?.select();
|
|
|
+ }, 60);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onInput(ev: Event): void {
|
|
|
+ this.draft.set((ev.target as HTMLInputElement).value);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected canSave(): boolean {
|
|
|
+ const v = this.draft().trim();
|
|
|
+ return v.length > 0 && v !== this.initial().trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onConfirm(): void {
|
|
|
+ const v = this.draft().trim();
|
|
|
+ if (!v || v === this.initial().trim()) return;
|
|
|
+ this.save.emit(v);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onCancel(): void {
|
|
|
+ this.cancel.emit();
|
|
|
+ }
|
|
|
+}
|