@onehat/ui 0.2.43 → 0.2.45
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 +1 -1
- package/src/Components/Editor/Editor.js +58 -0
- package/src/Components/Form/Field/Input.js +1 -1
- package/src/Components/Grid/Grid.js +4 -3
- package/src/Components/Grid/GridRow.js +1 -1
- package/src/Components/Hoc/withDraggable.js +1 -1
- package/src/Components/Hoc/withEditor.js +1 -1
- package/src/Components/Hoc/withPresetButtons.js +33 -0
- package/src/Components/Screens/DataMgt.js +1 -1
- package/src/Hooks/useAdjustedWindowSize.js +18 -0
- package/src/Hooks/useWindowSize.js +25 -0
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDITOR_MODE__VIEW,
|
|
3
|
+
EDITOR_MODE__ADD,
|
|
4
|
+
EDITOR_MODE__EDIT,
|
|
5
|
+
} from '../../Constants/Editor.js';
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default function Editor(props) {
|
|
10
|
+
const {
|
|
11
|
+
Form,
|
|
12
|
+
Viewer,
|
|
13
|
+
isEditorViewOnly: isViewOnly,
|
|
14
|
+
onEditorCancel: onCancel,
|
|
15
|
+
onEditorSave: onSave,
|
|
16
|
+
onEditorClose: onClose,
|
|
17
|
+
editorMode,
|
|
18
|
+
setEditorMode,
|
|
19
|
+
|
|
20
|
+
// withData
|
|
21
|
+
Repository,
|
|
22
|
+
|
|
23
|
+
// withSelection
|
|
24
|
+
selection,
|
|
25
|
+
|
|
26
|
+
} = props,
|
|
27
|
+
onEditMode = () => {
|
|
28
|
+
setEditorMode(EDITOR_MODE__EDIT);
|
|
29
|
+
},
|
|
30
|
+
onBack = () => {
|
|
31
|
+
setEditorMode(EDITOR_MODE__VIEW);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (_.isEmpty(selection)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Repository.isRemotePhantomMode && selection.length === 1 && editorMode === EDITOR_MODE__VIEW) {
|
|
39
|
+
return <Viewer
|
|
40
|
+
record={selection[0]}
|
|
41
|
+
Repository={Repository}
|
|
42
|
+
onEditMode={isViewOnly ? null : onEditMode}
|
|
43
|
+
{...props}
|
|
44
|
+
/>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// NOTE: Ideally, this form should use multiple columns when screen is wide enough,
|
|
48
|
+
// and only show in one column when it's not.
|
|
49
|
+
|
|
50
|
+
return <Form
|
|
51
|
+
record={selection}
|
|
52
|
+
onBack={onBack}
|
|
53
|
+
onCancel={onCancel}
|
|
54
|
+
onSave={onSave}
|
|
55
|
+
onClose={onClose}
|
|
56
|
+
{...props}
|
|
57
|
+
/>;
|
|
58
|
+
}
|
|
@@ -14,7 +14,7 @@ function InputElement(props) {
|
|
|
14
14
|
let {
|
|
15
15
|
value,
|
|
16
16
|
setValue,
|
|
17
|
-
autoSubmit =
|
|
17
|
+
autoSubmit = true, // automatically setValue after user stops typing for autoSubmitDelay
|
|
18
18
|
autoSubmitDelay = AUTO_SUBMIT_DELAY,
|
|
19
19
|
maxLength,
|
|
20
20
|
onKeyPress,
|
|
@@ -751,11 +751,11 @@ export function Grid(props) {
|
|
|
751
751
|
return () => {};
|
|
752
752
|
}
|
|
753
753
|
if (!disableSelectorSelected) {
|
|
754
|
-
let
|
|
754
|
+
let id = selectorSelected?.id;
|
|
755
755
|
if (_.isEmpty(selectorSelected)) {
|
|
756
|
-
|
|
756
|
+
id = noSelectorMeansNoResults ? 'NO_MATCHES' : null;
|
|
757
757
|
}
|
|
758
|
-
Repository.filter(selectorId,
|
|
758
|
+
Repository.filter(selectorId, id, false); // so it doesn't clear existing filters
|
|
759
759
|
}
|
|
760
760
|
|
|
761
761
|
}, [selectorId, selectorSelected]);
|
|
@@ -808,6 +808,7 @@ export function Grid(props) {
|
|
|
808
808
|
borderWidth: isReorderMode ? 4 : 0,
|
|
809
809
|
borderColor: isReorderMode ? '#23d9ea' : null,
|
|
810
810
|
borderStyle: 'dashed',
|
|
811
|
+
flex: 1,
|
|
811
812
|
}}
|
|
812
813
|
refreshing={isLoading}
|
|
813
814
|
onRefresh={pullToRefresh ? onRefresh : null}
|
|
@@ -227,7 +227,7 @@ export default function withDraggable(WrappedComponent) {
|
|
|
227
227
|
position={{ x: 0, y: 0, /* reset to dropped position */ }}
|
|
228
228
|
// bounds={bounds}
|
|
229
229
|
>
|
|
230
|
-
<div className="nsResize"
|
|
230
|
+
<div className="nsResize">
|
|
231
231
|
<WrappedComponent {...propsToPass} />
|
|
232
232
|
</div>
|
|
233
233
|
</Draggable>;
|
|
@@ -162,7 +162,7 @@ export default function withEditor(WrappedComponent) {
|
|
|
162
162
|
// For multiple entities selected, change it to edit multiple mode
|
|
163
163
|
mode = EDITOR_MODE__EDIT;
|
|
164
164
|
}
|
|
165
|
-
} else if (selection.length === 1 && selection.isPhantom) {
|
|
165
|
+
} else if (selection.length === 1 && selection[0].isPhantom) {
|
|
166
166
|
if (!disableAdd) {
|
|
167
167
|
// When a phantom entity is selected, change it to add mode.
|
|
168
168
|
mode = EDITOR_MODE__ADD;
|
|
@@ -121,34 +121,67 @@ export default function withPresetButtons(WrappedComponent) {
|
|
|
121
121
|
text = 'Add';
|
|
122
122
|
handler = onAdd;
|
|
123
123
|
icon = <Plus />;
|
|
124
|
+
if (selectorId && !selectorSelected) {
|
|
125
|
+
isDisabled = true;
|
|
126
|
+
}
|
|
124
127
|
break;
|
|
125
128
|
case 'edit':
|
|
126
129
|
text = 'Edit';
|
|
127
130
|
handler = onEdit;
|
|
128
131
|
icon = <Edit />;
|
|
132
|
+
if (selectorId && !selectorSelected) {
|
|
133
|
+
isDisabled = true;
|
|
134
|
+
}
|
|
135
|
+
if (_.isEmpty(selection)) {
|
|
136
|
+
isDisabled = true;
|
|
137
|
+
}
|
|
129
138
|
break;
|
|
130
139
|
case 'delete':
|
|
131
140
|
text = 'Delete';
|
|
132
141
|
handler = onDelete;
|
|
133
142
|
icon = <Trash />;
|
|
143
|
+
if (selectorId && !selectorSelected) {
|
|
144
|
+
isDisabled = true;
|
|
145
|
+
}
|
|
146
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
147
|
+
isDisabled = true;
|
|
148
|
+
}
|
|
134
149
|
break;
|
|
135
150
|
case 'view':
|
|
136
151
|
text = 'View';
|
|
137
152
|
handler = onView;
|
|
138
153
|
icon = <Eye />;
|
|
139
154
|
isDisabled = !selection.length || selection.length !== 1;
|
|
155
|
+
if (selectorId && !selectorSelected) {
|
|
156
|
+
isDisabled = true;
|
|
157
|
+
}
|
|
158
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
159
|
+
isDisabled = true;
|
|
160
|
+
}
|
|
140
161
|
break;
|
|
141
162
|
case 'copy':
|
|
142
163
|
text = 'Copy to Clipboard';
|
|
143
164
|
handler = onCopyToClipboard;
|
|
144
165
|
icon = <Clipboard />;
|
|
145
166
|
isDisabled = !selection.length;
|
|
167
|
+
if (selectorId && !selectorSelected) {
|
|
168
|
+
isDisabled = true;
|
|
169
|
+
}
|
|
170
|
+
if (_.isEmpty(selection)) {
|
|
171
|
+
isDisabled = true;
|
|
172
|
+
}
|
|
146
173
|
break;
|
|
147
174
|
case 'duplicate':
|
|
148
175
|
text = 'Duplicate';
|
|
149
176
|
handler = onDuplicate;
|
|
150
177
|
icon = <Duplicate />;
|
|
151
178
|
isDisabled = !selection.length || selection.length !== 1;
|
|
179
|
+
if (selectorId && !selectorSelected) {
|
|
180
|
+
isDisabled = true;
|
|
181
|
+
}
|
|
182
|
+
if (_.isEmpty(selection) || selection.length > 1) {
|
|
183
|
+
isDisabled = true;
|
|
184
|
+
}
|
|
152
185
|
break;
|
|
153
186
|
// case 'print':
|
|
154
187
|
// text = 'Print';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import useWindowSize from './useWindowSize.js';
|
|
2
|
+
|
|
3
|
+
// This hook takes the submitted window size and adjusts it
|
|
4
|
+
// to fit the actual screen size
|
|
5
|
+
|
|
6
|
+
export default function(width, height, percentage = 0.9) {
|
|
7
|
+
|
|
8
|
+
const windowSize = useWindowSize();
|
|
9
|
+
|
|
10
|
+
if (width > windowSize.width) {
|
|
11
|
+
width = windowSize.width * percentage;
|
|
12
|
+
}
|
|
13
|
+
if (height > windowSize.height) {
|
|
14
|
+
height = windowSize.height * percentage;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return [ width, height, ];
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// from https://designcode.io/react-hooks-usewindowsize-hook
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
// For web only!
|
|
6
|
+
export default function useWindowSize() {
|
|
7
|
+
const [windowSize, setWindowSize] = useState({ width: 0, height: 0 });
|
|
8
|
+
|
|
9
|
+
const handleSize = () => {
|
|
10
|
+
setWindowSize({
|
|
11
|
+
width: window.innerWidth,
|
|
12
|
+
height: window.innerHeight
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
handleSize();
|
|
18
|
+
|
|
19
|
+
window.addEventListener('resize', handleSize);
|
|
20
|
+
|
|
21
|
+
return () => window.removeEventListener('resize', handleSize);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return windowSize;
|
|
25
|
+
};
|