Skip to content

Commit 0f12d9e

Browse files
authored
Selected cross-realm fixes (tldraw#6338)
A few small changes to make tldraw work in cross-realm based on suggestions by @derekcicerone Fixes tldraw#6337 and partially tldraw#5728 ### Change type - [x] `bugfix` ### Release notes - Fix a few code paths that didn't work for cross-realm situations.
1 parent 9fbe607 commit 0f12d9e

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/editor/src/lib/editor/Editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3662,7 +3662,7 @@ export class Editor extends EventEmitter<TLEventMap> {
36623662
* @public
36633663
*/
36643664
updateViewportScreenBounds(screenBounds: Box | HTMLElement, center = false): this {
3665-
if (screenBounds instanceof HTMLElement) {
3665+
if (!(screenBounds instanceof Box)) {
36663666
const rect = screenBounds.getBoundingClientRect()
36673667
screenBounds = new Box(
36683668
rect.left || rect.x,

packages/editor/src/lib/utils/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { debugFlags, pointerCaptureTrackingObject } from './debug-flags'
1818

1919
/** @public */
2020
export function loopToHtmlElement(elm: Element): HTMLElement {
21-
if (elm instanceof HTMLElement) return elm
21+
if (elm.nodeType === Node.ELEMENT_NODE) return elm as HTMLElement
2222
if (elm.parentElement) return loopToHtmlElement(elm.parentElement)
2323
else throw Error('Could not find a parent element of an HTML type!')
2424
}

packages/tldraw/src/lib/ui/hooks/useKeyboardShortcuts.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ export function useKeyboardShortcuts() {
3333
if (!isFocused) return
3434

3535
const disposables = new Array<() => void>()
36+
const container = editor.getContainer()
3637

3738
const hot = (keys: string, callback: (event: KeyboardEvent) => void) => {
38-
hotkeys(keys, { element: document.body }, callback)
39+
hotkeys(keys, { element: container.ownerDocument.body }, callback)
3940
disposables.push(() => {
4041
hotkeys.unbind(keys, callback)
4142
})
4243
}
4344

4445
const hotUp = (keys: string, callback: (event: KeyboardEvent) => void) => {
45-
hotkeys(keys, { element: document.body, keyup: true, keydown: false }, callback)
46+
hotkeys(
47+
keys,
48+
{ element: container.ownerDocument.body, keyup: true, keydown: false },
49+
callback
50+
)
4651
disposables.push(() => {
4752
hotkeys.unbind(keys, callback)
4853
})

0 commit comments

Comments
 (0)