react-naver-maps
Version:
React Navermaps API integration for modern development.
111 lines (105 loc) • 3.91 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/use-navermaps.ts
var use_navermaps_exports = {};
__export(use_navermaps_exports, {
useNavermaps: () => useNavermaps
});
module.exports = __toCommonJS(use_navermaps_exports);
var import_suspend_react = require("suspend-react");
// src/contexts/client-options.ts
var import_react = require("react");
var ClientOptionsContext = (0, import_react.createContext)({});
var useClientOptions = () => (0, import_react.useContext)(ClientOptionsContext);
// src/load-navermaps-script.tsx
var import_react2 = require("react");
// src/utils/load-script.ts
var import_load_script = __toESM(require("load-script"));
function loadScript(src) {
return new Promise((resolve, reject) => {
(0, import_load_script.default)(src, (err, script) => {
if (err)
reject(err);
else
resolve(script);
});
});
}
// src/load-navermaps-script.tsx
var import_jsx_runtime = require("react/jsx-runtime");
function loadNavermapsScript(options) {
const url = makeUrl(options);
const promise = loadScript(url).then(() => {
const navermaps = window.naver.maps;
if (navermaps.jsContentLoaded) {
return navermaps;
}
return new Promise((resolve) => {
navermaps.onJSContentLoaded = () => {
resolve(navermaps);
};
});
});
return promise;
}
function makeUrl(options) {
const submodules = options.submodules;
const clientIdQuery = "ncpKeyId" in options ? `ncpKeyId=${options.ncpKeyId}` : "ncpClientId" in options ? `ncpClientId=${options.ncpClientId}` : "govClientId" in options ? `govClientId=${options.govClientId}` : "finClientId" in options ? `finClientId=${options.finClientId}` : void 0;
if (!clientIdQuery) {
throw new Error("react-naver-maps: ncpKeyId, ncpClientId, govClientId or finClientId is required");
}
let url = `https://oapi.map.naver.com/openapi/v3/maps.js?${clientIdQuery}`;
if (submodules) {
url += `&submodules=${submodules.join(",")}`;
}
return url;
}
// src/use-navermaps.ts
async function load(options) {
var _a;
if (typeof window !== "undefined" && ((_a = window.naver) == null ? void 0 : _a.maps)) {
return window.naver.maps;
}
if (!options) {
throw new Error("react-naver-maps: set options with `useNavermaps.config`");
}
return await loadNavermapsScript(options);
}
function useNavermaps() {
var _a;
if (typeof window === "undefined") {
throw new Error("react-naver-maps: browser");
}
if ((_a = window.naver) == null ? void 0 : _a.maps) {
return window.naver.maps;
}
const options = useClientOptions();
return (0, import_suspend_react.suspend)(load, [options, "react-naver-maps/loadClient"]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useNavermaps
});
//# sourceMappingURL=use-navermaps.js.map
;