@luomus/laji-form 15.1.11 → 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/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 {
@@ -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;
@@ -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" }, tags.map((item, idx) => React.createElement("li", { key: idx, className: "rw-multiselect-tag", onClick: this.onTagClick(idx) },
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 FriendsWrapper = React.forwardRef(({ formContext, children, id, inputValue, isSuggested }, ref) => {
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.UnknownOrganization));
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");
@@ -74,6 +74,11 @@
74
74
  "en": "Unknown organization",
75
75
  "sv": "Okänd organisation"
76
76
  },
77
+ "unknownCollection": {
78
+ "fi": "Tuntematon kokoelma",
79
+ "en": "Unknown collection",
80
+ "sv": "Okänd samling"
81
+ },
77
82
  "fix": {
78
83
  "fi": "Korjaa",
79
84
  "en": "Fix",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.11",
3
+ "version": "15.1.12",
4
4
  "description": "React module capable of building dynamic forms from Laji form json schemas",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",