@dreamtree-org/twreact-ui 1.1.3 → 1.1.4

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
@@ -15913,6 +15913,176 @@ function LocationPicker(_ref) {
15913
15913
  }, iconButton)));
15914
15914
  }
15915
15915
 
15916
+ var SpeechToText = /*#__PURE__*/forwardRef(function (_ref, ref) {
15917
+ var _ref$lang = _ref.lang,
15918
+ lang = _ref$lang === void 0 ? "en-US" : _ref$lang,
15919
+ _ref$continuous = _ref.continuous,
15920
+ continuous = _ref$continuous === void 0 ? true : _ref$continuous,
15921
+ _ref$interimResults = _ref.interimResults,
15922
+ interimResults = _ref$interimResults === void 0 ? true : _ref$interimResults,
15923
+ _ref$onSpeechComplete = _ref.onSpeechComplete,
15924
+ onSpeechComplete = _ref$onSpeechComplete === void 0 ? function () {} : _ref$onSpeechComplete,
15925
+ _ref$onSpeaking = _ref.onSpeaking,
15926
+ onSpeaking = _ref$onSpeaking === void 0 ? function () {} : _ref$onSpeaking,
15927
+ _ref$onError = _ref.onError,
15928
+ onError = _ref$onError === void 0 ? function () {} : _ref$onError,
15929
+ _ref$onStart = _ref.onStart,
15930
+ onStart = _ref$onStart === void 0 ? function () {} : _ref$onStart,
15931
+ _ref$onStop = _ref.onStop,
15932
+ onStop = _ref$onStop === void 0 ? function () {} : _ref$onStop,
15933
+ _ref$renderButton = _ref.renderButton,
15934
+ renderButton = _ref$renderButton === void 0 ? null : _ref$renderButton,
15935
+ _ref$autoStart = _ref.autoStart,
15936
+ autoStart = _ref$autoStart === void 0 ? false : _ref$autoStart,
15937
+ _ref$disabled = _ref.disabled,
15938
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
15939
+ var recognitionRef = useRef(null);
15940
+ var finalTranscriptRef = useRef("");
15941
+ var _useState = useState(false),
15942
+ _useState2 = _slicedToArray(_useState, 2),
15943
+ _isListening = _useState2[0],
15944
+ setIsListening = _useState2[1];
15945
+ var _useState3 = useState(true),
15946
+ _useState4 = _slicedToArray(_useState3, 2),
15947
+ _isSupported = _useState4[0],
15948
+ setIsSupported = _useState4[1];
15949
+ useEffect(function () {
15950
+ if (!("webkitSpeechRecognition" in window) && !("SpeechRecognition" in window)) {
15951
+ setIsSupported(false);
15952
+ } else {
15953
+ setIsSupported(true);
15954
+ }
15955
+ }, []);
15956
+ useEffect(function () {
15957
+ if (autoStart && _isSupported) {
15958
+ startListening();
15959
+ }
15960
+ return function () {
15961
+ if (recognitionRef.current) {
15962
+ try {
15963
+ recognitionRef.current.onresult = null;
15964
+ recognitionRef.current.onerror = null;
15965
+ recognitionRef.current.onend = null;
15966
+ recognitionRef.current.onstart = null;
15967
+ recognitionRef.current.stop();
15968
+ } catch (e) {}
15969
+ }
15970
+ };
15971
+ }, [autoStart, _isSupported]);
15972
+ function initializeRecognition() {
15973
+ if (recognitionRef.current) return recognitionRef.current;
15974
+ var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
15975
+ if (!SpeechRecognition) {
15976
+ var err = new Error("SpeechRecognition API not available");
15977
+ onError(err);
15978
+ return null;
15979
+ }
15980
+ var recognition = new SpeechRecognition();
15981
+ recognition.continuous = !!continuous;
15982
+ recognition.interimResults = !!interimResults;
15983
+ recognition.lang = lang;
15984
+ recognition.onstart = function () {
15985
+ finalTranscriptRef.current = finalTranscriptRef.current || "";
15986
+ setIsListening(true);
15987
+ onStart();
15988
+ };
15989
+ recognition.onresult = function (event) {
15990
+ var interim = "";
15991
+ var finalPart = "";
15992
+ for (var i = event.resultIndex; i < event.results.length; i++) {
15993
+ var piece = event.results[i][0].transcript;
15994
+ if (event.results[i].isFinal) {
15995
+ finalPart += piece + " ";
15996
+ } else {
15997
+ interim += piece;
15998
+ }
15999
+ }
16000
+ if (interim) {
16001
+ onSpeaking(interim);
16002
+ }
16003
+ if (finalPart) {
16004
+ finalTranscriptRef.current = (finalTranscriptRef.current || "") + finalPart;
16005
+ onSpeechComplete(finalTranscriptRef.current.trim());
16006
+ }
16007
+ };
16008
+ recognition.onerror = function (event) {
16009
+ var err = event && event.error ? new Error(event.error) : new Error("Speech recognition error");
16010
+ onError(err);
16011
+ setIsListening(false);
16012
+ };
16013
+ recognition.onend = function () {
16014
+ setIsListening(false);
16015
+ onStop();
16016
+ onSpeechComplete((finalTranscriptRef.current || "").trim());
16017
+ };
16018
+ recognitionRef.current = recognition;
16019
+ return recognition;
16020
+ }
16021
+ function startListening() {
16022
+ if (!_isSupported) {
16023
+ onError(new Error("Speech recognition not supported in this browser"));
16024
+ return;
16025
+ }
16026
+ try {
16027
+ var rec = initializeRecognition();
16028
+ if (!rec) return;
16029
+ rec.start();
16030
+ } catch (err) {
16031
+ onError(err);
16032
+ }
16033
+ }
16034
+ function stopListening() {
16035
+ if (recognitionRef.current) {
16036
+ try {
16037
+ recognitionRef.current.stop();
16038
+ } catch (e) {}
16039
+ }
16040
+ }
16041
+ function toggleListening() {
16042
+ if (disabled) return;
16043
+ if (_isListening) {
16044
+ stopListening();
16045
+ } else {
16046
+ startListening();
16047
+ }
16048
+ }
16049
+ useImperativeHandle(ref, function () {
16050
+ return {
16051
+ start: startListening,
16052
+ stop: stopListening,
16053
+ toggle: toggleListening,
16054
+ isListening: function isListening() {
16055
+ return _isListening;
16056
+ },
16057
+ isSupported: function isSupported() {
16058
+ return _isSupported;
16059
+ },
16060
+ getTranscript: function getTranscript() {
16061
+ return (finalTranscriptRef.current || "").trim();
16062
+ },
16063
+ clearTranscript: function clearTranscript() {
16064
+ finalTranscriptRef.current = "";
16065
+ }
16066
+ };
16067
+ }, [_isListening, _isSupported]);
16068
+ if (renderButton && typeof renderButton === "function") {
16069
+ return renderButton({
16070
+ isListening: _isListening,
16071
+ isSupported: _isSupported,
16072
+ start: startListening,
16073
+ stop: stopListening,
16074
+ toggle: toggleListening,
16075
+ disabled: disabled
16076
+ });
16077
+ }
16078
+ return /*#__PURE__*/React__default.createElement("button", {
16079
+ type: "button",
16080
+ "aria-pressed": _isListening,
16081
+ onClick: toggleListening,
16082
+ disabled: disabled || !_isSupported
16083
+ }, _isListening ? "Stop" : "Start");
16084
+ });
16085
+
15916
16086
  var _excluded$d = ["items", "collapsed", "onToggle", "className", "logo", "user", "onUserClick", "drawerPosition", "isMobileOpen", "setIsMobileOpen", "showCollapsedTooltips", "tooltipOptions"];
