@luomus/laji-form 15.1.0 → 15.1.2
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/CHANGELOG.md +0 -4
- package/dist/laji-form.js +1 -1
- package/jsonconfig.json +26 -0
- package/migrate.sh +0 -1
- package/package.json +8 -8
- package/test-export/test-utils.d.ts +100 -54
- package/test-export/test-utils.js +102 -84
- package/xsel -b +9 -0
- package/cypress/fixtures/example.json +0 -5
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and closes suggestion list (failed).png +0 -0
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and is marked as suggested (failed).png +0 -0
- package/lib/ApiClient.d.ts +0 -46
- package/lib/ApiClient.js +0 -93
- package/lib/Context.d.ts +0 -8
- package/lib/Context.js +0 -18
- package/lib/ReactContext.d.ts +0 -7
- package/lib/ReactContext.js +0 -5
- package/lib/components/BaseComponent.d.ts +0 -9
- package/lib/components/BaseComponent.js +0 -29
- package/lib/components/LajiForm.d.ts +0 -221
- package/lib/components/LajiForm.js +0 -615
- package/lib/components/VirtualSchemaField.d.ts +0 -42
- package/lib/components/VirtualSchemaField.js +0 -74
- package/lib/components/components.d.ts +0 -119
- package/lib/components/components.js +0 -606
- package/lib/components/fields/AnnotationField.d.ts +0 -34
- package/lib/components/fields/AnnotationField.js +0 -242
- package/lib/components/fields/AnyToBooleanField.d.ts +0 -18
- package/lib/components/fields/AnyToBooleanField.js +0 -20
- package/lib/components/fields/ArrayBulkField.d.ts +0 -23
- package/lib/components/fields/ArrayBulkField.js +0 -82
- package/lib/components/fields/ArrayCombinerField.d.ts +0 -36
- package/lib/components/fields/ArrayCombinerField.js +0 -138
- package/lib/components/fields/ArrayField.d.ts +0 -39
- package/lib/components/fields/ArrayField.js +0 -148
- package/lib/components/fields/AudioArrayField.d.ts +0 -22
- package/lib/components/fields/AudioArrayField.js +0 -100
- package/lib/components/fields/AutoArrayField.d.ts +0 -24
- package/lib/components/fields/AutoArrayField.js +0 -56
- package/lib/components/fields/AutosuggestField.d.ts +0 -69
- package/lib/components/fields/AutosuggestField.js +0 -299
- package/lib/components/fields/CombinedValueDisplayField.d.ts +0 -41
- package/lib/components/fields/CombinedValueDisplayField.js +0 -100
- package/lib/components/fields/ConditionalOnChangeField.d.ts +0 -42
- package/lib/components/fields/ConditionalOnChangeField.js +0 -107
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +0 -123
- package/lib/components/fields/ConditionalUiSchemaField.js +0 -143
- package/lib/components/fields/ContextInjectionField.d.ts +0 -24
- package/lib/components/fields/ContextInjectionField.js +0 -68
- package/lib/components/fields/DataLeakerField.d.ts +0 -40
- package/lib/components/fields/DataLeakerField.js +0 -68
- package/lib/components/fields/DefaultValueArrayField.d.ts +0 -34
- package/lib/components/fields/DefaultValueArrayField.js +0 -59
- package/lib/components/fields/DependentBooleanField.d.ts +0 -38
- package/lib/components/fields/DependentBooleanField.js +0 -87
- package/lib/components/fields/DependentDisableField.d.ts +0 -35
- package/lib/components/fields/DependentDisableField.js +0 -71
- package/lib/components/fields/EnumRangeArrayField.d.ts +0 -27
- package/lib/components/fields/EnumRangeArrayField.js +0 -115
- package/lib/components/fields/ExtraLabelRowField.d.ts +0 -38
- package/lib/components/fields/ExtraLabelRowField.js +0 -100
- package/lib/components/fields/FakePropertyField.d.ts +0 -18
- package/lib/components/fields/FakePropertyField.js +0 -48
- package/lib/components/fields/FilterArrayField.d.ts +0 -73
- package/lib/components/fields/FilterArrayField.js +0 -121
- package/lib/components/fields/FlatField.d.ts +0 -29
- package/lib/components/fields/FlatField.js +0 -171
- package/lib/components/fields/GeocoderField.d.ts +0 -47
- package/lib/components/fields/GeocoderField.js +0 -372
- package/lib/components/fields/GridLayoutField.d.ts +0 -18
- package/lib/components/fields/GridLayoutField.js +0 -32
- package/lib/components/fields/HiddenField.d.ts +0 -10
- package/lib/components/fields/HiddenField.js +0 -11
- package/lib/components/fields/ImageArrayField.d.ts +0 -172
- package/lib/components/fields/ImageArrayField.js +0 -697
- package/lib/components/fields/ImageDisplayField.d.ts +0 -18
- package/lib/components/fields/ImageDisplayField.js +0 -44
- package/lib/components/fields/InitiallyHiddenField.d.ts +0 -21
- package/lib/components/fields/InitiallyHiddenField.js +0 -58
- package/lib/components/fields/InjectDefaultValueField.d.ts +0 -37
- package/lib/components/fields/InjectDefaultValueField.js +0 -68
- package/lib/components/fields/InjectField.d.ts +0 -46
- package/lib/components/fields/InjectField.js +0 -88
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +0 -25
- package/lib/components/fields/InputWithDefaultValueButtonField.js +0 -61
- package/lib/components/fields/LocalityField.d.ts +0 -22
- package/lib/components/fields/LocalityField.js +0 -94
- package/lib/components/fields/LocationChooserField.d.ts +0 -27
- package/lib/components/fields/LocationChooserField.js +0 -440
- package/lib/components/fields/MapArrayField.d.ts +0 -78
- package/lib/components/fields/MapArrayField.js +0 -1783
- package/lib/components/fields/MapField.d.ts +0 -48
- package/lib/components/fields/MapField.js +0 -434
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +0 -25
- package/lib/components/fields/MultiAnyToBooleanField.js +0 -100
- package/lib/components/fields/MultiArrayField.d.ts +0 -53
- package/lib/components/fields/MultiArrayField.js +0 -224
- package/lib/components/fields/MultiLanguageField.d.ts +0 -13
- package/lib/components/fields/MultiLanguageField.js +0 -52
- package/lib/components/fields/MultiTagArrayField.d.ts +0 -36
- package/lib/components/fields/MultiTagArrayField.js +0 -142
- package/lib/components/fields/NamedPlaceChooserField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceChooserField.js +0 -380
- package/lib/components/fields/NamedPlaceSaverField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceSaverField.js +0 -237
- package/lib/components/fields/NestField.d.ts +0 -148
- package/lib/components/fields/NestField.js +0 -289
- package/lib/components/fields/ObjectField.d.ts +0 -2
- package/lib/components/fields/ObjectField.js +0 -119
- package/lib/components/fields/PdfArrayField.d.ts +0 -21
- package/lib/components/fields/PdfArrayField.js +0 -40
- package/lib/components/fields/PrefillingArrayField.d.ts +0 -22
- package/lib/components/fields/PrefillingArrayField.js +0 -65
- package/lib/components/fields/SchemaField.d.ts +0 -7
- package/lib/components/fields/SchemaField.js +0 -109
- package/lib/components/fields/ScopeField.d.ts +0 -85
- package/lib/components/fields/ScopeField.js +0 -521
- package/lib/components/fields/SectionArrayField.d.ts +0 -38
- package/lib/components/fields/SectionArrayField.js +0 -618
- package/lib/components/fields/SelectTreeField.d.ts +0 -39
- package/lib/components/fields/SelectTreeField.js +0 -143
- package/lib/components/fields/SingleActiveArrayField.d.ts +0 -49
- package/lib/components/fields/SingleActiveArrayField.js +0 -974
- package/lib/components/fields/SingleItemArrayField.d.ts +0 -15
- package/lib/components/fields/SingleItemArrayField.js +0 -60
- package/lib/components/fields/SortArrayField.d.ts +0 -73
- package/lib/components/fields/SortArrayField.js +0 -351
- package/lib/components/fields/SplitField.d.ts +0 -28
- package/lib/components/fields/SplitField.js +0 -65
- package/lib/components/fields/StringToArrayField.d.ts +0 -24
- package/lib/components/fields/StringToArrayField.js +0 -48
- package/lib/components/fields/SumField.d.ts +0 -35
- package/lib/components/fields/SumField.js +0 -83
- package/lib/components/fields/TableField.d.ts +0 -18
- package/lib/components/fields/TableField.js +0 -136
- package/lib/components/fields/TagArrayField.d.ts +0 -38
- package/lib/components/fields/TagArrayField.js +0 -128
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +0 -26
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +0 -81
- package/lib/components/fields/UiFieldApplierField.d.ts +0 -30
- package/lib/components/fields/UiFieldApplierField.js +0 -106
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +0 -42
- package/lib/components/fields/UiFieldMapperArrayField.js +0 -121
- package/lib/components/fields/UnitCountShorthandField.d.ts +0 -22
- package/lib/components/fields/UnitCountShorthandField.js +0 -149
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +0 -26
- package/lib/components/fields/UnitListShorthandArrayField.js +0 -108
- package/lib/components/fields/UnitShorthandField.d.ts +0 -32
- package/lib/components/fields/UnitShorthandField.js +0 -220
- package/lib/components/templates/ArrayFieldTemplate.d.ts +0 -85
- package/lib/components/templates/ArrayFieldTemplate.js +0 -417
- package/lib/components/templates/BaseInputTemplate.d.ts +0 -11
- package/lib/components/templates/BaseInputTemplate.js +0 -80
- package/lib/components/templates/DescriptionField.d.ts +0 -1
- package/lib/components/templates/DescriptionField.js +0 -37
- package/lib/components/templates/ErrorListTemplate.d.ts +0 -9
- package/lib/components/templates/ErrorListTemplate.js +0 -95
- package/lib/components/templates/FieldTemplate.d.ts +0 -6
- package/lib/components/templates/FieldTemplate.js +0 -112
- package/lib/components/templates/ObjectFieldTemplate.d.ts +0 -7
- package/lib/components/templates/ObjectFieldTemplate.js +0 -66
- package/lib/components/templates/TitleField.d.ts +0 -9
- package/lib/components/templates/TitleField.js +0 -51
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +0 -20
- package/lib/components/widgets/AnyToBooleanWidget.js +0 -49
- package/lib/components/widgets/AutosuggestWidget.d.ts +0 -66
- package/lib/components/widgets/AutosuggestWidget.js +0 -1127
- package/lib/components/widgets/CheckboxWidget.d.ts +0 -37
- package/lib/components/widgets/CheckboxWidget.js +0 -139
- package/lib/components/widgets/DateTimeWidget.d.ts +0 -62
- package/lib/components/widgets/DateTimeWidget.js +0 -251
- package/lib/components/widgets/DateWidget.d.ts +0 -23
- package/lib/components/widgets/DateWidget.js +0 -41
- package/lib/components/widgets/HiddenWidget.d.ts +0 -15
- package/lib/components/widgets/HiddenWidget.js +0 -19
- package/lib/components/widgets/ImageSelectWidget.d.ts +0 -14
- package/lib/components/widgets/ImageSelectWidget.js +0 -57
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +0 -43
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +0 -237
- package/lib/components/widgets/InputGroupWidget.d.ts +0 -21
- package/lib/components/widgets/InputGroupWidget.js +0 -36
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +0 -21
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +0 -47
- package/lib/components/widgets/NumberWidget.d.ts +0 -13
- package/lib/components/widgets/NumberWidget.js +0 -21
- package/lib/components/widgets/PlainTextWidget.d.ts +0 -12
- package/lib/components/widgets/PlainTextWidget.js +0 -24
- package/lib/components/widgets/SelectWidget.d.ts +0 -52
- package/lib/components/widgets/SelectWidget.js +0 -158
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +0 -19
- package/lib/components/widgets/SeparatedDateTimeWidget.js +0 -59
- package/lib/components/widgets/TaxonImageWidget.d.ts +0 -13
- package/lib/components/widgets/TaxonImageWidget.js +0 -30
- package/lib/components/widgets/TextSelectWidget.d.ts +0 -25
- package/lib/components/widgets/TextSelectWidget.js +0 -94
- package/lib/components/widgets/TextareaWidget.d.ts +0 -32
- package/lib/components/widgets/TextareaWidget.js +0 -87
- package/lib/components/widgets/TimeWidget.d.ts +0 -11
- package/lib/components/widgets/TimeWidget.js +0 -19
- package/lib/components/widgets/URLWidget.d.ts +0 -14
- package/lib/components/widgets/URLWidget.js +0 -12
- package/lib/components/widgets/UpperCaseWidget.d.ts +0 -13
- package/lib/components/widgets/UpperCaseWidget.js +0 -21
- package/lib/index.d.ts +0 -20
- package/lib/index.js +0 -50
- package/lib/services/blocker-service.d.ts +0 -11
- package/lib/services/blocker-service.js +0 -55
- package/lib/services/custom-event-service.d.ts +0 -17
- package/lib/services/custom-event-service.js +0 -35
- package/lib/services/dom-id-service.d.ts +0 -8
- package/lib/services/dom-id-service.js +0 -30
- package/lib/services/focus-service.d.ts +0 -13
- package/lib/services/focus-service.js +0 -60
- package/lib/services/id-service.d.ts +0 -22
- package/lib/services/id-service.js +0 -130
- package/lib/services/key-handler-service.d.ts +0 -56
- package/lib/services/key-handler-service.js +0 -184
- package/lib/services/root-instance-service.d.ts +0 -25
- package/lib/services/root-instance-service.js +0 -49
- package/lib/services/settings-service.d.ts +0 -34
- package/lib/services/settings-service.js +0 -154
- package/lib/services/singleton-map-service.d.ts +0 -23
- package/lib/services/singleton-map-service.js +0 -44
- package/lib/services/submit-hook-service.d.ts +0 -24
- package/lib/services/submit-hook-service.js +0 -73
- package/lib/styles.d.ts +0 -1
- package/lib/styles.js +0 -4
- package/lib/themes/bs3.d.ts +0 -3
- package/lib/themes/bs3.js +0 -133
- package/lib/themes/bs5.d.ts +0 -3
- package/lib/themes/bs5.js +0 -111
- package/lib/themes/glyphicon-fa-mapping.d.ts +0 -3
- package/lib/themes/glyphicon-fa-mapping.js +0 -271
- package/lib/themes/stub.d.ts +0 -3
- package/lib/themes/stub.js +0 -82
- package/lib/themes/theme.d.ts +0 -233
- package/lib/themes/theme.js +0 -2
- package/lib/translations.json +0 -847
- package/lib/utils.d.ts +0 -171
- package/lib/utils.js +0 -1191
- package/lib/validation.d.ts +0 -7
- package/lib/validation.js +0 -141
- package/llol +0 -10
- package/llol.pdf +0 -10
- package/playwright-report/index.html +0 -62
- package/q +0 -196
- package/rename.sh +0 -24
- package/trip-report.spec.ts +0 -594
|
@@ -1,299 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
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";
|
|
@@ -1,100 +0,0 @@
|
|
|
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;
|
|
@@ -1,42 +0,0 @@
|
|
|
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";
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
window.PropTypes = PropTypes;
|
|
13
|
-
const conditionPropType = {
|
|
14
|
-
regexp: PropTypes.string,
|
|
15
|
-
length: PropTypes.number,
|
|
16
|
-
reverse: PropTypes.bool,
|
|
17
|
-
};
|
|
18
|
-
const rulePropType = PropTypes.shape({
|
|
19
|
-
transformations: PropTypes.object.isRequired,
|
|
20
|
-
conditions: (props, propName, componentName) => Object.keys(props[propName]).every(prop => PropTypes.checkPropTypes(conditionPropType, props[propName][prop], propName, componentName))
|
|
21
|
-
}).isRequired;
|
|
22
|
-
/**
|
|
23
|
-
* Changes formData on onChange event according to conditional rules.
|
|
24
|
-
* uiSchema = {
|
|
25
|
-
* "ui:options": {
|
|
26
|
-
* rules: { // Can also be an array of rules
|
|
27
|
-
* transformations: {
|
|
28
|
-
* <field name to change if conditions met>: <new value>
|
|
29
|
-
* },
|
|
30
|
-
* conditions: {
|
|
31
|
-
* <conditional field name>: { // Note that regexp and length must both pass for this rule to pass.
|
|
32
|
-
* regexp: <string> <if the conditional field value matches this regexp, this condition will pass>
|
|
33
|
-
* length: <number> <if the conditional field value length is equal or more, this conndition will pass>
|
|
34
|
-
* reverse: <boolean> <Reverses the passing value>
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
*/
|
|
41
|
-
let ConditionalOnChangeField = class ConditionalOnChangeField extends React.Component {
|
|
42
|
-
constructor() {
|
|
43
|
-
super(...arguments);
|
|
44
|
-
this.onChange = (formData) => {
|
|
45
|
-
const { rules } = this.getUiOptions();
|
|
46
|
-
(Array.isArray(rules) ? rules : [rules]).forEach(({ conditions, transformations }) => {
|
|
47
|
-
let passes = true;
|
|
48
|
-
// If transforming field is updated, do nothing
|
|
49
|
-
// (If a transforming field is also a condition field, the field would take the conditional value always when updated).
|
|
50
|
-
if (Object.keys(transformations).some(field => formData && formData[field] && formData[field] !== this.props.formData[field])) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
// If condition fields didn't change, do nothing.
|
|
54
|
-
if (Object.keys(conditions).every(field => formData && formData[field] && formData[field] === this.props.formData[field])) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
for (let field in conditions) {
|
|
58
|
-
const condition = conditions[field];
|
|
59
|
-
const { regexp, length, reverse } = condition;
|
|
60
|
-
if (passes && regexp !== undefined) {
|
|
61
|
-
const regexp = new RegExp(condition.regexp.replace("%default", this.props.schema.properties[field].default));
|
|
62
|
-
const result = `${formData[field]}`.match(regexp);
|
|
63
|
-
passes = reverse ? !result : result;
|
|
64
|
-
}
|
|
65
|
-
if (passes && length !== undefined) {
|
|
66
|
-
const result = (formData[field] || []).length >= length;
|
|
67
|
-
passes = reverse ? !result : result;
|
|
68
|
-
}
|
|
69
|
-
if (!passes)
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
if (passes) {
|
|
73
|
-
let formDataChange = {};
|
|
74
|
-
if (transformations)
|
|
75
|
-
for (let transformField in transformations) {
|
|
76
|
-
formDataChange[transformField] = transformations[transformField];
|
|
77
|
-
}
|
|
78
|
-
formData = Object.assign(Object.assign({}, formData), formDataChange);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
this.props.onChange(formData);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
static getName() { return "ConditionalOnChangeField"; }
|
|
85
|
-
getStateFromProps() {
|
|
86
|
-
return { onChange: this.onChange };
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
ConditionalOnChangeField.propTypes = {
|
|
90
|
-
uiSchema: PropTypes.shape({
|
|
91
|
-
"ui:options": PropTypes.shape({
|
|
92
|
-
rules: PropTypes.oneOfType([
|
|
93
|
-
rulePropType,
|
|
94
|
-
PropTypes.arrayOf(rulePropType)
|
|
95
|
-
]).isRequired
|
|
96
|
-
}).isRequired,
|
|
97
|
-
uiSchema: PropTypes.object
|
|
98
|
-
}).isRequired,
|
|
99
|
-
schema: PropTypes.shape({
|
|
100
|
-
type: PropTypes.oneOf(["object"])
|
|
101
|
-
}).isRequired,
|
|
102
|
-
formData: PropTypes.object.isRequired
|
|
103
|
-
};
|
|
104
|
-
ConditionalOnChangeField = __decorate([
|
|
105
|
-
VirtualSchemaField_1.default
|
|
106
|
-
], ConditionalOnChangeField);
|
|
107
|
-
exports.default = ConditionalOnChangeField;
|