Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/timeline/interaction/interaction-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ export class InteractionController implements TimelineInteractionRegistration {
clipElement.style.height = `${clipRect.height}px`;
clipElement.style.zIndex = "18";
clipElement.style.pointerEvents = "none";
// A finger held still shows nothing else to say the clip was lifted
if (this.liftPoint) clipElement.classList.add("ss-clip--lifted");

// Create ghost as drop preview (shows where clip will land)
const pps = this.stateManager.getViewport().pixelsPerSecond;
Expand Down Expand Up @@ -645,6 +647,7 @@ export class InteractionController implements TimelineInteractionRegistration {
}

private setIdle(): void {
if (this.liftPoint && this.state.type === "dragging") this.state.clipElement.classList.remove("ss-clip--lifted");
this.state = IDLE_STATE;
this.activePointerId = -1;
this.activePointerType = "";
Expand Down
16 changes: 16 additions & 0 deletions src/styles/timeline/timeline.css
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,22 @@
.ss-clip.selected .ss-clip-content {
padding-right: calc(var(--ss-touch-edge) + 24px);
}

/* Same specificity as .selected and .dragging, so it must stay after them to win */
.ss-clip.ss-clip--lifted {
transform: scale(1.04);
outline: 2px solid var(--clip-border, #3b82f6);
box-shadow:
0 10px 24px rgba(0, 0, 0, 0.28),
0 2px 6px rgba(0, 0, 0, 0.2);
transition: transform 0.15s ease-out;
}
}

@media (pointer: coarse) and (prefers-reduced-motion: reduce) {
.ss-clip.ss-clip--lifted {
transition: none;
}
}

/* Playhead */
Expand Down
61 changes: 61 additions & 0 deletions tests/interaction-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,67 @@ describe("InteractionController", () => {
jest.advanceTimersByTime(500);
expect(controller.isDragging(0, 0)).toBe(false);
});

describe("lifted look", () => {
const raised = (clip: Element) => clip.classList.contains("ss-clip--lifted");
const lift = () => {
touch("pointerdown", 50, { target: firstClip() });
jest.advanceTimersByTime(450);
};

it("raises the clip at 450 ms of a still touch, not at 449", () => {
touch("pointerdown", 50, { target: firstClip() });
jest.advanceTimersByTime(449);
expect(raised(firstClip())).toBe(false);

jest.advanceTimersByTime(1);
expect(raised(firstClip())).toBe(true);
});

it.each([
["a release", () => touch("pointerup", 50)],
["pointercancel", () => touch("pointercancel", 50)],
["a second pointer", () => touch("pointerdown", 300, { target: mockDOM.tracksContainer, pointerId: 2 })],
["dispose", () => controller.dispose()]
])("lowers it on %s", (_, end) => {
lift();
end();
expect(raised(firstClip())).toBe(false);
});

it("keeps it raised while dragged and lowers it when the drag commits", () => {
// Alone on its track, so the drag lands as a move
mockStateManager.setTestTracks([createMockTrack(0, [{ start: 0, length: 2 }])] as MockTrack[]);
lift();
touch("pointermove", 150);
expect(raised(firstClip())).toBe(true);

touch("pointerup", 150);
expect(mockEdit.executeEditCommand).toHaveBeenCalled();
expect(raised(firstClip())).toBe(false);
});

it("lowers the element it raised after a re-render hands its place to another clip", () => {
lift();
const [lifted, neighbour] = mockDOM.tracksContainer.querySelectorAll<HTMLElement>(".ss-clip");
lifted.dataset["clipIndex"] = "1";
neighbour.dataset["clipIndex"] = "0";
touch("pointerup", 50);

expect([lifted, neighbour].filter(raised)).toEqual([]);
});

it.each(["mouse", "pen"])("never raises a clip for a %s, held 600 ms or dragged", pointerType => {
firstClip().classList.add("selected");
firstClip().dispatchEvent(createPointerEvent("pointerdown", { clientX: 50, clientY: 20, pointerType }));
jest.advanceTimersByTime(600);
expect(raised(firstClip())).toBe(false);

document.dispatchEvent(createPointerEvent("pointermove", { clientX: 100, clientY: 20, pointerType }));
expect(controller.isDragging(0, 0)).toBe(true);
expect(raised(firstClip())).toBe(false);
});
});
});
});

Expand Down
24 changes: 24 additions & 0 deletions tests/touch-hit-areas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,27 @@ describe("touch hit areas", () => {
expect(declared(primaryCoarse, ".ss-clip-menu-trigger")["right"]).toBe("var(--ss-touch-edge)");
});
});

describe("lifted clip look", () => {
const lifted = (rules: Rule[]) => rules.filter(rule => rule.selector.includes("ss-clip--lifted"));

it("styles a lifted clip only where the primary pointer is coarse", () => {
expect(lifted(primaryCoarse).length).toBeGreaterThan(0);
expect(lifted(rulesIn([styles]))).toEqual(lifted(primaryCoarse));
});

it("animates only its scale, and not for reduced motion", () => {
const reduced = lifted(rulesIn(mediaBlocks(styles, "@media (pointer: coarse) and (prefers-reduced-motion: reduce)")));

expect(lifted(primaryCoarse)[0].declarations["transition"]).toMatch(/^transform [^,]+$/);
expect(reduced.map(rule => rule.declarations["transition"])).toEqual(["none"]);
});

it("comes after the selected and dragging rules, which share its specificity", () => {
const order = rulesIn([styles]).map(rule => rule.selector);

expect(order.indexOf(".ss-clip.ss-clip--lifted")).toBeGreaterThan(
Math.max(order.lastIndexOf(".ss-clip.selected"), order.lastIndexOf(".ss-clip.dragging"))
);
});
});
Loading