@onehat/ui 0.3.23 → 0.3.24
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.
|
|
3
|
+
"version": "0.3.24",
|
|
4
4
|
"description": "Base UI for OneHat apps",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"license": "UNLICENSED",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@gluestack-style/react": "^0.2.38",
|
|
29
|
-
"@gluestack-ui/themed": "^0.1.
|
|
29
|
+
"@gluestack-ui/themed": "^0.1.53",
|
|
30
30
|
"@hookform/resolvers": "^3.3.1",
|
|
31
31
|
"@k-renwick/colour-mixer": "^1.2.1",
|
|
32
32
|
"@onehat/data": "^1.19.0",
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Box,
|
|
3
|
-
} from 'native-base';
|
|
4
1
|
import {
|
|
5
2
|
EDITOR_MODE__VIEW,
|
|
6
3
|
} from '../../Constants/Editor.js';
|
|
4
|
+
import Form from '../Form/Form.js';
|
|
5
|
+
import Viewer from '../Viewer/Viewer.js';
|
|
7
6
|
import _ from 'lodash';
|
|
8
7
|
|
|
9
|
-
|
|
10
8
|
export default function Editor(props) {
|
|
11
9
|
const {
|
|
12
|
-
Form,
|
|
13
|
-
Viewer,
|
|
14
10
|
isEditorViewOnly,
|
|
15
11
|
onEditorCancel: onCancel,
|
|
16
12
|
onEditorSave: onSave,
|
|
@@ -19,9 +15,6 @@ export default function Editor(props) {
|
|
|
19
15
|
editorMode,
|
|
20
16
|
onEditMode,
|
|
21
17
|
|
|
22
|
-
// withData
|
|
23
|
-
Repository,
|
|
24
|
-
|
|
25
18
|
// withSelection
|
|
26
19
|
selection,
|
|
27
20
|
|
|
@@ -46,9 +39,6 @@ export default function Editor(props) {
|
|
|
46
39
|
/>;
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
// NOTE: Ideally, this form should use multiple columns when screen is wide enough,
|
|
50
|
-
// and only show in one column when it's not.
|
|
51
|
-
|
|
52
42
|
return <Form
|
|
53
43
|
{...props}
|
|
54
44
|
record={selection}
|
|
@@ -96,7 +96,6 @@ function Form(props) {
|
|
|
96
96
|
|
|
97
97
|
// withAlert
|
|
98
98
|
alert,
|
|
99
|
-
confirm,
|
|
100
99
|
} = props,
|
|
101
100
|
styles = UiGlobals.styles,
|
|
102
101
|
record = props.record?.length === 1 ? props.record[0] : props.record,
|
|
@@ -269,14 +268,14 @@ function Form(props) {
|
|
|
269
268
|
onChange: onEditorChange,
|
|
270
269
|
useSelectorId = false,
|
|
271
270
|
...propsToPass
|
|
272
|
-
} = item
|
|
273
|
-
|
|
271
|
+
} = item,
|
|
272
|
+
editorTypeProps = {};
|
|
274
273
|
|
|
275
274
|
const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
|
|
276
275
|
if (propertyDef?.isEditingDisabled) {
|
|
277
276
|
isEditable = false;
|
|
278
277
|
}
|
|
279
|
-
if (!type
|
|
278
|
+
if (!type) {
|
|
280
279
|
if (isEditable) {
|
|
281
280
|
const
|
|
282
281
|
{
|
|
@@ -10,37 +10,105 @@ import {
|
|
|
10
10
|
EDITOR_TYPE__SIDE,
|
|
11
11
|
} from '../../Constants/Editor.js';
|
|
12
12
|
import UiGlobals from '../../UiGlobals.js';
|
|
13
|
+
import inArray from '../../Functions/inArray.js';
|
|
13
14
|
import getComponentFromType from '../../Functions/getComponentFromType.js';
|
|
14
15
|
import Label from '../Form/Label.js';
|
|
15
16
|
import Pencil from '../Icons/Pencil.js';
|
|
16
17
|
import Footer from '../Layout/Footer.js';
|
|
17
18
|
import _ from 'lodash';
|
|
18
19
|
|
|
19
|
-
// This is a wrapper for the Viewer subcomponent passed to props,
|
|
20
|
-
// that adds buttons and a footer
|
|
21
|
-
|
|
22
20
|
export default function Viewer(props) {
|
|
23
21
|
const {
|
|
24
|
-
additionalViewButtons = [],
|
|
25
|
-
ancillaryItems = [],
|
|
26
22
|
viewerCanDelete = false,
|
|
27
|
-
|
|
28
|
-
//
|
|
23
|
+
items = [], // Columns, FieldSets, Fields, etc to define the form
|
|
24
|
+
ancillaryItems = [], // additional items which are not controllable form elements, but should appear in the form
|
|
25
|
+
columnDefaults = {}, // defaults for each Column defined in items (above)
|
|
29
26
|
record,
|
|
27
|
+
additionalViewButtons = [],
|
|
30
28
|
|
|
31
|
-
//
|
|
32
|
-
|
|
29
|
+
// withData
|
|
30
|
+
Repository,
|
|
33
31
|
|
|
34
32
|
// withEditor
|
|
35
33
|
editorType,
|
|
36
34
|
onEditMode,
|
|
37
35
|
onClose,
|
|
38
36
|
onDelete,
|
|
37
|
+
|
|
38
|
+
// parent container
|
|
39
|
+
selectorId,
|
|
40
|
+
selectorSelected,
|
|
41
|
+
|
|
39
42
|
} = props,
|
|
40
43
|
isMultiple = _.isArray(record),
|
|
41
44
|
isSideEditor = editorType === EDITOR_TYPE__SIDE,
|
|
42
45
|
styles = UiGlobals.styles,
|
|
43
46
|
flex = props.flex || 1,
|
|
47
|
+
buildFromItems = () => {
|
|
48
|
+
return _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
|
|
49
|
+
},
|
|
50
|
+
buildNextLayer = (item, ix, defaults) => {
|
|
51
|
+
let {
|
|
52
|
+
type,
|
|
53
|
+
title,
|
|
54
|
+
name,
|
|
55
|
+
label,
|
|
56
|
+
items,
|
|
57
|
+
// onChange: onEditorChange,
|
|
58
|
+
useSelectorId = false,
|
|
59
|
+
...propsToPass
|
|
60
|
+
} = item,
|
|
61
|
+
editorTypeProps = {};
|
|
62
|
+
|
|
63
|
+
const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
|
|
64
|
+
if (!type) {
|
|
65
|
+
if (propertyDef.viewerType) {
|
|
66
|
+
const
|
|
67
|
+
{
|
|
68
|
+
type: t,
|
|
69
|
+
...p
|
|
70
|
+
} = propertyDef.viewerType;
|
|
71
|
+
type = t
|
|
72
|
+
} else {
|
|
73
|
+
type = 'Text';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (type?.match && type.match(/Combo$/) && Repository?.isRemote && !Repository?.isLoaded) {
|
|
77
|
+
editorTypeProps.autoLoad = true;
|
|
78
|
+
}
|
|
79
|
+
const Element = getComponentFromType(type);
|
|
80
|
+
let children;
|
|
81
|
+
|
|
82
|
+
if (inArray(type, ['Column', 'FieldSet'])) {
|
|
83
|
+
if (_.isEmpty(items)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const defaults = item.defaults;
|
|
87
|
+
children = _.map(items, (item, ix) => {
|
|
88
|
+
return buildNextLayer(item, ix, defaults);
|
|
89
|
+
});
|
|
90
|
+
return <Element key={ix} title={title} {...defaults} {...propsToPass} {...editorTypeProps}>{children}</Element>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!label && Repository && propertyDef.title) {
|
|
94
|
+
label = propertyDef.title;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const value = (record?.properties[name]?.displayValue) || null;
|
|
98
|
+
|
|
99
|
+
let element = <Element
|
|
100
|
+
value={value}
|
|
101
|
+
{...propsToPass}
|
|
102
|
+
/>;
|
|
103
|
+
if (label) {
|
|
104
|
+
const labelProps = {};
|
|
105
|
+
if (defaults?.labelWidth) {
|
|
106
|
+
labelProps.w = defaults.labelWidth;
|
|
107
|
+
}
|
|
108
|
+
element = <><Label {...labelProps}>{label}</Label>{element}</>;
|
|
109
|
+
}
|
|
110
|
+
return <Row key={ix} px={2} pb={1}>{element}</Row>;
|
|
111
|
+
},
|
|
44
112
|
buildAncillary = () => {
|
|
45
113
|
const components = [];
|
|
46
114
|
if (ancillaryItems.length) {
|
|
@@ -101,7 +169,7 @@ export default function Viewer(props) {
|
|
|
101
169
|
{additionalViewButtons}
|
|
102
170
|
</Row>}
|
|
103
171
|
|
|
104
|
-
{
|
|
172
|
+
{buildFromItems()}
|
|
105
173
|
|
|
106
174
|
{buildAncillary()}
|
|
107
175
|
|