Skip to content

Commit

Permalink
fix(whiteboard): some context menu related issues on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored and tiensonqin committed Nov 14, 2022
1 parent 1d83f00 commit dd0e741
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ export const ContextMenu = observer(function ContextMenu({
}, [])

return (
<ReactContextMenu.Root>
<ReactContextMenu.Root
onOpenChange={open => {
if (open && !app.isIn('select.contextMenu')) {
app.transition('select').selectedTool.transition('contextMenu')
} else if (!open && app.isIn('select.contextMenu')) {
app.selectedTool.transition('idle')
}
}}
>
<ReactContextMenu.Trigger>{children}</ReactContextMenu.Trigger>
<ReactContextMenu.Content
className="tl-menu tl-context-menu"
Expand Down
2 changes: 1 addition & 1 deletion tldraw/apps/tldraw-logseq/src/hooks/usePaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export function usePaste() {
}

function tryCreateClonedShapesFromJSON(rawText: string) {
const result = app.api.getClonedShapesFromTldrString(rawText, point)
const result = app.api.getClonedShapesFromTldrString(decodeURIComponent(rawText), point)
if (result) {
const { shapes, assets, bindings } = result
assetsToClone.push(...assets)
Expand Down
2 changes: 1 addition & 1 deletion tldraw/packages/core/src/lib/TLApi/TLApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
const getWhiteboardsTldrFromText = (text: string) => {
const innerText = text.match(/<whiteboard-tldr>(.*)<\/whiteboard-tldr>/)?.[1]
if (innerText) {
return safeParseJson(decodeURIComponent(innerText))
return safeParseJson(innerText)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tldraw/packages/core/src/lib/TLApp/TLApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export class TLApp<
// convey the bindings to maintain the new links after pasting
bindings: toJS(this.currentPage.bindings),
})
const tldrawString = `<whiteboard-tldr>${encodeURIComponent(jsonString)}</whiteboard-tldr>`
const tldrawString = encodeURIComponent(`<whiteboard-tldr>${jsonString}</whiteboard-tldr>`)
// FIXME: use `writeClipboard` in frontend.utils
navigator.clipboard.write([
new ClipboardItem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class IdleState<
} = this.app

if (event.button === 2) {
this.tool.transition('contextMenu', info)
// relies on @radix-ui/react-context-menu Root's onOpenChange now
// this.tool.transition('contextMenu', info)
return
}

Expand Down

0 comments on commit dd0e741

Please sign in to comment.