Skip to content

Commit 5a971a6

Browse files
committed
fix: handle both reactive and plain width objects in note geometry calculations - add (model.width as any)?.value ?? model.width fallback pattern across DisplayArrow, DisplayNote, clipboard, note-geometry, useArrowDrag, and useCanvasActions to support both reactive Ref<Width> and plain Width objects when accessing expanded property
1 parent 8f10f84 commit 5a971a6

6 files changed

Lines changed: 17 additions & 12 deletions

File tree

new-deepnotes/apps/web/src/features/spatial/DisplayArrow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ const geometry = computed(() => {
4646
// Need at least one real endpoint or a fakePos to render
4747
if (!s && !t && !fake) return null;
4848
49-
const w1 = s?.width.value.expanded;
49+
const w1 = s ? ((s.width as any)?.value ?? s.width)?.expanded : undefined;
5050
const nw1 = w1 === "Auto" ? 160 : w1 ? parseFloat(w1) : 0;
5151
const h1 = s ? (noteHeights.value.get(props.model.source.value) ?? 80) : 0;
5252
53-
const w2 = t?.width.value.expanded;
53+
const w2 = t ? ((t.width as any)?.value ?? t.width)?.expanded : undefined;
5454
const nw2 = w2 === "Auto" ? 160 : w2 ? parseFloat(w2) : 0;
5555
const h2 = t ? (noteHeights.value.get(props.model.target.value) ?? 80) : 0;
5656

new-deepnotes/apps/web/src/features/spatial/DisplayNote.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ const transform = computed(() => {
7979
style.transform = `translate(${pos.x}px, ${pos.y}px)`;
8080
style.zIndex = props.model.zIndex.value;
8181
}
82-
style.width = props.model.width.value.expanded === "Auto" ? "auto" : `${props.model.width.value.expanded}px`;
82+
const widthVal = (props.model.width as any)?.value ?? props.model.width;
83+
style.width = widthVal?.expanded === "Auto" ? "auto" : `${widthVal?.expanded}px`;
8384
const cv = colorVariants.value;
8485
if (cv) {
8586
style.borderColor = cv.base;
@@ -198,8 +199,9 @@ function onResizePointerDown(e: PointerEvent, handle: ResizeHandle) {
198199
resizeHandle = handle;
199200
resizeStartX = e.clientX;
200201
resizeStartY = e.clientY;
201-
const w = props.model.width.value.expanded;
202-
resizeStartWidth = w === "Auto" ? 160 : parseFloat(w);
202+
const widthVal = (props.model.width as any)?.value ?? props.model.width;
203+
const w = widthVal?.expanded;
204+
resizeStartWidth = w === "Auto" ? 160 : parseFloat(w ?? "160");
203205
resizeStartPosX = props.model.pos.value.x;
204206
isDragging.value = true;
205207
const el = e.currentTarget as HTMLElement;

new-deepnotes/apps/web/src/features/spatial/clipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function serializeNote(model: NoteModel, id: string): ClipboardNote {
134134
return {
135135
id,
136136
pos: model.pos.value,
137-
width: model.width.value,
137+
width: ((model.width as any)?.value ?? model.width) ?? { expanded: "Auto", collapsed: "Auto" },
138138
head: {
139139
enabled: model.head.enabled.value,
140140
wrap: model.head.wrap.value,

new-deepnotes/apps/web/src/features/spatial/note-geometry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ export function getNoteRect(
5252
if (!entry) return null;
5353
const pos = getNoteEffectiveWorldPos(noteId, noteList, parentOf, originOffsets);
5454
if (!pos) return null;
55-
const wStr = entry.model.width.value.expanded;
56-
const w = wStr === "Auto" ? 160 : parseFloat(wStr);
55+
const widthVal = (entry.model.width as any)?.value ?? entry.model.width;
56+
const wStr = widthVal?.expanded;
57+
const w = wStr === "Auto" ? 160 : parseFloat(wStr ?? "160");
5758
const h = heights?.get(noteId) ?? 80;
5859
return { x: pos.x, y: pos.y, width: w, height: h };
5960
}

new-deepnotes/apps/web/src/features/spatial/useArrowDrag.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export function useArrowDrag(input: UseArrowDragInput) {
3939
const camX = input.canvasRef.value.camX;
4040
const camY = input.canvasRef.value.camY;
4141

42-
const wStr = sourceNote.model.width.value.expanded;
43-
const w = wStr === "Auto" ? 160 : parseFloat(wStr);
42+
const widthVal = (sourceNote.model.width as any)?.value ?? sourceNote.model.width;
43+
const wStr = widthVal?.expanded;
44+
const w = wStr === "Auto" ? 160 : parseFloat(wStr ?? "160");
4445
const h = noteHeights.value.get(sourceNote.id) ?? 80;
4546
const sourceScreen = worldToScreen(
4647
sourceNote.model.pos.value.x + w / 2,

new-deepnotes/apps/web/src/features/spatial/useCanvasActions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ export function useCanvasActions(input: UseCanvasActionsInput) {
6767
let maxY = -Infinity;
6868

6969
for (const note of notesToFit) {
70-
const wStr = note.model.width.value.expanded;
71-
const w = wStr === "Auto" ? 160 : parseFloat(wStr);
70+
const widthVal = (note.model.width as any)?.value ?? note.model.width;
71+
const wStr = widthVal?.expanded;
72+
const w = wStr === "Auto" ? 160 : parseFloat(wStr ?? "160");
7273
const h = noteHeights.value.get(note.id) ?? 80;
7374
const x = note.model.pos.value.x;
7475
const y = note.model.pos.value.y;

0 commit comments

Comments
 (0)