@tbox.cn/app-agent-ui-kit 1.0.0-alpha.16 → 1.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/ChatPage.tsx +204 -27
- package/src/card/confirm-fields.test.tsx +106 -0
- package/src/card/primitives.tsx +270 -59
- package/src/card/use-card-actions.ts +5 -1
- package/src/card/view-card.tsx +113 -22
- package/src/chat-config.ts +2 -0
- package/src/components/ActionBar/DebugButton.tsx +12 -4
- package/src/components/ActionBar/index.tsx +61 -27
- package/src/components/BottomSheet/index.tsx +26 -2
- package/src/components/QuickCommands/index.tsx +60 -14
- package/src/components/ToolCallBlock/detail.test.ts +2 -0
- package/src/components/ToolCallBlock/detail.ts +9 -2
- package/src/contract.test.tsx +176 -0
- package/src/hooks/use-stick-to-bottom.test.tsx +101 -0
- package/src/hooks/use-stick-to-bottom.ts +35 -7
- package/src/index.ts +2 -0
- package/src/overlay/Overlay.tsx +20 -2
- package/src/preview-provider.tsx +8 -0
- package/src/shell.contract.json +1 -1
- package/src/shell.test.ts +105 -2
- package/src/theme/base.css +42 -2
package/src/card/primitives.tsx
CHANGED
|
@@ -189,36 +189,71 @@ export function ActionRow({ primary, secondary, disabled }: ActionRowProps) {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/** 按钮:与基元同一套排版,禁用态统一。 *
|
|
192
|
-
* @behavior primary
|
|
192
|
+
* @behavior primary 实心胶囊;secondary 描边胶囊;link 无底色文字按钮。边框归各变体独占
|
|
193
|
+
* (基础类不再写 `border-0`,否则会按工具类声明序覆盖变体的 `border`,二级按钮退化成纯文字)。
|
|
193
194
|
*/
|
|
195
|
+
// 职责正交:变体只管「颜色/边框/字重/宽度语义」,尺寸档只管「高度/内距/字号」。
|
|
196
|
+
// 两边都写 px/py/text 会让 size="sm" 被变体在同一个 class 串里覆盖(曾经就是这样失效的)。
|
|
194
197
|
const BUTTON_VARIANT = {
|
|
195
|
-
primary: 'w-full bg-primary
|
|
196
|
-
secondary: 'w-full border border-border bg-
|
|
197
|
-
|
|
198
|
+
primary: 'w-full border border-transparent bg-primary font-medium text-white shadow-xs',
|
|
199
|
+
secondary: 'w-full border border-border-strong bg-card font-medium text-primary',
|
|
200
|
+
// 双保险:宿主映射了 `--color-destructive` 用主题色;没映射时回落到契约里的 `--tbox-error`。
|
|
201
|
+
danger:
|
|
202
|
+
'w-full border border-transparent bg-destructive font-medium text-white shadow-xs [background-color:var(--color-destructive,var(--tbox-error))]',
|
|
203
|
+
link: 'w-auto border-0 bg-transparent font-medium text-primary',
|
|
198
204
|
} as const;
|
|
199
205
|
|
|
206
|
+
/** 尺寸档:`sm` 只压视觉,命中区仍由 `min-h-11` 保证 ≥44px。 */
|
|
207
|
+
const BUTTON_SIZE = {
|
|
208
|
+
md: 'min-h-11 px-4 py-2.5 text-sm',
|
|
209
|
+
sm: 'min-h-11 px-3 py-1.5 text-xs',
|
|
210
|
+
} as const;
|
|
211
|
+
|
|
212
|
+
/** `link` 变体的内距单独给:它不是胶囊,用胶囊内距会撑出一大块空白。 */
|
|
213
|
+
const LINK_SIZE = {
|
|
214
|
+
md: 'min-h-11 px-1 py-1 text-sm',
|
|
215
|
+
sm: 'min-h-11 px-1 py-1 text-xs',
|
|
216
|
+
} as const;
|
|
217
|
+
|
|
218
|
+
export type CardButtonVariant = keyof typeof BUTTON_VARIANT;
|
|
219
|
+
|
|
200
220
|
export function CardButton({
|
|
201
221
|
children,
|
|
202
222
|
onClick,
|
|
203
223
|
variant = 'primary',
|
|
224
|
+
size = 'md',
|
|
204
225
|
disabled,
|
|
205
226
|
busy,
|
|
227
|
+
loading,
|
|
228
|
+
className = '',
|
|
206
229
|
}: {
|
|
207
230
|
children: ReactNode;
|
|
208
231
|
onClick?: () => void;
|
|
209
|
-
variant?:
|
|
232
|
+
variant?: CardButtonVariant;
|
|
233
|
+
/** `sm` 只压视觉(字号/内距),命中区仍 ≥44px */
|
|
234
|
+
size?: 'md' | 'sm';
|
|
210
235
|
disabled?: boolean;
|
|
211
236
|
/** 动作进行中:只影响可访问性语义,视觉由调用方给 spinner */
|
|
212
237
|
busy?: boolean;
|
|
238
|
+
/** 由按钮自己渲染 spinner(自定义卡不必再手写 loading 标记) */
|
|
239
|
+
loading?: boolean;
|
|
240
|
+
/** 追加类名(布局用;颜色/尺寸仍走变体与 size,避免再次出现类冲突) */
|
|
241
|
+
className?: string;
|
|
213
242
|
}) {
|
|
214
243
|
return (
|
|
215
244
|
<button
|
|
216
|
-
className={`tbox-btn tbox-btn--${variant} inline-flex
|
|
245
|
+
className={`tbox-btn tbox-btn--${variant} inline-flex cursor-pointer items-center justify-center gap-2 rounded-full leading-tight outline-offset-2 focus-visible:outline-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-55 ${variant === 'link' ? LINK_SIZE[size] : BUTTON_SIZE[size]} ${BUTTON_VARIANT[variant]} ${className}`}
|
|
217
246
|
type="button"
|
|
218
247
|
onClick={onClick}
|
|
219
248
|
disabled={disabled}
|
|
220
|
-
aria-busy={busy || undefined}
|
|
249
|
+
aria-busy={busy || loading || undefined}
|
|
221
250
|
>
|
|
251
|
+
{loading ? (
|
|
252
|
+
<span
|
|
253
|
+
className="tbox-btn__spinner inline-block size-4 animate-spin rounded-full border-2 border-current border-t-transparent"
|
|
254
|
+
aria-hidden="true"
|
|
255
|
+
/>
|
|
256
|
+
) : null}
|
|
222
257
|
{children}
|
|
223
258
|
</button>
|
|
224
259
|
);
|
|
@@ -230,6 +265,10 @@ export interface ConfirmSheetProps {
|
|
|
230
265
|
description?: ReactNode;
|
|
231
266
|
confirmText?: string;
|
|
232
267
|
cancelText?: string;
|
|
268
|
+
/** 主按钮语气:`danger` 用于取消报名/解绑等不可逆操作 */
|
|
269
|
+
tone?: 'primary' | 'danger';
|
|
270
|
+
/** 确认要点(如「+100 积分」「满100减20券」):渲染为紧凑标签行,扫一眼即知收益 */
|
|
271
|
+
highlights?: string[];
|
|
233
272
|
onConfirm: () => void;
|
|
234
273
|
onCancel: () => void;
|
|
235
274
|
}
|
|
@@ -241,6 +280,8 @@ export function ConfirmSheet({
|
|
|
241
280
|
description,
|
|
242
281
|
confirmText = '确认',
|
|
243
282
|
cancelText = '取消',
|
|
283
|
+
tone = 'primary',
|
|
284
|
+
highlights,
|
|
244
285
|
onConfirm,
|
|
245
286
|
onCancel,
|
|
246
287
|
}: ConfirmSheetProps) {
|
|
@@ -253,16 +294,29 @@ export function ConfirmSheet({
|
|
|
253
294
|
labelledBy={titleId}
|
|
254
295
|
exitMs={180}
|
|
255
296
|
rootClassName="tbox-sheet tbox-sheet__root group"
|
|
256
|
-
panelClassName="tbox-sheet__panel flex w-full flex-col gap-2.5 rounded-t-xl bg-card px-4 pb-[calc(20px+env(safe-area-inset-bottom))] pt-
|
|
297
|
+
panelClassName="tbox-sheet__panel mx-auto flex w-full max-w-md flex-col gap-2.5 rounded-t-xl border-t border-border bg-card px-4 pb-[calc(20px+env(safe-area-inset-bottom))] pt-3 shadow-lg animate-[tbox-sheet-in_180ms_ease-out] group-data-[state=closed]:animate-[tbox-sheet-out_180ms_ease-in_both] motion-reduce:animate-none"
|
|
257
298
|
maskClassName="bg-scrim animate-[tbox-fade-in_180ms_ease-out] group-data-[state=closed]:animate-[tbox-fade-out_180ms_ease-in_both] motion-reduce:animate-none"
|
|
258
299
|
>
|
|
300
|
+
<span
|
|
301
|
+
className="tbox-sheet__handle mx-auto mb-1 block h-1 w-9 shrink-0 rounded-full bg-neutral-soft"
|
|
302
|
+
aria-hidden="true"
|
|
303
|
+
/>
|
|
259
304
|
<h5 id={titleId} className="tbox-sheet__title m-0 text-base">{title}</h5>
|
|
260
305
|
{description ? <p className="tbox-sheet__desc m-0 text-sm text-secondary-foreground">{description}</p> : null}
|
|
306
|
+
{highlights && highlights.length > 0 ? (
|
|
307
|
+
<ul className="tbox-sheet__highlights m-0 flex list-none flex-wrap gap-1.5 p-0">
|
|
308
|
+
{highlights.map((item) => (
|
|
309
|
+
<li key={item}>
|
|
310
|
+
<StatusTag tone="info">{item}</StatusTag>
|
|
311
|
+
</li>
|
|
312
|
+
))}
|
|
313
|
+
</ul>
|
|
314
|
+
) : null}
|
|
261
315
|
<div className="tbox-sheet__actions mt-1 grid grid-cols-2 gap-2">
|
|
262
316
|
<CardButton variant="secondary" onClick={onCancel}>
|
|
263
317
|
<span className="whitespace-nowrap">{cancelText}</span>
|
|
264
318
|
</CardButton>
|
|
265
|
-
<CardButton onClick={onConfirm}>
|
|
319
|
+
<CardButton variant={tone === 'danger' ? 'danger' : 'primary'} onClick={onConfirm}>
|
|
266
320
|
<span className="whitespace-nowrap">{confirmText}</span>
|
|
267
321
|
</CardButton>
|
|
268
322
|
</div>
|
|
@@ -287,6 +341,10 @@ const HERO_TONE = {
|
|
|
287
341
|
export interface TicketProps {
|
|
288
342
|
/** 主金额或主标题 */
|
|
289
343
|
amount: ReactNode;
|
|
344
|
+
/** 券名(券组场景必填,单票券可省) */
|
|
345
|
+
title?: ReactNode;
|
|
346
|
+
/** 右侧/底部动作(券组里的「领取」按钮) */
|
|
347
|
+
action?: ReactNode;
|
|
290
348
|
/** 面额后的说明(如「满 100 减 20」) */
|
|
291
349
|
condition?: ReactNode;
|
|
292
350
|
/** 有效期、码等补充 */
|
|
@@ -296,15 +354,19 @@ export interface TicketProps {
|
|
|
296
354
|
}
|
|
297
355
|
|
|
298
356
|
/** 票券形:券、凭证、卡包条目。 */
|
|
299
|
-
export function Ticket({ amount, condition, meta, status, tone = 'primary' }: TicketProps) {
|
|
357
|
+
export function Ticket({ amount, title, condition, meta, status, action, tone = 'primary' }: TicketProps) {
|
|
300
358
|
return (
|
|
301
359
|
<div className={`tbox-ticket tbox-ticket--${tone} flex items-center gap-2.5 rounded-lg border border-dashed p-3 ${TICKET_TONE[tone]}`}>
|
|
302
360
|
<div className="tbox-ticket__main flex shrink-0 flex-col gap-1">
|
|
303
361
|
<span className={`tbox-ticket__amount text-2xl font-bold ${tone === 'muted' ? 'text-muted-foreground' : 'text-primary'}`}>{amount}</span>
|
|
304
362
|
{condition ? <span className="tbox-ticket__condition text-xs text-secondary-foreground">{condition}</span> : null}
|
|
305
363
|
</div>
|
|
306
|
-
|
|
364
|
+
<div className="tbox-ticket__body min-w-0 flex-1">
|
|
365
|
+
{title ? <div className="tbox-ticket__title text-sm font-semibold text-foreground">{title}</div> : null}
|
|
366
|
+
{meta ? <div className="tbox-ticket__meta min-w-0 text-xs text-muted-foreground">{meta}</div> : null}
|
|
367
|
+
</div>
|
|
307
368
|
{status ? <div className="tbox-ticket__status shrink-0">{status}</div> : null}
|
|
369
|
+
{action ? <div className="tbox-ticket__action shrink-0">{action}</div> : null}
|
|
308
370
|
</div>
|
|
309
371
|
);
|
|
310
372
|
}
|
|
@@ -367,7 +429,8 @@ export function MediaRow({ title, meta, tags, action, thumb }: MediaRowProps) {
|
|
|
367
429
|
export interface HeroProps {
|
|
368
430
|
/** 标题上方小字(品牌名、卡类别) */
|
|
369
431
|
eyebrow?: ReactNode;
|
|
370
|
-
|
|
432
|
+
/** 主标题(可选:纯数值型主视觉只需要 eyebrow + value) */
|
|
433
|
+
title?: ReactNode;
|
|
371
434
|
/** 主数值(积分、余额、金额) */
|
|
372
435
|
value?: ReactNode;
|
|
373
436
|
/** 数值后的单位 */
|
|
@@ -386,7 +449,7 @@ export function Hero({ eyebrow, title, value, unit, footnote, icon, tone = 'prim
|
|
|
386
449
|
<div className={`tbox-hero tbox-hero--${tone} flex items-center gap-2 rounded-md p-3.5 pb-3.25 ${toneClass}`}>
|
|
387
450
|
<div className="tbox-hero__text flex min-w-0 flex-1 flex-col gap-1.5">
|
|
388
451
|
{eyebrow ? <span className="tbox-hero__eyebrow text-xs tracking-wide text-muted-foreground">{eyebrow}</span> : null}
|
|
389
|
-
<span className="tbox-hero__title text-sm font-semibold">{title}</span>
|
|
452
|
+
{title ? <span className="tbox-hero__title text-sm font-semibold">{title}</span> : null}
|
|
390
453
|
{value !== undefined ? (
|
|
391
454
|
<span className="tbox-hero__value text-3xl font-bold leading-tight [&_small]:ml-1 [&_small]:text-xs [&_small]:font-medium [&_small]:text-secondary-foreground">
|
|
392
455
|
{value}
|
|
@@ -427,6 +490,10 @@ export function StatGrid({ items }: { items: StatItem[] }) {
|
|
|
427
490
|
|
|
428
491
|
export interface EntityRowProps {
|
|
429
492
|
title: ReactNode;
|
|
493
|
+
/** 标题前的短标记(分类字、评分) */
|
|
494
|
+
badge?: ReactNode;
|
|
495
|
+
/** 标题右侧状态胶囊(可领取 / 已领取 / 售罄) */
|
|
496
|
+
status?: ReactNode;
|
|
430
497
|
/** 副标题:分类、距离、营业时间 */
|
|
431
498
|
meta?: ReactNode;
|
|
432
499
|
tags?: ReactNode;
|
|
@@ -434,6 +501,8 @@ export interface EntityRowProps {
|
|
|
434
501
|
price?: ReactNode;
|
|
435
502
|
/** 右侧操作(按钮) */
|
|
436
503
|
action?: ReactNode;
|
|
504
|
+
/** 底部操作行(多个条目级动作并排) */
|
|
505
|
+
actions?: ReactNode;
|
|
437
506
|
/** 左侧缩略图或首字 */
|
|
438
507
|
thumb?: ReactNode;
|
|
439
508
|
/** 展开后的说明 */
|
|
@@ -441,25 +510,36 @@ export interface EntityRowProps {
|
|
|
441
510
|
}
|
|
442
511
|
|
|
443
512
|
/** 实体行(MediaRow 的超集):商户、活动、券包条目,支持价格与展开说明。 */
|
|
444
|
-
export function EntityRow({ title, meta, tags, price, action, thumb, description }: EntityRowProps) {
|
|
513
|
+
export function EntityRow({ title, badge, status, meta, tags, price, action, actions, thumb, description }: EntityRowProps) {
|
|
445
514
|
return (
|
|
446
|
-
<div className="tbox-entity flex
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
515
|
+
<div className="tbox-entity flex flex-col gap-2 border-b border-border py-2.5 last:border-b-0">
|
|
516
|
+
<div className="tbox-entity__row flex items-center gap-2">
|
|
517
|
+
{thumb ? (
|
|
518
|
+
<div className="tbox-entity__thumb flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-media bg-muted [&_img]:size-full [&_img]:object-cover">
|
|
519
|
+
{thumb}
|
|
520
|
+
</div>
|
|
521
|
+
) : null}
|
|
522
|
+
<div className="tbox-entity__text flex min-w-0 flex-1 flex-col gap-1.5">
|
|
523
|
+
<span className="tbox-entity__heading flex min-w-0 items-center gap-1.5">
|
|
524
|
+
{badge ? <span className="tbox-entity__badge shrink-0 rounded-sm bg-muted px-1.5 py-0.5 text-xs font-medium text-secondary-foreground">{badge}</span> : null}
|
|
525
|
+
<span className="tbox-entity__title min-w-0 text-sm font-semibold">{title}</span>
|
|
526
|
+
{status ? <span className="tbox-entity__status shrink-0">{status}</span> : null}
|
|
527
|
+
</span>
|
|
528
|
+
{meta ? <span className="tbox-entity__meta text-xs text-secondary-foreground">{meta}</span> : null}
|
|
529
|
+
{tags ? <span className="tbox-entity__tags flex flex-wrap gap-1">{tags}</span> : null}
|
|
530
|
+
{description ? <span className="tbox-entity__desc text-xs leading-normal text-muted-foreground">{description}</span> : null}
|
|
450
531
|
</div>
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
</div>
|
|
458
|
-
{price !== undefined || action ? (
|
|
459
|
-
<div className="tbox-entity__right flex shrink-0 flex-col items-end gap-1">
|
|
460
|
-
{price !== undefined ? <span className="tbox-entity__price text-base font-bold text-primary">{price}</span> : null}
|
|
461
|
-
{action}
|
|
532
|
+
{price !== undefined || action ? (
|
|
533
|
+
<div className="tbox-entity__right flex shrink-0 flex-col items-end gap-1">
|
|
534
|
+
{price !== undefined ? <span className="tbox-entity__price text-base font-bold text-primary">{price}</span> : null}
|
|
535
|
+
{action}
|
|
536
|
+
</div>
|
|
537
|
+
) : null}
|
|
462
538
|
</div>
|
|
539
|
+
{actions ? (
|
|
540
|
+
// 条目动作行:按钮等分撑满(`[&>*]:min-w-0 [&>*]:flex-1` 让任意子元素都能均分,
|
|
541
|
+
// 调用方不必自己包一层 div——曾经双层 flex 缺 flex-1 导致三个按钮挤成一条)。
|
|
542
|
+
<div className="tbox-entity__action-row flex gap-1.5 [&>*]:min-w-0 [&>*]:flex-1">{actions}</div>
|
|
463
543
|
) : null}
|
|
464
544
|
</div>
|
|
465
545
|
);
|
|
@@ -582,8 +662,15 @@ export interface CardActionSpec {
|
|
|
582
662
|
send?: string | { text: string; displayText?: string };
|
|
583
663
|
/** 走确定性动作:id + 入参 */
|
|
584
664
|
invoke?: { id: string; input?: Record<string, unknown> };
|
|
585
|
-
/**
|
|
586
|
-
confirm?: {
|
|
665
|
+
/** 点击前确认(tone/highlights 与 ConfirmSheet 同义:危险操作语气、权益摘要) */
|
|
666
|
+
confirm?: {
|
|
667
|
+
title: string;
|
|
668
|
+
description?: ReactNode;
|
|
669
|
+
confirmText?: string;
|
|
670
|
+
cancelText?: string;
|
|
671
|
+
tone?: 'primary' | 'danger';
|
|
672
|
+
highlights?: string[];
|
|
673
|
+
};
|
|
587
674
|
style?: 'primary' | 'secondary';
|
|
588
675
|
}
|
|
589
676
|
|
|
@@ -615,6 +702,105 @@ function stableHash(text: string): string {
|
|
|
615
702
|
return (hash >>> 0).toString(36);
|
|
616
703
|
}
|
|
617
704
|
|
|
705
|
+
/**
|
|
706
|
+
* 单动作按钮(`ActionList` 的单个版本):三件套自定义卡片想复用「单飞 / 确认弹层 / 历史禁用」
|
|
707
|
+
* 却不想摆一整行时用它——与 `ActionList` 共用同一套挂起键与确认语义。
|
|
708
|
+
*
|
|
709
|
+
* ```tsx
|
|
710
|
+
* const api = useCardActions({ cardId, isHistory, actionTokens });
|
|
711
|
+
* <CardActionButton api={api} action={{ label: '领取', invoke: { id: 'claim' } }} />
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
export function CardActionButton({
|
|
715
|
+
api,
|
|
716
|
+
action,
|
|
717
|
+
variant,
|
|
718
|
+
size = 'md',
|
|
719
|
+
className,
|
|
720
|
+
}: {
|
|
721
|
+
api: CardActions;
|
|
722
|
+
action: CardActionSpec;
|
|
723
|
+
/** 缺省按 action.style(primary → 实心) */
|
|
724
|
+
variant?: CardButtonVariant;
|
|
725
|
+
size?: 'md' | 'sm';
|
|
726
|
+
className?: string;
|
|
727
|
+
}) {
|
|
728
|
+
const [confirming, setConfirming] = useState(false);
|
|
729
|
+
const [running, setRunning] = useState(false);
|
|
730
|
+
const runningRef = useRef(false);
|
|
731
|
+
const mountedRef = useRef(true);
|
|
732
|
+
/** 挂起令牌:await 回来时若已开始下一轮动作(连点/换卡),旧回调不再改状态。 */
|
|
733
|
+
const tokenRef = useRef<symbol | null>(null);
|
|
734
|
+
useEffect(() => {
|
|
735
|
+
mountedRef.current = true;
|
|
736
|
+
return () => { mountedRef.current = false; };
|
|
737
|
+
}, []);
|
|
738
|
+
|
|
739
|
+
const run = () => {
|
|
740
|
+
if (!action.invoke && !action.send) return;
|
|
741
|
+
const token = Symbol('card-action');
|
|
742
|
+
tokenRef.current = token;
|
|
743
|
+
runningRef.current = true;
|
|
744
|
+
setRunning(true);
|
|
745
|
+
const promise = action.invoke
|
|
746
|
+
? api.invoke(action.invoke.id, action.invoke.input)
|
|
747
|
+
: typeof action.send === 'string'
|
|
748
|
+
? api.send(action.send)
|
|
749
|
+
: api.send(action.send!.text, { displayText: action.send!.displayText });
|
|
750
|
+
const clear = () => {
|
|
751
|
+
if (!mountedRef.current) return;
|
|
752
|
+
if (tokenRef.current !== token) return;
|
|
753
|
+
runningRef.current = false;
|
|
754
|
+
setRunning(false);
|
|
755
|
+
};
|
|
756
|
+
void promise.then(clear, clear);
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
const onClick = () => {
|
|
760
|
+
if (api.disabled || runningRef.current) return;
|
|
761
|
+
// 与 ActionList 同语义:有 confirm 先弹确认层,确认后才真正执行
|
|
762
|
+
if (action.confirm) {
|
|
763
|
+
setConfirming(true);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
run();
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
const resolvedVariant: CardButtonVariant =
|
|
770
|
+
variant ?? (action.style === 'primary' ? 'primary' : action.style === 'secondary' ? 'secondary' : 'secondary');
|
|
771
|
+
|
|
772
|
+
return (
|
|
773
|
+
<>
|
|
774
|
+
<CardButton
|
|
775
|
+
variant={resolvedVariant}
|
|
776
|
+
size={size}
|
|
777
|
+
disabled={api.disabled || running}
|
|
778
|
+
loading={running}
|
|
779
|
+
className={className ?? ''}
|
|
780
|
+
onClick={onClick}
|
|
781
|
+
>
|
|
782
|
+
{action.label}
|
|
783
|
+
</CardButton>
|
|
784
|
+
{confirming && action.confirm ? (
|
|
785
|
+
<ConfirmSheet
|
|
786
|
+
open
|
|
787
|
+
title={action.confirm.title}
|
|
788
|
+
{...(action.confirm.description ? { description: action.confirm.description } : {})}
|
|
789
|
+
{...(action.confirm.confirmText ? { confirmText: action.confirm.confirmText } : {})}
|
|
790
|
+
{...(action.confirm.cancelText ? { cancelText: action.confirm.cancelText } : {})}
|
|
791
|
+
{...(action.confirm.tone ? { tone: action.confirm.tone } : {})}
|
|
792
|
+
{...(action.confirm.highlights ? { highlights: action.confirm.highlights } : {})}
|
|
793
|
+
onConfirm={() => {
|
|
794
|
+
setConfirming(false);
|
|
795
|
+
run();
|
|
796
|
+
}}
|
|
797
|
+
onCancel={() => setConfirming(false)}
|
|
798
|
+
/>
|
|
799
|
+
) : null}
|
|
800
|
+
</>
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
|
|
618
804
|
export function ActionList({ actions, api }: { actions: CardActionSpec[]; api: CardActions }) {
|
|
619
805
|
const [confirmIndex, setConfirmIndex] = useState<number | null>(null);
|
|
620
806
|
const [running, setRunning] = useState<string | null>(null);
|
|
@@ -664,6 +850,8 @@ export function ActionList({ actions, api }: { actions: CardActionSpec[]; api: C
|
|
|
664
850
|
run(spec, index);
|
|
665
851
|
};
|
|
666
852
|
const pendingSpec = confirmIndex === null ? undefined : actions[confirmIndex];
|
|
853
|
+
// 两个短文案按钮(≤8 字)单行并排;动作 ≥3 或文案过长时退回「整行主按钮 + 次行并排」。
|
|
854
|
+
const pairInline = actions.length === 2 && actions.every((spec) => spec.label.trim().length <= 8);
|
|
667
855
|
const busy = api.disabled || running !== null || confirmIndex !== null;
|
|
668
856
|
const label = (text: string, index: number) => (
|
|
669
857
|
<span className="inline-flex items-center gap-2">
|
|
@@ -679,35 +867,56 @@ export function ActionList({ actions, api }: { actions: CardActionSpec[]; api: C
|
|
|
679
867
|
return (
|
|
680
868
|
<>
|
|
681
869
|
<div className="tbox-action-list mt-2.5 flex flex-col gap-2">
|
|
682
|
-
{
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
<CardButton
|
|
699
|
-
variant={spec.style ?? 'secondary'}
|
|
700
|
-
disabled={busy}
|
|
701
|
-
busy={running === actionKeyOf(spec, actionIndex)}
|
|
702
|
-
onClick={() => trigger(spec, actionIndex)}
|
|
703
|
-
>
|
|
704
|
-
{label(spec.label, actionIndex)}
|
|
705
|
-
</CardButton>
|
|
706
|
-
</div>
|
|
707
|
-
);
|
|
708
|
-
})}
|
|
870
|
+
{/* 两个短按钮并排:DOM 顺序恒为 [主, 次](保键盘首焦与按索引查按钮的测试),
|
|
871
|
+
用 flex-row-reverse 让主按钮落在右手侧。单行后卡高立省 52px。 */}
|
|
872
|
+
{pairInline ? (
|
|
873
|
+
<div className="tbox-action-list__row tbox-action-list__row--inline flex flex-row-reverse gap-2">
|
|
874
|
+
{actions.map((spec, actionIndex) => (
|
|
875
|
+
<div key={spec.label + '-' + actionIndex} className={actionIndex === 0 ? 'min-w-0 flex-[1.35]' : 'min-w-0 flex-1'}>
|
|
876
|
+
<CardButton
|
|
877
|
+
variant={spec.style ?? (actionIndex === 0 ? 'primary' : 'secondary')}
|
|
878
|
+
disabled={busy}
|
|
879
|
+
busy={running === actionKeyOf(spec, actionIndex)}
|
|
880
|
+
onClick={() => trigger(spec, actionIndex)}
|
|
881
|
+
>
|
|
882
|
+
{label(spec.label, actionIndex)}
|
|
883
|
+
</CardButton>
|
|
884
|
+
</div>
|
|
885
|
+
))}
|
|
709
886
|
</div>
|
|
710
|
-
) :
|
|
887
|
+
) : (
|
|
888
|
+
<>
|
|
889
|
+
{actions[0] ? (
|
|
890
|
+
<CardButton
|
|
891
|
+
variant={actions[0].style ?? 'primary'}
|
|
892
|
+
disabled={busy}
|
|
893
|
+
busy={running === actionKeyOf(actions[0], 0)}
|
|
894
|
+
onClick={() => trigger(actions[0], 0)}
|
|
895
|
+
>
|
|
896
|
+
{label(actions[0].label, 0)}
|
|
897
|
+
</CardButton>
|
|
898
|
+
) : null}
|
|
899
|
+
{actions.length > 1 ? (
|
|
900
|
+
<div className="tbox-action-list__row flex gap-2">
|
|
901
|
+
{actions.slice(1).map((spec, index) => {
|
|
902
|
+
const actionIndex = index + 1;
|
|
903
|
+
return (
|
|
904
|
+
<div key={spec.label + '-' + actionIndex} className="min-w-0 flex-1">
|
|
905
|
+
<CardButton
|
|
906
|
+
variant={spec.style ?? 'secondary'}
|
|
907
|
+
disabled={busy}
|
|
908
|
+
busy={running === actionKeyOf(spec, actionIndex)}
|
|
909
|
+
onClick={() => trigger(spec, actionIndex)}
|
|
910
|
+
>
|
|
911
|
+
{label(spec.label, actionIndex)}
|
|
912
|
+
</CardButton>
|
|
913
|
+
</div>
|
|
914
|
+
);
|
|
915
|
+
})}
|
|
916
|
+
</div>
|
|
917
|
+
) : null}
|
|
918
|
+
</>
|
|
919
|
+
)}
|
|
711
920
|
</div>
|
|
712
921
|
{pendingSpec?.confirm ? (
|
|
713
922
|
<ConfirmSheet
|
|
@@ -716,6 +925,8 @@ export function ActionList({ actions, api }: { actions: CardActionSpec[]; api: C
|
|
|
716
925
|
{...(pendingSpec.confirm.description ? { description: pendingSpec.confirm.description } : {})}
|
|
717
926
|
{...(pendingSpec.confirm.confirmText ? { confirmText: pendingSpec.confirm.confirmText } : {})}
|
|
718
927
|
{...(pendingSpec.confirm.cancelText ? { cancelText: pendingSpec.confirm.cancelText } : {})}
|
|
928
|
+
{...(pendingSpec.confirm.tone ? { tone: pendingSpec.confirm.tone } : {})}
|
|
929
|
+
{...(pendingSpec.confirm.highlights ? { highlights: pendingSpec.confirm.highlights } : {})}
|
|
719
930
|
onConfirm={() => {
|
|
720
931
|
const spec = pendingSpec;
|
|
721
932
|
const index = confirmIndex ?? 0;
|
|
@@ -44,6 +44,8 @@ export function toOutcome(dispatch: UiActionDispatch): Promise<ActionOutcome> {
|
|
|
44
44
|
|
|
45
45
|
export function useCardActions(opts: UseCardActionsOptions): CardActions {
|
|
46
46
|
const sendUiAction = useChatStore((s) => s.sendUiAction);
|
|
47
|
+
// 抽屉里点「带我去 / 问一句」后立刻收起抽屉:否则 65vh 的面板会挡住底层刚产生的回复。
|
|
48
|
+
const closeSheetCard = useChatStore((s) => s.closeSheetCard);
|
|
47
49
|
const isGenerating = useChatStore((s) => s.isGenerating);
|
|
48
50
|
const isHistory = opts.isHistory === true;
|
|
49
51
|
const disabled = isHistory || isGenerating;
|
|
@@ -59,6 +61,8 @@ export function useCardActions(opts: UseCardActionsOptions): CardActions {
|
|
|
59
61
|
void toast('正在处理上一条消息,请稍候', 'info');
|
|
60
62
|
return Promise.resolve({ status: 'rejected', reason: 'generating' });
|
|
61
63
|
}
|
|
64
|
+
// 抽屉里发起对话 → 先收起抽屉,让底层刚产生的回复可见(否则 65vh 面板挡住回复)。
|
|
65
|
+
closeSheetCard?.();
|
|
62
66
|
return toOutcome(sendUiAction(opts.cardId, {
|
|
63
67
|
type: 'sendMessage',
|
|
64
68
|
value: text,
|
|
@@ -66,7 +70,7 @@ export function useCardActions(opts: UseCardActionsOptions): CardActions {
|
|
|
66
70
|
visible: true,
|
|
67
71
|
}));
|
|
68
72
|
},
|
|
69
|
-
[opts.cardId, isHistory, isGenerating, sendUiAction],
|
|
73
|
+
[opts.cardId, isHistory, isGenerating, sendUiAction, closeSheetCard],
|
|
70
74
|
);
|
|
71
75
|
|
|
72
76
|
const invoke = useCallback(
|