@trops/dash-core 0.1.240 → 0.1.242

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.esm.js CHANGED
@@ -6291,11 +6291,37 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6291
6291
  createdDashboard = _useState12[0],
6292
6292
  setCreatedDashboard = _useState12[1];
6293
6293
 
6294
- // Sub-step state (DASH-188): 0 = Name, 1 = Folder, 2 = Theme
6295
- var _useState13 = useState(0),
6294
+ // Auth flow state (device-code auth for registry install)
6295
+ var _useState13 = useState(null),
6296
6296
  _useState14 = _slicedToArray(_useState13, 2),
6297
- subStep = _useState14[0],
6298
- setSubStep = _useState14[1];
6297
+ authNeeded = _useState14[0],
6298
+ setAuthNeeded = _useState14[1];
6299
+ var _useState15 = useState(null),
6300
+ _useState16 = _slicedToArray(_useState15, 2),
6301
+ authFlow = _useState16[0],
6302
+ setAuthFlow = _useState16[1];
6303
+ var _useState17 = useState(false),
6304
+ _useState18 = _slicedToArray(_useState17, 2),
6305
+ isPolling = _useState18[0],
6306
+ setIsPolling = _useState18[1];
6307
+ var _useState19 = useState(null),
6308
+ _useState20 = _slicedToArray(_useState19, 2),
6309
+ authError = _useState20[0],
6310
+ setAuthError = _useState20[1];
6311
+ var pollIntervalRef = useRef(null);
6312
+
6313
+ // Clean up polling on unmount
6314
+ useEffect(function () {
6315
+ return function () {
6316
+ if (pollIntervalRef.current) clearInterval(pollIntervalRef.current);
6317
+ };
6318
+ }, []);
6319
+
6320
+ // Sub-step state (DASH-188): 0 = Name, 1 = Folder, 2 = Theme
6321
+ var _useState21 = useState(0),
6322
+ _useState22 = _slicedToArray(_useState21, 2),
6323
+ subStep = _useState22[0],
6324
+ setSubStep = _useState22[1];
6299
6325
  var isPrebuilt = state.path === "prebuilt";
6300
6326
 
6301
6327
  // Initialize customization defaults when stepping into this step
@@ -6337,10 +6363,11 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6337
6363
  case 0:
6338
6364
  setCreating(true);
6339
6365
  setError(null);
6366
+ setAuthNeeded(null);
6340
6367
  _context2.prev = 1;
6341
6368
  _state$customization = state.customization, name = _state$customization.name, menuId = _state$customization.menuId, theme = _state$customization.theme;
6342
6369
  if (!(isPrebuilt && state.selectedDashboard)) {
6343
- _context2.next = 7;
6370
+ _context2.next = 9;
6344
6371
  break;
6345
6372
  }
6346
6373
  if (!onInstallDashboard) {
@@ -6357,19 +6384,27 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6357
6384
  });
6358
6385
  case 2:
6359
6386
  result = _context2.sent;
6360
- _context2.next = 6;
6387
+ _context2.next = 8;
6361
6388
  break;
6362
6389
  case 3:
