-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-1884 Add 'convert to' node option to right click menu for tldraw shape to allow user to convert shape to node (Roam) #1431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: eng-1356-implement-image-to-node-conversion-flow-via-icon-button-in
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ import { | |
| TLImageShape, | ||
| TLShape, | ||
| TLShapeId, | ||
| TLTextShape, | ||
| TLUiDialogProps, | ||
| TLUiOverrides, | ||
| TLUiTranslationKey, | ||
|
|
@@ -57,6 +56,7 @@ import { | |
| import { | ||
| replaceShapeWithDiscourseNode, | ||
| uploadImageShapeToRoam, | ||
| getConvertibleShapeText, | ||
| } from "./convertShapeToDiscourseNode"; | ||
| import { AddReferencedNodeType } from "./DiscourseRelationShape/DiscourseRelationTool"; | ||
| import { | ||
|
|
@@ -201,6 +201,9 @@ export const getOnSelectForShape = ({ | |
| }); | ||
| }; | ||
|
|
||
| const shapeText = getConvertibleShapeText(shape); | ||
| if (shapeText === null) return () => {}; | ||
|
|
||
| if (shape.type === "image") { | ||
| return async () => { | ||
| const src = await uploadImageShapeToRoam({ | ||
|
|
@@ -212,13 +215,8 @@ export const getOnSelectForShape = ({ | |
|
|
||
| openDialogAndCreateShape({ initialText, imageUrl: src }); | ||
| }; | ||
| } else if (shape.type === "text") { | ||
| return () => { | ||
| const { text } = (shape as TLTextShape).props; | ||
| openDialogAndCreateShape({ initialText: text }); | ||
| }; | ||
| } | ||
| return () => {}; | ||
| return () => openDialogAndCreateShape({ initialText: shapeText }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When one of the newly supported geo or note shapes is inside a frame or group, this route eventually calls Useful? React with 👍 / 👎. |
||
| }; | ||
|
|
||
| type ArrowBoundNodeInfo = { | ||
|
|
@@ -407,7 +405,7 @@ export const CustomContextMenu = ({ | |
| const shareableResults = getShareableCanvasSelectionResults({ | ||
| shapes: selectedShapes, | ||
| }); | ||
| const isTextSelected = selectedShape?.type === "text"; | ||
| const convertibleText = getConvertibleShapeText(selectedShape); | ||
| const isImageSelected = selectedShape?.type === "image"; | ||
| const arrowRelationOptions = useValue( | ||
| "arrowRelationOptions", | ||
|
|
@@ -454,7 +452,7 @@ export const CustomContextMenu = ({ | |
| /> | ||
| </TldrawUiMenuGroup> | ||
| )} | ||
| {(isTextSelected || isImageSelected) && ( | ||
| {selectedShape && convertibleText !== null && ( | ||
| <TldrawUiMenuGroup id="convert-to-group"> | ||
| <TldrawUiMenuSubmenu id="convert-to-submenu" label="Convert To"> | ||
| {allNodes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a text, note, or geo shape begins or ends with whitespace—for example, an intentionally indented multiline snippet—this trimmed value is passed to the node dialog, so conversion silently changes the shape's content and existing text shapes no longer behave as before. Use the trimmed value only to decide whether a note or geo shape is empty, while returning the original
shape.props.text.Useful? React with 👍 / 👎.