Socket
Socket
Sign inDemoInstall

@uiw/react-amap-utils

Package Overview
Dependencies
3
Maintainers
0
Versions
100
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.1 to 7.0.2

6

cjs/usePortal.d.ts

@@ -1,7 +0,5 @@

import React, { ReactPortal } from 'react';
import { PropsWithChildren } from 'react';
export declare const usePortal: () => {
Portal: (props: {
children: React.ReactNode;
}) => ReactPortal | null;
Portal: ({ children }: PropsWithChildren) => import("react").ReactPortal;
container: HTMLDivElement;
};
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

@@ -10,56 +9,18 @@ Object.defineProperty(exports, "__esModule", {

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireWildcard(require("react"));
var _react = require("react");
var _reactDom = require("react-dom");
var _client = require("react-dom/client");
var usePortal = exports.usePortal = function usePortal() {
var ref = (0, _react.useRef)();
var _React$useState = _react["default"].useState(function () {
var el = document.createElement('div');
ref.current = (0, _client.createRoot)(el);
return el;
var _useState = (0, _react.useState)(function () {
return document.createElement('div');
}),
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 1),
container = _React$useState2[0];
var _useState = (0, _react.useState)({
render: function render() {
return null;
},
remove: function remove() {
return null;
}
}),
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
portal = _useState2[0],
setPortal = _useState2[1];
var ReactCreatePortal = _react["default"].useCallback(function (elmm) {
var Portal = function Portal(_ref) {
var children = _ref.children;
if (!children) return null;
return /*#__PURE__*/(0, _reactDom.createPortal)(children, elmm);
};
var remove = function remove(elm) {
// https://stackoverflow.com/a/74445760/1334703
var timeout = setTimeout(function () {
var _ref$current;
elm && ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.unmount());
clearTimeout(timeout);
});
};
return {
render: Portal,
remove: remove
};
}, []);
(0, _react.useEffect)(function () {
if (container) portal.remove();
var newPortal = ReactCreatePortal(container);
setPortal(newPortal);
return function () {
newPortal.remove(container);
};
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
container = _useState2[0];
var Portal = (0, _react.useCallback)(function Portal(_ref) {
var children = _ref.children;
return /*#__PURE__*/(0, _reactDom.createPortal)(children, container);
}, [container]);
return {
Portal: portal.render,
Portal: Portal,
container: container
};
};

@@ -1,7 +0,5 @@

import React, { ReactPortal } from 'react';
import { PropsWithChildren } from 'react';
export declare const usePortal: () => {
Portal: (props: {
children: React.ReactNode;
}) => ReactPortal | null;
Portal: ({ children }: PropsWithChildren) => import("react").ReactPortal;
container: HTMLDivElement;
};

@@ -1,48 +0,15 @@

import React, { useState, useEffect, useRef } from 'react';
import { useCallback, useState } from 'react';
import { createPortal } from 'react-dom';
import { createRoot } from 'react-dom/client';
export var usePortal = () => {
var ref = useRef();
var [container] = React.useState(() => {
var el = document.createElement('div');
ref.current = createRoot(el);
return el;
});
var [portal, setPortal] = useState({
render: () => null,
remove: () => null
});
var ReactCreatePortal = React.useCallback(elmm => {
var Portal = _ref => {
var {
children
} = _ref;
if (!children) return null;
return /*#__PURE__*/createPortal(children, elmm);
};
var remove = elm => {
// https://stackoverflow.com/a/74445760/1334703
var timeout = setTimeout(() => {
var _ref$current;
elm && ((_ref$current = ref.current) == null ? void 0 : _ref$current.unmount());
clearTimeout(timeout);
});
};
return {
render: Portal,
remove
};
}, []);
useEffect(() => {
if (container) portal.remove();
var newPortal = ReactCreatePortal(container);
setPortal(newPortal);
return () => {
newPortal.remove(container);
};
var [container] = useState(() => document.createElement('div'));
var Portal = useCallback(function Portal(_ref) {
var {
children
} = _ref;
return /*#__PURE__*/createPortal(children, container);
}, [container]);
return {
Portal: portal.render,
Portal,
container
};
};
{
"name": "@uiw/react-amap-utils",
"version": "7.0.1",
"version": "7.0.2",
"description": "基于 React 封装的高德地图组件。AMap Component Based On React.",

@@ -37,4 +37,4 @@ "funding": "https://jaywcjlove.github.io/#/sponsor",

"dependencies": {
"@uiw/react-amap-types": "7.0.1"
"@uiw/react-amap-types": "7.0.2"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc