@luomus/laji-form 15.1.4 → 15.1.6
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/lib/ApiClient.d.ts +46 -0
- package/lib/ApiClient.js +93 -0
- package/lib/Context.d.ts +8 -0
- package/lib/Context.js +18 -0
- package/lib/ReactContext.d.ts +7 -0
- package/lib/ReactContext.js +5 -0
- package/lib/components/BaseComponent.d.ts +9 -0
- package/lib/components/BaseComponent.js +29 -0
- package/lib/components/LajiForm.d.ts +221 -0
- package/lib/components/LajiForm.js +616 -0
- package/lib/components/VirtualSchemaField.d.ts +42 -0
- package/lib/components/VirtualSchemaField.js +74 -0
- package/lib/components/components.d.ts +119 -0
- package/lib/components/components.js +606 -0
- package/lib/components/fields/AnnotationField.d.ts +34 -0
- package/lib/components/fields/AnnotationField.js +242 -0
- package/lib/components/fields/AnyToBooleanField.d.ts +18 -0
- package/lib/components/fields/AnyToBooleanField.js +20 -0
- package/lib/components/fields/ArrayBulkField.d.ts +23 -0
- package/lib/components/fields/ArrayBulkField.js +82 -0
- package/lib/components/fields/ArrayCombinerField.d.ts +36 -0
- package/lib/components/fields/ArrayCombinerField.js +138 -0
- package/lib/components/fields/ArrayField.d.ts +39 -0
- package/lib/components/fields/ArrayField.js +148 -0
- package/lib/components/fields/AsArrayField.d.ts +292 -0
- package/lib/components/fields/AsArrayField.js +38 -0
- package/lib/components/fields/AudioArrayField.d.ts +22 -0
- package/lib/components/fields/AudioArrayField.js +100 -0
- package/lib/components/fields/AutoArrayField.d.ts +24 -0
- package/lib/components/fields/AutoArrayField.js +56 -0
- package/lib/components/fields/AutosuggestField.d.ts +69 -0
- package/lib/components/fields/AutosuggestField.js +299 -0
- package/lib/components/fields/CombinedValueDisplayField.d.ts +41 -0
- package/lib/components/fields/CombinedValueDisplayField.js +100 -0
- package/lib/components/fields/ConditionalOnChangeField.d.ts +42 -0
- package/lib/components/fields/ConditionalOnChangeField.js +107 -0
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +123 -0
- package/lib/components/fields/ConditionalUiSchemaField.js +143 -0
- package/lib/components/fields/ContextInjectionField.d.ts +24 -0
- package/lib/components/fields/ContextInjectionField.js +68 -0
- package/lib/components/fields/DataLeakerField.d.ts +40 -0
- package/lib/components/fields/DataLeakerField.js +68 -0
- package/lib/components/fields/DefaultValueArrayField.d.ts +34 -0
- package/lib/components/fields/DefaultValueArrayField.js +59 -0
- package/lib/components/fields/DependentBooleanField.d.ts +38 -0
- package/lib/components/fields/DependentBooleanField.js +87 -0
- package/lib/components/fields/DependentDisableField.d.ts +35 -0
- package/lib/components/fields/DependentDisableField.js +71 -0
- package/lib/components/fields/EnumRangeArrayField.d.ts +27 -0
- package/lib/components/fields/EnumRangeArrayField.js +115 -0
- package/lib/components/fields/ExtraLabelRowField.d.ts +38 -0
- package/lib/components/fields/ExtraLabelRowField.js +100 -0
- package/lib/components/fields/FakePropertyField.d.ts +18 -0
- package/lib/components/fields/FakePropertyField.js +48 -0
- package/lib/components/fields/FilterArrayField.d.ts +73 -0
- package/lib/components/fields/FilterArrayField.js +121 -0
- package/lib/components/fields/FlatField.d.ts +29 -0
- package/lib/components/fields/FlatField.js +171 -0
- package/lib/components/fields/GeocoderField.d.ts +47 -0
- package/lib/components/fields/GeocoderField.js +372 -0
- package/lib/components/fields/GridLayoutField.d.ts +18 -0
- package/lib/components/fields/GridLayoutField.js +32 -0
- package/lib/components/fields/HiddenField.d.ts +10 -0
- package/lib/components/fields/HiddenField.js +11 -0
- package/lib/components/fields/ImageArrayField.d.ts +172 -0
- package/lib/components/fields/ImageArrayField.js +699 -0
- package/lib/components/fields/ImageDisplayField.d.ts +18 -0
- package/lib/components/fields/ImageDisplayField.js +44 -0
- package/lib/components/fields/InitiallyHiddenField.d.ts +21 -0
- package/lib/components/fields/InitiallyHiddenField.js +58 -0
- package/lib/components/fields/InjectDefaultValueField.d.ts +37 -0
- package/lib/components/fields/InjectDefaultValueField.js +68 -0
- package/lib/components/fields/InjectField.d.ts +46 -0
- package/lib/components/fields/InjectField.js +88 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +25 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.js +61 -0
- package/lib/components/fields/LocalityField.d.ts +22 -0
- package/lib/components/fields/LocalityField.js +94 -0
- package/lib/components/fields/LocationChooserField.d.ts +27 -0
- package/lib/components/fields/LocationChooserField.js +440 -0
- package/lib/components/fields/MapArrayField.d.ts +78 -0
- package/lib/components/fields/MapArrayField.js +1783 -0
- package/lib/components/fields/MapField.d.ts +48 -0
- package/lib/components/fields/MapField.js +434 -0
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +25 -0
- package/lib/components/fields/MultiAnyToBooleanField.js +100 -0
- package/lib/components/fields/MultiArrayField.d.ts +53 -0
- package/lib/components/fields/MultiArrayField.js +224 -0
- package/lib/components/fields/MultiLanguageField.d.ts +13 -0
- package/lib/components/fields/MultiLanguageField.js +52 -0
- package/lib/components/fields/MultiTagArrayField.d.ts +36 -0
- package/lib/components/fields/MultiTagArrayField.js +142 -0
- package/lib/components/fields/NamedPlaceChooserField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceChooserField.js +380 -0
- package/lib/components/fields/NamedPlaceSaverField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceSaverField.js +237 -0
- package/lib/components/fields/NestField.d.ts +148 -0
- package/lib/components/fields/NestField.js +289 -0
- package/lib/components/fields/ObjectField.d.ts +2 -0
- package/lib/components/fields/ObjectField.js +119 -0
- package/lib/components/fields/PdfArrayField.d.ts +21 -0
- package/lib/components/fields/PdfArrayField.js +40 -0
- package/lib/components/fields/PrefillingArrayField.d.ts +22 -0
- package/lib/components/fields/PrefillingArrayField.js +65 -0
- package/lib/components/fields/SchemaField.d.ts +7 -0
- package/lib/components/fields/SchemaField.js +109 -0
- package/lib/components/fields/ScopeField.d.ts +85 -0
- package/lib/components/fields/ScopeField.js +521 -0
- package/lib/components/fields/SectionArrayField.d.ts +38 -0
- package/lib/components/fields/SectionArrayField.js +618 -0
- package/lib/components/fields/SelectTreeField.d.ts +39 -0
- package/lib/components/fields/SelectTreeField.js +143 -0
- package/lib/components/fields/SingleActiveArrayField.d.ts +49 -0
- package/lib/components/fields/SingleActiveArrayField.js +974 -0
- package/lib/components/fields/SingleItemArrayField.d.ts +15 -0
- package/lib/components/fields/SingleItemArrayField.js +60 -0
- package/lib/components/fields/SortArrayField.d.ts +73 -0
- package/lib/components/fields/SortArrayField.js +351 -0
- package/lib/components/fields/SplitField.d.ts +28 -0
- package/lib/components/fields/SplitField.js +65 -0
- package/lib/components/fields/StringToArrayField.d.ts +24 -0
- package/lib/components/fields/StringToArrayField.js +48 -0
- package/lib/components/fields/SumField.d.ts +35 -0
- package/lib/components/fields/SumField.js +83 -0
- package/lib/components/fields/TableField.d.ts +18 -0
- package/lib/components/fields/TableField.js +136 -0
- package/lib/components/fields/TagArrayField.d.ts +38 -0
- package/lib/components/fields/TagArrayField.js +128 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +26 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +81 -0
- package/lib/components/fields/UiFieldApplierField.d.ts +30 -0
- package/lib/components/fields/UiFieldApplierField.js +106 -0
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +42 -0
- package/lib/components/fields/UiFieldMapperArrayField.js +121 -0
- package/lib/components/fields/UnitCountShorthandField.d.ts +22 -0
- package/lib/components/fields/UnitCountShorthandField.js +149 -0
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +26 -0
- package/lib/components/fields/UnitListShorthandArrayField.js +108 -0
- package/lib/components/fields/UnitShorthandField.d.ts +32 -0
- package/lib/components/fields/UnitShorthandField.js +220 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +85 -0
- package/lib/components/templates/ArrayFieldTemplate.js +416 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +11 -0
- package/lib/components/templates/BaseInputTemplate.js +80 -0
- package/lib/components/templates/DescriptionField.d.ts +1 -0
- package/lib/components/templates/DescriptionField.js +37 -0
- package/lib/components/templates/ErrorListTemplate.d.ts +9 -0
- package/lib/components/templates/ErrorListTemplate.js +95 -0
- package/lib/components/templates/FieldTemplate.d.ts +6 -0
- package/lib/components/templates/FieldTemplate.js +112 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ObjectFieldTemplate.js +66 -0
- package/lib/components/templates/TitleField.d.ts +9 -0
- package/lib/components/templates/TitleField.js +51 -0
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +20 -0
- package/lib/components/widgets/AnyToBooleanWidget.js +49 -0
- package/lib/components/widgets/AutosuggestWidget.d.ts +66 -0
- package/lib/components/widgets/AutosuggestWidget.js +1127 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +37 -0
- package/lib/components/widgets/CheckboxWidget.js +139 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +62 -0
- package/lib/components/widgets/DateTimeWidget.js +251 -0
- package/lib/components/widgets/DateWidget.d.ts +23 -0
- package/lib/components/widgets/DateWidget.js +41 -0
- package/lib/components/widgets/HiddenWidget.d.ts +15 -0
- package/lib/components/widgets/HiddenWidget.js +19 -0
- package/lib/components/widgets/ImageSelectWidget.d.ts +14 -0
- package/lib/components/widgets/ImageSelectWidget.js +57 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +43 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +237 -0
- package/lib/components/widgets/InputGroupWidget.d.ts +21 -0
- package/lib/components/widgets/InputGroupWidget.js +36 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +21 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +47 -0
- package/lib/components/widgets/NumberWidget.d.ts +13 -0
- package/lib/components/widgets/NumberWidget.js +21 -0
- package/lib/components/widgets/PlainTextWidget.d.ts +12 -0
- package/lib/components/widgets/PlainTextWidget.js +24 -0
- package/lib/components/widgets/SelectWidget.d.ts +52 -0
- package/lib/components/widgets/SelectWidget.js +158 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +19 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.js +59 -0
- package/lib/components/widgets/TaxonImageWidget.d.ts +13 -0
- package/lib/components/widgets/TaxonImageWidget.js +30 -0
- package/lib/components/widgets/TextSelectWidget.d.ts +25 -0
- package/lib/components/widgets/TextSelectWidget.js +94 -0
- package/lib/components/widgets/TextareaWidget.d.ts +32 -0
- package/lib/components/widgets/TextareaWidget.js +87 -0
- package/lib/components/widgets/TimeWidget.d.ts +11 -0
- package/lib/components/widgets/TimeWidget.js +19 -0
- package/lib/components/widgets/URLWidget.d.ts +14 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/UpperCaseWidget.d.ts +13 -0
- package/lib/components/widgets/UpperCaseWidget.js +21 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +50 -0
- package/lib/services/blocker-service.d.ts +11 -0
- package/lib/services/blocker-service.js +55 -0
- package/lib/services/custom-event-service.d.ts +17 -0
- package/lib/services/custom-event-service.js +35 -0
- package/lib/services/dom-id-service.d.ts +8 -0
- package/lib/services/dom-id-service.js +30 -0
- package/lib/services/focus-service.d.ts +13 -0
- package/lib/services/focus-service.js +60 -0
- package/lib/services/id-service.d.ts +22 -0
- package/lib/services/id-service.js +130 -0
- package/lib/services/key-handler-service.d.ts +56 -0
- package/lib/services/key-handler-service.js +184 -0
- package/lib/services/root-instance-service.d.ts +25 -0
- package/lib/services/root-instance-service.js +49 -0
- package/lib/services/settings-service.d.ts +34 -0
- package/lib/services/settings-service.js +154 -0
- package/lib/services/singleton-map-service.d.ts +23 -0
- package/lib/services/singleton-map-service.js +44 -0
- package/lib/services/submit-hook-service.d.ts +24 -0
- package/lib/services/submit-hook-service.js +73 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +4 -0
- package/lib/themes/bs3.d.ts +3 -0
- package/lib/themes/bs3.js +133 -0
- package/lib/themes/bs5.d.ts +3 -0
- package/lib/themes/bs5.js +111 -0
- package/lib/themes/glyphicon-fa-mapping.d.ts +3 -0
- package/lib/themes/glyphicon-fa-mapping.js +271 -0
- package/lib/themes/stub.d.ts +3 -0
- package/lib/themes/stub.js +82 -0
- package/lib/themes/theme.d.ts +233 -0
- package/lib/themes/theme.js +2 -0
- package/lib/translations.json +847 -0
- package/lib/utils.d.ts +167 -0
- package/lib/utils.js +1185 -0
- package/lib/validation.d.ts +7 -0
- package/lib/validation.js +141 -0
- package/package.json +2 -2
- package/patches/protractor++webdriver-manager+12.1.8.patch +0 -20395
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
let AutoArrayField = class AutoArrayField extends React.Component {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.onChange = (formData) => {
|
|
17
|
+
const emptyItem = utils_1.getDefaultFormState(this.props.schema.items);
|
|
18
|
+
if (formData && formData.length !== 0 && this.props.formContext.utils.formDataEquals(formData[formData.length - 1], emptyItem, this.props.idSchema.$id)) {
|
|
19
|
+
formData = formData.slice(0, formData.length - 1);
|
|
20
|
+
}
|
|
21
|
+
this.props.onChange(formData);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getName() { return "AutoArrayField"; }
|
|
25
|
+
getStateFromProps(props) {
|
|
26
|
+
const { formData = [], schema, uiSchema, formContext: { utils } } = props;
|
|
27
|
+
const state = { formData, onChange: this.onChange };
|
|
28
|
+
const newEmptyItem = utils_1.getDefaultFormState(schema.items);
|
|
29
|
+
const emptyItem = this.emptyItem
|
|
30
|
+
&& utils.formDataEquals(newEmptyItem, this.emptyItem, props.idSchema.$id)
|
|
31
|
+
&& formData.every(item => utils_1.getUUID(item) !== utils_1.getUUID(this.emptyItem))
|
|
32
|
+
? this.emptyItem
|
|
33
|
+
: utils_1.assignUUID(newEmptyItem);
|
|
34
|
+
this.emptyItem = emptyItem;
|
|
35
|
+
if (formData && (formData.length === 0 || !utils.formDataEquals(formData[formData.length - 1], emptyItem, props.idSchema.$id))) {
|
|
36
|
+
state.formData = [...formData, emptyItem];
|
|
37
|
+
}
|
|
38
|
+
state.uiSchema = Object.assign(Object.assign({}, uiSchema), { "ui:options": Object.assign(Object.assign({ canAdd: false }, (uiSchema["ui:options"] || {})), { nonOrderables: [state.formData.length - 1], nonRemovables: [state.formData.length - 1] }) });
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
AutoArrayField.propTypes = {
|
|
43
|
+
uiSchema: PropTypes.shape({
|
|
44
|
+
"ui:options": PropTypes.shape({
|
|
45
|
+
autofocus: PropTypes.boolean
|
|
46
|
+
})
|
|
47
|
+
}),
|
|
48
|
+
schema: PropTypes.shape({
|
|
49
|
+
type: PropTypes.oneOf(["array"])
|
|
50
|
+
}).isRequired,
|
|
51
|
+
formData: PropTypes.array
|
|
52
|
+
};
|
|
53
|
+
AutoArrayField = __decorate([
|
|
54
|
+
VirtualSchemaField_1.default
|
|
55
|
+
], AutoArrayField);
|
|
56
|
+
exports.default = AutoArrayField;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uses AutosuggestWidget to apply autosuggested values to multiple object's fields. Options are passed to AutosuggestWidget.
|
|
3
|
+
*
|
|
4
|
+
* uischema = {"ui:options": {
|
|
5
|
+
* autosuggestField: <string> (field name which is used for api call. The suggestions renderer method is also defined by autosuggestField)
|
|
6
|
+
* suggestionInputField: <fieldName> (the field which is rendered as the autosuggest input)
|
|
7
|
+
* suggestionValueField: <fieldName> (the field which the value for autosuggest is pulled from)
|
|
8
|
+
* suggestionReceivers: {
|
|
9
|
+
* <fieldName>: <suggestion path>, (when an autosuggestion is selected, these fields receive the autosuggestions value defined by suggestion path.
|
|
10
|
+
* <fieldName2>: <suggestion path 2>, Example: autosuggestion = {key: "MLV.2", value: "kalalokki", payload: {informalGroups: ["linnut"]}}
|
|
11
|
+
* } suggestionReceivers: {someFieldName: "key", someFieldName2: "/payload/informalgroups/0"}
|
|
12
|
+
* If fieldName start with '$', then a function from autosuggestFieldSettings parses the suggestion. Example: $taxonGroup
|
|
13
|
+
* If fieldName start with '/', it is handled as a JSON pointer.
|
|
14
|
+
* uiSchema: <uiSchema> (uiSchema which is passed to inner SchemaField)
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
export default class AutosuggestField extends React.Component<any, any, any> {
|
|
18
|
+
static propTypes: {
|
|
19
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
20
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
21
|
+
autosuggestField: PropTypes.Validator<string>;
|
|
22
|
+
suggestionInputField: PropTypes.Validator<string>;
|
|
23
|
+
allowNonsuggestedValue: any;
|
|
24
|
+
suggestionReceivers: PropTypes.Validator<object>;
|
|
25
|
+
inputTransformer: PropTypes.Requireable<PropTypes.InferProps<{
|
|
26
|
+
regexp: PropTypes.Validator<string>;
|
|
27
|
+
transformations: PropTypes.Validator<object>;
|
|
28
|
+
}>>;
|
|
29
|
+
informalTaxonGroups: PropTypes.Requireable<string>;
|
|
30
|
+
informalTaxonGroupPersistenceKey: PropTypes.Requireable<string>;
|
|
31
|
+
}>>;
|
|
32
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
33
|
+
}>>;
|
|
34
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
35
|
+
type: PropTypes.Requireable<string>;
|
|
36
|
+
}>>;
|
|
37
|
+
formData: PropTypes.Validator<object>;
|
|
38
|
+
};
|
|
39
|
+
static getName(): string;
|
|
40
|
+
constructor(props: any);
|
|
41
|
+
onNextTick: (() => any) | undefined;
|
|
42
|
+
getTogglePersistenceContextKey: (props: any) => string;
|
|
43
|
+
getInformalTaxonGroupsPersistenceContextKey: (props: any) => string;
|
|
44
|
+
getStateFromProps: (props: any, toggled: any) => {
|
|
45
|
+
schema: any;
|
|
46
|
+
uiSchema: any;
|
|
47
|
+
toggled: any;
|
|
48
|
+
taxonGroupID: any;
|
|
49
|
+
};
|
|
50
|
+
getActiveOptions: (options: any, toggled: any) => any;
|
|
51
|
+
getSuggestionReceiverValue(suggestion: any, suggestionReceiver: any): any;
|
|
52
|
+
getSuggestionValue: (suggestion: any, def: any) => any;
|
|
53
|
+
onSuggestionSelected: (suggestion: any, mounted: any) => void;
|
|
54
|
+
onConfirmUnsuggested: (value: any) => void;
|
|
55
|
+
onInputChange: ({ target: { value } }: {
|
|
56
|
+
target: {
|
|
57
|
+
value: any;
|
|
58
|
+
};
|
|
59
|
+
}) => any;
|
|
60
|
+
isValueSuggested: () => boolean;
|
|
61
|
+
getSuggestionFromValue: () => Promise<{
|
|
62
|
+
value: any;
|
|
63
|
+
key: any;
|
|
64
|
+
}>;
|
|
65
|
+
onInformalTaxonGroupSelected: (informalTaxonID: any) => void;
|
|
66
|
+
onToggleChange: (value: any) => void;
|
|
67
|
+
}
|
|
68
|
+
import * as React from "react";
|
|
69
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const PropTypes = require("prop-types");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const Context_1 = require("../../Context");
|
|
7
|
+
const merge = require("deepmerge");
|
|
8
|
+
const suggestionParsers = {
|
|
9
|
+
taxonGroup: suggestion => {
|
|
10
|
+
return suggestion.payload ? suggestion.payload.informalTaxonGroups.map(item => typeof item === "string" ? item : item.id) : [];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const parseQuery = (query, props, taxonGroups) => {
|
|
14
|
+
return Object.keys(query).reduce((_query, key) => {
|
|
15
|
+
if (typeof query[key] === "object") {
|
|
16
|
+
const { parser, field } = query[key];
|
|
17
|
+
const { formData = {} } = props;
|
|
18
|
+
if (parser === "arrayJoin") {
|
|
19
|
+
_query[key] = ((key === "informalTaxonGroup" ? taxonGroups : formData[field]) || []).join(",");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
_query[key] = query[key];
|
|
24
|
+
}
|
|
25
|
+
return _query;
|
|
26
|
+
}, {});
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Uses AutosuggestWidget to apply autosuggested values to multiple object's fields. Options are passed to AutosuggestWidget.
|
|
30
|
+
*
|
|
31
|
+
* uischema = {"ui:options": {
|
|
32
|
+
* autosuggestField: <string> (field name which is used for api call. The suggestions renderer method is also defined by autosuggestField)
|
|
33
|
+
* suggestionInputField: <fieldName> (the field which is rendered as the autosuggest input)
|
|
34
|
+
* suggestionValueField: <fieldName> (the field which the value for autosuggest is pulled from)
|
|
35
|
+
* suggestionReceivers: {
|
|
36
|
+
* <fieldName>: <suggestion path>, (when an autosuggestion is selected, these fields receive the autosuggestions value defined by suggestion path.
|
|
37
|
+
* <fieldName2>: <suggestion path 2>, Example: autosuggestion = {key: "MLV.2", value: "kalalokki", payload: {informalGroups: ["linnut"]}}
|
|
38
|
+
* } suggestionReceivers: {someFieldName: "key", someFieldName2: "/payload/informalgroups/0"}
|
|
39
|
+
* If fieldName start with '$', then a function from autosuggestFieldSettings parses the suggestion. Example: $taxonGroup
|
|
40
|
+
* If fieldName start with '/', it is handled as a JSON pointer.
|
|
41
|
+
* uiSchema: <uiSchema> (uiSchema which is passed to inner SchemaField)
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
class AutosuggestField extends React.Component {
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.UNSAFE_componentWillReceiveProps = (props) => {
|
|
48
|
+
this.setState(this.getStateFromProps(props));
|
|
49
|
+
if (this.onNextTick) {
|
|
50
|
+
this.onNextTick();
|
|
51
|
+
this.onNextTick = undefined;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
this.getTogglePersistenceContextKey = (props) => `AUTOSUGGEST_FIELD_TOGGLE_PERSISTENCE_${props.uiSchema["ui:options"].togglePersistenceKey}`;
|
|
55
|
+
this.getInformalTaxonGroupsPersistenceContextKey = (props) => `AUTOSUGGEST_FIELD_PERSISTENCE_${props.uiSchema["ui:options"].informalTaxonGroupPersistenceKey}`;
|
|
56
|
+
this.getStateFromProps = (props, toggled) => {
|
|
57
|
+
let { schema, uiSchema, formData } = props;
|
|
58
|
+
const context = Context_1.default(this.props.formContext.contextId);
|
|
59
|
+
const uiOptions = utils_1.getUiOptions(uiSchema);
|
|
60
|
+
const { informalTaxonGroups = "informalTaxonGroups", informalTaxonGroupPersistenceKey, togglePersistenceKey, suggestionInputField, suggestionReceivers } = uiOptions;
|
|
61
|
+
if (togglePersistenceKey) {
|
|
62
|
+
toggled = context[this.getTogglePersistenceContextKey(props)];
|
|
63
|
+
}
|
|
64
|
+
const { toggleable } = uiOptions;
|
|
65
|
+
toggled = (toggled !== undefined)
|
|
66
|
+
? toggled
|
|
67
|
+
: this.state
|
|
68
|
+
? this.state.toggled
|
|
69
|
+
: togglePersistenceKey
|
|
70
|
+
? context[this.getTogglePersistenceContextKey(props)] !== undefined
|
|
71
|
+
? context[this.getTogglePersistenceContextKey(props)]
|
|
72
|
+
: (toggleable && toggleable.toggled || false)
|
|
73
|
+
: false;
|
|
74
|
+
const taxonGroupID = !informalTaxonGroups
|
|
75
|
+
? undefined
|
|
76
|
+
: informalTaxonGroupPersistenceKey !== undefined
|
|
77
|
+
? context[this.getInformalTaxonGroupsPersistenceContextKey(props)]
|
|
78
|
+
: formData[informalTaxonGroups]
|
|
79
|
+
? formData[informalTaxonGroups][0]
|
|
80
|
+
: undefined;
|
|
81
|
+
let options = Object.assign(Object.assign({}, uiOptions), { onSuggestionSelected: this.onSuggestionSelected, onUnsuggestedSelected: this.onUnsuggestedSelected, inputProps: {
|
|
82
|
+
onChange: this.onInputChange
|
|
83
|
+
}, isValueSuggested: this.isValueSuggested, getSuggestionFromValue: this.getSuggestionFromValue, onInformalTaxonGroupSelected: informalTaxonGroups ? this.onInformalTaxonGroupSelected : undefined, getSuggestionValue: this.getSuggestionValue, informalTaxonGroupsValue: props.formData[informalTaxonGroups], taxonGroupID, placeholder: toggled
|
|
84
|
+
? typeof toggleable.placeholder === "string"
|
|
85
|
+
? toggleable.placeholder
|
|
86
|
+
: this.props.formContext.translations.UnitAutosuggestFieldTogglePlaceholder
|
|
87
|
+
: uiOptions["ui:placeholder"], controlledValue: suggestionReceivers
|
|
88
|
+
&& suggestionReceivers[suggestionInputField]
|
|
89
|
+
&& suggestionReceivers[suggestionInputField] !== "key" });
|
|
90
|
+
if (toggleable) {
|
|
91
|
+
options.toggled = toggled;
|
|
92
|
+
options.onToggle = this.onToggleChange;
|
|
93
|
+
options = this.getActiveOptions(options, toggled);
|
|
94
|
+
}
|
|
95
|
+
if (suggestionInputField && props.formData && !utils_1.isEmptyString(utils_1.parseJSONPointer(props.formData, suggestionInputField, !!"safe"))) {
|
|
96
|
+
options.value = utils_1.parseJSONPointer(props.formData, suggestionInputField);
|
|
97
|
+
}
|
|
98
|
+
if (options.query) {
|
|
99
|
+
options.query = parseQuery(options.query, props, [options.taxonGroupID]);
|
|
100
|
+
}
|
|
101
|
+
const innerUiSchema = utils_1.getInnerUiSchema(uiSchema);
|
|
102
|
+
const _uiSchemaJSONPointer = utils_1.uiSchemaJSONPointer(schema, suggestionInputField);
|
|
103
|
+
const suggestionInputFieldExistingUiSchema = utils_1.parseJSONPointer(innerUiSchema, _uiSchemaJSONPointer);
|
|
104
|
+
let widgetProps = suggestionInputFieldExistingUiSchema || {};
|
|
105
|
+
if (options.chooseImages && props.formContext.uiSchemaContext.isEdit && options.value) {
|
|
106
|
+
widgetProps = Object.assign(Object.assign({}, widgetProps), { "ui:title": utils_1.capitalizeFirstLetter(options.orWriteSpeciesNameLabel || props.formContext.translations.orWriteSpeciesName) });
|
|
107
|
+
}
|
|
108
|
+
let _uiSchema = utils_1.updateSafelyWithJSONPointer(innerUiSchema, Object.assign(Object.assign({ "ui:widget": "AutosuggestWidget" }, widgetProps), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions((suggestionInputFieldExistingUiSchema || {})[suggestionInputField])), options) }), _uiSchemaJSONPointer);
|
|
109
|
+
return { schema, uiSchema: _uiSchema, toggled, taxonGroupID };
|
|
110
|
+
};
|
|
111
|
+
this.getActiveOptions = (options, toggled) => {
|
|
112
|
+
toggled = (toggled !== undefined) ? toggled : (this.state || {}).toggled;
|
|
113
|
+
return toggled ? merge(options, options.toggleable) : options;
|
|
114
|
+
};
|
|
115
|
+
this.getSuggestionValue = (suggestion, def) => {
|
|
116
|
+
const { suggestionValueParse } = this.getActiveOptions(utils_1.getUiOptions(this.props.uiSchema));
|
|
117
|
+
return suggestionValueParse
|
|
118
|
+
? this.getSuggestionReceiverValue(suggestion, suggestionValueParse)
|
|
119
|
+
: def;
|
|
120
|
+
};
|
|
121
|
+
this.onSuggestionSelected = (suggestion, mounted) => {
|
|
122
|
+
if (suggestion === null)
|
|
123
|
+
suggestion = undefined;
|
|
124
|
+
let { formData, uiSchema, formContext } = this.props;
|
|
125
|
+
const { suggestionReceivers, autosuggestField, suggestionValueField, autocopy, suggestionInputField } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
126
|
+
const handleSuggestionReceivers = (formData, suggestion) => {
|
|
127
|
+
for (let fieldName in suggestionReceivers) {
|
|
128
|
+
const fieldVal = this.getSuggestionReceiverValue(suggestion, suggestionReceivers[fieldName]);
|
|
129
|
+
formData = utils_1.updateFormDataWithJSONPointer(Object.assign(Object.assign({}, this.props), { formData }), fieldVal, fieldName);
|
|
130
|
+
}
|
|
131
|
+
return formData;
|
|
132
|
+
};
|
|
133
|
+
if (autosuggestField === "unit") {
|
|
134
|
+
let { unit } = suggestion.payload;
|
|
135
|
+
if (unit.unitType) {
|
|
136
|
+
unit.informalTaxonGroups = unit.unitType;
|
|
137
|
+
delete unit.unitType;
|
|
138
|
+
}
|
|
139
|
+
unit = (mounted && formContext.formDataTransformers || []).reduce((unit, { "ui:field": uiField, props: fieldProps }) => {
|
|
140
|
+
const { state = {} } = new fieldProps.registry.fields[uiField](Object.assign(Object.assign({}, fieldProps), { formData: unit }));
|
|
141
|
+
return state.formData;
|
|
142
|
+
}, unit);
|
|
143
|
+
formData = handleSuggestionReceivers(formData, {});
|
|
144
|
+
formData = Object.assign(Object.assign({}, utils_1.updateFormDataWithJSONPointer(Object.assign(Object.assign({}, this.props), { formData }), undefined, suggestionValueField)), unit);
|
|
145
|
+
if (utils_1.isEmptyString(utils_1.parseJSONPointer(this.props.formData, suggestionInputField, !!"safe")) && autocopy && !this.props.formContext.utils.formDataEquals(this.props.formData, formData, this.props.idSchema.$id)) {
|
|
146
|
+
this.onNextTick = () => this.props.formContext.services.customEvents.send(this.props.idSchema.$id, "copy", autocopy);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
formData = handleSuggestionReceivers(formData, suggestion);
|
|
151
|
+
}
|
|
152
|
+
if (mounted) {
|
|
153
|
+
this.props.onChange(formData);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (formContext.formDataTransformers) {
|
|
157
|
+
formData = formContext.formDataTransformers.reduce((unit, { "ui:field": uiField, props: fieldProps }) => {
|
|
158
|
+
let changed;
|
|
159
|
+
const getChanged = (_changed) => {
|
|
160
|
+
changed = _changed;
|
|
161
|
+
};
|
|
162
|
+
const field = new fieldProps.registry.fields[uiField](Object.assign(Object.assign({}, fieldProps), { formData: formData, onChange: getChanged }));
|
|
163
|
+
field.onChange(field.state && field.state.formData ? field.state.formData : formData);
|
|
164
|
+
return changed;
|
|
165
|
+
}, formData);
|
|
166
|
+
}
|
|
167
|
+
const lajiFormInstance = formContext.services.rootInstance;
|
|
168
|
+
const pointer = this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndFormDataAndIdSchemaId(this.props.idSchema.$id, utils_1.getFieldUUID(this.props));
|
|
169
|
+
const newFormData = Object.assign(Object.assign({}, utils_1.parseJSONPointer(lajiFormInstance.state.formData, pointer)), formData);
|
|
170
|
+
lajiFormInstance.onChange(utils_1.updateSafelyWithJSONPointer(lajiFormInstance.getFormData(), newFormData, pointer));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
this.onConfirmUnsuggested = (value) => {
|
|
174
|
+
let { formData, uiSchema } = this.props;
|
|
175
|
+
const { suggestionReceivers, suggestionInputField } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
176
|
+
Object.keys(suggestionReceivers).forEach(fieldName => {
|
|
177
|
+
const defaultValue = utils_1.getDefaultFormState(utils_1.parseJSONPointer(this.props.schema, utils_1.schemaJSONPointer(this.props.schema, fieldName)));
|
|
178
|
+
formData = utils_1.updateFormDataWithJSONPointer(Object.assign(Object.assign({}, this.props), { formData }), defaultValue, fieldName);
|
|
179
|
+
});
|
|
180
|
+
formData = utils_1.updateFormDataWithJSONPointer(Object.assign(Object.assign({}, this.props), { formData }), value, suggestionInputField);
|
|
181
|
+
this.props.onChange(formData);
|
|
182
|
+
};
|
|
183
|
+
this.onInputChange = ({ target: { value } }) => {
|
|
184
|
+
let { formData, uiSchema } = this.props;
|
|
185
|
+
const { inputTransformer } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
186
|
+
if (inputTransformer) {
|
|
187
|
+
const regexp = new RegExp(inputTransformer.regexp);
|
|
188
|
+
if (value.match(regexp)) {
|
|
189
|
+
if (!formData)
|
|
190
|
+
formData = {};
|
|
191
|
+
let formDataChange = {};
|
|
192
|
+
value = value.replace(regexp, "$1");
|
|
193
|
+
if (inputTransformer.transformations)
|
|
194
|
+
for (let transformField in inputTransformer.transformations) {
|
|
195
|
+
formDataChange[transformField] = inputTransformer.transformations[transformField];
|
|
196
|
+
}
|
|
197
|
+
formData = Object.assign(Object.assign({}, formData), formDataChange);
|
|
198
|
+
this.props.onChange(formData);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
};
|
|
203
|
+
this.isValueSuggested = () => {
|
|
204
|
+
const { formData, uiSchema } = this.props;
|
|
205
|
+
const { suggestionValueField } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
206
|
+
if (suggestionValueField) {
|
|
207
|
+
return !!utils_1.parseJSONPointer(formData, suggestionValueField, !!"safe");
|
|
208
|
+
}
|
|
209
|
+
for (let fieldName in this.getActiveOptions(utils_1.getUiOptions(uiSchema)).suggestionReceivers) {
|
|
210
|
+
if (!formData || !utils_1.parseJSONPointer(formData, fieldName, !!"safe")) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
};
|
|
216
|
+
this.getSuggestionFromValue = () => {
|
|
217
|
+
const { formData, uiSchema } = this.props;
|
|
218
|
+
const { suggestionValueField, suggestionInputField } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
219
|
+
const suggestionValue = utils_1.parseJSONPointer(formData, suggestionValueField, !!"safe");
|
|
220
|
+
const suggestionInputValue = utils_1.parseJSONPointer(formData, suggestionInputField, !!"safe");
|
|
221
|
+
const value = suggestionInputField && formData && !utils_1.isEmptyString(suggestionValue) ?
|
|
222
|
+
suggestionInputValue : undefined;
|
|
223
|
+
const key = suggestionValueField && formData && !utils_1.isEmptyString(suggestionValue) ?
|
|
224
|
+
suggestionValue : undefined;
|
|
225
|
+
let suggestion = undefined;
|
|
226
|
+
if (value !== undefined && key !== undefined) {
|
|
227
|
+
suggestion = { value, key };
|
|
228
|
+
}
|
|
229
|
+
return suggestion ? Promise.resolve(suggestion) : Promise.reject();
|
|
230
|
+
};
|
|
231
|
+
this.onInformalTaxonGroupSelected = (informalTaxonID) => {
|
|
232
|
+
const { uiSchema } = this.props;
|
|
233
|
+
const { informalTaxonGroups, informalTaxonGroupPersistenceKey } = this.getActiveOptions(utils_1.getUiOptions(uiSchema));
|
|
234
|
+
if (informalTaxonGroupPersistenceKey !== undefined) {
|
|
235
|
+
Context_1.default(this.props.formContext.contextId)[this.getInformalTaxonGroupsPersistenceContextKey(this.props)] = informalTaxonID;
|
|
236
|
+
this.setState(this.getStateFromProps(this.props));
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.props.onChange(Object.assign(Object.assign({}, this.props.formData), { [informalTaxonGroups]: [informalTaxonID] }));
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
this.onToggleChange = (value) => {
|
|
243
|
+
const { togglePersistenceKey } = utils_1.getUiOptions(this.props.uiSchema);
|
|
244
|
+
if (togglePersistenceKey) {
|
|
245
|
+
Context_1.default(this.props.formContext.contextId)[this.getTogglePersistenceContextKey(this.props)] = value;
|
|
246
|
+
}
|
|
247
|
+
this.setState(this.getStateFromProps(this.props, value));
|
|
248
|
+
};
|
|
249
|
+
this.props.formContext.services.settings.bind(this, props);
|
|
250
|
+
this.state = this.getStateFromProps(props);
|
|
251
|
+
}
|
|
252
|
+
static getName() { return "AutosuggestField"; }
|
|
253
|
+
getSuggestionReceiverValue(suggestion, suggestionReceiver) {
|
|
254
|
+
// undefined suggestion clears value.
|
|
255
|
+
let fieldVal = undefined;
|
|
256
|
+
if (typeof suggestion === "object") {
|
|
257
|
+
const suggestionValPath = suggestionReceiver;
|
|
258
|
+
if (suggestionValPath[0] === "$") {
|
|
259
|
+
fieldVal = suggestionParsers[suggestionValPath.substring(1)](suggestion);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const fieldsToTry = suggestionValPath.split("||").map(s => s.trim());
|
|
263
|
+
for (let field of fieldsToTry) {
|
|
264
|
+
fieldVal = utils_1.parseJSONPointer(suggestion, field);
|
|
265
|
+
if (fieldVal !== undefined) {
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return fieldVal;
|
|
272
|
+
}
|
|
273
|
+
render() {
|
|
274
|
+
const { SchemaField } = this.props.registry.fields;
|
|
275
|
+
return React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: this.state.uiSchema }));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.default = AutosuggestField;
|
|
279
|
+
AutosuggestField.propTypes = {
|
|
280
|
+
uiSchema: PropTypes.shape({
|
|
281
|
+
"ui:options": PropTypes.shape({
|
|
282
|
+
autosuggestField: PropTypes.string.isRequired,
|
|
283
|
+
suggestionInputField: PropTypes.string.isRequired,
|
|
284
|
+
allowNonsuggestedValue: PropTypes.boolean,
|
|
285
|
+
suggestionReceivers: PropTypes.object.isRequired,
|
|
286
|
+
inputTransformer: PropTypes.shape({
|
|
287
|
+
regexp: PropTypes.string.isRequired,
|
|
288
|
+
transformations: PropTypes.object.isRequired
|
|
289
|
+
}),
|
|
290
|
+
informalTaxonGroups: PropTypes.string,
|
|
291
|
+
informalTaxonGroupPersistenceKey: PropTypes.string
|
|
292
|
+
}).isRequired,
|
|
293
|
+
uiSchema: PropTypes.object
|
|
294
|
+
}).isRequired,
|
|
295
|
+
schema: PropTypes.shape({
|
|
296
|
+
type: PropTypes.oneOf(["object"])
|
|
297
|
+
}).isRequired,
|
|
298
|
+
formData: PropTypes.object.isRequired
|
|
299
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default class CombinedValueDisplayField extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
5
|
+
combined: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
firstField: PropTypes.Validator<string>;
|
|
7
|
+
secondField: PropTypes.Validator<string>;
|
|
8
|
+
name: PropTypes.Requireable<string>;
|
|
9
|
+
title: PropTypes.Requireable<string>;
|
|
10
|
+
combineType: PropTypes.Requireable<string>;
|
|
11
|
+
delimiter: PropTypes.Requireable<string>;
|
|
12
|
+
}> | (PropTypes.InferProps<{
|
|
13
|
+
firstField: PropTypes.Validator<string>;
|
|
14
|
+
secondField: PropTypes.Validator<string>;
|
|
15
|
+
name: PropTypes.Requireable<string>;
|
|
16
|
+
title: PropTypes.Requireable<string>;
|
|
17
|
+
combineType: PropTypes.Requireable<string>;
|
|
18
|
+
delimiter: PropTypes.Requireable<string>;
|
|
19
|
+
}> | null | undefined)[]>;
|
|
20
|
+
}>>;
|
|
21
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
22
|
+
}>>;
|
|
23
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
24
|
+
type: PropTypes.Requireable<string>;
|
|
25
|
+
}>>;
|
|
26
|
+
formData: PropTypes.Validator<object>;
|
|
27
|
+
};
|
|
28
|
+
static getName(): string;
|
|
29
|
+
constructor(props: any);
|
|
30
|
+
constructor(props: any, context: any);
|
|
31
|
+
getStateFromProps(props: any): {
|
|
32
|
+
schema: any;
|
|
33
|
+
idSchema: any;
|
|
34
|
+
formData: any;
|
|
35
|
+
onChange: (formData: any) => void;
|
|
36
|
+
};
|
|
37
|
+
toMinutes: (time: any) => number;
|
|
38
|
+
onChange: (formData: any) => void;
|
|
39
|
+
}
|
|
40
|
+
import * as React from "react";
|
|
41
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
13
|
+
/**
|
|
14
|
+
* Combines values of two fields into one value which can be used for displaying (editing that value doesn't change formData)
|
|
15
|
+
* Combine types:
|
|
16
|
+
* timeDifference: combines the values by calculating their time difference
|
|
17
|
+
* stringJoin (default): combines the values by joining them. delimiter is added between if given
|
|
18
|
+
*/
|
|
19
|
+
const combinedPropType = PropTypes.shape({
|
|
20
|
+
firstField: PropTypes.string.isRequired,
|
|
21
|
+
secondField: PropTypes.string.isRequired,
|
|
22
|
+
name: PropTypes.string,
|
|
23
|
+
title: PropTypes.string,
|
|
24
|
+
combineType: PropTypes.string,
|
|
25
|
+
delimiter: PropTypes.string
|
|
26
|
+
});
|
|
27
|
+
let CombinedValueDisplayField = class CombinedValueDisplayField extends React.Component {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.toMinutes = (time) => {
|
|
31
|
+
const parts = time.split(":");
|
|
32
|
+
return Number(parts[0]) * 60 + Number(parts[1]);
|
|
33
|
+
};
|
|
34
|
+
this.onChange = (formData) => {
|
|
35
|
+
const uiOptions = this.getUiOptions();
|
|
36
|
+
const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
|
|
37
|
+
const combinedFields = combined.map(options => {
|
|
38
|
+
return options.name || "";
|
|
39
|
+
}, []);
|
|
40
|
+
combinedFields.forEach(field => {
|
|
41
|
+
formData = utils_1.immutableDelete(formData, field);
|
|
42
|
+
});
|
|
43
|
+
this.props.onChange(formData);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
static getName() { return "CombinedValueDisplayField"; }
|
|
47
|
+
getStateFromProps(props) {
|
|
48
|
+
const uiOptions = this.getUiOptions();
|
|
49
|
+
let { schema, idSchema, formData } = props;
|
|
50
|
+
const combined = Array.isArray(uiOptions.combined) ? uiOptions.combined : [uiOptions.combined];
|
|
51
|
+
combined.forEach(options => {
|
|
52
|
+
const { name, title, combineType, firstField, secondField } = options;
|
|
53
|
+
schema = Object.assign(Object.assign({}, schema), { properties: Object.assign(Object.assign({}, schema.properties), { [name || ""]: { title: title || "", type: "string" } }) });
|
|
54
|
+
idSchema = this.props.registry.schemaUtils.toIdSchema(schema, idSchema.$id);
|
|
55
|
+
let value = undefined;
|
|
56
|
+
const firstValue = firstField[0] === "/" ? utils_1.parseJSONPointer(formData, firstField, !!"safely") : formData[firstField];
|
|
57
|
+
const secondValue = secondField[0] === "/" ? utils_1.parseJSONPointer(formData, secondField, !!"safely") : formData[secondField];
|
|
58
|
+
if (combineType === "timeDifference") {
|
|
59
|
+
if (firstValue && secondValue) {
|
|
60
|
+
const difference = this.toMinutes(secondValue) - this.toMinutes(formData[firstField]);
|
|
61
|
+
if (difference >= 0) {
|
|
62
|
+
const hours = Math.floor(difference / 60);
|
|
63
|
+
const minutes = difference % 60;
|
|
64
|
+
value = hours + " h " + minutes + " min";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const delimiter = options.delimiter || "";
|
|
70
|
+
value = [];
|
|
71
|
+
if (firstValue)
|
|
72
|
+
value.push(firstValue);
|
|
73
|
+
if (secondValue)
|
|
74
|
+
value.push(secondValue);
|
|
75
|
+
value = value.join(delimiter);
|
|
76
|
+
}
|
|
77
|
+
formData = Object.assign(Object.assign({}, formData), { [name]: value });
|
|
78
|
+
});
|
|
79
|
+
return { schema, idSchema, formData, onChange: this.onChange };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
CombinedValueDisplayField.propTypes = {
|
|
83
|
+
uiSchema: PropTypes.shape({
|
|
84
|
+
"ui:options": PropTypes.shape({
|
|
85
|
+
combined: PropTypes.oneOfType([
|
|
86
|
+
combinedPropType,
|
|
87
|
+
PropTypes.arrayOf(combinedPropType)
|
|
88
|
+
])
|
|
89
|
+
}),
|
|
90
|
+
uiSchema: PropTypes.object
|
|
91
|
+
}).isRequired,
|
|
92
|
+
schema: PropTypes.shape({
|
|
93
|
+
type: PropTypes.oneOf(["object"])
|
|
94
|
+
}).isRequired,
|
|
95
|
+
formData: PropTypes.object.isRequired
|
|
96
|
+
};
|
|
97
|
+
CombinedValueDisplayField = __decorate([
|
|
98
|
+
VirtualSchemaField_1.default
|
|
99
|
+
], CombinedValueDisplayField);
|
|
100
|
+
exports.default = CombinedValueDisplayField;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changes formData on onChange event according to conditional rules.
|
|
3
|
+
* uiSchema = {
|
|
4
|
+
* "ui:options": {
|
|
5
|
+
* rules: { // Can also be an array of rules
|
|
6
|
+
* transformations: {
|
|
7
|
+
* <field name to change if conditions met>: <new value>
|
|
8
|
+
* },
|
|
9
|
+
* conditions: {
|
|
10
|
+
* <conditional field name>: { // Note that regexp and length must both pass for this rule to pass.
|
|
11
|
+
* regexp: <string> <if the conditional field value matches this regexp, this condition will pass>
|
|
12
|
+
* length: <number> <if the conditional field value length is equal or more, this conndition will pass>
|
|
13
|
+
* reverse: <boolean> <Reverses the passing value>
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export default class ConditionalOnChangeField extends React.Component<any, any, any> {
|
|
21
|
+
static propTypes: {
|
|
22
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
23
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
24
|
+
rules: PropTypes.Validator<PropTypes.InferProps<PropTypes.ValidationMap<any>> | PropTypes.InferProps<PropTypes.ValidationMap<any>>[]>;
|
|
25
|
+
}>>;
|
|
26
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
27
|
+
}>>;
|
|
28
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
29
|
+
type: PropTypes.Requireable<string>;
|
|
30
|
+
}>>;
|
|
31
|
+
formData: PropTypes.Validator<object>;
|
|
32
|
+
};
|
|
33
|
+
static getName(): string;
|
|
34
|
+
constructor(props: any);
|
|
35
|
+
constructor(props: any, context: any);
|
|
36
|
+
getStateFromProps(): {
|
|
37
|
+
onChange: (formData: any) => void;
|
|
38
|
+
};
|
|
39
|
+
onChange: (formData: any) => void;
|
|
40
|
+
}
|
|
41
|
+
import * as React from "react";
|
|
42
|
+
import * as PropTypes from "prop-types";
|