@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.
@@ -14,8 +14,13 @@ var css = require('@emotion/css');
14
14
  var resizeObserver = require('@juggle/resize-observer');
15
15
  var reactIcons = require('@fluentui/react-icons');
16
16
  var react = require('@iconify/react');
17
- var m365Hooks = require('@spteck/m365-hooks');
17
+ var idb = require('idb');
18
18
 
19
+ function _arrayLikeToArray(r, a) {
20
+ (null == a || a > r.length) && (a = r.length);
21
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
22
+ return n;
23
+ }
19
24
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
20
25
  try {
21
26
  var i = n[a](c),
@@ -41,6 +46,23 @@ function _asyncToGenerator(n) {
41
46
  });
42
47
  };
43
48
  }
49
+ function _createForOfIteratorHelperLoose(r, e) {
50
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
51
+ if (t) return (t = t.call(r)).next.bind(t);
52
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
53
+ t && (r = t);
54
+ var o = 0;
55
+ return function () {
56
+ return o >= r.length ? {
57
+ done: !0
58
+ } : {
59
+ done: !1,
60
+ value: r[o++]
61
+ };
62
+ };
63
+ }
64
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
+ }
44
66
  function _extends() {
45
67
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
46
68
  for (var e = 1; e < arguments.length; e++) {
@@ -163,6 +185,13 @@ function _regeneratorDefine(e, r, n, t) {
163
185
  function _taggedTemplateLiteralLoose(e, t) {
164
186
  return t || (t = e.slice(0)), e.raw = t, e;
165
187
  }
188
+ function _unsupportedIterableToArray(r, a) {
189
+ if (r) {
190
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
191
+ var t = {}.toString.call(r).slice(8, -1);
192
+ 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;
193
+ }
194
+ }
166
195
 
167
196
  /**
168
197
  * Lightens a given hex color by a percentage amount (0 to 1).
@@ -1230,7 +1259,16 @@ var useStyles = function useStyles() {
1230
1259
  hoveredCell: css.css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n transform: scale(1.05);\n "])), reactComponents.tokens.colorNeutralBackground1Hover),
1231
1260
  selectedCell: css.css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n background-color: ", ";\n "])), reactComponents.tokens.colorNeutralBackground1Selected),
1232
1261
  menuPopover: css.css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n min-width: fit-content;\n "]))),
1233
- bottomText: css.css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n padding-left: 8px;\n padding-right: 8px;\n "])))
1262
+ bottomText: css.css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n padding-left: 8px;\n padding-right: 8px;\n "]))),
1263
+ zoomContainer: css.css({
1264
+ display: 'flex',
1265
+ flexDirection: 'row',
1266
+ alignItems: 'center',
1267
+ gap: '6px',
1268
+ width: '100%',
1269
+ boxSizing: 'border-box',
1270
+ padding: '8px 0px'
1271
+ })
1234
1272
  };
1235
1273
  };
1236
1274
  var SelectZoom = function SelectZoom(props) {
@@ -1323,22 +1361,9 @@ var SelectZoom = function SelectZoom(props) {
1323
1361
  padding: 8
1324
1362
  }
1325
1363
  }, React.createElement("div", {
1326
- style: {
1327
- display: "flex",
1328
- flexDirection: "row",
1329
- alignItems: "center",
1330
- gap: "6px",
1331
- width: "100%",
1332
- boxSizing: "border-box",
1333
- padding: "8px"
1334
- }
1364
+ className: styles.zoomContainer
1335
1365
  }, React.createElement(RenderLabel, {
1336
- label: "Selected Span (" + values.spanCols + " \xD7 " + values.spanRows + ")",
1337
- icon: React.createElement(react.Icon, {
1338
- icon: "fluent:number-row-20-regular",
1339
- width: "32",
1340
- height: "32"
1341
- })
1366
+ label: "Span (" + values.spanCols + " \xD7 " + values.spanRows + ")"
1342
1367
  })), React.createElement("div", {
1343
1368
  className: styles.gridContainer,
1344
1369
  style: {
@@ -3509,6 +3534,268 @@ var useDashboardStyles = function useDashboardStyles() {
3509
3534
  };
3510
3535
  };
3511
3536
 
3537
+ var CACHE = "application-cache";
3538
+ var openDatabase = /*#__PURE__*/function () {
3539
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
3540
+ return _regenerator().w(function (_context) {
3541
+ while (1) switch (_context.n) {
3542
+ case 0:
3543
+ return _context.a(2, idb.openDB('app-cache-db', 1, {
3544
+ upgrade: function upgrade(db) {
3545
+ db.createObjectStore(CACHE);
3546
+ }
3547
+ }));
3548
+ }
3549
+ }, _callee);
3550
+ }));
3551
+ return function openDatabase() {
3552
+ return _ref.apply(this, arguments);
3553
+ };
3554
+ }();
3555
+ var getCachedData = /*#__PURE__*/function () {
3556
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(key) {
3557
+ var db, cached;
3558
+ return _regenerator().w(function (_context2) {
3559
+ while (1) switch (_context2.n) {
3560
+ case 0:
3561
+ _context2.n = 1;
3562
+ return openDatabase();
3563
+ case 1:
3564
+ db = _context2.v;
3565
+ _context2.n = 2;
3566
+ return db.get(CACHE, key);
3567
+ case 2:
3568
+ cached = _context2.v;
3569
+ return _context2.a(2, cached ? cached.data : undefined);
3570
+ }
3571
+ }, _callee2);
3572
+ }));
3573
+ return function getCachedData(_x) {
3574
+ return _ref2.apply(this, arguments);
3575
+ };
3576
+ }();
3577
+ var setCachedData = /*#__PURE__*/function () {
3578
+ var _ref3 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(key, data) {
3579
+ var db;
3580
+ return _regenerator().w(function (_context3) {
3581
+ while (1) switch (_context3.n) {
3582
+ case 0:
3583
+ _context3.n = 1;
3584
+ return openDatabase();
3585
+ case 1:
3586
+ db = _context3.v;
3587
+ _context3.n = 2;
3588
+ return db.put(CACHE, {
3589
+ data: data,
3590
+ timestamp: Date.now()
3591
+ }, key);
3592
+ case 2:
3593
+ return _context3.a(2);
3594
+ }
3595
+ }, _callee3);
3596
+ }));
3597
+ return function setCachedData(_x2, _x3) {
3598
+ return _ref3.apply(this, arguments);
3599
+ };
3600
+ }();
3601
+ var deleteCachedData = /*#__PURE__*/function () {
3602
+ var _ref4 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(key) {
3603
+ var db;
3604
+ return _regenerator().w(function (_context4) {
3605
+ while (1) switch (_context4.n) {
3606
+ case 0:
3607
+ _context4.n = 1;
3608
+ return openDatabase();
3609
+ case 1:
3610
+ db = _context4.v;
3611
+ _context4.n = 2;
3612
+ return db["delete"](CACHE, key);
3613
+ case 2:
3614
+ return _context4.a(2);
3615
+ }
3616
+ }, _callee4);
3617
+ }));
3618
+ return function deleteCachedData(_x4) {
3619
+ return _ref4.apply(this, arguments);
3620
+ };
3621
+ }();
3622
+ var clearCache = /*#__PURE__*/function () {
3623
+ var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
3624
+ var db;
3625
+ return _regenerator().w(function (_context5) {
3626
+ while (1) switch (_context5.n) {
3627
+ case 0:
3628
+ _context5.n = 1;
3629
+ return openDatabase();
3630
+ case 1:
3631
+ db = _context5.v;
3632
+ _context5.n = 2;
3633
+ return db.clear(CACHE);
3634
+ case 2:
3635
+ return _context5.a(2);
3636
+ }
3637
+ }, _callee5);
3638
+ }));
3639
+ return function clearCache() {
3640
+ return _ref5.apply(this, arguments);
3641
+ };
3642
+ }();
3643
+ var clearExpiredCache = /*#__PURE__*/function () {
3644
+ var _ref6 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(maxAge) {
3645
+ var db, allKeys, now, _iterator, _step, key, cached;
3646
+ return _regenerator().w(function (_context6) {
3647
+ while (1) switch (_context6.n) {
3648
+ case 0:
3649
+ _context6.n = 1;
3650
+ return openDatabase();
3651
+ case 1:
3652
+ db = _context6.v;
3653
+ _context6.n = 2;
3654
+ return db.getAllKeys(CACHE);
3655
+ case 2:
3656
+ allKeys = _context6.v;
3657
+ now = Date.now();
3658
+ _iterator = _createForOfIteratorHelperLoose(allKeys);
3659
+ case 3:
3660
+ if ((_step = _iterator()).done) {
3661
+ _context6.n = 6;
3662
+ break;
3663
+ }
3664
+ key = _step.value;
3665
+ _context6.n = 4;
3666
+ return db.get(CACHE, key);
3667
+ case 4:
3668
+ cached = _context6.v;
3669
+ if (!(cached && now - cached.timestamp > maxAge)) {
3670
+ _context6.n = 5;
3671
+ break;
3672
+ }
3673
+ _context6.n = 5;
3674
+ return db["delete"](CACHE, key);
3675
+ case 5:
3676
+ _context6.n = 3;
3677
+ break;
3678
+ case 6:
3679
+ return _context6.a(2);
3680
+ }
3681
+ }, _callee6);
3682
+ }));
3683
+ return function clearExpiredCache(_x5) {
3684
+ return _ref6.apply(this, arguments);
3685
+ };
3686
+ }();
3687
+ var DEFAULT_MAX_AGE = 24 * 60 * 60 * 1000; // 1 day in milliseconds
3688
+ /**
3689
+ * Custom hook to manage IndexedDB cache with a specified maximum age.
3690
+ *
3691
+ * @template T - The type of data to be cached.
3692
+ * @param {number} [maxAge=DEFAULT_MAX_AGE] - The maximum age (in milliseconds) for cached data before it is considered expired.
3693
+ * @returns {UseIndexedDBCacheReturn<T>} An object containing methods to interact with the cache.
3694
+ *
3695
+ * @example
3696
+ * const { getData, setData, deleteData, clearAllCache } = useIndexedDBCache<MyDataType>(3600000);
3697
+ *
3698
+ * @function
3699
+ * @name useIndexedDBCache
3700
+ * @memberof hooks
3701
+ * @inner
3702
+ *
3703
+ * @typedef {Object} UseIndexedDBCacheReturn<T>
3704
+ * @property {function(string): Promise<T | undefined>} getData - Retrieves cached data by key.
3705
+ * @property {function(string, T): Promise<void>} setData - Caches data with a specified key.
3706
+ * @property {function(string): Promise<void>} deleteData - Deletes cached data by key.
3707
+ * @property {function(): Promise<void>} clearAllCache - Clears all cached data.
3708
+ */
3709
+ var useIndexedDBCache = function useIndexedDBCache(maxAge) {
3710
+ if (maxAge === void 0) {
3711
+ maxAge = DEFAULT_MAX_AGE;
3712
+ }
3713
+ React.useEffect(function () {
3714
+ // Clear expired cache on component mount
3715
+ _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
3716
+ return _regenerator().w(function (_context7) {
3717
+ while (1) switch (_context7.n) {
3718
+ case 0:
3719
+ _context7.n = 1;
3720
+ return clearExpiredCache(maxAge);
3721
+ case 1:
3722
+ return _context7.a(2);
3723
+ }
3724
+ }, _callee7);
3725
+ }))();
3726
+ }, [maxAge]);
3727
+ var getData = /*#__PURE__*/function () {
3728
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(key) {
3729
+ return _regenerator().w(function (_context8) {
3730
+ while (1) switch (_context8.n) {
3731
+ case 0:
3732
+ _context8.n = 1;
3733
+ return getCachedData(key);
3734
+ case 1:
3735
+ return _context8.a(2, _context8.v);
3736
+ }
3737
+ }, _callee8);
3738
+ }));
3739
+ return function getData(_x6) {
3740
+ return _ref8.apply(this, arguments);
3741
+ };
3742
+ }();
3743
+ var setData = /*#__PURE__*/function () {
3744
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(key, data) {
3745
+ return _regenerator().w(function (_context9) {
3746
+ while (1) switch (_context9.n) {
3747
+ case 0:
3748
+ _context9.n = 1;
3749
+ return setCachedData(key, data);
3750
+ case 1:
3751
+ return _context9.a(2);
3752
+ }
3753
+ }, _callee9);
3754
+ }));
3755
+ return function setData(_x7, _x8) {
3756
+ return _ref9.apply(this, arguments);
3757
+ };
3758
+ }();
3759
+ var deleteData = /*#__PURE__*/function () {
3760
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(key) {
3761
+ return _regenerator().w(function (_context0) {
3762
+ while (1) switch (_context0.n) {
3763
+ case 0:
3764
+ _context0.n = 1;
3765
+ return deleteCachedData(key);
3766
+ case 1:
3767
+ return _context0.a(2);
3768
+ }
3769
+ }, _callee0);
3770
+ }));
3771
+ return function deleteData(_x9) {
3772
+ return _ref0.apply(this, arguments);
3773
+ };
3774
+ }();
3775
+ var clearAllCache = /*#__PURE__*/function () {
3776
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
3777
+ return _regenerator().w(function (_context1) {
3778
+ while (1) switch (_context1.n) {
3779
+ case 0:
3780
+ _context1.n = 1;
3781
+ return clearCache();
3782
+ case 1:
3783
+ return _context1.a(2);
3784
+ }
3785
+ }, _callee1);
3786
+ }));
3787
+ return function clearAllCache() {
3788
+ return _ref1.apply(this, arguments);
3789
+ };
3790
+ }();
3791
+ return {
3792
+ getData: getData,
3793
+ setData: setData,
3794
+ deleteData: deleteData,
3795
+ clearAllCache: clearAllCache
3796
+ };
3797
+ };
3798
+
3512
3799
  var MINIMUM_DASHBOARD_WIDTH = 600;
