@onehat/ui 0.3.316 → 0.3.318
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 +2 -1
- package/src/Components/Form/Field/Json.js +74 -0
- package/src/Components/Grid/GridRow.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 +2 -0
- package/src/PlatformImports/ReactNative/JsonEditor.js +3 -0
- package/src/PlatformImports/Web/JsonEditor.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.318",
|
|
4
4
|
"description": "Base UI for OneHat apps",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"react-native": "*",
|
|
56
56
|
"react-native-draggable": "^3.3.0",
|
|
57
57
|
"react-native-svg": "*",
|
|
58
|
+
"react18-json-view": "^0.2.8",
|
|
58
59
|
"use-file-picker": "^2.1.1"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
isViewOnly = false,
|
|
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
|
+
|
|
39
|
+
let assembledComponents = null;
|
|
40
|
+
|
|
41
|
+
if (UiGlobals.mode === UI_MODE_WEB) {
|
|
42
|
+
const src = JSON.parse(value);
|
|
43
|
+
assembledComponents =
|
|
44
|
+
<Row
|
|
45
|
+
flex={1}
|
|
46
|
+
{...propsToPass}
|
|
47
|
+
justifyContent="flex-start"
|
|
48
|
+
>
|
|
49
|
+
<JsonEditor
|
|
50
|
+
width="100%"
|
|
51
|
+
editable={!isViewOnly}
|
|
52
|
+
src={src}
|
|
53
|
+
enableClipboard={false}
|
|
54
|
+
collapsed={true}
|
|
55
|
+
onEdit={(obj) => {
|
|
56
|
+
setValue(JSON.stringify(obj.updated_src));
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
</Row>;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
if (UiGlobals.mode === UI_MODE_REACT_NATIVE) {
|
|
63
|
+
throw new Error('JsonElement not yet implemented for React Native');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (tooltip) {
|
|
67
|
+
assembledComponents = <Tooltip label={tooltip} placement={tooltipPlacement}>
|
|
68
|
+
{assembledComponents}
|
|
69
|
+
</Tooltip>;
|
|
70
|
+
}
|
|
71
|
+
return assembledComponents;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default withComponent(withValue(JsonElement));
|
|
@@ -122,7 +122,7 @@ function GridRow(props) {
|
|
|
122
122
|
if (UiGlobals.mode === UI_MODE_WEB) {
|
|
123
123
|
elementProps.textOverflow = 'ellipsis';
|
|
124
124
|
}
|
|
125
|
-
if (type.match(/(Tag|TagEditor)$/)) {
|
|
125
|
+
if (type.match(/(Tag|TagEditor|Json)$/)) {
|
|
126
126
|
elementProps.isViewOnly = true; // TODO: this won't work for InlineGridEditor, bc that Grid can't use isViewOnly when actually editing
|
|
127
127
|
}
|
|
128
128
|
if (config.getCellProps) {
|
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,7 @@ 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';
|
|
7
8
|
import useWindowSize from '../PlatformImports/Web/useWindowSize.js';
|
|
8
9
|
import _ from 'lodash';
|
|
9
10
|
|
|
@@ -14,6 +15,7 @@ export default function registerWebComponents() {
|
|
|
14
15
|
Datetime,
|
|
15
16
|
Draggable,
|
|
16
17
|
File,
|
|
18
|
+
JsonEditor,
|
|
17
19
|
useWindowSize,
|
|
18
20
|
});
|
|
19
21
|
}
|