@luomus/laji-form 14.3.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/CHANGELOG.md +215 -0
- package/LICENSE +21 -0
- package/README.md +180 -0
- package/cypress/fixtures/example.json +5 -0
- closes suggestion list (failed).png +0 -0
- is marked as suggested (failed).png +0 -0
- package/dist/images/finnish-flag.png +0 -0
- package/dist/images/handled.png +0 -0
- package/dist/images/heard.png +0 -0
- package/dist/images/indirect.png +0 -0
- package/dist/images/media.png +0 -0
- package/dist/images/seen.png +0 -0
- package/dist/images/specimen.png +0 -0
- package/dist/laji-form.js +2 -0
- package/dist/laji-form.js.LICENSE.txt +92 -0
- package/dist/styles.css +3771 -0
- 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 +614 -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/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 +153 -0
- package/lib/components/fields/ImageArrayField.js +696 -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/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 +614 -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 +842 -0
- package/lib/utils.d.ts +167 -0
- package/lib/utils.js +1191 -0
- package/lib/validation.d.ts +7 -0
- package/lib/validation.js +141 -0
- package/llol +10 -0
- package/llol.pdf +10 -0
- package/package.json +99 -0
- package/q +196 -0
- package/test-export/array-spec.d.ts +1 -0
- package/test-export/array-spec.js +204 -0
- package/test-export/bird-point-count-spec.d.ts +1 -0
- package/test-export/bird-point-count-spec.js +62 -0
- package/test-export/collection-contest-form-spec.d.ts +1 -0
- package/test-export/collection-contest-form-spec.js +38 -0
- package/test-export/dataset-form-spec.d.ts +1 -0
- package/test-export/dataset-form-spec.js +50 -0
- package/test-export/date-time-widget-spec.d.ts +1 -0
- package/test-export/date-time-widget-spec.js +188 -0
- package/test-export/geocoder-spec.d.ts +1 -0
- package/test-export/geocoder-spec.js +135 -0
- package/test-export/image-array-spec.d.ts +1 -0
- package/test-export/image-array-spec.js +94 -0
- package/test-export/inject-field-spec.d.ts +1 -0
- package/test-export/inject-field-spec.js +148 -0
- package/test-export/internal-uuids-spec.d.ts +1 -0
- package/test-export/internal-uuids-spec.js +157 -0
- package/test-export/invasive-species-eradication-np-spec.d.ts +1 -0
- package/test-export/invasive-species-eradication-np-spec.js +18 -0
- package/test-export/invasive-species-eradication-spec.d.ts +1 -0
- package/test-export/invasive-species-eradication-spec.js +25 -0
- package/test-export/line-transect-spec.d.ts +1 -0
- package/test-export/line-transect-spec.js +121 -0
- package/test-export/mobile-form-spec.d.ts +1 -0
- package/test-export/mobile-form-spec.js +84 -0
- package/test-export/nafi-spec.d.ts +1 -0
- package/test-export/nafi-spec.js +85 -0
- package/test-export/select-widget-spec.d.ts +1 -0
- package/test-export/select-widget-spec.js +68 -0
- package/test-export/single-item-array-field-spec.d.ts +1 -0
- package/test-export/single-item-array-field-spec.js +92 -0
- package/test-export/syke-butterfly-spec.d.ts +1 -0
- package/test-export/syke-butterfly-spec.js +163 -0
- package/test-export/test-utils.d.ts +184 -0
- package/test-export/test-utils.js +354 -0
- package/test-export/transaction-form-spec.d.ts +1 -0
- package/test-export/transaction-form-spec.js +63 -0
- package/test-export/trip-report-autosuggest-spec.d.ts +1 -0
- package/test-export/trip-report-autosuggest-spec.js +272 -0
- package/test-export/trip-report-spec.d.ts +1 -0
- package/test-export/trip-report-spec.js +456 -0
- package/test-export/unit-list-shorthand-array-field-spec.d.ts +1 -0
- package/test-export/unit-list-shorthand-array-field-spec.js +71 -0
- package/test-export/validation-spec.d.ts +1 -0
- package/test-export/validation-spec.js +336 -0
- package/test-export/water-bird-spec.d.ts +1 -0
- package/test-export/water-bird-spec.js +30 -0
- package/test-export/wbc-spec.d.ts +1 -0
- package/test-export/wbc-spec.js +82 -0
- package/tsconfig.json +25 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,974 @@
|
|
|
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 react_dom_1 = require("react-dom");
|
|
22
|
+
const PropTypes = require("prop-types");
|
|
23
|
+
const merge = require("deepmerge");
|
|
24
|
+
const utils_1 = require("../../utils");
|
|
25
|
+
const utils_2 = require("@rjsf/utils");
|
|
26
|
+
const components_1 = require("../components");
|
|
27
|
+
const ArrayFieldTemplate_1 = require("../templates/ArrayFieldTemplate");
|
|
28
|
+
const ArrayField_1 = require("./ArrayField");
|
|
29
|
+
const Context_1 = require("../../Context");
|
|
30
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
31
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
32
|
+
const utils_3 = require("@luomus/laji-map/lib/utils");
|
|
33
|
+
const utils_4 = require("@rjsf/utils");
|
|
34
|
+
const memoize = require("memoizee");
|
|
35
|
+
const ArrayField_2 = require("./ArrayField");
|
|
36
|
+
const popupMappers = {
|
|
37
|
+
units: (schema, units, options) => {
|
|
38
|
+
const identifications = units.map(item => (item && item.identifications && item.identifications[0]) ?
|
|
39
|
+
item.identifications[0] :
|
|
40
|
+
undefined).filter(item => item);
|
|
41
|
+
return Promise.all(identifications.map(identification => Promise.resolve(identification.taxon))).then(result => {
|
|
42
|
+
return Promise.resolve({ [(schema.units ? schema.units.title : undefined) || options.label || options.field]: result });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
let SingleActiveArrayField = class SingleActiveArrayField extends React.Component {
|
|
47
|
+
constructor(props) {
|
|
48
|
+
super(props);
|
|
49
|
+
this.getInitialActiveIdx = (props) => {
|
|
50
|
+
const { formData, uiSchema, schema } = props;
|
|
51
|
+
const formDataLength = (formData || []).length;
|
|
52
|
+
const options = utils_1.getUiOptions(uiSchema);
|
|
53
|
+
return (formDataLength === 1 || formDataLength === 0 && schema.minItems) ? 0 : options.initialActiveIdx;
|
|
54
|
+
};
|
|
55
|
+
this.updatePopups = (props) => {
|
|
56
|
+
const { popupFields } = utils_1.getUiOptions(this.props.uiSchema);
|
|
57
|
+
let { popups } = this.state;
|
|
58
|
+
let count = 0;
|
|
59
|
+
if (popupFields)
|
|
60
|
+
props.formData.forEach((item, idx) => {
|
|
61
|
+
this.getPopupDataPromise(idx, props, item).then(popupData => {
|
|
62
|
+
count++;
|
|
63
|
+
popups = Object.assign(Object.assign({}, popups), { [idx]: popupData });
|
|
64
|
+
if (this.mounted && count === props.formData.length)
|
|
65
|
+
this.setState({ popups });
|
|
66
|
+
}).catch(() => {
|
|
67
|
+
count++;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
this.onHeaderAffixChange = (elem, value) => {
|
|
72
|
+
if (value) {
|
|
73
|
+
this.setState({ scrollHeightFixed: elem.scrollHeight }, () => {
|
|
74
|
+
this.getLocalFormContext().utils.syncScroll(!!"force");
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.setState({ scrollHeightFixed: 0 });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
this.getLocalFormContext = () => {
|
|
82
|
+
if (this.localContextKey === this.state.scrollHeightFixed) {
|
|
83
|
+
return this.localContext;
|
|
84
|
+
}
|
|
85
|
+
this.localContextKey = this.state.scrollHeightFixed;
|
|
86
|
+
this.localContext = Object.assign(Object.assign({}, this.props.formContext), { topOffset: this.props.formContext.topOffset + this.state.scrollHeightFixed });
|
|
87
|
+
this.localContext.utils = utils_1.ReactUtils(this.localContext);
|
|
88
|
+
return this.localContext;
|
|
89
|
+
};
|
|
90
|
+
this.updateRenderingMode = (normalRendering, callback) => {
|
|
91
|
+
this.setState({ normalRendering }, () => callback && callback(normalRendering));
|
|
92
|
+
};
|
|
93
|
+
this.getPopupDataPromise = (idx, props, itemFormData) => {
|
|
94
|
+
const { popupFields } = utils_1.getUiOptions(props.uiSchema);
|
|
95
|
+
if (!this.props.formData)
|
|
96
|
+
return Promise.resolve({});
|
|
97
|
+
return Promise.all(popupFields.map(field => {
|
|
98
|
+
const fieldName = field.field;
|
|
99
|
+
let fieldData = itemFormData ? itemFormData[fieldName] : undefined;
|
|
100
|
+
let fieldSchema = props.schema.items.properties;
|
|
101
|
+
if (field.mapper && fieldData) {
|
|
102
|
+
return popupMappers[field.mapper](fieldSchema, fieldData, field);
|
|
103
|
+
}
|
|
104
|
+
else if (fieldData) {
|
|
105
|
+
return new Promise(resolve => resolve({ [fieldSchema && fieldSchema[fieldName] ? fieldSchema[fieldName].title : fieldName]: fieldData }));
|
|
106
|
+
}
|
|
107
|
+
})).then(fields => {
|
|
108
|
+
const popupData = fields.reduce((popup, item) => {
|
|
109
|
+
if (item)
|
|
110
|
+
Object.keys(item).forEach(label => {
|
|
111
|
+
popup[label] = item[label];
|
|
112
|
+
});
|
|
113
|
+
return popup;
|
|
114
|
+
}, {});
|
|
115
|
+
return Promise.resolve(popupData);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
this.onActiveChange = (idx, prop, callback) => {
|
|
119
|
+
if (idx !== undefined) {
|
|
120
|
+
idx = parseInt(idx);
|
|
121
|
+
}
|
|
122
|
+
if (this.state.activeIdx === idx) {
|
|
123
|
+
idx = undefined;
|
|
124
|
+
}
|
|
125
|
+
const { onActiveChange } = utils_1.getUiOptions(this.props.uiSchema);
|
|
126
|
+
onActiveChange ? onActiveChange(idx, prop, callback) : this.setState({ activeIdx: idx }, callback);
|
|
127
|
+
};
|
|
128
|
+
this.onDelete = (item) => (e) => {
|
|
129
|
+
const newLength = this.props.formData.length - 1;
|
|
130
|
+
if (!newLength) {
|
|
131
|
+
this.onActiveChange(undefined);
|
|
132
|
+
}
|
|
133
|
+
else if (this.state.activeIdx > newLength - 1) {
|
|
134
|
+
this.onActiveChange(newLength - 1);
|
|
135
|
+
}
|
|
136
|
+
item.onDropIndexClick(item.index)(e);
|
|
137
|
+
};
|
|
138
|
+
this.buttonDefinitions = {
|
|
139
|
+
add: {
|
|
140
|
+
callback: () => this.onActiveChange((this.props.formData || []).length)
|
|
141
|
+
},
|
|
142
|
+
addPredefined: {
|
|
143
|
+
callback: () => this.onActiveChange((this.props.formData || []).length)
|
|
144
|
+
},
|
|
145
|
+
copy: {
|
|
146
|
+
fn: () => (...params) => {
|
|
147
|
+
const { formData = [] } = this.props;
|
|
148
|
+
const idx = this.state.activeIdx !== undefined ?
|
|
149
|
+
this.state.activeIdx :
|
|
150
|
+
formData.length - 1;
|
|
151
|
+
ArrayFieldTemplate_1.beforeAdd(this.props, idx + 1);
|
|
152
|
+
this.props.onChange([
|
|
153
|
+
...formData.slice(0, idx + 1),
|
|
154
|
+
ArrayField_1.copyItemFunction(this, formData[idx])(...params),
|
|
155
|
+
...formData.slice(idx + 1)
|
|
156
|
+
]);
|
|
157
|
+
},
|
|
158
|
+
callback: () => {
|
|
159
|
+
const idx = this.state.activeIdx !== undefined ?
|
|
160
|
+
this.state.activeIdx :
|
|
161
|
+
(this.props.formData || []).length - 1;
|
|
162
|
+
this.onActiveChange(idx + 1);
|
|
163
|
+
},
|
|
164
|
+
rules: {
|
|
165
|
+
minLength: 1
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
this.deleteButtonRefs = {};
|
|
170
|
+
this.deleteButtonRefSetters = {};
|
|
171
|
+
this.state = Object.assign(Object.assign({ activeIdx: this.getInitialActiveIdx(props), scrollHeightFixed: 0 }, this.getStateFromProps(props)), { popups: {} });
|
|
172
|
+
const id = `${this.props.idSchema.$id}`;
|
|
173
|
+
this.props.formContext.globals[`${id}.activeIdx`] = this.state.activeIdx;
|
|
174
|
+
}
|
|
175
|
+
componentDidMount() {
|
|
176
|
+
this.mounted = true;
|
|
177
|
+
this.updatePopups(this.props);
|
|
178
|
+
if (utils_1.getUiOptions(this.props.uiSchema).receiveActiveIdxEvents !== false) {
|
|
179
|
+
this.props.formContext.services.customEvents.add(this.props.idSchema.$id, "activeIdx", this.onActiveChange);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
componentWillUnmount() {
|
|
183
|
+
this.mounted = false;
|
|
184
|
+
if (utils_1.getUiOptions(this.props.uiSchema).receiveActiveIdxEvents !== false) {
|
|
185
|
+
this.props.formContext.services.customEvents.remove(this.props.idSchema.$id, "activeIdx", this.onActiveChange);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
189
|
+
this.prevActiveIdx = this.state.activeIdx;
|
|
190
|
+
this.setState(this.getStateFromProps(props));
|
|
191
|
+
this.updatePopups(props);
|
|
192
|
+
}
|
|
193
|
+
componentDidUpdate(prevProps, prevState) {
|
|
194
|
+
const options = utils_1.getUiOptions(this.props);
|
|
195
|
+
const prevOptions = utils_1.getUiOptions(prevProps);
|
|
196
|
+
this.props.formContext.globals[`${this.props.idSchema.$id}.activeIdx`] = this.state.activeIdx;
|
|
197
|
+
const { idToFocusAfterNavigate, idToScrollAfterNavigate, focusOnNavigate = true, renderer = "accordion", affixed } = utils_1.getUiOptions(this.props.uiSchema);
|
|
198
|
+
if (renderer === "uncontrolled")
|
|
199
|
+
return;
|
|
200
|
+
if ((prevProps.formData || []).length === (this.props.formData || []).length && ("activeIdx" in options && options.activeIdx !== prevOptions.activeIdx || (!("activeIdx" in options) && this.state.activeIdx !== prevState.activeIdx))) {
|
|
201
|
+
const id = `${this.props.idSchema.$id}_${utils_1.getFormDataIndex(this.state.activeIdx, this.props.uiSchema)}`;
|
|
202
|
+
const idToScroll = idToScrollAfterNavigate
|
|
203
|
+
? idToScrollAfterNavigate
|
|
204
|
+
: !affixed && (renderer === "accordion" || renderer === "pager")
|
|
205
|
+
? `${id}-header`
|
|
206
|
+
: `${this.props.idSchema.$id}-add`;
|
|
207
|
+
this.getLocalFormContext().utils.focusAndScroll(idToFocusAfterNavigate || id, idToScroll, focusOnNavigate);
|
|
208
|
+
}
|
|
209
|
+
if (prevProps.idSchema.$id !== this.props.idSchema.$id) {
|
|
210
|
+
this.props.formContext.services.customEvents.remove(prevProps.idSchema.$id, "activeIdx", this.onActiveChange);
|
|
211
|
+
this.props.formContext.services.customEvents.add(this.props.idSchema.$id, "activeIdx", this.onActiveChange);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
shouldComponentUpdate(prevProps, prevState) {
|
|
215
|
+
if ((this.state.scrollHeightFixed && !prevState.scrollHeightFixed)
|
|
216
|
+
|| this.state.scrollHeightFixed && this.state.scrollHeightFixed !== prevState.scrollHeightFixed) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
getStateFromProps(props) {
|
|
222
|
+
const state = {};
|
|
223
|
+
const options = utils_1.getUiOptions(props.uiSchema);
|
|
224
|
+
if ("activeIdx" in options) {
|
|
225
|
+
state.activeIdx = options.activeIdx;
|
|
226
|
+
}
|
|
227
|
+
else if ((props.formData || []).length === 1 && (this.props.formData || []).length === 0) {
|
|
228
|
+
state.activeIdx = 0;
|
|
229
|
+
}
|
|
230
|
+
if (!state.activeIdx && this.props && props.idSchema.$id !== this.props.idSchema.$id) {
|
|
231
|
+
state.activeIdx = this.getInitialActiveIdx(props);
|
|
232
|
+
}
|
|
233
|
+
if (options.sortCols && options.sortCols !== utils_1.getUiOptions(this.props.uiSchema).sortCols) {
|
|
234
|
+
state.activeIdx = undefined;
|
|
235
|
+
}
|
|
236
|
+
return state;
|
|
237
|
+
}
|
|
238
|
+
render() {
|
|
239
|
+
const { renderer = "accordion", tableActiveItemClassNames } = utils_1.getUiOptions(this.props.uiSchema);
|
|
240
|
+
let ArrayFieldTemplate = undefined;
|
|
241
|
+
switch (renderer) {
|
|
242
|
+
case "accordion":
|
|
243
|
+
ArrayFieldTemplate = AccordionArrayFieldTemplate;
|
|
244
|
+
break;
|
|
245
|
+
case "pager":
|
|
246
|
+
ArrayFieldTemplate = PagerArrayFieldTemplate;
|
|
247
|
+
break;
|
|
248
|
+
case "uncontrolled":
|
|
249
|
+
ArrayFieldTemplate = UncontrolledArrayFieldTemplate;
|
|
250
|
+
break;
|
|
251
|
+
case "table":
|
|
252
|
+
ArrayFieldTemplate = TableArrayFieldTemplate;
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
throw new Error(`Unknown renderer '${renderer}' for SingleActiveArrayField`);
|
|
256
|
+
}
|
|
257
|
+
const formContext = Object.assign(Object.assign({}, this.getLocalFormContext()), { this: this, prevActiveIdx: this.prevActiveIdx, activeIdx: this.state.activeIdx });
|
|
258
|
+
const { registry: { fields: { ArrayField } } } = this.props;
|
|
259
|
+
const { buttons = [], buttonDefinitions } = utils_1.getUiOptions(this.props.uiSchema);
|
|
260
|
+
let uiSchema = Object.assign(Object.assign({}, this.props.uiSchema), { "ui:field": undefined, "ui:classNames": undefined, "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(this.props.uiSchema)), { buttons, buttonDefinitions: buttonDefinitions
|
|
261
|
+
? merge(this.buttonDefinitions, buttonDefinitions)
|
|
262
|
+
: this.buttonDefinitions }) });
|
|
263
|
+
if (renderer === "table" && tableActiveItemClassNames && !this.state.normalRendering) {
|
|
264
|
+
uiSchema = Object.assign(Object.assign({}, uiSchema), { items: Object.assign(Object.assign({}, uiSchema.items), { "ui:classNames": tableActiveItemClassNames }) });
|
|
265
|
+
}
|
|
266
|
+
uiSchema["ui:ArrayFieldTemplate"] = ArrayFieldTemplate;
|
|
267
|
+
return (React.createElement(ArrayField, Object.assign({}, this.props, { formContext: formContext, registry: Object.assign(Object.assign({}, this.props.registry), { formContext }), uiSchema: uiSchema })));
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
SingleActiveArrayField.propTypes = {
|
|
271
|
+
uiSchema: PropTypes.shape({
|
|
272
|
+
"ui:options": PropTypes.shape({
|
|
273
|
+
renderer: PropTypes.oneOf(["accordion", "pager", "uncontrolled", "table"]),
|
|
274
|
+
activeIdx: PropTypes.number
|
|
275
|
+
})
|
|
276
|
+
}),
|
|
277
|
+
schema: PropTypes.shape({
|
|
278
|
+
type: PropTypes.oneOf(["array"])
|
|
279
|
+
}).isRequired,
|
|
280
|
+
formData: PropTypes.array
|
|
281
|
+
};
|
|
282
|
+
SingleActiveArrayField = __decorate([
|
|
283
|
+
BaseComponent_1.default
|
|
284
|
+
], SingleActiveArrayField);
|
|
285
|
+
exports.default = SingleActiveArrayField;
|
|
286
|
+
class Popup extends React.Component {
|
|
287
|
+
render() {
|
|
288
|
+
const { data } = this.props;
|
|
289
|
+
return (data && Object.keys(data).length) ? (React.createElement("ul", { className: "map-data-tooltip" }, data ? Object.keys(data).map(fieldName => {
|
|
290
|
+
const item = data[fieldName];
|
|
291
|
+
return React.createElement("li", { key: fieldName },
|
|
292
|
+
React.createElement("strong", null,
|
|
293
|
+
fieldName,
|
|
294
|
+
":"),
|
|
295
|
+
" ",
|
|
296
|
+
Array.isArray(item) ? item.filter(utils_1.hasData).join(", ") : item);
|
|
297
|
+
}) : null)) : null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function handlesButtonsAndFocus(ComposedComponent) {
|
|
301
|
+
let SingleActiveArrayTemplateField = class SingleActiveArrayTemplateField extends ComposedComponent {
|
|
302
|
+
constructor() {
|
|
303
|
+
super(...arguments);
|
|
304
|
+
this.getFocusHandlers = (props) => {
|
|
305
|
+
const that = props.formContext.this;
|
|
306
|
+
return props.items.map((_, i) => {
|
|
307
|
+
const idx = utils_1.getFormDataIndex(i, that.props.uiSchema);
|
|
308
|
+
return [`${that.props.idSchema.$id}_${idx}`, () => {
|
|
309
|
+
if (that.state.activeIdx !== i)
|
|
310
|
+
return new Promise(resolve => {
|
|
311
|
+
that.onActiveChange(i, undefined, () => resolve());
|
|
312
|
+
});
|
|
313
|
+
}];
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
getKeyHandlers(props) {
|
|
318
|
+
const { renderer = "accordion" } = utils_1.getUiOptions(props.uiSchema);
|
|
319
|
+
const that = props.formContext.this;
|
|
320
|
+
return [ArrayFieldTemplate_1.arrayKeyFunctions, {
|
|
321
|
+
getProps: () => this.props,
|
|
322
|
+
insertCallforward: callback => that.onActiveChange((that.props.formData || []).length, undefined, callback),
|
|
323
|
+
getCurrentIdx: () => that.state.activeIdx,
|
|
324
|
+
focusByIdx: (idx, prop, callback) => idx === that.state.activeIdx
|
|
325
|
+
? callback()
|
|
326
|
+
: that.onActiveChange(idx, prop, callback),
|
|
327
|
+
getIdToScrollAfterNavigate: renderer === "accordion" || renderer === "pager"
|
|
328
|
+
? () => `${props.idSchema.$id}_${that.state.activeIdx}-header`
|
|
329
|
+
: undefined
|
|
330
|
+
}];
|
|
331
|
+
}
|
|
332
|
+
componentDidMount() {
|
|
333
|
+
this.addFocusHandlers();
|
|
334
|
+
if (super.componentDidMount)
|
|
335
|
+
super.componentDidMount();
|
|
336
|
+
}
|
|
337
|
+
componentDidUpdate(...params) {
|
|
338
|
+
this.removeFocusHandlers();
|
|
339
|
+
this.addFocusHandlers();
|
|
340
|
+
if (super.componentDidUpdate)
|
|
341
|
+
super.componentDidUpdate(...params);
|
|
342
|
+
}
|
|
343
|
+
componentWillUnmount() {
|
|
344
|
+
this.removeFocusHandlers();
|
|
345
|
+
if (super.componentWillUnmount)
|
|
346
|
+
super.componentWillUnmount();
|
|
347
|
+
}
|
|
348
|
+
addFocusHandlers() {
|
|
349
|
+
this.focusHandlers = this.getFocusHandlers(this.props);
|
|
350
|
+
this.focusHandlers.forEach(handler => {
|
|
351
|
+
this.props.formContext.services.focus.addFocusHandler(...handler);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
removeFocusHandlers() {
|
|
355
|
+
this.focusHandlers.forEach(handler => {
|
|
356
|
+
this.props.formContext.services.focus.removeFocusHandler(...handler);
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
getChildKeyHandlers(props) {
|
|
360
|
+
const that = props.formContext.this;
|
|
361
|
+
const handlers = [];
|
|
362
|
+
if (that.state.activeIdx !== undefined) {
|
|
363
|
+
const id = `${props.idSchema.$id}_${that.state.activeIdx}`;
|
|
364
|
+
handlers.push([id, ArrayFieldTemplate_1.arrayItemKeyFunctions, { id, getProps: () => this.props, getDeleteButton: () => {
|
|
365
|
+
return that.deleteButtonRefs[that.state.activeIdx];
|
|
366
|
+
} }]);
|
|
367
|
+
}
|
|
368
|
+
return handlers;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
SingleActiveArrayTemplateField.displayName = utils_1.getReactComponentName(ComposedComponent);
|
|
372
|
+
SingleActiveArrayTemplateField = __decorate([
|
|
373
|
+
ArrayFieldTemplate_1.handlesArrayKeys
|
|
374
|
+
], SingleActiveArrayTemplateField);
|
|
375
|
+
return SingleActiveArrayTemplateField;
|
|
376
|
+
}
|
|
377
|
+
// Swallow unknown prop warnings.
|
|
378
|
+
const ButtonsWrapper = ({ props }) => {
|
|
379
|
+
const buttons = utils_1.getUiOptions(props.uiSchema).buttons;
|
|
380
|
+
return React.createElement("div", null, ArrayFieldTemplate_1.getButtonElems(buttons, props));
|
|
381
|
+
};
|
|
382
|
+
const AccordionButtonsWrapper = ({ props, position }) => {
|
|
383
|
+
const buttons = ArrayFieldTemplate_1.getButtonsForPosition(props, ArrayFieldTemplate_1.getButtons(utils_1.getUiOptions(props.uiSchema).buttons, props), position);
|
|
384
|
+
const { Row, Col } = React.useContext(ReactContext_1.default).theme;
|
|
385
|
+
if (!buttons)
|
|
386
|
+
return null;
|
|
387
|
+
const cols = Object.keys(utils_1.getBootstrapCols()).reduce((cols, colType) => {
|
|
388
|
+
cols[colType] = (colType === "xs" || buttons.length > 3) ? 12 : 12 / buttons.length;
|
|
389
|
+
return cols;
|
|
390
|
+
}, {});
|
|
391
|
+
return (React.createElement(Row, { className: "laji-form-accordion-buttons" }, buttons.map((button, idx) => React.createElement(Col, Object.assign({}, cols, { key: idx }), button))));
|
|
392
|
+
};
|
|
393
|
+
let AccordionArrayFieldTemplate = class AccordionArrayFieldTemplate extends React.Component {
|
|
394
|
+
constructor() {
|
|
395
|
+
super(...arguments);
|
|
396
|
+
this.setContainerRef = (elem) => {
|
|
397
|
+
this.containerRef = elem;
|
|
398
|
+
};
|
|
399
|
+
this.getContainerRef = () => react_dom_1.findDOMNode(this.containerRef);
|
|
400
|
+
this.setHeaderRef = (elem) => {
|
|
401
|
+
this.headerRef = elem;
|
|
402
|
+
};
|
|
403
|
+
this.onSelect = key => {
|
|
404
|
+
const that = this.props.formContext.this;
|
|
405
|
+
that.onActiveChange(key);
|
|
406
|
+
};
|
|
407
|
+
this.setDeleteButtonRef = idx => elem => { this.props.formContext.this.deleteButtonRefs[idx] = elem; };
|
|
408
|
+
}
|
|
409
|
+
render() {
|
|
410
|
+
const that = this.props.formContext.this;
|
|
411
|
+
const arrayFieldTemplateProps = this.props;
|
|
412
|
+
const activeIdx = that.state.activeIdx;
|
|
413
|
+
const { confirmDelete, closeButton, affixed } = utils_1.getUiOptions(arrayFieldTemplateProps.uiSchema);
|
|
414
|
+
const { translations } = this.props.formContext;
|
|
415
|
+
const { disabled, readonly } = arrayFieldTemplateProps;
|
|
416
|
+
const getHeader = (item, idx) => {
|
|
417
|
+
let header = React.createElement(AccordionHeader, { ref: this.setHeaderRef, that: that, idx: idx, wrapperClassName: "panel-title", className: "laji-form-panel-header laji-form-clickable-panel-header laji-form-accordion-header" }, item.hasRemove && React.createElement(components_1.DeleteButton, { id: `${that.props.idSchema.$id}_${utils_1.getFormDataIndex(idx, that.props.uiSchema)}`, disabled: disabled || readonly, ref: this.setDeleteButtonRef(idx), className: "pull-right", confirm: confirmDelete, translations: translations, onClick: that.onDelete(item) }));
|
|
418
|
+
if (affixed && activeIdx === idx) {
|
|
419
|
+
const offset = this.props.formContext.topOffset - (that.state.scrollHeightFixed);
|
|
420
|
+
header = (React.createElement(components_1.Affix, { getContainer: this.getContainerRef, topOffset: offset, onAffixChange: this.onHeaderAffixChange }, header));
|
|
421
|
+
}
|
|
422
|
+
return header;
|
|
423
|
+
};
|
|
424
|
+
const { Panel, Accordion, Glyphicon } = this.context.theme;
|
|
425
|
+
return (React.createElement("div", { className: "laji-form-single-active-array no-transition" },
|
|
426
|
+
React.createElement(AccordionButtonsWrapper, { props: arrayFieldTemplateProps, position: "top" }),
|
|
427
|
+
React.createElement(Accordion, { onSelect: this.onSelect, activeKey: activeIdx === undefined ? -1 : activeIdx, id: `${that.props.idSchema.$id}-accordion` },
|
|
428
|
+
arrayFieldTemplateProps.items.map((item, idx) => (React.createElement(Panel, { key: idx, ref: idx === activeIdx ? this.setContainerRef : undefined, id: `${this.props.idSchema.$id}_${utils_1.getFormDataIndex(idx, that.props.uiSchema)}-panel`, className: "laji-form-panel laji-form-clickable-panel", eventKey: idx, variant: utils_1.filteredErrors(that.props.errorSchema)[utils_1.getFormDataIndex(idx, that.props.uiSchema)] ? "danger" : "default" },
|
|
429
|
+
React.createElement(Panel.Heading, null, getHeader(item, idx)),
|
|
430
|
+
idx === activeIdx ? (React.createElement(Panel.Body, null,
|
|
431
|
+
item.children,
|
|
432
|
+
closeButton ? React.createElement(components_1.Button, { onClick: this.onSelect, small: true, className: "pull-right" },
|
|
433
|
+
React.createElement(Glyphicon, { glyph: "chevron-up" }),
|
|
434
|
+
" ",
|
|
435
|
+
translations.Close) : null)) : null))),
|
|
436
|
+
React.createElement(AccordionButtonsWrapper, { props: arrayFieldTemplateProps, position: "bottom" }))));
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
AccordionArrayFieldTemplate.contextType = ReactContext_1.default;
|
|
440
|
+
AccordionArrayFieldTemplate = __decorate([
|
|
441
|
+
handlesButtonsAndFocus
|
|
442
|
+
], AccordionArrayFieldTemplate);
|
|
443
|
+
let PagerArrayFieldTemplate = class PagerArrayFieldTemplate extends React.Component {
|
|
444
|
+
constructor() {
|
|
445
|
+
super(...arguments);
|
|
446
|
+
this.setContainerRef = (elem) => {
|
|
447
|
+
this.containerRef = elem;
|
|
448
|
+
};
|
|
449
|
+
this.getContainerRef = () => this.containerRef;
|
|
450
|
+
this.setHeaderRef = (elem) => {
|
|
451
|
+
this.headerRef = elem;
|
|
452
|
+
};
|
|
453
|
+
this.onHeaderAffixChange = (value) => {
|
|
454
|
+
const elem = this.headerRef;
|
|
455
|
+
const that = this.props.formContext.this;
|
|
456
|
+
that.onHeaderAffixChange(elem, value);
|
|
457
|
+
};
|
|
458
|
+
this.navigatePrev = () => this.props.formContext.this.onActiveChange(this.props.formContext.this.state.activeIdx - 1);
|
|
459
|
+
this.navigateNext = () => this.props.formContext.this.onActiveChange(this.props.formContext.this.state.activeIdx + 1);
|
|
460
|
+
this.setDeleteButtonRef = idx => elem => { this.props.formContext.this.deleteButtonRefs[idx] = elem; };
|
|
461
|
+
}
|
|
462
|
+
render() {
|
|
463
|
+
const that = this.props.formContext.this;
|
|
464
|
+
const arrayTemplateFieldProps = this.props;
|
|
465
|
+
const { translations } = that.props.formContext;
|
|
466
|
+
const { buttons, affixed, headerClassName, confirmDelete } = utils_1.getUiOptions(arrayTemplateFieldProps.uiSchema);
|
|
467
|
+
const activeIdx = that.state.activeIdx;
|
|
468
|
+
const { Pager } = this.context.theme;
|
|
469
|
+
let header = (React.createElement("div", { className: `laji-form-panel-header laji-form-accordion-header${headerClassName ? ` ${headerClassName}` : ""}`, ref: this.setHeaderRef },
|
|
470
|
+
React.createElement(Pager, null,
|
|
471
|
+
React.createElement(Pager.Item, { previous: true, href: "#", disabled: activeIdx <= 0 || activeIdx === undefined, onClick: this.navigatePrev },
|
|
472
|
+
"\u2190 ",
|
|
473
|
+
translations.Previous),
|
|
474
|
+
activeIdx !== undefined
|
|
475
|
+
? (React.createElement(AccordionHeader, { that: that, idx: activeIdx, className: "panel-title", canHaveUndefinedIdx: false }))
|
|
476
|
+
: null,
|
|
477
|
+
React.createElement(Pager.Item, { next: true, href: "#", disabled: activeIdx >= (that.props.formData || []).length - 1 || activeIdx === undefined, onClick: this.navigateNext },
|
|
478
|
+
translations.Next,
|
|
479
|
+
" \u2192"))));
|
|
480
|
+
if (affixed) {
|
|
481
|
+
const offset = this.props.formContext.topOffset - (that.state.scrollHeightFixed);
|
|
482
|
+
header = (React.createElement(components_1.Affix, { getContainer: this.getContainerRef, topOffset: offset, onAffixChange: this.onHeaderAffixChange }, header));
|
|
483
|
+
}
|
|
484
|
+
const { Panel } = this.context.theme;
|
|
485
|
+
return (React.createElement("div", { className: "laji-form-single-active-array", ref: this.setContainerRef },
|
|
486
|
+
React.createElement("div", { className: "laji-form-field-template-item" },
|
|
487
|
+
React.createElement("div", { className: "laji-form-field-template-schema" },
|
|
488
|
+
React.createElement(Panel, { className: "laji-form-panel" },
|
|
489
|
+
React.createElement(Panel.Heading, null, header),
|
|
490
|
+
React.createElement(Panel.Body, null,
|
|
491
|
+
React.createElement("div", { key: utils_1.getUUID(this.props.formData[activeIdx]) || activeIdx }, activeIdx !== undefined && arrayTemplateFieldProps.items && arrayTemplateFieldProps.items[activeIdx] ? arrayTemplateFieldProps.items[activeIdx].children : null))),
|
|
492
|
+
ArrayFieldTemplate_1.getButtonElems(buttons, arrayTemplateFieldProps)),
|
|
493
|
+
React.createElement("div", { className: "laji-form-field-template-buttons" }, activeIdx !== undefined && arrayTemplateFieldProps.items[activeIdx].hasRemove
|
|
494
|
+
? (React.createElement(components_1.DeleteButton, { id: `${that.props.idSchema.$id}_${utils_1.getFormDataIndex(activeIdx, that.props.uiSchema)}`, ref: this.setDeleteButtonRef(activeIdx), className: "pull-right", confirm: confirmDelete, translations: translations, onClick: that.onDelete(arrayTemplateFieldProps.items[activeIdx]) }))
|
|
495
|
+
: null))));
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
PagerArrayFieldTemplate.contextType = ReactContext_1.default;
|
|
499
|
+
PagerArrayFieldTemplate = __decorate([
|
|
500
|
+
handlesButtonsAndFocus
|
|
501
|
+
], PagerArrayFieldTemplate);
|
|
502
|
+
let UncontrolledArrayFieldTemplate = class UncontrolledArrayFieldTemplate extends React.Component {
|
|
503
|
+
render() {
|
|
504
|
+
const that = this.props.formContext.this;
|
|
505
|
+
const arrayTemplateFieldProps = this.props;
|
|
506
|
+
const activeIdx = that.state.activeIdx;
|
|
507
|
+
const TitleFieldTemplate = utils_4.getTemplate("TitleFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
|
|
508
|
+
const DescriptionFieldTemplate = utils_4.getTemplate("DescriptionFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
|
|
509
|
+
const { Label } = this.props.formContext;
|
|
510
|
+
const Title = utils_1.getUiOptions(that.props.uiSchema).renderTitleAsLabel ? Label : TitleFieldTemplate;
|
|
511
|
+
const title = utils_1.getTitle(this.props, activeIdx);
|
|
512
|
+
const titleUiSchema = Object.assign(Object.assign({}, arrayTemplateFieldProps.uiSchema), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(arrayTemplateFieldProps.uiSchema)), { titleFormatters: that.props.uiSchema.titleFormatters }) });
|
|
513
|
+
return activeIdx !== undefined && arrayTemplateFieldProps.items && arrayTemplateFieldProps.items[activeIdx] ?
|
|
514
|
+
React.createElement("div", { key: utils_1.getUUID(this.props.formData[activeIdx]) || activeIdx },
|
|
515
|
+
React.createElement(Title, { title: title, label: title, schema: this.props.schema, uiSchema: titleUiSchema, formData: that.props.formData, registry: this.props.registry }),
|
|
516
|
+
React.createElement(DescriptionFieldTemplate, { description: this.props.uiSchema["ui:description"], schema: this.props.schema }),
|
|
517
|
+
arrayTemplateFieldProps.items[activeIdx].children)
|
|
518
|
+
: null;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
UncontrolledArrayFieldTemplate = __decorate([
|
|
522
|
+
handlesButtonsAndFocus
|
|
523
|
+
], UncontrolledArrayFieldTemplate);
|
|
524
|
+
let TableArrayFieldTemplate = class TableArrayFieldTemplate extends React.Component {
|
|
525
|
+
constructor(props) {
|
|
526
|
+
super(props);
|
|
527
|
+
this.mouseCache = { enter: {}, leave: {}, keydown: {} };
|
|
528
|
+
this.onResize = () => {
|
|
529
|
+
this.updateLayout();
|
|
530
|
+
};
|
|
531
|
+
// Sets state.normalRendering on if screen is too small for table layout.
|
|
532
|
+
this.updateRenderingMode = (callback) => {
|
|
533
|
+
const _callback = (updateLayout = true) => {
|
|
534
|
+
if (updateLayout && this._lastWidth && utils_1.pixelsToBsSize(this._lastWidth) !== utils_1.pixelsToBsSize(window.innerWidth)) {
|
|
535
|
+
this.updateLayout(null, callback);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
const that = this.props.formContext.this;
|
|
539
|
+
const { normalRenderingTreshold } = utils_1.getUiOptions(this.props.uiSchema);
|
|
540
|
+
let initialized = false;
|
|
541
|
+
if (Object.keys(this.state).length === 0) {
|
|
542
|
+
initialized = true;
|
|
543
|
+
const state = this.getStyles();
|
|
544
|
+
if (state) {
|
|
545
|
+
this.setState(state, _callback);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (!normalRenderingTreshold) {
|
|
549
|
+
if (!initialized) {
|
|
550
|
+
_callback();
|
|
551
|
+
}
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
let treshold = utils_1.bsSizeToPixels(normalRenderingTreshold);
|
|
555
|
+
requestAnimationFrame(() => {
|
|
556
|
+
let normalRendering = undefined;
|
|
557
|
+
if (!this.state.normalRendering && window.innerWidth <= treshold) {
|
|
558
|
+
normalRendering = true;
|
|
559
|
+
}
|
|
560
|
+
else if (this.state.normalRendering && window.innerWidth > treshold) {
|
|
561
|
+
normalRendering = false;
|
|
562
|
+
}
|
|
563
|
+
if (normalRendering !== undefined) {
|
|
564
|
+
that.updateRenderingMode(normalRendering, () => this.setState({ normalRendering }, () => this.updateLayout(null, () => _callback(false))));
|
|
565
|
+
}
|
|
566
|
+
else if (!this.state.normalRendering) {
|
|
567
|
+
this.updateLayout(null, _callback);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
this.setActiveRef = (elem) => {
|
|
572
|
+
this.activeElem = elem;
|
|
573
|
+
this.activeElem && this.resizeObserver.observe(this.activeElem);
|
|
574
|
+
};
|
|
575
|
+
this.setTHeadRef = (elem) => {
|
|
576
|
+
this.tHeadRef = elem;
|
|
577
|
+
};
|
|
578
|
+
this.updateLayout = (idx = null, callback) => {
|
|
579
|
+
requestAnimationFrame(() => {
|
|
580
|
+
this._lastWidth = window.innerWidth;
|
|
581
|
+
const scrollBack = this.props.formContext.utils.shouldSyncScroll();
|
|
582
|
+
const state = this.getStyles();
|
|
583
|
+
if (!state) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
if (idx !== null)
|
|
587
|
+
state.activeIdx = idx;
|
|
588
|
+
const _callback = () => {
|
|
589
|
+
if (scrollBack) {
|
|
590
|
+
this.props.formContext.utils.syncScroll(!!"force");
|
|
591
|
+
}
|
|
592
|
+
if (callback)
|
|
593
|
+
callback();
|
|
594
|
+
};
|
|
595
|
+
this.setState(state, _callback);
|
|
596
|
+
});
|
|
597
|
+
};
|
|
598
|
+
this.getStyles = () => {
|
|
599
|
+
const that = this.props.formContext.this;
|
|
600
|
+
const { activeIdx } = that.state;
|
|
601
|
+
const { activeHeightOffset = 0 } = utils_1.getUiOptions(this.props.uiSchema);
|
|
602
|
+
const rowElem = this.itemElems[activeIdx];
|
|
603
|
+
if (!rowElem || !this.activeElem)
|
|
604
|
+
return;
|
|
605
|
+
return {
|
|
606
|
+
activeStyle: activeIdx !== undefined ? {
|
|
607
|
+
position: "absolute",
|
|
608
|
+
top: rowElem.offsetTop,
|
|
609
|
+
width: "100%",
|
|
610
|
+
right: 0
|
|
611
|
+
} : {},
|
|
612
|
+
activeTrStyle: activeIdx !== undefined ? {
|
|
613
|
+
height: this.activeElem.offsetHeight + activeHeightOffset
|
|
614
|
+
} : {}
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
this.getDeleteButtonRef = (idx) => {
|
|
618
|
+
const that = this.props.formContext.this;
|
|
619
|
+
that.deleteButtonRefSetters[idx] = that.deleteButtonRefSetters[idx]
|
|
620
|
+
|| (elem => {
|
|
621
|
+
that.deleteButtonRefs[idx] = elem;
|
|
622
|
+
});
|
|
623
|
+
return that.deleteButtonRefSetters[idx];
|
|
624
|
+
};
|
|
625
|
+
this.customEventSender = memoize((eventName) => memoize((idx) => () => {
|
|
626
|
+
const that = this.props.formContext.this;
|
|
627
|
+
that.props.formContext.services.customEvents.send(that.props.idSchema.$id, eventName, { idx });
|
|
628
|
+
}));
|
|
629
|
+
this.onKeyDownActivate = memoize((idx) => (e) => {
|
|
630
|
+
if (idx !== this.state.activeIdx && (e.key === " " || e.key === "Enter")) {
|
|
631
|
+
this.getOnChangeActive(idx)();
|
|
632
|
+
e.preventDefault();
|
|
633
|
+
e.stopPropagation();
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
this.getOnChangeActive = memoize(idx => () => {
|
|
637
|
+
const that = this.props.formContext.this;
|
|
638
|
+
idx !== that.state.activeIdx && that.onActiveChange(idx, undefined, this.updateLayout);
|
|
639
|
+
});
|
|
640
|
+
this.getOnHeaderClick = memoize((col, onSortToggle) => () => onSortToggle(col));
|
|
641
|
+
this.state = {};
|
|
642
|
+
this.itemElems = [];
|
|
643
|
+
this.resizeObserver = new ResizeObserver(this.onResize);
|
|
644
|
+
}
|
|
645
|
+
componentDidMount() {
|
|
646
|
+
this._updateRenderingMode = () => this.updateRenderingMode();
|
|
647
|
+
window.addEventListener("resize", this._updateRenderingMode);
|
|
648
|
+
this.updateRenderingMode();
|
|
649
|
+
this._prevCheckedLength = this.props.items.length;
|
|
650
|
+
}
|
|
651
|
+
componentWillUnmount() {
|
|
652
|
+
window.removeEventListener("resize", this._updateRenderingMode);
|
|
653
|
+
this.resizeObserver.disconnect();
|
|
654
|
+
}
|
|
655
|
+
componentDidUpdate(prevProps, prevState) {
|
|
656
|
+
const that = this.props.formContext.this;
|
|
657
|
+
let updated = false;
|
|
658
|
+
if (this.props.items.length !== prevProps.items.length || this.state.activeIdx !== prevState.activeIdx) {
|
|
659
|
+
if (!this.state.normalRendering && this.props.items.length === 1 && this.state.activeIdx === 0) {
|
|
660
|
+
this.updateRenderingMode();
|
|
661
|
+
updated = true;
|
|
662
|
+
}
|
|
663
|
+
else if (this.state.normalRendering && this.props.items.length > 1 || this.state.activeIdx !== 0) {
|
|
664
|
+
this.updateRenderingMode();
|
|
665
|
+
updated = true;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (!updated) {
|
|
669
|
+
const activeChanged = this.state.activeIdx !== that.state.activeIdx;
|
|
670
|
+
const itemsLengthChanged = this._prevCheckedLength !== this.props.items.length;
|
|
671
|
+
let tHeadHeight, tHeadHeightChanged;
|
|
672
|
+
if (this.tHeadRef) {
|
|
673
|
+
tHeadHeight = this.tHeadRef.scrollHeight;
|
|
674
|
+
tHeadHeightChanged = this.prevTHeadHeight && tHeadHeight !== this.prevTHeadHeight;
|
|
675
|
+
}
|
|
676
|
+
if (activeChanged || itemsLengthChanged || tHeadHeightChanged) {
|
|
677
|
+
this.updateLayout(this.props.formContext.this.state.activeIdx);
|
|
678
|
+
}
|
|
679
|
+
if (tHeadHeight)
|
|
680
|
+
this.prevTHeadHeight = tHeadHeight;
|
|
681
|
+
this._prevCheckedLength = this.props.items.length;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
getSortableHeaderProps(col, props) {
|
|
685
|
+
const { onSortToggle, sortCols, ui, sortableColumns, sortColTooltips } = utils_1.getUiOptions(props.uiSchema);
|
|
686
|
+
if (!onSortToggle || sortableColumns && !sortableColumns.includes(col)) {
|
|
687
|
+
return {};
|
|
688
|
+
}
|
|
689
|
+
const sortCol = sortCols.find(({ name }) => name === col);
|
|
690
|
+
const className = utils_1.classNames((sortCol === null || sortCol === void 0 ? void 0 : sortCol.descending)
|
|
691
|
+
? "laji-form-col-desc"
|
|
692
|
+
: (sortCol === null || sortCol === void 0 ? void 0 : sortCol.descending) === false
|
|
693
|
+
? "laji-form-col-asc"
|
|
694
|
+
: undefined, "laji-form-col-sortable");
|
|
695
|
+
const tooltip = sortColTooltips[col] || props.formContext.translations["ClickToSort"];
|
|
696
|
+
return { onClick: this.getOnHeaderClick(col, onSortToggle), className, ui: ui[col], role: "button", tooltip };
|
|
697
|
+
}
|
|
698
|
+
render() {
|
|
699
|
+
if (this.state.normalRendering) {
|
|
700
|
+
return React.createElement(ArrayFieldTemplate_1.default, Object.assign({}, this.props));
|
|
701
|
+
}
|
|
702
|
+
const { schema, uiSchema = {}, formData = [], items, disabled, readonly } = this.props;
|
|
703
|
+
const TitleFieldTemplate = utils_4.getTemplate("TitleFieldTemplate", this.props.registry, utils_1.getUiOptions(uiSchema));
|
|
704
|
+
const DescriptionFieldTemplate = utils_4.getTemplate("DescriptionFieldTemplate", this.props.registry, utils_1.getUiOptions(uiSchema));
|
|
705
|
+
const { renderTitleAsLabel, formatters = {}, shownColumns = [], removable = true } = utils_1.getUiOptions(uiSchema);
|
|
706
|
+
const { Label } = this.props.formContext;
|
|
707
|
+
const Title = renderTitleAsLabel ? Label : TitleFieldTemplate;
|
|
708
|
+
const foundProps = {};
|
|
709
|
+
const shownColumnsDict = utils_1.dictionarify(shownColumns);
|
|
710
|
+
const { tmpImgs = {} } = Context_1.default("IMAGE_ARRAY_FIELD");
|
|
711
|
+
let cols = Object.keys(schema.items.properties).reduce((_cols, prop) => {
|
|
712
|
+
if (formData.some(item => {
|
|
713
|
+
const found = shownColumnsDict[prop]
|
|
714
|
+
|| foundProps[prop]
|
|
715
|
+
|| (prop in item
|
|
716
|
+
&& !utils_1.isEmptyString(item[prop])
|
|
717
|
+
&& (!Array.isArray(item[prop])
|
|
718
|
+
|| Array.isArray(item[prop]) && !item[prop].every(utils_1.isEmptyString))
|
|
719
|
+
&& !utils_1.isDefaultData(item[prop], schema.items.properties[prop])
|
|
720
|
+
&& !utils_1.isHidden(uiSchema.items || {}, prop)
|
|
721
|
+
&& !utils_1.isHidden(utils_1.getNestedTailUiSchema(uiSchema.items || {}), prop))
|
|
722
|
+
|| uiSchema.items && uiSchema.items[prop] && uiSchema.items[prop]["ui:field"] === "ImageArrayField" && utils_1.getUUID(item) && tmpImgs[utils_1.getUUID(item)];
|
|
723
|
+
if (found)
|
|
724
|
+
foundProps[prop] = true;
|
|
725
|
+
return found;
|
|
726
|
+
})) {
|
|
727
|
+
_cols.push(prop);
|
|
728
|
+
}
|
|
729
|
+
return _cols;
|
|
730
|
+
}, []);
|
|
731
|
+
const { "ui:order": order } = (uiSchema.items || {});
|
|
732
|
+
if (order)
|
|
733
|
+
cols = utils_2.orderProperties(cols, order.filter(field => field === "*" || foundProps[field]));
|
|
734
|
+
const that = this.props.formContext.this;
|
|
735
|
+
const { errorSchema } = that.props;
|
|
736
|
+
const activeIdx = that.state.activeIdx;
|
|
737
|
+
const { confirmDelete } = utils_1.getUiOptions(uiSchema);
|
|
738
|
+
const getDeleteButtonFor = (idx, item) => {
|
|
739
|
+
return removable && React.createElement(components_1.DeleteButton, { id: `${that.props.idSchema.$id}_${idx}`, disabled: disabled || readonly, ref: this.getDeleteButtonRef(idx), key: utils_1.getUUID(this.props.formData[item.index]) || item.key, confirm: confirmDelete, translations: this.props.formContext.translations, onClick: that.onDelete(item) });
|
|
740
|
+
};
|
|
741
|
+
const setItemRef = idx => elem => {
|
|
742
|
+
this.itemElems[idx] = elem;
|
|
743
|
+
};
|
|
744
|
+
const title = utils_1.getTitle(this.props, that.state.activeIdx);
|
|
745
|
+
const onMouseEnter = this.customEventSender("startHighlight");
|
|
746
|
+
const onMouseLeave = this.customEventSender("endHighlight");
|
|
747
|
+
const { Table } = this.context.theme;
|
|
748
|
+
return (React.createElement("div", { style: { position: "relative" }, className: "single-active-array-table-container" },
|
|
749
|
+
React.createElement(Title, { title: title, label: title, uiSchema: uiSchema, schema: schema, formData: formData, registry: this.props.registry }),
|
|
750
|
+
React.createElement(DescriptionFieldTemplate, { description: uiSchema["ui:description"], schema: this.props.schema }),
|
|
751
|
+
React.createElement("div", { className: "laji-form-field-template-item" },
|
|
752
|
+
React.createElement("div", { className: "table-responsive laji-form-field-template-schema" },
|
|
753
|
+
React.createElement(Table, { hover: true, bordered: true, condensed: true, className: "single-active-array-table" },
|
|
754
|
+
items.length > 1 || (that.state.activeIdx !== undefined && that.state.activeIdx !== 0) ? (React.createElement("thead", { ref: this.setTHeadRef },
|
|
755
|
+
React.createElement("tr", null,
|
|
756
|
+
cols.length ? cols.map(col => {
|
|
757
|
+
const sortableHeaderProps = this.getSortableHeaderProps(col, this.props);
|
|
758
|
+
const { ui, tooltip } = sortableHeaderProps, _sortableHeaderProps = __rest(sortableHeaderProps, ["ui", "tooltip"]);
|
|
759
|
+
const className = utils_1.classNames("darker", sortableHeaderProps.className);
|
|
760
|
+
return (React.createElement(components_1.TooltipComponent, { key: col, tooltip: tooltip, placement: "top" },
|
|
761
|
+
React.createElement("th", Object.assign({ key: col }, _sortableHeaderProps, { className: className }),
|
|
762
|
+
((uiSchema.items || {})[col] || {})["ui:title"] || schema.items.properties[col].title,
|
|
763
|
+
ui || null)));
|
|
764
|
+
}) : React.createElement("th", { className: "darker" }),
|
|
765
|
+
React.createElement("th", { key: "_activeContent", className: "single-active-array-table-content-col" }),
|
|
766
|
+
React.createElement("th", { key: "_delete", className: "single-active-array-table-delete" })))) : null,
|
|
767
|
+
React.createElement("tbody", null, formData.map((_, idx) => {
|
|
768
|
+
const item = items[idx];
|
|
769
|
+
let className = "";
|
|
770
|
+
if (utils_1.filteredErrors(errorSchema)[utils_1.getFormDataIndex(idx, uiSchema)])
|
|
771
|
+
className = className ? `${className} bg-danger` : "bg-danger";
|
|
772
|
+
return [
|
|
773
|
+
React.createElement("tr", { key: utils_1.getUUID(this.props.formData[item.index]) || item.key, onClick: this.getOnChangeActive(idx), className: className, tabIndex: idx === activeIdx ? undefined : 0, id: idx !== activeIdx ? `_laji-form_${this.props.formContext.contextId}_${ArrayField_2.ArrayFieldPatched.prototype.getIdSchema(this.props, idx).$id}` : undefined, ref: setItemRef(idx), style: idx === activeIdx ? this.state.activeTrStyle : undefined, onMouseEnter: onMouseEnter(idx), onMouseLeave: onMouseLeave(idx), onKeyDown: this.onKeyDownActivate(idx) },
|
|
774
|
+
cols.length ? cols.map(col => React.createElement("td", { key: col }, utils_1.formatValue(Object.assign(Object.assign({}, that.props), { schema: schema.items.properties[col], uiSchema: (uiSchema.items || {})[col], formData: formData[idx][col] }), formatters[col], { formData: formData[idx] }))) : React.createElement("td", null),
|
|
775
|
+
(activeIdx !== undefined && items[activeIdx] && idx === activeIdx) ? (React.createElement("td", { key: utils_1.getUUID(formData[activeIdx]) || activeIdx, className: "single-active-array-table-content-col" },
|
|
776
|
+
React.createElement("div", { className: "laji-form-field-template-item keep-vertical", style: this.state.activeStyle, ref: this.setActiveRef },
|
|
777
|
+
React.createElement("div", { className: "laji-form-field-template-schema" }, items[activeIdx].children),
|
|
778
|
+
React.createElement("div", { className: "laji-form-field-template-buttons" })))) : React.createElement("td", { className: "single-active-array-table-content-col" }),
|
|
779
|
+
React.createElement("td", { key: "delete", className: "delete-button-container" }, getDeleteButtonFor(idx, item)))
|
|
780
|
+
];
|
|
781
|
+
})))),
|
|
782
|
+
React.createElement("div", { className: "laji-form-field-template-buttons" })),
|
|
783
|
+
React.createElement(ButtonsWrapper, { props: this.props })));
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
TableArrayFieldTemplate.contextType = ReactContext_1.default;
|
|
787
|
+
TableArrayFieldTemplate = __decorate([
|
|
788
|
+
handlesButtonsAndFocus
|
|
789
|
+
], TableArrayFieldTemplate);
|
|
790
|
+
const headerFormatters = {
|
|
791
|
+
units: {
|
|
792
|
+
component: (props) => {
|
|
793
|
+
const { that: { props: { formContext: { translations }, formData } }, idx } = props;
|
|
794
|
+
const item = formData[idx];
|
|
795
|
+
const unitsLength = (item && item.units && "length" in item.units) ?
|
|
796
|
+
item.units.filter(unit => unit &&
|
|
797
|
+
unit.identifications &&
|
|
798
|
+
unit.identifications[0] &&
|
|
799
|
+
unit.identifications[0].taxon).length
|
|
800
|
+
: 0;
|
|
801
|
+
return (React.createElement("span", { className: "text-muted" }, ` (${unitsLength} ${translations.unitsPartitive})`));
|
|
802
|
+
},
|
|
803
|
+
onClick: (that, idx) => {
|
|
804
|
+
if (that.state.activeIdx === idx) {
|
|
805
|
+
headerFormatters.units.onMouseEnter(that, idx, !!"use the force");
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
headerFormatters.units.onMouseLeave(that);
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
onMouseEnter: (that, idx, force) => {
|
|
812
|
+
const { props: { formData } } = that;
|
|
813
|
+
const item = formData[idx];
|
|
814
|
+
that.hoveredIdx = idx;
|
|
815
|
+
if (!force && idx === that.state.activeIdx)
|
|
816
|
+
return;
|
|
817
|
+
const map = Context_1.default(`${that.props.formContext.contextId}_MAP`).map;
|
|
818
|
+
const gatheringGeometries = (item && item.geometry && item.geometry.geometries) ? item.geometry.geometries : [];
|
|
819
|
+
const unitGeometries = [...(item && item.units ? item.units : [])]
|
|
820
|
+
.filter(unit => unit.unitGathering && utils_1.hasData(unit.unitGathering.geometry))
|
|
821
|
+
.map(unit => unit.unitGathering.geometry);
|
|
822
|
+
const geometries = [...gatheringGeometries, ...unitGeometries]
|
|
823
|
+
.map(geometry => {
|
|
824
|
+
return { type: "Feature", properties: {}, geometry };
|
|
825
|
+
});
|
|
826
|
+
map.addData({
|
|
827
|
+
featureCollection: { type: "featureCollection", features: geometries },
|
|
828
|
+
getFeatureStyle: () => ({ opacity: 0.6, color: "#888888" }),
|
|
829
|
+
temp: true
|
|
830
|
+
});
|
|
831
|
+
},
|
|
832
|
+
onMouseLeave: (that) => {
|
|
833
|
+
const map = Context_1.default(`${that.props.formContext.contextId}_MAP`).map;
|
|
834
|
+
const lastData = map.data[map.data.length - 1];
|
|
835
|
+
if (lastData && lastData.temp) {
|
|
836
|
+
map.removeData(map.data.length - 1);
|
|
837
|
+
}
|
|
838
|
+
that.hoveredIdx = undefined;
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
namedPlace: {
|
|
842
|
+
component: class NamedPlaceHeader extends React.Component {
|
|
843
|
+
constructor(props) {
|
|
844
|
+
super(props);
|
|
845
|
+
this.fetch = (props) => {
|
|
846
|
+
const { namedPlaceID } = (props.that.props.formData || {})[props.idx] || {};
|
|
847
|
+
if (namedPlaceID)
|
|
848
|
+
props.that.props.formContext.apiClient.fetchCached(`/named-places/${namedPlaceID}`, undefined, { failSilently: true }).then(response => {
|
|
849
|
+
if (this.mounted && response.name !== this.state.name)
|
|
850
|
+
this.setState({
|
|
851
|
+
namedPlaceID,
|
|
852
|
+
name: response.name
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
};
|
|
856
|
+
this.state = {};
|
|
857
|
+
}
|
|
858
|
+
componentDidMount() {
|
|
859
|
+
this.mounted = true;
|
|
860
|
+
this.fetch(this.props);
|
|
861
|
+
}
|
|
862
|
+
componentWillUnmount() {
|
|
863
|
+
this.mounted = false;
|
|
864
|
+
}
|
|
865
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
866
|
+
this.fetch(props);
|
|
867
|
+
}
|
|
868
|
+
render() {
|
|
869
|
+
const { name } = this.state;
|
|
870
|
+
const { locality } = (this.props.that.props.formData || {})[this.props.idx] || {};
|
|
871
|
+
return React.createElement("span", { className: "text-muted" }, !utils_1.isEmptyString(name) ? name : locality);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
lineTransect: {
|
|
876
|
+
component: (props) => {
|
|
877
|
+
let start, end;
|
|
878
|
+
const lineTransectFeature = Object.keys((props.that.props.formData || [])[0].geometry || {}).length
|
|
879
|
+
? { type: "Feature", properties: {}, geometry: { type: "MultiLineString", coordinates: props.that.props.formData.map(item => item.geometry.coordinates) } }
|
|
880
|
+
: undefined;
|
|
881
|
+
if (lineTransectFeature)
|
|
882
|
+
[start, end] = utils_3.getLineTransectStartEndDistancesForIdx(lineTransectFeature, props.idx, 10);
|
|
883
|
+
return props.idx !== undefined && end ? React.createElement("span", { className: "text-muted" }, `${start}-${end}m`) : null;
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
number: {
|
|
887
|
+
component: (props) => {
|
|
888
|
+
return props.idx !== undefined ? (props.idx + 1) + "." : null;
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
lolife: {
|
|
892
|
+
onMouseEnter: (that, idx) => {
|
|
893
|
+
that.props.formContext.services.customEvents.send(that.props.idSchema.$id, "startHighlight", { id: utils_1.getUUID(that.props.formData[idx]) });
|
|
894
|
+
},
|
|
895
|
+
onMouseLeave: (that, idx) => {
|
|
896
|
+
that.props.formContext.services.customEvents.send(that.props.idSchema.$id, "endHighlight", { id: utils_1.getUUID(that.props.formData[idx]) });
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
class AccordionHeader extends React.Component {
|
|
901
|
+
constructor() {
|
|
902
|
+
super(...arguments);
|
|
903
|
+
this.onHeaderClick = () => {
|
|
904
|
+
const { that, idx, canHaveUndefinedIdx = true } = this.props;
|
|
905
|
+
const formatters = this.getFormatters();
|
|
906
|
+
if (!canHaveUndefinedIdx) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
that.onActiveChange(idx);
|
|
910
|
+
formatters.forEach(formatter => { formatter.onClick && formatter.onClick(that, idx); });
|
|
911
|
+
};
|
|
912
|
+
this.onMouseEnter = () => {
|
|
913
|
+
this.getFormatters().forEach(formatter => {
|
|
914
|
+
formatter.onMouseEnter && formatter.onMouseEnter(this.props.that, this.props.idx);
|
|
915
|
+
});
|
|
916
|
+
};
|
|
917
|
+
this.onMouseLeave = () => {
|
|
918
|
+
this.getFormatters().forEach(formatter => {
|
|
919
|
+
formatter.onMouseLeave && formatter.onMouseLeave(this.props.that, this.props.idx);
|
|
920
|
+
});
|
|
921
|
+
};
|
|
922
|
+
this.getFormatters = () => {
|
|
923
|
+
const { that } = this.props;
|
|
924
|
+
const { uiSchema, schema } = that.props;
|
|
925
|
+
const formData = (that.props.formData || {})[this.props.idx];
|
|
926
|
+
// try both headerFormatters & headerFormatter for backward compatibility. TODO: Remove in future.
|
|
927
|
+
const options = utils_1.getUiOptions(uiSchema);
|
|
928
|
+
let _headerFormatters = options.headerFormatters || options.headerFormatter || [];
|
|
929
|
+
if (_headerFormatters && !Array.isArray(_headerFormatters))
|
|
930
|
+
_headerFormatters = [_headerFormatters];
|
|
931
|
+
if (options.headerFormatter) {
|
|
932
|
+
console.warn("laji-form warning: 'headerFormatter' is deprecated. Use 'headerFormatters' instead.");
|
|
933
|
+
}
|
|
934
|
+
return _headerFormatters.map(formatter => {
|
|
935
|
+
if (headerFormatters[formatter])
|
|
936
|
+
return headerFormatters[formatter];
|
|
937
|
+
else
|
|
938
|
+
return {
|
|
939
|
+
component: () => {
|
|
940
|
+
const { field, default: _default } = utils_1.isObject(formatter) ? formatter : { field: formatter };
|
|
941
|
+
const formattedValue = utils_1.formatValue(Object.assign(Object.assign({}, that.props), { schema: utils_1.parseSchemaFromFormDataPointer(schema.items, field), uiSchema: utils_1.parseUiSchemaFromFormDataPointer(uiSchema.items, field), formData: utils_1.parseJSONPointer(formData, field, !!"safely") }));
|
|
942
|
+
const value = utils_1.isEmptyString(formattedValue) ? _default : formattedValue;
|
|
943
|
+
return React.createElement("span", { className: "text-muted" }, value);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
render() {
|
|
950
|
+
const { that, idx } = this.props;
|
|
951
|
+
const title = utils_1.getTitle(that.props, idx);
|
|
952
|
+
const popupData = that.state.popups[idx];
|
|
953
|
+
const { uiSchema } = that.props;
|
|
954
|
+
const hasHelp = uiSchema && uiSchema["ui:help"];
|
|
955
|
+
const headerText = (React.createElement("span", null,
|
|
956
|
+
title,
|
|
957
|
+
this.getFormatters().map((formatter, i) => {
|
|
958
|
+
const { component: Formatter } = formatter;
|
|
959
|
+
return Formatter && (React.createElement("span", { key: i },
|
|
960
|
+
" ",
|
|
961
|
+
React.createElement(Formatter, { that: that, idx: idx }))) || null;
|
|
962
|
+
}),
|
|
963
|
+
hasHelp ? React.createElement(components_1.Help, null) : null));
|
|
964
|
+
const headerTextComponent = hasHelp ? React.createElement(components_1.TooltipComponent, { tooltip: uiSchema["ui:help"] }, headerText) : headerText;
|
|
965
|
+
const header = (React.createElement("div", { className: this.props.className, role: "tab", id: `${that.props.idSchema.$id}_${utils_1.getFormDataIndex(idx, that.props.uiSchema)}-header`, onClick: this.onHeaderClick, onMouseEnter: this.onMouseEnter, onMouseLeave: this.onMouseLeave },
|
|
966
|
+
React.createElement("div", { className: this.props.wrapperClassName },
|
|
967
|
+
headerTextComponent,
|
|
968
|
+
this.props.children)));
|
|
969
|
+
const { OverlayTrigger, Tooltip } = this.context.theme;
|
|
970
|
+
return utils_1.hasData(popupData) ? (React.createElement(OverlayTrigger, { placement: "left", overlay: React.createElement(Tooltip, { id: "nav-tooltip-" + idx },
|
|
971
|
+
React.createElement(Popup, { data: popupData })) }, header)) : (header);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
AccordionHeader.contextType = ReactContext_1.default;
|