@trops/dash-core 0.1.180 → 0.1.182

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
@@ -33241,8 +33241,21 @@ var ThemeQuickCreate = function ThemeQuickCreate(_ref8) {
33241
33241
  _ref8$onExtract = _ref8.onExtract,
33242
33242
  onExtract = _ref8$onExtract === void 0 ? null : _ref8$onExtract,
33243
33243
  _ref8$onMapToTheme = _ref8.onMapToTheme,
33244
- onMapToTheme = _ref8$onMapToTheme === void 0 ? null : _ref8$onMapToTheme;
33244
+ onMapToTheme = _ref8$onMapToTheme === void 0 ? null : _ref8$onMapToTheme,
33245
+ _ref8$initialMethod = _ref8.initialMethod,
33246
+ initialMethod = _ref8$initialMethod === void 0 ? null : _ref8$initialMethod;
33245
33247
  var canCreate = wizardName.trim().length > 0 && wizardTheme !== null;
33248
+ var showMethodPicker = initialMethod === null;
33249
+ React.useEffect(function () {
33250
+ if (initialMethod && wizardMethod !== initialMethod) {
33251
+ setWizardMethod(initialMethod);
33252
+ setWizardTheme(null);
33253
+ if (initialMethod === "random") {
33254
+ setWizardTheme(generateRandomTheme());
33255
+ }
33256
+ }
33257
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33258
+ }, [initialMethod]);
33246
33259
  function handleMethodSelect(method) {
33247
33260
  setWizardMethod(method);
33248
33261
  setWizardTheme(null);
@@ -33264,7 +33277,7 @@ var ThemeQuickCreate = function ThemeQuickCreate(_ref8) {
33264
33277
  },
33265
33278
  placeholder: "Theme name..."
33266
33279
  })]