6363
- if (!((_window$mainApi = window.mainApi) !== null && _window$mainApi !== void 0 && (_window$mainApi = _window$mainApi.registry) !== null && _window$mainApi !== void 0 && _window$mainApi.installDashboard)) {
6364
- _context2.next = 6;
6390
+ if (!((_window$mainApi = window.mainApi) !== null && _window$mainApi !== void 0 && (_window$mainApi = _window$mainApi.dashboardConfig) !== null && _window$mainApi !== void 0 && _window$mainApi.installDashboardFromRegistry)) {
6391
+ _context2.next = 8;
6365
6392
  break;
6366
6393
  }
6367
6394
  _context2.next = 4;
6368
- return window.mainApi.registry.installDashboard(appId, state.selectedDashboard.name || state.selectedDashboard.key);
6395
+ return window.mainApi.dashboardConfig.installDashboardFromRegistry(appId, state.selectedDashboard.name || state.selectedDashboard.key);
6369
6396
  case 4:
6370
6397
  installResult = _context2.sent;
6398
+ if (!(installResult !== null && installResult !== void 0 && installResult.authRequired)) {
6399
+ _context2.next = 5;
6400
+ break;
6401
+ }
6402
+ setAuthNeeded(installResult.error || "Sign in to install this dashboard.");
6403
+ setCreating(false);
6404
+ return _context2.abrupt("return");
6405
+ case 5:
6371
6406
  if (!(installResult !== null && installResult !== void 0 && installResult.workspace)) {
6372
- _context2.next = 6;
6407
+ _context2.next = 7;
6373
6408
  break;
6374
6409
  }
6375
6410
  updatedWorkspace = _objectSpread$B(_objectSpread$B({}, installResult.workspace), {}, {
@@ -6377,87 +6412,95 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6377
6412
  menuId: menuId || 1,
6378
6413
  themeKey: theme
6379
6414
  });
6380
- _context2.next = 5;
6415
+ _context2.next = 6;
6381
6416
  return window.mainApi.workspace.saveWorkspaceForApplication(appId, updatedWorkspace);
6382
- case 5:
6417
+ case 6:
6383
6418
  result = {
6384
6419
  success: true,
6385
6420
  workspace: updatedWorkspace
6386
6421
  };
6387
- case 6:
6388
- _context2.next = 25;
6422
+ _context2.next = 8;
6389
6423
  break;
6390
6424
  case 7:
6425
+ if (!(installResult !== null && installResult !== void 0 && installResult.error)) {
6426
+ _context2.next = 8;
6427
+ break;
6428
+ }
6429
+ throw new Error(installResult.error);
6430
+ case 8:
6431
+ _context2.next = 27;
6432
+ break;
6433
+ case 9:
6391
6434
  // Build-your-own path: create layout from template + place widgets
6392
6435
  template = layoutTemplates.find(function (t) {
6393
6436
  return t.id === state.layout.templateKey;
6394
6437
  });
6395
6438
  if (template) {
6396
- _context2.next = 8;
6439
+ _context2.next = 10;
6397
6440
  break;
6398
6441
  }
6399
6442
  throw new Error("No layout template selected.");
6400
- case 8:
6443
+ case 10:
6401
6444
  if (!((_window$mainApi2 = window.mainApi) !== null && _window$mainApi2 !== void 0 && _window$mainApi2.widgets)) {
6402
- _context2.next = 18;
6445
+ _context2.next = 20;
6403
6446
  break;
6404
6447
  }
6405
- _context2.next = 9;
6448
+ _context2.next = 11;
6406
6449
  return window.mainApi.widgets.list();
6407
- case 9:
6450
+ case 11:
6408
6451
  _t = _context2.sent;
6409
6452
  if (_t) {
6410
- _context2.next = 10;
6453
+ _context2.next = 12;
6411
6454
  break;
6412
6455
  }
6413
6456
  _t = [];
6414
- case 10:
6457
+ case 12:
6415
6458
  installedList = _t;
6416
6459
  installedNames = new Set(installedList.map(function (w) {
6417
6460
  return w.name;
6418
6461
  }));
6419
6462
  _iterator = _createForOfIteratorHelper$e(state.selectedWidgets);
6420
- _context2.prev = 11;
6463
+ _context2.prev = 13;
6421
6464
  _iterator.s();
6422
- case 12:
6465
+ case 14:
6423
6466
  if ((_step = _iterator.n()).done) {
6424
- _context2.next = 15;
6467
+ _context2.next = 17;
6425
6468
  break;
6426
6469
  }
6427
6470
  widget = _step.value;
6428
6471
  if (widget.isRegistry) {
6429
- _context2.next = 13;
6472
+ _context2.next = 15;
6430
6473
  break;
6431
6474
  }
6432
- return _context2.abrupt("continue", 14);
6433
- case 13:
6475
+ return _context2.abrupt("continue", 16);
6476
+ case 15:
6434
6477
  scopedId = widget.packageScope ? "@".concat(widget.packageScope.replace(/^@/, ""), "/").concat(widget.packageName) : widget.packageName;
6435
6478
  if (!(!installedNames.has(scopedId) && !installedNames.has(widget.packageName))) {
6436
- _context2.next = 14;
6479
+ _context2.next = 16;
6437
6480
  break;
6438
6481
  }
6439
6482
  resolvedUrl = (widget.downloadUrl || "").replace(/\{version\}/g, widget.packageVersion || "").replace(/\{name\}/g, widget.packageName || "");
6440
6483
  if (!resolvedUrl) {
6441
- _context2.next = 14;
6484
+ _context2.next = 16;
6442
6485
  break;
6443
6486
  }
6444
- _context2.next = 14;
6487
+ _context2.next = 16;
6445
6488
  return window.mainApi.widgets.install(scopedId, resolvedUrl);
6446
- case 14:
6447
- _context2.next = 12;
6489
+ case 16:
6490
+ _context2.next = 14;
6448
6491
  break;
6449
- case 15:
6450
- _context2.next = 17;
6492
+ case 17:
6493
+ _context2.next = 19;
6451
6494
  break;
6452
- case 16:
6453
- _context2.prev = 16;
6454
- _t2 = _context2["catch"](11);
6495
+ case 18:
6496
+ _context2.prev = 18;
6497
+ _t2 = _context2["catch"](13);
6455
6498
  _iterator.e(_t2);
6456
- case 17:
6457
- _context2.prev = 17;
6499
+ case 19:
6500
+ _context2.prev = 19;
6458
6501
  _iterator.f();
6459
- return _context2.finish(17);
6460
- case 18:
6502
+ return _context2.finish(19);
6503
+ case 20:
6461
6504
  layoutObj = createLayoutFromTemplate(template, menuId || 1); // Place widgets into grid cells as proper layout items
6462
6505
  widgetOrder = state.layout.widgetOrder || [];
6463
6506
  cells = template.cells.filter(function (c) {
@@ -6494,31 +6537,31 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6494
6537
  }, _loop);
6495
6538
  });
