@luomus/laji-form 15.1.5 → 15.1.7
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/test-export/test-utils.d.ts +3 -2
- package/test-export/test-utils.js +14 -13
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const React = require("react");
|
|
15
|
+
const react_dom_1 = require("react-dom");
|
|
16
|
+
const PropTypes = require("prop-types");
|
|
17
|
+
const validation_1 = require("../validation");
|
|
18
|
+
const validation_2 = require("../validation");
|
|
19
|
+
const components_1 = require("./components");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const equals = require("deep-equal");
|
|
22
|
+
const validator_ajv6_1 = require("@rjsf/validator-ajv6");
|
|
23
|
+
const merge = require("deepmerge");
|
|
24
|
+
const ReactContext_1 = require("../ReactContext");
|
|
25
|
+
const stub_1 = require("../themes/stub");
|
|
26
|
+
const core_1 = require("@rjsf/core");
|
|
27
|
+
const ApiClient_1 = require("../ApiClient");
|
|
28
|
+
const Context_1 = require("../Context");
|
|
29
|
+
const translations = require("../translations.json");
|
|
30
|
+
const key_handler_service_1 = require("../services/key-handler-service");
|
|
31
|
+
const settings_service_1 = require("../services/settings-service");
|
|
32
|
+
const focus_service_1 = require("../services/focus-service");
|
|
33
|
+
const blocker_service_1 = require("../services/blocker-service");
|
|
34
|
+
const custom_event_service_1 = require("../services/custom-event-service");
|
|
35
|
+
const submit_hook_service_1 = require("../services/submit-hook-service");
|
|
36
|
+
const dom_id_service_1 = require("../services/dom-id-service");
|
|
37
|
+
const id_service_1 = require("../services/id-service");
|
|
38
|
+
const root_instance_service_1 = require("../services/root-instance-service");
|
|
39
|
+
const singleton_map_service_1 = require("../services/singleton-map-service");
|
|
40
|
+
const fields = importLocalComponents("fields", [
|
|
41
|
+
"SchemaField",
|
|
42
|
+
{ "ArraySchemaField": "SchemaField" },
|
|
43
|
+
"ArrayField",
|
|
44
|
+
"ObjectField",
|
|
45
|
+
"NestField",
|
|
46
|
+
"ArrayBulkField",
|
|
47
|
+
"ArrayBulkField",
|
|
48
|
+
"ScopeField",
|
|
49
|
+
"SelectTreeField",
|
|
50
|
+
"GridLayoutField",
|
|
51
|
+
"TableField",
|
|
52
|
+
"InjectField",
|
|
53
|
+
"InjectDefaultValueField",
|
|
54
|
+
"ArrayCombinerField",
|
|
55
|
+
"DependentBooleanField",
|
|
56
|
+
"DependentDisableField",
|
|
57
|
+
"MapArrayField",
|
|
58
|
+
"AutoArrayField",
|
|
59
|
+
"AutosuggestField",
|
|
60
|
+
"HiddenField",
|
|
61
|
+
"InitiallyHiddenField",
|
|
62
|
+
"ContextInjectionField",
|
|
63
|
+
"ImageArrayField",
|
|
64
|
+
"SplitField",
|
|
65
|
+
"FlatField",
|
|
66
|
+
"SingleActiveArrayField",
|
|
67
|
+
"SingleItemArrayField",
|
|
68
|
+
"UnitShorthandField",
|
|
69
|
+
"CombinedValueDisplayField",
|
|
70
|
+
"UiFieldMapperArrayField",
|
|
71
|
+
"ExtraLabelRowField",
|
|
72
|
+
"SumField",
|
|
73
|
+
"NamedPlaceChooserField",
|
|
74
|
+
"NamedPlaceSaverField",
|
|
75
|
+
"MapField",
|
|
76
|
+
"GeocoderField",
|
|
77
|
+
"TagArrayField",
|
|
78
|
+
"StringToArrayField",
|
|
79
|
+
"ConditionalOnChangeField",
|
|
80
|
+
"ConditionalUiSchemaField",
|
|
81
|
+
"AnnotationField",
|
|
82
|
+
"PrefillingArrayField",
|
|
83
|
+
"AnyToBooleanField",
|
|
84
|
+
"EnumRangeArrayField",
|
|
85
|
+
"UnitListShorthandArrayField",
|
|
86
|
+
"LocationChooserField",
|
|
87
|
+
"DataLeakerField",
|
|
88
|
+
"LocalityField",
|
|
89
|
+
"ImageDisplayField",
|
|
90
|
+
"FakePropertyField",
|
|
91
|
+
"SectionArrayField",
|
|
92
|
+
"MultiArrayField",
|
|
93
|
+
"AudioArrayField",
|
|
94
|
+
"FilterArrayField",
|
|
95
|
+
"MultiAnyToBooleanField",
|
|
96
|
+
"UnitCountShorthandField",
|
|
97
|
+
"ToggleAdditionalArrayFieldsField",
|
|
98
|
+
"DefaultValueArrayField",
|
|
99
|
+
"UiFieldApplierField",
|
|
100
|
+
"MultiLanguageField",
|
|
101
|
+
"SortArrayField",
|
|
102
|
+
"InputWithDefaultValueButtonField",
|
|
103
|
+
"MultiTagArrayField",
|
|
104
|
+
"PdfArrayField",
|
|
105
|
+
"AsArrayField",
|
|
106
|
+
{ "InputTransformerField": "ConditionalOnChangeField" },
|
|
107
|
+
{ "ConditionalField": "ConditionalUiSchemaField" },
|
|
108
|
+
{ "UnitRapidField": "UnitShorthandField" },
|
|
109
|
+
{ "AccordionArrayField": "SingleActiveArrayField" } // Alias for backward compatibility.
|
|
110
|
+
]);
|
|
111
|
+
const widgets = importLocalComponents("widgets", [
|
|
112
|
+
"CheckboxWidget",
|
|
113
|
+
"SelectWidget",
|
|
114
|
+
"TextareaWidget",
|
|
115
|
+
"DateTimeWidget",
|
|
116
|
+
"DateWidget",
|
|
117
|
+
"TimeWidget",
|
|
118
|
+
"SeparatedDateTimeWidget",
|
|
119
|
+
"AutosuggestWidget",
|
|
120
|
+
"HiddenWidget",
|
|
121
|
+
"PlainTextWidget",
|
|
122
|
+
"TextSelectWidget",
|
|
123
|
+
"ImageSelectWidget",
|
|
124
|
+
"AnyToBooleanWidget",
|
|
125
|
+
"URLWidget",
|
|
126
|
+
"InformalTaxonGroupChooserWidget",
|
|
127
|
+
"TaxonImageWidget",
|
|
128
|
+
"UpperCaseWidget",
|
|
129
|
+
"NumberWidget",
|
|
130
|
+
"InputGroupWidget",
|
|
131
|
+
"InputWithDefaultValueButtonWidget"
|
|
132
|
+
]);
|
|
133
|
+
const templates = importLocalComponents("templates", [
|
|
134
|
+
"BaseInputTemplate",
|
|
135
|
+
"DescriptionField",
|
|
136
|
+
{ "TitleFieldTemplate": "TitleField" },
|
|
137
|
+
{ "DescriptionFieldTemplate": "DescriptionField" },
|
|
138
|
+
"FieldTemplate",
|
|
139
|
+
"ArrayFieldTemplate",
|
|
140
|
+
"ErrorListTemplate",
|
|
141
|
+
"ObjectFieldTemplate"
|
|
142
|
+
]);
|
|
143
|
+
function importLocalComponents(dir, fieldNames) {
|
|
144
|
+
return fieldNames.reduce((fields, field) => {
|
|
145
|
+
if (typeof field === "string") {
|
|
146
|
+
fields[field] = require(`./${dir}/${field}`).default;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const fieldName = Object.keys(field)[0];
|
|
150
|
+
if (typeof field[fieldName] === "string") {
|
|
151
|
+
fields[fieldName] = require(`./${dir}/${field[fieldName]}`).default;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
fields[fieldName] = field[fieldName];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return fields;
|
|
158
|
+
}, {});
|
|
159
|
+
}
|
|
160
|
+
// Each form should have a unique id to keep Context private.
|
|
161
|
+
let id = 0;
|
|
162
|
+
function getNewId() {
|
|
163
|
+
const _id = id;
|
|
164
|
+
id++;
|
|
165
|
+
return _id;
|
|
166
|
+
}
|
|
167
|
+
class LajiForm extends React.Component {
|
|
168
|
+
constructor(props) {
|
|
169
|
+
super(props);
|
|
170
|
+
this.translations = this.constructTranslations();
|
|
171
|
+
this.bgJobRef = React.createRef();
|
|
172
|
+
this.shortcutHelpRef = React.createRef();
|
|
173
|
+
this.propagateSubmit = true;
|
|
174
|
+
this.formRef = React.createRef();
|
|
175
|
+
this.validating = false;
|
|
176
|
+
this.eventListeners = [];
|
|
177
|
+
this.timeouts = [];
|
|
178
|
+
this.onSubmitHooksChange = (submitHooks, callback) => {
|
|
179
|
+
this.setState({ submitHooks }, callback);
|
|
180
|
+
};
|
|
181
|
+
this.getDefaultNotifier = () => {
|
|
182
|
+
if (this.defaultNotifier)
|
|
183
|
+
return this.defaultNotifier;
|
|
184
|
+
this.defaultNotifier = ["success", "info", "warning", "error"].reduce((notifier, method) => {
|
|
185
|
+
notifier[method] = msg => console.warn(`Notification component not specified for LajiForm! Got '${method}'notification: '${msg}'`);
|
|
186
|
+
return notifier;
|
|
187
|
+
}, {});
|
|
188
|
+
return this.defaultNotifier;
|
|
189
|
+
};
|
|
190
|
+
this.onChange = ({ formData }) => {
|
|
191
|
+
this.setState({ formData }, () => {
|
|
192
|
+
if (this.props.onChange) {
|
|
193
|
+
const _formData = this.props.optimizeOnChange
|
|
194
|
+
? formData
|
|
195
|
+
: this.memoizedFormContext.services.ids.removeLajiFormIds(formData);
|
|
196
|
+
this.props.onChange(_formData);
|
|
197
|
+
}
|
|
198
|
+
this.memoizedFormContext.services.ids.setFormData(formData);
|
|
199
|
+
this.memoizedFormContext.services.rootInstance.setFormData(formData);
|
|
200
|
+
!this.validating && this.validate(!!"warnings", !"nonlive");
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
this.getFields = (_fields) => (Object.assign(Object.assign({}, fields), (_fields || {})));
|
|
204
|
+
this.getWidgets = (_widgets) => (Object.assign(Object.assign({}, widgets), (_widgets || {})));
|
|
205
|
+
this.getTemplates = (_templates) => (Object.assign(Object.assign({}, templates), (_templates || {})));
|
|
206
|
+
this.getContext = (props, context) => {
|
|
207
|
+
const nextKey = ["theme"].reduce((key, prop) => {
|
|
208
|
+
key[prop] = props[prop];
|
|
209
|
+
return key;
|
|
210
|
+
}, {});
|
|
211
|
+
if (this.contextMemoizeKey && Object.keys(this.contextMemoizeKey).every(k => this.contextMemoizeKey[k] === nextKey[k])) {
|
|
212
|
+
return this.memoizedContext;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this.contextMemoizeKey = nextKey;
|
|
216
|
+
this.memoizedContext = {
|
|
217
|
+
theme: props.theme || (context === null || context === void 0 ? void 0 : context.theme) || stub_1.default,
|
|
218
|
+
};
|
|
219
|
+
return this.memoizedContext;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
this.renderSubmitHooks = () => {
|
|
223
|
+
if (!this.state || !this.state.submitHooks)
|
|
224
|
+
return;
|
|
225
|
+
const jobsAmount = this.state.submitHooks.filter(({ failed }) => !failed).length;
|
|
226
|
+
const runningAmount = this.state.submitHooks.reduce((count, { running }) => running ? count + 1 : count, 0);
|
|
227
|
+
if (!this.state.runningSubmitHooks)
|
|
228
|
+
return null;
|
|
229
|
+
const { ProgressBar } = this.getContext(this.props, this.context).theme;
|
|
230
|
+
return (React.createElement("div", { className: "running-jobs" },
|
|
231
|
+
this.state.formContext.translations.PendingRunningJobs,
|
|
232
|
+
"... (",
|
|
233
|
+
jobsAmount - runningAmount + 1,
|
|
234
|
+
" / ",
|
|
235
|
+
jobsAmount,
|
|
236
|
+
")",
|
|
237
|
+
React.createElement(ProgressBar, { now: 100 / jobsAmount * (jobsAmount - runningAmount) })));
|
|
238
|
+
};
|
|
239
|
+
this.validateAndSubmit = (warnings = true, onlySchema = false) => {
|
|
240
|
+
const { formData } = this.state;
|
|
241
|
+
const { onValidationError, onSubmit } = this.props;
|
|
242
|
+
return this.validate(warnings, true, onlySchema).then((valid) => {
|
|
243
|
+
if (formData !== this.state.formData) {
|
|
244
|
+
this.validateAndSubmit(warnings, onlySchema);
|
|
245
|
+
}
|
|
246
|
+
else if (valid) {
|
|
247
|
+
onSubmit && onSubmit({ formData: this.memoizedFormContext.services.ids.removeLajiFormIds(formData) });
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
onValidationError && onValidationError(this.state.extraErrors);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
this.validate = (warnings = true, nonlive = true, onlySchema = false) => {
|
|
255
|
+
this.validating = true;
|
|
256
|
+
let live = true;
|
|
257
|
+
if (onlySchema) {
|
|
258
|
+
warnings = false;
|
|
259
|
+
nonlive = false;
|
|
260
|
+
live = false;
|
|
261
|
+
}
|
|
262
|
+
const block = nonlive || onlySchema;
|
|
263
|
+
const { formData } = this.state;
|
|
264
|
+
const { live: liveErrorValidators, rest: errorValidators } = splitLive(this.props.validators, this.props.schema.properties);
|
|
265
|
+
const { live: liveWarningValidators, rest: warningValidators } = splitLive(this.props.warnings, this.props.schema.properties);
|
|
266
|
+
let liveValidations = { errors: liveErrorValidators };
|
|
267
|
+
const validations = {};
|
|
268
|
+
if (!onlySchema && nonlive) {
|
|
269
|
+
validations.errors = errorValidators;
|
|
270
|
+
}
|
|
271
|
+
if (!onlySchema && warnings) {
|
|
272
|
+
liveValidations.warnings = liveWarningValidators;
|
|
273
|
+
if (nonlive) {
|
|
274
|
+
validations.warnings = warningValidators;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (!live) {
|
|
278
|
+
liveValidations = {};
|
|
279
|
+
}
|
|
280
|
+
const schemaErrors = nonlive || onlySchema
|
|
281
|
+
? validator_ajv6_1.default.validateFormData(formData, this.props.schema, undefined, ((e) => validation_2.transformErrors(this.state.formContext.translations, e))).errorSchema
|
|
282
|
+
: {};
|
|
283
|
+
block && this.memoizedFormContext.services.blocker.push();
|
|
284
|
+
return new Promise(resolve => Promise.all([validation_1.default(validations, formData), validation_1.default(liveValidations, formData)]).then(([_validations, _liveValidations]) => {
|
|
285
|
+
if (nonlive || onlySchema) {
|
|
286
|
+
this.cachedNonliveValidations = merge(schemaErrors, _validations);
|
|
287
|
+
block && this.memoizedFormContext.services.blocker.pop();
|
|
288
|
+
}
|
|
289
|
+
const merged = merge(_liveValidations, !nonlive
|
|
290
|
+
? (this.cachedNonliveValidations || {})
|
|
291
|
+
: merge(_validations, schemaErrors));
|
|
292
|
+
this.validating = false;
|
|
293
|
+
resolve(!Object.keys(merged).length);
|
|
294
|
+
!equals((this.state.extraErrors || {}), merged) && this.setState({ extraErrors: merged }, this.popErrorListIfNeeded);
|
|
295
|
+
}).catch((e) => {
|
|
296
|
+
block && this.memoizedFormContext.services.blocker.pop();
|
|
297
|
+
throw e;
|
|
298
|
+
}));
|
|
299
|
+
function splitLive(validators = {}, schema, live = {}, rest = {}) {
|
|
300
|
+
Object.keys(validators).forEach(key => {
|
|
301
|
+
if (schema[key]) {
|
|
302
|
+
live[key] = {};
|
|
303
|
+
rest[key] = {};
|
|
304
|
+
splitLive(validators[key], schema[key], live[key], rest[key]);
|
|
305
|
+
if (Object.keys(live[key]).length === 0)
|
|
306
|
+
delete live[key];
|
|
307
|
+
if (Object.keys(rest[key]).length === 0)
|
|
308
|
+
delete rest[key];
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
const container = validators[key].options && validators[key].options._live ? live : rest;
|
|
312
|
+
container[key] = validators[key];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
return { live, rest };
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
this.onSubmit = (onlySchemaValidations) => {
|
|
319
|
+
const _onlySchemaValidations = onlySchemaValidations === "onlySchemaValidations";
|
|
320
|
+
const { uiSchema } = this.props;
|
|
321
|
+
if (uiSchema["ui:disabled"] || uiSchema["ui:readonly"]) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
this.memoizedFormContext.services.blocker.push();
|
|
325
|
+
this.setState({ runningSubmitHooks: true });
|
|
326
|
+
this.memoizedFormContext.services.submitHooks.checkHooks().then(() => {
|
|
327
|
+
this.memoizedFormContext.services.blocker.pop();
|
|
328
|
+
this.setState({ runningSubmitHooks: false });
|
|
329
|
+
this.validateAndSubmit(!_onlySchemaValidations, _onlySchemaValidations);
|
|
330
|
+
}).catch(() => {
|
|
331
|
+
var _a;
|
|
332
|
+
this.setState({ runningSubmitHooks: false });
|
|
333
|
+
this.memoizedFormContext.services.blocker.pop();
|
|
334
|
+
utils_1.highlightElem(react_dom_1.findDOMNode((_a = this.bgJobRef) === null || _a === void 0 ? void 0 : _a.current));
|
|
335
|
+
});
|
|
336
|
+
return undefined;
|
|
337
|
+
};
|
|
338
|
+
this.popErrorListIfNeeded = () => {
|
|
339
|
+
const errorList = this.memoizedFormContext.services.rootInstance.getErrorListInstance();
|
|
340
|
+
let errorListElem;
|
|
341
|
+
try {
|
|
342
|
+
errorListElem = react_dom_1.findDOMNode(errorList);
|
|
343
|
+
}
|
|
344
|
+
catch (e) {
|
|
345
|
+
// Empty
|
|
346
|
+
}
|
|
347
|
+
if (!errorListElem)
|
|
348
|
+
return;
|
|
349
|
+
const wouldScrollTo = utils_1.getScrollPositionForScrollIntoViewIfNeeded(errorListElem, this.props.topOffset, this.props.bottomOffset) || 0;
|
|
350
|
+
const scrollAmount = wouldScrollTo - utils_1.getWindowScrolled();
|
|
351
|
+
if (!errorList.state.poppedTouched && scrollAmount !== 0) {
|
|
352
|
+
errorList.expand();
|
|
353
|
+
}
|
|
354
|
+
utils_1.highlightElem(errorListElem);
|
|
355
|
+
};
|
|
356
|
+
this._onDefaultSubmit = (e) => {
|
|
357
|
+
e.preventDefault();
|
|
358
|
+
this.submit();
|
|
359
|
+
};
|
|
360
|
+
this.submit = () => {
|
|
361
|
+
this.onSubmit();
|
|
362
|
+
};
|
|
363
|
+
this.submitOnlySchemaValidations = () => {
|
|
364
|
+
this.onSubmit("onlySchemaValidations");
|
|
365
|
+
};
|
|
366
|
+
this.getShorcutButtonTooltip = () => {
|
|
367
|
+
const { translations } = this.state.formContext;
|
|
368
|
+
if (this.keyCombo) {
|
|
369
|
+
return utils_1.translate(translations, "ShortcutHelp", { key: utils_1.stringifyKeyCombo(this.keyCombo) });
|
|
370
|
+
}
|
|
371
|
+
return undefined;
|
|
372
|
+
};
|
|
373
|
+
this.toggleHelp = (e) => {
|
|
374
|
+
this.helpVisible ? this.dismissHelp(e) : this.showHelp();
|
|
375
|
+
};
|
|
376
|
+
this.showHelp = () => {
|
|
377
|
+
const node = react_dom_1.findDOMNode(this.shortcutHelpRef.current);
|
|
378
|
+
if (!this.helpVisible) {
|
|
379
|
+
if (node)
|
|
380
|
+
node.className = node.className.replace(" hidden", "");
|
|
381
|
+
this.helpVisible = true;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
this.dismissHelp = (e) => {
|
|
385
|
+
const node = react_dom_1.findDOMNode(this.shortcutHelpRef.current);
|
|
386
|
+
e.preventDefault();
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
if (this.helpVisible && node) {
|
|
389
|
+
node.className += " hidden";
|
|
390
|
+
}
|
|
391
|
+
this.helpVisible = false;
|
|
392
|
+
this.helpStarted = false;
|
|
393
|
+
document.removeEventListener("keyup", this.dismissHelp);
|
|
394
|
+
window.removeEventListener("blur", this.dismissHelp);
|
|
395
|
+
clearTimeout(this.helpTimeout);
|
|
396
|
+
};
|
|
397
|
+
this.keyFunctions = {
|
|
398
|
+
navigate: (e, { reverse }) => {
|
|
399
|
+
return this.memoizedFormContext.services.focus.focusNextInput(reverse);
|
|
400
|
+
},
|
|
401
|
+
help: (e, { delay }) => {
|
|
402
|
+
if (this.helpStarted)
|
|
403
|
+
return false;
|
|
404
|
+
this.helpStarted = true;
|
|
405
|
+
this.helpTimeout = window.setTimeout(() => {
|
|
406
|
+
this.showHelp();
|
|
407
|
+
}, delay * 1000);
|
|
408
|
+
this.addEventListener(document, "keyup", this.dismissHelp);
|
|
409
|
+
this.addEventListener(window, "blur", this.dismissHelp);
|
|
410
|
+
return false;
|
|
411
|
+
},
|
|
412
|
+
revalidate: () => {
|
|
413
|
+
this.submit();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
this.pushBlockingLoader = () => {
|
|
417
|
+
this.memoizedFormContext.services.blocker.push();
|
|
418
|
+
};
|
|
419
|
+
this.popBlockingLoader = () => {
|
|
420
|
+
this.memoizedFormContext.services.blocker.pop();
|
|
421
|
+
};
|
|
422
|
+
this.onSettingsChange = (settings, global = false) => {
|
|
423
|
+
if (this.props.onSettingsChange)
|
|
424
|
+
this.props.onSettingsChange(settings, global);
|
|
425
|
+
};
|
|
426
|
+
this.addEventListener = (target, name, fn) => {
|
|
427
|
+
target.addEventListener(name, fn);
|
|
428
|
+
this.eventListeners.push([target, name, fn]);
|
|
429
|
+
};
|
|
430
|
+
this.setTimeout = (fn, time = 0) => {
|
|
431
|
+
const timeout = window.setTimeout(fn, time);
|
|
432
|
+
this.timeouts.push(timeout);
|
|
433
|
+
return timeout;
|
|
434
|
+
};
|
|
435
|
+
this.destroy = () => {
|
|
436
|
+
if (this.eventListeners)
|
|
437
|
+
this.eventListeners.forEach(([target, name, fn]) => {
|
|
438
|
+
target.removeEventListener(name, fn);
|
|
439
|
+
});
|
|
440
|
+
if (this.timeouts)
|
|
441
|
+
this.timeouts.forEach((timeout) => {
|
|
442
|
+
clearTimeout(timeout);
|
|
443
|
+
});
|
|
444
|
+
this.eventListeners = [];
|
|
445
|
+
};
|
|
446
|
+
if (props.apiClient) {
|
|
447
|
+
this.apiClient = new ApiClient_1.default(props.apiClient, props.lang, this.translations);
|
|
448
|
+
}
|
|
449
|
+
validation_2.initializeValidation(this.apiClient);
|
|
450
|
+
this._id = getNewId();
|
|
451
|
+
this.getMemoizedFormContext(props); // Initialize form context.
|
|
452
|
+
this.resetShortcuts((props.uiSchema || {})["ui:shortcuts"]);
|
|
453
|
+
this.state = this.getStateFromProps(props);
|
|
454
|
+
}
|
|
455
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
456
|
+
if (props.apiClient && props.apiClient !== this.apiClient) {
|
|
457
|
+
this.apiClient = new ApiClient_1.default(props.apiClient, props.lang, this.translations);
|
|
458
|
+
}
|
|
459
|
+
if (this.apiClient && "lang" in props && this.props.lang !== props.lang) {
|
|
460
|
+
this.apiClient.setLang(props.lang);
|
|
461
|
+
}
|
|
462
|
+
this.setState(this.getStateFromProps(props));
|
|
463
|
+
}
|
|
464
|
+
getStateFromProps(props) {
|
|
465
|
+
const state = {
|
|
466
|
+
formContext: this.getMemoizedFormContext(props)
|
|
467
|
+
};
|
|
468
|
+
if (((!this.state && props.schema && Object.keys(props.schema).length) || (this.state && !("formData" in this.state))) || ("formData" in props && props.formData !== this.props.formData)) {
|
|
469
|
+
state.formData = state.formContext.services.ids.addLajiFormIds(utils_1.getDefaultFormState(props.schema, props.formData, props.schema))[0];
|
|
470
|
+
}
|
|
471
|
+
else if (this.state && this.formRef.current) {
|
|
472
|
+
state.formData = this.formRef.current.state.formData;
|
|
473
|
+
}
|
|
474
|
+
if (this.state && props.schema !== this.props.schema) {
|
|
475
|
+
state.extraErrors = {};
|
|
476
|
+
}
|
|
477
|
+
this.memoizedFormContext.services.ids.setFormData(state.formData);
|
|
478
|
+
this.memoizedFormContext.services.rootInstance.setFormData(state.formData);
|
|
479
|
+
return state;
|
|
480
|
+
}
|
|
481
|
+
getMemoizedFormContext(props) {
|
|
482
|
+
const nextKey = ["lang", "topOffset", "bottomOffset", "formContext", "settings", "schema", "uiSchemaContext", "lajiGeoServerAddress"].reduce((key, prop) => {
|
|
483
|
+
key[prop] = props[prop];
|
|
484
|
+
return key;
|
|
485
|
+
}, {});
|
|
486
|
+
if (this.contextFormMemoizeKey && Object.keys(this.contextFormMemoizeKey).every(k => this.contextFormMemoizeKey[k] === nextKey[k])) {
|
|
487
|
+
return this.memoizedFormContext;
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
this.contextFormMemoizeKey = nextKey;
|
|
491
|
+
const { services } = this.memoizedFormContext || {};
|
|
492
|
+
this.memoizedFormContext = Object.assign(Object.assign({}, props.formContext), { translations: this.translations[props.lang], lang: props.lang, uiSchemaContext: props.uiSchemaContext || {}, topOffset: props.topOffset || 0, bottomOffset: props.bottomOffset || 0, contextId: this._id, formID: props.id, googleApiKey: props.googleApiKey, notifier: props.notifier || this.getDefaultNotifier(), apiClient: this.apiClient, Label: (props.fields || {}).Label || components_1.Label, mediaMetadata: props.mediaMetadata, setTimeout: this.setTimeout, services: {}, formRef: this.formRef, lajiGeoServerAddress: props.lajiGeoServerAddress, globals: Context_1.default(this._id) });
|
|
493
|
+
this.memoizedFormContext.utils = utils_1.ReactUtils(this.memoizedFormContext);
|
|
494
|
+
if (services) {
|
|
495
|
+
this.memoizedFormContext.services = services;
|
|
496
|
+
services.keyHandler.setFormContext(this.memoizedFormContext);
|
|
497
|
+
services.focus.setFormContext(this.memoizedFormContext);
|
|
498
|
+
services.settings.setSettings(props.settings);
|
|
499
|
+
services.ids.setSchema(props.schema);
|
|
500
|
+
services.rootInstance.setSchema(props.schema);
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
this.memoizedFormContext.services.keyHandler = new key_handler_service_1.default(this.memoizedFormContext);
|
|
504
|
+
this.memoizedFormContext.services.settings = new settings_service_1.default(this.onSettingsChange, props.settings);
|
|
505
|
+
this.memoizedFormContext.services.focus = new focus_service_1.default(this.memoizedFormContext);
|
|
506
|
+
this.memoizedFormContext.services.blocker = new blocker_service_1.default(this.memoizedFormContext);
|
|
507
|
+
this.memoizedFormContext.services.customEvents = new custom_event_service_1.default();
|
|
508
|
+
this.memoizedFormContext.services.submitHooks = new submit_hook_service_1.default(this.onSubmitHooksChange);
|
|
509
|
+
this.memoizedFormContext.services.DOMIds = new dom_id_service_1.default();
|
|
510
|
+
this.memoizedFormContext.services.ids = new id_service_1.default(props.schema, props.formData);
|
|
511
|
+
this.memoizedFormContext.services.rootInstance = new root_instance_service_1.default(props.schema, props.formData, (formData) => this.onChange({ formData }), this.validate, () => this.validateAndSubmit(false));
|
|
512
|
+
this.memoizedFormContext.services.singletonMap = new singleton_map_service_1.default();
|
|
513
|
+
}
|
|
514
|
+
return this.memoizedFormContext;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
componentDidMount() {
|
|
518
|
+
this.mounted = true;
|
|
519
|
+
this.memoizedFormContext.services.rootInstance.setIsMounted(true);
|
|
520
|
+
this.props.autoFocus && this.memoizedFormContext.utils.focusById("root");
|
|
521
|
+
Object.keys(this.memoizedFormContext.services).forEach(service => {
|
|
522
|
+
var _a, _b;
|
|
523
|
+
(_b = (_a = this.memoizedFormContext.services[service]).initialize) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
524
|
+
});
|
|
525
|
+
if (this.props.componentDidMount)
|
|
526
|
+
this.props.componentDidMount();
|
|
527
|
+
}
|
|
528
|
+
componentWillUnmount() {
|
|
529
|
+
this.mounted = false;
|
|
530
|
+
this.memoizedFormContext.services.rootInstance.setIsMounted(false);
|
|
531
|
+
Object.keys(this.memoizedFormContext.services).forEach(service => {
|
|
532
|
+
var _a, _b;
|
|
533
|
+
(_b = (_a = this.memoizedFormContext.services[service]).destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
componentDidCatch(e, i) {
|
|
537
|
+
this.setState({ error: true });
|
|
538
|
+
if (this.props.onError) {
|
|
539
|
+
this.props.onError(e, i);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
componentDidUpdate(prevProps) {
|
|
543
|
+
if ((prevProps.uiSchema || {})["ui:shortcuts"] !== (this.props.uiSchema || {})["ui:shortcuts"]) {
|
|
544
|
+
this.resetShortcuts((this.props.uiSchema || {})["ui:shortcuts"]);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
resetShortcuts(shortcuts = {}) {
|
|
548
|
+
this.memoizedFormContext.services.keyHandler.setShortcuts(shortcuts, this.keyFunctions);
|
|
549
|
+
Object.keys(shortcuts).some(keyCombo => {
|
|
550
|
+
if (shortcuts[keyCombo].fn == "help") {
|
|
551
|
+
this.keyCombo = keyCombo;
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
constructTranslations() {
|
|
558
|
+
return utils_1.constructTranslations(translations);
|
|
559
|
+
}
|
|
560
|
+
render() {
|
|
561
|
+
if (this.state.error)
|
|
562
|
+
return null;
|
|
563
|
+
const { translations } = this.state.formContext;
|
|
564
|
+
const { "ui:shortcuts": shortcuts, "ui:showShortcutsButton": showShortcutsButton = true, "ui:readonly": readonly, "ui:disabled": disabled } = this.props.uiSchema;
|
|
565
|
+
const uiSchema = Object.assign(Object.assign({}, this.props.uiSchema), { "ui:submitButtonOptions": {
|
|
566
|
+
norender: true
|
|
567
|
+
} });
|
|
568
|
+
const { Panel, Table } = this.getContext(this.props, this.context).theme;
|
|
569
|
+
const panelHeader = (React.createElement("h3", null,
|
|
570
|
+
translations.Shortcuts,
|
|
571
|
+
React.createElement("button", { type: "button", className: "close pull-right", onClick: this.dismissHelp }, "\u00D7")));
|
|
572
|
+
return (React.createElement(ReactContext_1.default.Provider, { value: this.getContext(this.props, this.context) },
|
|
573
|
+
React.createElement("div", { className: "laji-form" },
|
|
574
|
+
showShortcutsButton && this.props.showShortcutButton !== false && shortcuts && (React.createElement(components_1.TooltipComponent, { tooltip: this.getShorcutButtonTooltip() },
|
|
575
|
+
React.createElement(components_1.Button, { variant: undefined, onClick: this.toggleHelp }, translations.Shortcuts))),
|
|
576
|
+
React.createElement(components_1.FailedBackgroundJobsPanel, { jobs: this.state.submitHooks, schema: this.props.schema, uiSchema: uiSchema, formContext: this.state.formContext, errorClickHandler: this.memoizedFormContext.services.focus.focus, ref: this.bgJobRef }),
|
|
577
|
+
React.createElement(core_1.default, Object.assign({}, this.props, { formData: this.state.formData, uiSchema: uiSchema, ref: this.formRef, onChange: this.onChange, onSubmit: this.onSubmit, fields: this.getFields(this.props.fields), widgets: this.getWidgets(this.props.widgets), templates: this.getTemplates(this.props.templates), formContext: this.state.formContext, validator: validator_ajv6_1.default, noValidate: true, extraErrors: this.state.extraErrors, noHtml5Validate: true, liveValidate: true, autoComplete: "off", tagName: "div", readonly: readonly, disabled: disabled }), this.props.children),
|
|
578
|
+
(!this.props.children && this.props.renderSubmit !== false) ? (React.createElement(components_1.Button, { id: "submit", onClick: this.submit, disabled: readonly || disabled }, this.props.submitText || translations.Submit)) : null,
|
|
579
|
+
shortcuts &&
|
|
580
|
+
React.createElement(Panel, { ref: this.shortcutHelpRef, className: "shortcut-help laji-form-popped z-depth-3 hidden", style: { top: (this.props.topOffset || 0) + 5, bottom: (this.props.bottomOffset || 0) + 5 }, variant: "info" },
|
|
581
|
+
React.createElement(Panel.Heading, null, panelHeader),
|
|
582
|
+
React.createElement(Table, null,
|
|
583
|
+
React.createElement("tbody", { className: "well" }, Object.keys(shortcuts).map((keyCombo, idx) => {
|
|
584
|
+
const _a = shortcuts[keyCombo], { fn, targetLabel, label } = _a, rest = __rest(_a, ["fn", "targetLabel", "label"]);
|
|
585
|
+
if (["help", "autosuggestToggle"].includes(fn) || fn === "navigateSection" && rest.goOverRow)
|
|
586
|
+
return;
|
|
587
|
+
let translation = "";
|
|
588
|
+
if (translation)
|
|
589
|
+
translation = label;
|
|
590
|
+
else
|
|
591
|
+
translation = translations[[fn, ...Object.keys(rest)].map(utils_1.capitalizeFirstLetter).join("")];
|
|
592
|
+
if (targetLabel)
|
|
593
|
+
translation = `${translation} ${targetLabel}`;
|
|
594
|
+
return (React.createElement("tr", { key: idx },
|
|
595
|
+
React.createElement("td", null, utils_1.stringifyKeyCombo(keyCombo)),
|
|
596
|
+
React.createElement("td", null, translation)));
|
|
597
|
+
})))),
|
|
598
|
+
this.renderSubmitHooks())));
|
|
599
|
+
}
|
|
600
|
+
getSettings(global = false) {
|
|
601
|
+
return this.memoizedFormContext.services.settings.getSettings(global);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
exports.default = LajiForm;
|
|
605
|
+
LajiForm.contextType = ReactContext_1.default;
|
|
606
|
+
LajiForm.propTypes = {
|
|
607
|
+
uiSchemaContext: PropTypes.object,
|
|
608
|
+
settings: PropTypes.object,
|
|
609
|
+
validators: PropTypes.object,
|
|
610
|
+
warnings: PropTypes.object,
|
|
611
|
+
};
|
|
612
|
+
LajiForm.defaultProps = {
|
|
613
|
+
lang: "en",
|
|
614
|
+
schema: {},
|
|
615
|
+
uiSchema: {}
|
|
616
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { FieldProps } from "./LajiForm";
|
|
3
|
+
export declare function getPropsWithInnerUiSchema(props: FieldProps): FieldProps;
|
|
4
|
+
declare type Constructor<LFC> = new (...args: any[]) => LFC;
|
|
5
|
+
interface LajiFormComponentForVirtualSchemaField extends Omit<React.Component<FieldProps>, "render"> {
|
|
6
|
+
getStateFromProps?(propsWithInnerUiSchema: FieldProps, origProps: FieldProps): any;
|
|
7
|
+
render?(): React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Virtual SchemaFields are components which are just state transforming machines.
|
|
11
|
+
*/
|
|
12
|
+
export default function VirtualSchemaField<LFC extends Constructor<LajiFormComponentForVirtualSchemaField>>(ComposedComponent: LFC): {
|
|
13
|
+
new (...args: any[]): {
|
|
14
|
+
getUiOptions(): any;
|
|
15
|
+
getStateFromProps: (props: FieldProps) => any;
|
|
16
|
+
render: () => React.ReactNode;
|
|
17
|
+
context: any;
|
|
18
|
+
readonly props: Readonly<FieldProps> & Readonly<{
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
}>;
|
|
21
|
+
state: Readonly<{}>;
|
|
22
|
+
componentDidMount?: (() => void) | undefined;
|
|
23
|
+
setState: <K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<FieldProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined) => void;
|
|
24
|
+
forceUpdate: (callback?: (() => void) | undefined) => void;
|
|
25
|
+
refs: {
|
|
26
|
+
[key: string]: React.ReactInstance;
|
|
27
|
+
};
|
|
28
|
+
shouldComponentUpdate?: ((nextProps: Readonly<FieldProps>, nextState: Readonly<{}>, nextContext: any) => boolean) | undefined;
|
|
29
|
+
componentWillUnmount?: (() => void) | undefined;
|
|
30
|
+
componentDidCatch?: ((error: Error, errorInfo: React.ErrorInfo) => void) | undefined;
|
|
31
|
+
getSnapshotBeforeUpdate?: ((prevProps: Readonly<FieldProps>, prevState: Readonly<{}>) => any) | undefined;
|
|
32
|
+
componentDidUpdate?: ((prevProps: Readonly<FieldProps>, prevState: Readonly<{}>, snapshot?: any) => void) | undefined;
|
|
33
|
+
componentWillMount?: (() => void) | undefined;
|
|
34
|
+
UNSAFE_componentWillMount?: (() => void) | undefined;
|
|
35
|
+
componentWillReceiveProps?: ((nextProps: Readonly<FieldProps>, nextContext: any) => void) | undefined;
|
|
36
|
+
UNSAFE_componentWillReceiveProps?: ((nextProps: Readonly<FieldProps>, nextContext: any) => void) | undefined;
|
|
37
|
+
componentWillUpdate?: ((nextProps: Readonly<FieldProps>, nextState: Readonly<{}>, nextContext: any) => void) | undefined;
|
|
38
|
+
UNSAFE_componentWillUpdate?: ((nextProps: Readonly<FieldProps>, nextState: Readonly<{}>, nextContext: any) => void) | undefined;
|
|
39
|
+
};
|
|
40
|
+
displayName: string;
|
|
41
|
+
} & LFC;
|
|
42
|
+
export {};
|