@spteck/fluentui-react-charts 1.0.6 → 1.0.7

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.
@@ -7,8 +7,13 @@ import { css } from '@emotion/css';
7
7
  import { ResizeObserver } from '@juggle/resize-observer';
8
8
  import { bundleIcon, Settings20Filled, Settings20Regular } from '@fluentui/react-icons';
9
9
  import { Icon } from '@iconify/react';
10
- import { useIndexedDBCache } from '@spteck/m365-hooks';
10
+ import { openDB } from 'idb';
11
11
 
12
+ function _arrayLikeToArray(r, a) {
13
+ (null == a || a > r.length) && (a = r.length);
14
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
15
+ return n;
16
+ }
12
17
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
13
18
  try {
14
19
  var i = n[a](c),
@@ -34,6 +39,23 @@ function _asyncToGenerator(n) {
34
39
  });
35
40
  };
36
41
  }
42
+ function _createForOfIteratorHelperLoose(r, e) {
43
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
44
+ if (t) return (t = t.call(r)).next.bind(t);
45
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
46
+ t && (r = t);
47
+ var o = 0;
48
+ return function () {
49
+ return o >= r.length ? {
50
+ done: !0
51
+ } : {
52
+ done: !1,
53
+ value: r[o++]
54
+ };
55
+ };
56
+ }
57
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ }
37
59
  function _extends() {
38
60
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
39
61
  for (var e = 1; e < arguments.length; e++) {
@@ -156,6 +178,13 @@ function _regeneratorDefine(e, r, n, t) {
156
178
  function _taggedTemplateLiteralLoose(e, t) {
157
179
  return t || (t = e.slice(0)), e.raw = t, e;
158
180
  }
181
+ function _unsupportedIterableToArray(r, a) {
182
+ if (r) {
183
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
184
+ var t = {}.toString.call(r).slice(8, -1);
185
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
186
+ }
187
+ }
159
188
 
160
189
  /**
161
190
  * Lightens a given hex color by a percentage amount (0 to 1).
@@ -1223,7 +1252,16 @@ var useStyles = function useStyles() {
1223
1252
  hoveredCell: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n transform: scale(1.05);\n "])), tokens.colorNeutralBackground1Hover),
1224
1253
  selectedCell: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), tokens.colorNeutralBackground1Selected),
1225
1254
  menuPopover: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n min-width: fit-content;\n "]))),
1226
- bottomText: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n padding-left: 8px;\n padding-right: 8px;\n "])))
1255
+ bottomText: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n padding-left: 8px;\n padding-right: 8px;\n "]))),
1256
+ zoomContainer: css({
1257
+ display: 'flex',
1258
+ flexDirection: 'row',
1259
+ alignItems: 'center',
1260
+ gap: '6px',
1261
+ width: '100%',
1262
+ boxSizing: 'border-box',
1263
+ padding: '8px 0px'
1264
+ })
1227
1265
  };
1228
1266
  };
1229
1267
  var SelectZoom = function SelectZoom(props) {
@@ -1316,22 +1354,9 @@ var SelectZoom = function SelectZoom(props) {
1316
1354
  padding: 8
1317
1355
  }
1318
1356
  }, createElement("div", {
1319
- style: {
1320
- display: "flex",
1321
- flexDirection: "row",
1322
- alignItems: "center",
1323
- gap: "6px",
1324
- width: "100%",
1325
- boxSizing: "border-box",
1326
- padding: "8px"
1327
- }
1357
+ className: styles.zoomContainer
1328
1358
  }, createElement(RenderLabel, {
1329
- label: "Selected Span (" + values.spanCols + " \xD7 " + values.spanRows + ")",
1330
- icon: createElement(Icon, {
1331
- icon: "fluent:number-row-20-regular",
1332
- width: "32",
1333
- height: "32"
1334
- })
1359
+ label: "Span (" + values.spanCols + " \xD7 " + values.spanRows + ")"
1335
1360
  })), createElement("div", {
1336
1361
  className: styles.gridContainer,
1337
1362
  style: {
@@ -3502,6 +3527,268 @@ var useDashboardStyles = function useDashboardStyles() {
3502
3527
  };
3503
3528
  };
3504
3529
 
3530
+ var CACHE = "application-cache";
3531
+ var openDatabase = /*#__PURE__*/function () {
3532
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
3533
+ return _regenerator().w(function (_context) {
3534
+ while (1) switch (_context.n) {
3535
+ case 0:
3536
+ return _context.a(2, openDB('app-cache-db', 1, {
3537
+ upgrade: function upgrade(db) {
3538
+ db.createObjectStore(CACHE);
3539
+ }
3540
+ }));
3541
+ }
3542
+ }, _callee);
3543
+ }));
3544
+ return function openDatabase() {
3545
+ return _ref.apply(this, arguments);
3546
+ };
3547
+ }();
3548
+ var getCachedData = /*#__PURE__*/function () {
3549
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(key) {
3550
+ var db, cached;
3551
+ return _regenerator().w(function (_context2) {
3552
+ while (1) switch (_context2.n) {
3553
+ case 0:
3554
+ _context2.n = 1;
3555
+ return openDatabase();
3556
+ case 1:
3557
+ db = _context2.v;
3558
+ _context2.n = 2;
3559
+ return db.get(CACHE, key);
3560
+ case 2:
3561
+ cached = _context2.v;
3562
+ return _context2.a(2, cached ? cached.data : undefined);
3563
+ }
3564
+ }, _callee2);
3565
+ }));
3566
+ return function getCachedData(_x) {
3567
+ return _ref2.apply(this, arguments);
3568
+ };
3569
+ }();
3570
+ var setCachedData = /*#__PURE__*/function () {
3571
+ var _ref3 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(key, data) {
3572
+ var db;
3573
+ return _regenerator().w(function (_context3) {
3574
+ while (1) switch (_context3.n) {
3575
+ case 0:
3576
+ _context3.n = 1;
3577
+ return openDatabase();
3578
+ case 1:
3579
+ db = _context3.v;
3580
+ _context3.n = 2;
3581
+ return db.put(CACHE, {
3582
+ data: data,
3583
+ timestamp: Date.now()
3584
+ }, key);
3585
+ case 2:
3586
+ return _context3.a(2);
3587
+ }
3588
+ }, _callee3);
3589
+ }));
3590
+ return function setCachedData(_x2, _x3) {
3591
+ return _ref3.apply(this, arguments);
3592
+ };
3593
+ }();
3594
+ var deleteCachedData = /*#__PURE__*/function () {
3595
+ var _ref4 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(key) {
3596
+ var db;
3597
+ return _regenerator().w(function (_context4) {
3598
+ while (1) switch (_context4.n) {
3599
+ case 0:
3600
+ _context4.n = 1;
3601
+ return openDatabase();
3602
+ case 1:
3603
+ db = _context4.v;
3604
+ _context4.n = 2;
3605
+ return db["delete"](CACHE, key);
3606
+ case 2:
3607
+ return _context4.a(2);
3608
+ }
3609
+ }, _callee4);
3610
+ }));
3611
+ return function deleteCachedData(_x4) {
3612
+ return _ref4.apply(this, arguments);
3613
+ };
3614
+ }();
3615
+ var clearCache = /*#__PURE__*/function () {
3616
+ var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
3617
+ var db;
3618
+ return _regenerator().w(function (_context5) {
3619
+ while (1) switch (_context5.n) {
3620
+ case 0:
3621
+ _context5.n = 1;
3622
+ return openDatabase();
3623
+ case 1:
3624
+ db = _context5.v;
3625
+ _context5.n = 2;
3626
+ return db.clear(CACHE);
3627
+ case 2:
3628
+ return _context5.a(2);
3629
+ }
3630
+ }, _callee5);
3631
+ }));
3632
+ return function clearCache() {
3633
+ return _ref5.apply(this, arguments);
3634
+ };
3635
+ }();
3636
+ var clearExpiredCache = /*#__PURE__*/function () {
3637
+ var _ref6 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(maxAge) {
3638
+ var db, allKeys, now, _iterator, _step, key, cached;
3639
+ return _regenerator().w(function (_context6) {
3640
+ while (1) switch (_context6.n) {
3641
+ case 0:
3642
+ _context6.n = 1;
3643
+ return openDatabase();
3644
+ case 1:
3645
+ db = _context6.v;
3646
+ _context6.n = 2;
3647
+ return db.getAllKeys(CACHE);
3648
+ case 2:
3649
+ allKeys = _context6.v;
3650
+ now = Date.now();
3651
+ _iterator = _createForOfIteratorHelperLoose(allKeys);
3652
+ case 3:
3653
+ if ((_step = _iterator()).done) {
3654
+ _context6.n = 6;
3655
+ break;
3656
+ }
3657
+ key = _step.value;
3658
+ _context6.n = 4;
3659
+ return db.get(CACHE, key);
3660
+ case 4:
3661
+ cached = _context6.v;
3662
+ if (!(cached && now - cached.timestamp > maxAge)) {
3663
+ _context6.n = 5;
3664
+ break;
3665
+ }
3666
+ _context6.n = 5;
3667
+ return db["delete"](CACHE, key);
3668
+ case 5:
3669
+ _context6.n = 3;
3670
+ break;
3671
+ case 6:
3672
+ return _context6.a(2);
3673
+ }
3674
+ }, _callee6);
3675
+ }));
3676
+ return function clearExpiredCache(_x5) {
3677
+ return _ref6.apply(this, arguments);
3678
+ };
3679
+ }();
3680
+ var DEFAULT_MAX_AGE = 24 * 60 * 60 * 1000; // 1 day in milliseconds
3681
+ /**
3682
+ * Custom hook to manage IndexedDB cache with a specified maximum age.
3683
+ *
3684
+ * @template T - The type of data to be cached.
3685
+ * @param {number} [maxAge=DEFAULT_MAX_AGE] - The maximum age (in milliseconds) for cached data before it is considered expired.
3686
+ * @returns {UseIndexedDBCacheReturn<T>} An object containing methods to interact with the cache.
3687
+ *
3688
+ * @example
3689
+ * const { getData, setData, deleteData, clearAllCache } = useIndexedDBCache<MyDataType>(3600000);
3690
+ *
3691
+ * @function
3692
+ * @name useIndexedDBCache
3693
+ * @memberof hooks
3694
+ * @inner
3695
+ *
3696
+ * @typedef {Object} UseIndexedDBCacheReturn<T>
3697
+ * @property {function(string): Promise<T | undefined>} getData - Retrieves cached data by key.
3698
+ * @property {function(string, T): Promise<void>} setData - Caches data with a specified key.
3699
+ * @property {function(string): Promise<void>} deleteData - Deletes cached data by key.
3700
+ * @property {function(): Promise<void>} clearAllCache - Clears all cached data.
3701
+ */
3702
+ var useIndexedDBCache = function useIndexedDBCache(maxAge) {
3703
+ if (maxAge === void 0) {
3704
+ maxAge = DEFAULT_MAX_AGE;
3705
+ }
3706
+ useEffect(function () {
3707
+ // Clear expired cache on component mount
3708
+ _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
3709
+ return _regenerator().w(function (_context7) {
3710
+ while (1) switch (_context7.n) {
3711
+ case 0:
3712
+ _context7.n = 1;
3713
+ return clearExpiredCache(maxAge);
3714
+ case 1:
3715
+ return _context7.a(2);
3716
+ }
3717
+ }, _callee7);
3718
+ }))();
3719
+ }, [maxAge]);
3720
+ var getData = /*#__PURE__*/function () {
3721
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(key) {
3722
+ return _regenerator().w(function (_context8) {
3723
+ while (1) switch (_context8.n) {
3724
+ case 0:
3725
+ _context8.n = 1;
3726
+ return getCachedData(key);
3727
+ case 1:
3728
+ return _context8.a(2, _context8.v);
3729
+ }
3730
+ }, _callee8);
3731
+ }));
3732
+ return function getData(_x6) {
3733
+ return _ref8.apply(this, arguments);
3734
+ };
3735
+ }();
3736
+ var setData = /*#__PURE__*/function () {
3737
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(key, data) {
3738
+ return _regenerator().w(function (_context9) {
3739
+ while (1) switch (_context9.n) {
3740
+ case 0:
3741
+ _context9.n = 1;
3742
+ return setCachedData(key, data);
3743
+ case 1:
3744
+ return _context9.a(2);
3745
+ }
3746
+ }, _callee9);
3747
+ }));
3748
+ return function setData(_x7, _x8) {
3749
+ return _ref9.apply(this, arguments);
3750
+ };
3751
+ }();
3752
+ var deleteData = /*#__PURE__*/function () {
3753
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(key) {
3754
+ return _regenerator().w(function (_context0) {
3755
+ while (1) switch (_context0.n) {
3756
+ case 0:
3757
+ _context0.n = 1;
3758
+ return deleteCachedData(key);
3759
+ case 1:
3760
+ return _context0.a(2);
3761
+ }
3762
+ }, _callee0);
3763
+ }));
3764
+ return function deleteData(_x9) {
3765
+ return _ref0.apply(this, arguments);
3766
+ };
3767
+ }();
3768
+ var clearAllCache = /*#__PURE__*/function () {
3769
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
3770
+ return _regenerator().w(function (_context1) {
3771
+ while (1) switch (_context1.n) {
3772
+ case 0:
3773
+ _context1.n = 1;
3774
+ return clearCache();
3775
+ case 1:
3776
+ return _context1.a(2);
3777
+ }
3778
+ }, _callee1);
3779
+ }));
3780
+ return function clearAllCache() {
3781
+ return _ref1.apply(this, arguments);
3782
+ };
3783
+ }();
3784
+ return {
3785
+ getData: getData,
3786
+ setData: setData,
3787
+ deleteData: deleteData,
3788
+ clearAllCache: clearAllCache
3789
+ };
3790
+ };
3791
+
3505
3792
  var MINIMUM_DASHBOARD_WIDTH = 600;
