@symply.io/basic-components 1.5.5-alpha.4 → 1.5.5-alpha.5

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.
@@ -40,8 +40,8 @@ function NumberInput(props) {
40
40
  decimals: decimals,
41
41
  integerOnly: integerOnly,
42
42
  onChange: onChange
43
- }), typing = _f.typing, exceedError = _f.exceedError, tooltipOpen = _f.tooltipOpen, roundedValue = _f.roundedValue, handleBlur = _f.handleBlur, handleFocus = _f.handleFocus, handleClick = _f.handleClick, handleChange = _f.handleChange, onOpenTooltip = _f.onOpenTooltip, onCloseTooltip = _f.onCloseTooltip, handleKeyboardEvent = _f.handleKeyboardEvent;
43
+ }), typing = _f.typing, exceedError = _f.exceedError, tooltipOpen = _f.tooltipOpen, roundedValue = _f.roundedValue, handleBlur = _f.handleBlur, handleFocus = _f.handleFocus, handleChange = _f.handleChange, onOpenTooltip = _f.onOpenTooltip, onCloseTooltip = _f.onCloseTooltip, handleKeyboardEvent = _f.handleKeyboardEvent;
44
44
  var valueDisplay = useMemo(function () { return (typing ? value : roundedValue); }, [typing, value, roundedValue]);
45
- return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tooltip, __assign({ arrow: true, placement: "top", title: tooltip !== null && tooltip !== void 0 ? tooltip : "", open: !!tooltip && tooltipOpen }, { children: _jsx(Field, __assign({ size: size, margin: "dense", type: "number", value: value === undefined || value === null ? "" : valueDisplay, onMouseEnter: onOpenTooltip, onMouseLeave: onCloseTooltip, onBlur: handleBlur, onFocus: handleFocus, onChange: handleChange, error: error || exceedError, helperText: helperText || (exceedError ? EXCEED_ERROR : ""), inputProps: { onKeyDown: handleKeyboardEvent, onClick: handleClick } }, rest)) })) })));
45
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tooltip, __assign({ arrow: true, placement: "top", title: tooltip !== null && tooltip !== void 0 ? tooltip : "", open: !!tooltip && tooltipOpen }, { children: _jsx(Field, __assign({ size: size, margin: "dense", type: "number", value: value === undefined || value === null ? "" : valueDisplay, onMouseEnter: onOpenTooltip, onMouseLeave: onCloseTooltip, onBlur: handleBlur, onFocus: handleFocus, onChange: handleChange, error: error || exceedError, helperText: helperText || (exceedError ? EXCEED_ERROR : ""), inputProps: { onKeyDown: handleKeyboardEvent } }, rest)) })) })));
46
46
  }
47
47
  export default NumberInput;
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ChangeEvent, MouseEventHandler, FocusEventHandler, KeyboardEventHandler } from "react";
1
+ import { CSSProperties, ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
2
2
  import { TextFieldProps } from "@mui/material/TextField";
3
3
  export interface InteractionStates {
4
4
  typing: boolean;
@@ -7,7 +7,6 @@ export interface InteractionStates {
7
7
  roundedValue: string;
8
8
  exceedError: boolean;
9
9
  handleKeyboardEvent: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
- handleClick: MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
11
10
  handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
12
11
  handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
13
12
  handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
@@ -1,16 +1,15 @@
1
- import { ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
1
+ /// <reference types="react" />
2
2
  import type { InteractionProps } from "./types";
3
3
  declare function useInteractions(props: InteractionProps): {
4
4
  typing: boolean;
5
5
  exceedError: boolean;
6
6
  tooltipOpen: boolean;
7
7
  roundedValue: string;
8
- handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
9
- handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
- handleClick: import("react").MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
11
- handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
8
+ handleBlur: import("react").FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
9
+ handleFocus: import("react").FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
+ handleChange: (event: import("react").ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
12
11
  onOpenTooltip: () => void;
13
12
  onCloseTooltip: () => void;
14
- handleKeyboardEvent: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
13
+ handleKeyboardEvent: import("react").KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
15
14
  };
16
15
  export default useInteractions;
@@ -26,7 +26,8 @@ function useInteractions(props) {
26
26
  }, [value, decimals]);
27
27
  var exceedError = useMemo(function () { return !!value && (Number(value) < minValue || Number(value) > maxValue); }, [value, minValue, maxValue]);
28
28
  var handleKeyboardEvent = useCallback(function (event) {
29
- var key = event.key, target = event.target;
29
+ var _a, _b;
30
+ var key = event.key;
30
31
  if (key === "e") {
31
32
  event.preventDefault();
32
33
  }
@@ -43,13 +44,14 @@ function useInteractions(props) {
43
44
  event.preventDefault();
44
45
  }
45
46
  else if (String(value).includes(".") && decimals > 0) {
47
+ var cursorPos = ((_b = (_a = document.getSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0)) === null || _b === void 0 ? void 0 : _b.startOffset) || 0;
46
48
  var decimalPointIndex = String(value).lastIndexOf(".");
47
49
  var decimalStrLen = String(value).split(".")[1].length;
48
50
  console.log({
49
51
  cursorIndex: cursorIndex,
50
52
  decimalPointIndex: decimalPointIndex,
51
53
  decimalStrLen: decimalStrLen,
52
- v: target.value
54
+ cursorPos: cursorPos
53
55
  });
54
56
  if (cursorIndex && decimalPointIndex <= cursorIndex) {
55
57
  if (![
@@ -79,13 +81,6 @@ function useInteractions(props) {
79
81
  return;
80
82
  onChange(val);
81
83
  }, [onChange, minValue, integerOnly]);
82
- var handleClick = useCallback(function (event) {
83
- console.log({
84
- cts: event.currentTarget.selectionStart,
85
- cte: event.currentTarget.selectionEnd
86
- });
87
- setCursorIndex(event.currentTarget.selectionStart || 0);
88
- }, []);
89
84
  var handleFocus = useCallback(function () {
90
85
  setTyping(true);
91
86
  }, []);
@@ -123,7 +118,6 @@ function useInteractions(props) {
123
118
  roundedValue: roundedValue,
124
119
  handleBlur: handleBlur,
125
120
  handleFocus: handleFocus,
126
- handleClick: handleClick,
127
121
  handleChange: handleChange,
128
122
  onOpenTooltip: onOpenTooltip,
129
123
  onCloseTooltip: onCloseTooltip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.5.5-alpha.4",
3
+ "version": "1.5.5-alpha.5",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",