@luomus/laji-form 15.1.55 → 15.1.56

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.
Files changed (149) hide show
  1. package/dist/laji-form.js +1 -1
  2. package/dist/styles.css +6 -3
  3. package/lib/ReactContext.js +20 -1
  4. package/lib/components/LajiForm.js +47 -25
  5. package/lib/components/VirtualSchemaField.d.ts +1 -1
  6. package/lib/components/VirtualSchemaField.js +25 -3
  7. package/lib/components/components/Affix.d.ts +38 -0
  8. package/lib/components/components/Affix.js +155 -0
  9. package/lib/components/components/Button.d.ts +14 -0
  10. package/lib/components/components/Button.js +46 -0
  11. package/lib/components/components/DeleteButton.d.ts +36 -0
  12. package/lib/components/components/DeleteButton.js +132 -0
  13. package/lib/components/components/ErrorPanel.d.ts +29 -0
  14. package/lib/components/components/ErrorPanel.js +75 -0
  15. package/lib/components/components/FailedBackgroundJobsPanel.d.ts +24 -0
  16. package/lib/components/components/FailedBackgroundJobsPanel.js +97 -0
  17. package/lib/components/components/FetcherInput.d.ts +14 -0
  18. package/lib/components/components/FetcherInput.js +62 -0
  19. package/lib/components/components/Fullscreen.d.ts +14 -0
  20. package/lib/components/components/Fullscreen.js +43 -0
  21. package/lib/components/components/GlyphButton.d.ts +10 -0
  22. package/lib/components/components/GlyphButton.js +46 -0
  23. package/lib/components/components/Help.d.ts +19 -0
  24. package/lib/components/components/Help.js +54 -0
  25. package/lib/components/components/Label.d.ts +12 -0
  26. package/lib/components/components/Label.js +59 -0
  27. package/lib/components/components/OverlayTrigger.d.ts +36 -0
  28. package/lib/components/components/OverlayTrigger.js +90 -0
  29. package/lib/components/components/Stretch.d.ts +36 -0
  30. package/lib/components/components/Stretch.js +115 -0
  31. package/lib/components/components/TooltipComponent.d.ts +12 -0
  32. package/lib/components/components/TooltipComponent.js +38 -0
  33. package/lib/components/components/index.d.ts +13 -0
  34. package/lib/components/components/index.js +25 -0
  35. package/lib/components/fields/AnnotationField.js +30 -8
  36. package/lib/components/fields/AnyToBooleanField.js +21 -2
  37. package/lib/components/fields/ArrayBulkField.js +25 -3
  38. package/lib/components/fields/ArrayCombinerField.js +27 -5
  39. package/lib/components/fields/ArrayField.js +27 -5
  40. package/lib/components/fields/ArrayPropertySumField.js +25 -3
  41. package/lib/components/fields/AsArrayField.js +25 -3
  42. package/lib/components/fields/AudioArrayField.js +28 -6
  43. package/lib/components/fields/AutoArrayField.js +25 -3
  44. package/lib/components/fields/AutosuggestField.js +27 -5
  45. package/lib/components/fields/CombinedValueDisplayField.js +25 -3
  46. package/lib/components/fields/CondensedObjectField.d.ts +1 -1
  47. package/lib/components/fields/CondensedObjectField.js +29 -7
  48. package/lib/components/fields/ConditionalOnChangeField.js +25 -3
  49. package/lib/components/fields/ConditionalUiSchemaField.js +27 -5
  50. package/lib/components/fields/ContextInjectionField.js +26 -4
  51. package/lib/components/fields/DataLeakerField.js +25 -3
  52. package/lib/components/fields/DefaultValueArrayField.js +26 -4
  53. package/lib/components/fields/DependentBooleanField.js +26 -4
  54. package/lib/components/fields/DependentDisableField.js +26 -4
  55. package/lib/components/fields/EnumRangeArrayField.js +25 -3
  56. package/lib/components/fields/ExtraLabelRowField.d.ts +1 -3
  57. package/lib/components/fields/ExtraLabelRowField.js +29 -12
  58. package/lib/components/fields/FakePropertyField.js +25 -3
  59. package/lib/components/fields/FilterArrayField.js +25 -3
  60. package/lib/components/fields/FlatField.js +26 -4
  61. package/lib/components/fields/GeocoderField.js +32 -10
  62. package/lib/components/fields/GridLayoutField.js +21 -2
  63. package/lib/components/fields/HiddenField.js +21 -2
  64. package/lib/components/fields/HiddenWithTextField.js +21 -2
  65. package/lib/components/fields/ImageArrayField.js +41 -19
  66. package/lib/components/fields/ImageDisplayField.js +26 -4
  67. package/lib/components/fields/InitiallyHiddenField.js +26 -4
  68. package/lib/components/fields/InjectDefaultValueField.js +26 -4
  69. package/lib/components/fields/InjectField.js +25 -3
  70. package/lib/components/fields/InputWithDefaultValueButtonField.js +27 -5
  71. package/lib/components/fields/LocalityField.js +27 -5
  72. package/lib/components/fields/LocationChooserField.js +27 -5
  73. package/lib/components/fields/MapArrayField.js +33 -12
  74. package/lib/components/fields/MapField.js +29 -8
  75. package/lib/components/fields/MultiAnyToBooleanField.js +26 -4
  76. package/lib/components/fields/MultiArrayField.js +26 -4
  77. package/lib/components/fields/MultiLanguageField.js +25 -3
  78. package/lib/components/fields/MultiTagArrayField.d.ts +2 -5
  79. package/lib/components/fields/MultiTagArrayField.js +34 -19
  80. package/lib/components/fields/NamedPlaceChooserField.js +31 -9
  81. package/lib/components/fields/NamedPlaceSaverField.js +33 -11
  82. package/lib/components/fields/NestField.js +28 -6
  83. package/lib/components/fields/ObjectField.js +24 -2
  84. package/lib/components/fields/PdfArrayField.js +20 -1
  85. package/lib/components/fields/PrefillingArrayField.js +25 -3
  86. package/lib/components/fields/SchemaField.js +20 -1
  87. package/lib/components/fields/ScopeField.js +30 -8
  88. package/lib/components/fields/SectionArrayField.js +34 -13
  89. package/lib/components/fields/SelectTreeField.js +20 -1
  90. package/lib/components/fields/SingleActiveArrayField.js +41 -26
  91. package/lib/components/fields/SingleItemArrayField.js +25 -3
  92. package/lib/components/fields/SortArrayField.js +31 -9
  93. package/lib/components/fields/SplitField.js +26 -4
  94. package/lib/components/fields/StringToArrayField.js +25 -3
  95. package/lib/components/fields/SumField.js +25 -3
  96. package/lib/components/fields/TableField.js +26 -4
  97. package/lib/components/fields/TagArrayField.d.ts +1 -1
  98. package/lib/components/fields/TagArrayField.js +28 -6
  99. package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +26 -4
  100. package/lib/components/fields/UiFieldApplierField.js +25 -3
  101. package/lib/components/fields/UiFieldMapperArrayField.js +25 -3
  102. package/lib/components/fields/UnitCountShorthandField.js +29 -7
  103. package/lib/components/fields/UnitListShorthandArrayField.js +26 -4
  104. package/lib/components/fields/UnitShorthandField.js +27 -5
  105. package/lib/components/templates/ArrayFieldTemplate.js +27 -5
  106. package/lib/components/templates/BaseInputTemplate.js +24 -2
  107. package/lib/components/templates/DescriptionField.js +21 -2
  108. package/lib/components/templates/ErrorListTemplate.js +24 -2
  109. package/lib/components/templates/FieldTemplate.js +24 -2
  110. package/lib/components/templates/ObjectFieldTemplate.js +24 -2
  111. package/lib/components/templates/TitleField.js +25 -3
  112. package/lib/components/widgets/AnyToBooleanWidget.js +21 -2
  113. package/lib/components/widgets/AutosuggestWidget.js +33 -7
  114. package/lib/components/widgets/CheckboxWidget.js +25 -3
  115. package/lib/components/widgets/DateTimeWidget.d.ts +1 -1
  116. package/lib/components/widgets/DateTimeWidget.js +38 -16
  117. package/lib/components/widgets/DateWidget.js +27 -5
  118. package/lib/components/widgets/HiddenWidget.js +21 -2
  119. package/lib/components/widgets/ImageSelectWidget.js +28 -6
  120. package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +30 -8
  121. package/lib/components/widgets/InputGroupWidget.js +27 -5
  122. package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +26 -4
  123. package/lib/components/widgets/NumberWidget.js +25 -3
  124. package/lib/components/widgets/PlainTextWidget.js +21 -2
  125. package/lib/components/widgets/SelectWidget.js +26 -4
  126. package/lib/components/widgets/SeparatedDateTimeWidget.js +28 -6
  127. package/lib/components/widgets/TaxonImageWidget.js +21 -2
  128. package/lib/components/widgets/TextSelectWidget.js +27 -5
  129. package/lib/components/widgets/TextareaWidget.js +26 -4
  130. package/lib/components/widgets/TimeWidget.js +28 -6
  131. package/lib/components/widgets/URLWidget.js +21 -2
  132. package/lib/components/widgets/UpperCaseWidget.js +25 -3
  133. package/lib/index.js +24 -2
  134. package/lib/services/id-service.d.ts +1 -1
  135. package/lib/services/id-service.js +1 -1
  136. package/lib/services/key-handler-service.js +4 -1
  137. package/lib/services/singleton-map-service.js +4 -1
  138. package/lib/services/submit-hook-service.d.ts +4 -2
  139. package/lib/services/submit-hook-service.js +1 -0
  140. package/lib/themes/bs3.js +94 -72
  141. package/lib/themes/bs5.js +20 -1
  142. package/lib/themes/stub.js +20 -1
  143. package/lib/themes/theme.d.ts +5 -3
  144. package/lib/utils.js +27 -5
  145. package/lib/validation.js +20 -1
  146. package/package.json +1 -1
  147. package/test-export/test-utils.js +20 -1
  148. package/lib/components/components.d.ts +0 -129
  149. package/lib/components/components.js +0 -633