3513
3800
  var MAX_ROWS = 4;
3514
3801
  var DASHBOARD_LAYOUT_CACHE_KEY = 'dashboard-layout-settings';
@@ -3526,11 +3813,11 @@ var Dashboard = function Dashboard(_ref) {
3526
3813
  var _useChartFactory = useChartFactory(),
3527
3814
  getChartComponent = _useChartFactory.getChartComponent;
3528
3815
  // Cache with 30-day expiration for dashboard layout settings
3529
- var _useIndexedDBCache = m365Hooks.useIndexedDBCache(CACHE_EXPIRATION_DAYS * 24 * 60 * 60 * 1000),
3816
+ var _useIndexedDBCache = useIndexedDBCache(CACHE_EXPIRATION_DAYS * 24 * 60 * 60 * 1000),
3530
3817
  getData = _useIndexedDBCache.getData,
3531
3818
  setData = _useIndexedDBCache.setData;
3532
3819
  // Cache for card order
3533
- var _useIndexedDBCache2 = m365Hooks.useIndexedDBCache(CACHE_EXPIRATION_DAYS * 24 * 60 * 60 * 1000),
3820
+ var _useIndexedDBCache2 = useIndexedDBCache(CACHE_EXPIRATION_DAYS * 24 * 60 * 60 * 1000),
3534
3821
  getOrderData = _useIndexedDBCache2.getData,
3535
3822
  setOrderData = _useIndexedDBCache2.setData;
3536
3823
  var _useState = React.useState([]),
@@ -3612,7 +3899,7 @@ var Dashboard = function Dashboard(_ref) {
3612
3899
  };
3613
3900
  }();
