@luomus/laji-form 15.1.4 → 15.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ApiClient.d.ts +46 -0
- package/lib/ApiClient.js +93 -0
- package/lib/Context.d.ts +8 -0
- package/lib/Context.js +18 -0
- package/lib/ReactContext.d.ts +7 -0
- package/lib/ReactContext.js +5 -0
- package/lib/components/BaseComponent.d.ts +9 -0
- package/lib/components/BaseComponent.js +29 -0
- package/lib/components/LajiForm.d.ts +221 -0
- package/lib/components/LajiForm.js +616 -0
- package/lib/components/VirtualSchemaField.d.ts +42 -0
- package/lib/components/VirtualSchemaField.js +74 -0
- package/lib/components/components.d.ts +119 -0
- package/lib/components/components.js +606 -0
- package/lib/components/fields/AnnotationField.d.ts +34 -0
- package/lib/components/fields/AnnotationField.js +242 -0
- package/lib/components/fields/AnyToBooleanField.d.ts +18 -0
- package/lib/components/fields/AnyToBooleanField.js +20 -0
- package/lib/components/fields/ArrayBulkField.d.ts +23 -0
- package/lib/components/fields/ArrayBulkField.js +82 -0
- package/lib/components/fields/ArrayCombinerField.d.ts +36 -0
- package/lib/components/fields/ArrayCombinerField.js +138 -0
- package/lib/components/fields/ArrayField.d.ts +39 -0
- package/lib/components/fields/ArrayField.js +148 -0
- package/lib/components/fields/AsArrayField.d.ts +292 -0
- package/lib/components/fields/AsArrayField.js +38 -0
- package/lib/components/fields/AudioArrayField.d.ts +22 -0
- package/lib/components/fields/AudioArrayField.js +100 -0
- package/lib/components/fields/AutoArrayField.d.ts +24 -0
- package/lib/components/fields/AutoArrayField.js +56 -0
- package/lib/components/fields/AutosuggestField.d.ts +69 -0
- package/lib/components/fields/AutosuggestField.js +299 -0
- package/lib/components/fields/CombinedValueDisplayField.d.ts +41 -0
- package/lib/components/fields/CombinedValueDisplayField.js +100 -0
- package/lib/components/fields/ConditionalOnChangeField.d.ts +42 -0
- package/lib/components/fields/ConditionalOnChangeField.js +107 -0
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +123 -0
- package/lib/components/fields/ConditionalUiSchemaField.js +143 -0
- package/lib/components/fields/ContextInjectionField.d.ts +24 -0
- package/lib/components/fields/ContextInjectionField.js +68 -0
- package/lib/components/fields/DataLeakerField.d.ts +40 -0
- package/lib/components/fields/DataLeakerField.js +68 -0
- package/lib/components/fields/DefaultValueArrayField.d.ts +34 -0
- package/lib/components/fields/DefaultValueArrayField.js +59 -0
- package/lib/components/fields/DependentBooleanField.d.ts +38 -0
- package/lib/components/fields/DependentBooleanField.js +87 -0
- package/lib/components/fields/DependentDisableField.d.ts +35 -0
- package/lib/components/fields/DependentDisableField.js +71 -0
- package/lib/components/fields/EnumRangeArrayField.d.ts +27 -0
- package/lib/components/fields/EnumRangeArrayField.js +115 -0
- package/lib/components/fields/ExtraLabelRowField.d.ts +38 -0
- package/lib/components/fields/ExtraLabelRowField.js +100 -0
- package/lib/components/fields/FakePropertyField.d.ts +18 -0
- package/lib/components/fields/FakePropertyField.js +48 -0
- package/lib/components/fields/FilterArrayField.d.ts +73 -0
- package/lib/components/fields/FilterArrayField.js +121 -0
- package/lib/components/fields/FlatField.d.ts +29 -0
- package/lib/components/fields/FlatField.js +171 -0
- package/lib/components/fields/GeocoderField.d.ts +47 -0
- package/lib/components/fields/GeocoderField.js +372 -0
- package/lib/components/fields/GridLayoutField.d.ts +18 -0
- package/lib/components/fields/GridLayoutField.js +32 -0
- package/lib/components/fields/HiddenField.d.ts +10 -0
- package/lib/components/fields/HiddenField.js +11 -0
- package/lib/components/fields/ImageArrayField.d.ts +172 -0
- package/lib/components/fields/ImageArrayField.js +699 -0
- package/lib/components/fields/ImageDisplayField.d.ts +18 -0
- package/lib/components/fields/ImageDisplayField.js +44 -0
- package/lib/components/fields/InitiallyHiddenField.d.ts +21 -0
- package/lib/components/fields/InitiallyHiddenField.js +58 -0
- package/lib/components/fields/InjectDefaultValueField.d.ts +37 -0
- package/lib/components/fields/InjectDefaultValueField.js +68 -0
- package/lib/components/fields/InjectField.d.ts +46 -0
- package/lib/components/fields/InjectField.js +88 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +25 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.js +61 -0
- package/lib/components/fields/LocalityField.d.ts +22 -0
- package/lib/components/fields/LocalityField.js +94 -0
- package/lib/components/fields/LocationChooserField.d.ts +27 -0
- package/lib/components/fields/LocationChooserField.js +440 -0
- package/lib/components/fields/MapArrayField.d.ts +78 -0
- package/lib/components/fields/MapArrayField.js +1783 -0
- package/lib/components/fields/MapField.d.ts +48 -0
- package/lib/components/fields/MapField.js +434 -0
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +25 -0
- package/lib/components/fields/MultiAnyToBooleanField.js +100 -0
- package/lib/components/fields/MultiArrayField.d.ts +53 -0
- package/lib/components/fields/MultiArrayField.js +224 -0
- package/lib/components/fields/MultiLanguageField.d.ts +13 -0
- package/lib/components/fields/MultiLanguageField.js +52 -0
- package/lib/components/fields/MultiTagArrayField.d.ts +36 -0
- package/lib/components/fields/MultiTagArrayField.js +142 -0
- package/lib/components/fields/NamedPlaceChooserField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceChooserField.js +380 -0
- package/lib/components/fields/NamedPlaceSaverField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceSaverField.js +237 -0
- package/lib/components/fields/NestField.d.ts +148 -0
- package/lib/components/fields/NestField.js +289 -0
- package/lib/components/fields/ObjectField.d.ts +2 -0
- package/lib/components/fields/ObjectField.js +119 -0
- package/lib/components/fields/PdfArrayField.d.ts +21 -0
- package/lib/components/fields/PdfArrayField.js +40 -0
- package/lib/components/fields/PrefillingArrayField.d.ts +22 -0
- package/lib/components/fields/PrefillingArrayField.js +65 -0
- package/lib/components/fields/SchemaField.d.ts +7 -0
- package/lib/components/fields/SchemaField.js +109 -0
- package/lib/components/fields/ScopeField.d.ts +85 -0
- package/lib/components/fields/ScopeField.js +521 -0
- package/lib/components/fields/SectionArrayField.d.ts +38 -0
- package/lib/components/fields/SectionArrayField.js +618 -0
- package/lib/components/fields/SelectTreeField.d.ts +39 -0
- package/lib/components/fields/SelectTreeField.js +143 -0
- package/lib/components/fields/SingleActiveArrayField.d.ts +49 -0
- package/lib/components/fields/SingleActiveArrayField.js +974 -0
- package/lib/components/fields/SingleItemArrayField.d.ts +15 -0
- package/lib/components/fields/SingleItemArrayField.js +60 -0
- package/lib/components/fields/SortArrayField.d.ts +73 -0
- package/lib/components/fields/SortArrayField.js +351 -0
- package/lib/components/fields/SplitField.d.ts +28 -0
- package/lib/components/fields/SplitField.js +65 -0
- package/lib/components/fields/StringToArrayField.d.ts +24 -0
- package/lib/components/fields/StringToArrayField.js +48 -0
- package/lib/components/fields/SumField.d.ts +35 -0
- package/lib/components/fields/SumField.js +83 -0
- package/lib/components/fields/TableField.d.ts +18 -0
- package/lib/components/fields/TableField.js +136 -0
- package/lib/components/fields/TagArrayField.d.ts +38 -0
- package/lib/components/fields/TagArrayField.js +128 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +26 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +81 -0
- package/lib/components/fields/UiFieldApplierField.d.ts +30 -0
- package/lib/components/fields/UiFieldApplierField.js +106 -0
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +42 -0
- package/lib/components/fields/UiFieldMapperArrayField.js +121 -0
- package/lib/components/fields/UnitCountShorthandField.d.ts +22 -0
- package/lib/components/fields/UnitCountShorthandField.js +149 -0
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +26 -0
- package/lib/components/fields/UnitListShorthandArrayField.js +108 -0
- package/lib/components/fields/UnitShorthandField.d.ts +32 -0
- package/lib/components/fields/UnitShorthandField.js +220 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +85 -0
- package/lib/components/templates/ArrayFieldTemplate.js +416 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +11 -0
- package/lib/components/templates/BaseInputTemplate.js +80 -0
- package/lib/components/templates/DescriptionField.d.ts +1 -0
- package/lib/components/templates/DescriptionField.js +37 -0
- package/lib/components/templates/ErrorListTemplate.d.ts +9 -0
- package/lib/components/templates/ErrorListTemplate.js +95 -0
- package/lib/components/templates/FieldTemplate.d.ts +6 -0
- package/lib/components/templates/FieldTemplate.js +112 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ObjectFieldTemplate.js +66 -0
- package/lib/components/templates/TitleField.d.ts +9 -0
- package/lib/components/templates/TitleField.js +51 -0
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +20 -0
- package/lib/components/widgets/AnyToBooleanWidget.js +49 -0
- package/lib/components/widgets/AutosuggestWidget.d.ts +66 -0
- package/lib/components/widgets/AutosuggestWidget.js +1127 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +37 -0
- package/lib/components/widgets/CheckboxWidget.js +139 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +62 -0
- package/lib/components/widgets/DateTimeWidget.js +251 -0
- package/lib/components/widgets/DateWidget.d.ts +23 -0
- package/lib/components/widgets/DateWidget.js +41 -0
- package/lib/components/widgets/HiddenWidget.d.ts +15 -0
- package/lib/components/widgets/HiddenWidget.js +19 -0
- package/lib/components/widgets/ImageSelectWidget.d.ts +14 -0
- package/lib/components/widgets/ImageSelectWidget.js +57 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +43 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +237 -0
- package/lib/components/widgets/InputGroupWidget.d.ts +21 -0
- package/lib/components/widgets/InputGroupWidget.js +36 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +21 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +47 -0
- package/lib/components/widgets/NumberWidget.d.ts +13 -0
- package/lib/components/widgets/NumberWidget.js +21 -0
- package/lib/components/widgets/PlainTextWidget.d.ts +12 -0
- package/lib/components/widgets/PlainTextWidget.js +24 -0
- package/lib/components/widgets/SelectWidget.d.ts +52 -0
- package/lib/components/widgets/SelectWidget.js +158 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +19 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.js +59 -0
- package/lib/components/widgets/TaxonImageWidget.d.ts +13 -0
- package/lib/components/widgets/TaxonImageWidget.js +30 -0
- package/lib/components/widgets/TextSelectWidget.d.ts +25 -0
- package/lib/components/widgets/TextSelectWidget.js +94 -0
- package/lib/components/widgets/TextareaWidget.d.ts +32 -0
- package/lib/components/widgets/TextareaWidget.js +87 -0
- package/lib/components/widgets/TimeWidget.d.ts +11 -0
- package/lib/components/widgets/TimeWidget.js +19 -0
- package/lib/components/widgets/URLWidget.d.ts +14 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/UpperCaseWidget.d.ts +13 -0
- package/lib/components/widgets/UpperCaseWidget.js +21 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +50 -0
- package/lib/services/blocker-service.d.ts +11 -0
- package/lib/services/blocker-service.js +55 -0
- package/lib/services/custom-event-service.d.ts +17 -0
- package/lib/services/custom-event-service.js +35 -0
- package/lib/services/dom-id-service.d.ts +8 -0
- package/lib/services/dom-id-service.js +30 -0
- package/lib/services/focus-service.d.ts +13 -0
- package/lib/services/focus-service.js +60 -0
- package/lib/services/id-service.d.ts +22 -0
- package/lib/services/id-service.js +130 -0
- package/lib/services/key-handler-service.d.ts +56 -0
- package/lib/services/key-handler-service.js +184 -0
- package/lib/services/root-instance-service.d.ts +25 -0
- package/lib/services/root-instance-service.js +49 -0
- package/lib/services/settings-service.d.ts +34 -0
- package/lib/services/settings-service.js +154 -0
- package/lib/services/singleton-map-service.d.ts +23 -0
- package/lib/services/singleton-map-service.js +44 -0
- package/lib/services/submit-hook-service.d.ts +24 -0
- package/lib/services/submit-hook-service.js +73 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +4 -0
- package/lib/themes/bs3.d.ts +3 -0
- package/lib/themes/bs3.js +133 -0
- package/lib/themes/bs5.d.ts +3 -0
- package/lib/themes/bs5.js +111 -0
- package/lib/themes/glyphicon-fa-mapping.d.ts +3 -0
- package/lib/themes/glyphicon-fa-mapping.js +271 -0
- package/lib/themes/stub.d.ts +3 -0
- package/lib/themes/stub.js +82 -0
- package/lib/themes/theme.d.ts +233 -0
- package/lib/themes/theme.js +2 -0
- package/lib/translations.json +847 -0
- package/lib/utils.d.ts +167 -0
- package/lib/utils.js +1185 -0
- package/lib/validation.d.ts +7 -0
- package/lib/validation.js +141 -0
- package/package.json +2 -2
- package/patches/protractor++webdriver-manager+12.1.8.patch +0 -20395
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
window.PropTypes = PropTypes;
|
|
13
|
+
const conditionPropType = {
|
|
14
|
+
regexp: PropTypes.string,
|
|
15
|
+
length: PropTypes.number,
|
|
16
|
+
reverse: PropTypes.bool,
|
|
17
|
+
};
|
|
18
|
+
const rulePropType = PropTypes.shape({
|
|
19
|
+
transformations: PropTypes.object.isRequired,
|
|
20
|
+
conditions: (props, propName, componentName) => Object.keys(props[propName]).every(prop => PropTypes.checkPropTypes(conditionPropType, props[propName][prop], propName, componentName))
|
|
21
|
+
}).isRequired;
|
|
22
|
+
/**
|
|
23
|
+
* Changes formData on onChange event according to conditional rules.
|
|
24
|
+
* uiSchema = {
|
|
25
|
+
* "ui:options": {
|
|
26
|
+
* rules: { // Can also be an array of rules
|
|
27
|
+
* transformations: {
|
|
28
|
+
* <field name to change if conditions met>: <new value>
|
|
29
|
+
* },
|
|
30
|
+
* conditions: {
|
|
31
|
+
* <conditional field name>: { // Note that regexp and length must both pass for this rule to pass.
|
|
32
|
+
* regexp: <string> <if the conditional field value matches this regexp, this condition will pass>
|
|
33
|
+
* length: <number> <if the conditional field value length is equal or more, this conndition will pass>
|
|
34
|
+
* reverse: <boolean> <Reverses the passing value>
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
let ConditionalOnChangeField = class ConditionalOnChangeField extends React.Component {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.onChange = (formData) => {
|
|
45
|
+
const { rules } = this.getUiOptions();
|
|
46
|
+
(Array.isArray(rules) ? rules : [rules]).forEach(({ conditions, transformations }) => {
|
|
47
|
+
let passes = true;
|
|
48
|
+
// If transforming field is updated, do nothing
|
|
49
|
+
// (If a transforming field is also a condition field, the field would take the conditional value always when updated).
|
|
50
|
+
if (Object.keys(transformations).some(field => formData && formData[field] && formData[field] !== this.props.formData[field])) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// If condition fields didn't change, do nothing.
|
|
54
|
+
if (Object.keys(conditions).every(field => formData && formData[field] && formData[field] === this.props.formData[field])) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (let field in conditions) {
|
|
58
|
+
const condition = conditions[field];
|
|
59
|
+
const { regexp, length, reverse } = condition;
|
|
60
|
+
if (passes && regexp !== undefined) {
|
|
61
|
+
const regexp = new RegExp(condition.regexp.replace("%default", this.props.schema.properties[field].default));
|
|
62
|
+
const result = `${formData[field]}`.match(regexp);
|
|
63
|
+
passes = reverse ? !result : result;
|
|
64
|
+
}
|
|
65
|
+
if (passes && length !== undefined) {
|
|
66
|
+
const result = (formData[field] || []).length >= length;
|
|
67
|
+
passes = reverse ? !result : result;
|
|
68
|
+
}
|
|
69
|
+
if (!passes)
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (passes) {
|
|
73
|
+
let formDataChange = {};
|
|
74
|
+
if (transformations)
|
|
75
|
+
for (let transformField in transformations) {
|
|
76
|
+
formDataChange[transformField] = transformations[transformField];
|
|
77
|
+
}
|
|
78
|
+
formData = Object.assign(Object.assign({}, formData), formDataChange);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.props.onChange(formData);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
static getName() { return "ConditionalOnChangeField"; }
|
|
85
|
+
getStateFromProps() {
|
|
86
|
+
return { onChange: this.onChange };
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
ConditionalOnChangeField.propTypes = {
|
|
90
|
+
uiSchema: PropTypes.shape({
|
|
91
|
+
"ui:options": PropTypes.shape({
|
|
92
|
+
rules: PropTypes.oneOfType([
|
|
93
|
+
rulePropType,
|
|
94
|
+
PropTypes.arrayOf(rulePropType)
|
|
95
|
+
]).isRequired
|
|
96
|
+
}).isRequired,
|
|
97
|
+
uiSchema: PropTypes.object
|
|
98
|
+
}).isRequired,
|
|
99
|
+
schema: PropTypes.shape({
|
|
100
|
+
type: PropTypes.oneOf(["object"])
|
|
101
|
+
}).isRequired,
|
|
102
|
+
formData: PropTypes.object.isRequired
|
|
103
|
+
};
|
|
104
|
+
ConditionalOnChangeField = __decorate([
|
|
105
|
+
VirtualSchemaField_1.default
|
|
106
|
+
], ConditionalOnChangeField);
|
|
107
|
+
exports.default = ConditionalOnChangeField;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const rulePropType: PropTypes.Requireable<string | PropTypes.InferProps<{
|
|
2
|
+
container: PropTypes.Requireable<string>;
|
|
3
|
+
field: PropTypes.Validator<string>;
|
|
4
|
+
regexp: PropTypes.Requireable<string>;
|
|
5
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
6
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
7
|
+
complement: PropTypes.Requireable<boolean>;
|
|
8
|
+
}>>;
|
|
9
|
+
export const operationPropType: PropTypes.Requireable<PropTypes.InferProps<{
|
|
10
|
+
type: PropTypes.Requireable<string>;
|
|
11
|
+
uiSchema: PropTypes.Validator<object>;
|
|
12
|
+
}>>;
|
|
13
|
+
export const rulesPropType: PropTypes.Requireable<string | PropTypes.InferProps<{
|
|
14
|
+
container: PropTypes.Requireable<string>;
|
|
15
|
+
field: PropTypes.Validator<string>;
|
|
16
|
+
regexp: PropTypes.Requireable<string>;
|
|
17
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
18
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
19
|
+
complement: PropTypes.Requireable<boolean>;
|
|
20
|
+
}> | (string | PropTypes.InferProps<{
|
|
21
|
+
container: PropTypes.Requireable<string>;
|
|
22
|
+
field: PropTypes.Validator<string>;
|
|
23
|
+
regexp: PropTypes.Requireable<string>;
|
|
24
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
25
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
26
|
+
complement: PropTypes.Requireable<boolean>;
|
|
27
|
+
}> | null | undefined)[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Transforms uiSchema according to conditional cases. Cases are not mutually exclusive.
|
|
30
|
+
* uiSchema = {"ui:options": {
|
|
31
|
+
* cases: [
|
|
32
|
+
* rules: [
|
|
33
|
+
* {
|
|
34
|
+
* regexp: The regexp that the field must match.
|
|
35
|
+
* valueIn: An array that the field must be in.
|
|
36
|
+
* field: The field that the rule is being checked on (can be a JSON pointer or a field name)
|
|
37
|
+
* }
|
|
38
|
+
* ],
|
|
39
|
+
* operations: [ // All the operations are performed if all rules pass.
|
|
40
|
+
* {
|
|
41
|
+
* type: "merge" or "wrap" "replace". "merge" deeply merges the conditional uiSchema to the nested uiSchema.
|
|
42
|
+
* "wrap" sets the nested uiSchema inside conditional uiSchema.
|
|
43
|
+
* "replace" (default) replaces nested uiSchema with conditional uiSchema.
|
|
44
|
+
* uiSchema: conditional uiSchema to use.
|
|
45
|
+
* }
|
|
46
|
+
* ],
|
|
47
|
+
* else: [<same as operations>] // Operations performed if the rules do not pass.
|
|
48
|
+
* cache: <boolean> true by default. If you know the cases will cache, set this to false.
|
|
49
|
+
* There will be a performance penalty on valueIn rule, as they are not indexed without caching.
|
|
50
|
+
* ]
|
|
51
|
+
* }
|
|
52
|
+
* uiSchema: nested uiSchema
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
export default class ConditionalUiSchemaField extends React.Component<any, any, any> {
|
|
56
|
+
static propTypes: {
|
|
57
|
+
uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
58
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
59
|
+
cases: PropTypes.Requireable<PropTypes.InferProps<{
|
|
60
|
+
rules: PropTypes.Requireable<string | PropTypes.InferProps<{
|
|
61
|
+
container: PropTypes.Requireable<string>;
|
|
62
|
+
field: PropTypes.Validator<string>;
|
|
63
|
+
regexp: PropTypes.Requireable<string>;
|
|
64
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
65
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
66
|
+
complement: PropTypes.Requireable<boolean>;
|
|
67
|
+
}> | (string | PropTypes.InferProps<{
|
|
68
|
+
container: PropTypes.Requireable<string>;
|
|
69
|
+
field: PropTypes.Validator<string>;
|
|
70
|
+
regexp: PropTypes.Requireable<string>;
|
|
71
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
72
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
73
|
+
complement: PropTypes.Requireable<boolean>;
|
|
74
|
+
}> | null | undefined)[]>;
|
|
75
|
+
operations: PropTypes.Requireable<PropTypes.InferProps<{
|
|
76
|
+
type: PropTypes.Requireable<string>;
|
|
77
|
+
uiSchema: PropTypes.Validator<object>;
|
|
78
|
+
}> | (PropTypes.InferProps<{
|
|
79
|
+
type: PropTypes.Requireable<string>;
|
|
80
|
+
uiSchema: PropTypes.Validator<object>;
|
|
81
|
+
}> | null | undefined)[]>;
|
|
82
|
+
}> | (PropTypes.InferProps<{
|
|
83
|
+
rules: PropTypes.Requireable<string | PropTypes.InferProps<{
|
|
84
|
+
container: PropTypes.Requireable<string>;
|
|
85
|
+
field: PropTypes.Validator<string>;
|
|
86
|
+
regexp: PropTypes.Requireable<string>;
|
|
87
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
88
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
89
|
+
complement: PropTypes.Requireable<boolean>;
|
|
90
|
+
}> | (string | PropTypes.InferProps<{
|
|
91
|
+
container: PropTypes.Requireable<string>;
|
|
92
|
+
field: PropTypes.Validator<string>;
|
|
93
|
+
regexp: PropTypes.Requireable<string>;
|
|
94
|
+
valueIn: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
95
|
+
valueLengthLessThan: PropTypes.Requireable<number>;
|
|
96
|
+
complement: PropTypes.Requireable<boolean>;
|
|
97
|
+
}> | null | undefined)[]>;
|
|
98
|
+
operations: PropTypes.Requireable<PropTypes.InferProps<{
|
|
99
|
+
type: PropTypes.Requireable<string>;
|
|
100
|
+
uiSchema: PropTypes.Validator<object>;
|
|
101
|
+
}> | (PropTypes.InferProps<{
|
|
102
|
+
type: PropTypes.Requireable<string>;
|
|
103
|
+
uiSchema: PropTypes.Validator<object>;
|
|
104
|
+
}> | null | undefined)[]>;
|
|
105
|
+
}> | null | undefined)[]>;
|
|
106
|
+
cache: any;
|
|
107
|
+
}>>;
|
|
108
|
+
}>>;
|
|
109
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
110
|
+
type: PropTypes.Requireable<string>;
|
|
111
|
+
}>>;
|
|
112
|
+
};
|
|
113
|
+
static getName(): string;
|
|
114
|
+
constructor(props: any);
|
|
115
|
+
constructor(props: any, context: any);
|
|
116
|
+
cache: {};
|
|
117
|
+
getStateFromProps(props: any): {
|
|
118
|
+
uiSchema: any;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function computeUiSchema(uiSchema: any, operations: any, arrayMerge?: string): any;
|
|
122
|
+
import * as PropTypes from "prop-types";
|
|
123
|
+
import * as React from "react";
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
exports.computeUiSchema = exports.rulesPropType = exports.operationPropType = exports.rulePropType = void 0;
|
|
10
|
+
const React = require("react");
|
|
11
|
+
const PropTypes = require("prop-types");
|
|
12
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
13
|
+
const deepmerge = require("deepmerge");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
exports.rulePropType = PropTypes.oneOfType([
|
|
16
|
+
PropTypes.shape({
|
|
17
|
+
container: PropTypes.string,
|
|
18
|
+
field: PropTypes.string.isRequired,
|
|
19
|
+
regexp: PropTypes.string,
|
|
20
|
+
valueIn: PropTypes.arrayOf(PropTypes.string),
|
|
21
|
+
valueLengthLessThan: PropTypes.number,
|
|
22
|
+
complement: PropTypes.bool
|
|
23
|
+
}),
|
|
24
|
+
PropTypes.oneOf(["isAdmin", "isEdit"])
|
|
25
|
+
]);
|
|
26
|
+
exports.operationPropType = PropTypes.shape({
|
|
27
|
+
type: PropTypes.oneOf(["merge", "wrap"]),
|
|
28
|
+
uiSchema: PropTypes.object.isRequired,
|
|
29
|
+
});
|
|
30
|
+
exports.rulesPropType = PropTypes.oneOfType([
|
|
31
|
+
exports.rulePropType,
|
|
32
|
+
PropTypes.arrayOf(exports.rulePropType)
|
|
33
|
+
]);
|
|
34
|
+
const casePropType = PropTypes.shape({
|
|
35
|
+
rules: exports.rulesPropType,
|
|
36
|
+
operations: PropTypes.oneOfType([
|
|
37
|
+
exports.operationPropType,
|
|
38
|
+
PropTypes.arrayOf(exports.operationPropType)
|
|
39
|
+
])
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Transforms uiSchema according to conditional cases. Cases are not mutually exclusive.
|
|
43
|
+
* uiSchema = {"ui:options": {
|
|
44
|
+
* cases: [
|
|
45
|
+
* rules: [
|
|
46
|
+
* {
|
|
47
|
+
* regexp: The regexp that the field must match.
|
|
48
|
+
* valueIn: An array that the field must be in.
|
|
49
|
+
* field: The field that the rule is being checked on (can be a JSON pointer or a field name)
|
|
50
|
+
* }
|
|
51
|
+
* ],
|
|
52
|
+
* operations: [ // All the operations are performed if all rules pass.
|
|
53
|
+
* {
|
|
54
|
+
* type: "merge" or "wrap" "replace". "merge" deeply merges the conditional uiSchema to the nested uiSchema.
|
|
55
|
+
* "wrap" sets the nested uiSchema inside conditional uiSchema.
|
|
56
|
+
* "replace" (default) replaces nested uiSchema with conditional uiSchema.
|
|
57
|
+
* uiSchema: conditional uiSchema to use.
|
|
58
|
+
* }
|
|
59
|
+
* ],
|
|
60
|
+
* else: [<same as operations>] // Operations performed if the rules do not pass.
|
|
61
|
+
* cache: <boolean> true by default. If you know the cases will cache, set this to false.
|
|
62
|
+
* There will be a performance penalty on valueIn rule, as they are not indexed without caching.
|
|
63
|
+
* ]
|
|
64
|
+
* }
|
|
65
|
+
* uiSchema: nested uiSchema
|
|
66
|
+
* }
|
|
67
|
+
*/
|
|
68
|
+
let ConditionalUiSchemaField = class ConditionalUiSchemaField extends React.Component {
|
|
69
|
+
constructor() {
|
|
70
|
+
super(...arguments);
|
|
71
|
+
this.cache = {};
|
|
72
|
+
}
|
|
73
|
+
static getName() { return "ConditionalUiSchemaField"; }
|
|
74
|
+
getStateFromProps(props) {
|
|
75
|
+
const { cases = [], cache = true, arrayMerge } = this.getUiOptions();
|
|
76
|
+
const { uiSchema } = props;
|
|
77
|
+
let computedUiSchema = uiSchema;
|
|
78
|
+
(Array.isArray(cases) ? cases : [cases]).forEach(({ rules = [], operations = [], else: _else, arrayMerge: _arrayMerge }, idx) => {
|
|
79
|
+
let passes;
|
|
80
|
+
if (cache) {
|
|
81
|
+
if (!this.cache[idx]) {
|
|
82
|
+
this.cache[idx] = {};
|
|
83
|
+
}
|
|
84
|
+
const check = utils_1.checkRules(rules, props, this.cache[idx]);
|
|
85
|
+
const { cache } = check;
|
|
86
|
+
passes = check.passes;
|
|
87
|
+
this.cache = cache;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
passes = utils_1.checkRules(rules, props);
|
|
91
|
+
}
|
|
92
|
+
if (passes) {
|
|
93
|
+
computedUiSchema = exports.computeUiSchema(computedUiSchema, operations, _arrayMerge || arrayMerge);
|
|
94
|
+
}
|
|
95
|
+
else if (_else) {
|
|
96
|
+
computedUiSchema = exports.computeUiSchema(computedUiSchema, _else, _arrayMerge || arrayMerge);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return { uiSchema: computedUiSchema };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
ConditionalUiSchemaField.propTypes = {
|
|
103
|
+
uiSchema: PropTypes.shape({
|
|
104
|
+
"ui:options": PropTypes.shape({
|
|
105
|
+
cases: PropTypes.oneOfType([
|
|
106
|
+
casePropType,
|
|
107
|
+
PropTypes.arrayOf(casePropType)
|
|
108
|
+
]),
|
|
109
|
+
cache: PropTypes.boolean
|
|
110
|
+
})
|
|
111
|
+
}),
|
|
112
|
+
schema: PropTypes.shape({
|
|
113
|
+
type: PropTypes.oneOf(["array", "object", "string", "integer", "number", "boolean"])
|
|
114
|
+
}).isRequired,
|
|
115
|
+
};
|
|
116
|
+
ConditionalUiSchemaField = __decorate([
|
|
117
|
+
VirtualSchemaField_1.default
|
|
118
|
+
], ConditionalUiSchemaField);
|
|
119
|
+
exports.default = ConditionalUiSchemaField;
|
|
120
|
+
const computeUiSchema = (uiSchema, operations, arrayMerge = "replace") => {
|
|
121
|
+
if (!operations)
|
|
122
|
+
return uiSchema;
|
|
123
|
+
return (Array.isArray(operations) ? operations : [operations]).reduce((_uiSchema, op) => {
|
|
124
|
+
switch (op.type) {
|
|
125
|
+
case "merge":
|
|
126
|
+
uiSchema = deepmerge(uiSchema, op.uiSchema, { arrayMerge: arrayMerge === "replace"
|
|
127
|
+
? (a1, a2) => a2
|
|
128
|
+
: (a1, a2) => [...a1, ...a2] });
|
|
129
|
+
break;
|
|
130
|
+
case "wrap":
|
|
131
|
+
uiSchema = Object.assign(Object.assign({}, op.uiSchema), { uiSchema });
|
|
132
|
+
break;
|
|
133
|
+
case "jsonPointer":
|
|
134
|
+
uiSchema = utils_1.updateSafelyWithJSONPointer(uiSchema, op.value, op.pointer);
|
|
135
|
+
break;
|
|
136
|
+
case "replace":
|
|
137
|
+
default:
|
|
138
|
+
uiSchema = op.uiSchema;
|
|
139
|
+
}
|
|
140
|
+
return uiSchema;
|
|
141
|
+
}, uiSchema);
|
|
142
|
+
};
|
|
143
|
+
exports.computeUiSchema = computeUiSchema;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function getInjectedUiSchema(uiSchema: any, injections: any, uiSchemaContext: any): any;
|
|
2
|
+
export default class ContextInjectionField extends React.Component<any, any, any> {
|
|
3
|
+
static propTypes: {
|
|
4
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
5
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
6
|
+
injections: PropTypes.Validator<object>;
|
|
7
|
+
target: PropTypes.Requireable<string>;
|
|
8
|
+
}>>;
|
|
9
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
10
|
+
}>>;
|
|
11
|
+
formData: PropTypes.Requireable<string | number | boolean | object>;
|
|
12
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
13
|
+
type: PropTypes.Requireable<string>;
|
|
14
|
+
}>>;
|
|
15
|
+
};
|
|
16
|
+
static getName(): string;
|
|
17
|
+
constructor(props: any);
|
|
18
|
+
constructor(props: any, context: any);
|
|
19
|
+
getStateFromProps(props: any): {
|
|
20
|
+
[x: number]: any;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
import * as React from "react";
|
|
24
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
exports.getInjectedUiSchema = void 0;
|
|
10
|
+
const React = require("react");
|
|
11
|
+
const PropTypes = require("prop-types");
|
|
12
|
+
const immutability_helper_1 = require("immutability-helper");
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
15
|
+
let ContextInjectionField = class ContextInjectionField extends React.Component {
|
|
16
|
+
static getName() { return "ContextInjectionField"; }
|
|
17
|
+
getStateFromProps(props) {
|
|
18
|
+
const { injections, target = "uiSchema" } = this.getUiOptions();
|
|
19
|
+
const container = props[target];
|
|
20
|
+
return { [target]: getInjectedUiSchema(container, injections, props.formContext.uiSchemaContext) };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
ContextInjectionField.propTypes = {
|
|
24
|
+
uiSchema: PropTypes.shape({
|
|
25
|
+
"ui:options": PropTypes.shape({
|
|
26
|
+
injections: PropTypes.object.isRequired,
|
|
27
|
+
target: PropTypes.oneOf(["uiSchema", "schema"]),
|
|
28
|
+
}).isRequired,
|
|
29
|
+
uiSchema: PropTypes.object
|
|
30
|
+
}).isRequired,
|
|
31
|
+
formData: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
32
|
+
schema: PropTypes.shape({
|
|
33
|
+
type: PropTypes.oneOf(["array", "object", "string", "integer", "number", "boolean"])
|
|
34
|
+
}).isRequired,
|
|
35
|
+
};
|
|
36
|
+
ContextInjectionField = __decorate([
|
|
37
|
+
VirtualSchemaField_1.default
|
|
38
|
+
], ContextInjectionField);
|
|
39
|
+
exports.default = ContextInjectionField;
|
|
40
|
+
function getInjectedUiSchema(uiSchema, injections, uiSchemaContext) {
|
|
41
|
+
let injected = false;
|
|
42
|
+
const updateObject = {};
|
|
43
|
+
for (let injectionPath in injections) {
|
|
44
|
+
const splitted = injectionPath.substring(1).split("/");
|
|
45
|
+
const last = splitted.pop();
|
|
46
|
+
const tail = splitted.reduce((pointer, path) => {
|
|
47
|
+
if (!pointer[path])
|
|
48
|
+
pointer[path] = {};
|
|
49
|
+
return pointer[path];
|
|
50
|
+
}, updateObject);
|
|
51
|
+
let value = injections[injectionPath];
|
|
52
|
+
if (value.match(/%{.*}/)) {
|
|
53
|
+
while (value.match(/%{.*}/)) {
|
|
54
|
+
const [match, innerValue] = value.match(/%{(.*)}/);
|
|
55
|
+
value = value.replace(match, utils_1.parseJSONPointer(uiSchemaContext, innerValue));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
value = utils_1.parseJSONPointer(uiSchemaContext, value);
|
|
60
|
+
}
|
|
61
|
+
tail[last] = { $set: value };
|
|
62
|
+
injected = true;
|
|
63
|
+
}
|
|
64
|
+
if (injected)
|
|
65
|
+
uiSchema = immutability_helper_1.default(uiSchema, updateObject);
|
|
66
|
+
return uiSchema;
|
|
67
|
+
}
|
|
68
|
+
exports.getInjectedUiSchema = getInjectedUiSchema;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enables leaking any prop to any other prop container.
|
|
3
|
+
*
|
|
4
|
+
* uiSchema = {"ui:options": {
|
|
5
|
+
* props: [
|
|
6
|
+
* {
|
|
7
|
+
* from: If a regular string, a property to copy from formData. If a JSON pointer, the root will be this.props.
|
|
8
|
+
* target: Target where to copy the 'from'. If a regular string, it will be copied to /uischema/ui:options. If a JSON pointer, the root will be this.props.
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
export default class DataLeakerField extends React.Component<any, any, any> {
|
|
12
|
+
static propTypes: {
|
|
13
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
14
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
15
|
+
props: PropTypes.Requireable<PropTypes.InferProps<{
|
|
16
|
+
from: PropTypes.Validator<string>;
|
|
17
|
+
fromArrayKey: PropTypes.Requireable<string>;
|
|
18
|
+
target: PropTypes.Requireable<string>;
|
|
19
|
+
joinArray: PropTypes.Requireable<boolean>;
|
|
20
|
+
}> | (PropTypes.InferProps<{
|
|
21
|
+
from: PropTypes.Validator<string>;
|
|
22
|
+
fromArrayKey: PropTypes.Requireable<string>;
|
|
23
|
+
target: PropTypes.Requireable<string>;
|
|
24
|
+
joinArray: PropTypes.Requireable<boolean>;
|
|
25
|
+
}> | null | undefined)[]>;
|
|
26
|
+
}>>;
|
|
27
|
+
uiSchema: PropTypes.Requireable<object>;
|
|
28
|
+
}>>;
|
|
29
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
30
|
+
type: PropTypes.Requireable<string>;
|
|
31
|
+
}>>;
|
|
32
|
+
formData: PropTypes.Requireable<object>;
|
|
33
|
+
};
|
|
34
|
+
static getName(): string;
|
|
35
|
+
constructor(props: any);
|
|
36
|
+
constructor(props: any, context: any);
|
|
37
|
+
getStateFromProps(props: any): any;
|
|
38
|
+
}
|
|
39
|
+
import * as React from "react";
|
|
40
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
const PropTypes = require("prop-types");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
13
|
+
const propsPropType = PropTypes.shape({
|
|
14
|
+
from: PropTypes.string.isRequired,
|
|
15
|
+
fromArrayKey: PropTypes.string,
|
|
16
|
+
target: PropTypes.string,
|
|
17
|
+
joinArray: PropTypes.bool
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Enables leaking any prop to any other prop container.
|
|
21
|
+
*
|
|
22
|
+
* uiSchema = {"ui:options": {
|
|
23
|
+
* props: [
|
|
24
|
+
* {
|
|
25
|
+
* from: If a regular string, a property to copy from formData. If a JSON pointer, the root will be this.props.
|
|
26
|
+
* target: Target where to copy the 'from'. If a regular string, it will be copied to /uischema/ui:options. If a JSON pointer, the root will be this.props.
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
let DataLeakerField = class DataLeakerField extends React.Component {
|
|
30
|
+
static getName() { return "DataLeakerField"; }
|
|
31
|
+
getStateFromProps(props) {
|
|
32
|
+
const { props: _props = [] } = this.getUiOptions(props.uiSchema);
|
|
33
|
+
return (Array.isArray(_props) ? _props : [_props]).reduce((props, strOrObjProp) => {
|
|
34
|
+
const [fromPath, fromArrayKey, targetPath, joinArray] = ["from", "fromArrayKey", "target", "joinArray"]
|
|
35
|
+
.map(p => strOrObjProp[p]);
|
|
36
|
+
let from = fromPath[0] === "/"
|
|
37
|
+
? utils_1.parseJSONPointer(props, fromPath)
|
|
38
|
+
: utils_1.parseJSONPointer(props.formData, fromPath);
|
|
39
|
+
if (fromArrayKey) {
|
|
40
|
+
from = (from || []).map(obj => obj[fromArrayKey]);
|
|
41
|
+
}
|
|
42
|
+
if (joinArray && Array.isArray(from)) {
|
|
43
|
+
from = from.join(",");
|
|
44
|
+
}
|
|
45
|
+
const _targetPath = targetPath[0] === "/"
|
|
46
|
+
? targetPath
|
|
47
|
+
: `/uiSchema/ui:options/${targetPath}`;
|
|
48
|
+
props = utils_1.updateSafelyWithJSONPointer(props, from, _targetPath);
|
|
49
|
+
return props;
|
|
50
|
+
}, props);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
DataLeakerField.propTypes = {
|
|
54
|
+
uiSchema: PropTypes.shape({
|
|
55
|
+
"ui:options": PropTypes.shape({
|
|
56
|
+
props: PropTypes.oneOfType([PropTypes.arrayOf(propsPropType), propsPropType])
|
|
57
|
+
}),
|
|
58
|
+
uiSchema: PropTypes.object
|
|
59
|
+
}).isRequired,
|
|
60
|
+
schema: PropTypes.shape({
|
|
61
|
+
type: PropTypes.oneOf(["array", "object"])
|
|
62
|
+
}).isRequired,
|
|
63
|
+
formData: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
|
64
|
+
};
|
|
65
|
+
DataLeakerField = __decorate([
|
|
66
|
+
VirtualSchemaField_1.default
|
|
67
|
+
], DataLeakerField);
|
|
68
|
+
exports.default = DataLeakerField;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets given default values to target fields.
|
|
3
|
+
* uiSchema = { "ui:options": {
|
|
4
|
+
* "default": [
|
|
5
|
+
* {
|
|
6
|
+
* field1: defaultValue1,
|
|
7
|
+
* field2: defaultValue2
|
|
8
|
+
* }
|
|
9
|
+
* ...
|
|
10
|
+
* ]
|
|
11
|
+
* }}
|
|
12
|
+
*/
|
|
13
|
+
export default class DefaultValueArrayField extends React.Component<any, any, any> {
|
|
14
|
+
static propTypes: {
|
|
15
|
+
uiSchema: PropTypes.Validator<PropTypes.InferProps<{
|
|
16
|
+
"ui:options": PropTypes.Validator<PropTypes.InferProps<{
|
|
17
|
+
default: PropTypes.Validator<object>;
|
|
18
|
+
}>>;
|
|
19
|
+
}>>;
|
|
20
|
+
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
21
|
+
type: PropTypes.Requireable<string>;
|
|
22
|
+
}>>;
|
|
23
|
+
formData: PropTypes.Validator<any[]>;
|
|
24
|
+
};
|
|
25
|
+
static getName(): string;
|
|
26
|
+
constructor(props: any);
|
|
27
|
+
constructor(props: any, context: any);
|
|
28
|
+
getStateFromProps(): {
|
|
29
|
+
onChange: (formData: any) => void;
|
|
30
|
+
};
|
|
31
|
+
onChange: (formData: any) => void;
|
|
32
|
+
}
|
|
33
|
+
import * as React from "react";
|
|
34
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,59 @@
|
|
|
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 immutability_helper_1 = require("immutability-helper");
|
|
12
|
+
const VirtualSchemaField_1 = require("../VirtualSchemaField");
|
|
13
|
+
/**
|
|
14
|
+
* Sets given default values to target fields.
|
|
15
|
+
* uiSchema = { "ui:options": {
|
|
16
|
+
* "default": [
|
|
17
|
+
* {
|
|
18
|
+
* field1: defaultValue1,
|
|
19
|
+
* field2: defaultValue2
|
|
20
|
+
* }
|
|
21
|
+
* ...
|
|
22
|
+
* ]
|
|
23
|
+
* }}
|
|
24
|
+
*/
|
|
25
|
+
let DefaultValueArrayField = class DefaultValueArrayField extends React.Component {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.onChange = (formData) => {
|
|
29
|
+
const options = this.getUiOptions();
|
|
30
|
+
const _default = options.default;
|
|
31
|
+
Object.keys(_default).forEach(field => {
|
|
32
|
+
if (formData)
|
|
33
|
+
formData.forEach((item, i) => {
|
|
34
|
+
formData = immutability_helper_1.default(formData, { $splice: [[i, 1, immutability_helper_1.default(item, { $merge: { [field]: _default[field] } })]] });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
this.props.onChange(formData);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static getName() { return "DefaultValueArrayField"; }
|
|
41
|
+
getStateFromProps() {
|
|
42
|
+
return { onChange: this.onChange };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
DefaultValueArrayField.propTypes = {
|
|
46
|
+
uiSchema: PropTypes.shape({
|
|
47
|
+
"ui:options": PropTypes.shape({
|
|
48
|
+
default: PropTypes.object.isRequired
|
|
49
|
+
}).isRequired
|
|
50
|
+
}).isRequired,
|
|
51
|
+
schema: PropTypes.shape({
|
|
52
|
+
type: PropTypes.oneOf(["array"])
|
|
53
|
+
}).isRequired,
|
|
54
|
+
formData: PropTypes.oneOfType([PropTypes.array]).isRequired
|
|
55
|
+
};
|
|
56
|
+
DefaultValueArrayField = __decorate([
|
|
57
|
+
VirtualSchemaField_1.default
|
|
58
|
+
], DefaultValueArrayField);
|
|
59
|
+
exports.default = DefaultValueArrayField;
|