33267
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
33280
+ }), showMethodPicker && /*#__PURE__*/jsxRuntime.jsxs("div", {
33268
33281
  className: "flex flex-col gap-2",
33269
33282
  children: [/*#__PURE__*/jsxRuntime.jsx("span", {
33270
33283
  className: "text-sm font-semibold opacity-50",
@@ -33362,9 +33375,7 @@ var ChooserCard = function ChooserCard(_ref) {
33362
33375
  };
33363
33376
  var ThemeNewChooser = function ThemeNewChooser(_ref2) {
33364
33377
  var onSearchThemes = _ref2.onSearchThemes,
33365
- onCreateNew = _ref2.onCreateNew,
33366
- _ref2$onCreateFromUrl = _ref2.onCreateFromUrl,
33367
- onCreateFromUrl = _ref2$onCreateFromUrl === void 0 ? null : _ref2$onCreateFromUrl;
33378
+ onSelectMethod = _ref2.onSelectMethod;
33368
33379
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
33369
33380
  className: "flex flex-col gap-6 p-6 overflow-y-auto flex-1 min-h-0",
33370
33381
  children: [/*#__PURE__*/jsxRuntime.jsx("span", {
@@ -33374,19 +33385,37 @@ var ThemeNewChooser = function ThemeNewChooser(_ref2) {
33374
33385
  className: "grid grid-cols-2 gap-3",
33375
33386
  children: [/*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33376
33387
  icon: "magnifying-glass",
33377
- title: "Search for Themes",
33378
- subtitle: "Browse the theme marketplace",
33388
+ title: "Search Marketplace",
33389
+ subtitle: "Browse community themes",
33379
33390
  onClick: onSearchThemes
33380
33391
  }), /*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33381
- icon: "wand-magic-sparkles",
33382
- title: "Create New",
33383
- subtitle: "Build from presets, random palettes, or color harmony rules",
33384
- onClick: onCreateNew
33385
- }), onCreateFromUrl && /*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33392
+ icon: "swatchbook",
33393
+ title: "From Presets",
33394
+ subtitle: "Start from a curated preset",
33395
+ onClick: function onClick() {
33396
+ return onSelectMethod("presets");
33397
+ }
33398
+ }), /*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33399
+ icon: "droplet",
33400
+ title: "From Colors",
33401
+ subtitle: "Build from a color palette",
33402
+ onClick: function onClick() {
33403
+ return onSelectMethod("color");
33404
+ }
33405
+ }), /*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33406
+ icon: "shuffle",
33407
+ title: "From Random",
33408
+ subtitle: "Generate a random theme",
33409
+ onClick: function onClick() {
33410
+ return onSelectMethod("random");
33411
+ }
33412
+ }), /*#__PURE__*/jsxRuntime.jsx(ChooserCard, {
33386
33413
  icon: "globe",
33387
33414
  title: "From Website",
33388
- subtitle: "Extract colors from any URL to create a theme",
33389
- onClick: onCreateFromUrl
33415
+ subtitle: "Extract colors from any URL",
33416
+ onClick: function onClick() {
33417
+ return onSelectMethod("from-url");
33418
+ }
33390
33419
  })]
33391
33420
  })]
33392
33421
  });
@@ -34074,10 +34103,10 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34074
34103
  _useState12 = _slicedToArray(_useState11, 2),
34075
34104
  isSearching = _useState12[0],
34076
34105
  setIsSearching = _useState12[1];
34077
- var _useState13 = React.useState(false),
34106
+ var _useState13 = React.useState(null),
34078
34107
  _useState14 = _slicedToArray(_useState13, 2),
34079
- isFromUrl = _useState14[0],
34080
- setIsFromUrl = _useState14[1];
34108
+ selectedMethod = _useState14[0],
34109
+ setSelectedMethod = _useState14[1];
34081
34110
  var _useState15 = React.useState(""),
34082
34111
  _useState16 = _slicedToArray(_useState15, 2),
34083
34112
  wizardName = _useState16[0],
@@ -34105,7 +34134,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34105
34134
  setIsCreating(false);
34106
34135
  setIsChoosingMode(false);
34107
34136
  setIsSearching(false);
34108
- setIsFromUrl(false);
34137
+ setSelectedMethod(null);
34109
34138
  } else {
34110
34139
  if (themeKeySelected === null && themes) {
34111
34140
  var themeKeyTemp = settings && "theme" in settings ? settings["theme"] in themes ? settings["theme"] : Object.keys(themes)[0] : Object.keys(themes)[0];
@@ -34148,10 +34177,12 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34148
34177
  setIsCreating(false);
34149
34178
  setIsSearching(false);
34150
34179
  setIsEditing(false);
34180
+ setSelectedMethod(null);
34151
34181
  }
34152
- function handleChooseCreate() {
34182
+ function handleSelectMethod(method) {
34153
34183
  setIsChoosingMode(false);
34154
34184
  setIsCreating(true);
34185
+ setSelectedMethod(method);
34155
34186
  setWizardName("");
34156
34187
  setWizardMethod(null);
34157
34188
  setWizardTheme(null);
@@ -34160,10 +34191,6 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34160
34191
  setIsChoosingMode(false);
34161
34192
  setIsSearching(true);
34162
34193
  }
34163
- function handleChooseFromUrl() {
34164
- setIsChoosingMode(false);
34165
- setIsFromUrl(true);
34166
- }
34167
34194
  function handleBackFromSearch() {
34168
34195
  setIsSearching(false);
34169
34196
  setIsChoosingMode(true);
@@ -34222,24 +34249,6 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34222
34249
  }));
34223
34250
  return _handleUrlMapToTheme.apply(this, arguments);
34224
34251
  }
34225
- function handleUrlThemeGenerated(theme) {
34226
- var key = theme.id || "theme-".concat(Date.now());
34227
- var finalTheme = _objectSpread$c(_objectSpread$c({}, theme), {}, {
34228
- id: key
34229
- });
34230
- if (dashApi) {
34231
- dashApi.saveTheme(credentials.appId, key, finalTheme, function (e, message) {
34232
- changeThemesForApplication(message["themes"]);
34233
- setIsFromUrl(false);
34234
- var newThemes = message["themes"];
34235
- if (newThemes && newThemes[key]) {
34236
- setThemeKeySelected(key);
34237
- setThemeSelected(newThemes[key]);
34238
- setRawThemeSelected(finalTheme);
34239
- }
34240
- }, handleSaveThemeError);
34241
- }
34242
- }
34243
34252
  function handleWizardComplete() {
34244
34253
  if (!wizardTheme || !wizardName.trim()) return;
34245
34254
  var key = wizardTheme.id || "theme-".concat(Date.now());
@@ -34252,6 +34261,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34252
34261
  changeThemesForApplication(message["themes"]);
34253
34262
  setIsCreating(false);
34254
34263
  setIsEditing(false);
34264
+ setSelectedMethod(null);
34255
34265
  var newThemes = message["themes"];
34256
34266
  if (newThemes && newThemes[key]) {
34257
34267
  setThemeKeySelected(key);
@@ -34265,7 +34275,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34265
34275
  setIsCreating(false);
34266
34276
  setIsChoosingMode(false);
34267
34277
  setIsSearching(false);
34268
- setIsFromUrl(false);
34278
+ setSelectedMethod(null);
34269
34279
  }
34270
34280
  function handleSaveTheme() {
34271
34281
  if (themeKeySelected !== null && rawThemeSelected !== null) {
@@ -34320,6 +34330,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34320
34330
  setThemeSelected(null);
34321
34331
  setIsEditing(false);
34322
34332
  }
34333
+ var isInWizardFlow = isCreating || isChoosingMode || isSearching;
34323
34334
  return /*#__PURE__*/jsxRuntime.jsx(DashReact.Modal, {
34324
34335
  isOpen: open,
34325
34336
  setIsOpen: setIsOpen,
@@ -34344,8 +34355,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34344
34355
  rawTheme: rawThemeSelected,
34345
34356
  wizardContent: isChoosingMode ? /*#__PURE__*/jsxRuntime.jsx(ThemeNewChooser, {
34346
34357
  onSearchThemes: handleChooseSearch,
34347
- onCreateNew: handleChooseCreate,
34348
- onCreateFromUrl: handleChooseFromUrl
34358
+ onSelectMethod: handleSelectMethod
34349
34359
  }) : isSearching ? /*#__PURE__*/jsxRuntime.jsx(DiscoverThemesDetail, {
34350
34360
  onBack: handleBackFromSearch,
34351
34361
  appId: credentials === null || credentials === void 0 ? void 0 : credentials.appId,
@@ -34366,12 +34376,9 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34366
34376
  wizardTheme: wizardTheme,
34367
34377
  setWizardTheme: setWizardTheme,
34368
34378
  onComplete: handleWizardComplete,
34369
- onExtract: handleUrlExtract,
34370
- onMapToTheme: handleUrlMapToTheme
34371
- }) : isFromUrl ? /*#__PURE__*/jsxRuntime.jsx(DashReact.ThemeFromUrlPane, {
34372
34379
  onExtract: handleUrlExtract,
34373
34380
  onMapToTheme: handleUrlMapToTheme,
34374
- onGenerate: handleUrlThemeGenerated
34381
+ initialMethod: selectedMethod
34375
34382
  }) : null
34376
34383
  }), !isCreating && themeSelected && isEditing === true && /*#__PURE__*/jsxRuntime.jsx(PanelTheme, {
34377
34384
  theme: themeSelected,
@@ -34392,13 +34399,13 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34392
34399
  children: themeKeySelected
34393
34400
  })]
34394
34401
  })
34395
- }), (isCreating || isChoosingMode || isSearching || isFromUrl) && /*#__PURE__*/jsxRuntime.jsx("div", {
34402
+ }), isInWizardFlow && /*#__PURE__*/jsxRuntime.jsx("div", {
34396
34403
  className: "flex flex-row space-x-2",
34397
34404
  children: /*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
34398
34405
  onClick: handleCancelCreate,
34399
34406
  title: "Cancel"
34400
34407
  })
34401
- }), !isCreating && !isChoosingMode && !isSearching && !isFromUrl && isEditing === false && /*#__PURE__*/jsxRuntime.jsxs("div", {
34408
+ }), !isInWizardFlow && isEditing === false && /*#__PURE__*/jsxRuntime.jsxs("div", {
34402
34409
  className: "flex flex-row space-x-2",
34403
34410
  children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
34404
34411
  onClick: function onClick() {
@@ -34417,7 +34424,7 @@ var ThemeManagerModal = function ThemeManagerModal(_ref) {
34417
34424
  onClick: handleActivateTheme,
34418
34425
  title: "Activate"
34419
34426
  })]
34420
- }), !isCreating && !isChoosingMode && !isSearching && !isFromUrl && isEditing === true && /*#__PURE__*/jsxRuntime.jsxs("div", {
34427
+ }), !isInWizardFlow && isEditing === true && /*#__PURE__*/jsxRuntime.jsxs("div", {
34421
34428
  className: "flex flex-row space-x-2",
34422
34429
  children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
34423
34430
  onClick: function onClick() {
@@ -38605,6 +38612,16 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38605
38612
  _useState10 = _slicedToArray(_useState1, 2),
38606
38613
  errors = _useState10[0],
38607
38614
  setErrors = _useState10[1];
38615
+ var _useState11 = React.useState(false),
38616
+ _useState12 = _slicedToArray(_useState11, 2),
38617
+ isWsTesting = _useState12[0],
38618
+ setIsWsTesting = _useState12[1];
38619
+ var _useState13 = React.useState(null),
38620
+ _useState14 = _slicedToArray(_useState13, 2),
38621
+ wsTestResult = _useState14[0],
38622
+ setWsTestResult = _useState14[1];
38623
+ var appContext = React.useContext(AppContext);
38624
+ var dashApi = appContext === null || appContext === void 0 ? void 0 : appContext.dashApi;
38608
38625
  var nextRowIdRef = React.useRef(0);
38609
38626
  var nextRowId = function nextRowId() {
38610
38627
  return "ws_hdr_".concat(++nextRowIdRef.current);
@@ -38694,6 +38711,92 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38694
38711
  });
38695
38712
  });
38696
38713
  }
