/** Configuration is owned by the installed skill's declaration/recipe. */ import { useEffect, useState } from 'react' import { ImageGenApi } from './api.ts' import type { CanvasSkillConfigView } from '../protocol.ts' import { errorMessage, tt } from './helpers.ts' import { useImageGenLanguageTick } from './use-language.ts' import css from './ppt-workspace.module.css' export const PPT_SKILL_NAME = 'image-to-editable-ppt' export const PPT_SKILL_URL = 'https://github.com/ningzimu/image-to-editable-ppt-skill' const settingsApi = new ImageGenApi() export function PptSetup() { useImageGenLanguageTick() const [config, setConfig] = useState() const [installed, setInstalled] = useState(false) const [draft, setDraft] = useState>({}) const [busy, setBusy] = useState(false) const [message, setMessage] = useState('') const load = async (): Promise => { const library = await settingsApi.canvasSkillLibrary() const entry = library.entries.find(entry => entry.name === PPT_SKILL_NAME) setInstalled(entry !== undefined) setConfig(entry?.config) } useEffect(() => { void load().catch(error => setMessage(errorMessage(error))) }, []) const act = (action: () => Promise): void => { if (busy) return setBusy(true); setMessage('') void action().then(setMessage, error => setMessage(errorMessage(error))).finally(() => setBusy(false)) } return

{tt('ppt.setupHint')} image-to-editable-ppt ↗

{tt('ppt.runtimeHint')}

{config ?
{ event.preventDefault(); act(async () => { await settingsApi.canvasSkillConfigSave({ name: PPT_SKILL_NAME, values: Object.entries(draft).filter(([id, value]) => value !== '' || config.fields.find(field => field.id === id)?.type !== 'secret').map(([id, value]) => ({ id, value })) }) setDraft({}); await load() const applied = await settingsApi.canvasSkillConfigApply({ name: PPT_SKILL_NAME }) if (!applied.ok) throw new Error(applied.message || applied.steps.filter(step => !step.ok).map(step => step.output || step.detail).join('\n')) return tt('ppt.configSaved') }) }}>

{config.note}

{config.fields.map(field => { const stored = config.values.find(value => value.id === field.id) return })} {tt('ppt.paddleLink')} ↗
: null} {busy ?

{tt('ppt.setupWorking')}

: null} {message ?
{message}
: null}
}