/* eslint-disable @typescript-eslint/no-namespace */
import * as React from "react";
import Moveable from "@/react-moveable";
import { createPortal } from "react-dom";
const CustomElement = `
class CustomElement extends HTMLElement {
styleText = ${"`"}
.card {
width: 100%;
height: 100%;
}
.card-header {
width:100%;
height: 80px;
background-color: #3794FF;
}
.card-content {
width: 100%;
height: calc(100% - 80px);
background-color: #EDF0F3;
position: relative;
}
${"`"};
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open' });
const style = document.createElement('style');
const div = document.createElement('div');
div.classList.add('card');
div.innerHTML = ${"`"}
${"`"};
style.textContent = this.styleText;
this.shadow.appendChild(style);
this.shadow.appendChild(div);
}
}
if (!customElements.get("custom-element")) {
customElements.define('custom-element', CustomElement);
}
`;
if (typeof window !== "undefined") {
eval(CustomElement);
}
declare global {
interface HTMLElementTagNameMap {
"custom-element": HTMLElement;
}
namespace JSX {
interface IntrinsicElements {
// HTML
"custom-element": React.DetailedHTMLProps, HTMLElement>;
}
}
}
export default function App() {
const [customElement, setCustomElement] = React.useState();
React.useEffect(() => {
setCustomElement(document.querySelector("custom-element")!);
}, []);
return
{customElement && createPortal(
{
e.target.style.transform = e.transform;
}}
/>, customElement.shadowRoot!.querySelector('.card-content')!)}
;
}