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