Skip to content

Commit 3421e22

Browse files
authored
[ENG-1080 & ENG-1067] Change key figure behaviors and styles (#574)
* change key figure behaviors and styles * sm clean up
1 parent b1c69c3 commit 3421e22

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

apps/obsidian/src/components/canvas/shapes/DiscourseNodeShape.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const discourseNodeContent = memo(
308308
style={{
309309
backgroundColor: nodeType?.color ?? "",
310310
}}
311-
// NOTE: These Tailwind classes (p-2, border-2, rounded-md, m-1, text-base, m-0, text-sm)
311+
// NOTE: These Tailwind classes (p-2, border-2, rounded-md, m-1, text-base, m-0, text-sm)
312312
// correspond to constants in nodeConstants.ts. If you change these classes, update the
313313
// constants and the measureNodeText function to keep measurements accurate.
314314
className="relative box-border flex h-full w-full flex-col items-start justify-center rounded-md border-2 p-2"
@@ -348,8 +348,6 @@ const discourseNodeContent = memo(
348348
</svg>
349349
</button>
350350
)}
351-
<h1 className="m-0 text-base">{title || "..."}</h1>
352-
<p className="m-0 text-sm opacity-80">{nodeType?.name || ""}</p>
353351
{shape.props.imageSrc ? (
354352
<div className="mt-2 flex min-h-0 w-full flex-1 items-center justify-center overflow-hidden">
355353
<img
@@ -361,6 +359,8 @@ const discourseNodeContent = memo(
361359
/>
362360
</div>
363361
) : null}
362+
<h1 className="m-0 pt-4 text-base">{title || "..."}</h1>
363+
<p className="m-0 text-sm opacity-80">{nodeType?.name || ""}</p>
364364
</div>
365365
);
366366
},

apps/obsidian/src/components/canvas/utils/convertToDiscourseNode.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "~/components/canvas/stores/assetStore";
1919
import { showToast } from "./toastUtils";
2020
import { CreateNodeModal } from "~/components/CreateNodeModal";
21+
import { calcDiscourseNodeSize } from "~/utils/calcDiscourseNodeSize";
2122

2223
type ConvertToDiscourseNodeArgs = {
2324
editor: Editor;
@@ -140,8 +141,10 @@ const convertImageShapeToNode = async ({
140141
throw new Error("Failed to create discourse node file");
141142
}
142143

144+
let imageSrc: string | undefined;
143145
if (imageFile) {
144146
await embedImageInNode(createdFile, imageFile, plugin);
147+
imageSrc = plugin.app.vault.getResourcePath(imageFile);
145148
}
146149

147150
shapeId = await createDiscourseNodeShape({
@@ -151,6 +154,7 @@ const convertImageShapeToNode = async ({
151154
nodeType: selectedNodeType,
152155
plugin,
153156
canvasFile,
157+
imageSrc,
154158
});
155159

156160
showToast({
@@ -178,38 +182,44 @@ const createDiscourseNodeShape = async ({
178182
nodeType,
179183
plugin,
180184
canvasFile,
185+
imageSrc,
181186
}: {
182187
editor: Editor;
183188
shape: TLShape;
184189
createdFile: TFile;
185190
nodeType: DiscourseNode;
186191
plugin: DiscourseGraphPlugin;
187192
canvasFile: TFile;
193+
imageSrc?: string;
188194
}): Promise<TLShapeId> => {
189195
const src = await addWikilinkBlockrefForFile({
190196
app: plugin.app,
191197
canvasFile,
192198
linkedFile: createdFile,
193199
});
194200

195-
// Get the position and size of the original shape
196201
const { x, y } = shape;
197-
const width = "w" in shape.props ? Number(shape.props.w) : 200;
198-
const height = "h" in shape.props ? Number(shape.props.h) : 100;
202+
203+
const { w, h } = await calcDiscourseNodeSize({
204+
title: createdFile.basename,
205+
nodeTypeId: nodeType.id,
206+
imageSrc,
207+
plugin,
208+
});
199209

200210
const shapeId = createShapeId();
201-
// TODO: Update the imageSrc, width and height of the shape after the key figure is merged
202211
editor.createShape({
203212
id: shapeId,
204213
type: "discourse-node",
205214
x,
206215
y,
207216
props: {
208-
w: Math.max(width, 200),
209-
h: Math.max(height, 100),
217+
w,
218+
h,
210219
src: src ?? "",
211220
title: createdFile.basename,
212221
nodeTypeId: nodeType.id,
222+
imageSrc,
213223
},
214224
});
215225

0 commit comments

Comments
 (0)