@yakad/ui 1.3.138 → 1.3.140
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/dist/ActiveOnVisible/ActiveOnVisible.d.ts +5 -0
- package/dist/ActiveOnVisible/ActiveOnVisible.js +20 -0
- package/dist/RenderByVisibility/RenderByVisibility.d.ts +5 -3
- package/dist/RenderByVisibility/RenderByVisibility.js +53 -35
- package/dist/Stack/Stack.d.ts +0 -1
- package/dist/Stack/Stack.js +2 -2
- package/dist/WithInteractions/WithInteractions.d.ts +2 -1
- package/dist/WithInteractions/WithInteractions.js +3 -10
- package/dist/index.d.ts +4 -6
- package/dist/index.js +11 -14
- package/package.json +1 -1
- package/dist/DisplayOnVisible/DisplayOnVisible.d.ts +0 -10
- package/dist/DisplayOnVisible/DisplayOnVisible.js +0 -41
- package/dist/DisplayOnVisible/DisplayOnVisible.module.css +0 -3
- package/dist/LoadingControl/LoadingControl.d.ts +0 -12
- package/dist/LoadingControl/LoadingControl.js +0 -95
- package/dist/RenderOnVisible/RenderOnVisible.d.ts +0 -10
- package/dist/RenderOnVisible/RenderOnVisible.js +0 -40
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StackProps } from "..";
|
|
3
|
+
export interface ActiveOnVisibleProps extends StackProps {
|
|
4
|
+
}
|
|
5
|
+
export declare const ActiveOnVisible: import("react").ForwardRefExoticComponent<ActiveOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { Activity, forwardRef, useState } from "react";
|
|
15
|
+
import { WithInteractions } from "..";
|
|
16
|
+
export const ActiveOnVisible = forwardRef(function ActiveOnVisible(_a, ref) {
|
|
17
|
+
var { children } = _a, restProps = __rest(_a, ["children"]);
|
|
18
|
+
const [isVisible, setIsVisible] = useState(true);
|
|
19
|
+
return (_jsx(WithInteractions, Object.assign({ ref: ref }, restProps, { onVisibilityChange: (v) => setIsVisible(v), children: _jsx(Activity, { mode: isVisible ? "visible" : "hidden", children: children }) })));
|
|
20
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
import { StackProps } from "..";
|
|
3
|
+
export interface RenderByVisibilityProps extends StackProps {
|
|
4
|
+
scrollMarginTop?: number;
|
|
3
5
|
extraRender?: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
jumpToIndex?: number;
|
|
7
|
+
stopNewRenders?: boolean;
|
|
6
8
|
newChildRendered?: (index: number) => void;
|
|
7
9
|
children?: React.ReactNode;
|
|
8
10
|
}
|
|
@@ -12,58 +12,76 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import React, { forwardRef, useEffect, useRef, useState } from "react";
|
|
15
|
-
import {
|
|
15
|
+
import { Stack, WithInteractions } from "..";
|
|
16
16
|
const data = Array.from({ length: 78 });
|
|
17
17
|
export const RenderByVisibility = forwardRef(function RenderByVisibility(_a, ref) {
|
|
18
|
-
var { extraRender = 5,
|
|
19
|
-
const childRefs = useRef({});
|
|
18
|
+
var { scrollMarginTop = 2, extraRender = 5, jumpToIndex = 0, stopNewRenders, newChildRendered, style, children } = _a, restProps = __rest(_a, ["scrollMarginTop", "extraRender", "jumpToIndex", "stopNewRenders", "newChildRendered", "style", "children"]);
|
|
20
19
|
const childrenArray = React.Children.toArray(children);
|
|
21
|
-
//
|
|
22
|
-
const
|
|
20
|
+
// Scroll Zone
|
|
21
|
+
const childRefs = useRef({});
|
|
22
|
+
const scrollTo = (i, smooth) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = childRefs.current[i]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
25
|
+
behavior: smooth ? "smooth" : "auto",
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
// Collect Visibled Childs
|
|
29
|
+
const [visibled, setVisibled] = useState({ lowest: jumpToIndex, highest: jumpToIndex });
|
|
23
30
|
const handleOnVisible = (i) => {
|
|
24
31
|
if (i < visibled.lowest)
|
|
25
32
|
setVisibled(Object.assign(Object.assign({}, visibled), { lowest: i }));
|
|
26
33
|
if (i > visibled.highest)
|
|
27
34
|
setVisibled(Object.assign(Object.assign({}, visibled), { highest: i }));
|
|
28
35
|
};
|
|
29
|
-
// Collect Rendered Childs
|
|
30
|
-
const [rendered, setRendered] = useState({ lowest:
|
|
31
|
-
// Calculate Over Screen Renders
|
|
36
|
+
// Collect Rendered Childs
|
|
37
|
+
const [rendered, setRendered] = useState({ lowest: jumpToIndex, highest: jumpToIndex });
|
|
32
38
|
const overRenderedOnLowSide = visibled.lowest - rendered.lowest;
|
|
33
39
|
const overRenderedOnHighSide = rendered.highest - visibled.highest;
|
|
40
|
+
// Is Visible Loading Box
|
|
41
|
+
const [isVisibleLowSideLoadingBox, setIsVisibleLowSideLoadingBox] = useState(false);
|
|
42
|
+
// Render new Childs if needed
|
|
34
43
|
useEffect(() => {
|
|
35
|
-
if (!
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
if (!stopNewRenders) {
|
|
45
|
+
if (overRenderedOnHighSide <= overRenderedOnLowSide) {
|
|
46
|
+
if (rendered.highest < data.length &&
|
|
47
|
+
overRenderedOnHighSide < extraRender) {
|
|
48
|
+
setRendered(Object.assign(Object.assign({}, rendered), { highest: rendered.highest + 1 }));
|
|
49
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(rendered.highest + 1);
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
|
-
else
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
else {
|
|
53
|
+
if (rendered.lowest > 0 &&
|
|
54
|
+
overRenderedOnLowSide < extraRender) {
|
|
55
|
+
if (isVisibleLowSideLoadingBox) {
|
|
56
|
+
scrollTo(rendered.lowest);
|
|
57
|
+
}
|
|
58
|
+
setRendered(Object.assign(Object.assign({}, rendered), { lowest: rendered.lowest - 1 }));
|
|
59
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(rendered.lowest - 1);
|
|
60
|
+
}
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
|
-
|
|
63
|
+
// eslint-disable-next-line
|
|
64
|
+
}, [visibled, rendered, extraRender, stopNewRenders]);
|
|
65
|
+
// Scroll to jumpToIndex
|
|
48
66
|
useEffect(() => {
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}, [overRenderedOnHighSide]);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
var _a;
|
|
57
|
-
if (overRenderedOnHighSide == 1) {
|
|
58
|
-
(_a = childRefs.current[jump]) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
|
|
59
|
-
console.log("SCROLL TO JUMP");
|
|
67
|
+
const isJumpToIndexOutOfRenderedRange = jumpToIndex < rendered.lowest || jumpToIndex > rendered.highest;
|
|
68
|
+
if (isJumpToIndexOutOfRenderedRange) {
|
|
69
|
+
setVisibled({ lowest: jumpToIndex, highest: jumpToIndex });
|
|
70
|
+
setRendered({ lowest: jumpToIndex, highest: jumpToIndex });
|
|
60
71
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
const timeout = setTimeout(() => {
|
|
73
|
+
scrollTo(jumpToIndex, true);
|
|
74
|
+
}, 300);
|
|
75
|
+
return () => clearTimeout(timeout);
|
|
76
|
+
// eslint-disable-next-line
|
|
77
|
+
}, [jumpToIndex]);
|
|
78
|
+
// console.log("visibled", visibled);
|
|
79
|
+
// console.log("rendered", rendered);
|
|
80
|
+
// console.log("stopNewRenders", stopNewRenders);
|
|
81
|
+
return (_jsxs(Stack, Object.assign({ ref: ref }, restProps, { style: Object.assign({ minHeight: "100vh" }, style), children: [rendered.lowest > 0 && (_jsx(WithInteractions, { style: {
|
|
82
|
+
marginBottom: `${scrollMarginTop}rem`,
|
|
83
|
+
}, onVisibilityChange: (v) => setIsVisibleLowSideLoadingBox(v) })), childrenArray.map((child, i) => i >= rendered.lowest &&
|
|
66
84
|
i <= rendered.highest && (_jsx(WithInteractions, { ref: (el) => {
|
|
67
85
|
childRefs.current[i] = el;
|
|
68
|
-
}, onVisible: () => handleOnVisible(i),
|
|
86
|
+
}, onVisible: () => handleOnVisible(i), style: { scrollMarginTop: `${scrollMarginTop}rem` }, children: child }, i)))] })));
|
|
69
87
|
});
|
package/dist/Stack/Stack.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export interface StackProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
3
|
align?: "start" | "space" | "center" | "end";
|
|
4
|
-
fullWidth?: boolean;
|
|
5
4
|
children?: React.ReactNode;
|
|
6
5
|
}
|
|
7
6
|
export declare const Stack: import("react").ForwardRefExoticComponent<StackProps & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/Stack/Stack.js
CHANGED
|
@@ -15,7 +15,7 @@ import classNames from "classnames";
|
|
|
15
15
|
import boxingStyles from "../boxing.module.css";
|
|
16
16
|
import styles from "./Stack.module.css";
|
|
17
17
|
export const Stack = forwardRef(function Stack(_a, ref) {
|
|
18
|
-
var { align,
|
|
19
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, {
|
|
18
|
+
var { align, className, children } = _a, restProps = __rest(_a, ["align", "className", "children"]);
|
|
19
|
+
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidthLover: true }, styles.stack, className);
|
|
20
20
|
return (_jsx("div", Object.assign({ ref: ref }, restProps, { className: joinedClassNames, children: children })));
|
|
21
21
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { StackProps } from "../Stack/Stack";
|
|
3
|
+
export interface WithInteractionsProps extends StackProps {
|
|
3
4
|
onRightClick?: (e: MouseEvent) => void;
|
|
4
5
|
onTap?: (e: TouchEvent) => void;
|
|
5
6
|
onDoubleTap?: (e: TouchEvent) => void;
|
|
@@ -11,10 +11,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
15
|
+
import { Stack } from "../Stack/Stack";
|
|
16
16
|
export const WithInteractions = forwardRef(function WithInteractions(_a, forwardedRef) {
|
|
17
|
-
var _b;
|
|
18
17
|
var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibilityChange, onVisible, onHidden, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibilityChange", "onVisible", "onHidden", "onMouseHoverStart", "onMouseHoverLeave"]);
|
|
19
18
|
const localRef = useRef(null);
|
|
20
19
|
// Let the parent access our DOM node
|
|
@@ -215,11 +214,5 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
|
|
|
215
214
|
onMouseHoverStart,
|
|
216
215
|
onMouseHoverLeave,
|
|
217
216
|
]);
|
|
218
|
-
|
|
219
|
-
return null;
|
|
220
|
-
return _jsx("div", { ref: localRef, children: children });
|
|
221
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
|
-
return cloneElement(children, Object.assign(Object.assign({}, restProps), { ref: mergeRefs(localRef, forwardedRef,
|
|
223
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
-
(_b = children.props) === null || _b === void 0 ? void 0 : _b.ref) }));
|
|
217
|
+
return (_jsx(Stack, Object.assign({ ref: localRef }, restProps, { children: children })));
|
|
225
218
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export * from "./Main/Main";
|
|
|
4
4
|
export * from "./Footer/Footer";
|
|
5
5
|
export * from "./Navigation/Navigation";
|
|
6
6
|
export * from "./Container/Container";
|
|
7
|
-
export * from "./Stack/Stack";
|
|
8
7
|
export * from "./Row/Row";
|
|
8
|
+
export * from "./Stack/Stack";
|
|
9
9
|
export * from "./GridContainer/GridContainer";
|
|
10
10
|
export * from "./GridItem/GridItem";
|
|
11
11
|
export * from "./Card/Card";
|
|
@@ -28,11 +28,9 @@ export * from "./RadioGroup/RadioGroup";
|
|
|
28
28
|
export * from "./RadioButton/RadioButton";
|
|
29
29
|
export * from "./CodeBox/CodeBox";
|
|
30
30
|
export * from "./Display/Display";
|
|
31
|
-
export * from "./WithInteractions/WithInteractions";
|
|
32
31
|
export * from "./WithOverlay/WithOverlay";
|
|
32
|
+
export * from "./WithInteractions/WithInteractions";
|
|
33
|
+
export * from "./RenderByVisibility/RenderByVisibility";
|
|
34
|
+
export * from "./ActiveOnVisible/ActiveOnVisible";
|
|
33
35
|
export * from "./Dropdown/Dropdown";
|
|
34
36
|
export * from "./Popup/Popup";
|
|
35
|
-
export * from "./LoadingControl/LoadingControl";
|
|
36
|
-
export * from "./RenderByVisibility/RenderByVisibility";
|
|
37
|
-
export * from "./DisplayOnVisible/DisplayOnVisible";
|
|
38
|
-
export * from "./RenderOnVisible/RenderOnVisible";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// Layout & Structure
|
|
2
|
-
export * from "./Screen/Screen";
|
|
2
|
+
export * from "./Screen/Screen"; // Stack Based
|
|
3
3
|
export * from "./AppBar/AppBar";
|
|
4
4
|
export * from "./Main/Main";
|
|
5
5
|
export * from "./Footer/Footer";
|
|
6
6
|
export * from "./Navigation/Navigation";
|
|
7
|
-
export * from "./Container/Container";
|
|
8
|
-
export * from "./Stack/Stack";
|
|
7
|
+
export * from "./Container/Container"; // Stack Based
|
|
9
8
|
export * from "./Row/Row";
|
|
9
|
+
export * from "./Stack/Stack";
|
|
10
10
|
export * from "./GridContainer/GridContainer";
|
|
11
11
|
export * from "./GridItem/GridItem";
|
|
12
|
-
export * from "./Card/Card";
|
|
12
|
+
export * from "./Card/Card"; // Stack Based
|
|
13
13
|
// Theme & Styling
|
|
14
|
-
export * from "./Theme/Theme";
|
|
14
|
+
export * from "./Theme/Theme"; // Stack Based
|
|
15
15
|
export * from "./Spacer/Spacer";
|
|
16
16
|
export * from "./Hr/Hr";
|
|
17
17
|
// UI Components
|
|
@@ -32,14 +32,11 @@ export * from "./RadioGroup/RadioGroup";
|
|
|
32
32
|
export * from "./RadioButton/RadioButton";
|
|
33
33
|
export * from "./CodeBox/CodeBox";
|
|
34
34
|
// Utilities
|
|
35
|
-
export * from "./Display/Display";
|
|
36
|
-
export * from "./WithInteractions/WithInteractions";
|
|
35
|
+
export * from "./Display/Display"; // Stack Based
|
|
37
36
|
export * from "./WithOverlay/WithOverlay";
|
|
37
|
+
export * from "./WithInteractions/WithInteractions"; // Stack Based
|
|
38
|
+
export * from "./RenderByVisibility/RenderByVisibility"; // Stack Based
|
|
39
|
+
export * from "./ActiveOnVisible/ActiveOnVisible"; // Stack Based
|
|
38
40
|
// Overlays
|
|
39
|
-
export * from "./Dropdown/Dropdown";
|
|
40
|
-
export * from "./Popup/Popup";
|
|
41
|
-
// Loading Control
|
|
42
|
-
export * from "./LoadingControl/LoadingControl";
|
|
43
|
-
export * from "./RenderByVisibility/RenderByVisibility";
|
|
44
|
-
export * from "./DisplayOnVisible/DisplayOnVisible";
|
|
45
|
-
export * from "./RenderOnVisible/RenderOnVisible";
|
|
41
|
+
export * from "./Dropdown/Dropdown"; // Card Based
|
|
42
|
+
export * from "./Popup/Popup"; // Card Based
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export interface DisplayOnVisibleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
-
align?: "start" | "space" | "center" | "end";
|
|
4
|
-
fullWidth?: boolean;
|
|
5
|
-
onVisibilityChange?: (visible: boolean) => void;
|
|
6
|
-
onVisible?: () => void;
|
|
7
|
-
onHidden?: () => void;
|
|
8
|
-
children?: React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
export declare const DisplayOnVisible: import("react").ForwardRefExoticComponent<DisplayOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
15
|
-
import classNames from "classnames";
|
|
16
|
-
import boxingStyles from "../boxing.module.css";
|
|
17
|
-
import { WithInteractions } from "..";
|
|
18
|
-
import styles from "./DisplayOnVisible.module.css";
|
|
19
|
-
export const DisplayOnVisible = forwardRef(function DisplayOnVisible(_a, forwardedRef) {
|
|
20
|
-
var { align, fullWidth = true, onVisibilityChange, onVisible, onHidden, className, style, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "onVisibilityChange", "onVisible", "onHidden", "className", "style", "children"]);
|
|
21
|
-
const localRef = useRef(null);
|
|
22
|
-
// Let the parent access our DOM node
|
|
23
|
-
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
24
|
-
const [boxHeight, setBoxHeight] = useState(0);
|
|
25
|
-
const isVisible = boxHeight === 0;
|
|
26
|
-
const handleOnVisible = () => {
|
|
27
|
-
setBoxHeight(0);
|
|
28
|
-
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(true);
|
|
29
|
-
onVisible === null || onVisible === void 0 ? void 0 : onVisible();
|
|
30
|
-
};
|
|
31
|
-
const handleOnHidden = () => {
|
|
32
|
-
if (localRef.current) {
|
|
33
|
-
const boxRect = localRef.current.getBoundingClientRect();
|
|
34
|
-
setBoxHeight(boxRect.height);
|
|
35
|
-
}
|
|
36
|
-
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(false);
|
|
37
|
-
onHidden === null || onHidden === void 0 ? void 0 : onHidden();
|
|
38
|
-
};
|
|
39
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, { [styles.notVisible]: !isVisible }, className);
|
|
40
|
-
return (_jsx(WithInteractions, { onVisible: handleOnVisible, onHidden: handleOnHidden, children: _jsx("div", Object.assign({ ref: localRef }, restProps, { className: joinedClassNames, style: Object.assign({ height: boxHeight || "auto" }, style), children: children })) }));
|
|
41
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
type LoadingControlChildren = React.ReactElement<{
|
|
3
|
-
index?: number;
|
|
4
|
-
}>;
|
|
5
|
-
export interface LoadingControlProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
-
align?: "start" | "space" | "center" | "end";
|
|
7
|
-
fullWidth?: boolean;
|
|
8
|
-
loadingLimit?: number;
|
|
9
|
-
children: LoadingControlChildren;
|
|
10
|
-
}
|
|
11
|
-
export declare const LoadingControl: React.ForwardRefExoticComponent<LoadingControlProps & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
-
export {};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import React, { forwardRef, useEffect, useState } from "react";
|
|
15
|
-
import classNames from "classnames";
|
|
16
|
-
import boxingStyles from "../boxing.module.css";
|
|
17
|
-
import { DisplayOnVisible } from "..";
|
|
18
|
-
export const LoadingControl = forwardRef(function LoadingControl(_a, ref) {
|
|
19
|
-
var { align, fullWidth = true, loadingLimit = 200, className, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "loadingLimit", "className", "children"]);
|
|
20
|
-
const [maxTotalVisibledItems, setMaxTotalVisibledItems] = useState(3); // Min: default
|
|
21
|
-
const extraLoading = maxTotalVisibledItems * 2;
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
-
const [loadedItems, setLoadedItems] = useState([
|
|
24
|
-
React.cloneElement(children, {
|
|
25
|
-
index: 0,
|
|
26
|
-
}),
|
|
27
|
-
]);
|
|
28
|
-
const [visibilityStatus, setVisibilityStatus] = useState({});
|
|
29
|
-
const handleOnVisibilityChange = (visible, i) => {
|
|
30
|
-
if (i !== undefined)
|
|
31
|
-
if (visibilityStatus[i] !== visible)
|
|
32
|
-
setVisibilityStatus((prev) => (Object.assign(Object.assign({}, prev), { [i]: visible })));
|
|
33
|
-
};
|
|
34
|
-
const visibleIndexes = Object.entries(visibilityStatus)
|
|
35
|
-
// eslint-disable-next-line
|
|
36
|
-
.filter(([_, isVisible]) => isVisible)
|
|
37
|
-
.map(([index]) => parseInt(index));
|
|
38
|
-
const visibleCount = Object.values(visibilityStatus).filter(Boolean).length;
|
|
39
|
-
const lowestVisibleItemIndex = visibleIndexes.length
|
|
40
|
-
? Math.min(...visibleIndexes)
|
|
41
|
-
: 0;
|
|
42
|
-
const highestVisibleItemIndex = visibleIndexes.length
|
|
43
|
-
? Math.max(...visibleIndexes)
|
|
44
|
-
: 0;
|
|
45
|
-
const lowestLoadedItemIndex = loadedItems[0].props.index;
|
|
46
|
-
const highestLoadedItemIndex = loadedItems[loadedItems.length - 1].props.index;
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (highestLoadedItemIndex < loadingLimit &&
|
|
49
|
-
highestLoadedItemIndex < highestVisibleItemIndex + extraLoading) {
|
|
50
|
-
setLoadedItems([
|
|
51
|
-
...loadedItems,
|
|
52
|
-
React.cloneElement(children, {
|
|
53
|
-
index: highestLoadedItemIndex + 1,
|
|
54
|
-
}),
|
|
55
|
-
].slice(
|
|
56
|
-
// Slice from start
|
|
57
|
-
lowestVisibleItemIndex - lowestLoadedItemIndex >
|
|
58
|
-
extraLoading
|
|
59
|
-
? 1
|
|
60
|
-
: 0));
|
|
61
|
-
console.log(">>>>>>>>>>>>>>>>>>>>>>>> ++++ Item ", highestLoadedItemIndex + 1, " Added to end");
|
|
62
|
-
}
|
|
63
|
-
if (lowestLoadedItemIndex > 0 &&
|
|
64
|
-
lowestLoadedItemIndex > lowestVisibleItemIndex - extraLoading) {
|
|
65
|
-
setLoadedItems([
|
|
66
|
-
React.cloneElement(children, {
|
|
67
|
-
index: lowestLoadedItemIndex - 1,
|
|
68
|
-
}),
|
|
69
|
-
...loadedItems,
|
|
70
|
-
].slice(
|
|
71
|
-
// Slice from end
|
|
72
|
-
0, highestLoadedItemIndex - highestVisibleItemIndex >
|
|
73
|
-
extraLoading
|
|
74
|
-
? -1
|
|
75
|
-
: undefined));
|
|
76
|
-
console.log(">>>>>>>>>>>> ---- Item ", lowestLoadedItemIndex - 1, " Added to start");
|
|
77
|
-
}
|
|
78
|
-
if (visibleCount > maxTotalVisibledItems) {
|
|
79
|
-
setMaxTotalVisibledItems(visibleCount);
|
|
80
|
-
}
|
|
81
|
-
// eslint-disable-next-line
|
|
82
|
-
}, [visibilityStatus]);
|
|
83
|
-
console.log("###### ", "Total Loaded:", loadedItems.length, "extraLoading:", extraLoading, " ##### ", "L:", lowestLoadedItemIndex, "V:", lowestVisibleItemIndex, "D:", -(lowestLoadedItemIndex - lowestVisibleItemIndex), "|", "V:", visibleCount, "|", "D:", highestLoadedItemIndex - highestVisibleItemIndex, "V:", highestVisibleItemIndex, "L:", highestLoadedItemIndex);
|
|
84
|
-
// console.log("visibilityStatus", visibilityStatus);
|
|
85
|
-
// console.log(
|
|
86
|
-
// "loadedItems",
|
|
87
|
-
// loadedItems.map((item) => item.props.index)
|
|
88
|
-
// );
|
|
89
|
-
// console.log(
|
|
90
|
-
// "visibilityStatus.length",
|
|
91
|
-
// Object.keys(visibilityStatus).length
|
|
92
|
-
// );
|
|
93
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, className);
|
|
94
|
-
return (_jsx("div", Object.assign({ ref: ref, className: joinedClassNames }, restProps, { children: loadedItems.map((item) => (_jsx(DisplayOnVisible, { onVisibilityChange: (visible) => handleOnVisibilityChange(visible, item.props.index), children: item }, item.props.index))) })));
|
|
95
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export interface RenderOnVisibleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
-
align?: "start" | "space" | "center" | "end";
|
|
4
|
-
fullWidth?: boolean;
|
|
5
|
-
onVisibilityChange?: (visible: boolean) => void;
|
|
6
|
-
onVisible?: () => void;
|
|
7
|
-
onHidden?: () => void;
|
|
8
|
-
children?: React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
export declare const RenderOnVisible: import("react").ForwardRefExoticComponent<RenderOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
15
|
-
import classNames from "classnames";
|
|
16
|
-
import boxingStyles from "../boxing.module.css";
|
|
17
|
-
import { WithInteractions } from "..";
|
|
18
|
-
export const RenderOnVisible = forwardRef(function RenderOnVisible(_a, forwardedRef) {
|
|
19
|
-
var { align, fullWidth = true, onVisibilityChange, onVisible, onHidden, className, style, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "onVisibilityChange", "onVisible", "onHidden", "className", "style", "children"]);
|
|
20
|
-
const localRef = useRef(null);
|
|
21
|
-
// Let the parent access our DOM node
|
|
22
|
-
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
23
|
-
const [boxHeight, setBoxHeight] = useState(0);
|
|
24
|
-
const isVisible = boxHeight === 0;
|
|
25
|
-
const handleOnVisible = () => {
|
|
26
|
-
setBoxHeight(0);
|
|
27
|
-
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(true);
|
|
28
|
-
onVisible === null || onVisible === void 0 ? void 0 : onVisible();
|
|
29
|
-
};
|
|
30
|
-
const handleOnHidden = () => {
|
|
31
|
-
if (localRef.current) {
|
|
32
|
-
const boxRect = localRef.current.getBoundingClientRect();
|
|
33
|
-
setBoxHeight(boxRect.height);
|
|
34
|
-
}
|
|
35
|
-
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(false);
|
|
36
|
-
onHidden === null || onHidden === void 0 ? void 0 : onHidden();
|
|
37
|
-
};
|
|
38
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, className);
|
|
39
|
-
return (_jsx(WithInteractions, { onVisible: handleOnVisible, onHidden: handleOnHidden, children: _jsx("div", Object.assign({ ref: localRef }, restProps, { className: joinedClassNames, style: Object.assign({ height: boxHeight || "auto" }, style), children: isVisible && children })) }));
|
|
40
|
-
});
|