mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
* feat(studio): edit and style text in the preview Double-press a text element in the canvas and the caret opens where you pressed, in the element itself rather than in a panel. Select characters and a small toolbar offers colour, bold, italic and underline, applied to exactly those characters. The toolbar lives in Studio's document rather than the composition's. Putting it in the preview would inject Studio's chrome into the user's composition, where a render would capture it and the composition's own styling would inherit into it. In a flex or grid container the rebuilt runs go inside one wrapper, so a coloured word cannot reflow the element it sits in. Also fixes the keyboard: the shortcut guards matched contenteditable=true only, so playback shortcuts ate letters typed into the composition. * refactor(studio): keep domEditingLayers under the size cap The rich-text operation pushed this file past the 600-line gate. Same change the branch made later, landed with the commit that caused it. * test(studio): wrap selection changes in act * fix(studio): restore rich text after failed save * fix(studio): polish inline text editing * fix(studio): harden inline text editing
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { isTypingTarget } from "./typingTarget";
|
|
import { isEditableTarget } from "./timelineDiscovery";
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
function mount(html: string): HTMLElement {
|
|
document.body.innerHTML = html;
|
|
return document.body.firstElementChild as HTMLElement;
|
|
}
|
|
|
|
describe("isTypingTarget", () => {
|
|
it("keeps the legacy import on the same canonical decision", () => {
|
|
expect(isEditableTarget).toBe(isTypingTarget);
|
|
});
|
|
|
|
// The bug this exists for: inline text editing uses plaintext-only, an
|
|
// attribute selector for 'true' missed it, and the playback shortcuts ate
|
|
// every letter typed into the composition.
|
|
it("recognises a plaintext-only editable, not just contenteditable=true", () => {
|
|
expect(isTypingTarget(mount('<h1 contenteditable="plaintext-only">Hi</h1>'))).toBe(true);
|
|
expect(isTypingTarget(mount('<h1 contenteditable="true">Hi</h1>'))).toBe(true);
|
|
expect(isTypingTarget(mount("<h1 contenteditable>Hi</h1>"))).toBe(true);
|
|
});
|
|
|
|
it("recognises a child of an editable, which a selector on the target alone misses", () => {
|
|
const host = mount('<div contenteditable="true"><span>inner</span></div>');
|
|
expect(isTypingTarget(host.querySelector("span"))).toBe(true);
|
|
});
|
|
|
|
it("recognises the ordinary fields too", () => {
|
|
expect(isTypingTarget(mount("<input />"))).toBe(true);
|
|
expect(isTypingTarget(mount("<textarea></textarea>"))).toBe(true);
|
|
expect(isTypingTarget(mount("<select></select>"))).toBe(true);
|
|
expect(isTypingTarget(mount('<div role="textbox"></div>'))).toBe(true);
|
|
expect(isTypingTarget(mount('<div role="searchbox"></div>'))).toBe(true);
|
|
expect(isTypingTarget(mount('<div role="combobox"></div>'))).toBe(true);
|
|
});
|
|
|
|
it("leaves the keys alone for anything that is not being typed into", () => {
|
|
expect(isTypingTarget(mount("<div>plain</div>"))).toBe(false);
|
|
expect(isTypingTarget(mount("<button>press</button>"))).toBe(false);
|
|
expect(isTypingTarget(mount('<h1 contenteditable="false">Hi</h1>'))).toBe(false);
|
|
});
|
|
|
|
it("says no to nothing at all", () => {
|
|
expect(isTypingTarget(null)).toBe(false);
|
|
expect(isTypingTarget({} as EventTarget)).toBe(false);
|
|
});
|
|
});
|