@luomus/laji-form 15.1.10 → 15.1.12
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/dist/laji-form.js +1 -1
- package/dist/styles.css +1 -1
- package/lib/ApiClient.js +3 -0
- package/lib/components/fields/ImageArrayField.js +1 -1
- package/lib/components/fields/MultiTagArrayField.d.ts +1 -1
- package/lib/components/fields/MultiTagArrayField.js +2 -1
- package/lib/components/fields/PdfArrayField.d.ts +1 -1
- package/lib/components/fields/PdfArrayField.js +1 -1
- package/lib/components/fields/TagArrayField.d.ts +1 -1
- package/lib/components/fields/TagArrayField.js +10 -4
- package/lib/components/widgets/AutosuggestWidget.js +50 -10
- package/lib/components/widgets/DateTimeWidget.d.ts +4 -0
- package/lib/components/widgets/DateTimeWidget.js +23 -0
- package/lib/translations.json +15 -0
- package/package.json +1 -1
- package/test-export/test-utils.d.ts +4 -0
- package/test-export/test-utils.js +3 -1
package/dist/styles.css
CHANGED
|
@@ -3752,7 +3752,7 @@ min-height: 20px;
|
|
|
3752
3752
|
.laji-form-multi-tag-array-field-buttons .btn-group-vertical {
|
|
3753
3753
|
margin-right: 17px;
|
|
3754
3754
|
}
|
|
3755
|
-
.laji-form-multi-tag-array-field.laji-form-multi-tag-array-field-active .rw-multiselect-tag:hover {
|
|
3755
|
+
.laji-form-multi-tag-array-field.laji-form-multi-tag-array-field-active .rw-multiselect-tag:hover, .laji-form-multi-tag-array-field.laji-form-multi-tag-array-field-active .rw-multiselect-tag:hover a {
|
|
3756
3756
|
cursor: crosshair;
|
|
3757
3757
|
}
|
|
3758
3758
|
.laji-form-multi-tag-array-field-buttons .btn-group-vertical button.active::before {
|
package/lib/ApiClient.js
CHANGED
|
@@ -118,7 +118,7 @@ function MediaArrayField(ComposedComponent) {
|
|
|
118
118
|
if (!medias || !medias[item])
|
|
119
119
|
return null;
|
|
120
120
|
return (React.createElement("div", { key: i, className: "media-container" },
|
|
121
|
-
React.createElement("
|
|
121
|
+
React.createElement("div", { className: "media-container-link" }, this.renderLoadingMedia(medias[item]))));
|
|
122
122
|
});
|
|
123
123
|
};
|
|
124
124
|
this.openModalFor = (i) => () => {
|
|
@@ -31,6 +31,6 @@ export default class MultiTagArrayField extends React.Component<FieldProps, Stat
|
|
|
31
31
|
render(): JSX.Element;
|
|
32
32
|
onChange: ((key: string) => (formData: any) => void) & memoize.Memoized<(key: string) => (formData: any) => void>;
|
|
33
33
|
onButtonClick: ((idx: number) => () => void) & memoize.Memoized<(idx: number) => () => void>;
|
|
34
|
-
onTagClick: ((fromField: string) => (idx: number) => void) & memoize.Memoized<(fromField: string) => (idx: number) => void>;
|
|
34
|
+
onTagClick: ((fromField: string) => (idx: number, e: React.MouseEvent<HTMLButtonElement>) => void) & memoize.Memoized<(fromField: string) => (idx: number, e: React.MouseEvent<HTMLButtonElement>) => void>;
|
|
35
35
|
}
|
|
36
36
|
export {};
|
|
@@ -50,7 +50,8 @@ let MultiTagArrayField = class MultiTagArrayField extends React.Component {
|
|
|
50
50
|
this.setState({ activeButtonIdx: idx });
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
this.onTagClick = memoize((fromField) => (idx) => {
|
|
53
|
+
this.onTagClick = memoize((fromField) => (idx, e) => {
|
|
54
|
+
e.preventDefault();
|
|
54
55
|
const { activeButtonIdx } = this.state;
|
|
55
56
|
if (activeButtonIdx === undefined) {
|
|
56
57
|
return;
|
|
@@ -14,7 +14,7 @@ export default class PdfArrayField extends React.Component<FieldProps, MediaArra
|
|
|
14
14
|
CONTAINER_CLASS: string;
|
|
15
15
|
METADATA_FORM_ID: string;
|
|
16
16
|
renderMedia: (id: string) => JSX.Element;
|
|
17
|
-
renderLoadingMedia: (
|
|
17
|
+
renderLoadingMedia: () => JSX.Element;
|
|
18
18
|
onMediaClick: () => null;
|
|
19
19
|
formatValue(value: string[], options: any, props: FieldProps): string | null;
|
|
20
20
|
}
|
|
@@ -23,7 +23,7 @@ let PdfArrayField = class PdfArrayField extends React.Component {
|
|
|
23
23
|
this.CONTAINER_CLASS = "pdf-container";
|
|
24
24
|
this.METADATA_FORM_ID = "";
|
|
25
25
|
this.renderMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { id: id, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT, downloadLink: true });
|
|
26
|
-
this.renderLoadingMedia = (
|
|
26
|
+
this.renderLoadingMedia = () => React.createElement(ImageArrayField_1.Thumbnail, { loading: true, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT, downloadLink: true });
|
|
27
27
|
this.onMediaClick = () => null;
|
|
28
28
|
}
|
|
29
29
|
formatValue(value, options, props) {
|
|
@@ -30,7 +30,7 @@ export class TagInputComponent extends React.Component<any, any, any> {
|
|
|
30
30
|
inputRef: any;
|
|
31
31
|
onClick: () => void;
|
|
32
32
|
onInputChange: (e: any) => void;
|
|
33
|
-
onTagClick: ((idx: any) => () => void) & memoize.Memoized<(idx: any) => () => void>;
|
|
33
|
+
onTagClick: ((idx: any) => (e: any) => void) & memoize.Memoized<(idx: any) => (e: any) => void>;
|
|
34
34
|
getTrimmedValue(): any;
|
|
35
35
|
}
|
|
36
36
|
import * as React from "react";
|
|
@@ -98,9 +98,9 @@ class TagInputComponent extends React.Component {
|
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
|
-
this.onTagClick = memoize((idx) => () => {
|
|
101
|
+
this.onTagClick = memoize((idx) => (e) => {
|
|
102
102
|
const { onTagClick } = utils_1.getUiOptions(this.props.uiSchema);
|
|
103
|
-
onTagClick === null || onTagClick === void 0 ? void 0 : onTagClick(idx);
|
|
103
|
+
onTagClick === null || onTagClick === void 0 ? void 0 : onTagClick(idx, e);
|
|
104
104
|
});
|
|
105
105
|
this.state = this.getStateFromProps(props);
|
|
106
106
|
}
|
|
@@ -116,10 +116,16 @@ class TagInputComponent extends React.Component {
|
|
|
116
116
|
tags = tags.filter(s => !utils_1.isEmptyString(s));
|
|
117
117
|
const { value = "" } = this.state;
|
|
118
118
|
const inputProps = Object.assign(Object.assign({ type: "text", className: "rw-input-reset", ref: this.setInputRef, value: value, onChange: this.onInputChange, id: this.props.id }, this.props.inputProps), { onFocus: this.onFocus, onBlur: this.onBlur, onKeyDown: this.onKeyDown });
|
|
119
|
-
const { showDeleteButton = true } = utils_1.getUiOptions(uiSchema);
|
|
119
|
+
const { showDeleteButton = true, showAsLink = false, linkPrefix = "" } = utils_1.getUiOptions(uiSchema);
|
|
120
|
+
const tagElems = tags.map(item => {
|
|
121
|
+
if (showAsLink) {
|
|
122
|
+
return React.createElement("a", { href: `${linkPrefix}${item}`, target: "_blank", rel: "noopener noreferrer" }, item);
|
|
123
|
+
}
|
|
124
|
+
return item;
|
|
125
|
+
});
|
|
120
126
|
return (React.createElement("div", { className: `rw-multiselect rw-widget${this.state.focused ? " rw-state-focus" : ""}${readonly || disabled ? " rw-state-disabled" : ""}`, onClick: this.onClick },
|
|
121
127
|
React.createElement("div", { className: "rw-widget-input rw-widget-picked rw-widget-container" },
|
|
122
|
-
React.createElement("ul", { className: "rw-multiselect-taglist" },
|
|
128
|
+
React.createElement("ul", { className: "rw-multiselect-taglist" }, tagElems.map((item, idx) => React.createElement("li", { key: idx, className: "rw-multiselect-tag", onClick: this.onTagClick(idx) },
|
|
123
129
|
item,
|
|
124
130
|
showDeleteButton ? React.createElement("span", { className: "rw-tag-btn", onClick: this.onRemove(idx), tabIndex: 0, onKeyDown: this.props.formContext.utils.keyboardClick(this.onRemove(idx)) }, "\u00D7") : ""))),
|
|
125
131
|
InputComponent ? React.createElement(InputComponent, Object.assign({}, inputProps)) : React.createElement("input", Object.assign({}, inputProps, { disabled: disabled || readonly })))));
|
|
@@ -46,6 +46,8 @@ class _AutosuggestWidget extends React.Component {
|
|
|
46
46
|
return React.createElement(FriendsAutosuggestWidget, Object.assign({}, this.props));
|
|
47
47
|
case "organization":
|
|
48
48
|
return React.createElement(OrganizationAutosuggestWidget, Object.assign({}, this.props));
|
|
49
|
+
case "collection":
|
|
50
|
+
return React.createElement(CollectionAutosuggestWidget, Object.assign({}, this.props));
|
|
49
51
|
default:
|
|
50
52
|
return React.createElement(RangeAutosuggestWidget, Object.assign({}, this.props));
|
|
51
53
|
}
|
|
@@ -69,6 +71,9 @@ class _AutosuggestWidget extends React.Component {
|
|
|
69
71
|
case "organization":
|
|
70
72
|
component = OrganizationAutosuggestWidget;
|
|
71
73
|
break;
|
|
74
|
+
case "collection":
|
|
75
|
+
component = CollectionAutosuggestWidget;
|
|
76
|
+
break;
|
|
72
77
|
default:
|
|
73
78
|
component = RangeAutosuggestWidget;
|
|
74
79
|
}
|
|
@@ -348,6 +353,46 @@ class OrganizationAutosuggestWidget extends React.Component {
|
|
|
348
353
|
}
|
|
349
354
|
}
|
|
350
355
|
OrganizationAutosuggestWidget.contextType = ReactContext_1.default;
|
|
356
|
+
class CollectionAutosuggestWidget extends React.Component {
|
|
357
|
+
constructor(props) {
|
|
358
|
+
super(props);
|
|
359
|
+
this.findExactMatch = (suggestions, inputValue) => {
|
|
360
|
+
return suggestions.find(suggestion => (suggestion && suggestion.value.toLowerCase() === inputValue.trim().toLowerCase()));
|
|
361
|
+
};
|
|
362
|
+
this.getSuggestionFromValue = this.getSuggestionFromValue.bind(this);
|
|
363
|
+
this.isValueSuggested = this.isValueSuggested.bind(this);
|
|
364
|
+
}
|
|
365
|
+
getSuggestionFromValue(value) {
|
|
366
|
+
if (this.isValueSuggested(value)) {
|
|
367
|
+
return this.props.formContext.apiClient.fetchCached(`/collection/by-id/${value}`).then(({ collectionName }) => {
|
|
368
|
+
if (collectionName) {
|
|
369
|
+
return {
|
|
370
|
+
value: collectionName,
|
|
371
|
+
key: value
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
return Promise.reject();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
isValueSuggested(value) {
|
|
381
|
+
return !utils_1.isEmptyString(value) && value.match(/HR\.\d+/);
|
|
382
|
+
}
|
|
383
|
+
render() {
|
|
384
|
+
const _a = this.props, { options: propsOptions } = _a, propsWithoutOptions = __rest(_a, ["options"]);
|
|
385
|
+
const options = {
|
|
386
|
+
query: Object.assign({ includeSelf: true }, propsOptions.queryOptions),
|
|
387
|
+
getSuggestionFromValue: this.getSuggestionFromValue,
|
|
388
|
+
isValueSuggested: this.isValueSuggested,
|
|
389
|
+
Wrapper: CollectionWrapper,
|
|
390
|
+
findExactMatch: this.findExactMatch
|
|
391
|
+
};
|
|
392
|
+
return React.createElement(Autosuggest, Object.assign({}, options, propsWithoutOptions, propsOptions));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
CollectionAutosuggestWidget.contextType = ReactContext_1.default;
|
|
351
396
|
class RangeAutosuggestWidget extends React.Component {
|
|
352
397
|
render() {
|
|
353
398
|
const _a = this.props, { options: propsOptions } = _a, propsWithoutOptions = __rest(_a, ["options"]);
|
|
@@ -1109,19 +1154,14 @@ class ReactAutosuggest extends React.Component {
|
|
|
1109
1154
|
}
|
|
1110
1155
|
}
|
|
1111
1156
|
ReactAutosuggest.contextType = ReactContext_1.default;
|
|
1112
|
-
const
|
|
1113
|
-
const { Tooltip } = React.useContext(ReactContext_1.default).theme;
|
|
1114
|
-
if (!inputValue || isSuggested) {
|
|
1115
|
-
return children;
|
|
1116
|
-
}
|
|
1117
|
-
const tooltip = (React.createElement(Tooltip, { id: `${id}-tooltip` }, formContext.translations.UnknownName));
|
|
1118
|
-
return (React.createElement(components_1.OverlayTrigger, { overlay: tooltip, placement: "top", ref: ref }, children));
|
|
1119
|
-
});
|
|
1120
|
-
const OrganizationWrapper = React.forwardRef(({ formContext, children, id, inputValue, isSuggested }, ref) => {
|
|
1157
|
+
const getWrapper = (unknownValueLabel) => React.forwardRef(({ formContext, children, id, inputValue, isSuggested }, ref) => {
|
|
1121
1158
|
const { Tooltip } = React.useContext(ReactContext_1.default).theme;
|
|
1122
1159
|
if (!inputValue || isSuggested) {
|
|
1123
1160
|
return children;
|
|
1124
1161
|
}
|
|
1125
|
-
const tooltip = (React.createElement(Tooltip, { id: `${id}-tooltip` }, formContext.translations
|
|
1162
|
+
const tooltip = (React.createElement(Tooltip, { id: `${id}-tooltip` }, formContext.translations[unknownValueLabel]));
|
|
1126
1163
|
return (React.createElement(components_1.OverlayTrigger, { overlay: tooltip, placement: "top", ref: ref }, children));
|
|
1127
1164
|
});
|
|
1165
|
+
const FriendsWrapper = getWrapper("UnknownName");
|
|
1166
|
+
const OrganizationWrapper = getWrapper("UnknownOrganization");
|
|
1167
|
+
const CollectionWrapper = getWrapper("UnknownCollection");
|
|
@@ -56,7 +56,11 @@ export default class DateTimeWidget extends React.Component<any, any, any> {
|
|
|
56
56
|
setToday: () => void;
|
|
57
57
|
setYesterday: () => void;
|
|
58
58
|
setSameAsToday: () => void;
|
|
59
|
+
setPlusSixMonths: () => void;
|
|
60
|
+
setPlusYear: () => void;
|
|
59
61
|
formatValue(value: any, options: any, props: any): any;
|
|
62
|
+
getCurrentDateOrNow(): moment.Moment;
|
|
60
63
|
}
|
|
61
64
|
import * as React from "react";
|
|
65
|
+
import * as moment from "moment";
|
|
62
66
|
import * as PropTypes from "prop-types";
|
|
@@ -102,6 +102,12 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
|
|
|
102
102
|
this.onChange(today);
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
+
this.setPlusSixMonths = () => {
|
|
106
|
+
this.onChange(this.getCurrentDateOrNow().add(6, "M").format("YYYY-MM-DD"));
|
|
107
|
+
};
|
|
108
|
+
this.setPlusYear = () => {
|
|
109
|
+
this.onChange(this.getCurrentDateOrNow().add(1, "y").format("YYYY-MM-DD"));
|
|
110
|
+
};
|
|
105
111
|
momentLocalizer(moment);
|
|
106
112
|
}
|
|
107
113
|
componentDidMount() {
|
|
@@ -192,6 +198,16 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
|
|
|
192
198
|
className: "same",
|
|
193
199
|
label: translations.Same,
|
|
194
200
|
onClick: this.setSameAsToday
|
|
201
|
+
},
|
|
202
|
+
plusSixMonths: {
|
|
203
|
+
className: "plus-six-months",
|
|
204
|
+
label: translations.plusSixMonths,
|
|
205
|
+
onClick: this.setPlusSixMonths
|
|
206
|
+
},
|
|
207
|
+
plusYear: {
|
|
208
|
+
className: "plus-year",
|
|
209
|
+
label: translations.plusYear,
|
|
210
|
+
onClick: this.setPlusYear
|
|
195
211
|
}
|
|
196
212
|
};
|
|
197
213
|
const options = showButtons === true
|
|
@@ -209,6 +225,13 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
|
|
|
209
225
|
const { inputFormat: format } = DateTimeWidget_1.prototype.getStateFromProps(Object.assign(Object.assign({}, props), { date: true, time: true, value }));
|
|
210
226
|
return localizers_1.date.format(value, format, props.formContext.lang);
|
|
211
227
|
}
|
|
228
|
+
getCurrentDateOrNow() {
|
|
229
|
+
const date = moment(this.props.value);
|
|
230
|
+
if (date.isValid()) {
|
|
231
|
+
return date;
|
|
232
|
+
}
|
|
233
|
+
return moment();
|
|
234
|
+
}
|
|
212
235
|
};
|
|
213
236
|
DateTimeWidget.contextType = ReactContext_1.default;
|
|
214
237
|
DateTimeWidget.propTypes = {
|
package/lib/translations.json
CHANGED
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
"en": "Yesterday",
|
|
20
20
|
"sv": "Igår"
|
|
21
21
|
},
|
|
22
|
+
"plusSixMonths": {
|
|
23
|
+
"fi": "+6k",
|
|
24
|
+
"en": "+6m",
|
|
25
|
+
"sv": "+6m"
|
|
26
|
+
},
|
|
27
|
+
"plusYear": {
|
|
28
|
+
"fi": "+1v",
|
|
29
|
+
"en": "+1y",
|
|
30
|
+
"sv": "+1å"
|
|
31
|
+
},
|
|
22
32
|
"dd/mm/yyyy": {
|
|
23
33
|
"fi": "pp/kk/vvvv",
|
|
24
34
|
"en": "dd/mm/yyyy",
|
|
@@ -64,6 +74,11 @@
|
|
|
64
74
|
"en": "Unknown organization",
|
|
65
75
|
"sv": "Okänd organisation"
|
|
66
76
|
},
|
|
77
|
+
"unknownCollection": {
|
|
78
|
+
"fi": "Tuntematon kokoelma",
|
|
79
|
+
"en": "Unknown collection",
|
|
80
|
+
"sv": "Okänd samling"
|
|
81
|
+
},
|
|
67
82
|
"fix": {
|
|
68
83
|
"fi": "Korjaa",
|
|
69
84
|
"en": "Fix",
|
package/package.json
CHANGED
|
@@ -21,6 +21,8 @@ export interface DateWidgetPO {
|
|
|
21
21
|
$same: Locator;
|
|
22
22
|
$date: Locator;
|
|
23
23
|
$time: Locator;
|
|
24
|
+
$plusSixMonths: Locator;
|
|
25
|
+
$plusYear: Locator;
|
|
24
26
|
};
|
|
25
27
|
calendar: {
|
|
26
28
|
$today: Locator;
|
|
@@ -118,6 +120,8 @@ export declare class Form {
|
|
|
118
120
|
$same: Locator;
|
|
119
121
|
$date: Locator;
|
|
120
122
|
$time: Locator;
|
|
123
|
+
$plusSixMonths: Locator;
|
|
124
|
+
$plusYear: Locator;
|
|
121
125
|
};
|
|
122
126
|
calendar: {
|
|
123
127
|
$today: Locator;
|
|
@@ -223,7 +223,9 @@ class Form {
|
|
|
223
223
|
$yesterday: $widget.locator(".yesterday"),
|
|
224
224
|
$same: $widget.locator(".same"),
|
|
225
225
|
$date: $widget.locator(".rw-i-calendar"),
|
|
226
|
-
$time: $widget.locator(".rw-i-clock-o")
|
|
226
|
+
$time: $widget.locator(".rw-i-clock-o"),
|
|
227
|
+
$plusSixMonths: $widget.locator(".plus-six-months"),
|
|
228
|
+
$plusYear: $widget.locator(".plus-year"),
|
|
227
229
|
},
|
|
228
230
|
calendar: {
|
|
229
231
|
$today: $widget.locator(".rw-calendar-footer button"),
|