6496
6539
  i = 0;
6497
- case 19:
6540
+ case 21:
6498
6541
  if (!(i < widgetOrder.length && i < cells.length)) {
6499
- _context2.next = 21;
6542
+ _context2.next = 23;
6500
6543
  break;
6501
6544
  }
6502
- return _context2.delegateYield(_loop(i), "t0", 20);
6503
- case 20:
6545
+ return _context2.delegateYield(_loop(i), "t0", 22);
6546
+ case 22:
6504
6547
  i++;
6505
- _context2.next = 19;
6548
+ _context2.next = 21;
6506
6549
  break;
6507
- case 21:
6550
+ case 23:
6508
6551
  fullLayout = [layoutObj].concat(widgetItems);
6509
6552
  if (!onCreateWorkspace) {
6510
- _context2.next = 23;
6553
+ _context2.next = 25;
6511
6554
  break;
6512
6555
  }
6513
- _context2.next = 22;
6556
+ _context2.next = 24;
6514
6557
  return onCreateWorkspace(fullLayout, theme, name.trim());
6515
- case 22:
6558
+ case 24:
6516
6559
  result = _context2.sent;
6517
- _context2.next = 25;
6560
+ _context2.next = 27;
6518
6561
  break;
6519
- case 23:
6562
+ case 25:
6520
6563
  if (!((_window$mainApi3 = window.mainApi) !== null && _window$mainApi3 !== void 0 && (_window$mainApi3 = _window$mainApi3.workspace) !== null && _window$mainApi3 !== void 0 && _window$mainApi3.saveWorkspaceForApplication)) {
6521
- _context2.next = 25;
6564
+ _context2.next = 27;
6522
6565
  break;
6523
6566
  }
6524
6567
  workspace = {
@@ -6527,32 +6570,32 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6527
6570
  themeKey: theme,
6528
6571
  layout: fullLayout
6529
6572
  };
6530
- _context2.next = 24;
6573
+ _context2.next = 26;
6531
6574
  return window.mainApi.workspace.saveWorkspaceForApplication(appId, workspace);
6532
- case 24:
6575
+ case 26:
6533
6576
  result = {
6534
6577
  success: true,
6535
6578
  workspace: workspace
6536
6579
  };
6537
- case 25:
6580
+ case 27:
6538
6581
  if (result) {
6539
6582
  setCreatedDashboard(result.workspace || result);
6540
6583
  }
6541
- _context2.next = 27;
6584
+ _context2.next = 29;
6542
6585
  break;