@@ -1,633 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.FailedBackgroundJobsPanel = exports.Fullscreen = exports.OverlayTrigger = exports.FetcherInput = exports.TooltipComponent = exports.ErrorPanel = exports.Label = exports.Help = exports.Stretch = exports.Affix = exports.GlyphButton = exports.AddButton = exports.DeleteButton = exports.Button = void 0;
15
- const React = require("react");
16
- const PropTypes = require("prop-types");
17
- const react_dom_1 = require("react-dom");
18
- const Spinner = require("react-spinner");
19
- const utils_1 = require("../utils");
20
- const ReactContext_1 = require("../ReactContext");
21
- class Button extends React.Component {
22
- render() {
23
- const _a = this.props, { tooltip, tooltipPlacement, tooltipTrigger, tooltipClass } = _a, _props = __rest(_a, ["tooltip", "tooltipPlacement", "tooltipTrigger", "tooltipClass"]);
24
- const { Button: _Button } = this.context.theme;
25
- return (React.createElement(TooltipComponent, { tooltip: tooltip, placement: tooltipPlacement, trigger: tooltipTrigger, className: tooltipClass },
26
- React.createElement(_Button, Object.assign({}, _props), _props.children)));
27
- }
28
- }
29
- exports.Button = Button;
30
- Button.contextType = ReactContext_1.default;
31
- class DeleteButton extends React.Component {
32
- constructor(props) {
33
- super(props);
34
- this.onButtonKeyDown = ({ key }) => {
35
- if (key === "Enter")
36
- this.onConfirmedClick();
37
- else if (key === "Escape")
38
- this.setState({ show: false });
39
- };
40
- this.onHideConfirm = () => {
41
- this.setState({ show: false }, () => {
42
- if (this.callback) {
43
- this.callback(this.deleted);
44
- this.callbackCalled = true;
45
- }
46
- });
47
- };
48
- this.onShowConfirm = (e) => {
49
- e.preventDefault();
50
- e.stopPropagation();
51
- this.setState({ show: true }, () => {
52
- if (this.props.confirmStyle === "browser") {
53
- this.browserConfirm();
54
- }
55
- });
56
- };
57
- this.onConfirmedClick = (e) => {
58
- e && e.preventDefault();
59
- e && e.stopPropagation();
60
- this.props.onClick();
61
- this.onHideConfirm();
62
- this.deleted = true;
63
- };
64
- this.onClick = (e, callback) => {
65
- this.callback = callback;
66
- this.props.confirm ? this.onShowConfirm(e) : this.onConfirmedClick(e);
67
- };
68
- this.componentWillUnmount = () => {
69
- if (this.callback && !this.callbackCalled) {
70
- this.callback(this.deleted);
71
- }
72
- };
73
- this.setConfirmAutofocus = (elem) => {
74
- setTimeout(() => {
75
- const domElem = react_dom_1.findDOMNode(elem);
76
- domElem && domElem.focus();
77
- });
78
- };
79
- this.renderConfirm = () => {
80
- const { show } = this.state;
81
- if (!show) {
82
- return null;
83
- }
84
- const { confirmStyle = "popup" } = this.props;
85
- if (confirmStyle === "popup") {
86
- return this.renderConfirmPopup();
87
- }
88
- return null;
89
- };
90
- this.getOverlayTarget = () => react_dom_1.findDOMNode(this.refs.del);
91
- this.state = { show: false };
92
- }
93
- render() {
94
- const { props } = this;
95
- const { corner, tooltip, disabled, readonly, glyphButton = true, confirm, confirmPlacement, confirmStyle } = props, maybeProps = __rest(props, ["corner", "tooltip", "disabled", "readonly", "glyphButton", "confirm", "confirmPlacement", "confirmStyle"]); // eslint-disable-line @typescript-eslint/no-unused-vars
96
- let buttonClassName = glyphButton ? "glyph-button" : "";
97
- buttonClassName += corner ? " button-corner" : "";
98
- if (props.className) {
99
- buttonClassName = `${buttonClassName} ${props.className}`;
100
- }
101
- if (props.id !== undefined) {
102
- maybeProps.id = `${props.id}-delete`;
103
- }
104
- const button = (React.createElement(React.Fragment, null,
105
- React.createElement(Button, Object.assign({}, maybeProps, { disabled: disabled || readonly, variant: "danger", className: buttonClassName, style: this.props.style, ref: "del", onKeyDown: this.onButtonKeyDown, onClick: this.onClick }),
106
- this.props.children,
107
- " ",
108
- "✖"),
109
- this.renderConfirm()));
110
- return tooltip ? React.createElement(TooltipComponent, { tooltip: tooltip }, button) : button;
111
- }
112
- renderConfirmPopup() {
113
- const { translations, confirmPlacement = "left" } = this.props;
114
- const { Overlay, Popover, ButtonGroup } = this.context.theme;
115
- return (React.createElement(Overlay, { show: true, placement: confirmPlacement, rootClose: true, onHide: this.onHideConfirm, target: this.getOverlayTarget },
116
- React.createElement(Popover, { id: `${this.props.id}-button-confirm` },
117
- React.createElement("span", null, translations.ConfirmRemove),
118
- React.createElement(ButtonGroup, null,
119
- React.createElement(Button, { variant: "danger", onClick: this.onConfirmedClick, ref: this.setConfirmAutofocus, id: `${this.props.id}-delete-confirm-yes` }, translations.Remove),
120
- React.createElement(Button, { variant: "default", onClick: this.onHideConfirm, id: `${this.props.id}-delete-confirm-no` }, translations.Cancel)))));
121
- }
122
- browserConfirm() {
123
- const choice = confirm(this.props.translations.ConfirmRemove);
124
- if (choice) {
125
- this.onConfirmedClick();
126
- }
127
- else {
128
- this.onHideConfirm();
129
- }
130
- }
131
- }
132
- exports.DeleteButton = DeleteButton;
133
- DeleteButton.contextType = ReactContext_1.default;
134
- DeleteButton.propTypes = {
135
- confirm: PropTypes.bool,
136
- onClick: PropTypes.func.isRequired,
137
- translations: PropTypes.object.isRequired,
138
- confirmStyle: PropTypes.oneOf(["popup", "browser"])
139
- };
140
- function AddButton({ onClick }) {
141
- const { Row, Col } = React.useContext(ReactContext_1.default).theme;
142
- return React.createElement(Row, null,
143
- React.createElement(Col, { xs: 2 },
144
- React.createElement(Button, { onClick: onClick }, "\u2795")));
145
- }
146
- exports.AddButton = AddButton;
147
- exports.GlyphButton = React.forwardRef((props, ref) => {
148
- const { glyph } = props, buttonProps = __rest(props, ["glyph"]);
149
- const { Glyphicon } = React.useContext(ReactContext_1.default).theme;
150
- return (React.createElement(Button, Object.assign({}, buttonProps, { ref: ref, className: `glyph-button${props.className ? ` ${props.className}` : ""}`, tooltipPlacement: props.tooltipPlacement || "left" }),
151
- React.createElement(Glyphicon, { glyph: glyph }),
152
- props.children));
153
- });
154
- const TOP = "TOP", AFFIXED = "AFFIXED", BOTTOM = "BOTTOM";
155
- class Affix extends React.Component {
156
- constructor(props) {
157
- super(props);
158
- this.getState = (props) => {
159
- const { topOffset = 0, bottomOffset = 0, getContainer } = props;
160
- const container = getContainer ? getContainer() : this.refs.container;
161
- const wrapperElem = react_dom_1.findDOMNode(this.refs.wrapper);
162
- if (!container || !document.body.contains(container) || !wrapperElem)
163
- return;
164
- const containerTop = container.getBoundingClientRect().top;
165
- const containerHeight = container.offsetHeight;
166
- const containerVisibleHeight = containerHeight + containerTop;
167
- const wrapperHeight = wrapperElem.offsetHeight;
168
- const wrapperScrollHeight = wrapperElem.scrollHeight;
169
- const scrolled = this.refs.container.getBoundingClientRect().top < topOffset;
170
- const viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
171
- const bottomDist = viewportHeight - container.getBoundingClientRect().top - containerHeight;
172
- const bottomInvisibleHeight = Math.min(bottomDist, 0);
173
- let affixState = TOP;
174
- if (scrolled && containerVisibleHeight < wrapperScrollHeight + topOffset)
175
- affixState = BOTTOM;
176
- else if (scrolled)
177
- affixState = AFFIXED;
178
- const width = wrapperElem ? wrapperElem.offsetWidth : undefined;
179
- const top = topOffset;
180
- const affixHeight = affixState === BOTTOM
181
- ? Math.max(containerVisibleHeight
182
- - topOffset
183
- + Math.min(bottomInvisibleHeight, 0)
184
- - (bottomDist < bottomOffset ? Math.min(bottomOffset - bottomDist, bottomOffset) : 0), 0)
185
- : undefined;
186
- const wrapperCutHeight = wrapperHeight - (affixHeight || 0);
187
- let change;
188
- if (affixState === BOTTOM) {
189
- if (!this.state) {
190
- change = wrapperCutHeight;
191
- }
192
- else {
193
- if (this.state.affixState === BOTTOM) {
194
- const lastChange = this.state.change;
195
- const changeNow = wrapperCutHeight;
196
- change = lastChange + changeNow;
197
- }
198
- else {
199
- change = wrapperCutHeight;
200
- }
201
- }
202
- }
203
- const fixerHeight = affixState === AFFIXED
204
- ? wrapperHeight - (affixHeight || 0)
205
- : affixState === BOTTOM
206
- ? affixHeight + change
207
- : 0;
208
- return { affixState, width, top, affixHeight, fixerHeight, change };
209
- };
210
- this._onScroll = () => {
211
- this.setState(this.getState(this.props));
212
- };
213
- this.onScroll = () => {
214
- requestAnimationFrame(this._onScroll);
215
- };
216
- this._onResize = () => {
217
- const positioner = react_dom_1.findDOMNode(this.refs.positioner);
218
- const width = positioner.getBoundingClientRect().width;
219
- const state = { width };
220
- const _state = this.getState(this.props);
221
- if (_state.affixState !== TOP)
222
- state.top = _state.top;
223
- this.setState(state);
224
- };
225
- this.onResize = () => {
226
- requestAnimationFrame(this._onResize);
227
- };
228
- this.state = this.getState(props);
229
- }
230
- componentDidMount() {
231
- window.addEventListener("scroll", this.onScroll);
232
- window.addEventListener("resize", this.onResize);
233
- }
234
- componentWillUnmount() {
235
- window.removeEventListener("scroll", this.onScroll);
236
- window.removeEventListener("resize", this.onResize);
237
- }
238
- componentDidUpdate(prevProps, prevState) {
239
- if (!this.props.onAffixChange || !prevState || !this.state) {
240
- return;
241
- }
242
- if (prevState.affixState !== AFFIXED && this.state.affixState === AFFIXED) {
243
- this.props.onAffixChange(true);
244
- }
245
- else if (prevState.affixState === AFFIXED && this.state.affixState !== AFFIXED) {
246
- this.props.onAffixChange(false);
247
- }
248
- }
249
- render() {
250
- const { children, style: containerStyle } = this.props;
251
- const { top, width, affixState, affixHeight, fixerHeight } = this.state || {};
252
- const style = {};
253
- const fixerStyle = { position: "relative", zIndex: -1, height: fixerHeight };
254
- style.position = "relative";
255
- if (affixState === BOTTOM || affixState === AFFIXED) {
256
- style.position = "fixed";
257
- style.width = width;
258
- style.top = top;
259
- style.zIndex = 1000;
260
- style.height = affixHeight;
261
- if (affixState === BOTTOM) {
262
- style.overflow = "hidden";
263
- }
264
- }
265
- return (React.createElement("div", { style: containerStyle, ref: "container" },
266
- React.createElement("div", { ref: "positioner" }),
267
- React.createElement("div", { ref: "wrapper", style: style, className: this.props.className }, children),
268
- React.createElement("div", { style: fixerStyle })));
269
- }
270
- }
271
- exports.Affix = Affix;
272
- class Stretch extends React.Component {
273
- constructor(props) {
274
- super(props);
275
- this._onScroll = () => {
276
- let callback = undefined;
277
- const state = this.getState();
278
- if (!this.cameToViewFirstTime && state.height > this.props.enterViewPortTreshold || 0) {
279
- this.cameToViewFirstTime = true;
280
- if (this.props.onEnterViewPort)
281
- callback = () => this.props.onEnterViewPort();
282
- }
283
- this.update(state, callback);
284
- };
285
- this.onScroll = () => {
286
- requestAnimationFrame(this._onScroll);
287
- };
288
- this.update = (state, callback) => {
289
- const afterStateChange = () => {
290
- if (this.props.onResize)
291
- this.props.onResize();
292
- callback && callback();
293
- };
294
- state ? this.setState(state, () => {
295
- afterStateChange();
296
- }) : afterStateChange;
297
- };
298
- this.getState = () => {
299
- const { getContainer, topOffset = 0, bottomOffset = 0, minHeight } = this.props;
300
- let container = getContainer();
301
- if (this.refs.wrapper &&
302
- this.props.getContainer().getBoundingClientRect().top !== react_dom_1.findDOMNode(this.refs.wrapper).getBoundingClientRect().top) {
303
- return {
304
- horizontallyAligned: false
305
- };
306
- }
307
- let containerHeight = container.offsetHeight;
308
- if (minHeight && containerHeight < minHeight) {
309
- containerHeight = minHeight;
310
- container = this.refs.wrapper;
311
- }
312
- const viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
313
- const bottomDist = viewportHeight - container.getBoundingClientRect().top - containerHeight;
314
- const bottomInvisibleHeight = Math.min(bottomDist, 0);
315
- return {
316
- horizontallyAligned: true,
317
- containerHeight,
318
- height: Math.max(containerHeight
319
- + Math.min(container.getBoundingClientRect().top, 0)
320
- + Math.min(bottomInvisibleHeight, 0)
321
- - (container.getBoundingClientRect().top < topOffset ? Math.min(topOffset - container.getBoundingClientRect().top, topOffset) : 0)
322
- - (bottomDist < bottomOffset ? Math.min(bottomOffset - bottomDist, bottomOffset) : 0), 0),
323
- top: Math.max(-container.getBoundingClientRect().top + topOffset, 0)
324
- };
325
- };
326
- this.state = {};
327
- }
328
- UNSAFE_componentWillReceiveProps(props) {
329
- if (props.mounted && !this.initialized) {
330
- const state = this.getState();
331
- this.update(state);
332
- this.cameToViewFirstTime = state.height > this.props.enterViewPortTreshold || 0;
333
- this.initialized = true;
334
- }
335
- }
336
- componentDidMount() {
337
- window.addEventListener("scroll", this.onScroll);
338
- window.addEventListener("resize", this.onScroll);
339
- }
340
- componentWillUnmount() {
341
- window.removeEventListener("scroll", this.onScroll);
342
- window.removeEventListener("resize", this.onScroll);
343
- }
344
- render() {
345
- const { children } = this.props;
346
- const wrapperStyle = {
347
- height: this.state.horizontallyAligned ? this.state.containerHeight : this.props.minHeight,
348
- };
349
- const style = {
350
- position: "relative",
351
- top: this.state.horizontallyAligned ? this.state.top : undefined,
352
- height: this.state.horizontallyAligned ? this.state.height : "100%",
353
- };
354
- return (React.createElement("div", { ref: "wrapper", style: wrapperStyle, className: this.props.className },
355
- React.createElement("div", { style: style }, children)));
356
- }
357
- }
358
- exports.Stretch = Stretch;
359
- /**
360
- * @param standalone If provided, the help icon will handle **accessibility** itself.
361
- * If not provided, the parent element must take care of showing the tooltip.
362
- *
363
- * **accessibility** means that it handles showing the tooltip on focus & hover, and
364
- */
365
- function Help({ help, id, focusable = false, onFocus, onBlur, className, onClick, standalone }) {
366
- const { Tooltip } = React.useContext(ReactContext_1.default).theme;
367
- const [focused, setFocused] = React.useState(undefined);
368
- const onHelpFocus = React.useCallback(() => {
369
- setFocused(true);
370
- }, []);
371
- const onHelpBlur = React.useCallback(() => {
372
- setFocused(false);
373
- }, []);
374
- const helpGlyph = React.createElement("span", { className: utils_1.classNames("laji-form-help-glyph", "text-muted", className), tabIndex: focusable ? 0 : -1, onFocus: standalone ? onHelpFocus : onFocus, onBlur: standalone ? onHelpBlur : onBlur, onClick: onClick });
375
- const tooltip = React.createElement(Tooltip, { id: id },
376
- React.createElement("span", { dangerouslySetInnerHTML: { __html: help } }));
377
- return help ? (React.createElement(OverlayTrigger, { placement: "right", overlay: tooltip, show: standalone && focused || undefined },
378
- React.createElement(React.Fragment, null,
379
- helpGlyph,
380
- standalone && React.createElement("div", { id: `${id}--help`, style: { display: "none" } }, help)))) : helpGlyph;
381
- }
382
- exports.Help = Help;
383
- function Label({ label, children, id, required, registry = {}, uiSchema = {} }) {
384
- const { "ui:help": help, "ui:helpHoverable": helpHoverable, "ui:helpPlacement": helpPlacement, labelComponent } = uiSchema;
385
- const showHelp = label && help;
386
- const { Tooltip } = React.useContext(ReactContext_1.default).theme;
387
- const tooltipElem = (React.createElement(Tooltip, { id: id + "-tooltip" }, help ? (React.createElement("span", null,
388
- React.createElement("strong", { dangerouslySetInnerHTML: { __html: label } }),
389
- React.createElement("br", null),
390
- React.createElement("span", { dangerouslySetInnerHTML: { __html: help } }))) : label));
391
- const requiredHtml = required ? "<span class='text-danger'>*</span>" : "";
392
- const [focused, setFocused] = React.useState(undefined);
393
- const onHelpFocus = React.useCallback(() => {
394
- setFocused(true);
395
- }, []);
396
- const onHelpBlur = React.useCallback(() => {
397
- setFocused(false);
398
- }, []);
399
- const onHelpClick = React.useCallback((e) => {
400
- e.preventDefault();
401
- }, []);
402
- const LabelComponent = labelComponent || "label";
403
- const labelElem = (React.createElement(LabelComponent, { htmlFor: id, "aria-describedby": `${id}--help` },
404
- React.createElement("div", { style: { whiteSpace: "normal" } },
405
- React.createElement("span", { dangerouslySetInnerHTML: { __html: label + requiredHtml } }),
406
- showHelp ? React.createElement(Help, { focusable: true, onFocus: onHelpFocus, onBlur: onHelpBlur, onClick: onHelpClick, id: id }) : null),
407
- children));
408
- return help ? React.createElement(React.Fragment, null,
409
- React.createElement(OverlayTrigger, { placement: helpPlacement || "right", overlay: tooltipElem, hoverable: helpHoverable, formContext: registry.formContext, show: focused || undefined, style: { display: "inline-block" } }, labelElem),
410
- React.createElement("div", { id: `${id}--help`, style: { display: "none" } }, help)) : labelElem;
411
- }
412
- exports.Label = Label;
413
- class ErrorPanel extends React.Component {
414
- constructor(props) {
415
- super(props);
416
- this.expand = () => {
417
- if (!this.state.expanded)
418
- this.setState({ expanded: true });
419
- };
420
- this.collapseToggle = () => this.setState({ expanded: !this.state.expanded });
421
- this.state = { expanded: true };
422
- }
423
- render() {
424
- const { errors, title, clickHandler, poppedToggle, showToggle, classNames, footer } = this.props;
425
- if (errors.length === 0)
426
- return null;
427
- const { Panel, ListGroup } = this.context.theme;
428
- return (React.createElement(Panel, { collapsible: "true", onToggle: this.collapseToggle, className: classNames },
429
- React.createElement(Panel.Heading, null,
430
- React.createElement("div", { className: "laji-form-clickable-panel-header", onClick: this.collapseToggle },
431
- React.createElement("div", { className: "panel-title" },
432
- title,
433
- React.createElement("span", { className: "pull-right" },
434
- React.createElement(exports.GlyphButton, { glyph: this.state.expanded ? "chevron-up" : "chevron-down", variant: "link" }),
435
- showToggle ? React.createElement(exports.GlyphButton, { glyph: "new-window", variant: "link", onClick: poppedToggle }) : null)))),
436
- React.createElement(Panel.Collapse, { in: this.state.expanded },
437
- React.createElement(ListGroup, null, errors.map((props, i) => React.createElement(ErrorPanelError, Object.assign({ key: i, clickHandler: clickHandler }, props))))),
438
- footer
439
- ? (React.createElement(Panel.Footer, null, footer))
440
- : null));
441
- }
442
- }
443
- exports.ErrorPanel = ErrorPanel;
444
- ErrorPanel.contextType = ReactContext_1.default;
445
- function ErrorPanelError({ label, error, id, getId, extra = null, disabled, clickHandler }) {
446
- const message = error && error.message ? error.message : error;
447
- const _clickHandler = React.useCallback(() => {
448
- clickHandler(id || (getId ? getId() : undefined));
449
- }, [clickHandler, id, getId]);
450
- const { ListGroupItem } = React.useContext(ReactContext_1.default).theme;
451
- return (React.createElement(ListGroupItem, { onClick: _clickHandler, disabled: disabled },
452
- label ? React.createElement("b", null,
453
- label,
454
- ":") : null,
455
- " ",
456
- message,
457
- " ",
458
- extra));
459
- }
460
- // Tooltip component that doesn't show tooltip for empty/undefined tooltip.
461
- class TooltipComponent extends React.Component {
462
- constructor(props) {
463
- super(props);
464
- this.onMouseOver = () => {
465
- this.setState({ show: true });
466
- };
467
- this.onMouseOut = () => {
468
- this.setState({ show: false });
469
- };
470
- this.state = { show: false };
471
- }
472
- render() {
473
- const { tooltip, children, id, placement, trigger, className } = this.props;
474
- const { OverlayTrigger, Tooltip } = this.context.theme;
475
- const overlay = (tooltip ? (React.createElement(OverlayTrigger, { show: this.state.show, placement: placement, trigger: trigger === "hover" ? [] : trigger, key: `${id}-overlay`, overlay: React.createElement(Tooltip, { id: `${id}-tooltip`, className: `${className}` }, React.isValidElement(tooltip) ? tooltip : React.createElement("span", { dangerouslySetInnerHTML: { __html: tooltip } })) }, children)) : React.createElement(React.Fragment, null, children));
476
- return (trigger === "hover") ? (React.createElement("div", { onMouseOver: this.onMouseOver, onMouseOut: this.onMouseOut }, overlay)) : overlay;
477
- }
478
- }
479
- exports.TooltipComponent = TooltipComponent;
480
- TooltipComponent.contextType = ReactContext_1.default;
481
- exports.FetcherInput = React.forwardRef((props, ref) => {
482
- const { loading, validationState, glyph, extra, onMouseOver, onMouseOut, className = "", InputComponent } = props, inputProps = __rest(props, ["loading", "validationState", "glyph", "extra", "onMouseOver", "onMouseOut", "className", "InputComponent"]); // eslint-disable-line @typescript-eslint/no-unused-vars
483
- const { InputGroup, FormGroup } = React.useContext(ReactContext_1.default).theme;
484
- const Input = InputComponent ? InputComponent : FetcherInputDefaultInput;
485
- const _extra = (!Array.isArray(extra)) ? [extra] : extra;
486
- const hasExtras = _extra.some(item => item !== null && item !== undefined);
487
- const inputContent = React.createElement(React.Fragment, null,
488
- hasExtras && React.createElement(InputGroup.Button, null, _extra),
489
- React.createElement(Input, Object.assign({}, inputProps, { ref: ref })),
490
- glyph,
491
- loading && React.createElement(Spinner, null));
492
- const content = hasExtras
493
- ? (React.createElement(InputGroup, null, inputContent))
494
- : inputContent;
495
- return (React.createElement(FormGroup, { onMouseOver: onMouseOver, onMouseOut: onMouseOut, validationState: validationState, className: utils_1.classNames(className, "fetcher-input") }, content));
496
- });
497
- const FetcherInputDefaultInput = React.forwardRef((props, ref) => {
498
- const { readonly } = props, inputProps = __rest(props, ["readonly"]);
499
- const { FormControl } = React.useContext(ReactContext_1.default).theme;
500
- return React.createElement(FormControl, Object.assign({ type: "text" }, inputProps, { readOnly: readonly, ref: ref }));
501
- });
502
- // OverlayTrigger that is hoverable if hoverable === true
503
- class OverlayTrigger extends React.Component {
504
- constructor(props) {
505
- super(props);
506
- this.overlayTriggerMouseOver = () => {
507
- this.setState({ hoveringElem: true });
508
- };
509
- this.overlayTriggerMouseOut = () => {
510
- if (this.overlayTimeout) {
511
- clearTimeout(this.overlayTimeout);
512
- }
513
- if (this.props.hoverable) {
514
- this.overlayTimeout = this.props.formContext.setTimeout(() => {
515
- if (!this.popoverMouseIn && !this.overlayTriggerMouseIn) {
516
- this.setState({ hoveringElem: false });
517
- }
518
- }, 200);
519
- }
520
- else {
521
- this.setState({ hoveringElem: false });
522
- }
523
- };
524
- this.overlayMouseOver = () => {
525
- this.setState({ hoveringOverlay: true });
526
- };
527
- this.overlayMouseOut = () => {
528
- this.setState({ hoveringOverlay: false, hoveringElem: false });
529
- };
530
- this.state = {};
531
- }
532
- componentWillUnmount() {
533
- if (this.overlayTimeout) {
534
- clearTimeout(this.overlayTimeout);
535
- }
536
- }
537
- render() {
538
- const _a = this.props, { children, overlay, contextId, //eslint-disable-line @typescript-eslint/no-unused-vars
539
- style } = _a, props = __rest(_a, ["children", "overlay", "contextId", "style"]);
540
- const { OverlayTrigger } = this.context.theme;
541
- let _overlay = React.cloneElement(overlay, { onMouseOver: this.overlayMouseOver, onMouseOut: this.overlayMouseOut });
542
- const show = this.props.show !== undefined
543
- ? this.props.show
544
- : this.state.hoveringElem || this.props.hoverable && this.state.hoveringOverlay;
545
- return (React.createElement("div", { onMouseOver: this.overlayTriggerMouseOver, onMouseOut: this.overlayTriggerMouseOut, style: style },
546
- React.createElement(OverlayTrigger, Object.assign({}, props, { delay: 1, trigger: [], placement: this.props.placement || "top", overlay: _overlay, show: show }), children)));
547
- }
548
- }
549
- exports.OverlayTrigger = OverlayTrigger;
550
- OverlayTrigger.contextType = ReactContext_1.default;
551
- class Fullscreen extends React.Component {
552
- componentDidMount() {
553
- this.bodyOverFlow = document.body.style.overflow;
554
- if (this.props.onKeyDown) {
555
- this._onKeyDown = true;
556
- this.props.formContext.services.keyHandler.addGlobalEventHandler("keydown", this.props.onKeyDown);
557
- }
558
- }
559
- componentWillUnmount() {
560
- document.body.style.overflow = this.bodyOverFlow;
561
- if (this._onKeyDown) {
562
- this.props.formContext.services.keyHandler.removeGlobalEventHandler("keydown", this.props.onKeyDown);
563
- }
564
- }
565
- render() {
566
- return react_dom_1.createPortal((React.createElement("div", { className: "laji-form fullscreen" }, this.props.children)), document.body);
567
- }
568
- }
569
- exports.Fullscreen = Fullscreen;
570
- class FailedBackgroundJobsPanel extends React.Component {
571
- constructor(props) {
572
- super(props);
573
- this.dismissFailedJob = ({ id, hook, running }) => (e) => {
574
- e.stopPropagation();
575
- if (running)
576
- return;
577
- this.props.formContext.services.submitHooks.remove(id, hook);
578
- };
579
- this.retryFailedJob = ({ hook, running }) => (e) => {
580
- e.stopPropagation();
581
- if (running)
582
- return;
583
- hook();
584
- };
585
- this.poppedToggle = (e) => {
586
- e.stopPropagation();
587
- this.setState({ popped: !this.state.popped, poppedTouched: true });
588
- };
589
- this.state = { popped: true };
590
- }
591
- render() {
592
- const { jobs = [], schema, uiSchema = {}, formContext: { translations } } = this.props;
593
- if (!jobs.length)
594
- return null;
595
- const { Glyphicon } = this.context.theme;
596
- const errors = jobs.reduce((_errors, error) => {
597
- const { lajiFormId, relativePointer, e, running } = error;
598
- if (!e) {
599
- return _errors;
600
- }
601
- const getJsonPointer = () => this.props.formContext.services.ids.getJSONPointerFromLajiFormIdAndRelativePointer(lajiFormId, relativePointer);
602
- const jsonPointer = getJsonPointer();
603
- const label = utils_1.parseJSONPointer(uiSchema, `${utils_1.uiSchemaJSONPointer(uiSchema, jsonPointer)}/ui:title`, "safely")
604
- || utils_1.parseJSONPointer(schema, `${utils_1.schemaJSONPointer(schema, jsonPointer)}/title`, "safely");
605
- const retryButton = React.createElement("a", { key: "rety", className: "pull-right", disabled: running, onClick: this.retryFailedJob(error) },
606
- React.createElement(Glyphicon, { className: running ? "rotating" : "", glyph: "refresh" }),
607
- " ",
608
- translations.Retry);
609
- const dismissButton = React.createElement("a", { key: "dismiss", className: "pull-right", onClick: this.dismissFailedJob(error) },
610
- React.createElement(Glyphicon, { glyph: "ok" }),
611
- " ",
612
- translations.Dismiss);
613
- const getId = () => {
614
- const jsonPointer = getJsonPointer();
615
- return `root_${utils_1.JSONPointerToId(jsonPointer)}`;
616
- };
617
- const _error = { getId, error: e, extra: [dismissButton, retryButton], disabled: running };
618
- if (label)
619
- _error.label = label;
620
- return [..._errors, _error];
621
- }, []);
622
- if (!errors.length)
623
- return null;
624
- const footer = (React.createElement(Button, { onClick: this.props.formContext.services.submitHooks.removeAll },
625
- React.createElement(Glyphicon, { glyph: "ok" }),
626
- " ",
627
- `${translations.Dismiss} ${translations.all}`));
628
- return (React.createElement("div", { className: `laji-form-error-list laji-form-failed-jobs-list${this.state.popped ? " laji-form-popped" : ""}`, style: this.state.popped ? { top: (this.props.formContext.topOffset || 0) + 5 } : null },
629
- React.createElement(ErrorPanel, { title: translations.FailedBackgroundJobs, errors: errors, showToggle: true, poppedToggle: this.poppedToggle, clickHandler: this.props.errorClickHandler, classNames: "error-panel", footer: footer })));
630
- }
631
- }
632
- exports.FailedBackgroundJobsPanel = FailedBackgroundJobsPanel;
633
- FailedBackgroundJobsPanel.contextType = ReactContext_1.default;