@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,416 @@
|
|
|
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
|
+
exports.arrayItemKeyFunctions = exports.arrayKeyFunctions = exports.ArrayFieldTemplateWithoutKeyHandling = exports.handlesArrayKeys = exports.getButtonsForPosition = exports.getButtonElems = exports.getButtons = exports.getButton = exports.beforeAdd = void 0;
|
|
15
|
+
const React = require("react");
|
|
16
|
+
const components_1 = require("../components");
|
|
17
|
+
const merge = require("deepmerge");
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
19
|
+
const Context_1 = require("../../Context");
|
|
20
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
21
|
+
const react_sortable_hoc_1 = require("react-sortable-hoc");
|
|
22
|
+
const utils_2 = require("@rjsf/utils");
|
|
23
|
+
function onAdd(e, props) {
|
|
24
|
+
if (!utils_1.canAdd(props))
|
|
25
|
+
return;
|
|
26
|
+
props.onAddClick(e);
|
|
27
|
+
}
|
|
28
|
+
function beforeAdd(props, addedIdx) {
|
|
29
|
+
if (!utils_1.canAdd(props))
|
|
30
|
+
return;
|
|
31
|
+
const { contextId } = props.formContext;
|
|
32
|
+
const startIdx = props.startIdx || utils_1.getUiOptions(props.uiSchema).startIdx;
|
|
33
|
+
let { idToScrollAfterAdd = `${props.idSchema.$id}-add`, idxOffsets, totalOffset } = utils_1.getUiOptions(props.uiSchema || {});
|
|
34
|
+
let idx = addedIdx !== null && addedIdx !== void 0 ? addedIdx : (props.items || props.formData || []).length;
|
|
35
|
+
const offset = startIdx !== undefined
|
|
36
|
+
? startIdx
|
|
37
|
+
: idxOffsets
|
|
38
|
+
? utils_1.getIdxWithOffset(idx, idxOffsets, totalOffset) - idx
|
|
39
|
+
: 0;
|
|
40
|
+
idx = offset + idx;
|
|
41
|
+
let idToFocus = `${props.idSchema.$id}_${idx}`;
|
|
42
|
+
Context_1.default(contextId).idToFocus = idToFocus;
|
|
43
|
+
Context_1.default(contextId).idToScroll = idToScrollAfterAdd;
|
|
44
|
+
}
|
|
45
|
+
exports.beforeAdd = beforeAdd;
|
|
46
|
+
const buttonDefinitions = {
|
|
47
|
+
add: {
|
|
48
|
+
glyph: "plus",
|
|
49
|
+
fn: (e) => (props) => {
|
|
50
|
+
onAdd(e, props);
|
|
51
|
+
},
|
|
52
|
+
beforeFn: beforeAdd
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function getButton(button, props = {}) {
|
|
56
|
+
function handleButton(button) {
|
|
57
|
+
function rulesSatisfied(rules = {}) {
|
|
58
|
+
return Object.keys(rules || {}).every(ruleName => {
|
|
59
|
+
const ruleVal = rules[ruleName];
|
|
60
|
+
if (ruleName === "minLength") {
|
|
61
|
+
return (props.formData || []).length >= ruleVal;
|
|
62
|
+
}
|
|
63
|
+
else if (ruleName === "canAdd") {
|
|
64
|
+
return (button.id && button.id !== props.idSchema.$id) || utils_1.canAdd(props);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const fnName = button.fnName || button.fn;
|
|
69
|
+
const _buttonDefinitions = props.uiSchema && utils_1.getUiOptions(props.uiSchema).buttonDefinitions
|
|
70
|
+
? merge(buttonDefinitions, utils_1.getUiOptions(props.uiSchema).buttonDefinitions)
|
|
71
|
+
: buttonDefinitions;
|
|
72
|
+
const definition = _buttonDefinitions[fnName];
|
|
73
|
+
const _button = Object.assign(Object.assign({}, (definition || {})), button);
|
|
74
|
+
if (!rulesSatisfied(_button.rules))
|
|
75
|
+
return;
|
|
76
|
+
if (!_button.fnName)
|
|
77
|
+
_button.fnName = fnName;
|
|
78
|
+
if (definition && typeof _button.fn !== "function")
|
|
79
|
+
_button.fn = _buttonDefinitions[fnName].fn;
|
|
80
|
+
if (fnName !== "add" || (utils_1.getUiOptions(props.uiSchema).renderAdd !== false && ((button.id && button.id !== props.idSchema.$id) || utils_1.canAdd(props))))
|
|
81
|
+
return _button;
|
|
82
|
+
}
|
|
83
|
+
button = handleButton(button);
|
|
84
|
+
if (!button)
|
|
85
|
+
return;
|
|
86
|
+
const id = button.id || (props.idSchema || {}).$id;
|
|
87
|
+
const buttonId = `${id}-${button.fnName}${button.key ? `-${button.key}` : ""}`;
|
|
88
|
+
return React.createElement(_Button, { key: buttonId, buttonId: buttonId, button: button, props: props });
|
|
89
|
+
}
|
|
90
|
+
exports.getButton = getButton;
|
|
91
|
+
function _Button({ button, props, getProps, buttonId }) {
|
|
92
|
+
let { fn, fnName, glyph, label, className, callforward, beforeFn, callback, render, variant, tooltip, tooltipPlacement, tooltipClass, changesFormData, disabled, help, active } = button, options = __rest(button, ["fn", "fnName", "glyph", "label", "className", "callforward", "beforeFn", "callback", "render", "variant", "tooltip", "tooltipPlacement", "tooltipClass", "changesFormData", "disabled", "help", "active"]);
|
|
93
|
+
label = label !== undefined
|
|
94
|
+
? (glyph ? ` ${label}` : label)
|
|
95
|
+
: "";
|
|
96
|
+
const onClick = React.useCallback(e => {
|
|
97
|
+
const onClickProps = getProps ? getProps() : props;
|
|
98
|
+
let _fn = () => fn(e)(onClickProps, options);
|
|
99
|
+
const __fn = () => {
|
|
100
|
+
beforeFn && beforeFn(onClickProps);
|
|
101
|
+
_fn();
|
|
102
|
+
callback && callback();
|
|
103
|
+
};
|
|
104
|
+
if (callforward) {
|
|
105
|
+
e.persist();
|
|
106
|
+
callforward(__fn);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
__fn();
|
|
110
|
+
}
|
|
111
|
+
}, [props, getProps, options, callforward, beforeFn, callback, fn]);
|
|
112
|
+
return render ? render(onClick, button) : (React.createElement(components_1.Button, { id: buttonId, className: className, onClick: onClick, variant: variant, active: active, tooltip: tooltip || help, tooltipPlacement: tooltipPlacement, tooltipClass: tooltipClass, disabled: disabled || ((fnName === "add" || changesFormData) && (props.disabled || props.readonly)), style: button.style },
|
|
113
|
+
glyph && React.createElement(ReactContext_1.default.Consumer, null, ({ theme: { Glyphicon } }) => React.createElement(Glyphicon, { glyph: glyph })),
|
|
114
|
+
glyph ? ` ${label}` : label,
|
|
115
|
+
help && React.createElement(components_1.Help, null)));
|
|
116
|
+
}
|
|
117
|
+
function getButtons(buttons = [], props = {}) {
|
|
118
|
+
const addBtnAdded = buttons.some(button => button.fn === "add");
|
|
119
|
+
if (!addBtnAdded && (!props || utils_1.canAdd(props)))
|
|
120
|
+
buttons = [{ fn: "add", id: props.idSchema.$id }, ...buttons];
|
|
121
|
+
return buttons;
|
|
122
|
+
}
|
|
123
|
+
exports.getButtons = getButtons;
|
|
124
|
+
function getButtonElems(buttons = [], props = {}) {
|
|
125
|
+
buttons = getButtons(buttons, props);
|
|
126
|
+
let buttonElems = buttons.map(button => getButton(button, props));
|
|
127
|
+
if (props.uiSchema["ui:buttons"]) {
|
|
128
|
+
buttonElems = [...buttonElems, ...props.uiSchema["ui:buttons"]];
|
|
129
|
+
}
|
|
130
|
+
return getButtonsElem(buttonElems, props);
|
|
131
|
+
}
|
|
132
|
+
exports.getButtonElems = getButtonElems;
|
|
133
|
+
function getButtonsElem(buttonElems = [], props = {}) {
|
|
134
|
+
if (!Array.isArray(buttonElems) || buttonElems.length === 0) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
return (React.createElement(ReactContext_1.default.Consumer, null, ({ theme: { ButtonToolbar } }) => React.createElement(ButtonToolbar, { className: utils_1.getUiOptions(props.uiSchema)["ui:buttonsDesktopLayout"] ? "desktop-layout" : undefined, key: "buttons" }, buttonElems)));
|
|
138
|
+
}
|
|
139
|
+
function getButtonsForPosition(props, buttonDescriptions = [], position, defaultPosition = "bottom") {
|
|
140
|
+
buttonDescriptions = buttonDescriptions.filter(button => button.position === position || (!button.position && position === defaultPosition));
|
|
141
|
+
return (buttonDescriptions && buttonDescriptions.length) ?
|
|
142
|
+
buttonDescriptions.map(buttonDescription => getButton(buttonDescription, props)).filter(button => button) :
|
|
143
|
+
null;
|
|
144
|
+
}
|
|
145
|
+
exports.getButtonsForPosition = getButtonsForPosition;
|
|
146
|
+
function handlesArrayKeys(ComposedComponent) {
|
|
147
|
+
var _a;
|
|
148
|
+
return _a = class ArrayFieldTemplateField extends ComposedComponent {
|
|
149
|
+
constructor() {
|
|
150
|
+
super(...arguments);
|
|
151
|
+
this.onFocus = target => {
|
|
152
|
+
const context = Context_1.default(this.props.formContext.contextId);
|
|
153
|
+
if (target === "last") {
|
|
154
|
+
context.idToFocus = `${this.props.idSchema.$id}_${this.props.formData.length - 1}`;
|
|
155
|
+
context.idToScroll = `_laji-form_${this.props.formContext.contextId}_${this.props.idSchema.$id}_${this.props.formData.length - 2}`;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.warn(`custom event "focus" has only "last" implemented. Target value was: ${target}`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
this.onCopy = (options = {}) => {
|
|
162
|
+
const { type = "blacklist", filter = [] } = options;
|
|
163
|
+
const { buttonDefinitions = {} } = utils_1.getUiOptions(this.props.uiSchema);
|
|
164
|
+
const { copy } = buttonDefinitions;
|
|
165
|
+
if (copy) {
|
|
166
|
+
copy.fn()(this.props, { type, filter });
|
|
167
|
+
if (copy.callback) {
|
|
168
|
+
copy.callback();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
componentDidMount() {
|
|
174
|
+
this.addKeyHandlers(this.props);
|
|
175
|
+
this.addChildKeyHandlers(this.props);
|
|
176
|
+
this.addCustomEventListeners(this.props);
|
|
177
|
+
if (super.componentDidMount)
|
|
178
|
+
super.componentDidMount();
|
|
179
|
+
}
|
|
180
|
+
componentDidUpdate(prevProps, prevState) {
|
|
181
|
+
this.removeKeyHandlers(prevProps);
|
|
182
|
+
this.addKeyHandlers(this.props);
|
|
183
|
+
this.removeChildKeyHandlers(prevProps);
|
|
184
|
+
this.addChildKeyHandlers(this.props);
|
|
185
|
+
this.removeCustomEventListeners(prevProps);
|
|
186
|
+
this.addCustomEventListeners(this.props);
|
|
187
|
+
if (super.componentDidUpdate)
|
|
188
|
+
super.componentDidUpdate(prevProps, prevState);
|
|
189
|
+
}
|
|
190
|
+
componentWillUnmount() {
|
|
191
|
+
this.removeKeyHandlers(this.props);
|
|
192
|
+
this.removeChildKeyHandlers(this.props);
|
|
193
|
+
this.removeCustomEventListeners(this.props);
|
|
194
|
+
if (super.componentWillUnmount)
|
|
195
|
+
super.componentWillUnmount();
|
|
196
|
+
}
|
|
197
|
+
addKeyHandlers() {
|
|
198
|
+
const [keys, options] = (super.getKeyHandlers || this.getKeyHandlers).call(this, this.props);
|
|
199
|
+
this.arrayKeyFunctions = keys;
|
|
200
|
+
this.props.formContext.services.keyHandler.addKeyHandler(this.props.idSchema.$id, keys, options);
|
|
201
|
+
}
|
|
202
|
+
removeKeyHandlers(props) {
|
|
203
|
+
this.props.formContext.services.keyHandler.removeKeyHandler(props.idSchema.$id, this.arrayKeyFunctions);
|
|
204
|
+
}
|
|
205
|
+
getKeyHandlers(props) {
|
|
206
|
+
const { arrayKeyFunctions: _arrayKeyFunctions } = utils_1.getUiOptions(props.uiSchema);
|
|
207
|
+
return [_arrayKeyFunctions ? Object.assign({}, _arrayKeyFunctions) : Object.assign({}, exports.arrayKeyFunctions), {
|
|
208
|
+
getProps: () => this.props,
|
|
209
|
+
}];
|
|
210
|
+
}
|
|
211
|
+
addChildKeyHandlers(props) {
|
|
212
|
+
this.childKeyHandlers = (super.getChildKeyHandlers || this.getChildKeyHandlers).call(this, props);
|
|
213
|
+
this.childKeyHandlers.forEach(handler => {
|
|
214
|
+
this.props.formContext.services.keyHandler.addKeyHandler(...handler);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
removeChildKeyHandlers() {
|
|
218
|
+
this.childKeyHandlers.forEach(handler => {
|
|
219
|
+
this.props.formContext.services.keyHandler.removeKeyHandler(...handler);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getChildKeyHandlers(props) {
|
|
223
|
+
return props.items.map((item, i) => {
|
|
224
|
+
const id = `${props.idSchema.$id}_${i}`;
|
|
225
|
+
return [id, exports.arrayItemKeyFunctions, { getProps: () => this.props, id, getDeleteButton: () => {
|
|
226
|
+
return this.deleteButtonRefs[i];
|
|
227
|
+
} }];
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getCustomEventListeners() {
|
|
231
|
+
return [
|
|
232
|
+
["focus", this.onFocus],
|
|
233
|
+
["copy", this.onCopy]
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
addCustomEventListeners(props) {
|
|
237
|
+
const { customEvents } = props.formContext.services;
|
|
238
|
+
const customEventListeners = (super.getCustomEventListeners || this.getCustomEventListeners).call(this, props);
|
|
239
|
+
this.customEventListeners = customEventListeners;
|
|
240
|
+
customEventListeners.forEach(params => customEvents.add(props.idSchema.$id, ...params));
|
|
241
|
+
}
|
|
242
|
+
removeCustomEventListeners(props) {
|
|
243
|
+
const { customEvents } = props.formContext.services;
|
|
244
|
+
this.customEventListeners.forEach(params => customEvents.remove(props.idSchema.$id, ...params));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
_a.displayName = utils_1.getReactComponentName(ComposedComponent),
|
|
248
|
+
_a;
|
|
249
|
+
}
|
|
250
|
+
exports.handlesArrayKeys = handlesArrayKeys;
|
|
251
|
+
const SortableList = react_sortable_hoc_1.SortableContainer(({ items, itemProps, nonOrderables, formData }) => (React.createElement("div", null, items.map((item, i) => {
|
|
252
|
+
return React.createElement(SortableItem, { key: utils_1.isObject(formData[i]) ? utils_1.getUUID(formData[i]) : i, index: i, item: item, disabled: (!itemProps[i].hasMoveDown && !itemProps[i].hasMoveUp) || nonOrderables.includes(i) });
|
|
253
|
+
}))));
|
|
254
|
+
const SortableItem = react_sortable_hoc_1.SortableElement(({ item }) => item);
|
|
255
|
+
class ArrayFieldTemplateWithoutKeyHandling extends React.Component {
|
|
256
|
+
constructor() {
|
|
257
|
+
super(...arguments);
|
|
258
|
+
this.onSort = ({ oldIndex, newIndex }) => {
|
|
259
|
+
this.props.items[oldIndex].onReorderClick(oldIndex, newIndex)();
|
|
260
|
+
};
|
|
261
|
+
this.onFocuses = [];
|
|
262
|
+
this.getOnFocus = (i) => () => {
|
|
263
|
+
Context_1.default(this.props.formContext.contextId)[`${this.props.idSchema.$id}.activeIdx`] = i + (utils_1.getUiOptions(this.props.uiSchema).startIdx || 0);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
render() {
|
|
267
|
+
const { props } = this;
|
|
268
|
+
const { confirmDelete, renderTitleAsLabel, deleteCorner, removable = true, orderable, nonRemovables = [], nonOrderables = [], "ui:deleteHelp": deleteHelp, buttons = [] } = utils_1.getUiOptions(props.uiSchema);
|
|
269
|
+
const { readonly, disabled } = this.props;
|
|
270
|
+
const { Label } = this.props.formContext;
|
|
271
|
+
const Title = renderTitleAsLabel ? Label : utils_2.getTemplate("TitleFieldTemplate", props.registry, utils_1.getUiOptions(props.uiSchema));
|
|
272
|
+
const Description = utils_2.getTemplate("DescriptionFieldTemplate", this.props.registry, utils_1.getUiOptions(props.uiSchema));
|
|
273
|
+
if (!this.deleteButtonRefs)
|
|
274
|
+
this.deleteButtonRefs = [];
|
|
275
|
+
const _buttons = getButtons(buttons, props);
|
|
276
|
+
const topButtons = getButtonsElem(getButtonsForPosition(props, _buttons, "top"), props);
|
|
277
|
+
const bottomButtons = getButtonsElem(getButtonsForPosition(props, _buttons, "bottom"), props);
|
|
278
|
+
const getRefFor = i => elem => { this.deleteButtonRefs[i] = elem; };
|
|
279
|
+
const items = props.items.map((item, i) => {
|
|
280
|
+
const getDeleteButton = () => (React.createElement("div", { className: "laji-form-field-template-buttons" },
|
|
281
|
+
React.createElement(components_1.DeleteButton, { id: `${props.idSchema.$id}_${i}`, disabled: disabled || readonly, ref: getRefFor(i), onClick: item.onDropIndexClick(item.index), confirm: confirmDelete, corner: deleteCorner, tooltip: deleteHelp, translations: props.formContext.translations })));
|
|
282
|
+
if (!this.onFocuses[i]) {
|
|
283
|
+
this.onFocuses[i] = this.getOnFocus(i);
|
|
284
|
+
}
|
|
285
|
+
return (React.createElement("div", { key: utils_1.getUUID(props.formData[i]) || item.key, className: "laji-form-field-template-item keep-vertical field-array-row", onFocus: this.onFocuses[i] },
|
|
286
|
+
React.createElement("div", { className: "laji-form-field-template-schema" }, item.children),
|
|
287
|
+
item.hasRemove && !nonRemovables.includes(item.index) && removable && getDeleteButton()));
|
|
288
|
+
});
|
|
289
|
+
const title = "ui:title" in props.uiSchema ? props.uiSchema["ui:title"] : props.title;
|
|
290
|
+
return (React.createElement("div", { className: props.className },
|
|
291
|
+
React.createElement(Title, { title: title, label: title, uiSchema: this.props.uiSchema, registry: this.props.registry }),
|
|
292
|
+
topButtons,
|
|
293
|
+
props.description && React.createElement(Description, { description: props.description }),
|
|
294
|
+
orderable ?
|
|
295
|
+
React.createElement(SortableList, { helperClass: "laji-form reorder-active", distance: 5, items: items, formData: props.formData, onSortEnd: this.onSort, itemProps: props.items, nonOrderables: nonOrderables }) :
|
|
296
|
+
items,
|
|
297
|
+
bottomButtons));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.ArrayFieldTemplateWithoutKeyHandling = ArrayFieldTemplateWithoutKeyHandling;
|
|
301
|
+
exports.default = handlesArrayKeys(ArrayFieldTemplateWithoutKeyHandling);
|
|
302
|
+
exports.arrayKeyFunctions = {
|
|
303
|
+
navigateArray: function (e, { reverse, getProps, navigateCallforward, getCurrentIdx, focusByIdx, getIdToScrollAfterNavigate }) {
|
|
304
|
+
var _a;
|
|
305
|
+
function focusIdx(idx, prop) {
|
|
306
|
+
function callback() {
|
|
307
|
+
const options = utils_1.getUiOptions(getProps().uiSchema);
|
|
308
|
+
const { focusOnNavigate = true, idToFocusAfterNavigate, keepPropFocusOnNavigate = false } = options;
|
|
309
|
+
const idByIdx = `${getProps().idSchema.$id}_${idx}`;
|
|
310
|
+
const _idToFocusAfterNavigate = idToFocusAfterNavigate ||
|
|
311
|
+
prop && keepPropFocusOnNavigate
|
|
312
|
+
? `${idByIdx}_${prop}`
|
|
313
|
+
: idByIdx;
|
|
314
|
+
const idToScrollAfterNavigate = options.idToScrollAfterNavigate
|
|
315
|
+
? options.idToScrollAfterNavigate
|
|
316
|
+
: getIdToScrollAfterNavigate
|
|
317
|
+
? getIdToScrollAfterNavigate()
|
|
318
|
+
: undefined;
|
|
319
|
+
getProps().formContext.utils.focusAndScroll(_idToFocusAfterNavigate, idToScrollAfterNavigate, focusOnNavigate);
|
|
320
|
+
}
|
|
321
|
+
if (focusByIdx) {
|
|
322
|
+
focusByIdx(idx, prop, callback);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
callback();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const nearestSchemaElemId = getProps().formContext.utils.findNearestParentSchemaElemId(document.activeElement);
|
|
329
|
+
// Should contain all nested array item ids. We want the last one, which is focused.
|
|
330
|
+
const activeItemQuery = nearestSchemaElemId.match(new RegExp(`${getProps().idSchema.$id}_\\d+`, "g"));
|
|
331
|
+
const focusedIdx = activeItemQuery ? utils_1.getReversedFormDataIndex(+activeItemQuery[0].replace(/^.*_(\d+)$/, "$1"), getProps().uiSchema) : undefined;
|
|
332
|
+
const focusedPropMaybe = (_a = nearestSchemaElemId.match(new RegExp(`${getProps().idSchema.$id}_${focusedIdx}_(.+)`))) === null || _a === void 0 ? void 0 : _a[1];
|
|
333
|
+
const focusedProp = isNaN(focusedPropMaybe) ? focusedPropMaybe : undefined;
|
|
334
|
+
const currentIdx = getCurrentIdx ? getCurrentIdx() : focusedIdx;
|
|
335
|
+
const arrayLength = getProps().formData ? getProps().formData.length : 0;
|
|
336
|
+
if (utils_1.isNullOrUndefined(currentIdx) && arrayLength > 0) {
|
|
337
|
+
focusIdx(reverse ? arrayLength - 1 : 0, focusedProp);
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
let amount = 0;
|
|
342
|
+
if (focusedIdx === currentIdx)
|
|
343
|
+
amount = reverse ? -1 : 1;
|
|
344
|
+
const nextIdx = currentIdx + amount;
|
|
345
|
+
if (amount === 0 || amount < 0 && nextIdx >= 0 || amount > 0 && nextIdx < arrayLength) {
|
|
346
|
+
if (navigateCallforward) {
|
|
347
|
+
e.persist();
|
|
348
|
+
navigateCallforward(() => focusIdx(nextIdx, focusedProp), nextIdx);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
focusIdx(nextIdx, focusedProp);
|
|
352
|
+
}
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
},
|
|
358
|
+
insert: function (e, _props) {
|
|
359
|
+
const { getProps, insertCallforward } = _props;
|
|
360
|
+
const props = getProps();
|
|
361
|
+
function afterInsert() {
|
|
362
|
+
onAdd(e, props);
|
|
363
|
+
}
|
|
364
|
+
if (!props.disabled && !props.readonly && utils_1.canAdd(props) && utils_1.getUiOptions(props.uiSchema).canAddByKey !== false) {
|
|
365
|
+
if (e.target) {
|
|
366
|
+
e.target.blur();
|
|
367
|
+
}
|
|
368
|
+
if (insertCallforward) {
|
|
369
|
+
e.persist();
|
|
370
|
+
beforeAdd(props);
|
|
371
|
+
insertCallforward(() => {
|
|
372
|
+
afterInsert();
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
beforeAdd(props);
|
|
377
|
+
afterInsert();
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
exports.arrayItemKeyFunctions = {
|
|
385
|
+
delete: function (e, { getDeleteButton, id, getProps }) {
|
|
386
|
+
const { items, idSchema, formContext, readonly, disabled } = getProps();
|
|
387
|
+
if (readonly || disabled || !utils_1.isDescendant(getProps().formContext.utils.getSchemaElementById(id), e.target)) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!getDeleteButton)
|
|
391
|
+
return;
|
|
392
|
+
const deleteButton = getDeleteButton();
|
|
393
|
+
if (!deleteButton || !deleteButton.onClick)
|
|
394
|
+
return;
|
|
395
|
+
const activeId = formContext.utils.findNearestParentSchemaElemId(document.activeElement);
|
|
396
|
+
const idxsMatch = activeId.match(/_\d+/g);
|
|
397
|
+
const idx = +idxsMatch[idxsMatch.length - 1].replace("_", "");
|
|
398
|
+
const elem = getProps().formContext.utils.getSchemaElementById(`${idSchema.$id}_${idx}`);
|
|
399
|
+
const prevElem = elem ? formContext.utils.getNextInput(utils_1.getTabbableFields(elem)[0], !!"reverse") : null;
|
|
400
|
+
deleteButton.onClick(e, (deleted) => {
|
|
401
|
+
if (deleted) {
|
|
402
|
+
const idxToFocus = idx === items.length - 1 ? idx - 1 : idx;
|
|
403
|
+
if (idxToFocus >= 0) {
|
|
404
|
+
getProps().formContext.utils.focusById(`${idSchema.$id}_${idxToFocus}`);
|
|
405
|
+
}
|
|
406
|
+
else if (prevElem) {
|
|
407
|
+
prevElem.focus();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
getProps().formContext.utils.focusById(`${activeId}`);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default class _BaseInputTemplate extends React.Component<any, any, any> {
|
|
2
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
getStateFromProps: (props: any) => any;
|
|
5
|
+
onChange: (value: any) => void;
|
|
6
|
+
timeout: any;
|
|
7
|
+
onFocus: (e: any) => void;
|
|
8
|
+
focused: boolean | undefined;
|
|
9
|
+
onBlur: (e: any) => void;
|
|
10
|
+
}
|
|
11
|
+
import * as React from "react";
|
|
@@ -0,0 +1,80 @@
|
|
|
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 core_1 = require("@rjsf/core");
|
|
16
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
class _BaseInputTemplate extends React.Component {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.getStateFromProps = (props) => {
|
|
22
|
+
return Object.assign({ value: props.value }, utils_1.getUiOptions(props).inputOptions);
|
|
23
|
+
};
|
|
24
|
+
this.onChange = (value) => {
|
|
25
|
+
if (this.props.formatValue)
|
|
26
|
+
value = this.props.formatValue(value);
|
|
27
|
+
const type = this.props.schema.type;
|
|
28
|
+
// Accept only integers
|
|
29
|
+
if (type === "integer") {
|
|
30
|
+
value = value ? value.replace(/[^0-9-]/g, "") : value;
|
|
31
|
+
value = value ? value.replace(/(.+)-/g, "$1") : value;
|
|
32
|
+
}
|
|
33
|
+
// Accept integers or floats
|
|
34
|
+
if (type === "number") {
|
|
35
|
+
value = value ? value.replace(/[^0-9.-]/g, "") : value;
|
|
36
|
+
value = value ? value.replace(/(\..*)\./g, "$1") : value;
|
|
37
|
+
value = value ? value.replace(/(.+)-/g, "$1") : value;
|
|
38
|
+
}
|
|
39
|
+
this.setState({ value }, () => {
|
|
40
|
+
if (!this.focused) {
|
|
41
|
+
this.props.onChange(value);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (this.timeout)
|
|
45
|
+
clearTimeout(this.timeout);
|
|
46
|
+
this.timeout = this.props.formContext.setTimeout(() => {
|
|
47
|
+
this.props.onChange(value);
|
|
48
|
+
}, 1000);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
this.onFocus = (e) => {
|
|
53
|
+
this.focused = true;
|
|
54
|
+
this.props.onFocus && this.props.onFocus(e);
|
|
55
|
+
};
|
|
56
|
+
this.onBlur = (e) => {
|
|
57
|
+
this.focused = false;
|
|
58
|
+
if (this.state.value !== this.props.value) {
|
|
59
|
+
this.props.onChange(this.state.value);
|
|
60
|
+
}
|
|
61
|
+
if (this.timeout)
|
|
62
|
+
clearTimeout(this.timeout);
|
|
63
|
+
this.props.onBlur && this.props.onBlur(e);
|
|
64
|
+
};
|
|
65
|
+
this.state = this.getStateFromProps(props);
|
|
66
|
+
}
|
|
67
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
68
|
+
this.setState(this.getStateFromProps(props));
|
|
69
|
+
}
|
|
70
|
+
render() {
|
|
71
|
+
const _a = this.props, { formatValue } = _a, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
72
|
+
props = __rest(_a, ["formatValue"]);
|
|
73
|
+
const options = props.schema.type === "number" || props.schema.type === "integer"
|
|
74
|
+
? Object.assign(Object.assign({}, props.options), { inputType: "text" }) : props.options;
|
|
75
|
+
const { BaseInputTemplate } = core_1.getDefaultRegistry().templates;
|
|
76
|
+
return React.createElement(BaseInputTemplate, Object.assign({}, props, this.state, { onChange: this.onChange, onFocus: this.onFocus, onBlur: this.onBlur, options: options }));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.default = _BaseInputTemplate;
|
|
80
|
+
_BaseInputTemplate.contextType = ReactContext_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function DescriptonField(props: any): JSX.Element | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const L = require("leaflet");
|
|
6
|
+
function DescriptonField(props) {
|
|
7
|
+
const { description } = props;
|
|
8
|
+
if (!description) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const replacePatterns = description.match(/%{.*?}/g) || [];
|
|
12
|
+
const _description = replacePatterns.reduce((desc, replacePattern) => {
|
|
13
|
+
replacePattern = replacePattern.replace(/%|{|}/g, "");
|
|
14
|
+
let replacement;
|
|
15
|
+
const formData = props.registry.formContext.services.rootInstance.getFormData();
|
|
16
|
+
if (replacePattern[0] === "#") {
|
|
17
|
+
replacement = utils_1.parseJSONPointer(formData, replacePattern.substr(1));
|
|
18
|
+
// TODO DescriptionField doesn't receive formData
|
|
19
|
+
//} else if (replacePattern[0] === "/") {
|
|
20
|
+
// replacement = parseJSONPointer(props.formData, replacePattern);
|
|
21
|
+
}
|
|
22
|
+
else if (replacePattern.startsWith("bbox")) {
|
|
23
|
+
const field = replacePattern.match(/\((.*)\)/)[1];
|
|
24
|
+
const value = utils_1.parseJSONPointer(formData, field.substr(1));
|
|
25
|
+
const bounds = L.geoJSON(value).getBounds();
|
|
26
|
+
const sw = bounds.getSouthWest();
|
|
27
|
+
const ne = bounds.getNorthEast();
|
|
28
|
+
replacement = `${sw.lat}:${ne.lat}:${sw.lng}:${ne.lng}:WGS84`;
|
|
29
|
+
}
|
|
30
|
+
else if (replacePattern === "lang") {
|
|
31
|
+
replacement = props.registry.formContext.lang;
|
|
32
|
+
}
|
|
33
|
+
return desc.replace(`%{${replacePattern}}`, replacement);
|
|
34
|
+
}, description);
|
|
35
|
+
return React.createElement("span", { dangerouslySetInnerHTML: { __html: _description } });
|
|
36
|
+
}
|
|
37
|
+
exports.default = DescriptonField;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class ErrorListTemplate extends React.Component<any, any, any> {
|
|
2
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
expand: () => void;
|
|
5
|
+
poppedToggle: (e: any) => void;
|
|
6
|
+
revalidate: () => void;
|
|
7
|
+
submitWithWarnings: () => void;
|
|
8
|
+
}
|
|
9
|
+
import * as React from "react";
|
|
@@ -0,0 +1,95 @@
|
|
|
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 components_1 = require("../components");
|
|
16
|
+
const utils_1 = require("../../utils");
|
|
17
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
18
|
+
class ErrorListTemplate extends React.Component {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.expand = () => {
|
|
22
|
+
if (!this.state.popped)
|
|
23
|
+
this.setState({ popped: true });
|
|
24
|
+
this.refs.errorPanel.expand();
|
|
25
|
+
this.refs.warningPanel.expand();
|
|
26
|
+
};
|
|
27
|
+
this.poppedToggle = (e) => {
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
this.setState({ popped: !this.state.popped, poppedTouched: true });
|
|
30
|
+
};
|
|
31
|
+
this.revalidate = () => {
|
|
32
|
+
this.props.formContext.services.rootInstance.validate();
|
|
33
|
+
this.refs.errorPanel.expand();
|
|
34
|
+
this.refs.warningPanel.expand();
|
|
35
|
+
};
|
|
36
|
+
this.submitWithWarnings = () => {
|
|
37
|
+
this.props.formContext.services.rootInstance.submitWithWarnings();
|
|
38
|
+
};
|
|
39
|
+
this.state = { popped: false, poppedTouched: false };
|
|
40
|
+
this.props.formContext.services.rootInstance.setErrorListInstance(this);
|
|
41
|
+
}
|
|
42
|
+
render() {
|
|
43
|
+
const { errorSchema, schema, formContext, uiSchema } = this.props;
|
|
44
|
+
const { "ui:disabled": disabled, "ui:readonly": readonly } = uiSchema;
|
|
45
|
+
const { translations } = formContext;
|
|
46
|
+
const clickHandler = formContext.services.focus.focus;
|
|
47
|
+
function walkErrors(path, id, errorSchema, uiSchema, defaultTitle) {
|
|
48
|
+
const { __errors } = errorSchema, properties = __rest(errorSchema, ["__errors"]);
|
|
49
|
+
const _schema = utils_1.parseJSONPointer(schema, path);
|
|
50
|
+
const title = _schema.title || defaultTitle;
|
|
51
|
+
let { errors, warnings } = (__errors || []).reduce(({ errors, warnings }, _error) => {
|
|
52
|
+
if (_error.includes("[warning]")) {
|
|
53
|
+
warnings.push({
|
|
54
|
+
label: title,
|
|
55
|
+
error: utils_1.formatErrorMessage(_error),
|
|
56
|
+
id: id
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
errors.push({
|
|
61
|
+
label: title,
|
|
62
|
+
error: utils_1.formatErrorMessage(_error),
|
|
63
|
+
id: id
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return { errors, warnings };
|
|
67
|
+
}, { errors: [], warnings: [] });
|
|
68
|
+
Object.keys(properties).forEach(prop => {
|
|
69
|
+
let _path = path;
|
|
70
|
+
if (prop.match(/^\d+$/))
|
|
71
|
+
_path = `${_path}/items`;
|
|
72
|
+
else
|
|
73
|
+
_path = `${_path}/properties/${prop}`;
|
|
74
|
+
const _defaultTitle = uiSchema["ui:multiLanguage"] ? `${title} (${prop})` : prop;
|
|
75
|
+
const childErrors = walkErrors(_path, `${id}_${prop}`, errorSchema[prop], uiSchema[prop] || {}, _defaultTitle);
|
|
76
|
+
errors = [...errors, ...childErrors.errors];
|
|
77
|
+
warnings = [...warnings, ...childErrors.warnings];
|
|
78
|
+
});
|
|
79
|
+
return { errors, warnings };
|
|
80
|
+
}
|
|
81
|
+
const { Glyphicon } = this.context.theme;
|
|
82
|
+
const { errors, warnings } = walkErrors("", "root", errorSchema, uiSchema, "");
|
|
83
|
+
const footer = (errors.length > 0
|
|
84
|
+
? React.createElement(components_1.Button, { onClick: this.revalidate },
|
|
85
|
+
React.createElement(Glyphicon, { glyph: "refresh" }),
|
|
86
|
+
" ",
|
|
87
|
+
translations.Revalidate)
|
|
88
|
+
: React.createElement(components_1.Button, { onClick: this.submitWithWarnings, variant: "success", disabled: disabled || readonly }, translations.SubmitWithWarnings));
|
|
89
|
+
return (React.createElement("div", { className: `laji-form-error-list${this.state.popped ? " laji-form-popped" : ""}${errors.length === 0 ? " laji-form-warning-list" : ""}`, style: this.state.popped ? { top: (this.props.formContext.topOffset || 0) + 5 } : null },
|
|
90
|
+
React.createElement(components_1.ErrorPanel, { classNames: "error-panel", ref: "errorPanel", errors: errors, title: translations.Errors, clickHandler: clickHandler, showToggle: true, poppedToggle: this.poppedToggle, footer: footer }),
|
|
91
|
+
React.createElement(components_1.ErrorPanel, { classNames: "warning-panel", ref: "warningPanel", errors: warnings, title: translations.Warnings, clickHandler: clickHandler, showToggle: errors.length === 0, poppedToggle: this.poppedToggle, footer: footer })));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.default = ErrorListTemplate;
|
|
95
|
+
ErrorListTemplate.contextType = ReactContext_1.default;
|