import { customElement, noShadowDOM } from 'solid-element'; import { For, Show, createEffect } from 'solid-js'; import type {TextResult, RuntimeResult, OptionsResult} from '../yarn-spinner/runtime/results'; import { createYarnStore } from './stores/yarnStore'; export interface YarnSpinnerProps { start: string; } customElement<{start: string}>('md-yarn-spinner', {start: 'start'}, (props, { element }) => { noShadowDOM(); let historyContainer: HTMLDivElement | undefined; const { store, advance, restart } = createYarnStore(element as any, props); // 滚动到底部 const scrollToBottom = () => { if (historyContainer) { setTimeout(() => { historyContainer!.scrollTop = historyContainer!.scrollHeight; }, 0); } }; // 监听对话历史变化,自动滚动到底部 createEffect(() => { store.dialogueHistory; scrollToBottom(); }); // 渲染对话历史项 const renderEntry = (result: RuntimeResult | OptionsResult['options'][0]) => { if(!('type' in result)){ return
{"->"} {result.text}
} if (result.type === 'text') { const textResult = result as TextResult; return (
{textResult.speaker}: {textResult.text}
); } if (result.type === 'command') { return (
[{result.command}]
); } return null; }; return (
{/* 对话历史 */}
点击重新开始开始对话
{renderEntry}
{/* 浮动工具栏 */}
{/* 当前选项 */}
{(option, index) => ( )}
); });