Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Enable expanded editing for long-video part descriptions

Bowen Xue42510d22d075
diff --git a/web/editor_expand.css b/web/editor_expand.css
index d0de662..df42cb7 100644
--- a/web/editor_expand.css
+++ b/web/editor_expand.css
@@ -1,6 +1,6 @@
.fv-ed-description-box{position:relative;display:flex;flex:1;min-width:0}
.fv-ed-description-box .fv-ed-description{width:100%;min-height:36px;max-height:108px;line-height:18px;padding:8px 36px 8px 10px;border-radius:var(--fv-r-sm);resize:none;overflow-y:hidden}
-.fv-ed-expand,.fv-editor .fv-ed-expand{position:absolute;right:4px;bottom:4px;width:26px;height:26px;padding:4px;min-height:0;border:0;background:var(--fv-bg);color:var(--fv-muted)}
+.fv-ed-expand,.fv-editor .fv-ed-expand,.fv-studio .fv-ed-expand{position:absolute;right:4px;bottom:4px;width:26px;height:26px;padding:4px;min-height:0;border:0;background:var(--fv-bg);color:var(--fv-muted)}
.fv-ed-expand svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round}
.fv-ed-expand-dialog{box-sizing:border-box;position:fixed;inset:0;margin:auto;width:60vw;height:70dvh;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);padding:20px;border:1px solid var(--fv-border);border-radius:var(--fv-r-lg);background:var(--fv-card);color:var(--fv-ink)}
.fv-ed-expand-dialog[open]{display:flex;flex-direction:column;gap:16px}
diff --git a/web/editor_expand.js b/web/editor_expand.js
index 2442a30..73a20d5 100644
--- a/web/editor_expand.js
+++ b/web/editor_expand.js
@@ -35,10 +35,10 @@ export function createExpandButton({t = en => en, textarea, onGenerate, canGener
if (!dialog) return;
// The small box changed from outside (another part selected, text restored): the dialog follows.
if (textarea.value !== seen) { seen = textarea.value; large.value = seen; }
- large.disabled = !writable(); generate.disabled = !allowed();
+ large.disabled = !writable(); if (generate) generate.disabled = !allowed();
}
async function submit() {
- if (!allowed()) return;
+ if (!onGenerate || !allowed()) return;
commit(); notice.textContent = '';
pending = true; sync();
let reason = '';
@@ -83,6 +83,7 @@ export function createExpandButton({t = en => en, textarea, onGenerate, canGener
dialog.setAttribute('aria-label', t('Expand', '放大'));
seen = textarea.value;
large = el('textarea', 'fv-ed-expand-text'); large.value = seen;
+ if (textarea.maxLength >= 0) large.maxLength = textarea.maxLength;
large.setAttribute('aria-label', textarea.getAttribute('aria-label') || t('Expand', '放大'));
notice = el('div', 'fv-ed-expand-note'); notice.setAttribute('role', 'status');
large.oninput = () => {
@@ -92,9 +93,10 @@ export function createExpandButton({t = en => en, textarea, onGenerate, canGener
sync();
};
const buttons = el('div', 'fv-ed-expand-buttons');
- generate = el('button', 'fv-primary', t('Generate', '生成')); generate.type = 'button'; generate.onclick = submit;
+ // Without a way to generate (a single part cannot be generated alone) only Close is offered.
+ if (onGenerate) { generate = el('button', 'fv-primary', t('Generate', '生成')); generate.type = 'button'; generate.onclick = submit; }
const dismiss = el('button', '', t('Close', '关闭')); dismiss.type = 'button'; dismiss.onclick = close;
- buttons.append(generate, dismiss); dialog.append(large, notice, buttons);
+ if (generate) buttons.append(generate); buttons.append(dismiss); dialog.append(large, notice, buttons);
cleanups.push(listenDialogKey(dialog, 'keydown', event => {
if (event.isComposing || event.keyCode === 229) return;
if (event.key === 'Escape') { event.preventDefault(); close(); }
@@ -102,7 +104,7 @@ export function createExpandButton({t = en => en, textarea, onGenerate, canGener
event.preventDefault(); if (!event.repeat) submit();
} else if (event.key === 'Tab') {
event.preventDefault();
- const controls = [large, generate, dismiss].filter(node => !node.disabled);
+ const controls = [large, generate, dismiss].filter(node => node && !node.disabled);
const index = controls.indexOf(document.activeElement);
controls[(index + (event.shiftKey ? -1 : 1) + controls.length) % controls.length]?.focus();
}
@@ -132,7 +134,7 @@ export function createExpandButton({t = en => en, textarea, onGenerate, canGener
const observer = typeof MutationObserver === 'function' ? new MutationObserver(sync) : null;
observer?.observe(textarea, {attributes: true, attributeFilter: ['disabled', 'readonly']});
sync();
- return {element, open, close, commit, dispose() {
+ return {element, open, close, commit, get isOpen() { return !!dialog; }, dispose() {
close(); disposed = true; observer?.disconnect();
textarea.removeEventListener('input', sync); textarea.removeEventListener('change', sync);
element.onclick = null; element.remove();
diff --git a/web/studio.css b/web/studio.css
index f25d467..54df01b 100644
--- a/web/studio.css
+++ b/web/studio.css
@@ -211,7 +211,8 @@
.fv-studio .fv-chain-part .fv-chain-part-text:disabled{opacity:1;color:var(--fv-disabled)}
.fv-studio .fv-chain-part:has(.fv-chain-part-text:disabled) :is(.fv-chain-part-name,.fv-chain-part-tag:not([data-kind=error])){color:var(--fv-disabled)}
.fv-studio .fv-chain-part-text[hidden]{display:none}
-.fv-studio .fv-chain-part .fv-chain-part-editor{min-height:76px;height:96px;max-height:220px;padding:6px 10px;font-size:var(--fv-micro);line-height:20px;outline:none}
+.fv-studio .fv-chain-part-edit{position:relative;min-width:0}
+.fv-studio .fv-chain-part .fv-chain-part-editor{min-height:76px;height:96px;max-height:220px;padding:6px 36px 6px 10px;font-size:var(--fv-micro);line-height:20px;outline:none}
.fv-studio .fv-chain-part-tag{padding:7px 8px 0 0;color:var(--fv-muted);white-space:nowrap}
.fv-studio .fv-chain-part-tag:empty{display:none}
.fv-studio .fv-chain-part-tag[data-kind=error]{color:var(--fv-warning);white-space:normal;max-width:16em;text-align:right}
diff --git a/web/studio.js b/web/studio.js
index ce44606..7937519 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -1,5 +1,6 @@
import { createErrorPanel, errorText, createErrorReport } from './error_panel.js';
import {topDialog} from './dialog_keys.js';
+import {createExpandButton} from './editor_expand.js';
import {cleanOptionalPrompt} from './optional_inputs.js';
import { app } from '../../scripts/app.js';
import { api } from '../../scripts/api.js';
@@ -73,12 +74,17 @@ function createChainPartList(t, save, {onShow = () => {}, onHide = () => {}} = {
const rows = new Map(), timers = new Map();
let editing = null, showing = null;
function tag(row, text, kind = '') { row.tag.textContent = text; row.tag.dataset.kind = kind; }
+ function removeEditor(row) {
+ row.expand?.dispose(); row.expand = null;
+ row.editBox?.remove(); row.editBox = row.editor = null; row.draft = null;
+ row.text.hidden = false;
+ }
function draw(row) {
const {part} = row, writing = editing === row;
row.element.dataset.state = part.editable ? 'pending' : part.state;
row.text.textContent = part.text;
row.text.disabled = !part.editable;
- if (!writing && row.editor) { row.editor.remove(); row.editor = null; row.text.hidden = false; }
+ if (!writing && row.editor) removeEditor(row);
// A note about a lost edit stays on its line until that part is done.
if (row.tag.dataset.kind === 'error' && part.state === 'done') row.tag.dataset.kind = '';
if (timers.has(part.id) || row.tag.dataset.kind === 'error') return;
@@ -90,6 +96,7 @@ function createChainPartList(t, save, {onShow = () => {}, onHide = () => {}} = {
}
async function finish(row, keep) {
if (editing !== row) return;
+ row.expand?.commit();
const before = row.part.text, value = row.editor.value;
editing = null;
if (!keep || !value.trim() || value === before) { draw(row); return; }
@@ -111,29 +118,45 @@ function createChainPartList(t, save, {onShow = () => {}, onHide = () => {}} = {
if (editing) finish(editing, true);
editing = row; clearTimeout(timers.get(row.part.id)); timers.delete(row.part.id); tag(row, '');
const editor = row.editor = el('textarea', null, 'fv-chain-part-editor');
- editor.maxLength = 20000; editor.value = row.part.text;
+ editor.maxLength = 20000; editor.value = row.draft = row.part.text;
editor.setAttribute('aria-label', t(`Part ${row.part.index + 1} description`, `第 ${row.part.index + 1} 段描述`));
- editor.addEventListener('blur', () => finish(row, true));
+ editor.addEventListener('input', () => { row.draft = editor.value; });
editor.addEventListener('keydown', event => {
// Escape leaves the edit, never the studio.
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); finish(row, false); row.text.focus(); }
});
- row.text.hidden = true; row.text.after(editor); editor.focus();
+ const box = row.editBox = el('div', null, 'fv-chain-part-edit');
+ row.expand = createExpandButton({t, textarea: editor, canGenerate: () => false,
+ // Like the main description, keep a live draft while preserving the small box's undo history.
+ onDraft: text => { row.draft = text; }});
+ box.append(editor, row.expand.element);
+ box.addEventListener('focusout', event => {
+ if (!row.expand?.isOpen && !box.contains(event.relatedTarget)) finish(row, true);
+ });
+ row.text.hidden = true; row.text.after(box); editor.focus();
editor.setSelectionRange(editor.value.length, editor.value.length);
editor.scrollIntoView({block: 'nearest'});
}
function clear() {
if (!element.hidden) onHide();
- element.hidden = true; element.replaceChildren(); rows.clear(); editing = null; showing = null;
+ editing = null;
+ for (const row of rows.values()) removeEditor(row);
+ element.hidden = true; element.replaceChildren(); rows.clear(); showing = null;
for (const id of timers.values()) clearTimeout(id); timers.clear();
}
return {element, clear, update(chain, active) {
// The list belongs to one generation: it shows once the descriptions are written and closes when that ends.
- if (!active || !chain?.split || chainSplit(chain).writing) { if (!active || showing !== chain?.id) clear(); return; }
+ if (!active || !chain?.split || chainSplit(chain).writing) { clear(); return; }
if (showing !== chain.id) clear();
showing = chain.id;
const first = element.hidden; element.hidden = false;
- chainParts(chain).forEach((part, index) => {
+ const parts = chainParts(chain), ids = new Set(parts.map(part => part.id));
+ for (const [id, row] of rows) if (!ids.has(id)) {
+ if (editing === row) editing = null;
+ removeEditor(row); row.element.remove(); rows.delete(id);
+ clearTimeout(timers.get(id)); timers.delete(id);
+ }
+ parts.forEach((part, index) => {
part.state = chain.blocks[index].state === 'pending' && chain.blocks[index].prompt_id != null ? 'queued' : chain.blocks[index].state;
let row = rows.get(part.id);
if (!row) {
@@ -145,7 +168,7 @@ function createChainPartList(t, save, {onShow = () => {}, onHide = () => {}} = {
}
if (editing === row && !part.editable) {
// The part began while it was open: the words typed so far cannot reach it.
- const changed = row.editor.value !== row.part.text;
+ const changed = row.draft !== row.part.text;
editing = null; row.part = part; draw(row);
if (changed) flash(row, t('This part is already generating. Your edit was not saved.', '这一段已在生成,改动没有保存'), 'error');
return;