15917
16087
 
15918
16088
  /**
@@ -16545,7 +16715,7 @@ var Navbar = function Navbar(_ref3) {
16545
16715
  "text-gray-700 hover:bg-gray-50": !item.active
16546
16716
  })
16547
16717
  }, item.label);
16548
- }))));
16718
+ }))), /*#__PURE__*/React__default.createElement("h1", null, "asddddddddddddd"));
16549
16719
  };
16550
16720
  Navbar.displayName = "Navbar";
16551
16721
  Navbar.propTypes = {
@@ -26585,4 +26755,4 @@ var StoreProvider = function StoreProvider(_ref) {
26585
26755
  }, children));
26586
26756
  };
26587
26757
 
26588
- export { Accordion, Alert, Avatar, Badge, Breadcrumbs, Button, Card, Carousel, Checkbox, ColorPicker, Condition, DatePicker, DateRangePicker, Dialog, EmitterClass as Emitter, FileUpload, FootNav, Form, Helpers, Input, Loader, LocationPicker, Navbar, Pagination, PriceRangePicker, ProgressBar, Radio, Rate, RoundedTag, Select, Sidebar, Skeleton, Stepper, StoreProvider, Switch, Table, Tabs, ThemeProvider, ThreeDotPopoverSimple as ThreeDotPopover, Toast, ToastContainer, Tooltip, cn$1 as cn, useApi, useMixins, useTheme, useToast };
26758
+ export { Accordion, Alert, Avatar, Badge, Breadcrumbs, Button, Card, Carousel, Checkbox, ColorPicker, Condition, DatePicker, DateRangePicker, Dialog, EmitterClass as Emitter, FileUpload, FootNav, Form, Helpers, Input, Loader, LocationPicker, Navbar, Pagination, PriceRangePicker, ProgressBar, Radio, Rate, RoundedTag, Select, Sidebar, Skeleton, SpeechToText, Stepper, StoreProvider, Switch, Table, Tabs, ThemeProvider, ThreeDotPopoverSimple as ThreeDotPopover, Toast, ToastContainer, Tooltip, cn$1 as cn, useApi, useMixins, useTheme, useToast };
package/dist/index.js CHANGED
@@ -15933,6 +15933,176 @@ function LocationPicker(_ref) {
15933
15933
  }, iconButton)));
