2024-02-01 13:18:16 +00:00
|
|
|
import WidgetApp from "./WidgetApp";
|
2024-01-20 12:26:28 +00:00
|
|
|
import { Root, createRoot } from "react-dom/client";
|
|
|
|
|
|
|
|
|
|
|
|
let root: Root | undefined = undefined;
|
|
|
|
|
|
|
|
const widget = {
|
2024-01-31 14:39:50 +00:00
|
|
|
create({ selector, quizId }: {
|
2024-01-20 12:26:28 +00:00
|
|
|
selector: string;
|
2024-01-31 14:39:50 +00:00
|
|
|
quizId: string;
|
2024-01-20 12:26:28 +00:00
|
|
|
}) {
|
|
|
|
const element = document.getElementById(selector);
|
|
|
|
if (!element) throw new Error("Element for widget doesn't exist");
|
|
|
|
|
|
|
|
root = createRoot(element);
|
|
|
|
|
2024-02-01 13:18:16 +00:00
|
|
|
root.render(<WidgetApp quizId={quizId} />);
|
2024-01-20 12:26:28 +00:00
|
|
|
},
|
|
|
|
unmount() {
|
|
|
|
if (root) root.unmount();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default widget;
|
2024-01-20 12:51:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
<script type="module">
|
|
|
|
import widget from ".../widget.js";
|
|
|
|
|
|
|
|
widget.create({
|
2024-01-31 14:39:50 +00:00
|
|
|
selector: "widget-container",
|
|
|
|
quizId: "...",
|
2024-01-20 12:51:17 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
*/
|