@trops/dash-core 0.1.181 → 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
@@ -38612,6 +38612,16 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38612
38612
  _useState10 = _slicedToArray(_useState1, 2),
38613
38613
  errors = _useState10[0],
38614
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;
38615
38625
  var nextRowIdRef = React.useRef(0);
38616
38626
  var nextRowId = function nextRowId() {
38617
38627
  return "ws_hdr_".concat(++nextRowIdRef.current);
@@ -38701,6 +38711,92 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38701
38711
  });
38702
38712
  });
38703
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
+ }
38704
38800
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
38705
38801
  className: "flex flex-col flex-1 min-h-0",
38706
38802
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
@@ -38719,7 +38815,7 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38719
38815
  return setName(value);
38720
38816
  },
38721
38817
  placeholder: "e.g., crypto-ws, stock-feed",
38722
- error: !!errors.name
38818
+ inputClassName: errors.name ? "border-red-500" : ""
38723
38819
  }), errors.name && /*#__PURE__*/jsxRuntime.jsx("span", {
38724
38820
  className: "text-xs text-red-400",
38725
38821
  children: errors.name
@@ -38735,7 +38831,7 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38735
38831
  return setUrl(value);
38736
38832
  },
38737
38833
  placeholder: "wss://api.example.com/ws or ws://localhost:8080",
38738
- error: !!errors.url
38834
+ inputClassName: errors.url ? "border-red-500" : ""
38739
38835
  }), errors.url && /*#__PURE__*/jsxRuntime.jsx("span", {
38740
38836
  className: "text-xs text-red-400",
38741
38837
  children: errors.url
@@ -38843,17 +38939,32 @@ var WebSocketProviderForm = function WebSocketProviderForm(_ref) {
38843
38939
  });
38844
38940
  },
38845
38941
  placeholder: "Enter ".concat(field),
38846
- error: !!errors["cred_".concat(field)]
38942
+ inputClassName: errors["cred_".concat(field)] ? "border-red-500" : ""
38847
38943
  }), errors["cred_".concat(field)] && /*#__PURE__*/jsxRuntime.jsx("span", {
38848
38944
  className: "text-xs text-red-400",
38849
38945
  children: errors["cred_".concat(field)]
38850
38946
  })]
38851
38947
  }, field);
38852
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
+ })
38853
38959
  })]
38854
38960
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
38855
38961
  className: "flex-shrink-0 flex flex-row justify-end gap-2 px-6 py-4 border-t border-white/10",
38856
- 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, {
38857
38968
  title: "Cancel",
38858
38969
  onClick: onCancel,
38859
38970
  size: "sm"