15934
15934
  }
15935
15935
 
15936
+ var SpeechToText = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
15937
+ var _ref$lang = _ref.lang,
15938
+ lang = _ref$lang === void 0 ? "en-US" : _ref$lang,
15939
+ _ref$continuous = _ref.continuous,
15940
+ continuous = _ref$continuous === void 0 ? true : _ref$continuous,
15941
+ _ref$interimResults = _ref.interimResults,
15942
+ interimResults = _ref$interimResults === void 0 ? true : _ref$interimResults,
15943
+ _ref$onSpeechComplete = _ref.onSpeechComplete,
15944
+ onSpeechComplete = _ref$onSpeechComplete === void 0 ? function () {} : _ref$onSpeechComplete,
15945
+ _ref$onSpeaking = _ref.onSpeaking,
15946
+ onSpeaking = _ref$onSpeaking === void 0 ? function () {} : _ref$onSpeaking,
15947
+ _ref$onError = _ref.onError,
15948
+ onError = _ref$onError === void 0 ? function () {} : _ref$onError,
15949
+ _ref$onStart = _ref.onStart,
15950
+ onStart = _ref$onStart === void 0 ? function () {} : _ref$onStart,
15951
+ _ref$onStop = _ref.onStop,
15952
+ onStop = _ref$onStop === void 0 ? function () {} : _ref$onStop,
15953
+ _ref$renderButton = _ref.renderButton,
15954
+ renderButton = _ref$renderButton === void 0 ? null : _ref$renderButton,
15955
+ _ref$autoStart = _ref.autoStart,
15956
+ autoStart = _ref$autoStart === void 0 ? false : _ref$autoStart,
15957
+ _ref$disabled = _ref.disabled,
15958
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
15959
+ var recognitionRef = React.useRef(null);
15960
+ var finalTranscriptRef = React.useRef("");
15961
+ var _useState = React.useState(false),
15962
+ _useState2 = _slicedToArray(_useState, 2),
15963
+ _isListening = _useState2[0],
15964
+ setIsListening = _useState2[1];
15965
+ var _useState3 = React.useState(true),
15966
+ _useState4 = _slicedToArray(_useState3, 2),
15967
+ _isSupported = _useState4[0],
15968
+ setIsSupported = _useState4[1];
15969
+ React.useEffect(function () {
15970
+ if (!("webkitSpeechRecognition" in window) && !("SpeechRecognition" in window)) {
15971
+ setIsSupported(false);
15972
+ } else {
15973
+ setIsSupported(true);
15974
+ }
15975
+ }, []);
15976
+ React.useEffect(function () {
15977
+ if (autoStart && _isSupported) {
15978
+ startListening();
15979
+ }
15980
+ return function () {
15981
+ if (recognitionRef.current) {
15982
+ try {
15983
+ recognitionRef.current.onresult = null;
15984
+ recognitionRef.current.onerror = null;
15985
+ recognitionRef.current.onend = null;
15986
+ recognitionRef.current.onstart = null;
15987
+ recognitionRef.current.stop();
15988
+ } catch (e) {}
15989
+ }
15990
+ };
15991
+ }, [autoStart, _isSupported]);
15992
+ function initializeRecognition() {
15993
+ if (recognitionRef.current) return recognitionRef.current;
15994
+ var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
15995
+ if (!SpeechRecognition) {
15996
+ var err = new Error("SpeechRecognition API not available");
15997
+ onError(err);
15998
+ return null;
15999
+ }
16000
+ var recognition = new SpeechRecognition();
16001
+ recognition.continuous = !!continuous;
16002
+ recognition.interimResults = !!interimResults;
16003
+ recognition.lang = lang;
16004
+ recognition.onstart = function () {
16005
+ finalTranscriptRef.current = finalTranscriptRef.current || "";
16006
+ setIsListening(true);
16007
+ onStart();
16008
+ };
16009
+ recognition.onresult = function (event) {
16010
+ var interim = "";
16011
+ var finalPart = "";
16012
+ for (var i = event.resultIndex; i < event.results.length; i++) {
16013
+ var piece = event.results[i][0].transcript;
16014
+ if (event.results[i].isFinal) {
16015
+ finalPart += piece + " ";
16016
+ } else {
16017
+ interim += piece;
16018
+ }
16019
+ }
16020
+ if (interim) {
16021
+ onSpeaking(interim);
16022
+ }
16023
+ if (finalPart) {
16024
+ finalTranscriptRef.current = (finalTranscriptRef.current || "") + finalPart;
16025
+ onSpeechComplete(finalTranscriptRef.current.trim());
16026
+ }
16027
+ };
16028
+ recognition.onerror = function (event) {
16029
+ var err = event && event.error ? new Error(event.error) : new Error("Speech recognition error");
16030
+ onError(err);
16031
+ setIsListening(false);
16032
+ };
16033
+ recognition.onend = function () {
16034
+ setIsListening(false);
16035
+ onStop();
16036
+ onSpeechComplete((finalTranscriptRef.current || "").trim());
16037
+ };
16038
+ recognitionRef.current = recognition;
16039
+ return recognition;
16040
+ }
16041
+ function startListening() {
16042
+ if (!_isSupported) {
16043
+ onError(new Error("Speech recognition not supported in this browser"));
16044
+ return;
16045
+ }
16046
+ try {
16047
+ var rec = initializeRecognition();
16048
+ if (!rec) return;
16049
+ rec.start();
16050
+ } catch (err) {
16051
+ onError(err);
16052
+ }
16053
+ }
16054
+ function stopListening() {
16055
+ if (recognitionRef.current) {
16056
+ try {
16057
+ recognitionRef.current.stop();
16058
+ } catch (e) {}
16059
+ }
16060
+ }
16061
+ function toggleListening() {
16062
+ if (disabled) return;
16063
+ if (_isListening) {
16064
+ stopListening();
16065
+ } else {
16066
+ startListening();
16067
+ }
16068
+ }
16069
+ React.useImperativeHandle(ref, function () {
16070
+ return {
16071
+ start: startListening,
16072
+ stop: stopListening,
16073
+ toggle: toggleListening,
16074
+ isListening: function isListening() {
16075
+ return _isListening;
16076
+ },
16077
+ isSupported: function isSupported() {
16078
+ return _isSupported;
16079
+ },
16080
+ getTranscript: function getTranscript() {
16081
+ return (finalTranscriptRef.current || "").trim();
16082
+ },
16083
+ clearTranscript: function clearTranscript() {
16084
+ finalTranscriptRef.current = "";
16085
+ }
16086
+ };
16087
+ }, [_isListening, _isSupported]);
16088
+ if (renderButton && typeof renderButton === "function") {
16089
+ return renderButton({
16090
+ isListening: _isListening,
16091
+ isSupported: _isSupported,
16092
+ start: startListening,
16093
+ stop: stopListening,
16094
+ toggle: toggleListening,
16095
+ disabled: disabled
16096
+ });
16097
+ }
16098
+ return /*#__PURE__*/React.createElement("button", {
16099
+ type: "button",
16100
+ "aria-pressed": _isListening,
16101
+ onClick: toggleListening,
16102
+ disabled: disabled || !_isSupported
16103
+ }, _isListening ? "Stop" : "Start");
16104
+ });
16105
+
15936
16106
  var _excluded$d = ["items", "collapsed", "onToggle", "className", "logo", "user", "onUserClick", "drawerPosition", "isMobileOpen", "setIsMobileOpen", "showCollapsedTooltips", "tooltipOptions"];
15937
16107
 
15938
16108
  /**
@@ -16565,7 +16735,7 @@ var Navbar = function Navbar(_ref3) {
16565
16735
  "text-gray-700 hover:bg-gray-50": !item.active
16566
16736
  })
16567
16737
  }, item.label);
16568
- }))));
16738
+ }))), /*#__PURE__*/React.createElement("h1", null, "asddddddddddddd"));
16569
16739
  };
16570
16740
  Navbar.displayName = "Navbar";
16571
16741
  Navbar.propTypes = {
@@ -26637,6 +26807,7 @@ exports.RoundedTag = RoundedTag;
26637
26807
  exports.Select = Select;
26638
26808
  exports.Sidebar = Sidebar;
26639
26809
  exports.Skeleton = Skeleton;
26810
+ exports.SpeechToText = SpeechToText;
26640
26811
  exports.Stepper = Stepper;
26641
26812
  exports.StoreProvider = StoreProvider;
26642
26813
  exports.Switch = Switch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamtree-org/twreact-ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "A comprehensive React + Tailwind components library for building modern web apps",
5
5
  "author": {
6
6
  "name": "Partha Preetham Krishna",