@davedev42/react-naver-maps
Version:
React Navermaps API integration for modern development.
76 lines (74 loc) • 1.98 kB
JavaScript
import {
omitUndefined
} from "./chunk-SOBCLIXD.mjs";
import {
useNavermaps
} from "./chunk-JX27UDSU.mjs";
import {
HandleEvents
} from "./chunk-TMGZDWPN.mjs";
import {
Overlay
} from "./chunk-P2HFB547.mjs";
// src/overlays/info-window.tsx
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { jsx } from "react/jsx-runtime";
var primitiveKvoKeys = [
"content",
"zIndex",
"maxWidth",
"pixelOffset",
"backgroundColor",
"borderColor",
"borderWidth",
"disableAutoPan",
"disableAnchor",
"anchorSkew",
"anchorSize",
"anchorColor"
];
var kvoKeys = [
...primitiveKvoKeys,
"position"
];
var kvoEvents = kvoKeys.map((key) => `${key}_changed`);
var uiEvents = [
"mousedown",
"mouseup",
"click",
"dblclick",
"rightclick",
"mouseover",
"mouseout",
"mousemove"
];
var events = [...uiEvents, ...kvoEvents];
var InfoWindow = forwardRef(function InfoWindow2(props, ref) {
const { position } = props;
const navermaps = useNavermaps();
const [infoWindow] = useState(() => new navermaps.InfoWindow(omitUndefined({
position,
...Object.fromEntries(kvoKeys.filter((key) => key !== "position").map((key) => [key, props[key]]))
})));
useImperativeHandle(ref, () => infoWindow);
useEffect(() => {
const options = {
...Object.fromEntries(primitiveKvoKeys.map((key) => [key, props[key]])),
position
};
const cleanOptions = omitUndefined(options);
if (Object.keys(cleanOptions).length > 0) {
infoWindow.setOptions(cleanOptions);
}
}, primitiveKvoKeys.map((key) => props[key]));
useEffect(() => {
if (position && infoWindow.getPosition().equals(position)) {
infoWindow.setPosition(position);
}
}, [position]);
return /* @__PURE__ */ jsx(Overlay, { element: infoWindow, autoMount: false, children: /* @__PURE__ */ jsx(HandleEvents, { events, listeners: props }) });
});
export {
InfoWindow
};
//# sourceMappingURL=chunk-CTR6SLNA.mjs.map