@ioca/react 1.3.68 → 1.3.69

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.
Files changed (36) hide show
  1. package/lib/cjs/components/affix/affix.js +5 -1
  2. package/lib/cjs/components/affix/affix.js.map +1 -1
  3. package/lib/cjs/components/drawer/drawer.js +1 -1
  4. package/lib/cjs/components/drawer/drawer.js.map +1 -1
  5. package/lib/cjs/components/editor/controls.js +5 -1
  6. package/lib/cjs/components/editor/controls.js.map +1 -1
  7. package/lib/cjs/components/modal/modal.js +7 -2
  8. package/lib/cjs/components/modal/modal.js.map +1 -1
  9. package/lib/cjs/components/popup/content.js +5 -1
  10. package/lib/cjs/components/popup/content.js.map +1 -1
  11. package/lib/cjs/components/video/video.js +4 -0
  12. package/lib/cjs/components/video/video.js.map +1 -1
  13. package/lib/cjs/js/hooks.js +90 -50
  14. package/lib/cjs/js/hooks.js.map +1 -1
  15. package/lib/cjs/js/useRipple/index.js +6 -2
  16. package/lib/cjs/js/useRipple/index.js.map +1 -1
  17. package/lib/css/index.css +1 -1
  18. package/lib/css/index.css.map +1 -1
  19. package/lib/es/components/affix/affix.js +5 -1
  20. package/lib/es/components/affix/affix.js.map +1 -1
  21. package/lib/es/components/drawer/drawer.js +1 -1
  22. package/lib/es/components/drawer/drawer.js.map +1 -1
  23. package/lib/es/components/editor/controls.js +5 -1
  24. package/lib/es/components/editor/controls.js.map +1 -1
  25. package/lib/es/components/modal/modal.js +7 -2
  26. package/lib/es/components/modal/modal.js.map +1 -1
  27. package/lib/es/components/popup/content.js +5 -1
  28. package/lib/es/components/popup/content.js.map +1 -1
  29. package/lib/es/components/video/video.js +4 -0
  30. package/lib/es/components/video/video.js.map +1 -1
  31. package/lib/es/js/hooks.js +91 -51
  32. package/lib/es/js/hooks.js.map +1 -1
  33. package/lib/es/js/useRipple/index.js +6 -2
  34. package/lib/es/js/useRipple/index.js.map +1 -1
  35. package/lib/index.js +123 -58
  36. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -16,9 +16,11 @@ import SortableContainer, { SortableItem } from 'react-easy-sort';
16
16
 
17
17
  const TIMEOUT = 500;
18
18
  const useRipple = () => {
19
- if (document.documentElement.dataset["useripple"])
19
+ if (!document)
20
20
  return;
21
- document.documentElement.dataset["useripple"] = "enable";
21
+ if (document.documentElement.dataset["ioca-ripple"])
22
+ return;
23
+ document.documentElement.dataset["ioca-ripple"] = "enable";
22
24
  document.addEventListener("mousedown", listener);
23
25
  };
24
26
  function listener(e) {
@@ -29,6 +31,8 @@ function listener(e) {
29
31
  triggerRipple(parent, e);
30
32
  }
31
33
  function triggerRipple(target, e) {
34
+ if (!document)
35
+ return;
32
36
  const [$box, $ripple] = createRipple();
33
37
  const rect = target.getBoundingClientRect();
34
38
  const size = Math.max(rect.width, rect.height) * 2;
@@ -196,7 +200,11 @@ function ToTop(props) {
196
200
  }
197
201
 
198
202
  const Affix = (props) => {
199
- const { position = "fixed", left, top, right, bottom, offset, style, className, children, getContainer = () => document.body, } = props;
203
+ const { position = "fixed", left, top, right, bottom, offset, style, className, children, getContainer = () => {
204
+ if (typeof document === "undefined")
205
+ return null;
206
+ return document.body;
207
+ }, } = props;
200
208
  const [hidden, setHidden] = useState(false);
201
209
  const hijackChildren = useMemo(() => {
202
210
  return Children.map(children, (node) => {
@@ -692,32 +700,42 @@ function Cell(props) {
692
700
  }), children: data[id] })) }));
