@luomus/laji-form 15.1.0 → 15.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/laji-form.js +1 -1
- package/dist/styles.css +81 -90
- package/jsonconfig.json +26 -0
- package/migrate.sh +0 -1
- package/package.json +8 -8
- 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 +150 -177
- package/test-export/test-utils.js +218 -214
- 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.test.json +1 -1
- package/xsel -b +9 -0
- package/cypress/fixtures/example.json +0 -5
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and closes suggestion list (failed).png +0 -0
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and is marked as suggested (failed).png +0 -0
- package/lib/ApiClient.d.ts +0 -46
- package/lib/ApiClient.js +0 -93
- package/lib/Context.d.ts +0 -8
- package/lib/Context.js +0 -18
- package/lib/ReactContext.d.ts +0 -7
- package/lib/ReactContext.js +0 -5
- package/lib/components/BaseComponent.d.ts +0 -9
- package/lib/components/BaseComponent.js +0 -29
- package/lib/components/LajiForm.d.ts +0 -221
- package/lib/components/LajiForm.js +0 -615
- package/lib/components/VirtualSchemaField.d.ts +0 -42
- package/lib/components/VirtualSchemaField.js +0 -74
- package/lib/components/components.d.ts +0 -119
- package/lib/components/components.js +0 -606
- package/lib/components/fields/AnnotationField.d.ts +0 -34
- package/lib/components/fields/AnnotationField.js +0 -242
- package/lib/components/fields/AnyToBooleanField.d.ts +0 -18
- package/lib/components/fields/AnyToBooleanField.js +0 -20
- package/lib/components/fields/ArrayBulkField.d.ts +0 -23
- package/lib/components/fields/ArrayBulkField.js +0 -82
- package/lib/components/fields/ArrayCombinerField.d.ts +0 -36
- package/lib/components/fields/ArrayCombinerField.js +0 -138
- package/lib/components/fields/ArrayField.d.ts +0 -39
- package/lib/components/fields/ArrayField.js +0 -148
- package/lib/components/fields/AudioArrayField.d.ts +0 -22
- package/lib/components/fields/AudioArrayField.js +0 -100
- package/lib/components/fields/AutoArrayField.d.ts +0 -24
- package/lib/components/fields/AutoArrayField.js +0 -56
- package/lib/components/fields/AutosuggestField.d.ts +0 -69
- package/lib/components/fields/AutosuggestField.js +0 -299
- package/lib/components/fields/CombinedValueDisplayField.d.ts +0 -41
- package/lib/components/fields/CombinedValueDisplayField.js +0 -100
- package/lib/components/fields/ConditionalOnChangeField.d.ts +0 -42
- package/lib/components/fields/ConditionalOnChangeField.js +0 -107
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +0 -123
- package/lib/components/fields/ConditionalUiSchemaField.js +0 -143
- package/lib/components/fields/ContextInjectionField.d.ts +0 -24
- package/lib/components/fields/ContextInjectionField.js +0 -68
- package/lib/components/fields/DataLeakerField.d.ts +0 -40
- package/lib/components/fields/DataLeakerField.js +0 -68
- package/lib/components/fields/DefaultValueArrayField.d.ts +0 -34
- package/lib/components/fields/DefaultValueArrayField.js +0 -59
- package/lib/components/fields/DependentBooleanField.d.ts +0 -38
- package/lib/components/fields/DependentBooleanField.js +0 -87
- package/lib/components/fields/DependentDisableField.d.ts +0 -35
- package/lib/components/fields/DependentDisableField.js +0 -71
- package/lib/components/fields/EnumRangeArrayField.d.ts +0 -27
- package/lib/components/fields/EnumRangeArrayField.js +0 -115
- package/lib/components/fields/ExtraLabelRowField.d.ts +0 -38
- package/lib/components/fields/ExtraLabelRowField.js +0 -100
- package/lib/components/fields/FakePropertyField.d.ts +0 -18
- package/lib/components/fields/FakePropertyField.js +0 -48
- package/lib/components/fields/FilterArrayField.d.ts +0 -73
- package/lib/components/fields/FilterArrayField.js +0 -121
- package/lib/components/fields/FlatField.d.ts +0 -29
- package/lib/components/fields/FlatField.js +0 -171
- package/lib/components/fields/GeocoderField.d.ts +0 -47
- package/lib/components/fields/GeocoderField.js +0 -372
- package/lib/components/fields/GridLayoutField.d.ts +0 -18
- package/lib/components/fields/GridLayoutField.js +0 -32
- package/lib/components/fields/HiddenField.d.ts +0 -10
- package/lib/components/fields/HiddenField.js +0 -11
- package/lib/components/fields/ImageArrayField.d.ts +0 -172
- package/lib/components/fields/ImageArrayField.js +0 -697
- package/lib/components/fields/ImageDisplayField.d.ts +0 -18
- package/lib/components/fields/ImageDisplayField.js +0 -44
- package/lib/components/fields/InitiallyHiddenField.d.ts +0 -21
- package/lib/components/fields/InitiallyHiddenField.js +0 -58
- package/lib/components/fields/InjectDefaultValueField.d.ts +0 -37
- package/lib/components/fields/InjectDefaultValueField.js +0 -68
- package/lib/components/fields/InjectField.d.ts +0 -46
- package/lib/components/fields/InjectField.js +0 -88
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +0 -25
- package/lib/components/fields/InputWithDefaultValueButtonField.js +0 -61
- package/lib/components/fields/LocalityField.d.ts +0 -22
- package/lib/components/fields/LocalityField.js +0 -94
- package/lib/components/fields/LocationChooserField.d.ts +0 -27
- package/lib/components/fields/LocationChooserField.js +0 -440
- package/lib/components/fields/MapArrayField.d.ts +0 -78
- package/lib/components/fields/MapArrayField.js +0 -1783
- package/lib/components/fields/MapField.d.ts +0 -48
- package/lib/components/fields/MapField.js +0 -434
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +0 -25
- package/lib/components/fields/MultiAnyToBooleanField.js +0 -100
- package/lib/components/fields/MultiArrayField.d.ts +0 -53
- package/lib/components/fields/MultiArrayField.js +0 -224
- package/lib/components/fields/MultiLanguageField.d.ts +0 -13
- package/lib/components/fields/MultiLanguageField.js +0 -52
- package/lib/components/fields/MultiTagArrayField.d.ts +0 -36
- package/lib/components/fields/MultiTagArrayField.js +0 -142
- package/lib/components/fields/NamedPlaceChooserField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceChooserField.js +0 -380
- package/lib/components/fields/NamedPlaceSaverField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceSaverField.js +0 -237
- package/lib/components/fields/NestField.d.ts +0 -148
- package/lib/components/fields/NestField.js +0 -289
- package/lib/components/fields/ObjectField.d.ts +0 -2
- package/lib/components/fields/ObjectField.js +0 -119
- package/lib/components/fields/PdfArrayField.d.ts +0 -21
- package/lib/components/fields/PdfArrayField.js +0 -40
- package/lib/components/fields/PrefillingArrayField.d.ts +0 -22
- package/lib/components/fields/PrefillingArrayField.js +0 -65
- package/lib/components/fields/SchemaField.d.ts +0 -7
- package/lib/components/fields/SchemaField.js +0 -109
- package/lib/components/fields/ScopeField.d.ts +0 -85
- package/lib/components/fields/ScopeField.js +0 -521
- package/lib/components/fields/SectionArrayField.d.ts +0 -38
- package/lib/components/fields/SectionArrayField.js +0 -618
- package/lib/components/fields/SelectTreeField.d.ts +0 -39
- package/lib/components/fields/SelectTreeField.js +0 -143
- package/lib/components/fields/SingleActiveArrayField.d.ts +0 -49
- package/lib/components/fields/SingleActiveArrayField.js +0 -974
- package/lib/components/fields/SingleItemArrayField.d.ts +0 -15
- package/lib/components/fields/SingleItemArrayField.js +0 -60
- package/lib/components/fields/SortArrayField.d.ts +0 -73
- package/lib/components/fields/SortArrayField.js +0 -351
- package/lib/components/fields/SplitField.d.ts +0 -28
- package/lib/components/fields/SplitField.js +0 -65
- package/lib/components/fields/StringToArrayField.d.ts +0 -24
- package/lib/components/fields/StringToArrayField.js +0 -48
- package/lib/components/fields/SumField.d.ts +0 -35
- package/lib/components/fields/SumField.js +0 -83
- package/lib/components/fields/TableField.d.ts +0 -18
- package/lib/components/fields/TableField.js +0 -136
- package/lib/components/fields/TagArrayField.d.ts +0 -38
- package/lib/components/fields/TagArrayField.js +0 -128
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +0 -26
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +0 -81
- package/lib/components/fields/UiFieldApplierField.d.ts +0 -30
- package/lib/components/fields/UiFieldApplierField.js +0 -106
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +0 -42
- package/lib/components/fields/UiFieldMapperArrayField.js +0 -121
- package/lib/components/fields/UnitCountShorthandField.d.ts +0 -22
- package/lib/components/fields/UnitCountShorthandField.js +0 -149
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +0 -26
- package/lib/components/fields/UnitListShorthandArrayField.js +0 -108
- package/lib/components/fields/UnitShorthandField.d.ts +0 -32
- package/lib/components/fields/UnitShorthandField.js +0 -220
- package/lib/components/templates/ArrayFieldTemplate.d.ts +0 -85
- package/lib/components/templates/ArrayFieldTemplate.js +0 -417
- package/lib/components/templates/BaseInputTemplate.d.ts +0 -11
- package/lib/components/templates/BaseInputTemplate.js +0 -80
- package/lib/components/templates/DescriptionField.d.ts +0 -1
- package/lib/components/templates/DescriptionField.js +0 -37
- package/lib/components/templates/ErrorListTemplate.d.ts +0 -9
- package/lib/components/templates/ErrorListTemplate.js +0 -95
- package/lib/components/templates/FieldTemplate.d.ts +0 -6
- package/lib/components/templates/FieldTemplate.js +0 -112
- package/lib/components/templates/ObjectFieldTemplate.d.ts +0 -7
- package/lib/components/templates/ObjectFieldTemplate.js +0 -66
- package/lib/components/templates/TitleField.d.ts +0 -9
- package/lib/components/templates/TitleField.js +0 -51
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +0 -20
- package/lib/components/widgets/AnyToBooleanWidget.js +0 -49
- package/lib/components/widgets/AutosuggestWidget.d.ts +0 -66
- package/lib/components/widgets/AutosuggestWidget.js +0 -1127
- package/lib/components/widgets/CheckboxWidget.d.ts +0 -37
- package/lib/components/widgets/CheckboxWidget.js +0 -139
- package/lib/components/widgets/DateTimeWidget.d.ts +0 -62
- package/lib/components/widgets/DateTimeWidget.js +0 -251
- package/lib/components/widgets/DateWidget.d.ts +0 -23
- package/lib/components/widgets/DateWidget.js +0 -41
- package/lib/components/widgets/HiddenWidget.d.ts +0 -15
- package/lib/components/widgets/HiddenWidget.js +0 -19
- package/lib/components/widgets/ImageSelectWidget.d.ts +0 -14
- package/lib/components/widgets/ImageSelectWidget.js +0 -57
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +0 -43
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +0 -237
- package/lib/components/widgets/InputGroupWidget.d.ts +0 -21
- package/lib/components/widgets/InputGroupWidget.js +0 -36
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +0 -21
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +0 -47
- package/lib/components/widgets/NumberWidget.d.ts +0 -13
- package/lib/components/widgets/NumberWidget.js +0 -21
- package/lib/components/widgets/PlainTextWidget.d.ts +0 -12
- package/lib/components/widgets/PlainTextWidget.js +0 -24
- package/lib/components/widgets/SelectWidget.d.ts +0 -52
- package/lib/components/widgets/SelectWidget.js +0 -158
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +0 -19
- package/lib/components/widgets/SeparatedDateTimeWidget.js +0 -59
- package/lib/components/widgets/TaxonImageWidget.d.ts +0 -13
- package/lib/components/widgets/TaxonImageWidget.js +0 -30
- package/lib/components/widgets/TextSelectWidget.d.ts +0 -25
- package/lib/components/widgets/TextSelectWidget.js +0 -94
- package/lib/components/widgets/TextareaWidget.d.ts +0 -32
- package/lib/components/widgets/TextareaWidget.js +0 -87
- package/lib/components/widgets/TimeWidget.d.ts +0 -11
- package/lib/components/widgets/TimeWidget.js +0 -19
- package/lib/components/widgets/URLWidget.d.ts +0 -14
- package/lib/components/widgets/URLWidget.js +0 -12
- package/lib/components/widgets/UpperCaseWidget.d.ts +0 -13
- package/lib/components/widgets/UpperCaseWidget.js +0 -21
- package/lib/index.d.ts +0 -20
- package/lib/index.js +0 -50
- package/lib/services/blocker-service.d.ts +0 -11
- package/lib/services/blocker-service.js +0 -55
- package/lib/services/custom-event-service.d.ts +0 -17
- package/lib/services/custom-event-service.js +0 -35
- package/lib/services/dom-id-service.d.ts +0 -8
- package/lib/services/dom-id-service.js +0 -30
- package/lib/services/focus-service.d.ts +0 -13
- package/lib/services/focus-service.js +0 -60
- package/lib/services/id-service.d.ts +0 -22
- package/lib/services/id-service.js +0 -130
- package/lib/services/key-handler-service.d.ts +0 -56
- package/lib/services/key-handler-service.js +0 -184
- package/lib/services/root-instance-service.d.ts +0 -25
- package/lib/services/root-instance-service.js +0 -49
- package/lib/services/settings-service.d.ts +0 -34
- package/lib/services/settings-service.js +0 -154
- package/lib/services/singleton-map-service.d.ts +0 -23
- package/lib/services/singleton-map-service.js +0 -44
- package/lib/services/submit-hook-service.d.ts +0 -24
- package/lib/services/submit-hook-service.js +0 -73
- package/lib/styles.js +0 -4
- package/lib/themes/bs3.d.ts +0 -3
- package/lib/themes/bs3.js +0 -133
- package/lib/themes/bs5.d.ts +0 -3
- package/lib/themes/bs5.js +0 -111
- package/lib/themes/glyphicon-fa-mapping.d.ts +0 -3
- package/lib/themes/glyphicon-fa-mapping.js +0 -271
- package/lib/themes/stub.d.ts +0 -3
- package/lib/themes/stub.js +0 -82
- package/lib/themes/theme.d.ts +0 -233
- package/lib/themes/theme.js +0 -2
- package/lib/translations.json +0 -847
- package/lib/utils.d.ts +0 -171
- package/lib/utils.js +0 -1191
- package/lib/validation.d.ts +0 -7
- package/lib/validation.js +0 -141
- package/llol +0 -10
- package/llol.pdf +0 -10
- package/playwright-report/index.html +0 -62
- package/q +0 -196
- package/rename.sh +0 -24
- package/trip-report.spec.ts +0 -594
- /package/{lib/styles.d.ts → test-export/array-spec.d.ts} +0 -0
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default class SingleItemArrayField extends React.Component<any, any, any> {
|
|
2
|
-
static propTypes: {
|
|
3
|
-
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
-
type: PropTypes.Requireable<string>;
|
|
5
|
-
}>>;
|
|
6
|
-
formData: PropTypes.Requireable<any[]>;
|
|
7
|
-
};
|
|
8
|
-
static getName(): string;
|
|
9
|
-
constructor(props: any);
|
|
10
|
-
getStateFromProps(props: any): any;
|
|
11
|
-
getActiveIdx: (props: any) => any;
|
|
12
|
-
onChange: (formData: any) => void;
|
|
13
|
-
}
|
|
14
|
-
import * as React from "react";
|
|
15
|
-
import * as PropTypes from "prop-types";
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const React = require("react");
|
|
10
|
-
const PropTypes = require("prop-types");
|
|
11
|
-
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
12
|
-
const utils_1 = require("../../utils");
|
|
13
|
-
const ArrayField_1 = require("./ArrayField");
|
|
14
|
-
let SingleItemArrayField = class SingleItemArrayField extends React.Component {
|
|
15
|
-
constructor(props) {
|
|
16
|
-
super(props);
|
|
17
|
-
this.getActiveIdx = (props) => {
|
|
18
|
-
const options = utils_1.getUiOptions(props.uiSchema);
|
|
19
|
-
return "activeIdx" in options
|
|
20
|
-
? options.activeIdx
|
|
21
|
-
: 0;
|
|
22
|
-
};
|
|
23
|
-
this.onChange = (formData) => {
|
|
24
|
-
const activeIdx = this.getActiveIdx(this.props);
|
|
25
|
-
const copy = (this.props.formData || []).slice();
|
|
26
|
-
copy[activeIdx] = formData;
|
|
27
|
-
this.props.onChange(copy);
|
|
28
|
-
};
|
|
29
|
-
props.formContext.globals[`${this.props.idSchema.$id}.activeIdx`] = this.getActiveIdx(props);
|
|
30
|
-
}
|
|
31
|
-
static getName() { return "SingleItemArrayField"; }
|
|
32
|
-
componentDidUpdate() {
|
|
33
|
-
this.props.formContext.globals[`${this.props.idSchema.$id}.activeIdx`] = this.getActiveIdx(this.props);
|
|
34
|
-
}
|
|
35
|
-
getStateFromProps(props) {
|
|
36
|
-
const activeIdx = this.getActiveIdx(props);
|
|
37
|
-
if (typeof activeIdx !== "number" || isNaN(activeIdx)) {
|
|
38
|
-
return Object.assign(Object.assign({}, props), { uiSchema: {
|
|
39
|
-
"ui:field": "HiddenField"
|
|
40
|
-
} });
|
|
41
|
-
}
|
|
42
|
-
let uiSchema = Object.assign(Object.assign({ "ui:title": utils_1.getTitle(props, activeIdx), "ui:help": props.uiSchema["ui:help"] }, props.uiSchema.items || {}), { "ui:options": Object.assign({ titleClassName: utils_1.getUiOptions(props.uiSchema).titleClassName }, utils_1.getUiOptions(props.uiSchema.items)) });
|
|
43
|
-
if (utils_1.isMultiSelect(props.schema, uiSchema)) {
|
|
44
|
-
uiSchema = Object.assign(Object.assign({}, uiSchema), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(uiSchema)), { renderTitleAsLabel: true }) });
|
|
45
|
-
}
|
|
46
|
-
return Object.assign(Object.assign({}, props), { formData: props.formData && props.formData.length && activeIdx in props.formData
|
|
47
|
-
? props.formData[activeIdx]
|
|
48
|
-
: utils_1.addLajiFormIds(utils_1.getDefaultFormState(props.schema.items), this.props.formContext.services.ids.getRelativeTmpIdTree(props.idSchema.$id), false)[0], schema: props.schema.items, uiSchema, idSchema: ArrayField_1.ArrayFieldPatched.prototype.getIdSchema.call(this, props, activeIdx), errorSchema: props.errorSchema[activeIdx] || {}, onChange: this.onChange });
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
SingleItemArrayField.propTypes = {
|
|
52
|
-
schema: PropTypes.shape({
|
|
53
|
-
type: PropTypes.oneOf(["array"])
|
|
54
|
-
}).isRequired,
|
|
55
|
-
formData: PropTypes.array
|
|
56
|
-
};
|
|
57
|
-
SingleItemArrayField = __decorate([
|
|
58
|
-
VirtualSchemaField_1.default
|
|
59
|
-
], SingleItemArrayField);
|
|
60
|
-
exports.default = SingleItemArrayField;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { FieldProps } from "../LajiForm";
|
|
3
|
-
export declare const colIsLoading: (col: SortCol) => boolean;
|
|
4
|
-
interface SortCol {
|
|
5
|
-
name: string;
|
|
6
|
-
/**
|
|
7
|
-
* Undefined if shouldn't sort at all.
|
|
8
|
-
*/
|
|
9
|
-
descending?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Compare function provided by the compare strategy. It can be asynchronously set.
|
|
12
|
-
* If it returns undefined, comparison will fallback to the default algorithm.
|
|
13
|
-
*/
|
|
14
|
-
compare?: (a: any, b: any, sortCol: SortCol, schema: any) => number | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* The chosen compare strategy object.
|
|
17
|
-
*/
|
|
18
|
-
compareStrategy: CompareStrategy;
|
|
19
|
-
loading?: boolean;
|
|
20
|
-
}
|
|
21
|
-
interface State {
|
|
22
|
-
uiSchema?: any;
|
|
23
|
-
sortCols: SortCol[];
|
|
24
|
-
}
|
|
25
|
-
declare type DefaultCompareStrategy = {
|
|
26
|
-
strategy: "default";
|
|
27
|
-
noDescending?: boolean;
|
|
28
|
-
};
|
|
29
|
-
declare type TaxonomicCompareStrategy = {
|
|
30
|
-
strategy: "taxonomic";
|
|
31
|
-
noDescending?: boolean;
|
|
32
|
-
valueField?: string;
|
|
33
|
-
query: {
|
|
34
|
-
informalGroupsFilter?: string;
|
|
35
|
-
onlyFinnish?: boolean;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
declare type CompareStrategy = DefaultCompareStrategy | TaxonomicCompareStrategy;
|
|
39
|
-
/**
|
|
40
|
-
* Sorts date according to selected columns. This component provides only the sorting logic,
|
|
41
|
-
* a child component must handle the UI for selecting the sort columns.
|
|
42
|
-
*
|
|
43
|
-
* Can be used only if items are objects (non-objects don't have UUIDs which are used for
|
|
44
|
-
* keeping the original order intact upon changes);
|
|
45
|
-
*/
|
|
46
|
-
export default class SortArrayField extends React.Component<FieldProps, State> {
|
|
47
|
-
state: State;
|
|
48
|
-
sortTimeIdToSortedIdx: Record<string, number>;
|
|
49
|
-
/**
|
|
50
|
-
* Id-to-idx mapping when the sorting was touched. Used to sorting newly items where they are put, instead of sorting them according to the sort cols.
|
|
51
|
-
*/
|
|
52
|
-
sortTimeIdToOrigIdx: Record<string, number>;
|
|
53
|
-
constructor(props: FieldProps);
|
|
54
|
-
componentDidUpdate(): void;
|
|
55
|
-
/**
|
|
56
|
-
* Sort cols might be retrieved from settings JSON, which doesn't hold the 'compare' fn. We add the fn
|
|
57
|
-
* asynchronously when the component updates according to the comparison strategy name.
|
|
58
|
-
*/
|
|
59
|
-
syncColumns(): void;
|
|
60
|
-
getUiShema(props: FieldProps, { sortCols }: State, sortedData: any[]): any;
|
|
61
|
-
getSortableColumns(props: FieldProps): string[] | undefined;
|
|
62
|
-
getNextComponentProps(props: any, state: State): {
|
|
63
|
-
uiSchema: any;
|
|
64
|
-
formData: any[];
|
|
65
|
-
onChange: (formData: any[]) => void;
|
|
66
|
-
};
|
|
67
|
-
updateSortCol(sortCol: SortCol): void;
|
|
68
|
-
setSortCols(sortCols: SortCol[]): void;
|
|
69
|
-
onSortToggle(name: string): void;
|
|
70
|
-
onChange: (formData: any[]) => void;
|
|
71
|
-
render(): JSX.Element;
|
|
72
|
-
}
|
|
73
|
-
export {};
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.colIsLoading = void 0;
|
|
13
|
-
const React = require("react");
|
|
14
|
-
const utils_1 = require("../../utils");
|
|
15
|
-
const memoize = require("memoizee");
|
|
16
|
-
const ReactContext_1 = require("../../ReactContext");
|
|
17
|
-
const components_1 = require("../components");
|
|
18
|
-
const Spinner = require("react-spinner");
|
|
19
|
-
const colIsLoading = (col) => col.compareStrategy && !col.compare;
|
|
20
|
-
exports.colIsLoading = colIsLoading;
|
|
21
|
-
const colsLoading = (sortCols) => sortCols.filter(exports.colIsLoading).length > 0;
|
|
22
|
-
class Comparer {
|
|
23
|
-
constructor(options, colName, formContext) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.formContext = formContext;
|
|
26
|
-
this.colName = colName;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class TaxonomicComparer extends Comparer {
|
|
30
|
-
constructor(options, colName, formContext) {
|
|
31
|
-
super(options, colName, formContext);
|
|
32
|
-
this.compare = this.compare.bind(this);
|
|
33
|
-
}
|
|
34
|
-
initialize() {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
this.idToIdx = (yield this.formContext.apiClient.fetchCached("/taxa", Object.assign(Object.assign({}, this.options.query), { pageSize: 10000, selectedFields: "id" })))
|
|
37
|
-
.results.reduce((idToIdx, { id }, idx) => {
|
|
38
|
-
idToIdx[id] = idx;
|
|
39
|
-
return idToIdx;
|
|
40
|
-
}, {});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
compare(a, b) {
|
|
44
|
-
const aValue = a[this.options.valueField || this.colName];
|
|
45
|
-
const bValue = b[this.options.valueField || this.colName];
|
|
46
|
-
if (this.idToIdx[aValue] === undefined && this.idToIdx[bValue] !== undefined) {
|
|
47
|
-
return 1;
|
|
48
|
-
}
|
|
49
|
-
else if (this.idToIdx[aValue] !== undefined && this.idToIdx[bValue] === undefined) {
|
|
50
|
-
return -1;
|
|
51
|
-
// Fall back to default comparison if it's neither are in the taxonomic set.
|
|
52
|
-
}
|
|
53
|
-
else if (this.idToIdx[aValue] === undefined && this.idToIdx[bValue] === undefined) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return this.idToIdx[aValue] - this.idToIdx[bValue];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
class DefaultComparer extends Comparer {
|
|
60
|
-
compare(a, b, sortCol, schema) {
|
|
61
|
-
const { name } = sortCol;
|
|
62
|
-
const colSchema = schema.items.properties[name];
|
|
63
|
-
const aValue = getValue(a[name], colSchema);
|
|
64
|
-
const bValue = getValue(b[name], colSchema);
|
|
65
|
-
if (aValue === undefined && bValue !== undefined || aValue < bValue) {
|
|
66
|
-
return -1;
|
|
67
|
-
}
|
|
68
|
-
else if (aValue !== undefined && bValue === undefined || aValue > bValue) {
|
|
69
|
-
return 1;
|
|
70
|
-
}
|
|
71
|
-
return 0;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const compareStrategyMap = {
|
|
75
|
-
taxonomic: TaxonomicComparer,
|
|
76
|
-
default: DefaultComparer
|
|
77
|
-
};
|
|
78
|
-
const comparers = {};
|
|
79
|
-
const ColumnOptionsUI = ({ field, compareStrategies = [], sortCol, updateSortCol, formContext }) => {
|
|
80
|
-
const { MenuItem, Glyphicon, Dropdown } = React.useContext(ReactContext_1.default).theme;
|
|
81
|
-
const selectedStrategy = sortCol === null || sortCol === void 0 ? void 0 : sortCol.compareStrategy;
|
|
82
|
-
const selectedStrategyIdx = selectedStrategy ? compareStrategies.indexOf(selectedStrategy) : 0;
|
|
83
|
-
const onClick = React.useCallback((e) => {
|
|
84
|
-
e.stopPropagation();
|
|
85
|
-
}, []);
|
|
86
|
-
const onSelect = React.useCallback((idx) => {
|
|
87
|
-
const strategy = compareStrategies[idx];
|
|
88
|
-
updateSortCol(Object.assign(Object.assign({}, (sortCol || {})), { compareStrategy: strategy }));
|
|
89
|
-
}, [compareStrategies, sortCol, updateSortCol]);
|
|
90
|
-
if (!compareStrategies) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return (React.createElement(components_1.TooltipComponent, { tooltip: formContext.translations["SortStrategies"], placement: "left" },
|
|
94
|
-
React.createElement(Dropdown, { id: `${field}-column-options`, onClick: onClick, className: "laji-form-col-options", pullRight: true },
|
|
95
|
-
React.createElement(Dropdown.Toggle, { noCaret: true },
|
|
96
|
-
React.createElement(Glyphicon, { glyph: "cog" })),
|
|
97
|
-
React.createElement(Dropdown.Menu, { onSelect: onSelect }, compareStrategies.map((strategy, i) => {
|
|
98
|
-
const label = formContext.translations[`SortStrategy${utils_1.capitalizeFirstLetter(strategy.strategy)}`];
|
|
99
|
-
return React.createElement(MenuItem, { key: i, eventKey: i, active: selectedStrategyIdx === i }, label);
|
|
100
|
-
})))));
|
|
101
|
-
};
|
|
102
|
-
const getUpdateSortCol = memoize((col, sortCols, setSortCols) => (sortCol) => {
|
|
103
|
-
const existingIdx = sortCols.findIndex(c => c.name === col);
|
|
104
|
-
const _sortCols = [...sortCols];
|
|
105
|
-
_sortCols.splice(existingIdx === -1 ? _sortCols.length : existingIdx, 1, Object.assign(Object.assign({}, sortCol), { name: col, descending: sortCol.descending }));
|
|
106
|
-
setSortCols(_sortCols);
|
|
107
|
-
});
|
|
108
|
-
const getUI = (columns, sortCols, setSortCols, formContext) => {
|
|
109
|
-
return Object.keys(columns || {}).reduce((fieldToUI, field) => {
|
|
110
|
-
var _a, _b;
|
|
111
|
-
fieldToUI[field] = React.createElement(React.Fragment, null,
|
|
112
|
-
colsLoading(sortCols) && React.createElement(Spinner, null),
|
|
113
|
-
(((_b = (_a = columns === null || columns === void 0 ? void 0 : columns[field]) === null || _a === void 0 ? void 0 : _a.compareStrategies) === null || _b === void 0 ? void 0 : _b.length) || 0) > 1 && React.createElement(ColumnOptionsUI, Object.assign({ field: field }, columns === null || columns === void 0 ? void 0 : columns[field], { sortCol: sortCols === null || sortCols === void 0 ? void 0 : sortCols.find(c => c.name === field), updateSortCol: getUpdateSortCol(field, sortCols, setSortCols), formContext: formContext })));
|
|
114
|
-
return fieldToUI;
|
|
115
|
-
}, {});
|
|
116
|
-
};
|
|
117
|
-
const getValue = (formData, schema) => {
|
|
118
|
-
var _a;
|
|
119
|
-
if (schema.oneOf) {
|
|
120
|
-
return (_a = schema.oneOf.find(({ const: v }) => v === formData)) === null || _a === void 0 ? void 0 : _a.title;
|
|
121
|
-
}
|
|
122
|
-
return formData;
|
|
123
|
-
};
|
|
124
|
-
const sort = (schema, { sortCols }, sortTimeIdToSortedIdx, sortTimeIdToOrigIdx) => (a, b) => {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
// Don't sort items that weren't there when the sorting was done.
|
|
127
|
-
// For example when adding a new item to the array, it should be exactly where it is added.
|
|
128
|
-
// const idToOrigIdx = getIdToOrigIdx(formData);
|
|
129
|
-
const aSortedIdx = sortTimeIdToOrigIdx[utils_1.getUUID(a)];
|
|
130
|
-
const bSortedIdx = sortTimeIdToOrigIdx[utils_1.getUUID(b)];
|
|
131
|
-
if (aSortedIdx === undefined || bSortedIdx === undefined) {
|
|
132
|
-
return sortTimeIdToSortedIdx[utils_1.getUUID(a)] - sortTimeIdToSortedIdx[utils_1.getUUID(b)];
|
|
133
|
-
}
|
|
134
|
-
const defaultSort = DefaultComparer.prototype.compare;
|
|
135
|
-
let result;
|
|
136
|
-
for (const sortCol of sortCols) {
|
|
137
|
-
result = sortCol.descending === undefined
|
|
138
|
-
? 0
|
|
139
|
-
: ((_b = (_a = sortCol.compare) === null || _a === void 0 ? void 0 : _a.call(sortCol, a, b, sortCol, schema)) !== null && _b !== void 0 ? _b : defaultSort(a, b, sortCol, schema)) || 0;
|
|
140
|
-
if (result !== 0) {
|
|
141
|
-
result = sortCol.descending ? result * -1 : result;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
};
|
|
147
|
-
const getSortedData = memoize((formData, schema, state, sortTimeIdToSortedIdx, sortTimeIdToOrigIdx) => {
|
|
148
|
-
return (state.sortCols.length && !colsLoading(state.sortCols))
|
|
149
|
-
? [...formData].sort(sort(schema, state, sortTimeIdToSortedIdx, sortTimeIdToOrigIdx))
|
|
150
|
-
: formData;
|
|
151
|
-
}, { max: 1 });
|
|
152
|
-
const getIdToIdx = (formData) => formData.reduce((idToIdx, item, idx) => {
|
|
153
|
-
idToIdx[utils_1.getUUID(item)] = idx;
|
|
154
|
-
return idToIdx;
|
|
155
|
-
}, {});
|
|
156
|
-
// These are otherwise identical, but are memoized against different input.
|
|
157
|
-
// Use max 2 because current props / next props might be compared.
|
|
158
|
-
const getIdToSortedIdx = memoize((formData) => getIdToIdx(formData), { max: 2 });
|
|
159
|
-
const getIdToOrigIdx = memoize((formData) => getIdToIdx(formData), { max: 2 });
|
|
160
|
-
/**
|
|
161
|
-
* Sorts date according to selected columns. This component provides only the sorting logic,
|
|
162
|
-
* a child component must handle the UI for selecting the sort columns.
|
|
163
|
-
*
|
|
164
|
-
* Can be used only if items are objects (non-objects don't have UUIDs which are used for
|
|
165
|
-
* keeping the original order intact upon changes);
|
|
166
|
-
*/
|
|
167
|
-
class SortArrayField extends React.Component {
|
|
168
|
-
constructor(props) {
|
|
169
|
-
super(props);
|
|
170
|
-
this.state = { sortCols: [] };
|
|
171
|
-
this.sortTimeIdToSortedIdx = {};
|
|
172
|
-
/**
|
|
173
|
-
* Id-to-idx mapping when the sorting was touched. Used to sorting newly items where they are put, instead of sorting them according to the sort cols.
|
|
174
|
-
*/
|
|
175
|
-
this.sortTimeIdToOrigIdx = {};
|
|
176
|
-
// Note: if next component hard sorts the data, this won't work with that.
|
|
177
|
-
// Probably not a common use case to have both hard/soft sorting.
|
|
178
|
-
this.onChange = (formData) => {
|
|
179
|
-
if (!this.state.sortCols.length) {
|
|
180
|
-
this.props.onChange(formData);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
const idToOrigIdx = getIdToOrigIdx(this.props.formData);
|
|
185
|
-
this.sortTimeIdToSortedIdx = getIdToSortedIdx(formData);
|
|
186
|
-
const existingItems = [];
|
|
187
|
-
const newItems = [];
|
|
188
|
-
let prevUUID = -1; // Start with UUID that won't match any item.
|
|
189
|
-
const UUIDToPrev = {};
|
|
190
|
-
formData.forEach(i => {
|
|
191
|
-
const uuid = utils_1.getUUID(i);
|
|
192
|
-
if (idToOrigIdx[uuid] !== undefined) {
|
|
193
|
-
existingItems.push(i);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
newItems.push(i);
|
|
197
|
-
UUIDToPrev[uuid] = prevUUID;
|
|
198
|
-
}
|
|
199
|
-
prevUUID = uuid;
|
|
200
|
-
});
|
|
201
|
-
const sortedToOriginal = existingItems.sort((a, b) => {
|
|
202
|
-
const aIdx = idToOrigIdx[utils_1.getUUID(a)];
|
|
203
|
-
const bIdx = idToOrigIdx[utils_1.getUUID(b)];
|
|
204
|
-
return aIdx - bIdx;
|
|
205
|
-
});
|
|
206
|
-
newItems.forEach(item => {
|
|
207
|
-
const uuid = utils_1.getUUID(item);
|
|
208
|
-
const precedingUUID = UUIDToPrev[uuid];
|
|
209
|
-
const precedingOriginalIdx = sortedToOriginal.findIndex((i) => utils_1.getUUID(i) === precedingUUID);
|
|
210
|
-
const precedingSortedIdx = this.sortTimeIdToSortedIdx[utils_1.getUUID(item)];
|
|
211
|
-
// Detect whether i's a new empty item. If it is, put it to the end of the original array.
|
|
212
|
-
// Otherwise (it's e.g. a copied item), put it in the original array after the preceding item of the sorted order.
|
|
213
|
-
if (precedingSortedIdx === sortedToOriginal.length && utils_1.isDefaultData(item, this.props.schema.items)) {
|
|
214
|
-
sortedToOriginal.push(item);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
sortedToOriginal.splice(precedingOriginalIdx + 1, 0, item);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
this.props.onChange(sortedToOriginal);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
props.formContext.services.settings.bind(this, props);
|
|
224
|
-
this.syncColumns();
|
|
225
|
-
}
|
|
226
|
-
componentDidUpdate() {
|
|
227
|
-
this.syncColumns();
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Sort cols might be retrieved from settings JSON, which doesn't hold the 'compare' fn. We add the fn
|
|
231
|
-
* asynchronously when the component updates according to the comparison strategy name.
|
|
232
|
-
*/
|
|
233
|
-
syncColumns() {
|
|
234
|
-
const { sortCols } = this.state;
|
|
235
|
-
sortCols.forEach(sortCol => {
|
|
236
|
-
const { compareStrategy } = sortCol;
|
|
237
|
-
if (sortCol.compare) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const finish = (comparer) => {
|
|
241
|
-
const descending = (sortCol === null || sortCol === void 0 ? void 0 : sortCol.descending) === undefined
|
|
242
|
-
? true
|
|
243
|
-
: sortCol === null || sortCol === void 0 ? void 0 : sortCol.descending;
|
|
244
|
-
this.updateSortCol(Object.assign(Object.assign({}, (sortCol || {})), { compareStrategy, compare: comparer.compare, descending }));
|
|
245
|
-
};
|
|
246
|
-
const comparer = comparers[compareStrategy.strategy];
|
|
247
|
-
if (!comparer) {
|
|
248
|
-
comparers[compareStrategy.strategy] = new compareStrategyMap[compareStrategy.strategy](compareStrategy, sortCol.name, this.props.formContext);
|
|
249
|
-
const instance = comparers[compareStrategy.strategy];
|
|
250
|
-
if (instance.initialize) {
|
|
251
|
-
instance.initialize().then(() => finish(instance));
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
finish(instance);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
finish(comparer);
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
getUiShema(props, { sortCols }, sortedData) {
|
|
263
|
-
var _a;
|
|
264
|
-
const idToSortedIdx = getIdToSortedIdx(sortedData);
|
|
265
|
-
const idToOrigIdx = getIdToSortedIdx(props.formData);
|
|
266
|
-
const nextComponentUiSchema = utils_1.getInnerUiSchema(props.uiSchema);
|
|
267
|
-
const uiOptions = utils_1.getUiOptions(props.uiSchema);
|
|
268
|
-
return Object.assign(Object.assign({}, nextComponentUiSchema), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(nextComponentUiSchema)), { onSortToggle: this.onSortToggle.bind(this), sortCols, ui: getUI(uiOptions.columns, sortCols, this.setSortCols.bind(this), props.formContext), sortableColumns: this.getSortableColumns(props), sortColTooltips: (_a = Object.keys(uiOptions.columns || {})) === null || _a === void 0 ? void 0 : _a.reduce((map, c) => {
|
|
269
|
-
var _a;
|
|
270
|
-
const { tooltip } = ((_a = uiOptions.columns) === null || _a === void 0 ? void 0 : _a[c]) || {};
|
|
271
|
-
if (tooltip) {
|
|
272
|
-
map[c] = tooltip;
|
|
273
|
-
}
|
|
274
|
-
return map;
|
|
275
|
-
}, {}), idxMap: Object.keys(idToOrigIdx).reduce((map, id) => {
|
|
276
|
-
map[idToSortedIdx[id]] = idToOrigIdx[id];
|
|
277
|
-
map["_" + idToOrigIdx[id]] = idToSortedIdx[id];
|
|
278
|
-
return map;
|
|
279
|
-
}, {}) }) });
|
|
280
|
-
}
|
|
281
|
-
getSortableColumns(props) {
|
|
282
|
-
const { uiSchema, schema } = props;
|
|
283
|
-
const { sortableColumns, excludeSortableColumns } = utils_1.getUiOptions(uiSchema);
|
|
284
|
-
if (sortableColumns) {
|
|
285
|
-
if (excludeSortableColumns) {
|
|
286
|
-
return sortableColumns.filter(c => !excludeSortableColumns.includes(c));
|
|
287
|
-
}
|
|
288
|
-
return sortableColumns;
|
|
289
|
-
}
|
|
290
|
-
if (excludeSortableColumns) {
|
|
291
|
-
return Object.keys(schema.items.properties).filter(c => !excludeSortableColumns.includes(c));
|
|
292
|
-
}
|
|
293
|
-
return undefined;
|
|
294
|
-
}
|
|
295
|
-
getNextComponentProps(props, state) {
|
|
296
|
-
const sortedFormData = getSortedData(props.formData || [], props.schema, state, this.sortTimeIdToSortedIdx, this.sortTimeIdToOrigIdx);
|
|
297
|
-
return {
|
|
298
|
-
uiSchema: this.getUiShema(props, state, sortedFormData),
|
|
299
|
-
formData: sortedFormData,
|
|
300
|
-
onChange: this.onChange
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
updateSortCol(sortCol) {
|
|
304
|
-
const existingIdx = this.state.sortCols.findIndex(c => c.name === sortCol.name);
|
|
305
|
-
const _sortCols = [...this.state.sortCols];
|
|
306
|
-
_sortCols.splice(existingIdx === -1 ? _sortCols.length : existingIdx, 1, sortCol);
|
|
307
|
-
this.setSortCols(_sortCols);
|
|
308
|
-
}
|
|
309
|
-
setSortCols(sortCols) {
|
|
310
|
-
this.sortTimeIdToSortedIdx = {};
|
|
311
|
-
this.sortTimeIdToOrigIdx = getIdToOrigIdx(this.props.formData);
|
|
312
|
-
this.setState({ sortCols });
|
|
313
|
-
}
|
|
314
|
-
onSortToggle(name) {
|
|
315
|
-
var _a, _b;
|
|
316
|
-
const { sortCols: _sortCols = [] } = this.state || {};
|
|
317
|
-
const sortCols = [..._sortCols];
|
|
318
|
-
const colSortIdx = sortCols === null || sortCols === void 0 ? void 0 : sortCols.findIndex(s => s.name === name);
|
|
319
|
-
const current = sortCols[colSortIdx];
|
|
320
|
-
const options = utils_1.getUiOptions(this.props.uiSchema);
|
|
321
|
-
const { multisort } = options;
|
|
322
|
-
const colOptions = ((_a = options.columns) === null || _a === void 0 ? void 0 : _a[name]) || {};
|
|
323
|
-
const compareStrategy = (current === null || current === void 0 ? void 0 : current.compareStrategy) || ((_b = colOptions.compareStrategies) === null || _b === void 0 ? void 0 : _b[0]) || { strategy: "default" };
|
|
324
|
-
const { noDescending } = compareStrategy;
|
|
325
|
-
const nextDescending = (current === null || current === void 0 ? void 0 : current.descending) === undefined
|
|
326
|
-
? false
|
|
327
|
-
: current.descending
|
|
328
|
-
? undefined
|
|
329
|
-
: noDescending ? undefined : true;
|
|
330
|
-
const sortCol = Object.assign(Object.assign({}, (current || {})), { compareStrategy,
|
|
331
|
-
name, descending: nextDescending });
|
|
332
|
-
if (!multisort) {
|
|
333
|
-
this.setSortCols([sortCol]);
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
if (current && current.descending === undefined) { // Push to end if the "descending" changes from undefined.
|
|
337
|
-
sortCols.splice(colSortIdx, 1);
|
|
338
|
-
sortCols.push(sortCol);
|
|
339
|
-
}
|
|
340
|
-
else { // Replace current with new
|
|
341
|
-
sortCols.splice(current ? colSortIdx : sortCols.length, 1, sortCol);
|
|
342
|
-
}
|
|
343
|
-
this.setSortCols(sortCols);
|
|
344
|
-
}
|
|
345
|
-
render() {
|
|
346
|
-
const { SchemaField } = this.props.registry.fields;
|
|
347
|
-
const nextProps = this.getNextComponentProps(this.props, this.state);
|
|
348
|
-
return (React.createElement(SchemaField, Object.assign({}, this.props, nextProps, { onChange: this.onChange })));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
exports.default = SortArrayField;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import * as PropTypes from "prop-types";
|
|
3
|
-
import { FieldProps } from "../LajiForm";
|
|
4
|
-
export default class SplitField extends React.Component<FieldProps> {
|
|
5
|
-
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
6
|
-
static propTypes: {
|
|
7
|
-
uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
8
|
-
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
9
|
-
splits: PropTypes.Validator<(PropTypes.InferProps<{
|
|
10
|
-
fields: PropTypes.Validator<(string | null | undefined)[]>;
|
|
11
|
-
uiSchema: PropTypes.Requireable<object>;
|
|
12
|
-
name: PropTypes.Requireable<string>;
|
|
13
|
-
lg: PropTypes.Requireable<number>;
|
|
14
|
-
md: PropTypes.Requireable<number>;
|
|
15
|
-
sm: PropTypes.Requireable<number>;
|
|
16
|
-
xs: PropTypes.Requireable<number>;
|
|
17
|
-
}> | null | undefined)[]>;
|
|
18
|
-
}>>;
|
|
19
|
-
}>>;
|
|
20
|
-
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
21
|
-
type: PropTypes.Requireable<string>;
|
|
22
|
-
}>>;
|
|
23
|
-
formData: PropTypes.Validator<object>;
|
|
24
|
-
};
|
|
25
|
-
render(): JSX.Element;
|
|
26
|
-
renderSplitField: ({ fields }: any) => JSX.Element;
|
|
27
|
-
onChange: (fields: string[]) => (formData: any) => void;
|
|
28
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const React = require("react");
|
|
10
|
-
const PropTypes = require("prop-types");
|
|
11
|
-
const utils_1 = require("../../utils");
|
|
12
|
-
const BaseComponent_1 = require("../BaseComponent");
|
|
13
|
-
const NestField_1 = require("./NestField");
|
|
14
|
-
const ReactContext_1 = require("../../ReactContext");
|
|
15
|
-
const utils_2 = require("@rjsf/utils");
|
|
16
|
-
let SplitField = class SplitField extends React.Component {
|
|
17
|
-
constructor() {
|
|
18
|
-
super(...arguments);
|
|
19
|
-
this.renderSplitField = ({ fields }) => {
|
|
20
|
-
const { SchemaField } = this.props.registry.fields;
|
|
21
|
-
// TODO TS fix typing after NestField ts conversion.
|
|
22
|
-
const _props = NestField_1.getPropsForFields(this.props, fields);
|
|
23
|
-
return (React.createElement(SchemaField, Object.assign({}, this.props, _props, { onChange: this.onChange(fields), name: "" })));
|
|
24
|
-
};
|
|
25
|
-
this.onChange = (fields) => (formData) => {
|
|
26
|
-
this.props.onChange(fields.reduce((updatedFormData, field) => {
|
|
27
|
-
return Object.assign(Object.assign({}, updatedFormData), { [field]: formData[field] });
|
|
28
|
-
}, this.props.formData));
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
render() {
|
|
32
|
-
const TitleFieldTemplate = utils_2.getTemplate("TitleFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
|
|
33
|
-
const DescriptionFieldTemplate = utils_2.getTemplate("DescriptionFieldTemplate", this.props.registry, utils_1.getUiOptions(this.props.uiSchema));
|
|
34
|
-
const { "ui:title": _title } = this.props.uiSchema;
|
|
35
|
-
const { Row, Col } = this.context.theme;
|
|
36
|
-
return (React.createElement("div", null,
|
|
37
|
-
React.createElement(TitleFieldTemplate, { id: `${this.props.idSchema.$id}__title`, title: _title !== undefined ? _title : this.props.title, required: this.props.required || this.props.uiSchema["ui:required"], schema: this.props.schema, uiSchema: this.props.uiSchema, registry: this.props.registry }),
|
|
38
|
-
React.createElement(DescriptionFieldTemplate, { id: `${this.props.idSchema.$id}__description`, schema: this.props.schema, description: this.props.description, registry: this.props.registry }),
|
|
39
|
-
React.createElement(Row, null, utils_1.getUiOptions(this.props.uiSchema).splits.map((split, i) => React.createElement(Col, { md: split.md, lg: split.lg, xs: split.xs, sm: split.sm, key: i }, this.renderSplitField(split))))));
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
SplitField.contextType = ReactContext_1.default;
|
|
43
|
-
SplitField.propTypes = {
|
|
44
|
-
uiSchema: PropTypes.shape({
|
|
45
|
-
"ui:options": PropTypes.shape({
|
|
46
|
-
splits: PropTypes.arrayOf(PropTypes.shape({
|
|
47
|
-
fields: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
48
|
-
uiSchema: PropTypes.object,
|
|
49
|
-
name: PropTypes.string,
|
|
50
|
-
lg: PropTypes.number,
|
|
51
|
-
md: PropTypes.number,
|
|
52
|
-
sm: PropTypes.number,
|
|
53
|
-
xs: PropTypes.number
|
|
54
|
-
})).isRequired
|
|
55
|
-
}).isRequired
|
|
56
|
-
}),
|
|
57
|
-
schema: PropTypes.shape({
|
|
58
|
-
type: PropTypes.oneOf(["object"])
|
|
59
|
-
}).isRequired,
|
|
60
|
-
formData: PropTypes.object.isRequired
|
|
61
|
-
};
|
|
62
|
-
SplitField = __decorate([
|
|
63
|
-
BaseComponent_1.default
|
|
64
|
-
], SplitField);
|
|
65
|
-
exports.default = SplitField;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export default class StringToArrayField extends React.Component<any, any, any> {
|
|
2
|
-
static propTypes: {
|
|
3
|
-
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
4
|
-
type: PropTypes.Requireable<string>;
|
|
5
|
-
}>>;
|
|
6
|
-
formData: PropTypes.Requireable<string>;
|
|
7
|
-
};
|
|
8
|
-
static getName(): string;
|
|
9
|
-
constructor(props: any);
|
|
10
|
-
constructor(props: any, context: any);
|
|
11
|
-
getStateFromProps(props: any): {
|
|
12
|
-
schema: {
|
|
13
|
-
type: string;
|
|
14
|
-
title: any;
|
|
15
|
-
items: any;
|
|
16
|
-
};
|
|
17
|
-
formData: any;
|
|
18
|
-
uiSchema: any;
|
|
19
|
-
onChange: (formData: any) => void;
|
|
20
|
-
};
|
|
21
|
-
onChange: (formData: any) => void;
|
|
22
|
-
}
|
|
23
|
-
import * as React from "react";
|
|
24
|
-
import * as PropTypes from "prop-types";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const React = require("react");
|
|
10
|
-
const PropTypes = require("prop-types");
|
|
11
|
-
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
12
|
-
const utils_1 = require("../../utils");
|
|
13
|
-
let StringToArrayField = class StringToArrayField extends React.Component {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.onChange = (formData) => {
|
|
17
|
-
const { delimiter = " " } = this.getUiOptions();
|
|
18
|
-
this.props.onChange(formData.filter(v => v).join(delimiter));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
static getName() { return "StringToArrayField"; }
|
|
22
|
-
getStateFromProps(props) {
|
|
23
|
-
const { formData = "" } = props;
|
|
24
|
-
const { delimiter = " " } = this.getUiOptions();
|
|
25
|
-
const { "ui:disabled": disabled, "ui:readonly": readonly } = props.uiSchema;
|
|
26
|
-
const innerUiSchema = utils_1.getInnerUiSchema(props.uiSchema);
|
|
27
|
-
return {
|
|
28
|
-
schema: {
|
|
29
|
-
type: "array",
|
|
30
|
-
title: props.schema.title,
|
|
31
|
-
items: Object.assign(Object.assign({}, props.schema), { title: "" })
|
|
32
|
-
},
|
|
33
|
-
formData: formData.split(delimiter),
|
|
34
|
-
uiSchema: Object.assign({ "ui:disabled": disabled, "ui:readonly": readonly }, innerUiSchema),
|
|
35
|
-
onChange: this.onChange
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
StringToArrayField.propTypes = {
|
|
40
|
-
schema: PropTypes.shape({
|
|
41
|
-
type: PropTypes.oneOf(["string"])
|
|
42
|
-
}).isRequired,
|
|
43
|
-
formData: PropTypes.string
|
|
44
|
-
};
|
|
45
|
-
StringToArrayField = __decorate([
|
|
46
|
-
VirtualSchemaField_1.default
|
|
47
|
-
], StringToArrayField);
|
|
48
|
-
exports.default = StringToArrayField;
|