@huin-core/react-portal 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { Primitive } from '@huin-core/react-primitive';
3
+
4
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
5
+ interface PortalProps extends PrimitiveDivProps {
6
+ /**
7
+ * An optional container where the portaled content should be appended.
8
+ */
9
+ container?: Element | null;
10
+ }
11
+ declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
12
+ declare const Root: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
13
+
14
+ export { Portal, type PortalProps, Root };
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { Primitive } from '@huin-core/react-primitive';
3
+
4
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
5
+ interface PortalProps extends PrimitiveDivProps {
6
+ /**
7
+ * An optional container where the portaled content should be appended.
8
+ */
9
+ container?: Element | null;
10
+ }
11
+ declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
12
+ declare const Root: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<HTMLDivElement>>;
13
+
14
+ export { Portal, type PortalProps, Root };
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // packages/react/portal/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ Portal: () => Portal,
35
+ Root: () => Root
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // packages/react/portal/src/Portal.tsx
40
+ var React = __toESM(require("react"));
41
+ var import_react_dom = __toESM(require("react-dom"));
42
+ var import_react_primitive = require("@huin-core/react-primitive");
43
+ var import_react_use_layout_effect = require("@huin-core/react-use-layout-effect");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var PORTAL_NAME = "Portal";
46
+ var Portal = React.forwardRef((props, forwardedRef) => {
47
+ const { container: containerProp, ...portalProps } = props;
48
+ const [mounted, setMounted] = React.useState(false);
49
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => setMounted(true), []);
50
+ const container = containerProp || mounted && globalThis?.document?.body;
51
+ return container ? import_react_dom.default.createPortal(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
52
+ });
53
+ Portal.displayName = PORTAL_NAME;
54
+ var Root = Portal;
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/Portal.tsx"],
4
+ "sourcesContent": ["'use client';\nexport {\n Portal,\n //\n Root,\n} from './Portal';\nexport type { PortalProps } from './Portal';\n", "import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@huin-core/react-primitive';\nimport { useLayoutEffect } from '@huin-core/react-use-layout-effect';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: Element | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container: containerProp, ...portalProps } = props;\n const [mounted, setMounted] = React.useState(false);\n useLayoutEffect(() => setMounted(true), []);\n const container = containerProp || (mounted && globalThis?.document?.body);\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAAqB;AACrB,6BAA0B;AAC1B,qCAAgC;AAuBJ;AAjB5B,IAAM,cAAc;AAWpB,IAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,QAAM,EAAE,WAAW,eAAe,GAAG,YAAY,IAAI;AACrD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAS,KAAK;AAClD,sDAAgB,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAC1C,QAAM,YAAY,iBAAkB,WAAW,YAAY,UAAU;AACrE,SAAO,YACH,iBAAAA,QAAS,aAAa,4CAAC,iCAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AACN,CAAC;AAED,OAAO,cAAc;AAIrB,IAAM,OAAO;",
6
+ "names": ["ReactDOM"]
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ "use client";
2
+
3
+ // packages/react/portal/src/Portal.tsx
4
+ import * as React from "react";
5
+ import ReactDOM from "react-dom";
6
+ import { Primitive } from "@huin-core/react-primitive";
7
+ import { useLayoutEffect } from "@huin-core/react-use-layout-effect";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var PORTAL_NAME = "Portal";
10
+ var Portal = React.forwardRef((props, forwardedRef) => {
11
+ const { container: containerProp, ...portalProps } = props;
12
+ const [mounted, setMounted] = React.useState(false);
13
+ useLayoutEffect(() => setMounted(true), []);
14
+ const container = containerProp || mounted && globalThis?.document?.body;
15
+ return container ? ReactDOM.createPortal(/* @__PURE__ */ jsx(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
16
+ });
17
+ Portal.displayName = PORTAL_NAME;
18
+ var Root = Portal;
19
+ export {
20
+ Portal,
21
+ Root
22
+ };
23
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/Portal.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport { Primitive } from '@huin-core/react-primitive';\nimport { useLayoutEffect } from '@huin-core/react-use-layout-effect';\n\n/* -------------------------------------------------------------------------------------------------\n * Portal\n * -----------------------------------------------------------------------------------------------*/\n\nconst PORTAL_NAME = 'Portal';\n\ntype PortalElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface PortalProps extends PrimitiveDivProps {\n /**\n * An optional container where the portaled content should be appended.\n */\n container?: Element | null;\n}\n\nconst Portal = React.forwardRef<PortalElement, PortalProps>((props, forwardedRef) => {\n const { container: containerProp, ...portalProps } = props;\n const [mounted, setMounted] = React.useState(false);\n useLayoutEffect(() => setMounted(true), []);\n const container = containerProp || (mounted && globalThis?.document?.body);\n return container\n ? ReactDOM.createPortal(<Primitive.div {...portalProps} ref={forwardedRef} />, container)\n : null;\n});\n\nPortal.displayName = PORTAL_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Portal;\n\nexport {\n Portal,\n //\n Root,\n};\nexport type { PortalProps };\n"],
5
+ "mappings": ";;;AAAA,YAAY,WAAW;AACvB,OAAO,cAAc;AACrB,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAuBJ;AAjB5B,IAAM,cAAc;AAWpB,IAAM,SAAe,iBAAuC,CAAC,OAAO,iBAAiB;AACnF,QAAM,EAAE,WAAW,eAAe,GAAG,YAAY,IAAI;AACrD,QAAM,CAAC,SAAS,UAAU,IAAU,eAAS,KAAK;AAClD,kBAAgB,MAAM,WAAW,IAAI,GAAG,CAAC,CAAC;AAC1C,QAAM,YAAY,iBAAkB,WAAW,YAAY,UAAU;AACrE,SAAO,YACH,SAAS,aAAa,oBAAC,UAAU,KAAV,EAAe,GAAG,aAAa,KAAK,cAAc,GAAI,SAAS,IACtF;AACN,CAAC;AAED,OAAO,cAAc;AAIrB,IAAM,OAAO;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huin-core/react-portal",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -20,7 +20,8 @@
20
20
  "types": "./dist/index.d.ts",
21
21
  "files": [
22
22
  "dist",
23
- "README.md"
23
+ "README.md",
24
+ "package.json"
24
25
  ],
25
26
  "sideEffects": false,
26
27
  "scripts": {