@vitus-labs/elements 0.64.0 → 0.66.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.
@@ -74,7 +74,7 @@ var Styled$2 = config.styled(config.component) `
74
74
  })};
75
75
  `;
76
76
 
77
- const component$5 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
77
+ const component$4 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
78
78
  const debugProps = process.env.NODE_ENV !== 'production'
79
79
  ? {
80
80
  'data-vl-element': 'Element',
@@ -179,7 +179,7 @@ var Styled$1 = config.styled(config.component) `
179
179
  })};
180
180
  `;
181
181
 
182
- const Component$5 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
182
+ const Component$6 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
183
183
  const debugProps = process.env.NODE_ENV !== 'production'
184
184
  ? {
185
185
  'data-vl-element': contentType,
@@ -196,7 +196,7 @@ const Component$5 = ({ contentType, tag, parentDirection, direction, alignX, ali
196
196
  extraStyles: extendCss,
197
197
  }, ...debugProps, ...props }));
198
198
  };
199
- var component$4 = memo(Component$5);
199
+ var component$3 = memo(Component$6);
200
200
 
201
201
  const INLINE_ELEMENTS = {
202
202
  span: true,
@@ -264,7 +264,7 @@ const defaultDirection = 'inline';
264
264
  const defaultContentDirection = 'rows';
265
265
  const defaultAlignX = 'left';
266
266
  const defaultAlignY = 'center';
267
- const Component$4 = forwardRef(({ innerRef, tag, label, content, children, beforeContent, afterContent, block, equalCols, gap, direction, alignX = defaultAlignX, alignY = defaultAlignY, css, contentCss, beforeContentCss, afterContentCss, contentDirection = defaultContentDirection, contentAlignX = defaultAlignX, contentAlignY = defaultAlignY, beforeContentDirection = defaultDirection, beforeContentAlignX = defaultAlignX, beforeContentAlignY = defaultAlignY, afterContentDirection = defaultDirection, afterContentAlignX = defaultAlignX, afterContentAlignY = defaultAlignY, ...props }, ref) => {
267
+ const Component$5 = forwardRef(({ innerRef, tag, label, content, children, beforeContent, afterContent, block, equalCols, gap, direction, alignX = defaultAlignX, alignY = defaultAlignY, css, contentCss, beforeContentCss, afterContentCss, contentDirection = defaultContentDirection, contentAlignX = defaultAlignX, contentAlignY = defaultAlignY, beforeContentDirection = defaultDirection, beforeContentAlignX = defaultAlignX, beforeContentAlignY = defaultAlignY, afterContentDirection = defaultDirection, afterContentAlignX = defaultAlignX, afterContentAlignY = defaultAlignY, ...props }, ref) => {
268
268
  // --------------------------------------------------------
269
269
  // check if should render only single element
270
270
  // --------------------------------------------------------
@@ -325,18 +325,18 @@ const Component$4 = forwardRef(({ innerRef, tag, label, content, children, befor
325
325
  // return simple/empty element like input or image etc.
326
326
  // --------------------------------------------------------
327
327
  if (shouldBeEmpty) {
328
- return React.createElement(component$5, { ...props, ...WRAPPER_PROPS });
328
+ return React.createElement(component$4, { ...props, ...WRAPPER_PROPS });
329
329
  }
330
330
  const contentRenderOutput = render(CHILDREN);
331
- return (React.createElement(component$5, { ...props, ...WRAPPER_PROPS, isInline: isInline },
332
- beforeContent && (React.createElement(component$4, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, render(beforeContent))),
333
- isSimpleElement ? (contentRenderOutput) : (React.createElement(component$4, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
334
- afterContent && (React.createElement(component$4, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, render(afterContent)))));
331
+ return (React.createElement(component$4, { ...props, ...WRAPPER_PROPS, isInline: isInline },
332
+ beforeContent && (React.createElement(component$3, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, render(beforeContent))),
333
+ isSimpleElement ? (contentRenderOutput) : (React.createElement(component$3, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
334
+ afterContent && (React.createElement(component$3, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, render(afterContent)))));
335
335
  });
336
336
  const name$5 = `${PKG_NAME}/Element`;
337
- Component$4.displayName = name$5;
338
- Component$4.pkgName = PKG_NAME;
339
- Component$4.VITUS_LABS__COMPONENT = name$5;
337
+ Component$5.displayName = name$5;
338
+ Component$5.pkgName = PKG_NAME;
339
+ Component$5.VITUS_LABS__COMPONENT = name$5;
340
340
 
341
341
  // @ts-nocheck
342
342
  const isNumber = (a, b) => Number.isInteger(a) && Number.isInteger(b);
@@ -401,7 +401,7 @@ const attachItemProps = ({ i, length, }) => {
401
401
  position,
402
402
  };
403
403
  };
404
- const Component$3 = (props) => {
404
+ const Component$4 = (props) => {
405
405
  const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
406
406
  const injectItemProps = useMemo(() => (typeof itemProps === 'function' ? itemProps : () => itemProps), [itemProps]);
407
407
  const injectWrapItemProps = useMemo(() => (typeof wrapProps === 'function' ? wrapProps : () => wrapProps), [wrapProps]);
@@ -547,19 +547,19 @@ const Component$3 = (props) => {
547
547
  };
548
548
  return renderItems();
549
549
  };
550
- Component$3.isIterator = true;
551
- Component$3.RESERVED_PROPS = RESERVED_PROPS;
550
+ Component$4.isIterator = true;
551
+ Component$4.RESERVED_PROPS = RESERVED_PROPS;
552
552
 
553
- const component$3 = forwardRef(({ rootElement = false, ...props }, ref) => {
554
- const renderedList = React.createElement(Component$3, { ...pick(props, Component$3.RESERVED_PROPS) });
553
+ const component$2 = forwardRef(({ rootElement = false, ...props }, ref) => {
554
+ const renderedList = React.createElement(Component$4, { ...pick(props, Component$4.RESERVED_PROPS) });
555
555
  if (!rootElement)
556
556
  return renderedList;
557
- return (React.createElement(Component$4, { ref: ref, ...omit(props, Component$3.RESERVED_PROPS) }, renderedList));
557
+ return (React.createElement(Component$5, { ref: ref, ...omit(props, Component$4.RESERVED_PROPS) }, renderedList));
558
558
  });
559
559
  const name$4 = `${PKG_NAME}/List`;
560
- component$3.displayName = name$4;
561
- component$3.pkgName = PKG_NAME;
562
- component$3.VITUS_LABS__COMPONENT = name$4;
560
+ component$2.displayName = name$4;
561
+ component$2.pkgName = PKG_NAME;
562
+ component$2.VITUS_LABS__COMPONENT = name$4;
563
563
 
564
564
  // @ts-nocheck
565
565
  const RESERVED_KEYS = [
@@ -568,7 +568,7 @@ const RESERVED_KEYS = [
568
568
  'itemProps',
569
569
  'activeItemRequired',
570
570
  ];
571
- const component$2 = (WrappedComponent) => {
571
+ const component$1 = (WrappedComponent) => {
572
572
  const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
573
573
  const Enhanced = (props) => {
574
574
  const { type = 'single', activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
@@ -691,7 +691,7 @@ const component$2 = (WrappedComponent) => {
691
691
  return Enhanced;
692
692
  };
693
693
 
694
- const Component$2 = ({ DOMLocation, tag = 'div', children, }) => {
694
+ const Component$3 = ({ DOMLocation, tag = 'div', children, }) => {
695
695
  const [element, setElement] = useState();
696
696
  useEffect(() => {
697
697
  if (!tag)
@@ -709,17 +709,24 @@ const Component$2 = ({ DOMLocation, tag = 'div', children, }) => {
709
709
  return createPortal(children, element);
710
710
  };
711
711
  const name$3 = `${PKG_NAME}/Portal`;
712
- Component$2.displayName = name$3;
713
- Component$2.pkgName = PKG_NAME;
714
- Component$2.VITUS_LABS__COMPONENT = name$3;
712
+ Component$3.displayName = name$3;
713
+ Component$3.pkgName = PKG_NAME;
714
+ Component$3.VITUS_LABS__COMPONENT = name$3;
715
715
 
716
716
  const context = createContext({});
717
717
  const { Provider } = context;
718
718
  const useOverlayContext = () => useContext(context);
719
- const component$1 = ({ children, blocked, setBlocked, setUnblocked, }) => (React.createElement(Provider, { value: { blocked, setBlocked, setUnblocked } }, children));
719
+ const Component$2 = ({ children, blocked, setBlocked, setUnblocked, }) => {
720
+ const ctx = useMemo(() => ({
721
+ blocked,
722
+ setBlocked,
723
+ setUnblocked,
724
+ }), [blocked, setBlocked, setUnblocked]);
725
+ return React.createElement(Provider, { value: ctx }, children);
726
+ };
720
727
 
721
728
  /* eslint-disable no-console */
722
- var useOverlay = ({ isOpen = false, openOn = 'click', // click | hover
729
+ const useOverlay = ({ isOpen = false, openOn = 'click', // click | hover
723
730
  closeOn = 'click', // click | 'clickOnTrigger' | 'clickOutsideContent' | hover | manual
724
731
  type = 'dropdown', // dropdown | tooltip | popover | modal
725
732
  position = 'fixed', // absolute | fixed | relative | static
@@ -746,7 +753,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
746
753
  }, []);
747
754
  const calculateContentPosition = useCallback(() => {
748
755
  const overlayPosition = {};
749
- if (!active)
756
+ if (!active || !isContentLoaded)
750
757
  return overlayPosition;
751
758
  if (!triggerRef.current || !contentRef.current) {
752
759
  if (process.env.NODE_ENV === 'development') {
@@ -892,13 +899,14 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
892
899
  }
893
900
  return overlayPosition;
894
901
  }, [
902
+ isContentLoaded,
895
903
  active,
896
- type,
897
904
  align,
898
905
  alignX,
899
906
  alignY,
900
907
  offsetX,
901
908
  offsetY,
909
+ type,
902
910
  triggerRef,
903
911
  contentRef,
904
912
  ]);
@@ -907,12 +915,17 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
907
915
  return;
908
916
  const setValue = (param) => value(param, rootSize);
909
917
  // ADD POSITION STYLES TO CONTENT
918
+ // eslint-disable-next-line no-param-reassign
910
919
  contentRef.current.style.position = position;
920
+ // eslint-disable-next-line no-param-reassign
911
921
  contentRef.current.style.top = setValue(values.top);
922
+ // eslint-disable-next-line no-param-reassign
912
923
  contentRef.current.style.bottom = setValue(values.bottom);
924
+ // eslint-disable-next-line no-param-reassign
913
925
  contentRef.current.style.left = setValue(values.left);
926
+ // eslint-disable-next-line no-param-reassign
914
927
  contentRef.current.style.right = setValue(values.right);
915
- }, [rootSize, position, contentRef]);
928
+ }, [position, rootSize, contentRef]);
916
929
  const setContentPosition = useCallback(() => {
917
930
  const currentPosition = calculateContentPosition();
918
931
  assignContentPosition(currentPosition);
@@ -923,11 +936,11 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
923
936
  }
924
937
  return false;
925
938
  };
926
- const isTrigger = isNodeOrChild(triggerRef);
927
- const isContent = isNodeOrChild(contentRef);
928
939
  const handleVisibilityByEventType = useCallback((e) => {
929
940
  if (blocked || disabled)
930
941
  return;
942
+ const isTrigger = isNodeOrChild(triggerRef);
943
+ const isContent = isNodeOrChild(contentRef);
931
944
  // showing content observing
932
945
  if (!active) {
933
946
  if ((openOn === 'hover' && e.type === 'mousemove') ||
@@ -969,18 +982,13 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
969
982
  openOn,
970
983
  closeOn,
971
984
  hideContent,
972
- isContent,
973
- isTrigger,
974
985
  showContent,
986
+ triggerRef,
987
+ contentRef,
975
988
  ]);
976
989
  const handleContentPosition = throttle(setContentPosition, throttleDelay);
977
990
  const handleClick = handleVisibilityByEventType;
978
991
  const handleVisibility = throttle(handleVisibilityByEventType, throttleDelay);
979
- const handleEscKey = (e) => {
980
- if (e.key === 'Escape') {
981
- hideContent();
982
- }
983
- };
984
992
  // --------------------------------------------------------------------------
985
993
  // useEffects
986
994
  // --------------------------------------------------------------------------
@@ -990,7 +998,13 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
990
998
  if (disabled) {
991
999
  hideContent();
992
1000
  }
993
- }, [disabled, alignX, alignY]);
1001
+ }, [disabled, alignX, alignY, hideContent]);
1002
+ useEffect(() => {
1003
+ if (active && isContentLoaded) {
1004
+ setContentPosition();
1005
+ setContentPosition();
1006
+ }
1007
+ }, [active, isContentLoaded, setContentPosition]);
994
1008
  // if an Overlay has an Overlay child, this will prevent closing parent child
995
1009
  // and calculates correct position when an Overlay is opened
996
1010
  useEffect(() => {
@@ -999,40 +1013,49 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
999
1013
  onOpen();
1000
1014
  if (ctx.setBlocked)
1001
1015
  ctx.setBlocked();
1002
- showContent();
1003
1016
  }
1004
- else {
1005
- setContentLoaded(false);
1017
+ return () => {
1006
1018
  if (onClose)
1007
1019
  onClose();
1008
1020
  if (ctx.setUnblocked)
1009
1021
  ctx.setUnblocked();
1010
- }
1011
- }, [active, onOpen, onClose, ctx.setBlocked, ctx.setUnblocked]);
1022
+ setContentLoaded(false);
1023
+ };
1024
+ }, [active, onOpen, onClose, showContent, ctx]);
1025
+ // handle closing only when content is active
1012
1026
  useEffect(() => {
1013
- if (isContentLoaded) {
1014
- setContentPosition();
1015
- setContentPosition();
1016
- }
1017
- }, [isContentLoaded]);
1027
+ if (!closeOnEsc || !active || blocked)
1028
+ return undefined;
1029
+ const handleEscKey = (e) => {
1030
+ if (e.key === 'Escape') {
1031
+ hideContent();
1032
+ }
1033
+ };
1034
+ window.addEventListener('keydown', handleEscKey);
1035
+ return () => {
1036
+ window.removeEventListener('keydown', handleEscKey);
1037
+ };
1038
+ }, [active, blocked, closeOnEsc, hideContent]);
1018
1039
  // handles repositioning of content on document events
1019
1040
  useEffect(() => {
1020
1041
  if (!active)
1021
1042
  return undefined;
1022
1043
  const shouldSetOverflow = type === 'modal';
1044
+ const onScroll = (e) => {
1045
+ handleContentPosition();
1046
+ handleVisibility(e);
1047
+ };
1023
1048
  if (shouldSetOverflow)
1024
1049
  document.body.style.overflow = 'hidden';
1025
- window.addEventListener('resize', handleContentPosition, false);
1026
- window.addEventListener('scroll', handleContentPosition, false);
1027
- window.addEventListener('scroll', handleVisibility, false);
1050
+ window.addEventListener('resize', handleContentPosition);
1051
+ window.addEventListener('scroll', onScroll);
1028
1052
  return () => {
1029
1053
  if (shouldSetOverflow)
1030
1054
  document.body.style.overflow = '';
1031
- window.removeEventListener('scroll', handleVisibility, false);
1032
- window.removeEventListener('resize', handleContentPosition, false);
1033
- window.removeEventListener('scroll', handleContentPosition, false);
1055
+ window.removeEventListener('resize', handleContentPosition);
1056
+ window.removeEventListener('scroll', onScroll);
1034
1057
  };
1035
- }, [active, type]);
1058
+ }, [active, type, handleVisibility, handleContentPosition]);
1036
1059
  // handles repositioning of content on a custom element if defined
1037
1060
  useEffect(() => {
1038
1061
  if (!active || !parentContainer)
@@ -1040,24 +1063,23 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
1040
1063
  // eslint-disable-next-line no-param-reassign
1041
1064
  if (closeOn !== 'hover')
1042
1065
  parentContainer.style.overflow = 'hidden';
1043
- parentContainer.addEventListener('scroll', handleContentPosition, false);
1044
- parentContainer.addEventListener('scroll', handleVisibility, false);
1066
+ const onScroll = (e) => {
1067
+ handleContentPosition();
1068
+ handleVisibility(e);
1069
+ };
1070
+ parentContainer.addEventListener('scroll', onScroll);
1045
1071
  return () => {
1046
1072
  // eslint-disable-next-line no-param-reassign
1047
1073
  parentContainer.style.overflow = '';
1048
- parentContainer.removeEventListener('scroll', handleVisibility, false);
1049
- parentContainer.removeEventListener('scroll', handleContentPosition, false);
1074
+ parentContainer.removeEventListener('scroll', onScroll);
1050
1075
  };
1051
- }, [active, parentContainer, closeOn]);
1052
- // only when content is active handle closing
1053
- useEffect(() => {
1054
- if (!closeOnEsc || !active || blocked)
1055
- return undefined;
1056
- window.addEventListener('keydown', handleEscKey, false);
1057
- return () => {
1058
- window.removeEventListener('keydown', handleEscKey, false);
1059
- };
1060
- }, [active, blocked, closeOnEsc]);
1076
+ }, [
1077
+ active,
1078
+ parentContainer,
1079
+ closeOn,
1080
+ handleContentPosition,
1081
+ handleVisibility,
1082
+ ]);
1061
1083
  // enable overlay manipulation only when the state is NOT blocked
1062
1084
  // nor in disabled state
1063
1085
  useEffect(() => {
@@ -1067,29 +1089,32 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
1067
1089
  const enabledClick = openOn === 'click' ||
1068
1090
  ['click', 'clickOnTrigger', 'clickOutsideContent'].includes(closeOn);
1069
1091
  if (enabledClick) {
1070
- window.addEventListener('click', handleClick, false);
1092
+ window.addEventListener('click', handleClick);
1071
1093
  }
1072
1094
  if (enabledMouseMove) {
1073
- window.addEventListener('mousemove', handleVisibility, false);
1095
+ window.addEventListener('mousemove', handleVisibility);
1074
1096
  }
1075
1097
  return () => {
1076
- if (enabledClick) {
1077
- window.removeEventListener('click', handleClick, false);
1078
- }
1079
- if (enabledMouseMove) {
1080
- window.removeEventListener('mousemove', handleVisibility, false);
1081
- }
1098
+ window.removeEventListener('click', handleClick);
1099
+ window.removeEventListener('mousemove', handleVisibility);
1082
1100
  };
1083
- }, [openOn, closeOn, blocked, disabled, active]);
1084
- // hask-ish way to load contet correctly on the first load
1101
+ }, [
1102
+ openOn,
1103
+ closeOn,
1104
+ blocked,
1105
+ disabled,
1106
+ active,
1107
+ handleClick,
1108
+ handleVisibility,
1109
+ ]);
1110
+ // hack-ish way to load contet correctly on the first load
1085
1111
  // as `contentRef` is loaded dynamically
1086
- const contentRefCallback = (node) => {
1087
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1088
- // @ts-ignore
1089
- if (node)
1112
+ const contentRefCallback = useCallback((node) => {
1113
+ if (node) {
1090
1114
  contentRef.current = node;
1091
- setContentLoaded(true);
1092
- };
1115
+ setContentLoaded(true);
1116
+ }
1117
+ }, []);
1093
1118
  return {
1094
1119
  triggerRef,
1095
1120
  contentRef: contentRefCallback,
@@ -1102,7 +1127,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = tru
1102
1127
  blocked,
1103
1128
  setBlocked,
1104
1129
  setUnblocked,
1105
- Provider: component$1,
1130
+ Provider: Component$2,
1106
1131
  };
1107
1132
  };
1108
1133
 
@@ -1165,5 +1190,5 @@ Component.displayName = name;
1165
1190
  Component.pkgName = PKG_NAME;
1166
1191
  Component.VITUS_LABS__COMPONENT = name;
1167
1192
 
1168
- export { Component$4 as Element, component$3 as List, Component$1 as Overlay, component$1 as OverlayProvider, Component$2 as Portal, component as Text, Component as Util, useOverlay, component$2 as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
1193
+ export { Component$5 as Element, component$2 as List, Component$1 as Overlay, Component$2 as OverlayProvider, Component$3 as Portal, component as Text, Component as Util, useOverlay, component$1 as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
1169
1194
  //# sourceMappingURL=vitus-labs-elements.module.js.map