6543
- case 26:
6544
- _context2.prev = 26;
6586
+ case 28:
6587
+ _context2.prev = 28;
6545
6588
  _t3 = _context2["catch"](1);
6546
6589
  setError(_t3.message || "Failed to create dashboard.");
6547
- case 27:
6548
- _context2.prev = 27;
6590
+ case 29:
6591
+ _context2.prev = 29;
6549
6592
  setCreating(false);
6550
- return _context2.finish(27);
6551
- case 28:
6593
+ return _context2.finish(29);
6594
+ case 30:
6552
6595
  case "end":
6553
6596
  return _context2.stop();
6554
6597
  }
6555
- }, _callee, null, [[1, 26, 27, 28], [11, 16, 17, 18]]);
6598
+ }, _callee, null, [[1, 28, 29, 30], [13, 18, 19, 20]]);
6556
6599
  })), [state, isPrebuilt, onInstallDashboard, onCreateWorkspace, appId]);
6557
6600
 
6558
6601
  // Expose handleCreate and creating state to parent via ref (DASH-183)
@@ -6621,7 +6664,80 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6621
6664
  setNewFolderIcon(null);
6622
6665
  }
6623
6666
 
6624
- // --- Success state ---
6667
+ // --- Registry auth sign-in (device-code flow) ---
6668
+ function handleSignIn() {
6669
+ return _handleSignIn.apply(this, arguments);
6670
+ } // --- Success state ---
6671
+ function _handleSignIn() {
6672
+ _handleSignIn = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
6673
+ var flow, interval;
6674
+ return _regeneratorRuntime.wrap(function (_context4) {
6675
+ while (1) switch (_context4.prev = _context4.next) {
6676
+ case 0:
6677
+ setAuthError(null);
6678
+ _context4.prev = 1;
6679
+ _context4.next = 2;
6680
+ return window.mainApi.registryAuth.initiateLogin();
6681
+ case 2:
6682
+ flow = _context4.sent;
6683
+ setAuthFlow(flow);
6684
+ if (flow.verificationUrlComplete) {
6685
+ window.mainApi.shell.openExternal(flow.verificationUrlComplete);
6686
+ }
6687
+ setIsPolling(true);
6688
+ interval = (flow.interval || 5) * 1000;
6689
+ pollIntervalRef.current = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
6690
+ var pollResult;
6691
+ return _regeneratorRuntime.wrap(function (_context3) {
6692
+ while (1) switch (_context3.prev = _context3.next) {
6693
+ case 0:
6694
+ _context3.prev = 0;
6695
+ _context3.next = 1;
6696
+ return window.mainApi.registryAuth.pollToken(flow.deviceCode);
6697
+ case 1:
6698
+ pollResult = _context3.sent;
6699
+ if (pollResult.status === "authorized") {
6700
+ clearInterval(pollIntervalRef.current);
6701
+ pollIntervalRef.current = null;
6702
+ setIsPolling(false);
6703
+ setAuthFlow(null);
6704
+ setAuthNeeded(null);
6705
+ handleCreate();
6706
+ } else if (pollResult.status === "expired") {
6707
+ clearInterval(pollIntervalRef.current);
6708
+ pollIntervalRef.current = null;
6709
+ setIsPolling(false);
6710
+ setAuthFlow(null);
6711
+ setAuthError("Authorization expired. Please try again.");
6712
+ }
6713
+ _context3.next = 3;
6714
+ break;
6715
+ case 2:
6716
+ _context3.prev = 2;
6717
+ _context3["catch"](0);
6718
+ clearInterval(pollIntervalRef.current);
6719
+ pollIntervalRef.current = null;
6720
+ setIsPolling(false);
6721
+ case 3:
6722
+ case "end":
6723
+ return _context3.stop();
6724
+ }
6725
+ }, _callee2, null, [[0, 2]]);
6726
+ })), interval);
6727
+ _context4.next = 4;
6728
+ break;
6729
+ case 3:
6730
+ _context4.prev = 3;
6731
+ _context4["catch"](1);
6732
+ setAuthError("Could not reach the registry. Check your connection and try again.");
6733
+ case 4:
6734
+ case "end":
6735
+ return _context4.stop();
6736
+ }
6737
+ }, _callee3, null, [[1, 3]]);
6738
+ }));
6739
+ return _handleSignIn.apply(this, arguments);
6740
+ }
6625
6741
  if (createdDashboard) {
6626
6742
  return /*#__PURE__*/jsx("div", {
6627
6743
  className: "flex flex-col gap-4",
@@ -6985,6 +7101,55 @@ var WizardCustomizeStep = function WizardCustomizeStep(_ref) {
6985
7101
  children: isPrebuilt ? ((_state$selectedDashbo = state.selectedDashboard) === null || _state$selectedDashbo === void 0 ? void 0 : _state$selectedDashbo.displayName) || ((_state$selectedDashbo2 = state.selectedDashboard) === null || _state$selectedDashbo2 === void 0 ? void 0 : _state$selectedDashbo2.name) || "Pre-built dashboard" : "".concat(state.selectedWidgets.length, " widget").concat(state.selectedWidgets.length !== 1 ? "s" : "")
6986
7102
  })]
6987
7103
  })]
