File size: 2,639 Bytes
494c9e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import type * as d3 from 'd3';
/**
* 「主操作 + Force retry」在「草稿 vs 已提交快照」下的禁用/样式规则。
* Context Attribution 与 LLM Raw Chat 共用:idleInputsReady ∧ hasUncommittedDraft → 主钮;
* idleInputsReady → Force retry;进行中时按页面策略冻结或变为 Stop。
*/
export type SyncDraftCommittedButtonPairOptions = {
primaryBtn: d3.Selection<any, unknown, any, any>;
forceRetryBtn: d3.Selection<any, unknown, any, any>;
inFlight: boolean;
/** freeze:两钮禁用且不改主钮文案(归因);stop:主钮可点并换文案(Chat → Stop) */
primaryInFlightMode: 'freeze' | 'stop';
/** primaryInFlightMode === 'stop' 时必填 */
primaryInFlightLabel?: string;
primaryIdleLabel: string;
/** 非进行中时,输入是否满足发起请求 */
idleInputsReady: boolean;
hasUncommittedDraft: boolean;
};
export function syncDraftCommittedButtonPair(opts: SyncDraftCommittedButtonPairOptions): void {
const {
primaryBtn,
forceRetryBtn,
inFlight,
primaryInFlightMode,
primaryInFlightLabel,
primaryIdleLabel,
idleInputsReady,
hasUncommittedDraft,
} = opts;
if (inFlight && primaryInFlightMode === 'stop') {
if (primaryInFlightLabel === undefined) {
throw new Error(
'syncDraftCommittedButtonPair: primaryInFlightLabel is required when primaryInFlightMode is stop'
);
}
primaryBtn.text(primaryInFlightLabel);
primaryBtn.property('disabled', false);
primaryBtn.classed('inactive', false);
forceRetryBtn.property('disabled', true);
forceRetryBtn.classed('inactive', true);
return;
}
if (inFlight && primaryInFlightMode === 'freeze') {
primaryBtn.property('disabled', true);
primaryBtn.classed('inactive', true);
forceRetryBtn.property('disabled', true);
forceRetryBtn.classed('inactive', true);
return;
}
primaryBtn.text(primaryIdleLabel);
if (!idleInputsReady) {
primaryBtn.property('disabled', true);
primaryBtn.classed('inactive', true);
forceRetryBtn.property('disabled', true);
forceRetryBtn.classed('inactive', true);
return;
}
const enablePrimary = hasUncommittedDraft;
const enableForceRetry = true;
primaryBtn.property('disabled', !enablePrimary);
primaryBtn.classed('inactive', !enablePrimary);
forceRetryBtn.property('disabled', !enableForceRetry);
forceRetryBtn.classed('inactive', !enableForceRetry);
}
|