@yakad/ui 1.3.136 → 1.3.138
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/RenderByVisibility/RenderByVisibility.d.ts +9 -0
- package/dist/RenderByVisibility/RenderByVisibility.js +69 -0
- package/dist/Screen/Screen.js +1 -1
- package/dist/Theme/Theme.js +1 -1
- package/dist/WithInteractions/WithInteractions.d.ts +1 -1
- package/dist/WithInteractions/WithInteractions.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -3
- package/dist/LoadingControlV3/LoadingControlV3.d.ts +0 -12
- package/dist/LoadingControlV3/LoadingControlV3.js +0 -94
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface RenderByVisibilityProps {
|
|
3
|
+
extraRender?: number;
|
|
4
|
+
jump?: number;
|
|
5
|
+
stopRendering?: boolean;
|
|
6
|
+
newChildRendered?: (index: number) => void;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare const RenderByVisibility: React.ForwardRefExoticComponent<RenderByVisibilityProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,69 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import React, { forwardRef, useEffect, useRef, useState } from "react";
|
|
15
|
+
import { Card, LoadingIcon, Stack, WithInteractions } from "..";
|
|
16
|
+
const data = Array.from({ length: 78 });
|
|
17
|
+
export const RenderByVisibility = forwardRef(function RenderByVisibility(_a, ref) {
|
|
18
|
+
var { extraRender = 5, jump = 0, stopRendering, newChildRendered, children } = _a, restProps = __rest(_a, ["extraRender", "jump", "stopRendering", "newChildRendered", "children"]);
|
|
19
|
+
const childRefs = useRef({});
|
|
20
|
+
const childrenArray = React.Children.toArray(children);
|
|
21
|
+
// Collect Visibility Status
|
|
22
|
+
const [visibled, setVisibled] = useState({ lowest: jump, highest: jump });
|
|
23
|
+
const handleOnVisible = (i) => {
|
|
24
|
+
if (i < visibled.lowest)
|
|
25
|
+
setVisibled(Object.assign(Object.assign({}, visibled), { lowest: i }));
|
|
26
|
+
if (i > visibled.highest)
|
|
27
|
+
setVisibled(Object.assign(Object.assign({}, visibled), { highest: i }));
|
|
28
|
+
};
|
|
29
|
+
// Collect Rendered Childs Status
|
|
30
|
+
const [rendered, setRendered] = useState({ lowest: jump, highest: jump });
|
|
31
|
+
// Calculate Over Screen Renders
|
|
32
|
+
const overRenderedOnLowSide = visibled.lowest - rendered.lowest;
|
|
33
|
+
const overRenderedOnHighSide = rendered.highest - visibled.highest;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!stopRendering) {
|
|
36
|
+
if (rendered.highest < data.length &&
|
|
37
|
+
overRenderedOnHighSide < extraRender) {
|
|
38
|
+
setRendered(Object.assign(Object.assign({}, rendered), { highest: rendered.highest + 1 }));
|
|
39
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(rendered.highest + 1);
|
|
40
|
+
}
|
|
41
|
+
else if (rendered.lowest > 0 &&
|
|
42
|
+
overRenderedOnLowSide < extraRender) {
|
|
43
|
+
setRendered(Object.assign(Object.assign({}, rendered), { lowest: rendered.lowest - 1 }));
|
|
44
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(rendered.lowest - 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, [visibled, rendered, stopRendering]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
var _a;
|
|
50
|
+
if (overRenderedOnHighSide == 1) {
|
|
51
|
+
(_a = childRefs.current[jump]) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
|
|
52
|
+
console.log("SCROLL TO JUMP");
|
|
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");
|
|
60
|
+
}
|
|
61
|
+
}, [overRenderedOnHighSide]);
|
|
62
|
+
console.log("visibled", visibled);
|
|
63
|
+
console.log("rendered", rendered);
|
|
64
|
+
console.log("stopRendering", stopRendering);
|
|
65
|
+
return (_jsxs(Stack, Object.assign({ ref: ref }, restProps, { children: [rendered.lowest > 0 && (_jsx(Stack, { style: { height: "20rem" }, children: _jsx(LoadingIcon, { variant: "dots", size: "extraLarge" }) })), childrenArray.map((child, i) => i >= rendered.lowest &&
|
|
66
|
+
i <= rendered.highest && (_jsx(WithInteractions, { ref: (el) => {
|
|
67
|
+
childRefs.current[i] = el;
|
|
68
|
+
}, onVisible: () => handleOnVisible(i), children: child }, i))), rendered.highest < data.length && (_jsx(Card, { children: _jsx(LoadingIcon, { variant: "dots", size: "extraLarge" }) }))] })));
|
|
69
|
+
});
|
package/dist/Screen/Screen.js
CHANGED
|
@@ -16,6 +16,6 @@ import boxingStyles from "../boxing.module.css";
|
|
|
16
16
|
import styles from "./Screen.module.css";
|
|
17
17
|
export const Screen = forwardRef(function Screen(_a, ref) {
|
|
18
18
|
var { align, className, children } = _a, restProps = __rest(_a, ["align", "className", "children"]);
|
|
19
|
-
const joinedClassNames = classNames(
|
|
19
|
+
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.screen, className);
|
|
20
20
|
return (_jsx("div", Object.assign({ ref: ref }, restProps, { className: joinedClassNames, children: children })));
|
|
21
21
|
});
|
package/dist/Theme/Theme.js
CHANGED
|
@@ -22,6 +22,6 @@ export const Theme = forwardRef(function Theme(_a, ref) {
|
|
|
22
22
|
useEffect(() => {
|
|
23
23
|
document.documentElement.style.setProperty("font-size", zoomPercentage + "%");
|
|
24
24
|
}, [zoomPercentage]);
|
|
25
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.theme, styles[darkStyle], styles[color], className);
|
|
25
|
+
const joinedClassNames = classNames("portalRoot", boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.theme, styles[darkStyle], styles[color], className);
|
|
26
26
|
return (_jsx("div", Object.assign({ ref: ref }, restProps, { className: joinedClassNames, children: children })));
|
|
27
27
|
});
|
|
@@ -19,6 +19,6 @@ export interface WithInteractionsProps {
|
|
|
19
19
|
onHidden?: () => void;
|
|
20
20
|
onMouseHoverStart?: (e: MouseEvent) => void;
|
|
21
21
|
onMouseHoverLeave?: (e: MouseEvent) => void;
|
|
22
|
-
children?: React.
|
|
22
|
+
children?: React.ReactNode;
|
|
23
23
|
}
|
|
24
24
|
export declare const WithInteractions: import("react").ForwardRefExoticComponent<WithInteractionsProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -10,6 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
import { mergeRefs } from "@yakad/lib";
|
|
14
15
|
import { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef, } from "react";
|
|
15
16
|
export const WithInteractions = forwardRef(function WithInteractions(_a, forwardedRef) {
|
|
@@ -216,6 +217,7 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
|
|
|
216
217
|
]);
|
|
217
218
|
if (!isValidElement(children))
|
|
218
219
|
return null;
|
|
220
|
+
return _jsx("div", { ref: localRef, children: children });
|
|
219
221
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
220
222
|
return cloneElement(children, Object.assign(Object.assign({}, restProps), { ref: mergeRefs(localRef, forwardedRef,
|
|
221
223
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,6 @@ export * from "./WithOverlay/WithOverlay";
|
|
|
33
33
|
export * from "./Dropdown/Dropdown";
|
|
34
34
|
export * from "./Popup/Popup";
|
|
35
35
|
export * from "./LoadingControl/LoadingControl";
|
|
36
|
-
export * from "./
|
|
36
|
+
export * from "./RenderByVisibility/RenderByVisibility";
|
|
37
37
|
export * from "./DisplayOnVisible/DisplayOnVisible";
|
|
38
38
|
export * from "./RenderOnVisible/RenderOnVisible";
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,6 @@ export * from "./Dropdown/Dropdown";
|
|
|
40
40
|
export * from "./Popup/Popup";
|
|
41
41
|
// Loading Control
|
|
42
42
|
export * from "./LoadingControl/LoadingControl";
|
|
43
|
-
export * from "./
|
|
43
|
+
export * from "./RenderByVisibility/RenderByVisibility";
|
|
44
44
|
export * from "./DisplayOnVisible/DisplayOnVisible";
|
|
45
45
|
export * from "./RenderOnVisible/RenderOnVisible";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakad/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.138",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Natiq",
|
|
6
6
|
"description": "UI components for NextJS/React",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"typecheck": "tsc --noEmit",
|
|
29
29
|
"lint": "eslint src/**/*.{ts,tsx}",
|
|
30
30
|
"test": "echo \"No tests specified\" && exit 0",
|
|
31
|
-
"prepublishOnly": "npm run lint && npm run test && npm run build && npm run typecheck"
|
|
32
|
-
"newPublish": "npm version patch && npm publish"
|
|
31
|
+
"prepublishOnly": "npm run lint && npm run test && npm run build && npm run typecheck"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"@yakad/lib": "1.0.22",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
type LoadingControlV3Children = React.ReactElement<{
|
|
3
|
-
index?: number;
|
|
4
|
-
}>;
|
|
5
|
-
export interface LoadingControlV3Props extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
-
align?: "start" | "space" | "center" | "end";
|
|
7
|
-
fullWidth?: boolean;
|
|
8
|
-
loadingLimit?: number;
|
|
9
|
-
children: LoadingControlV3Children;
|
|
10
|
-
}
|
|
11
|
-
export declare const LoadingControlV3: React.ForwardRefExoticComponent<LoadingControlV3Props & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
-
export {};
|
|
@@ -1,94 +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 LoadingControlV3 = forwardRef(function LoadingControlV3(_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
|
-
const [loadedItems, setLoadedItems] = useState({
|
|
23
|
-
0: React.cloneElement(children, {
|
|
24
|
-
index: 0,
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
const [visibilityStatus, setVisibilityStatus] = useState({});
|
|
28
|
-
const handleOnVisibilityChange = (visible, i) => {
|
|
29
|
-
if (i !== undefined)
|
|
30
|
-
if (visibilityStatus[i] !== visible)
|
|
31
|
-
setVisibilityStatus((prev) => (Object.assign(Object.assign({}, prev), { [i]: visible })));
|
|
32
|
-
};
|
|
33
|
-
const visibleIndexes = Object.entries(visibilityStatus)
|
|
34
|
-
// eslint-disable-next-line
|
|
35
|
-
.filter(([_, isVisible]) => isVisible)
|
|
36
|
-
.map(([index]) => parseInt(index));
|
|
37
|
-
const visibleCount = Object.values(visibilityStatus).filter(Boolean).length;
|
|
38
|
-
const lowestVisibleItemIndex = visibleIndexes.length
|
|
39
|
-
? Math.min(...visibleIndexes)
|
|
40
|
-
: 0;
|
|
41
|
-
const highestVisibleItemIndex = visibleIndexes.length
|
|
42
|
-
? Math.max(...visibleIndexes)
|
|
43
|
-
: 0;
|
|
44
|
-
const loadedItemsLength = Object.values(loadedItems).length;
|
|
45
|
-
const lowestLoadedItemIndex = Number(Object.keys(loadedItems)[0]);
|
|
46
|
-
const highestLoadedItemIndex = Number(Object.keys(loadedItems)[loadedItemsLength - 1]);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (highestLoadedItemIndex < loadingLimit &&
|
|
49
|
-
highestLoadedItemIndex - highestVisibleItemIndex < extraLoading) {
|
|
50
|
-
setLoadedItems(Object.assign(Object.assign({}, loadedItems), { [highestLoadedItemIndex + 1]: React.cloneElement(children, {
|
|
51
|
-
index: highestLoadedItemIndex + 1,
|
|
52
|
-
}) }));
|
|
53
|
-
console.log(">>>>>>>>>>>>>>>>>>>>>>>> ++++ Item ", highestLoadedItemIndex + 1, " Added to end");
|
|
54
|
-
}
|
|
55
|
-
if (lowestLoadedItemIndex > 0 &&
|
|
56
|
-
lowestVisibleItemIndex - lowestLoadedItemIndex < extraLoading) {
|
|
57
|
-
setLoadedItems(Object.assign({ [lowestLoadedItemIndex - 1]: React.cloneElement(children, {
|
|
58
|
-
index: lowestLoadedItemIndex - 1,
|
|
59
|
-
}) }, loadedItems));
|
|
60
|
-
console.log(">>>>>>>>>>>> ---- Item ", lowestLoadedItemIndex - 1, " Added to start");
|
|
61
|
-
}
|
|
62
|
-
if (visibleCount > maxTotalVisibledItems) {
|
|
63
|
-
setMaxTotalVisibledItems(visibleCount);
|
|
64
|
-
}
|
|
65
|
-
// eslint-disable-next-line
|
|
66
|
-
}, [visibilityStatus]);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const loadLimit = extraLoading + 2;
|
|
69
|
-
if (lowestVisibleItemIndex - lowestLoadedItemIndex > loadLimit) {
|
|
70
|
-
setLoadedItems(removeFromStart(loadedItems, lowestVisibleItemIndex - loadLimit));
|
|
71
|
-
console.log("$$$$$$$$$$$ Sliced $$$$$$$$$$$$$$$$$$$$$ from start smaller than:", lowestVisibleItemIndex - loadLimit);
|
|
72
|
-
}
|
|
73
|
-
if (highestLoadedItemIndex - highestVisibleItemIndex > loadLimit) {
|
|
74
|
-
setLoadedItems(removeFromEnd(loadedItems, highestVisibleItemIndex + loadLimit));
|
|
75
|
-
console.log("$$$$$$$$$$$ Sliced $$$$$$$$$$$$$$$$$$$$$ from end bigger than:", highestVisibleItemIndex + loadLimit);
|
|
76
|
-
}
|
|
77
|
-
// eslint-disable-next-line
|
|
78
|
-
}, [loadedItems, visibilityStatus]);
|
|
79
|
-
console.log("###### ", "Total Loaded:", loadedItemsLength, "extraLoading:", extraLoading, " ##### ", "L:", lowestLoadedItemIndex, "V:", lowestVisibleItemIndex, "D:", -(lowestLoadedItemIndex - lowestVisibleItemIndex), "|", "TV:", visibleCount, "|", "D:", highestLoadedItemIndex - highestVisibleItemIndex, "V:", highestVisibleItemIndex, "L:", highestLoadedItemIndex);
|
|
80
|
-
// console.log("visibilityStatus", visibilityStatus);
|
|
81
|
-
// console.log("loadedItems", loadedItems);
|
|
82
|
-
// console.log(
|
|
83
|
-
// "visibilityStatus.length",
|
|
84
|
-
// Object.keys(visibilityStatus).length
|
|
85
|
-
// );
|
|
86
|
-
const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, className);
|
|
87
|
-
return (_jsx("div", Object.assign({ ref: ref, className: joinedClassNames }, restProps, { children: Object.entries(loadedItems).map(([key, value]) => (_jsx(DisplayOnVisible, { onVisibilityChange: (visible) => handleOnVisibilityChange(visible, Number(key)), children: value }, key))) })));
|
|
88
|
-
});
|
|
89
|
-
function removeFromStart(obj, start) {
|
|
90
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => Number(key) >= start));
|
|
91
|
-
}
|
|
92
|
-
function removeFromEnd(obj, end) {
|
|
93
|
-
return Object.fromEntries(Object.entries(obj).filter(([key]) => Number(key) <= end));
|
|
94
|
-
}
|