@griddo/ax 11.10.14 → 11.10.16-rc.0

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "11.10.14",
4
+ "version": "11.10.16-rc.0",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -217,5 +217,5 @@
217
217
  "publishConfig": {
218
218
  "access": "public"
219
219
  },
220
- "gitHead": "ae45e364544d784f76299b04463a19c1ac701ff8"
220
+ "gitHead": "f43d569318efc17ca8e2f7a8f44eaa188854d549"
221
221
  }
@@ -60,7 +60,7 @@ const Gallery = (props: IProps): JSX.Element => {
60
60
  const isLocalTab = selectedTab === "local";
61
61
  const galleryScope = isLocalTab && site ? site.id : "global";
62
62
  const hasFolders = !!folders?.length;
63
- const isRoot = !breadcrumb.length;
63
+ const isRoot = !breadcrumb?.length;
64
64
  const validFormats = ["jpeg", "jpg", "png", "svg", "gif"];
65
65
 
66
66
  const galleryRef = useRef<HTMLDivElement>(null);
@@ -1,9 +1,11 @@
1
- import React, { useEffect, useRef, useState } from "react";
1
+ import type { ReactNode } from "react";
2
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
3
+
2
4
  import { useHandleClickOutside } from "@ax/hooks";
3
5
 
4
6
  import * as S from "./style";
5
7
 
6
- const Tooltip = (props: ITooltipProps): JSX.Element => {
8
+ const Tooltip = (props: ITooltipProps) => {
7
9
  const { content, children, hideOnClick = true, bottom, left, expanded, top } = props;
8
10
 
9
11
  const initialState: IState = {
@@ -15,26 +17,31 @@ const Tooltip = (props: ITooltipProps): JSX.Element => {
15
17
  const [state, setState] = useState(initialState);
16
18
  const { active, childrenWidth, clicked, fixOutOfBounds } = state;
17
19
 
18
- const changeState = (value: any) => {
20
+ const changeState = useCallback((value: Partial<IState>) => {
19
21
  setState((state) => ({ ...state, ...value }));
20
- };
22
+ }, []);
21
23
 
22
24
  const childrenRef = useRef<HTMLDivElement>(null);
23
25
  const tipRef = useRef<HTMLDivElement>(null);
24
-
25
- let timeout: any;
26
+ const timeoutRef = useRef<NodeJS.Timeout | null>(null);
26
27
 
27
28
  const showTip = () => {
28
29
  if (!clicked) {
29
- timeout = setTimeout(() => {
30
+ if (timeoutRef.current) {
31
+ clearTimeout(timeoutRef.current);
32
+ }
33
+ timeoutRef.current = setTimeout(() => {
30
34
  changeState({ active: true });
31
35
  }, 1000);
32
36
  }
33
37
  };
34
38
 
35
39
  const hideTip = () => {
36
- clearInterval(timeout);
37
- changeState({ active: false });
40
+ if (timeoutRef.current) {
41
+ clearTimeout(timeoutRef.current);
42
+ timeoutRef.current = null;
43
+ }
44
+ changeState({ active: false, fixOutOfBounds: 0 });
38
45
  };
39
46
 
40
47
  const handleClick = () => {
@@ -44,8 +51,8 @@ const Tooltip = (props: ITooltipProps): JSX.Element => {
44
51
  }
45
52
  };
46
53
 
47
- const handleClickOutside = (e: any) => {
48
- if (childrenRef.current && childrenRef.current.contains(e.target)) {
54
+ const handleClickOutside = (e: MouseEvent | TouchEvent) => {
55
+ if (childrenRef.current?.contains(e.target as Node)) {
49
56
  return;
50
57
  }
51
58
  changeState({ clicked: false });
@@ -53,16 +60,22 @@ const Tooltip = (props: ITooltipProps): JSX.Element => {
53
60
 
54
61
  useHandleClickOutside(clicked, handleClickOutside);
55
62
 
56
- // biome-ignore lint/correctness/useExhaustiveDependencies: TODO: fix this
57
63
  useEffect(() => {
58
- if (childrenRef.current && childrenRef.current.children[0]) {
64
+ return () => {
65
+ if (timeoutRef.current) {
66
+ clearTimeout(timeoutRef.current);
67
+ }
68
+ };
69
+ }, []);
70
+
71
+ useEffect(() => {
72
+ if (childrenRef.current?.children[0]) {
59
73
  const childrenWidth = childrenRef.current.children[0].clientWidth;
60
74
  changeState({ childrenWidth });
61
75
  }
62
- }, [childrenRef]);
76
+ }, [changeState]);
63
77
 
64
- // biome-ignore lint/correctness/useExhaustiveDependencies: TODO: fix this
65
- useEffect(() => {
78
+ useLayoutEffect(() => {
66
79
  if (active && tipRef.current) {
67
80
  const clientRect = tipRef.current.getBoundingClientRect();
68
81
 
@@ -72,11 +85,13 @@ const Tooltip = (props: ITooltipProps): JSX.Element => {
72
85
  changeState({ fixOutOfBounds: left });
73
86
  } else if (right > windowSize) {
74
87
  changeState({ fixOutOfBounds: right - windowSize });
88
+ } else {
89
+ changeState({ fixOutOfBounds: 0 });
75
90
  }
76
91
  }
77
- }, [tipRef, active]);
92
+ }, [active, changeState]);
78
93
 
79
- if (!content) return children;
94
+ if (!content) return <>{children}</>;
80
95
 
81
96
  return (
82
97
  <S.Tooltip
@@ -126,7 +126,7 @@ const MediaGallery = (props: IProps) => {
126
126
  const isTabGlobal = selectedTab === "global";
127
127
  const siteID: number | "global" = !isSiteView || isTabGlobal ? "global" : currentSiteInfo.id;
128
128
  const hasFolders = !!folders?.length;
129
- const isRoot = !breadcrumb.length;
129
+ const isRoot = !breadcrumb?.length;
130
130
  const isGrid = displayMode === "grid";
131
131
  const validFormats = ["jpeg", "jpg", "png", "svg", "gif"];
132
132