Skip to content

Commit dc0b57c

Browse files
committed
refactor: replace text-specific update command with generic
1 parent a218a52 commit dc0b57c

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

apps/web/src/components/editor/panels/properties/text-properties.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function TextProperties({
5959
const fontSize = Number.isNaN(parsed)
6060
? element.fontSize
6161
: clamp({ value: parsed, min: MIN_FONT_SIZE, max: MAX_FONT_SIZE });
62-
editor.timeline.updateTextElement({
62+
editor.timeline.updateElement({
6363
trackId,
6464
elementId: element.id,
6565
updates: { fontSize },
@@ -73,7 +73,7 @@ export function TextProperties({
7373
? element.fontSize
7474
: clamp({ value: parsed, min: MIN_FONT_SIZE, max: MAX_FONT_SIZE });
7575
setFontSizeInput(fontSize.toString());
76-
editor.timeline.updateTextElement({
76+
editor.timeline.updateElement({
7777
trackId,
7878
elementId: element.id,
7979
updates: { fontSize },
@@ -88,7 +88,7 @@ export function TextProperties({
8888
const opacityPercent = Number.isNaN(parsed)
8989
? Math.round(element.opacity * 100)
9090
: clamp({ value: parsed, min: 0, max: 100 });
91-
editor.timeline.updateTextElement({
91+
editor.timeline.updateElement({
9292
trackId,
9393
elementId: element.id,
9494
updates: { opacity: opacityPercent / 100 },
@@ -102,7 +102,7 @@ export function TextProperties({
102102
? Math.round(element.opacity * 100)
103103
: clamp({ value: parsed, min: 0, max: 100 });
104104
setOpacityInput(opacityPercent.toString());
105-
editor.timeline.updateTextElement({
105+
editor.timeline.updateElement({
106106
trackId,
107107
elementId: element.id,
108108
updates: { opacity: opacityPercent / 100 },
@@ -113,7 +113,7 @@ export function TextProperties({
113113
if (color !== "transparent") {
114114
lastSelectedColor.current = color;
115115
}
116-
editor.timeline.updateTextElement({
116+
editor.timeline.updateElement({
117117
trackId,
118118
elementId: element.id,
119119
updates: { backgroundColor: color },
@@ -126,7 +126,7 @@ export function TextProperties({
126126
isTransparent: boolean;
127127
}) => {
128128
const newColor = isTransparent ? "transparent" : lastSelectedColor.current;
129-
editor.timeline.updateTextElement({
129+
editor.timeline.updateElement({
130130
trackId,
131131
elementId: element.id,
132132
updates: { backgroundColor: newColor },
@@ -154,7 +154,7 @@ export function TextProperties({
154154
defaultValue={element.content}
155155
className="bg-panel-accent min-h-20"
156156
onChange={(e) =>
157-
editor.timeline.updateTextElement({
157+
editor.timeline.updateElement({
158158
trackId,
159159
elementId: element.id,
160160
updates: { content: e.target.value },
@@ -167,7 +167,7 @@ export function TextProperties({
167167
<FontPicker
168168
defaultValue={element.fontFamily}
169169
onValueChange={(value: FontFamily) =>
170-
editor.timeline.updateTextElement({
170+
editor.timeline.updateElement({
171171
trackId,
172172
elementId: element.id,
173173
updates: { fontFamily: value },
@@ -186,7 +186,7 @@ export function TextProperties({
186186
}
187187
size="sm"
188188
onClick={() =>
189-
editor.timeline.updateTextElement({
189+
editor.timeline.updateElement({
190190
trackId,
191191
elementId: element.id,
192192
updates: {
@@ -205,7 +205,7 @@ export function TextProperties({
205205
}
206206
size="sm"
207207
onClick={() =>
208-
editor.timeline.updateTextElement({
208+
editor.timeline.updateElement({
209209
trackId,
210210
elementId: element.id,
211211
updates: {
@@ -228,7 +228,7 @@ export function TextProperties({
228228
}
229229
size="sm"
230230
onClick={() =>
231-
editor.timeline.updateTextElement({
231+
editor.timeline.updateElement({
232232
trackId,
233233
elementId: element.id,
234234
updates: {
@@ -251,7 +251,7 @@ export function TextProperties({
251251
}
252252
size="sm"
253253
onClick={() =>
254-
editor.timeline.updateTextElement({
254+
editor.timeline.updateElement({
255255
trackId,
256256
elementId: element.id,
257257
updates: {
@@ -279,7 +279,7 @@ export function TextProperties({
279279
max={MAX_FONT_SIZE}
280280
step={1}
281281
onValueChange={([value]) => {
282-
editor.timeline.updateTextElement({
282+
editor.timeline.updateElement({
283283
trackId,
284284
elementId: element.id,
285285
updates: { fontSize: value },
@@ -310,7 +310,7 @@ export function TextProperties({
310310
string: (element.color || "FFFFFF").replace("#", ""),
311311
})}
312312
onChange={(color) => {
313-
editor.timeline.updateTextElement({
313+
editor.timeline.updateElement({
314314
trackId,
315315
elementId: element.id,
316316
updates: { color: `#${color}` },
@@ -330,7 +330,7 @@ export function TextProperties({
330330
max={100}
331331
step={1}
332332
onValueChange={([value]) => {
333-
editor.timeline.updateTextElement({
333+
editor.timeline.updateElement({
334334
trackId,
335335
elementId: element.id,
336336
updates: { opacity: value / 100 },

apps/web/src/core/managers/timeline-manager.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { EditorCore } from "@/core";
22
import type {
33
TrackType,
44
TimelineTrack,
5-
TextElement,
65
TimelineElement,
76
ClipboardItem,
87
} from "@/types/timeline";
@@ -19,7 +18,7 @@ import {
1918
DuplicateElementsCommand,
2019
ToggleElementsVisibilityCommand,
2120
ToggleElementsMutedCommand,
22-
UpdateTextElementCommand,
21+
UpdateElementCommand,
2322
SplitElementsCommand,
2423
PasteCommand,
2524
UpdateElementStartTimeCommand,
@@ -199,31 +198,16 @@ export class TimelineManager {
199198
this.editor.command.execute({ command });
200199
}
201200

202-
updateTextElement({
201+
updateElement({
203202
trackId,
204203
elementId,
205204
updates,
206205
}: {
207206
trackId: string;
208207
elementId: string;
209-
updates: Partial<
210-
Pick<
211-
TextElement,
212-
| "content"
213-
| "fontSize"
214-
| "fontFamily"
215-
| "color"
216-
| "backgroundColor"
217-
| "textAlign"
218-
| "fontWeight"
219-
| "fontStyle"
220-
| "textDecoration"
221-
| "transform"
222-
| "opacity"
223-
>
224-
>;
208+
updates: Partial<Record<string, unknown>>;
225209
}): void {
226-
const command = new UpdateTextElementCommand(trackId, elementId, updates);
210+
const command = new UpdateElementCommand(trackId, elementId, updates);
227211
this.editor.command.execute({ command });
228212
}
229213

apps/web/src/lib/commands/timeline/element/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { UpdateElementTrimCommand } from "./update-element-trim";
55
export { UpdateElementDurationCommand } from "./update-element-duration";
66
export { UpdateElementStartTimeCommand } from "./update-element-start-time";
77
export { SplitElementsCommand } from "./split-elements";
8-
export { UpdateTextElementCommand } from "./update-text-element";
8+
export { UpdateElementCommand } from "./update-element";
99
export { ToggleElementsVisibilityCommand } from "./toggle-elements-visibility";
1010
export { ToggleElementsMutedCommand } from "./toggle-elements-muted";
1111
export { MoveElementCommand } from "./move-elements";

apps/web/src/lib/commands/timeline/element/update-text-element.ts renamed to apps/web/src/lib/commands/timeline/element/update-element.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
import { Command } from "@/lib/commands/base-command";
2-
import type { TextElement, TimelineTrack } from "@/types/timeline";
2+
import type { TimelineTrack } from "@/types/timeline";
33
import { EditorCore } from "@/core";
44

5-
export class UpdateTextElementCommand extends Command {
5+
export class UpdateElementCommand extends Command {
66
private savedState: TimelineTrack[] | null = null;
77

88
constructor(
99
private trackId: string,
1010
private elementId: string,
11-
private updates: Partial<
12-
Pick<
13-
TextElement,
14-
| "content"
15-
| "fontSize"
16-
| "fontFamily"
17-
| "color"
18-
| "backgroundColor"
19-
| "textAlign"
20-
| "fontWeight"
21-
| "fontStyle"
22-
| "textDecoration"
23-
>
24-
>,
11+
private updates: Partial<Record<string, unknown>>,
2512
) {
2613
super();
2714
}
@@ -33,9 +20,7 @@ export class UpdateTextElementCommand extends Command {
3320
const updatedTracks = this.savedState.map((t) => {
3421
if (t.id !== this.trackId) return t;
3522
const newElements = t.elements.map((el) =>
36-
el.id === this.elementId && el.type === "text"
37-
? { ...el, ...this.updates }
38-
: el,
23+
el.id === this.elementId ? { ...el, ...this.updates } : el,
3924
);
4025
return { ...t, elements: newElements } as typeof t;
4126
});

0 commit comments

Comments
 (0)