HEL-840: share preview and protected replacement across prompt fields
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -240,7 +240,8 @@
|
||||
>
|
||||
<span class="result-title"
|
||||
><span class="media-tag">第 {job?.id} 次生成</span><small
|
||||
class="media-tag">{wf?.name ?? '历史作品'}</small
|
||||
class="media-tag"
|
||||
title={wf?.name}>{wf?.name ?? '历史作品'}</small
|
||||
>{#if dims}<span class="media-tag">{dims}</span>{/if}</span
|
||||
>
|
||||
</button>
|
||||
@@ -703,6 +704,8 @@
|
||||
color: var(--text-2);
|
||||
}
|
||||
.media-tag {
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 18px;
|
||||
@@ -713,6 +716,8 @@
|
||||
color: var(--on-media);
|
||||
}
|
||||
.result-title small {
|
||||
min-width: 0;
|
||||
flex-shrink: 1;
|
||||
color: var(--on-media);
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -291,7 +291,9 @@
|
||||
}
|
||||
|
||||
let actionRevision = 0;
|
||||
let promptContextEpoch = $state(0);
|
||||
function pickWorkflow(id: number) {
|
||||
++promptContextEpoch;
|
||||
bayOpen = false;
|
||||
if (slotBusy || submitting) return;
|
||||
actionRevision++;
|
||||
@@ -1279,6 +1281,8 @@
|
||||
>
|
||||
<Composer
|
||||
bind:this={composer}
|
||||
contextEpoch={promptContextEpoch}
|
||||
contextIdentity={`${kind}|${ctx?.projectId ?? ''}|${ctx?.stage ?? ''}|${ctx?.sourceId ?? ''}`}
|
||||
dock
|
||||
{ds}
|
||||
{values}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { promptTool } from '$lib/components/prompt-tools/state.svelte';
|
||||
import ToolButtons from '$lib/components/prompt-tools/ToolButtons.svelte';
|
||||
import ResultBand from '$lib/components/prompt-tools/ResultBand.svelte';
|
||||
import { resolve } from '$app/paths';
|
||||
import Modal from '$lib/components/ui/Modal.svelte';
|
||||
import { tick } from 'svelte';
|
||||
@@ -19,6 +23,8 @@
|
||||
/** Scrollable creative inputs with a separate, always visible submission footer. */
|
||||
interface Props {
|
||||
header?: Snippet;
|
||||
contextEpoch?: number;
|
||||
contextIdentity?: string;
|
||||
dock?: boolean;
|
||||
ds: DeskSchema;
|
||||
values: FormValues;
|
||||
@@ -47,6 +53,8 @@
|
||||
|
||||
let {
|
||||
header,
|
||||
contextEpoch = 0,
|
||||
contextIdentity = '',
|
||||
dock = false,
|
||||
ds,
|
||||
values,
|
||||
@@ -108,6 +116,27 @@
|
||||
const promptVal = $derived(
|
||||
ds.prompt ? String(values[ds.prompt.nodeId] ?? '') : '',
|
||||
);
|
||||
const positiveTool = promptTool(
|
||||
() => promptVal,
|
||||
() =>
|
||||
`${page.url.href}|${contextIdentity}|${contextEpoch}|${current?.id}|${current?.kind}|${ds.prompt?.nodeId}|positive`,
|
||||
(v) => {
|
||||
if (ds.prompt) onSet(ds.prompt.nodeId, v);
|
||||
},
|
||||
'正向提示词',
|
||||
() => negativeTool.close(),
|
||||
);
|
||||
const negativeTool = promptTool(
|
||||
() => (ds.negative ? String(values[ds.negative.nodeId] ?? '') : ''),
|
||||
() =>
|
||||
`${page.url.href}|${contextIdentity}|${contextEpoch}|${current?.id}|${current?.kind}|${ds.negative?.nodeId}|negative`,
|
||||
(v) => {
|
||||
if (ds.negative) onSet(ds.negative.nodeId, v);
|
||||
},
|
||||
'反向提示词',
|
||||
() => positiveTool.close(),
|
||||
);
|
||||
|
||||
const promptErr = $derived(
|
||||
showErrors && ds.prompt ? errors[ds.prompt.nodeId] : undefined,
|
||||
);
|
||||
@@ -210,6 +239,7 @@
|
||||
>{ds.negative ? '正向提示词' : '提示词'}
|
||||
{#if ds.prompt.required}<span>必填</span>{/if}</label
|
||||
>
|
||||
<ToolButtons tool={positiveTool} />
|
||||
<button
|
||||
class="expand-prompt"
|
||||
aria-expanded={expanded}
|
||||
@@ -227,8 +257,10 @@
|
||||
placeholder="描述你想要的画面、动作和镜头…"
|
||||
aria-label={t('studio.promptLabel')}
|
||||
aria-invalid={!!promptErr || undefined}
|
||||
oninput={(e) =>
|
||||
onSet(ds.prompt!.nodeId, e.currentTarget.value)}
|
||||
oninput={(e) => (
|
||||
positiveTool.edit(),
|
||||
onSet(ds.prompt!.nodeId, e.currentTarget.value)
|
||||
)}
|
||||
></textarea>
|
||||
<div class="prompt-counter">
|
||||
<span>Enter 换行 · Ctrl + Enter 生成</span><span
|
||||
@@ -242,10 +274,13 @@
|
||||
这个工具不需要填写提示词,请准备它需要的素材。
|
||||
</p>{/if}
|
||||
{#if dock && ds.negative}<div class="prompt-field negative">
|
||||
<label for="desk-negative"
|
||||
>反向提示词 {#if ds.negative.required}<span>必填</span
|
||||
>{/if}</label
|
||||
><textarea
|
||||
<div class="prompt-label">
|
||||
<label for="desk-negative"
|
||||
>反向提示词 {#if ds.negative.required}<span>必填</span
|
||||
>{/if}</label
|
||||
><ToolButtons tool={negativeTool} compact />
|
||||
</div>
|
||||
<textarea
|
||||
id="desk-negative"
|
||||
class="prompt"
|
||||
rows="4"
|
||||
@@ -254,8 +289,10 @@
|
||||
aria-label="反向提示词"
|
||||
aria-invalid={(showErrors && !!errors[ds.negative.nodeId]) ||
|
||||
undefined}
|
||||
oninput={(e) =>
|
||||
onSet(ds.negative!.nodeId, e.currentTarget.value)}
|
||||
oninput={(e) => (
|
||||
negativeTool.edit(),
|
||||
onSet(ds.negative!.nodeId, e.currentTarget.value)
|
||||
)}
|
||||
></textarea>
|
||||
<div class="prompt-counter">
|
||||
<span>避免的内容</span><span
|
||||
@@ -321,6 +358,7 @@
|
||||
>
|
||||
</details>{/if}
|
||||
</div>
|
||||
<ResultBand tool={positiveTool} /><ResultBand tool={negativeTool} />
|
||||
<footer class="submit">
|
||||
{#if dock}<div class="dock-chips">
|
||||
<button id="desk-conn" class="parameter" onclick={onOpenParams}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from "svelte";
|
||||
import { page } from "$app/state";
|
||||
import { promptTool } from "./state.svelte";
|
||||
import ToolButtons from "./ToolButtons.svelte";
|
||||
import ResultBand from "./ResultBand.svelte";
|
||||
let {
|
||||
value = $bindable(""),
|
||||
identity,
|
||||
label = "提示词",
|
||||
rows = 2,
|
||||
placeholder = "",
|
||||
}: {
|
||||
value?: string;
|
||||
identity: string;
|
||||
label?: string;
|
||||
rows?: number;
|
||||
placeholder?: string;
|
||||
} = $props();
|
||||
const tool = promptTool(
|
||||
() => value,
|
||||
() => `${page.url.pathname}|${identity}`,
|
||||
(v) => (value = v),
|
||||
untrack(() => label),
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="prompt-editor">
|
||||
<div class="prompt-editor-label">
|
||||
<span>{label}</span><ToolButtons {tool} />
|
||||
</div>
|
||||
<textarea
|
||||
class="a-input mono"
|
||||
bind:value
|
||||
{rows}
|
||||
{placeholder}
|
||||
oninput={() => tool.edit()}
|
||||
></textarea><ResultBand {tool} />
|
||||
</div>
|
||||
@@ -0,0 +1,102 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from "$app/paths";
|
||||
import type { PromptTool } from "./state.svelte";
|
||||
import Button from "$lib/components/ui/Button.svelte";
|
||||
import { toast } from "$lib/toast";
|
||||
let { tool }: { tool: PromptTool } = $props();
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(tool.result?.result ?? "");
|
||||
toast.success("已复制");
|
||||
} catch {
|
||||
toast.error("复制失败,请手动选择文本");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (e.key === "Escape" && tool.state !== "idle") tool.close();
|
||||
}}
|
||||
/>
|
||||
{#if tool.state !== "idle"}
|
||||
<section class="ptband" aria-label="提示词工具结果" aria-live="polite">
|
||||
<div class="pt-h">
|
||||
<b>{tool.action === "translate" ? "翻译" : "润色"} · {tool.label}</b>
|
||||
{#if tool.result}<span class="pt-dir"
|
||||
>{tool.result.direction
|
||||
? (tool.result.direction === "zh-en" ? "中→英" : "英→中") +
|
||||
" · " +
|
||||
(tool.result.direction_source === "auto"
|
||||
? "自动判断"
|
||||
: "手动换向")
|
||||
: "同语言润色"}</span
|
||||
>{/if}
|
||||
<span class="mg-grow"></span>
|
||||
{#if tool.state === "loading"}<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onclick={tool.close}>取消</Button
|
||||
>
|
||||
{:else if tool.state === "result"}
|
||||
{#if tool.confirm}<span class="pt-confirm">替换会覆盖你刚才的修改</span
|
||||
><Button size="sm" variant="ghost" onclick={tool.cancelConfirm}
|
||||
>取消</Button
|
||||
><Button size="sm" variant="scene" onclick={tool.replace}
|
||||
>仍然替换</Button
|
||||
>
|
||||
{:else}<Button size="sm" variant="ghost" onclick={copy}>复制</Button
|
||||
>{#if tool.action === "translate"}<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onclick={() =>
|
||||
tool.run(
|
||||
"translate",
|
||||
tool.result?.direction === "zh-en" ? "en-zh" : "zh-en",
|
||||
)}>换向重译</Button
|
||||
>{/if}<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onclick={() => tool.run(tool.action)}
|
||||
>重新{tool.action === "translate" ? "翻译" : "润色"}</Button
|
||||
><Button size="sm" variant="scene" onclick={tool.replace}>替换</Button
|
||||
>{/if}
|
||||
{:else}<Button size="sm" onclick={() => tool.run(tool.action)}
|
||||
>按当前文本重新处理</Button
|
||||
>{/if}
|
||||
<button
|
||||
type="button"
|
||||
class="pt-btn"
|
||||
aria-label="关闭提示词结果"
|
||||
onclick={tool.close}>×</button
|
||||
>
|
||||
</div>
|
||||
<div class="pt-b">
|
||||
{#if tool.text.length > 8000}<small>内容较长,处理可能较慢</small>{/if}
|
||||
{#if tool.state === "loading"}<div class="pt-wait">
|
||||
<i></i><i></i>你可以继续编辑原文;返回前若原文有改动,这次结果会被丢弃
|
||||
</div>
|
||||
{:else if tool.state === "stale"}<p class="pt-confirm">
|
||||
原文已修改,结果已丢弃
|
||||
</p>
|
||||
{:else if tool.state === "error"}<p class="pt-error">{tool.error}</p>
|
||||
<a href={resolve(`/connections?tab=llm&role=${tool.action}`)}
|
||||
>去指定{tool.action === "translate" ? "翻译" : "润色"}模型</a
|
||||
>
|
||||
{:else if tool.result}
|
||||
{#if tool.changed}<p class="pt-confirm">
|
||||
原文已修改,替换会覆盖新改动
|
||||
</p>{/if}
|
||||
<div class="pt-res">{tool.result.result}</div>
|
||||
<div class="pt-note">
|
||||
<span
|
||||
>{tool.result.model.following_default ? "跟随默认 · " : ""}{tool
|
||||
.result.model.name} · {tool.result.elapsed_ms} ms</span
|
||||
><span class="pt-verified"
|
||||
>技术片段已逐字核对 {tool.result.protected_fragments.length} 处</span
|
||||
><span>原提示词未改动 · 点「替换」才会写入</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
@@ -0,0 +1,28 @@
|
||||
<script lang="ts">
|
||||
import type { PromptTool } from "./state.svelte";
|
||||
let { tool, compact = false }: { tool: PromptTool; compact?: boolean } =
|
||||
$props();
|
||||
</script>
|
||||
|
||||
<div class="pt-buttons">
|
||||
<button
|
||||
type="button"
|
||||
class="pt-btn"
|
||||
class:on={tool.state !== "idle" && tool.action === "translate"}
|
||||
class:running={tool.state === "loading" && tool.action === "translate"}
|
||||
disabled={!tool.text.trim()}
|
||||
title={tool.text.trim() ? "翻译提示词,再点取消" : "先输入提示词"}
|
||||
onclick={() => tool.run("translate")}
|
||||
>译 {compact ? "" : "翻译"}
|
||||
<small>{tool.direction === "zh-en" ? "中→英" : "英→中"}</small></button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="pt-btn"
|
||||
class:on={tool.state !== "idle" && tool.action === "polish"}
|
||||
class:running={tool.state === "loading" && tool.action === "polish"}
|
||||
disabled={!tool.text.trim()}
|
||||
title={tool.text.trim() ? "同语言润色,再点取消" : "先输入提示词"}
|
||||
onclick={() => tool.run("polish")}>✦ {compact ? "" : "润色"}</button
|
||||
>
|
||||
</div>
|
||||
@@ -0,0 +1,182 @@
|
||||
/* Approved HEL-837 v2; shared by desk and workbench fields. */
|
||||
.pt-buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex: none;
|
||||
}
|
||||
.pt-btn {
|
||||
height: 22px;
|
||||
padding: 0 7px;
|
||||
border-radius: 5px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 11.5px;
|
||||
color: var(--tx-2);
|
||||
border: 1px solid transparent;
|
||||
position: relative;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pt-btn:hover {
|
||||
background: rgb(var(--ink) / 0.06);
|
||||
color: var(--tx-1);
|
||||
}
|
||||
.pt-btn.on {
|
||||
color: var(--tx-1);
|
||||
border-color: color-mix(in srgb, var(--scene) 50%, transparent);
|
||||
background: color-mix(in srgb, var(--scene) 12%, transparent);
|
||||
}
|
||||
.pt-btn:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.pt-btn small {
|
||||
font: 500 10px var(--mono);
|
||||
color: var(--tx-3);
|
||||
}
|
||||
.pt-btn.running::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
height: 2px;
|
||||
bottom: 0;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
background: var(--scene);
|
||||
animation: pt-progress 1s linear infinite;
|
||||
}
|
||||
.ptband {
|
||||
flex: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
border-top: 1px solid color-mix(in srgb, var(--scene) 30%, var(--line));
|
||||
background: color-mix(in srgb, var(--scene) 5%, transparent);
|
||||
max-height: var(--ptband-max-h);
|
||||
animation: pt-in var(--t-base) var(--ease-out);
|
||||
}
|
||||
.pt-h {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 10px 6px 12px;
|
||||
flex: none;
|
||||
min-height: 38px;
|
||||
}
|
||||
.pt-h b {
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pt-dir {
|
||||
font: 500 11px var(--mono);
|
||||
color: var(--tx-2);
|
||||
padding: 0 6px;
|
||||
height: 20px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 4px;
|
||||
background: rgb(var(--ink) / 0.05);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pt-b {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 0 12px 8px;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.pt-res {
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--tx-1);
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
user-select: text;
|
||||
padding: 6px 10px;
|
||||
border-radius: 8px;
|
||||
background: var(--well);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.pt-note {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 11px;
|
||||
color: var(--tx-3);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.pt-verified {
|
||||
color: var(--ok);
|
||||
}
|
||||
.pt-confirm {
|
||||
font-size: 11.5px;
|
||||
color: var(--warn);
|
||||
margin: 0;
|
||||
}
|
||||
.pt-error {
|
||||
color: var(--err);
|
||||
margin: 0;
|
||||
}
|
||||
.pt-wait {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
font-size: 11.5px;
|
||||
color: var(--tx-3);
|
||||
}
|
||||
.pt-wait i {
|
||||
height: 10px;
|
||||
border-radius: 4px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgb(var(--ink) / 0.06),
|
||||
rgb(var(--ink) / 0.13),
|
||||
rgb(var(--ink) / 0.06)
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: pt-skeleton 1.2s linear infinite;
|
||||
}
|
||||
.pt-wait i:nth-child(2) {
|
||||
width: 70%;
|
||||
}
|
||||
.prompt-editor {
|
||||
min-width: 0;
|
||||
}
|
||||
.prompt-editor textarea {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.prompt-editor-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 11.5px;
|
||||
color: var(--tx-2);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
@keyframes pt-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@keyframes pt-progress {
|
||||
50% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
}
|
||||
@keyframes pt-skeleton {
|
||||
to {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
html[data-motion="calm"] .ptband,
|
||||
html[data-motion="off"] .ptband,
|
||||
html[data-motion="calm"] .pt-btn::after,
|
||||
html[data-motion="off"] .pt-btn::after,
|
||||
html[data-motion="calm"] .pt-wait i,
|
||||
html[data-motion="off"] .pt-wait i {
|
||||
animation: none;
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
import { onDestroy, untrack } from "svelte";
|
||||
import { showToast, toast } from "$lib/toast";
|
||||
|
||||
export type Action = "translate" | "polish";
|
||||
export type Direction = "auto" | "zh-en" | "en-zh";
|
||||
export interface TransformResult {
|
||||
action: Action;
|
||||
direction: Exclude<Direction, "auto"> | null;
|
||||
direction_source: "auto" | "explicit" | null;
|
||||
result: string;
|
||||
protected_fragments: string[];
|
||||
model: {
|
||||
id: string;
|
||||
name: string;
|
||||
model: string;
|
||||
following_default: boolean;
|
||||
};
|
||||
elapsed_ms: number;
|
||||
}
|
||||
export function directionFor(text: string): Exclude<Direction, "auto"> {
|
||||
const body = text
|
||||
.replace(/<[^<>\n]{1,300}>/g, "")
|
||||
.replace(/:\s*-?\d+(?:\.\d+)?/g, "");
|
||||
return /[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]/.test(body)
|
||||
? "zh-en"
|
||||
: "en-zh";
|
||||
}
|
||||
|
||||
/** One field owns its monotonic history, including edits that restore the same text. */
|
||||
export function promptTool(
|
||||
getText: () => string,
|
||||
getContext: () => string,
|
||||
setText: (s: string) => void,
|
||||
label: string,
|
||||
onOpen?: () => void,
|
||||
) {
|
||||
let state = $state<"idle" | "loading" | "result" | "stale" | "error">("idle");
|
||||
let result = $state<TransformResult | null>(null);
|
||||
let error = $state("");
|
||||
let action = $state<Action>("translate");
|
||||
let confirm = $state(false);
|
||||
let textVersion = $state(0);
|
||||
let contextVersion = $state(0);
|
||||
let ticketTextVersion = $state(0);
|
||||
let seq = 0;
|
||||
let abort: AbortController | null = null;
|
||||
let alive = true;
|
||||
let observedText = untrack(getText);
|
||||
let observedContext = untrack(getContext);
|
||||
|
||||
function close() {
|
||||
++seq;
|
||||
abort?.abort();
|
||||
abort = null;
|
||||
state = "idle";
|
||||
confirm = false;
|
||||
}
|
||||
function edit() {
|
||||
++textVersion;
|
||||
confirm = false;
|
||||
}
|
||||
function sync() {
|
||||
const context = getContext();
|
||||
const text = getText();
|
||||
if (context !== observedContext) {
|
||||
observedContext = context;
|
||||
++contextVersion;
|
||||
close();
|
||||
}
|
||||
if (text !== observedText) {
|
||||
observedText = text;
|
||||
edit();
|
||||
}
|
||||
}
|
||||
$effect.pre(() => {
|
||||
getText();
|
||||
getContext();
|
||||
untrack(sync);
|
||||
});
|
||||
onDestroy(() => {
|
||||
alive = false;
|
||||
++contextVersion;
|
||||
close();
|
||||
});
|
||||
|
||||
async function run(next: Action, direction: Direction = "auto") {
|
||||
sync();
|
||||
if (!getText().trim()) return;
|
||||
if (state === "loading" && next === action) {
|
||||
close();
|
||||
toast.info("已取消,原提示词未改动");
|
||||
return;
|
||||
}
|
||||
onOpen?.();
|
||||
close();
|
||||
action = next;
|
||||
state = "loading";
|
||||
error = "";
|
||||
result = null;
|
||||
const id = ++seq;
|
||||
const textRev = textVersion,
|
||||
contextRev = contextVersion;
|
||||
const snapshot = getText(),
|
||||
context = getContext();
|
||||
ticketTextVersion = textRev;
|
||||
const controller = new AbortController();
|
||||
abort = controller;
|
||||
try {
|
||||
const response = await fetch("/api/prompt-tools/transform", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
signal: controller.signal,
|
||||
body: JSON.stringify({
|
||||
action: next,
|
||||
text: snapshot,
|
||||
...(next === "translate" ? { direction } : {}),
|
||||
}),
|
||||
});
|
||||
const payload = await response.json();
|
||||
sync();
|
||||
if (
|
||||
!alive ||
|
||||
id !== seq ||
|
||||
controller.signal.aborted ||
|
||||
contextRev !== contextVersion ||
|
||||
context !== getContext()
|
||||
)
|
||||
return;
|
||||
if (textRev !== textVersion) {
|
||||
state = "stale";
|
||||
return;
|
||||
}
|
||||
if (!response.ok) {
|
||||
const detail = payload.detail;
|
||||
error =
|
||||
typeof detail === "object" && detail
|
||||
? `${detail.message ?? "处理失败"}${detail.model?.name ? " · " + detail.model.name : ""}`
|
||||
: "处理失败,请重试";
|
||||
state = "error";
|
||||
return;
|
||||
}
|
||||
result = payload as TransformResult;
|
||||
state = "result";
|
||||
} catch (e) {
|
||||
sync();
|
||||
if (
|
||||
!alive ||
|
||||
id !== seq ||
|
||||
controller.signal.aborted ||
|
||||
contextRev !== contextVersion
|
||||
)
|
||||
return;
|
||||
if (textRev !== textVersion) {
|
||||
state = "stale";
|
||||
return;
|
||||
}
|
||||
error =
|
||||
e instanceof TypeError
|
||||
? "无法连接工作台服务器,请检查连接后重试"
|
||||
: "处理失败,请重试";
|
||||
state = "error";
|
||||
} finally {
|
||||
if (id === seq) abort = null;
|
||||
}
|
||||
}
|
||||
function replace() {
|
||||
sync();
|
||||
if (state !== "result" || !result) return;
|
||||
if (textVersion !== ticketTextVersion && !confirm) {
|
||||
confirm = true;
|
||||
return;
|
||||
}
|
||||
const before = getText(),
|
||||
output = result.result,
|
||||
ctxRev = contextVersion,
|
||||
ctx = getContext();
|
||||
setText(output);
|
||||
edit();
|
||||
observedText = output;
|
||||
const replaceVersion = textVersion;
|
||||
close();
|
||||
const expires = Date.now() + 5000;
|
||||
showToast(`已替换${label}`, "success", 5000, {
|
||||
label: "撤销",
|
||||
run() {
|
||||
sync();
|
||||
if (
|
||||
!alive ||
|
||||
Date.now() > expires ||
|
||||
textVersion !== replaceVersion ||
|
||||
contextVersion !== ctxRev ||
|
||||
getContext() !== ctx
|
||||
) {
|
||||
toast.info("内容已变化或已切换,未自动恢复");
|
||||
return;
|
||||
}
|
||||
setText(before);
|
||||
observedText = before;
|
||||
edit();
|
||||
},
|
||||
});
|
||||
}
|
||||
return {
|
||||
get state() {
|
||||
return state;
|
||||
},
|
||||
get result() {
|
||||
return result;
|
||||
},
|
||||
get error() {
|
||||
return error;
|
||||
},
|
||||
get action() {
|
||||
return action;
|
||||
},
|
||||
get confirm() {
|
||||
return confirm;
|
||||
},
|
||||
get label() {
|
||||
return label;
|
||||
},
|
||||
get changed() {
|
||||
return textVersion !== ticketTextVersion;
|
||||
},
|
||||
get text() {
|
||||
return getText();
|
||||
},
|
||||
get direction() {
|
||||
return directionFor(getText());
|
||||
},
|
||||
run,
|
||||
close,
|
||||
edit,
|
||||
replace,
|
||||
cancelConfirm() {
|
||||
confirm = false;
|
||||
},
|
||||
};
|
||||
}
|
||||
export type PromptTool = ReturnType<typeof promptTool>;
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
interface Props {
|
||||
/** `danger` = outlined (list rows); `danger-solid` = confirm dialogs only. */
|
||||
variant?: 'primary' | 'secondary' | 'ghost' | 'danger' | 'danger-solid';
|
||||
variant?:
|
||||
'primary' | 'secondary' | 'ghost' | 'danger' | 'danger-solid' | 'scene';
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
/** Stretch to the container width (e.g. a panel's main action). */
|
||||
block?: boolean;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import PromptEditor from '$lib/components/prompt-tools/PromptEditor.svelte';
|
||||
import { resolve } from '$app/paths';
|
||||
import type { WorkbenchAsset, WorkbenchStage } from '$lib/api';
|
||||
import { assetUrl } from '$lib/api';
|
||||
@@ -24,14 +25,23 @@
|
||||
busy?: boolean;
|
||||
}
|
||||
|
||||
let { stage, projectId, onSave, onRun, onGenerate, onRetryJob, busy = false }: Props = $props();
|
||||
let {
|
||||
stage,
|
||||
projectId,
|
||||
onSave,
|
||||
onRun,
|
||||
onGenerate,
|
||||
onRetryJob,
|
||||
busy = false,
|
||||
}: Props = $props();
|
||||
|
||||
let editing = $state(false);
|
||||
let draft = $state<WorkbenchAsset[]>([]);
|
||||
|
||||
const assets = $derived(
|
||||
Array.isArray((stage.content as { assets?: unknown } | null)?.assets)
|
||||
? ((stage.content as unknown as { assets: WorkbenchAsset[] }).assets ?? [])
|
||||
? ((stage.content as unknown as { assets: WorkbenchAsset[] }).assets ??
|
||||
[])
|
||||
: [],
|
||||
);
|
||||
|
||||
@@ -75,11 +85,13 @@
|
||||
return !!job && (job.status === 'pending' || job.status === 'running');
|
||||
}
|
||||
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() { return editing; }
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() {
|
||||
return editing;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
@@ -89,11 +101,19 @@
|
||||
<div class="asset-edit">
|
||||
<div class="asset-edit-head">
|
||||
<select class="a-input w-kind" bind:value={asset.kind}>
|
||||
<option value="character">{t('workbench.asset.kindCharacter')}</option>
|
||||
<option value="location">{t('workbench.asset.kindLocation')}</option>
|
||||
<option value="character"
|
||||
>{t('workbench.asset.kindCharacter')}</option
|
||||
>
|
||||
<option value="location"
|
||||
>{t('workbench.asset.kindLocation')}</option
|
||||
>
|
||||
<option value="prop">{t('workbench.asset.kindProp')}</option>
|
||||
</select>
|
||||
<input class="a-input name" bind:value={asset.name} placeholder={t('workbench.asset.namePh')} />
|
||||
<input
|
||||
class="a-input name"
|
||||
bind:value={asset.name}
|
||||
placeholder={t('workbench.asset.namePh')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn danger"
|
||||
@@ -103,17 +123,20 @@
|
||||
<Icon name="trash" size={13} />
|
||||
</button>
|
||||
</div>
|
||||
<input class="a-input" bind:value={asset.description} placeholder={t('workbench.asset.descPh')} />
|
||||
<textarea
|
||||
class="a-input mono"
|
||||
rows="2"
|
||||
bind:value={asset.prompt}
|
||||
placeholder={t('workbench.asset.promptPh')}
|
||||
></textarea>
|
||||
<input
|
||||
class="a-input mono"
|
||||
class="a-input"
|
||||
bind:value={asset.description}
|
||||
placeholder={t('workbench.asset.descPh')}
|
||||
/>
|
||||
<PromptEditor
|
||||
bind:value={asset.prompt}
|
||||
identity={`assets|${asset.id}|prompt`}
|
||||
label="提示词"
|
||||
/>
|
||||
<PromptEditor
|
||||
bind:value={asset.negative_prompt}
|
||||
placeholder={t('workbench.style.negativePh')}
|
||||
identity={`assets|${asset.id}|negative_prompt`}
|
||||
label="反向提示词"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -124,7 +147,11 @@
|
||||
{t('workbench.asset.add')}
|
||||
</button>
|
||||
<div class="foot-btns">
|
||||
<button type="button" class="a-btn ghost" onclick={() => (editing = false)}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
onclick={() => (editing = false)}
|
||||
>
|
||||
{t('workbench.cancelEdit')}
|
||||
</button>
|
||||
<button
|
||||
@@ -142,7 +169,12 @@
|
||||
<div class="todo-card">
|
||||
<p class="todo-title">{t('workbench.asset.todoTitle')}</p>
|
||||
<p class="todo-body">{t('workbench.asset.todoBody')}</p>
|
||||
<button type="button" class="a-btn primary" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn primary"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="sparkle" size={14} />
|
||||
{t('workbench.asset.generate')}
|
||||
</button>
|
||||
@@ -152,7 +184,9 @@
|
||||
{#each assets as asset (asset.id)}
|
||||
<div class="asset-card">
|
||||
<div class="asset-head">
|
||||
<span class="kind-tag kind-{asset.kind}">{t(KIND_LABEL[asset.kind] ?? 'workbench.asset.kindProp')}</span>
|
||||
<span class="kind-tag kind-{asset.kind}"
|
||||
>{t(KIND_LABEL[asset.kind] ?? 'workbench.asset.kindProp')}</span
|
||||
>
|
||||
<span class="asset-name">{asset.name}</span>
|
||||
{#if asset.job}
|
||||
<JobChip job={asset.job} />
|
||||
@@ -167,33 +201,54 @@
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{#if asset.description}<p class="asset-desc">{asset.description}</p>{/if}
|
||||
{#if asset.description}<p class="asset-desc">
|
||||
{asset.description}
|
||||
</p>{/if}
|
||||
{#if asset.job?.status === 'done' && asset.job.output}
|
||||
<a class="asset-shot" href={assetUrl(asset.job.output) ?? '#'} target="_blank" rel="noopener external">
|
||||
<img src={assetUrl(asset.job.output) ?? ''} alt={asset.name} loading="lazy" />
|
||||
<a
|
||||
class="asset-shot"
|
||||
href={assetUrl(asset.job.output) ?? '#'}
|
||||
target="_blank"
|
||||
rel="noopener external"
|
||||
>
|
||||
<img
|
||||
src={assetUrl(asset.job.output) ?? ''}
|
||||
alt={asset.name}
|
||||
loading="lazy"
|
||||
/>
|
||||
</a>
|
||||
{/if}
|
||||
<PromptBlock label={t('workbench.asset.promptLabel')} text={asset.prompt} />
|
||||
<PromptBlock
|
||||
label={t('workbench.asset.promptLabel')}
|
||||
text={asset.prompt}
|
||||
/>
|
||||
{#if asset.negative_prompt}
|
||||
<PromptBlock label={t('workbench.style.negativeLabel')} text={asset.negative_prompt} />
|
||||
<PromptBlock
|
||||
label={t('workbench.style.negativeLabel')}
|
||||
text={asset.negative_prompt}
|
||||
/>
|
||||
{/if}
|
||||
<div class="asset-foot">
|
||||
{#if projectId}
|
||||
<a
|
||||
class="a-btn ghost sm"
|
||||
href={resolve(deskHref({
|
||||
kind: 'image',
|
||||
projectId,
|
||||
stage: 'assets',
|
||||
label: t('desk.ctxAsset', {
|
||||
kind: t(KIND_LABEL[asset.kind] ?? 'workbench.asset.kindProp'),
|
||||
name: asset.name,
|
||||
href={resolve(
|
||||
deskHref({
|
||||
kind: 'image',
|
||||
projectId,
|
||||
stage: 'assets',
|
||||
label: t('desk.ctxAsset', {
|
||||
kind: t(
|
||||
KIND_LABEL[asset.kind] ?? 'workbench.asset.kindProp',
|
||||
),
|
||||
name: asset.name,
|
||||
}),
|
||||
prompt: asset.prompt,
|
||||
negative: asset.negative_prompt || undefined,
|
||||
sourceKind: 'asset',
|
||||
sourceId: asset.id,
|
||||
}),
|
||||
prompt: asset.prompt,
|
||||
negative: asset.negative_prompt || undefined,
|
||||
sourceKind: 'asset',
|
||||
sourceId: asset.id,
|
||||
}))}
|
||||
)}
|
||||
title={t('desk.openInDeskHint')}
|
||||
>
|
||||
{t('desk.openInDesk')}
|
||||
@@ -213,21 +268,35 @@
|
||||
})}
|
||||
>
|
||||
<Icon name="image" size={13} />
|
||||
{jobActive(asset.job) ? t('workbench.generating') : t('workbench.asset.generateImage')}
|
||||
{jobActive(asset.job)
|
||||
? t('workbench.generating')
|
||||
: t('workbench.asset.generateImage')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="view-foot">
|
||||
<span class="hint">{t('workbench.asset.summary', { n: assets.length })}</span>
|
||||
<span class="hint"
|
||||
>{t('workbench.asset.summary', { n: assets.length })}</span
|
||||
>
|
||||
<div class="foot-btns">
|
||||
{#if stage.status !== 'running'}
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={startEdit}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={startEdit}
|
||||
>
|
||||
<Icon name="edit" size={13} />
|
||||
{t('workbench.editDraft')}
|
||||
</button>
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="retry" size={13} />
|
||||
{t('workbench.regenerate')}
|
||||
</button>
|
||||
@@ -420,5 +489,4 @@
|
||||
background: var(--error-dim);
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import PromptEditor from '$lib/components/prompt-tools/PromptEditor.svelte';
|
||||
import { resolve } from '$app/paths';
|
||||
import type { VideoShot, WorkbenchStage } from '$lib/api';
|
||||
import { assetUrl } from '$lib/api';
|
||||
@@ -24,7 +25,15 @@
|
||||
busy?: boolean;
|
||||
}
|
||||
|
||||
let { stage, projectId, onSave, onRun, onGenerate, onRetryJob, busy = false }: Props = $props();
|
||||
let {
|
||||
stage,
|
||||
projectId,
|
||||
onSave,
|
||||
onRun,
|
||||
onGenerate,
|
||||
onRetryJob,
|
||||
busy = false,
|
||||
}: Props = $props();
|
||||
|
||||
let editing = $state(false);
|
||||
let draft = $state<VideoShot[]>([]);
|
||||
@@ -68,11 +77,13 @@
|
||||
return !!job && (job.status === 'pending' || job.status === 'running');
|
||||
}
|
||||
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() { return editing; }
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() {
|
||||
return editing;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
@@ -81,7 +92,11 @@
|
||||
{#each draft as shot (shot.id)}
|
||||
<div class="vshot-edit">
|
||||
<div class="vshot-edit-head">
|
||||
<input class="a-input w-no mono" bind:value={shot.shot_no} placeholder={t('workbench.vshot.noPh')} />
|
||||
<input
|
||||
class="a-input w-no mono"
|
||||
bind:value={shot.shot_no}
|
||||
placeholder={t('workbench.vshot.noPh')}
|
||||
/>
|
||||
<input
|
||||
class="a-input w-dur mono"
|
||||
type="number"
|
||||
@@ -99,13 +114,16 @@
|
||||
<Icon name="trash" size={13} />
|
||||
</button>
|
||||
</div>
|
||||
<input class="a-input" bind:value={shot.description} placeholder={t('workbench.vshot.descPh')} />
|
||||
<textarea
|
||||
class="a-input mono"
|
||||
rows="3"
|
||||
<input
|
||||
class="a-input"
|
||||
bind:value={shot.description}
|
||||
placeholder={t('workbench.vshot.descPh')}
|
||||
/>
|
||||
<PromptEditor
|
||||
bind:value={shot.prompt}
|
||||
placeholder={t('workbench.vshot.promptPh')}
|
||||
></textarea>
|
||||
identity={`shot|${shot.id}|prompt`}
|
||||
label="提示词"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -115,7 +133,11 @@
|
||||
{t('workbench.vshot.add')}
|
||||
</button>
|
||||
<div class="foot-btns">
|
||||
<button type="button" class="a-btn ghost" onclick={() => (editing = false)}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
onclick={() => (editing = false)}
|
||||
>
|
||||
{t('workbench.cancelEdit')}
|
||||
</button>
|
||||
<button
|
||||
@@ -133,7 +155,12 @@
|
||||
<div class="todo-card">
|
||||
<p class="todo-title">{t('workbench.vshot.todoTitle')}</p>
|
||||
<p class="todo-body">{t('workbench.vshot.todoBody')}</p>
|
||||
<button type="button" class="a-btn primary" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn primary"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="sparkle" size={14} />
|
||||
{t('workbench.vshot.generate')}
|
||||
</button>
|
||||
@@ -168,22 +195,28 @@
|
||||
preload="metadata"
|
||||
></video>
|
||||
{/if}
|
||||
<PromptBlock label={t('workbench.vshot.promptLabel')} text={shot.prompt} />
|
||||
<PromptBlock
|
||||
label={t('workbench.vshot.promptLabel')}
|
||||
text={shot.prompt}
|
||||
/>
|
||||
<div class="vshot-foot">
|
||||
{#if projectId}
|
||||
<a class="a-btn ghost sm" href={resolve('/build-scene')}>三维搭景</a>
|
||||
<a class="a-btn ghost sm" href={resolve('/build-scene')}>三维搭景</a
|
||||
>
|
||||
<a
|
||||
class="a-btn ghost sm"
|
||||
href={resolve(deskHref({
|
||||
kind: 'video',
|
||||
projectId,
|
||||
stage: 'shot',
|
||||
label: t('desk.ctxShot', { no: shot.shot_no }),
|
||||
prompt: shot.prompt,
|
||||
durationSec: shot.duration_sec,
|
||||
sourceKind: 'shot',
|
||||
sourceId: shot.id,
|
||||
}))}
|
||||
href={resolve(
|
||||
deskHref({
|
||||
kind: 'video',
|
||||
projectId,
|
||||
stage: 'shot',
|
||||
label: t('desk.ctxShot', { no: shot.shot_no }),
|
||||
prompt: shot.prompt,
|
||||
durationSec: shot.duration_sec,
|
||||
sourceKind: 'shot',
|
||||
sourceId: shot.id,
|
||||
}),
|
||||
)}
|
||||
title={t('desk.openInDeskHint')}
|
||||
>
|
||||
{t('desk.openInDesk')}
|
||||
@@ -203,21 +236,34 @@
|
||||
})}
|
||||
>
|
||||
<Icon name="film" size={13} />
|
||||
{jobActive(shot.job) ? t('workbench.generating') : t('workbench.vshot.generateVideo')}
|
||||
{jobActive(shot.job)
|
||||
? t('workbench.generating')
|
||||
: t('workbench.vshot.generateVideo')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="view-foot">
|
||||
<span class="hint">{t('workbench.vshot.summary', { n: shots.length })}</span>
|
||||
<span class="hint">{t('workbench.vshot.summary', { n: shots.length })}</span
|
||||
>
|
||||
<div class="foot-btns">
|
||||
{#if stage.status !== 'running'}
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={startEdit}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={startEdit}
|
||||
>
|
||||
<Icon name="edit" size={13} />
|
||||
{t('workbench.editDraft')}
|
||||
</button>
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="retry" size={13} />
|
||||
{t('workbench.regenerate')}
|
||||
</button>
|
||||
@@ -394,5 +440,4 @@
|
||||
background: var(--error-dim);
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import PromptEditor from '$lib/components/prompt-tools/PromptEditor.svelte';
|
||||
import type { StyleDirection, WorkbenchStage } from '$lib/api';
|
||||
import Icon from '$lib/components/ui/Icon.svelte';
|
||||
import PromptBlock from './PromptBlock.svelte';
|
||||
@@ -12,14 +13,23 @@
|
||||
busy?: boolean;
|
||||
}
|
||||
|
||||
let { stage, chosenStyleId = $bindable(null), onSave, onRun, busy = false }: Props = $props();
|
||||
let {
|
||||
stage,
|
||||
chosenStyleId = $bindable(null),
|
||||
onSave,
|
||||
onRun,
|
||||
busy = false,
|
||||
}: Props = $props();
|
||||
|
||||
let editing = $state(false);
|
||||
let draft = $state<StyleDirection[]>([]);
|
||||
|
||||
const directions = $derived(
|
||||
Array.isArray((stage.content as { directions?: unknown } | null)?.directions)
|
||||
? ((stage.content as unknown as { directions: StyleDirection[] }).directions ?? [])
|
||||
Array.isArray(
|
||||
(stage.content as { directions?: unknown } | null)?.directions,
|
||||
)
|
||||
? ((stage.content as unknown as { directions: StyleDirection[] })
|
||||
.directions ?? [])
|
||||
: [],
|
||||
);
|
||||
|
||||
@@ -60,11 +70,13 @@
|
||||
];
|
||||
}
|
||||
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() { return editing; }
|
||||
export function saveDraft() {
|
||||
if (editing) save();
|
||||
else if (stage.content) onSave?.(stage.content);
|
||||
}
|
||||
export function hasUnsavedDraft() {
|
||||
return editing;
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
@@ -73,7 +85,11 @@
|
||||
<div class="dir-edit">
|
||||
<div class="dir-edit-head">
|
||||
<span class="dir-index mono">{i + 1}</span>
|
||||
<input class="a-input name" bind:value={dir.name} placeholder={t('workbench.style.namePh')} />
|
||||
<input
|
||||
class="a-input name"
|
||||
bind:value={dir.name}
|
||||
placeholder={t('workbench.style.namePh')}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="icon-btn danger"
|
||||
@@ -88,16 +104,15 @@
|
||||
bind:value={dir.description}
|
||||
placeholder={t('workbench.style.descPh')}
|
||||
/>
|
||||
<textarea
|
||||
class="a-input mono"
|
||||
rows="2"
|
||||
<PromptEditor
|
||||
bind:value={dir.prompt}
|
||||
placeholder={t('workbench.style.promptPh')}
|
||||
></textarea>
|
||||
<input
|
||||
class="a-input mono"
|
||||
identity={`style|${dir.id}|prompt`}
|
||||
label="提示词"
|
||||
/>
|
||||
<PromptEditor
|
||||
bind:value={dir.negative_prompt}
|
||||
placeholder={t('workbench.style.negativePh')}
|
||||
identity={`style|${dir.id}|negative_prompt`}
|
||||
label="反向提示词"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -107,13 +122,18 @@
|
||||
{t('workbench.style.add')}
|
||||
</button>
|
||||
<div class="foot-btns">
|
||||
<button type="button" class="a-btn ghost" onclick={() => (editing = false)}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
onclick={() => (editing = false)}
|
||||
>
|
||||
{t('workbench.cancelEdit')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn primary"
|
||||
disabled={draft.filter((d) => d.name.trim() && d.prompt.trim()).length < 2}
|
||||
disabled={draft.filter((d) => d.name.trim() && d.prompt.trim())
|
||||
.length < 2}
|
||||
onclick={save}
|
||||
>
|
||||
{t('workbench.saveDraft')}
|
||||
@@ -125,13 +145,23 @@
|
||||
<div class="todo-card">
|
||||
<p class="todo-title">{t('workbench.style.todoTitle')}</p>
|
||||
<p class="todo-body">{t('workbench.style.todoBody')}</p>
|
||||
<button type="button" class="a-btn primary" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn primary"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="sparkle" size={14} />
|
||||
{t('workbench.style.generate')}
|
||||
</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="dir-grid" role="radiogroup" aria-label={t('workbench.stage.style')} data-testid="style-directions">
|
||||
<div
|
||||
class="dir-grid"
|
||||
role="radiogroup"
|
||||
aria-label={t('workbench.stage.style')}
|
||||
data-testid="style-directions"
|
||||
>
|
||||
{#each directions as dir (dir.id)}
|
||||
<label class="dir-card" class:chosen={dir.id === effectiveChosen}>
|
||||
<input
|
||||
@@ -148,9 +178,15 @@
|
||||
{/if}
|
||||
</div>
|
||||
{#if dir.description}<p class="dir-desc">{dir.description}</p>{/if}
|
||||
<PromptBlock label={t('workbench.style.promptLabel')} text={dir.prompt} />
|
||||
<PromptBlock
|
||||
label={t('workbench.style.promptLabel')}
|
||||
text={dir.prompt}
|
||||
/>
|
||||
{#if dir.negative_prompt}
|
||||
<PromptBlock label={t('workbench.style.negativeLabel')} text={dir.negative_prompt} />
|
||||
<PromptBlock
|
||||
label={t('workbench.style.negativeLabel')}
|
||||
text={dir.negative_prompt}
|
||||
/>
|
||||
{/if}
|
||||
</label>
|
||||
{/each}
|
||||
@@ -159,11 +195,21 @@
|
||||
<span class="hint">{t('workbench.style.chooseHint')}</span>
|
||||
<div class="foot-btns">
|
||||
{#if stage.status !== 'running'}
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={startEdit}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={startEdit}
|
||||
>
|
||||
<Icon name="edit" size={13} />
|
||||
{t('workbench.editDraft')}
|
||||
</button>
|
||||
<button type="button" class="a-btn ghost" disabled={busy} onclick={() => onRun?.()}>
|
||||
<button
|
||||
type="button"
|
||||
class="a-btn ghost"
|
||||
disabled={busy}
|
||||
onclick={() => onRun?.()}
|
||||
>
|
||||
<Icon name="retry" size={13} />
|
||||
{t('workbench.regenerate')}
|
||||
</button>
|
||||
@@ -301,10 +347,6 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.a-input.mono {
|
||||
font-family: var(--font-a-mono);
|
||||
font-size: 11.5px;
|
||||
}
|
||||
.a-input.name {
|
||||
font-weight: 600;
|
||||
}
|
||||
@@ -330,5 +372,4 @@
|
||||
background: var(--error-dim);
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import "$lib/components/prompt-tools/prompt-tools.css";
|
||||
import "./app.css";
|
||||
import { initTheme } from "$lib/theme";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
@@ -1222,3 +1222,38 @@ select:focus-visible {
|
||||
opacity: 1;
|
||||
inset: var(--viewfinder-selected-inset);
|
||||
}
|
||||
|
||||
/* HEL-837 v2 approved geometry; theme colours remain the established tokens. */
|
||||
:root {
|
||||
--studio-side: 320px;
|
||||
--lib-filter: 220px;
|
||||
--lib-detail: 360px;
|
||||
--lib-tile-min: 176px;
|
||||
--lib-tile-ratio: 4/3;
|
||||
--selbar-h: 52px;
|
||||
--mdl-detail: 400px;
|
||||
--mdl-list-row: 60px;
|
||||
--ptband-max-h: min(26vh, 210px);
|
||||
}
|
||||
@media (max-width: 1366px) {
|
||||
:root {
|
||||
--studio-side: 296px;
|
||||
--lib-filter: 200px;
|
||||
--lib-detail: 300px;
|
||||
--lib-tile-min: 160px;
|
||||
--mdl-detail: 360px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 1280px) {
|
||||
:root {
|
||||
--studio-side: 280px;
|
||||
--lib-filter: 184px;
|
||||
--lib-detail: 288px;
|
||||
--lib-tile-min: 140px;
|
||||
}
|
||||
}
|
||||
@media (max-height: 780px) {
|
||||
:root {
|
||||
--ptband-max-h: min(24vh, 172px);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user