|
|
|
@ -10,11 +10,13 @@ export type PixelPefectTouchProps = {
|
|
|
|
|
* Called whenever the touchMap is updated.
|
|
|
|
|
* You can safely pass the setter of a solid.js signal to have reactive updates to the touchMap.
|
|
|
|
|
**/
|
|
|
|
|
onUpdate?: (touchMap: Map<number, Touch>) => void
|
|
|
|
|
onUpdate?: (touchMap: Map<number, Touch>) => void;
|
|
|
|
|
|
|
|
|
|
style?: JSX.CSSProperties,
|
|
|
|
|
} & AttachTouchOptions;
|
|
|
|
|
|
|
|
|
|
export const PixelPerfectTouch: Component<PixelPefectTouchProps> = (
|
|
|
|
|
{ children, onMount, ...options }
|
|
|
|
|
{ children, onMount, style, ...options }
|
|
|
|
|
) => {
|
|
|
|
|
let element: HTMLDivElement;
|
|
|
|
|
|
|
|
|
@ -40,7 +42,27 @@ export const PixelPerfectTouch: Component<PixelPefectTouchProps> = (
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onCleanup(cleanup);
|
|
|
|
|
|
|
|
|
|
if (options.preventDefault) {
|
|
|
|
|
function onContext(event: MouseEvent) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
element.addEventListener("contextmenu", onContext);
|
|
|
|
|
|
|
|
|
|
onCleanup(() => {
|
|
|
|
|
element.removeEventListener("contextmenu", onContext);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <div ref={el => element = el}>{children}</div>;
|
|
|
|
|
return (<div
|
|
|
|
|
ref={el => element = el}
|
|
|
|
|
style={{
|
|
|
|
|
...(options.preventDefault ? {"user-select": "none"} : {}),
|
|
|
|
|
...(style ?? {}),
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</div>);
|
|
|
|
|
};
|
|
|
|
|