38714
+ function handleTestConnection() {
38715
+ return _handleTestConnection.apply(this, arguments);
38716
+ }
38717
+ function _handleTestConnection() {
38718
+ _handleTestConnection = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
38719
+ var headers, _iterator4, _step4, row, subprotoArray, testName, startTime, result, latency, _t;
38720
+ return _regeneratorRuntime.wrap(function (_context) {
38721
+ while (1) switch (_context.prev = _context.next) {
38722
+ case 0:
38723
+ if (!(!(dashApi !== null && dashApi !== void 0 && dashApi.webSocket) || !url.trim() || !isValidWsUrl(url))) {
38724
+ _context.next = 1;
38725
+ break;
38726
+ }
38727
+ return _context.abrupt("return");
38728
+ case 1:
38729
+ setIsWsTesting(true);
38730
+ setWsTestResult(null);
38731
+
38732
+ // Build config from current form state (same as handleSave)
38733
+ headers = {};
38734
+ _iterator4 = _createForOfIteratorHelper$4(headerRows);
38735
+ try {
38736
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
38737
+ row = _step4.value;
38738
+ if (row.key.trim()) {
38739
+ headers[row.key.trim()] = row.value;
38740
+ }
38741
+ }
38742
+ } catch (err) {
38743
+ _iterator4.e(err);
38744
+ } finally {
38745
+ _iterator4.f();
38746
+ }
38747
+ subprotoArray = subprotocols.split(",").map(function (s) {
38748
+ return s.trim();
38749
+ }).filter(Boolean);
38750
+ testName = name.trim() || "__ws_test__";
38751
+ startTime = Date.now();
38752
+ _context.prev = 2;
38753
+ _context.next = 3;
38754
+ return dashApi.webSocket.connect(testName, {
38755
+ url: url.trim(),
38756
+ headers: Object.keys(headers).length > 0 ? headers : null,
38757
+ subprotocols: subprotoArray.length > 0 ? subprotoArray : null,
38758
+ credentials: Object.keys(credentials).length > 0 ? credentials : null
38759
+ });
38760
+ case 3:
38761
+ result = _context.sent;
38762
+ latency = Date.now() - startTime;
38763
+ if (!result.error) {
38764
+ _context.next = 4;
38765
+ break;
38766
+ }
38767
+ setWsTestResult({
38768
+ success: false,
38769
+ message: result.message || "Connection failed"
38770
+ });
38771
+ _context.next = 5;
38772
+ break;
38773
+ case 4:
38774
+ setWsTestResult({
38775
+ success: true,
38776
+ message: "Connected in ".concat(latency, "ms")
38777
+ });
38778
+ _context.next = 5;
38779
+ return dashApi.webSocket.disconnect(testName)["catch"](function () {});
38780
+ case 5:
38781
+ _context.next = 7;
38782
+ break;
38783
+ case 6:
38784
+ _context.prev = 6;
38785
+ _t = _context["catch"](2);
38786
+ setWsTestResult({
38787
+ success: false,
38788
+ message: (_t === null || _t === void 0 ? void 0 : _t.message) || "Connection failed"
38789
+ });
38790
+ case 7:
38791
+ setIsWsTesting(false);
38792
+ case 8:
38793
+ case "end":
38794
+ return _context.stop();
38795
+ }
38796
+ }, _callee, null, [[2, 6]]);
38797
+ }));
38798
+ return _handleTestConnection.apply(this, arguments);
38799
+ }
38697
38800
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
38698
38801
  className: "flex flex-col flex-1 min-h-0",
