@onehat/ui 0.3.359 → 0.3.361

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.359",
3
+ "version": "0.3.361",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@ import withValue from '../../Hoc/withValue.js';
9
9
  import _ from 'lodash';
10
10
 
11
11
  function InputElement(props) {
12
- let {
12
+ let { // so localValue can be changed, if needed
13
13
  value,
14
14
  setValue,
15
15
  autoSubmit = true, // automatically setValue after user stops typing for autoSubmitDelay
@@ -25,6 +25,28 @@ function InputElement(props) {
25
25
  styles = UiGlobals.styles,
26
26
  debouncedSetValueRef = useRef(),
27
27
  [localValue, setLocalValue] = useState(value),
28
+ isTypingRef = useRef(),
29
+ isTypingTimeoutRef = useRef(),
30
+ isTyping = () => {
31
+ return isTypingRef.current;
32
+ },
33
+ setIsTyping = (isTyping) => {
34
+ isTypingRef.current = isTyping;
35
+ if (isTyping) {
36
+ startIsTypingTimeout();
37
+ }
38
+ },
39
+ startIsTypingTimeout = () => {
40
+ clearIsTypingTimeout();
41
+ isTypingTimeoutRef.current = setTimeout(() => {
42
+ setIsTyping(false);
43
+ }, autoSubmitDelay + 1000);
44
+ },
45
+ clearIsTypingTimeout = () => {
46
+ if (isTypingTimeoutRef.current) {
47
+ clearTimeout(isTypingTimeoutRef.current);
48
+ }
49
+ },
28
50
  onKeyPressLocal = (e) => {
29
51
  if (e.key === 'Enter') {
30
52
  debouncedSetValueRef.current?.cancel();
@@ -35,6 +57,7 @@ function InputElement(props) {
35
57
  }
36
58
  },
37
59
  onChangeTextLocal = (value) => {
60
+ setIsTyping(true);
38
61
  if (value === '') {
39
62
  value = null; // empty string makes value null
40
63
  setLocalValue(value);
@@ -60,7 +83,7 @@ function InputElement(props) {
60
83
 
61
84
  useEffect(() => {
62
85
 
63
- if (value !== localValue) {
86
+ if (!isTyping() && value !== localValue) {
64
87
  // Make local value conform to externally changed value
65
88
  setLocalValue(value);
66
89
  }
@@ -20,7 +20,30 @@ const
20
20
  styles = UiGlobals.styles,
21
21
  debouncedSetValueRef = useRef(),
22
22
  [localValue, setLocalValue] = useState(value),
23
+ isTypingRef = useRef(),
24
+ isTypingTimeoutRef = useRef(),
25
+ isTyping = () => {
26
+ return isTypingRef.current;
27
+ },
28
+ setIsTyping = (isTyping) => {
29
+ isTypingRef.current = isTyping;
30
+ if (isTyping) {
31
+ startIsTypingTimeout();
32
+ }
33
+ },
34
+ startIsTypingTimeout = () => {
35
+ clearIsTypingTimeout();
36
+ isTypingTimeoutRef.current = setTimeout(() => {
37
+ setIsTyping(false);
38
+ }, autoSubmitDelay + 1000);
39
+ },
40
+ clearIsTypingTimeout = () => {
41
+ if (isTypingTimeoutRef.current) {
42
+ clearTimeout(isTypingTimeoutRef.current);
43
+ }
44
+ },
23
45
  onChangeTextLocal = (value) => {
46
+ setIsTyping(true);
24
47
  if (value === '') {
25
48
  value = null; // empty string makes value null
26
49
  }
@@ -42,8 +65,10 @@ const
42
65
 
43
66
  useEffect(() => {
44
67
 
45
- // Make local value conform to externally changed value
46
- setLocalValue(value);
68
+ if (!isTyping() && value !== localValue) {
69
+ // Make local value conform to externally changed value
70
+ setLocalValue(value);
71
+ }
47
72
 
48
73
  }, [value]);
49
74
 
@@ -26,7 +26,7 @@ export default function withInlineEditor(WrappedComponent, skipWrappers = false)
26
26
  const {
27
27
  isEditorShown = false,
28
28
  setIsEditorShown,
29
- editorProps = {},
29
+ _editor = {},
30
30
 
31
31
  // withComponent
32
32
  self,
@@ -48,7 +48,7 @@ export default function withInlineEditor(WrappedComponent, skipWrappers = false)
48
48
  isInlineEditorShown={isEditorShown}
49
49
  inlineEditor={<InlineEditor
50
50
  {...propsToPass}
51
- {...editorProps}
51
+ {..._editor}
52
52
  parent={self}
53
53
  reference="editor"
54
54
  columnsConfig={localColumnsConfig}
@@ -23,7 +23,7 @@ export default function withSideEditor(WrappedComponent, isTree = false) {
23
23
  const SideEditor = (props) => {
24
24
  const {
25
25
  Editor,
26
- editorProps = {},
26
+ _editor = {},
27
27
  sideFlex = 100,
28
28
  isResizable = false,
29
29
 
@@ -42,10 +42,10 @@ export default function withSideEditor(WrappedComponent, isTree = false) {
42
42
  }
43
43
 
44
44
  if (isResizable) {
45
- editorProps.w = 500;
46
- editorProps.isResizable = true;
45
+ _editor.w = 500;
46
+ _editor.isResizable = true;
47
47
  } else {
48
- editorProps.flex = sideFlex;
48
+ _editor.flex = sideFlex;
49
49
  }
50
50
 
51
51
  return <Container
@@ -61,7 +61,7 @@ export default function withSideEditor(WrappedComponent, isTree = false) {
61
61
  editorType={EDITOR_TYPE__SIDE}
62
62
  borderLeftWidth={1}
63
63
  borderLeftColor="#ccc"
64
- {...editorProps}
64
+ {..._editor}
65
65
  parent={self}
66
66
  reference="editor"
67
67
  />}
@@ -47,7 +47,7 @@ export default function withWindowedEditor(WrappedComponent, isTree = false) {
47
47
  isEditorShown = false,
48
48
  setIsEditorShown,
49
49
  Editor,
50
- editorProps = {},
50
+ _editor = {},
51
51
 
52
52
  // withComponent
53
53
  self,
@@ -75,7 +75,7 @@ export default function withWindowedEditor(WrappedComponent, isTree = false) {
75
75
  <Editor
76
76
  editorType={EDITOR_TYPE__WINDOWED}
77
77
  {...propsToPass}
78
- {...editorProps}
78
+ {..._editor}
79
79
  parent={self}
80
80
  reference="editor"
81
81
  />