7104
+ }), authNeeded && /*#__PURE__*/jsxs("div", {
7105
+ className: "flex flex-col gap-3",
7106
+ children: [/*#__PURE__*/jsx("div", {
7107
+ className: "bg-yellow-500/10 border border-yellow-500/20 rounded-lg p-3",
7108
+ children: /*#__PURE__*/jsxs("div", {
7109
+ className: "flex items-start gap-2",
7110
+ children: [/*#__PURE__*/jsx(FontAwesomeIcon, {
7111
+ icon: "lock",
7112
+ className: "h-3.5 w-3.5 text-yellow-400 mt-0.5 flex-shrink-0"
7113
+ }), /*#__PURE__*/jsx("span", {
7114
+ className: "text-sm text-yellow-300/90",
7115
+ children: authNeeded
7116
+ })]
7117
+ })
7118
+ }), !authFlow && !isPolling && /*#__PURE__*/jsxs(Fragment, {
7119
+ children: [/*#__PURE__*/jsx("button", {
7120
+ type: "button",
7121
+ onClick: handleSignIn,
7122
+ className: "px-4 py-2 rounded-lg text-sm bg-blue-500/20 border border-blue-500/30 text-blue-300 hover:bg-blue-500/30 transition-colors cursor-pointer",
7123
+ children: "Sign in to Registry"
7124
+ }), authError && /*#__PURE__*/jsx("div", {
7125
+ className: "bg-red-500/10 border border-red-500/20 rounded-lg p-3",
7126
+ children: /*#__PURE__*/jsxs("div", {
7127
+ className: "flex items-start gap-2",
7128
+ children: [/*#__PURE__*/jsx(FontAwesomeIcon, {
7129
+ icon: "circle-xmark",
7130
+ className: "h-3.5 w-3.5 text-red-400 mt-0.5 flex-shrink-0"
7131
+ }), /*#__PURE__*/jsx("span", {
7132
+ className: "text-xs text-red-300/90",
7133
+ children: authError
7134
+ })]
7135
+ })
7136
+ })]
7137
+ }), authFlow && isPolling && /*#__PURE__*/jsxs("div", {
7138
+ className: "bg-blue-500/10 border border-blue-500/20 rounded-lg p-4 space-y-3",
7139
+ children: [/*#__PURE__*/jsx("p", {
7140
+ className: "text-xs text-blue-300/90",
7141
+ children: "Enter this code in your browser:"
7142
+ }), /*#__PURE__*/jsx("div", {
7143
+ className: "text-center",
7144
+ children: /*#__PURE__*/jsx("span", {
7145
+ className: "text-2xl font-mono font-bold tracking-widest text-white",
7146
+ children: authFlow.userCode
7147
+ })
7148
+ }), /*#__PURE__*/jsx("p", {
7149
+ className: "text-xs text-blue-300/70 text-center",
7150
+ children: "Waiting for authorization \u2014 install will resume automatically..."
7151
+ })]
7152
+ })]
6988
7153
  }), error && /*#__PURE__*/jsxs("div", {
6989
7154
  className: "flex items-center gap-2 text-red-400 py-2",
6990
7155
  children: [/*#__PURE__*/jsx(FontAwesomeIcon, {