693
701
  }
694
702
 
695
- const MouseMoveEvents = new Set();
696
- const MouseUpEvents = new Set();
697
- const KeydownEvents = new Set();
698
- const touchable = "ontouchend" in document;
699
- const EVENTS = {
700
- MOVE: touchable ? "touchmove" : "mousemove",
701
- UP: touchable ? "touchend" : "mouseup",
702
- KEYDOWN: "keydown",
703
- };
704
- document.addEventListener(EVENTS.MOVE, (e) => {
705
- for (const listener of MouseMoveEvents.values()) {
706
- listener(e);
707
- }
708
- }, { passive: false });
709
- document.addEventListener(EVENTS.UP, (e) => {
710
- for (const listener of MouseUpEvents.values()) {
711
- listener(e);
712
- }
713
- });
714
- document.addEventListener(EVENTS.KEYDOWN, (e) => {
715
- for (const listener of KeydownEvents.values()) {
716
- listener(e);
717
- }
718
- });
703
+ const isBrowser = typeof window !== "undefined";
704
+ let MouseMoveEvents;
705
+ let MouseUpEvents;
706
+ let KeydownEvents;
707
+ let touchable;
708
+ let EVENTS;
709
+ if (isBrowser) {
710
+ MouseMoveEvents = new Set();
711
+ MouseUpEvents = new Set();
712
+ KeydownEvents = new Set();
713
+ touchable = "ontouchend" in document;
714
+ EVENTS = {
715
+ MOVE: touchable ? "touchmove" : "mousemove",
716
+ UP: touchable ? "touchend" : "mouseup",
717
+ KEYDOWN: "keydown",
718
+ };
719
+ document.addEventListener(EVENTS.MOVE, (e) => {
720
+ for (const listener of MouseMoveEvents.values()) {
721
+ listener(e);
722
+ }
723
+ }, { passive: false });
724
+ document.addEventListener(EVENTS.UP, (e) => {
725
+ for (const listener of MouseUpEvents.values()) {
726
+ listener(e);
727
+ }
728
+ });
729
+ document.addEventListener(EVENTS.KEYDOWN, (e) => {
730
+ for (const listener of KeydownEvents.values()) {
731
+ listener(e);
732
+ }
733
+ });
734
+ }
719
735
  function useMouseMove(listener, options) {
720
736
  useEffect(() => {
737
+ if (!isBrowser || options?.disabled)
738
+ return;
721
739
  MouseMoveEvents.add(listener);
722
740
  return () => {
723
741
  MouseMoveEvents.delete(listener);
@@ -726,6 +744,8 @@ function useMouseMove(listener, options) {
726
744
  }
727
745
  function useMouseUp(listener, options) {
728
746
  useEffect(() => {
747
+ if (!isBrowser || options?.disabled)
748
+ return;
729
749
  MouseUpEvents.add(listener);
730
750
  return () => {
731
751
  MouseUpEvents.delete(listener);
@@ -734,7 +754,7 @@ function useMouseUp(listener, options) {
734
754
  }
735
755
  function useKeydown(listener, options) {
736
756
  useEffect(() => {
737
- if (options?.disabled)
757
+ if (!isBrowser || options?.disabled)
738
758
  return;
739
759
  KeydownEvents.add(listener);
740
760
  return () => {
@@ -743,25 +763,39 @@ function useKeydown(listener, options) {
743
763
  }, [listener]);
744
764
  }
745
765
  function useIntersectionObserver(configs) {
746
- const WM = new WeakMap();
747
- const IO = new IntersectionObserver((entries) => {
748
- entries.map((entry) => {
749
- const callback = WM.get(entry.target);
750
- callback?.(entry.target, entry.isIntersecting);
751
- });
752
- }, configs);
766
+ const WM = useRef(new WeakMap());
767
+ const IO = useRef(null);
768
+ useEffect(() => {
769
+ if (!isBrowser)
770
+ return;
771
+ IO.current = new IntersectionObserver((entries) => {
772
+ entries.map((entry) => {
773
+ const callback = WM.current.get(entry.target);
774
+ callback?.(entry.target, entry.isIntersecting);
775
+ });
776
+ }, configs);
777
+ return () => {
778
+ IO.current?.disconnect();
779
+ };
780
+ }, []);
753
781
  function observe(target, callback) {
754
- if (WM.get(target))
782
+ if (!isBrowser || !IO.current || !target)
783
+ return;
784
+ if (WM.current.get(target))
755
785
  return;
756
- WM.set(target, callback);
757
- target && IO.observe(target);
786
+ WM.current.set(target, callback);
787
+ IO.current.observe(target);
758
788
  }
759
789
  function unobserve(target) {
760
- target && IO.unobserve(target);
761
- WM.delete(target);
790
+ if (!isBrowser || !IO.current || !target)
791
+ return;
792
+ IO.current.unobserve(target);
793
+ WM.current.delete(target);
762
794
  }
763
795
  function disconnect() {
764
- IO.disconnect();
796
+ if (!isBrowser || !IO.current)
797
+ return;
798
+ IO.current.disconnect();
765
799
  }
766
800
  return {
767
801
  observe,
@@ -770,25 +804,39 @@ function useIntersectionObserver(configs) {
770
804
  };
771
805
  }
772
806
  function useResizeObserver() {
773
- const WM = new WeakMap();
774
- const IO = new ResizeObserver((entries) => {
775
- entries.map((entry) => {
776
- const callback = WM.get(entry.target);
777
- callback?.(entry.target);
807
+ const WM = useRef(new WeakMap());
808
+ const IO = useRef(null);
809
+ useEffect(() => {
810
+ if (!isBrowser)
811
+ return;
812
+ IO.current = new ResizeObserver((entries) => {
813
+ entries.map((entry) => {
814
+ const callback = WM.current.get(entry.target);
815
+ callback?.(entry.target);
816
+ });
778
817
  });
779
- });
818
+ return () => {
819
+ IO.current?.disconnect();
820
+ };
821
+ }, []);
780
822
  function observe(target, callback) {
781
- if (WM.get(target))
823
+ if (!isBrowser || !IO.current || !target)
824
+ return;
825
+ if (WM.current.get(target))
782
826
  return;
783
- target && IO.observe(target);
784
- WM.set(target, callback);
827
+ IO.current.observe(target);
828
+ WM.current.set(target, callback);
785
829
  }
786
830
  function unobserve(target) {
787
- target && IO.unobserve(target);
788
- WM.delete(target);
831
+ if (!isBrowser || !IO.current || !target)
832
+ return;
833
+ IO.current.unobserve(target);
834
+ WM.current.delete(target);
789
835
  }
790
836
  function disconnect() {
791
- IO.disconnect();
837
+ if (!isBrowser || !IO.current)
838
+ return;
839
+ IO.current.disconnect();
792
840
  }
793
841
  return {
794
842
  observe,
@@ -1037,7 +1085,7 @@ function Drawer(props) {
1037
1085
  });
1038
1086
  return createPortal(state.show && (jsx("div", { className: classNames("i-backdrop-drawer", className, {
1039
1087
  "i-active": state.active,
1040
- }), onClick: handleBackdropClick, ...restProps, children: jsxs("div", { className: classNames("i-drawer", `i-drawer-${position}`), onClick: (e) => e.stopPropagation(), children: [jsxs("header", { className: 'i-drawer-header', children: [header, jsx(Helpericon, { active: !hideCloseButton, className: 'i-drawer-close', onClick: handleHide })] }), jsx("div", { className: 'i-drawer-content', children: children }), jsx("div", { className: 'i-drawer-footer', children: footer })] }) })), document.body);
1088
+ }), onClick: handleBackdropClick, ...restProps, children: jsxs("div", { className: classNames("i-drawer", `i-drawer-${position}`), onClick: (e) => e.stopPropagation(), children: [jsxs("header", { className: 'i-drawer-header', children: [header, jsx(Helpericon, { active: !hideCloseButton, className: 'i-drawer-close', onClick: handleHide })] }), jsx("div", { className: 'i-drawer-content', children: children }), jsx("div", { className: 'i-drawer-footer', children: footer })] }) })), document?.body ?? null);
1041
1089
  }
1042
1090
 
1043
1091
  const Item$4 = (props) => {
@@ -1067,7 +1115,11 @@ const List$1 = (props) => {
1067
1115
  List$1.Item = Item$4;
1068
1116
 
1069
1117
  const Content$1 = (props) => {
1070
- const { ref, getContainer = (trigger) => trigger?.offsetParent ?? document.body, trigger, arrow, arrowProps = {}, className, children, ...restProps } = props;
1118
+ const { ref, getContainer = (trigger) => {
1119
+ if (typeof document === "undefined")
1120
+ return null;
1121
+ return trigger?.offsetParent ?? document.body;
1122
+ }, trigger, arrow, arrowProps = {}, className, children, ...restProps } = props;
1071
1123
  const arrowCSS = useMemo(() => {
1072
1124
  let { left, top, pos } = arrowProps;
1073
1125
  let transform = "";
@@ -1327,7 +1379,11 @@ const Dropdown = (props) => {
1327
1379
  };
1328
1380
  Dropdown.Item = Item$3;
1329
1381
 
1330
- const exec = (a, b, c) => document.execCommand(a, b, c);
1382
+ const exec = (a, b, c) => {
1383
+ if (typeof document === "undefined")
1384
+ return;
1385
+ return document.execCommand(a, b, c);
1386
+ };
1331
1387
  const xssOptions = {
1332
1388
  onIgnoreTagAttr: function (tag, name, value) {
1333
1389
  if (["data-", "style"].includes(name.substr(0, 5))) {
@@ -1795,6 +1851,11 @@ function Modal(props) {
1795
1851
  useEffect(() => {
1796
1852
  visible ? handleShow() : handleHide();
1797
1853
  }, [visible]);
1854
+ const handleClick = () => {
1855
+ if (typeof document === "undefined")
1856
+ return;
1857
+ document.documentElement.click();
1858
+ };
1798
1859
  if (!show)
1799
1860
  return null;
1800
1861
  return createPortal(jsx("div", { className: classNames("i-modal-container", {
@@ -1810,9 +1871,9 @@ function Modal(props) {
1810
1871
  height,
1811
1872
  }, onClick: (e) => {
1812
1873
  e.stopPropagation();
1813
- document.documentElement.click();
1874
+ handleClick();
1814
1875
  onClick?.(e);
1815
- }, ...restProps, children: [customized && children, !customized && (jsx(DefaultContent, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }), document.body);
1876
+ }, ...restProps, children: [customized && children, !customized && (jsx(DefaultContent, { title: title, hideCloseButton: hideCloseButton, footer: footer, okButtonProps: okButtonProps, cancelButtonProps: cancelButtonProps, children: children, footerLeft: footerLeft, onOk: onOk, onClose: handleHide }))] }) }), document?.body ?? null);
1816
1877
  }
1817
1878
 
1818
1879
  const HookModal = (props) => {
@@ -2035,6 +2096,8 @@ const Video = (props) => {
2035
2096
  state.playing = !e.target.paused;
2036
2097
  };
2037
2098
  const fsChangeListener = () => {
2099
+ if (typeof document === "undefined")
2100
+ return;
2038
2101
  const tar = videoRef.current?.parentElement;
2039
2102
  if (!tar)
2040
2103
  return;
@@ -2136,6 +2199,8 @@ const Video = (props) => {
2136
2199
  getVideo: () => videoRef.current,
2137
2200
  }));
2138
2201
  useEffect(() => {
2202
+ if (typeof document === "undefined")
2203
+ return;
2139
2204
  const v = videoRef.current;
2140
2205
  if (!v)
2141
2206
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ioca/react",
3
- "version": "1.3.68",
3
+ "version": "1.3.69",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",