Skip to content

Commit

Permalink
chore: compile
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Mar 15, 2024
1 parent 2434f65 commit 066a9cc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion dist/other/jupyterlite/JupyterLiteSession.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ interface JupyterLiteSessionProps {
messageHandler?: MessageHandler;
}
declare class JupyterLiteSession extends React.Component<JupyterLiteSessionProps> {
static defaultProps: Partial<JupyterLiteSessionProps>;
static defaultProps: JupyterLiteSessionProps;
constructor(props?: JupyterLiteSessionProps);
componentDidMount(): void;
componentWillUnmount(): void;
render(): React.JSX.Element;
Expand Down
7 changes: 5 additions & 2 deletions dist/other/jupyterlite/JupyterLiteSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const defaultProps = {
frameId: "jupyter-lite-iframe",
};
class JupyterLiteSession extends React.Component {
constructor(props = defaultProps) {
super(props);
}
componentDidMount() {
const { messageHandler, originURL } = this.props;
messageHandler === null || messageHandler === void 0 ? void 0 : messageHandler.init(originURL);
const { messageHandler, originURL, frameId } = this.props;
messageHandler === null || messageHandler === void 0 ? void 0 : messageHandler.init(originURL, frameId);
}
componentWillUnmount() {
const { messageHandler } = this.props;
Expand Down
5 changes: 3 additions & 2 deletions dist/other/jupyterlite/MessageHandler.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
type HandlerFunction = (data?: any, variableName?: string) => void;
type HandlerFunction = (...args: any[]) => void | any;
declare class MessageHandler {
private handlers;
private originURL;
init(originURL: string): void;
private frameId;
init(originURL: string, frameId: string): void;
destroy(): void;
addHandlers(action: string, handlers: HandlerFunction[]): void;
private receiveMessage;
Expand Down
16 changes: 13 additions & 3 deletions dist/other/jupyterlite/MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class MessageHandler {
constructor() {
this.handlers = {};
this.originURL = "*";
this.frameId = "";
this.receiveMessage = (event) => {
if (this.originURL !== "*" && event.origin !== this.originURL) {
return;
Expand All @@ -12,16 +13,21 @@ class MessageHandler {
// @ts-ignore
if (this.handlers[action]) {
// @ts-ignore
this.handlers[action].forEach((handler) => {
this.handlers["set-data"].forEach((handler) => {
handler(event.data.payload.data, event.data.payload.variableName);
});
this.handlers["get-data"].forEach((handler) => {
const data = handler(event.data.payload.variableName);
this.sendData(data, event.data.payload.variableName);
});
}
}
};
}
init(originURL) {
init(originURL, frameId) {
window.addEventListener("message", this.receiveMessage);
this.originURL = originURL;
this.frameId = frameId;
}
destroy() {
window.removeEventListener("message", this.receiveMessage);
Expand All @@ -41,7 +47,11 @@ class MessageHandler {
variableName,
},
};
window.parent.postMessage(message, this.originURL);
const iframe = document.getElementById(this.frameId);
if (iframe) {
// @ts-ignore
iframe.contentWindow.postMessage(message, this.originURL);
}
}
}
export default MessageHandler;

0 comments on commit 066a9cc

Please sign in to comment.