3614
3901
  initializeData();
3615
- }, [cardCharts, getData, getOrderData]);
3902
+ }, [cardCharts]); // Only depend on cardCharts - getData/getOrderData are stable
3616
3903
  // Save sizes to cache whenever they change
3617
3904
  React.useEffect(function () {
3618
3905
  var saveSizesToCache = /*#__PURE__*/function () {
@@ -3644,7 +3931,7 @@ var Dashboard = function Dashboard(_ref) {
3644
3931
  if (Object.keys(sizes).length > 0) {
3645
3932
  saveSizesToCache();
3646
3933
  }
3647
- }, [sizes, setData]);
3934
+ }, [sizes]); // Only depend on sizes - setData is stable
3648
3935
  // Save card order to cache whenever it changes
3649
3936
  React.useEffect(function () {
3650
3937
  var saveOrderToCache = /*#__PURE__*/function () {
@@ -3679,7 +3966,7 @@ var Dashboard = function Dashboard(_ref) {
3679
3966
  if (CardChartContainer.length > 0) {
3680
3967
  saveOrderToCache();
3681
3968
  }
3682
- }, [CardChartContainer, setOrderData]);
3969
+ }, [CardChartContainer]); // Only depend on CardChartContainer - setOrderData is stable
3683
3970
  React.useEffect(function () {
3684
3971
  if (containerWidth <= MINIMUM_DASHBOARD_WIDTH) {
3685
3972
  setSizes(function () {