forked from TileDB-Inc/jupyter-iframe-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
35 lines (30 loc) · 998 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) TileDB, Inc.
// Distributed under the terms of the Modified BSD License.
import { windowEndpoint, wrap, proxy, ProxyOrClone } from 'comlink';
import { ICommandBridgeRemote } from 'jupyter-iframe-commands';
/**
* A bridge to expose actions on JupyterLab commands.
*/
export function createBridge({ iframeId }: { iframeId: string }) {
const iframe = document.getElementById(iframeId) as HTMLIFrameElement;
if (!iframe) {
throw new Error(
`Cannot create bridge: iframe with id "${iframeId}" not found`
);
}
if (!iframe.contentWindow) {
throw new Error(
`Cannot create bridge: iframe with id "${iframeId}" has no content window`
);
}
return wrap<ICommandBridgeRemote>(windowEndpoint(iframe.contentWindow));
}
/**
* Creates a proxy for the given object.
*
* @param args - The object to create a proxy for.
* @returns A proxy for the given object.
*/
export function createProxy(args: any): ProxyOrClone<any> {
return proxy(args);
}