@trops/dash-core 0.1.287 → 0.1.289

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
@@ -45477,7 +45477,7 @@ var useInstalledWidgets = function useInstalledWidgets() {
45477
45477
  *
45478
45478
  * @param {Array} installedWidgets - Widgets from useInstalledWidgets()
45479
45479
  * @param {Function} onUpdated - Callback after a successful update (e.g. refresh)
45480
- * @returns {{ updates: Map, isChecking: boolean, updateWidget: Function, isUpdating: string|null }}
45480
+ * @returns {{ updates: Map, isChecking: boolean, updateWidget: Function, isUpdating: string|null, needsAuth: boolean, clearNeedsAuth: Function, updateError: string|null }}
45481
45481
  */
45482
45482
  function useWidgetUpdates() {
45483
45483
  var installedWidgets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -45494,6 +45494,14 @@ function useWidgetUpdates() {
45494
45494
  _useState6 = _slicedToArray(_useState5, 2),
45495
45495
  isUpdating = _useState6[0],
45496
45496
  setIsUpdating = _useState6[1];
45497
+ var _useState7 = React.useState(false),
45498
+ _useState8 = _slicedToArray(_useState7, 2),
45499
+ needsAuth = _useState8[0],
45500
+ setNeedsAuth = _useState8[1];
45501
+ var _useState9 = React.useState(null),
45502
+ _useState0 = _slicedToArray(_useState9, 2),
45503
+ updateError = _useState0[0],
45504
+ setUpdateError = _useState0[1];
45497
45505
  var checkedRef = React.useRef(false);
45498
45506
 
45499
45507
  // Check for updates once when installed widgets are available
@@ -45544,7 +45552,7 @@ function useWidgetUpdates() {
45544
45552
  // Update a single widget by downloading the latest version
45545
45553
  var updateWidget = React.useCallback(/*#__PURE__*/function () {
45546
45554
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(name) {
45547
- var info, widget, packageId, resolvedUrl;
45555
+ var info, widget, packageId, _window$mainApi2, status, resolvedUrl, _t;
45548
45556
  return _regeneratorRuntime.wrap(function (_context) {
45549
45557
  while (1) switch (_context.prev = _context.next) {
45550
45558
  case 0:
@@ -45561,11 +45569,23 @@ function useWidgetUpdates() {
45561
45569
  });
45562
45570
  packageId = (widget === null || widget === void 0 ? void 0 : widget.packageId) || info.name || name;
45563
45571
  setIsUpdating(name);
45572
+ setUpdateError(null);
45564
45573
  _context.prev = 2;
45565
- resolvedUrl = info.downloadUrl.replace(/\{version\}/g, info.latestVersion).replace(/\{name\}/g, packageId);
45566
45574
  _context.next = 3;
45567
- return window.mainApi.widgets.install(packageId, resolvedUrl);
45575
+ return (_window$mainApi2 = window.mainApi) === null || _window$mainApi2 === void 0 || (_window$mainApi2 = _window$mainApi2.registryAuth) === null || _window$mainApi2 === void 0 ? void 0 : _window$mainApi2.getStatus();
45568
45576
  case 3:
45577
+ status = _context.sent;
45578
+ if (status !== null && status !== void 0 && status.authenticated) {
45579
+ _context.next = 4;
45580
+ break;
45581
+ }
45582
+ setNeedsAuth(true);
45583
+ return _context.abrupt("return");
45584
+ case 4:
45585
+ resolvedUrl = info.downloadUrl.replace(/\{version\}/g, info.latestVersion).replace(/\{name\}/g, packageId);
45586
+ _context.next = 5;
45587
+ return window.mainApi.widgets.install(packageId, resolvedUrl);
45588
+ case 5:
45569
45589
  // Remove from updates map on success
45570
45590
  setUpdates(function (prev) {
45571
45591
  var next = new Map(prev);
@@ -45573,30 +45593,37 @@ function useWidgetUpdates() {
45573
45593
  return next;
45574
45594
  });
45575
45595
  if (onUpdated) onUpdated();
45576
- _context.next = 5;
45596
+ _context.next = 7;
45577
45597
  break;
45578
- case 4:
45579
- _context.prev = 4;
45580
- _context["catch"](2);
45581
- case 5:
45582
- _context.prev = 5;
45583
- setIsUpdating(null);
45584
- return _context.finish(5);
45585
45598
  case 6:
45599
+ _context.prev = 6;
45600
+ _t = _context["catch"](2);
45601
+ setUpdateError(_t.message || "Update failed");
45602
+ case 7:
45603
+ _context.prev = 7;
45604
+ setIsUpdating(null);
45605
+ return _context.finish(7);
45606
+ case 8:
45586
45607
  case "end":
45587
45608
  return _context.stop();
45588
45609
  }
45589
- }, _callee, null, [[2, 4, 5, 6]]);
45610
+ }, _callee, null, [[2, 6, 7, 8]]);
45590
45611
  }));
45591
45612
  return function (_x) {
45592
45613
  return _ref.apply(this, arguments);
45593
45614
  };
45594
45615
  }(), [updates, onUpdated, installedWidgets]);
45616
+ var clearNeedsAuth = React.useCallback(function () {
45617
+ return setNeedsAuth(false);
45618
+ }, []);
45595
45619
  return {
45596
45620
  updates: updates,
45597
45621
  isChecking: isChecking,
45598
45622
  updateWidget: updateWidget,
45599
- isUpdating: isUpdating
45623
+ isUpdating: isUpdating,
45624
+ needsAuth: needsAuth,
45625
+ clearNeedsAuth: clearNeedsAuth,
45626
+ updateError: updateError
45600
45627
  };
45601
45628
  }
45602
45629
 
@@ -45624,7 +45651,9 @@ var WidgetsSection = function WidgetsSection(_ref) {
45624
45651
  var _useWidgetUpdates = useWidgetUpdates(widgets, refresh),
45625
45652
  updates = _useWidgetUpdates.updates,
45626
45653
  updateWidget = _useWidgetUpdates.updateWidget,
45627
- isUpdating = _useWidgetUpdates.isUpdating;
45654
+ isUpdating = _useWidgetUpdates.isUpdating,
45655
+ needsAuth = _useWidgetUpdates.needsAuth,
45656
+ clearNeedsAuth = _useWidgetUpdates.clearNeedsAuth;
45628
45657
  var _useState = React.useState(null),
45629
45658
  _useState2 = _slicedToArray(_useState, 2),
45630
45659
  selectedWidgetName = _useState2[0],
@@ -46348,7 +46377,16 @@ var WidgetsSection = function WidgetsSection(_ref) {
46348
46377
  })]
46349
46378
  })]
46350
46379
  })
46351
- }))]
46380
+ })), /*#__PURE__*/jsxRuntime.jsx(RegistryAuthModal, {
46381
+ isOpen: needsAuth,
46382
+ setIsOpen: function setIsOpen(open) {
46383
+ if (!open) clearNeedsAuth();
46384
+ },
46385
+ onAuthenticated: function onAuthenticated() {
46386
+ clearNeedsAuth();
46387
+ if (selectedWidget !== null && selectedWidget !== void 0 && selectedWidget.name) updateWidget(selectedWidget.name);
46388
+ }
46389
+ })]
46352
46390
  });
46353
46391
  };
46354
46392