38699
38802
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
@@ -38712,7 +38815,7 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38712
38815
  return setName(value);
38713
38816
  },
38714
38817
  placeholder: "e.g., crypto-ws, stock-feed",
38715
- error: !!errors.name
38818
+ inputClassName: errors.name ? "border-red-500" : ""
38716
38819
  }), errors.name && /*#__PURE__*/jsxRuntime.jsx("span", {
38717
38820
  className: "text-xs text-red-400",
38718
38821
  children: errors.name
@@ -38728,7 +38831,7 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38728
38831
  return setUrl(value);
38729
38832
  },
38730
38833
  placeholder: "wss://api.example.com/ws or ws://localhost:8080",
38731
- error: !!errors.url
38834
+ inputClassName: errors.url ? "border-red-500" : ""
38732
38835
  }), errors.url && /*#__PURE__*/jsxRuntime.jsx("span", {
38733
38836
  className: "text-xs text-red-400",
38734
38837
  children: errors.url
@@ -38836,17 +38939,32 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38836
38939
  });
38837
38940
  },
38838
38941
  placeholder: "Enter ".concat(field),
38839
- error: !!errors["cred_".concat(field)]
38942
+ inputClassName: errors["cred_".concat(field)] ? "border-red-500" : ""
38840
38943
  }), errors["cred_".concat(field)] && /*#__PURE__*/jsxRuntime.jsx("span", {
38841
38944
  className: "text-xs text-red-400",
38842
38945
  children: errors["cred_".concat(field)]
38843
38946
  })]
