@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,106 @@
|
|
|
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
|
+
const functionPropType = PropTypes.shape({
|
|
14
|
+
"ui:field": PropTypes.string.isRequired,
|
|
15
|
+
"ui:options": PropTypes.object
|
|
16
|
+
});
|
|
17
|
+
let UiFieldApplierField = class UiFieldApplierField extends React.Component {
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
this.getFunctions = () => {
|
|
21
|
+
let { functions } = this.getUiOptions();
|
|
22
|
+
if (!Array.isArray(functions)) {
|
|
23
|
+
functions = [functions];
|
|
24
|
+
}
|
|
25
|
+
return functions;
|
|
26
|
+
};
|
|
27
|
+
this.onChange = (formData) => {
|
|
28
|
+
const { field } = this.getUiOptions();
|
|
29
|
+
this.onChangeFormData = formData;
|
|
30
|
+
this.functions[this.functions.length - 1].fn.onChange(utils_1.parseJSONPointer(formData, field));
|
|
31
|
+
};
|
|
32
|
+
this.functions = [];
|
|
33
|
+
}
|
|
34
|
+
static getName() { return "UiFieldApplierField"; }
|
|
35
|
+
getStateFromProps(props) {
|
|
36
|
+
if (this.functions.length !== this.getFunctions().length) {
|
|
37
|
+
this.functions = this.functions.slice(0, this.getFunctions().length);
|
|
38
|
+
}
|
|
39
|
+
let { field } = this.getUiOptions();
|
|
40
|
+
const state = this.getFunctions().reduce((props, options, idx) => {
|
|
41
|
+
let { "ui:field": uiField, "ui:options": uiOptions } = options;
|
|
42
|
+
const uiSchemaForField = utils_1.parseJSONPointer(props.uiSchema, utils_1.uiSchemaJSONPointer(props.schema, field));
|
|
43
|
+
const propsForField = {
|
|
44
|
+
schema: utils_1.parseJSONPointer(props.schema, utils_1.schemaJSONPointer(props.schema, field)),
|
|
45
|
+
uiSchema: Object.assign(Object.assign({}, uiSchemaForField), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(uiSchemaForField)), uiOptions) }),
|
|
46
|
+
formData: utils_1.parseJSONPointer(props.formData, field, !!"safe"),
|
|
47
|
+
idSchema: utils_1.parseJSONPointer(props.idSchema, field),
|
|
48
|
+
errorSchema: utils_1.parseJSONPointer(props.errorSchema, field, !!"safe") || {},
|
|
49
|
+
registry: props.registry,
|
|
50
|
+
formContext: props.formContext,
|
|
51
|
+
onChange: this.functions[idx] && this.functions[idx].uiField === uiField
|
|
52
|
+
? this.functions[idx].fn.props.onChange
|
|
53
|
+
: (formData) => {
|
|
54
|
+
idx === 0
|
|
55
|
+
? this.combinedOnChange(formData)
|
|
56
|
+
: this.functions[idx - 1].fn.onChange(formData);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
let fn, state;
|
|
60
|
+
if (this.functions[idx] && this.functions[idx].uiField === uiField) {
|
|
61
|
+
fn = this.functions[idx].fn;
|
|
62
|
+
state = fn.getStateFromProps(propsForField);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
fn = new props.registry.fields[uiField](propsForField);
|
|
66
|
+
this.functions[idx] = { uiField, fn };
|
|
67
|
+
state = fn.state || {};
|
|
68
|
+
}
|
|
69
|
+
let computedProps = {};
|
|
70
|
+
if ("schema" in state) {
|
|
71
|
+
computedProps.schema = utils_1.updateSafelyWithJSONPointer(props.schema, state.schema, utils_1.schemaJSONPointer(props.schema, field));
|
|
72
|
+
}
|
|
73
|
+
if ("uiSchema" in state) {
|
|
74
|
+
computedProps.uiSchema = utils_1.updateSafelyWithJSONPointer(props.uiSchema, state.uiSchema, utils_1.uiSchemaJSONPointer(props.schema, field));
|
|
75
|
+
}
|
|
76
|
+
["formData", "idSchema", "errorSchema"].forEach(prop => {
|
|
77
|
+
if (prop in state) {
|
|
78
|
+
computedProps[prop] = utils_1.updateSafelyWithJSONPointer(props[prop] || {}, state[prop], field);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return Object.assign(Object.assign({}, props), computedProps);
|
|
82
|
+
}, props);
|
|
83
|
+
state.onChange = this.onChange;
|
|
84
|
+
return state;
|
|
85
|
+
}
|
|
86
|
+
combinedOnChange(formData) {
|
|
87
|
+
const { field } = this.getUiOptions();
|
|
88
|
+
this.props.onChange(utils_1.updateSafelyWithJSONPointer(this.onChangeFormData, formData, field));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
UiFieldApplierField.propTypes = {
|
|
92
|
+
schema: PropTypes.shape({
|
|
93
|
+
type: PropTypes.oneOf(["object"])
|
|
94
|
+
}).isRequired,
|
|
95
|
+
uiSchema: PropTypes.shape({
|
|
96
|
+
"ui:options": PropTypes.shape({
|
|
97
|
+
field: PropTypes.string,
|
|
98
|
+
functions: PropTypes.oneOfType([functionPropType, PropTypes.arrayOf(functionPropType)])
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
101
|
+
formData: PropTypes.object
|
|
102
|
+
};
|
|
103
|
+
UiFieldApplierField = __decorate([
|
|
104
|
+
VirtualSchemaField_1.default
|
|
105
|
+
], UiFieldApplierField);
|
|
106
|
+
exports.default = UiFieldApplierField;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default class UiFieldMapperArrayField extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
5
|
+
functions: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
"ui:field": PropTypes.Validator<string>;
|
|
7
|
+
"ui:options": PropTypes.Requireable<object>;
|
|
8
|
+
}> | (PropTypes.InferProps<{
|
|
9
|
+
"ui:field": PropTypes.Validator<string>;
|
|
10
|
+
"ui:options": PropTypes.Requireable<object>;
|
|
11
|
+
}> | null | undefined)[]>;
|
|
12
|
+
}>>;
|
|
13
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
14
|
+
}>>;
|
|
15
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
16
|
+
type: PropTypes.Requireable<string>;
|
|
17
|
+
}>>;
|
|
18
|
+
formData: PropTypes.Requireable<any[]>;
|
|
19
|
+
};
|
|
20
|
+
static getName(): string;
|
|
21
|
+
constructor(props: any);
|
|
22
|
+
childProps: any[];
|
|
23
|
+
functionOutputProps: any[];
|
|
24
|
+
updateChildProps: (props: any) => void;
|
|
25
|
+
getFieldPropsForIdx: (props: any, idx: any) => any;
|
|
26
|
+
tmpItemFormData: any;
|
|
27
|
+
applyFunctionsToChildProps: (props: any, childProps: any) => any;
|
|
28
|
+
getFunctionOutputForIdx: (props: any, idx: any) => any;
|
|
29
|
+
getStateFromProps(props: any, origProps: any): {
|
|
30
|
+
schema: any;
|
|
31
|
+
uiSchema: any;
|
|
32
|
+
formData: any;
|
|
33
|
+
idSchema: any;
|
|
34
|
+
errorSchema: any;
|
|
35
|
+
formContext: any;
|
|
36
|
+
registry: any;
|
|
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";
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
9
|
+
var t = {};
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
13
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
15
|
+
t[p[i]] = s[p[i]];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const React = require("react");
|
|
21
|
+
const PropTypes = require("prop-types");
|
|
22
|
+
const utils_1 = require("@rjsf/utils");
|
|
23
|
+
const utils_2 = require("../../utils");
|
|
24
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
25
|
+
const functionPropType = PropTypes.shape({
|
|
26
|
+
"ui:field": PropTypes.string.isRequired,
|
|
27
|
+
"ui:options": PropTypes.object
|
|
28
|
+
});
|
|
29
|
+
let UiFieldMapperArrayField = class UiFieldMapperArrayField extends React.Component {
|
|
30
|
+
constructor(props) {
|
|
31
|
+
super(props);
|
|
32
|
+
this.updateChildProps = (props) => {
|
|
33
|
+
(props.formData || []).forEach((item, idx) => {
|
|
34
|
+
const currentFieldProps = this.childProps[idx];
|
|
35
|
+
const nextFieldProps = this.getFieldPropsForIdx(props, idx);
|
|
36
|
+
if (!utils_1.deepEquals([currentFieldProps, nextFieldProps])) {
|
|
37
|
+
this.functionOutputProps[idx] = this.applyFunctionsToChildProps(props, nextFieldProps);
|
|
38
|
+
this.childProps[idx] = nextFieldProps;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
this.getFieldPropsForIdx = (props, idx) => {
|
|
43
|
+
return Object.assign(Object.assign({}, props), { schema: props.schema.items, uiSchema: (props.uiSchema.uiSchema || props.uiSchema).items, idSchema: props.idSchema, formData: (props.formData || [])[idx], errorSchema: (props.errorSchema || {})[idx] || {}, onChange: formData => {
|
|
44
|
+
this.tmpItemFormData = formData;
|
|
45
|
+
} });
|
|
46
|
+
};
|
|
47
|
+
this.applyFunctionsToChildProps = (props, childProps) => {
|
|
48
|
+
let { functions } = utils_2.getUiOptions(props.uiSchema);
|
|
49
|
+
return ((Array.isArray(functions)) ? functions : [functions]).reduce((_props, { "ui:field": uiField, "ui:options": uiOptions }) => {
|
|
50
|
+
const _a = _props.uiSchema || {}, { "ui:functions": uiFunctions, uiSchema, "ui:field": origUiField, "ui:options": origUiOptions, "ui:settings": origUiSettings } = _a, _propsUiSchema = __rest(_a, ["ui:functions", "uiSchema", "ui:field", "ui:options", "ui:settings"]);
|
|
51
|
+
_props = Object.assign(Object.assign({}, _props), { uiSchema: Object.assign(Object.assign({}, _propsUiSchema), { "ui:field": uiField, "ui:options": uiOptions }) });
|
|
52
|
+
const { state = {} } = new props.registry.fields[uiField](_props);
|
|
53
|
+
return Object.assign(Object.assign(Object.assign({}, _props), state), { uiSchema: Object.assign(Object.assign(Object.assign({}, _props.uiSchema), state.uiSchema), { "ui:functions": uiFunctions, "ui:field": origUiField, "ui:options": origUiOptions, "ui:settings": origUiSettings, uiSchema }) });
|
|
54
|
+
}, childProps);
|
|
55
|
+
};
|
|
56
|
+
this.getFunctionOutputForIdx = (props, idx) => {
|
|
57
|
+
return this.applyFunctionsToChildProps(props, this.getFieldPropsForIdx(props, idx));
|
|
58
|
+
};
|
|
59
|
+
this.onChange = (formData) => {
|
|
60
|
+
this.props.onChange(formData.map((item, idx) => {
|
|
61
|
+
if (!utils_1.deepEquals(item, (this.props.formData || [])[idx])) {
|
|
62
|
+
const output = this.functionOutputProps[idx] || this.getFunctionOutputForIdx(this.props, idx);
|
|
63
|
+
output.onChange(item); // Will trigger child instance onChange, which will set this.tmpItemFormData.
|
|
64
|
+
return this.tmpItemFormData;
|
|
65
|
+
}
|
|
66
|
+
return item;
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
this.childProps = [];
|
|
70
|
+
this.functionOutputProps = [];
|
|
71
|
+
this.updateChildProps(props);
|
|
72
|
+
}
|
|
73
|
+
static getName() { return "UiFieldMapperArrayField"; }
|
|
74
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
75
|
+
this.updateChildProps(props);
|
|
76
|
+
this.setState(this.getStateFromProps(props));
|
|
77
|
+
}
|
|
78
|
+
getStateFromProps(props, origProps) {
|
|
79
|
+
const templateOutput = this.functionOutputProps && this.functionOutputProps.length ?
|
|
80
|
+
this.functionOutputProps[0] :
|
|
81
|
+
this.getFunctionOutputForIdx(origProps, undefined);
|
|
82
|
+
const addBaseErrors = (errorSchema) => (props.errorSchema || {}).__errors
|
|
83
|
+
? Object.assign(Object.assign({}, errorSchema), { __errors: props.errorSchema.__errors }) : errorSchema;
|
|
84
|
+
const schema = Object.assign(Object.assign({}, props.schema), { items: templateOutput.schema });
|
|
85
|
+
const state = {
|
|
86
|
+
schema,
|
|
87
|
+
uiSchema: Object.assign(Object.assign({}, props.uiSchema), { items: Object.assign(Object.assign({}, props.uiSchema.items), templateOutput.uiSchema) }),
|
|
88
|
+
formData: (props.formData || []).map((item, idx) => this.functionOutputProps[idx].formData),
|
|
89
|
+
idSchema: templateOutput.idSchema,
|
|
90
|
+
errorSchema: addBaseErrors(Object.keys((props.errorSchema || {})).reduce((errorSchema, idx) => {
|
|
91
|
+
if (!this.functionOutputProps[idx])
|
|
92
|
+
return errorSchema;
|
|
93
|
+
errorSchema[idx] = this.functionOutputProps[idx].errorSchema;
|
|
94
|
+
return errorSchema;
|
|
95
|
+
}, {})),
|
|
96
|
+
formContext: templateOutput.formContext,
|
|
97
|
+
registry: templateOutput.registry,
|
|
98
|
+
onChange: this.onChange
|
|
99
|
+
};
|
|
100
|
+
return state;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
UiFieldMapperArrayField.propTypes = {
|
|
104
|
+
uiSchema: PropTypes.shape({
|
|
105
|
+
"ui:options": PropTypes.shape({
|
|
106
|
+
functions: PropTypes.oneOfType([
|
|
107
|
+
PropTypes.arrayOf(functionPropType),
|
|
108
|
+
functionPropType
|
|
109
|
+
])
|
|
110
|
+
}),
|
|
111
|
+
uiSchema: PropTypes.object
|
|
112
|
+
}).isRequired,
|
|
113
|
+
schema: PropTypes.shape({
|
|
114
|
+
type: PropTypes.oneOf(["array"])
|
|
115
|
+
}).isRequired,
|
|
116
|
+
formData: PropTypes.array
|
|
117
|
+
};
|
|
118
|
+
UiFieldMapperArrayField = __decorate([
|
|
119
|
+
VirtualSchemaField_1.default
|
|
120
|
+
], UiFieldMapperArrayField);
|
|
121
|
+
exports.default = UiFieldMapperArrayField;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default class UnitCountShorthandField extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
5
|
+
shorthandField: PropTypes.Validator<string>;
|
|
6
|
+
pairCountField: PropTypes.Validator<string>;
|
|
7
|
+
taxonIDField: PropTypes.Validator<string>;
|
|
8
|
+
}>>;
|
|
9
|
+
}>>;
|
|
10
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
11
|
+
type: PropTypes.Requireable<string>;
|
|
12
|
+
}>>;
|
|
13
|
+
formData: PropTypes.Validator<object>;
|
|
14
|
+
};
|
|
15
|
+
static getName(): string;
|
|
16
|
+
constructor(props: any);
|
|
17
|
+
parseCode(value: any, taxonId: any): Promise<any>;
|
|
18
|
+
getStateFromProps(props: any): any;
|
|
19
|
+
promiseTimestamp: number | undefined;
|
|
20
|
+
}
|
|
21
|
+
import * as React from "react";
|
|
22
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
14
|
+
const components_1 = require("../components");
|
|
15
|
+
const merge = require("deepmerge");
|
|
16
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
17
|
+
let UnitCountShorthandField = class UnitCountShorthandField extends React.Component {
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
this.parseCode = this.parseCode.bind(this);
|
|
21
|
+
}
|
|
22
|
+
static getName() { return "UnitCountShorthandField"; }
|
|
23
|
+
getStateFromProps(props) {
|
|
24
|
+
const { uiSchema, formData } = props;
|
|
25
|
+
const { shorthandField, taxonIDField } = utils_1.getUiOptions(props.uiSchema);
|
|
26
|
+
const shortHandUiSchema = merge(utils_1.parseJSONPointer(props.uiSchema, shorthandField) || {}, {
|
|
27
|
+
"ui:widget": CodeReader,
|
|
28
|
+
"ui:options": {
|
|
29
|
+
parseCode: this.parseCode,
|
|
30
|
+
taxonID: utils_1.parseJSONPointer(formData, taxonIDField)
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const _uiSchema = utils_1.updateSafelyWithJSONPointer(uiSchema, shortHandUiSchema, shorthandField);
|
|
34
|
+
return Object.assign(Object.assign({}, props), { uiSchema: _uiSchema });
|
|
35
|
+
}
|
|
36
|
+
parseCode(value, taxonId) {
|
|
37
|
+
const { apiClient } = this.props.formContext;
|
|
38
|
+
let formData = this.props.formData;
|
|
39
|
+
const { shorthandField, pairCountField } = utils_1.getUiOptions(this.props.uiSchema);
|
|
40
|
+
let timestamp = Date.now();
|
|
41
|
+
this.promiseTimestamp = timestamp;
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
if (!value || !taxonId) {
|
|
44
|
+
formData = utils_1.updateSafelyWithJSONPointer(formData, undefined, pairCountField);
|
|
45
|
+
this.props.onChange(formData);
|
|
46
|
+
resolve({ success: undefined });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
apiClient.fetchCached("/autocomplete/pairCount", { q: value, taxonID: taxonId }).then(suggestion => {
|
|
50
|
+
if (timestamp !== this.promiseTimestamp) {
|
|
51
|
+
reject();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
formData = utils_1.updateSafelyWithJSONPointer(formData, suggestion.key, shorthandField);
|
|
55
|
+
formData = utils_1.updateSafelyWithJSONPointer(formData, suggestion.value, pairCountField);
|
|
56
|
+
this.props.onChange(formData);
|
|
57
|
+
resolve({ success: suggestion.key ? true : undefined, value: suggestion.key });
|
|
58
|
+
}).catch(() => {
|
|
59
|
+
if (timestamp !== this.promiseTimestamp) {
|
|
60
|
+
reject();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
formData = utils_1.updateSafelyWithJSONPointer(formData, undefined, pairCountField);
|
|
64
|
+
this.props.onChange(formData);
|
|
65
|
+
resolve({ success: false, value: value });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
UnitCountShorthandField.propTypes = {
|
|
71
|
+
uiSchema: PropTypes.shape({
|
|
72
|
+
"ui:options": PropTypes.shape({
|
|
73
|
+
shorthandField: PropTypes.string.isRequired,
|
|
74
|
+
pairCountField: PropTypes.string.isRequired,
|
|
75
|
+
taxonIDField: PropTypes.string.isRequired
|
|
76
|
+
}).isRequired
|
|
77
|
+
}).isRequired,
|
|
78
|
+
schema: PropTypes.shape({
|
|
79
|
+
type: PropTypes.oneOf(["object"])
|
|
80
|
+
}).isRequired,
|
|
81
|
+
formData: PropTypes.object.isRequired
|
|
82
|
+
};
|
|
83
|
+
UnitCountShorthandField = __decorate([
|
|
84
|
+
VirtualSchemaField_1.default
|
|
85
|
+
], UnitCountShorthandField);
|
|
86
|
+
exports.default = UnitCountShorthandField;
|
|
87
|
+
let CodeReader = class CodeReader extends React.Component {
|
|
88
|
+
constructor(props) {
|
|
89
|
+
super(props);
|
|
90
|
+
this.onChange = ({ target: { value } }) => {
|
|
91
|
+
this.props.onChange(value);
|
|
92
|
+
};
|
|
93
|
+
this.onKeyDown = (e) => {
|
|
94
|
+
if (e.key === "Enter") {
|
|
95
|
+
this.onBlur();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
this.state = { loading: false };
|
|
99
|
+
this.onBlur = this.onBlur.bind(this);
|
|
100
|
+
}
|
|
101
|
+
componentDidUpdate(prevProps) {
|
|
102
|
+
if (prevProps.options.taxonID !== this.props.options.taxonID) {
|
|
103
|
+
this.onBlur();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
render() {
|
|
107
|
+
let validationState = null;
|
|
108
|
+
if (this.state.success === false) {
|
|
109
|
+
validationState = "error";
|
|
110
|
+
}
|
|
111
|
+
else if (this.state.success) {
|
|
112
|
+
validationState = "success";
|
|
113
|
+
}
|
|
114
|
+
const { formContext } = this.props;
|
|
115
|
+
const { translations } = formContext;
|
|
116
|
+
const inputElem = (React.createElement(components_1.FetcherInput, { id: this.props.id, loading: this.state.loading, value: this.props.value || "", validationState: validationState, onBlur: this.onBlur, onKeyDown: this.onKeyDown, onChange: this.onChange }));
|
|
117
|
+
const { FormGroup, HelpBlock } = this.context.theme;
|
|
118
|
+
return (React.createElement(FormGroup, { validationState: this.state.success === false ? "error" : undefined },
|
|
119
|
+
inputElem,
|
|
120
|
+
this.state.success === false ? (React.createElement(HelpBlock, null, translations.InvalidUnitCode)) : null,
|
|
121
|
+
React.createElement("div", { className: "small text-muted", dangerouslySetInnerHTML: { __html: this.props.help } })));
|
|
122
|
+
}
|
|
123
|
+
onBlur() {
|
|
124
|
+
const { value, options } = this.props;
|
|
125
|
+
const { parseCode, taxonID } = options;
|
|
126
|
+
if (!(value === this.state.value && taxonID === this.state.taxonID)) {
|
|
127
|
+
this.setState({ value, taxonID, loading: true, success: undefined });
|
|
128
|
+
this.props.formContext.services.submitHooks.add(this.props, () => {
|
|
129
|
+
return parseCode(value, taxonID).then((result) => {
|
|
130
|
+
this.setState({ loading: false, success: result.success, value: result.value });
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
CodeReader.contextType = ReactContext_1.default;
|
|
137
|
+
CodeReader.propTypes = {
|
|
138
|
+
options: PropTypes.shape({
|
|
139
|
+
parseCode: PropTypes.func.isRequired,
|
|
140
|
+
taxonID: PropTypes.string
|
|
141
|
+
}).isRequired,
|
|
142
|
+
schema: PropTypes.shape({
|
|
143
|
+
type: PropTypes.oneOf(["string"])
|
|
144
|
+
}),
|
|
145
|
+
value: PropTypes.string
|
|
146
|
+
};
|
|
147
|
+
CodeReader = __decorate([
|
|
148
|
+
BaseComponent_1.default
|
|
149
|
+
], CodeReader);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatible only with unit array.
|
|
3
|
+
*/
|
|
4
|
+
export default class UnitListShorthandArrayField extends React.Component<any, any, any> {
|
|
5
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
6
|
+
static propTypes: {
|
|
7
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
8
|
+
type: PropTypes.Requireable<string>;
|
|
9
|
+
}>>;
|
|
10
|
+
formData: PropTypes.Validator<any[]>;
|
|
11
|
+
};
|
|
12
|
+
constructor(props: any);
|
|
13
|
+
constructor(props: any, context: any);
|
|
14
|
+
getStateFromProps(props: any): {
|
|
15
|
+
uiSchema: any;
|
|
16
|
+
};
|
|
17
|
+
onButtonClick: () => () => void;
|
|
18
|
+
onHide: () => void;
|
|
19
|
+
onTagFieldChange: (tags: any) => void;
|
|
20
|
+
onSubmit: () => void;
|
|
21
|
+
onKeyDown: (e: any) => void;
|
|
22
|
+
setTagArrayRef: (ref: any) => void;
|
|
23
|
+
tagRef: any;
|
|
24
|
+
}
|
|
25
|
+
import * as React from "react";
|
|
26
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,108 @@
|
|
|
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 BaseComponent_1 = require("../BaseComponent");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const components_1 = require("../components");
|
|
14
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
15
|
+
const TagArrayField_1 = require("./TagArrayField");
|
|
16
|
+
/**
|
|
17
|
+
* Compatible only with unit array.
|
|
18
|
+
*/
|
|
19
|
+
let UnitListShorthandArrayField = class UnitListShorthandArrayField extends React.Component {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.onButtonClick = () => () => {
|
|
23
|
+
this.setState({ show: !this.state.show });
|
|
24
|
+
};
|
|
25
|
+
this.onHide = () => {
|
|
26
|
+
this.setState({ show: false, value: "" });
|
|
27
|
+
};
|
|
28
|
+
this.onTagFieldChange = (tags) => {
|
|
29
|
+
this.setState({ value: tags.join(",") });
|
|
30
|
+
};
|
|
31
|
+
this.onSubmit = () => {
|
|
32
|
+
const value = this.state.value + (utils_1.isEmptyString(this.tagRef.state.value) ? "" : `,${this.tagRef.state.value}`);
|
|
33
|
+
this.onHide();
|
|
34
|
+
const { translations, notifier, apiClient } = this.props.formContext;
|
|
35
|
+
this.props.formContext.services.blocker.push();
|
|
36
|
+
apiClient.fetch("/autocomplete/unit", { q: value, list: true, includePayload: true }).then(({ payload: { units, nonMatchingCount } }) => {
|
|
37
|
+
units = units.map(unit => {
|
|
38
|
+
unit = utils_1.getDefaultFormState(this.props.schema.items, unit);
|
|
39
|
+
unit = utils_1.bringRemoteFormData(unit, this.props.formContext);
|
|
40
|
+
unit = utils_1.assignUUID(unit);
|
|
41
|
+
return unit;
|
|
42
|
+
});
|
|
43
|
+
const formData = this.props.formData;
|
|
44
|
+
const last = formData[formData.length - 1];
|
|
45
|
+
if (last && utils_1.isDefaultData(last, this.props.schema.items)) {
|
|
46
|
+
formData.pop();
|
|
47
|
+
}
|
|
48
|
+
this.props.onChange([...formData, ...units]);
|
|
49
|
+
nonMatchingCount
|
|
50
|
+
? notifier.warning(`${translations.UnitListShorthandWarning} ${nonMatchingCount}`)
|
|
51
|
+
: notifier.success(translations.UnitListShorthandSuccess);
|
|
52
|
+
this.props.formContext.services.blocker.pop();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
this.onKeyDown = (e) => {
|
|
56
|
+
if (e.key === "Enter") {
|
|
57
|
+
this.onSubmit(e);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.setTagArrayRef = (ref) => {
|
|
61
|
+
this.tagRef = ref;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getStateFromProps(props) {
|
|
65
|
+
const buttonDefinition = {
|
|
66
|
+
fn: this.onButtonClick,
|
|
67
|
+
fnName: "addUnitList",
|
|
68
|
+
glyph: "align-justify",
|
|
69
|
+
label: this.props.formContext.translations.AddUnitList,
|
|
70
|
+
id: this.props.idSchema.$id,
|
|
71
|
+
changesFormData: true,
|
|
72
|
+
rules: {
|
|
73
|
+
canAdd: true
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const innerUiSchema = utils_1.getInnerUiSchema(props.uiSchema);
|
|
77
|
+
const options = utils_1.getUiOptions(innerUiSchema);
|
|
78
|
+
const uiSchema = Object.assign(Object.assign({}, innerUiSchema), { "ui:options": Object.assign(Object.assign({}, options), { buttons: [
|
|
79
|
+
...(options.buttons || []),
|
|
80
|
+
buttonDefinition
|
|
81
|
+
] }) });
|
|
82
|
+
return { uiSchema };
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
const { SchemaField } = this.props.registry.fields;
|
|
86
|
+
const { Modal } = this.context.theme;
|
|
87
|
+
return (React.createElement(React.Fragment, null,
|
|
88
|
+
React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: this.state.uiSchema })),
|
|
89
|
+
this.state.show && (React.createElement(Modal, { show: true, onHide: this.onHide, dialogClassName: "unit-list-shorthand-modal" },
|
|
90
|
+
React.createElement(Modal.Body, null,
|
|
91
|
+
React.createElement(TagArrayField_1.TagInputComponent, { tags: utils_1.isEmptyString(this.state.value) ? [] : this.state.value.split(",").filter(s => !utils_1.isEmptyString(s)), onChange: this.onTagFieldChange, schema: {}, idSchema: {}, uiSchema: { "ui:options": { separatorKeys: [","] } }, inputProps: { autoFocus: true }, onKeyDown: this.onKeyDown, ref: this.setTagArrayRef, formContext: this.props.formContext }),
|
|
92
|
+
React.createElement("span", { className: "text-muted" },
|
|
93
|
+
React.createElement("i", null, this.props.formContext.translations.UnitListShorthandHelp)),
|
|
94
|
+
React.createElement("br", null),
|
|
95
|
+
React.createElement(components_1.Button, { type: "submit", disabled: utils_1.isEmptyString(this.state.value), onClick: this.onSubmit }, this.props.formContext.translations.Add))))));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
UnitListShorthandArrayField.contextType = ReactContext_1.default;
|
|
99
|
+
UnitListShorthandArrayField.propTypes = {
|
|
100
|
+
schema: PropTypes.shape({
|
|
101
|
+
type: PropTypes.oneOf(["array"])
|
|
102
|
+
}).isRequired,
|
|
103
|
+
formData: PropTypes.array.isRequired
|
|
104
|
+
};
|
|
105
|
+
UnitListShorthandArrayField = __decorate([
|
|
106
|
+
BaseComponent_1.default
|
|
107
|
+
], UnitListShorthandArrayField);
|
|
108
|
+
exports.default = UnitListShorthandArrayField;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default class UnitShorthandField extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
4
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
5
|
+
shorthandField: PropTypes.Requireable<string>;
|
|
6
|
+
formID: PropTypes.Requireable<string>;
|
|
7
|
+
showSchema: PropTypes.Requireable<boolean>;
|
|
8
|
+
persistenceKey: PropTypes.Requireable<string>;
|
|
9
|
+
}>>;
|
|
10
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
11
|
+
}>>;
|
|
12
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
13
|
+
type: PropTypes.Requireable<string>;
|
|
14
|
+
}>>;
|
|
15
|
+
formData: PropTypes.Validator<object>;
|
|
16
|
+
};
|
|
17
|
+
constructor(props: any);
|
|
18
|
+
getStateFromProps: (props: any) => any;
|
|
19
|
+
onNextTick: (() => void) | undefined;
|
|
20
|
+
shouldShowSchema: (props: any) => any;
|
|
21
|
+
onToggleButtonClick: () => () => void;
|
|
22
|
+
getToggleButton: () => {
|
|
23
|
+
glyph: string;
|
|
24
|
+
fn: () => () => void;
|
|
25
|
+
tooltip: any;
|
|
26
|
+
tooltipPlacement: string;
|
|
27
|
+
active: boolean;
|
|
28
|
+
};
|
|
29
|
+
onCodeChange: (formData?: {}) => void;
|
|
30
|
+
}
|
|
31
|
+
import * as React from "react";
|
|
32
|
+
import * as PropTypes from "prop-types";
|