@sphereon/ui-components.ssi-react 0.4.1-unstable.76 → 0.4.1-unstable.77
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/dist/components/buttons/SSISwitchItem/index.d.ts +11 -0
- package/dist/components/buttons/SSISwitchItem/index.js +88 -0
- package/dist/components/fields/JSONForms/PassportPhotoControl/index.js +2 -2
- package/dist/components/views/FormView/index.js +48 -21
- package/dist/components/views/FormView/styles.css +0 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/renders/jsonFormsRenders.js +0 -2
- package/dist/styles/css/tailwind.css +0 -3
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/package.json +4 -5
- package/dist/components/fields/JSONForms/CustomArrayControl/index.d.ts +0 -5
- package/dist/components/fields/JSONForms/CustomArrayControl/index.js +0 -71
- package/dist/types/jsonForms/index.d.ts +0 -4
- package/dist/types/jsonForms/index.js +0 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC, ReactElement } from 'react';
|
|
2
|
+
type Props = {
|
|
3
|
+
label: string;
|
|
4
|
+
checked: boolean;
|
|
5
|
+
onChange: (checked: boolean) => void;
|
|
6
|
+
tooltip?: ReactElement | string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
color?: string;
|
|
9
|
+
};
|
|
10
|
+
declare const SSISwitchItem: FC<Props>;
|
|
11
|
+
export default SSISwitchItem;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Switch, Tooltip } from '@mui/material';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { parseColor } from '@sphereon/ui-components.core';
|
|
6
|
+
const createMaterialSwitch = (color) => styled(Switch)(({ theme }) => ({
|
|
7
|
+
width: 52,
|
|
8
|
+
height: 32,
|
|
9
|
+
padding: 0,
|
|
10
|
+
'& .MuiSwitch-switchBase': {
|
|
11
|
+
padding: 4,
|
|
12
|
+
transitionDuration: '300ms',
|
|
13
|
+
'&.Mui-checked': {
|
|
14
|
+
transform: 'translateX(20px)',
|
|
15
|
+
color: 'var(--color-grey-50)',
|
|
16
|
+
'& + .MuiSwitch-track': {
|
|
17
|
+
backgroundColor: parseColor(color),
|
|
18
|
+
opacity: 1,
|
|
19
|
+
border: 0,
|
|
20
|
+
},
|
|
21
|
+
'&.Mui-disabled + .MuiSwitch-track': {
|
|
22
|
+
opacity: 0.5,
|
|
23
|
+
},
|
|
24
|
+
'& .MuiSwitch-thumb:before': {
|
|
25
|
+
backgroundImage: `url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(parseColor(color))}" d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>')`,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
'&.Mui-focusVisible .MuiSwitch-thumb': {
|
|
29
|
+
color: parseColor(color),
|
|
30
|
+
border: '6px solid var(--color-grey-50)',
|
|
31
|
+
},
|
|
32
|
+
'&.Mui-disabled .MuiSwitch-thumb': {
|
|
33
|
+
color: theme.palette.grey[100],
|
|
34
|
+
},
|
|
35
|
+
'&.Mui-disabled + .MuiSwitch-track': {
|
|
36
|
+
opacity: 0.3,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
'& .MuiSwitch-thumb': {
|
|
40
|
+
boxSizing: 'border-box',
|
|
41
|
+
width: 24,
|
|
42
|
+
height: 24,
|
|
43
|
+
'&:before': {
|
|
44
|
+
content: "''",
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
width: '100%',
|
|
47
|
+
height: '100%',
|
|
48
|
+
left: 0,
|
|
49
|
+
top: 0,
|
|
50
|
+
backgroundRepeat: 'no-repeat',
|
|
51
|
+
backgroundPosition: 'center',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
'& .MuiSwitch-track': {
|
|
55
|
+
borderRadius: 16,
|
|
56
|
+
backgroundColor: 'var(--color-grey-300)',
|
|
57
|
+
opacity: 1,
|
|
58
|
+
transition: theme.transitions.create(['background-color'], {
|
|
59
|
+
duration: 300,
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
const SSISwitchItem = (props) => {
|
|
64
|
+
const { label, checked, onChange, tooltip, disabled = false, color = 'var(--color-pending-500)' } = props;
|
|
65
|
+
const [showTooltip, setShowTooltip] = useState(false);
|
|
66
|
+
const MaterialSwitch = createMaterialSwitch(parseColor(color));
|
|
67
|
+
const handleChange = (event) => {
|
|
68
|
+
onChange(event.target.checked);
|
|
69
|
+
};
|
|
70
|
+
const containerStyle = {
|
|
71
|
+
display: 'flex',
|
|
72
|
+
flexDirection: 'row',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
gap: '12px',
|
|
75
|
+
};
|
|
76
|
+
const labelStyle = {
|
|
77
|
+
fontSize: '14px',
|
|
78
|
+
fontWeight: 400,
|
|
79
|
+
color: 'var(--color-grey-800)',
|
|
80
|
+
letterSpacing: '0.14px',
|
|
81
|
+
};
|
|
82
|
+
const content = (_jsxs("div", { style: containerStyle, children: [_jsx(MaterialSwitch, { checked: checked, onChange: handleChange, disabled: disabled }), _jsx("span", { style: labelStyle, children: label })] }));
|
|
83
|
+
if (tooltip) {
|
|
84
|
+
return (_jsx(Tooltip, { title: tooltip, open: showTooltip, onOpen: () => setShowTooltip(true), onClose: () => setShowTooltip(false), arrow: true, children: _jsx("div", { onMouseEnter: () => setShowTooltip(true), onMouseLeave: () => setShowTooltip(false), children: content }) }));
|
|
85
|
+
}
|
|
86
|
+
return content;
|
|
87
|
+
};
|
|
88
|
+
export default SSISwitchItem;
|
|
@@ -8,7 +8,7 @@ import PersonPlaceholder from '../../../assets/placeholders/PersonPlaceholder';
|
|
|
8
8
|
import FileSelection from '../../FileSelection';
|
|
9
9
|
import { base64UriToFile } from '../../../../utils';
|
|
10
10
|
import { PassportPhotoControlContainerStyled as Container, PassportPhotoControlDragAndDropBoxContainerStyled as DragAndDropBoxContainer, PassportPhotoControlPassportPhotoContainerStyled as PassportPhotoContainer, PassportPhotoControlPassportPhotoImageStyled as PassportPhotoImage, } from '../../../../styles';
|
|
11
|
-
import { FileSelectionFieldType
|
|
11
|
+
import { FileSelectionFieldType } from '../../../../types';
|
|
12
12
|
const PassportPhotoControl = (props) => {
|
|
13
13
|
const { data, handleChange, path } = props;
|
|
14
14
|
const [image, setImage] = useState(data && { file: base64UriToFile(data.base64Uri, data.fileName, data.mimeType), base64Uri: data.base64Uri });
|
|
@@ -30,5 +30,5 @@ const PassportPhotoControl = (props) => {
|
|
|
30
30
|
};
|
|
31
31
|
return (_jsxs(Container, { children: [_jsxs(DragAndDropBoxContainer, { children: [_jsx(DragAndDropBox, { caption: Localization.translate('drag_and_drop_upload_image_caption'), description: Localization.translate('credential_attach_image_description'), onChangeFile: onAddImage }), _jsx(PassportPhotoContainer, { children: image ? _jsx(PassportPhotoImage, { src: image.base64Uri, alt: Localization.translate('passport_photo_alt') }) : _jsx(PersonPlaceholder, {}) })] }), image && _jsx(FileSelection, { file: image.file, fileType: FileSelectionFieldType.IMAGE, onRemove: onRemoveImage })] }));
|
|
32
32
|
};
|
|
33
|
-
export const passportPhotoControlTester = rankWith(3, and(isObjectControl, optionIs('type',
|
|
33
|
+
export const passportPhotoControlTester = rankWith(3, and(isObjectControl, optionIs('type', 'passportPhoto')));
|
|
34
34
|
export default withJsonFormsControlProps(PassportPhotoControl);
|
|
@@ -1,31 +1,58 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
2
3
|
import { JsonForms } from '@jsonforms/react';
|
|
3
4
|
import { materialCells } from '@jsonforms/material-renderers';
|
|
4
5
|
import { jsonFormsMaterialRenderers } from '../../../renders/jsonFormsRenders';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
import { formatDateToISO } from '../../../helpers';
|
|
7
|
+
const initializeDefaultValues = (schema, currentData = {}) => {
|
|
8
|
+
const result = { ...currentData };
|
|
9
|
+
if (!schema.properties) {
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
Object.entries(schema.properties).forEach(([key, property]) => {
|
|
13
|
+
if (typeof property === 'object') {
|
|
14
|
+
if (property.const && (!(key in result) || !result[key])) {
|
|
15
|
+
result[key] = property.const;
|
|
16
|
+
}
|
|
17
|
+
if (property.default !== undefined && !(key in result)) {
|
|
18
|
+
if (property.format?.startsWith('date') || property.format?.startsWith('time')) {
|
|
19
|
+
result[key] = formatDateToISO(property.default, property.format);
|
|
20
|
+
}
|
|
21
|
+
else if (typeof property.default === 'object') {
|
|
22
|
+
result[key] = Array.isArray(property.default)
|
|
23
|
+
? [...property.default]
|
|
24
|
+
: { ...property.default };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
result[key] = property.default;
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
if (property.properties) {
|
|
31
|
+
if (!result[key]) {
|
|
32
|
+
result[key] = {};
|
|
33
|
+
}
|
|
34
|
+
result[key] = initializeDefaultValues(property, result[key]);
|
|
21
35
|
}
|
|
22
|
-
return true;
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
27
40
|
const FormView = (props) => {
|
|
28
|
-
const { data, schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv
|
|
29
|
-
|
|
41
|
+
const { data, schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv, onFormStateChange, readonly = false, config, } = props;
|
|
42
|
+
const [formData, setFormData] = useState(data ?? {});
|
|
43
|
+
const [initialized, setInitialized] = useState(false);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const initializedData = initializeDefaultValues(schema, formData);
|
|
46
|
+
setFormData(initializedData);
|
|
47
|
+
setInitialized(true);
|
|
48
|
+
}, [schema]);
|
|
49
|
+
const onFormStateChanged = (state) => {
|
|
50
|
+
if (!initialized) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setFormData(state.data);
|
|
54
|
+
void onFormStateChange?.(state);
|
|
55
|
+
};
|
|
56
|
+
return (_jsx("div", { style: style, children: _jsx(JsonForms, { schema: schema, uischema: uiSchema, data: formData, renderers: renderers, cells: cells, onChange: onFormStateChanged, validationMode: validationMode, middleware: middleware, ajv: ajv, readonly: readonly, config: config }) }));
|
|
30
57
|
};
|
|
31
58
|
export default FormView;
|
|
@@ -103,14 +103,3 @@ textarea.MuiInputBase-input.MuiInputBase-inputMultiline {
|
|
|
103
103
|
.MuiTabs-scroller.MuiTabs-fixed {
|
|
104
104
|
margin-bottom: 12px !important;
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
.MuiFormHelperText-root {
|
|
108
|
-
display: none;
|
|
109
|
-
}
|
|
110
|
-
.MuiFormHelperText-root:empty {
|
|
111
|
-
display: none;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
.MuiFormControlLabel-root {
|
|
115
|
-
height: fit-content;
|
|
116
|
-
}
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,6 @@ import ComboBox from './components/fields/ComboBox';
|
|
|
37
37
|
import DragAndDropBox from './components/fields/DragAndDropBox';
|
|
38
38
|
import PersonPlaceholder from './components/assets/placeholders/PersonPlaceholder';
|
|
39
39
|
import PassportPhotoControl, { passportPhotoControlTester } from './components/fields/JSONForms/PassportPhotoControl';
|
|
40
|
-
import CustomArrayControl, { customArrayControlTester } from './components/fields/JSONForms/CustomArrayControl';
|
|
41
40
|
import CredentialIssuanceWizardView from './components/views/CredentialIssuanceWizardView';
|
|
42
41
|
import PaginationControls from './components/views/SSITableView/PaginationControls';
|
|
43
42
|
import PaginationControlsProps from './components/views/SSITableView/PaginationControls';
|
|
@@ -60,6 +59,7 @@ import ActivityIcon from './components/assets/icons/ActivityIcon';
|
|
|
60
59
|
import ContactIcon from './components/assets/icons/ContactIcon';
|
|
61
60
|
import BellIcon from './components/assets/icons/BellIcon';
|
|
62
61
|
import CredentialIcon from './components/assets/icons/CredentialIcon';
|
|
62
|
+
import SSISwitchItem from './components/buttons/SSISwitchItem';
|
|
63
63
|
import { Row } from '@tanstack/react-table';
|
|
64
64
|
import './styles/css/tailwind.css';
|
|
65
65
|
import './components/views/FormView/styles.css';
|
|
@@ -68,4 +68,4 @@ export * from './styles/fonts';
|
|
|
68
68
|
export * from './types';
|
|
69
69
|
export * from './helpers';
|
|
70
70
|
export * from './utils';
|
|
71
|
-
export { SSICredentialCardView, CredentialMiniCardView, CredentialMiniCardViewProps, SSIStatusLabel, SSICheckmarkBadge, SSIExclamationMarkBadge, SSIPlaceholderLogo, SSILogo, SSIAddIcon, SSIFilterIcon, SSIArrowDownIcon, SSITypeLabel, IconButton, PrimaryButton, SecondaryButton, DropDownList, SSITableView, SSITableViewHeader, SSITabView, SSITabViewHeader, SSIProfileIcon, SSIToastContainer, SSICheckbox, SSIActivityIndicator, SSIHoverText, StepMarker, ProgressStepIndicator, PaginationControls, PaginationControlsProps, Row, DocumentIcon, CrossIcon, ImageIcon, MeatBallsIcon, PencilIcon, ViewIcon, CopyIcon, DeleteIcon, FileSelection, ComboBox, DragAndDropBox, PersonPlaceholder, PassportPhotoControl, passportPhotoControlTester,
|
|
71
|
+
export { SSICredentialCardView, CredentialMiniCardView, CredentialMiniCardViewProps, SSIStatusLabel, SSICheckmarkBadge, SSIExclamationMarkBadge, SSIPlaceholderLogo, SSILogo, SSIAddIcon, SSIFilterIcon, SSIArrowDownIcon, SSITypeLabel, IconButton, PrimaryButton, SecondaryButton, DropDownList, SSITableView, SSITableViewHeader, SSITabView, SSITabViewHeader, SSIProfileIcon, SSIToastContainer, SSICheckbox, SSIActivityIndicator, SSIHoverText, StepMarker, ProgressStepIndicator, PaginationControls, PaginationControlsProps, Row, DocumentIcon, CrossIcon, ImageIcon, MeatBallsIcon, PencilIcon, ViewIcon, CopyIcon, DeleteIcon, FileSelection, ComboBox, DragAndDropBox, PersonPlaceholder, PassportPhotoControl, passportPhotoControlTester, CredentialIssuanceWizardView, CredentialViewItem, JSONDataView, TextInputField, WarningImage, FormView, InformationRequestView, ContactViewItem, CapitolIcon, ChevronIcon, ManIcon, LaptopIcon, StoreIcon, RoleIconView, RoleViewItem, Listbox, ActivityIcon, ContactIcon, BellIcon, CredentialIcon, SSISwitchItem };
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ import ComboBox from './components/fields/ComboBox';
|
|
|
37
37
|
import DragAndDropBox from './components/fields/DragAndDropBox';
|
|
38
38
|
import PersonPlaceholder from './components/assets/placeholders/PersonPlaceholder';
|
|
39
39
|
import PassportPhotoControl, { passportPhotoControlTester } from './components/fields/JSONForms/PassportPhotoControl';
|
|
40
|
-
import CustomArrayControl, { customArrayControlTester } from './components/fields/JSONForms/CustomArrayControl';
|
|
41
40
|
import CredentialIssuanceWizardView from './components/views/CredentialIssuanceWizardView';
|
|
42
41
|
import PaginationControls from './components/views/SSITableView/PaginationControls';
|
|
43
42
|
import PaginationControlsProps from './components/views/SSITableView/PaginationControls';
|
|
@@ -60,6 +59,7 @@ import ActivityIcon from './components/assets/icons/ActivityIcon';
|
|
|
60
59
|
import ContactIcon from './components/assets/icons/ContactIcon';
|
|
61
60
|
import BellIcon from './components/assets/icons/BellIcon';
|
|
62
61
|
import CredentialIcon from './components/assets/icons/CredentialIcon';
|
|
62
|
+
import SSISwitchItem from './components/buttons/SSISwitchItem';
|
|
63
63
|
import './styles/css/tailwind.css';
|
|
64
64
|
import './components/views/FormView/styles.css';
|
|
65
65
|
import '@sphereon/ui-components.core/dist/styles/tokens.css';
|
|
@@ -67,4 +67,4 @@ export * from './styles/fonts';
|
|
|
67
67
|
export * from './types';
|
|
68
68
|
export * from './helpers';
|
|
69
69
|
export * from './utils';
|
|
70
|
-
export { SSICredentialCardView, CredentialMiniCardView, SSIStatusLabel, SSICheckmarkBadge, SSIExclamationMarkBadge, SSIPlaceholderLogo, SSILogo, SSIAddIcon, SSIFilterIcon, SSIArrowDownIcon, SSITypeLabel, IconButton, PrimaryButton, SecondaryButton, DropDownList, SSITableView, SSITableViewHeader, SSITabView, SSITabViewHeader, SSIProfileIcon, SSIToastContainer, SSICheckbox, SSIActivityIndicator, SSIHoverText, StepMarker, ProgressStepIndicator, PaginationControls, PaginationControlsProps, DocumentIcon, CrossIcon, ImageIcon, MeatBallsIcon, PencilIcon, ViewIcon, CopyIcon, DeleteIcon, FileSelection, ComboBox, DragAndDropBox, PersonPlaceholder, PassportPhotoControl, passportPhotoControlTester,
|
|
70
|
+
export { SSICredentialCardView, CredentialMiniCardView, SSIStatusLabel, SSICheckmarkBadge, SSIExclamationMarkBadge, SSIPlaceholderLogo, SSILogo, SSIAddIcon, SSIFilterIcon, SSIArrowDownIcon, SSITypeLabel, IconButton, PrimaryButton, SecondaryButton, DropDownList, SSITableView, SSITableViewHeader, SSITabView, SSITabViewHeader, SSIProfileIcon, SSIToastContainer, SSICheckbox, SSIActivityIndicator, SSIHoverText, StepMarker, ProgressStepIndicator, PaginationControls, PaginationControlsProps, DocumentIcon, CrossIcon, ImageIcon, MeatBallsIcon, PencilIcon, ViewIcon, CopyIcon, DeleteIcon, FileSelection, ComboBox, DragAndDropBox, PersonPlaceholder, PassportPhotoControl, passportPhotoControlTester, CredentialIssuanceWizardView, CredentialViewItem, JSONDataView, TextInputField, WarningImage, FormView, InformationRequestView, ContactViewItem, CapitolIcon, ChevronIcon, ManIcon, LaptopIcon, StoreIcon, RoleIconView, RoleViewItem, Listbox, ActivityIcon, ContactIcon, BellIcon, CredentialIcon, SSISwitchItem };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { materialRenderers } from '@jsonforms/material-renderers';
|
|
2
2
|
import PassportPhotoControl, { passportPhotoControlTester } from '../components/fields/JSONForms/PassportPhotoControl';
|
|
3
|
-
import CustomArrayControl, { customArrayControlTester } from '../components/fields/JSONForms/CustomArrayControl';
|
|
4
3
|
export const jsonFormsMaterialRenderers = [
|
|
5
4
|
...materialRenderers,
|
|
6
5
|
{ tester: passportPhotoControlTester, renderer: PassportPhotoControl },
|
|
7
|
-
{ tester: customArrayControlTester, renderer: CustomArrayControl },
|
|
8
6
|
];
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ui-components.ssi-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.4.1-unstable.
|
|
4
|
+
"version": "0.4.1-unstable.77+aa9a3ab",
|
|
5
5
|
"description": "SSI UI components for React",
|
|
6
6
|
"repository": "git@github.com:Sphereon-Opensource/UI-Components.git",
|
|
7
7
|
"author": "Sphereon <dev@sphereon.com>",
|
|
@@ -50,10 +50,8 @@
|
|
|
50
50
|
"@mui/x-date-pickers": "^6.19.5",
|
|
51
51
|
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.45.94",
|
|
52
52
|
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.45.94",
|
|
53
|
-
"@sphereon/ui-components.core": "0.4.1-unstable.
|
|
53
|
+
"@sphereon/ui-components.core": "0.4.1-unstable.77+aa9a3ab",
|
|
54
54
|
"@tanstack/react-table": "^8.9.3",
|
|
55
|
-
"ajv": "^8.17.1",
|
|
56
|
-
"ajv-formats": "^3.0.1",
|
|
57
55
|
"react-dom": "npm:react-dom@18.3.1",
|
|
58
56
|
"react-json-tree": "^0.18.0",
|
|
59
57
|
"react-loader-spinner": "5.4.5",
|
|
@@ -65,11 +63,12 @@
|
|
|
65
63
|
"devDependencies": {
|
|
66
64
|
"@tailwindcss/cli": "^4.1.11",
|
|
67
65
|
"@types/react": "~18.3.18",
|
|
66
|
+
"ajv": "^8.12.0",
|
|
68
67
|
"tailwindcss": "^4.1.11",
|
|
69
68
|
"typescript": "4.9.5"
|
|
70
69
|
},
|
|
71
70
|
"peerDependencies": {
|
|
72
71
|
"react": ">= 18"
|
|
73
72
|
},
|
|
74
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "aa9a3ab1117d288ef200fd14e94f6010a20926c0"
|
|
75
74
|
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { JsonFormsDispatch, withJsonFormsControlProps } from '@jsonforms/react';
|
|
3
|
-
import { and, isArrayObjectControl, optionIs, rankWith } from '@jsonforms/core';
|
|
4
|
-
import { ButtonIcon } from '@sphereon/ui-components.core';
|
|
5
|
-
import IconButton from '../../../buttons/IconButton';
|
|
6
|
-
import PrimaryButton from '../../../buttons/PrimaryButton';
|
|
7
|
-
import { JsonFormsCustomControlKey } from '../../../../types';
|
|
8
|
-
const CustomArrayControl = (props) => {
|
|
9
|
-
const { data = [], handleChange, path, schema, uischema, label } = props;
|
|
10
|
-
const elements = uischema.options?.detail?.elements || [];
|
|
11
|
-
const itemSchema = schema.items && !Array.isArray(schema.items) ? schema.items : {};
|
|
12
|
-
const handleAdd = async (index) => {
|
|
13
|
-
if (index !== undefined) {
|
|
14
|
-
const targetItem = { ...data[index] };
|
|
15
|
-
targetItem.properties = targetItem.properties ?? [];
|
|
16
|
-
targetItem.properties.push({});
|
|
17
|
-
data[index] = targetItem;
|
|
18
|
-
handleChange(path, [...data]);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
handleChange(path, [...data, {}]);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const handleRemove = async (index) => {
|
|
25
|
-
const newData = data.filter((_, i) => i !== index);
|
|
26
|
-
handleChange(path, newData);
|
|
27
|
-
};
|
|
28
|
-
const getItemElements = () => {
|
|
29
|
-
return data.map((item, index) => _jsx("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: _jsx("div", { style: { display: 'flex', flexDirection: 'row', borderRadius: 8, overflow: 'hidden', width: '100%' }, children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', width: '100%' }, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx("div", { style: { display: 'flex', flexDirection: 'row', gap: 24, padding: 24, border: '1px solid #C4C4C4', borderRadius: 8, flexGrow: 1, alignItems: 'center' }, children: getFieldElements(elements, `${path}.${index}`) }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 24 }, children: [_jsx(IconButton, { icon: ButtonIcon.DELETE, onClick: () => handleRemove(index) }), item?.type === 'object' &&
|
|
30
|
-
_jsx(IconButton, { icon: ButtonIcon.ADD, onClick: () => handleAdd(index) })] })] }), item?.type === 'object' &&
|
|
31
|
-
_jsx("div", { style: { marginLeft: 24, display: 'flex', flexDirection: 'row' }, children: getChildFieldElements(elements, `${path}.${index}.properties`) })] }) }) }, index));
|
|
32
|
-
};
|
|
33
|
-
const getFieldElements = (elements, path) => {
|
|
34
|
-
return elements
|
|
35
|
-
.filter(element => element?.options?.type !== JsonFormsCustomControlKey.ARRAY)
|
|
36
|
-
.map((element, i) => _jsx(JsonFormsDispatch, { uischema: element, schema: itemSchema, path: path }, i));
|
|
37
|
-
};
|
|
38
|
-
const getChildFieldElements = (elements, path) => {
|
|
39
|
-
return elements
|
|
40
|
-
.filter(element => element?.options?.type === JsonFormsCustomControlKey.ARRAY)
|
|
41
|
-
.map((element, i) => {
|
|
42
|
-
const childrenArraySchema = itemSchema.properties?.children;
|
|
43
|
-
const resolvedChildrenSchema = {
|
|
44
|
-
...childrenArraySchema,
|
|
45
|
-
items: itemSchema
|
|
46
|
-
};
|
|
47
|
-
const childrenUiSchema = {
|
|
48
|
-
...element,
|
|
49
|
-
type: "Control",
|
|
50
|
-
scope: "#",
|
|
51
|
-
options: {
|
|
52
|
-
...uischema.options,
|
|
53
|
-
isChild: true,
|
|
54
|
-
type: JsonFormsCustomControlKey.ARRAY,
|
|
55
|
-
detail: {
|
|
56
|
-
elements
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return (_jsx(JsonFormsDispatch, { uischema: childrenUiSchema, schema: resolvedChildrenSchema, path: path }, i));
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 28, width: '100%' }, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'row', alignItems: 'center' }, children: [_jsx("div", { style: { color: 'black', fontSize: 16, fontWeight: '400' }, children: label }), !uischema.options?.isChild &&
|
|
64
|
-
_jsx(PrimaryButton, { caption: uischema.options?.addLabel || '+', onClick: handleAdd, style: {
|
|
65
|
-
marginLeft: 'auto',
|
|
66
|
-
height: 33,
|
|
67
|
-
width: 120
|
|
68
|
-
} })] }), getItemElements()] }));
|
|
69
|
-
};
|
|
70
|
-
export const customArrayControlTester = rankWith(5, and(isArrayObjectControl, optionIs('type', JsonFormsCustomControlKey.ARRAY)));
|
|
71
|
-
export default withJsonFormsControlProps(CustomArrayControl);
|