38844
38947
  }, field);
38845
38948
  })]
38949
+ }), wsTestResult && /*#__PURE__*/jsxRuntime.jsx("div", {
38950
+ className: "p-3 rounded-lg text-sm ".concat(wsTestResult.success ? "bg-green-900/30 border border-green-700 text-green-300" : "bg-red-900/30 border border-red-700 text-red-300"),
38951
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
38952
+ className: "flex items-center gap-2",
38953
+ children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.FontAwesomeIcon, {
38954
+ icon: wsTestResult.success ? "circle-check" : "circle-exclamation"
38955
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
38956
+ children: wsTestResult.message
38957
+ })]
38958
+ })
38846
38959
  })]
38847
38960
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
38848
38961
  className: "flex-shrink-0 flex flex-row justify-end gap-2 px-6 py-4 border-t border-white/10",
38849
- children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
38962
+ children: [(dashApi === null || dashApi === void 0 ? void 0 : dashApi.webSocket) && /*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
38963
+ title: isWsTesting ? "Testing..." : "Test Connection",
38964
+ onClick: handleTestConnection,
38965
+ size: "sm",
38966
+ disabled: !url.trim() || !isValidWsUrl(url)
38967
+ }), /*#__PURE__*/jsxRuntime.jsx(DashReact.Button, {
38850
38968
  title: "Cancel",
38851
38969
  onClick: onCancel,
38852
38970
  size: "sm"