aefis-core-ui 2.4.1 → 2.4.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.
@@ -89,6 +89,7 @@ import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
89
89
  import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
90
90
  import { v4 } from 'uuid';
91
91
  import produce from 'immer';
92
+ import { Scrollbars } from 'react-custom-scrollbars-2';
92
93
  import { GridColumnMenu, GridFooterContainer, GridPagination, GridRowCount, useGridApiRef, DataGridPro } from '@mui/x-data-grid-pro';
93
94
  import { MuiForm5 } from '@rjsf/material-ui';
94
95
  import isEmpty from 'lodash/isEmpty';
@@ -26158,367 +26159,97 @@ TextBuilder.propTypes = {
26158
26159
  };
26159
26160
  var TextBuilder$1 = withStore(TextBuilder);
26160
26161
 
26161
- const ScrollBarContent = /*#__PURE__*/React__default.forwardRef(({
26162
- children,
26163
- sx
26164
- }, ref) => {
26165
- return /*#__PURE__*/jsx(Box$2, {
26166
- sx: _extends({}, sx, {
26167
- overflow: "auto",
26168
- position: "relative",
26169
- "&::-webkit-scrollbar": {
26170
- display: "none"
26171
- }
26172
- }),
26173
- ref: ref,
26174
- children: children
26175
- });
26176
- });
26177
-
26178
- const ScrollBarContainer = /*#__PURE__*/React__default.forwardRef(({
26179
- children,
26180
- isDragging
26181
- }, ref) => {
26182
- return /*#__PURE__*/jsx(Box$2, {
26183
- id: "custom-scrollbars__scrollbar",
26184
- sx: {
26185
- display: "flex",
26186
- justifyContent: "center"
26187
- },
26188
- children: /*#__PURE__*/jsx(Box$2, {
26189
- id: "custom-scrollbars__track-and-thumb",
26190
- sx: [{
26191
- display: "block",
26192
- height: "100%",
26193
- position: "relative",
26194
- width: "9px",
26195
- transition: "0.2s",
26196
- zIndex: 9
26197
- }, isDragging && {
26198
- width: 13
26199
- }, {
26200
- "&:hover": {
26201
- width: "13px"
26202
- }
26203
- }],
26204
- children: children
26205
- })
26206
- });
26207
- });
26208
-
26209
- const ScrollBarTrack = /*#__PURE__*/React__default.forwardRef(({
26210
- sx,
26211
- onClick
26212
- }, ref) => {
26213
- return /*#__PURE__*/jsx(Box$2, {
26214
- id: "custom-scrollbars__track",
26215
- sx: [_extends({
26216
- bgcolor: "#eee",
26217
- opacity: 0.9,
26218
- borderRadius: "12px"
26219
- }, sx, {
26220
- height: "100%",
26221
- width: "inherit"
26222
- })],
26223
- ref: ref,
26224
- onClick: onClick
26225
- });
26226
- });
26227
-
26228
- const ScrollBarThumb = /*#__PURE__*/React__default.forwardRef(({
26229
- thumbHeight,
26230
- isDragging,
26231
- onMouseDown,
26232
- sx,
26233
- thumbPosition
26234
- }, ref) => {
26235
- return /*#__PURE__*/jsx(Box$2, {
26236
- id: "custom-scrollbars__thumb",
26237
- ref: ref,
26238
- sx: _extends({
26239
- borderRadius: "12px",
26240
- bgcolor: "#aaa"
26241
- }, sx, {
26242
- position: "absolute",
26243
- width: "inherit",
26244
- height: thumbHeight,
26245
- cursor: isDragging ? "grabbing" : "grab",
26246
- top: thumbPosition
26247
- }),
26248
- onMouseDown: onMouseDown
26249
- });
26250
- });
26251
-
26252
- const _excluded$5 = ["children", "height", "thumbHeight", "scrollBarSx", "scrollBarContentSx", "scrollBarTrackSx", "scrollBarThumbSx", "showTopFade", "showBottomFade", "component", "onScrollReachStart", "onScrollReachEnd", "onScroll"];
26162
+ const _excluded$5 = ["children", "height", "showTopFade", "showBottomFade", "component", "onScrollReachStart", "onScrollReachEnd", "onScroll", "scrollBarsProps"];
26163
+ const calculatePercentage = (value, maxValue) => {
26164
+ if (maxValue === 0) return 0;
26165
+ return Math.floor(value / maxValue * 100);
26166
+ };
26253
26167
  const ScrollingContainer = _ref => {
26254
26168
  let {
26255
26169
  children,
26256
26170
  height = "100%",
26257
- thumbHeight = 20,
26258
- scrollBarSx = {},
26259
- scrollBarContentSx = {},
26260
- scrollBarTrackSx = {},
26261
- scrollBarThumbSx = {},
26262
26171
  showTopFade = true,
26263
26172
  showBottomFade = true,
26264
26173
  component: Component = Box$2,
26265
26174
  onScrollReachStart,
26266
26175
  onScrollReachEnd,
26267
- onScroll
26176
+ onScroll,
26177
+ scrollBarsProps
26268
26178
  } = _ref,
26269
26179
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
26270
- /*
26271
- * Refs for Content Box, Scroll Track And Scroll Thumb
26272
- * */
26273
- const contentRef = useRef(null);
26274
- const scrollTrackRef = useRef(null);
26275
- const scrollThumbRef = useRef(null);
26276
- const wrapperRef = useRef(null);
26277
- /*
26278
- Resize observer is for scroll tracking
26279
- */
26280
- const observer = useRef(null);
26281
-
26282
- /**
26283
- * thumbHeightState : Uncontrolled state, it will set the thumb's minimum height
26284
- * scrollStartPosition: when the user grabs the thumb it's first scrolltop will be setted to this state
26285
- * initialScrollTop: when the user grabs the thumb container's scrolltop position will be setted to this state.
26286
- * isDragging: when the user grabs the thumb it will be true.
26287
- * hasOverflowingChildren: control for overflow if not overflowing then there is no need for scrollbar
26288
- * thumbPosition: dynamically gets the thumb's position
26289
- */
26290
-
26291
- const [thumbHeightState, setThumbHeightState] = useState(1);
26292
- const [scrollStartPosition, setScrollStartPosition] = useState(null);
26293
- const [initialScrollTop, setInitialScrollTop] = useState(0);
26294
- const [isDragging, setIsDragging] = useState(false);
26295
- const [thumbPosition, setThumbPosition] = useState(-1);
26296
- const [hasOverflowingChildren, setHasOverflowingChildren] = useState(true);
26297
-
26298
- /**
26299
- * HandleThumbMouseDown function is used for
26300
- * - when user grabs the thumb this function will set the isDragging state to true
26301
- * - it will get where the user started to grab the thumb -> scrollStartPosition
26302
- * @returns {void}
26303
- */
26304
- const handleThumbMousedown = useCallback(e => {
26305
- e.preventDefault();
26306
- e.stopPropagation();
26307
- setScrollStartPosition(e.clientY);
26308
- if (contentRef.current) setInitialScrollTop(contentRef.current.scrollTop);
26309
- setIsDragging(true);
26310
- }, []);
26311
-
26312
- /**
26313
- * When the user leaves the thumb isDragging will be false
26314
- *
26315
- */
26316
- const handleThumbMouseup = useCallback(e => {
26317
- e.preventDefault();
26318
- e.stopPropagation();
26319
- if (isDragging) {
26320
- setIsDragging(false);
26321
- }
26322
- }, [isDragging]);
26323
-
26324
- /**
26325
- * if the user is dragging the thumb
26326
- * - it will get content's scroll height and offset height
26327
- * - calculate the deltaY (Subtract the current mouse y position from where you started to get the pixel difference in mouse position. Multiply by ratio of visible content height to thumb height to scale up the difference for content scrolling.)
26328
- * - get the minimum value (in this case max value is contentScrollHeight - contentOffsetHeight and deltaY works with screen height. if initialScrollTop + deltaY > contentScrollHeight - contentOffsetHeight then it has to be the minimum value)
26329
- * - set contentRef.scrollTop to new value
26330
- */
26331
- const handleThumbMousemove = useCallback(e => {
26332
- e.preventDefault();
26333
- e.stopPropagation();
26334
- if (isDragging) {
26335
- const {
26336
- scrollHeight: contentScrollHeight,
26337
- offsetHeight: contentOffsetHeight
26338
- } = contentRef.current;
26339
- const deltaY = (e.clientY - scrollStartPosition) * (contentOffsetHeight / thumbHeightState);
26340
- const newScrollTop = Math.min(initialScrollTop + deltaY, contentScrollHeight - contentOffsetHeight);
26341
- contentRef.current.scrollTop = newScrollTop;
26180
+ const scrollBarRef = useRef();
26181
+ const [ariaScrollValues, setAriaScrollValues] = useState({
26182
+ horizontal: 0,
26183
+ vertical: 0
26184
+ });
26185
+ const onScrollEvent = useCallback(event => {
26186
+ setAriaScrollValues({
26187
+ vertical: calculatePercentage(event.target.scrollTop, event.target.scrollHeight - event.target.clientHeight),
26188
+ horizontal: calculatePercentage(event.target.scrollLeft, event.target.scrollWidth - event.target.clientWidth)
26189
+ });
26190
+ onScroll && onScroll(event);
26191
+ if (Math.round(event.target.scrollTop) === event.target.scrollHeight - event.target.clientHeight) {
26192
+ onScrollReachEnd && onScrollReachEnd(event);
26342
26193
  }
26343
- }, [isDragging, scrollStartPosition, thumbHeightState]);
26344
-
26345
- /**
26346
- * When user scrolls
26347
- * - first we need to calculate ratio.
26348
- * - we get content's scrollTop and ScrollHeight, scrollTrack's Height
26349
- * - to calculate the ratio we need to divide content's scrollTop to scrollHeight to get the ratio and then multiply it with trackHeight
26350
- * - with math.min if scrolling > trackHeight - thumbHeightSize it will be setted to (trackHeight - thumbHeightSize)
26351
- */
26352
- const handleThumbPosition = useCallback(() => {
26353
- if (!contentRef.current || !scrollTrackRef.current || !scrollThumbRef.current) {
26354
- return;
26194
+ if (event.target.scrollTop === 0) {
26195
+ onScrollReachStart && onScrollReachStart(event);
26355
26196
  }
26356
- const {
26357
- scrollTop: contentTop,
26358
- scrollHeight: contentHeight
26359
- } = contentRef.current;
26360
- const {
26361
- clientHeight: trackHeight
26362
- } = scrollTrackRef.current;
26363
- let newTop = +contentTop / +contentHeight * trackHeight;
26364
- newTop = Math.min(newTop, trackHeight - thumbHeightState);
26365
- setThumbPosition(newTop);
26366
26197
  }, []);
26367
-
26368
- /**
26369
- * - First, figure out where we clicked
26370
- * - Next, figure out the distance between the top of the track and the top of the viewport
26371
- * - We want the middle of the thumb to jump to where we clicked, so we subtract half the thumb's height to offset the position
26372
- * - Find the ratio of the new position to the total content length using the thumb and track values...
26373
- * - multiply ratio with scrollHeight to get the amount
26374
- *
26375
- * @param {any} (e
26376
- * @returns {any}
26377
- */
26378
- const handleTrackClick = useCallback(e => {
26379
- e.preventDefault();
26380
- e.stopPropagation();
26381
- const {
26382
- current: trackCurrent
26383
- } = scrollTrackRef;
26384
- const {
26385
- current: contentCurrent
26386
- } = contentRef;
26387
- if (trackCurrent && contentCurrent) {
26388
- const {
26389
- clientY
26390
- } = e;
26391
- const target = e.target;
26392
- const rect = target.getBoundingClientRect();
26393
- const trackTop = rect.top;
26394
- const thumbOffset = -(thumbHeight / 2);
26395
- const clickRatio = (clientY - trackTop + thumbOffset) / trackCurrent.clientHeight;
26396
- const scrollAmount = Math.floor(clickRatio * contentCurrent.scrollHeight);
26397
- contentCurrent.scrollTo({
26398
- top: scrollAmount
26399
- });
26400
- }
26401
- }, [thumbHeight]);
26402
-
26403
- /**
26404
- * This useEffect checks if the user scrolled to bottom or to top
26405
- */
26406
- useEffect(() => {
26407
- if (contentRef.current) {
26408
- var _contentRef$current;
26409
- if (thumbPosition + thumbHeightState >= ((_contentRef$current = contentRef.current) == null ? void 0 : _contentRef$current.clientHeight)) {
26410
- onScrollReachEnd && onScrollReachEnd();
26411
- }
26412
- if (thumbPosition == 0) {
26413
- onScrollReachStart && onScrollReachStart();
26414
- }
26415
- //this is for datatable to determine if the user is scrolled or not
26416
- const isScrolled = contentRef.current.scrollTop > 5 ? true : false;
26417
- onScroll && onScroll(isScrolled);
26418
- }
26419
- }, [thumbPosition]);
26420
-
26421
- /**
26422
- * ResizeObserver objects function. it will set the maximum height for thumb when this component resized.
26423
- * @param {any} ref
26424
- * @param {any} trackSize
26425
- * @returns {void}
26426
- */
26427
- function handleResize(ref, trackSize) {
26428
- const {
26429
- clientHeight,
26430
- scrollHeight
26431
- } = ref;
26432
- setThumbHeightState(Math.max(clientHeight / scrollHeight * trackSize, 20));
26433
- }
26434
-
26435
- /**
26436
- * hasOverflowChildren checks if the component has overflow or not
26437
- * observer sets itself to observe component size changes
26438
- * contentRef gets the handleThumbPosition scroll event
26439
- */
26440
-
26441
- useEffect(() => {
26442
- if (contentRef.current && scrollTrackRef.current) {
26443
- var _contentRef$current2;
26444
- const hasOverflowChildren = contentRef.current.offsetHeight < contentRef.current.scrollHeight || contentRef.current.offsetWidth < contentRef.current.scrollWidth;
26445
- if (!hasOverflowChildren) {
26446
- setHasOverflowingChildren(false);
26447
- return;
26448
- }
26449
- observer.current = new ResizeObserver(() => {
26450
- handleResize(contentRef == null ? void 0 : contentRef.current, scrollTrackRef.current.clientHeight);
26451
- });
26452
- observer.current.observe(contentRef.current);
26453
- (_contentRef$current2 = contentRef.current) == null ? void 0 : _contentRef$current2.addEventListener("scroll", handleThumbPosition);
26454
- return () => {
26455
- var _contentRef$current3, _observer$current;
26456
- if (!contentRef.current) return;
26457
- (_contentRef$current3 = contentRef.current) == null ? void 0 : _contentRef$current3.removeEventListener("scroll", handleThumbPosition);
26458
- (_observer$current = observer.current) == null ? void 0 : _observer$current.unobserve(contentRef == null ? void 0 : contentRef.current);
26459
- };
26460
- }
26461
- }, []);
26462
-
26463
- /**
26464
- * this useEffect is to set thumbMouseMoves
26465
- */
26466
- useEffect(() => {
26467
- document.addEventListener("mousemove", handleThumbMousemove);
26468
- document.addEventListener("mouseup", handleThumbMouseup);
26469
- document.addEventListener("mouseleave", handleThumbMouseup);
26470
- return () => {
26471
- document.removeEventListener("mousemove", handleThumbMousemove);
26472
- document.removeEventListener("mouseup", handleThumbMouseup);
26473
- document.removeEventListener("mouseleave", handleThumbMouseup);
26474
- };
26475
- }, [handleThumbMousemove, handleThumbMouseup]);
26476
- return /*#__PURE__*/jsxs(Component, _extends({}, rest, {
26477
- sx: _extends({}, scrollBarSx, {
26478
- height: height,
26479
- overflow: "hidden",
26198
+ return /*#__PURE__*/jsxs(Box$2, _extends({
26199
+ sx: {
26480
26200
  position: "relative",
26481
- gridTemplate: `auto / 1fr auto`,
26482
- display: "grid",
26483
- "&::-webkit-scrollbar": {
26484
- display: "none"
26485
- }
26486
- }),
26487
- ref: wrapperRef,
26201
+ height: height
26202
+ }
26203
+ }, rest, {
26488
26204
  children: [showTopFade && /*#__PURE__*/jsx(Box$2, {
26489
26205
  sx: {
26490
- width: "100%",
26206
+ width: "calc(100% - 10px)",
26491
26207
  bottom: "auto",
26492
26208
  top: 0,
26493
26209
  left: 0,
26494
26210
  height: "1rem",
26495
- position: "fixed",
26211
+ position: "absolute",
26496
26212
  zIndex: 4,
26497
26213
  content: '""',
26498
26214
  background: "linear-gradient(180deg,#fff 20%,hsla(0,0%,100%,0))",
26499
26215
  zIndex: 8
26500
26216
  }
26501
- }), /*#__PURE__*/jsx(ScrollBarContent, {
26502
- sx: scrollBarContentSx,
26503
- ref: contentRef,
26217
+ }), /*#__PURE__*/jsx(Scrollbars, _extends({
26218
+ id: "scrollbar-content"
26219
+ }, scrollBarsProps, {
26220
+ onScroll: onScrollEvent,
26221
+ ref: scrollBarRef,
26222
+ role: "scrollbar",
26223
+ renderTrackVertical: props => {
26224
+ return /*#__PURE__*/jsx("div", {
26225
+ "aria-controls": "scrollbar-content",
26226
+ "aria-orientation": "vertical",
26227
+ "aria-valuenow": ariaScrollValues.vertical,
26228
+ style: _extends({}, props.style, {
26229
+ bottom: 2,
26230
+ right: 2,
26231
+ top: 2,
26232
+ borderRadius: 3
26233
+ })
26234
+ });
26235
+ },
26236
+ renderTrackHorizontal: props => {
26237
+ return /*#__PURE__*/jsx("div", {
26238
+ "aria-controls": "scrollbar-content",
26239
+ "aria-orientation": "horizontal",
26240
+ "aria-valuenow": ariaScrollValues.horizontal,
26241
+ style: _extends({}, props.style, {
26242
+ right: 2,
26243
+ bottom: 2,
26244
+ left: 2,
26245
+ borderRadius: 3
26246
+ })
26247
+ });
26248
+ },
26504
26249
  children: children
26505
- }), hasOverflowingChildren && /*#__PURE__*/jsxs(ScrollBarContainer, {
26506
- isDragging: isDragging,
26507
- children: [/*#__PURE__*/jsx(ScrollBarTrack, {
26508
- sx: scrollBarTrackSx,
26509
- ref: scrollTrackRef,
26510
- onClick: handleTrackClick
26511
- }), /*#__PURE__*/jsx(ScrollBarThumb, {
26512
- ref: scrollThumbRef,
26513
- thumbHeight: thumbHeightState,
26514
- isDragging: isDragging,
26515
- onMouseDown: handleThumbMousedown,
26516
- sx: scrollBarThumbSx,
26517
- thumbPosition: thumbPosition
26518
- })]
26519
- }), showBottomFade && /*#__PURE__*/jsx(Box$2, {
26250
+ })), showBottomFade && /*#__PURE__*/jsx(Box$2, {
26520
26251
  sx: {
26521
- width: "100%",
26252
+ width: "calc(100% - 10px)",
26522
26253
  bottom: 0,
26523
26254
  top: "auto",
26524
26255
  left: 0,
@@ -26548,7 +26279,9 @@ ScrollingContainer.propTypes = {
26548
26279
  /** Function to handle when component scroll reaches the end or bottom. */
26549
26280
  onScrollReachEnd: PropTypes.func,
26550
26281
  /** Component used to render the container. */
26551
- component: PropTypes.string
26282
+ component: PropTypes.string,
26283
+ /**ScrollBars Props */
26284
+ scrollBarsProps: PropTypes.object
26552
26285
  };
26553
26286
 
26554
26287
  // Store the license information in a global, so it can be shared