@yakad/ui 1.3.133 → 1.3.136

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.
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
- type LoadingControlV2Children = React.ReactElement<{
2
+ type LoadingControlChildren = React.ReactElement<{
3
3
  index?: number;
4
4
  }>;
5
- export interface LoadingControlV2Props extends React.HTMLAttributes<HTMLDivElement> {
5
+ export interface LoadingControlProps extends React.HTMLAttributes<HTMLDivElement> {
6
6
  align?: "start" | "space" | "center" | "end";
7
7
  fullWidth?: boolean;
8
8
  loadingLimit?: number;
9
- children: LoadingControlV2Children;
9
+ children: LoadingControlChildren;
10
10
  }
11
- export declare const LoadingControlV2: React.ForwardRefExoticComponent<LoadingControlV2Props & React.RefAttributes<HTMLDivElement>>;
11
+ export declare const LoadingControl: React.ForwardRefExoticComponent<LoadingControlProps & React.RefAttributes<HTMLDivElement>>;
12
12
  export {};
@@ -15,7 +15,7 @@ import React, { forwardRef, useEffect, useState } from "react";
15
15
  import classNames from "classnames";
16
16
  import boxingStyles from "../boxing.module.css";
17
17
  import { DisplayOnVisible } from "..";
18
- export const LoadingControlV2 = forwardRef(function LoadingControlV2(_a, ref) {
18
+ export const LoadingControl = forwardRef(function LoadingControl(_a, ref) {
19
19
  var { align, fullWidth = true, loadingLimit = 200, className, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "loadingLimit", "className", "children"]);
20
20
  const [maxTotalVisibledItems, setMaxTotalVisibledItems] = useState(3); // Min: default
21
21
  const extraLoading = maxTotalVisibledItems * 2;
@@ -0,0 +1,12 @@
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 {};
@@ -0,0 +1,94 @@
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
+ }
@@ -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(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.screen, className);
19
+ const joinedClassNames = classNames("portalRoot", boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, styles.screen, className);
20
20
  return (_jsx("div", Object.assign({ ref: ref }, restProps, { className: joinedClassNames, children: children })));
21
21
  });
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { useState, cloneElement, useEffect, useRef } from "react";
4
4
  import { WithInteractions, } from "..";
5
5
  import { mergeRefs } from "@yakad/lib";
6
+ import { createPortal } from "react-dom";
6
7
  export function WithOverlay({ trigger = "onClick", overlay, children, }) {
7
8
  var _a;
8
9
  const triggerRef = useRef(null);
@@ -26,12 +27,13 @@ export function WithOverlay({ trigger = "onClick", overlay, children, }) {
26
27
  },
27
28
  }) }), showOverlay &&
28
29
  overlay &&
29
- cloneElement(overlay, {
30
+ createPortal(cloneElement(overlay, {
30
31
  triggerref: triggerRef,
31
32
  onClose: () => {
32
33
  var _a, _b;
33
34
  (_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
34
35
  setShowOverlay(false);
35
36
  },
36
- })] }));
37
+ }), document.getElementsByClassName("portalRoot")[0] ||
38
+ document.body)] }));
37
39
  }
package/dist/index.d.ts CHANGED
@@ -33,5 +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 "./LoadingControlV3/LoadingControlV3";
36
37
  export * from "./DisplayOnVisible/DisplayOnVisible";
37
38
  export * from "./RenderOnVisible/RenderOnVisible";
package/dist/index.js CHANGED
@@ -40,5 +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 "./LoadingControlV3/LoadingControlV3";
43
44
  export * from "./DisplayOnVisible/DisplayOnVisible";
44
45
  export * from "./RenderOnVisible/RenderOnVisible";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakad/ui",
3
- "version": "1.3.133",
3
+ "version": "1.3.136",
4
4
  "private": false,
5
5
  "author": "Natiq",
6
6
  "description": "UI components for NextJS/React",