@luomus/laji-form 15.1.5 → 15.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ApiClient.d.ts +46 -0
- package/lib/ApiClient.js +93 -0
- package/lib/Context.d.ts +8 -0
- package/lib/Context.js +18 -0
- package/lib/ReactContext.d.ts +7 -0
- package/lib/ReactContext.js +5 -0
- package/lib/components/BaseComponent.d.ts +9 -0
- package/lib/components/BaseComponent.js +29 -0
- package/lib/components/LajiForm.d.ts +221 -0
- package/lib/components/LajiForm.js +616 -0
- package/lib/components/VirtualSchemaField.d.ts +42 -0
- package/lib/components/VirtualSchemaField.js +74 -0
- package/lib/components/components.d.ts +119 -0
- package/lib/components/components.js +606 -0
- package/lib/components/fields/AnnotationField.d.ts +34 -0
- package/lib/components/fields/AnnotationField.js +242 -0
- package/lib/components/fields/AnyToBooleanField.d.ts +18 -0
- package/lib/components/fields/AnyToBooleanField.js +20 -0
- package/lib/components/fields/ArrayBulkField.d.ts +23 -0
- package/lib/components/fields/ArrayBulkField.js +82 -0
- package/lib/components/fields/ArrayCombinerField.d.ts +36 -0
- package/lib/components/fields/ArrayCombinerField.js +138 -0
- package/lib/components/fields/ArrayField.d.ts +39 -0
- package/lib/components/fields/ArrayField.js +148 -0
- package/lib/components/fields/AsArrayField.d.ts +292 -0
- package/lib/components/fields/AsArrayField.js +38 -0
- package/lib/components/fields/AudioArrayField.d.ts +22 -0
- package/lib/components/fields/AudioArrayField.js +100 -0
- package/lib/components/fields/AutoArrayField.d.ts +24 -0
- package/lib/components/fields/AutoArrayField.js +56 -0
- package/lib/components/fields/AutosuggestField.d.ts +69 -0
- package/lib/components/fields/AutosuggestField.js +299 -0
- package/lib/components/fields/CombinedValueDisplayField.d.ts +41 -0
- package/lib/components/fields/CombinedValueDisplayField.js +100 -0
- package/lib/components/fields/ConditionalOnChangeField.d.ts +42 -0
- package/lib/components/fields/ConditionalOnChangeField.js +107 -0
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +123 -0
- package/lib/components/fields/ConditionalUiSchemaField.js +143 -0
- package/lib/components/fields/ContextInjectionField.d.ts +24 -0
- package/lib/components/fields/ContextInjectionField.js +68 -0
- package/lib/components/fields/DataLeakerField.d.ts +40 -0
- package/lib/components/fields/DataLeakerField.js +68 -0
- package/lib/components/fields/DefaultValueArrayField.d.ts +34 -0
- package/lib/components/fields/DefaultValueArrayField.js +59 -0
- package/lib/components/fields/DependentBooleanField.d.ts +38 -0
- package/lib/components/fields/DependentBooleanField.js +87 -0
- package/lib/components/fields/DependentDisableField.d.ts +35 -0
- package/lib/components/fields/DependentDisableField.js +71 -0
- package/lib/components/fields/EnumRangeArrayField.d.ts +27 -0
- package/lib/components/fields/EnumRangeArrayField.js +115 -0
- package/lib/components/fields/ExtraLabelRowField.d.ts +38 -0
- package/lib/components/fields/ExtraLabelRowField.js +100 -0
- package/lib/components/fields/FakePropertyField.d.ts +18 -0
- package/lib/components/fields/FakePropertyField.js +48 -0
- package/lib/components/fields/FilterArrayField.d.ts +73 -0
- package/lib/components/fields/FilterArrayField.js +121 -0
- package/lib/components/fields/FlatField.d.ts +29 -0
- package/lib/components/fields/FlatField.js +171 -0
- package/lib/components/fields/GeocoderField.d.ts +47 -0
- package/lib/components/fields/GeocoderField.js +372 -0
- package/lib/components/fields/GridLayoutField.d.ts +18 -0
- package/lib/components/fields/GridLayoutField.js +32 -0
- package/lib/components/fields/HiddenField.d.ts +10 -0
- package/lib/components/fields/HiddenField.js +11 -0
- package/lib/components/fields/ImageArrayField.d.ts +172 -0
- package/lib/components/fields/ImageArrayField.js +699 -0
- package/lib/components/fields/ImageDisplayField.d.ts +18 -0
- package/lib/components/fields/ImageDisplayField.js +44 -0
- package/lib/components/fields/InitiallyHiddenField.d.ts +21 -0
- package/lib/components/fields/InitiallyHiddenField.js +58 -0
- package/lib/components/fields/InjectDefaultValueField.d.ts +37 -0
- package/lib/components/fields/InjectDefaultValueField.js +68 -0
- package/lib/components/fields/InjectField.d.ts +46 -0
- package/lib/components/fields/InjectField.js +88 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +25 -0
- package/lib/components/fields/InputWithDefaultValueButtonField.js +61 -0
- package/lib/components/fields/LocalityField.d.ts +22 -0
- package/lib/components/fields/LocalityField.js +94 -0
- package/lib/components/fields/LocationChooserField.d.ts +27 -0
- package/lib/components/fields/LocationChooserField.js +440 -0
- package/lib/components/fields/MapArrayField.d.ts +78 -0
- package/lib/components/fields/MapArrayField.js +1783 -0
- package/lib/components/fields/MapField.d.ts +48 -0
- package/lib/components/fields/MapField.js +434 -0
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +25 -0
- package/lib/components/fields/MultiAnyToBooleanField.js +100 -0
- package/lib/components/fields/MultiArrayField.d.ts +53 -0
- package/lib/components/fields/MultiArrayField.js +224 -0
- package/lib/components/fields/MultiLanguageField.d.ts +13 -0
- package/lib/components/fields/MultiLanguageField.js +52 -0
- package/lib/components/fields/MultiTagArrayField.d.ts +36 -0
- package/lib/components/fields/MultiTagArrayField.js +142 -0
- package/lib/components/fields/NamedPlaceChooserField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceChooserField.js +380 -0
- package/lib/components/fields/NamedPlaceSaverField.d.ts +29 -0
- package/lib/components/fields/NamedPlaceSaverField.js +237 -0
- package/lib/components/fields/NestField.d.ts +148 -0
- package/lib/components/fields/NestField.js +289 -0
- package/lib/components/fields/ObjectField.d.ts +2 -0
- package/lib/components/fields/ObjectField.js +119 -0
- package/lib/components/fields/PdfArrayField.d.ts +21 -0
- package/lib/components/fields/PdfArrayField.js +40 -0
- package/lib/components/fields/PrefillingArrayField.d.ts +22 -0
- package/lib/components/fields/PrefillingArrayField.js +65 -0
- package/lib/components/fields/SchemaField.d.ts +7 -0
- package/lib/components/fields/SchemaField.js +109 -0
- package/lib/components/fields/ScopeField.d.ts +85 -0
- package/lib/components/fields/ScopeField.js +521 -0
- package/lib/components/fields/SectionArrayField.d.ts +38 -0
- package/lib/components/fields/SectionArrayField.js +618 -0
- package/lib/components/fields/SelectTreeField.d.ts +39 -0
- package/lib/components/fields/SelectTreeField.js +143 -0
- package/lib/components/fields/SingleActiveArrayField.d.ts +49 -0
- package/lib/components/fields/SingleActiveArrayField.js +974 -0
- package/lib/components/fields/SingleItemArrayField.d.ts +15 -0
- package/lib/components/fields/SingleItemArrayField.js +60 -0
- package/lib/components/fields/SortArrayField.d.ts +73 -0
- package/lib/components/fields/SortArrayField.js +351 -0
- package/lib/components/fields/SplitField.d.ts +28 -0
- package/lib/components/fields/SplitField.js +65 -0
- package/lib/components/fields/StringToArrayField.d.ts +24 -0
- package/lib/components/fields/StringToArrayField.js +48 -0
- package/lib/components/fields/SumField.d.ts +35 -0
- package/lib/components/fields/SumField.js +83 -0
- package/lib/components/fields/TableField.d.ts +18 -0
- package/lib/components/fields/TableField.js +136 -0
- package/lib/components/fields/TagArrayField.d.ts +38 -0
- package/lib/components/fields/TagArrayField.js +128 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +26 -0
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +81 -0
- package/lib/components/fields/UiFieldApplierField.d.ts +30 -0
- package/lib/components/fields/UiFieldApplierField.js +106 -0
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +42 -0
- package/lib/components/fields/UiFieldMapperArrayField.js +121 -0
- package/lib/components/fields/UnitCountShorthandField.d.ts +22 -0
- package/lib/components/fields/UnitCountShorthandField.js +149 -0
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +26 -0
- package/lib/components/fields/UnitListShorthandArrayField.js +108 -0
- package/lib/components/fields/UnitShorthandField.d.ts +32 -0
- package/lib/components/fields/UnitShorthandField.js +220 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +85 -0
- package/lib/components/templates/ArrayFieldTemplate.js +416 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +11 -0
- package/lib/components/templates/BaseInputTemplate.js +80 -0
- package/lib/components/templates/DescriptionField.d.ts +1 -0
- package/lib/components/templates/DescriptionField.js +37 -0
- package/lib/components/templates/ErrorListTemplate.d.ts +9 -0
- package/lib/components/templates/ErrorListTemplate.js +95 -0
- package/lib/components/templates/FieldTemplate.d.ts +6 -0
- package/lib/components/templates/FieldTemplate.js +112 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ObjectFieldTemplate.js +66 -0
- package/lib/components/templates/TitleField.d.ts +9 -0
- package/lib/components/templates/TitleField.js +51 -0
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +20 -0
- package/lib/components/widgets/AnyToBooleanWidget.js +49 -0
- package/lib/components/widgets/AutosuggestWidget.d.ts +66 -0
- package/lib/components/widgets/AutosuggestWidget.js +1127 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +37 -0
- package/lib/components/widgets/CheckboxWidget.js +139 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +62 -0
- package/lib/components/widgets/DateTimeWidget.js +251 -0
- package/lib/components/widgets/DateWidget.d.ts +23 -0
- package/lib/components/widgets/DateWidget.js +41 -0
- package/lib/components/widgets/HiddenWidget.d.ts +15 -0
- package/lib/components/widgets/HiddenWidget.js +19 -0
- package/lib/components/widgets/ImageSelectWidget.d.ts +14 -0
- package/lib/components/widgets/ImageSelectWidget.js +57 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +43 -0
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +237 -0
- package/lib/components/widgets/InputGroupWidget.d.ts +21 -0
- package/lib/components/widgets/InputGroupWidget.js +36 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +21 -0
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +47 -0
- package/lib/components/widgets/NumberWidget.d.ts +13 -0
- package/lib/components/widgets/NumberWidget.js +21 -0
- package/lib/components/widgets/PlainTextWidget.d.ts +12 -0
- package/lib/components/widgets/PlainTextWidget.js +24 -0
- package/lib/components/widgets/SelectWidget.d.ts +52 -0
- package/lib/components/widgets/SelectWidget.js +158 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +19 -0
- package/lib/components/widgets/SeparatedDateTimeWidget.js +59 -0
- package/lib/components/widgets/TaxonImageWidget.d.ts +13 -0
- package/lib/components/widgets/TaxonImageWidget.js +30 -0
- package/lib/components/widgets/TextSelectWidget.d.ts +25 -0
- package/lib/components/widgets/TextSelectWidget.js +94 -0
- package/lib/components/widgets/TextareaWidget.d.ts +32 -0
- package/lib/components/widgets/TextareaWidget.js +87 -0
- package/lib/components/widgets/TimeWidget.d.ts +11 -0
- package/lib/components/widgets/TimeWidget.js +19 -0
- package/lib/components/widgets/URLWidget.d.ts +14 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/UpperCaseWidget.d.ts +13 -0
- package/lib/components/widgets/UpperCaseWidget.js +21 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +50 -0
- package/lib/services/blocker-service.d.ts +11 -0
- package/lib/services/blocker-service.js +55 -0
- package/lib/services/custom-event-service.d.ts +17 -0
- package/lib/services/custom-event-service.js +35 -0
- package/lib/services/dom-id-service.d.ts +8 -0
- package/lib/services/dom-id-service.js +30 -0
- package/lib/services/focus-service.d.ts +13 -0
- package/lib/services/focus-service.js +60 -0
- package/lib/services/id-service.d.ts +22 -0
- package/lib/services/id-service.js +130 -0
- package/lib/services/key-handler-service.d.ts +56 -0
- package/lib/services/key-handler-service.js +184 -0
- package/lib/services/root-instance-service.d.ts +25 -0
- package/lib/services/root-instance-service.js +49 -0
- package/lib/services/settings-service.d.ts +34 -0
- package/lib/services/settings-service.js +154 -0
- package/lib/services/singleton-map-service.d.ts +23 -0
- package/lib/services/singleton-map-service.js +44 -0
- package/lib/services/submit-hook-service.d.ts +24 -0
- package/lib/services/submit-hook-service.js +73 -0
- package/lib/styles.d.ts +1 -0
- package/lib/styles.js +4 -0
- package/lib/themes/bs3.d.ts +3 -0
- package/lib/themes/bs3.js +133 -0
- package/lib/themes/bs5.d.ts +3 -0
- package/lib/themes/bs5.js +111 -0
- package/lib/themes/glyphicon-fa-mapping.d.ts +3 -0
- package/lib/themes/glyphicon-fa-mapping.js +271 -0
- package/lib/themes/stub.d.ts +3 -0
- package/lib/themes/stub.js +82 -0
- package/lib/themes/theme.d.ts +233 -0
- package/lib/themes/theme.js +2 -0
- package/lib/translations.json +847 -0
- package/lib/utils.d.ts +167 -0
- package/lib/utils.js +1185 -0
- package/lib/validation.d.ts +7 -0
- package/lib/validation.js +141 -0
- package/package.json +2 -2
- package/test-export/test-utils.d.ts +3 -2
- package/test-export/test-utils.js +14 -13
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default class CheckboxWidget extends React.Component<any, any, any> {
|
|
2
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
3
|
+
static propTypes: {
|
|
4
|
+
uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
5
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
allowUndefined: PropTypes.Requireable<boolean>;
|
|
7
|
+
showUndefined: PropTypes.Requireable<boolean>;
|
|
8
|
+
invert: PropTypes.Requireable<boolean>;
|
|
9
|
+
trueLabel: PropTypes.Requireable<string>;
|
|
10
|
+
falseLabel: PropTypes.Requireable<string>;
|
|
11
|
+
unknownLabel: PropTypes.Requireable<string>;
|
|
12
|
+
}>>;
|
|
13
|
+
}>>;
|
|
14
|
+
schema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
15
|
+
type: PropTypes.Requireable<string>;
|
|
16
|
+
}>>;
|
|
17
|
+
value: PropTypes.Requireable<boolean>;
|
|
18
|
+
};
|
|
19
|
+
constructor(props: any);
|
|
20
|
+
trueRef: React.RefObject<any>;
|
|
21
|
+
falseRef: React.RefObject<any>;
|
|
22
|
+
undefinedRef: React.RefObject<any>;
|
|
23
|
+
groupRef: React.RefObject<any>;
|
|
24
|
+
rmInputTabIndices: () => void;
|
|
25
|
+
onChange: (value: any) => void;
|
|
26
|
+
onButtonGroupChange: (value: any) => void;
|
|
27
|
+
getOptions: (props: any) => any;
|
|
28
|
+
getToggleMode: (props: any) => boolean;
|
|
29
|
+
onGroupKeyDown: any;
|
|
30
|
+
onTrueKeyDown: any;
|
|
31
|
+
onFalseKeyDown: any;
|
|
32
|
+
onUndefinedKeyDown: any;
|
|
33
|
+
toggle: (e: any) => void;
|
|
34
|
+
formatValue(value: any, options: any, props: any): any;
|
|
35
|
+
}
|
|
36
|
+
import * as React from "react";
|
|
37
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const react_dom_1 = require("react-dom");
|
|
5
|
+
const PropTypes = require("prop-types");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
8
|
+
class CheckboxWidget extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.rmInputTabIndices = () => {
|
|
12
|
+
[this.trueRef, this.falseRef, this.undefinedRef].forEach(node => {
|
|
13
|
+
const domNode = react_dom_1.findDOMNode(node.current);
|
|
14
|
+
if (!domNode) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const input = domNode.getElementsByTagName("input")[0];
|
|
18
|
+
if (!input) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
input.setAttribute("tabindex", -1);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
this.onChange = (value) => {
|
|
25
|
+
if (value !== undefined && this.getOptions(this.props).invert) {
|
|
26
|
+
value = !value;
|
|
27
|
+
}
|
|
28
|
+
this.props.onChange(value);
|
|
29
|
+
};
|
|
30
|
+
this.onButtonGroupChange = (value) => {
|
|
31
|
+
if (value === "undefined") {
|
|
32
|
+
value = undefined;
|
|
33
|
+
}
|
|
34
|
+
this.onChange(value);
|
|
35
|
+
};
|
|
36
|
+
this.getOptions = (props) => {
|
|
37
|
+
const { Yes, No, Unknown } = props.registry.formContext.translations;
|
|
38
|
+
return Object.assign({ allowUndefined: true, showUndefined: true, invert: false, trueLabel: Yes, falseLabel: No, unknownLabel: Unknown, required: this.props.required }, utils_1.getUiOptions(props));
|
|
39
|
+
};
|
|
40
|
+
this.getToggleMode = (props) => {
|
|
41
|
+
const { allowUndefined, showUndefined, falseLabel, trueLabel } = this.getOptions(props);
|
|
42
|
+
const displayUndefined = (allowUndefined && showUndefined);
|
|
43
|
+
const { Yes, No } = props.registry.formContext.translations;
|
|
44
|
+
return !displayUndefined && (trueLabel === Yes && falseLabel === No);
|
|
45
|
+
};
|
|
46
|
+
this.onGroupKeyDown = this.props.formContext.utils.keyboardClick((e) => {
|
|
47
|
+
this.getToggleMode(this.props) && this.toggle(e);
|
|
48
|
+
});
|
|
49
|
+
this.onTrueKeyDown = this.props.formContext.utils.keyboardClick(() => {
|
|
50
|
+
if (this.props.disabled || this.props.readonly) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.onChange(true);
|
|
54
|
+
});
|
|
55
|
+
this.onFalseKeyDown = this.props.formContext.utils.keyboardClick(() => {
|
|
56
|
+
if (this.props.disabled || this.props.readonly) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.onChange(false);
|
|
60
|
+
});
|
|
61
|
+
this.onUndefinedKeyDown = this.props.formContext.utils.keyboardClick(() => {
|
|
62
|
+
this.onChange(undefined);
|
|
63
|
+
});
|
|
64
|
+
this.toggle = (e) => {
|
|
65
|
+
if (this.props.disabled || this.props.readonly) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const nodes = [this.trueRef, this.falseRef, this.groupRef].map(r => react_dom_1.findDOMNode(r.current));
|
|
69
|
+
if (!nodes.includes(e.target)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
this.props.onChange(!this.props.value);
|
|
74
|
+
};
|
|
75
|
+
this.trueRef = React.createRef();
|
|
76
|
+
this.falseRef = React.createRef();
|
|
77
|
+
this.undefinedRef = React.createRef();
|
|
78
|
+
this.groupRef = React.createRef();
|
|
79
|
+
}
|
|
80
|
+
componentDidMount() {
|
|
81
|
+
this.rmInputTabIndices();
|
|
82
|
+
}
|
|
83
|
+
componentDidUpdate() {
|
|
84
|
+
this.rmInputTabIndices();
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const { value, disabled, readonly, label, id } = this.props;
|
|
88
|
+
const options = this.getOptions(this.props);
|
|
89
|
+
const { allowUndefined, showUndefined, invert, trueLabel, falseLabel, unknownLabel, required, label: uiOptionsLabel } = options;
|
|
90
|
+
const hasLabel = !utils_1.isEmptyString(label) && uiOptionsLabel !== false;
|
|
91
|
+
// "undefined" for silencing ToggleButton warning.
|
|
92
|
+
const _value = value === undefined
|
|
93
|
+
? "undefined"
|
|
94
|
+
: invert
|
|
95
|
+
? !value
|
|
96
|
+
: value;
|
|
97
|
+
const { ButtonToolbar, ToggleButton, ToggleButtonGroup } = this.context.theme;
|
|
98
|
+
const displayUndefined = (allowUndefined && showUndefined);
|
|
99
|
+
const toggleMode = this.getToggleMode(this.props);
|
|
100
|
+
const _disabled = disabled || readonly;
|
|
101
|
+
const commonProps = {
|
|
102
|
+
disabled: _disabled,
|
|
103
|
+
tabIndex: (toggleMode || _disabled) ? undefined : 0
|
|
104
|
+
};
|
|
105
|
+
const tabTargetClass = "laji-form-checkbox-widget-tab-target";
|
|
106
|
+
const checkbox = (React.createElement(ButtonToolbar, { className: utils_1.classNames(toggleMode && "desktop-layout") },
|
|
107
|
+
React.createElement(ToggleButtonGroup, Object.assign({ ref: this.groupRef, type: "radio", value: [_value], name: this.props.id, onChange: this.onButtonGroupChange, onKeyDown: this.onGroupKeyDown, className: utils_1.classNames(toggleMode && tabTargetClass) }, commonProps, { tabIndex: (toggleMode && !_disabled) ? 0 : undefined }),
|
|
108
|
+
React.createElement(ToggleButton, Object.assign({ id: `${id}-true`, ref: this.trueRef, value: true, onClick: toggleMode ? this.toggle : undefined, className: utils_1.classNames(toggleMode && _value === false && "laji-form-hide-btn-label", !toggleMode && tabTargetClass), onKeyDown: this.onTrueKeyDown }, commonProps), trueLabel),
|
|
109
|
+
React.createElement(ToggleButton, Object.assign({ id: `${id}-false`, ref: this.falseRef, value: false, onClick: toggleMode ? this.toggle : undefined, className: utils_1.classNames(toggleMode && _value === true && "laji-form-hide-btn-label"), onKeyDown: this.onFalseKeyDown }, commonProps), falseLabel),
|
|
110
|
+
(displayUndefined ? React.createElement(ToggleButton, Object.assign({ id: `${id}-undefined`, ref: this.undefinedRef, value: "undefined" }, commonProps, { onKeyDown: this.onUndefinedKeyDown }), unknownLabel) : null))));
|
|
111
|
+
const { Label } = this.props.formContext;
|
|
112
|
+
return !hasLabel ? checkbox : (React.createElement(Label, { label: label, required: required, uiSchema: options, contextId: this.props.formContext.contextId }, checkbox));
|
|
113
|
+
}
|
|
114
|
+
formatValue(value, options, props) {
|
|
115
|
+
return value === undefined
|
|
116
|
+
? ""
|
|
117
|
+
: value === true
|
|
118
|
+
? props.formContext.translations.Yes
|
|
119
|
+
: props.formContext.translations.No;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = CheckboxWidget;
|
|
123
|
+
CheckboxWidget.contextType = ReactContext_1.default;
|
|
124
|
+
CheckboxWidget.propTypes = {
|
|
125
|
+
uiSchema: PropTypes.shape({
|
|
126
|
+
"ui:options": PropTypes.shape({
|
|
127
|
+
allowUndefined: PropTypes.bool,
|
|
128
|
+
showUndefined: PropTypes.bool,
|
|
129
|
+
invert: PropTypes.bool,
|
|
130
|
+
trueLabel: PropTypes.string,
|
|
131
|
+
falseLabel: PropTypes.string,
|
|
132
|
+
unknownLabel: PropTypes.string
|
|
133
|
+
})
|
|
134
|
+
}),
|
|
135
|
+
schema: PropTypes.shape({
|
|
136
|
+
type: PropTypes.oneOf(["boolean"])
|
|
137
|
+
}),
|
|
138
|
+
value: PropTypes.bool
|
|
139
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const YEAR_MATCH: RegExp;
|
|
2
|
+
export default class DateTimeWidget extends React.Component<any, any, any> {
|
|
3
|
+
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
4
|
+
static propTypes: {
|
|
5
|
+
uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
7
|
+
showButtons: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
8
|
+
today: PropTypes.Requireable<boolean>;
|
|
9
|
+
yesterday: PropTypes.Requireable<boolean>;
|
|
10
|
+
same: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
11
|
+
path: PropTypes.Requireable<string>;
|
|
12
|
+
}>>;
|
|
13
|
+
}>>;
|
|
14
|
+
showTimeList: PropTypes.Requireable<boolean>;
|
|
15
|
+
allowOnlyYear: PropTypes.Requireable<boolean>;
|
|
16
|
+
dateFormat: PropTypes.Requireable<string>;
|
|
17
|
+
}>>;
|
|
18
|
+
}>>;
|
|
19
|
+
schema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
20
|
+
type: PropTypes.Requireable<string>;
|
|
21
|
+
}>>;
|
|
22
|
+
value: PropTypes.Requireable<string>;
|
|
23
|
+
};
|
|
24
|
+
static defaultProps: {
|
|
25
|
+
type: string;
|
|
26
|
+
readonly: boolean;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
required: boolean;
|
|
29
|
+
calendar: boolean;
|
|
30
|
+
time: boolean;
|
|
31
|
+
};
|
|
32
|
+
constructor(props: any);
|
|
33
|
+
focus: () => void;
|
|
34
|
+
getStateFromProps(props: any): {
|
|
35
|
+
dateFormat: any;
|
|
36
|
+
timeFormat: string;
|
|
37
|
+
format: string;
|
|
38
|
+
inputFormat: any;
|
|
39
|
+
placeholder: string;
|
|
40
|
+
};
|
|
41
|
+
parse: (value: any) => any;
|
|
42
|
+
timeWritten: any;
|
|
43
|
+
onlyYearWritten: any;
|
|
44
|
+
onChange: (value: any) => void;
|
|
45
|
+
onToggle: (p: any) => void;
|
|
46
|
+
toggle: any;
|
|
47
|
+
setRef: (elem: any) => void;
|
|
48
|
+
dateTimePickerRef: any;
|
|
49
|
+
setContainerRef: (elem: any) => void;
|
|
50
|
+
containerRef: any;
|
|
51
|
+
onTextWidgetFocus: () => void;
|
|
52
|
+
onBlur: () => void;
|
|
53
|
+
onDateTimePickerChange: (value: any) => void;
|
|
54
|
+
renderButtons(showButtons: any): JSX.Element[];
|
|
55
|
+
getDateWithCurrentTime: (date: any) => any;
|
|
56
|
+
setToday: () => void;
|
|
57
|
+
setYesterday: () => void;
|
|
58
|
+
setSameAsToday: () => void;
|
|
59
|
+
formatValue(value: any, options: any, props: any): any;
|
|
60
|
+
}
|
|
61
|
+
import * as React from "react";
|
|
62
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var DateTimeWidget_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.YEAR_MATCH = void 0;
|
|
11
|
+
const React = require("react");
|
|
12
|
+
const react_dom_1 = require("react-dom");
|
|
13
|
+
const PropTypes = require("prop-types");
|
|
14
|
+
const DateTimePicker = require("react-widgets/lib/DateTimePicker");
|
|
15
|
+
const moment = require("moment");
|
|
16
|
+
const momentLocalizer = require("react-widgets-moment");
|
|
17
|
+
const localizers_1 = require("react-widgets/lib/util/localizers");
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
19
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
20
|
+
const ReactContext_1 = require("../../ReactContext");
|
|
21
|
+
const DATE_TIME_SEPARATOR = ", ";
|
|
22
|
+
exports.YEAR_MATCH = /^\d{4}$/;
|
|
23
|
+
let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Component {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
26
|
+
this.focus = () => {
|
|
27
|
+
this.dateTimePickerRef.focus();
|
|
28
|
+
};
|
|
29
|
+
this.parse = (value) => {
|
|
30
|
+
if (!value)
|
|
31
|
+
value = "";
|
|
32
|
+
const { allowOnlyYear } = utils_1.getUiOptions(this.props);
|
|
33
|
+
const hasTime = value.includes(DATE_TIME_SEPARATOR) || this.state.time && !this.state.calendar;
|
|
34
|
+
const onlyYear = allowOnlyYear && this.state.calendar && value.match(exports.YEAR_MATCH);
|
|
35
|
+
let momentValue = moment(value, onlyYear ? "YYYY" : this.state.format);
|
|
36
|
+
if (!momentValue.isValid()) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const isoValue = onlyYear
|
|
40
|
+
? value
|
|
41
|
+
: hasTime
|
|
42
|
+
? momentValue.toISOString()
|
|
43
|
+
: momentValue.format("YYYY-MM-DD");
|
|
44
|
+
this.timeWritten = hasTime;
|
|
45
|
+
this.onlyYearWritten = onlyYear;
|
|
46
|
+
return onlyYear ? isoValue : moment(isoValue).toDate();
|
|
47
|
+
};
|
|
48
|
+
this.onChange = (value) => {
|
|
49
|
+
this.props.onChange(value, !!"force");
|
|
50
|
+
};
|
|
51
|
+
this.onToggle = p => {
|
|
52
|
+
if (p !== false)
|
|
53
|
+
this.toggle = p; //"time" or "date"
|
|
54
|
+
};
|
|
55
|
+
this.setRef = (elem) => {
|
|
56
|
+
this.dateTimePickerRef = elem;
|
|
57
|
+
};
|
|
58
|
+
this.setContainerRef = (elem) => {
|
|
59
|
+
this.containerRef = elem;
|
|
60
|
+
};
|
|
61
|
+
this.onTextWidgetFocus = () => {
|
|
62
|
+
this.setState({ textInputFocused: true }, this.focus);
|
|
63
|
+
};
|
|
64
|
+
this.onBlur = () => {
|
|
65
|
+
!utils_1.isDescendant(react_dom_1.findDOMNode(this.containerRef), document.activeElement) && this.setState({ textInputFocused: false });
|
|
66
|
+
};
|
|
67
|
+
this.onDateTimePickerChange = (value) => {
|
|
68
|
+
const momentValue = moment(value);
|
|
69
|
+
let formattedValue = momentValue.format("YYYY-MM-DDTHH:mm");
|
|
70
|
+
if (this.onlyYearWritten) {
|
|
71
|
+
formattedValue = value;
|
|
72
|
+
}
|
|
73
|
+
else if (value !== null && !momentValue.isValid()) {
|
|
74
|
+
formattedValue = this.props.value;
|
|
75
|
+
}
|
|
76
|
+
else if ((!this.toggle && !this.timeWritten) ||
|
|
77
|
+
(this.toggle === "date" && (!this.props.value || !this.props.value.includes("T")))) {
|
|
78
|
+
formattedValue = momentValue.format("YYYY-MM-DD");
|
|
79
|
+
}
|
|
80
|
+
this.onChange(!value ? undefined : formattedValue);
|
|
81
|
+
this.toggle = undefined;
|
|
82
|
+
this.timeWritten = false;
|
|
83
|
+
this.onlyYearWritten = false;
|
|
84
|
+
};
|
|
85
|
+
this.getDateWithCurrentTime = (date) => {
|
|
86
|
+
const { value } = this.props;
|
|
87
|
+
const time = value !== undefined && value !== null ? value.split("T")[1] : false;
|
|
88
|
+
return time ? `${date}T${time}` : date;
|
|
89
|
+
};
|
|
90
|
+
this.setToday = () => {
|
|
91
|
+
this.onChange(this.getDateWithCurrentTime(moment().format("YYYY-MM-DD")));
|
|
92
|
+
};
|
|
93
|
+
this.setYesterday = () => {
|
|
94
|
+
this.onChange(this.getDateWithCurrentTime(moment().subtract(1, "d").format("YYYY-MM-DD")));
|
|
95
|
+
};
|
|
96
|
+
this.setSameAsToday = () => {
|
|
97
|
+
const formData = this.props.formContext.services.rootInstance.getFormData();
|
|
98
|
+
const sameOptions = utils_1.getUiOptions(this.props).showButtons.same || {};
|
|
99
|
+
const { path = "/gatheringEvent/dateBegin" } = sameOptions;
|
|
100
|
+
const today = utils_1.parseJSONPointer(formData, path, !!"safely");
|
|
101
|
+
if (today) {
|
|
102
|
+
this.onChange(today);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
momentLocalizer(moment);
|
|
106
|
+
}
|
|
107
|
+
componentDidMount() {
|
|
108
|
+
this.props.formContext.services.focus.addFocusHandler(this.props.id, this.focus);
|
|
109
|
+
}
|
|
110
|
+
componentWillUnmount() {
|
|
111
|
+
this.props.formContext.services.focus.removeFocusHandler(this.props.id, this.focus);
|
|
112
|
+
}
|
|
113
|
+
getStateFromProps(props) {
|
|
114
|
+
const { lang, translations } = props.formContext;
|
|
115
|
+
const formatLang = lang === "sv" ? "fi" : lang === "en" ? "en-gb" : lang;
|
|
116
|
+
let localeFormats = moment().locale(formatLang)._locale._longDateFormat;
|
|
117
|
+
let { allowOnlyYear, dateFormat = "" } = utils_1.getUiOptions(props);
|
|
118
|
+
let timeFormat = "";
|
|
119
|
+
let placeholder = "";
|
|
120
|
+
if (props.calendar) {
|
|
121
|
+
if (!dateFormat)
|
|
122
|
+
dateFormat = localeFormats.L;
|
|
123
|
+
placeholder += translations[dateFormat.toLowerCase()] || dateFormat;
|
|
124
|
+
}
|
|
125
|
+
if (props.time) {
|
|
126
|
+
timeFormat = localeFormats.LT;
|
|
127
|
+
if (placeholder)
|
|
128
|
+
placeholder += DATE_TIME_SEPARATOR;
|
|
129
|
+
placeholder += translations[timeFormat.toLowerCase()] || timeFormat;
|
|
130
|
+
}
|
|
131
|
+
const format = `${dateFormat}${dateFormat ? DATE_TIME_SEPARATOR : ""}${timeFormat}`;
|
|
132
|
+
const splitted = props.value && props.value.split("T");
|
|
133
|
+
const hasTime = props.value && splitted.length > 1 && splitted[1] !== "";
|
|
134
|
+
let inputFormat = allowOnlyYear && props.value && props.value.match(exports.YEAR_MATCH)
|
|
135
|
+
? "YYYY"
|
|
136
|
+
: hasTime
|
|
137
|
+
? format
|
|
138
|
+
: dateFormat;
|
|
139
|
+
const state = {
|
|
140
|
+
dateFormat,
|
|
141
|
+
timeFormat,
|
|
142
|
+
format,
|
|
143
|
+
inputFormat,
|
|
144
|
+
placeholder
|
|
145
|
+
};
|
|
146
|
+
["value", "disabled", "time", "calendar"].forEach(prop => {
|
|
147
|
+
if (prop in props) {
|
|
148
|
+
state[prop] = props[prop];
|
|
149
|
+
if (prop === "calendar") {
|
|
150
|
+
state["date"] = props[prop];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return state;
|
|
155
|
+
}
|
|
156
|
+
render() {
|
|
157
|
+
const { value, readonly, disabled } = this.props;
|
|
158
|
+
const { translations, lang } = this.props.formContext;
|
|
159
|
+
const momentValue = moment(value);
|
|
160
|
+
if (!this.state.textInputFocused && value !== null && !momentValue.isValid()) {
|
|
161
|
+
const { TextWidget } = this.props.registry.widgets;
|
|
162
|
+
return React.createElement(TextWidget, Object.assign({}, this.props, { onFocus: this.onTextWidgetFocus }));
|
|
163
|
+
}
|
|
164
|
+
const options = utils_1.getUiOptions(this.props);
|
|
165
|
+
const showTimeList = options.showTimeList !== undefined ? options.showTimeList : true;
|
|
166
|
+
const culture = lang === "en" ? "en-gb" : lang;
|
|
167
|
+
const datePicker = (React.createElement(DateTimePicker, { ref: this.setRef, date: this.state.calendar, time: this.state.time && showTimeList, format: this.state.inputFormat, timeFormat: this.state.timeFormat, placeholder: this.state.placeholder, onToggle: this.onToggle, onChange: this.onDateTimePickerChange, value: value && momentValue.isValid() ? momentValue.toDate() : null, parse: this.parse, disabled: readonly || disabled, culture: culture, messages: {
|
|
168
|
+
calendarButton: translations.ChooseDate,
|
|
169
|
+
timeButton: translations.ChooseTime
|
|
170
|
+
}, onBlur: this.onBlur }));
|
|
171
|
+
const { showButtons } = options;
|
|
172
|
+
const { ButtonGroup } = this.context.theme;
|
|
173
|
+
return showButtons ? (React.createElement("div", { className: "date-widget", ref: this.setContainerRef },
|
|
174
|
+
React.createElement("div", { className: "date-picker" }, datePicker),
|
|
175
|
+
React.createElement(ButtonGroup, null, this.renderButtons(showButtons)))) : React.createElement("div", { className: "date-widget" }, datePicker);
|
|
176
|
+
}
|
|
177
|
+
renderButtons(showButtons) {
|
|
178
|
+
const { readonly, disabled } = this.props;
|
|
179
|
+
const { translations } = this.props.formContext;
|
|
180
|
+
const buttonDefinitions = {
|
|
181
|
+
today: {
|
|
182
|
+
className: "today",
|
|
183
|
+
label: translations.Today,
|
|
184
|
+
onClick: this.setToday
|
|
185
|
+
},
|
|
186
|
+
yesterday: {
|
|
187
|
+
className: "yesterday",
|
|
188
|
+
label: translations.Yesterday,
|
|
189
|
+
onClick: this.setYesterday
|
|
190
|
+
},
|
|
191
|
+
same: {
|
|
192
|
+
className: "same",
|
|
193
|
+
label: translations.Same,
|
|
194
|
+
onClick: this.setSameAsToday
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const options = showButtons === true
|
|
198
|
+
? { today: true, yesterday: true }
|
|
199
|
+
: showButtons;
|
|
200
|
+
const { Button } = this.context.theme;
|
|
201
|
+
return Object.keys(options)
|
|
202
|
+
.filter(name => options[name])
|
|
203
|
+
.map(name => buttonDefinitions[name])
|
|
204
|
+
.map(({ className, onClick, label }) => (React.createElement(Button, { key: className, className: className, onClick: onClick, disabled: readonly || disabled }, label)));
|
|
205
|
+
}
|
|
206
|
+
formatValue(value, options, props) {
|
|
207
|
+
if (!value)
|
|
208
|
+
return value;
|
|
209
|
+
const { inputFormat: format } = DateTimeWidget_1.prototype.getStateFromProps(Object.assign(Object.assign({}, props), { date: true, time: true, value }));
|
|
210
|
+
return localizers_1.date.format(value, format, props.formContext.lang);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
DateTimeWidget.contextType = ReactContext_1.default;
|
|
214
|
+
DateTimeWidget.propTypes = {
|
|
215
|
+
uiSchema: PropTypes.shape({
|
|
216
|
+
"ui:options": PropTypes.shape({
|
|
217
|
+
showButtons: PropTypes.oneOfType([
|
|
218
|
+
PropTypes.bool,
|
|
219
|
+
PropTypes.shape({
|
|
220
|
+
today: PropTypes.bool,
|
|
221
|
+
yesterday: PropTypes.bool,
|
|
222
|
+
same: PropTypes.oneOfType([
|
|
223
|
+
PropTypes.bool,
|
|
224
|
+
PropTypes.shape({
|
|
225
|
+
path: PropTypes.string
|
|
226
|
+
})
|
|
227
|
+
])
|
|
228
|
+
})
|
|
229
|
+
]),
|
|
230
|
+
showTimeList: PropTypes.bool,
|
|
231
|
+
allowOnlyYear: PropTypes.bool,
|
|
232
|
+
dateFormat: PropTypes.string
|
|
233
|
+
})
|
|
234
|
+
}),
|
|
235
|
+
schema: PropTypes.shape({
|
|
236
|
+
type: PropTypes.oneOf(["string"])
|
|
237
|
+
}),
|
|
238
|
+
value: PropTypes.string
|
|
239
|
+
};
|
|
240
|
+
DateTimeWidget.defaultProps = {
|
|
241
|
+
type: "text",
|
|
242
|
+
readonly: false,
|
|
243
|
+
disabled: false,
|
|
244
|
+
required: false,
|
|
245
|
+
calendar: true,
|
|
246
|
+
time: true
|
|
247
|
+
};
|
|
248
|
+
DateTimeWidget = DateTimeWidget_1 = __decorate([
|
|
249
|
+
BaseComponent_1.default
|
|
250
|
+
], DateTimeWidget);
|
|
251
|
+
exports.default = DateTimeWidget;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default DateWidget;
|
|
2
|
+
declare function DateWidget(props: any): JSX.Element;
|
|
3
|
+
declare namespace DateWidget {
|
|
4
|
+
namespace propTypes {
|
|
5
|
+
const uiSchema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
"ui:options": PropTypes.Requireable<PropTypes.InferProps<{
|
|
7
|
+
showButtons: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
8
|
+
today: PropTypes.Requireable<boolean>;
|
|
9
|
+
yesterday: PropTypes.Requireable<boolean>;
|
|
10
|
+
same: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
11
|
+
path: PropTypes.Requireable<string>;
|
|
12
|
+
}>>;
|
|
13
|
+
}>>;
|
|
14
|
+
allowOnlyYear: PropTypes.Requireable<boolean>;
|
|
15
|
+
}>>;
|
|
16
|
+
}>>;
|
|
17
|
+
const schema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
18
|
+
type: PropTypes.Requireable<string>;
|
|
19
|
+
}>>;
|
|
20
|
+
const value: PropTypes.Requireable<string>;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const PropTypes = require("prop-types");
|
|
5
|
+
const moment = require("moment");
|
|
6
|
+
const DateTimeWidget_1 = require("./DateTimeWidget");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const format = (allowOnlyYear, value) => moment(value).format(allowOnlyYear && value.match(DateTimeWidget_1.YEAR_MATCH)
|
|
9
|
+
? "YYYY"
|
|
10
|
+
: "YYYY-MM-DD");
|
|
11
|
+
const DateWidget = (props) => {
|
|
12
|
+
const { onChange } = props;
|
|
13
|
+
const { allowOnlyYear } = utils_1.getUiOptions(props);
|
|
14
|
+
const _onChange = React.useCallback((value) => onChange(utils_1.isEmptyString(value) ? undefined : format(allowOnlyYear, value)), [allowOnlyYear, onChange]);
|
|
15
|
+
return (React.createElement(DateTimeWidget_1.default, Object.assign({}, props, { onChange: _onChange, time: false, value: props.value ? format(allowOnlyYear, props.value) : null })));
|
|
16
|
+
};
|
|
17
|
+
DateWidget.propTypes = {
|
|
18
|
+
uiSchema: PropTypes.shape({
|
|
19
|
+
"ui:options": PropTypes.shape({
|
|
20
|
+
showButtons: PropTypes.oneOfType([
|
|
21
|
+
PropTypes.bool,
|
|
22
|
+
PropTypes.shape({
|
|
23
|
+
today: PropTypes.bool,
|
|
24
|
+
yesterday: PropTypes.bool,
|
|
25
|
+
same: PropTypes.oneOfType([
|
|
26
|
+
PropTypes.bool,
|
|
27
|
+
PropTypes.shape({
|
|
28
|
+
path: PropTypes.string
|
|
29
|
+
})
|
|
30
|
+
])
|
|
31
|
+
})
|
|
32
|
+
]),
|
|
33
|
+
allowOnlyYear: PropTypes.bool
|
|
34
|
+
})
|
|
35
|
+
}),
|
|
36
|
+
schema: PropTypes.shape({
|
|
37
|
+
type: PropTypes.oneOf(["string"])
|
|
38
|
+
}),
|
|
39
|
+
value: PropTypes.string
|
|
40
|
+
};
|
|
41
|
+
exports.default = DateWidget;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default HiddenWidget;
|
|
2
|
+
declare function HiddenWidget({ id, value }: {
|
|
3
|
+
id: any;
|
|
4
|
+
value: any;
|
|
5
|
+
}): JSX.Element;
|
|
6
|
+
declare namespace HiddenWidget {
|
|
7
|
+
namespace propTypes {
|
|
8
|
+
const id: PropTypes.Validator<string>;
|
|
9
|
+
const value: PropTypes.Requireable<string | number | boolean>;
|
|
10
|
+
const schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
11
|
+
type: PropTypes.Requireable<string>;
|
|
12
|
+
}>>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const PropTypes = require("prop-types");
|
|
5
|
+
function HiddenWidget({ id, value }) {
|
|
6
|
+
return (React.createElement("input", { type: "hidden", id: id, value: typeof value === "undefined" ? "" : value }));
|
|
7
|
+
}
|
|
8
|
+
HiddenWidget.propTypes = {
|
|
9
|
+
id: PropTypes.string.isRequired,
|
|
10
|
+
value: PropTypes.oneOfType([
|
|
11
|
+
PropTypes.string,
|
|
12
|
+
PropTypes.number,
|
|
13
|
+
PropTypes.bool,
|
|
14
|
+
]),
|
|
15
|
+
schema: PropTypes.shape({
|
|
16
|
+
type: PropTypes.oneOf(["string", "number", "boolean", "integer"])
|
|
17
|
+
}).isRequired
|
|
18
|
+
};
|
|
19
|
+
exports.default = HiddenWidget;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class ImageSelectWidget extends React.Component<any, any, any> {
|
|
2
|
+
static propTypes: {
|
|
3
|
+
options: PropTypes.Validator<object>;
|
|
4
|
+
schema: PropTypes.Requireable<PropTypes.InferProps<{
|
|
5
|
+
type: PropTypes.Requireable<string>;
|
|
6
|
+
}>>;
|
|
7
|
+
value: PropTypes.Requireable<string>;
|
|
8
|
+
};
|
|
9
|
+
constructor(props: any);
|
|
10
|
+
_context: Record<string, unknown>;
|
|
11
|
+
renderImg: (enumName: any, fallback: any) => any;
|
|
12
|
+
}
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import * as PropTypes from "prop-types";
|
|
@@ -0,0 +1,57 @@
|
|
|
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 Context_1 = require("../../Context");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const react_inlinesvg_1 = require("react-inlinesvg");
|
|
14
|
+
const SelectWidget_1 = require("./SelectWidget");
|
|
15
|
+
const BaseComponent_1 = require("../BaseComponent");
|
|
16
|
+
let ImageSelectWidget = class ImageSelectWidget extends React.Component {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
this.renderImg = (enumName, fallback) => {
|
|
20
|
+
const imgName = utils_1.getUiOptions(this.props).images[enumName];
|
|
21
|
+
if (imgName === undefined)
|
|
22
|
+
return fallback;
|
|
23
|
+
let path = this._context[enumName] || {};
|
|
24
|
+
try {
|
|
25
|
+
path.svg = `https://cdn.laji.fi/images/${imgName}.svg`;
|
|
26
|
+
path.png = `https://cdn.laji.fi/images/${imgName}.png`;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
this._context[enumName] = path;
|
|
30
|
+
return React.createElement("span", { className: "select-icon" },
|
|
31
|
+
React.createElement(react_inlinesvg_1.default, { key: enumName, src: path.svg, cacheGetRequests: true },
|
|
32
|
+
React.createElement("img", { src: path.png })));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this._context = Context_1.default("IMAGES");
|
|
36
|
+
}
|
|
37
|
+
render() {
|
|
38
|
+
return (React.createElement(SelectWidget_1.default, Object.assign({}, this.props, { selectProps: {
|
|
39
|
+
renderValue: item => this.renderImg(item.value, item.label),
|
|
40
|
+
renderOption: item => React.createElement("div", null,
|
|
41
|
+
this.renderImg(item.value, item.label),
|
|
42
|
+
" ",
|
|
43
|
+
React.createElement("span", null, item.label))
|
|
44
|
+
} })));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
ImageSelectWidget.propTypes = {
|
|
48
|
+
options: PropTypes.object.isRequired,
|
|
49
|
+
schema: PropTypes.shape({
|
|
50
|
+
type: PropTypes.oneOf(["string"])
|
|
51
|
+
}),
|
|
52
|
+
value: PropTypes.string
|
|
53
|
+
};
|
|
54
|
+
ImageSelectWidget = __decorate([
|
|
55
|
+
BaseComponent_1.default
|
|
56
|
+
], ImageSelectWidget);
|
|
57
|
+
exports.default = ImageSelectWidget;
|