@onehat/ui 0.3.315 → 0.3.317
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 +3 -1
- package/src/Components/Form/Field/Json.js +79 -0
- package/src/Components/Grid/Grid.js +1 -1
- package/src/Components/index.js +2 -0
- package/src/Functions/jsonValidator.js +16 -0
- package/src/Functions/registerReactNativeComponents.js +2 -0
- package/src/Functions/registerWebComponents.js +4 -0
- package/src/PlatformImports/ReactNative/JsonEditor.js +3 -0
- package/src/PlatformImports/Web/JsonEditor.js +3 -0
- package/src/PlatformImports/Web/JsonViewer.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onehat/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.317",
|
|
4
4
|
"description": "Base UI for OneHat apps",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,6 +52,8 @@
|
|
|
52
52
|
"react-dnd-html5-backend": "^16.0.1",
|
|
53
53
|
"react-dnd-touch-backend":"16.0.1",
|
|
54
54
|
"react-draggable": "^4.4.5",
|
|
55
|
+
"react-json-view": "^1.21.3",
|
|
56
|
+
"react-json-view-lite": "^1.4.0",
|
|
55
57
|
"react-native": "*",
|
|
56
58
|
"react-native-draggable": "^3.3.0",
|
|
57
59
|
"react-native-svg": "*",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef, } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Row,
|
|
4
|
+
Text,
|
|
5
|
+
Tooltip,
|
|
6
|
+
} from 'native-base';
|
|
7
|
+
import {
|
|
8
|
+
UI_MODE_REACT_NATIVE,
|
|
9
|
+
UI_MODE_WEB,
|
|
10
|
+
} from '../../../constants/UiModes.js';
|
|
11
|
+
import UiGlobals from '../../../UiGlobals.js';
|
|
12
|
+
import withComponent from '../../Hoc/withComponent.js';
|
|
13
|
+
import withValue from '../../Hoc/withValue.js';
|
|
14
|
+
import testProps from '../../../functions/testProps.js';
|
|
15
|
+
import getComponentFromType from '../../../functions/getComponentFromType.js';
|
|
16
|
+
import _ from 'lodash';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function JsonElement(props) {
|
|
20
|
+
const {
|
|
21
|
+
tooltipRef = null,
|
|
22
|
+
tooltip = null,
|
|
23
|
+
isDisabled = false,
|
|
24
|
+
isEditable = true,
|
|
25
|
+
tooltipPlacement = 'bottom',
|
|
26
|
+
testID,
|
|
27
|
+
|
|
28
|
+
// withComponent
|
|
29
|
+
self,
|
|
30
|
+
|
|
31
|
+
// withValue
|
|
32
|
+
value,
|
|
33
|
+
setValue,
|
|
34
|
+
...propsToPass
|
|
35
|
+
} = props,
|
|
36
|
+
styles = UiGlobals.styles,
|
|
37
|
+
JsonEditor = getComponentFromType('JsonEditor'),
|
|
38
|
+
JsonViewer = getComponentFromType('JsonViewer');
|
|
39
|
+
|
|
40
|
+
let assembledComponents = null;
|
|
41
|
+
|
|
42
|
+
if (UiGlobals.mode === UI_MODE_WEB) {
|
|
43
|
+
const src = JSON.parse(value);
|
|
44
|
+
|
|
45
|
+
if (isEditable) {
|
|
46
|
+
assembledComponents =
|
|
47
|
+
<JsonEditor
|
|
48
|
+
// {...propsToPass}
|
|
49
|
+
src={src}
|
|
50
|
+
enableClipboard={false}
|
|
51
|
+
collapsed={true}
|
|
52
|
+
editable={isEditable}
|
|
53
|
+
onEdit={(obj) => {
|
|
54
|
+
setValue(JSON.stringify(obj.updated_src));
|
|
55
|
+
}}
|
|
56
|
+
isDisabled={isDisabled}
|
|
57
|
+
/>;
|
|
58
|
+
} else {
|
|
59
|
+
assembledComponents =
|
|
60
|
+
<JsonViewer
|
|
61
|
+
// {...propsToPass}
|
|
62
|
+
data={src}
|
|
63
|
+
/>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
if (UiGlobals.mode === UI_MODE_REACT_NATIVE) {
|
|
68
|
+
throw new Error('JsonElement not yet implemented for React Native');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (tooltip) {
|
|
72
|
+
assembledComponents = <Tooltip label={tooltip} placement={tooltipPlacement}>
|
|
73
|
+
{assembledComponents}
|
|
74
|
+
</Tooltip>;
|
|
75
|
+
}
|
|
76
|
+
return assembledComponents;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default withComponent(withValue(JsonElement));
|
|
@@ -225,7 +225,7 @@ function GridComponent(props) {
|
|
|
225
225
|
const usedIds = [];
|
|
226
226
|
_.each(localConfig, (column, ix) => {
|
|
227
227
|
if (!column.id || inArray(column.id, usedIds)) {
|
|
228
|
-
throw Error('When using unserializable columns, each column must have a unique id.
|
|
228
|
+
throw Error('When using unserializable columns, each column must have a unique id. ' + localColumnsConfigKey);
|
|
229
229
|
}
|
|
230
230
|
usedIds.push(column.id);
|
|
231
231
|
localConfig[ix] = {
|
package/src/Components/index.js
CHANGED
|
@@ -214,6 +214,7 @@ import GridPanel from './Panel/GridPanel.js';
|
|
|
214
214
|
import IconButton from './Buttons/IconButton.js';
|
|
215
215
|
import Input from './Form/Field/Input.js';
|
|
216
216
|
import IntervalsCombo from './Form/Field/Combo/IntervalsCombo.js';
|
|
217
|
+
import Json from './Form/Field/Json.js';
|
|
217
218
|
import Label from './Form/Label.js';
|
|
218
219
|
import MonthsCombo from './Form/Field/Combo/MonthsCombo.js';
|
|
219
220
|
import Number from './Form/Field/Number.js';
|
|
@@ -450,6 +451,7 @@ const components = {
|
|
|
450
451
|
IconButton,
|
|
451
452
|
Input,
|
|
452
453
|
IntervalsCombo,
|
|
454
|
+
Json,
|
|
453
455
|
Label,
|
|
454
456
|
MonthsCombo,
|
|
455
457
|
Number,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
|
|
3
|
+
export default function json() {
|
|
4
|
+
return yup.mixed().test(
|
|
5
|
+
'is-json',
|
|
6
|
+
'${path} is not valid JSON',
|
|
7
|
+
value => {
|
|
8
|
+
try {
|
|
9
|
+
JSON.parse(value);
|
|
10
|
+
return true; // Valid JSON
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return false; // Invalid JSON
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import UiGlobals from '../UiGlobals.js';
|
|
2
2
|
import Datetime from '../PlatformImports/ReactNative/Datetime';
|
|
3
3
|
import Draggable from '../PlatformImports/ReactNative/Draggable';
|
|
4
|
+
import JsonEditor from '../PlatformImports/ReactNative/JsonEditor.js';
|
|
4
5
|
import ScreenContainer from '../Components/Container/ScreenContainer';
|
|
5
6
|
import useWindowSize from '../PlatformImports/ReactNative/useWindowSize.js';
|
|
6
7
|
import _ from 'lodash';
|
|
@@ -9,6 +10,7 @@ export default function registerReactNativeComponents() {
|
|
|
9
10
|
_.merge(UiGlobals.components, {
|
|
10
11
|
Datetime,
|
|
11
12
|
Draggable,
|
|
13
|
+
JsonEditor,
|
|
12
14
|
ScreenContainer,
|
|
13
15
|
useWindowSize,
|
|
14
16
|
});
|
|
@@ -4,6 +4,8 @@ import Attachments from '../PlatformImports/Web/Attachments.js';
|
|
|
4
4
|
import Datetime from '../PlatformImports/Web/Datetime.js';
|
|
5
5
|
import Draggable from '../PlatformImports/Web/Draggable.js';
|
|
6
6
|
import File from '../PlatformImports/Web/File.js';
|
|
7
|
+
import JsonEditor from '../PlatformImports/Web/JsonEditor.js';
|
|
8
|
+
import JsonViewer from '../PlatformImports/Web/JsonViewer.js';
|
|
7
9
|
import useWindowSize from '../PlatformImports/Web/useWindowSize.js';
|
|
8
10
|
import _ from 'lodash';
|
|
9
11
|
|
|
@@ -14,6 +16,8 @@ export default function registerWebComponents() {
|
|
|
14
16
|
Datetime,
|
|
15
17
|
Draggable,
|
|
16
18
|
File,
|
|
19
|
+
JsonEditor,
|
|
20
|
+
JsonViewer,
|
|
17
21
|
useWindowSize,
|
|
18
22
|
});
|
|
19
23
|
}
|