@woobee/ui 0.2.0 → 0.2.2

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/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- var React15 = require('react');
4
+ var React16 = require('react');
5
5
  var reactDom = require('react-dom');
6
6
  var reactTransitionGroup = require('react-transition-group');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
- var React15__default = /*#__PURE__*/_interopDefault(React15);
10
+ var React16__default = /*#__PURE__*/_interopDefault(React16);
11
11
 
12
12
  // src/utils/classNames.ts
13
13
  function classNames(classNameHash) {
@@ -35,6 +35,7 @@ function Button({
35
35
  leftIcon = null,
36
36
  rightIcon = null,
37
37
  compact = false,
38
+ darkMode = false,
38
39
  ...props
39
40
  }) {
40
41
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -51,11 +52,20 @@ function Button({
51
52
  "px-5 py-3 text-base": size === "big",
52
53
  "px-5 py-3 text-lg font-medium": size === "huge",
53
54
  "!px-1 !py-0.5": compact,
54
- "border bg-brown-500 dark:bg-primary-500 dark:hover:bg-primary-600 border-transparent text-white dark:text-black": variant === "primary",
55
- "text-gray-700 bg-white dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 border border-gray-300 dark:border-charcoal-700 hover:text-gray-500": variant === "secondary",
56
- "!rounded-md text-left w-full text-gray-700 bg-white dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 border border-gray-200 dark:border-charcoal-700 hover:bg-gray-50 hover:text-gray-500": variant === "form-input",
57
- "hover:text-brown-500 dark:text-charcoal-100 dark:hover:text-primary-500 !shadow-none": variant === "flat",
58
- "!text-gray-300 hover:!text-gray-400 dark:!text-charcoal-400": !children,
55
+ "border bg-brown-500 border-transparent text-white": variant === "primary" && !darkMode,
56
+ "dark:bg-primary-500 dark:hover:bg-primary-600 dark:text-black": variant === "primary" && !darkMode,
57
+ "border bg-primary-500 hover:bg-primary-600 border-transparent text-black": variant === "primary" && !!darkMode,
58
+ "text-gray-700 bg-white border border-gray-300 hover:text-gray-500": variant === "secondary" && !darkMode,
59
+ "text-charcoal-100 bg-charcoal-800 hover:bg-charcoal-700 border border-charcoal-700": variant === "secondary" && !!darkMode,
60
+ "!rounded-md text-left w-full text-gray-700 bg-white border border-gray-200 hover:bg-gray-50 hover:text-gray-500": variant === "form-input" && !darkMode,
61
+ "!rounded-md text-left w-full text-charcoal-100 bg-charcoal-800 hover:bg-charcoal-700 border border-charcoal-700": variant === "form-input" && !!darkMode,
62
+ "dark:bg-charcoal-800 dark:hover:bg-charcoal-700 dark:text-charcoal-100 dark:border-charcoal-700": (variant === "secondary" || variant === "form-input") && !darkMode,
63
+ "hover:text-brown-500 !shadow-none": variant === "flat" && !darkMode,
64
+ "dark:text-charcoal-100 dark:hover:text-primary-500": variant === "flat" && !darkMode,
65
+ "text-charcoal-100 hover:text-primary-500 !shadow-none": variant === "flat" && !!darkMode,
66
+ "!text-gray-300 hover:!text-gray-400": !children && !darkMode,
67
+ "dark:!text-charcoal-400": !children && !darkMode,
68
+ "!text-charcoal-400": !children && !!darkMode,
59
69
  ...classNameObject(className)
60
70
  }),
61
71
  ...props,
@@ -172,11 +182,11 @@ function Tabs({
172
182
  }
173
183
  );
174
184
  }
175
- var Toggle = React15.forwardRef(
185
+ var Toggle = React16.forwardRef(
176
186
  ({ listening, size, name, value, onChange, className }, ref) => {
177
- const internalRef = React15.useRef(null);
187
+ const internalRef = React16.useRef(null);
178
188
  const spanRef = ref || internalRef;
179
- React15.useEffect(() => {
189
+ React16.useEffect(() => {
180
190
  if (listening && spanRef && "current" in spanRef && spanRef.current && value !== null) {
181
191
  spanRef.current.value = value;
182
192
  }
@@ -261,6 +271,10 @@ function CheckboxList({
261
271
  loading = false,
262
272
  placeholder = "No items found."
263
273
  }) {
274
+ const hasLoadedRef = React16.useRef(false);
275
+ if (!loading) {
276
+ hasLoadedRef.current = true;
277
+ }
264
278
  const getFinalKey = (item, index) => {
265
279
  const key = typeof itemKey === "function" ? itemKey(item) : item[itemKey];
266
280
  return key !== void 0 && key !== null ? key : index;
@@ -271,7 +285,7 @@ function CheckboxList({
271
285
  }
272
286
  return placeholder;
273
287
  };
274
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full border border-gray-300 dark:border-charcoal-700 rounded-lg shadow-sm bg-white dark:bg-charcoal-800 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-60 overflow-y-auto divide-y divide-gray-100 dark:divide-charcoal-700", children: loading && items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 flex items-center justify-center min-h-36", children: /* @__PURE__ */ jsxRuntime.jsx(Loading, { spinSizeClassName: "w-6 h-6", className: "inline-block" }) }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: items.length > 0 ? items.map((item, index) => {
288
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full border border-gray-300 dark:border-charcoal-700 rounded-lg shadow-sm bg-white dark:bg-charcoal-800 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-60 overflow-y-auto divide-y divide-gray-100 dark:divide-charcoal-700", children: loading && !hasLoadedRef.current ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 flex items-center justify-center min-h-36", children: /* @__PURE__ */ jsxRuntime.jsx(Loading, { spinSizeClassName: "w-6 h-6", className: "inline-block" }) }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: items.length > 0 ? items.map((item, index) => {
275
289
  const finalKey = getFinalKey(item, index);
276
290
  const label = typeof itemLabel === "function" ? itemLabel(item) : item[itemLabel];
277
291
  const checked = typeof isChecked === "function" ? isChecked(item, selected) : selected.some(
@@ -315,7 +329,7 @@ function CheckboxList({
315
329
  );
316
330
  }) : renderPlaceholder() }) }) });
317
331
  }
318
- var ModalContext = React15.createContext({
332
+ var ModalContext = React16.createContext({
319
333
  modalShowing: false,
320
334
  drawerShowing: false,
321
335
  setModalShowing: () => {
@@ -324,11 +338,11 @@ var ModalContext = React15.createContext({
324
338
  }
325
339
  });
326
340
  function useModalContext() {
327
- return React15.useContext(ModalContext);
341
+ return React16.useContext(ModalContext);
328
342
  }
329
343
  function ModalProvider({ children }) {
330
- const [currentState, setCurrentState] = React15.useState(0);
331
- function reducer(state, action) {
344
+ const [currentState, setCurrentState] = React16.useState(0);
345
+ function reducer2(state, action) {
332
346
  const updatedValues = { ...state };
333
347
  if ("modalShowing" in action) {
334
348
  updatedValues.modalShowing = action.modalShowing;
@@ -341,12 +355,12 @@ function ModalProvider({ children }) {
341
355
  }
342
356
  return updatedValues;
343
357
  }
344
- const [values, dispatch] = React15.useReducer(reducer, {
358
+ const [values, dispatch] = React16.useReducer(reducer2, {
345
359
  modalShowing: false,
346
360
  drawerShowing: false
347
361
  });
348
362
  const { modalShowing, drawerShowing } = values;
349
- React15.useEffect(() => {
363
+ React16.useEffect(() => {
350
364
  if (typeof document === "undefined") return;
351
365
  const bodyEl = document.getElementsByTagName("BODY")[0];
352
366
  if (!bodyEl) return;
@@ -369,12 +383,12 @@ function ModalProvider({ children }) {
369
383
  }
370
384
  );
371
385
  }
372
- var TransitionContext = React15.createContext({
386
+ var TransitionContext = React16.createContext({
373
387
  parent: {}
374
388
  });
375
389
  function useIsInitialRender() {
376
- const isInitialRender = React15.useRef(true);
377
- React15.useEffect(() => {
390
+ const isInitialRender = React16.useRef(true);
391
+ React16.useEffect(() => {
378
392
  isInitialRender.current = false;
379
393
  }, []);
380
394
  return isInitialRender.current;
@@ -408,7 +422,7 @@ function CSSTransitionComponent({
408
422
  const leaveClasses = leave.split(" ").filter((s) => s.length);
409
423
  const leaveFromClasses = leaveFrom.split(" ").filter((s) => s.length);
410
424
  const leaveToClasses = leaveTo.split(" ").filter((s) => s.length);
411
- const nodeRef = React15.useRef(null);
425
+ const nodeRef = React16.useRef(null);
412
426
  function addClasses(node, classes) {
413
427
  classes.length && node.classList.add(...classes);
414
428
  }
@@ -458,7 +472,7 @@ function CSSTransitionComponent({
458
472
  removeClasses(nodeRef.current, [...leaveToClasses, ...leaveClasses]);
459
473
  onExited(nodeRef.current);
460
474
  },
461
- children: React15__default.default.cloneElement(children, {
475
+ children: React16__default.default.cloneElement(children, {
462
476
  ref: (node) => {
463
477
  nodeRef.current = node;
464
478
  const childRef = children.ref;
@@ -473,7 +487,7 @@ function CSSTransitionComponent({
473
487
  );
474
488
  }
475
489
  function Transition({ show, appear, ...rest }) {
476
- const { parent } = React15.useContext(TransitionContext);
490
+ const { parent } = React16.useContext(TransitionContext);
477
491
  const isInitialRender = useIsInitialRender();
478
492
  const isChild = show === void 0;
479
493
  if (isChild) {
@@ -588,15 +602,15 @@ function Modal({
588
602
  fullscreen,
589
603
  opts
590
604
  }) {
591
- const { setModalShowing } = React15.useContext(ModalContext);
605
+ const { setModalShowing } = React16.useContext(ModalContext);
592
606
  const { darkMode, sidebarPosition = "right", mobileSidebarPosition = "bottom" } = opts || {};
593
607
  const isMobileSidebarTop = mobileSidebarPosition === "top" || mobileSidebarPosition === "above";
594
- const [mounted, setMounted] = React15.useState(false);
595
- React15.useEffect(() => {
608
+ const [mounted, setMounted] = React16.useState(false);
609
+ React16.useEffect(() => {
596
610
  setMounted(true);
597
611
  return () => setMounted(false);
598
612
  }, []);
599
- React15.useEffect(() => {
613
+ React16.useEffect(() => {
600
614
  if (typeof document === "undefined") return;
601
615
  const bodyEl = document.getElementsByTagName("BODY")[0];
602
616
  if (open) {
@@ -821,8 +835,8 @@ function Drawer({
821
835
  wrapperClassName,
822
836
  sectionClassName = ""
823
837
  }) {
824
- const { setDrawerShowing } = React15.useContext(ModalContext);
825
- React15.useEffect(() => {
838
+ const { setDrawerShowing } = React16.useContext(ModalContext);
839
+ React16.useEffect(() => {
826
840
  setDrawerShowing(open);
827
841
  }, [open]);
828
842
  function handleClose() {
@@ -943,9 +957,9 @@ function InlinePrompt({
943
957
  cancelText,
944
958
  opts
945
959
  }) {
946
- const [isOpen, setIsOpen] = React15.useState(false);
947
- const nodeTarget = React15.useRef(null);
948
- const nodeWindow = React15.useRef(null);
960
+ const [isOpen, setIsOpen] = React16.useState(false);
961
+ const nodeTarget = React16.useRef(null);
962
+ const nodeWindow = React16.useRef(null);
949
963
  const { condensed, blocked } = opts || {};
950
964
  function handleClickOutside(e) {
951
965
  if (nodeTarget.current?.contains(e.target) || nodeWindow.current?.contains(e.target)) {
@@ -965,7 +979,7 @@ function InlinePrompt({
965
979
  onConfirm();
966
980
  setIsOpen(false);
967
981
  }
968
- React15.useEffect(() => {
982
+ React16.useEffect(() => {
969
983
  if (isOpen) {
970
984
  document.addEventListener("mousedown", handleClickOutside);
971
985
  } else {
@@ -1185,7 +1199,7 @@ function Td({ className, align, colSpan, condensed, narrow, children }) {
1185
1199
  }
1186
1200
  );
1187
1201
  }
1188
- var Input = React15.forwardRef((props, ref) => {
1202
+ var Input = React16.forwardRef((props, ref) => {
1189
1203
  const {
1190
1204
  id,
1191
1205
  theme,
@@ -1221,11 +1235,11 @@ var Input = React15.forwardRef((props, ref) => {
1221
1235
  hideIndicator,
1222
1236
  darkMode
1223
1237
  } = props;
1224
- const [focused, setFocused] = React15.useState(false);
1225
- const inputRef = React15.useRef(null);
1238
+ const [focused, setFocused] = React16.useState(false);
1239
+ const inputRef = React16.useRef(null);
1226
1240
  const hasPrefix = !!prefix && prefix.length > 0;
1227
- React15.useImperativeHandle(ref, () => inputRef.current);
1228
- React15.useEffect(() => {
1241
+ React16.useImperativeHandle(ref, () => inputRef.current);
1242
+ React16.useEffect(() => {
1229
1243
  if (listening && inputRef.current && defaultValue !== null && defaultValue !== void 0) {
1230
1244
  if (hasPrefix) {
1231
1245
  inputRef.current.value = prefix + String(defaultValue);
@@ -1403,7 +1417,7 @@ function Label({
1403
1417
  )
1404
1418
  ] });
1405
1419
  }
1406
- var Select = React15.forwardRef((props, ref) => {
1420
+ var Select = React16.forwardRef((props, ref) => {
1407
1421
  const {
1408
1422
  id,
1409
1423
  loading = false,
@@ -1443,7 +1457,7 @@ var Select = React15.forwardRef((props, ref) => {
1443
1457
  });
1444
1458
  Select.displayName = "Select";
1445
1459
  var Select_default = Select;
1446
- var SelectInput = React15.forwardRef((props, ref) => {
1460
+ var SelectInput = React16.forwardRef((props, ref) => {
1447
1461
  const {
1448
1462
  className,
1449
1463
  placeholder = "Select an option",
@@ -1480,7 +1494,7 @@ var SelectInput = React15.forwardRef((props, ref) => {
1480
1494
  });
1481
1495
  SelectInput.displayName = "SelectInput";
1482
1496
  var SelectInput_default = SelectInput;
1483
- var Textarea = React15.forwardRef((props, ref) => {
1497
+ var Textarea = React16.forwardRef((props, ref) => {
1484
1498
  const {
1485
1499
  id,
1486
1500
  className,
@@ -1545,9 +1559,9 @@ function TagInput({
1545
1559
  onChange,
1546
1560
  placeholder
1547
1561
  }) {
1548
- const [currentState, setCurrentState] = React15.useState(0);
1549
- const tagInputRef = React15.useRef(null);
1550
- function reducer(state, action) {
1562
+ const [currentState, setCurrentState] = React16.useState(0);
1563
+ const tagInputRef = React16.useRef(null);
1564
+ function reducer2(state, action) {
1551
1565
  const updatedValues = { ...state };
1552
1566
  if ("tags" in action) {
1553
1567
  updatedValues.tags = Array.from(new Set(action.tags));
@@ -1560,11 +1574,11 @@ function TagInput({
1560
1574
  }
1561
1575
  return updatedValues;
1562
1576
  }
1563
- const [values, dispatch] = React15.useReducer(reducer, {
1577
+ const [values, dispatch] = React16.useReducer(reducer2, {
1564
1578
  tags: []
1565
1579
  });
1566
1580
  const { tags } = values;
1567
- React15.useEffect(() => {
1581
+ React16.useEffect(() => {
1568
1582
  if (defaultValue) {
1569
1583
  dispatch({ tags: defaultValue, render: true });
1570
1584
  } else {
@@ -1651,35 +1665,115 @@ function NoData({ className }) {
1651
1665
  ] })
1652
1666
  ] });
1653
1667
  }
1654
- var ThemeContext = React15.createContext(void 0);
1668
+ var ThemeContext = React16.createContext(void 0);
1669
+ var currentIsDark = false;
1670
+ var matchMediaListeners = /* @__PURE__ */ new Set();
1671
+ var originalMatchMedia = null;
1672
+ if (typeof window !== "undefined") {
1673
+ originalMatchMedia = window.matchMedia;
1674
+ try {
1675
+ const saved = localStorage.getItem("theme");
1676
+ const prefersDark = originalMatchMedia.call(window, "(prefers-color-scheme: dark)").matches;
1677
+ const isSystemOrNone = !saved || saved === "system";
1678
+ currentIsDark = saved === "dark" || isSystemOrNone && prefersDark;
1679
+ } catch (e) {
1680
+ }
1681
+ window.matchMedia = function(query) {
1682
+ const normalized = query.replace(/\s+/g, "").toLowerCase();
1683
+ const isDarkQuery = normalized.includes("prefers-color-scheme:dark");
1684
+ const isLightQuery = normalized.includes("prefers-color-scheme:light");
1685
+ if (isDarkQuery || isLightQuery) {
1686
+ const matches = isDarkQuery ? currentIsDark : !currentIsDark;
1687
+ return {
1688
+ matches,
1689
+ media: query,
1690
+ onchange: null,
1691
+ addListener(listener) {
1692
+ matchMediaListeners.add({ listener, query });
1693
+ },
1694
+ removeListener(listener) {
1695
+ for (const item of matchMediaListeners) {
1696
+ if (item.listener === listener) {
1697
+ matchMediaListeners.delete(item);
1698
+ }
1699
+ }
1700
+ },
1701
+ addEventListener(type, listener) {
1702
+ if (type === "change") {
1703
+ matchMediaListeners.add({ listener, query });
1704
+ }
1705
+ },
1706
+ removeEventListener(type, listener) {
1707
+ if (type === "change") {
1708
+ for (const item of matchMediaListeners) {
1709
+ if (item.listener === listener) {
1710
+ matchMediaListeners.delete(item);
1711
+ }
1712
+ }
1713
+ }
1714
+ },
1715
+ dispatchEvent(event) {
1716
+ return true;
1717
+ }
1718
+ };
1719
+ }
1720
+ return originalMatchMedia.call(window, query);
1721
+ };
1722
+ }
1655
1723
  function ThemeProvider({ children, defaultTheme = "system" }) {
1656
- const [mode, setMode] = React15.useState(defaultTheme);
1657
- const [isDark, setIsDark] = React15.useState(false);
1658
- const stateRef = React15.useRef(mode);
1659
- React15.useEffect(() => {
1660
- const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
1661
- const isDark2 = mode === "dark" || mode === "system" && prefersDark;
1662
- document.documentElement.classList.toggle("dark", isDark2);
1663
- stateRef.current = mode;
1664
- setIsDark(isDark2);
1665
- }, [mode]);
1666
- React15.useEffect(() => {
1724
+ const [mode, setMode] = React16.useState(defaultTheme);
1725
+ const [isDark, setIsDark] = React16.useState(false);
1726
+ const [mounted, setMounted] = React16.useState(false);
1727
+ React16.useEffect(() => {
1667
1728
  const saved = localStorage.getItem("theme") || defaultTheme;
1668
1729
  setMode(saved);
1730
+ setMounted(true);
1669
1731
  }, [defaultTheme]);
1670
- React15.useEffect(() => {
1671
- const media = window.matchMedia("(prefers-color-scheme: dark)");
1672
- const listener = () => {
1673
- const prevMode = stateRef.current;
1674
- if (prevMode !== "system") {
1675
- setTimeout(() => {
1676
- document.documentElement.classList.toggle("dark", prevMode === "dark");
1677
- }, 100);
1732
+ React16.useEffect(() => {
1733
+ if (!mounted) return;
1734
+ const media = originalMatchMedia ? originalMatchMedia.call(window, "(prefers-color-scheme: dark)") : null;
1735
+ const updateTheme = () => {
1736
+ const prefersDark = media ? media.matches : false;
1737
+ const currentIsDarkVal = mode === "dark" || mode === "system" && prefersDark;
1738
+ if (currentIsDarkVal) {
1739
+ document.documentElement.classList.add("dark");
1740
+ document.documentElement.classList.remove("light");
1741
+ } else {
1742
+ document.documentElement.classList.remove("dark");
1743
+ document.documentElement.classList.add("light");
1678
1744
  }
1745
+ currentIsDark = currentIsDarkVal;
1746
+ setIsDark(currentIsDarkVal);
1747
+ matchMediaListeners.forEach(({ listener, query }) => {
1748
+ try {
1749
+ const normalized = query.replace(/\s+/g, "").toLowerCase();
1750
+ const isDarkQuery = normalized.includes("prefers-color-scheme:dark");
1751
+ const matches = isDarkQuery ? currentIsDarkVal : !currentIsDarkVal;
1752
+ const event = { matches, media: query };
1753
+ if (typeof listener === "function") {
1754
+ listener(event);
1755
+ } else if (listener && typeof listener.handleEvent === "function") {
1756
+ listener.handleEvent(event);
1757
+ }
1758
+ } catch (e) {
1759
+ console.error(e);
1760
+ }
1761
+ });
1679
1762
  };
1680
- media.addEventListener("change", listener);
1681
- return () => media.removeEventListener("change", listener);
1682
- }, []);
1763
+ const timeoutId = setTimeout(updateTheme, 0);
1764
+ const handleMediaChange = () => {
1765
+ updateTheme();
1766
+ };
1767
+ if (media) {
1768
+ media.addEventListener("change", handleMediaChange);
1769
+ }
1770
+ return () => {
1771
+ clearTimeout(timeoutId);
1772
+ if (media) {
1773
+ media.removeEventListener("change", handleMediaChange);
1774
+ }
1775
+ };
1776
+ }, [mode, mounted]);
1683
1777
  function handleToggleTheme(triggerMode) {
1684
1778
  const triggeredMode = triggerMode === mode ? "system" : triggerMode;
1685
1779
  setMode(triggeredMode);
@@ -1702,7 +1796,7 @@ function ThemeProvider({ children, defaultTheme = "system" }) {
1702
1796
  );
1703
1797
  }
1704
1798
  function useThemeContext() {
1705
- const context = React15.useContext(ThemeContext);
1799
+ const context = React16.useContext(ThemeContext);
1706
1800
  if (!context) {
1707
1801
  throw new Error("useThemeContext must be used within a ThemeProvider");
1708
1802
  }
@@ -1749,13 +1843,13 @@ function debounce(fn, delay) {
1749
1843
 
1750
1844
  // src/hooks/useDebounce.ts
1751
1845
  function useDebounce(callback, delay, deps = []) {
1752
- const callbackFn = React15.useCallback(debounce(callback, delay), deps);
1846
+ const callbackFn = React16.useCallback(debounce(callback, delay), deps);
1753
1847
  return [callbackFn];
1754
1848
  }
1755
1849
 
1756
1850
  // src/hooks/useResizeListener.ts
1757
1851
  function useResizeListener(props = {}) {
1758
- const [values, setValues] = React15.useState(
1852
+ const [values, setValues] = React16.useState(
1759
1853
  [
1760
1854
  typeof window === "undefined" ? props.mobileAgent ? 375 : 1080 : window.innerWidth,
1761
1855
  typeof window === "undefined" ? props.mobileAgent ? 812 : 750 : window.innerHeight,
@@ -1777,7 +1871,7 @@ function useResizeListener(props = {}) {
1777
1871
  ]);
1778
1872
  }
1779
1873
  const [debouncedSetValue] = useDebounce(handleChangeViewport, 300);
1780
- React15.useEffect(() => {
1874
+ React16.useEffect(() => {
1781
1875
  window.addEventListener("resize", debouncedSetValue);
1782
1876
  return () => {
1783
1877
  window.removeEventListener("resize", debouncedSetValue);
@@ -1785,7 +1879,7 @@ function useResizeListener(props = {}) {
1785
1879
  }, [debouncedSetValue]);
1786
1880
  return { screenWidth, screenHeight, viewport, viewMode, mobileView, tabletView };
1787
1881
  }
1788
- var PopoverContext = React15.createContext(void 0);
1882
+ var PopoverContext = React16.createContext(void 0);
1789
1883
  function PopoverCard({
1790
1884
  show,
1791
1885
  style,
@@ -1933,74 +2027,68 @@ var resetValues = {
1933
2027
  description: null,
1934
2028
  actions: null
1935
2029
  };
1936
- function PopoverProvider({ children }) {
1937
- const [currentState, setCurrentState] = React15.useState(0);
1938
- const [values, dispatch] = React15.useReducer(reducer, resetValues);
1939
- const { show, style, tooltipStyle, position, description, actions } = values;
1940
- function reducer(state, action) {
1941
- const updatedValues = { ...state };
1942
- if ("show" in action) {
1943
- updatedValues.show = action.show;
1944
- }
1945
- if ("style" in action) {
1946
- updatedValues.style = action.style;
1947
- }
1948
- if ("tooltipStyle" in action) {
1949
- updatedValues.tooltipStyle = action.tooltipStyle;
1950
- }
1951
- if ("position" in action) {
1952
- updatedValues.position = action.position;
1953
- }
1954
- if ("description" in action) {
1955
- updatedValues.description = action.description;
1956
- }
1957
- if ("actions" in action) {
1958
- updatedValues.actions = action.actions;
2030
+ function reducer(state, action) {
2031
+ let changed = false;
2032
+ for (const k in action) {
2033
+ const key = k;
2034
+ if (action[key] !== state[key]) {
2035
+ changed = true;
2036
+ break;
1959
2037
  }
1960
- if ("render" in action && !!action.render) {
1961
- setCurrentState((prev) => 1 - prev);
1962
- }
1963
- return updatedValues;
1964
2038
  }
1965
- function handleShowPopover(params) {
1966
- dispatch({
1967
- ...params,
1968
- render: true
1969
- });
2039
+ if (!changed) return state;
2040
+ const updatedValues = { ...state };
2041
+ if ("show" in action) {
2042
+ updatedValues.show = action.show;
1970
2043
  }
1971
- function handleClosePopover() {
1972
- dispatch({
1973
- ...resetValues,
1974
- render: true
1975
- });
2044
+ if ("style" in action) {
2045
+ updatedValues.style = action.style;
1976
2046
  }
1977
- return /* @__PURE__ */ jsxRuntime.jsxs(
1978
- PopoverContext.Provider,
1979
- {
1980
- value: {
1981
- showPopover: show,
1982
- setPopover: handleShowPopover
1983
- },
1984
- children: [
1985
- children,
1986
- !!show && /* @__PURE__ */ jsxRuntime.jsx(
1987
- PopoverCard,
1988
- {
1989
- show,
1990
- style,
1991
- tooltipStyle,
1992
- position,
1993
- description,
1994
- actions,
1995
- onClose: handleClosePopover
1996
- }
1997
- )
1998
- ]
1999
- }
2000
- );
2047
+ if ("tooltipStyle" in action) {
2048
+ updatedValues.tooltipStyle = action.tooltipStyle;
2049
+ }
2050
+ if ("position" in action) {
2051
+ updatedValues.position = action.position;
2052
+ }
2053
+ if ("description" in action) {
2054
+ updatedValues.description = action.description;
2055
+ }
2056
+ if ("actions" in action) {
2057
+ updatedValues.actions = action.actions;
2058
+ }
2059
+ return updatedValues;
2060
+ }
2061
+ function PopoverProvider({ children }) {
2062
+ const [values, dispatch] = React16.useReducer(reducer, resetValues);
2063
+ const { show, style, tooltipStyle, position, description, actions } = values;
2064
+ const handleShowPopover = React16.useCallback((params) => {
2065
+ dispatch(params);
2066
+ }, []);
2067
+ const handleClosePopover = React16.useCallback(() => {
2068
+ dispatch(resetValues);
2069
+ }, []);
2070
+ const contextValue = React16.useMemo(() => ({
2071
+ showPopover: show,
2072
+ setPopover: handleShowPopover
2073
+ }), [show, handleShowPopover]);
2074
+ return /* @__PURE__ */ jsxRuntime.jsxs(PopoverContext.Provider, { value: contextValue, children: [
2075
+ children,
2076
+ !!show && /* @__PURE__ */ jsxRuntime.jsx(
2077
+ PopoverCard,
2078
+ {
2079
+ show,
2080
+ style,
2081
+ tooltipStyle,
2082
+ position,
2083
+ description,
2084
+ actions,
2085
+ onClose: handleClosePopover
2086
+ }
2087
+ )
2088
+ ] });
2001
2089
  }
2002
2090
  function usePopoverContext() {
2003
- const context = React15.useContext(PopoverContext);
2091
+ const context = React16.useContext(PopoverContext);
2004
2092
  if (!context) {
2005
2093
  throw new Error("usePopoverContext must be used within a PopoverProvider");
2006
2094
  }
@@ -2010,10 +2098,17 @@ function Popover({ className, description, actions, children, opts }) {
2010
2098
  const { activated } = opts || {};
2011
2099
  const { showPopover, setPopover } = usePopoverContext();
2012
2100
  const { screenWidth, screenHeight } = useResizeListener();
2013
- const [menuData, setMenuData] = React15.useState({ showMenu: false, x: 0, y: 0, left: 0, right: 0, top: 0, bottom: 0 });
2014
- const parentRef = React15.useRef(null);
2101
+ const [menuData, setMenuData] = React16.useState({ showMenu: false, x: 0, y: 0, left: 0, right: 0, top: 0, bottom: 0 });
2102
+ const parentRef = React16.useRef(null);
2103
+ const prevShowMenuRef = React16.useRef(false);
2104
+ const prevShowPopoverRef = React16.useRef(false);
2015
2105
  (actions || []).some((action) => (action.items || []).length > 0);
2016
- React15.useEffect(() => {
2106
+ React16.useEffect(() => {
2107
+ const wasOpen = prevShowMenuRef.current;
2108
+ prevShowMenuRef.current = menuData.showMenu;
2109
+ if (!menuData.showMenu && !wasOpen) {
2110
+ return;
2111
+ }
2017
2112
  const stickyTop = menuData.showMenu && screenHeight - (menuData.y + 14) < 300;
2018
2113
  setPopover({
2019
2114
  show: menuData.showMenu,
@@ -2036,14 +2131,15 @@ function Popover({ className, description, actions, children, opts }) {
2036
2131
  actions
2037
2132
  });
2038
2133
  }, [menuData, screenWidth, screenHeight, description, actions, setPopover]);
2039
- React15.useEffect(() => {
2040
- if (!showPopover && !!menuData.showMenu) {
2134
+ React16.useEffect(() => {
2135
+ if (prevShowPopoverRef.current && !showPopover) {
2041
2136
  setMenuData((prev) => ({
2042
2137
  ...prev,
2043
2138
  showMenu: false
2044
2139
  }));
2045
2140
  }
2046
- }, [showPopover, menuData.showMenu]);
2141
+ prevShowPopoverRef.current = showPopover;
2142
+ }, [showPopover]);
2047
2143
  function handleToggleMenu(e) {
2048
2144
  e.stopPropagation();
2049
2145
  if (menuData.showMenu) {
@@ -2165,8 +2261,8 @@ function Dragger({
2165
2261
  children,
2166
2262
  onChange
2167
2263
  }) {
2168
- const [, setCurrentState] = React15.useState(0);
2169
- const [values, dispatch] = React15.useReducer(reducer, {
2264
+ const [, setCurrentState] = React16.useState(0);
2265
+ const [values, dispatch] = React16.useReducer(reducer2, {
2170
2266
  items: null,
2171
2267
  displayItems: null,
2172
2268
  dragging: false,
@@ -2179,14 +2275,14 @@ function Dragger({
2179
2275
  const { items, displayItems, dragging, dragItem, dragFrom, dragTo, updated } = values || {};
2180
2276
  const grandChildren = children && children.props.children;
2181
2277
  const isValid = !disabled && !!records && !!children && !!grandChildren && grandChildren.length > 0;
2182
- React15.useEffect(() => {
2278
+ React16.useEffect(() => {
2183
2279
  dispatch({
2184
2280
  items: grandChildren,
2185
2281
  updated: false,
2186
2282
  render: true
2187
2283
  });
2188
2284
  }, [timestamp, grandChildren]);
2189
- React15.useEffect(() => {
2285
+ React16.useEffect(() => {
2190
2286
  if (!updated) {
2191
2287
  if (grandChildren && grandChildren.length > 0) {
2192
2288
  dispatch({
@@ -2205,7 +2301,7 @@ function Dragger({
2205
2301
  }
2206
2302
  }
2207
2303
  }, [grandChildren, updated]);
2208
- function reducer(state, action) {
2304
+ function reducer2(state, action) {
2209
2305
  const updatedValues = { ...state };
2210
2306
  if ("items" in action) {
2211
2307
  updatedValues.items = action.items;
@@ -2426,9 +2522,9 @@ function Dragger({
2426
2522
  }
2427
2523
  dispatch({ dragging: false });
2428
2524
  }
2429
- const derivedItems = !!items && React15__default.default.cloneElement(children, {
2525
+ const derivedItems = !!items && React16__default.default.cloneElement(children, {
2430
2526
  children: items.map((grandChild, index) => {
2431
- return React15__default.default.cloneElement(grandChild, {
2527
+ return React16__default.default.cloneElement(grandChild, {
2432
2528
  id: (records[index] || {}).id,
2433
2529
  draggable: true,
2434
2530
  className: classNames({
@@ -2445,9 +2541,9 @@ function Dragger({
2445
2541
  });
2446
2542
  })
2447
2543
  });
2448
- const derivedDisplayItems = !!displayItems && React15__default.default.cloneElement(children, {
2544
+ const derivedDisplayItems = !!displayItems && React16__default.default.cloneElement(children, {
2449
2545
  children: displayItems.map((grandChild, index) => {
2450
- return React15__default.default.cloneElement(grandChild, {
2546
+ return React16__default.default.cloneElement(grandChild, {
2451
2547
  draggable: true,
2452
2548
  className: classNames({
2453
2549
  ...classNameObject(grandChild.props.className),
@@ -2505,8 +2601,8 @@ function ExcelTable({
2505
2601
  isAddRowVisible = true,
2506
2602
  addRowLabel = "+ Add Option"
2507
2603
  }) {
2508
- const [editingCell, setEditingCell] = React15.useState(null);
2509
- React15.useEffect(() => {
2604
+ const [editingCell, setEditingCell] = React16.useState(null);
2605
+ React16.useEffect(() => {
2510
2606
  setTimeout(() => {
2511
2607
  const textareas = document.querySelectorAll(".excel-table-textarea");
2512
2608
  textareas.forEach((ta) => {
@@ -2730,21 +2826,21 @@ function ExcelTable({
2730
2826
  ] }) });
2731
2827
  }
2732
2828
  function Coverflow({ images = [], onClose }) {
2733
- const scrollContainerRef = React15.useRef(null);
2734
- const thumbnailContainerRef = React15.useRef(null);
2735
- const [visualIndex, setVisualIndex] = React15.useState(0);
2736
- const isJumpingRef = React15.useRef(false);
2737
- const wheelLockRef = React15.useRef(false);
2738
- const wheelTimeoutRef = React15.useRef(null);
2739
- const [isReady, setIsReady] = React15.useState(false);
2740
- const [isMounted, setIsMounted] = React15.useState(false);
2741
- React15.useEffect(() => {
2829
+ const scrollContainerRef = React16.useRef(null);
2830
+ const thumbnailContainerRef = React16.useRef(null);
2831
+ const [visualIndex, setVisualIndex] = React16.useState(0);
2832
+ const isJumpingRef = React16.useRef(false);
2833
+ const wheelLockRef = React16.useRef(false);
2834
+ const wheelTimeoutRef = React16.useRef(null);
2835
+ const [isReady, setIsReady] = React16.useState(false);
2836
+ const [isMounted, setIsMounted] = React16.useState(false);
2837
+ React16.useEffect(() => {
2742
2838
  setIsMounted(true);
2743
2839
  }, []);
2744
2840
  const count = images.length;
2745
2841
  const hasMultiple = count > 1;
2746
2842
  const extendedImages = hasMultiple ? [images[count - 1], ...images, images[0]] : images;
2747
- React15.useEffect(() => {
2843
+ React16.useEffect(() => {
2748
2844
  if (hasMultiple && scrollContainerRef.current) {
2749
2845
  const container = scrollContainerRef.current;
2750
2846
  const width = container.offsetWidth;
@@ -2755,7 +2851,7 @@ function Coverflow({ images = [], onClose }) {
2755
2851
  setIsReady(true);
2756
2852
  }
2757
2853
  }, [hasMultiple]);
2758
- React15.useEffect(() => {
2854
+ React16.useEffect(() => {
2759
2855
  if (hasMultiple && thumbnailContainerRef.current) {
2760
2856
  const thumbContainer = thumbnailContainerRef.current;
2761
2857
  const thumbNode = thumbContainer.children[visualIndex];
@@ -2768,7 +2864,7 @@ function Coverflow({ images = [], onClose }) {
2768
2864
  }
2769
2865
  }
2770
2866
  }, [visualIndex, hasMultiple]);
2771
- React15.useEffect(() => {
2867
+ React16.useEffect(() => {
2772
2868
  const container = scrollContainerRef.current;
2773
2869
  if (!container || !hasMultiple) return;
2774
2870
  const handleWheel = (e) => {
@@ -2872,7 +2968,7 @@ function Coverflow({ images = [], onClose }) {
2872
2968
  behavior: "smooth"
2873
2969
  });
2874
2970
  };
2875
- React15.useEffect(() => {
2971
+ React16.useEffect(() => {
2876
2972
  const handleKeyDown = (e) => {
2877
2973
  if (e.key === "Escape") onClose && onClose();
2878
2974
  if (e.key === "ArrowLeft") prevSlide();
@@ -3046,7 +3142,7 @@ function DataTableRow({ index, selected, label, description, additionalDescripti
3046
3142
  "!text-left": dataItem.align === "left",
3047
3143
  "align-middle": vertical === "middle"
3048
3144
  }),
3049
- children: typeof dataItem.data[index] === "string" || React15__default.default.isValidElement(dataItem.data[index]) ? dataItem.data[index] : numberFormatter(dataItem.data[index], dataItem.decimal != null ? dataItem.decimal : 1)
3145
+ children: typeof dataItem.data[index] === "string" || React16__default.default.isValidElement(dataItem.data[index]) ? dataItem.data[index] : numberFormatter(dataItem.data[index], dataItem.decimal != null ? dataItem.decimal : 1)
3050
3146
  },
3051
3147
  `${dataIndex}-${index}`
3052
3148
  ))
@@ -3067,8 +3163,8 @@ function DataTable({
3067
3163
  }) {
3068
3164
  const { mobileView } = useResizeListener();
3069
3165
  const { ignoreTotal, showCurrency, labelTitle, labelCentered, vertical, darkMode } = opts || {};
3070
- const [displayHeaders, setDisplayHeaders] = React15.useState([]);
3071
- React15.useEffect(() => {
3166
+ const [displayHeaders, setDisplayHeaders] = React16.useState([]);
3167
+ React16.useEffect(() => {
3072
3168
  setDisplayHeaders(headers);
3073
3169
  }, [headers]);
3074
3170
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3183,7 +3279,7 @@ function DataTable({
3183
3279
  backgroundColor: `${colors[dataIndex]}`,
3184
3280
  color: bestTextColorForBg(colors[dataIndex])
3185
3281
  } : void 0,
3186
- children: typeof total[dataIndex] === "string" || React15__default.default.isValidElement(total[dataIndex]) ? total[dataIndex] : showCurrency ? /* @__PURE__ */ jsxRuntime.jsx(CurrencyDisplay, { amount: total[dataIndex] }) : numberFormatter(total[dataIndex], 1)
3282
+ children: typeof total[dataIndex] === "string" || React16__default.default.isValidElement(total[dataIndex]) ? total[dataIndex] : showCurrency ? /* @__PURE__ */ jsxRuntime.jsx(CurrencyDisplay, { amount: total[dataIndex] }) : numberFormatter(total[dataIndex], 1)
3187
3283
  },
3188
3284
  `${dataIndex}-total`
3189
3285
  ))
@@ -3365,8 +3461,8 @@ function DataGridHeader({ sort, onClick, opts, children }) {
3365
3461
  );
3366
3462
  }
3367
3463
  function DataGridElement({ processing: defaultProcessing, type, value, error, menu, params, opts, onSelect }) {
3368
- const [processing, setProcessing] = React15.useState(defaultProcessing);
3369
- React15.useEffect(() => {
3464
+ const [processing, setProcessing] = React16.useState(defaultProcessing);
3465
+ React16.useEffect(() => {
3370
3466
  setProcessing(defaultProcessing);
3371
3467
  }, [defaultProcessing]);
3372
3468
  const { align } = opts || {};
@@ -3458,8 +3554,8 @@ function DataGridContent({ loading, error, type, value, opts, onClick }) {
3458
3554
  );
3459
3555
  }
3460
3556
  function DataGrid({ headers, data, selectedId, footers, opts, onSelect }) {
3461
- const [displayedData, setDisplayedData] = React15.useState([]);
3462
- const [orderByState, setOrderByState] = React15.useState({
3557
+ const [displayedData, setDisplayedData] = React16.useState([]);
3558
+ const [orderByState, setOrderByState] = React16.useState({
3463
3559
  category: headers[0]?.id || "",
3464
3560
  direction: "asc"
3465
3561
  });
@@ -3471,7 +3567,7 @@ function DataGrid({ headers, data, selectedId, footers, opts, onSelect }) {
3471
3567
  setOrderByState({ category, direction: orderByState.direction === "asc" ? "desc" : "asc" });
3472
3568
  }
3473
3569
  }
3474
- React15.useEffect(() => {
3570
+ React16.useEffect(() => {
3475
3571
  if ((data || []).length > 0) {
3476
3572
  const availableKeys = (headers || []).map((header) => header.id);
3477
3573
  const { category, direction } = orderByState;