@hrnec06/react_utils 1.2.1 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hrnec06/react_utils",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "A debugger component for react.",
5
5
  "exports": {
6
6
  ".": "./src/index.tsx"
@@ -21,6 +21,7 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "^19.1.8",
24
+ "@types/react-dom": "^19.2.3",
24
25
  "tsup": "^8.5.0",
25
26
  "typescript": "^5.8.3"
26
27
  },
@@ -28,7 +29,8 @@
28
29
  "@hrnec06/util": "^1.4.14",
29
30
  "clsx": "^2.1.1",
30
31
  "lucide-react": "^0.525.0",
31
- "react": "^19.1.0"
32
+ "react": "^19.1.0",
33
+ "react-dom": "^19.2.3"
32
34
  },
33
35
  "scripts": {
34
36
  "dev": "tsup src/index.tsx --format cjs,esm --dts --watch"
@@ -1,5 +1,6 @@
1
1
  import { minmax, Nullable, Vector2 } from "@hrnec06/util";
2
2
  import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { createPortal } from 'react-dom';
3
4
  import {DebuggerContext} from "./DebuggerContext";
4
5
  import clsx from "clsx";
5
6
  import ResizeBorder from "./DebuggerWindowResize";
@@ -182,7 +183,7 @@ export default function Debug({
182
183
 
183
184
  const calculateScrollHeight = () => {
184
185
  if (!containerRef.current) return 0;
185
-
186
+
186
187
  return containerRef.current.scrollHeight - calculateContainerHeight();
187
188
  }
188
189
 
@@ -206,7 +207,11 @@ export default function Debug({
206
207
  const handleExpandChange = (path: string[], state: boolean) => {
207
208
  if (!containerRef.current) return;
208
209
 
209
- setScrollProgress(minmax((scrollProgress * scrollHeight) / calculateScrollHeight(), 0, 1));
210
+ let newScrollProgress = minmax((scrollProgress * scrollHeight) / calculateScrollHeight(), 0, 1);
211
+ if (isNaN(newScrollProgress))
212
+ newScrollProgress = 0;
213
+
214
+ setScrollProgress(newScrollProgress);
210
215
 
211
216
  updateScrollHeight();
212
217
  }
@@ -222,76 +227,79 @@ export default function Debug({
222
227
  setScrollProgress(p => minmax(p + addProgress, 0, 1));
223
228
  }
224
229
 
225
- return (
226
- <DebuggerContext.Provider
227
- value={{
228
- paths: {
229
- exclude: excludePaths ?? [],
230
- open: openPaths ?? []
231
- },
232
- options: {
233
- compactArrays: compactArrays,
234
- autoHeight: autoHeight,
235
- openRoot: openRoot
236
- },
237
- window: {
238
- resize: setWindowSize,
239
- size: windowSize
240
- },
241
- placement: {
242
- reposition: setPosition,
243
- position: position
244
- },
245
- event: {
246
- expand: handleExpandChange
247
- },
248
- scroll: {
249
- setProgress: setScrollProgress,
250
- progress: scrollProgress,
251
- isScrollable: isScrollable
252
- }
253
- }}
254
- >
255
- <div className="fixed pointer-events-none w-full h-full left-0 top-0 overflow-hidden">
256
- <div
257
- className={clsx(
258
- "absolute font-jetbrains pointer-events-auto",
259
- size === 'tiny' && 'text-xs',
260
- size === 'normal' && 'text-sm',
261
- size === 'big' && 'text-base'
262
- )}
263
- style={{
264
- left: finalPosition[0],
265
- top: finalPosition[1],
266
- width: windowSize[0],
267
- height: windowSize[1],
268
- }}
269
- >
270
- <ResizeBorder />
271
-
230
+ return createPortal(
231
+ (
232
+ <DebuggerContext.Provider
233
+ value={{
234
+ paths: {
235
+ exclude: excludePaths ?? [],
236
+ open: openPaths ?? []
237
+ },
238
+ options: {
239
+ compactArrays: compactArrays,
240
+ autoHeight: autoHeight,
241
+ openRoot: openRoot
242
+ },
243
+ window: {
244
+ resize: setWindowSize,
245
+ size: windowSize
246
+ },
247
+ placement: {
248
+ reposition: setPosition,
249
+ position: position
250
+ },
251
+ event: {
252
+ expand: handleExpandChange
253
+ },
254
+ scroll: {
255
+ setProgress: setScrollProgress,
256
+ progress: scrollProgress,
257
+ isScrollable: isScrollable
258
+ }
259
+ }}
260
+ >
261
+ <div className="fixed pointer-events-none w-full h-full left-0 top-0 overflow-hidden z-999999">
272
262
  <div
273
- onWheel={handleWheel}
274
- className="bg-[#1f1f1f] shadow-lg rounded-md border border-[#4b4b4b] w-full h-full overflow-hidden flex"
263
+ className={clsx(
264
+ "absolute font-jetbrains pointer-events-auto",
265
+ size === 'tiny' && 'text-xs',
266
+ size === 'normal' && 'text-sm',
267
+ size === 'big' && 'text-base'
268
+ )}
269
+ style={{
270
+ left: finalPosition[0],
271
+ top: finalPosition[1],
272
+ width: windowSize[0],
273
+ height: windowSize[1],
274
+ }}
275
275
  >
276
+ <ResizeBorder />
277
+
276
278
  <div
277
- ref={containerRef}
278
- onMouseDown={handleMouseDown}
279
- className=" cursor-grab w-full"
280
- style={{
281
- transform: `translateY(${-(scrollProgress * scrollHeight)}px)`
282
- }}
279
+ onWheel={handleWheel}
280
+ className="bg-[#1f1f1f] shadow-lg rounded-md border border-[#4b4b4b] w-full h-full overflow-hidden flex"
283
281
  >
284
- <div className="p-3 pl-5">
285
- <ParseValue value={value} />
282
+ <div
283
+ ref={containerRef}
284
+ onMouseDown={handleMouseDown}
285
+ className=" cursor-grab w-full"
286
+ style={{
287
+ transform: `translateY(${-(scrollProgress * scrollHeight)}px)`
288
+ }}
289
+ >
290
+ <div className="p-3 pl-5">
291
+ <ParseValue value={value} />
292
+ </div>
286
293
  </div>
294
+ <ScrollBar
295
+ containerHeight={containerHeight}
296
+ scrollHeight={scrollHeight}
297
+ />
287
298
  </div>
288
- <ScrollBar
289
- containerHeight={containerHeight}
290
- scrollHeight={scrollHeight}
291
- />
292
299
  </div>
293
300
  </div>
294
- </div>
295
- </DebuggerContext.Provider>
301
+ </DebuggerContext.Provider>
302
+ ),
303
+ document.body
296
304
  );
297
305
  }
@@ -34,7 +34,7 @@ export default function ParseValueSimple({
34
34
  if (className === null || className.length > MAX_LENGTH)
35
35
  return <ValueKeyword value="object" />
36
36
 
37
- return className;
37
+ return (<span className="text-white">{className}</span>);
38
38
  }
39
39
  case 'string': {
40
40
  if (value.length > MAX_LENGTH)
@@ -53,7 +53,7 @@ export default function ValueObject({
53
53
  <Chevron_Toggle expanded={expanded} onToggle={handleExpand} />
54
54
 
55
55
  {
56
- Object.getPrototypeOf(value) !== Object.prototype && <span>({value.constructor.name}) </span>
56
+ Object.getPrototypeOf(value) !== Object.prototype && <span className="text-white">({value.constructor.name}) </span>
57
57
  }
58
58
 
59
59
  {