@hrnec06/react_utils 1.9.1 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/ContextMenu/ContextMenu.tsx +4 -1
- package/src/components/Debugger/Debugger.tsx +4 -1
- package/src/components/Dialog/Dialog.tsx +4 -1
- package/src/components/ShadowRoot/ShadowRoot.tsx +1 -2
- package/src/context/ReactUtilsConfig.ts +19 -0
- package/src/index.ts +5 -0
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import clsx from "clsx";
|
|
|
10
10
|
import ContextMenuSection from "./ContextMenuSection";
|
|
11
11
|
import ContextMenuRoot from "./ContextMenuRoot";
|
|
12
12
|
import useSignal, { Signal } from "../../hooks/useSignal";
|
|
13
|
+
import { useReactUtilsConfig } from "../../context/ReactUtilsConfig";
|
|
13
14
|
|
|
14
15
|
type InheritCallback = (parent: TContextMenuContext) => (CTXM.ContextMenuRoot | { parent: string, children: CTXM.ContextMenuRoot });
|
|
15
16
|
|
|
@@ -24,6 +25,8 @@ function ContextMenuWrapper({
|
|
|
24
25
|
menu
|
|
25
26
|
}: ContextMenuWrapperProps)
|
|
26
27
|
{
|
|
28
|
+
const { portalElement } = useReactUtilsConfig();
|
|
29
|
+
|
|
27
30
|
if (!open)
|
|
28
31
|
return undefined;
|
|
29
32
|
|
|
@@ -46,7 +49,7 @@ function ContextMenuWrapper({
|
|
|
46
49
|
>
|
|
47
50
|
<ContextMenuRoot menu={menu} />
|
|
48
51
|
</div>
|
|
49
|
-
),
|
|
52
|
+
), portalElement);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
|
|
@@ -12,6 +12,7 @@ import useNamespacedId from "../../hooks/useNamespacedId";
|
|
|
12
12
|
import useLocalStorage from "../../hooks/useLocalStorage";
|
|
13
13
|
import z from "zod";
|
|
14
14
|
import useDefaultValue from "../../hooks/useDefaultValue";
|
|
15
|
+
import { useReactUtilsConfig } from "../../context/ReactUtilsConfig";
|
|
15
16
|
|
|
16
17
|
const DEBUG_NAMESPACE = "debugger";
|
|
17
18
|
|
|
@@ -67,6 +68,8 @@ function Debug({
|
|
|
67
68
|
autoHeight = false,
|
|
68
69
|
openRoot = true
|
|
69
70
|
}: DebugProps) {
|
|
71
|
+
const { portalElement } = useReactUtilsConfig();
|
|
72
|
+
|
|
70
73
|
// Config
|
|
71
74
|
|
|
72
75
|
const id = useDebuggerID(customID);
|
|
@@ -312,7 +315,7 @@ function Debug({
|
|
|
312
315
|
</div>
|
|
313
316
|
</DebuggerContext.Provider>
|
|
314
317
|
),
|
|
315
|
-
|
|
318
|
+
portalElement
|
|
316
319
|
);
|
|
317
320
|
}
|
|
318
321
|
|
|
@@ -7,6 +7,7 @@ import { DialogContext } from "./DialogContext";
|
|
|
7
7
|
import DialogPanel from "./DialogPanel";
|
|
8
8
|
import { useEffect } from "react";
|
|
9
9
|
import { createPortal } from "react-dom";
|
|
10
|
+
import { useReactUtilsConfig } from "../../context/ReactUtilsConfig";
|
|
10
11
|
|
|
11
12
|
interface DialogProps extends React.PropsWithChildren {
|
|
12
13
|
open?: boolean,
|
|
@@ -20,6 +21,8 @@ function Dialog({
|
|
|
20
21
|
children,
|
|
21
22
|
}: DialogProps)
|
|
22
23
|
{
|
|
24
|
+
const { portalElement } = useReactUtilsConfig();
|
|
25
|
+
|
|
23
26
|
const pressingEsc = useKeyListener(KeyboardButton.Escape);
|
|
24
27
|
|
|
25
28
|
useEffect(() => {
|
|
@@ -43,7 +46,7 @@ function Dialog({
|
|
|
43
46
|
{children}
|
|
44
47
|
</DialogContext.Provider>
|
|
45
48
|
),
|
|
46
|
-
|
|
49
|
+
portalElement
|
|
47
50
|
);
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Optional, ReactUtils } from "@hrnec06/util";
|
|
2
2
|
import React, { useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import useDefaultValue from "../../hooks/useDefaultValue";
|
|
4
3
|
import { createPortal } from "react-dom";
|
|
5
4
|
|
|
6
5
|
type ShadowRootProps = ReactUtils.Props<{
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
interface ReactUtilsConfig {
|
|
4
|
+
/**
|
|
5
|
+
* @default document.body
|
|
6
|
+
*/
|
|
7
|
+
portalElement: Element | DocumentFragment,
|
|
8
|
+
}
|
|
9
|
+
const ReactUtilsConfig = createContext<ReactUtilsConfig>({
|
|
10
|
+
portalElement: document.body
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function useReactUtilsConfig()
|
|
14
|
+
{
|
|
15
|
+
return useContext(ReactUtilsConfig);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useReactUtilsConfig, ReactUtilsConfig };
|
|
19
|
+
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,8 @@ import useSyncRef, { useSyncRefAuto } from "./hooks/useSyncRef";
|
|
|
19
19
|
import useSignal, { Signal } from "./hooks/useSignal";
|
|
20
20
|
import useLazySignal, { LazySignal } from "./hooks/useLazySignal";
|
|
21
21
|
|
|
22
|
+
import { ReactUtilsConfig } from "./context/ReactUtilsConfig";
|
|
23
|
+
|
|
22
24
|
import * as Debugger from './components/Debugger/Debugger';
|
|
23
25
|
|
|
24
26
|
import ResizeableBox from "./components/ResizeableBox/ResizeableBox";
|
|
@@ -53,6 +55,9 @@ export {
|
|
|
53
55
|
useUUID,
|
|
54
56
|
useWindowSize,
|
|
55
57
|
|
|
58
|
+
// Context
|
|
59
|
+
ReactUtilsConfig,
|
|
60
|
+
|
|
56
61
|
// Signals
|
|
57
62
|
useSignal,
|
|
58
63
|
Signal,
|