3506
3793
  var MAX_ROWS = 4;
3507
3794
  var DASHBOARD_LAYOUT_CACHE_KEY = 'dashboard-layout-settings';
@@ -3605,7 +3892,7 @@ var Dashboard = function Dashboard(_ref) {
3605
3892
  };
3606
3893
  }();
3607
3894
  initializeData();
3608
- }, [cardCharts, getData, getOrderData]);
3895
+ }, [cardCharts]); // Only depend on cardCharts - getData/getOrderData are stable
3609
3896
  // Save sizes to cache whenever they change
3610
3897
  useEffect(function () {
3611
3898
  var saveSizesToCache = /*#__PURE__*/function () {
@@ -3637,7 +3924,7 @@ var Dashboard = function Dashboard(_ref) {
3637
3924
  if (Object.keys(sizes).length > 0) {
3638
3925
  saveSizesToCache();
3639
3926
  }
3640
- }, [sizes, setData]);
3927
+ }, [sizes]); // Only depend on sizes - setData is stable
3641
3928
  // Save card order to cache whenever it changes
3642
3929
  useEffect(function () {
3643
3930
  var saveOrderToCache = /*#__PURE__*/function () {
@@ -3672,7 +3959,7 @@ var Dashboard = function Dashboard(_ref) {
3672
3959
  if (CardChartContainer.length > 0) {
3673
3960
  saveOrderToCache();
3674
3961
  }
3675
- }, [CardChartContainer, setOrderData]);
3962
+ }, [CardChartContainer]); // Only depend on CardChartContainer - setOrderData is stable
3676
3963
  useEffect(function () {
3677
3964
  if (containerWidth <= MINIMUM_DASHBOARD_WIDTH) {
3678
3965
  setSizes(function () {